60G4DNAMoleculeEncounterStepper::Utils::Utils(
const G4Track& tA,
63 , fpMoleculeB(pMoleculeB)
66 fDA = fpMoleculeA->GetDiffusionCoefficient();
67 fDB = fpMoleculeB->GetDiffusionCoefficient();
68 fConstant = 8 * (fDA + fDB + 2 * sqrt(fDA * fDB));
85#if defined (DEBUG_MEM)
86 MemStat mem_first, mem_second, mem_diff;
89#if defined (DEBUG_MEM)
90 mem_first = MemoryUsage();
94#if defined (DEBUG_MEM)
95 mem_second = MemoryUsage();
96 mem_diff = mem_second - mem_first;
97 G4cout <<
"\t || MEM || G4DNAMoleculeEncounterStepper::Prepare || "
98 "After computing G4ITManager<G4Molecule>::Instance()->"
99 "UpdatePositionMap, diff is : " << mem_diff <<
G4endl;
103void G4DNAMoleculeEncounterStepper::InitializeForNewTrack()
110 fHasAlreadyReachedNullTime =
false;
116 return std::numeric_limits<T>::has_infinity
117 && value == std::numeric_limits<T>::infinity();
125 InitializeForNewTrack();
132 <<
"_______________________________________________________________________"
134 G4cout <<
"G4DNAMoleculeEncounterStepper::CalculateStep" <<
G4endl;
135 G4cout <<
"Check done for molecule : " << pMoleculeA->GetName()
143 auto pMolConfA = pMoleculeA->GetMolecularConfiguration();
145 const auto pReactantList = fMolecularReactionTable->
CanReactWith(pMolConfA);
147 if (pReactantList ==
nullptr)
155 G4cout <<
"G4MoleculeEncounterStepper::CalculateStep will return infinity "
156 "for the reaction because the molecule "
157 << pMoleculeA->GetName()
158 <<
" does not have any reactants given in the reaction table."
166 auto nbReactives = (
G4int)pReactantList->size();
168 if (nbReactives == 0)
177 G4cout <<
"G4MoleculeEncounterStepper::CalculateStep will return infinity "
178 "for the reaction because the molecule "
179 << pMoleculeA->GetName()
180 <<
" does not have any reactants given in the reaction table."
181 <<
"This message can also result from a wrong implementation of the reaction table."
189 fReactants = std::make_shared<vector<G4Track*>>();
190 fReactionModel->
Initialise(pMolConfA, trackA);
194 for (
G4int i = 0; i < nbReactives; i++)
196 auto pMoleculeB = (*pReactantList)[i];
208 if (
static_cast<int>(resultsNearest) == 0)
continue;
210 G4double r2 = resultsNearest->GetDistanceSqr();
211 Utils utils(trackA, pMoleculeB);
220 if (!fHasAlreadyReachedNullTime)
223 fHasAlreadyReachedNullTime =
true;
231 CheckAndRecordResults(utils,
240 G4double tempMinET = pow(r - R, 2) / utils.fConstant;
259 FindNearestInRange(pMoleculeA,
263 CheckAndRecordResults(utils,
278 CheckAndRecordResults(utils,
291 G4cout <<
"G4MoleculeEncounterStepper::CalculateStep will finally return :"
296 G4cout <<
"Selected reactants for trackA: " << pMoleculeA->GetName()
299 vector<G4Track*>::iterator it;
313void G4DNAMoleculeEncounterStepper::CheckAndRecordResults(
const Utils& utils,
319 if (
static_cast<int>(results) == 0)
324 G4cout <<
"No molecule " << utils.fpMoleculeB->GetName()
325 <<
" found to react with " << utils.fpMoleculeA->GetName()
332 for (results->Rewind(); !results->End(); results->Next())
334 auto reactiveB = results->GetItem<
G4IT>();
336 if (reactiveB ==
nullptr)
341 G4Track *trackB = reactiveB->GetTrack();
343 if (trackB ==
nullptr)
347 <<
"The reactant B found using the MoleculeFinder does not have a valid "
348 "track attached to it. If this is done on purpose, please do "
349 "not record this molecule in the MoleculeFinder."
351 G4Exception(
"G4DNAMoleculeEncounterStepper::RetrieveResults",
353 exceptionDescription);
362 if (trackB == &utils.fpTrackA)
366 <<
"A track is reacting with itself (which is impossible) ie fpTrackA == trackB"
368 exceptionDescription <<
"Molecule A (and B) is of type : "
369 << utils.fpMoleculeA->GetName() <<
" with trackID : "
370 << utils.fpTrackA.GetTrackID() <<
G4endl;
372 G4Exception(
"G4DNAMoleculeEncounterStepper::RetrieveResults",
374 exceptionDescription);
378 if (fabs(trackB->
GetGlobalTime() - utils.fpTrackA.GetGlobalTime())
379 > utils.fpTrackA.GetGlobalTime() * (1 - 1 / 100))
384 <<
"The interacting tracks are not synchronized in time" <<
G4endl;
386 <<
"trackB->GetGlobalTime() != fpTrackA.GetGlobalTime()" <<
G4endl;
388 exceptionDescription <<
"fpTrackA : trackID : " << utils.fpTrackA.GetTrackID()
389 <<
"\t Name :" << utils.fpMoleculeA->GetName()
390 <<
"\t fpTrackA->GetGlobalTime() = "
393 exceptionDescription <<
"trackB : trackID : " << trackB->
GetTrackID()
394 <<
"\t Name :" << utils.fpMoleculeB->GetName()
395 <<
"\t trackB->GetGlobalTime() = "
398 G4Exception(
"G4DNAMoleculeEncounterStepper::RetrieveResults",
400 exceptionDescription);
407 G4double r2 = results->GetDistanceSqr();
408 G4cout <<
"\t ************************************************** " <<
G4endl;
409 G4cout <<
"\t Reaction between "
410 << utils.fpMoleculeA->GetName() <<
" (" << utils.fpTrackA.GetTrackID() <<
") "
411 <<
" & " << utils.fpMoleculeB->GetName() <<
" (" << trackB->
GetTrackID() <<
"), "
412 <<
"Interaction Range = "
414 G4cout <<
"\t Real distance between reactants = "
416 G4cout <<
"\t Distance between reactants calculated by nearest neighbor algorithm = "
428 fReactionModel = pReactionModel;
433 return fReactionModel;
445 for (
auto pTrack : *fpTrackContainer->
GetMainList())
447 if (pTrack ==
nullptr)
450 exceptionDescription <<
"No track found.";
451 G4Exception(
"G4Scheduler::CalculateMinStep",
"ITScheduler006",
465 if (sampledMinTimeStep < fTSTimeStep)
467 fTSTimeStep = sampledMinTimeStep;
477 else if (fTSTimeStep == sampledMinTimeStep &&
bool(reactants))
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
G4Molecule * GetMolecule(const G4Track &track)
ReturnType & reference_cast(OriginalType &source)
G4GLOB_DLL std::ostream G4cout
const ReactantList * CanReactWith(Reactant *) const
G4VDNAReactionModel * GetReactionModel()
G4DNAMoleculeEncounterStepper()
void SetReactionModel(G4VDNAReactionModel *)
G4double CalculateStep(const G4Track &, const G4double &) override
~G4DNAMoleculeEncounterStepper() override
G4double CalculateMinTimeStep(G4double, G4double) override
void UpdatePositionMap() override
static G4ITFinder * Instance()
static G4ITReactionSet * Instance()
void AddReactions(G4double time, G4Track *trackA, G4TrackVectorHandle reactants)
G4TrackList * GetMainList(Key)
static G4ITTrackHolder * Instance()
G4int GetMoleculeID() const
const G4String & GetName() const override
G4TrackStatus GetTrackStatus() const
const G4ThreeVector & GetPosition() const
G4double GetGlobalTime() const
virtual void Initialise(const G4MolecularConfiguration *, const G4Track &)
virtual G4double GetReactionRadius(const G4MolecularConfiguration *, const G4MolecularConfiguration *)=0
G4TrackVectorHandle fReactants
G4TrackVectorHandle GetReactants()
virtual void ResetReactants()
static G4ThreadLocal G4double fUserMinTimeStep
G4double fSampledMinTimeStep