Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DNAIndependentReactionTimeStepper Class Reference

#include <G4DNAIndependentReactionTimeStepper.hh>

+ Inheritance diagram for G4DNAIndependentReactionTimeStepper:

Public Member Functions

 G4DNAIndependentReactionTimeStepper ()
 
 ~G4DNAIndependentReactionTimeStepper () override=default
 
 G4DNAIndependentReactionTimeStepper (const G4DNAIndependentReactionTimeStepper &)=delete
 
G4DNAIndependentReactionTimeStepperoperator= (const G4DNAIndependentReactionTimeStepper &)=delete
 
void Prepare () override
 
G4double CalculateStep (const G4Track &, const G4double &) override
 
G4double CalculateMinTimeStep (G4double, G4double) override
 
void SetReactionModel (G4VDNAReactionModel *)
 
G4VDNAReactionModelGetReactionModel ()
 
std::unique_ptr< G4ITReactionChangeFindReaction (G4ITReactionSet *pReactionSet, const G4double &currentStepTime=0, const G4double &previousStepTime=0, const G4bool &reachedUserStepTimeLimit=false)
 
void SetReactionProcess (G4VITReactionProcess *pReactionProcess)
 
void SetVerbose (G4int)
 
- Public Member Functions inherited from G4VITTimeStepComputer
 G4VITTimeStepComputer ()
 
virtual ~G4VITTimeStepComputer ()
 
 G4VITTimeStepComputer (const G4VITTimeStepComputer &)
 
G4VITTimeStepComputeroperator= (const G4VITTimeStepComputer &other)
 
virtual void Initialize ()
 
virtual void Prepare ()
 
virtual G4double CalculateStep (const G4Track &, const G4double &)=0
 
virtual G4double CalculateMinTimeStep (G4double, G4double)=0
 
G4TrackVectorHandle GetReactants ()
 
virtual void ResetReactants ()
 
G4double GetSampledMinTimeStep ()
 
void SetReactionTable (const G4ITReactionTable *)
 
const G4ITReactionTableGetReactionTable ()
 

Additional Inherited Members

- Static Public Member Functions inherited from G4VITTimeStepComputer
static void SetTimes (const G4double &, const G4double &)
 
- Protected Attributes inherited from G4VITTimeStepComputer
G4double fSampledMinTimeStep
 
G4TrackVectorHandle fReactants
 
const G4ITReactionTablefpReactionTable
 
- Static Protected Attributes inherited from G4VITTimeStepComputer
static G4ThreadLocal G4double fCurrentGlobalTime = -1
 
static G4ThreadLocal G4double fUserMinTimeStep = -1
 

Detailed Description

Definition at line 51 of file G4DNAIndependentReactionTimeStepper.hh.

Constructor & Destructor Documentation

◆ G4DNAIndependentReactionTimeStepper() [1/2]

G4DNAIndependentReactionTimeStepper::G4DNAIndependentReactionTimeStepper ( )

Definition at line 54 of file G4DNAIndependentReactionTimeStepper.cc.

56{
57 fReactionSet->SortByTime();
58}

◆ ~G4DNAIndependentReactionTimeStepper()

G4DNAIndependentReactionTimeStepper::~G4DNAIndependentReactionTimeStepper ( )
overridedefault

◆ G4DNAIndependentReactionTimeStepper() [2/2]

G4DNAIndependentReactionTimeStepper::G4DNAIndependentReactionTimeStepper ( const G4DNAIndependentReactionTimeStepper )
delete

Member Function Documentation

◆ CalculateMinTimeStep()

G4double G4DNAIndependentReactionTimeStepper::CalculateMinTimeStep ( G4double  ,
G4double  definedMinTimeStep 
)
overridevirtual

Implements G4VITTimeStepComputer.

Definition at line 413 of file G4DNAIndependentReactionTimeStepper.cc.

415{
416 G4double fTSTimeStep = DBL_MAX;
417 fCheckedTracks.clear();
418
419 for(auto pTrack : *fpTrackContainer->GetMainList())
420 {
421 if(pTrack == nullptr)
422 {
423 G4ExceptionDescription exceptionDescription;
424 exceptionDescription << "No track found.";
425 G4Exception("G4DNAIndependentReactionTimeStepper::CalculateMinTimeStep",
426 "G4DNAIndependentReactionTimeStepper006",
427 FatalErrorInArgument, exceptionDescription);
428 continue;
429 }
430
431 G4TrackStatus trackStatus = pTrack->GetTrackStatus();
432 if(trackStatus == fStopAndKill || trackStatus == fStopButAlive)
433 {
434 continue;
435 }
436
437 G4double sampledMinTimeStep = CalculateStep(*pTrack, definedMinTimeStep);
438 G4TrackVectorHandle reactants = GetReactants();
439
440 if(sampledMinTimeStep < fTSTimeStep)
441 {
442 fTSTimeStep = sampledMinTimeStep;
443 fReactionSet->CleanAllReaction();
444 if(reactants)
445 {
446 fReactionSet->AddReactions(fTSTimeStep, const_cast<G4Track*>(pTrack),
447 reactants);
448
449 fSampledPositions[pTrack->GetTrackID()] = pTrack->GetPosition();
450 for(const auto& it : *fReactants)
451 {
452 auto pTrackB = it;
453 // G4cout<<"position : "<<pTrackB->GetTrackID()<<G4endl;
454 fSampledPositions[pTrackB->GetTrackID()] = pTrackB->GetPosition();
455 }
457 }
458 }
459 else if(fTSTimeStep == sampledMinTimeStep && G4bool(reactants))
460 {
461 fReactionSet->AddReactions(fTSTimeStep, const_cast<G4Track*>(pTrack),
462 reactants);
463
464 fSampledPositions[pTrack->GetTrackID()] = pTrack->GetPosition();
465 for(const auto& it : *fReactants)
466 {
467 auto pTrackB = it;
468 // G4cout<<"position : "<<pTrackB->GetTrackID()<<G4endl;
469 fSampledPositions[pTrackB->GetTrackID()] = pTrackB->GetPosition();
470 }
472 }
473 else if(reactants)
474 {
476 }
477 }
478
479 return fTSTimeStep;
480}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4shared_ptr< std::vector< G4Track * > > G4TrackVectorHandle
Definition: G4ITReaction.hh:44
G4TrackStatus
@ fStopAndKill
@ fStopButAlive
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
G4double CalculateStep(const G4Track &, const G4double &) override
void CleanAllReaction()
void AddReactions(G4double time, G4Track *trackA, G4TrackVectorHandle reactants)
G4TrackList * GetMainList(Key)
G4TrackVectorHandle fReactants
G4TrackVectorHandle GetReactants()
#define DBL_MAX
Definition: templates.hh:62

◆ CalculateStep()

G4double G4DNAIndependentReactionTimeStepper::CalculateStep ( const G4Track trackA,
const G4double userMinTimeStep 
)
overridevirtual

Implements G4VITTimeStepComputer.

Definition at line 77 of file G4DNAIndependentReactionTimeStepper.cc.

79{
80 auto pMoleculeA = GetMolecule(trackA);
81 InitializeForNewTrack();
82 fUserMinTimeStep = userMinTimeStep;
83 fCheckedTracks.insert(trackA.GetTrackID());
84
85#ifdef G4VERBOSE
86 if(fVerbose != 0)
87 {
88 G4cout << "________________________________________________________________"
89 "_______"
90 << G4endl;
91 G4cout << "G4DNAIndependentReactionTimeStepper::CalculateStep" << G4endl;
92 G4cout << "Check done for molecule : " << pMoleculeA->GetName() << " ("
93 << trackA.GetTrackID() << ") " << G4endl;
94 }
95#endif
96
97 auto pMolConfA = pMoleculeA->GetMolecularConfiguration();
98
99 const auto pReactantList = fMolecularReactionTable->CanReactWith(pMolConfA);
100
101 if(pReactantList == nullptr)
102 {
103#ifdef G4VERBOSE
104 if(fVerbose > 1)
105 {
106 G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
107 G4cout << "!!! WARNING" << G4endl;
108 G4cout << "G4DNAIndependentReactionTimeStepper::CalculateStep will "
109 "return infinity "
110 "for the reaction because the molecule "
111 << pMoleculeA->GetName()
112 << " does not have any reactants given in the reaction table."
113 << G4endl;
114 G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
115 }
116#endif
117 return DBL_MAX;
118 }
119
120 G4int nbReactives = (G4int)pReactantList->size();
121
122 if(nbReactives == 0)
123 {
124#ifdef G4VERBOSE
125 // DEBUG
126 if(fVerbose != 0)
127 {
128 G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
129 G4cout << "!!! WARNING" << G4endl;
130 G4cout << "G4DNAIndependentReactionTimeStepper::CalculateStep will "
131 "return infinity "
132 "for the reaction because the molecule "
133 << pMoleculeA->GetName()
134 << " does not have any reactants given in the reaction table."
135 << "This message can also result from a wrong implementation of "
136 "the reaction table."
137 << G4endl;
138 G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
139 }
140#endif
141 return DBL_MAX;
142 }
143 fReactants = std::make_shared<vector<G4Track*>>();
144 fReactionModel->Initialise(pMolConfA, trackA);
145 for(G4int i = 0; i < nbReactives; ++i)
146 {
147 auto pMoleculeB = (*pReactantList)[i];
148 G4int key = pMoleculeB->GetMoleculeID();
149
150 // fRCutOff = G4IRTUtils::GetRCutOff(1 * ps);
151 fRCutOff = G4IRTUtils::GetRCutOff();
152 //______________________________________________________________
153 // Retrieve reaction range
154 const G4double Reff = fReactionModel->GetReactionRadius(i);
155 std::vector<std::pair<G4TrackList::iterator, G4double>> resultIndices;
156 resultIndices.clear();
158 trackA, key, fRCutOff, resultIndices);
159
160 if(resultIndices.empty())
161 {
162 continue;
163 }
164 for(auto& it : resultIndices)
165 {
166 G4Track* pTrackB = *(std::get<0>(it));
167
168 if(pTrackB == &trackA)
169 {
170 continue;
171 }
172 if(pTrackB == nullptr)
173 {
174 G4ExceptionDescription exceptionDescription;
175 exceptionDescription << "No trackB no valid";
176 G4Exception("G4DNAIndependentReactionTimeStepper"
177 "::CalculateStep()",
178 "G4DNAIndependentReactionTimeStepper007", FatalException,
179 exceptionDescription);
180 }else
181 {
182 if(fCheckedTracks.find(pTrackB->GetTrackID()) != fCheckedTracks.end())
183 {
184 continue;
185 }
186
187 Utils utils(trackA, *pTrackB);
188
189 auto pMolB = GetMolecule(pTrackB);
190 auto pMolConfB = pMolB->GetMolecularConfiguration();
191 G4double distance = (trackA.GetPosition() - pTrackB->GetPosition()).mag();
192 if(distance * distance < Reff * Reff)
193 {
194 auto reactionData =
195 fMolecularReactionTable->GetReactionData(pMolConfA, pMolConfB);
197 {
198 if(reactionData->GetProbability() > G4UniformRand())
199 {
200 if(!fHasAlreadyReachedNullTime)
201 {
202 fReactants->clear();
203 fHasAlreadyReachedNullTime = true;
204 }
206 CheckAndRecordResults(utils);
207 }
208 }
209 }
210 else
211 {
212 G4double tempMinET = GetTimeToEncounter(trackA, *pTrackB);
213 if(tempMinET < 0 || tempMinET > G4Scheduler::Instance()->GetEndTime())
214 {
215 continue;
216 }
217 if(tempMinET >= fSampledMinTimeStep)
218 {
219 continue;
220 }
221 fSampledMinTimeStep = tempMinET;
222 fReactants->clear();
223 CheckAndRecordResults(utils);
224 }
225 }
226 }
227 }
228
229#ifdef G4VERBOSE
230 if(fVerbose != 0)
231 {
232 G4cout << "G4DNAIndependentReactionTimeStepper::CalculateStep will finally "
233 "return :"
235
236 if(fVerbose > 1)
237 {
238 G4cout << "Selected reactants for trackA: " << pMoleculeA->GetName()
239 << " (" << trackA.GetTrackID() << ") are: ";
240
241 vector<G4Track*>::iterator it;
242 for(it = fReactants->begin(); it != fReactants->end(); it++)
243 {
244 G4Track* trackB = *it;
245 G4cout << GetMolecule(trackB)->GetName() << " (" << trackB->GetTrackID()
246 << ") \t ";
247 }
248 G4cout << G4endl;
249 }
250 }
251#endif
252 return fSampledMinTimeStep;
253}
@ FatalException
G4Molecule * GetMolecule(const G4Track &track)
Definition: G4Molecule.cc:74
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition: Randomize.hh:52
Data * GetReactionData(Reactant *, Reactant *) const
const ReactantList * CanReactWith(Reactant *) const
static G4double GetRCutOff()
Definition: G4IRTUtils.cc:39
const G4String & GetName() const
Definition: G4Molecule.cc:336
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()
Definition: G4Scheduler.cc:101
G4double GetGlobalTime() const
Definition: G4Scheduler.hh:364
G4double GetStartTime() const
Definition: G4Scheduler.hh:344
G4int GetTrackID() const
const G4ThreeVector & GetPosition() const
virtual void Initialise(const G4MolecularConfiguration *, const G4Track &)
virtual G4double GetReactionRadius(const G4MolecularConfiguration *, const G4MolecularConfiguration *)=0
static G4ThreadLocal G4double fUserMinTimeStep

Referenced by CalculateMinTimeStep().

◆ FindReaction()

std::unique_ptr< G4ITReactionChange > G4DNAIndependentReactionTimeStepper::FindReaction ( G4ITReactionSet pReactionSet,
const G4double currentStepTime = 0,
const G4double previousStepTime = 0,
const G4bool reachedUserStepTimeLimit = false 
)

Definition at line 311 of file G4DNAIndependentReactionTimeStepper.cc.

315{
316 if(pReactionSet == nullptr)
317 {
318 return nullptr;
319 }
320
321 G4ITReactionPerTime& reactionPerTime = pReactionSet->GetReactionsPerTime();
322 if(reactionPerTime.empty())
323 {
324 return nullptr;
325 }
326
327 for(auto reaction_i = reactionPerTime.begin();
328 reaction_i != reactionPerTime.end(); reaction_i = reactionPerTime.begin())
329 {
330 G4Track* pTrackA = (*reaction_i)->GetReactants().first;
331 if(pTrackA->GetTrackStatus() == fStopAndKill)
332 {
333 continue;
334 }
335 G4Track* pTrackB = (*reaction_i)->GetReactant(pTrackA);
336 if(pTrackB->GetTrackStatus() == fStopAndKill)
337 {
338 continue;
339 }
340
341 if(pTrackB == pTrackA)
342 {
343 G4ExceptionDescription exceptionDescription;
344 exceptionDescription << "The IT reaction process sent back a reaction "
345 "between trackA and trackB. ";
346 exceptionDescription << "The problem is trackA == trackB";
347 G4Exception("G4DNAIndependentReactionTimeStepper::FindReaction",
348 "G4DNAIndependentReactionTimeStepper02", FatalErrorInArgument,
349 exceptionDescription);
350 }
351 pReactionSet->SelectThisReaction(*reaction_i);
352 if(fpReactionProcess != nullptr &&
353 fpReactionProcess->TestReactibility(*pTrackA, *pTrackB, currentStepTime,
354 false))
355 {
356 if((fSampledPositions.find(pTrackA->GetTrackID()) ==
357 fSampledPositions.end() &&
358 (fSampledPositions.find(pTrackB->GetTrackID()) ==
359 fSampledPositions.end())))
360 {
361 G4ExceptionDescription exceptionDescription;
362 exceptionDescription
363 << "The positions of trackA and trackB have no counted ";
364 G4Exception("G4DNAIndependentReactionTimeStepper::FindReaction",
365 "G4DNAIndependentReactionTimeStepper0001",
366 FatalErrorInArgument, exceptionDescription);
367 }
368
369 pTrackA->SetPosition(fSampledPositions[pTrackA->GetTrackID()]);
370 pTrackB->SetPosition(fSampledPositions[pTrackB->GetTrackID()]);
371 auto pReactionChange =
372 fpReactionProcess->MakeReaction(*pTrackA, *pTrackB);
373 if(pReactionChange == nullptr)
374 {
375 return nullptr;
376 }
377 return pReactionChange;
378 }
379 }
380 return nullptr;
381}
std::multiset< G4ITReactionPtr, compReactionPerTime > G4ITReactionPerTime
Definition: G4ITReaction.hh:77
void SelectThisReaction(G4ITReactionPtr reaction)
G4ITReactionPerTime & GetReactionsPerTime()
G4TrackStatus GetTrackStatus() const
void SetPosition(const G4ThreeVector &aValue)
virtual std::unique_ptr< G4ITReactionChange > MakeReaction(const G4Track &, const G4Track &)=0
virtual G4bool TestReactibility(const G4Track &, const G4Track &, double, bool)=0

◆ GetReactionModel()

G4VDNAReactionModel * G4DNAIndependentReactionTimeStepper::GetReactionModel ( )

Definition at line 389 of file G4DNAIndependentReactionTimeStepper.cc.

390{
391 return fReactionModel;
392}

◆ operator=()

G4DNAIndependentReactionTimeStepper & G4DNAIndependentReactionTimeStepper::operator= ( const G4DNAIndependentReactionTimeStepper )
delete

◆ Prepare()

void G4DNAIndependentReactionTimeStepper::Prepare ( )
overridevirtual

Reimplemented from G4VITTimeStepComputer.

Definition at line 60 of file G4DNAIndependentReactionTimeStepper.cc.

61{
63 fSampledPositions.clear();
65}
#define BuildChemicalMoleculeFinder()

◆ SetReactionModel()

void G4DNAIndependentReactionTimeStepper::SetReactionModel ( G4VDNAReactionModel pReactionModel)

Definition at line 383 of file G4DNAIndependentReactionTimeStepper.cc.

385{
386 fReactionModel = pReactionModel;
387}

◆ SetReactionProcess()

void G4DNAIndependentReactionTimeStepper::SetReactionProcess ( G4VITReactionProcess pReactionProcess)

Definition at line 408 of file G4DNAIndependentReactionTimeStepper.cc.

410{
411 fpReactionProcess = pReactionProcess;
412}

◆ SetVerbose()

void G4DNAIndependentReactionTimeStepper::SetVerbose ( G4int  flag)

Definition at line 394 of file G4DNAIndependentReactionTimeStepper.cc.

395{
396 fVerbose = flag;
397}

The documentation for this class was generated from the following files: