Geant4  10.02.p02
G4Scheduler.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4Scheduler.cc 60494 2012-07-12 14:49:30Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 #include <G4AllITFinder.hh>
37 #include <G4Scheduler.hh>
38 #include <G4SchedulerMessenger.hh>
39 
40 #include "G4SystemOfUnits.hh"
41 #include "G4ITModelProcessor.hh"
42 #include "G4ITStepProcessor.hh"
43 #include "G4IT.hh"
44 #include "G4ITReactionChange.hh"
45 #include "G4ITModelHandler.hh"
46 #include "G4VITStepModel.hh"
47 #include "G4UserTimeStepAction.hh"
48 #include "G4ITTrackingManager.hh"
50 #include "G4TrackingInformation.hh"
51 #include "G4UnitsTable.hh"
52 #include "G4ITStepStatus.hh"
53 #include "G4ITGun.hh"
54 #include "G4StateManager.hh"
55 #include "G4Timer.hh"
56 #include "G4IosFlagsSaver.hh"
57 #include <sstream>
58 
59 //#include "G4Phenomenon.hh"
60 //#include "G4MIWorkspace.hh"
61 
62 //#define DEBUG_MEM 1
63 #define DEBUG_MEM_STEPPING
64 #define DEBUG_MEM_DETAILED_STEPPING
65 //#define DEBUG_MEM_DOIT
66 
67 #ifdef DEBUG_MEM
68 #include "G4MemStat.hh"
69 using namespace G4MemStat;
70 using G4MemStat::MemStat;
71 #endif
72 
73 //COLOR FOR DEBUGING
74 //#define USE_COLOR 1
75 
76 #ifdef USE_COLOR
77 #define RED "\033[0;31m"
78 #define LIGHT_RED "\33[1;31m"
79 #define GREEN "\033[32;40m"
80 #define GREEN_ON_BLUE "\033[1;32;44m"
81 #define RESET_COLOR "\033[0m"
82 #else
83 #define RED ""
84 #define LIGHT_RED ""
85 #define GREEN ""
86 #define GREEN_ON_BLUE ""
87 #define RESET_COLOR ""
88 #endif
89 
90 using namespace std;
91 
93 
94 template<typename T>
95  inline bool IsInf(T value)
96  {
97  return std::numeric_limits<T>::has_infinity
98  && value == std::numeric_limits<T>::infinity();
99  }
100 //_________________________________________________________________________
101 
103 {
104  if(fgScheduler == 0) fgScheduler = new G4Scheduler();
105  return fgScheduler;
106 }
107 //_________________________________________________________________________
108 
110 {
111  if(requestedState == G4State_Quit)
112  {
113  if(fVerbose >= 4)
114  {
115  G4cout << "G4Scheduler received G4State_Quit" << G4endl;
116  }
117  Clear();
118  //DeleteInstance();
119  }
120  return true;
121 }
122 //_________________________________________________________________________
123 
125 {
126  if(fgScheduler)
127  {
128  delete fgScheduler;
129  }
130 }
131 //_________________________________________________________________________
132 
135  fTrackContainer((G4ITTrackHolder&) *G4ITTrackHolder::Instance())
136 {
137  Create();
138 }
139 
141 {
142  fUseDefaultTimeSteps = true;
143  fUserUpperTimeLimit = -1;
144  fpGun = 0;
145  fContinue = true;
146 // fpMainList = 0;
147 // fpWaitingList = 0;
149 
151 
152  fpUserTimeSteps = 0;
153 
154  fTimeStep = DBL_MAX;
158 
159  fZeroTimeCount = 0;
161 
162  fStartTime = 0;
164  fEndTime = 1 * microsecond;
165  fGlobalTime = -1;
166  fInteractionStep = true;
167  fUsePreDefinedTimeSteps = false;
168 
170 
171  fpStepProcessor = 0;
172  fpModelProcessor = 0;
173 
174  fNbSteps = 0;
175  fMaxSteps = -1;
176 
177  fRunning = false;
178  fInitialized = false;
179 
183 
184  fVerbose = 0;
185  fWhyDoYouStop = false;
186  fDefinedMinTimeStep = -1.;
187  fReachedUserTimeLimit = false;
188  fStopTime = -1.;
189  fTmpGlobalTime = -1.;
190 
191  fpMessenger = new G4SchedulerMessenger(this);
192 
195 
197 }
198 
199 //_________________________________________________________________________
200 
202 {
203 
204  if(fpMessenger) // is used as a flag to know whether the manager was cleared
205  {
206  Clear();
207  }
208 
209  fgScheduler = 0;
210 
211 // if (fVerbose >= 1)
212 // {
213 // G4cout << "G4Scheduler is being deleted. Bye :) !" << G4endl;
214 // }
215 }
216 
218 {
219 // if (fVerbose) G4cout << "*** G4Scheduler is being cleared ***" << G4endl;
220 
221  if(fpMessenger)
222  {
223  delete fpMessenger;
224  fpMessenger = 0;
225  }
226  if(fpStepProcessor)
227  {
228  delete fpStepProcessor;
229  fpStepProcessor = 0;
230  }
231  if(fpModelProcessor)
232  {
233  delete fpModelProcessor;
234  fpModelProcessor = 0;
235  }
236 
238  ClearList();
240  {
241  delete fpTrackingManager;
242  fpTrackingManager = 0;
243  }
244 
245  if(fReactionSet)
246  {
247  delete fReactionSet;
248  fReactionSet = 0;
249  }
250 
251  if(fpModelHandler)
252  {
253  delete fpModelHandler;
254  fpModelHandler = 0;
255  }
256 
257  //* DEBUG
258  //* assert(G4StateManager::GetStateManager()->
259  //* DeregisterDependent(this) == true);
260 
261 }
262 
263 //_________________________________________________________________________
264 
266 {
267 // if (fNbTracks == 0) return;
268 
270 
272 }
273 
274 //_________________________________________________________________________
276 {
277  fpModelHandler->RegisterModel(model, time);
278 }
279 
280 //_________________________________________________________________________
281 
283 {
284  if(fpStepProcessor)
285  {
286  delete fpStepProcessor;
287  }
288  if(fpModelProcessor)
289  {
290  delete fpModelProcessor;
291  }
292  // if(fpMasterModelProcessor)
293  // {
294  // delete fpMasterModelProcessor;
295  // }
296 
297  //______________________________________________________________
298 
302 
303  // fpMasterModelProcessor = new G4ITModelProcessor();
304  // fpMasterModelProcessor->SetModelHandler(fpModelHandler);
305  // fpModelProcessor = fpMasterModelProcessor;
306 
307  //______________________________________________________________
308 
311 
313 
314  // fpMasterStepProcessor = new G4ITStepProcessor();
315  // fpMasterStepProcessor->SetTrackingManager(fpTrackingManager);
316  // fpStepProcessor = fpMasterStepProcessor ;
317  //______________________________________________________________
318 
320  {
321  if(fpUserTimeSteps == 0) // Extra checking, is it necessary ?
322  {
323  G4ExceptionDescription exceptionDescription;
324  exceptionDescription
325  << "You are asking to use user defined steps but you did not give any.";
326  G4Exception("G4Scheduler::FindUserPreDefinedTimeStep",
327  "Scheduler004",
329  exceptionDescription);
330  return; // makes coverity happy
331  }
332  }
333 
334 // if (fComputeTimeStep)
335 // {
336 // if (fpModelProcessor == 0)
337 // {
338 // G4ExceptionDescription exceptionDescription;
339 // exceptionDescription
340 // << "There is no G4ITModelProcessor to handle IT reaction. ";
341 // exceptionDescription
342 // << "You probably did not initialize the G4Scheduler. ";
343 // exceptionDescription
344 // << "Just do G4Scheduler::Instance()->Initialize(); ";
345 // exceptionDescription << " but only after initializing the run manager.";
346 // G4Exception("G4Scheduler::CalculateMinStep", "ITScheduler005",
347 // FatalErrorInArgument, exceptionDescription);
348 // return; // makes coverity happy
349 // }
350 // }
351 
352  fInitialized = true;
353 }
354 
355 //_________________________________________________________________________
356 
358 {
359  fStartTime = 0;
360  fUserUpperTimeLimit = -1;
361  fTimeStep = DBL_MAX;
365  fGlobalTime = -1;
366  fInteractionStep = true;
368  fZeroTimeCount = 0;
369 
370  fNbSteps = 0;
371  fContinue = true;
372  // fReactingTracks.clear();
374 }
375 //_________________________________________________________________________
376 
378 {
379 
380 #ifdef G4VERBOSE
381  if(fVerbose)
382  {
383  G4cout << "*** G4Scheduler starts processing " << G4endl;
384  if(fVerbose > 2)
385  G4cout << "___________________________________________"
386  "___________________________" << G4endl;
387  }
388 #endif
389 
390  if (fInitialized == false) Initialize();
391 
392  // fpTrackingManager->Initialize();
395 
396  // TODO
397  // fpMasterModelProcessor->Initialize();
398  // fpMasterStepProcessor->Initialize();
399 
400  if (fpGun) fpGun->DefineTracks();
401 
403 
404  // ___________________
405  fRunning = true;
406  Reset();
407 
409 
410 #ifdef G4VERBOSE
411  G4bool trackFound = false;
412 #endif
413 
414  //===========================================================================
415  // By default, before the G4Scheduler is launched, the tracks are pushed to
416  // the delayed lists
417  //===========================================================================
418 
420  {
422 #ifdef G4VERBOSE
423  trackFound = true;
424  G4Timer localtimer;
425  if(fVerbose>1)
426  {
427  localtimer.Start();
428  }
429 #endif
431 #ifdef G4VERBOSE
432  if(fVerbose>1)
433  {
434  localtimer.Stop();
435  G4cout << "G4Scheduler: process time= "<< localtimer << G4endl;
436  }
437 #endif
438  }
439 
440 // //---------------------------------
441 // // TODO: This could be removed ?
442 // if(fTrackContainer.MainListsNOTEmpty()
443 // && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
444 // && fGlobalTime < fEndTime
445 // && fContinue == true)
446 //{
447 //#ifdef G4VERBOSE
448 // trackFound = true;
449 //#endif
450 // DoProcess();
451 //}
452 // //---------------------------------
453 
454 #ifdef G4VERBOSE
455  if(fVerbose)
456  {
457  if(trackFound)
458  {
459  G4cout << "*** G4Scheduler ends at time : "
460  << G4BestUnit(fGlobalTime,"Time") << G4endl;
461  G4cout << "___________________________________" << G4endl;
462  }
463  else
464  {
465  G4cout << "*** G4Scheduler did not start because no "
466  "track was found to be processed"<< G4endl;
467  G4cout << "___________________________________" << G4endl;
468  }
469  }
470 #endif
471 
472  fRunning = false;
473 
475 
476  // ___________________
477  EndTracking();
478  ClearList();
479 
480  Reset();
481 
483 }
484 
485 //_________________________________________________________________________
486 
488 {
489  std::set<double>::const_iterator up = fWatchedTimes.upper_bound(fGlobalTime);
490  if(up == fWatchedTimes.end()) return DBL_MAX;
491  return *up;
492 }
493 
494 //_________________________________________________________________________
495 
497 {
498 // if(fTrackContainer.WaitingListsNOTEmpty())
499 // {
500 // G4ExceptionDescription exceptionDescription;
501 // exceptionDescription
502 // << "There is a waiting track list (fpWaitingList != 0).";
503 // exceptionDescription
504 // << " When G4Scheduler::SynchronizeTracks() is called, ";
505 // exceptionDescription
506 // << "no more tracks should remain in the fpWaitingList.";
507 // G4Exception("G4Scheduler::SynchronizeTracks", "ITScheduler002",
508 // FatalErrorInArgument, exceptionDescription);
509 // }
510 
511  // Backup main list and time feature
512  // Reminder : the main list here, should
513  // have the biggest global time
514  // fTrackContainer.MoveMainToWaitingList();
515  // TODO: not yet supported
516 
518  //fTmpEndTime = fEndTime;
519 
521  G4double tmpGlobalTime = fGlobalTime;
522 
523  double nextWatchedTime = -1;
524  bool carryOn = true;
525 
526  while(fTrackContainer.MergeNextTimeToMainList(tmpGlobalTime) && carryOn)
527  {
528 // assert(tmpGlobalTime == fGlobalTime);
530  while((nextWatchedTime = GetNextWatchedTime()) < fTrackContainer.GetNextTime()
531  && (carryOn = CanICarryOn()))
532  {
533  fStopTime = min(nextWatchedTime, fEndTime);
534  DoProcess();
535  }
536 
537  carryOn = CanICarryOn();
538 
539  if(nextWatchedTime > fEndTime && carryOn)
540  {
542  DoProcess();
543  }
544  }
545 }
546 
547 //_________________________________________________________________________
548 
550 {
551  return fGlobalTime < fEndTime && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
552  && fContinue == true;
553 }
554 
555 //_________________________________________________________________________
556 
558 {
559 #ifdef G4VERBOSE
560  if(fWhyDoYouStop)
561  {
562  G4cout << "G4Scheduler has reached a stage: it might be"
563  " a transition or the end"
564  << G4endl;
565 
566  G4bool normalStop = false;
567 
568  if(fGlobalTime >= fStopTime)
569  {
570  G4cout << "== G4Scheduler: I stop because I reached the stop time : "
571  << G4BestUnit(fStopTime,"Time") << " =="<< G4endl;
572  normalStop = true;
573  }
574  if(fTrackContainer.MainListsNOTEmpty() == false) // is empty
575  {
576  G4cout << "G4Scheduler: I stop because the current main list of tracks "
577  "is empty"
578  << G4endl;
579  normalStop = true;
580  }
581  if(fMaxSteps == -1 ? false : fNbSteps >= fMaxSteps)
582  {
583  G4cout << "G4Scheduler: I stop because I reached the maximum allowed "
584  "number of steps=" << fMaxSteps
585  << G4endl;
586  normalStop = true;
587  }
588  if(fContinue && normalStop == false)
589  {
590  G4cout << "G4Scheduler: It might be that I stop because "
591  "I have been told so. You may check "
592  "member fContinue and usage of the method G4Scheduler::Stop()."
593  << G4endl;
594  }
595  }
596 #endif
597 }
598 
599 //_________________________________________________________________________
600 
602 // We split it from the Process() method to avoid repeating code in SynchronizeTracks
603 {
605 
606 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
607  MemStat mem_first, mem_second, mem_diff;
608 #endif
609 
610 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
611  mem_first = MemoryUsage();
612 #endif
613 
614  while (fGlobalTime < fStopTime
616  && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps)
617  && fContinue == true)
618  {
619 // G4cout << "Mainlist size : " << fTrackContainer.GetMainList()->size()
620 // << G4endl;
621 
622  Stepping();
623 
624 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
625  mem_second = MemoryUsage();
626  mem_diff = mem_second-mem_first;
627  G4cout << "\t || MEM || After step " << fNbSteps << ", diff is : "
628  << mem_diff << G4endl;
629 #endif
630  }
631 
633 
634 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING)
635  mem_second = MemoryUsage();
636  mem_diff = mem_second-mem_first;
637  G4cout << "\t || MEM || After stepping, diff is : " << mem_diff << G4endl;
638 #endif
639 
640 #ifdef G4VERBOSE
641  if(fVerbose > 2)
642  G4cout << "*** G4Scheduler has finished processing a track list at time : "
643  << G4BestUnit(fGlobalTime, "Time") << G4endl;
644 #endif
645 }
646 //_________________________________________________________________________
647 
649 {
650  G4IosFlagsSaver iosfs(G4cout);
652 
655 
656  fInteractionStep = false;
657  fReachedUserTimeLimit = false;
658 
660 
661  // Start of step
662 #ifdef G4VERBOSE
663  if (fVerbose > 2)
664  {
665 #ifdef USE_COLOR
666  G4cout << LIGHT_RED;
667 #endif
668  G4cout << "*** Start Of Step N°" << fNbSteps + 1 << " ***" << G4endl;
669  G4cout << "Current Global time : " << G4BestUnit(fGlobalTime, "Time")
670  <<G4endl;
671 #ifdef USE_COLOR
672  G4cout << RESET_COLOR;
673 #endif
674  }
675 #endif
676 
677 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
678  MemStat mem_first, mem_second, mem_diff;
679 #endif
680 
681 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
682  mem_first = MemoryUsage();
683 #endif
684 
686 
688  {
689 #ifdef G4VERBOSE
690  if (fVerbose > 2)
691  {
692 #ifdef USE_COLOR
693  G4cout << LIGHT_RED;
694 #endif
695  G4cout << "*** At time : " << G4BestUnit(fGlobalTime, "Time")
696  << " the chosen user time step is : "
697  << G4BestUnit(fDefinedMinTimeStep, "Time") << " ***" << G4endl;
698 #ifdef USE_COLOR
699  G4cout << RESET_COLOR;
700 #endif
701  }
702 #endif
703  }
704 
705  if (fpModelProcessor->GetComputeTimeStep()) // fComputeTimeStep)
706  {
709  // => at least N (N = nb of tracks) loops
710  }
711  else if(fUseDefaultTimeSteps)
712  {
714  }
715 
716 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
717  mem_second = MemoryUsage();
718  mem_diff = mem_second-mem_first;
719  G4cout << "|| MEM || After computing TS, diff is : " << mem_diff << G4endl;
720 #endif
721 
722 #ifdef G4VERBOSE
723  if (fVerbose > 2)
724  {
725 #ifdef USE_COLOR
726  G4cout << LIGHT_RED;
727 #endif
728  G4cout << "*** Time stepper returned : " << G4BestUnit(fTSTimeStep, "Time")
729  << " ***" << G4endl;
730 #ifdef USE_COLOR
731  G4cout << RESET_COLOR;
732 #endif
733  }
734 #endif
735 
736 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
737  mem_first = MemoryUsage();
738 #endif
739 
740  // Call IL even if fTSTimeStep == 0
741  // if fILTimeStep == 0 give the priority to DoIt processes
742 
743  fILTimeStep =
745  // => at least N loops
746  // All process returns the physical step of interaction
747  // The transportation process calculates the corresponding
748  // time step
749 
750 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
751  mem_second = MemoryUsage();
752  mem_diff = mem_second-mem_first;
753  G4cout << "|| MEM || After IL, diff is : " << mem_diff << G4endl;
754 #endif
755 
756 #ifdef G4VERBOSE
757  if (fVerbose > 2)
758  {
759 #ifdef USE_COLOR
760  G4cout << LIGHT_RED;
761 #endif
762  G4cout << "*** The minimum time returned by the processes is : "
763  << G4BestUnit(fILTimeStep, "Time") << " ***" << G4endl;
764 #ifdef USE_COLOR
765  G4cout << RESET_COLOR;
766 #endif
767  }
768 #endif
769 
770 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
771  mem_first = MemoryUsage();
772 #endif
773 
774  if (fILTimeStep <= fTSTimeStep)
775  // Give the priority to the IL
776  {
777  fInteractionStep = true;
782  }
783  else
784  {
785  fInteractionStep = false;
789  }
790 
792  // This check is done at every time step
793  {
795  fITStepStatus = eInteractionWithMedium; // ie: transportation
796  fInteractionStep = true;
799  }
800 
801  if (fTimeStep == 0) // < fTimeTolerance)
802  {
803  ++fZeroTimeCount;
805  {
806  G4ExceptionDescription exceptionDescription;
807 
808  exceptionDescription << "Too many zero time steps were detected. ";
809  exceptionDescription << "The simulation is probably stuck. ";
810  exceptionDescription
811  << "The maximum number of zero time steps is currently : "
813  exceptionDescription << ".";
814 
815  G4Exception("G4Scheduler::Stepping",
816  "SchedulerNullTimeSteps",
818  exceptionDescription);
819  }
820  }
821  else
822  {
823  fZeroTimeCount = 0;
824  }
825 
827  ((fTimeStep <= fDefinedMinTimeStep) || ((fTimeStep > fDefinedMinTimeStep)
829  true : false;
830 
832  // TODO: pre/post
833 
834 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
835  mem_second = MemoryUsage();
836  mem_diff = mem_second-mem_first;
837  G4cout << "|| MEM || After LeadingTracks and UserPreTimeStepAction: "
838  << mem_diff << G4endl;
839 #endif
840 
841 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
842  mem_first = MemoryUsage();
843 #endif
844 
845 
847 
848  // if fTSTimeStep > 0 => still need to call the transportation process
849  // if fILTimeStep < fTSTimeStep => call only DoIt processes, no reactions
850  // if fILTimeStep == fTSTimeStep => give the priority to the DoIt processes
851  if (fTSTimeStep > 0 || fILTimeStep <= fTSTimeStep)
852  {
853  // G4cout << "Will call DoIT" << G4endl;
855  // fTrackContainer.MergeSecondariesWithMainList();
856  // fTrackContainer.KillTracks(); // remove ?
857  }
858  // else
859  // {
860  // G4cout << "fTSTimeStep : " << fTSTimeStep << G4endl;
861  // G4cout << "fILTimeStep : " << fILTimeStep << G4endl;
862  // }
863 
864 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
865  mem_second = MemoryUsage();
866  mem_diff = mem_second-mem_first;
867  G4cout << "|| MEM || After DoIT, diff is : " << mem_diff << G4endl;
868 #endif
869 
870 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
871  mem_first = MemoryUsage();
872 #endif
873 
875  fGlobalTime,
876  fTimeStep,
881  fVerbose);
882 
883  ++fNbSteps;
884 
886  {
888  }
889 
891 
892 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING)
893  mem_second = MemoryUsage();
894  mem_diff = mem_second-mem_first;
895  G4cout << "|| MEM || After computing reactions + UserPostTimeStepAction, "
896  "diff is : " << mem_diff << G4endl;
897 #endif
898 
899  // End of step
900 #ifdef G4VERBOSE
901  if (fVerbose >= 2)
902  {
903 #ifdef USE_COLOR
904  G4cout << LIGHT_RED;
905 #endif
906 
907  G4String interactionType;
908  GetCollisionType(interactionType);
909 
910  std::stringstream finalOutput;
911 
912  finalOutput << "*** End of step N°" << fNbSteps
913  << "\t T_i= " << G4BestUnit(fGlobalTime-fTimeStep, "Time")
914  << "\t dt= " << G4BestUnit(fTimeStep, "Time")
915  << "\t T_f= " << G4BestUnit(fGlobalTime, "Time")
916  << "\t " << interactionType
917  << G4endl;
918 
919  if(fVerbose>2)
920  {
922  {
923  finalOutput << "It has also reached the user time limit" << G4endl;
924  }
925  finalOutput << "_______________________________________________________________"
926  "_______"<< G4endl;
927  }
928 
929  G4cout << finalOutput.str();
930 
931 #ifdef USE_COLOR
932  G4cout << RESET_COLOR;
933 #endif
934  }
935 #endif
936 
937 }
938 //_________________________________________________________________________
939 
941 {
942  if (fpUserTimeSteps == 0) return fDefaultMinTimeStep;
944  return fDefinedMinTimeStep;
945 
946  map<double, double>::const_iterator it_fpUserTimeSteps_i = fpUserTimeSteps
947  ->upper_bound(fGlobalTime);
948  map<double, double>::const_iterator it_fpUserTimeSteps_low = fpUserTimeSteps
949  ->lower_bound(fGlobalTime);
950 
951  // DEBUG
952  // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time")
953  // << G4endl;
954  // G4cout << "fpUserTimeSteps_i : "
955  // <<"<"<<G4BestUnit(it_fpUserTimeSteps->first,"Time")
956  // <<", "<< G4BestUnit(it_fpUserTimeSteps->second,"Time")<<">"
957  // << "\t fpUserTimeSteps_low : "
958  // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "*
959  // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">"
960  // << G4endl;
961 
962  if (it_fpUserTimeSteps_i == fpUserTimeSteps->end())
963  {
964  it_fpUserTimeSteps_i--;
966  }
967  else if (fabs(fGlobalTime - it_fpUserTimeSteps_low->first) < fTimeTolerance)
968  {
969  // Case : fGlobalTime = X picosecond
970  // and fpUserTimeSteps_low->first = X picosecond
971  // but the precision is not good enough
972  it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
973  map<double, double>::const_iterator tmp_it = it_fpUserTimeSteps_low;
974  ++tmp_it;
975  if (tmp_it == fpUserTimeSteps->end())
976  {
978  }
979  else
980  {
981  fUserUpperTimeLimit = tmp_it->first;
982  }
983  }
984  else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low)
985  {
986  // "Normal" cases
987  fUserUpperTimeLimit = it_fpUserTimeSteps_i->first;
988 // it_fpUserTimeSteps_i++;
989 // G4cout << "Global time = " << fGlobalTime << G4endl;
990 // G4cout << "Is begin = "
991 // << (it_fpUserTimeSteps_i == fpUserTimeSteps->begin())<< G4endl;
992 
993  if(it_fpUserTimeSteps_i != fpUserTimeSteps->begin()) it_fpUserTimeSteps_i--;
994  }
995  else
996  {
997  fUserUpperTimeLimit = it_fpUserTimeSteps_i->first;
998  it_fpUserTimeSteps_i = it_fpUserTimeSteps_low;
999  }
1000 
1001  return it_fpUserTimeSteps_i->second;
1002 }
1003 
1004 //_________________________________________________________________________
1005 
1007 {
1008 
1009  if(fpUserTimeSteps == 0)
1010  {
1011  G4ExceptionDescription exceptionDescription;
1012  exceptionDescription
1013  << "You are asking to use user defined steps but you did not give any.";
1014  G4Exception("G4Scheduler::FindUserPreDefinedTimeStep",
1015  "Scheduler004",
1017  exceptionDescription);
1018  return; // makes coverity happy
1019  }
1020  map<double, double>::iterator fpUserTimeSteps_i =
1021  fpUserTimeSteps->upper_bound(fGlobalTime);
1022  map<double, double>::iterator fpUserTimeSteps_low = fpUserTimeSteps
1023  ->lower_bound(fGlobalTime);
1024 
1025  // DEBUG
1026  // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time") << G4endl;
1027  // G4cout << "fpUserTimeSteps_i : "
1028  // <<"<"<<G4BestUnit(fpUserTimeSteps_i->first,"Time")<<", "
1029  // << G4BestUnit(fpUserTimeSteps_i->second,"Time")<<">"
1030  // << "\t fpUserTimeSteps_low : "
1031  // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "
1032  // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">"
1033  // << G4endl;
1034 
1035  if(fpUserTimeSteps_i == fpUserTimeSteps->end())
1036  {
1037  fpUserTimeSteps_i--;
1038  }
1039  else if(fabs(fGlobalTime - fpUserTimeSteps_low->first) < fTimeTolerance)
1040  {
1041  // Case : fGlobalTime = X picosecond
1042  // and fpUserTimeSteps_low->first = X picosecond
1043  // but the precision is not good enough
1044  fpUserTimeSteps_i = fpUserTimeSteps_low;
1045  }
1046  else if(fpUserTimeSteps_i == fpUserTimeSteps_low)
1047  {
1048  // "Normal" cases
1049  fpUserTimeSteps_i--;
1050  }
1051  else
1052  {
1053  fpUserTimeSteps_i = fpUserTimeSteps_low;
1054  }
1055 
1056  fDefinedMinTimeStep = fpUserTimeSteps_i->second;
1057 }
1058 
1059 //_________________________________________________________________________
1060 
1062 {
1063  if(fRunning)
1064  {
1065  G4ExceptionDescription exceptionDescription;
1066  exceptionDescription
1067  << "End tracking is called while G4Scheduler is still running."
1068  << G4endl;
1069 
1070  G4Exception("G4Scheduler::EndTracking",
1071  "Scheduler017",
1073  exceptionDescription);
1074  }
1075 
1077 
1079  {
1081  G4TrackManyList::iterator it = mainList->begin();
1082  G4TrackManyList::iterator end = mainList->end();
1083  for (; it != end; ++it)
1084  {
1086  }
1087  }
1088 
1089  if (fTrackContainer.SecondaryListsNOTEmpty()) // should be empty
1090  {
1092  G4TrackManyList::iterator it = secondaries->begin();
1093  G4TrackManyList::iterator end = secondaries->end();
1094 
1095  for (; it != end; ++it)
1096  {
1098  }
1099  }
1100 }
1101 
1102 //_________________________________________________________________________
1104 {
1105  fpTrackingInteractivity = interactivity;
1106  if(fpTrackingManager)
1107  {
1109  }
1110 
1111  //G4MIWorkspace::GetWorldWorkspace()->SetTrackingInteractivity(interactivity);
1112 }
1113 
1114 //_________________________________________________________________________
1116 {
1117  fInitialized = false;
1118  Initialize();
1119 }
1120 
1121 //_________________________________________________________________________
1124  fTrackContainer((G4ITTrackHolder&) *G4ITTrackHolder::Instance())
1125 
1126 {
1127  Create();
1128 }
1129 
1130 //_________________________________________________________________________
1132 {
1133  if(this != &right)
1134  {
1135  Create();
1136  }
1137  return *this;
1138 }
1139 
1141 {
1142  return fTrackContainer.GetNTracks();
1143 }
1144 //_________________________________________________________________________
1145 
1147 {
1148  switch(fITStepStatus)
1149  {
1151  interactionType = "eInteractionWithMedium";
1152  break;
1154  interactionType = "eCollisionBetweenTracks";
1155  break;
1156  default:
1157  interactionType = "eCollisionBetweenTracks";
1158  break;
1159  }
1160 }
G4ITModelHandler holds for two IT types the corresponding model manager.
void RegisterModel(G4VITStepModel *aModel, const G4double globalTime)
G4bool fUseDefaultTimeSteps
Definition: G4Scheduler.hh:232
void Process()
Definition: G4Scheduler.cc:377
std::map< double, double > * fpUserTimeSteps
Definition: G4Scheduler.hh:249
G4ITReactionSet * fReactionSet
Definition: G4Scheduler.hh:266
Its role is the same as G4StepManager :
bool fInteractionStep
Definition: G4Scheduler.hh:277
virtual void DefineTracks()
Definition: G4ITGun.hh:56
void MergeSecondariesWithMainList()
virtual size_t GetNTracks()
void FindUserPreDefinedTimeStep()
The G4ITModelProcessor will call the two processes defined in G4VITModel.
void EndTracking()
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:109
G4TrackManyList * GetSecondariesList()
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetTrackingManager(G4ITTrackingManager *trackingManager)
void SetTrackingManager(G4ITTrackingManager *trackMan)
bool fReachedUserTimeLimit
Definition: G4Scheduler.hh:254
void PrintWhyDoYouStop()
Definition: G4Scheduler.cc:557
double fTSTimeStep
Definition: G4Scheduler.hh:271
void Clear(Node *)
Define what to do before stepping and after stepping.
virtual ~G4Scheduler()
Definition: G4Scheduler.cc:201
void SynchronizeTracks()
Definition: G4Scheduler.cc:496
double fMaxTimeStep
Definition: G4Scheduler.hh:244
double fPreviousTimeStep
Definition: G4Scheduler.hh:239
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
double fStopTime
Definition: G4Scheduler.hh:237
G4ITStepStatus fITStepStatus
Definition: G4Scheduler.hh:229
#define G4ThreadLocal
Definition: tls.hh:89
bool IsInf(T value)
Definition: G4Scheduler.cc:95
int fMaxNZeroTimeStepsAllowed
Definition: G4Scheduler.hh:241
double fILTimeStep
Definition: G4Scheduler.hh:273
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:102
MemStat MemoryUsage()
Definition: G4MemStat.cc:55
G4double CalculateMinTimeStep(G4double currentGlobalTime, G4double definedMinTimeStep)
static G4ITTypeManager * Instance()
Definition: G4ITType.cc:58
static G4ThreadLocal G4Scheduler * fgScheduler
Definition: G4Scheduler.hh:219
static G4ITReactionSet * Instance()
G4ITGun * fpGun
Definition: G4Scheduler.hh:281
static const double microsecond
Definition: G4SIunits.hh:159
bool fUsePreDefinedTimeSteps
Definition: G4Scheduler.hh:247
virtual void UserPostTimeStepAction()
void EndTrackingWOKill(G4Track *)
bool fInitialized
Definition: G4Scheduler.hh:222
G4GLOB_DLL std::ostream G4cout
double fUserUpperTimeLimit
Definition: G4Scheduler.hh:251
static void DeleteInstance()
#define RESET_COLOR
Definition: G4Scheduler.cc:87
void Clear()
Definition: G4Scheduler.cc:217
virtual void UserPreTimeStepAction()
In this method, the user can use : G4Scheduler::Instance()->GetGlobalTime(), to know the current simu...
void DoIt(double timeStep)
bool G4bool
Definition: G4Types.hh:79
G4ITStepManager enables to synchronize in time the step of tracks.
Definition: G4Scheduler.hh:94
G4ITTrackingManager * fpTrackingManager
Definition: G4Scheduler.hh:264
double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:940
void ForceReinitialization()
void ClearList()
Definition: G4Scheduler.cc:265
double fEndTime
Definition: G4Scheduler.hh:238
bool MergeNextTimeToMainList(double &time)
G4ITModelProcessor * fpModelProcessor
Definition: G4Scheduler.hh:263
G4SchedulerMessenger * fpMessenger
Definition: G4Scheduler.hh:217
bool SecondaryListsNOTEmpty()
double fTimeTolerance
Definition: G4Scheduler.hh:233
void Create()
Definition: G4Scheduler.cc:140
static void DeleteInstance()
DeleteInstance should be used instead of the destructor.
Definition: G4Scheduler.cc:124
bool CanICarryOn()
Definition: G4Scheduler.cc:549
void ReserveRessource()
Definition: G4ITType.cc:77
G4ITModelHandler * fpModelHandler
Definition: G4Scheduler.hh:268
virtual size_t GetNTracks()
G4ITStepProcessor * fpStepProcessor
Definition: G4Scheduler.hh:262
double GetNextWatchedTime() const
Definition: G4Scheduler.cc:487
double fTimeStep
Definition: G4Scheduler.hh:243
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual void Initialize()
double fStartTime
Definition: G4Scheduler.hh:236
G4double ComputeInteractionLength(double previousTimeStep)
G4ITTrackingInteractivity * fpTrackingInteractivity
Definition: G4Scheduler.hh:265
bool fWhyDoYouStop
Definition: G4Scheduler.hh:221
G4UserTimeStepAction * fpUserTimeStepAction
Definition: G4Scheduler.hh:258
void ReleaseRessource()
Definition: G4ITType.cc:83
void Stop()
std::set< double > fWatchedTimes
Definition: G4Scheduler.hh:256
void CleanAllReaction()
double fDefinedMinTimeStep
Definition: G4Scheduler.hh:252
G4bool fContinue
Definition: G4Scheduler.hh:224
void ComputeTrackReaction(G4ITStepStatus fITStepStatus, G4double fGlobalTime, G4double currentTimeStep, G4double previousTimeStep, G4bool reachedUserTimeLimit, G4double fTimeTolerance, G4UserTimeStepAction *fpUserTimeStepAction, G4int fVerbose)
T min(const T t1, const T t2)
brief Return the smallest of the two arguments
void Reset()
Definition: G4Scheduler.cc:357
G4Scheduler & operator=(const G4Scheduler &)
virtual void RegisterModel(G4VITStepModel *, double)
Definition: G4Scheduler.cc:275
#define G4endl
Definition: G4ios.hh:61
double fDefaultMinTimeStep
Definition: G4Scheduler.hh:248
void SetModelHandler(G4ITModelHandler *)
double fGlobalTime
Definition: G4Scheduler.hh:234
static const double picosecond
Definition: G4SIunits.hh:160
void Start()
G4TrackList * GetMainList(Key)
double G4double
Definition: G4Types.hh:76
void DoProcess()
Definition: G4Scheduler.cc:601
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
int fZeroTimeCount
Definition: G4Scheduler.hh:240
#define DBL_MAX
Definition: templates.hh:83
void Initialize()
Definition: G4Scheduler.cc:282
void Stepping()
Definition: G4Scheduler.cc:648
G4ITTrackHolder & fTrackContainer
Definition: G4Scheduler.hh:267
G4ApplicationState
void SetInteractivity(G4ITTrackingInteractivity *)
double fTmpGlobalTime
Definition: G4Scheduler.hh:235
#define LIGHT_RED
Definition: G4Scheduler.cc:84
virtual void StartProcessing()