File indexing completed on 2026-05-19 07:40:46
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "ChemistryWorld.hh"
0030
0031 #include "G4DNABoundingBox.hh"
0032 #include "G4DNAMolecularReactionTable.hh"
0033 #include "G4MoleculeTable.hh"
0034
0035
0036 ChemistryWorld::ChemistryWorld() : G4VChemistryWorld(), G4UImessenger()
0037 {
0038 fpChemWoldDir = std::make_unique<G4UIdirectory>("/UHDR/env/", false);
0039 fpChemWoldDir->SetGuidance("chemistry environment commands");
0040
0041 fpAddpH = std::make_unique<G4UIcmdWithADouble>("/UHDR/env/pH", this);
0042 fpAddpH->SetGuidance("Add pH for water.");
0043 fpAddpH->SetParameterName("pH", false);
0044 fpAddpH->SetToBeBroadcasted(false);
0045
0046 fpAddScavengerName = std::make_unique<G4UIcmdWithAString>("/UHDR/env/scavenger", this);
0047 fpAddScavengerName->SetToBeBroadcasted(false);
0048
0049 fpTargetVolume = std::make_unique<G4UIcmdWithADoubleAndUnit>("/UHDR/env/volume", this);
0050 fpTargetVolume->SetGuidance("Volume of water.");
0051 fpTargetVolume->SetParameterName("Volume", false);
0052 fpTargetVolume->AvailableForStates(G4State_PreInit);
0053 fpTargetVolume->SetToBeBroadcasted(false);
0054 }
0055
0056
0057 void ChemistryWorld::ConstructChemistryBoundary()
0058 {
0059 fHalfBox = 1.6 * um;
0060 std::initializer_list<G4double> l{fHalfBox, -fHalfBox, fHalfBox, -fHalfBox, fHalfBox, -fHalfBox};
0061 fpChemistryBoundary = std::make_unique<G4DNABoundingBox>(l);
0062 }
0063
0064
0065 void ChemistryWorld::SetNewValue(G4UIcommand* command, G4String newValue)
0066 {
0067 if (command == fpAddpH.get()) {
0068 fpH = fpAddpH->GetNewDoubleValue(newValue);
0069 ConstructChemistryComponents();
0070 }
0071 else if (command == fpAddScavengerName.get()) {
0072 std::istringstream iss(newValue);
0073 G4String species;
0074 iss >> species;
0075 auto scavengerConf = G4MoleculeTable::Instance()->GetConfiguration(species);
0076 G4double concentraion;
0077 iss >> concentraion;
0078 G4String unit;
0079 iss >> unit;
0080 if (unit == "M") {
0081 G4double ConcentrationInM = concentraion / (mole * liter);
0082 fpChemicalComponent[scavengerConf] = ConcentrationInM;
0083 }
0084 else if (unit == "mM") {
0085 G4double ConcentrationInM = concentraion / (mole * liter * 1e3);
0086 fpChemicalComponent[scavengerConf] = ConcentrationInM;
0087 }
0088 else if (unit == "uM") {
0089 G4double ConcentrationInM = concentraion / (mole * liter * 1e6);
0090 fpChemicalComponent[scavengerConf] = ConcentrationInM;
0091 }
0092 else if (unit == "%")
0093 {
0094 G4double kH = 0.;
0095 if (species == "O2")
0096 kH = 0.0013;
0097 else if (species == "CO2")
0098 kH = 0.034;
0099 G4double ConcentrationInM = (concentraion / 100) * kH / (mole * liter);
0100 fpChemicalComponent[scavengerConf] = ConcentrationInM;
0101 }
0102 else {
0103 throw std::runtime_error("Unit should be in Molarity");
0104 }
0105 }
0106 else if (command == fpTargetVolume.get()) {
0107 fHalfBox = G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(newValue);
0108 std::initializer_list<G4double> l{fHalfBox, -fHalfBox, fHalfBox,
0109 -fHalfBox, fHalfBox, -fHalfBox};
0110 fpChemistryBoundary = std::make_unique<G4DNABoundingBox>(l);
0111 }
0112 }
0113
0114
0115 void ChemistryWorld::ConstructChemistryComponents()
0116 {
0117 auto O2 = G4MoleculeTable::Instance()->GetConfiguration("O2");
0118 auto CO2 = G4MoleculeTable::Instance()->GetConfiguration("CO2");
0119 auto H2O = G4MoleculeTable::Instance()->GetConfiguration("H2O");
0120 auto H3Op = G4MoleculeTable::Instance()->GetConfiguration("H3Op(B)");
0121 auto OHm = G4MoleculeTable::Instance()->GetConfiguration("OHm(B)");
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131 G4double pKw = 14;
0132 G4double waterMolarity = 55.3 / (mole * liter);
0133 fpChemicalComponent[H2O] = waterMolarity;
0134
0135 G4double H3OpBMolarity = std::pow(10, -fpH) / (mole * liter);
0136 fpChemicalComponent[H3Op] = H3OpBMolarity;
0137
0138 G4double OHmBMolarity = std::pow(10, -(pKw - fpH)) / (mole * liter);
0139 fpChemicalComponent[OHm] = OHmBMolarity;
0140
0141 G4double O2Molarity = (0. / 100) * 0.0013 / (mole * liter);
0142 fpChemicalComponent[O2] = O2Molarity;
0143
0144
0145 G4double CO2Molarity = (0. / 100) * 0.034 / (mole * liter);
0146 fpChemicalComponent[CO2] = CO2Molarity;
0147 }
0148