69 G4DNAChemistryManager::fpThreadData =
nullptr;
75G4DNAChemistryManager::ThreadLocalData::ThreadLocalData()
77 fpPhysChemIO =
nullptr;
78 fThreadInitialized =
false;
83G4DNAChemistryManager::ThreadLocalData::~ThreadLocalData()
85 fpThreadData =
nullptr;
92 fpThreadData->fpPhysChemIO = std::move(pPhysChemIO);
112 fpExcitationLevel(nullptr)
113 , fpIonisationLevel(nullptr)
114 , fpUserChemistryList(nullptr)
116 fpRunChem->SetParameterName(
"Number of runs to execute for the chemistry module"
117 "(this works when used in standalone",
true,
true);
118 fpRunChem->SetDefaultValue(1);
119 fpScaleForNewTemperature->SetUnitCategory(
"Temperature");
126 if (fgInstance ==
nullptr)
129 if (fgInstance ==
nullptr)
137 if (fpThreadData ==
nullptr)
139 fpThreadData =
new ThreadLocalData();
142 assert(fpThreadData !=
nullptr);
159 fgInstance =
nullptr;
166 fpIonisationLevel.reset();
167 fpExcitationLevel.reset();
169 if (fpUserChemistryList)
174 fpChemDNADirectory.reset();
175 fpActivateChem.reset();
178 fpSkipReactionsFromChemList.reset();
181 if (fpThreadData !=
nullptr)
184 fpThreadData =
nullptr;
198 if (fgInstance !=
nullptr)
201 fgInstance =
nullptr;
207 G4cerr <<
"G4DNAChemistryManager already deleted" <<
G4endl;
220 G4cout <<
"G4DNAChemistryManager::Notify ---> received G4State_Quit"
227 fGeometryClosed =
true;
241 if (pCommand == fpActivateChem.get())
245 else if (pCommand == fpRunChem.get())
248 for (
int i = 0 ; i < nbExec ; ++i)
253 else if (pCommand == fpSkipReactionsFromChemList.get())
255 fSkipReactions =
true;
257 else if (pCommand == fpScaleForNewTemperature.get())
261 else if (pCommand == fpInitChem.get())
272 if (pCommand == fpActivateChem.get())
276 if (pCommand == fpScaleForNewTemperature.get())
280 if (pCommand == fpSkipReactionsFromChemList.get())
304 if (!fActiveChemistry)
311 if (!fMasterInitialized)
314 description <<
"Global components were not initialized.";
319 if (!fpThreadData->fThreadInitialized)
322 description <<
"Thread local components were not initialized.";
329 if (fResetCounterWhenRunEnds)
340 fUseInStandalone = flag;
389 if (fMasterInitialized)
396 G4cout <<
"G4DNAChemistryManager::InitializeMaster() is called" <<
G4endl;
400 if (fpUserChemistryList ==
nullptr)
403 description <<
"No user chemistry list has been provided.";
404 G4Exception(
"G4DNAChemistryManager::InitializeMaster",
"NO_CHEM_LIST",
408 fpUserChemistryList->ConstructDissociationChannels();
421 fMasterInitialized =
true;
428 if (!fUseInStandalone || fPhysicsTableBuilt)
435 G4cout <<
"G4DNAChemistryManager: Build the physics tables for "
436 "molecule definition only."
440 fpUserChemistryList->BuildPhysicsTable();
442 if (!fGeometryClosed)
446 G4cout <<
"G4DNAChemistryManager: Close geometry" <<
G4endl;
452 fGeometryClosed =
true;
455 fPhysicsTableBuilt =
true;
462 if (fpThreadData->fThreadInitialized && !fForceThreadReinitialization)
467 if (fpUserChemistryList ==
nullptr)
470 description <<
"No user chemistry list has been provided.";
471 G4Exception(
"G4DNAChemistryManager::InitializeThread",
"NO_CHEM_LIST",
481 G4cout <<
"G4DNAChemistryManager::InitializeThread() is called"
487 fpThreadData->fThreadInitialized =
true;
500 G4cout <<
"G4DNAChemistryManager::InitializeFile() is called"
504 if (fpThreadData->fpPhysChemIO)
506 fpThreadData->fpPhysChemIO->InitializeFile();
521 return fActiveChemistry;
528 fActiveChemistry = flag;
534 std::ios_base::openmode mode)
538 G4cout <<
"G4DNAChemistryManager: Write chemical stage into "
539 << output.data() <<
G4endl;
542 if (!fpThreadData->fpPhysChemIO)
544 fpThreadData->fpPhysChemIO = std::make_unique<G4PhysChemIO::FormattedText>();
547 fpThreadData->fpPhysChemIO->WriteInto(output, mode);
555 if (fpThreadData->fpPhysChemIO)
557 fpThreadData->fpPhysChemIO->AddEmptyLineInOutputFile();
565 if (fpThreadData->fpPhysChemIO)
567 fpThreadData->fpPhysChemIO->CloseFile();
575 if (!fpExcitationLevel)
577 fpExcitationLevel = std::make_unique<G4DNAWaterExcitationStructure>();
579 return fpExcitationLevel.get();
586 if (!fpIonisationLevel)
588 fpIonisationLevel = std::make_unique<G4DNAWaterIonisationStructure>();
590 return fpIonisationLevel.get();
596 G4int electronicLevel,
599 if (fpThreadData->fpPhysChemIO)
603 switch (modification)
616 fpThreadData->fpPhysChemIO->CreateWaterMolecule(modification,
622 if (fActiveChemistry)
626 switch (modification)
629 pH2OMolecule->AddElectron(5, 1);
632 pH2OMolecule->ExciteMolecule(4 - electronicLevel);
635 pH2OMolecule->IonizeMolecule(4 - electronicLevel);
644 if(pPulseInfo !=
nullptr)
646 delayedTime = pPulseInfo->GetDelayedTime();
650 G4Track* pH2OTrack = pH2OMolecule->BuildTrack(picosecond + delayedTime,
665 if (fpThreadData->fpPhysChemIO)
667 fpThreadData->fpPhysChemIO->CreateSolvatedElectron(pIncomingTrack,
671 if (fActiveChemistry)
678 if(pPulseInfo !=
nullptr)
680 delayedTime = pPulseInfo->GetDelayedTime();
685 picosecond + delayedTime,
686 pFinalPosition !=
nullptr ? *pFinalPosition : pIncomingTrack->
GetPosition(),
698 assert(fActiveChemistry
699 &&
"To inject chemical species, the chemistry must be activated. "
700 "Check chemistry activation before injecting species.");
720 fpUserChemistryList.reset(pChemistryList);
721 fOwnChemistryList =
false;
727 fpUserChemistryList.reset(&chemistryList);
728 fOwnChemistryList =
false;
734 fpUserChemistryList = std::move(pChemistryList);
735 fOwnChemistryList =
true;
743 if (fpUserChemistryList.get() == &chemistryList)
745 if (!fpUserChemistryList->IsPhysicsConstructor() || fOwnChemistryList)
747 fpUserChemistryList.reset();
750 fpUserChemistryList.release();
772 return fResetCounterWhenRunEnds;
779 fResetCounterWhenRunEnds = resetCounterWhenRunEnds;
786 fPhysicsTableBuilt =
false;
793 fMasterInitialized =
false;
801 fForceThreadReinitialization =
true;
808 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()
void Push(G4Track *) override
static G4ITTrackHolder * Instance()
static void DeleteManager()
static void SetGlobalTemperature(G4double)
static G4double GetGlobalTemperature()
void Finalize(G4MoleculeDefinition *)
void PrepareMolecularConfiguration()
static G4MoleculeTable * Instance()
void SetGun(G4ITGun *) override
static G4Scheduler * Instance()
void Initialize() override
void SetTrackStatus(const G4TrackStatus aTrackStatus)
const G4ThreeVector & GetPosition() const
G4VUserTrackInformation * GetUserInformation() 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()