Import Geant4 10.6.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2019-06-28 11:59:04 +02:00
parent 28a70706e0
commit d0f911957d
1056 changed files with 95168 additions and 78160 deletions
@@ -38,188 +38,86 @@
#include "G4DNAMolecularReaction.hh"
#include "G4DNAMolecularReactionTable.hh"
#include "G4VDNAReactionModel.hh"
#include "G4MoleculeFinder.hh"
#include "G4UnitsTable.hh"
#include "G4MolecularConfiguration.hh"
#include "G4Molecule.hh"
#include "G4MoleculeFinder.hh"
#include "G4ITReactionChange.hh"
using namespace std;
G4DNAMolecularReaction::G4DNAMolecularReaction() :
G4VITReactionProcess(),
fMolReactionTable(
reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
G4DNAMolecularReaction::G4DNAMolecularReaction()
: G4VITReactionProcess()
, fMolReactionTable(reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
, fpReactionModel(nullptr)
{
//ctor
fVerbose = 0;
fReactionModel = 0;
fReactionRadius = -1;
fDistance = -1;
}
G4DNAMolecularReaction::~G4DNAMolecularReaction()
G4DNAMolecularReaction::G4DNAMolecularReaction(G4VDNAReactionModel* pReactionModel)
: G4DNAMolecularReaction()
{
//dtor
if (fpChanges) delete fpChanges;
fpReactionModel = pReactionModel;
}
G4DNAMolecularReaction::G4DNAMolecularReaction(const G4DNAMolecularReaction& other) :
G4VITReactionProcess(other),
fMolReactionTable(
reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
{
//copy ctor
fVerbose = other.fVerbose;
fMolReactionTable = other.fMolReactionTable;
fReactionModel = 0;
fReactionRadius = -1;
fDistance = -1;
}
G4DNAMolecularReaction& G4DNAMolecularReaction::operator=(const G4DNAMolecularReaction& rhs)
{
if (this == &rhs) return *this; // handle self assignment
fVerbose = rhs.fVerbose;
fMolReactionTable = rhs.fMolReactionTable;
fReactionRadius = -1;
fDistance = -1;
//assignment operator
return *this;
}
G4bool G4DNAMolecularReaction::TestReactibility(const G4Track& trackA,
const G4Track& trackB,
const double currentStepTime,
const double /*previousStepTime*/,
G4bool G4DNAMolecularReaction::TestReactibility(const G4Track &trackA,
const G4Track &trackB,
double currentStepTime,
bool userStepTimeLimit) /*const*/
{
G4MolecularConfiguration* moleculeA =
GetMolecule(trackA)->GetMolecularConfiguration();
G4MolecularConfiguration* moleculeB =
GetMolecule(trackB)->GetMolecularConfiguration();
const auto pMoleculeA = GetMolecule(trackA)->GetMolecularConfiguration();
const auto pMoleculeB = GetMolecule(trackB)->GetMolecularConfiguration();
if (!fReactionModel)
{
G4ExceptionDescription exceptionDescription(
"You have to give a reaction model to the molecular reaction process");
G4Exception("G4DNAMolecularReaction::TestReactibility",
"MolecularReaction001", FatalErrorInArgument,
exceptionDescription);
return false; // makes coverity happy
}
if (fMolReactionTable == 0)
{
G4ExceptionDescription exceptionDescription(
"You have to give a reaction table to the molecular reaction process");
G4Exception("G4DNAMolecularReaction::TestReactibility",
"MolecularReaction002", FatalErrorInArgument,
exceptionDescription);
return false; // makes coverity happy
}
const G4double reactionRadius = fpReactionModel->GetReactionRadius(pMoleculeA, pMoleculeB);
// Retrieve reaction range
fReactionRadius = -1; // reaction Range
fReactionRadius = fReactionModel->GetReactionRadius(moleculeA, moleculeB);
G4double separationDistance = -1.;
fDistance = -1; // separation distance
if (currentStepTime == 0.)
{
userStepTimeLimit = false;
}
G4bool output = fReactionModel->FindReaction(trackA, trackB, fReactionRadius,
fDistance, userStepTimeLimit);
#ifdef G4VERBOSE
// DEBUG
if (fVerbose > 1)
{
G4cout << "\033[1;39;36m" << "G4MolecularReaction " << G4endl;
G4cout << "FindReaction returned : " << G4BestUnit(output,"Length") << G4endl;
G4cout << " reaction radius : " << G4BestUnit(fReactionRadius,"Length")
<< " real distance : " << G4BestUnit((trackA.GetPosition() - trackB.GetPosition()).mag(), "Length")
<< " calculated distance by model (= -1 if real distance > reaction radius and the user limitation step is not reached) : "
<< G4BestUnit(fDistance,"Length")
<< G4endl;
G4cout << "TrackID A : " << trackA.GetTrackID()
<< ", TrackID B : " << trackB.GetTrackID()
<< " | MolA " << moleculeA->GetName()
<< ", MolB " << moleculeB->GetName()
<<"\033[0m\n"
<< G4endl;
G4cout << "--------------------------------------------" << G4endl;
}
#endif
return output;
}
G4ITReactionChange* G4DNAMolecularReaction::MakeReaction(const G4Track& trackA,
const G4Track& trackB)
{
fpChanges = new G4ITReactionChange();
fpChanges->Initialize(trackA, trackB);
G4MolecularConfiguration* moleculeA =
GetMolecule(trackA)->GetMolecularConfiguration();
G4MolecularConfiguration* moleculeB =
GetMolecule(trackB)->GetMolecularConfiguration();
#ifdef G4VERBOSE
// DEBUG
if (fVerbose)
{
G4cout << "G4DNAMolecularReaction::MakeReaction" << G4endl;
G4cout<<"TrackA n°" << trackA.GetTrackID()
<<"\t | Track B n°" << trackB.GetTrackID() << G4endl;
G4cout<<"Track A : Position : " << G4BestUnit(trackA.GetPosition(),"Length")
<<"\t Global Time : " << G4BestUnit(trackA.GetGlobalTime(), "Time")<< G4endl;
G4cout<<"Track B : Position : " << G4BestUnit(trackB.GetPosition() ,"Length")
<<"\t Global Time : " << G4BestUnit(trackB.GetGlobalTime(), "Time")<< G4endl;
G4cout<<"Reaction range : " << G4BestUnit(fReactionRadius,"Length")
<< " \t Separation distance : " << G4BestUnit(fDistance,"Length")<< G4endl;
G4cout << "--------------------------------------------" << G4endl;
}
#endif
const G4DNAMolecularReactionData* reactionData = fMolReactionTable
->GetReactionData(moleculeA, moleculeB);
G4int nbProducts = reactionData->GetNbProducts();
if (nbProducts)
{
G4double D1 = moleculeA->GetDiffusionCoefficient();
G4double D2 = moleculeB->GetDiffusionCoefficient();
G4double sqrD1 = sqrt(D1);
G4double sqrD2 = sqrt(D2);
G4double numerator = sqrD1 + sqrD2;
G4ThreeVector reactionSite = sqrD1 / numerator * trackA.GetPosition()
+ sqrD2 / numerator * trackB.GetPosition();
for (G4int j = 0; j < nbProducts; j++)
if (currentStepTime == 0.)
{
G4Molecule* product = new G4Molecule(reactionData->GetProduct(j));
G4Track* productTrack = product->BuildTrack(trackA.GetGlobalTime(),
reactionSite);
// G4cout << ">> G4DNAMolecularReaction::MakeReaction " << G4endl
// << "\t track A ("<< trackA.GetTrackID() <<"): " << trackA.GetGlobalTime() << G4endl
// << "\t track B ("<< trackB.GetTrackID() <<"): " << trackB.GetGlobalTime() << G4endl;
productTrack->SetTrackStatus(fAlive);
fpChanges->AddSecondary(productTrack);
G4MoleculeFinder::Instance()->Push(productTrack);
userStepTimeLimit = false;
}
}
fpChanges->KillParents(true);
return fpChanges;
G4bool output = fpReactionModel->FindReaction(trackA, trackB, reactionRadius,
separationDistance, userStepTimeLimit);
return output;
}
std::unique_ptr<G4ITReactionChange> G4DNAMolecularReaction::MakeReaction(const G4Track &trackA,
const G4Track &trackB)
{
std::unique_ptr<G4ITReactionChange> pChanges(new G4ITReactionChange());
pChanges->Initialize(trackA, trackB);
const auto pMoleculeA = GetMolecule(trackA)->GetMolecularConfiguration();
const auto pMoleculeB = GetMolecule(trackB)->GetMolecularConfiguration();
const auto pReactionData = fMolReactionTable->GetReactionData(pMoleculeA, pMoleculeB);
const G4int nbProducts = pReactionData->GetNbProducts();
if (nbProducts)
{
const G4double D1 = pMoleculeA->GetDiffusionCoefficient();
const G4double D2 = pMoleculeB->GetDiffusionCoefficient();
const G4double sqrD1 = D1 == 0. ? 0. : sqrt(D1);
const G4double sqrD2 = D2 == 0. ? 0. : sqrt(D2);
const G4double inv_numerator = 1./(sqrD1 + sqrD2);
const G4ThreeVector reactionSite = sqrD2 * inv_numerator * trackA.GetPosition()
+ sqrD1 * inv_numerator * trackB.GetPosition();
for (G4int j = 0; j < nbProducts; ++j)
{
auto pProduct = new G4Molecule(pReactionData->GetProduct(j));
auto pProductTrack = pProduct->BuildTrack(trackA.GetGlobalTime(), reactionSite);
pProductTrack->SetTrackStatus(fAlive);
pChanges->AddSecondary(pProductTrack);
G4MoleculeFinder::Instance()->Push(pProductTrack);
}
}
pChanges->KillParents(true);
return pChanges;
}
void G4DNAMolecularReaction::SetReactionModel(G4VDNAReactionModel* pReactionModel)
{
fpReactionModel = pReactionModel;
}
@@ -36,72 +36,60 @@
#include <G4ReferenceCast.hh>
#include <G4VDNAReactionModel.hh>
G4DNAMolecularStepByStepModel::G4DNAMolecularStepByStepModel(const G4String& name) :
G4VITStepModel(name),
fMolecularReactionTable(reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
G4DNAMolecularStepByStepModel::G4DNAMolecularStepByStepModel(const G4String& name)
: G4DNAMolecularStepByStepModel(name,
std::unique_ptr<G4DNAMoleculeEncounterStepper>(new G4DNAMoleculeEncounterStepper()),
std::unique_ptr<G4DNAMolecularReaction>(new G4DNAMolecularReaction()))
{
fpTimeStepper = new G4DNAMoleculeEncounterStepper();
fpReactionProcess = new G4DNAMolecularReaction();
fType1 = G4Molecule::ITType();
fType2 = G4Molecule::ITType();
fReactionModel = 0;
}
G4DNAMolecularStepByStepModel::~G4DNAMolecularStepByStepModel()
G4DNAMolecularStepByStepModel::G4DNAMolecularStepByStepModel(const G4String& name,
std::unique_ptr<G4VITTimeStepComputer> pTimeStepper,
std::unique_ptr<G4VITReactionProcess> pReactionProcess)
: G4VITStepModel(std::move(pTimeStepper),
std::move(pReactionProcess),
name)
, fMolecularReactionTable(reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
{
if(fReactionModel) delete fReactionModel;
fType1 = G4Molecule::ITType();
fType2 = G4Molecule::ITType();
}
G4DNAMolecularStepByStepModel& G4DNAMolecularStepByStepModel::operator=(const G4DNAMolecularStepByStepModel& right)
{
G4ExceptionDescription exceptionDescription("Use copy constructor rather than assignement operator.");
G4Exception("G4DNAMolecularStepByStepModel::operator=(const G4DNAMolecularStepByStepModel&)",
"G4DNAMolecularStepByStepModel001",
FatalErrorInArgument,
exceptionDescription);
if(&right == this) return *this;
return *this; // avoid warnings
}
G4DNAMolecularStepByStepModel::G4DNAMolecularStepByStepModel(const G4DNAMolecularStepByStepModel& right) :
G4VITStepModel(right),
fMolecularReactionTable(reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
{
fpReactionTable = right.fpReactionTable;
if(right.fReactionModel)
{
fReactionModel = right.fReactionModel->Clone();
((G4DNAMolecularReaction*) fpReactionProcess)->SetReactionModel(fReactionModel);
((G4DNAMoleculeEncounterStepper*) fpTimeStepper)->SetReactionModel(fReactionModel);
}
else fReactionModel = 0;
}
G4DNAMolecularStepByStepModel::~G4DNAMolecularStepByStepModel() = default;
void G4DNAMolecularStepByStepModel::Initialize()
{
if(fpReactionTable == 0)
{
SetReactionTable(G4DNAMolecularReactionTable::GetReactionTable());
}
if(fpReactionTable == nullptr)
{
SetReactionTable(G4DNAMolecularReactionTable::GetReactionTable());
}
if(fReactionModel == 0)
{
fReactionModel = new G4DNASmoluchowskiReactionModel();
}
if(!fpReactionModel)
{
fpReactionModel.reset(new G4DNASmoluchowskiReactionModel());
}
fReactionModel->SetReactionTable((const G4DNAMolecularReactionTable*) fpReactionTable);
fpReactionModel->SetReactionTable((const G4DNAMolecularReactionTable*) fpReactionTable);
((G4DNAMolecularReaction*) fpReactionProcess)->SetReactionModel(fReactionModel);
((G4DNAMoleculeEncounterStepper*) fpTimeStepper)->SetReactionModel(fReactionModel);
((G4DNAMolecularReaction*) fpReactionProcess.get())->SetReactionModel(fpReactionModel.get());
((G4DNAMoleculeEncounterStepper*) fpTimeStepper.get())->SetReactionModel(fpReactionModel.get());
G4VITStepModel::Initialize();
G4VITStepModel::Initialize();
}
void G4DNAMolecularStepByStepModel::PrintInfo()
{
#ifdef G4VERBOSE
G4cout << "DNAMolecularStepByStepModel will be used" << G4endl;
G4cout << fName << " will be used" << G4endl;
#endif
}
void G4DNAMolecularStepByStepModel::SetReactionModel(G4VDNAReactionModel* pReactionModel)
{
fpReactionModel.reset(pReactionModel);
}
G4VDNAReactionModel* G4DNAMolecularStepByStepModel::GetReactionModel()
{
return fpReactionModel.get();
}
@@ -55,319 +55,257 @@ using namespace G4MemStat;
#endif
G4DNAMoleculeEncounterStepper::Utils::Utils(const G4Track& tA,
G4MolecularConfiguration* mB) :
trackA(tA), moleculeB(mB)
const G4MolecularConfiguration* pMoleculeB)
: fpTrackA(tA)
, fpMoleculeB(pMoleculeB)
{
moleculeA = GetMolecule(tA);
DA = moleculeA->GetDiffusionCoefficient();
DB = moleculeB->GetDiffusionCoefficient();
Constant = 8 * (DA + DB + 2 * sqrt(DA * DB));
fpMoleculeA = GetMolecule(tA);
fDA = fpMoleculeA->GetDiffusionCoefficient();
fDB = fpMoleculeB->GetDiffusionCoefficient();
fConstant = 8 * (fDA + fDB + 2 * sqrt(fDA * fDB));
}
G4DNAMoleculeEncounterStepper::G4DNAMoleculeEncounterStepper() :
G4VITTimeStepComputer(),
fMolecularReactionTable(
reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable)),
fReactionModel(0)
{
fVerbose = 0;
fHasAlreadyReachedNullTime = false;
}
G4DNAMoleculeEncounterStepper& G4DNAMoleculeEncounterStepper::operator=(const G4DNAMoleculeEncounterStepper& rhs)
{
if (this == &rhs) return *this;
fReactionModel = 0;
fVerbose = rhs.fVerbose;
fMolecularReactionTable = rhs.fMolecularReactionTable;
fHasAlreadyReachedNullTime = false;
return *this;
}
G4DNAMoleculeEncounterStepper::~G4DNAMoleculeEncounterStepper()
G4DNAMoleculeEncounterStepper::G4DNAMoleculeEncounterStepper()
: G4VITTimeStepComputer()
, fHasAlreadyReachedNullTime(false)
, fMolecularReactionTable(reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
, fReactionModel(nullptr)
, fVerbose(0)
{
}
G4DNAMoleculeEncounterStepper::G4DNAMoleculeEncounterStepper(const G4DNAMoleculeEncounterStepper& right) :
G4VITTimeStepComputer(right),
fMolecularReactionTable(
reference_cast<const G4DNAMolecularReactionTable*>(fpReactionTable))
{
fVerbose = right.fVerbose;
fMolecularReactionTable = right.fMolecularReactionTable;
fReactionModel = 0;
fHasAlreadyReachedNullTime = false;
}
G4DNAMoleculeEncounterStepper::~G4DNAMoleculeEncounterStepper() = default;
void G4DNAMoleculeEncounterStepper::Prepare()
{
// DEBUG
// G4cout << "G4DNAMoleculeEncounterStepper::PrepareForAllProcessors" << G4endl;
G4VITTimeStepComputer::Prepare();
G4VITTimeStepComputer::Prepare();
#if defined (DEBUG_MEM)
MemStat mem_first, mem_second, mem_diff;
MemStat mem_first, mem_second, mem_diff;
#endif
#if defined (DEBUG_MEM)
mem_first = MemoryUsage();
mem_first = MemoryUsage();
#endif
G4MoleculeFinder::Instance()->UpdatePositionMap();
G4MoleculeFinder::Instance()->UpdatePositionMap();
#if defined (DEBUG_MEM)
mem_second = MemoryUsage();
mem_diff = mem_second-mem_first;
G4cout << "\t || MEM || G4DNAMoleculeEncounterStepper::Prepare || "
"After computing G4ITManager<G4Molecule>::Instance()->"
"UpdatePositionMap, diff is : " << mem_diff << G4endl;
mem_second = MemoryUsage();
mem_diff = mem_second - mem_first;
G4cout << "\t || MEM || G4DNAMoleculeEncounterStepper::Prepare || "
"After computing G4ITManager<G4Molecule>::Instance()->"
"UpdatePositionMap, diff is : " << mem_diff << G4endl;
#endif
}
void G4DNAMoleculeEncounterStepper::InitializeForNewTrack()
{
// if(fReactants) fReactants = 0 ;
if (fReactants) fReactants.reset();
fSampledMinTimeStep = DBL_MAX;
fHasAlreadyReachedNullTime = false;
if (fReactants)
{
fReactants.reset();
}
fSampledMinTimeStep = DBL_MAX;
fHasAlreadyReachedNullTime = false;
}
template<typename T>
inline bool IsInf(T value)
{
inline bool IsInf(T value)
{
return std::numeric_limits<T>::has_infinity
&& value == std::numeric_limits<T>::infinity();
}
}
G4double
G4DNAMoleculeEncounterStepper::CalculateStep(const G4Track& trackA,
const G4double& userMinTimeStep)
{
// DEBUG
// G4cout << "G4MoleculeEncounterStepper::CalculateStep, time :"
// << G4ITTrackHolder::Instance()->GetGlobalTime() << G4endl;
G4Molecule* moleculeA = GetMolecule(trackA);
InitializeForNewTrack();
fUserMinTimeStep = userMinTimeStep;
auto pMoleculeA = GetMolecule(trackA);
InitializeForNewTrack();
fUserMinTimeStep = userMinTimeStep;
#ifdef G4VERBOSE
if (fVerbose)
{
G4cout
<< "_______________________________________________________________________"
<< G4endl;
G4cout << "G4DNAMoleculeEncounterStepper::CalculateStep" << G4endl;
G4cout << "Check done for molecule : " << moleculeA->GetName()
<< " (" << trackA.GetTrackID() << ") "
<< G4endl;
}
#endif
//__________________________________________________________________
// Retrieve general informations for making reactions
G4MolecularConfiguration* molConfA = moleculeA->GetMolecularConfiguration();
const vector<G4MolecularConfiguration*>* reactivesVector = fMolecularReactionTable
->CanReactWith(molConfA);
if (!reactivesVector)
{
#ifdef G4VERBOSE
// DEBUG
if (fVerbose > 1)
{
G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
G4cout << "!!! WARNING" << G4endl;
G4cout << "G4MoleculeEncounterStepper::CalculateStep will return infinity "
"for the reaction because the molecule "
<< moleculeA->GetName()
<< " does not have any reactants given in the reaction table."
<< G4endl;
G4cout << "!!!!!!!!!!!!!!!!!!!!"<<G4endl;
}
#endif
return DBL_MAX;
}
G4int nbReactives = reactivesVector->size();
if (nbReactives == 0)
{
#ifdef G4VERBOSE
// DEBUG
if (fVerbose)
{
// TODO replace with the warning mode of G4Exception
G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
G4cout << "!!! WARNING" << G4endl;
G4cout << "G4MoleculeEncounterStepper::CalculateStep will return infinity "
"for the reaction because the molecule "
<< moleculeA->GetName()
<< " does not have any reactants given in the reaction table."
<< "This message can also result from a wrong implementation of the reaction table."
<< G4endl;
G4cout << "!!!!!!!!!!!!!!!!!!!!"<<G4endl;
G4cout
<< "_______________________________________________________________________"
<< G4endl;
G4cout << "G4DNAMoleculeEncounterStepper::CalculateStep" << G4endl;
G4cout << "Check done for molecule : " << pMoleculeA->GetName()
<< " (" << trackA.GetTrackID() << ") "
<< G4endl;
}
#endif
return DBL_MAX;
}
// DEBUG
// else
// {
// G4cout << "nb reactants : " << nbReactives << " pour mol "<< moleculeA -> GetName () << G4endl;
// for(int k=0 ; k < nbReactives ; k++)
// {
// G4cout << (*reactivesVector)[k]->GetName() << G4endl;
// }
// }
// fReactants = new vector<G4Track*>();
fReactants.reset(new vector<G4Track*>());
fReactionModel->Initialise(molConfA, trackA);
//__________________________________________________________________
// Retrieve general informations for making reactions
auto pMolConfA = pMoleculeA->GetMolecularConfiguration();
//__________________________________________________________________
// Start looping on possible reactants
for (G4int i = 0; i < nbReactives; i++)
{
G4MolecularConfiguration* moleculeB = (*reactivesVector)[i];
const auto pReactantList = fMolecularReactionTable->CanReactWith(pMolConfA);
//______________________________________________________________
// Retrieve reaction range
const G4double R = fReactionModel->GetReactionRadius(i);
//G4cout << "Reaction range = " << G4BestUnit(R, "Length") << G4endl;
//______________________________________________________________
// Use KdTree algorithm to find closest reactants
G4KDTreeResultHandle resultsNearest(
G4MoleculeFinder::Instance()->FindNearest(moleculeA,
moleculeB->GetMoleculeID()));
if (resultsNearest == 0) continue;
G4double r2 = resultsNearest->GetDistanceSqr();
Utils utils(trackA, moleculeB);
if (r2 <= R * R) // ==> Record in range
if (!pReactantList)
{
// Entering in this condition may due to the fact that molecules are very close
// to each other
// Therefore, if we only take the nearby reactant into account, it might have already
// reacted. Instead, we will take all possible reactants that satisfy the condition r<R
if (fHasAlreadyReachedNullTime == false)
{
fReactants->clear();
fHasAlreadyReachedNullTime = true;
}
fSampledMinTimeStep = 0.;
G4KDTreeResultHandle resultsInRange(
G4MoleculeFinder::Instance()->FindNearestInRange(moleculeA,
moleculeB->GetMoleculeID(),
R));
CheckAndRecordResults(utils,
#ifdef G4VERBOSE
R,
#endif
resultsInRange);
}
else
{
G4double r = sqrt(r2);
G4double tempMinET = pow(r - R, 2) / utils.Constant;
// constant = 16 * (DA + DB + 2*sqrt(DA*DB))
//G4cout << tempMinET << G4endl;
// G4cout << "fSampledMinTimeStep =" << fSampledMinTimeStep << G4endl;
// G4cout << "fUserMinTimeStep =" << fUserMinTimeStep
// << " isInf = "<< IsInf(fUserMinTimeStep) << G4endl;
if (tempMinET <= fSampledMinTimeStep)
{
if (fUserMinTimeStep < DBL_MAX/*IsInf(fUserMinTimeStep) == false*/
&& tempMinET <= fUserMinTimeStep) // ==> Record in range
// DEBUG
if (fVerbose > 1)
{
if(fSampledMinTimeStep > fUserMinTimeStep)
{
fReactants->clear();
}
fSampledMinTimeStep = fUserMinTimeStep;
G4double range = R + sqrt(fUserMinTimeStep*utils.Constant);
G4KDTreeResultHandle resultsInRange (
G4MoleculeFinder::Instance()->
FindNearestInRange(moleculeA,
moleculeB->GetMoleculeID(),
range));
CheckAndRecordResults(utils,
#ifdef G4VERBOSE
range,
#endif
resultsInRange);
G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
G4cout << "!!! WARNING" << G4endl;
G4cout << "G4MoleculeEncounterStepper::CalculateStep will return infinity "
"for the reaction because the molecule "
<< pMoleculeA->GetName()
<< " does not have any reactants given in the reaction table."
<< G4endl;
G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
}
else // ==> Record nearest
{
if(tempMinET < fSampledMinTimeStep)
// to avoid cases where fSampledMinTimeStep == tempMinET
{
fSampledMinTimeStep = tempMinET;
fReactants->clear();
}
CheckAndRecordResults(utils,
#ifdef G4VERBOSE
R,
#endif
resultsNearest);
}
}
return DBL_MAX;
}
// DEBUG
// if(bool(fReactants))
// {
// G4cout << "Potential reactions :" << G4endl;
// G4cout << GetMolecule(trackA)->GetName()
// << " ("<< trackA.GetTrackID()<< ") " << " + ..." << G4endl;
// //<< " | " << trackB->GetTrackID() << G4endl;
//
// for(int j = 0 ; j < (int) fReactants->size() ; j++)
// {
// G4cout << GetMolecule(fReactants->at(j) )->GetName()
// <<" ("<< fReactants->at(j)->GetTrackID() << ")" << G4endl;
// }
// }
G4int nbReactives = pReactantList->size();
}
#ifdef G4VERBOSE
// DEBUG
if (fVerbose)
{
G4cout << "G4MoleculeEncounterStepper::CalculateStep will finally return :"
<< G4BestUnit(fSampledMinTimeStep, "Time") << G4endl;
if(fVerbose > 1)
if (nbReactives == 0)
{
G4cout << "Selected reactants for trackA: " << moleculeA->GetName()
<< " (" << trackA.GetTrackID() << ") are: ";
vector<G4Track*>::iterator it;
for(it = fReactants->begin(); it != fReactants->end(); it++)
{
G4Track* trackB = *it;
G4cout << GetMolecule(trackB)->GetName() << " ("
<< trackB->GetTrackID() << ") \t ";
}
G4cout << G4endl;
}
}
#ifdef G4VERBOSE
// DEBUG
if (fVerbose)
{
// TODO replace with the warning mode of G4Exception
G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
G4cout << "!!! WARNING" << G4endl;
G4cout << "G4MoleculeEncounterStepper::CalculateStep will return infinity "
"for the reaction because the molecule "
<< pMoleculeA->GetName()
<< " does not have any reactants given in the reaction table."
<< "This message can also result from a wrong implementation of the reaction table."
<< G4endl;
G4cout << "!!!!!!!!!!!!!!!!!!!!" << G4endl;
}
#endif
return fSampledMinTimeStep;
return DBL_MAX;
}
fReactants.reset(new vector<G4Track*>());
fReactionModel->Initialise(pMolConfA, trackA);
//__________________________________________________________________
// Start looping on possible reactants
for (G4int i = 0; i < nbReactives; i++)
{
auto pMoleculeB = (*pReactantList)[i];
//______________________________________________________________
// Retrieve reaction range
const G4double R = fReactionModel->GetReactionRadius(i);
//______________________________________________________________
// Use KdTree algorithm to find closest reactants
G4KDTreeResultHandle resultsNearest(
G4MoleculeFinder::Instance()->FindNearest(pMoleculeA,
pMoleculeB->GetMoleculeID()));
if (resultsNearest == 0) continue;
G4double r2 = resultsNearest->GetDistanceSqr();
Utils utils(trackA, pMoleculeB);
if (r2 <= R * R) // ==> Record in range
{
// Entering in this condition may due to the fact that molecules are very close
// to each other
// Therefore, if we only take the nearby reactant into account, it might have already
// reacted. Instead, we will take all possible reactants that satisfy the condition r<R
if (fHasAlreadyReachedNullTime == false)
{
fReactants->clear();
fHasAlreadyReachedNullTime = true;
}
fSampledMinTimeStep = 0.;
G4KDTreeResultHandle resultsInRange(
G4MoleculeFinder::Instance()->FindNearestInRange(pMoleculeA,
pMoleculeB->GetMoleculeID(),
R));
CheckAndRecordResults(utils,
#ifdef G4VERBOSE
R,
#endif
resultsInRange);
}
else
{
G4double r = sqrt(r2);
G4double tempMinET = pow(r - R, 2) / utils.fConstant;
// constant = 16 * (fDA + fDB + 2*sqrt(fDA*fDB))
if (tempMinET <= fSampledMinTimeStep)
{
if (fUserMinTimeStep < DBL_MAX/*IsInf(fUserMinTimeStep) == false*/
&& tempMinET <= fUserMinTimeStep) // ==> Record in range
{
if (fSampledMinTimeStep > fUserMinTimeStep)
{
fReactants->clear();
}
fSampledMinTimeStep = fUserMinTimeStep;
G4double range = R + sqrt(fUserMinTimeStep*utils.fConstant);
G4KDTreeResultHandle resultsInRange(
G4MoleculeFinder::Instance()->
FindNearestInRange(pMoleculeA,
pMoleculeB->GetMoleculeID(),
range));
CheckAndRecordResults(utils,
#ifdef G4VERBOSE
range,
#endif
resultsInRange);
}
else // ==> Record nearest
{
if (tempMinET < fSampledMinTimeStep)
// to avoid cases where fSampledMinTimeStep == tempMinET
{
fSampledMinTimeStep = tempMinET;
fReactants->clear();
}
CheckAndRecordResults(utils,
#ifdef G4VERBOSE
R,
#endif
resultsNearest);
}
}
}
}
#ifdef G4VERBOSE
if (fVerbose)
{
G4cout << "G4MoleculeEncounterStepper::CalculateStep will finally return :"
<< G4BestUnit(fSampledMinTimeStep, "Time") << G4endl;
if (fVerbose > 1)
{
G4cout << "Selected reactants for trackA: " << pMoleculeA->GetName()
<< " (" << trackA.GetTrackID() << ") are: ";
vector<G4Track*>::iterator it;
for (it = fReactants->begin(); it != fReactants->end(); it++)
{
G4Track* trackB = *it;
G4cout << GetMolecule(trackB)->GetName() << " ("
<< trackB->GetTrackID() << ") \t ";
}
G4cout << G4endl;
}
}
#endif
return fSampledMinTimeStep;
}
void G4DNAMoleculeEncounterStepper::CheckAndRecordResults(const Utils& utils,
@@ -376,128 +314,122 @@ void G4DNAMoleculeEncounterStepper::CheckAndRecordResults(const Utils& utils,
#endif
G4KDTreeResultHandle& results)
{
if (results == 0)
{
if (results == 0)
{
#ifdef G4VERBOSE
// DEBUG
if (fVerbose > 1)
{
G4cout << "No molecule " << utils.moleculeB->GetName()
<< " found to react with " << utils.moleculeA->GetName()
<< G4endl;
}
if (fVerbose > 1)
{
G4cout << "No molecule " << utils.fpMoleculeB->GetName()
<< " found to react with " << utils.fpMoleculeA->GetName()
<< G4endl;
}
#endif
return;
}
for (results->Rewind(); !results->End(); results->Next())
{
G4IT* reactiveB = results->GetItem<G4IT>();
if (reactiveB == 0)
{
// DEBUG
// G4cout<<"Continue 1"<<G4endl;
continue;
return;
}
G4Track *trackB = reactiveB->GetTrack();
if (trackB == 0)
for (results->Rewind(); !results->End(); results->Next())
{
G4ExceptionDescription exceptionDescription;
exceptionDescription
<<"The reactant B found using the MoleculeFinder does not have a valid "
"track attached to it. If this is done on purpose, please do "
"not record this molecule in the MoleculeFinder."
<< G4endl;
G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
"MoleculeEncounterStepper001", FatalErrorInArgument,
exceptionDescription);
continue;
}
G4IT* reactiveB = results->GetItem<G4IT>();
if (trackB->GetTrackStatus() != fAlive)
{
// G4ExceptionDescription exceptionDescription;
// exceptionDescription
// << "The track status of one of the nearby reactants is not fAlive"
// << G4endl;
// exceptionDescription << "The incomming trackID "
// << "(trackA entering in G4DNAMoleculeEncounterStepper and "
// << "for which you are looking reactant for) is : "
// << utils.trackA.GetTrackID() << "("
// << GetMolecule(utils.trackA)->GetName() << ")" << G4endl;
// exceptionDescription << "And the trackID of the reactant (trackB) is: "
// << trackB->GetTrackID() << "(" << GetMolecule(trackB)->GetName()
// << ")" << G4endl;
// G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
// "MoleculeEncounterStepper002", FatalErrorInArgument,
// exceptionDescription);
continue;
}
if (reactiveB == 0)
{
continue;
}
if (trackB == &utils.trackA)
{
// DEBUG
G4ExceptionDescription exceptionDescription;
exceptionDescription
<< "A track is reacting with itself (which is impossible) ie trackA == trackB"
<< G4endl;
exceptionDescription << "Molecule A (and B) is of type : "
<< utils.moleculeA->GetName() << " with trackID : "
<< utils.trackA.GetTrackID() << G4endl;
G4Track *trackB = reactiveB->GetTrack();
G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
"MoleculeEncounterStepper003", FatalErrorInArgument,
exceptionDescription);
if (trackB == 0)
{
G4ExceptionDescription exceptionDescription;
exceptionDescription
<< "The reactant B found using the MoleculeFinder does not have a valid "
"track attached to it. If this is done on purpose, please do "
"not record this molecule in the MoleculeFinder."
<< G4endl;
G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
"MoleculeEncounterStepper001", FatalErrorInArgument,
exceptionDescription);
continue;
}
}
if (trackB->GetTrackStatus() != fAlive)
{
continue;
}
if (fabs(trackB->GetGlobalTime() - utils.trackA.GetGlobalTime())
> utils.trackA.GetGlobalTime() * (1 - 1 / 100))
{
// DEBUG
G4ExceptionDescription exceptionDescription;
exceptionDescription
<< "The interacting tracks are not synchronized in time" << G4endl;
exceptionDescription
<< "trackB->GetGlobalTime() != trackA.GetGlobalTime()" << G4endl;
if (trackB == &utils.fpTrackA)
{
G4ExceptionDescription exceptionDescription;
exceptionDescription
<< "A track is reacting with itself (which is impossible) ie fpTrackA == trackB"
<< G4endl;
exceptionDescription << "Molecule A (and B) is of type : "
<< utils.fpMoleculeA->GetName() << " with trackID : "
<< utils.fpTrackA.GetTrackID() << G4endl;
exceptionDescription << "trackA : trackID : " << utils.trackA.GetTrackID()
<< "\t Name :" << utils.moleculeA->GetName()
<< "\t trackA->GetGlobalTime() = "
<< G4BestUnit(utils.trackA.GetGlobalTime(), "Time") << G4endl;
G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
"MoleculeEncounterStepper003", FatalErrorInArgument,
exceptionDescription);
exceptionDescription << "trackB : trackID : " << trackB->GetTrackID()
<< "\t Name :" << utils.moleculeB->GetName()
<< "\t trackB->GetGlobalTime() = "
<< G4BestUnit(trackB->GetGlobalTime(), "Time") << G4endl;
}
G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
"MoleculeEncounterStepper004", FatalErrorInArgument,
exceptionDescription);
}
if (fabs(trackB->GetGlobalTime() - utils.fpTrackA.GetGlobalTime())
> utils.fpTrackA.GetGlobalTime() * (1 - 1 / 100))
{
// DEBUG
G4ExceptionDescription exceptionDescription;
exceptionDescription
<< "The interacting tracks are not synchronized in time" << G4endl;
exceptionDescription
<< "trackB->GetGlobalTime() != fpTrackA.GetGlobalTime()" << G4endl;
exceptionDescription << "fpTrackA : trackID : " << utils.fpTrackA.GetTrackID()
<< "\t Name :" << utils.fpMoleculeA->GetName()
<< "\t fpTrackA->GetGlobalTime() = "
<< G4BestUnit(utils.fpTrackA.GetGlobalTime(), "Time") << G4endl;
exceptionDescription << "trackB : trackID : " << trackB->GetTrackID()
<< "\t Name :" << utils.fpMoleculeB->GetName()
<< "\t trackB->GetGlobalTime() = "
<< G4BestUnit(trackB->GetGlobalTime(), "Time") << G4endl;
G4Exception("G4DNAMoleculeEncounterStepper::RetrieveResults",
"MoleculeEncounterStepper004", FatalErrorInArgument,
exceptionDescription);
}
#ifdef G4VERBOSE
if(fVerbose > 1)
{
G4double r2 = results->GetDistanceSqr();
G4cout << "\t ************************************************** " << G4endl;
G4cout <<"\t Reaction between "
<< utils.moleculeA->GetName() << " (" << utils.trackA.GetTrackID() << ") "
<< " & " << utils.moleculeB->GetName() << " (" << trackB->GetTrackID() << "), "
<< "Interaction Range = "
<< G4BestUnit(R, "Length")<<G4endl;
G4cout <<"\t Real distance between reactants = "
<< G4BestUnit((utils.trackA.GetPosition() - trackB->GetPosition()).mag(), "Length")<<G4endl;
G4cout <<"\t Distance between reactants calculated by nearest neighbor algorithm = "
<< G4BestUnit(sqrt(r2), "Length")<<G4endl;
// G4cout << " ***** " << G4endl;
}
if (fVerbose > 1)
{
G4double r2 = results->GetDistanceSqr();
G4cout << "\t ************************************************** " << G4endl;
G4cout << "\t Reaction between "
<< utils.fpMoleculeA->GetName() << " (" << utils.fpTrackA.GetTrackID() << ") "
<< " & " << utils.fpMoleculeB->GetName() << " (" << trackB->GetTrackID() << "), "
<< "Interaction Range = "
<< G4BestUnit(R, "Length") << G4endl;
G4cout << "\t Real distance between reactants = "
<< G4BestUnit((utils.fpTrackA.GetPosition() - trackB->GetPosition()).mag(), "Length") << G4endl;
G4cout << "\t Distance between reactants calculated by nearest neighbor algorithm = "
<< G4BestUnit(sqrt(r2), "Length") << G4endl;
}
#endif
fReactants->push_back(trackB);
}
fReactants->push_back(trackB);
}
}
void G4DNAMoleculeEncounterStepper::SetReactionModel(G4VDNAReactionModel* pReactionModel)
{
fReactionModel = pReactionModel;
}
G4VDNAReactionModel* G4DNAMoleculeEncounterStepper::GetReactionModel()
{
return fReactionModel;
}
void G4DNAMoleculeEncounterStepper::SetVerbose(int flag)
{
fVerbose = flag;
}
@@ -30,155 +30,108 @@
#include "G4DNAMolecularReactionTable.hh"
#include "G4UnitsTable.hh"
#include "G4Molecule.hh"
//#include "G4Scheduler.hh"
#include "G4Exp.hh"
G4DNASmoluchowskiReactionModel::G4DNASmoluchowskiReactionModel() :
G4VDNAReactionModel()
G4DNASmoluchowskiReactionModel::G4DNASmoluchowskiReactionModel()
: G4VDNAReactionModel()
, fpReactionData(nullptr)
{
fReactionData = 0;
}
G4DNASmoluchowskiReactionModel::G4DNASmoluchowskiReactionModel(const G4DNASmoluchowskiReactionModel& __right) :
G4VDNAReactionModel(__right)
{
fReactionData = 0;
}
G4DNASmoluchowskiReactionModel::~G4DNASmoluchowskiReactionModel() = default;
G4DNASmoluchowskiReactionModel& G4DNASmoluchowskiReactionModel::operator=(const G4DNASmoluchowskiReactionModel& right)
{
if (this == &right) return *this;
fReactionData = 0;
return *this;
}
G4DNASmoluchowskiReactionModel::~G4DNASmoluchowskiReactionModel()
{
fReactionData = 0;
}
void G4DNASmoluchowskiReactionModel::Initialise(G4MolecularConfiguration* __molecule,
void G4DNASmoluchowskiReactionModel::Initialise(const G4MolecularConfiguration* pMolecule,
const G4Track&)
{
fReactionData = fReactionTable->GetReactionData(__molecule);
fpReactionData = fpReactionTable->GetReactionData(pMolecule);
}
void
G4DNASmoluchowskiReactionModel::
InitialiseToPrint(G4MolecularConfiguration* __molecule)
void G4DNASmoluchowskiReactionModel::InitialiseToPrint(const G4MolecularConfiguration* pMolecule)
{
fReactionData = fReactionTable->GetReactionData(__molecule);
fpReactionData = fpReactionTable->GetReactionData(pMolecule);
}
G4double
G4DNASmoluchowskiReactionModel::GetReactionRadius(G4MolecularConfiguration* __mol1,
G4MolecularConfiguration* __mol2)
G4double G4DNASmoluchowskiReactionModel::GetReactionRadius(const G4MolecularConfiguration* pMol1,
const G4MolecularConfiguration* pMol2)
{
G4double __output = fReactionTable->GetReactionData(__mol1, __mol2)
->GetEffectiveReactionRadius();
return __output;
G4double __output = fpReactionTable->GetReactionData(pMol1, pMol2)->GetEffectiveReactionRadius();
return __output;
}
G4double G4DNASmoluchowskiReactionModel::GetReactionRadius(const G4int __i)
{
G4double __output = (*fReactionData)[__i]->GetEffectiveReactionRadius();
return __output;
G4double __output = (*fpReactionData)[__i]->GetEffectiveReactionRadius();
return __output;
}
G4bool G4DNASmoluchowskiReactionModel::FindReaction(const G4Track& __trackA,
const G4Track& __trackB,
const G4double __R,
G4double& __r,
const G4double __reactionRadius,
G4double& __separationDistance,
const G4bool __alongStepReaction)
{
G4double postStepSeparation = 0;
bool do_break = false;
G4double R2 = __R * __R;
int k = 0;
const G4double R2 = __reactionRadius * __reactionRadius;
G4double postStepSeparation = 0.;
bool do_break = false;
int k = 0;
for (; k < 3; k++)
{
postStepSeparation += std::pow(
__trackA.GetPosition()[k] - __trackB.GetPosition()[k], 2);
if (postStepSeparation > R2)
for (; k < 3; ++k)
{
do_break = true;
break;
}
}
postStepSeparation += std::pow(
__trackA.GetPosition()[k] - __trackB.GetPosition()[k], 2);
if (do_break == false)
{
// The loop was not break
// => __r^2 < __R^2
__r = std::sqrt(postStepSeparation);
return true;
}
else if (__alongStepReaction == true)
{
//G4cout << "alongStepReaction==true" << G4endl;
//Along step cheack and
// the loop has break
// Continue loop
for (; k < 3; k++)
{
postStepSeparation += std::pow(
__trackA.GetPosition()[k] - __trackB.GetPosition()[k], 2);
}
// Use Green approach : the Brownian bridge
__r = (postStepSeparation = std::sqrt(postStepSeparation));
G4Molecule* __moleculeA = GetMolecule(__trackA);
G4Molecule* __moleculeB = GetMolecule(__trackB);
G4double __D = __moleculeA->GetDiffusionCoefficient()
+ __moleculeB->GetDiffusionCoefficient();
G4ThreeVector __preStepPositionA = __trackA.GetStep()->GetPreStepPoint()
->GetPosition();
G4ThreeVector __preStepPositionB = __trackB.GetStep()->GetPreStepPoint()
->GetPosition();
if (__preStepPositionA == __trackA.GetPosition())
{
G4ExceptionDescription exceptionDescription;
exceptionDescription << "The molecule : " << __moleculeA->GetName();
exceptionDescription << " with track ID :" << __trackA.GetTrackID();
exceptionDescription << " did not move since the previous step." << G4endl;
exceptionDescription << "Current position : "
<< G4BestUnit(__trackA.GetPosition(), "Length")
<< G4endl;
exceptionDescription << "Previous position : "
<< G4BestUnit(__preStepPositionA, "Length") << G4endl;
G4Exception("G4DNASmoluchowskiReactionModel::FindReaction",
"G4DNASmoluchowskiReactionModel", FatalErrorInArgument,
exceptionDescription);
if (postStepSeparation > R2)
{
do_break = true;
break;
}
}
G4double __preStepSeparation =
(__preStepPositionA - __preStepPositionB).mag();
if (do_break == false)
{
// The loop was not break
// => r^2 < R^2
__separationDistance = std::sqrt(postStepSeparation);
return true;
}
else if (__alongStepReaction == true)
{
//Along step check and the loop has break
//===================================
// Brownian bridge
// Continue loop
for (; k < 3; ++k)
{
postStepSeparation += std::pow(
__trackA.GetPosition()[k] - __trackB.GetPosition()[k], 2);
}
// Use Green approach : the Brownian bridge
__separationDistance = (postStepSeparation = std::sqrt(postStepSeparation));
auto pMoleculeA = GetMolecule(__trackA);
auto pMoleculeB = GetMolecule(__trackB);
// if(G4Scheduler::Instance()->GetTimeStep() != __trackB.GetStep()->GetDeltaTime())
// {
// G4cout << G4Scheduler::Instance()->GetTimeStep() << G4endl;
// G4cout << __trackB.GetStep()->GetDeltaTime() << G4endl;
// assert(G4Scheduler::Instance()->GetTimeStep() == __trackB.GetStep()->GetDeltaTime());
// }
G4double D = pMoleculeA->GetDiffusionCoefficient()
+ pMoleculeB->GetDiffusionCoefficient();
G4double __probabiltyOfEncounter = G4Exp(
-(__preStepSeparation - __R) * (postStepSeparation - __R) / (__D
* (__trackB.GetStep()->GetDeltaTime())));
G4double __selectedPOE = G4UniformRand();
const auto& preStepPositionA = __trackA.GetStep()->GetPreStepPoint()->GetPosition();
const auto& preStepPositionB = __trackB.GetStep()->GetPreStepPoint()->GetPosition();
if (__selectedPOE <= __probabiltyOfEncounter) return true;
//===================================
}
G4double preStepSeparation = (preStepPositionA - preStepPositionB).mag();
return false;
//===================================
// Brownian bridge
G4double __probabiltyOfEncounter = G4Exp(-(preStepSeparation - __reactionRadius)
* (postStepSeparation - __reactionRadius)
/ (D * (__trackB.GetStep()->GetDeltaTime()))
);
G4double __selectedPOE = G4UniformRand();
if (__selectedPOE <= __probabiltyOfEncounter)
{
return true;
}
//===================================
}
return false;
}