Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // 26 // 27 // Author: Mathieu Karamitros (kara (AT) cenbg 27 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 28 // 28 // 29 // History: 29 // History: 30 // ----------- 30 // ----------- 31 // 10 Oct 2011 M.Karamitros created 31 // 10 Oct 2011 M.Karamitros created 32 // 32 // 33 // ------------------------------------------- 33 // ------------------------------------------------------------------- 34 34 35 #include "G4ITGun.hh" << 35 #include <G4AllITFinder.hh> 36 #include "G4ITModelHandler.hh" << 36 #include <G4Scheduler.hh> >> 37 #include <G4SchedulerMessenger.hh> >> 38 >> 39 #include "G4SystemOfUnits.hh" 37 #include "G4ITModelProcessor.hh" 40 #include "G4ITModelProcessor.hh" 38 #include "G4ITStepProcessor.hh" 41 #include "G4ITStepProcessor.hh" 39 #include "G4ITStepStatus.hh" << 42 #include "G4IT.hh" 40 #include "G4ITTrackingInteractivity.hh" << 43 #include "G4ITReactionChange.hh" >> 44 #include "G4ITModelHandler.hh" >> 45 #include "G4VITStepModel.hh" >> 46 #include "G4UserTimeStepAction.hh" 41 #include "G4ITTrackingManager.hh" 47 #include "G4ITTrackingManager.hh" 42 #include "G4IosFlagsSaver.hh" << 48 #include "G4ITTrackingInteractivity.hh" 43 #include "G4StateManager.hh" << 44 #include "G4SystemOfUnits.hh" << 45 #include "G4Timer.hh" << 46 #include "G4TrackingInformation.hh" 49 #include "G4TrackingInformation.hh" 47 #include "G4UnitsTable.hh" 50 #include "G4UnitsTable.hh" 48 #include "G4UserTimeStepAction.hh" << 51 #include "G4ITStepStatus.hh" 49 #include "G4VITStepModel.hh" << 52 #include "G4ITGun.hh" 50 << 53 #include "G4StateManager.hh" 51 #include <G4AllITFinder.hh> << 54 #include "G4Timer.hh" 52 #include <G4Scheduler.hh> << 55 #include "G4IosFlagsSaver.hh" 53 #include <G4SchedulerMessenger.hh> << 54 << 55 #include <sstream> 56 #include <sstream> 56 57 >> 58 //#include "G4Phenomenon.hh" >> 59 //#include "G4MIWorkspace.hh" >> 60 >> 61 //#define DEBUG_MEM 1 57 #define DEBUG_MEM_STEPPING 62 #define DEBUG_MEM_STEPPING 58 #define DEBUG_MEM_DETAILED_STEPPING 63 #define DEBUG_MEM_DETAILED_STEPPING >> 64 //#define DEBUG_MEM_DOIT 59 65 60 #ifdef DEBUG_MEM 66 #ifdef DEBUG_MEM 61 # include "G4MemStat.hh" << 67 #include "G4MemStat.hh" 62 using namespace G4MemStat; 68 using namespace G4MemStat; 63 using G4MemStat::MemStat; 69 using G4MemStat::MemStat; 64 #endif 70 #endif 65 71 >> 72 //COLOR FOR DEBUGING >> 73 //#define USE_COLOR 1 >> 74 66 #ifdef USE_COLOR 75 #ifdef USE_COLOR 67 # define RED "\033[0;31m" << 76 #define RED "\033[0;31m" 68 # define LIGHT_RED "\33[1;31m" << 77 #define LIGHT_RED "\33[1;31m" 69 # define GREEN "\033[32;40m" << 78 #define GREEN "\033[32;40m" 70 # define GREEN_ON_BLUE "\033[1;32;44m" << 79 #define GREEN_ON_BLUE "\033[1;32;44m" 71 # define RESET_COLOR "\033[0m" << 80 #define RESET_COLOR "\033[0m" 72 #else 81 #else 73 # define RED "" << 82 #define RED "" 74 # define LIGHT_RED "" << 83 #define LIGHT_RED "" 75 # define GREEN "" << 84 #define GREEN "" 76 # define GREEN_ON_BLUE "" << 85 #define GREEN_ON_BLUE "" 77 # define RESET_COLOR "" << 86 #define RESET_COLOR "" 78 #endif 87 #endif 79 88 80 using namespace std; 89 using namespace std; 81 90 82 G4ThreadLocal G4Scheduler* G4Scheduler::fgSche << 91 G4ThreadLocal G4Scheduler* G4Scheduler::fgScheduler(0); 83 92 84 template<typename T> 93 template<typename T> 85 inline G4bool IsInf(T value) << 94 inline G4bool IsInf(T value) 86 { << 95 { 87 return std::numeric_limits<T>::has_infinity << 96 return std::numeric_limits<T>::has_infinity 88 } << 97 && value == std::numeric_limits<T>::infinity(); >> 98 } 89 //____________________________________________ 99 //_________________________________________________________________________ 90 100 91 G4Scheduler* G4Scheduler::Instance() 101 G4Scheduler* G4Scheduler::Instance() 92 { 102 { 93 if (fgScheduler == nullptr) fgScheduler = ne << 103 if(fgScheduler == 0) fgScheduler = new G4Scheduler(); 94 return fgScheduler; 104 return fgScheduler; 95 } 105 } 96 //____________________________________________ 106 //_________________________________________________________________________ 97 107 98 G4bool G4Scheduler::Notify(G4ApplicationState 108 G4bool G4Scheduler::Notify(G4ApplicationState requestedState) 99 { 109 { 100 if (requestedState == G4State_Quit) { << 110 if(requestedState == G4State_Quit) 101 if (fVerbose >= 4) { << 111 { >> 112 if(fVerbose >= 4) >> 113 { 102 G4cout << "G4Scheduler received G4State_ 114 G4cout << "G4Scheduler received G4State_Quit" << G4endl; 103 } 115 } 104 Clear(); 116 Clear(); >> 117 //DeleteInstance(); 105 } 118 } 106 return true; 119 return true; 107 } 120 } 108 //____________________________________________ 121 //_________________________________________________________________________ 109 122 110 void G4Scheduler::DeleteInstance() 123 void G4Scheduler::DeleteInstance() 111 { 124 { 112 delete fgScheduler; << 125 if(fgScheduler) >> 126 { >> 127 delete fgScheduler; >> 128 } 113 } 129 } 114 //____________________________________________ 130 //_________________________________________________________________________ 115 131 116 G4Scheduler::G4Scheduler() : fTrackContainer(( << 132 G4Scheduler::G4Scheduler() : >> 133 G4VScheduler(), G4VStateDependent(), >> 134 fTrackContainer((G4ITTrackHolder&) *G4ITTrackHolder::Instance()) 117 { 135 { 118 Create(); 136 Create(); 119 } 137 } 120 138 121 void G4Scheduler::Create() 139 void G4Scheduler::Create() 122 { 140 { 123 fUseDefaultTimeSteps = true; 141 fUseDefaultTimeSteps = true; 124 fUserUpperTimeLimit = -1; 142 fUserUpperTimeLimit = -1; 125 fpGun = nullptr; << 143 fpGun = 0; 126 fContinue = true; 144 fContinue = true; 127 fpTrackingInteractivity = nullptr; << 145 // fpMainList = 0; >> 146 // fpWaitingList = 0; >> 147 fpTrackingInteractivity = 0; >> 148 128 fITStepStatus = eUndefined; 149 fITStepStatus = eUndefined; 129 fpUserTimeSteps = nullptr; << 150 >> 151 fpUserTimeSteps = 0; >> 152 130 fTimeStep = DBL_MAX; 153 fTimeStep = DBL_MAX; 131 fTSTimeStep = DBL_MAX; 154 fTSTimeStep = DBL_MAX; 132 fILTimeStep = DBL_MAX; 155 fILTimeStep = DBL_MAX; 133 fPreviousTimeStep = DBL_MAX; 156 fPreviousTimeStep = DBL_MAX; >> 157 134 fZeroTimeCount = 0; 158 fZeroTimeCount = 0; 135 fMaxNZeroTimeStepsAllowed = 10000; 159 fMaxNZeroTimeStepsAllowed = 10000; >> 160 136 fStartTime = 0; 161 fStartTime = 0; 137 fTimeTolerance = 1 * picosecond; 162 fTimeTolerance = 1 * picosecond; 138 fEndTime = 1 * microsecond; 163 fEndTime = 1 * microsecond; 139 fGlobalTime = -1; 164 fGlobalTime = -1; 140 fInteractionStep = true; 165 fInteractionStep = true; 141 fUsePreDefinedTimeSteps = false; 166 fUsePreDefinedTimeSteps = false; 142 167 143 fDefaultMinTimeStep = 1 * picosecond; 168 fDefaultMinTimeStep = 1 * picosecond; 144 fpStepProcessor = nullptr; << 169 145 fpModelProcessor = nullptr; << 170 fpStepProcessor = 0; >> 171 fpModelProcessor = 0; >> 172 146 fNbSteps = 0; 173 fNbSteps = 0; 147 fMaxSteps = -1; 174 fMaxSteps = -1; >> 175 148 fRunning = false; 176 fRunning = false; 149 fInitialized = false; 177 fInitialized = false; 150 fpUserTimeStepAction = nullptr; << 178 >> 179 fpUserTimeStepAction = 0; 151 fpModelHandler = new G4ITModelHandler(); 180 fpModelHandler = new G4ITModelHandler(); 152 fpTrackingManager = new G4ITTrackingManager( 181 fpTrackingManager = new G4ITTrackingManager(); >> 182 153 fVerbose = 0; 183 fVerbose = 0; 154 fWhyDoYouStop = false; 184 fWhyDoYouStop = false; 155 fDefinedMinTimeStep = -1.; 185 fDefinedMinTimeStep = -1.; 156 fReachedUserTimeLimit = false; 186 fReachedUserTimeLimit = false; 157 fStopTime = -1.; 187 fStopTime = -1.; >> 188 fTmpGlobalTime = -1.; >> 189 158 fpMessenger = new G4SchedulerMessenger(this) 190 fpMessenger = new G4SchedulerMessenger(this); >> 191 159 fReactionSet = G4ITReactionSet::Instance(); 192 fReactionSet = G4ITReactionSet::Instance(); 160 fMaxTimeStep = DBL_MAX; 193 fMaxTimeStep = DBL_MAX; 161 // hoang add << 194 162 fResetScavenger = true; // true by default << 195 //hoang add >> 196 fResetScavenger = true;//true by default >> 197 163 G4ITTypeManager::Instance()->ReserveRessourc 198 G4ITTypeManager::Instance()->ReserveRessource(); 164 } 199 } 165 200 166 //____________________________________________ 201 //_________________________________________________________________________ 167 202 168 G4Scheduler::~G4Scheduler() 203 G4Scheduler::~G4Scheduler() 169 { 204 { 170 if (fpMessenger != nullptr) // is used as a << 205 >> 206 if(fpMessenger) // is used as a flag to know whether the manager was cleared 171 { 207 { 172 Clear(); 208 Clear(); 173 } 209 } 174 fgScheduler = nullptr; << 210 >> 211 fgScheduler = 0; >> 212 >> 213 // if (fVerbose >= 1) >> 214 // { >> 215 // G4cout << "G4Scheduler is being deleted. Bye :) !" << G4endl; >> 216 // } 175 } 217 } 176 218 177 void G4Scheduler::Clear() 219 void G4Scheduler::Clear() 178 { 220 { 179 if (fpMessenger != nullptr) { << 221 // if (fVerbose) G4cout << "*** G4Scheduler is being cleared ***" << G4endl; >> 222 >> 223 if(fpMessenger) >> 224 { 180 delete fpMessenger; 225 delete fpMessenger; 181 fpMessenger = nullptr; << 226 fpMessenger = 0; 182 } 227 } 183 if (fpStepProcessor != nullptr) { << 228 if(fpStepProcessor) >> 229 { 184 delete fpStepProcessor; 230 delete fpStepProcessor; 185 fpStepProcessor = nullptr; << 231 fpStepProcessor = 0; 186 } 232 } 187 if (fpModelProcessor != nullptr) { << 233 if(fpModelProcessor) >> 234 { 188 delete fpModelProcessor; 235 delete fpModelProcessor; 189 fpModelProcessor = nullptr; << 236 fpModelProcessor = 0; 190 } 237 } 191 238 192 G4ITTypeManager::Instance()->ReleaseRessourc 239 G4ITTypeManager::Instance()->ReleaseRessource(); 193 ClearList(); 240 ClearList(); 194 if (fpTrackingManager != nullptr) { << 241 if(fpTrackingManager) >> 242 { 195 delete fpTrackingManager; 243 delete fpTrackingManager; 196 fpTrackingManager = nullptr; << 244 fpTrackingManager = 0; 197 } 245 } 198 246 199 if (fReactionSet != nullptr) { << 247 if(fReactionSet) >> 248 { 200 delete fReactionSet; 249 delete fReactionSet; 201 fReactionSet = nullptr; << 250 fReactionSet = 0; 202 } 251 } 203 252 204 if (fpModelHandler != nullptr) { << 253 if(fpModelHandler) >> 254 { 205 delete fpModelHandler; 255 delete fpModelHandler; 206 fpModelHandler = nullptr; << 256 fpModelHandler = 0; 207 } 257 } >> 258 >> 259 //* DEBUG >> 260 //* assert(G4StateManager::GetStateManager()-> >> 261 //* DeregisterDependent(this) == true); >> 262 208 } 263 } 209 264 210 //____________________________________________ 265 //_________________________________________________________________________ 211 266 212 void G4Scheduler::ClearList() 267 void G4Scheduler::ClearList() 213 { 268 { >> 269 // if (fNbTracks == 0) return; >> 270 214 fTrackContainer.Clear(); 271 fTrackContainer.Clear(); >> 272 215 G4AllITFinder::DeleteInstance(); 273 G4AllITFinder::DeleteInstance(); 216 } 274 } 217 275 218 //____________________________________________ 276 //_________________________________________________________________________ 219 void G4Scheduler::RegisterModel(G4VITStepModel 277 void G4Scheduler::RegisterModel(G4VITStepModel* model, G4double time) 220 { 278 { 221 fpModelHandler->RegisterModel(model, time); 279 fpModelHandler->RegisterModel(model, time); 222 } 280 } 223 281 224 //____________________________________________ 282 //_________________________________________________________________________ 225 283 226 void G4Scheduler::Initialize() 284 void G4Scheduler::Initialize() 227 { 285 { 228 delete fpStepProcessor; << 286 if(fpStepProcessor) 229 delete fpModelProcessor; << 287 { >> 288 delete fpStepProcessor; >> 289 } >> 290 if(fpModelProcessor) >> 291 { >> 292 delete fpModelProcessor; >> 293 } >> 294 // if(fpMasterModelProcessor) >> 295 // { >> 296 // delete fpMasterModelProcessor; >> 297 // } >> 298 >> 299 //______________________________________________________________ 230 300 231 fpModelProcessor = new G4ITModelProcessor(); 301 fpModelProcessor = new G4ITModelProcessor(); 232 fpModelProcessor->SetModelHandler(fpModelHan 302 fpModelProcessor->SetModelHandler(fpModelHandler); 233 fpModelProcessor->SetTrackingManager(fpTrack 303 fpModelProcessor->SetTrackingManager(fpTrackingManager); >> 304 >> 305 // fpMasterModelProcessor = new G4ITModelProcessor(); >> 306 // fpMasterModelProcessor->SetModelHandler(fpModelHandler); >> 307 // fpModelProcessor = fpMasterModelProcessor; >> 308 >> 309 //______________________________________________________________ >> 310 234 fpStepProcessor = new G4ITStepProcessor(); 311 fpStepProcessor = new G4ITStepProcessor(); 235 fpStepProcessor->SetTrackingManager(fpTracki 312 fpStepProcessor->SetTrackingManager(fpTrackingManager); >> 313 236 fpTrackingManager->SetInteractivity(fpTracki 314 fpTrackingManager->SetInteractivity(fpTrackingInteractivity); 237 if (fUsePreDefinedTimeSteps) { << 315 238 if (fpUserTimeSteps == nullptr) // Extra << 316 // fpMasterStepProcessor = new G4ITStepProcessor(); >> 317 // fpMasterStepProcessor->SetTrackingManager(fpTrackingManager); >> 318 // fpStepProcessor = fpMasterStepProcessor ; >> 319 //______________________________________________________________ >> 320 >> 321 if(fUsePreDefinedTimeSteps) >> 322 { >> 323 if(fpUserTimeSteps == 0) // Extra checking, is it necessary ? 239 { 324 { 240 G4ExceptionDescription exceptionDescript 325 G4ExceptionDescription exceptionDescription; 241 exceptionDescription << "You are asking << 326 exceptionDescription 242 G4Exception("G4Scheduler::FindUserPreDef << 327 << "You are asking to use user defined steps but you did not give any."; >> 328 G4Exception("G4Scheduler::FindUserPreDefinedTimeStep", >> 329 "Scheduler004", >> 330 FatalErrorInArgument, 243 exceptionDescription); 331 exceptionDescription); 244 return; // makes coverity happy << 332 return; // makes coverity happy 245 } 333 } 246 } 334 } 247 335 >> 336 // if (fComputeTimeStep) >> 337 // { >> 338 // if (fpModelProcessor == 0) >> 339 // { >> 340 // G4ExceptionDescription exceptionDescription; >> 341 // exceptionDescription >> 342 // << "There is no G4ITModelProcessor to handle IT reaction. "; >> 343 // exceptionDescription >> 344 // << "You probably did not initialize the G4Scheduler. "; >> 345 // exceptionDescription >> 346 // << "Just do G4Scheduler::Instance()->Initialize(); "; >> 347 // exceptionDescription << " but only after initializing the run manager."; >> 348 // G4Exception("G4Scheduler::CalculateMinStep", "ITScheduler005", >> 349 // FatalErrorInArgument, exceptionDescription); >> 350 // return; // makes coverity happy >> 351 // } >> 352 // } >> 353 248 fInitialized = true; 354 fInitialized = true; 249 } 355 } 250 356 251 //____________________________________________ 357 //_________________________________________________________________________ 252 358 253 void G4Scheduler::Reset() 359 void G4Scheduler::Reset() 254 { 360 { 255 fStartTime = 0; 361 fStartTime = 0; 256 fUserUpperTimeLimit = -1; 362 fUserUpperTimeLimit = -1; 257 fTimeStep = DBL_MAX; 363 fTimeStep = DBL_MAX; 258 fTSTimeStep = DBL_MAX; 364 fTSTimeStep = DBL_MAX; 259 fILTimeStep = DBL_MAX; 365 fILTimeStep = DBL_MAX; 260 fPreviousTimeStep = DBL_MAX; 366 fPreviousTimeStep = DBL_MAX; 261 fGlobalTime = -1; 367 fGlobalTime = -1; 262 fInteractionStep = true; 368 fInteractionStep = true; 263 fITStepStatus = eUndefined; 369 fITStepStatus = eUndefined; 264 fZeroTimeCount = 0; 370 fZeroTimeCount = 0; 265 371 266 fNbSteps = 0; 372 fNbSteps = 0; 267 fContinue = true; 373 fContinue = true; >> 374 // fReactingTracks.clear(); 268 fReactionSet->CleanAllReaction(); 375 fReactionSet->CleanAllReaction(); 269 } 376 } 270 //____________________________________________ 377 //_________________________________________________________________________ 271 378 272 void G4Scheduler::Process() 379 void G4Scheduler::Process() 273 { 380 { >> 381 274 #ifdef G4VERBOSE 382 #ifdef G4VERBOSE 275 if (fVerbose != 0) { << 383 if(fVerbose) >> 384 { 276 G4cout << "*** G4Scheduler starts processi 385 G4cout << "*** G4Scheduler starts processing " << G4endl; 277 if (fVerbose > 2) << 386 if(fVerbose > 2) 278 G4cout << "_____________________________ << 387 G4cout << "___________________________________________" 279 "___________________________" << 388 "___________________________" << G4endl; 280 << G4endl; << 281 } 389 } 282 #endif 390 #endif 283 391 284 if (!fInitialized) { << 392 if (fInitialized == false) Initialize(); 285 Initialize(); << 393 286 } << 394 // fpTrackingManager->Initialize(); 287 fpModelProcessor->Initialize(); 395 fpModelProcessor->Initialize(); 288 fpStepProcessor->Initialize(); 396 fpStepProcessor->Initialize(); 289 397 290 if (fpGun != nullptr) fpGun->DefineTracks(); << 398 // TODO >> 399 // fpMasterModelProcessor->Initialize(); >> 400 // fpMasterStepProcessor->Initialize(); 291 401 292 if (fpTrackingInteractivity != nullptr) fpTr << 402 if (fpGun) fpGun->DefineTracks(); >> 403 >> 404 if (fpTrackingInteractivity) fpTrackingInteractivity->Initialize(); 293 405 294 // ___________________ 406 // ___________________ 295 fRunning = true; 407 fRunning = true; 296 Reset(); 408 Reset(); 297 409 298 if (fResetScavenger) { << 410 //hoang 7/12/2020 299 if (fpUserScavenger != nullptr) { << 411 300 fpUserScavenger->Reset(); << 412 if(fResetScavenger) { >> 413 if (fpUserScavenger != nullptr) { >> 414 fpUserScavenger->Reset(); >> 415 } 301 } 416 } 302 } << 303 417 304 if (fpUserTimeStepAction != nullptr) { << 418 if (fpUserTimeStepAction) 305 fpUserTimeStepAction->StartProcessing(); << 419 { >> 420 fpUserTimeStepAction->StartProcessing(); 306 } 421 } 307 422 308 #ifdef G4VERBOSE 423 #ifdef G4VERBOSE 309 G4bool trackFound = false; 424 G4bool trackFound = false; 310 G4IosFlagsSaver iosfs(G4cout); 425 G4IosFlagsSaver iosfs(G4cout); 311 G4cout.precision(5); 426 G4cout.precision(5); 312 #endif 427 #endif 313 428 314 //========================================== 429 //=========================================================================== 315 // By default, before the G4Scheduler is lau 430 // By default, before the G4Scheduler is launched, the tracks are pushed to 316 // the delayed lists 431 // the delayed lists 317 //========================================== 432 //=========================================================================== 318 433 319 if (fTrackContainer.DelayListsNOTEmpty()) { << 434 if(fTrackContainer.DelayListsNOTEmpty()) >> 435 { 320 fStartTime = fTrackContainer.GetNextTime() 436 fStartTime = fTrackContainer.GetNextTime(); 321 #ifdef G4VERBOSE 437 #ifdef G4VERBOSE 322 trackFound = true; 438 trackFound = true; 323 G4Timer localtimer; 439 G4Timer localtimer; 324 if (fVerbose > 1) { << 440 if(fVerbose>1) >> 441 { 325 localtimer.Start(); 442 localtimer.Start(); 326 } 443 } 327 #endif 444 #endif 328 SynchronizeTracks(); 445 SynchronizeTracks(); 329 #ifdef G4VERBOSE 446 #ifdef G4VERBOSE 330 if (fVerbose > 1) { << 447 if(fVerbose>1) >> 448 { 331 localtimer.Stop(); 449 localtimer.Stop(); 332 G4cout << "G4Scheduler: process time= " << 450 G4cout << "G4Scheduler: process time= "<< localtimer << G4endl; 333 } 451 } 334 #endif 452 #endif 335 } 453 } >> 454 >> 455 // //--------------------------------- >> 456 // // TODO: This could be removed ? >> 457 // if(fTrackContainer.MainListsNOTEmpty() >> 458 // && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps) >> 459 // && fGlobalTime < fEndTime >> 460 // && fContinue == true) >> 461 //{ >> 462 //#ifdef G4VERBOSE >> 463 // trackFound = true; >> 464 //#endif >> 465 // DoProcess(); >> 466 //} >> 467 // //--------------------------------- >> 468 336 #ifdef G4VERBOSE 469 #ifdef G4VERBOSE 337 if (fVerbose != 0) { << 470 if(fVerbose) 338 if (trackFound) { << 471 { 339 G4cout << "*** G4Scheduler ends at time << 472 if(trackFound) >> 473 { >> 474 G4cout << "*** G4Scheduler ends at time : " >> 475 << G4BestUnit(fGlobalTime,"Time") << G4endl; 340 G4cout << "_____________________________ 476 G4cout << "___________________________________" << G4endl; 341 } 477 } 342 else { << 478 else >> 479 { 343 G4cout << "*** G4Scheduler did not start 480 G4cout << "*** G4Scheduler did not start because no " 344 "track was found to be process << 481 "track was found to be processed"<< G4endl; 345 << G4endl; << 346 G4cout << "_____________________________ 482 G4cout << "___________________________________" << G4endl; 347 } 483 } 348 } 484 } 349 #endif 485 #endif 350 486 351 fRunning = false; 487 fRunning = false; 352 488 353 if (fpUserTimeStepAction != nullptr) { << 489 if (fpUserTimeStepAction) fpUserTimeStepAction->EndProcessing(); 354 fpUserTimeStepAction->EndProcessing(); << 490 355 } << 356 // ___________________ 491 // ___________________ 357 EndTracking(); 492 EndTracking(); 358 ClearList(); 493 ClearList(); >> 494 359 Reset(); 495 Reset(); 360 496 361 if (fpTrackingInteractivity != nullptr) { << 497 if (fpTrackingInteractivity) fpTrackingInteractivity->Finalize(); 362 fpTrackingInteractivity->Finalize(); << 363 } << 364 } 498 } 365 499 366 //____________________________________________ 500 //_________________________________________________________________________ 367 501 368 G4double G4Scheduler::GetNextWatchedTime() con 502 G4double G4Scheduler::GetNextWatchedTime() const 369 { 503 { 370 auto up = fWatchedTimes.upper_bound(fGlobalT << 504 std::set<G4double>::const_iterator up = fWatchedTimes.upper_bound(fGlobalTime); 371 if (up == fWatchedTimes.end()) { << 505 if(up == fWatchedTimes.end()) return DBL_MAX; 372 return DBL_MAX; << 373 } << 374 return *up; 506 return *up; 375 } 507 } 376 508 377 //____________________________________________ 509 //_________________________________________________________________________ 378 510 379 void G4Scheduler::SynchronizeTracks() 511 void G4Scheduler::SynchronizeTracks() 380 { 512 { >> 513 // if(fTrackContainer.WaitingListsNOTEmpty()) >> 514 // { >> 515 // G4ExceptionDescription exceptionDescription; >> 516 // exceptionDescription >> 517 // << "There is a waiting track list (fpWaitingList != 0)."; >> 518 // exceptionDescription >> 519 // << " When G4Scheduler::SynchronizeTracks() is called, "; >> 520 // exceptionDescription >> 521 // << "no more tracks should remain in the fpWaitingList."; >> 522 // G4Exception("G4Scheduler::SynchronizeTracks", "ITScheduler002", >> 523 // FatalErrorInArgument, exceptionDescription); >> 524 // } >> 525 >> 526 // Backup main list and time feature >> 527 // Reminder : the main list here, should >> 528 // have the biggest global time >> 529 // fTrackContainer.MoveMainToWaitingList(); >> 530 // TODO: not yet supported >> 531 >> 532 fTmpGlobalTime = fGlobalTime; >> 533 //fTmpEndTime = fEndTime; >> 534 381 fGlobalTime = fTrackContainer.GetNextTime(); 535 fGlobalTime = fTrackContainer.GetNextTime(); 382 G4double tmpGlobalTime = fGlobalTime; 536 G4double tmpGlobalTime = fGlobalTime; >> 537 383 G4double nextWatchedTime = -1; 538 G4double nextWatchedTime = -1; 384 G4bool carryOn = true; 539 G4bool carryOn = true; 385 while (fTrackContainer.MergeNextTimeToMainLi << 540 386 if (tmpGlobalTime != fGlobalTime) { << 541 while(fTrackContainer.MergeNextTimeToMainList(tmpGlobalTime) && carryOn) 387 fGlobalTime = tmpGlobalTime; << 542 { 388 }; << 543 // assert(tmpGlobalTime == fGlobalTime); 389 fStopTime = min(fTrackContainer.GetNextTim 544 fStopTime = min(fTrackContainer.GetNextTime(), fEndTime); 390 while ((nextWatchedTime = GetNextWatchedTi << 545 while((nextWatchedTime = GetNextWatchedTime()) < fTrackContainer.GetNextTime() 391 && (carryOn = CanICarryOn())) << 546 && (carryOn = CanICarryOn())) 392 { 547 { 393 fStopTime = min(nextWatchedTime, fEndTim 548 fStopTime = min(nextWatchedTime, fEndTime); 394 DoProcess(); 549 DoProcess(); 395 } 550 } 396 551 397 carryOn = CanICarryOn(); 552 carryOn = CanICarryOn(); 398 553 399 if (nextWatchedTime > fEndTime && carryOn) << 554 if(nextWatchedTime > fEndTime && carryOn) >> 555 { 400 fStopTime = min(fTrackContainer.GetNextT 556 fStopTime = min(fTrackContainer.GetNextTime(), fEndTime); 401 DoProcess(); 557 DoProcess(); 402 } 558 } 403 } 559 } 404 } 560 } 405 561 406 //____________________________________________ 562 //_________________________________________________________________________ 407 563 408 G4bool G4Scheduler::CanICarryOn() 564 G4bool G4Scheduler::CanICarryOn() 409 { 565 { 410 return fGlobalTime < fEndTime && (fMaxSteps << 566 return fGlobalTime < fEndTime && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps) >> 567 && fContinue == true; 411 } 568 } 412 569 413 //____________________________________________ 570 //_________________________________________________________________________ 414 571 415 void G4Scheduler::PrintWhyDoYouStop() 572 void G4Scheduler::PrintWhyDoYouStop() 416 { 573 { 417 #ifdef G4VERBOSE 574 #ifdef G4VERBOSE 418 if (fWhyDoYouStop) { << 575 if(fWhyDoYouStop) >> 576 { 419 G4cout << "G4Scheduler has reached a stage 577 G4cout << "G4Scheduler has reached a stage: it might be" 420 " a transition or the end" << 578 " a transition or the end" 421 << G4endl; 579 << G4endl; 422 580 423 G4bool normalStop = false; 581 G4bool normalStop = false; 424 582 425 if (fGlobalTime >= fStopTime) { << 583 if(fGlobalTime >= fStopTime) >> 584 { 426 G4cout << "== G4Scheduler: I stop becaus 585 G4cout << "== G4Scheduler: I stop because I reached the stop time : " 427 << G4BestUnit(fStopTime, "Time") << 586 << G4BestUnit(fStopTime,"Time") << " =="<< G4endl; 428 normalStop = true; 587 normalStop = true; 429 } 588 } 430 if (!fTrackContainer.MainListsNOTEmpty()) << 589 if(fTrackContainer.MainListsNOTEmpty() == false) // is empty 431 { 590 { 432 G4cout << "G4Scheduler: I stop because t 591 G4cout << "G4Scheduler: I stop because the current main list of tracks " 433 "is empty" << 592 "is empty" 434 << G4endl; << 593 << G4endl; 435 normalStop = true; 594 normalStop = true; 436 } 595 } 437 if (fMaxSteps == -1 ? false : fNbSteps >= << 596 if(fMaxSteps == -1 ? false : fNbSteps >= fMaxSteps) >> 597 { 438 G4cout << "G4Scheduler: I stop because I 598 G4cout << "G4Scheduler: I stop because I reached the maximum allowed " 439 "number of steps=" << 599 "number of steps=" << fMaxSteps 440 << fMaxSteps << G4endl; << 600 << G4endl; 441 normalStop = true; 601 normalStop = true; 442 } 602 } 443 if (fContinue && !normalStop) { << 603 if(fContinue && normalStop == false) >> 604 { 444 G4cout << "G4Scheduler: It might be that 605 G4cout << "G4Scheduler: It might be that I stop because " 445 "I have been told so. You may << 606 "I have been told so. You may check " 446 "member fContinue and usage of << 607 "member fContinue and usage of the method G4Scheduler::Stop()." 447 << G4endl; << 608 << G4endl; 448 } 609 } 449 } 610 } 450 #endif 611 #endif 451 } 612 } 452 613 453 //____________________________________________ 614 //_________________________________________________________________________ 454 615 455 void G4Scheduler::DoProcess() 616 void G4Scheduler::DoProcess() >> 617 // We split it from the Process() method to avoid repeating code in SynchronizeTracks 456 { 618 { 457 if (fpUserTimeStepAction != nullptr) fpUserT << 619 if(fpUserTimeStepAction) fpUserTimeStepAction->NewStage(); 458 620 459 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 621 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING) 460 MemStat mem_first, mem_second, mem_diff; 622 MemStat mem_first, mem_second, mem_diff; 461 #endif 623 #endif 462 624 463 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 625 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING) 464 mem_first = MemoryUsage(); 626 mem_first = MemoryUsage(); 465 #endif 627 #endif 466 628 467 while (fGlobalTime < fStopTime && fTrackCont << 629 while (fGlobalTime < fStopTime 468 && (fMaxSteps == -1 ? true : fNbSteps << 630 && fTrackContainer.MainListsNOTEmpty() >> 631 && (fMaxSteps == -1 ? true : fNbSteps < fMaxSteps) >> 632 && fContinue == true) 469 { 633 { >> 634 // G4cout << "Mainlist size : " << fTrackContainer.GetMainList()->size() >> 635 // << G4endl; >> 636 470 Stepping(); 637 Stepping(); 471 638 472 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 639 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING) 473 mem_second = MemoryUsage(); 640 mem_second = MemoryUsage(); 474 mem_diff = mem_second - mem_first; << 641 mem_diff = mem_second-mem_first; 475 G4cout << "\t || MEM || After step " << fN << 642 G4cout << "\t || MEM || After step " << fNbSteps << ", diff is : " >> 643 << mem_diff << G4endl; 476 #endif 644 #endif 477 } 645 } 478 646 479 PrintWhyDoYouStop(); 647 PrintWhyDoYouStop(); 480 648 481 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_ST << 649 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_STEPPING) 482 mem_second = MemoryUsage(); 650 mem_second = MemoryUsage(); 483 mem_diff = mem_second - mem_first; << 651 mem_diff = mem_second-mem_first; 484 G4cout << "\t || MEM || After stepping, diff 652 G4cout << "\t || MEM || After stepping, diff is : " << mem_diff << G4endl; 485 #endif 653 #endif 486 654 487 #ifdef G4VERBOSE 655 #ifdef G4VERBOSE 488 if (fVerbose > 2) << 656 if(fVerbose > 2) 489 G4cout << "*** G4Scheduler has finished pr 657 G4cout << "*** G4Scheduler has finished processing a track list at time : " 490 << G4BestUnit(fGlobalTime, "Time") 658 << G4BestUnit(fGlobalTime, "Time") << G4endl; 491 #endif 659 #endif 492 } 660 } 493 //____________________________________________ 661 //_________________________________________________________________________ 494 662 495 void G4Scheduler::Stepping() 663 void G4Scheduler::Stepping() 496 { 664 { 497 fTimeStep = fMaxTimeStep; 665 fTimeStep = fMaxTimeStep; 498 666 499 fTSTimeStep = DBL_MAX; 667 fTSTimeStep = DBL_MAX; 500 fILTimeStep = DBL_MAX; 668 fILTimeStep = DBL_MAX; 501 669 502 fInteractionStep = false; 670 fInteractionStep = false; 503 fReachedUserTimeLimit = false; 671 fReachedUserTimeLimit = false; 504 672 505 fITStepStatus = eUndefined; 673 fITStepStatus = eUndefined; 506 674 507 // Start of step 675 // Start of step 508 #ifdef G4VERBOSE 676 #ifdef G4VERBOSE 509 if (fVerbose > 2) { << 677 if (fVerbose > 2) 510 # ifdef USE_COLOR << 678 { >> 679 #ifdef USE_COLOR 511 G4cout << LIGHT_RED; 680 G4cout << LIGHT_RED; 512 # endif << 681 #endif 513 G4cout << "*** Start Of Step N°" << fNbSt << 682 G4cout << "*** Start Of Step N°" << fNbSteps + 1 << " ***" << G4endl; 514 << " ***" << G4endl; << 683 G4cout << "Current Global time : " << G4BestUnit(fGlobalTime, "Time") 515 G4cout << "Current Global time : " << G4Be << 684 <<G4endl; 516 # ifdef USE_COLOR << 685 #ifdef USE_COLOR 517 G4cout << RESET_COLOR; 686 G4cout << RESET_COLOR; 518 # endif << 687 #endif 519 } 688 } 520 #endif 689 #endif 521 690 522 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 691 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 523 MemStat mem_first, mem_second, mem_diff; 692 MemStat mem_first, mem_second, mem_diff; 524 #endif 693 #endif 525 694 526 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 695 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 527 mem_first = MemoryUsage(); 696 mem_first = MemoryUsage(); 528 #endif 697 #endif 529 698 530 fDefinedMinTimeStep = GetLimitingTimeStep(); 699 fDefinedMinTimeStep = GetLimitingTimeStep(); 531 700 532 if (fUsePreDefinedTimeSteps) { << 701 if (fUsePreDefinedTimeSteps) >> 702 { 533 #ifdef G4VERBOSE 703 #ifdef G4VERBOSE 534 if (fVerbose > 2) { << 704 if (fVerbose > 2) 535 # ifdef USE_COLOR << 705 { >> 706 #ifdef USE_COLOR 536 G4cout << LIGHT_RED; 707 G4cout << LIGHT_RED; 537 # endif << 708 #endif 538 G4cout << "*** At time : " << G4BestUnit 709 G4cout << "*** At time : " << G4BestUnit(fGlobalTime, "Time") 539 << " the chosen user time step is << 710 << " the chosen user time step is : " 540 << " ***" << G4endl; << 711 << G4BestUnit(fDefinedMinTimeStep, "Time") << " ***" << G4endl; 541 # ifdef USE_COLOR << 712 #ifdef USE_COLOR 542 G4cout << RESET_COLOR; 713 G4cout << RESET_COLOR; 543 # endif << 714 #endif 544 } 715 } 545 #endif 716 #endif 546 } 717 } 547 718 548 if (fpModelProcessor->GetComputeTimeStep()) << 719 if (fpModelProcessor->GetComputeTimeStep()) // fComputeTimeStep) 549 { 720 { 550 fTSTimeStep = fpModelProcessor->CalculateM << 721 fTSTimeStep = fpModelProcessor->CalculateMinTimeStep(fGlobalTime, >> 722 fDefinedMinTimeStep); 551 // => at least N (N = nb of tracks) loops 723 // => at least N (N = nb of tracks) loops 552 } 724 } 553 else if (fUseDefaultTimeSteps) { << 725 else if(fUseDefaultTimeSteps) >> 726 { 554 fTSTimeStep = fDefinedMinTimeStep; 727 fTSTimeStep = fDefinedMinTimeStep; 555 } 728 } 556 729 557 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 730 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 558 mem_second = MemoryUsage(); 731 mem_second = MemoryUsage(); 559 mem_diff = mem_second - mem_first; << 732 mem_diff = mem_second-mem_first; 560 G4cout << "|| MEM || After computing TS, dif 733 G4cout << "|| MEM || After computing TS, diff is : " << mem_diff << G4endl; 561 #endif 734 #endif 562 735 563 #ifdef G4VERBOSE 736 #ifdef G4VERBOSE 564 if (fVerbose > 2) { << 737 if (fVerbose > 2) 565 # ifdef USE_COLOR << 738 { >> 739 #ifdef USE_COLOR 566 G4cout << LIGHT_RED; 740 G4cout << LIGHT_RED; 567 # endif << 741 #endif 568 G4cout << "*** Time stepper returned : " < << 742 G4cout << "*** Time stepper returned : " << G4BestUnit(fTSTimeStep, "Time") 569 # ifdef USE_COLOR << 743 << " ***" << G4endl; >> 744 #ifdef USE_COLOR 570 G4cout << RESET_COLOR; 745 G4cout << RESET_COLOR; 571 # endif << 746 #endif 572 } 747 } 573 #endif 748 #endif 574 749 575 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 750 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 576 mem_first = MemoryUsage(); 751 mem_first = MemoryUsage(); 577 #endif 752 #endif 578 753 579 // Call IL even if fTSTimeStep == 0 754 // Call IL even if fTSTimeStep == 0 580 // if fILTimeStep == 0 give the priority to 755 // if fILTimeStep == 0 give the priority to DoIt processes 581 756 582 fILTimeStep = fpStepProcessor->ComputeIntera 757 fILTimeStep = fpStepProcessor->ComputeInteractionLength(fPreviousTimeStep); 583 // => at least N loops 758 // => at least N loops 584 // All process returns the physical step of 759 // All process returns the physical step of interaction 585 // The transportation process calculates the 760 // The transportation process calculates the corresponding 586 // time step 761 // time step 587 762 588 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 763 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 589 mem_second = MemoryUsage(); 764 mem_second = MemoryUsage(); 590 mem_diff = mem_second - mem_first; << 765 mem_diff = mem_second-mem_first; 591 G4cout << "|| MEM || After IL, diff is : " < 766 G4cout << "|| MEM || After IL, diff is : " << mem_diff << G4endl; 592 #endif 767 #endif 593 768 594 #ifdef G4VERBOSE 769 #ifdef G4VERBOSE 595 if (fVerbose > 2) { << 770 if (fVerbose > 2) 596 # ifdef USE_COLOR << 771 { >> 772 #ifdef USE_COLOR 597 G4cout << LIGHT_RED; 773 G4cout << LIGHT_RED; 598 # endif << 774 #endif 599 G4cout << "*** The minimum time returned b 775 G4cout << "*** The minimum time returned by the processes is : " 600 << G4BestUnit(fILTimeStep, "Time") 776 << G4BestUnit(fILTimeStep, "Time") << " ***" << G4endl; 601 # ifdef USE_COLOR << 777 #ifdef USE_COLOR 602 G4cout << RESET_COLOR; 778 G4cout << RESET_COLOR; 603 # endif << 779 #endif 604 } 780 } 605 #endif 781 #endif 606 782 607 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 783 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 608 mem_first = MemoryUsage(); 784 mem_first = MemoryUsage(); 609 #endif 785 #endif 610 786 611 if (fILTimeStep <= fTSTimeStep) 787 if (fILTimeStep <= fTSTimeStep) 612 // Give the priority to the IL << 788 // Give the priority to the IL 613 { 789 { 614 fInteractionStep = true; 790 fInteractionStep = true; 615 fReactionSet->CleanAllReaction(); 791 fReactionSet->CleanAllReaction(); 616 fTimeStep = fILTimeStep; 792 fTimeStep = fILTimeStep; 617 fITStepStatus = eInteractionWithMedium; 793 fITStepStatus = eInteractionWithMedium; 618 fpStepProcessor->PrepareLeadingTracks(); 794 fpStepProcessor->PrepareLeadingTracks(); 619 } 795 } 620 else { << 796 else >> 797 { 621 fInteractionStep = false; 798 fInteractionStep = false; 622 fpStepProcessor->ResetLeadingTracks(); 799 fpStepProcessor->ResetLeadingTracks(); 623 fTimeStep = fTSTimeStep; 800 fTimeStep = fTSTimeStep; 624 fITStepStatus = eCollisionBetweenTracks; 801 fITStepStatus = eCollisionBetweenTracks; 625 } 802 } 626 803 627 if (fGlobalTime + fTimeStep > fStopTime) 804 if (fGlobalTime + fTimeStep > fStopTime) 628 // This check is done at every time step << 805 // This check is done at every time step 629 { 806 { 630 fTimeStep = fStopTime - fGlobalTime; 807 fTimeStep = fStopTime - fGlobalTime; 631 fITStepStatus = eInteractionWithMedium; / << 808 fITStepStatus = eInteractionWithMedium; // ie: transportation 632 fInteractionStep = true; 809 fInteractionStep = true; 633 fReactionSet->CleanAllReaction(); 810 fReactionSet->CleanAllReaction(); 634 fpStepProcessor->ResetLeadingTracks(); 811 fpStepProcessor->ResetLeadingTracks(); 635 } 812 } 636 813 637 if (fTimeStep == 0) // < fTimeTolerance) << 814 if (fTimeStep == 0) // < fTimeTolerance) 638 { 815 { 639 ++fZeroTimeCount; 816 ++fZeroTimeCount; 640 if (fZeroTimeCount >= fMaxNZeroTimeStepsAl << 817 if (fZeroTimeCount >= fMaxNZeroTimeStepsAllowed) >> 818 { 641 G4ExceptionDescription exceptionDescript 819 G4ExceptionDescription exceptionDescription; 642 820 643 exceptionDescription << "Too many zero t 821 exceptionDescription << "Too many zero time steps were detected. "; 644 exceptionDescription << "The simulation 822 exceptionDescription << "The simulation is probably stuck. "; 645 exceptionDescription << "The maximum num << 823 exceptionDescription 646 << fMaxNZeroTimeSte << 824 << "The maximum number of zero time steps is currently : " >> 825 << fMaxNZeroTimeStepsAllowed; 647 exceptionDescription << "."; 826 exceptionDescription << "."; 648 827 649 G4Exception("G4Scheduler::Stepping", "Sc << 828 G4Exception("G4Scheduler::Stepping", >> 829 "SchedulerNullTimeSteps", >> 830 FatalErrorInArgument, 650 exceptionDescription); 831 exceptionDescription); 651 } 832 } 652 } 833 } 653 else { << 834 else >> 835 { 654 fZeroTimeCount = 0; 836 fZeroTimeCount = 0; 655 } 837 } 656 838 657 fReachedUserTimeLimit = (fTimeStep <= fDefin << 839 fReachedUserTimeLimit = 658 || ((fTimeStep > fDe << 840 ((fTimeStep <= fDefinedMinTimeStep) || ((fTimeStep > fDefinedMinTimeStep) 659 && fabs(fTimeSte << 841 && fabs(fTimeStep - fDefinedMinTimeStep) < fTimeTolerance)) ? >> 842 true : false; 660 843 661 if (fpUserTimeStepAction != nullptr) fpUserT << 844 if (fpUserTimeStepAction) fpUserTimeStepAction->UserPreTimeStepAction(); 662 // TODO: pre/post << 845 // TODO: pre/post 663 846 664 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 847 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 665 mem_second = MemoryUsage(); 848 mem_second = MemoryUsage(); 666 mem_diff = mem_second - mem_first; << 849 mem_diff = mem_second-mem_first; 667 G4cout << "|| MEM || After LeadingTracks and << 850 G4cout << "|| MEM || After LeadingTracks and UserPreTimeStepAction: " >> 851 << mem_diff << G4endl; 668 #endif 852 #endif 669 853 670 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 854 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 671 mem_first = MemoryUsage(); 855 mem_first = MemoryUsage(); 672 #endif 856 #endif 673 857 >> 858 674 fGlobalTime += fTimeStep; 859 fGlobalTime += fTimeStep; 675 860 676 // if fTSTimeStep > 0 => still need to call 861 // if fTSTimeStep > 0 => still need to call the transportation process 677 // if fILTimeStep < fTSTimeStep => call only 862 // if fILTimeStep < fTSTimeStep => call only DoIt processes, no reactions 678 // if fILTimeStep == fTSTimeStep => give the 863 // if fILTimeStep == fTSTimeStep => give the priority to the DoIt processes 679 if (fTSTimeStep > 0 || fILTimeStep <= fTSTim << 864 if (fTSTimeStep > 0 || fILTimeStep <= fTSTimeStep) >> 865 { >> 866 // G4cout << "Will call DoIT" << G4endl; 680 fpStepProcessor->DoIt(fTimeStep); 867 fpStepProcessor->DoIt(fTimeStep); >> 868 // fTrackContainer.MergeSecondariesWithMainList(); >> 869 // fTrackContainer.KillTracks(); // remove ? 681 } 870 } 682 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 871 // else >> 872 // { >> 873 // G4cout << "fTSTimeStep : " << fTSTimeStep << G4endl; >> 874 // G4cout << "fILTimeStep : " << fILTimeStep << G4endl; >> 875 // } >> 876 >> 877 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 683 mem_second = MemoryUsage(); 878 mem_second = MemoryUsage(); 684 mem_diff = mem_second - mem_first; << 879 mem_diff = mem_second-mem_first; 685 G4cout << "|| MEM || After DoIT, diff is : " 880 G4cout << "|| MEM || After DoIT, diff is : " << mem_diff << G4endl; 686 #endif 881 #endif 687 882 688 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 883 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 689 mem_first = MemoryUsage(); 884 mem_first = MemoryUsage(); 690 #endif 885 #endif 691 886 692 fpModelProcessor->ComputeTrackReaction(fITSt << 887 fpModelProcessor->ComputeTrackReaction(fITStepStatus, 693 fReac << 888 fGlobalTime, 694 fpUse << 889 fTimeStep, >> 890 fPreviousTimeStep, >> 891 fReachedUserTimeLimit, >> 892 fTimeTolerance, >> 893 fpUserTimeStepAction, >> 894 fVerbose); 695 895 696 ++fNbSteps; 896 ++fNbSteps; 697 897 698 if (fpUserTimeStepAction != nullptr) { << 898 if (fpUserTimeStepAction) >> 899 { 699 fpUserTimeStepAction->UserPostTimeStepActi 900 fpUserTimeStepAction->UserPostTimeStepAction(); 700 } 901 } 701 902 702 fPreviousTimeStep = fTimeStep; 903 fPreviousTimeStep = fTimeStep; 703 904 704 #if defined(DEBUG_MEM) && defined(DEBUG_MEM_DE << 905 #if defined (DEBUG_MEM) && defined (DEBUG_MEM_DETAILED_STEPPING) 705 mem_second = MemoryUsage(); 906 mem_second = MemoryUsage(); 706 mem_diff = mem_second - mem_first; << 907 mem_diff = mem_second-mem_first; 707 G4cout << "|| MEM || After computing reactio 908 G4cout << "|| MEM || After computing reactions + UserPostTimeStepAction, " 708 "diff is : " << 909 "diff is : " << mem_diff << G4endl; 709 << mem_diff << G4endl; << 710 #endif 910 #endif 711 911 712 // End of step 912 // End of step 713 #ifdef G4VERBOSE 913 #ifdef G4VERBOSE 714 if (fVerbose >= 2) { << 914 if (fVerbose >= 2) 715 # ifdef USE_COLOR << 915 { 716 G4cout << LIGHT_RED; << 916 #ifdef USE_COLOR 717 # endif << 917 G4cout << LIGHT_RED; >> 918 #endif 718 919 719 G4String interactionType; << 920 G4String interactionType; 720 GetCollisionType(interactionType); << 921 GetCollisionType(interactionType); 721 922 722 std::stringstream finalOutput; << 923 std::stringstream finalOutput; >> 924 >> 925 finalOutput << "*** End of step N°" << fNbSteps >> 926 << "\t T_i= " << G4BestUnit(fGlobalTime-fTimeStep, "Time") >> 927 << "\t dt= " << G4BestUnit(fTimeStep, "Time") >> 928 << "\t T_f= " << G4BestUnit(fGlobalTime, "Time") >> 929 << "\t " << interactionType >> 930 << G4endl; 723 931 724 finalOutput << "*** End of step N°" << fN << 932 if(fVerbose>2) 725 << "\t T_i= " << G4BestUnit(fG << 933 { 726 << "\t dt= " << G4BestUnit(fTi << 934 if(fReachedUserTimeLimit) 727 << "\t T_f= " << G4BestUnit(fG << 935 { 728 << G4endl; << 936 finalOutput << "It has also reached the user time limit" << G4endl; 729 << 937 } 730 if (fVerbose > 2) { << 938 finalOutput << "_______________________________________________________________" 731 if (fReachedUserTimeLimit) { << 939 "_______"<< G4endl; 732 finalOutput << "It has also reached th << 733 } 940 } 734 finalOutput << "________________________ << 735 "_______" << 736 << G4endl; << 737 } << 738 941 739 G4cout << finalOutput.str(); << 942 G4cout << finalOutput.str(); 740 943 741 # ifdef USE_COLOR << 944 #ifdef USE_COLOR 742 G4cout << RESET_COLOR; << 945 G4cout << RESET_COLOR; 743 # endif << 946 #endif 744 } << 947 } 745 #endif 948 #endif >> 949 746 } 950 } 747 //____________________________________________ 951 //_________________________________________________________________________ 748 952 749 G4double G4Scheduler::GetLimitingTimeStep() co 953 G4double G4Scheduler::GetLimitingTimeStep() const 750 { 954 { 751 if (fpUserTimeSteps == nullptr) return fDefa << 955 if (fpUserTimeSteps == 0) return fDefaultMinTimeStep; 752 if (fabs(fGlobalTime - fUserUpperTimeLimit) << 956 if (fabs(fGlobalTime - fUserUpperTimeLimit) < fTimeTolerance) 753 << 957 return fDefinedMinTimeStep; 754 auto it_fpUserTimeSteps_i = fpUserTimeSteps- << 958 755 auto it_fpUserTimeSteps_low = fpUserTimeStep << 959 map<G4double, G4double>::const_iterator it_fpUserTimeSteps_i = fpUserTimeSteps >> 960 ->upper_bound(fGlobalTime); >> 961 map<G4double, G4double>::const_iterator it_fpUserTimeSteps_low = fpUserTimeSteps >> 962 ->lower_bound(fGlobalTime); >> 963 >> 964 // DEBUG >> 965 // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time") >> 966 // << G4endl; >> 967 // G4cout << "fpUserTimeSteps_i : " >> 968 // <<"<"<<G4BestUnit(it_fpUserTimeSteps->first,"Time") >> 969 // <<", "<< G4BestUnit(it_fpUserTimeSteps->second,"Time")<<">" >> 970 // << "\t fpUserTimeSteps_low : " >> 971 // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", "* >> 972 // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">" >> 973 // << G4endl; 756 974 757 if (it_fpUserTimeSteps_i == fpUserTimeSteps- << 975 if (it_fpUserTimeSteps_i == fpUserTimeSteps->end()) >> 976 { 758 it_fpUserTimeSteps_i--; 977 it_fpUserTimeSteps_i--; 759 fUserUpperTimeLimit = fStopTime; 978 fUserUpperTimeLimit = fStopTime; 760 } 979 } 761 else if (fabs(fGlobalTime - it_fpUserTimeSte << 980 else if (fabs(fGlobalTime - it_fpUserTimeSteps_low->first) < fTimeTolerance) >> 981 { >> 982 // Case : fGlobalTime = X picosecond >> 983 // and fpUserTimeSteps_low->first = X picosecond >> 984 // but the precision is not good enough 762 it_fpUserTimeSteps_i = it_fpUserTimeSteps_ 985 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low; 763 auto tmp_it = it_fpUserTimeSteps_low; << 986 map<G4double, G4double>::const_iterator tmp_it = it_fpUserTimeSteps_low; 764 ++tmp_it; 987 ++tmp_it; 765 if (tmp_it == fpUserTimeSteps->end()) { << 988 if (tmp_it == fpUserTimeSteps->end()) >> 989 { 766 fUserUpperTimeLimit = fStopTime; 990 fUserUpperTimeLimit = fStopTime; 767 } 991 } 768 else { << 992 else >> 993 { 769 fUserUpperTimeLimit = tmp_it->first; 994 fUserUpperTimeLimit = tmp_it->first; 770 } 995 } 771 } 996 } 772 else if (it_fpUserTimeSteps_i == it_fpUserTi << 997 else if (it_fpUserTimeSteps_i == it_fpUserTimeSteps_low) >> 998 { >> 999 // "Normal" cases 773 fUserUpperTimeLimit = it_fpUserTimeSteps_i 1000 fUserUpperTimeLimit = it_fpUserTimeSteps_i->first; 774 if (it_fpUserTimeSteps_i != fpUserTimeStep << 1001 // it_fpUserTimeSteps_i++; >> 1002 // G4cout << "Global time = " << fGlobalTime << G4endl; >> 1003 // G4cout << "Is begin = " >> 1004 // << (it_fpUserTimeSteps_i == fpUserTimeSteps->begin())<< G4endl; >> 1005 >> 1006 if(it_fpUserTimeSteps_i != fpUserTimeSteps->begin()) it_fpUserTimeSteps_i--; 775 } 1007 } 776 else { << 1008 else >> 1009 { 777 fUserUpperTimeLimit = it_fpUserTimeSteps_i 1010 fUserUpperTimeLimit = it_fpUserTimeSteps_i->first; 778 it_fpUserTimeSteps_i = it_fpUserTimeSteps_ 1011 it_fpUserTimeSteps_i = it_fpUserTimeSteps_low; 779 } 1012 } >> 1013 780 return it_fpUserTimeSteps_i->second; 1014 return it_fpUserTimeSteps_i->second; 781 } 1015 } 782 1016 783 //____________________________________________ 1017 //_________________________________________________________________________ 784 1018 785 void G4Scheduler::FindUserPreDefinedTimeStep() 1019 void G4Scheduler::FindUserPreDefinedTimeStep() 786 { 1020 { 787 if (fpUserTimeSteps == nullptr) { << 1021 >> 1022 if(fpUserTimeSteps == 0) >> 1023 { 788 G4ExceptionDescription exceptionDescriptio 1024 G4ExceptionDescription exceptionDescription; 789 exceptionDescription << "You are asking to << 1025 exceptionDescription 790 G4Exception("G4Scheduler::FindUserPreDefin << 1026 << "You are asking to use user defined steps but you did not give any."; >> 1027 G4Exception("G4Scheduler::FindUserPreDefinedTimeStep", >> 1028 "Scheduler004", >> 1029 FatalErrorInArgument, 791 exceptionDescription); 1030 exceptionDescription); 792 return; // makes coverity happy << 1031 return; // makes coverity happy 793 } 1032 } 794 auto fpUserTimeSteps_i = fpUserTimeSteps->up << 1033 map<G4double, G4double>::iterator fpUserTimeSteps_i = 795 auto fpUserTimeSteps_low = fpUserTimeSteps-> << 1034 fpUserTimeSteps->upper_bound(fGlobalTime); >> 1035 map<G4double, G4double>::iterator fpUserTimeSteps_low = fpUserTimeSteps >> 1036 ->lower_bound(fGlobalTime); >> 1037 >> 1038 // DEBUG >> 1039 // G4cout << "fGlobalTime : " << G4BestUnit(fGlobalTime,"Time") << G4endl; >> 1040 // G4cout << "fpUserTimeSteps_i : " >> 1041 // <<"<"<<G4BestUnit(fpUserTimeSteps_i->first,"Time")<<", " >> 1042 // << G4BestUnit(fpUserTimeSteps_i->second,"Time")<<">" >> 1043 // << "\t fpUserTimeSteps_low : " >> 1044 // <<"<"<<G4BestUnit(fpUserTimeSteps_low->first,"Time")<<", " >> 1045 // << G4BestUnit(fpUserTimeSteps_low->second,"Time")<<">" >> 1046 // << G4endl; 796 1047 797 if (fpUserTimeSteps_i == fpUserTimeSteps->en << 1048 if(fpUserTimeSteps_i == fpUserTimeSteps->end()) >> 1049 { 798 fpUserTimeSteps_i--; 1050 fpUserTimeSteps_i--; 799 } 1051 } 800 else if (fabs(fGlobalTime - fpUserTimeSteps_ << 1052 else if(fabs(fGlobalTime - fpUserTimeSteps_low->first) < fTimeTolerance) >> 1053 { 801 // Case : fGlobalTime = X picosecond 1054 // Case : fGlobalTime = X picosecond 802 // and fpUserTimeSteps_low->first = X pico 1055 // and fpUserTimeSteps_low->first = X picosecond 803 // but the precision is not good enough 1056 // but the precision is not good enough 804 fpUserTimeSteps_i = fpUserTimeSteps_low; 1057 fpUserTimeSteps_i = fpUserTimeSteps_low; 805 } 1058 } 806 else if (fpUserTimeSteps_i == fpUserTimeStep << 1059 else if(fpUserTimeSteps_i == fpUserTimeSteps_low) >> 1060 { 807 // "Normal" cases 1061 // "Normal" cases 808 fpUserTimeSteps_i--; 1062 fpUserTimeSteps_i--; 809 } 1063 } 810 else { << 1064 else >> 1065 { 811 fpUserTimeSteps_i = fpUserTimeSteps_low; 1066 fpUserTimeSteps_i = fpUserTimeSteps_low; 812 } 1067 } 813 1068 814 fDefinedMinTimeStep = fpUserTimeSteps_i->sec 1069 fDefinedMinTimeStep = fpUserTimeSteps_i->second; 815 } 1070 } 816 1071 817 //____________________________________________ 1072 //_________________________________________________________________________ 818 1073 819 void G4Scheduler::EndTracking() 1074 void G4Scheduler::EndTracking() 820 { 1075 { 821 if (fRunning) { << 1076 if(fRunning) >> 1077 { 822 G4ExceptionDescription exceptionDescriptio 1078 G4ExceptionDescription exceptionDescription; 823 exceptionDescription << "End tracking is c << 1079 exceptionDescription 824 << 1080 << "End tracking is called while G4Scheduler is still running." 825 G4Exception("G4Scheduler::EndTracking", "S << 1081 << G4endl; >> 1082 >> 1083 G4Exception("G4Scheduler::EndTracking", >> 1084 "Scheduler017", >> 1085 FatalErrorInArgument, 826 exceptionDescription); 1086 exceptionDescription); 827 } 1087 } 828 1088 829 while (fTrackContainer.DelayListsNOTEmpty()) << 830 auto nextTime = fTrackContainer.GetNextTim << 831 fTrackContainer.MergeNextTimeToMainList(ne << 832 } << 833 << 834 fTrackContainer.MergeSecondariesWithMainList 1089 fTrackContainer.MergeSecondariesWithMainList(); 835 1090 836 if (fTrackContainer.MainListsNOTEmpty()) { << 1091 if (fTrackContainer.MainListsNOTEmpty()) >> 1092 { 837 G4TrackManyList* mainList = fTrackContaine 1093 G4TrackManyList* mainList = fTrackContainer.GetMainList(); 838 G4TrackManyList::iterator it = mainList->b 1094 G4TrackManyList::iterator it = mainList->begin(); 839 G4TrackManyList::iterator end = mainList-> 1095 G4TrackManyList::iterator end = mainList->end(); 840 for (; it != end; ++it) { << 1096 for (; it != end; ++it) >> 1097 { 841 fpTrackingManager->EndTrackingWOKill(*it 1098 fpTrackingManager->EndTrackingWOKill(*it); 842 } 1099 } 843 } 1100 } 844 1101 845 if (fTrackContainer.SecondaryListsNOTEmpty() << 1102 if (fTrackContainer.SecondaryListsNOTEmpty()) // should be empty 846 { 1103 { 847 G4TrackManyList* secondaries = fTrackConta 1104 G4TrackManyList* secondaries = fTrackContainer.GetSecondariesList(); 848 G4TrackManyList::iterator it = secondaries 1105 G4TrackManyList::iterator it = secondaries->begin(); 849 G4TrackManyList::iterator end = secondarie 1106 G4TrackManyList::iterator end = secondaries->end(); 850 1107 851 for (; it != end; ++it) { << 1108 for (; it != end; ++it) >> 1109 { 852 fpTrackingManager->EndTrackingWOKill(*it 1110 fpTrackingManager->EndTrackingWOKill(*it); 853 } 1111 } 854 } 1112 } 855 } 1113 } 856 1114 857 //____________________________________________ 1115 //_________________________________________________________________________ 858 void G4Scheduler::SetInteractivity(G4ITTrackin 1116 void G4Scheduler::SetInteractivity(G4ITTrackingInteractivity* interactivity) 859 { 1117 { 860 fpTrackingInteractivity = interactivity; 1118 fpTrackingInteractivity = interactivity; 861 if (fpTrackingManager != nullptr) { << 1119 if(fpTrackingManager) >> 1120 { 862 fpTrackingManager->SetInteractivity(fpTrac 1121 fpTrackingManager->SetInteractivity(fpTrackingInteractivity); 863 } 1122 } >> 1123 >> 1124 //G4MIWorkspace::GetWorldWorkspace()->SetTrackingInteractivity(interactivity); 864 } 1125 } 865 1126 866 //____________________________________________ 1127 //_________________________________________________________________________ 867 void G4Scheduler::ForceReinitialization() 1128 void G4Scheduler::ForceReinitialization() 868 { 1129 { 869 fInitialized = false; 1130 fInitialized = false; 870 Initialize(); 1131 Initialize(); 871 } 1132 } 872 1133 >> 1134 //_________________________________________________________________________ >> 1135 G4Scheduler::G4Scheduler(const G4Scheduler&) : >> 1136 G4VScheduler(), G4VStateDependent(), >> 1137 fTrackContainer((G4ITTrackHolder&) *G4ITTrackHolder::Instance()) >> 1138 >> 1139 { >> 1140 Create(); >> 1141 } >> 1142 >> 1143 //_________________________________________________________________________ >> 1144 G4Scheduler& G4Scheduler::operator=(const G4Scheduler& right) >> 1145 { >> 1146 if(this != &right) >> 1147 { >> 1148 Create(); >> 1149 } >> 1150 return *this; >> 1151 } >> 1152 873 size_t G4Scheduler::GetNTracks() 1153 size_t G4Scheduler::GetNTracks() 874 { 1154 { 875 return fTrackContainer.GetNTracks(); 1155 return fTrackContainer.GetNTracks(); 876 } 1156 } 877 //____________________________________________ 1157 //_________________________________________________________________________ 878 1158 879 void G4Scheduler::GetCollisionType(G4String& i 1159 void G4Scheduler::GetCollisionType(G4String& interactionType) 880 { 1160 { 881 switch (fITStepStatus) { << 1161 switch(fITStepStatus) >> 1162 { 882 case eInteractionWithMedium: 1163 case eInteractionWithMedium: 883 interactionType = "eInteractionWithMediu 1164 interactionType = "eInteractionWithMedium"; 884 break; 1165 break; 885 case eCollisionBetweenTracks: 1166 case eCollisionBetweenTracks: 886 interactionType = "eCollisionBetweenTrac 1167 interactionType = "eCollisionBetweenTracks"; 887 break; 1168 break; 888 default: 1169 default: 889 interactionType = "eCollisionBetweenTrac 1170 interactionType = "eCollisionBetweenTracks"; 890 break; 1171 break; 891 } 1172 } 892 } 1173 } 893 1174