Geant4  10.01.p03
G4Scheduler.hh
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: G4ITStepManager.hh 60427 2012-07-11 16:34:35Z matkara $
27 //
28 // Author: Mathieu Karamitros, kara@cenbg.in2p3.fr
29 
30 // The code is developed in the framework of the ESA AO7146
31 //
32 // We would be very happy hearing from you, send us your feedback! :)
33 //
34 // In order for Geant4-DNA to be maintained and still open-source,
35 // article citations are crucial.
36 // If you use Geant4-DNA chemistry and you publish papers about your software,
37 // in addition to the general paper on Geant4-DNA:
38 //
39 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178
40 //
41 // we would be very happy if you could please also cite the following
42 // reference papers on chemistry:
43 //
44 // J. Comput. Phys. 274 (2014) 841-882
45 // Prog. Nucl. Sci. Tec. 2 (2011) 503-508
46 
47 #ifndef G4Scheduler_h
48 #define G4Scheduler_h
49 
50 #include <G4VScheduler.hh>
51 #include <vector>
52 #include <map>
53 #include <memory>
54 
55 #include "globals.hh"
56 
57 #include "G4ITModelHandler.hh"
58 #include "G4ITStepStatus.hh"
59 #include "G4ITTrackHolder.hh"
60 #include "G4VStateDependent.hh"
61 #include "G4ITReaction.hh"
62 
64 class G4ITModelProcessor;
65 class G4ITStepProcessor;
66 class G4Track;
70 class G4ITGun;
71 
72 #ifndef compTrackPerID__
73 #define compTrackPerID__
74  struct compTrackPerID
75  {
76  bool operator()(G4Track* rhs, G4Track* lhs) const
77  {
78  return rhs->GetTrackID() < lhs->GetTrackID();
79  }
80  };
81 #endif
82 
83 
88 class G4Scheduler :
89  public G4VScheduler,
90  public G4VStateDependent
91 {
92 protected:
93  virtual ~G4Scheduler();
94 
95 public:
96  static G4Scheduler* Instance();
100  static void DeleteInstance();
101  virtual G4bool Notify(G4ApplicationState requestedState);
102 
103  virtual void RegisterModel(G4VITStepModel*, double);
104 
105  void Initialize();
106  void ForceReinitialization();
107  inline bool IsInitialized();
108  inline bool IsRunning(){return fRunning;}
109  void Reset();
110  void Process();
111  virtual void PushTrack(G4Track*);
112  void ClearList();
113 
114  inline void SetGun(G4ITGun*);
115 
116  inline void Stop();
117  void Clear();
118 
119  // To be called only in UserReactionAction::EndProcessing()
120  // after fRunning flag has been turned off.
121  // This is not done automatically before UserReactionAction::EndProcessing()
122  // is called in case one would like to access some track information
123  void EndTracking();
124 
125  void SetEndTime(const double);
126 
127  inline void SetTimeTolerance(double);
128  // Two tracks below the time tolerance are supposed to be
129  // in the same time slice
130  inline double GetTimeTolerance() const;
131 
132  inline void SetMaxZeroTimeAllowed(int);
133  inline int GetMaxZeroTimeAllowed() const;
134 
136  inline void SetTimeSteps(std::map<double, double>*);
137  inline void AddTimeStep(double, double);
138  inline void SetDefaultTimeStep(double);
139  double GetLimitingTimeStep() const;
140  inline G4int GetNbSteps() const;
141  inline void SetMaxNbSteps(G4int);
142  inline G4int GetMaxNbSteps() const;
143  inline G4double GetStartTime() const;
144  inline G4double GetEndTime() const;
145  virtual inline G4double GetTimeStep() const;
146  inline G4double GetPreviousTimeStep() const;
147  inline G4double GetGlobalTime() const;
148  inline void SetUserAction(G4UserTimeStepAction*);
150 
151  // To use with transportation only, no reactions
152  inline void UseDefaultTimeSteps(G4bool);
154 
155  inline G4bool GetComputeTimeStepFlag() const;
156 
157  inline G4ITStepStatus GetStatus() const;
158 
159  inline void SetVerbose(int);
160  // 1 : Reaction information
161  // 2 : (1) + time step information
162  // 3 : (2) + step info for individual tracks
163  // 4 : (2) + trackList processing info + pushed and killed track info
164  inline int GetVerbose() const;
165 
166  inline void WhyDoYouStop();
167 
170 
171  virtual size_t GetNTracks();
172 
173  void GetCollisionType(G4String& interactionType);
174 
175 protected:
176 
177  void DoProcess();
178  void SynchronizeTracks();
179  void Stepping();
180 
182  void CalculateMinTimeStep();
184  void DoIt();
185  void ComputeTrackReaction();
186 // void MergeSecondariesWithMainList();
187 
189 // void _PushTrack(G4Track*);
190  void PushDelayed(G4Track*, const G4double&);
191 
192  void EndTracking(G4Track*);
193  void KillTracks();
194 
198 
199  void AddTrackID(G4Track*);
200 
201  void ResetLeadingTracks();
202 
203 private:
204  G4Scheduler();
205  void Create();
206  G4Scheduler(const G4Scheduler&);
208 
210 
212  int fVerbose;
215  bool fRunning;
216 
218  int fNbSteps;
220 
222 
223  // Time members
225  double fGlobalTime;
227  double fStartTime;
228  double fEndTime;
229  double fTmpEndTime;
230  // fTmpEndTime : Stores the biggest end time here (for synchronizing tracks)
234 
235  // Flags
238 
239  double fTimeStep; // The selected minimum time step
240 
241  // User steps
244  std::map<double, double>* fpUserTimeSteps;
245  // One can give time steps in respect to the global time
246  mutable double fUserUpperTimeLimit;
248  // selected user time step in respect to the global time
249  bool fReachedUserTimeLimit; // if fMinTimeStep == the user time step
250 
251  double fTSTimeStep;
252  // Time calculated by the time stepper in CalculateMinTimeStep()
253  double fILTimeStep;
254  // Time calculated by the interaction length methods
255  // in ComputeInteractionLength()
256 
257  // std::map<G4Track*, G4TrackVectorHandle, compTrackPerID> fReactingTracks;
259  std::vector<G4Track*> fLeadingTracks;
260 
262  // Flag : if the step is driven by the interaction with the matter and
263  // NOT by the reaction between tracks
264 
266 
269 
271 
275 
279 };
280 
282 {
283  return fInitialized;
284 }
285 
287 {
288  return fpModelHandler;
289 }
290 
291 inline void G4Scheduler::SetEndTime(const double __endtime)
292 {
293  fEndTime = __endtime;
294 }
295 
296 inline
297 void G4Scheduler::SetTimeSteps(std::map<double, double>* steps)
298 {
300  fpUserTimeSteps = steps;
301 }
302 
303 inline void G4Scheduler::AddTimeStep(double startingTime, double timeStep)
304 {
305  if (fpUserTimeSteps == 0)
306  {
307  fpUserTimeSteps = new std::map<double, double>();
309  }
310 
311  (*fpUserTimeSteps)[startingTime] = timeStep;
312 }
313 
315 {
316  return fNbSteps;
317 }
318 
319 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
320 {
321  fMaxSteps = maxSteps;
322 }
323 
325 {
326  return fMaxSteps;
327 }
328 
330 {
331  return fStartTime;
332 }
333 
335 {
336  return fEndTime;
337 }
338 
340 {
341  return fTimeStep;
342 }
343 
344 inline void G4Scheduler::SetDefaultTimeStep(double timeStep)
345 {
346  fDefaultMinTimeStep = timeStep;
347 }
348 
350 {
351  return fGlobalTime;
352 }
353 
354 inline
356 {
357  fpUserTimeStepAction = userITAction;
358 }
359 
361 {
362  return fpUserTimeStepAction;
363 }
364 
365 inline void G4Scheduler::SetVerbose(int verbose)
366 {
367  fVerbose = verbose;
368 }
369 
370 inline int G4Scheduler::GetVerbose() const
371 {
372  return fVerbose;
373 }
374 
375 inline
376 void G4Scheduler::SetMaxZeroTimeAllowed(int maxTimeStepAllowed)
377 {
378  fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
379 }
380 
382 {
384 }
385 
386 inline void G4Scheduler::SetTimeTolerance(double time)
387 {
388  fTimeTolerance = time;
389 }
390 
391 inline double G4Scheduler::GetTimeTolerance() const
392 {
393  return fTimeTolerance;
394 }
395 
397 {
398  return fPreviousTimeStep;
399 }
400 
402 {
403  return fITStepStatus;
404 }
405 
406 inline void G4Scheduler::Stop()
407 {
408  fContinue = false;
409 }
410 
412 {
414 }
415 
416 inline void G4Scheduler::SetGun(G4ITGun* gun)
417 {
418  fpGun = gun;
419 }
420 
422 {
423  return fComputeTimeStep;
424 }
425 
427 {
428  fWhyDoYouStop = true;
429 }
430 
432 {
433  fUseDefaultTimeSteps = flag;
434 }
435 
437 {
438  return (fUseDefaultTimeSteps == false && fUsePreDefinedTimeSteps == false);
439 }
440 
441 #endif
G4ITModelHandler holds for two IT types the corresponding model manager.
G4bool fUseDefaultTimeSteps
Definition: G4Scheduler.hh:278
void Process()
Definition: G4Scheduler.cc:363
std::map< double, double > * fpUserTimeSteps
Definition: G4Scheduler.hh:244
Its role is the same as G4StepManager :
bool fInteractionStep
Definition: G4Scheduler.hh:261
G4UserTimeStepAction * GetUserTimeStepAction() const
Definition: G4Scheduler.hh:360
G4bool GetComputeTimeStepFlag() const
Definition: G4Scheduler.hh:421
virtual size_t GetNTracks()
void FindUserPreDefinedTimeStep()
Definition: G4Scheduler.cc:946
The G4ITModelProcessor will call the two processes defined in G4VITModel.
double GetTimeTolerance() const
Definition: G4Scheduler.hh:391
void EndTracking()
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:125
G4double GetPreviousTimeStep() const
Definition: G4Scheduler.hh:396
void PushSecondaries(G4ITStepProcessor *)
bool fReachedUserTimeLimit
Definition: G4Scheduler.hh:249
bool fComputeTimeStep
Definition: G4Scheduler.hh:236
double fTSTimeStep
Definition: G4Scheduler.hh:251
double fTmpEndTime
Definition: G4Scheduler.hh:229
Define what to do before stepping and after stepping.
virtual ~G4Scheduler()
Definition: G4Scheduler.cc:222
void SetEndTime(const double)
Definition: G4Scheduler.hh:291
G4ITModelHandler * GetModelHandler()
Definition: G4Scheduler.hh:286
G4ITStepStatus
void SynchronizeTracks()
Definition: G4Scheduler.cc:472
double fPreviousTimeStep
Definition: G4Scheduler.hh:231
void SetTimeTolerance(double)
Definition: G4Scheduler.hh:386
G4double GetStartTime() const
Definition: G4Scheduler.hh:329
G4ITStepStatus fITStepStatus
Definition: G4Scheduler.hh:221
#define G4ThreadLocal
Definition: tls.hh:89
int fMaxNZeroTimeStepsAllowed
Definition: G4Scheduler.hh:233
void ComputeTrackReaction()
int G4int
Definition: G4Types.hh:78
double fILTimeStep
Definition: G4Scheduler.hh:253
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:118
virtual void PushTrack(G4Track *)
void KillTracks()
static G4ThreadLocal G4Scheduler * fgScheduler
Definition: G4Scheduler.hh:211
G4ITGun * fpGun
Definition: G4Scheduler.hh:276
bool fUsePreDefinedTimeSteps
Definition: G4Scheduler.hh:242
G4bool AreDefaultTimeStepsUsed()
Definition: G4Scheduler.hh:436
bool fInitialized
Definition: G4Scheduler.hh:214
G4int GetNbSteps() const
Definition: G4Scheduler.hh:314
double fUserUpperTimeLimit
Definition: G4Scheduler.hh:246
G4UserTimeStepAction is used by G4Scheduler.
void Clear()
Definition: G4Scheduler.cc:237
void SetVerbose(int)
Definition: G4Scheduler.hh:365
bool G4bool
Definition: G4Types.hh:79
G4ITStepManager enables to synchronize in time the step of tracks.
Definition: G4Scheduler.hh:88
G4ITTrackingManager * fpTrackingManager
Definition: G4Scheduler.hh:272
void SetGun(G4ITGun *)
Definition: G4Scheduler.hh:416
void ExtractILData(G4ITStepProcessor *)
double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:885
void ForceReinitialization()
void ExtractDoItData(G4ITStepProcessor *)
void ClearList()
Definition: G4Scheduler.cc:280
void AddTrackID(G4Track *)
double fEndTime
Definition: G4Scheduler.hh:228
G4ITModelProcessor * fpModelProcessor
Definition: G4Scheduler.hh:268
void SetUserAction(G4UserTimeStepAction *)
Definition: G4Scheduler.hh:355
G4SchedulerMessenger * fSteppingMsg
Definition: G4Scheduler.hh:209
double fTimeTolerance
Definition: G4Scheduler.hh:224
void Create()
Definition: G4Scheduler.cc:156
void SetDefaultTimeStep(double)
Definition: G4Scheduler.hh:344
G4int GetTrackID() const
bool IsRunning()
Definition: G4Scheduler.hh:108
static void DeleteInstance()
DeleteInstance should be used instead of the destructor.
Definition: G4Scheduler.cc:140
void SetMaxNbSteps(G4int)
Definition: G4Scheduler.hh:319
G4ITModelHandler * fpModelHandler
Definition: G4Scheduler.hh:270
int GetVerbose() const
Definition: G4Scheduler.hh:370
G4ITStepProcessor * fpStepProcessor
Definition: G4Scheduler.hh:267
double fTimeStep
Definition: G4Scheduler.hh:239
bool IsInitialized()
Definition: G4Scheduler.hh:281
std::vector< G4Track * > fLeadingTracks
Definition: G4Scheduler.hh:259
double fStartTime
Definition: G4Scheduler.hh:227
G4ITTrackingInteractivity * fpTrackingInteractivity
Definition: G4Scheduler.hh:274
bool fWhyDoYouStop
Definition: G4Scheduler.hh:213
G4UserTimeStepAction * fpUserTimeStepAction
Definition: G4Scheduler.hh:273
void CalculateMinTimeStep()
Definition: G4Scheduler.cc:998
G4int GetMaxNbSteps() const
Definition: G4Scheduler.hh:324
G4bool fContinue
Definition: G4Scheduler.hh:277
double fDefinedMinTimeStep
Definition: G4Scheduler.hh:247
G4ITReactionSet fReactionSet
Definition: G4Scheduler.hh:258
void PushDelayed(G4Track *, const G4double &)
void Reset()
Definition: G4Scheduler.cc:342
G4Scheduler & operator=(const G4Scheduler &)
virtual void RegisterModel(G4VITStepModel *, double)
Definition: G4Scheduler.cc:292
void SetTimeSteps(std::map< double, double > *)
Definition: G4Scheduler.hh:297
G4double GetEndTime() const
Definition: G4Scheduler.hh:334
double fDefaultMinTimeStep
Definition: G4Scheduler.hh:243
G4double GetGlobalTime() const
Definition: G4Scheduler.hh:349
virtual G4double GetTimeStep() const
Definition: G4Scheduler.hh:339
double fGlobalTime
Definition: G4Scheduler.hh:225
void SetMaxZeroTimeAllowed(int)
Definition: G4Scheduler.hh:376
int GetMaxZeroTimeAllowed() const
Definition: G4Scheduler.hh:381
double G4double
Definition: G4Types.hh:76
void DoProcess()
Definition: G4Scheduler.cc:507
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
int fZeroTimeCount
Definition: G4Scheduler.hh:232
bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:24
void ComputeInteractionLength()
void UseDefaultTimeSteps(G4bool)
Definition: G4Scheduler.hh:431
G4ITTrackingInteractivity * GetInteractivity()
Definition: G4Scheduler.hh:411
bool fComputeReaction
Definition: G4Scheduler.hh:237
void Initialize()
Definition: G4Scheduler.cc:299
void Stepping()
Definition: G4Scheduler.cc:591
G4ITTrackHolder & fTrackContainer
Definition: G4Scheduler.hh:265
void AddTimeStep(double, double)
Definition: G4Scheduler.hh:303
G4ITStepStatus GetStatus() const
Definition: G4Scheduler.hh:401
G4ApplicationState
double fTmpGlobalTime
Definition: G4Scheduler.hh:226
void ExtractTimeStepperData(G4ITModelProcessor *)
void ResetLeadingTracks()
void WhyDoYouStop()
Definition: G4Scheduler.hh:426