Geant4  10.03
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
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 
48 
49 #ifndef G4Scheduler_h
50 #define G4Scheduler_h
51 
52 #include <G4VScheduler.hh>
53 #include <vector>
54 #include <map>
55 #include <memory>
56 
57 #include "globals.hh"
58 
59 #include "G4ITModelHandler.hh"
60 #include "G4ITStepStatus.hh"
61 #include "G4ITTrackHolder.hh"
62 #include "G4VStateDependent.hh"
63 #include "G4ITReaction.hh"
64 
66 class G4ITModelProcessor;
67 class G4ITStepProcessor;
68 class G4Track;
72 class G4ITGun;
73 
74 #ifndef compTrackPerID__
75 #define compTrackPerID__
76  struct compTrackPerID
77  {
78  bool operator()(G4Track* rhs, G4Track* lhs) const
79  {
80  return rhs->GetTrackID() < lhs->GetTrackID();
81  }
82  };
83 #endif
84 
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  void ClearList();
112 
113  inline void SetGun(G4ITGun*);
114  inline G4ITGun* GetGun();
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  /* Two tracks below the time tolerance are supposed to be
128  * in the same time slice
129  */
130  inline void SetTimeTolerance(double);
131  inline double GetTimeTolerance() const;
132 
133  inline void SetMaxZeroTimeAllowed(int);
134  inline int GetMaxZeroTimeAllowed() const;
135 
137 
138  inline void SetTimeSteps(std::map<double, double>*);
139  inline void AddTimeStep(double, double);
140  inline void SetDefaultTimeStep(double);
141  double GetLimitingTimeStep() const;
142  inline G4int GetNbSteps() const;
143  inline void SetMaxNbSteps(G4int);
144  inline G4int GetMaxNbSteps() const;
145  inline G4double GetStartTime() const;
146  inline G4double GetEndTime() const;
147  virtual inline G4double GetTimeStep() const;
148  inline G4double GetPreviousTimeStep() const;
149  inline G4double GetGlobalTime() const;
150  inline void SetUserAction(G4UserTimeStepAction*);
152 
153  // To use with transportation only, no reactions
154  inline void UseDefaultTimeSteps(G4bool);
156 
157  inline G4ITStepStatus GetStatus() const;
158 
159  /* 1 : Reaction information
160  * 2 : (1) + time step information
161  * 3 : (2) + step info for individual tracks
162  * 4 : (2) + trackList processing info + pushed and killed track info
163  */
164  inline void SetVerbose(int);
165 
166  inline int GetVerbose() const;
167 
168  inline void WhyDoYouStop();
169 
172 
173  virtual size_t GetNTracks();
174 
175  void GetCollisionType(G4String& interactionType);
176 
177  void AddWatchedTime(double time)
178  {
179  fWatchedTimes.insert(time);
180  }
181 
182  double GetNextWatchedTime() const;
183 
184  inline void SetMaxTimeStep(double maxTimeStep)
185  {
186  fMaxTimeStep = maxTimeStep;
187  }
188 
189  inline double GetMaxTimeStep() const
190  {
191  return fMaxTimeStep;
192  }
193 
194 protected:
195 
196  void DoProcess();
197  void SynchronizeTracks();
198  void Stepping();
199 
201 
202  bool CanICarryOn();
203 
204  void PrintWhyDoYouStop();
205 
206 private:
207  G4Scheduler();
208  void Create();
209  G4Scheduler(const G4Scheduler&);
211 
213 
215  int fVerbose;
218  bool fRunning;
220 
221  int fNbSteps;
223 
225 
226  // Time members
229  double fGlobalTime;
231  double fStartTime;
232  double fStopTime;
233  double fEndTime;
237 
238  double fTimeStep; // The selected minimum time step
239  double fMaxTimeStep;
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  std::set<double> fWatchedTimes;
252 
254 
255  // ==========================================
256  // TO BE REMOVED
264  // ==========================================
265 
266  double fTSTimeStep;
267  // Time calculated by the time stepper in CalculateMinTimeStep()
268  double fILTimeStep;
269  // Time calculated by the interaction length methods
270  // in ComputeInteractionLength()
271 
273  // Flag : if the step is driven by the interaction with the matter and
274  // NOT by the reaction between tracks
275 
277 
278  // ==========================================
279  //
280 
281 };
282 
284 {
285  return fInitialized;
286 }
287 
289 {
290  return fpModelHandler;
291 }
292 
293 inline void G4Scheduler::SetEndTime(const double __endtime)
294 {
295  fEndTime = __endtime;
296 }
297 
298 inline
299 void G4Scheduler::SetTimeSteps(std::map<double, double>* steps)
300 {
302  fpUserTimeSteps = steps;
303 }
304 
305 inline void G4Scheduler::AddTimeStep(double startingTime, double timeStep)
306 {
307  if (fpUserTimeSteps == 0)
308  {
309  fpUserTimeSteps = new std::map<double, double>();
311  }
312 
313  (*fpUserTimeSteps)[startingTime] = timeStep;
314 }
315 
317 {
318  return fNbSteps;
319 }
320 
321 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
322 {
323  fMaxSteps = maxSteps;
324 }
325 
327 {
328  return fMaxSteps;
329 }
330 
332 {
333  return fStartTime;
334 }
335 
337 {
338  return fEndTime;
339 }
340 
342 {
343  return fTimeStep;
344 }
345 
346 inline void G4Scheduler::SetDefaultTimeStep(double timeStep)
347 {
348  fDefaultMinTimeStep = timeStep;
349 }
350 
352 {
353  return fGlobalTime;
354 }
355 
356 inline
358 {
359  fpUserTimeStepAction = userITAction;
360 }
361 
363 {
364  return fpUserTimeStepAction;
365 }
366 
367 inline void G4Scheduler::SetVerbose(int verbose)
368 {
369  fVerbose = verbose;
370 }
371 
372 inline int G4Scheduler::GetVerbose() const
373 {
374  return fVerbose;
375 }
376 
377 inline
378 void G4Scheduler::SetMaxZeroTimeAllowed(int maxTimeStepAllowed)
379 {
380  fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
381 }
382 
384 {
386 }
387 
388 inline void G4Scheduler::SetTimeTolerance(double time)
389 {
390  fTimeTolerance = time;
391 }
392 
393 inline double G4Scheduler::GetTimeTolerance() const
394 {
395  return fTimeTolerance;
396 }
397 
399 {
400  return fPreviousTimeStep;
401 }
402 
404 {
405  return fITStepStatus;
406 }
407 
408 inline void G4Scheduler::Stop()
409 {
410  fContinue = false;
411 }
412 
414 {
416 }
417 
418 inline void G4Scheduler::SetGun(G4ITGun* gun)
419 {
420  fpGun = gun;
421 }
422 
424 {
425  return fpGun;
426 }
427 
429 {
430  fWhyDoYouStop = true;
431 }
432 
434 {
435  fUseDefaultTimeSteps = flag;
436 }
437 
439 {
440  return (fUseDefaultTimeSteps == false && fUsePreDefinedTimeSteps == false);
441 }
442 
443 #endif
G4ITModelHandler holds for two IT types the corresponding model manager.
G4bool fUseDefaultTimeSteps
Definition: G4Scheduler.hh:227
void Process()
Definition: G4Scheduler.cc:377
std::map< double, double > * fpUserTimeSteps
Definition: G4Scheduler.hh:244
G4ITReactionSet * fReactionSet
Definition: G4Scheduler.hh:261
Its role is the same as G4StepManager :
bool fInteractionStep
Definition: G4Scheduler.hh:272
G4UserTimeStepAction * GetUserTimeStepAction() const
Definition: G4Scheduler.hh:362
virtual size_t GetNTracks()
void FindUserPreDefinedTimeStep()
The G4ITModelProcessor will call the two processes defined in G4VITModel.
double GetTimeTolerance() const
Definition: G4Scheduler.hh:393
void EndTracking()
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:109
double GetMaxTimeStep() const
Definition: G4Scheduler.hh:189
G4double GetPreviousTimeStep() const
Definition: G4Scheduler.hh:398
bool fReachedUserTimeLimit
Definition: G4Scheduler.hh:249
void PrintWhyDoYouStop()
Definition: G4Scheduler.cc:559
void AddWatchedTime(double time)
Definition: G4Scheduler.hh:177
double fTSTimeStep
Definition: G4Scheduler.hh:266
Define what to do before stepping and after stepping.
virtual ~G4Scheduler()
Definition: G4Scheduler.cc:201
void SetEndTime(const double)
Definition: G4Scheduler.hh:293
G4ITModelHandler * GetModelHandler()
Definition: G4Scheduler.hh:288
G4ITStepStatus
void SynchronizeTracks()
Definition: G4Scheduler.cc:498
double fMaxTimeStep
Definition: G4Scheduler.hh:239
double fPreviousTimeStep
Definition: G4Scheduler.hh:234
void SetTimeTolerance(double)
Definition: G4Scheduler.hh:388
double fStopTime
Definition: G4Scheduler.hh:232
G4double GetStartTime() const
Definition: G4Scheduler.hh:331
G4ITStepStatus fITStepStatus
Definition: G4Scheduler.hh:224
#define G4ThreadLocal
Definition: tls.hh:89
int fMaxNZeroTimeStepsAllowed
Definition: G4Scheduler.hh:236
int G4int
Definition: G4Types.hh:78
double fILTimeStep
Definition: G4Scheduler.hh:268
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:102
static G4ThreadLocal G4Scheduler * fgScheduler
Definition: G4Scheduler.hh:214
G4ITGun * fpGun
Definition: G4Scheduler.hh:276
bool fUsePreDefinedTimeSteps
Definition: G4Scheduler.hh:242
G4bool AreDefaultTimeStepsUsed()
Definition: G4Scheduler.hh:438
bool fInitialized
Definition: G4Scheduler.hh:217
G4int GetNbSteps() const
Definition: G4Scheduler.hh:316
double fUserUpperTimeLimit
Definition: G4Scheduler.hh:246
G4UserTimeStepAction is used by G4Scheduler.
void Clear()
Definition: G4Scheduler.cc:217
void SetVerbose(int)
Definition: G4Scheduler.hh:367
bool G4bool
Definition: G4Types.hh:79
G4Scheduler synchronizes (in time) track stepping.
Definition: G4Scheduler.hh:88
G4ITTrackingManager * fpTrackingManager
Definition: G4Scheduler.hh:259
void SetGun(G4ITGun *)
Definition: G4Scheduler.hh:418
double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:941
void ForceReinitialization()
void ClearList()
Definition: G4Scheduler.cc:265
double fEndTime
Definition: G4Scheduler.hh:233
G4ITModelProcessor * fpModelProcessor
Definition: G4Scheduler.hh:258
G4SchedulerMessenger * fpMessenger
Definition: G4Scheduler.hh:212
void SetUserAction(G4UserTimeStepAction *)
Definition: G4Scheduler.hh:357
double fTimeTolerance
Definition: G4Scheduler.hh:228
void Create()
Definition: G4Scheduler.cc:140
void SetDefaultTimeStep(double)
Definition: G4Scheduler.hh:346
G4int GetTrackID() const
bool IsRunning()
Definition: G4Scheduler.hh:108
static void DeleteInstance()
DeleteInstance should be used instead of the destructor.
Definition: G4Scheduler.cc:124
bool CanICarryOn()
Definition: G4Scheduler.cc:551
void SetMaxNbSteps(G4int)
Definition: G4Scheduler.hh:321
G4ITModelHandler * fpModelHandler
Definition: G4Scheduler.hh:263
int GetVerbose() const
Definition: G4Scheduler.hh:372
G4ITStepProcessor * fpStepProcessor
Definition: G4Scheduler.hh:257
double GetNextWatchedTime() const
Definition: G4Scheduler.cc:489
double fTimeStep
Definition: G4Scheduler.hh:238
bool IsInitialized()
Definition: G4Scheduler.hh:283
void SetMaxTimeStep(double maxTimeStep)
Definition: G4Scheduler.hh:184
double fStartTime
Definition: G4Scheduler.hh:231
G4ITTrackingInteractivity * fpTrackingInteractivity
Definition: G4Scheduler.hh:260
bool fWhyDoYouStop
Definition: G4Scheduler.hh:216
G4UserTimeStepAction * fpUserTimeStepAction
Definition: G4Scheduler.hh:253
std::set< double > fWatchedTimes
Definition: G4Scheduler.hh:251
G4int GetMaxNbSteps() const
Definition: G4Scheduler.hh:326
double fDefinedMinTimeStep
Definition: G4Scheduler.hh:247
G4bool fContinue
Definition: G4Scheduler.hh:219
void Reset()
Definition: G4Scheduler.cc:357
G4Scheduler & operator=(const G4Scheduler &)
virtual void RegisterModel(G4VITStepModel *, double)
Definition: G4Scheduler.cc:275
void SetTimeSteps(std::map< double, double > *)
Definition: G4Scheduler.hh:299
G4double GetEndTime() const
Definition: G4Scheduler.hh:336
G4ITGun * GetGun()
Definition: G4Scheduler.hh:423
double fDefaultMinTimeStep
Definition: G4Scheduler.hh:243
G4double GetGlobalTime() const
Definition: G4Scheduler.hh:351
virtual G4double GetTimeStep() const
Definition: G4Scheduler.hh:341
double fGlobalTime
Definition: G4Scheduler.hh:229
void SetMaxZeroTimeAllowed(int)
Definition: G4Scheduler.hh:378
int GetMaxZeroTimeAllowed() const
Definition: G4Scheduler.hh:383
double G4double
Definition: G4Types.hh:76
void DoProcess()
Definition: G4Scheduler.cc:603
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
int fZeroTimeCount
Definition: G4Scheduler.hh:235
bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:49
void UseDefaultTimeSteps(G4bool)
Definition: G4Scheduler.hh:433
G4ITTrackingInteractivity * GetInteractivity()
Definition: G4Scheduler.hh:413
void Initialize()
Definition: G4Scheduler.cc:282
void Stepping()
Definition: G4Scheduler.cc:650
G4ITTrackHolder & fTrackContainer
Definition: G4Scheduler.hh:262
void AddTimeStep(double, double)
Definition: G4Scheduler.hh:305
G4ITStepStatus GetStatus() const
Definition: G4Scheduler.hh:403
G4ApplicationState
double fTmpGlobalTime
Definition: G4Scheduler.hh:230
void WhyDoYouStop()
Definition: G4Scheduler.hh:428