Geant4  10.01.p01
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 
63 class G4ITModelProcessor;
64 class G4ITStepProcessor;
65 class G4Track;
69 class G4ITGun;
70 
75 class G4Scheduler :
76  public G4VScheduler,
77  public G4VStateDependent
78 {
79 protected:
80  virtual ~G4Scheduler();
81 
82 public:
83  static G4Scheduler* Instance();
87  static void DeleteInstance();
88  virtual G4bool Notify(G4ApplicationState requestedState);
89 
90  virtual void RegisterModel(G4VITStepModel*, double);
91 
92  void Initialize();
93  void ForceReinitialization();
94  inline bool IsInitialized();
95  inline bool IsRunning(){return fRunning;}
96  void Reset();
97  void Process();
98  virtual void PushTrack(G4Track*);
99  void ClearList();
100 
101  inline void SetGun(G4ITGun*);
102 
103  inline void Stop();
104  void Clear();
105 
106  // To be called only in UserReactionAction::EndProcessing()
107  // after fRunning flag has been turned off.
108  // This is not done automatically before UserReactionAction::EndProcessing()
109  // is called in case one would like to access some track information
110  void EndTracking();
111 
112  void SetEndTime(const double);
113 
114  inline void SetTimeTolerance(double);
115  // Two tracks below the time tolerance are supposed to be
116  // in the same time slice
117  inline double GetTimeTolerance() const;
118 
119  inline void SetMaxZeroTimeAllowed(int);
120  inline int GetMaxZeroTimeAllowed() const;
121 
123  inline void SetTimeSteps(std::map<double, double>*);
124  inline void AddTimeStep(double, double);
125  inline void SetDefaultTimeStep(double);
126  double GetLimitingTimeStep() const;
127  inline G4int GetNbSteps() const;
128  inline void SetMaxNbSteps(G4int);
129  inline G4int GetMaxNbSteps() const;
130  inline G4double GetStartTime() const;
131  inline G4double GetEndTime() const;
132  virtual inline G4double GetTimeStep() const;
133  inline G4double GetPreviousTimeStep() const;
134  inline G4double GetGlobalTime() const;
135  inline void SetUserAction(G4UserTimeStepAction*);
137 
138  // To use with transportation only, no reactions
139  inline void UseDefaultTimeSteps(G4bool);
141 
142  inline G4bool GetComputeTimeStepFlag() const;
143 
144  inline G4ITStepStatus GetStatus() const;
145 
146  inline void SetVerbose(int);
147  // 1 : Reaction information
148  // 2 : (1) + time step information
149  // 3 : (2) + step info for individual tracks
150  // 4 : (2) + trackList processing info + pushed and killed track info
151  inline int GetVerbose() const;
152 
153  inline void WhyDoYouStop();
154 
157 
158  virtual size_t GetNTracks();
159 
160  void GetCollisionType(G4String& interactionType);
161 
162 protected:
163 
164  void DoProcess();
165  void SynchronizeTracks();
166  void Stepping();
167 
169  void CalculateMinTimeStep();
171  void DoIt();
172  void ComputeTrackReaction();
173 // void MergeSecondariesWithMainList();
174 
176 // void _PushTrack(G4Track*);
177  void PushDelayed(G4Track*, const G4double&);
178 
179  void EndTracking(G4Track*);
180  void KillTracks();
181 
185 
186  void AddTrackID(G4Track*);
187 
188  void ResetLeadingTracks();
189 
190 private:
191  G4Scheduler();
192  void Create();
193  G4Scheduler(const G4Scheduler&);
195 
197 
199  int fVerbose;
202  bool fRunning;
203 
205  int fNbSteps;
207 
209 
210  // Time members
212  double fGlobalTime;
214  double fStartTime;
215  double fEndTime;
216  double fTmpEndTime;
217  // fTmpEndTime : Stores the biggest end time here (for synchronizing tracks)
221 
222  // Flags
225 
226  double fTimeStep; // The selected minimum time step
227 
228  // User steps
231  std::map<double, double>* fpUserTimeSteps;
232  // One can give time steps in respect to the global time
233  mutable double fUserUpperTimeLimit;
235  // selected user time step in respect to the global time
236  bool fReachedUserTimeLimit; // if fMinTimeStep == the user time step
237 
238  double fTSTimeStep;
239  // Time calculated by the time stepper in CalculateMinTimeStep()
240  double fILTimeStep;
241  // Time calculated by the interaction length methods
242  // in ComputeInteractionLength()
243 
244  std::map<G4Track*, G4TrackVectorHandle> fReactingTracks;
245  std::vector<G4Track*> fLeadingTracks;
246 
248  // Flag : if the step is driven by the interaction with the matter and
249  // NOT by the reaction between tracks
250 
252 
255 
257 
261 
265 };
266 
268 {
269  return fInitialized;
270 }
271 
273 {
274  return fpModelHandler;
275 }
276 
277 inline void G4Scheduler::SetEndTime(const double __endtime)
278 {
279  fEndTime = __endtime;
280 }
281 
282 inline
283 void G4Scheduler::SetTimeSteps(std::map<double, double>* steps)
284 {
286  fpUserTimeSteps = steps;
287 }
288 
289 inline void G4Scheduler::AddTimeStep(double startingTime, double timeStep)
290 {
291  if (fpUserTimeSteps == 0)
292  {
293  fpUserTimeSteps = new std::map<double, double>();
295  }
296 
297  (*fpUserTimeSteps)[startingTime] = timeStep;
298 }
299 
301 {
302  return fNbSteps;
303 }
304 
305 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
306 {
307  fMaxSteps = maxSteps;
308 }
309 
311 {
312  return fMaxSteps;
313 }
314 
316 {
317  return fStartTime;
318 }
319 
321 {
322  return fEndTime;
323 }
324 
326 {
327  return fTimeStep;
328 }
329 
330 inline void G4Scheduler::SetDefaultTimeStep(double timeStep)
331 {
332  fDefaultMinTimeStep = timeStep;
333 }
334 
336 {
337  return fGlobalTime;
338 }
339 
340 inline
342 {
343  fpUserTimeStepAction = userITAction;
344 }
345 
347 {
348  return fpUserTimeStepAction;
349 }
350 
351 inline void G4Scheduler::SetVerbose(int verbose)
352 {
353  fVerbose = verbose;
354 }
355 
356 inline int G4Scheduler::GetVerbose() const
357 {
358  return fVerbose;
359 }
360 
361 inline
362 void G4Scheduler::SetMaxZeroTimeAllowed(int maxTimeStepAllowed)
363 {
364  fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
365 }
366 
368 {
370 }
371 
372 inline void G4Scheduler::SetTimeTolerance(double time)
373 {
374  fTimeTolerance = time;
375 }
376 
377 inline double G4Scheduler::GetTimeTolerance() const
378 {
379  return fTimeTolerance;
380 }
381 
383 {
384  return fPreviousTimeStep;
385 }
386 
388 {
389  return fITStepStatus;
390 }
391 
392 inline void G4Scheduler::Stop()
393 {
394  fContinue = false;
395 }
396 
398 {
400 }
401 
402 inline void G4Scheduler::SetGun(G4ITGun* gun)
403 {
404  fpGun = gun;
405 }
406 
408 {
409  return fComputeTimeStep;
410 }
411 
413 {
414  fWhyDoYouStop = true;
415 }
416 
418 {
419  fUseDefaultTimeSteps = flag;
420 }
421 
423 {
424  return (fUseDefaultTimeSteps == false && fUsePreDefinedTimeSteps == false);
425 }
426 
427 #endif
G4ITModelHandler holds for two IT types the corresponding model manager.
G4bool fUseDefaultTimeSteps
Definition: G4Scheduler.hh:264
void Process()
Definition: G4Scheduler.cc:362
std::map< double, double > * fpUserTimeSteps
Definition: G4Scheduler.hh:231
Its role is the same as G4StepManager :
bool fInteractionStep
Definition: G4Scheduler.hh:247
G4UserTimeStepAction * GetUserTimeStepAction() const
Definition: G4Scheduler.hh:346
G4bool GetComputeTimeStepFlag() const
Definition: G4Scheduler.hh:407
virtual size_t GetNTracks()
void FindUserPreDefinedTimeStep()
Definition: G4Scheduler.cc:943
The G4ITModelProcessor will call the two processes defined in G4VITModel.
double GetTimeTolerance() const
Definition: G4Scheduler.hh:377
void EndTracking()
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:125
G4double GetPreviousTimeStep() const
Definition: G4Scheduler.hh:382
void PushSecondaries(G4ITStepProcessor *)
bool fReachedUserTimeLimit
Definition: G4Scheduler.hh:236
bool fComputeTimeStep
Definition: G4Scheduler.hh:223
double fTSTimeStep
Definition: G4Scheduler.hh:238
double fTmpEndTime
Definition: G4Scheduler.hh:216
Define what to do before stepping and after stepping.
virtual ~G4Scheduler()
Definition: G4Scheduler.cc:222
void SetEndTime(const double)
Definition: G4Scheduler.hh:277
G4ITModelHandler * GetModelHandler()
Definition: G4Scheduler.hh:272
G4ITStepStatus
void SynchronizeTracks()
Definition: G4Scheduler.cc:471
double fPreviousTimeStep
Definition: G4Scheduler.hh:218
void SetTimeTolerance(double)
Definition: G4Scheduler.hh:372
G4double GetStartTime() const
Definition: G4Scheduler.hh:315
G4ITStepStatus fITStepStatus
Definition: G4Scheduler.hh:208
#define G4ThreadLocal
Definition: tls.hh:89
int fMaxNZeroTimeStepsAllowed
Definition: G4Scheduler.hh:220
void ComputeTrackReaction()
int G4int
Definition: G4Types.hh:78
double fILTimeStep
Definition: G4Scheduler.hh:240
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:118
virtual void PushTrack(G4Track *)
void KillTracks()
static G4ThreadLocal G4Scheduler * fgScheduler
Definition: G4Scheduler.hh:198
G4ITGun * fpGun
Definition: G4Scheduler.hh:262
bool fUsePreDefinedTimeSteps
Definition: G4Scheduler.hh:229
G4bool AreDefaultTimeStepsUsed()
Definition: G4Scheduler.hh:422
bool fInitialized
Definition: G4Scheduler.hh:201
G4int GetNbSteps() const
Definition: G4Scheduler.hh:300
double fUserUpperTimeLimit
Definition: G4Scheduler.hh:233
G4UserTimeStepAction is used by G4Scheduler.
void Clear()
Definition: G4Scheduler.cc:237
void SetVerbose(int)
Definition: G4Scheduler.hh:351
bool G4bool
Definition: G4Types.hh:79
G4ITStepManager enables to synchronize in time the step of tracks.
Definition: G4Scheduler.hh:75
G4ITTrackingManager * fpTrackingManager
Definition: G4Scheduler.hh:258
void SetGun(G4ITGun *)
Definition: G4Scheduler.hh:402
void ExtractILData(G4ITStepProcessor *)
double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:882
void ForceReinitialization()
void ExtractDoItData(G4ITStepProcessor *)
void ClearList()
Definition: G4Scheduler.cc:280
void AddTrackID(G4Track *)
double fEndTime
Definition: G4Scheduler.hh:215
G4ITModelProcessor * fpModelProcessor
Definition: G4Scheduler.hh:254
void SetUserAction(G4UserTimeStepAction *)
Definition: G4Scheduler.hh:341
G4SchedulerMessenger * fSteppingMsg
Definition: G4Scheduler.hh:196
double fTimeTolerance
Definition: G4Scheduler.hh:211
void Create()
Definition: G4Scheduler.cc:156
void SetDefaultTimeStep(double)
Definition: G4Scheduler.hh:330
bool IsRunning()
Definition: G4Scheduler.hh:95
static void DeleteInstance()
DeleteInstance should be used instead of the destructor.
Definition: G4Scheduler.cc:140
void SetMaxNbSteps(G4int)
Definition: G4Scheduler.hh:305
G4ITModelHandler * fpModelHandler
Definition: G4Scheduler.hh:256
int GetVerbose() const
Definition: G4Scheduler.hh:356
G4ITStepProcessor * fpStepProcessor
Definition: G4Scheduler.hh:253
double fTimeStep
Definition: G4Scheduler.hh:226
bool IsInitialized()
Definition: G4Scheduler.hh:267
std::vector< G4Track * > fLeadingTracks
Definition: G4Scheduler.hh:245
double fStartTime
Definition: G4Scheduler.hh:214
G4ITTrackingInteractivity * fpTrackingInteractivity
Definition: G4Scheduler.hh:260
bool fWhyDoYouStop
Definition: G4Scheduler.hh:200
G4UserTimeStepAction * fpUserTimeStepAction
Definition: G4Scheduler.hh:259
void CalculateMinTimeStep()
Definition: G4Scheduler.cc:995
G4int GetMaxNbSteps() const
Definition: G4Scheduler.hh:310
G4bool fContinue
Definition: G4Scheduler.hh:263
double fDefinedMinTimeStep
Definition: G4Scheduler.hh:234
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:283
G4double GetEndTime() const
Definition: G4Scheduler.hh:320
double fDefaultMinTimeStep
Definition: G4Scheduler.hh:230
std::map< G4Track *, G4TrackVectorHandle > fReactingTracks
Definition: G4Scheduler.hh:244
G4double GetGlobalTime() const
Definition: G4Scheduler.hh:335
virtual G4double GetTimeStep() const
Definition: G4Scheduler.hh:325
double fGlobalTime
Definition: G4Scheduler.hh:212
void SetMaxZeroTimeAllowed(int)
Definition: G4Scheduler.hh:362
int GetMaxZeroTimeAllowed() const
Definition: G4Scheduler.hh:367
double G4double
Definition: G4Types.hh:76
void DoProcess()
Definition: G4Scheduler.cc:506
void SetInteractivity(G4ITTrackingInteractivity *)
void GetCollisionType(G4String &interactionType)
int fZeroTimeCount
Definition: G4Scheduler.hh:219
void ComputeInteractionLength()
void UseDefaultTimeSteps(G4bool)
Definition: G4Scheduler.hh:417
G4ITTrackingInteractivity * GetInteractivity()
Definition: G4Scheduler.hh:397
bool fComputeReaction
Definition: G4Scheduler.hh:224
void Initialize()
Definition: G4Scheduler.cc:299
void Stepping()
Definition: G4Scheduler.cc:590
G4ITTrackHolder & fTrackContainer
Definition: G4Scheduler.hh:251
void AddTimeStep(double, double)
Definition: G4Scheduler.hh:289
G4ITStepStatus GetStatus() const
Definition: G4Scheduler.hh:387
G4ApplicationState
double fTmpGlobalTime
Definition: G4Scheduler.hh:213
void ExtractTimeStepperData(G4ITModelProcessor *)
void ResetLeadingTracks()
void WhyDoYouStop()
Definition: G4Scheduler.hh:412