49 if(fTimeToRecord.find(time) == fTimeToRecord.end())
51 fTimeToRecord.insert(time);
53 fLastRecoredTime = fTimeToRecord.begin();
60 std::map<G4VDNAMesh::Index, MapList> TrackKeyMap;
61 if(fpMesh ==
nullptr){
62 fpMesh = std::make_unique<G4DNAMesh>(boundingBox, fPixel);
65 auto newMesh =
new G4DNAMesh(fpMesh->GetBoundingBox(), fPixel);
67 auto begin = fpMesh->begin();
68 auto end = fpMesh->end();
69 for(; begin != end; begin++)
71 auto numberOfBoxes = fPixel*fPixel*fPixel;
72 const auto& mapData = std::get<2>(*begin);
73 for(
auto it : mapData)
75 if(it.second == 0)
continue;
77 G4int base_mol = std::floor((
G4double)it.second / numberOfBoxes);
78 G4int remainder = (
G4int)it.second % numberOfBoxes;
79 for(
G4int i = 0; i < remainder; i++)
81 auto oldIndex = std::get<0>(*begin);
82 auto idx = newMesh->GetRandomIndex(oldIndex, fpMesh->GetResolution());
83 TrackKeyMap[idx][it.first] += base_mol + 1;
87 fpMesh.reset(newMesh);
92 G4String WarMessage =
"resolution is not good : " +
94 G4Exception(
"G4DNAEventScheduler::InitializeInMesh()",
"WrongResolution",
99 for(
auto track : *pMainList)
105 if(pScavengerMaterial !=
nullptr &&
106 pScavengerMaterial->find(molType))
111 auto key = fpMesh->GetIndex(track->GetPosition());
112 if(TrackKeyMap.find(key) != TrackKeyMap.end())
114 std::map<MolType, size_t>& TrackTypeMap = TrackKeyMap[key];
115 if(TrackTypeMap.find(molType) != TrackTypeMap.end())
117 TrackTypeMap[molType]++;
121 TrackTypeMap[molType] = 1;
126 TrackKeyMap[key][molType] = 1;
132 for(
auto& it : TrackKeyMap)
134 fpMesh->InitializeVoxel(it.first, std::move(it.second));
141 auto newMesh =
new G4DNAMesh(fpMesh->GetBoundingBox(), fPixel);
143 auto begin = fpMesh->begin();
144 auto end = fpMesh->end();
145 std::map<G4VDNAMesh::Index, MapList> TrackKeyMap;
146 for(; begin != end; begin++)
148 auto index = std::get<0>(*begin);
149 auto newIndex = fpMesh->ConvertIndex(index, fPixel);
150 if(TrackKeyMap.find(newIndex) == TrackKeyMap.end())
152 TrackKeyMap[newIndex] = std::get<2>(*begin);
156 for(
const auto& it : std::get<2>(*begin))
158 TrackKeyMap[newIndex][it.first] += it.second;
162 G4cout <<
" ReVoxelizing:: Old index : " << index
163 <<
" new index : " << fpMesh->ConvertIndex(index, fPixel)
164 <<
" number: " << std::get<2>(*begin).begin()->second <<
G4endl;
168 fpMesh.reset(newMesh);
170 for(
auto& it : TrackKeyMap)
172 fpMesh->InitializeVoxel(it.first, std::move(it.second));
178 fGlobalTime = fEndTime;
181 LastRegisterForCounter();
185 G4cout <<
"End Processing and reset Gird, ScavengerTable, EventSet for new "
189 fInitialized =
false;
192 fGlobalTime = fStartTime;
196 fpEventSet->RemoveEventSet();
197 if(fpMesh !=
nullptr) {
202 fpGillespieReaction->ResetEquilibrium();
215 if(pScavengerMaterial ==
nullptr)
223 pScavengerMaterial->PrintInfo();
232 fpGillespieReaction->SetVoxelMesh(*fpMesh);
233 fpGillespieReaction->SetEventSet(fpEventSet.get());
234 fpGillespieReaction->SetTimeStep(0);
235 fpGillespieReaction->Initialize();
236 fpGillespieReaction->CreateEvents();
237 fpUpdateSystem->SetMesh(fpMesh.get());
243 fpUpdateSystem->SetVerbose(1);
262 fpGillespieReaction->SetVoxelMesh(*fpMesh);
263 fpUpdateSystem->SetMesh(fpMesh.get());
264 fpGillespieReaction->CreateEvents();
272 <<
"*** End Processing In Mesh and reset Mesh, EventSet for new Mesh!!!!"
275 fpEventSet->RemoveEventSet();
276 fInitialized =
false;
277 fIsChangeMesh =
false;
280 fStepNumberInMesh = 0;
304 fGlobalTime = fStartTime;
314 G4cout <<
"***G4DNAEventScheduler::Run*** for Pixel : " << fPixel <<
G4endl;
316 while(fEndTime > fGlobalTime && fRunning)
320 fInitialized =
false;
325 G4cout <<
" StepNumber(" << fStepNumber <<
") = MaxStep(" << fMaxStep
328 else if(fEndTime <= fGlobalTime)
330 G4cout <<
" GlobalTime(" << fGlobalTime <<
") > EndTime(" << fEndTime
332 <<
" StepNumber : " << fStepNumber <<
G4endl;
335 G4cout <<
"***G4DNAEventScheduler::Ending::"
337 <<
" Events left : " << fpEventSet->size() <<
G4endl;
354 G4double resolution = fpMesh->GetResolution();
356 <<
" the Mesh has " << fPixel <<
" x " << fPixel <<
" x " << fPixel
357 <<
" voxels with Resolution " <<
G4BestUnit(resolution,
"Length")
359 <<
G4BestUnit(fGlobalTime + resolution * resolution * C / (6 * D),
"Time")
368 if(fpUserMeshAction !=
nullptr)
370 fpUserMeshAction->BeginOfMesh(fpMesh.get(), fGlobalTime);
375 while(!fpEventSet->Empty() && !fIsChangeMesh && fEndTime > fGlobalTime)
378 fGlobalTime = fTimeStep + fStartTime;
380 if(fpUserMeshAction !=
nullptr)
382 fpUserMeshAction->InMesh(fpMesh.get(), fGlobalTime);
390 G4double resolution = fpMesh->GetResolution();
391 fTransferTime = resolution * resolution * C / (6 * D);
392 if(fTransferTime == 0)
395 exceptionDescription <<
"fTransferTime == 0";
396 G4Exception(
"G4DNAEventScheduler::RunInMesh",
"G4DNAEventScheduler001",
399 if(fTransferTime < fTimeStep &&
406 G4cout <<
" Pixels : " << fPixel <<
" resolution : "
407 <<
G4BestUnit(fpMesh->GetResolution(),
"Length")
408 <<
" fStepNumberInMesh : " << fStepNumberInMesh
409 <<
" at fGlobalTime : " <<
G4BestUnit(fGlobalTime,
"Time")
410 <<
" at fTimeStep : " <<
G4BestUnit(fTimeStep,
"Time")
411 <<
" fReactionNumber : " << fReactionNumber
412 <<
" transferTime : " <<
G4BestUnit(fTransferTime,
"Time")
415 fIsChangeMesh =
true;
422 G4cout <<
"***G4DNAEventScheduler::Ending::"
424 <<
" Event left : " << fpEventSet->size() <<
G4endl;
426 if(fpEventSet->Empty())
430 else if(fIsChangeMesh)
432 G4cout <<
"Changing Mesh from : " << fPixel
433 <<
" pixels to : " << fPixel / 2 <<
" pixels" <<
G4endl;
434 G4cout <<
"Info : ReactionNumber : " << fReactionNumber
435 <<
" JumpingNumber : " << fJumpingNumber <<
G4endl;
437 else if(fEndTime > fGlobalTime)
439 G4cout <<
" GlobalTime(" << fGlobalTime <<
") > EndTime(" << fEndTime
441 <<
" StepNumber : " << fStepNumber <<
G4endl;
450 if(fpUserMeshAction !=
nullptr)
452 fpUserMeshAction->EndOfMesh(fpMesh.get(), fGlobalTime);
459 fStepNumber < fMaxStep ? fStepNumber++ : static_cast<int>(fRunning =
false);
460 if(fpEventSet->size() > fpMesh->size())
464 <<
"impossible that fpEventSet->size() > fpMesh->size()";
465 G4Exception(
"G4DNAEventScheduler::Stepping",
"G4DNAEventScheduler002",
469 auto selected = fpEventSet->begin();
470 auto index = (*selected)->GetIndex();
474 G4cout <<
"G4DNAEventScheduler::Stepping()*********************************"
477 (*selected)->PrintEvent();
481 fTimeStep = (*selected)->GetTime();
483 if(fTimeStep + fStartTime >fEndTime){
return;}
486 auto pJumping = (*selected)->GetJumpingData();
487 auto pReaction = (*selected)->GetReactionData();
489 fpUpdateSystem->SetGlobalTime(fTimeStep +
491 fpGillespieReaction->SetTimeStep(fTimeStep);
492 if(pJumping ==
nullptr && pReaction !=
nullptr)
494 fpUpdateSystem->UpdateSystem(index, *pReaction);
495 fpEventSet->RemoveEvent(selected);
498 if(fpGillespieReaction->SetEquilibrium(pReaction))
505 fpGillespieReaction->CreateEvent(index);
510 else if(pJumping !=
nullptr && pReaction ==
nullptr)
513 fpUpdateSystem->UpdateSystem(index, *pJumping);
515 auto jumpingIndex = pJumping->second;
516 fpEventSet->RemoveEvent(selected);
519 fpGillespieReaction->CreateEvent(jumpingIndex);
520 fpGillespieReaction->CreateEvent(index);
526 exceptionDescription <<
"pJumping == nullptr && pReaction == nullptr";
527 G4Exception(
"G4DNAEventScheduler::Stepping",
"G4DNAEventScheduler003",
533 G4cout <<
"G4DNAEventScheduler::Stepping::end "
534 "Print***********************************"
548 if(fLastRecoredTime == fTimeToRecord.end())
552 auto recordTime = *fLastRecoredTime;
553 if(fGlobalTime >= recordTime && fCounterMap[recordTime].empty())
555 if(fpMesh ==
nullptr)
return;
557 auto begin = fpMesh->begin();
558 auto end = fpMesh->end();
559 for(; begin != end; begin++)
561 const auto& mapData = std::get<2>(*begin);
566 for(
const auto& it : mapData)
568 fCounterMap[recordTime][it.first] += it.second;
577 G4cout <<
"CounterMap.size : " << fCounterMap.size() <<
G4endl;
578 for(
const auto& i : fCounterMap)
581 auto begin =
map.begin();
582 auto end =
map.end();
583 for(; begin != end; begin++)
585 auto molecule = begin->first;
586 auto number = begin->second;
591 G4cout <<
"molecule : " << molecule->GetName() <<
" number : " << number
604 std::unique_ptr<G4UserMeshAction> pUserMeshAction)
606 fpUserMeshAction = std::move(pUserMeshAction);
616 auto reactionDataList = pMolecularReactionTable->GetVectorOfReactionData();
617 if(reactionDataList.empty())
623 for(
auto it : reactionDataList)
625 if(it->GetEffectiveReactionRadius() >= resolution / CLHEP::pi)
627 G4cout << it->GetReactant1()->GetName() <<
" + "
628 << it->GetReactant2()->GetName() <<
G4endl;
629 G4cout <<
"G4DNAEventScheduler::ReactionRadius : "
630 <<
G4BestUnit(it->GetEffectiveReactionRadius(),
"Length")
639void G4DNAEventScheduler::ResetEventSet()
641 fpEventSet->RemoveEventSet();
642 fpGillespieReaction->CreateEvents();
645void G4DNAEventScheduler::LastRegisterForCounter()
647 if(fLastRecoredTime == fTimeToRecord.end())
653 auto lastRecorded = --fLastRecoredTime;
654 while (fLastRecoredTime != fTimeToRecord.end())
656 fCounterMap[*fLastRecoredTime] = fCounterMap[*lastRecorded];
664 if(fLastRecoredTime == fTimeToRecord.end())
668 auto recordTime = *fLastRecoredTime;
673 if(fpMesh !=
nullptr){
675 auto begin = fpMesh->begin();
676 auto end = fpMesh->end();
677 for(; begin != end; begin++)
679 const auto& mapData = std::get<2>(*begin);
684 for(
const auto& it : mapData)
686 fCounterMap[recordTime][it.first] += it.second;
693 for (
auto track: *pMainList) {
696 auto pScavengerMaterial =
698 if (pScavengerMaterial !=
nullptr
699 && pScavengerMaterial->find(molType))
703 fCounterMap[recordTime][molType]++;
713 if(fTimeToRecord.empty())
715 G4String WarMessage =
"fTimeToRecord is empty ";
716 G4Exception(
"G4DNAEventScheduler::ClearAndReChargeCounter()",
719 fLastRecoredTime = fTimeToRecord.begin();
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 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
void Voxelizing(const G4DNABoundingBox &boundingBox)
G4double GetGlobalTime() const
void ParticleBasedCounter()
G4DNAMesh * GetMesh() const
G4double GetStartTime() const
void SetStartTime(G4double time)
std::map< MolType, G4int > MapCounter
void AddTimeToRecord(const G4double &time)
static G4DNAMolecularReactionTable * Instance()
static G4ITReactionSet * Instance()
G4TrackList * GetMainList(Key)
static G4ITTrackHolder * Instance()
const G4MolecularConfiguration * GetMolecularConfiguration() const
static G4Scheduler * Instance()
G4VScavengerMaterial * GetScavengerMaterial() const
std::string to_string(G4FermiAtomicMass mass)