45 , fInitialPixels(fPixel)
46 , fpMesh(new
G4DNAMesh(boundingBox, fPixel))
53 G4String WarMessage =
"resolution is not good : " +
54 std::to_string(fpMesh->GetResolution() / nm);
55 G4Exception(
"G4DNAEventScheduler::InitializeInMesh()",
"WrongResolution",
63 if(fTimeToRecord.empty())
65 G4String WarMessage =
"fTimeToRecord is empty ";
66 G4Exception(
"G4DNAEventScheduler::ClearAndReChargeCounter()",
69 fLastRecoredTime = fTimeToRecord.begin();
75 if(species.get() ==
nullptr)
79 else if(species->empty())
84 for(
auto time_mol : fTimeToRecord)
86 if(time_mol > fStartTime)
91 for(
auto molecule : *species)
98 G4cerr <<
"G4DNAEventScheduler::ClearAndReChargeCounter() ::N "
99 "molecules not valid < 0 "
103 fCounterMap[time_mol][molecule] = n_mol;
113 exceptionDescription <<
"G4VMoleculeCounter is not used";
114 G4Exception(
"G4DNAEventScheduler::ClearAndReChargeCounter()",
115 "G4DNAEventScheduler010",
JustWarning, exceptionDescription);
121 if(fTimeToRecord.find(time) == fTimeToRecord.end())
123 fTimeToRecord.insert(time);
132 std::map<G4VDNAMesh::Index, MapList> TrackKeyMap;
133 for(
auto track : *pMainList)
139 if(pScavengerMaterial !=
nullptr &&
140 pScavengerMaterial->find(molType))
145 auto key = fpMesh->GetIndex(track->GetPosition());
146 if(TrackKeyMap.find(key) != TrackKeyMap.end())
148 std::map<MolType, size_t>& TrackTypeMap = TrackKeyMap[key];
149 if(TrackTypeMap.find(molType) != TrackTypeMap.end())
151 TrackTypeMap[molType]++;
155 TrackTypeMap[molType] = 1;
160 TrackKeyMap[key][molType] = 1;
164 for(
auto& it : TrackKeyMap)
166 fpMesh->InitializeVoxel(it.first, std::move(it.second));
173 auto newMesh =
new G4DNAMesh(fpMesh->GetBoundingBox(), fPixel);
175 auto begin = fpMesh->begin();
176 auto end = fpMesh->end();
177 std::map<G4VDNAMesh::Index, MapList> TrackKeyMap;
178 for(; begin != end; begin++)
180 auto index = std::get<0>(*begin);
181 auto newIndex = fpMesh->ConvertIndex(index, fPixel);
182 if(TrackKeyMap.find(newIndex) == TrackKeyMap.end())
184 TrackKeyMap[newIndex] = std::get<2>(*begin);
188 for(
const auto& it : std::get<2>(*begin))
190 TrackKeyMap[newIndex][it.first] += it.second;
194 G4cout <<
" ReVoxelizing:: Old index : " << index
195 <<
" new index : " << fpMesh->ConvertIndex(index, fPixel)
196 <<
" number: " << std::get<2>(*begin).begin()->second <<
G4endl;
200 fpMesh.reset(newMesh);
202 for(
auto& it : TrackKeyMap)
204 fpMesh->InitializeVoxel(it.first, std::move(it.second));
210 fGlobalTime = fEndTime;
217 G4cout <<
"End Processing and reset Gird, ScavengerTable, EventSet for new "
221 fInitialized =
false;
224 fGlobalTime = fStartTime;
229 fpEventSet->RemoveEventSet();
237 fPixel = fInitialPixels;
238 fpMesh = std::make_unique<G4DNAMesh>(fpMesh->GetBoundingBox(), fPixel);
244 if(pScavengerMaterial ==
nullptr)
252 pScavengerMaterial->PrintInfo();
257 fpGillespieReaction->SetVoxelMesh(*fpMesh);
258 fpGillespieReaction->SetEventSet(fpEventSet.get());
259 fpGillespieReaction->SetTimeStep(
261 fpGillespieReaction->Initialize();
262 fpUpdateSystem->SetMesh(fpMesh.get());
269 fpUpdateSystem->SetVerbose(1);
288 fpGillespieReaction->SetVoxelMesh(*fpMesh);
289 fpUpdateSystem->SetMesh(fpMesh.get());
290 fpGillespieReaction->Initialize();
298 <<
"*** End Processing In Mesh and reset Mesh, EventSet for new Mesh!!!!"
301 fpEventSet->RemoveEventSet();
302 fInitialized =
false;
303 fIsChangeMesh =
false;
306 fStepNumberInMesh = 0;
328 fGlobalTime = fStartTime;
338 G4cout <<
"***G4DNAEventScheduler::Run*** for Pixel : " << fPixel <<
G4endl;
340 while(fEndTime > fGlobalTime && fRunning)
348 G4cout <<
" StepNumber(" << fStepNumber <<
") = MaxStep(" << fMaxStep
351 else if(fEndTime <= fGlobalTime)
353 G4cout <<
" GlobalTime(" << fGlobalTime <<
") > EndTime(" << fEndTime
355 <<
" StepNumber : " << fStepNumber <<
G4endl;
358 G4cout <<
"***G4DNAEventScheduler::Ending::"
360 <<
" Events left : " << fpEventSet->size() <<
G4endl;
378 G4double resolution = fpMesh->GetResolution();
380 <<
" the Mesh has " << fPixel <<
" x " << fPixel <<
" x " << fPixel
381 <<
" voxels with Resolution " <<
G4BestUnit(resolution,
"Length")
383 <<
G4BestUnit(resolution * resolution * C / (6 * D),
"Time")
392 if(fpUserMeshAction !=
nullptr)
394 fpUserMeshAction->BeginOfMesh(fpMesh.get(), fGlobalTime);
399 while(!fpEventSet->Empty() && !fIsChangeMesh && fEndTime > fGlobalTime)
402 fGlobalTime = fTimeStep + fStartTime;
404 if(fpUserMeshAction !=
nullptr)
406 fpUserMeshAction->InMesh(fpMesh.get(), fGlobalTime);
414 G4double resolution = fpMesh->GetResolution();
415 fTransferTime = resolution * resolution * C / (6 * D);
416 if(fTransferTime == 0)
419 exceptionDescription <<
"fTransferTime == 0";
420 G4Exception(
"G4DNAEventScheduler::RunInMesh",
"G4DNAEventScheduler001",
423 if(fTransferTime < fTimeStep &&
430 G4cout <<
" Pixels : " << fPixel <<
" resolution : "
431 <<
G4BestUnit(fpMesh->GetResolution(),
"Length")
432 <<
" fStepNumberInMesh : " << fStepNumberInMesh
433 <<
" at fGlobalTime : " <<
G4BestUnit(fGlobalTime,
"Time")
434 <<
" at fTimeStep : " <<
G4BestUnit(fTimeStep,
"Time")
435 <<
" fReactionNumber : " << fReactionNumber
436 <<
" transferTime : " <<
G4BestUnit(fTransferTime,
"Time")
439 fIsChangeMesh =
true;
446 G4cout <<
"***G4DNAEventScheduler::Ending::"
448 <<
" Event left : " << fpEventSet->size() <<
G4endl;
450 if(fpEventSet->Empty())
454 else if(fIsChangeMesh)
456 G4cout <<
"Changing Mesh from : " << fPixel
457 <<
" pixels to : " << fPixel / 2 <<
" pixels" <<
G4endl;
458 G4cout <<
"Info : ReactionNumber : " << fReactionNumber
459 <<
" JumpingNumber : " << fJumpingNumber <<
G4endl;
461 else if(fEndTime > fGlobalTime)
463 G4cout <<
" GlobalTime(" << fGlobalTime <<
") > EndTime(" << fEndTime
465 <<
" StepNumber : " << fStepNumber <<
G4endl;
474 if(fpUserMeshAction !=
nullptr)
476 fpUserMeshAction->EndOfMesh(fpMesh.get(), fGlobalTime);
483 fStepNumber < fMaxStep ? fStepNumber++ : fRunning =
false;
484 if(fpEventSet->size() > fpMesh->size())
488 <<
"impossible that fpEventSet->size() > fpMesh->size()";
489 G4Exception(
"G4DNAEventScheduler::Stepping",
"G4DNAEventScheduler002",
493 auto selected = fpEventSet->begin();
494 auto index = (*selected)->GetIndex();
498 G4cout <<
"G4DNAEventScheduler::Stepping()*********************************"
501 (*selected)->PrintEvent();
505 fTimeStep = (*selected)->GetTime();
508 auto pJumping = (*selected)->GetJumpingData();
509 auto pReaction = (*selected)->GetReactionData();
511 fpUpdateSystem->SetGlobalTime(fTimeStep +
513 fpGillespieReaction->SetTimeStep(fTimeStep);
514 if(pJumping ==
nullptr && pReaction !=
nullptr)
516 fpUpdateSystem->UpdateSystem(index, *pReaction);
517 fpEventSet->RemoveEvent(selected);
519 fpGillespieReaction->CreateEvent(index);
524 else if(pJumping !=
nullptr && pReaction ==
nullptr)
527 fpUpdateSystem->UpdateSystem(index, *pJumping);
529 auto jumpingIndex = pJumping->second;
530 fpEventSet->RemoveEvent(selected);
533 fpGillespieReaction->CreateEvent(jumpingIndex);
534 fpGillespieReaction->CreateEvent(index);
540 exceptionDescription <<
"pJumping == nullptr && pReaction == nullptr";
541 G4Exception(
"G4DNAEventScheduler::Stepping",
"G4DNAEventScheduler003",
547 G4cout <<
"G4DNAEventScheduler::Stepping::end "
548 "Print***********************************"
562 auto recordTime = *fLastRecoredTime;
563 if(fGlobalTime >= recordTime && fCounterMap[recordTime].empty())
565 auto begin = fpMesh->begin();
566 auto end = fpMesh->end();
567 for(; begin != end; begin++)
569 const auto& mapData = std::get<2>(*begin);
574 for(
const auto& it : mapData)
576 fCounterMap[recordTime][it.first] += it.second;
585 G4cout <<
"CounterMap.size : " << fCounterMap.size() <<
G4endl;
586 for(
const auto& i : fCounterMap)
589 auto begin = map.begin();
590 auto end = map.end();
591 for(; begin != end; begin++)
593 auto molecule = begin->first;
594 auto number = begin->second;
599 G4cout <<
"molecule : " << molecule->GetName() <<
" number : " << number
612 std::unique_ptr<G4UserMeshAction> pUserMeshAction)
614 fpUserMeshAction = std::move(pUserMeshAction);
624 auto reactionDataList = pMolecularReactionTable->GetVectorOfReactionData();
625 if(reactionDataList.empty())
632 for(
auto it : reactionDataList)
634 if(it->GetEffectiveReactionRadius() >= resolution / CLHEP::pi)
636 G4cout << it->GetReactant1()->GetName() <<
" + "
637 << it->GetReactant2()->GetName() <<
G4endl;
638 G4cout <<
"G4DNAEventScheduler::ReactionRadius : "
639 <<
G4BestUnit(it->GetEffectiveReactionRadius(),
"Length")
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
static G4bool CheckingReactionRadius(G4double resolution)
void SetMaxNbSteps(G4int)
G4DNAEventScheduler(const G4DNABoundingBox &boundingBox, G4int pixel)
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()