-
Notifications
You must be signed in to change notification settings - Fork 1
/
mcml_conv.cpp
740 lines (594 loc) · 18.4 KB
/
mcml_conv.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
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
/***********************************************************
* class setup program for Monte Carlo simulation of photon
* distribution in multi-layered turbid media.
*
****/
#include "mcml_conv.h"
double ITheta(double r, double r2, double R);
double ModifiedBessI0(double x);
double ExpBessI0(double r, double r2, double R);
double RT_raInterp(double r2, double ** RT_ra, MCMLConv * mcmlConv);
double RT_rInterp(double r2, double * RT_r, MCMLConv * mcmlConv);
double A_rzInterp(double r2, MCMLConv * mcmlConv);
double Rd_raFGIntegrand(double r2, void * params);
double Rd_rFGIntegrand(double r2, void * params);
double A_rzFGIntegrand(double r2, void * params);
double Tt_raFGIntegrand(double r2, void * params);
double Tt_rFGIntegrand(double r2, void * params);
double IntegrateQuad(double (*func) (double x, void * params),
double a, double b, MCMLConv * mcmlConv);
double FlatIntegration(double (*func) (double x, void * params),
MCMLConv * mcmlConv);
double GaussIntegration(double (*func) (double x, void * params),
MCMLConv * mcmlConv);
Node * Node::FillNode(double x, double y) {
Node * l = new Node;
l->x = x;
l->y = y;
l->left = nullptr;
l->right = nullptr;
return l;
}
Node * Node::SearchNode(Node * tree, double x) {
Node * l = tree;
bool found = false;
while (l != nullptr && !found) {
if (x < l->x)
l = l->left;
else if (x > l->x)
l = l->right;
else
found = true;
}
return l;
}
void Node::InsertNode(Node * tree, double x, double y) {
Node * l1 = nullptr;
Node * l2 = tree;
while (l2 != nullptr) {
l1 = l2;
if (x < l2->x)
l2 = l2->left;
else
l2 = l2->right;
}
if (l1 == nullptr) // Empty tree.
tree = Node::FillNode(x, y);
else if (x < l1->x)
l1->left = Node::FillNode(x, y);
else
l1->right = Node::FillNode(x, y);
}
void Node::FreeTree(Node * tree) {
if (tree != nullptr) {
FreeTree(tree->left);
FreeTree(tree->right);
delete tree;
}
}
void ConvInput::SelectConvInput (MCMLModel mcmlModelSet,
Beam::BeamType beamType, double P, double R) {
/* ConvInput class - beam convolution input class
Input parameters for each independent run.
z and r are for the cylindrical coordinate system. [cm]
a is for the angle alpha between the photon exiting
direction and the surface normal. [radian]
The grid line separations in z, r, and alpha
directions are dz, dr, and da respectively. The numbers
of grid lines in z, r, and alpha directions are
nz, nr, and na respectively.
The member layerspecs will point to an array of
structures which store parameters of each layer.
This array has (number_layers + 2) elements. One
element is for a layer.
The layers 0 and (num_layers + 1) are for top ambient
medium and the bottom ambient medium respectively.
For convolution, the grid line separations in z, and alpha
directions are still dz, and da respectively. The numbers
of grid lines in z, and alpha directions are still
nz, and na respectively. However, the grid line separation
and the number of grid lines in r direction are drc and
nrc respectively.
Class instance variables:
beam - incident beam class instance object
drc - convolution r grid separation.[cm]
nrc - convolution array range 0..nrc-1.
eps - relative error in convolution
Methods:
*/
this->FreeConvInput(); // free previously set array members if needed
switch (beamType) {
case Beam::FLAT:
beam.type = Beam::FLAT; // incident beam of finite size
break;
case Beam::GAUSSIAN:
beam.type = Beam::GAUSSIAN;
break;
default:
beam.type = Beam::FLAT;
}
mcmlModel = mcmlModelSet;
beam.P = P;
beam.R = std::max<double>(R, 1e-5); // minimum radius required
double minR = 1.2*(R + mcmlModel.nr*mcmlModel.dr);
drc = std::max<double>(mcmlModel.dr, minR/200);
nrc = (short) (minR/drc);
}
void ConvInput::FreeConvInput () {
mcmlModel.FreeMCMLModel();
if (convVar.tree != nullptr) {
Node::FreeTree(convVar.tree);
convVar.tree = nullptr;
}
}
void MCMLConv::SelectMCMLConv (MCMLModel mcmlModelSet, std::string beamType,
double P, double R) {
this->FreeMCMLConv();
if (beamType.compare("FLAT") == 0)
this->SelectConvInput (mcmlModelSet, Beam::FLAT, P, R);
else if (beamType.compare("GAUSSIAN") == 0)
this->SelectConvInput (mcmlModelSet, Beam::GAUSSIAN, P, R);
else
this->SelectConvInput (mcmlModelSet, Beam::FLAT, P, R);
short na = mcmlModel.na;
short nz = mcmlModel.nz;
Rd_rac = new double * [nrc];
for (int i = 0; i < nrc; i++) {
Rd_rac[i] = new double [na];
// initialize array with 0
std::fill (Rd_rac[i], Rd_rac[i]+na-1, 0);
}
Rd_rc = new double [nrc];
std::fill (Rd_rc, Rd_rc+nrc-1, 0);
A_rzc = new double * [nrc];
for (int i = 0; i < nrc; i++) {
A_rzc[i] = new double [nz];
std::fill (A_rzc[i], A_rzc[i]+nz-1, 0);
}
Tt_rac = new double * [nrc];
for (int i = 0; i < nrc; i++) {
Tt_rac[i] = new double [na];
std::fill (Tt_rac[i], Tt_rac[i]+na-1, 0);
}
Tt_rc = new double [nrc];
std::fill (Tt_rc, Tt_rc+nrc-1, 0);
F_rzc = new double * [nrc];
for (int i = 0; i < nrc; i++) {
F_rzc[i] = new double [nz];
std::fill (F_rzc[i], F_rzc[i]+nz-1, 0);
}
}
void MCMLConv::FreeMCMLConv () {
if (Rd_rac != nullptr) {
for (int i = 0; i < nrc; i++)
delete[] Rd_rac[i];
}
Rd_rac = nullptr;
if (Rd_rc != nullptr)
delete[] Rd_rc;
Rd_rc = nullptr;
if (A_rzc != nullptr) {
for (int i = 0; i < nrc; i++)
delete[] A_rzc[i];
}
A_rzc = nullptr;
if (Tt_rac != nullptr) {
for (int i = 0; i < nrc; i++)
delete[] Tt_rac[i];
}
Tt_rac = nullptr;
if (Tt_rc != nullptr)
delete[] Tt_rc;
Tt_rc = nullptr;
if (F_rzc != nullptr) {
for (int i = 0; i < nrc; i++)
delete[] F_rzc[i];
}
F_rzc = nullptr;
this->FreeConvInput();
}
void MCMLConv::RunConv () {
ConvRd_ra();
ConvRd_r();
ConvA_rz();
ConvTt_ra();
ConvTt_r();
ConvA2F();
}
void MCMLConv::ConvA2F () {
short irc, iz;
short nz = mcmlModel.nz;
double mua;
for (irc = 0; irc < nrc; irc++) {
for (iz = 0; iz < nz; iz++) {
mua = mcmlModel.GetMuaAtIz(iz);
if (mua > 0.0)
F_rzc[irc][iz] = A_rzc[irc][iz]/mua; // F in J/cm2
}
}
}
double MCMLConv::CenterHalfMaxDepth () {
short iz;
short nz = mcmlModel.nz;
double dz = mcmlModel.dz;
double depth = 0;
for (iz = 0; iz < nz; iz++) {
if (F_rzc[0][iz] <= 0.5*F_rzc[0][0]) {
depth = (iz + 0.5)*dz;
break;
}
}
return depth;
}
double MCMLConv::SurfaceHalfMaxWidth () {
short irc;
double width = 0;
for (irc = 0; irc < nrc; irc++) {
if (F_rzc[irc][0] <= 0.5*F_rzc[0][0]) {
width = 2*(irc + 0.5)*drc;
break;
}
}
return width;
}
void MCMLConv::ConvRd_ra () {
short irc, ia;
double rc;
double P = beam.P;
double R = beam.R;
for (irc = 0; irc < nrc; irc++) {
rc = (irc + 0.5)*drc;
convVar.r = rc;
convVar.tree = nullptr; // init the tree
for (ia = 0; ia < mcmlModel.na; ia++) {
convVar.ia = ia;
if (beam.type == Beam::FLAT)
Rd_rac[irc][ia] = 2*P/(R*R)*FlatIntegration(&Rd_raFGIntegrand, this);
else // Gaussian
Rd_rac[irc][ia] = 4*P/(R*R)*GaussIntegration(&Rd_raFGIntegrand, this);
}
Node::FreeTree(convVar.tree);
}
}
void MCMLConv::ConvRd_r () {
short irc;
double rc;
double P = beam.P;
double R = beam.R;
for (irc = 0; irc < nrc; irc++) {
rc = (irc + 0.5)*drc;
convVar.r = rc;
if (beam.type == Beam::FLAT)
Rd_rc[irc] = 2*P/(R*R)*FlatIntegration(&Rd_rFGIntegrand, this);
else // Gaussian
Rd_rc[irc] = 4*P/(R*R)*GaussIntegration(&Rd_rFGIntegrand, this);
}
}
void MCMLConv::ConvA_rz () {
short irc, iz;
double rc;
double P = beam.P;
double R = beam.R;
for (irc = 0; irc < nrc; irc++) {
rc = (irc + 0.5)*drc;
convVar.r = rc;
convVar.tree = nullptr; // init the tree
for (iz = 0; iz < mcmlModel.nz; iz++) {
convVar.iz = iz;
if (beam.type == Beam::FLAT)
A_rzc[irc][iz] = 2*P/(R*R)*FlatIntegration(&A_rzFGIntegrand, this);
else // Gaussian
A_rzc[irc][iz] = 4*P/(R*R)*GaussIntegration(&A_rzFGIntegrand, this);
}
Node::FreeTree(convVar.tree);
}
}
void MCMLConv::ConvTt_ra () {
short irc, ia;
double rc;
double P = beam.P;
double R = beam.R;
for (irc = 0; irc < nrc; irc++) {
rc = (irc + 0.5)*drc;
convVar.r = rc;
convVar.tree = nullptr; // init the tree
for (ia = 0; ia < mcmlModel.na; ia++) {
convVar.ia = ia;
if (beam.type == Beam::FLAT)
Tt_rac[irc][ia] = 2*P/(R*R)*FlatIntegration(&Tt_raFGIntegrand, this);
else // Gaussian
Tt_rac[irc][ia] = 4*P/(R*R)*GaussIntegration(&Tt_raFGIntegrand, this);
}
Node::FreeTree(convVar.tree);
}
}
void MCMLConv::ConvTt_r () {
short irc;
double rc;
double P = beam.P;
double R = beam.R;
for (irc = 0; irc < nrc; irc++) {
rc = (irc + 0.5)*drc;
convVar.r = rc;
if (beam.type == Beam::FLAT)
Tt_rc[irc] = 2*P/(R*R)*FlatIntegration(&Tt_rFGIntegrand, this);
else // Gaussian
Tt_rc[irc] = 4*P/(R*R)*GaussIntegration(&Tt_rFGIntegrand, this);
}
}
double RT_raInterp(double r2, double ** RT_ra, MCMLConv * mcmlConv) {
// Interpolate for the arrays Rd_ra[] or Tt_ra[].
short nr = mcmlConv->mcmlModel.nr;
short ia = mcmlConv->convVar.ia;
short ir2lo;
double RT_lo, RT_hi, RT_at_r2;
double ir2 = r2/mcmlConv->mcmlModel.dr;
if (nr < 3)
RT_at_r2 = RT_ra[0][ia];
else if (ir2 < (nr - 1.5)) { // interpolation
ir2lo = std::max<short>(0, (short) (ir2 - 0.5)); // truncation
RT_lo = RT_ra[ir2lo][ia];
RT_hi = RT_ra[ir2lo + 1][ia];
RT_at_r2 = RT_lo + (RT_hi - RT_lo)*(ir2 - ir2lo - 0.5);
}
else { // extrapolation
ir2lo = nr - 3;
RT_lo = RT_ra[ir2lo][ia];
RT_hi = RT_ra[ir2lo + 1][ia];
if (RT_lo >= RT_hi) // Noise test
RT_at_r2 = RT_lo + (RT_hi - RT_lo)*(ir2 - ir2lo - 0.5);
else
RT_at_r2 = 0.0;
}
return std::max<double>(0, RT_at_r2);
}
double RT_rInterp(double r2, double * RT_r, MCMLConv * mcmlConv) {
// Interpolate for the arrays Rd_r[] or Tt_r[].
short nr = mcmlConv->mcmlModel.nr;
short ir2lo;
double RT_lo, RT_hi, RT_at_r2;
double ir2 = r2/mcmlConv->mcmlModel.dr;
if (nr < 3)
RT_at_r2 = RT_r[0];
else if (ir2 < (nr - 1.5)) { // interpolation
ir2lo = std::max<short>(0, (short) (ir2 - 0.5)); // truncation
RT_lo = RT_r[ir2lo];
RT_hi = RT_r[ir2lo + 1];
RT_at_r2 = RT_lo + (RT_hi - RT_lo)*(ir2 - ir2lo - 0.5);
}
else { // extrapolation
ir2lo = nr - 3;
RT_lo = RT_r[ir2lo];
RT_hi = RT_r[ir2lo + 1];
if (RT_lo >= RT_hi) // Noise test
RT_at_r2 = RT_lo + (RT_hi - RT_lo)*(ir2 - ir2lo - 0.5);
else
RT_at_r2 = 0.0;
}
return std::max<double>(0, RT_at_r2);
}
double A_rzInterp(double r2, MCMLConv * mcmlConv) {
// Interpolate for the arrays A_rz[]
double ** A_rz = mcmlConv->mcmlModel.A_rz;
short nr = mcmlConv->mcmlModel.nr;
short iz = mcmlConv->convVar.iz;
short ir2lo;
double A_lo, A_hi, A_at_r2;
double ir2 = r2/mcmlConv->mcmlModel.dr;
if (nr < 3)
A_at_r2 = A_rz[0][iz];
else if (ir2 < (nr - 1.5)) { // interpolation
ir2lo = std::max<short>(0, (short) (ir2 - 0.5)); // truncation
A_lo = A_rz[ir2lo][iz];
A_hi = A_rz[ir2lo + 1][iz];
A_at_r2 = A_lo + (A_hi - A_lo)*(ir2 - ir2lo - 0.5);
}
else { // extrapolation
ir2lo = nr - 3;
A_lo = A_rz[ir2lo][iz];
A_hi = A_rz[ir2lo + 1][iz];
if (A_lo >= A_hi) // Noise test
A_at_r2 = A_lo + (A_hi - A_lo)*(ir2 - ir2lo - 0.5);
else
A_at_r2 = 0.0;
}
return std::max<double>(0, A_at_r2);
}
double ITheta(double r, double r2, double R) {
double temp;
if (R >= (r + r2))
temp = 1;
else if (fabs(r - r2) <= R) {
temp = (r*r + r2*r2 - R*R)/(2*r*r2);
if (fabs(temp) > 1)
temp = SIGN(temp);
temp = acos(temp)/PI;
}
else // R < fabs(r-r2)
temp = 0;
return temp;
}
double ModifiedBessI0(double x) {
/* Modified Bessel function exp(-x) I0(x), for x >=0.
We modified from the original bessi0(). Instead of
I0(x) itself, it returns I0(x) exp(-x).
*/
double ax, y, ans;
ax = fabs(x);
if (ax < 3.75) {
y = x/3.75;
y *= y;
ans = exp(-ax)*(1.0 + y*(3.5156229 + y*(3.0899424 + y*(1.2067492
+ y*(0.2659732 + y*(0.360768e-1 + y*0.45813e-2))))));
} else {
y = 3.75/ax;
ans = (1/sqrt(ax))*(0.39894228 + y*(0.1328592e-1
+ y*(0.225319e-2 + y*(-0.157565e-2 + y*(0.916281e-2
+ y*(-0.2057706e-1 + y*(0.2635537e-1 + y*(-0.1647633e-1
+ y * 0.392377e-2))))))));
}
return ans;
}
double ExpBessI0(double r, double r2, double R) {
double _RR = 1/(R*R);
double x = 4*r*r2*_RR;
double y = 2*(r2*r2 + r*r)*_RR;
double expbess = exp(-y + x)*ModifiedBessI0(x);
return expbess;
}
double Rd_raFGIntegrand(double r2, void * params) {
/* Convolution integrand for either flat or gaussian beams.
See comments for A_rzFGIntegrand().
r" in the integration. */
MCMLConv * mcmlConv = (MCMLConv *) params;
double f;
double ** RT_ra = mcmlConv->mcmlModel.Rd_ra;
double Rd_at_r2 = RT_raInterp(r2, RT_ra, mcmlConv);
double R = mcmlConv->beam.R;
double r = mcmlConv->convVar.r;
Node * tree = mcmlConv->convVar.tree;
Node * link = Node::SearchNode(tree, r2);
if (link != nullptr) // f in tree.
f = link->y;
else {
if (mcmlConv->beam.type == Beam::FLAT)
f = ITheta(r, r2, R);
else // Gaussian
f = ExpBessI0(r, r2, R);
Node::InsertNode(tree, r2, f);
}
f *= Rd_at_r2*r2;
return f;
}
double Rd_rFGIntegrand(double r2, void * params) {
/* Convolution integrand for either flat or gaussian beams.
See comments for A_rzFGIntegrand().
r" in the integration
*/
MCMLConv * mcmlConv = (MCMLConv *) params;
double f;
double * RT_r = mcmlConv->mcmlModel.Rd_r;
double Rd_at_r2 = RT_rInterp(r2, RT_r, mcmlConv);
double R = mcmlConv->beam.R;
double r = mcmlConv->convVar.r;
if (mcmlConv->beam.type == Beam::FLAT)
f = Rd_at_r2*ITheta(r, r2, R)*r2;
else // Gaussian
f = Rd_at_r2*ExpBessI0(r, r2, R)*r2;
return f;
}
double A_rzFGIntegrand(double r2, void * params) {
/* Convolution integrand for either flat or gaussian beams.
Return the integrand for the convolution integral.
r2 is the r" in the formula shown in the manual.
When r2 is in the range of recorded array, interpolation
is used to evaluate the diffuse reflectance at r2.
Note that since the last grid elements collect all the
photon weight that falls beyond the grid system, we should
avoid using them in the convolution.
r" in the integration
*/
MCMLConv * mcmlConv = (MCMLConv *) params;
double f;
double A_at_r2 = A_rzInterp(r2, mcmlConv);
double R = mcmlConv->beam.R;
double r = mcmlConv->convVar.r;
Node * tree = mcmlConv->convVar.tree;
Node * link = Node::SearchNode(tree, r2);
if (link != nullptr) // f in tree
f = link->y;
else {
if (mcmlConv->beam.type == Beam::FLAT)
f = ITheta(r, r2, R);
else // Gaussian
f = ExpBessI0(r, r2, R);
Node::InsertNode(tree, r2, f);
}
f *= A_at_r2*r2;
return f;
}
double Tt_raFGIntegrand(double r2, void * params) {
/* Convolution integrand for either flat or gaussian beams.
See comments for A_rzFGIntegrand().
r" in the integration.
*/
MCMLConv * mcmlConv = (MCMLConv *) params;
double f;
double ** TT_ra = mcmlConv->mcmlModel.Tt_ra;
double Tt_at_r2 = RT_raInterp(r2, TT_ra, mcmlConv);
double R = mcmlConv->beam.R;
double r = mcmlConv->convVar.r;
Node * tree = mcmlConv->convVar.tree;
Node * link = Node::SearchNode(tree, r2);
if (link != nullptr) // f in tree
f = link->y;
else {
if (mcmlConv->beam.type == Beam::FLAT)
f = ITheta(r, r2, R);
else // Gaussian
f = ExpBessI0(r, r2, R);
Node::InsertNode(tree, r2, f);
}
f *= Tt_at_r2*r2;
return f;
}
double Tt_rFGIntegrand(double r2, void * params) {
/* Convolution integrand for either flat or gaussian beams.
See comments for A_rzFGIntegrand().
r" in the integration
*/
MCMLConv * mcmlConv = (MCMLConv *) params;
double f;
double * TT_r = mcmlConv->mcmlModel.Tt_r;
double Tt_at_r2 = RT_rInterp(r2, TT_r, mcmlConv);
double R = mcmlConv->beam.R;
double r = mcmlConv->convVar.r;
if (mcmlConv->beam.type == Beam::FLAT)
f = Tt_at_r2*ITheta(r, r2, R)*r2;
else // Gaussian
f = Tt_at_r2*ExpBessI0(r, r2, R)*r2;
return f;
}
double IntegrateQuad(double (*func) (double x, void * params),
double a, double b, MCMLConv * mcmlConv) {
gsl_integration_workspace * workPtr
= gsl_integration_workspace_alloc (2500);
double absError = 1.0e-5; // to avoid round-off problems
double relError = 1.0e-5; // the result will usually be much better
double result; // the result from the integration
double error; // the estimated error from the integration
gsl_function integralFunction;
void * paramsPtr = mcmlConv;
integralFunction.function = func;
integralFunction.params = paramsPtr;
gsl_integration_qags (&integralFunction, a, b, absError, relError, 2500,
workPtr, &result, &error);
gsl_integration_workspace_free (workPtr);
return result;
}
double FlatIntegration(double (*func) (double x, void * params),
MCMLConv * mcmlConv) {
double rc = mcmlConv->convVar.r;
double R = mcmlConv->beam.R;
double b_max = (mcmlConv->mcmlModel.nr - 0.5)*mcmlConv->mcmlModel.dr;
double a = std::max<double>(0, rc - R);
double b = std::min<double>(b_max, rc + R);
if (a >= b)
return 0;
else
return IntegrateQuad(func, a, b, mcmlConv);
}
double GaussIntegration(double (*func) (double x, void * params),
MCMLConv * mcmlConv) {
// Used by convolution over Gaussian beam. Ignore the value
// beyond GAUSSLIMIT radius.
double rc = mcmlConv->convVar.r;
double R = mcmlConv->beam.R;
double b_max = (mcmlConv->mcmlModel.nr - 0.5)*mcmlConv->mcmlModel.dr;
double a = std::max<double>(0, (rc - GAUSSLIMIT * R));
double b = std::min<double>(b_max, (rc + GAUSSLIMIT * R));
if (a >= b)
return 0;
else
return IntegrateQuad(func, a, b, mcmlConv);
}