Geant4 11.1.1
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"
64
68class G4Track;
72class G4ITGun;
73
74#ifndef compTrackPerID__
75#define compTrackPerID__
76 struct compTrackPerID
77 {
78 G4bool operator()(G4Track* rhs, G4Track* lhs) const
79 {
80 return rhs->GetTrackID() < lhs->GetTrackID();
81 }
82 };
83#endif
84
85/**
86 * G4Scheduler synchronizes (in time) track stepping
87 */
89 public G4VScheduler,
91{
92protected:
93 virtual ~G4Scheduler();
94
95public:
96 static G4Scheduler* Instance();
97 /** DeleteInstance should be used instead
98 * of the destructor
99 */
100 static void DeleteInstance();
101 virtual G4bool Notify(G4ApplicationState requestedState);
102
103 virtual void RegisterModel(G4VITStepModel*, G4double);
104
105 void Initialize();
107 inline G4bool IsInitialized();
108 inline G4bool 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 G4double);
126
127 /* Two tracks below the time tolerance are supposed to be
128 * in the same time slice
129 */
130 inline void SetTimeTolerance(G4double);
131 inline G4double GetTimeTolerance() const;
132
133 inline void SetMaxZeroTimeAllowed(G4int);
134 inline G4int GetMaxZeroTimeAllowed() const;
135
137
138 inline void SetTimeSteps(std::map<G4double, G4double>*);
139 inline void AddTimeStep(G4double, G4double);
140 inline void SetDefaultTimeStep(G4double);
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;
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(G4int);
165
166 inline G4int GetVerbose() const;
167
168 inline void WhyDoYouStop();
169
172
173 virtual size_t GetNTracks();
174
175 void GetCollisionType(G4String& interactionType);
176
178 {
179 fWatchedTimes.insert(time);
180 }
181
183
184 inline void SetMaxTimeStep(G4double maxTimeStep)
185 {
186 fMaxTimeStep = maxTimeStep;
187 }
188
190 {
191 return fMaxTimeStep;
192 }
193
195 {
196 return fpUserScavenger.get();
197 }
198 inline void SetScavengerMaterial(std::unique_ptr<G4VScavengerMaterial> scavengerMaterial)
199 {
200 fpUserScavenger = std::move(scavengerMaterial);
201 }
202
203protected:
204
205 void DoProcess();
206 void SynchronizeTracks();
207 void Stepping();
208
210
212
213 void PrintWhyDoYouStop();
214
215private:
216 G4Scheduler();
217 void Create();
218 G4Scheduler(const G4Scheduler&);
219 G4Scheduler& operator=(const G4Scheduler&);
220
221 G4SchedulerMessenger* fpMessenger;
222
223 static G4ThreadLocal G4Scheduler* fgScheduler;
224 G4int fVerbose;
225 G4bool fWhyDoYouStop;
226 G4bool fInitialized;
227 G4bool fRunning;
228 G4bool fContinue;
229
230 G4int fNbSteps;
231 G4int fMaxSteps;
232
233 G4ITStepStatus fITStepStatus;
234
235 // Time members
236 G4bool fUseDefaultTimeSteps;
237 G4double fTimeTolerance;
238 G4double fGlobalTime;
239 G4double fTmpGlobalTime;
240 G4double fStartTime;
241 G4double fStopTime;
242 G4double fEndTime;
243 G4double fPreviousTimeStep;
244 G4int fZeroTimeCount;
245 G4int fMaxNZeroTimeStepsAllowed;
246
247 G4double fTimeStep; // The selected minimum time step
248 G4double fMaxTimeStep;
249
250 // User steps
251 G4bool fUsePreDefinedTimeSteps;
252 G4double fDefaultMinTimeStep;
253 std::map<G4double, G4double>* fpUserTimeSteps;
254 // One can give time steps in respect to the global time
255 mutable G4double fUserUpperTimeLimit;
256 G4double fDefinedMinTimeStep;
257 // selected user time step in respect to the global time
258 G4bool fReachedUserTimeLimit; // if fMinTimeStep == the user time step
259
260 std::set<G4double> fWatchedTimes;
261
262 G4UserTimeStepAction* fpUserTimeStepAction;
263
264 std::unique_ptr<G4VScavengerMaterial> fpUserScavenger;
265
266 // ==========================================
267 // TO BE REMOVED
268 G4ITStepProcessor* fpStepProcessor;
269 G4ITModelProcessor* fpModelProcessor;
270 G4ITTrackingManager* fpTrackingManager;
271 G4ITTrackingInteractivity* fpTrackingInteractivity;
272 G4ITReactionSet* fReactionSet;
273 G4ITTrackHolder& fTrackContainer;
274 G4ITModelHandler* fpModelHandler;
275 // ==========================================
276
277 G4double fTSTimeStep;
278 // Time calculated by the time stepper in CalculateMinTimeStep()
279 G4double fILTimeStep;
280 // Time calculated by the interaction length methods
281 // in ComputeInteractionLength()
282
283 G4bool fInteractionStep;
284 // Flag : if the step is driven by the interaction with the matter and
285 // NOT by the reaction between tracks
286
287 G4ITGun* fpGun;
288
289 // ==========================================
290 //Hoang
291 bool fResetScavenger;
292public:
293 void ResetScavenger(bool);
294};
295
297{
298 return fInitialized;
299}
300
302{
303 return fpModelHandler;
304}
305
306inline void G4Scheduler::SetEndTime(const G4double __endtime)
307{
308 fEndTime = __endtime;
309}
310
311inline
312void G4Scheduler::SetTimeSteps(std::map<G4double, G4double>* steps)
313{
314 fUsePreDefinedTimeSteps = true;
315 fpUserTimeSteps = steps;
316}
317
318inline void G4Scheduler::AddTimeStep(G4double startingTime, G4double timeStep)
319{
320 if (fpUserTimeSteps == 0)
321 {
322 fpUserTimeSteps = new std::map<G4double, G4double>();
323 fUsePreDefinedTimeSteps = true;
324 }
325
326 (*fpUserTimeSteps)[startingTime] = timeStep;
327}
328
330{
331 return fNbSteps;
332}
333
335{
336 fMaxSteps = maxSteps;
337}
338
340{
341 return fMaxSteps;
342}
343
345{
346 return fStartTime;
347}
348
350{
351 return fEndTime;
352}
353
355{
356 return fTimeStep;
357}
358
360{
361 fDefaultMinTimeStep = timeStep;
362}
363
365{
366 return fGlobalTime;
367}
368
369inline
371{
372 fpUserTimeStepAction = userITAction;
373}
374
376{
377 return fpUserTimeStepAction;
378}
379
380inline void G4Scheduler::SetVerbose(G4int verbose)
381{
382 fVerbose = verbose;
383}
384
386{
387 return fVerbose;
388}
389
390inline
392{
393 fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
394}
395
397{
398 return fMaxNZeroTimeStepsAllowed;
399}
400
402{
403 fTimeTolerance = time;
404}
405
407{
408 return fTimeTolerance;
409}
410
412{
413 return fPreviousTimeStep;
414}
415
417{
418 return fITStepStatus;
419}
420
421inline void G4Scheduler::Stop()
422{
423 fContinue = false;
424}
425
427{
428 return fpTrackingInteractivity;
429}
430
432{
433 fpGun = gun;
434}
435
437{
438 return fpGun;
439}
440
442{
443 fWhyDoYouStop = true;
444}
445
447{
448 fUseDefaultTimeSteps = flag;
449}
450
452{
453 return (fUseDefaultTimeSteps == false && fUsePreDefinedTimeSteps == false);
454}
455
456inline void G4Scheduler::ResetScavenger(bool value)
457{
458 fResetScavenger = value;
459}
460
461#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:219
void SynchronizeTracks()
Definition: G4Scheduler.cc:511
G4bool CanICarryOn()
Definition: G4Scheduler.cc:564
void SetMaxTimeStep(G4double maxTimeStep)
Definition: G4Scheduler.hh:184
void AddTimeStep(G4double, G4double)
Definition: G4Scheduler.hh:318
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4Scheduler.cc:108
void EndTracking()
void FindUserPreDefinedTimeStep()
G4int GetMaxZeroTimeAllowed() const
Definition: G4Scheduler.hh:396
void ForceReinitialization()
virtual void RegisterModel(G4VITStepModel *, G4double)
Definition: G4Scheduler.cc:277
void SetGun(G4ITGun *)
Definition: G4Scheduler.hh:431
G4double GetNextWatchedTime() const
Definition: G4Scheduler.cc:502
void Reset()
Definition: G4Scheduler.cc:359
G4double GetMaxTimeStep() const
Definition: G4Scheduler.hh:189
void SetMaxNbSteps(G4int)
Definition: G4Scheduler.hh:334
G4bool IsRunning()
Definition: G4Scheduler.hh:108
G4bool IsInitialized()
Definition: G4Scheduler.hh:296
G4UserTimeStepAction * GetUserTimeStepAction() const
Definition: G4Scheduler.hh:375
G4int GetNbSteps() const
Definition: G4Scheduler.hh:329
void SetTimeSteps(std::map< G4double, G4double > *)
Definition: G4Scheduler.hh:312
void SetInteractivity(G4ITTrackingInteractivity *)
void SetUserAction(G4UserTimeStepAction *)
Definition: G4Scheduler.hh:370
G4double GetLimitingTimeStep() const
Definition: G4Scheduler.cc:953
G4int GetMaxNbSteps() const
Definition: G4Scheduler.hh:339
void SetVerbose(G4int)
Definition: G4Scheduler.hh:380
void Stepping()
Definition: G4Scheduler.cc:663
virtual ~G4Scheduler()
Definition: G4Scheduler.cc:203
static G4Scheduler * Instance()
Definition: G4Scheduler.cc:101
G4ITModelHandler * GetModelHandler()
Definition: G4Scheduler.hh:301
G4ITStepStatus GetStatus() const
Definition: G4Scheduler.hh:416
void Process()
Definition: G4Scheduler.cc:379
G4double GetEndTime() const
Definition: G4Scheduler.hh:349
void ClearList()
Definition: G4Scheduler.cc:267
G4bool AreDefaultTimeStepsUsed()
Definition: G4Scheduler.hh:451
void WhyDoYouStop()
Definition: G4Scheduler.hh:441
G4double GetPreviousTimeStep() const
Definition: G4Scheduler.hh:411
virtual size_t GetNTracks()
void SetDefaultTimeStep(G4double)
Definition: G4Scheduler.hh:359
void AddWatchedTime(G4double time)
Definition: G4Scheduler.hh:177
G4double GetGlobalTime() const
Definition: G4Scheduler.hh:364
G4ITGun * GetGun()
Definition: G4Scheduler.hh:436
G4ITTrackingInteractivity * GetInteractivity()
Definition: G4Scheduler.hh:426
void Initialize()
Definition: G4Scheduler.cc:284
void SetMaxZeroTimeAllowed(G4int)
Definition: G4Scheduler.hh:391
void SetEndTime(const G4double)
Definition: G4Scheduler.hh:306
G4double GetTimeTolerance() const
Definition: G4Scheduler.hh:406
void SetTimeTolerance(G4double)
Definition: G4Scheduler.hh:401
void GetCollisionType(G4String &interactionType)
void ResetScavenger(bool)
Definition: G4Scheduler.hh:456
void DoProcess()
Definition: G4Scheduler.cc:616
void PrintWhyDoYouStop()
Definition: G4Scheduler.cc:572
G4int GetVerbose() const
Definition: G4Scheduler.hh:385
static void DeleteInstance()
Definition: G4Scheduler.cc:123
void SetScavengerMaterial(std::unique_ptr< G4VScavengerMaterial > scavengerMaterial)
Definition: G4Scheduler.hh:198
G4double GetStartTime() const
Definition: G4Scheduler.hh:344
virtual G4double GetTimeStep() const
Definition: G4Scheduler.hh:354
void UseDefaultTimeSteps(G4bool)
Definition: G4Scheduler.hh:446
G4VScavengerMaterial * GetScavengerMaterial() const
Definition: G4Scheduler.hh:194
G4int GetTrackID() const
G4bool operator()(G4Track *rhs, G4Track *lhs) const
Definition: G4ITReaction.hh:50
#define G4ThreadLocal
Definition: tls.hh:77