277 G4cout <<
"*** G4Scheduler starts processing " <<
G4endl;
279 G4cout <<
"___________________________________________"
280 "___________________________"
288 fpModelProcessor->Initialize();
289 fpStepProcessor->Initialize();
291 if (fpGun !=
nullptr) fpGun->DefineTracks();
293 if (fpTrackingInteractivity !=
nullptr) fpTrackingInteractivity->Initialize();
299 if (fResetScavenger) {
300 if (fpUserScavenger !=
nullptr) {
301 fpUserScavenger->Reset();
305 if (fpUserTimeStepAction !=
nullptr) {
306 fpUserTimeStepAction->StartProcessing();
310 G4bool trackFound =
false;
320 if (fTrackContainer.DelayListsNOTEmpty()) {
321 fStartTime = fTrackContainer.GetNextTime();
333 G4cout <<
"G4Scheduler: process time= " << localtimer <<
G4endl;
341 G4cout <<
"___________________________________" <<
G4endl;
344 G4cout <<
"*** G4Scheduler did not start because no "
345 "track was found to be processed"
347 G4cout <<
"___________________________________" <<
G4endl;
354 if (fpUserTimeStepAction !=
nullptr) {
355 fpUserTimeStepAction->EndProcessing();
362 if (fpTrackingInteractivity !=
nullptr) {
363 fpTrackingInteractivity->Finalize();
382 fTmpGlobalTime = fGlobalTime;
383 fGlobalTime = fTrackContainer.GetNextTime();
384 G4double tmpGlobalTime = fGlobalTime;
387 while (fTrackContainer.MergeNextTimeToMainList(tmpGlobalTime) && carryOn) {
388 if (tmpGlobalTime != fGlobalTime) {
389 fGlobalTime = tmpGlobalTime;
391 fStopTime = min(fTrackContainer.GetNextTime(), fEndTime);
395 fStopTime = min(nextWatchedTime, fEndTime);
401 if (nextWatchedTime > fEndTime && carryOn) {
402 fStopTime = min(fTrackContainer.GetNextTime(), fEndTime);
459 if (fpUserTimeStepAction !=
nullptr) fpUserTimeStepAction->NewStage();
461#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
462 MemStat mem_first, mem_second, mem_diff;
465#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
469 while (fGlobalTime < fStopTime && fTrackContainer.MainListsNOTEmpty()
470 && (fMaxSteps == -1 ?
true : fNbSteps < fMaxSteps) && fContinue)
474#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
476 mem_diff = mem_second - mem_first;
477 G4cout <<
"\t || MEM || After step " << fNbSteps <<
", diff is : " << mem_diff <<
G4endl;
483#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
485 mem_diff = mem_second - mem_first;
486 G4cout <<
"\t || MEM || After stepping, diff is : " << mem_diff <<
G4endl;
491 G4cout <<
"*** G4Scheduler has finished processing a track list at time : "
499 fTimeStep = fMaxTimeStep;
505 fReachedUserTimeLimit =
false;
515 G4cout <<
"*** Start Of Step N°" << fNbSteps + 1 <<
" species number : " <<
GetNTracks()
524#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
525 MemStat mem_first, mem_second, mem_diff;
528#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
534 if (fUsePreDefinedTimeSteps) {
541 <<
" the chosen user time step is : " <<
G4BestUnit(fDefinedMinTimeStep,
"Time")
550 if (fpModelProcessor->GetComputeTimeStep())
552 fTSTimeStep = fpModelProcessor->CalculateMinTimeStep(fGlobalTime, fDefinedMinTimeStep);
555 else if (fUseDefaultTimeSteps) {
556 fTSTimeStep = fDefinedMinTimeStep;
559#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
561 mem_diff = mem_second - mem_first;
562 G4cout <<
"|| MEM || After computing TS, diff is : " << mem_diff <<
G4endl;
577#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
584 fILTimeStep = fpStepProcessor->ComputeInteractionLength(fPreviousTimeStep);
590#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
592 mem_diff = mem_second - mem_first;
593 G4cout <<
"|| MEM || After IL, diff is : " << mem_diff <<
G4endl;
601 G4cout <<
"*** The minimum time returned by the processes is : "
609#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
613 if (fILTimeStep <= fTSTimeStep)
616 fInteractionStep =
true;
618 fTimeStep = fILTimeStep;
620 fpStepProcessor->PrepareLeadingTracks();
623 fInteractionStep =
false;
624 fpStepProcessor->ResetLeadingTracks();
625 fTimeStep = fTSTimeStep;
629 if (fGlobalTime + fTimeStep > fStopTime)
632 fTimeStep = fStopTime - fGlobalTime;
634 fInteractionStep =
true;
635 fReactionSet->CleanAllReaction();
636 fpStepProcessor->ResetLeadingTracks();
642 if (fZeroTimeCount >= fMaxNZeroTimeStepsAllowed) {
645 exceptionDescription <<
"Too many zero time steps were detected. ";
646 exceptionDescription <<
"The simulation is probably stuck. ";
647 exceptionDescription <<
"The maximum number of zero time steps is currently : "
648 << fMaxNZeroTimeStepsAllowed;
649 exceptionDescription <<
".";
652 exceptionDescription);
659 fReachedUserTimeLimit = (fTimeStep <= fDefinedMinTimeStep)
660 || ((fTimeStep > fDefinedMinTimeStep)
661 && fabs(fTimeStep - fDefinedMinTimeStep) < fTimeTolerance);
663 if (fpUserTimeStepAction !=
nullptr) fpUserTimeStepAction->UserPreTimeStepAction();
666#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
668 mem_diff = mem_second - mem_first;
669 G4cout <<
"|| MEM || After LeadingTracks and UserPreTimeStepAction: " << mem_diff <<
G4endl;
672#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
676 fGlobalTime += fTimeStep;
681 if (fTSTimeStep > 0 || fILTimeStep <= fTSTimeStep) {
682 fpStepProcessor->DoIt(fTimeStep);
684#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
686 mem_diff = mem_second - mem_first;
687 G4cout <<
"|| MEM || After DoIT, diff is : " << mem_diff <<
G4endl;
690#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
694 fpModelProcessor->ComputeTrackReaction(fITStepStatus, fGlobalTime, fTimeStep, fPreviousTimeStep,
695 fReachedUserTimeLimit, fTimeTolerance,
696 fpUserTimeStepAction, fVerbose);
700 if (fpUserTimeStepAction !=
nullptr) {
701 fpUserTimeStepAction->UserPostTimeStepAction();
704 fPreviousTimeStep = fTimeStep;
706#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
708 mem_diff = mem_second - mem_first;
709 G4cout <<
"|| MEM || After computing reactions + UserPostTimeStepAction, "
724 std::stringstream finalOutput;
726 finalOutput <<
"*** End of step N°" << fNbSteps
727 <<
"\t T_i= " <<
G4BestUnit(fGlobalTime - fTimeStep,
"Time")
729 <<
"\t T_f= " <<
G4BestUnit(fGlobalTime,
"Time") <<
"\t " << interactionType
733 if (fReachedUserTimeLimit) {
734 finalOutput <<
"It has also reached the user time limit" <<
G4endl;
736 finalOutput <<
"_______________________________________________________________"
741 G4cout << finalOutput.str();
753 if (fpUserTimeSteps ==
nullptr)
return fDefaultMinTimeStep;
754 if (fabs(fGlobalTime - fUserUpperTimeLimit) < fTimeTolerance)
return fDefinedMinTimeStep;
756 auto it_fpUserTimeSteps_i = fpUserTimeSteps->upper_bound(fGlobalTime);
757 auto it_fpUserTimeSteps_low = fpUserTimeSteps->lower_bound(fGlobalTime);
759 if (it_fpUserTimeSteps_i == fpUserTimeSteps->end()) {
760 it_fpUserTimeSteps_i--;
761 fUserUpperTimeLimit = fStopTime;
763 else if (fabs(fGlobalTime - it_fpUserTimeSteps_low->first) < fTimeTolerance) {
764 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
765 auto tmp_it = it_fpUserTimeSteps_low;
767 if (tmp_it == fpUserTimeSteps->end()) {
768 fUserUpperTimeLimit = fStopTime;
771 fUserUpperTimeLimit = tmp_it->first;
774 else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low) {
775 fUserUpperTimeLimit = it_fpUserTimeSteps_i->first;
776 if (it_fpUserTimeSteps_i != fpUserTimeSteps->begin()) it_fpUserTimeSteps_i--;
779 fUserUpperTimeLimit = it_fpUserTimeSteps_i->first;
780 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
782 return it_fpUserTimeSteps_i->second;
789 if (fpUserTimeSteps ==
nullptr) {
791 exceptionDescription <<
"You are asking to use user defined steps but you did not give any.";
793 exceptionDescription);
796 auto fpUserTimeSteps_i = fpUserTimeSteps->upper_bound(fGlobalTime);
797 auto fpUserTimeSteps_low = fpUserTimeSteps->lower_bound(fGlobalTime);
799 if (fpUserTimeSteps_i == fpUserTimeSteps->end()) {
802 else if (fabs(fGlobalTime - fpUserTimeSteps_low->first) < fTimeTolerance) {
806 fpUserTimeSteps_i = fpUserTimeSteps_low;
808 else if (fpUserTimeSteps_i == fpUserTimeSteps_low) {
813 fpUserTimeSteps_i = fpUserTimeSteps_low;
816 fDefinedMinTimeStep = fpUserTimeSteps_i->second;
825 exceptionDescription <<
"End tracking is called while G4Scheduler is still running." <<
G4endl;
828 exceptionDescription);
831 while (fTrackContainer.DelayListsNOTEmpty()) {
832 auto nextTime = fTrackContainer.GetNextTime();
833 fTrackContainer.MergeNextTimeToMainList(nextTime);
836 fTrackContainer.MergeSecondariesWithMainList();
838 if (fTrackContainer.MainListsNOTEmpty()) {
842 for (; it != end; ++it) {
843 fpTrackingManager->EndTrackingWOKill(*it);
847 if (fTrackContainer.SecondaryListsNOTEmpty())
853 for (; it != end; ++it) {
854 fpTrackingManager->EndTrackingWOKill(*it);