50 using namespace G4MemStat;
57 fUserMinTimeStep = -1.;
59 fpTrackingManager =
nullptr;
60 fReactionSet =
nullptr;
61 fpTrackContainer =
nullptr;
62 fpModelHandler =
nullptr;
63 fpActiveModelWithMinTimeStep =
nullptr;
64 fComputeTimeStep =
false;
65 fComputeReaction =
false;
72 fpModelHandler->RegisterModel(model, time);
77 fpModelHandler->Initialize();
81 fComputeTimeStep =
false;
82 fComputeReaction =
false;
83 if (fpModelHandler->GetTimeStepComputerFlag())
85 fComputeTimeStep =
true;
87 if (fpModelHandler->GetReactionProcessFlag())
89 fComputeReaction =
true;
97 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
98 MemStat mem_first, mem_second, mem_diff;
102 fpActiveModelWithMinTimeStep =
nullptr;
105 InitializeStepper(currentGlobalTime, definedMinTimeStep);
107 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
109 mem_diff = mem_second-mem_first;
110 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || After "
111 "computing fpModelProcessor -> InitializeStepper, diff is : "
116 for (
auto pTrack : *fpTrackContainer->GetMainList())
118 if (pTrack ==
nullptr)
121 exceptionDescription <<
"No track found.";
122 G4Exception(
"G4Scheduler::CalculateMinStep",
"ITScheduler006",
129 <<
" ID: " <<
track->GetTrackID()
130 <<
" at time : " <<
track->GetGlobalTime()
140 CalculateTimeStep(pTrack, definedMinTimeStep);
142 ExtractTimeStepperData();
145 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
147 mem_diff = mem_second-mem_first;
148 G4cout <<
"\t || MEM || G4Scheduler::CalculateMinTimeStep || "
149 "After looping on tracks, diff is : " << mem_diff <<
G4endl;
158 if (fpTrack ==
nullptr)
164 for (
auto pStepModel : fActiveModels)
166 if (pStepModel ==
nullptr)
171 auto pTimeStepper = pStepModel->GetTimeStepper();
172 G4double sampledMinTimeStep = pTimeStepper->GetSampledMinTimeStep();
175 if (sampledMinTimeStep < fTSTimeStep)
177 fpActiveModelWithMinTimeStep = pStepModel;
178 fTSTimeStep = sampledMinTimeStep;
181 fReactionSet->CleanAllReaction();
185 fReactionSet->AddReactions(fTSTimeStep,
186 const_cast<G4Track*>(fpTrack),
188 pTimeStepper->ResetReactants();
191 else if (fTSTimeStep == sampledMinTimeStep &&
bool(reactants))
194 fReactionSet->AddReactions(fTSTimeStep,
195 const_cast<G4Track*>(fpTrack),
197 pTimeStepper->ResetReactants();
201 pTimeStepper->ResetReactants();
215 #if defined (DEBUG_MEM)
216 MemStat mem_first, mem_second, mem_diff;
220 fActiveModels = fpModelHandler->GetActiveModels(currentGlobalTime);
222 for (
auto& pModel : fActiveModels)
224 pModel->PrepareNewTimeStep();
227 #if defined (DEBUG_MEM)
229 mem_diff = mem_second-mem_first;
230 G4cout <<
"\t || MEM || G4ITModelProcessor::InitializeStepper || After computing stepper -> Prepare(), diff is : " << mem_diff <<
G4endl;
240 if (pTrack ==
nullptr)
243 exceptionDescription <<
"No track was passed to the method.";
245 "ITModelProcessor004",
247 exceptionDescription);
250 fUserMinTimeStep = userMinTimeStep;
259 for (
auto& pStepModel : fActiveModels)
261 pStepModel->GetTimeStepper()->CalculateStep(*fpTrack, fUserMinTimeStep);
271 G4bool reachedUserTimeLimit,
281 if (fReactionSet->Empty())
290 FindReaction(fReactionSet,
293 reachedUserTimeLimit);
298 for (
auto& pChanges : fReactionInfo)
300 auto pTrackA =
const_cast<G4Track*
>(pChanges->GetTrackA());
301 auto pTrackB =
const_cast<G4Track*
>(pChanges->GetTrackB());
303 if (pTrackA ==
nullptr
304 || pTrackB ==
nullptr
311 G4int nbSecondaries = pChanges->GetNumberOfSecondaries();
312 const std::vector<G4Track*>* productsVector = pChanges->GetfSecondary();
314 if (fpUserTimeStepAction)
326 << pTrackA->GetTrackID() <<
") + " <<
GetIT(pTrackB)->
GetName() <<
" ("
327 << pTrackB->GetTrackID() <<
") -> ";
331 if (nbSecondaries > 0)
333 for (
int i = 0; i < nbSecondaries; ++i)
336 if (fVerbose && i != 0)
342 G4Track* secondary = (*productsVector)[i];
343 fpTrackContainer->_PushTrack(secondary);
345 pTrackB->GetTrackID());
347 if (secondary->
GetGlobalTime() - fGlobalTime > fTimeTolerance)
350 exceptionDescription <<
"The time of the secondary should not be bigger than the"
351 " current global time."
352 <<
" This may cause synchronization problem. If the process you"
353 " are using required "
354 <<
"such feature please contact the developpers." <<
G4endl
355 <<
"The global time in the step manager : "
358 <<
"The global time of the track : "
362 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
365 exceptionDescription);
392 if (pTrackA->GetTrackID() == 0 || pTrackB->GetTrackID() == 0)
395 if (pTrackA->GetTrackID() == 0)
406 <<
"The problem was found for the reaction between tracks :"
408 << pTrackA->GetTrackID() <<
") & "
409 << pTrackB->GetParticleDefinition()->GetParticleName() <<
" ("
410 << pTrackB->GetTrackID() <<
"). \n";
412 if (pTrack->
GetStep() ==
nullptr)
414 exceptionDescription <<
"Also no step was found"
415 <<
" ie track->GetStep() == 0 \n";
418 exceptionDescription <<
"Parent ID of trackA : "
419 << pTrackA->GetParentID() <<
"\n";
420 exceptionDescription <<
"Parent ID of trackB : "
421 << pTrackB->GetParentID() <<
"\n";
424 <<
"The ID of one of the reaction track was not setup.";
425 G4Exception(
"G4Scheduler::ComputeInteractionBetweenTracks",
428 exceptionDescription);
431 if (pChanges->WereParentsKilled())
436 fpTrackingManager->EndTracking(pTrackA);
437 fpTrackingManager->EndTracking(pTrackB);
440 pChanges.reset(
nullptr);
443 fReactionInfo.clear();
446 fReactionSet->CleanAllReaction();
448 fpTrackContainer->MergeSecondariesWithMainList();
449 fpTrackContainer->KillTracks();
454 const double currentStepTime,
456 const bool reachedUserStepTimeLimit)
458 if (pReactionSet ==
nullptr || fActiveModels.empty())
466 for (
auto tracks_i = reactionPerTrackMap.begin();
467 tracks_i != reactionPerTrackMap.end();
468 tracks_i = reactionPerTrackMap.begin())
470 G4Track* pTrackA = tracks_i->first;
479 assert(reactionList.begin() != reactionList.end());
481 for (
auto it = reactionList.begin();
it != reactionList.end();
it = reactionList.begin())
484 G4Track* pTrackB = reaction->GetReactant(pTrackA);
490 if (pTrackB == pTrackA)
494 <<
"The IT reaction process sent back a reaction between trackA and trackB. ";
495 exceptionDescription <<
"The problem is trackA == trackB";
497 "ITModelProcessor005",
499 exceptionDescription);
507 reachedUserStepTimeLimit))
509 auto pReactionChange = pReactionProcess->
MakeReaction(*pTrackA, *pTrackB);
513 fReactionInfo.push_back(std::move(pReactionChange));
534 <<
"You are trying to set a new model while the model processor has alreaday be initialized";
535 G4Exception(
"G4ITModelProcessor::SetModelHandler",
"ITModelProcessor001",
538 fpModelHandler = pModelHandler;
548 return fComputeTimeStep;
558 fpTrackingManager = pTrackingManager;