45G4DNAIndependentReactionTimeStepper::Utils::Utils(
const G4Track& trackA,
62 fSampledPositions.clear();
66void G4DNAIndependentReactionTimeStepper::InitializeForNewTrack()
73 fHasAlreadyReachedNullTime =
false;
80 InitializeForNewTrack();
87 G4cout <<
"________________________________________________________________"
90 G4cout <<
"G4DNAIndependentReactionTimeStepper::CalculateStep" <<
G4endl;
91 G4cout <<
"Check done for molecule : " << pMoleculeA->GetName() <<
" ("
96 auto pMolConfA = pMoleculeA->GetMolecularConfiguration();
98 const auto pReactantList = fMolecularReactionTable->
CanReactWith(pMolConfA);
100 if(pReactantList ==
nullptr)
107 G4cout <<
"G4DNAIndependentReactionTimeStepper::CalculateStep will "
109 "for the reaction because the molecule "
110 << pMoleculeA->GetName()
111 <<
" does not have any reactants given in the reaction table."
119 auto nbReactives = (
G4int)pReactantList->size();
129 G4cout <<
"G4DNAIndependentReactionTimeStepper::CalculateStep will "
131 "for the reaction because the molecule "
132 << pMoleculeA->GetName()
133 <<
" does not have any reactants given in the reaction table."
134 <<
"This message can also result from a wrong implementation of "
135 "the reaction table."
142 fReactants = std::make_shared<vector<G4Track*>>();
143 fReactionModel->
Initialise(pMolConfA, trackA);
144 for(
G4int i = 0; i < nbReactives; ++i)
146 auto pMoleculeB = (*pReactantList)[i];
147 G4int key = pMoleculeB->GetMoleculeID();
154 std::vector<std::pair<G4TrackList::iterator, G4double>> resultIndices;
155 resultIndices.clear();
157 trackA, key, fRCutOff, resultIndices);
159 if(resultIndices.empty())
163 for(
auto& it : resultIndices)
165 G4Track* pTrackB = *(std::get<0>(it));
167 if(pTrackB == &trackA)
171 if(pTrackB ==
nullptr)
174 exceptionDescription <<
"No trackB no valid";
178 exceptionDescription);
181 if(fCheckedTracks.find(pTrackB->
GetTrackID()) != fCheckedTracks.end())
186 Utils utils(trackA, *pTrackB);
189 auto pMolConfB = pMolB->GetMolecularConfiguration();
191 if(distance * distance < Reff * Reff)
199 if(!fHasAlreadyReachedNullTime)
202 fHasAlreadyReachedNullTime =
true;
205 CheckAndRecordResults(utils);
211 G4double tempMinET = GetTimeToEncounter(trackA, *pTrackB);
222 CheckAndRecordResults(utils);
231 G4cout <<
"G4DNAIndependentReactionTimeStepper::CalculateStep will finally "
237 G4cout <<
"Selected reactants for trackA: " << pMoleculeA->GetName()
240 vector<G4Track*>::iterator it;
254void G4DNAIndependentReactionTimeStepper::CheckAndRecordResults(
257 if(utils.fTrackB.GetTrackStatus() !=
fAlive)
262 if(&utils.fTrackB == &utils.fTrackA)
265 exceptionDescription <<
"A track is reacting with itself"
266 " (which is impossible) ie fpTrackA == trackB"
268 exceptionDescription <<
"Molecule A is of type : "
269 << utils.fpMoleculeA->GetName()
270 <<
" with trackID : " << utils.fTrackA.GetTrackID()
271 <<
" and B : " << utils.fpMoleculeB->GetName()
272 <<
" with trackID : " << utils.fTrackB.GetTrackID()
274 G4Exception(
"G4DNAIndependentReactionTimeStepper::RetrieveResults",
276 exceptionDescription);
279 if(fabs(utils.fTrackB.GetGlobalTime() - utils.fTrackA.GetGlobalTime()) >
280 utils.fTrackA.GetGlobalTime() * (1. - 1. / 100))
285 <<
"The interacting tracks are not synchronized in time" <<
G4endl;
287 <<
"trackB->GetGlobalTime() != fpTrackA.GetGlobalTime()" <<
G4endl;
289 exceptionDescription <<
"fpTrackA : trackID : "
290 << utils.fTrackA.GetTrackID()
291 <<
"\t Name :" << utils.fpMoleculeA->GetName()
292 <<
"\t fpTrackA->GetGlobalTime() = "
293 <<
G4BestUnit(utils.fTrackA.GetGlobalTime(),
"Time")
296 exceptionDescription <<
"trackB : trackID : " << utils.fTrackB.GetTrackID()
297 <<
"\t Name :" << utils.fpMoleculeB->GetName()
298 <<
"\t trackB->GetGlobalTime() = "
299 <<
G4BestUnit(utils.fTrackB.GetGlobalTime(),
"Time")
302 G4Exception(
"G4DNAIndependentReactionTimeStepper::RetrieveResults",
304 exceptionDescription);
309std::unique_ptr<G4ITReactionChange>
315 if(pReactionSet ==
nullptr)
321 if(reactionPerTime.empty())
326 for(
auto reaction_i = reactionPerTime.begin();
327 reaction_i != reactionPerTime.end(); reaction_i = reactionPerTime.begin())
329 G4Track* pTrackA = (*reaction_i)->GetReactants().first;
334 G4Track* pTrackB = (*reaction_i)->GetReactant(pTrackA);
340 if(pTrackB == pTrackA)
343 exceptionDescription <<
"The IT reaction process sent back a reaction "
344 "between trackA and trackB. ";
345 exceptionDescription <<
"The problem is trackA == trackB";
346 G4Exception(
"G4DNAIndependentReactionTimeStepper::FindReaction",
348 exceptionDescription);
351 if(fpReactionProcess !=
nullptr &&
355 if((fSampledPositions.find(pTrackA->
GetTrackID()) ==
356 fSampledPositions.end() &&
357 (fSampledPositions.find(pTrackB->
GetTrackID()) ==
358 fSampledPositions.end())))
362 <<
"The positions of trackA and trackB have no counted ";
363 G4Exception(
"G4DNAIndependentReactionTimeStepper::FindReaction",
364 "G4DNAIndependentReactionTimeStepper0001",
370 auto pReactionChange =
372 if(pReactionChange ==
nullptr)
376 return pReactionChange;
385 fReactionModel = pReactionModel;
390 return fReactionModel;
398G4double G4DNAIndependentReactionTimeStepper::GetTimeToEncounter(
403 ->GetTimeToEncounter(trackA, trackB);
404 return timeToReaction;
410 fpReactionProcess = pReactionProcess;
416 fCheckedTracks.clear();
418 for(
auto pTrack : *fpTrackContainer->
GetMainList())
420 if(pTrack ==
nullptr)
423 exceptionDescription <<
"No track found.";
424 G4Exception(
"G4DNAIndependentReactionTimeStepper::CalculateMinTimeStep",
425 "G4DNAIndependentReactionTimeStepper006",
439 if(sampledMinTimeStep < fTSTimeStep)
441 fTSTimeStep = sampledMinTimeStep;
448 fSampledPositions[pTrack->GetTrackID()] = pTrack->GetPosition();
453 fSampledPositions[pTrackB->GetTrackID()] = pTrackB->GetPosition();
458 else if(fTSTimeStep == sampledMinTimeStep &&
G4bool(reactants))
463 fSampledPositions[pTrack->GetTrackID()] = pTrack->GetPosition();
468 fSampledPositions[pTrackB->GetTrackID()] = pTrackB->GetPosition();
#define BuildChemicalMoleculeFinder()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
std::multiset< G4ITReactionPtr, compReactionPerTime > G4ITReactionPerTime
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
G4Molecule * GetMolecule(const G4Track &track)
G4GLOB_DLL std::ostream G4cout
G4double CalculateStep(const G4Track &, const G4double &) override
G4DNAIndependentReactionTimeStepper()
G4VDNAReactionModel * GetReactionModel()
void SetReactionModel(G4VDNAReactionModel *)
G4double CalculateMinTimeStep(G4double, G4double) override
std::unique_ptr< G4ITReactionChange > FindReaction(G4ITReactionSet *pReactionSet, const G4double ¤tStepTime=0, const G4double &previousStepTime=0, const G4bool &reachedUserStepTimeLimit=false)
void SetReactionProcess(G4VITReactionProcess *pReactionProcess)
Data * GetReactionData(Reactant *, Reactant *) const
const ReactantList * CanReactWith(Reactant *) const
static G4double GetRCutOff()
void SelectThisReaction(G4ITReactionPtr reaction)
void AddReactions(G4double time, G4Track *trackA, G4TrackVectorHandle reactants)
G4ITReactionPerTime & GetReactionsPerTime()
G4TrackList * GetMainList(Key)
const G4String & GetName() const override
static G4OctreeFinder * Instance()
void FindNearestInRange(const G4Track &track, const int &key, G4double R, std::vector< std::pair< typename CONTAINER::iterator, G4double > > &result, G4bool isSort=false) const
static G4Scheduler * Instance()
G4TrackStatus GetTrackStatus() const
void SetPosition(const G4ThreeVector &aValue)
const G4ThreeVector & GetPosition() const
virtual void Initialise(const G4MolecularConfiguration *, const G4Track &)
virtual G4double GetReactionRadius(const G4MolecularConfiguration *, const G4MolecularConfiguration *)=0
virtual std::unique_ptr< G4ITReactionChange > MakeReaction(const G4Track &, const G4Track &)=0
virtual G4bool TestReactibility(const G4Track &, const G4Track &, double, bool)=0
G4TrackVectorHandle fReactants
G4TrackVectorHandle GetReactants()
virtual void ResetReactants()
static G4ThreadLocal G4double fUserMinTimeStep
G4double fSampledMinTimeStep