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