Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DNASmoluchowskiDiffusion Class Reference

#include <G4DNASmoluchowskiDiffusion.hh>

Classes

struct  BoundingBox
 

Public Member Functions

 G4DNASmoluchowskiDiffusion (double epsilon=1e-5)
 
virtual ~G4DNASmoluchowskiDiffusion ()
 
double GetRandomDistance (double _time, double D)
 
double GetRandomTime (double distance, double D)
 
double EstimateCrossingTime (double proba, double distance, double D)
 
void PrepareReverseTable (double xmin, double xmax)
 
double GetInverseProbability (double proba)
 
double PlotInverse (double *x, double *)
 
double Plot (double *x, double *)
 
void InitialiseInverseProbability (double xmax=3e28)
 

Static Public Member Functions

static double ComputeS (double r, double D, double t)
 
static double ComputeDistance (double sTransform, double D, double t)
 
static double ComputeTime (double sTransform, double D, double r)
 
static double GetDifferential (double sTransform)
 
static double GetDensityProbability (double r, double _time, double D)
 
static double GetCumulativeProbability (double sTransform)
 

Public Attributes

std::vector< double > fInverse
 
int fNbins
 
double fEpsilon
 

Detailed Description

Definition at line 70 of file G4DNASmoluchowskiDiffusion.hh.

Constructor & Destructor Documentation

◆ G4DNASmoluchowskiDiffusion()

G4DNASmoluchowskiDiffusion::G4DNASmoluchowskiDiffusion ( double epsilon = 1e-5)

Definition at line 50 of file G4DNASmoluchowskiDiffusion.cc.

51{
52 fNbins = (int) trunc(1/fEpsilon);
53 // std::cout << "fNbins: " << fNbins << std::endl;
54#ifdef DNADEV
55 assert(fNbins > 0);
56#endif
57 fInverse.resize(fNbins+2); // trunc sous-estime + borne max a rajouter ==> 2
58
59 // std::cout << "fInverse.capacity(): "<< fInverse.capacity() << std::endl;
60}
G4double epsilon(G4double density, G4double temperature)

◆ ~G4DNASmoluchowskiDiffusion()

G4DNASmoluchowskiDiffusion::~G4DNASmoluchowskiDiffusion ( )
virtualdefault

Member Function Documentation

◆ ComputeDistance()

static double G4DNASmoluchowskiDiffusion::ComputeDistance ( double sTransform,
double D,
double t )
inlinestatic

Definition at line 82 of file G4DNASmoluchowskiDiffusion.hh.

83 {
84 return sTransform * 2. * std::sqrt(D * t);
85 }
G4double D(G4double temp)

Referenced by GetRandomDistance().

◆ ComputeS()

static double G4DNASmoluchowskiDiffusion::ComputeS ( double r,
double D,
double t )
inlinestatic

Definition at line 76 of file G4DNASmoluchowskiDiffusion.hh.

77 {
78 double sTransform = r / (2. * std::sqrt(D * t));
79 return sTransform;
80 }

◆ ComputeTime()

static double G4DNASmoluchowskiDiffusion::ComputeTime ( double sTransform,
double D,
double r )
inlinestatic

Definition at line 87 of file G4DNASmoluchowskiDiffusion.hh.

88 {
89 return std::pow(r / sTransform, 2.) / (4. * D);
90 }

Referenced by EstimateCrossingTime(), and GetRandomTime().

◆ EstimateCrossingTime()

double G4DNASmoluchowskiDiffusion::EstimateCrossingTime ( double proba,
double distance,
double D )
inline

Definition at line 110 of file G4DNASmoluchowskiDiffusion.hh.

113 {
114 double sTransform = GetInverseProbability(proba);
115 return ComputeTime(sTransform, D, distance);
116 }
static double ComputeTime(double sTransform, double D, double r)

◆ GetCumulativeProbability()

static double G4DNASmoluchowskiDiffusion::GetCumulativeProbability ( double sTransform)
inlinestatic

Definition at line 303 of file G4DNASmoluchowskiDiffusion.hh.

304 {
305 static double constant = 2./std::sqrt(3.141592653589793);
306 return erfc(sTransform) + constant*sTransform*G4Exp(-sTransform*sTransform);
307 }
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
Definition G4Exp.hh:180

Referenced by G4DNASmoluchowskiDiffusion::BoundingBox::BoundingBox(), and PrepareReverseTable().

◆ GetDensityProbability()

static double G4DNASmoluchowskiDiffusion::GetDensityProbability ( double r,
double _time,
double D )
inlinestatic

Definition at line 129 of file G4DNASmoluchowskiDiffusion.hh.

130 {
131 static double my_pi = 3.141592653589793;
132 static double constant = 4.*my_pi/std::pow(4.*my_pi, 1.5);
133 return r*r/std::pow(D * _time,1.5)*G4Exp(-r*r/(4. * D * _time))*constant;
134 }

◆ GetDifferential()

static double G4DNASmoluchowskiDiffusion::GetDifferential ( double sTransform)
inlinestatic

Definition at line 123 of file G4DNASmoluchowskiDiffusion.hh.

124 {
125 static double constant = -4./std::sqrt(3.141592653589793);
126 return sTransform*sTransform*G4Exp(-sTransform*sTransform)*constant; // -4*sTransform*sTransform*exp(-sTransform*sTransform)/sqrt(3.141592653589793)
127 }

Referenced by Plot().

◆ GetInverseProbability()

double G4DNASmoluchowskiDiffusion::GetInverseProbability ( double proba)
inline

Definition at line 309 of file G4DNASmoluchowskiDiffusion.hh.

310 {
311 auto index_low = (size_t) trunc(proba/fEpsilon);
312
313 if(index_low == 0) // assymptote en 0
314 {
315 index_low = 1;
316 size_t index_up = 2;
317 double low_y = fInverse[index_low];
318 double up_y = fInverse[index_up];
319 double low_x = index_low*fEpsilon;
320 double up_x = proba+fEpsilon;
321 double tangente = (low_y-up_y)/(low_x - up_x); // ou utiliser GetDifferential(proba) ?
322 // double tangente = GetDifferential(proba);
323 return low_y + tangente*(proba-low_x);
324 }
325
326 size_t index_up = index_low+1;
327 if(index_low > fInverse.size()) return fInverse.back();
328 double low_y = fInverse[index_low];
329 double up_y = fInverse[index_up];
330
331 double low_x = index_low*fEpsilon;
332 double up_x = low_x+fEpsilon;
333
334 if(up_x > 1) // P(1) = 0
335 {
336 up_x = 1;
337 up_y = 0; // more general : fInverse.back()
338 }
339
340 double tangente = (low_y-up_y)/(low_x - up_x);
341
342 return low_y + tangente*(proba-low_x);
343 }

Referenced by EstimateCrossingTime(), GetRandomDistance(), GetRandomTime(), and PlotInverse().

◆ GetRandomDistance()

double G4DNASmoluchowskiDiffusion::GetRandomDistance ( double _time,
double D )
inline

Definition at line 94 of file G4DNASmoluchowskiDiffusion.hh.

95 {
96 double proba = G4UniformRand();
97// G4cout << "proba = " << proba << G4endl;
98 double sTransform = GetInverseProbability(proba);
99// G4cout << "sTransform = " << sTransform << G4endl;
100 return ComputeDistance(sTransform, D, _time);
101 }
#define G4UniformRand()
Definition Randomize.hh:52
static double ComputeDistance(double sTransform, double D, double t)

◆ GetRandomTime()

double G4DNASmoluchowskiDiffusion::GetRandomTime ( double distance,
double D )
inline

Definition at line 103 of file G4DNASmoluchowskiDiffusion.hh.

104 {
105 double proba = G4UniformRand();
106 double sTransform = GetInverseProbability(proba);
107 return ComputeTime(sTransform, D, distance);
108 }

◆ InitialiseInverseProbability()

void G4DNASmoluchowskiDiffusion::InitialiseInverseProbability ( double xmax = 3e28)
inline

Definition at line 356 of file G4DNASmoluchowskiDiffusion.hh.

357 {
358 // x > x'
359 // P'(x) = p(x') = lim(x->x') (P(x') - P(x))/(x'-x)
360 // x'-x = (P(x') - P(x))/p(x')
361 // x = x' - (P(x') - P(x))/p(x')
362
363 // fInverse initialized in the constructor
364
365 assert(fNbins !=0);
366 PrepareReverseTable(0,xmax);
367 }
void PrepareReverseTable(double xmin, double xmax)

◆ Plot()

double G4DNASmoluchowskiDiffusion::Plot ( double * x,
double *  )
inline

Definition at line 350 of file G4DNASmoluchowskiDiffusion.hh.

351 {
352 return GetDifferential(x[0]);
353 }
static double GetDifferential(double sTransform)

◆ PlotInverse()

double G4DNASmoluchowskiDiffusion::PlotInverse ( double * x,
double *  )
inline

Definition at line 345 of file G4DNASmoluchowskiDiffusion.hh.

346 {
347 return GetInverseProbability(x[0]);
348 }

◆ PrepareReverseTable()

void G4DNASmoluchowskiDiffusion::PrepareReverseTable ( double xmin,
double xmax )
inline

Definition at line 262 of file G4DNASmoluchowskiDiffusion.hh.

263 {
264 double x = xmax;
265 int index = 0;
266 double nextProba = fEpsilon;
267 double proposedX;
268
269 BoundingBox boundingBox(xmin, xmax, fEpsilon*1e-5);
270
271 while(index <= fNbins)
272 // in case GetCumulativeProbability is exact (digitally speaking), replace with:
273 // while(index <= fNbins+1)
274 {
275 nextProba = fEpsilon*index;
276
277 double newProba = GetCumulativeProbability(x);
278
279 if(boundingBox.Propose(x, newProba, nextProba, proposedX))
280 {
281 fInverse[index] = x;
282 index++;
283 }
284 else
285 {
286 if(x == proposedX)
287 {
288 G4cout << "BREAK : x= " << x << G4endl;
289 G4cout << "index= " << index << G4endl;
290 G4cout << "nextProba= " << nextProba << G4endl;
291 G4cout << "newProba= " << newProba << G4endl;
292 abort();
293 }
294 x = proposedX;
295 }
296 }
297
298 fInverse[fNbins+1] = 0; // P(1) = 0, because we want it exact !
299 // Tips to improve the exactness: get an better value of pi, get better approximation of erf and exp, use long double instead of double
300// boundingBox.Print();
301 }
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
static double GetCumulativeProbability(double sTransform)

Referenced by InitialiseInverseProbability().

Member Data Documentation

◆ fEpsilon

double G4DNASmoluchowskiDiffusion::fEpsilon

◆ fInverse

std::vector<double> G4DNASmoluchowskiDiffusion::fInverse

◆ fNbins

int G4DNASmoluchowskiDiffusion::fNbins

The documentation for this class was generated from the following files: