67#define State(theXInfo) (GetState<G4ITBrownianState>()->theXInfo)
77#define RED "\033[0;31m"
78#define LIGHT_RED "\33[1;31m"
79#define GREEN "\033[32;40m"
80#define GREEN_ON_BLUE "\033[1;32;44m"
81#define RESET_COLOR "\033[0m"
86#define GREEN_ON_BLUE ""
119#define State(theXInfo) (GetState<G4ITTransportationState>()->theXInfo)
129 fpState = std::make_shared<G4ITBrownianState>();
161 fpState = std::make_shared<G4ITBrownianState>();
202 if(
GetIT(track)->GetTrackingInfo()->IsLeadingStep())
206 G4bool makeException =
true;
208 if((ITProc !=
nullptr) && ITProc->
ProposesTimeStep()) makeException =
false;
214 exceptionDescription <<
"ComputeStep is called while the track has"
215 "the minimum interaction time";
216 exceptionDescription <<
" so it should not recompute a timeStep ";
217 G4Exception(
"G4DNABrownianTransportation::ComputeStep",
219 exceptionDescription);
223 State(fGeometryLimitedStep) =
false;
236 G4double sqrt_Dt = sqrt(diffCoeff*timeStep);
238 G4double x = G4RandGauss::shoot(0,sqrt_2Dt);
239 G4double y = G4RandGauss::shoot(0,sqrt_2Dt);
240 G4double z = G4RandGauss::shoot(0,sqrt_2Dt);
242 if(
State(fTimeStepReachedLimit)== 1)
245 State(fGeometryLimitedStep) =
true;
247 spaceStep =
State(fEndPointDistance);
252 spaceStep = sqrt(x*x + y*y + z*z);
254 if(spaceStep >=
State(fEndPointDistance))
258 State(fGeometryLimitedStep) =
true;
273 <<
"G4ITBrownianTransportation::ComputeStep() : "
274 <<
"Step was limited to boundary"
280 if(
State(fRandomNumber)>=0)
301 spaceStep = invErfc*2*sqrt_Dt;
303 if(
State(fTimeStepReachedLimit)== 0)
306 State(fGeometryLimitedStep) =
false;
327 G4double min_randomNumber = Erfc(
State(fEndPointDistance)/2*sqrt_Dt);
330 spaceStep = invErfc*2*sqrt_Dt;
331 if(spaceStep >=
State(fEndPointDistance))
334 State(fGeometryLimitedStep) =
true;
337 else if(
State(fTimeStepReachedLimit)== 0)
340 State(fGeometryLimitedStep) =
false;
347 State(fGeometryLimitedStep) =
true;
349 spaceStep =
State(fEndPointDistance);
366 State(fTransportEndPosition)= spaceStep*
374 State(fGeometryLimitedStep) =
false;
387 State(fTransportEndPosition) = nextPosition;
394 State(fGeometryLimitedStep) =
false;
399 State(fEndGlobalTimeComputed) =
true;
406 <<
"G4ITBrownianTransportation::ComputeStep() : "
407 <<
" trackID : " << track.
GetTrackID() <<
" : Molecule name: "
412 <<
"Final position:" <<
G4BestUnit(
State(fTransportEndPosition),
"Length")
416 <<
"Final magnitude:" <<
G4BestUnit(
State(fTransportEndPosition).mag(),
"Length")
418 <<
"Diffusion length : "
420 <<
" within time step : " <<
G4BestUnit(timeStep,
"Time")
422 <<
"State(fTimeStepReachedLimit)= " <<
State(fTimeStepReachedLimit) <<
G4endl
423 <<
"State(fGeometryLimitedStep)=" <<
State(fGeometryLimitedStep) <<
G4endl
424 <<
"End point distance was: " <<
G4BestUnit(
State(fEndPointDistance),
"Length")
449 <<
" trackID : " << track.
GetTrackID() <<
" Molecule name: "
451 G4cout <<
"Diffusion length : "
454 <<
"\t Current global time : "
467 MemStat mem_first = MemoryUsage();
475 <<
"G4DNABrownianTransportation::Diffusion :" << setw(8)
477 <<
"\t" <<
" Global Time = "
498 if (waterDensity == 0.0)
511 G4cout <<
"A track is outside water material : trackID = "
526 MemStat mem_intermediaire = MemoryUsage();
527 mem_diff = mem_intermediaire-mem_first;
528 G4cout <<
"\t\t\t >> || MEM || In G4DNABrownianTransportation::Diffusion "
529 "after dealing with waterDensity for "<< track.
GetTrackID()
530 <<
", diff is : " << mem_diff <<
G4endl;
534 State(fMomentumChanged) =
true;
538 mem_intermediaire = MemoryUsage();
539 mem_diff = mem_intermediaire-mem_first;
540 G4cout <<
"\t\t\t >> || MEM || In G4DNABrownianTransportation::"
541 "After proposing new direction to fParticleChange for "
577 G4cout <<
" G4DNABrownianTransportation::AlongStepGetPhysicalInteractionLength - track ID: "
586 track, previousStepSize, currentMinimumStep, currentSafety,
589 if(geometryStepLength==0)
592 if(
State(fGeometryLimitedStep))
598 State(fCurrentTouchableHandle)->GetHistory());
610 State(fCurrentTouchableHandle) = newTouchable;
625 track, previousStepSize, currentMinimumStep, currentSafety,
642 geometryStepLength = distanceToBoundary;
680 if(diffusionCoefficient <= 0)
682 State(fGeometryLimitedStep) =
false;
689 State(fComputeLastPosition) =
false;
690 State(fTimeStepReachedLimit) =
false;
692 if (
State(fGeometryLimitedStep))
702 State(theInteractionTimeLeft) = (geometryStepLength * geometryStepLength)
703 / (diffusionCoefficient);
707 State(theInteractionTimeLeft) = (currentSafety * currentSafety)
708 / (diffusionCoefficient);
715 State(fComputeLastPosition) =
true;
722 State(theInteractionTimeLeft) = 1 / (4 * diffusionCoefficient)
723 * pow(geometryStepLength / InvErfc(
State(fRandomNumber)),2);
725 State(fTransportEndPosition) = geometryStepLength*
737 if (
State(theInteractionTimeLeft) < minTimeStepAllowed)
739 State(theInteractionTimeLeft) = minTimeStepAllowed;
740 State(fTimeStepReachedLimit) =
true;
741 State(fComputeLastPosition) =
true;
747 State(fTimeStepReachedLimit) =
true;
751 State(fComputeLastPosition) =
true;
755 State(fCandidateEndGlobalTime) =
758 State(fEndGlobalTimeComputed) =
true;
760 State(fPathLengthWasCorrected) =
false;
765 geometryStepLength = 2
766 * sqrt(diffusionCoefficient *
State(theInteractionTimeLeft))
768 State(fPathLengthWasCorrected) =
true;
770 State(fTransportEndPosition) = geometryStepLength*
779 <<
"G4DNABrownianTransportation::AlongStepGetPhysicalInteractionLength = "
791 return geometryStepLength;
803 MemStat mem_first, mem_second, mem_diff;
807 mem_first = MemoryUsage();
810 if (
GetIT(track)->GetTrackingInfo()->IsLeadingStep()
811 &&
State(fComputeLastPosition)
812 &&
State(fGeometryLimitedStep)
824 GetDiffusionCoefficient();
826 G4double sqrt_2Dt= sqrt(2 * diffusionCoefficient *
State(theInteractionTimeLeft));
827 G4double x = G4RandGauss::shoot(0, sqrt_2Dt);
828 G4double y = G4RandGauss::shoot(0, sqrt_2Dt);
829 G4double z = G4RandGauss::shoot(0, sqrt_2Dt);
833 spaceStep =
State(fEndPointDistance);
834 State(fGeometryLimitedStep) =
true;
838 spaceStep = sqrt(x * x + y * y + z * z);
840 if(spaceStep >=
State(fEndPointDistance))
842 State(fGeometryLimitedStep) =
true;
846 && spaceStep >=
State(fEndPointDistance))
848 spaceStep =
State(fEndPointDistance);
853 State(fGeometryLimitedStep) =
false;
873 State(fTransportEndPosition) = nextPosition;
881 <<
"G4DNABrownianTransportation::AlongStepDoIt: "
882 "GeometryLimitedStep = "
883 <<
State(fGeometryLimitedStep)
896 MemStat mem_intermediaire = MemoryUsage();
897 mem_diff = mem_intermediaire-mem_first;
898 G4cout <<
"\t\t\t >> || MEM || After calling G4ITTransportation::"
899 "AlongStepDoIt for "<< track.
GetTrackID() <<
", diff is : "
947 mem_intermediaire = MemoryUsage();
948 mem_diff = mem_intermediaire-mem_first;
949 G4cout <<
"\t\t\t >> || MEM || After calling G4DNABrownianTransportation::"
950 "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)
@ fLowEnergyBrownianTransportation
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
G4double AlongStepGetPhysicalInteractionLength(const G4Track &, G4double, G4double, G4double &, G4GPILSelection *) override
G4BrownianAction * fpBrownianAction
void Diffusion(const G4Track &track)
~G4DNABrownianTransportation() override
G4VUserBrownianAction * fpUserBrownianAction
G4bool fUseSchedulerMinTimeSteps
G4DNABrownianTransportation(const G4String &aName="DNABrownianTransportation", G4int verbosityLevel=0)
const std::vector< G4double > * fpWaterDensity
G4double ComputeGeomLimit(const G4Track &track, G4double &presafety, G4double limit)
void StartTracking(G4Track *aTrack) override
G4double fInternalMinTimeStep
G4bool fUseMaximumTimeBeforeReachingBoundary
void BuildPhysicsTable(const G4ParticleDefinition &) override
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &) override
void ComputeStep(const G4Track &, const G4Step &, const G4double, G4double &) override
G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &) override
static G4DNAMolecularMaterial * Instance()
G4VPhysicalVolume * GetWorldVolume()
G4double CheckNextStep(const G4ThreeVector &position, const G4ThreeVector &direction, const G4double currentMaxStep, G4double &newSafety)
G4ParticleChangeForTransport fParticleChange
G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &stepData) override
void SetInstantiateProcessState(G4bool flag)
void BuildPhysicsTable(const G4ParticleDefinition &) override
void StartTracking(G4Track *aTrack) override
G4double AlongStepGetPhysicalInteractionLength(const G4Track &track, G4double, G4double currentMinimumStep, G4double ¤tSafety, G4GPILSelection *selection) override
G4ITSafetyHelper * fpSafetyHelper
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &) override
G4ITNavigator * fLinearNavigator
G4TrackingInformation * GetTrackingInfo()
virtual const G4String & GetName() const =0
G4double GetTemperature() const
std::size_t GetIndex() const
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
const G4String & GetName() const override
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 G4VPhysicalVolume * GetVolume(G4int depth=0) const
virtual void UpdateYourself(G4VPhysicalVolume *pPhysVol, const G4NavigationHistory *history=nullptr)
void LoadTrackState(G4TrackStateManager &manager) override
void ResetTrackState() override
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 G4double GetDistanceToBoundary(const G4Track &)=0
virtual void Transport(G4ThreeVector &, G4Track *pTrack=nullptr)=0
G4bool fTimeStepReachedLimit
G4bool fPathLengthWasCorrected
G4bool fComputeLastPosition