154 fNx =
G4int((fXMax-fXMin)/fRCutOff) == 0 ? 1 :
G4int((fXMax-fXMin)/fRCutOff);
155 fNy =
G4int((fYMax-fYMin)/fRCutOff) == 0 ? 1 :
G4int((fYMax-fYMin)/fRCutOff);
156 fNz =
G4int((fZMax-fZMin)/fRCutOff) == 0 ? 1 :
G4int((fZMax-fZMin)/fRCutOff);
164 G4int I =
FindBin(fNx, fXMin, fXMax, it_begin->GetPosition().x());
165 G4int J =
FindBin(fNy, fYMin, fYMax, it_begin->GetPosition().y());
166 G4int K =
FindBin(fNz, fZMin, fZMax, it_begin->GetPosition().z());
168 spaceBinned[I][J][K].push_back(*it_begin);
180 const vector<const G4MolecularConfiguration*>* reactivesVector =
183 if(reactivesVector ==
nullptr)
return;
195 for (
int ii = xiniIndex; ii <= xendIndex; ii++ ) {
196 for (
int jj = yiniIndex; jj <= yendIndex; jj++ ) {
197 for (
int kk = ziniIndex; kk <= zendIndex; kk++ ) {
199 std::vector<G4Track*> spaceBin = spaceBinned[ii][jj][kk];
200 for (
int n = 0; n < (int)spaceBinned[ii][jj][kk].size(); n++ ) {
201 if((spaceBin[n] ==
nullptr) || track == spaceBin[n])
continue;
205 if(molB ==
nullptr)
continue;
210 auto it = std::find(reactivesVector->begin(), reactivesVector->end(), molConfB);
211 if(it == reactivesVector->end())
continue;
221 sigma = std::sqrt(2.0 * diffusionCoefficient * dt);
223 x = G4RandGauss::shoot(0., 1.0)*sigma;
224 y = G4RandGauss::shoot(0., 1.0)*sigma;
225 z = G4RandGauss::shoot(0., 1.0)*sigma;
228 }
else if(dt < 0)
continue;
234 if(irt>=0 && irt<timeMax - globalTime)
237 if(irt < minTime) minTime = irt;
260 for(
size_t u=0; u<fReactionDatas->size();u++){
261 if((*fReactionDatas)[u]->GetReactant2()->GetDiffusionCoefficient() == 0){
262 G4double kObs = (*fReactionDatas)[u]->GetObservedReactionRateConstant();
263 if(kObs == 0)
continue;
265 if( time < minTime && time >= globalTime && time < timeMax){
274 G4cout<<
"scavenged: "<<minTime<<
'\t'<<molConfA->
GetName()<<it_begin->GetTrackID()<<
'\n';
276 auto fakeMol =
new G4Molecule((*fReactionDatas)[index]->GetReactant2());
278 fTrackHolder->
Push(fakeTrack);
279 fReactionSet->
AddReaction(minTime, track, fakeTrack);
285 const auto pMoleculeA = molA;
286 const auto pMoleculeB = molB;
290 if(r0 == 0) r0 += 1e-3*nm;
294 if(
D == 0)
D += 1e-20*(m2/s);
295 G4double rc = fReactionData->GetOnsagerRadius();
297 if ( reactionType == 0){
298 G4double sigma = fReactionData->GetEffectiveReactionRadius();
300 if(sigma > r0)
return 0;
301 if( rc != 0) r0 = -rc / (1-std::exp(rc/r0));
306 if (
W > 0 &&
W < Winf ) irt = (0.25/
D) * std::pow( (r0-sigma)/erfc->
erfcInv(r0*
W/sigma), 2 );
310 if ( reactionType == 1 ){
311 G4double sigma = fReactionData->GetReactionRadius();
312 G4double kact = fReactionData->GetActivationRateConstant();
313 G4double kdif = fReactionData->GetDiffusionRateConstant();
314 G4double kobs = fReactionData->GetObservedReactionRateConstant();
319 a = 1/sigma * kact / kobs;
320 b = (r0 - sigma) / 2;
322 G4double v = kact/Avogadro/(4*CLHEP::pi*pow(sigma,2) * exp(-rc / sigma));
323 G4double alpha = v+rc*
D/(pow(sigma,2)*(1-exp(-rc/sigma)));
324 a = 4*pow(sigma,2)*alpha/(
D*pow(rc,2))*pow(sinh(rc/(2*sigma)),2);
325 b = rc/4*(cosh(rc/(2*r0))/sinh(rc/(2*r0))-cosh(rc/(2*sigma))/sinh(rc/(2*sigma)));
326 r0 = -rc/(1-std::exp(rc/r0));
327 sigma = fReactionData->GetEffectiveReactionRadius();
331 if(fReactionData->GetProbability() >
G4UniformRand())
return 0;
334 Winf = sigma / r0 * kobs / kdif;
361 G4double p = 2.0 * std::sqrt(2.0*b/a);
362 G4double q = 2.0 / std::sqrt(2.0*b/a);
372 if ( U < p/(p + q *
M) ) X = pow(U * (p + q *
M) / 2, 2);
373 else X = pow(2/((1-U)*(p+q*
M)/
M),2);
377 lambdax = std::exp(-b*b/X) * ( 1.0 - a * std::sqrt(CLHEP::pi * X) * erfc->
erfcx(b/std::sqrt(X) + a*std::sqrt(X)));
379 if ((X <= 2.0*b/a && U <= lambdax) ||
380 (X >= 2.0*b/a && U*
M/X <= lambdax))
break;
384 if ( ntrials > 10000 ){
385 G4cout<<
"Totally rejected"<<
'\n';
397 pChanges->Initialize(trackA, trackB);
404 G4double effectiveReactionRadius = pReactionData->GetEffectiveReactionRadius();
406 const G4double D1 = pMoleculeA->GetDiffusionCoefficient();
407 const G4double D2 = pMoleculeB->GetDiffusionCoefficient();
418 S1.
setMag(effectiveReactionRadius);
422 if(dt != 0 && (D1 + D2) != 0 && r0 != 0){
425 if(s12 == 0) r2 = r1;
426 else if(s22 == 0) r1 = r2;
428 G4double alpha = effectiveReactionRadius * r0 / (2*(D1 + D2)*dt);
430 G4RandGauss::shoot(0, s12 + s22 * s22 / s12),
431 G4RandGauss::shoot(0, s12 + s22 * s22 / s12));
437 S1.
setTheta(rad * std::acos(1.0 + 1./alpha * std::log(1.0 -
G4UniformRand() * (1 - std::exp(-2.0 * alpha)))));
439 r1 = (D1 * S1 + D2 * S2) / (D1 + D2);
440 r2 = D2 * (S2 - S1) / (D1 + D2);
444 auto pTrackA =
const_cast<G4Track*
>(pChanges->GetTrackA());
445 auto pTrackB =
const_cast<G4Track*
>(pChanges->GetTrackB());
448 pTrackB->SetPosition(r2);
450 pTrackA->SetGlobalTime(globalTime);
451 pTrackB->SetGlobalTime(globalTime);
456 const G4int nbProducts = pReactionData->GetNbProducts();
460 const G4double sqrD1 = D1 == 0. ? 0. : std::sqrt(D1);
461 const G4double sqrD2 = D2 == 0. ? 0. : std::sqrt(D2);
462 if((sqrD1 + sqrD2) == 0){
465 const G4double inv_numerator = 1./(sqrD1 + sqrD2);
469 std::vector<G4ThreeVector>
position;
473 }
else if(nbProducts == 2){
476 }
else if (nbProducts == 3){
482 for(
G4int u = 0; u < nbProducts; u++){
484 auto product =
new G4Molecule(pReactionData->GetProduct(u));
485 auto productTrack = product->BuildTrack(globalTime,
488 productTrack->SetTrackStatus(
fAlive);
489 fTrackHolder->
Push(productTrack);
491 pChanges->AddSecondary(productTrack);
497 spaceBinned[I][J][K].push_back(productTrack);
504 pChanges->KillParents(
true);
515 std::vector<std::unique_ptr<G4ITReactionChange>> fReactionInfo;
516 fReactionInfo.clear();
518 if (pReactionSet ==
nullptr)
520 return fReactionInfo;
524 assert(fReactionsetInTime.begin() != fReactionsetInTime.end());
526 auto it_begin = fReactionsetInTime.begin();
527 while(it_begin != fReactionsetInTime.end())
529 G4double irt = it_begin->get()->GetTime();
531 if(fGlobalTime < irt)
break;
535 G4Track* pTrackA = it_begin->get()->GetReactants().first;
536 G4Track* pTrackB = it_begin->get()->GetReactants().second;
537 auto pReactionChange =
MakeReaction(*pTrackA, *pTrackB);
540 fReactionInfo.push_back(std::move(pReactionChange));
544 it_begin = fReactionsetInTime.begin();
547 return fReactionInfo;