File indexing completed on 2026-01-07 09:28:01
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 #include "TimeStepAction.hh"
0028
0029 #include "InterPulseAction.hh"
0030
0031 #include "G4DNAEventScheduler.hh"
0032 #include "G4DNAGillespieDirectMethod.hh"
0033 #include "G4DNAMolecularReactionTable.hh"
0034 #include "G4EventManager.hh"
0035 #include "G4ITLeadingTracks.hh"
0036 #include "G4MoleculeCounter.hh"
0037 #include "G4Scheduler.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4Track.hh"
0040 #include "G4UnitsTable.hh"
0041 #include "G4VChemistryWorld.hh"
0042 #include "G4VPrimitiveScorer.hh"
0043
0044 TimeStepAction::TimeStepAction(const G4VChemistryWorld* pChemWorld, PulseAction* pPulse)
0045 : G4UserTimeStepAction(), fpPulse(pPulse), fpChemWorld(pChemWorld)
0046 {
0047 fpEventScheduler = std::make_unique<G4DNAEventScheduler>();
0048 fScheduler = G4Scheduler::Instance();
0049 if (dynamic_cast<InterPulseAction*>(fpPulse) != nullptr) {
0050 fPulsePeriod = dynamic_cast<InterPulseAction*>(fpPulse)->GetPulsePeriod();
0051 fNumberOfPulse = dynamic_cast<InterPulseAction*>(fpPulse)->GetNumberOfPulse();
0052 }
0053 }
0054
0055
0056 void TimeStepAction::UserPreTimeStepAction()
0057 {
0058 fpEventScheduler->ParticleBasedCounter();
0059 }
0060
0061
0062
0063 void TimeStepAction::UserPostTimeStepAction()
0064 {
0065 G4double T1 = 5 * CLHEP::ns;
0066 if (fpPulse != nullptr && fpPulse->IsActivedPulse()) {
0067 T1 = fpPulse->GetPulseLarger() + 5 * CLHEP::ns;
0068 if (fNumberOfPulse != 0) {
0069 fPulseID = (floor)(fScheduler->GetGlobalTime() / fPulsePeriod);
0070 T1 = fPulseID * fPulsePeriod + fpPulse->GetPulseLarger() + 5 * CLHEP::ns;
0071 }
0072 }
0073
0074 if (fScheduler->GetGlobalTime() >= T1) {
0075 CompartmentBased();
0076 }
0077 }
0078
0079
0080
0081 void TimeStepAction::UserReactionAction(const G4Track& , const G4Track& ,
0082 const std::vector<G4Track*>* )
0083 {}
0084
0085
0086
0087 void TimeStepAction::EndProcessing()
0088 {
0089 fpEventScheduler->Reset();
0090 }
0091
0092
0093
0094 void TimeStepAction::CompartmentBased()
0095 {
0096 fpEventScheduler->SetStartTime(fScheduler->GetGlobalTime());
0097 fpEventScheduler->SetChangeMesh(true);
0098 fpEventScheduler->Initialize(*fpChemWorld->GetChemistryBoundary(), fPixel);
0099 fpEventScheduler->Run();
0100 }
0101
0102
0103
0104 G4DNAEventScheduler* TimeStepAction::GetEventScheduler() const
0105 {
0106 return fpEventScheduler.get();
0107 }
0108
0109
0110
0111 void TimeStepAction::SetInitialPixel()
0112 {
0113 auto pBoundingBox = fpChemWorld->GetChemistryBoundary();
0114 G4double Box = pBoundingBox->halfSideLengthInX();
0115 if (Box == 4 * 1.6 * um) {
0116 fPixel = 4 * 512;
0117 }
0118 else if (Box == 2 * 1.6 * um) {
0119 fPixel = 2 * 512;
0120 }
0121 else if (Box == 1.6 * um) {
0122 fPixel = 512;
0123 }
0124 else if (Box == 0.8 * um) {
0125 fPixel = 256;
0126 }
0127 else if (Box == 0.4 * um) {
0128 fPixel = 256 / 2;
0129 }
0130 else if (Box == 0.2 * um) {
0131 fPixel = 256 / 4;
0132 }
0133 else {
0134 G4cout << "Box : " << *pBoundingBox << " Pixel : " << fPixel << G4endl;
0135 G4Exception("This chem volume is not optimized and the result may be incorrect.",
0136 "TimeStepAction::TimeStepAction", FatalException, "");
0137 }
0138 }
0139
0140
0141
0142 void TimeStepAction::StartProcessing()
0143 {
0144 auto currentEvent = G4EventManager::GetEventManager();
0145 if (currentEvent->GetConstCurrentEvent()->IsAborted()) {
0146 G4cout << "This event is fully aborted" << G4endl;
0147 fScheduler->Stop();
0148 }
0149 fpEventScheduler->SetVerbose(G4Scheduler::Instance()->GetVerbose());
0150 SetInitialPixel();
0151 fPulseID = 0;
0152 }
0153
0154