276 G4cout <<
"*** G4Scheduler starts processing " <<
G4endl;
278 G4cout <<
"___________________________________________"
279 "___________________________"
287 fpModelProcessor->Initialize();
288 fpStepProcessor->Initialize();
290 if (fpGun !=
nullptr) fpGun->DefineTracks();
292 if (fpTrackingInteractivity !=
nullptr) fpTrackingInteractivity->Initialize();
298 if (fResetScavenger) {
299 if (fpUserScavenger !=
nullptr) {
300 fpUserScavenger->Reset();
304 if (fpUserTimeStepAction !=
nullptr) {
305 fpUserTimeStepAction->StartProcessing();
309 G4bool trackFound =
false;
319 if (fTrackContainer.DelayListsNOTEmpty()) {
320 fStartTime = fTrackContainer.GetNextTime();
332 G4cout <<
"G4Scheduler: process time= " << localtimer <<
G4endl;
340 G4cout <<
"___________________________________" <<
G4endl;
343 G4cout <<
"*** G4Scheduler did not start because no "
344 "track was found to be processed"
346 G4cout <<
"___________________________________" <<
G4endl;
353 if (fpUserTimeStepAction !=
nullptr) {
354 fpUserTimeStepAction->EndProcessing();
361 if (fpTrackingInteractivity !=
nullptr) {
362 fpTrackingInteractivity->Finalize();
381 fGlobalTime = fTrackContainer.GetNextTime();
382 G4double tmpGlobalTime = fGlobalTime;
385 while (fTrackContainer.MergeNextTimeToMainList(tmpGlobalTime) && carryOn) {
386 if (tmpGlobalTime != fGlobalTime) {
387 fGlobalTime = tmpGlobalTime;
389 fStopTime = min(fTrackContainer.GetNextTime(), fEndTime);
393 fStopTime = min(nextWatchedTime, fEndTime);
399 if (nextWatchedTime > fEndTime && carryOn) {
400 fStopTime = min(fTrackContainer.GetNextTime(), fEndTime);
457 if (fpUserTimeStepAction !=
nullptr) fpUserTimeStepAction->NewStage();
459#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
460 MemStat mem_first, mem_second, mem_diff;
463#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
467 while (fGlobalTime < fStopTime && fTrackContainer.MainListsNOTEmpty()
468 && (fMaxSteps == -1 ?
true : fNbSteps < fMaxSteps) && fContinue)
472#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
474 mem_diff = mem_second - mem_first;
475 G4cout <<
"\t || MEM || After step " << fNbSteps <<
", diff is : " << mem_diff <<
G4endl;
481#if defined(DEBUG_MEM) && defined(DEBUG_MEM_STEPPING)
483 mem_diff = mem_second - mem_first;
484 G4cout <<
"\t || MEM || After stepping, diff is : " << mem_diff <<
G4endl;
489 G4cout <<
"*** G4Scheduler has finished processing a track list at time : "
497 fTimeStep = fMaxTimeStep;
502 fInteractionStep =
false;
503 fReachedUserTimeLimit =
false;
513 G4cout <<
"*** Start Of Step N°" << fNbSteps + 1 <<
" species number : " <<
GetNTracks()
522#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
523 MemStat mem_first, mem_second, mem_diff;
526#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
532 if (fUsePreDefinedTimeSteps) {
539 <<
" the chosen user time step is : " <<
G4BestUnit(fDefinedMinTimeStep,
"Time")
548 if (fpModelProcessor->GetComputeTimeStep())
550 fTSTimeStep = fpModelProcessor->CalculateMinTimeStep(fGlobalTime, fDefinedMinTimeStep);
553 else if (fUseDefaultTimeSteps) {
554 fTSTimeStep = fDefinedMinTimeStep;
557#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
559 mem_diff = mem_second - mem_first;
560 G4cout <<
"|| MEM || After computing TS, diff is : " << mem_diff <<
G4endl;
575#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
582 fILTimeStep = fpStepProcessor->ComputeInteractionLength(fPreviousTimeStep);
588#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
590 mem_diff = mem_second - mem_first;
591 G4cout <<
"|| MEM || After IL, diff is : " << mem_diff <<
G4endl;
599 G4cout <<
"*** The minimum time returned by the processes is : "
607#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
611 if (fILTimeStep <= fTSTimeStep)
614 fInteractionStep =
true;
615 fReactionSet->CleanAllReaction();
616 fTimeStep = fILTimeStep;
618 fpStepProcessor->PrepareLeadingTracks();
621 fInteractionStep =
false;
622 fpStepProcessor->ResetLeadingTracks();
623 fTimeStep = fTSTimeStep;
627 if (fGlobalTime + fTimeStep > fStopTime)
630 fTimeStep = fStopTime - fGlobalTime;
632 fInteractionStep =
true;
633 fReactionSet->CleanAllReaction();
634 fpStepProcessor->ResetLeadingTracks();
640 if (fZeroTimeCount >= fMaxNZeroTimeStepsAllowed) {
643 exceptionDescription <<
"Too many zero time steps were detected. ";
644 exceptionDescription <<
"The simulation is probably stuck. ";
645 exceptionDescription <<
"The maximum number of zero time steps is currently : "
646 << fMaxNZeroTimeStepsAllowed;
647 exceptionDescription <<
".";
650 exceptionDescription);
657 fReachedUserTimeLimit = (fTimeStep <= fDefinedMinTimeStep)
658 || ((fTimeStep > fDefinedMinTimeStep)
659 && fabs(fTimeStep - fDefinedMinTimeStep) < fTimeTolerance);
661 if (fpUserTimeStepAction !=
nullptr) fpUserTimeStepAction->UserPreTimeStepAction();
664#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
666 mem_diff = mem_second - mem_first;
667 G4cout <<
"|| MEM || After LeadingTracks and UserPreTimeStepAction: " << mem_diff <<
G4endl;
670#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
674 fGlobalTime += fTimeStep;
679 if (fTSTimeStep > 0 || fILTimeStep <= fTSTimeStep) {
680 fpStepProcessor->DoIt(fTimeStep);
682#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
684 mem_diff = mem_second - mem_first;
685 G4cout <<
"|| MEM || After DoIT, diff is : " << mem_diff <<
G4endl;
688#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
692 fpModelProcessor->ComputeTrackReaction(fITStepStatus, fGlobalTime, fTimeStep, fPreviousTimeStep,
693 fReachedUserTimeLimit, fTimeTolerance,
694 fpUserTimeStepAction, fVerbose);
698 if (fpUserTimeStepAction !=
nullptr) {
699 fpUserTimeStepAction->UserPostTimeStepAction();
702 fPreviousTimeStep = fTimeStep;
704#if defined(DEBUG_MEM) && defined(DEBUG_MEM_DETAILED_STEPPING)
706 mem_diff = mem_second - mem_first;
707 G4cout <<
"|| MEM || After computing reactions + UserPostTimeStepAction, "
722 std::stringstream finalOutput;
724 finalOutput <<
"*** End of step N°" << fNbSteps
725 <<
"\t T_i= " <<
G4BestUnit(fGlobalTime - fTimeStep,
"Time")
727 <<
"\t T_f= " <<
G4BestUnit(fGlobalTime,
"Time") <<
"\t " << interactionType
731 if (fReachedUserTimeLimit) {
732 finalOutput <<
"It has also reached the user time limit" <<
G4endl;
734 finalOutput <<
"_______________________________________________________________"
739 G4cout << finalOutput.str();
751 if (fpUserTimeSteps ==
nullptr)
return fDefaultMinTimeStep;
752 if (fabs(fGlobalTime - fUserUpperTimeLimit) < fTimeTolerance)
return fDefinedMinTimeStep;
754 auto it_fpUserTimeSteps_i = fpUserTimeSteps->upper_bound(fGlobalTime);
755 auto it_fpUserTimeSteps_low = fpUserTimeSteps->lower_bound(fGlobalTime);
757 if (it_fpUserTimeSteps_i == fpUserTimeSteps->end()) {
758 it_fpUserTimeSteps_i--;
759 fUserUpperTimeLimit = fStopTime;
761 else if (fabs(fGlobalTime - it_fpUserTimeSteps_low->first) < fTimeTolerance) {
762 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
763 auto tmp_it = it_fpUserTimeSteps_low;
765 if (tmp_it == fpUserTimeSteps->end()) {
766 fUserUpperTimeLimit = fStopTime;
769 fUserUpperTimeLimit = tmp_it->first;
772 else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low) {
773 fUserUpperTimeLimit = it_fpUserTimeSteps_i->first;
774 if (it_fpUserTimeSteps_i != fpUserTimeSteps->begin()) it_fpUserTimeSteps_i--;
777 fUserUpperTimeLimit = it_fpUserTimeSteps_i->first;
778 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
780 return it_fpUserTimeSteps_i->second;
787 if (fpUserTimeSteps ==
nullptr) {
789 exceptionDescription <<
"You are asking to use user defined steps but you did not give any.";
791 exceptionDescription);
794 auto fpUserTimeSteps_i = fpUserTimeSteps->upper_bound(fGlobalTime);
795 auto fpUserTimeSteps_low = fpUserTimeSteps->lower_bound(fGlobalTime);
797 if (fpUserTimeSteps_i == fpUserTimeSteps->end()) {
800 else if (fabs(fGlobalTime - fpUserTimeSteps_low->first) < fTimeTolerance) {
804 fpUserTimeSteps_i = fpUserTimeSteps_low;
806 else if (fpUserTimeSteps_i == fpUserTimeSteps_low) {
811 fpUserTimeSteps_i = fpUserTimeSteps_low;
814 fDefinedMinTimeStep = fpUserTimeSteps_i->second;
823 exceptionDescription <<
"End tracking is called while G4Scheduler is still running." <<
G4endl;
826 exceptionDescription);
829 while (fTrackContainer.DelayListsNOTEmpty()) {
830 auto nextTime = fTrackContainer.GetNextTime();
831 fTrackContainer.MergeNextTimeToMainList(nextTime);
834 fTrackContainer.MergeSecondariesWithMainList();
836 if (fTrackContainer.MainListsNOTEmpty()) {
840 for (; it != end; ++it) {
841 fpTrackingManager->EndTrackingWOKill(*it);
845 if (fTrackContainer.SecondaryListsNOTEmpty())
851 for (; it != end; ++it) {
852 fpTrackingManager->EndTrackingWOKill(*it);