64#define State(theXInfo) (GetState<G4ITBrownianState>()->theXInfo)
74#define RED "\033[0;31m"
75#define LIGHT_RED "\33[1;31m"
76#define GREEN "\033[32;40m"
77#define GREEN_ON_BLUE "\033[1;32;44m"
78#define RESET_COLOR "\033[0m"
83#define GREEN_ON_BLUE ""
95static double InvErf(
double x)
100static double InvErfc(
double x)
110static double Erfc(
double x)
116#define State(theXInfo) (GetState<G4ITTransportationState>()->theXInfo)
164 if(
this == &rhs)
return *
this;
205 const double timeStep,
221 if(
GetIT(track)->GetTrackingInfo()->IsLeadingStep())
225 bool makeException =
true;
233 exceptionDescription <<
"ComputeStep is called while the track has"
234 "the minimum interaction time";
235 exceptionDescription <<
" so it should not recompute a timeStep ";
236 G4Exception(
"G4DNABrownianTransportation::ComputeStep",
238 exceptionDescription);
242 State(fGeometryLimitedStep) =
false;
254 static double sqrt_2 = sqrt(2.);
255 double sqrt_Dt = sqrt(diffCoeff*timeStep);
256 double sqrt_2Dt = sqrt_2*sqrt_Dt;
258 if(
State(fTimeStepReachedLimit)==
true)
261 State(fGeometryLimitedStep) =
true;
263 spaceStep =
State(fEndPointDistance);
268 G4double x = G4RandGauss::shoot(0,sqrt_2Dt);
269 G4double y = G4RandGauss::shoot(0,sqrt_2Dt);
270 G4double z = G4RandGauss::shoot(0,sqrt_2Dt);
272 spaceStep = sqrt(x*x + y*y + z*z);
274 if(spaceStep >=
State(fEndPointDistance))
278 State(fGeometryLimitedStep) =
true;
293 <<
"G4ITBrownianTransportation::ComputeStep() : "
294 <<
"Step was limited to boundary"
300 if(
State(fRandomNumber)>=0)
320 double invErfc = InvErfc(value);
321 spaceStep = invErfc*2*sqrt_Dt;
323 if(
State(fTimeStepReachedLimit)==
false)
326 State(fGeometryLimitedStep) =
false;
347 double min_randomNumber = Erfc(
State(fEndPointDistance)/2*sqrt_Dt);
348 double value = min_randomNumber+(1-min_randomNumber)*
G4UniformRand();
349 double invErfc = InvErfc(value);
350 spaceStep = invErfc*2*sqrt_Dt;
351 if(spaceStep >=
State(fEndPointDistance))
354 State(fGeometryLimitedStep) =
true;
357 else if(
State(fTimeStepReachedLimit)==
false)
360 State(fGeometryLimitedStep) =
false;
367 State(fGeometryLimitedStep) =
true;
369 spaceStep =
State(fEndPointDistance);
386 State(fTransportEndPosition)= spaceStep*
394 State(fGeometryLimitedStep) =
false;
405 State(fGeometryLimitedStep) =
false;
410 State(fEndGlobalTimeComputed) =
true;
417 <<
"G4ITBrownianTransportation::ComputeStep() : "
418 <<
" trackID : " << track.
GetTrackID() <<
" : Molecule name: "
423 <<
"Final position:" <<
G4BestUnit(
State(fTransportEndPosition),
"Length")
427 <<
"Final magnitude:" <<
G4BestUnit(
State(fTransportEndPosition).mag(),
"Length")
429 <<
"Diffusion length : "
431 <<
" within time step : " <<
G4BestUnit(timeStep,
"Time")
433 <<
"State(fTimeStepReachedLimit)= " <<
State(fTimeStepReachedLimit) <<
G4endl
434 <<
"State(fGeometryLimitedStep)=" <<
State(fGeometryLimitedStep) <<
G4endl
435 <<
"End point distance was: " <<
G4BestUnit(
State(fEndPointDistance),
"Length")
460 <<
" trackID : " << track.
GetTrackID() <<
" Molecule name: "
462 G4cout <<
"Diffusion length : "
465 <<
"\t Current global time : "
478 MemStat mem_first = MemoryUsage();
486 <<
"G4DNABrownianTransportation::Diffusion :" << setw(8)
488 <<
"\t" <<
" Global Time = "
509 if (waterDensity == 0.0)
523 G4cout <<
"A track is outside water material : trackID = "
539 MemStat mem_intermediaire = MemoryUsage();
540 mem_diff = mem_intermediaire-mem_first;
541 G4cout <<
"\t\t\t >> || MEM || In G4DNABrownianTransportation::Diffusion "
542 "after dealing with waterDensity for "<< track.
GetTrackID()
543 <<
", diff is : " << mem_diff <<
G4endl;
547 State(fMomentumChanged) =
true;
551 mem_intermediaire = MemoryUsage();
552 mem_diff = mem_intermediaire-mem_first;
553 G4cout <<
"\t\t\t >> || MEM || In G4DNABrownianTransportation::"
554 "After proposing new direction to fParticleChange for "
590 G4cout <<
" G4DNABrownianTransportation::AlongStepGetPhysicalInteractionLength - track ID: "
599 track, previousStepSize, currentMinimumStep, currentSafety,
602 if(geometryStepLength==0)
605 if(
State(fGeometryLimitedStep))
611 State(fCurrentTouchableHandle)->GetHistory());
623 State(fCurrentTouchableHandle) = newTouchable;
638 track, previousStepSize, currentMinimumStep, currentSafety,
683 if(diffusionCoefficient <= 0)
685 State(fGeometryLimitedStep) =
false;
692 State(fComputeLastPosition) =
false;
693 State(fTimeStepReachedLimit) =
false;
695 if (
State(fGeometryLimitedStep))
705 State(theInteractionTimeLeft) = (geometryStepLength * geometryStepLength)
706 / (diffusionCoefficient);
710 State(theInteractionTimeLeft) = (currentSafety * currentSafety)
711 / (diffusionCoefficient);
718 State(fComputeLastPosition) =
true;
725 State(theInteractionTimeLeft) = 1 / (4 * diffusionCoefficient)
726 * pow(geometryStepLength / InvErfc(
State(fRandomNumber)),2);
728 State(fTransportEndPosition) = geometryStepLength*
740 if (
State(theInteractionTimeLeft) < minTimeStepAllowed)
742 State(theInteractionTimeLeft) = minTimeStepAllowed;
743 State(fTimeStepReachedLimit) =
true;
744 State(fComputeLastPosition) =
true;
750 State(fTimeStepReachedLimit) =
true;
754 State(fComputeLastPosition) =
true;
758 State(fCandidateEndGlobalTime) =
761 State(fEndGlobalTimeComputed) =
true;
763 State(fPathLengthWasCorrected) =
false;
768 geometryStepLength = 2
769 * sqrt(diffusionCoefficient *
State(theInteractionTimeLeft))
771 State(fPathLengthWasCorrected) =
true;
773 State(fTransportEndPosition) = geometryStepLength*
782 <<
"G4DNABrownianTransportation::AlongStepGetPhysicalInteractionLength = "
794 return geometryStepLength;
806 MemStat mem_first, mem_second, mem_diff;
810 mem_first = MemoryUsage();
813 if (
GetIT(track)->GetTrackingInfo()->IsLeadingStep()
814 &&
State(fComputeLastPosition))
827 spaceStep =
State(fEndPointDistance);
828 State(fGeometryLimitedStep) =
true;
833 GetDiffusionCoefficient();
835 double sqrt_2Dt= sqrt(2 * diffusionCoefficient *
State(theInteractionTimeLeft));
836 G4double x = G4RandGauss::shoot(0, sqrt_2Dt);
837 G4double y = G4RandGauss::shoot(0, sqrt_2Dt);
838 G4double z = G4RandGauss::shoot(0, sqrt_2Dt);
840 spaceStep = sqrt(x * x + y * y + z * z);
842 if(spaceStep >=
State(fEndPointDistance))
844 State(fGeometryLimitedStep) =
true;
848 && spaceStep >=
State(fEndPointDistance))
850 spaceStep =
State(fEndPointDistance);
855 State(fGeometryLimitedStep) =
false;
871 <<
"G4DNABrownianTransportation::AlongStepDoIt: "
872 "GeometryLimitedStep = "
873 <<
State(fGeometryLimitedStep)
886 MemStat mem_intermediaire = MemoryUsage();
887 mem_diff = mem_intermediaire-mem_first;
888 G4cout <<
"\t\t\t >> || MEM || After calling G4ITTransportation::"
889 "AlongStepDoIt for "<< track.
GetTrackID() <<
", diff is : "
937 mem_intermediaire = MemoryUsage();
938 mem_diff = mem_intermediaire-mem_first;
939 G4cout <<
"\t\t\t >> || MEM || After calling G4DNABrownianTransportation::"
940 "Diffusion for "<< track.
GetTrackID() <<
", diff is : "
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4IT * GetIT(const G4Track *track)
G4Molecule * GetMolecule(const G4Track &track)
G4ThreeVector G4RandomDirection()
G4GLOB_DLL std::ostream G4cout
static double erf(double x)
static double inverseErf(double t)
virtual void Transport(const G4Track &, G4ParticleChangeForTransport &)=0
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &)
G4BrownianAction * fpBrownianAction
G4DNABrownianTransportation & operator=(const G4DNABrownianTransportation &)
void Diffusion(const G4Track &track)
G4bool fUseSchedulerMinTimeSteps
G4DNABrownianTransportation(const G4String &aName="DNABrownianTransportation", G4int verbosityLevel=0)
const std::vector< G4double > * fpWaterDensity
virtual void ComputeStep(const G4Track &, const G4Step &, const double, double &)
G4double ComputeGeomLimit(const G4Track &track, G4double &presafety, G4double limit)
virtual void StartTracking(G4Track *aTrack)
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *)
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &)
G4double fInternalMinTimeStep
G4bool fUseMaximumTimeBeforeReachingBoundary
virtual ~G4DNABrownianTransportation()
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
static G4DNAMolecularMaterial * Instance()
G4VPhysicalVolume * GetWorldVolume()
G4double CheckNextStep(const G4ThreeVector &position, const G4ThreeVector &direction, const G4double currentMaxStep, G4double &newSafety)
G4ParticleChangeForTransport fParticleChange
virtual void BuildPhysicsTable(const G4ParticleDefinition &)
void SetInstantiateProcessState(G4bool flag)
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData)
virtual G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double, G4double currentMinimumStep, G4double ¤tSafety, G4GPILSelection *selection)
G4ITSafetyHelper * fpSafetyHelper
G4ITNavigator * fLinearNavigator
virtual G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &)
virtual void StartTracking(G4Track *aTrack)
G4TrackingInformation * GetTrackingInfo()
virtual const G4String & GetName() const =0
G4double GetTemperature() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
const G4String & GetName() const
G4double GetDiffusionCoefficient() const
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
static G4NistManager * Instance()
void SetMomentumChanged(G4bool b)
void ProposeEnergy(G4double finalEnergy)
void ProposeMomentumDirection(G4double Px, G4double Py, G4double Pz)
const G4String & GetParticleName() const
G4double GetGlobalTime() const
const G4VProcess * GetProcessDefinedStep() const
const G4ThreeVector & GetPosition() const
G4double GetDeltaTime() const
G4StepPoint * GetPreStepPoint() const
G4double GetStepLength() const
G4StepPoint * GetPostStepPoint() const
virtual void LoadTrackState(G4TrackStateManager &manager)
virtual void ResetTrackState()
G4VPhysicalVolume * GetVolume() const
const G4ThreeVector & GetPosition() const
G4double GetGlobalTime() const
G4int GetCurrentStepNumber() const
G4Material * GetMaterial() const
const G4ThreeVector & GetMomentumDirection() const
G4double GetStepLength() const
const G4Step * GetStep() const
G4bool ProposesTimeStep() const
G4shared_ptr< G4ProcessState > fpState
void ProposeTrackStatus(G4TrackStatus status)
const G4String & GetName() const
void SetProcessSubType(G4int)
G4int GetProcessSubType() const
const G4String & GetProcessName() const
static G4VScheduler * Instance()
virtual double GetLimitingTimeStep() const
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
virtual void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=nullptr)
G4bool fTimeStepReachedLimit
G4bool fPathLengthWasCorrected
G4bool fComputeLastPosition