67 G4DNAChemistryManager::fpThreadData =
nullptr;
73G4DNAChemistryManager::ThreadLocalData::ThreadLocalData()
75 fpPhysChemIO =
nullptr;
76 fThreadInitialized =
false;
81G4DNAChemistryManager::ThreadLocalData::~ThreadLocalData()
83 fpThreadData =
nullptr;
90 fpThreadData->fpPhysChemIO = std::move(pPhysChemIO);
110 , fActiveChemistry(false)
111 , fMasterInitialized(false)
112 , fForceThreadReinitialization(false)
113 , fpExcitationLevel(nullptr)
114 , fpIonisationLevel(nullptr)
115 , fpUserChemistryList(nullptr)
116 , fOwnChemistryList(false)
117 , fUseInStandalone(false)
118 , fPhysicsTableBuilt(false)
119 , fSkipReactions(false)
120 , fGeometryClosed(false)
122 , fResetCounterWhenRunEnds(true)
124 fpRunChem->SetParameterName(
"Number of runs to execute for the chemistry module"
125 "(this works when used in standalone",
true,
true);
126 fpRunChem->SetDefaultValue(1);
127 fpScaleForNewTemperature->SetUnitCategory(
"Temperature");
134 if (fgInstance ==
nullptr)
137 if (fgInstance ==
nullptr)
145 if (fpThreadData ==
nullptr)
147 fpThreadData =
new ThreadLocalData();
150 assert(fpThreadData !=
nullptr);
167 fgInstance =
nullptr;
174 fpIonisationLevel.reset();
175 fpExcitationLevel.reset();
177 if (fpUserChemistryList)
182 fpChemDNADirectory.reset();
183 fpActivateChem.reset();
186 fpSkipReactionsFromChemList.reset();
189 if (fpThreadData !=
nullptr)
192 fpThreadData =
nullptr;
206 if (fgInstance !=
nullptr)
209 fgInstance =
nullptr;
215 G4cerr <<
"G4DNAChemistryManager already deleted" <<
G4endl;
228 G4cout <<
"G4DNAChemistryManager::Notify ---> received G4State_Quit"
235 fGeometryClosed =
true;
249 if (pCommand == fpActivateChem.get())
253 else if (pCommand == fpRunChem.get())
256 for (
int i = 0 ; i < nbExec ; ++i)
261 else if (pCommand == fpSkipReactionsFromChemList.get())
263 fSkipReactions =
true;
265 else if (pCommand == fpScaleForNewTemperature.get())
269 else if (pCommand == fpInitChem.get())
280 if (pCommand == fpActivateChem.get())
284 else if (pCommand == fpScaleForNewTemperature.get())
288 else if (pCommand == fpSkipReactionsFromChemList.get())
312 if (!fActiveChemistry)
319 if (!fMasterInitialized)
322 description <<
"Global components were not initialized.";
327 if (!fpThreadData->fThreadInitialized)
330 description <<
"Thread local components were not initialized.";
337 if (fResetCounterWhenRunEnds)
348 fUseInStandalone = flag;
401 if (fMasterInitialized)
408 G4cout <<
"G4DNAChemistryManager::InitializeMaster() is called" <<
G4endl;
412 if (fpUserChemistryList ==
nullptr)
415 description <<
"No user chemistry list has been provided.";
416 G4Exception(
"G4DNAChemistryManager::InitializeMaster",
"NO_CHEM_LIST",
424 fpUserChemistryList->ConstructDissociationChannels();
433 fMasterInitialized =
true;
440 if (!fUseInStandalone || fPhysicsTableBuilt)
447 G4cout <<
"G4DNAChemistryManager: Build the physics tables for "
448 "molecule definition only."
452 fpUserChemistryList->BuildPhysicsTable();
454 if (!fGeometryClosed)
458 G4cout <<
"G4DNAChemistryManager: Close geometry" <<
G4endl;
464 fGeometryClosed =
true;
467 fPhysicsTableBuilt =
true;
474 if (fpThreadData->fThreadInitialized && !fForceThreadReinitialization)
479 if (fpUserChemistryList ==
nullptr)
482 description <<
"No user chemistry list has been provided.";
483 G4Exception(
"G4DNAChemistryManager::InitializeThread",
"NO_CHEM_LIST",
489 G4cout <<
"G4DNAChemistryManager::InitializeThread() is called"
498 fpThreadData->fThreadInitialized =
true;
511 G4cout <<
"G4DNAChemistryManager::InitializeFile() is called"
515 if (fpThreadData->fpPhysChemIO)
517 fpThreadData->fpPhysChemIO->InitializeFile();
532 return fActiveChemistry;
539 fActiveChemistry = flag;
545 std::ios_base::openmode mode)
549 G4cout <<
"G4DNAChemistryManager: Write chemical stage into "
553 if (!fpThreadData->fpPhysChemIO)
558 fpThreadData->fpPhysChemIO->WriteInto(output, mode);
566 if (fpThreadData->fpPhysChemIO)
568 fpThreadData->fpPhysChemIO->AddEmptyLineInOutputFile();
576 if (fpThreadData->fpPhysChemIO)
578 fpThreadData->fpPhysChemIO->CloseFile();
586 if (!fpExcitationLevel)
590 return fpExcitationLevel.get();
597 if (!fpIonisationLevel)
601 return fpIonisationLevel.get();
607 G4int electronicLevel,
610 if (fpThreadData->fpPhysChemIO)
614 switch (modification)
627 fpThreadData->fpPhysChemIO->CreateWaterMolecule(modification,
633 if (fActiveChemistry)
637 switch (modification)
665 if (fpThreadData->fpPhysChemIO)
667 fpThreadData->fpPhysChemIO->CreateSolvatedElectron(pIncomingTrack,
671 if (fActiveChemistry)
675 pFinalPosition ? *pFinalPosition : pIncomingTrack->
GetPosition(),
687 assert(fActiveChemistry
688 &&
"To inject chemical species, the chemistry must be activated. "
689 "Check chemistry activation before injecting species.");
709 fpUserChemistryList.reset(pChemistryList);
710 fOwnChemistryList =
false;
716 fpUserChemistryList.reset(&chemistryList);
717 fOwnChemistryList =
false;
723 fpUserChemistryList = std::move(pChemistryList);
724 fOwnChemistryList =
true;
732 if (fpUserChemistryList.get() == &chemistryList)
734 if (!fpUserChemistryList->IsPhysicsConstructor() || fOwnChemistryList)
736 fpUserChemistryList.reset();
739 fpUserChemistryList.release();
761 return fResetCounterWhenRunEnds;
768 fResetCounterWhenRunEnds = resetCounterWhenRunEnds;
775 fPhysicsTableBuilt =
false;
782 fMasterInitialized =
false;
790 fForceThreadReinitialization =
true;
797 fpThreadData->fThreadInitialized =
false;
@ eDissociativeAttachment
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
void SetPhysChemIO(std::unique_ptr< G4VPhysChemIO > pPhysChemIO)
G4String GetCurrentValue(G4UIcommand *pCommand) override
G4bool IsCounterResetWhenRunEnds() const
void CreateSolvatedElectron(const G4Track *, G4ThreeVector *pFinalPosition=nullptr)
void InitializeThreadSharedData()
~G4DNAChemistryManager() override
G4bool IsChemistryActivated()
static G4DNAChemistryManager * GetInstanceIfExists()
void HandleStandaloneInitialization()
static G4DNAChemistryManager * Instance()
void UseAsStandalone(G4bool flag)
void PushTrack(G4Track *)
void SetChemistryList(G4VUserChemistryList &)
void ForceThreadReinitialization()
void AddEmptyLineInOutputFile()
void PushMolecule(std::unique_ptr< G4Molecule > pMolecule, G4double time, const G4ThreeVector &position, G4int parentID)
void ForceRebuildingPhysicsTable()
static G4bool IsActivated()
void ResetCounterWhenRunEnds(G4bool resetCounterWhenRunEnds)
void SetGlobalTemperature(G4double temperatureKelvin)
void SetGun(G4ITGun *pChemSpeciesGun)
Inject custom species to the simulation.
G4DNAWaterIonisationStructure * GetIonisationLevel()
void Deregister(G4VUserChemistryList &)
G4DNAWaterExcitationStructure * GetExcitationLevel()
void SetNewValue(G4UIcommand *, G4String) override
G4bool Notify(G4ApplicationState requestedState) override
void ForceMasterReinitialization()
void SetChemistryActivation(G4bool)
static void DeleteInstance()
void SetVerbose(G4int verbose)
void TagThreadForReinitialization()
void WriteInto(const G4String &, std::ios_base::openmode mode=std::ios_base::out)
void CreateWaterMolecule(ElectronicModification, G4int, const G4Track *)
static G4DNAMolecularReactionTable * GetReactionTable()
static G4DNAMolecularReactionTable * Instance()
static void DeleteInstance()
void ScaleReactionRateForNewTemperature(double temp_K)
G4double ExcitationEnergy(G4int level)
G4double IonisationEnergy(G4int level)
static G4Electron_aq * Definition()
static G4GeometryManager * GetInstance()
G4bool CloseGeometry(G4bool pOptimise=true, G4bool verbose=false, G4VPhysicalVolume *vol=nullptr)
void OpenGeometry(G4VPhysicalVolume *vol=nullptr)
static G4H2O * Definition()
virtual void Push(G4Track *)
static G4ITTrackHolder * Instance()
static void DeleteManager()
static void SetGlobalTemperature(G4double)
static G4double GetGlobalTemperature()
void Finalize(G4MoleculeDefinition *)
void PrepareMolecularConfiguration()
static G4MoleculeTable * Instance()
void IonizeMolecule(G4int)
void AddElectron(G4int orbit, G4int n=1)
G4Track * BuildTrack(G4double globalTime, const G4ThreeVector &Position)
void ExciteMolecule(G4int)
static G4Scheduler * Instance()
const char * data() const
void SetTrackStatus(const G4TrackStatus aTrackStatus)
const G4ThreeVector & GetPosition() const
void SetKineticEnergy(const G4double aValue)
void SetParentID(const G4int aValue)
static G4bool GetNewBoolValue(const char *paramString)
static G4String ConvertToString(G4bool boolVal)
static G4int ConvertToInt(const char *st)
static void InitializeInstance()
static void DeleteInstance()
static G4VMoleculeCounter * Instance()
virtual void ResetCounter()=0
G4bool IsMultithreadedApplication()