File indexing completed on 2025-01-18 09:59:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 #ifndef G4Scheduler_h
0049 #define G4Scheduler_h
0050
0051 #include <G4VScheduler.hh>
0052 #include <vector>
0053 #include <map>
0054 #include <memory>
0055
0056 #include "globals.hh"
0057
0058 #include "G4ITModelHandler.hh"
0059 #include "G4ITStepStatus.hh"
0060 #include "G4ITTrackHolder.hh"
0061 #include "G4VStateDependent.hh"
0062 #include "G4ITReaction.hh"
0063 #include "G4VScavengerMaterial.hh"
0064
0065 class G4ITTrackingManager;
0066 class G4ITModelProcessor;
0067 class G4ITStepProcessor;
0068 class G4Track;
0069 class G4UserTimeStepAction;
0070 class G4SchedulerMessenger;
0071 class G4ITTrackingInteractivity;
0072 class G4ITGun;
0073
0074 #ifndef compTrackPerID__
0075 #define compTrackPerID__
0076 struct compTrackPerID
0077 {
0078 G4bool operator()(G4Track* rhs, G4Track* lhs) const
0079 {
0080 return rhs->GetTrackID() < lhs->GetTrackID();
0081 }
0082 };
0083 #endif
0084
0085
0086
0087
0088 class G4Scheduler :
0089 public G4VScheduler,
0090 public G4VStateDependent
0091 {
0092 protected:
0093 ~G4Scheduler() override;
0094
0095 public:
0096 G4Scheduler(const G4Scheduler&) = delete;
0097 G4Scheduler& operator=(const G4Scheduler&) = delete;
0098
0099 static G4Scheduler* Instance();
0100
0101
0102
0103 static void DeleteInstance();
0104 G4bool Notify(G4ApplicationState requestedState) override;
0105
0106 void RegisterModel(G4VITStepModel*, G4double) override;
0107
0108 void Initialize() override;
0109 void ForceReinitialization();
0110 inline G4bool IsInitialized();
0111 inline G4bool IsRunning() override{return fRunning;}
0112 void Reset() override;
0113 void Process() override;
0114 void ClearList();
0115
0116 inline void SetGun(G4ITGun*) override;
0117 inline G4ITGun* GetGun();
0118
0119 inline void Stop();
0120 void Clear();
0121
0122
0123
0124
0125
0126 void EndTracking();
0127
0128 void SetEndTime(const G4double) override;
0129
0130
0131
0132
0133 inline void SetTimeTolerance(G4double) override;
0134 inline G4double GetTimeTolerance() const override;
0135
0136 inline void SetMaxZeroTimeAllowed(G4int) override;
0137 inline G4int GetMaxZeroTimeAllowed() const override;
0138
0139 inline G4ITModelHandler* GetModelHandler() override;
0140
0141 inline void SetTimeSteps(std::map<G4double, G4double>*) override;
0142 inline void AddTimeStep(G4double, G4double) override;
0143 inline void SetDefaultTimeStep(G4double) override;
0144 G4double GetLimitingTimeStep() const override;
0145 inline G4int GetNbSteps() const override;
0146 inline void SetMaxNbSteps(G4int) override;
0147 inline G4int GetMaxNbSteps() const override;
0148 inline G4double GetStartTime() const override;
0149 inline G4double GetEndTime() const override;
0150 inline G4double GetTimeStep() const override;
0151 inline G4double GetPreviousTimeStep() const override;
0152 inline G4double GetGlobalTime() const override;
0153 inline void SetUserAction(G4UserTimeStepAction*) override;
0154 inline G4UserTimeStepAction* GetUserTimeStepAction() const override;
0155
0156
0157 inline void UseDefaultTimeSteps(G4bool);
0158 inline G4bool AreDefaultTimeStepsUsed();
0159
0160 inline G4ITStepStatus GetStatus() const;
0161
0162
0163
0164
0165
0166
0167 inline void SetVerbose(G4int) override;
0168
0169 inline G4int GetVerbose() const;
0170
0171 inline void WhyDoYouStop();
0172
0173 void SetInteractivity(G4ITTrackingInteractivity*) override;
0174 inline G4ITTrackingInteractivity* GetInteractivity() override;
0175
0176 virtual size_t GetNTracks();
0177
0178 void GetCollisionType(G4String& interactionType);
0179
0180 void AddWatchedTime(G4double time)
0181 {
0182 fWatchedTimes.insert(time);
0183 }
0184
0185 G4double GetNextWatchedTime() const;
0186
0187 inline void SetMaxTimeStep(G4double maxTimeStep)
0188 {
0189 fMaxTimeStep = maxTimeStep;
0190 }
0191
0192 inline G4double GetMaxTimeStep() const
0193 {
0194 return fMaxTimeStep;
0195 }
0196
0197 inline G4VScavengerMaterial* GetScavengerMaterial() const
0198 {
0199 return fpUserScavenger.get();
0200 }
0201 inline void SetScavengerMaterial(std::unique_ptr<G4VScavengerMaterial> scavengerMaterial)
0202 {
0203 fpUserScavenger = std::move(scavengerMaterial);
0204 }
0205
0206 protected:
0207
0208 void DoProcess();
0209 void SynchronizeTracks();
0210 void Stepping();
0211
0212 void FindUserPreDefinedTimeStep();
0213
0214 G4bool CanICarryOn();
0215
0216 void PrintWhyDoYouStop();
0217
0218 private:
0219 G4Scheduler();
0220 void Create();
0221
0222 G4SchedulerMessenger* fpMessenger;
0223
0224 static G4ThreadLocal G4Scheduler* fgScheduler;
0225 G4int fVerbose;
0226 G4bool fWhyDoYouStop;
0227 G4bool fInitialized;
0228 G4bool fRunning;
0229 G4bool fContinue;
0230
0231 G4int fNbSteps;
0232 G4int fMaxSteps;
0233
0234 G4ITStepStatus fITStepStatus;
0235
0236
0237 G4bool fUseDefaultTimeSteps;
0238 G4double fTimeTolerance;
0239 G4double fGlobalTime;
0240 G4double fTmpGlobalTime;
0241 G4double fStartTime;
0242 G4double fStopTime;
0243 G4double fEndTime;
0244 G4double fPreviousTimeStep;
0245 G4int fZeroTimeCount;
0246 G4int fMaxNZeroTimeStepsAllowed;
0247
0248 G4double fTimeStep;
0249 G4double fMaxTimeStep;
0250
0251
0252 G4bool fUsePreDefinedTimeSteps;
0253 G4double fDefaultMinTimeStep;
0254 std::map<G4double, G4double>* fpUserTimeSteps;
0255
0256 mutable G4double fUserUpperTimeLimit;
0257 G4double fDefinedMinTimeStep;
0258
0259 G4bool fReachedUserTimeLimit;
0260
0261 std::set<G4double> fWatchedTimes;
0262
0263 G4UserTimeStepAction* fpUserTimeStepAction;
0264
0265 std::unique_ptr<G4VScavengerMaterial> fpUserScavenger;
0266
0267
0268
0269 G4ITStepProcessor* fpStepProcessor;
0270 G4ITModelProcessor* fpModelProcessor;
0271 G4ITTrackingManager* fpTrackingManager;
0272 G4ITTrackingInteractivity* fpTrackingInteractivity;
0273 G4ITReactionSet* fReactionSet;
0274 G4ITTrackHolder& fTrackContainer;
0275 G4ITModelHandler* fpModelHandler;
0276
0277
0278 G4double fTSTimeStep;
0279
0280 G4double fILTimeStep;
0281
0282
0283
0284 G4bool fInteractionStep;
0285
0286
0287
0288 G4ITGun* fpGun;
0289
0290
0291
0292 bool fResetScavenger;
0293 public:
0294 void ResetScavenger(bool);
0295 };
0296
0297 inline G4bool G4Scheduler::IsInitialized()
0298 {
0299 return fInitialized;
0300 }
0301
0302 inline G4ITModelHandler* G4Scheduler::GetModelHandler()
0303 {
0304 return fpModelHandler;
0305 }
0306
0307 inline void G4Scheduler::SetEndTime(const G4double __endtime)
0308 {
0309 fEndTime = __endtime;
0310 }
0311
0312 inline
0313 void G4Scheduler::SetTimeSteps(std::map<G4double, G4double>* steps)
0314 {
0315 fUsePreDefinedTimeSteps = true;
0316 fpUserTimeSteps = steps;
0317 }
0318
0319 inline void G4Scheduler::AddTimeStep(G4double startingTime, G4double timeStep)
0320 {
0321 if (fpUserTimeSteps == nullptr)
0322 {
0323 fpUserTimeSteps = new std::map<G4double, G4double>();
0324 fUsePreDefinedTimeSteps = true;
0325 }
0326
0327 (*fpUserTimeSteps)[startingTime] = timeStep;
0328 }
0329
0330 inline G4int G4Scheduler::GetNbSteps() const
0331 {
0332 return fNbSteps;
0333 }
0334
0335 inline void G4Scheduler::SetMaxNbSteps(G4int maxSteps)
0336 {
0337 fMaxSteps = maxSteps;
0338 }
0339
0340 inline G4int G4Scheduler::GetMaxNbSteps() const
0341 {
0342 return fMaxSteps;
0343 }
0344
0345 inline G4double G4Scheduler::GetStartTime() const
0346 {
0347 return fStartTime;
0348 }
0349
0350 inline G4double G4Scheduler::GetEndTime() const
0351 {
0352 return fEndTime;
0353 }
0354
0355 inline G4double G4Scheduler::GetTimeStep() const
0356 {
0357 return fTimeStep;
0358 }
0359
0360 inline void G4Scheduler::SetDefaultTimeStep(G4double timeStep)
0361 {
0362 fDefaultMinTimeStep = timeStep;
0363 }
0364
0365 inline G4double G4Scheduler::GetGlobalTime() const
0366 {
0367 return fGlobalTime;
0368 }
0369
0370 inline
0371 void G4Scheduler::SetUserAction(G4UserTimeStepAction* userITAction)
0372 {
0373 fpUserTimeStepAction = userITAction;
0374 }
0375
0376 inline G4UserTimeStepAction* G4Scheduler::GetUserTimeStepAction() const
0377 {
0378 return fpUserTimeStepAction;
0379 }
0380
0381 inline void G4Scheduler::SetVerbose(G4int verbose)
0382 {
0383 fVerbose = verbose;
0384 }
0385
0386 inline G4int G4Scheduler::GetVerbose() const
0387 {
0388 return fVerbose;
0389 }
0390
0391 inline
0392 void G4Scheduler::SetMaxZeroTimeAllowed(G4int maxTimeStepAllowed)
0393 {
0394 fMaxNZeroTimeStepsAllowed = maxTimeStepAllowed;
0395 }
0396
0397 inline G4int G4Scheduler::GetMaxZeroTimeAllowed() const
0398 {
0399 return fMaxNZeroTimeStepsAllowed;
0400 }
0401
0402 inline void G4Scheduler::SetTimeTolerance(G4double time)
0403 {
0404 fTimeTolerance = time;
0405 }
0406
0407 inline G4double G4Scheduler::GetTimeTolerance() const
0408 {
0409 return fTimeTolerance;
0410 }
0411
0412 inline G4double G4Scheduler::GetPreviousTimeStep() const
0413 {
0414 return fPreviousTimeStep;
0415 }
0416
0417 inline G4ITStepStatus G4Scheduler::GetStatus() const
0418 {
0419 return fITStepStatus;
0420 }
0421
0422 inline void G4Scheduler::Stop()
0423 {
0424 fContinue = false;
0425 }
0426
0427 inline G4ITTrackingInteractivity* G4Scheduler::GetInteractivity()
0428 {
0429 return fpTrackingInteractivity;
0430 }
0431
0432 inline void G4Scheduler::SetGun(G4ITGun* gun)
0433 {
0434 fpGun = gun;
0435 }
0436
0437 inline G4ITGun* G4Scheduler::GetGun()
0438 {
0439 return fpGun;
0440 }
0441
0442 inline void G4Scheduler::WhyDoYouStop()
0443 {
0444 fWhyDoYouStop = true;
0445 }
0446
0447 inline void G4Scheduler::UseDefaultTimeSteps(G4bool flag)
0448 {
0449 fUseDefaultTimeSteps = flag;
0450 }
0451
0452 inline G4bool G4Scheduler::AreDefaultTimeStepsUsed()
0453 {
0454 return (!fUseDefaultTimeSteps && !fUsePreDefinedTimeSteps);
0455 }
0456
0457 inline void G4Scheduler::ResetScavenger(bool value)
0458 {
0459 fResetScavenger = value;
0460 }
0461
0462 #endif