10void Dfact(
const int n, std::vector<std::vector<double> >& a,
11 std::vector<int>& ir,
int& ifail,
double& det,
int& jfail) {
13 const double g1 = 1.e-19;
14 const double g2 = 1.e-19;
16 double tf, p, q, t, s11, s12;
24 for (
int j = 1; j <= n; ++j) {
26 p = fabs(a[j - 1][j - 1]);
34 det *= a[j - 1][j - 1];
35 a[j - 1][j - 1] = 1. / a[j - 1][j - 1];
39 if (jfail == 0) jfail = -1;
42 if (jfail == 0) jfail = +1;
46 for (
int i = j + 1; i <= n; ++i) {
47 q = fabs(a[i - 1][j - 1]);
53 for (
int l = 1; l <= n; ++l) {
55 a[j - 1][l - 1] = a[k - 1][l - 1];
59 ir[nxch - 1] = j * 4096 + k;
66 det *= a[j - 1][j - 1];
67 a[j - 1][j - 1] = 1. / a[j - 1][j - 1];
71 if (jfail == 0) jfail = -1;
74 if (jfail == 0) jfail = +1;
76 for (k = j + 1; k <= n; ++k) {
77 s11 = -a[j - 1][k - 1];
80 a[j - 1][k - 1] = -s11 * a[j - 1][j - 1];
81 a[k - 1][j] = -(s12 + a[j - 1][j] * a[k - 1][j - 1]);
84 for (
int i = 1; i <= j - 1; ++i) {
85 s11 += a[i - 1][k - 1] * a[j - 1][i - 1];
86 s12 += a[i - 1][j] * a[k - 1][i - 1];
88 a[j - 1][k - 1] = -s11 * a[j - 1][j - 1];
89 a[k - 1][j] = -a[j - 1][j] * a[k - 1][j - 1] - s12;
93 if (nxch % 2 != 0) det = -det;
94 if (jfail != 0) det = 0.;
98void Dfeqn(
const int n, std::vector<std::vector<double> >& a,
99 std::vector<int>& ir, std::vector<double>& b) {
106 int nxch = ir[n - 1];
108 for (
int m = 1; m <= nxch; ++m) {
121 for (
int i = 2; i <= n; ++i) {
123 for (
int j = 1; j <= i - 1; ++j) {
124 s21 += a[i - 1][j - 1] * b[j - 1];
126 b[i - 1] = -a[i - 1][i - 1] * s21;
129 for (
int i = 1; i <= n - 1; ++i) {
131 for (
int j = 1; j <= i; ++j) {
132 s22 += a[n - i - 1][n - j] * b[n - j];
138void Dfinv(
const int n, std::vector<std::vector<double> >& a,
139 std::vector<int>& ir) {
142 double s31, s32, s33, s34;
145 a[1][0] = -a[1][1] * a[0][0] * a[1][0];
148 for (
int i = 3; i <= n; ++i) {
149 for (
int j = 1; j <= i - 2; ++j) {
151 s32 = a[j - 1][i - 1];
152 for (
int k = j; k <= i - 2; ++k) {
153 s31 += a[k - 1][j - 1] * a[i - 1][k - 1];
154 s32 += a[j - 1][k] * a[k][i - 1];
157 -a[i - 1][i - 1] * (s31 + a[i - 2][j - 1] * a[i - 1][i - 2]);
158 a[j - 1][i - 1] = -s32;
160 a[i - 1][i - 2] = -a[i - 1][i - 1] * a[i - 2][i - 2] * a[i - 1][i - 2];
161 a[i - 2][i - 1] = -a[i - 2][i - 1];
165 for (
int i = 1; i <= n - 1; ++i) {
166 for (
int j = 1; j <= i; ++j) {
167 s33 = a[i - 1][j - 1];
168 for (
int k = 1; k <= n - i; ++k) {
169 s33 += a[i + k - 1][j - 1] * a[i - 1][i + k - 1];
171 a[i - 1][j - 1] = s33;
173 for (
int j = 1; j <= n - i; ++j) {
175 for (
int k = j; k <= n - i; ++k) {
176 s34 += a[i + k - 1][i + j - 1] * a[i - 1][i + k - 1];
178 a[i - 1][i + j - 1] = s34;
182 int nxch = ir[n - 1];
183 if (nxch == 0)
return;
185 for (
int m = 1; m <= nxch; ++m) {
186 int k = nxch - m + 1;
190 for (k = 1; k <= n; ++k) {
191 ti = a[k - 1][i - 1];
192 a[k - 1][i - 1] = a[k - 1][j - 1];
193 a[k - 1][j - 1] = ti;
216void Deqinv(
const int n, std::vector<std::vector<double> >& a,
int& ifail,
217 std::vector<double>& b) {
221 double b1, b2, c11, c12, c13, c21, c22, c23, c31, c32, c33;
226 for (
int i = 0; i < n; ++i) ir[i] = 0;
240 Dfact(n, a, ir, ifail, det, jfail);
241 if (ifail != 0)
return;
247 c11 = a[1][1] * a[2][2] - a[1][2] * a[2][1];
248 c12 = a[1][2] * a[2][0] - a[1][0] * a[2][2];
249 c13 = a[1][0] * a[2][1] - a[1][1] * a[2][0];
250 c21 = a[2][1] * a[0][2] - a[2][2] * a[0][1];
251 c22 = a[2][2] * a[0][0] - a[2][0] * a[0][2];
252 c23 = a[2][0] * a[0][1] - a[2][1] * a[0][0];
253 c31 = a[0][1] * a[1][2] - a[0][2] * a[1][1];
254 c32 = a[0][2] * a[1][0] - a[0][0] * a[1][2];
255 c33 = a[0][0] * a[1][1] - a[0][1] * a[1][0];
265 det = c23 * c12 - c22 * c13;
269 det = c22 * c33 - c23 * c32;
275 det = c23 * c12 - c22 * c13;
279 det = c13 * c32 - c12 * c33;
302 b[0] = a[0][0] * b1 + a[0][1] * b2 + a[0][2] * b[2];
303 b[1] = a[1][0] * b1 + a[1][1] * b2 + a[1][2] * b[2];
304 b[2] = a[2][0] * b1 + a[2][1] * b2 + a[2][2] * b[2];
307 det = a[0][0] * a[1][1] - a[0][1] * a[1][0];
314 a[0][1] = -s * a[0][1];
315 a[1][0] = -s * a[1][0];
316 a[1][1] = s * a[0][0];
320 b[0] = c11 * b1 + a[0][1] * b[1];
321 b[1] = a[1][0] * b1 + a[1][1] * b[1];
328 a[0][0] = 1. / a[0][0];
329 b[0] = a[0][0] * b[0];
333void Cfact(
const int n, std::vector<std::vector<std::complex<double> > >& a,
334 std::vector<int>& ir,
int& ifail, std::complex<double>& det,
337 const double g1 = 1.e-19;
338 const double g2 = 1.e-19;
340 std::complex<double> tf;
342 std::complex<double> s11, s12;
348 det = std::complex<double>(1., 0.);
350 for (
int j = 1; j <= n; ++j) {
352 p = std::max(fabs(real(a[j - 1][j - 1])), fabs(imag(a[j - 1][j - 1])));
355 det = std::complex<double>(0., 0.);
360 det *= a[j - 1][j - 1];
361 a[j - 1][j - 1] = std::complex<double>(1., 0.) / a[j - 1][j - 1];
362 t = std::max(fabs(real(det)), fabs(imag(det)));
364 det = std::complex<double>(0., 0.);
365 if (jfail == 0) jfail = -1;
367 det = std::complex<double>(1., 0.);
368 if (jfail == 0) jfail = +1;
372 for (
int i = j + 1; i <= n; ++i) {
373 q = std::max(fabs(real(a[i - 1][j - 1])), fabs(imag(a[i - 1][j - 1])));
374 if (q <= p)
continue;
379 for (
int l = 1; l <= n; ++l) {
380 tf = a[j - 1][l - 1];
381 a[j - 1][l - 1] = a[k - 1][l - 1];
382 a[k - 1][l - 1] = tf;
385 ir[nxch - 1] = j * 4096 + k;
386 }
else if (p <= 0.) {
387 det = std::complex<double>(0., 0.);
392 det *= a[j - 1][j - 1];
393 a[j - 1][j - 1] = 1. / a[j - 1][j - 1];
394 t = std::max(fabs(real(det)), fabs(imag(det)));
396 det = std::complex<double>(0., 0.);
397 if (jfail == 0) jfail = -1;
399 det = std::complex<double>(1., 0.);
400 if (jfail == 0) jfail = +1;
402 for (k = j + 1; k <= n; ++k) {
403 s11 = -a[j - 1][k - 1];
406 a[j - 1][k - 1] = -s11 * a[j - 1][j - 1];
407 a[k - 1][j] = -(s12 + a[j - 1][j] * a[k - 1][j - 1]);
410 for (
int i = 1; i <= j - 1; ++i) {
411 s11 += a[i - 1][k - 1] * a[j - 1][i - 1];
412 s12 += a[i - 1][j] * a[k - 1][i - 1];
414 a[j - 1][k - 1] = -s11 * a[j - 1][j - 1];
415 a[k - 1][j] = -a[j - 1][j] * a[k - 1][j - 1] - s12;
419 if (nxch % 2 != 0) det = -det;
420 if (jfail != 0) det = std::complex<double>(0., 0.);
424void Cfinv(
const int n, std::vector<std::vector<std::complex<double> > >& a,
425 std::vector<int>& ir) {
427 std::complex<double> ti;
428 std::complex<double> s31, s32, s33, s34;
431 a[1][0] = -a[1][1] * a[0][0] * a[1][0];
434 for (
int i = 3; i <= n; ++i) {
435 for (
int j = 1; j <= i - 2; ++j) {
436 s31 = std::complex<double>(0., 0.);
437 s32 = a[j - 1][i - 1];
438 for (
int k = j; k <= i - 2; ++k) {
439 s31 += a[k - 1][j - 1] * a[i - 1][k - 1];
440 s32 += a[j - 1][k] * a[k][i - 1];
443 -a[i - 1][i - 1] * (s31 + a[i - 2][j - 1] * a[i - 1][i - 2]);
444 a[j - 1][i - 1] = -s32;
446 a[i - 1][i - 2] = -a[i - 1][i - 1] * a[i - 2][i - 2] * a[i - 1][i - 2];
447 a[i - 2][i - 1] = -a[i - 2][i - 1];
451 for (
int i = 1; i <= n - 1; ++i) {
452 for (
int j = 1; j <= i; ++j) {
453 s33 = a[i - 1][j - 1];
454 for (
int k = 1; k <= n - i; ++k) {
455 s33 += a[i + k - 1][j - 1] * a[i - 1][i + k - 1];
457 a[i - 1][j - 1] = s33;
459 for (
int j = 1; j <= n - i; ++j) {
460 s34 = std::complex<double>(0., 0.);
461 for (
int k = j; k <= n - i; ++k) {
462 s34 += a[i + k - 1][i + j - 1] * a[i - 1][i + k - 1];
464 a[i - 1][i + j - 1] = s34;
468 int nxch = ir[n - 1];
469 if (nxch == 0)
return;
471 for (
int m = 1; m <= nxch; ++m) {
472 int k = nxch - m + 1;
476 for (k = 1; k <= n; ++k) {
477 ti = a[k - 1][i - 1];
478 a[k - 1][i - 1] = a[k - 1][j - 1];
479 a[k - 1][j - 1] = ti;
494void Cinv(
const int n, std::vector<std::vector<std::complex<double> > >& a,
498 std::complex<double> det, temp, s;
499 std::complex<double> c11, c12, c13, c21, c22, c23, c31, c32, c33;
504 for (
int i = 0; i < n; ++i) ir[i] = 0;
518 Cfact(n, a, ir, ifail, det, jfail);
519 if (ifail != 0)
return;
524 c11 = a[1][1] * a[2][2] - a[1][2] * a[2][1];
525 c12 = a[1][2] * a[2][0] - a[1][0] * a[2][2];
526 c13 = a[1][0] * a[2][1] - a[1][1] * a[2][0];
527 c21 = a[2][1] * a[0][2] - a[2][2] * a[0][1];
528 c22 = a[2][2] * a[0][0] - a[2][0] * a[0][2];
529 c23 = a[2][0] * a[0][1] - a[2][1] * a[0][0];
530 c31 = a[0][1] * a[1][2] - a[0][2] * a[1][1];
531 c32 = a[0][2] * a[1][0] - a[0][0] * a[1][2];
532 c33 = a[0][0] * a[1][1] - a[0][1] * a[1][0];
533 t1 = fabs(real(a[0][0])) + fabs(imag(a[0][0]));
534 t2 = fabs(real(a[1][0])) + fabs(imag(a[1][0]));
535 t3 = fabs(real(a[2][0])) + fabs(imag(a[2][0]));
542 det = c23 * c12 - c22 * c13;
546 det = c22 * c33 - c23 * c32;
552 det = c23 * c12 - c22 * c13;
556 det = c13 * c32 - c12 * c33;
560 if (real(det) == 0. && imag(det) == 0.) {
576 det = a[0][0] * a[1][1] - a[0][1] * a[1][0];
577 if (real(det) == 0. && imag(det) == 0.) {
581 s = std::complex<double>(1., 0.) / det;
583 a[0][1] = -s * a[0][1];
584 a[1][0] = -s * a[1][0];
585 a[1][1] = s * a[0][0];
589 if (real(a[0][0]) == 0. && imag(a[0][0]) == 0.) {
593 a[0][0] = std::complex<double>(1., 0.) / a[0][0];
606 const double xGK[8] = {9.914553711208126e-01, 9.491079123427585e-01,
607 8.648644233597691e-01, 7.415311855993944e-01,
608 5.860872354676911e-01, 4.058451513773972e-01,
609 2.077849550078985e-01, 0.0e+00};
611 const double wGK[8] = {2.293532201052922e-02, 6.309209262997855e-02,
612 1.047900103222502e-01, 1.406532597155259e-01,
613 1.690047266392679e-01, 1.903505780647854e-01,
614 2.044329400752989e-01, 2.094821410847278e-01};
616 const double wG[4] = {1.294849661688697e-01, 2.797053914892767e-01,
617 3.818300505051189e-01, 4.179591836734694e-01};
620 const double center = 0.5 * (a + b);
622 const double halfLength = 0.5 * (b - a);
624 double fC = f(center);
626 double resG = fC * wG[3];
628 double resK = fC * wGK[7];
630 for (
int j = 0; j < 3; ++j) {
631 const int i = j * 2 + 1;
633 const double x = halfLength * xGK[i];
635 const double fSum = f(center - x) + f(center + x);
636 resG += wG[j] * fSum;
637 resK += wGK[i] * fSum;
640 for (
int j = 0; j < 4; ++j) {
642 const double x = halfLength * xGK[i];
643 const double fSum = f(center - x) + f(center + x);
644 resK += wGK[i] * fSum;
647 return resK * halfLength;
650double Divdif(
const std::vector<double>& f,
const std::vector<double>& a,
651 int nn,
double x,
int mm) {
662 std::cerr <<
"Divdif:\n";
663 std::cerr <<
" Array length < 2.\n";
667 std::cerr <<
"Divdif:\n";
668 std::cerr <<
" Interpolation order < 1.\n";
673 if (fabs(x - a[0]) < 1.e-6 * (fabs(a[0]) + fabs(a[nn - 1]))) {
676 if (fabs(x - a[nn - 1]) < 1.e-6 * (fabs(a[0]) + fabs(a[nn - 1]))) {
683 if (mm <= mmax && mm <= n - 1) {
696 if (a[0] > a[n - 1]) {
700 if (x > a[mid - 1]) {
705 }
while (iy - ix > 1);
710 if (x < a[mid - 1]) {
715 }
while (iy - ix > 1);
719 int npts = m + 2 - (m % 2);
723 const int isub = ix + l;
724 if ((1 > isub) || (isub > n)) {
730 t[ip - 1] = a[isub - 1];
731 d[ip - 1] = f[isub - 1];
741 bool extra = npts != mplus;
744 for (l = 1; l <= m; l++) {
746 const int isub = mplus - l;
747 d[m + 1] = (d[m + 1] - d[m - 1]) / (t[m + 1] - t[isub - 1]);
750 for (
int j = l; j <= m; j++) {
751 const int isub = i - l;
752 d[i - 1] = (d[i - 1] - d[i - 1 - 1]) / (t[i - 1] - t[isub - 1]);
758 double sum = d[mplus - 1];
760 sum = 0.5 * (sum + d[m + 1]);
763 for (l = 1; l <= m; l++) {
764 sum = d[j - 1] + (x - t[j - 1]) * sum;
770bool Boxin3(
const std::vector<std::vector<std::vector<double> > >& value,
771 const std::vector<double>& xAxis,
772 const std::vector<double>& yAxis,
773 const std::vector<double>& zAxis,
774 const int nx,
const int ny,
const int nz,
775 const double xx,
const double yy,
const double zz,
776 double& f,
const int iOrder) {
785 int iX0 = 0, iX1 = 0;
786 int iY0 = 0, iY1 = 0;
787 int iZ0 = 0, iZ1 = 0;
788 double fX[4], fY[4], fZ[4];
791 const double x = std::min(std::max(xx, std::min(xAxis[0], xAxis[nx - 1])),
792 std::max(xAxis[0], xAxis[nx - 1]));
793 const double y = std::min(std::max(yy, std::min(yAxis[0], yAxis[ny - 1])),
794 std::max(yAxis[0], yAxis[ny - 1]));
795 const double z = std::min(std::max(zz, std::min(zAxis[0], zAxis[nz - 1])),
796 std::max(zAxis[0], zAxis[nz - 1]));
799 if (iOrder < 0 || iOrder > 2 || nx < 1 || ny < 1 || nz < 1) {
800 std::cerr <<
"Boxin3:\n";
801 std::cerr <<
" Incorrect order or number of points.\n";
802 std::cerr <<
" No interpolation.\n";
807 if (iOrder == 0 || nx == 1) {
810 double dist = fabs(x - xAxis[0]);
812 for (
int i = 1; i < nx; i++) {
813 if (fabs(x - xAxis[i]) < dist) {
814 dist = fabs(x - xAxis[i]);
826 }
else if (iOrder == 1 || nx == 2) {
830 for (
int i = 1; i < nx; i++) {
831 if ((xAxis[i - 1] - x) * (x - xAxis[i]) >= 0.) {
836 if (xAxis[iGrid] == xAxis[iGrid - 1]) {
837 std::cerr <<
"Boxin3:\n";
838 std::cerr <<
" Incorrect grid; no interpolation.\n";
843 const double xLocal =
844 (x - xAxis[iGrid - 1]) / (xAxis[iGrid] - xAxis[iGrid - 1]);
853 }
else if (iOrder == 2) {
857 for (
int i = 1; i < nx; i++) {
858 if ((xAxis[i - 1] - x) * (x - xAxis[i]) >= 0.) {
863 const double xLocal =
864 (x - xAxis[iGrid - 1]) / (xAxis[iGrid] - xAxis[iGrid - 1]);
869 if (xAxis[iX0] == xAxis[iX0 + 1] || xAxis[iX0] == xAxis[iX0 + 2] ||
870 xAxis[iX0 + 1] == xAxis[iX0 + 2]) {
871 std::cerr <<
"Boxin3:\n";
872 std::cerr <<
" One or more grid points in x coincide.\n";
873 std::cerr <<
" No interpolation.\n";
877 fX[0] = (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
878 ((xAxis[iX0] - xAxis[iX0 + 1]) * (xAxis[iX0] - xAxis[iX0 + 2]));
880 (x - xAxis[iX0]) * (x - xAxis[iX0 + 2]) /
881 ((xAxis[iX0 + 1] - xAxis[iX0]) * (xAxis[iX0 + 1] - xAxis[iX0 + 2]));
883 (x - xAxis[iX0]) * (x - xAxis[iX0 + 1]) /
884 ((xAxis[iX0 + 2] - xAxis[iX0]) * (xAxis[iX0 + 2] - xAxis[iX0 + 1]));
885 }
else if (iGrid == nx - 1) {
888 if (xAxis[iX0] == xAxis[iX0 + 1] || xAxis[iX0] == xAxis[iX0 + 2] ||
889 xAxis[iX0 + 1] == xAxis[iX0 + 2]) {
890 std::cerr <<
"Boxin3:\n";
891 std::cerr <<
" One or more grid points in x coincide.\n";
892 std::cerr <<
" No interpolation.\n";
896 fX[0] = (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
897 ((xAxis[iX0] - xAxis[iX0 + 1]) * (xAxis[iX0] - xAxis[iX0 + 2]));
899 (x - xAxis[iX0]) * (x - xAxis[iX0 + 2]) /
900 ((xAxis[iX0 + 1] - xAxis[iX0]) * (xAxis[iX0 + 1] - xAxis[iX0 + 2]));
902 (x - xAxis[iX0]) * (x - xAxis[iX0 + 1]) /
903 ((xAxis[iX0 + 2] - xAxis[iX0]) * (xAxis[iX0 + 2] - xAxis[iX0 + 1]));
907 if (xAxis[iX0] == xAxis[iX0 + 1] || xAxis[iX0] == xAxis[iX0 + 2] ||
908 xAxis[iX0] == xAxis[iX0 + 3] || xAxis[iX0 + 1] == xAxis[iX0 + 2] ||
909 xAxis[iX0 + 1] == xAxis[iX0 + 3] ||
910 xAxis[iX0 + 2] == xAxis[iX0 + 3]) {
911 std::cerr <<
"Boxin3:\n";
912 std::cerr <<
" One or more grid points in x coincide.\n";
913 std::cerr <<
" No interpolation.\n";
917 fX[0] = (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
918 ((xAxis[iX0] - xAxis[iX0 + 1]) * (xAxis[iX0] - xAxis[iX0 + 2]));
920 (x - xAxis[iX0]) * (x - xAxis[iX0 + 2]) /
921 ((xAxis[iX0 + 1] - xAxis[iX0]) * (xAxis[iX0 + 1] - xAxis[iX0 + 2]));
923 (x - xAxis[iX0]) * (x - xAxis[iX0 + 1]) /
924 ((xAxis[iX0 + 2] - xAxis[iX0]) * (xAxis[iX0 + 2] - xAxis[iX0 + 1]));
925 fX[0] *= (1. - xLocal);
926 fX[1] = fX[1] * (1. - xLocal) + xLocal * (x - xAxis[iX0 + 2]) *
927 (x - xAxis[iX0 + 3]) /
928 ((xAxis[iX0 + 1] - xAxis[iX0 + 2]) *
929 (xAxis[iX0 + 1] - xAxis[iX0 + 3]));
930 fX[2] = fX[2] * (1. - xLocal) + xLocal * (x - xAxis[iX0 + 1]) *
931 (x - xAxis[iX0 + 3]) /
932 ((xAxis[iX0 + 2] - xAxis[iX0 + 1]) *
933 (xAxis[iX0 + 2] - xAxis[iX0 + 3]));
934 fX[3] = xLocal * (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
935 ((xAxis[iX0 + 3] - xAxis[iX0 + 1]) *
936 (xAxis[iX0 + 3] - xAxis[iX0 + 2]));
940 if (iOrder == 0 || ny == 1) {
943 double dist = fabs(y - yAxis[0]);
945 for (
int i = 1; i < ny; i++) {
946 if (fabs(y - yAxis[i]) < dist) {
947 dist = fabs(y - yAxis[i]);
958 }
else if (iOrder == 1 || ny == 2) {
962 for (
int i = 1; i < ny; i++) {
963 if ((yAxis[i - 1] - y) * (y - yAxis[i]) >= 0.) {
968 if (yAxis[iGrid] == yAxis[iGrid - 1]) {
969 std::cerr <<
"Boxin3:\n";
970 std::cerr <<
" Incorrect grid; no interpolation.\n";
975 const double yLocal =
976 (y - yAxis[iGrid - 1]) / (yAxis[iGrid] - yAxis[iGrid - 1]);
984 }
else if (iOrder == 2) {
988 for (
int i = 1; i < ny; i++) {
989 if ((yAxis[i - 1] - y) * (y - yAxis[i]) >= 0.) {
994 const double yLocal =
995 (y - yAxis[iGrid - 1]) / (yAxis[iGrid] - yAxis[iGrid - 1]);
999 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1000 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1001 fY[1] = (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1002 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1003 fY[2] = (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1004 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1009 if (yAxis[iY0] == yAxis[iY0 + 1] || yAxis[iY0] == yAxis[iY0 + 2] ||
1010 yAxis[iY0 + 1] == yAxis[iY0 + 2]) {
1011 std::cerr <<
"Boxin3:\n";
1012 std::cerr <<
" One or more grid points in y coincide.\n";
1013 std::cerr <<
" No interpolation.\n";
1017 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1018 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1020 (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1021 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1023 (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1024 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1025 }
else if (iGrid == ny - 1) {
1028 if (yAxis[iY0] == yAxis[iY0 + 1] || yAxis[iY0] == yAxis[iY0 + 2] ||
1029 yAxis[iY0 + 1] == yAxis[iY0 + 2]) {
1030 std::cerr <<
"Boxin3:\n";
1031 std::cerr <<
" One or more grid points in y coincide.\n";
1032 std::cerr <<
" No interpolation.\n";
1036 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1037 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1039 (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1040 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1042 (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1043 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1047 if (yAxis[iY0] == yAxis[iY0 + 1] || yAxis[iY0] == yAxis[iY0 + 2] ||
1048 yAxis[iY0] == yAxis[iY0 + 3] || yAxis[iY0 + 1] == yAxis[iY0 + 2] ||
1049 yAxis[iY0 + 1] == yAxis[iY0 + 3] ||
1050 yAxis[iY0 + 2] == yAxis[iY0 + 3]) {
1051 std::cerr <<
"Boxin3:\n";
1052 std::cerr <<
" One or more grid points in y coincide.\n";
1053 std::cerr <<
" No interpolation.\n";
1057 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1058 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1060 (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1061 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1063 (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1064 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1066 fY[0] *= (1. - yLocal);
1067 fY[1] = fY[1] * (1. - yLocal) + yLocal * (y - yAxis[iY0 + 2]) *
1068 (y - yAxis[iY0 + 3]) /
1069 ((yAxis[iY0 + 1] - yAxis[iY0 + 2]) *
1070 (yAxis[iY0 + 1] - yAxis[iY0 + 3]));
1071 fY[2] = fY[2] * (1. - yLocal) + yLocal * (y - yAxis[iY0 + 1]) *
1072 (y - yAxis[iY0 + 3]) /
1073 ((yAxis[iY0 + 2] - yAxis[iY0 + 1]) *
1074 (yAxis[iY0 + 2] - yAxis[iY0 + 3]));
1075 fY[3] = yLocal * (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1076 ((yAxis[iY0 + 3] - yAxis[iY0 + 1]) *
1077 (yAxis[iY0 + 3] - yAxis[iY0 + 2]));
1081 if (iOrder == 0 || nz == 1) {
1084 double dist = fabs(z - zAxis[0]);
1086 for (
int i = 1; i < nz; i++) {
1087 if (fabs(z - zAxis[i]) < dist) {
1088 dist = fabs(z - zAxis[i]);
1099 }
else if (iOrder == 1 || nz == 2) {
1103 for (
int i = 1; i < nz; i++) {
1104 if ((zAxis[i - 1] - z) * (z - zAxis[i]) >= 0.) {
1109 if (zAxis[iGrid] == zAxis[iGrid - 1]) {
1110 std::cerr <<
"Boxin3:\n";
1111 std::cerr <<
" Incorrect grid; no interpolation.\n";
1116 const double zLocal =
1117 (z - zAxis[iGrid - 1]) / (zAxis[iGrid] - zAxis[iGrid - 1]);
1122 fZ[0] = 1. - zLocal;
1125 }
else if (iOrder == 2) {
1129 for (
int i = 1; i < nz; i++) {
1130 if ((zAxis[i - 1] - z) * (z - zAxis[i]) >= 0.) {
1135 const double zLocal =
1136 (z - zAxis[iGrid - 1]) / (zAxis[iGrid] - zAxis[iGrid - 1]);
1140 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1141 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1142 fZ[1] = (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1143 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1144 fZ[2] = (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1145 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1150 if (zAxis[iZ0] == zAxis[iZ0 + 1] || zAxis[iZ0] == zAxis[iZ0 + 2] ||
1151 zAxis[iZ0 + 1] == zAxis[iZ0 + 2]) {
1152 std::cerr <<
"Boxin3:\n";
1153 std::cerr <<
" One or more grid points in z coincide.\n";
1154 std::cerr <<
" No interpolation.\n";
1158 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1159 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1161 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1162 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1164 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1165 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1166 }
else if (iGrid == nz - 1) {
1169 if (zAxis[iZ0] == zAxis[iZ0 + 1] || zAxis[iZ0] == zAxis[iZ0 + 2] ||
1170 zAxis[iZ0 + 1] == zAxis[iZ0 + 2]) {
1171 std::cerr <<
"Boxin3:\n";
1172 std::cerr <<
" One or more grid points in z coincide.\n";
1173 std::cerr <<
" No interpolation.\n";
1177 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1178 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1180 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1181 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1183 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1184 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1189 if (zAxis[iZ0] == zAxis[iZ0 + 1] || zAxis[iZ0] == zAxis[iZ0 + 2] ||
1190 zAxis[iZ0] == zAxis[iZ0 + 3] || zAxis[iZ0 + 1] == zAxis[iZ0 + 2] ||
1191 zAxis[iZ0 + 1] == zAxis[iZ0 + 3] ||
1192 zAxis[iZ0 + 2] == zAxis[iZ0 + 3]) {
1193 std::cerr <<
"Boxin3:\n";
1194 std::cerr <<
" One or more grid points in z coincide.\n";
1195 std::cerr <<
" No interpolation.\n";
1200 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1201 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1203 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1204 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1206 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1207 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1209 fZ[0] *= (1. - zLocal);
1210 fZ[1] = fZ[1] * (1. - zLocal) + zLocal * (z - zAxis[iZ0 + 2]) *
1211 (z - zAxis[iZ0 + 3]) /
1212 ((zAxis[iZ0 + 1] - zAxis[iZ0 + 2]) *
1213 (zAxis[iZ0 + 1] - zAxis[iZ0 + 3]));
1214 fZ[2] = fZ[2] * (1. - zLocal) + zLocal * (z - zAxis[iZ0 + 1]) *
1215 (z - zAxis[iZ0 + 3]) /
1216 ((zAxis[iZ0 + 2] - zAxis[iZ0 + 1]) *
1217 (zAxis[iZ0 + 2] - zAxis[iZ0 + 3]));
1218 fZ[3] = zLocal * (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1219 ((zAxis[iZ0 + 3] - zAxis[iZ0 + 1]) *
1220 (zAxis[iZ0 + 3] - zAxis[iZ0 + 2]));
1225 for (
int i = iX0; i <= iX1; ++i) {
1226 for (
int j = iY0; j <= iY1; ++j) {
1227 for (
int k = iZ0; k <= iZ1; ++k) {
1232 f += value[i][j][k] * fX[i - iX0] * fY[j - iY0] * fZ[k - iZ0];
bool Boxin3(const std::vector< std::vector< std::vector< double > > > &value, const std::vector< double > &xAxis, const std::vector< double > &yAxis, const std::vector< double > &zAxis, const int nx, const int ny, const int nz, const double xx, const double yy, const double zz, double &f, const int iOrder)
void Dfinv(const int n, std::vector< std::vector< double > > &a, std::vector< int > &ir)
void Dfact(const int n, std::vector< std::vector< double > > &a, std::vector< int > &ir, int &ifail, double &det, int &jfail)
void Cfact(const int n, std::vector< std::vector< std::complex< double > > > &a, std::vector< int > &ir, int &ifail, std::complex< double > &det, int &jfail)
double GaussKronrod15(double(*f)(const double), const double a, const double b)
Numerical integration using 15-point Gauss-Kronrod algorithm.
void Cinv(const int n, std::vector< std::vector< std::complex< double > > > &a, int &ifail)
double Divdif(const std::vector< double > &f, const std::vector< double > &a, int nn, double x, int mm)
void Deqinv(const int n, std::vector< std::vector< double > > &a, int &ifail, std::vector< double > &b)
void Cfinv(const int n, std::vector< std::vector< std::complex< double > > > &a, std::vector< int > &ir)
void Dfeqn(const int n, std::vector< std::vector< double > > &a, std::vector< int > &ir, std::vector< double > &b)