-
Notifications
You must be signed in to change notification settings - Fork 14
/
GreensFunction1DAbsAbs.cpp
703 lines (605 loc) · 20.4 KB
/
GreensFunction1DAbsAbs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <exception>
#include <vector>
#include <gsl/gsl_math.h>
#include <gsl/gsl_sf_trig.h>
#include <gsl/gsl_sum.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_interp.h>
#include <gsl/gsl_sf_expint.h>
#include <gsl/gsl_sf_elljac.h>
#include <gsl/gsl_roots.h>
#include <math.h>
#include "findRoot.hpp"
#include "GreensFunction1DAbsAbs.hpp"
#include "Defs.hpp"
// Calculates the probability of finding the particle inside the domain at
// time t
Real
GreensFunction1DAbsAbs::p_survival (Real t) const
{
THROW_UNLESS( std::invalid_argument, t >= 0.0 );
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
const Real D(this->getD());
const Real v(this->getv());
if ( fabs(r0-sigma) < L*EPSILON || fabs(a-r0) < L*EPSILON || L < 0.0 )
{
// The survival probability of a zero domain is zero
return 0.0;
}
// Set values that are constant in this calculation
const Real expo(-D*t/(L*L)); // part of the exponent -D n^2 PI^2 t / L^2
const Real r0s(r0 - sigma);
const Real r0s_L(r0s/L);
// some abbreviations for terms appearing in the sums with drift<>0
const Real sigmav2D(sigma*v/2.0/D);
const Real av2D(a*v/2.0/D);
const Real Lv2D(L*v/2.0/D);
const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D); // exponent of the drift-prefactor
// Initialize summation
Real sum = 0, term = 0, prev_term = 0;
Real nPI;
// Sum
Real n=1;
// different calculations depending on whether v=0 or not
if(v==0.0) // case without drift (v==0); in this case the summation is simpler, so do the complicated caluclation only if necessary
{
do
{
if (n >= MAX_TERMS )
{
std::cerr << "Too many terms for p_survival. N: " << n << std::endl;
break;
}
prev_term = term;
nPI = (double)n*M_PI;
term = exp(nPI*nPI*expo) * sin(nPI*r0s_L) * (1.0 - cos(nPI)) / nPI;
sum += term;
n++;
}
// Is 1 a good measure or will this fail at some point?
while ( fabs(term/sum) > EPSILON*1.0 ||
fabs(prev_term/sum) > EPSILON*1.0 ||
n < MIN_TERMS );
sum = 2.0*sum; // This is a prefactor of every term, so do only one multiplication here
}
else // case with drift (v<>0)
{
do
{
if (n >= MAX_TERMS )
{
std::cerr << "Too many terms for p_survival. N: " << n << std::endl;
break;
}
nPI = (double)n*M_PI;
prev_term = term;
term = exp(nPI*nPI*expo) * (exp(sigmav2D) - cos(nPI)*exp(av2D)) * nPI/(Lv2D*Lv2D+nPI*nPI) * sin(nPI*r0s_L);
sum += term;
n++;
}
// TODO: Is 1 a good measure or will this fail at some point?
while ( fabs(term/sum) > EPSILON*1.0 ||
fabs(prev_term/sum) > EPSILON*1.0 ||
n < MIN_TERMS );
sum = 2.0*exp(vexpo) * sum; // prefactor containing the drift
}
return sum;
}
// Calculates the probability density of finding the particle at location r at
// time t.
Real
GreensFunction1DAbsAbs::prob_r (Real r, Real t) const
{
THROW_UNLESS( std::invalid_argument, 0.0 <= (r-sigma) && r <= a );
THROW_UNLESS( std::invalid_argument, t >= 0.0 );
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
const Real D(this->getD());
const Real v(this->getv());
// if there was no time change or no diffusivity => no movement
if (t == 0 || D == 0)
{
// the probability density function is a delta function
if (r == r0)
{
return INFINITY;
}
else
{
return 0.0;
}
}
else if ( fabs(r-sigma) < L*EPSILON || fabs(a-r) < L*EPSILON || L < 0.0 )
{
return 0.0;
}
// Set values that are constant in this calculation
const Real expo(-D*t/(L*L));
const Real rs_L((r-sigma)/L);
const Real r0s_L((r0-sigma)/L);
const Real vexpo(-v*v*t/4.0/D + v*(r-r0)/2.0/D); // exponent of the drift-prefactor
// Initialize summation
Real nPI;
Real sum = 0, term = 0, prev_term = 0;
// Sum
int n=1;
do
{
if (n >= MAX_TERMS )
{
std::cerr << "Too many terms for prob_r. N: " << n << std::endl;
break;
}
prev_term = term;
nPI = n*M_PI;
term = exp(nPI*nPI*expo) * sin(nPI*r0s_L) * sin(nPI*rs_L);
sum += term;
n++;
}
while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
n <= MIN_TERMS);
return 2.0/L * exp(vexpo) * sum;
}
// Calculates the probability density of finding the particle at location r at
// timepoint t, given that the particle is still in the domain.
Real
GreensFunction1DAbsAbs::calcpcum (Real r, Real t) const
{
return prob_r(r, t) / p_survival(t);
}
// Calculates the amount of flux leaving the left boundary at time t
Real
GreensFunction1DAbsAbs::leaves(Real t) const
{
THROW_UNLESS( std::invalid_argument, t >= 0.0 );
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
const Real D(this->getD());
const Real v(this->getv());
if ( fabs(r0-sigma) < L*EPSILON || fabs(a-r0) < L*EPSILON || L < 0.0 )
{
// The flux of a zero domain is INFINITY. Also if the particle
// started on the left boundary (leaking out immediately).
return INFINITY;
}
else if ( t < EPSILON*this->t_scale )
{
// if t=0.0 the flux must be zero
return 0.0;
}
Real sum = 0, term = 0, prev_term = 0;
Real nPI;
const Real D_L_sq(D/(L*L));
const Real expo(-D_L_sq*t);
const Real r0s_L((r0-sigma)/L);
const Real vexpo(-v*v*t/4.0/D - v*(r0-sigma)/2.0/D);
Real n=1;
do
{
if (n >= MAX_TERMS )
{
std::cerr << "Too many terms for p_survival. N: " << n << std::endl;
break;
}
nPI = n*M_PI;
prev_term = term;
term = nPI * exp(nPI*nPI*expo) * sin(nPI*r0s_L);
sum += term;
n++;
}
while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
n < MIN_TERMS );
return 2.0*D_L_sq * exp(vexpo) * sum;
}
// Calculates the amount of flux leaving the right boundary at time t
Real
GreensFunction1DAbsAbs::leavea(Real t) const
{
THROW_UNLESS( std::invalid_argument, t >= 0.0 );
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
const Real D(this->getD());
const Real v(this->getv());
if ( fabs(r0-sigma) < L*EPSILON || fabs(a-r0) < L*EPSILON || L < 0.0 )
{
// The flux of a zero domain is INFINITY. Also if the particle
// started on the right boundary (leaking out immediately).
return INFINITY;
}
else if ( t < EPSILON*this->t_scale )
{
// if t=0.0 the flux must be zero
return 0.0;
}
Real sum = 0, term = 0, prev_term = 0;
Real nPI;
const Real D_L_sq(D/(L*L));
const Real expo(-D_L_sq*t); // exponent -D n^2 PI^2 t / l^2
const Real r0s_L((r0-sigma)/L);
const Real vexpo(-v*v*t/4.0/D + v*(a-r0)/2.0/D);
Real n=1;
do
{
if (n >= MAX_TERMS )
{
std::cerr << "Too many terms for leaves. N: " << n << std::endl;
break;
}
nPI = n*M_PI;
prev_term = term;
term = nPI * exp(nPI*nPI*expo) * cos(nPI) * sin(nPI*r0s_L);
sum += term;
n++;
}
while (fabs(term/sum) > EPSILON*PDENS_TYPICAL ||
fabs(prev_term/sum) > EPSILON*PDENS_TYPICAL ||
n < MIN_TERMS );
return -2.0*D_L_sq * exp(vexpo) * sum;
}
// This draws an eventtype of time t based on the flux through the left (z=sigma)
// and right (z=a) boundary. Although not completely accurate, it returns an
// IV_ESCAPE for an escape through the right boundary and a IV_REACTION for an
// escape through the left boundary.
GreensFunction1DAbsAbs::EventKind
GreensFunction1DAbsAbs::drawEventType( Real rnd, Real t ) const
{
THROW_UNLESS( std::invalid_argument, rnd < 1.0 && rnd >= 0.0 );
THROW_UNLESS( std::invalid_argument, t > 0.0 );
// if t=0 nothing has happened => no event
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
// For particles at the boundaries
if ( fabs(a-r0) < EPSILON*L )
{
// if the particle started on the right boundary
return IV_ESCAPE;
}
else if ( fabs(r0-sigma) < EPSILON*L )
{
// if the particle started on the left boundary
return IV_REACTION;
}
const Real leaves_s (this->leaves(t));
const Real leaves_a (this->leavea(t));
const Real flux_total (leaves_s + leaves_a);
const Real fluxratio (leaves_s/flux_total);
if (rnd > fluxratio )
{
return IV_ESCAPE;
}
else
{
return IV_REACTION;
}
}
// This is a help function that casts the drawT_params parameter structure into
// the right form and calculates the survival probability from it (and returns it).
// The routine drawTime uses this one to sample the next-event time from the
// survival probability using a rootfinder from GSL.
double
GreensFunction1DAbsAbs::drawT_f (double t, void *p)
{
// casts p to type 'struct drawT_params *'
struct drawT_params *params = (struct drawT_params *)p;
Real sum = 0, term = 0, prev_term = 0;
Real Xn, exponent, prefactor;
// the maximum number of terms in the params table
int terms = params->terms;
// the timescale used
Real tscale = params->tscale;
int n=0;
do
{
if ( n >= terms )
{
std::cerr << "Too many terms needed for DrawTime. N: "
<< n << std::endl;
break;
}
prev_term = term;
Xn = params->Xn[n];
exponent = params->exponent[n];
term = Xn * exp(exponent * t);
sum += term;
n++;
}
while (fabs(term/sum) > EPSILON*tscale ||
fabs(prev_term/sum) > EPSILON*tscale ||
n <= MIN_TERMS );
prefactor = params->prefactor;
// find intersection with the random number
return 1.0 - prefactor*sum - params->rnd;
}
// Draws the first passage time from the propensity function.
// Uses the help routine drawT_f and structure drawT_params for some technical
// reasons related to the way to input a function and parameters required by
// the GSL library.
Real
GreensFunction1DAbsAbs::drawTime (Real rnd) const
{
THROW_UNLESS( std::invalid_argument, 0.0 <= rnd && rnd < 1.0 );
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
const Real D(this->getD());
const Real v(this->getv());
if (D == 0.0 )
{
return INFINITY;
}
else if ( L < 0.0 || fabs(a-r0) < EPSILON*L || fabs(r0-sigma) > (1.0 - EPSILON)*L )
{
// if the domain had zero size
return 0.0;
}
const Real expo(-D/(L*L));
const Real r0s_L((r0-sigma)/L);
// some abbreviations for terms appearing in the sums with drift<>0
const Real sigmav2D(sigma*v/2.0/D);
const Real av2D(a*v/2.0/D);
const Real Lv2D(L*v/2.0/D);
// exponent of the prefactor present in case of v<>0; has to be split because it has a t-dep. and t-indep. part
const Real vexpo_t(-v*v/4.0/D);
const Real vexpo_pref(-v*r0/2.0/D);
// the structure to store the numbers to calculate the numbers for 1-S
struct drawT_params parameters;
Real Xn, exponent, prefactor;
Real nPI;
// Construct the coefficients and the terms in the exponent and put them
// into the params structure
int n = 0;
// a simpler sum has to be computed for the case w/o drift, so distinguish here
if(v==0)
{
do
{
nPI = ((Real)(n+1))*M_PI; // why n+1 : this loop starts at n=0 (1st index of the arrays), while the sum starts at n=1 !
Xn = sin(nPI*r0s_L) * (1.0 - cos(nPI)) / nPI;
exponent = nPI*nPI*expo;
// store the coefficients in the structure
parameters.Xn[n] = Xn;
// also store the values for the exponent
parameters.exponent[n]=exponent;
n++;
}
// TODO: Modify this later to include a cutoff when changes are small
while (n<MAX_TERMS);
}
else // case with drift<>0
{
do
{
nPI = ((Real)(n+1))*M_PI; // why n+1 : this loop starts at n=0 (1st index of the arrays), while the sum starts at n=1 !
Xn = (exp(sigmav2D) - cos(nPI)*exp(av2D)) * nPI/(Lv2D*Lv2D+nPI*nPI) * sin(nPI*r0s_L);
exponent = nPI*nPI*expo + vexpo_t;
// store the coefficients in the structure
parameters.Xn[n] = Xn;
// also store the values for the exponent
parameters.exponent[n]=exponent;
n++;
}
// TODO: Modify this later to include a cutoff when changes are small
while (n<MAX_TERMS);
}
// the prefactor of the sum is also different in case of drift<>0 :
if(v==0) prefactor = 2.0*exp(vexpo_pref);
else prefactor = 2.0;
parameters.prefactor = prefactor;
parameters.rnd = rnd;
parameters.terms = MAX_TERMS;
parameters.tscale = this->t_scale;
gsl_function F;
F.function = &drawT_f;
F.params = ¶meters;
// Find a good interval to determine the first passage time in
const Real dist( std::min(r0-sigma, a-r0) );
// construct a guess: MSD = sqrt (2*d*D*t)
Real t_guess( dist * dist / ( 2.0 * D ) );
// A different guess has to be made in case of nonzero drift to account for the displacement due to it
// When drifting towards the closest boundary...
if( ( r0-sigma >= L/2.0 && v > 0.0 ) || ( r0-sigma <= L/2.0 && v < 0.0 ) ) t_guess = sqrt(D*D/(v*v*v*v)+dist*dist/(v*v)) - D/(v*v);
// When drifting away from the closest boundary...
if( ( r0-sigma < L/2.0 && v > 0.0 ) || ( r0-sigma > L/2.0 && v < 0.0 ) ) t_guess = D/(v*v) - sqrt(D*D/(v*v*v*v)-dist*dist/(v*v));
Real value( GSL_FN_EVAL( &F, t_guess ) );
Real low( t_guess );
Real high( t_guess );
if( value < 0.0 )
{
// scale the interval around the guess such that the function
// straddles if the guess was too low
do
{
// keep increasing the upper boundary until the
// function straddles
high *= 10.0;
value = GSL_FN_EVAL( &F, high );
if( fabs( high ) >= t_guess * 1e6 )
{
std::cerr << "Couldn't adjust high. F(" << high << ") = "
<< value << std::endl;
throw std::exception();
}
}
while ( value <= 0.0 );
}
else
{
// if the guess was too high initialize with 2 so the test
// below survives the first iteration
Real value_prev( 2.0 );
do
{
if( fabs( low ) <= t_guess * 1.0e-6 ||
fabs(value-value_prev) < EPSILON*this->t_scale )
{
std::cerr << "Couldn't adjust low. F(" << low << ") = "
<< value << " t_guess: " << t_guess << " diff: "
<< (value - value_prev) << " value: " << value
<< " value_prev: " << value_prev << " t_scale: "
<< this->t_scale << std::endl;
return low;
}
value_prev = value;
// keep decreasing the lower boundary until the
// function straddles
low *= 0.1;
// get the accompanying value
value = GSL_FN_EVAL( &F, low );
}
while ( value >= 0.0 );
}
// find the intersection on the y-axis between the random number and
// the function
// define a new solver type brent
const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );
// make a new solver instance
// TODO: incl typecast?
gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );
const Real t( findRoot( F, solver, low, high, EPSILON*t_scale, EPSILON,
"GreensFunction1DAbsAbs::drawTime" ) );
// return the drawn time
return t;
}
// This is a help function that casts the drawR_params parameter structure into
// the right form and calculates the survival probability from it (and returns it).
// The routine drawR uses this function to sample the exit point, making use of the
// GSL root finder to draw the random position.
double
GreensFunction1DAbsAbs::drawR_f (double r, void *p)
{
struct drawR_params *params = (struct drawR_params *)p;
double sum = 0, term = 0, prev_term = 0;
double S_Cn_An, n_L;
int terms = params->terms;
double sigma = params->H[0];
double v2D = params->H[1]; // =v/(2D)
int n=0;
do
{
if (n >= terms )
{
std::cerr << "Too many terms for DrawR. N: " << n << std::endl;
break;
}
prev_term = term;
S_Cn_An = params->S_Cn_An[n];
n_L = params->n_L[n]; // this is n*pi/L
if(v2D==0.0) term = S_Cn_An * ( 1.0 - cos(n_L*(r-sigma)) );
else term = S_Cn_An * ( exp(v2D*sigma) + exp(v2D*r)*( v2D/n_L*sin(n_L*(r-sigma)) - cos(n_L*(r-sigma)) ));
// S_Cn_An contains all expon. prefactors, the 1/S(t) term and all parts
// of the terms that do not depend on r.
//
// In case of zero drift the terms become S_An_Cn * ( 1 - cos(nPi/L*(r-sigma)) )
// as it should be. The if-statement is only to avoid calculation costs.
sum += term;
n++;
}
while (fabs(term/sum) > EPSILON ||
fabs(prev_term/sum) > EPSILON ||
n <= MIN_TERMS );
// find the intersection with the random number
return sum - params->rnd;
}
// Draws the position of the particle at a given time from p(r,t), assuming
// that the particle is still in the domain
Real
GreensFunction1DAbsAbs::drawR (Real rnd, Real t) const
{
THROW_UNLESS( std::invalid_argument, 0.0 <= rnd && rnd < 1.0 );
THROW_UNLESS( std::invalid_argument, t >= 0.0 );
const Real a(this->geta());
const Real sigma(this->getsigma());
const Real L(this->geta() - this->getsigma());
const Real r0(this->getr0());
const Real D(this->getD());
const Real v(this->getv());
// the trivial case: if there was no movement or the domain was zero
if ( (D==0.0 && v==0.0) || L<0.0 || t==0.0)
{
return r0;
}
else
{
// if the initial condition is at the boundary, raise an error
// The particle can only be at the boundary in the ABOVE cases
THROW_UNLESS( std::invalid_argument,
(r0-sigma) >= L*EPSILON && (r0-sigma) <= L*(1.0-EPSILON) );
}
// else the normal case
// From here on the problem is well defined
// structure to store the numbers to calculate numbers for 1-S(t)
struct drawR_params parameters;
Real S_Cn_An;
Real nPI;
const Real expo (-D*t/(L*L));
const Real r0s_L((r0-sigma)/L);
const Real v2D(v/2.0/D);
const Real Lv2D(L*v/2.0/D);
const Real vexpo(-v*v*t/4.0/D - v*r0/2.0/D); // exponent of the drift-prefactor, same as in survival prob.
const Real S = 2.0*exp(vexpo)/p_survival(t); // This is a prefactor to every term, so it also contains there
// exponential drift-prefactor.
// Construct the coefficients and the terms in the exponent and put them
// in the params structure
int n=0;
do
{
nPI = ((Real)(n+1))*M_PI; // note: summation starting with n=1, indexing with n=0, therefore we need n+1 here
if(v==0.0) S_Cn_An = S * exp(nPI*nPI*expo) * sin(nPI*r0s_L) / nPI;
else S_Cn_An = S * exp(nPI*nPI*expo) * sin(nPI*r0s_L) * nPI/(nPI*nPI + Lv2D*Lv2D);
// The rest is the z-dependent part, which has to be defined directly in drawR_f(z).
// Of course also the summation happens there because the terms now are z-dependent.
// The last term originates from the integrated prob. density including drift.
//
// In case of zero drift this expression becomes: 2.0/p_survival(t) * exp(nPI*nPI*expo) * sin(nPI*r0s_L) / nPI
// also store the values for the exponent, so they don't have to be recalculated in drawR_f
parameters.S_Cn_An[n]= S_Cn_An;
parameters.n_L[n] = nPI/L;
n++;
}
while (n<MAX_TERMS);
// store the random number for the probability
parameters.rnd = rnd ;
// store the number of terms used
parameters.terms = MAX_TERMS;
// store needed constants
parameters.H[0] = sigma;
parameters.H[1] = v2D;
// find the intersection on the y-axis between the random number and
// the function
gsl_function F;
F.function = &drawR_f;
F.params = ¶meters;
// define a new solver type brent
const gsl_root_fsolver_type* solverType( gsl_root_fsolver_brent );
// make a new solver instance
// TODO: incl typecast?
gsl_root_fsolver* solver( gsl_root_fsolver_alloc( solverType ) );
const Real r( findRoot( F, solver, sigma, a, L*EPSILON, EPSILON,
"GreensFunction1DAbsAbs::drawR" ) );
// return the drawn time
return r;
}
std::string GreensFunction1DAbsAbs::dump() const
{
std::ostringstream ss;
ss << "D = " << this->getD() << ", sigma = " << this->getsigma() <<
", a = " << this->geta() << std::endl;
return ss.str();
}