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",
420 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",
493 G4cout <<
"G4DNAChemistryManager::InitializeThread() is called"
499 fpThreadData->fThreadInitialized =
true;
512 G4cout <<
"G4DNAChemistryManager::InitializeFile() is called"
516 if (fpThreadData->fpPhysChemIO)
518 fpThreadData->fpPhysChemIO->InitializeFile();
533 return fActiveChemistry;
540 fActiveChemistry = flag;
546 std::ios_base::openmode mode)
550 G4cout <<
"G4DNAChemistryManager: Write chemical stage into "
551 << output.data() <<
G4endl;
554 if (!fpThreadData->fpPhysChemIO)
559 fpThreadData->fpPhysChemIO->WriteInto(output, mode);
567 if (fpThreadData->fpPhysChemIO)
569 fpThreadData->fpPhysChemIO->AddEmptyLineInOutputFile();
577 if (fpThreadData->fpPhysChemIO)
579 fpThreadData->fpPhysChemIO->CloseFile();
587 if (!fpExcitationLevel)
591 return fpExcitationLevel.get();
598 if (!fpIonisationLevel)
602 return fpIonisationLevel.get();
608 G4int electronicLevel,
611 if (fpThreadData->fpPhysChemIO)
615 switch (modification)
628 fpThreadData->fpPhysChemIO->CreateWaterMolecule(modification,
634 if (fActiveChemistry)
638 switch (modification)
666 if (fpThreadData->fpPhysChemIO)
668 fpThreadData->fpPhysChemIO->CreateSolvatedElectron(pIncomingTrack,
672 if (fActiveChemistry)
676 pFinalPosition ? *pFinalPosition : pIncomingTrack->
GetPosition(),
688 assert(fActiveChemistry
689 &&
"To inject chemical species, the chemistry must be activated. "
690 "Check chemistry activation before injecting species.");
710 fpUserChemistryList.reset(pChemistryList);
711 fOwnChemistryList =
false;
717 fpUserChemistryList.reset(&chemistryList);
718 fOwnChemistryList =
false;
724 fpUserChemistryList = std::move(pChemistryList);
725 fOwnChemistryList =
true;
733 if (fpUserChemistryList.get() == &chemistryList)
735 if (!fpUserChemistryList->IsPhysicsConstructor() || fOwnChemistryList)
737 fpUserChemistryList.reset();
740 fpUserChemistryList.release();
762 return fResetCounterWhenRunEnds;
769 fResetCounterWhenRunEnds = resetCounterWhenRunEnds;
776 fPhysicsTableBuilt =
false;
783 fMasterInitialized =
false;
791 fForceThreadReinitialization =
true;
798 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()
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()