#include "Material.h"

#include "G4Element.hh"
#include "G4NistManager.hh"
#include "G4PhysicalConstants.hh"
#include "G4SystemOfUnits.hh"

void DefineMaterials() {
    G4double a, z;                            // 摩尔质量, 原子序数
    G4int ncomponents, fractionmass, natoms;  // 组分数, 质量分数, 原子数
    G4double density, pressure, temperature;

    G4NistManager* nist = G4NistManager::Instance();

    // 已有
    nist->FindOrBuildMaterial("G4_AIR");
    nist->FindOrBuildMaterial("G4_Al");

    // 真空
    density = universe_mean_density;
    pressure = 3.e-18 * pascal;
    temperature = 2.73 * kelvin;
    new G4Material("Vacuum", z = 1., a = 1.01 * g / mole, density, kStateGas, temperature, pressure);

    // 5系铝合金 0.4 Si + 0.35 Fe + 0.1 Cu + 0.7 Mn + 4.5 Mg + 0.15 Cr + 0.25 Zn + 0.15 Ti + 93.4 Al
    density = 2.68 * g / cm3;
    G4Material* AlAlloyS5 = new G4Material("AluminumAlloySeries5", density, ncomponents = 9);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Si"), fractionmass = .4 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Fe"), fractionmass = .35 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Cu"), fractionmass = .1 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Mn"), fractionmass = .7 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Mg"), fractionmass = 4.5 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Cr"), fractionmass = .15 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Zn"), fractionmass = .25 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Ti"), fractionmass = .15 * perCent);
    AlAlloyS5->AddElement(nist->FindOrBuildElement("Al"), fractionmass = 93.4 * perCent);

    // 泰普龙 Taparan
    density = 1.44 * g / cm3;
    G4Material* Taparan = new G4Material("Taparan", density, ncomponents = 4);
    Taparan->AddElement(nist->FindOrBuildElement("C"), natoms = 14);
    Taparan->AddElement(nist->FindOrBuildElement("H"), natoms = 10);
    Taparan->AddElement(nist->FindOrBuildElement("N"), natoms = 2);
    Taparan->AddElement(nist->FindOrBuildElement("O"), natoms = 2);

    // // 填充材质
    density = 0.23 * g / cm3;
    G4Material* midMaterial = new G4Material("midMaterial", density, ncomponents = 11);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Al"), .3);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Fe"), .25);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("C"), .1);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("O"), .1);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("H"), .02);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("N"), .03);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Mg"), .1);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Mn"), .04);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Zn"), .03);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Cr"), .015);
    midMaterial->AddElementByMassFraction(nist->FindOrBuildElement("Ti"), .015);

    std::cout << *(G4Material::GetMaterialTable()) << std::endl;
}
