45 fpEventSet = pEventSet;
50G4double G4DNAGillespieDirectMethod::VolumeOfNode(
const Voxel& voxel)
52 auto box = std::get<1>(voxel);
53 auto LengthY = box.Getyhi() - box.Getylo();
54 auto LengthX = box.Getxhi() - box.Getxlo();
55 auto LengthZ = box.Getzhi() - box.Getzlo();
56 G4double V = LengthY * LengthX * LengthZ;
60 exceptionDescription <<
"V > 0 !! ";
61 G4Exception(
"G4DNAGillespieDirectMethod::VolumeOfNode",
63 exceptionDescription);
74 const auto& node = std::get<2>(voxel);
75 const auto& box = std::get<1>(voxel);
78 auto it = node.find(moleType);
81 auto LengthY = box.Getyhi() - box.Getylo();
82 G4double d = it->first->GetDiffusionCoefficient() / std::pow(LengthY, 2);
83 alpha = d * it->second;
86 G4cout << it->first->GetName() <<
" " << it->second
87 <<
" D : " << it->first->GetDiffusionCoefficient()
88 <<
" LengthY : " << LengthY <<
" PropensityFunction : " << alpha
102 auto typeANumber = FindScavenging(voxel, ConfA, scavengerNumber)
104 : ComputeNumberInNode(voxel, ConfA);
106 auto typeBNumber = FindScavenging(voxel, ConfB, scavengerNumber)
108 : ComputeNumberInNode(voxel, ConfB);
110 if(typeANumber == 0 || typeBNumber == 0)
119 value = typeANumber * (typeBNumber - 1) * k;
123 value = typeANumber * typeBNumber * k;
130 <<
"G4DNAGillespieDirectMethod::PropensityFunction for : "
131 << ConfA->GetName() <<
"(" << typeANumber <<
") + " << ConfB->GetName()
132 <<
"(" << typeBNumber <<
") : propensity : " << value
133 <<
" GetObservedReactionRateConstant : "
135 <<
" GetEffectiveReactionRadius : "
137 <<
" k : " << k <<
" volume : " << VolumeOfNode(voxel) <<
G4endl;
138 G4Exception(
"G4DNAGillespieDirectMethod::PropensityFunction",
140 exceptionDescription);
145 G4cout <<
"G4DNAGillespieDirectMethod::PropensityFunction for : "
146 << ConfA->GetName() <<
"(" << typeANumber <<
") + "
147 << ConfB->GetName() <<
"(" << typeBNumber
148 <<
") : propensity : " << value
149 <<
" Time to Reaction : " <<
G4BestUnit(timeToReaction,
"Time")
150 <<
" k : " << k <<
" Index : " << index <<
G4endl;
162 auto begin = fpMesh->
begin();
163 auto end = fpMesh->
end();
164 for(; begin != end; begin++)
166 auto index = std::get<0>(*begin);
176 fTimeStep = stepTime;
180 const auto& voxel = fpMesh->
GetVoxel(index);
181 if(std::get<2>(voxel).empty())
184 exceptionDescription <<
"This voxel : " << index
185 <<
" is not ready to make event" <<
G4endl;
186 G4Exception(
"G4DNAGillespieDirectMethod::CreateEvent",
188 exceptionDescription);
192 G4double dAlpha0 = DiffusiveJumping(voxel);
194 G4double alphaTotal = dAlpha0 + rAlpha0;
200 auto timeStep = ((1.0 / (alphaTotal)) * std::log(1.0 / r1)) + fTimeStep;
203 G4cout <<
"r2 : " << r2 <<
" rAlpha0 : " << rAlpha0
204 <<
" dAlpha0 : " << dAlpha0 <<
" rAlpha0 / (dAlpha0 + rAlpha0) : "
205 << rAlpha0 / (dAlpha0 + rAlpha0) <<
G4endl;
207 if(r2 < rAlpha0 / alphaTotal)
211 G4cout <<
"=>>>>reaction at : " << timeStep <<
" timeStep : "
212 <<
G4BestUnit(((1.0 / alphaTotal) * std::log(1.0 / r1)),
"Time")
215 auto rSelectedIter = fReactionDataMap.upper_bound(r2 * alphaTotal);
216 fpEventSet->
CreateEvent(timeStep, index, rSelectedIter->second);
222 G4cout <<
"=>>>>jumping at : " << timeStep <<
" timeStep : "
223 <<
G4BestUnit(((1.0 / alphaTotal) * std::log(1.0 / r1)),
"Time")
227 auto dSelectedIter = fJumpingDataMap.upper_bound(r2 * alphaTotal - rAlpha0);
229 std::make_unique<std::pair<MolType, Index>>(dSelectedIter->second);
230 fpEventSet->
CreateEvent(timeStep, index, std::move(pDSelected));
237G4double G4DNAGillespieDirectMethod::Reaction(
const Voxel& voxel)
239 fReactionDataMap.clear();
241 const auto& dataList =
246 exceptionDescription <<
"MolecularReactionTable empty" <<
G4endl;
247 G4Exception(
"G4DNAGillespieDirectMethod::Reaction",
249 exceptionDescription);
252 for(
const auto& it : dataList)
259 alpha0 += propensity;
260 fReactionDataMap[alpha0] = it;
268G4double G4DNAGillespieDirectMethod::DiffusiveJumping(
const Voxel& voxel)
270 fJumpingDataMap.clear();
272 auto index = std::get<0>(voxel);
274 if(NeighboringVoxels.empty())
281 const auto* conf = iter.
value();
287 for(
const auto& it_Neighbor : NeighboringVoxels)
289 alpha0 += propensity;
290 fJumpingDataMap[alpha0] = std::make_pair(conf, it_Neighbor);
292 G4cout <<
"mole : " << conf->GetName()
293 <<
" number : " << ComputeNumberInNode(index, conf)
294 <<
" propensity : " << propensity <<
" alpha0 : " << alpha0
300 G4cout <<
"DiffusiveJumping :alpha0 : " << alpha0 <<
G4endl;
305G4double G4DNAGillespieDirectMethod::ComputeNumberInNode(
306 const Voxel& voxel, MolType type)
308 if(type->GetDiffusionCoefficient() != 0)
310 const auto& node = std::get<2>(voxel);
311 const auto& it = node.find(type);
312 return (it != node.end()) ? (it->second) : 0;
320G4bool G4DNAGillespieDirectMethod::FindScavenging(
const Voxel& voxel,
324 numberOfScavenger = 0;
325 if(fpScavengerMaterial ==
nullptr)
329 auto volumeOfNode = VolumeOfNode(voxel);
332 auto factor = Avogadro * volumeOfNode;
333 numberOfScavenger = factor;
346 G4double numberInDouble = volumeOfNode * std::floor(totalNumber) /
348 auto numberInInterg = (int64_t) (std::floor(numberInDouble));
349 G4double change = numberInDouble - numberInInterg;
350 G4UniformRand() > change ? numberOfScavenger = numberInInterg
351 : numberOfScavenger = numberInInterg + 1;
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
void CreateEvent(const G4double &time, const Index &index, Event::ReactionData *pReactionData)
~G4DNAGillespieDirectMethod()
void CreateEvent(const Index &index)
void SetEventSet(G4DNAEventSet *)
G4double PropensityFunction(const Voxel &voxel, ReactionData *data)
void SetTimeStep(const G4double &stepTime)
G4DNAGillespieDirectMethod()
void PrintVoxel(const Index &index)
Voxel & GetVoxel(const Index &index)
const G4DNABoundingBox & GetBoundingBox() const
std::vector< Index > FindNeighboringVoxels(const Index &index) const
Reactant * GetReactant1() const
G4double GetEffectiveReactionRadius() const
Reactant * GetReactant2() const
G4double GetObservedReactionRateConstant() const
DataList GetVectorOfReactionData()
G4double GetNumberMoleculePerVolumeUnitForMaterialConf(MolType) const
G4double GetDiffusionCoefficient() const
static G4MoleculeTable * Instance()
G4ConfigurationIterator GetConfigurationIterator()
static G4Scheduler * Instance()
G4VScavengerMaterial * GetScavengerMaterial() const