Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-19 07:40:46

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file ChemistryWorld.cc
0027 /// \brief Implementation of the ChemistryWorld class
0028 
0029 #include "ChemistryWorld.hh"
0030 
0031 #include "G4DNABoundingBox.hh"
0032 #include "G4DNAMolecularReactionTable.hh"
0033 #include "G4MoleculeTable.hh"
0034 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0056 
0057 void ChemistryWorld::ConstructChemistryBoundary()
0058 {
0059   fHalfBox = 1.6 * um;  // halfBox
0060   std::initializer_list<G4double> l{fHalfBox, -fHalfBox, fHalfBox, -fHalfBox, fHalfBox, -fHalfBox};
0061   fpChemistryBoundary = std::make_unique<G4DNABoundingBox>(l);
0062 }
0063 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 == "%")  // only for O2 and CO2
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // Water is defined from NIST material database
0125   // water 55.3 M, 9.9x10-8 M, and 9.9x10-8 M
0126   // water density =  18.01528 g/mol * 55.3 M = 996.24498 g/l
0127   // H3OpB density = 1 g/mol * 9.9x10-8 M
0128   // OHmB density = 17.01528 g/mol * 9.9x10-8 M
0129   // O2B density = 15.999 g/mol * 2.58e-4 M
0130   /////////////////////////////////////////////////////////////////
0131   G4double pKw = 14;  // at 25°C pK of water is 14
0132   G4double waterMolarity = 55.3 / (mole * liter);  // 55.3 M
0133   fpChemicalComponent[H2O] = waterMolarity;
0134 
0135   G4double H3OpBMolarity = std::pow(10, -fpH) / (mole * liter);  // pH = 7
0136   fpChemicalComponent[H3Op] = H3OpBMolarity;
0137 
0138   G4double OHmBMolarity = std::pow(10, -(pKw - fpH)) / (mole * liter);  // pH = 7
0139   fpChemicalComponent[OHm] = OHmBMolarity;
0140   // oxygen
0141   G4double O2Molarity = (0. / 100) * 0.0013 / (mole * liter);
0142   fpChemicalComponent[O2] = O2Molarity;
0143 
0144   // CO2 At 25°C,  kH  is approximately  3.3×10  −2   mol/(L·atm).
0145   G4double CO2Molarity = (0. / 100) * 0.034 / (mole * liter);
0146   fpChemicalComponent[CO2] = CO2Molarity;
0147 }
0148 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......