Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
195  {
196  return fpTrackingManager;
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&);
215  G4Scheduler& operator=(const G4Scheduler&);
216 
217  G4SchedulerMessenger* fpMessenger;
218 
219  static G4ThreadLocal G4Scheduler* fgScheduler;
220  int fVerbose;
221  bool fWhyDoYouStop;
222  bool fInitialized;
223  bool fRunning;
224  G4bool fContinue;
225 
226  int fNbSteps;
227  int fMaxSteps;
228 
229  G4ITStepStatus fITStepStatus;
230 
231  // Time members
232  G4bool fUseDefaultTimeSteps;
233  double fTimeTolerance;
234  double fGlobalTime;
235  double fTmpGlobalTime;
236  double fStartTime;
237  double fStopTime;
238  double fEndTime;
239  double fPreviousTimeStep;
240  int fZeroTimeCount;
241  int fMaxNZeroTimeStepsAllowed;
242 
243  double fTimeStep; // The selected minimum time step
244  double fMaxTimeStep;
245 
246  // User steps
247  bool fUsePreDefinedTimeSteps;
248  double fDefaultMinTimeStep;
249  std::map<double, double>* fpUserTimeSteps;
250  // One can give time steps in respect to the global time
251  mutable double fUserUpperTimeLimit;
252  double fDefinedMinTimeStep;
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 
258  G4UserTimeStepAction* fpUserTimeStepAction;
259 
260  // ==========================================
261  // TO BE REMOVED
262  G4ITStepProcessor* fpStepProcessor;
263  G4ITModelProcessor* fpModelProcessor;
264  G4ITTrackingManager* fpTrackingManager;
265  G4ITTrackingInteractivity* fpTrackingInteractivity;
266  G4ITReactionSet* fReactionSet;
267  G4ITTrackHolder& fTrackContainer;
268  G4ITModelHandler* fpModelHandler;
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 
277  bool fInteractionStep;
278  // Flag : if the step is driven by the interaction with the matter and
279  // NOT by the reaction between tracks
280 
281  G4ITGun* fpGun;
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 {
306  fUsePreDefinedTimeSteps = true;
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>();
315  fUsePreDefinedTimeSteps = true;
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 {
390  return fMaxNZeroTimeStepsAllowed;
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 {
420  return fpTrackingInteractivity;
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
void Process()
Definition: G4Scheduler.cc:377
G4UserTimeStepAction * GetUserTimeStepAction() const
Definition: G4Scheduler.hh:367
virtual size_t GetNTracks()
void FindUserPreDefinedTimeStep()
double GetTimeTolerance() const
Definition: G4Scheduler.hh:398
void EndTracking()
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:109
double GetMaxTimeStep() const
Definition: G4Scheduler.hh:189
G4double GetPreviousTimeStep() const
Definition: G4Scheduler.hh:403
void PrintWhyDoYouStop()
Definition: G4Scheduler.cc:559
void AddWatchedTime(double time)
Definition: G4Scheduler.hh:177
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:498
void SetTimeTolerance(double)
Definition: G4Scheduler.hh:393
G4double GetStartTime() const
Definition: G4Scheduler.hh:336
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:102
G4bool AreDefaultTimeStepsUsed()
Definition: G4Scheduler.hh:443
G4int GetNbSteps() const
Definition: G4Scheduler.hh:321
void Clear()
Definition: G4Scheduler.cc:217
void SetVerbose(int)
Definition: G4Scheduler.hh:372
bool G4bool
Definition: G4Types.hh:79
void SetGun(G4ITGun *)
Definition: G4Scheduler.hh:423
double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:941
void ForceReinitialization()
void ClearList()
Definition: G4Scheduler.cc:265
void SetUserAction(G4UserTimeStepAction *)
Definition: G4Scheduler.hh:362
void SetDefaultTimeStep(double)
Definition: G4Scheduler.hh:351
G4int GetTrackID() const
bool IsRunning()
Definition: G4Scheduler.hh:108
static void DeleteInstance()
Definition: G4Scheduler.cc:124
bool CanICarryOn()
Definition: G4Scheduler.cc:551
void SetMaxNbSteps(G4int)
Definition: G4Scheduler.hh:326
int GetVerbose() const
Definition: G4Scheduler.hh:377
double GetNextWatchedTime() const
Definition: G4Scheduler.cc:489
bool IsInitialized()
Definition: G4Scheduler.hh:288
void SetMaxTimeStep(double maxTimeStep)
Definition: G4Scheduler.hh:184
G4int GetMaxNbSteps() const
Definition: G4Scheduler.hh:331
void Reset()
Definition: G4Scheduler.cc:357
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
G4double GetGlobalTime() const
Definition: G4Scheduler.hh:356
virtual G4double GetTimeStep() const
Definition: G4Scheduler.hh:346
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:603
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:49
G4ITTrackingManager * GetTrackingManager() const
Definition: G4Scheduler.hh:194
void UseDefaultTimeSteps(G4bool)
Definition: G4Scheduler.hh:438
G4ITTrackingInteractivity * GetInteractivity()
Definition: G4Scheduler.hh:418
void Initialize()
Definition: G4Scheduler.cc:282
void Stepping()
Definition: G4Scheduler.cc:650
void AddTimeStep(double, double)
Definition: G4Scheduler.hh:310
G4ITStepStatus GetStatus() const
Definition: G4Scheduler.hh:408
G4ApplicationState
void WhyDoYouStop()
Definition: G4Scheduler.hh:433