50 if(fTimeToRecord.empty())
52 G4String WarMessage =
"fTimeToRecord is empty ";
53 G4Exception(
"G4DNAEventScheduler::ClearAndReChargeCounter()",
56 fLastRecoredTime = fTimeToRecord.begin();
62 if(species.get() ==
nullptr)
71 for(
auto time_mol : fTimeToRecord)
73 if(time_mol > fStartTime)
78 for(
auto molecule : *species)
85 G4cerr <<
"G4DNAEventScheduler::ClearAndReChargeCounter() ::N "
86 "molecules not valid < 0 "
90 fCounterMap[time_mol][molecule] = n_mol;
100 exceptionDescription <<
"G4VMoleculeCounter is not used";
101 G4Exception(
"G4DNAEventScheduler::ClearAndReChargeCounter()",
102 "G4DNAEventScheduler010",
JustWarning, exceptionDescription);
108 if(fTimeToRecord.find(time) == fTimeToRecord.end())
110 fTimeToRecord.insert(time);
119 std::map<G4VDNAMesh::Index, MapList> TrackKeyMap;
120 for(
auto track : *pMainList)
126 if(pScavengerMaterial !=
nullptr &&
127 pScavengerMaterial->find(molType))
132 auto key = fpMesh->GetIndex(track->GetPosition());
133 if(TrackKeyMap.find(key) != TrackKeyMap.end())
135 std::map<MolType, size_t>& TrackTypeMap = TrackKeyMap[key];
136 if(TrackTypeMap.find(molType) != TrackTypeMap.end())
138 TrackTypeMap[molType]++;
142 TrackTypeMap[molType] = 1;
147 TrackKeyMap[key][molType] = 1;
151 for(
auto& it : TrackKeyMap)
153 fpMesh->InitializeVoxel(it.first, std::move(it.second));
160 auto newMesh =
new G4DNAMesh(fpMesh->GetBoundingBox(), fPixel);
162 auto begin = fpMesh->begin();
163 auto end = fpMesh->end();
164 std::map<G4VDNAMesh::Index, MapList> TrackKeyMap;
165 for(; begin != end; begin++)
167 auto index = std::get<0>(*begin);
168 auto newIndex = fpMesh->ConvertIndex(index, fPixel);
169 if(TrackKeyMap.find(newIndex) == TrackKeyMap.end())
171 TrackKeyMap[newIndex] = std::get<2>(*begin);
175 for(
const auto& it : std::get<2>(*begin))
177 TrackKeyMap[newIndex][it.first] += it.second;
181 G4cout <<
" ReVoxelizing:: Old index : " << index
182 <<
" new index : " << fpMesh->ConvertIndex(index, fPixel)
183 <<
" number: " << std::get<2>(*begin).begin()->second <<
G4endl;
187 fpMesh.reset(newMesh);
189 for(
auto& it : TrackKeyMap)
191 fpMesh->InitializeVoxel(it.first, std::move(it.second));
197 fGlobalTime = fEndTime;
200 LastRegisterForCounter();
204 G4cout <<
"End Processing and reset Gird, ScavengerTable, EventSet for new "
208 fInitialized =
false;
211 fGlobalTime = fStartTime;
216 fpEventSet->RemoveEventSet();
218 fpGillespieReaction->ResetEquilibrium();
227 fpMesh = std::make_unique<G4DNAMesh>(boundingBox, pixel);
231 G4String WarMessage =
"resolution is not good : " +
232 std::to_string(fpMesh->GetResolution() / nm);
233 G4Exception(
"G4DNAEventScheduler::InitializeInMesh()",
"WrongResolution",
241 if(pScavengerMaterial ==
nullptr)
249 pScavengerMaterial->PrintInfo();
254 fpGillespieReaction->SetVoxelMesh(*fpMesh);
255 fpGillespieReaction->SetEventSet(fpEventSet.get());
256 fpGillespieReaction->SetTimeStep(0);
257 fpGillespieReaction->Initialize();
258 fpGillespieReaction->CreateEvents();
259 fpUpdateSystem->SetMesh(fpMesh.get());
266 fpUpdateSystem->SetVerbose(1);
285 fpGillespieReaction->SetVoxelMesh(*fpMesh);
286 fpUpdateSystem->SetMesh(fpMesh.get());
287 fpGillespieReaction->CreateEvents();
295 <<
"*** End Processing In Mesh and reset Mesh, EventSet for new Mesh!!!!"
298 fpEventSet->RemoveEventSet();
299 fInitialized =
false;
300 fIsChangeMesh =
false;
303 fStepNumberInMesh = 0;
325 fGlobalTime = fStartTime;
335 G4cout <<
"***G4DNAEventScheduler::Run*** for Pixel : " << fPixel <<
G4endl;
337 while(fEndTime > fGlobalTime && fRunning)
345 G4cout <<
" StepNumber(" << fStepNumber <<
") = MaxStep(" << fMaxStep
348 else if(fEndTime <= fGlobalTime)
350 G4cout <<
" GlobalTime(" << fGlobalTime <<
") > EndTime(" << fEndTime
352 <<
" StepNumber : " << fStepNumber <<
G4endl;
355 G4cout <<
"***G4DNAEventScheduler::Ending::"
357 <<
" Events left : " << fpEventSet->size() <<
G4endl;
375 G4double resolution = fpMesh->GetResolution();
377 <<
" the Mesh has " << fPixel <<
" x " << fPixel <<
" x " << fPixel
378 <<
" voxels with Resolution " <<
G4BestUnit(resolution,
"Length")
380 <<
G4BestUnit(resolution * resolution * C / (6 * D),
"Time")
389 if(fpUserMeshAction !=
nullptr)
391 fpUserMeshAction->BeginOfMesh(fpMesh.get(), fGlobalTime);
396 while(!fpEventSet->Empty() && !fIsChangeMesh && fEndTime > fGlobalTime)
399 fGlobalTime = fTimeStep + fStartTime;
401 if(fpUserMeshAction !=
nullptr)
403 fpUserMeshAction->InMesh(fpMesh.get(), fGlobalTime);
411 G4double resolution = fpMesh->GetResolution();
412 fTransferTime = resolution * resolution * C / (6 * D);
413 if(fTransferTime == 0)
416 exceptionDescription <<
"fTransferTime == 0";
417 G4Exception(
"G4DNAEventScheduler::RunInMesh",
"G4DNAEventScheduler001",
420 if(fTransferTime < fTimeStep &&
427 G4cout <<
" Pixels : " << fPixel <<
" resolution : "
428 <<
G4BestUnit(fpMesh->GetResolution(),
"Length")
429 <<
" fStepNumberInMesh : " << fStepNumberInMesh
430 <<
" at fGlobalTime : " <<
G4BestUnit(fGlobalTime,
"Time")
431 <<
" at fTimeStep : " <<
G4BestUnit(fTimeStep,
"Time")
432 <<
" fReactionNumber : " << fReactionNumber
433 <<
" transferTime : " <<
G4BestUnit(fTransferTime,
"Time")
436 fIsChangeMesh =
true;
443 G4cout <<
"***G4DNAEventScheduler::Ending::"
445 <<
" Event left : " << fpEventSet->size() <<
G4endl;
447 if(fpEventSet->Empty())
451 else if(fIsChangeMesh)
453 G4cout <<
"Changing Mesh from : " << fPixel
454 <<
" pixels to : " << fPixel / 2 <<
" pixels" <<
G4endl;
455 G4cout <<
"Info : ReactionNumber : " << fReactionNumber
456 <<
" JumpingNumber : " << fJumpingNumber <<
G4endl;
458 else if(fEndTime > fGlobalTime)
460 G4cout <<
" GlobalTime(" << fGlobalTime <<
") > EndTime(" << fEndTime
462 <<
" StepNumber : " << fStepNumber <<
G4endl;
471 if(fpUserMeshAction !=
nullptr)
473 fpUserMeshAction->EndOfMesh(fpMesh.get(), fGlobalTime);
480 fStepNumber < fMaxStep ? fStepNumber++ : static_cast<int>(fRunning =
false);
481 if(fpEventSet->size() > fpMesh->size())
485 <<
"impossible that fpEventSet->size() > fpMesh->size()";
486 G4Exception(
"G4DNAEventScheduler::Stepping",
"G4DNAEventScheduler002",
490 auto selected = fpEventSet->begin();
491 auto index = (*selected)->GetIndex();
495 G4cout <<
"G4DNAEventScheduler::Stepping()*********************************"
498 (*selected)->PrintEvent();
502 fTimeStep = (*selected)->GetTime();
505 auto pJumping = (*selected)->GetJumpingData();
506 auto pReaction = (*selected)->GetReactionData();
508 fpUpdateSystem->SetGlobalTime(fTimeStep +
510 fpGillespieReaction->SetTimeStep(fTimeStep);
511 if(pJumping ==
nullptr && pReaction !=
nullptr)
513 fpUpdateSystem->UpdateSystem(index, *pReaction);
514 fpEventSet->RemoveEvent(selected);
517 if(fpGillespieReaction->SetEquilibrium(pReaction))
524 fpGillespieReaction->CreateEvent(index);
529 else if(pJumping !=
nullptr && pReaction ==
nullptr)
532 fpUpdateSystem->UpdateSystem(index, *pJumping);
534 auto jumpingIndex = pJumping->second;
535 fpEventSet->RemoveEvent(selected);
538 fpGillespieReaction->CreateEvent(jumpingIndex);
539 fpGillespieReaction->CreateEvent(index);
545 exceptionDescription <<
"pJumping == nullptr && pReaction == nullptr";
546 G4Exception(
"G4DNAEventScheduler::Stepping",
"G4DNAEventScheduler003",
552 G4cout <<
"G4DNAEventScheduler::Stepping::end "
553 "Print***********************************"
567 auto recordTime = *fLastRecoredTime;
568 if(fGlobalTime >= recordTime && fCounterMap[recordTime].empty())
570 auto begin = fpMesh->begin();
571 auto end = fpMesh->end();
572 for(; begin != end; begin++)
574 const auto& mapData = std::get<2>(*begin);
579 for(
const auto& it : mapData)
581 fCounterMap[recordTime][it.first] += it.second;
590 G4cout <<
"CounterMap.size : " << fCounterMap.size() <<
G4endl;
591 for(
const auto& i : fCounterMap)
594 auto begin = map.begin();
595 auto end = map.end();
596 for(; begin != end; begin++)
598 auto molecule = begin->first;
599 auto number = begin->second;
604 G4cout <<
"molecule : " << molecule->GetName() <<
" number : " << number
617 std::unique_ptr<G4UserMeshAction> pUserMeshAction)
619 fpUserMeshAction = std::move(pUserMeshAction);
629 auto reactionDataList = pMolecularReactionTable->GetVectorOfReactionData();
630 if(reactionDataList.empty())
636 for(
auto it : reactionDataList)
638 if(it->GetEffectiveReactionRadius() >= resolution / CLHEP::pi)
640 G4cout << it->GetReactant1()->GetName() <<
" + "
641 << it->GetReactant2()->GetName() <<
G4endl;
642 G4cout <<
"G4DNAEventScheduler::ReactionRadius : "
643 <<
G4BestUnit(it->GetEffectiveReactionRadius(),
"Length")
652void G4DNAEventScheduler::ResetEventSet()
654 fpEventSet->RemoveEventSet();
655 fpGillespieReaction->CreateEvents();
658void G4DNAEventScheduler::LastRegisterForCounter()
660 if(fLastRecoredTime == fTimeToRecord.end())
666 auto lastRecorded = --fLastRecoredTime;
667 while (fLastRecoredTime != fTimeToRecord.end())
669 fCounterMap[*fLastRecoredTime] = fCounterMap[*lastRecorded];
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4Molecule * GetMolecule(const G4Track &track)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
void Initialize(const G4DNABoundingBox &boundingBox, G4int pixel)
static G4bool CheckingReactionRadius(G4double resolution)
void SetMaxNbSteps(G4int)
void SetUserMeshAction(std::unique_ptr< G4UserMeshAction >)
std::map< G4double, MapCounter > GetCounterMap() const
void SetEndTime(const G4double &)
G4double GetTimeStep() const
G4double GetEndTime() const
~G4DNAEventScheduler() override
G4DNAMesh * GetMesh() const
G4double GetStartTime() const
void SetStartTime(G4double time)
void ClearAndReChargeCounter()
std::map< MolType, G4int > MapCounter
void AddTimeToRecord(const G4double &time)
static G4DNAMolecularReactionTable * Instance()
G4TrackList * GetMainList(Key)
static G4ITTrackHolder * Instance()
std::unique_ptr< ReactantList > RecordedMolecules
static G4MoleculeCounter * Instance()
void ResetCounter() override
int GetNMoleculesAtTime(Reactant *molecule, double time)
RecordedMolecules GetRecordedMolecules()
const G4MolecularConfiguration * GetMolecularConfiguration() const
static G4Scheduler * Instance()
G4VScavengerMaterial * GetScavengerMaterial() const
void Use(G4bool flag=true)
static G4VMoleculeCounter * Instance()