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