Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /* 27 * G4MoleculeTable.cc 28 * 29 * Created on: 23 oct. 2013 30 * Author: kara 31 */ 32 33 #include "G4MoleculeTable.hh" 34 #include "G4MolecularConfiguration.hh" 35 #include "G4MoleculeDefinition.hh" 36 #include "G4MoleculeTableMessenger.hh" 37 38 G4MoleculeTable* G4MoleculeTable::fpgMoleculeTable(nullptr); 39 40 //------------------------------------------------------------------------------ 41 42 G4MoleculeTable::G4MoleculeTable() 43 : fMoleculeDefTableMessenger(new G4MoleculeTableMessenger()) 44 { 45 } 46 47 //------------------------------------------------------------------------------ 48 49 G4MoleculeTable::~G4MoleculeTable() 50 = default; 51 52 //------------------------------------------------------------------------------ 53 54 G4MoleculeTable* G4MoleculeTable::Instance() 55 { 56 if (fpgMoleculeTable == nullptr) fpgMoleculeTable = new G4MoleculeTable; 57 return fpgMoleculeTable; 58 } 59 60 //------------------------------------------------------------------------------ 61 62 G4MoleculeTable* G4MoleculeTable::GetMoleculeTable() 63 { 64 return Instance(); 65 } 66 67 //------------------------------------------------------------------------------ 68 69 G4MoleculeDefinition* 70 G4MoleculeTable::CreateMoleculeDefinition(const G4String& name, 71 double diffusion_coefficient) 72 { 73 return new G4MoleculeDefinition(name, -1 /* mass*/, 74 diffusion_coefficient); 75 } 76 77 //------------------------------------------------------------------------------ 78 79 G4MoleculeDefinition* 80 G4MoleculeTable::GetMoleculeDefinition(const G4String& name, 81 bool mustExist) 82 { 83 auto it = fMoleculeDefTable.find(name); 84 G4MoleculeDefinition* definition(nullptr); 85 if (it != fMoleculeDefTable.end()) 86 { 87 definition = it->second; 88 } 89 else if(mustExist) 90 { 91 // exception 92 G4ExceptionDescription description; 93 description << "The molecule definition " << name 94 << " was NOT recorded in the table" << G4endl; 95 G4Exception("G4MoleculeTable::CreateMoleculeModel", 96 "MOLECULE_DEFINITION_NOT_CREATED", 97 FatalException, 98 description); 99 } 100 return definition; 101 } 102 103 //------------------------------------------------------------------------------ 104 105 G4MolecularConfiguration* 106 G4MoleculeTable::GetConfiguration(const G4String& name, bool mustExist) 107 { 108 G4MolecularConfiguration* species = 109 G4MolecularConfiguration::GetMolecularConfiguration(name); 110 111 if(species == nullptr && mustExist) 112 { 113 // exception 114 G4ExceptionDescription description; 115 description << "The configuration " << name 116 << " was not recorded in the table" << G4endl; 117 G4Exception("G4MoleculeTable::GetConfiguration", 118 "CONF_NOT_CREATED", 119 FatalException, 120 description); 121 } 122 123 return species; 124 } 125 126 //------------------------------------------------------------------------------ 127 128 G4MolecularConfiguration* 129 G4MoleculeTable::GetConfiguration(G4int id) 130 { 131 G4MolecularConfiguration* species = 132 G4MolecularConfiguration::GetMolecularConfiguration(id); 133 134 return species; 135 } 136 137 //------------------------------------------------------------------------------ 138 139 void G4MoleculeTable::Insert(G4MoleculeDefinition* moleculeDefinition) 140 { 141 142 const G4String& name = moleculeDefinition->GetName(); 143 auto it = fMoleculeDefTable.find(name); 144 if (it == fMoleculeDefTable.end()) 145 { 146 fMoleculeDefTable[name] = moleculeDefinition; 147 } 148 else 149 { 150 // exception 151 G4ExceptionDescription description; 152 description << "The molecule definition " << name 153 << " was already recorded in the table" << G4endl; 154 G4Exception("G4MoleculeTable::CreateMoleculeDefinition", 155 "DEFINITION_ALREADY_CREATED", FatalException, description); 156 } 157 } 158 159 //------------------------------------------------------------------------------ 160 161 void G4MoleculeTable::PrepareMolecularConfiguration() 162 { 163 auto it = fMoleculeDefTable.begin(); 164 165 for(; it != fMoleculeDefTable.end() ; ++it) 166 { 167 G4MolecularConfiguration::GetOrCreateMolecularConfiguration(it->second); 168 } 169 } 170 171 //------------------------------------------------------------------------------ 172 173 G4MolecularConfiguration* 174 G4MoleculeTable::CreateConfiguration(const G4String& userIdentifier, 175 G4MoleculeDefinition* molDef) 176 { 177 bool alreadyCreated(false); 178 179 G4MolecularConfiguration* molConf = 180 G4MolecularConfiguration::CreateMolecularConfiguration(userIdentifier, 181 molDef, 182 alreadyCreated); 183 184 return molConf; 185 } 186 187 //------------------------------------------------------------------------------ 188 189 G4MolecularConfiguration* 190 G4MoleculeTable::CreateConfiguration(const G4String& userIdentifier, 191 G4MoleculeDefinition* molDef, 192 const G4String& configurationLabel, 193 int charge) 194 { 195 bool alreadyCreated(false); 196 197 G4MolecularConfiguration* molConf = 198 G4MolecularConfiguration::CreateMolecularConfiguration(userIdentifier, 199 molDef, 200 charge, 201 configurationLabel, 202 alreadyCreated); 203 204 return molConf; 205 } 206 207 //------------------------------------------------------------------------------ 208 209 G4MolecularConfiguration* 210 G4MoleculeTable::CreateConfiguration(const G4String& userIdentifier, 211 G4MoleculeDefinition* molDef, 212 int charge, 213 double diffusion_coefficient) 214 { 215 bool alreadyCreated(false); 216 217 G4MolecularConfiguration* molConf = 218 G4MolecularConfiguration::CreateMolecularConfiguration(userIdentifier, 219 molDef, 220 charge, 221 userIdentifier, 222 alreadyCreated); 223 224 if(diffusion_coefficient!=-1) // TODO 225 { 226 molConf->SetDiffusionCoefficient(diffusion_coefficient); 227 } 228 return molConf; 229 } 230 231 //------------------------------------------------------------------------------ 232 233 G4MolecularConfiguration* 234 G4MoleculeTable::CreateConfiguration(const G4String& userIdentifier, 235 const G4MoleculeDefinition* molDef, 236 const G4String& configurationLabel, 237 const G4ElectronOccupancy& eOcc) 238 { 239 bool alreadyCreated(false); 240 241 G4MolecularConfiguration* molConf = 242 G4MolecularConfiguration::CreateMolecularConfiguration(userIdentifier, 243 molDef, 244 configurationLabel, 245 eOcc, 246 alreadyCreated); 247 248 return molConf; 249 } 250 251 //------------------------------------------------------------------------------ 252 253 void G4MoleculeTable::Finalize() 254 { 255 G4MolecularConfiguration::FinalizeAll(); 256 } 257 258 //------------------------------------------------------------------------------ 259 260 G4ConfigurationIterator G4MoleculeTable::GetConfigurationIterator() 261 { 262 return G4ConfigurationIterator(G4MolecularConfiguration::GetUserIDTable()); 263 } 264 265 //------------------------------------------------------------------------------ 266 267 int G4MoleculeTable::GetNumberOfDefinedSpecies() 268 { 269 return G4MolecularConfiguration::GetNumberOfSpecies(); 270 } 271