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);
725 if ((1 > isub) || (isub > n)) {
731 t[ip - 1] = a[isub - 1];
732 d[ip - 1] = f[isub - 1];
742 bool extra = npts != mplus;
745 for (
int l = 1; l <= m; l++) {
748 d[m + 1] = (d[m + 1] - d[m - 1]) / (t[m + 1] - t[isub - 1]);
751 for (
int j = l; j <= m; j++) {
753 d[i - 1] = (d[i - 1] - d[i - 1 - 1]) / (t[i - 1] - t[isub - 1]);
759 double sum = d[mplus - 1];
761 sum = 0.5 * (sum + d[m + 1]);
764 for (
int l = 1; l <= m; l++) {
765 sum = d[j - 1] + (x - t[j - 1]) * sum;
771bool Boxin3(std::vector<std::vector<std::vector<double> > >& value,
772 std::vector<double>& xAxis, std::vector<double>& yAxis,
773 std::vector<double>& zAxis,
int nx,
int ny,
int nz,
double xx,
774 double yy,
double zz,
double& f,
int iOrder) {
783 int iX0 = 0, iX1 = 0;
784 int iY0 = 0, iY1 = 0;
785 int iZ0 = 0, iZ1 = 0;
786 double fX[4], fY[4], fZ[4];
789 const double x = std::min(std::max(xx, std::min(xAxis[0], xAxis[nx - 1])),
790 std::max(xAxis[0], xAxis[nx - 1]));
791 const double y = std::min(std::max(yy, std::min(yAxis[0], yAxis[ny - 1])),
792 std::max(yAxis[0], yAxis[ny - 1]));
793 const double z = std::min(std::max(zz, std::min(zAxis[0], zAxis[nz - 1])),
794 std::max(zAxis[0], zAxis[nz - 1]));
797 if (iOrder < 0 || iOrder > 2 || nx < 1 || ny < 1 || nz < 1) {
798 std::cerr <<
"Boxin3:\n";
799 std::cerr <<
" Incorrect order or number of points.\n";
800 std::cerr <<
" No interpolation.\n";
805 if (iOrder == 0 || nx == 1) {
808 double dist =
fabs(x - xAxis[0]);
810 for (
int i = 1; i < nx; i++) {
811 if (
fabs(x - xAxis[i]) < dist) {
812 dist =
fabs(x - xAxis[i]);
824 }
else if (iOrder == 1 || nx == 2) {
828 for (
int i = 1; i < nx; i++) {
829 if ((xAxis[i - 1] - x) * (x - xAxis[i]) >= 0.) {
834 if (xAxis[iGrid] == xAxis[iGrid - 1]) {
835 std::cerr <<
"Boxin3:\n";
836 std::cerr <<
" Incorrect grid; no interpolation.\n";
841 const double xLocal =
842 (x - xAxis[iGrid - 1]) / (xAxis[iGrid] - xAxis[iGrid - 1]);
851 }
else if (iOrder == 2) {
855 for (
int i = 1; i < nx; i++) {
856 if ((xAxis[i - 1] - x) * (x - xAxis[i]) >= 0.) {
861 const double xLocal =
862 (x - xAxis[iGrid - 1]) / (xAxis[iGrid] - xAxis[iGrid - 1]);
867 if (xAxis[iX0] == xAxis[iX0 + 1] || xAxis[iX0] == xAxis[iX0 + 2] ||
868 xAxis[iX0 + 1] == xAxis[iX0 + 2]) {
869 std::cerr <<
"Boxin3:\n";
870 std::cerr <<
" One or more grid points in x coincide.\n";
871 std::cerr <<
" No interpolation.\n";
875 fX[0] = (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
876 ((xAxis[iX0] - xAxis[iX0 + 1]) * (xAxis[iX0] - xAxis[iX0 + 2]));
878 (x - xAxis[iX0]) * (x - xAxis[iX0 + 2]) /
879 ((xAxis[iX0 + 1] - xAxis[iX0]) * (xAxis[iX0 + 1] - xAxis[iX0 + 2]));
881 (x - xAxis[iX0]) * (x - xAxis[iX0 + 1]) /
882 ((xAxis[iX0 + 2] - xAxis[iX0]) * (xAxis[iX0 + 2] - xAxis[iX0 + 1]));
883 }
else if (iGrid == nx - 1) {
886 if (xAxis[iX0] == xAxis[iX0 + 1] || xAxis[iX0] == xAxis[iX0 + 2] ||
887 xAxis[iX0 + 1] == xAxis[iX0 + 2]) {
888 std::cerr <<
"Boxin3:\n";
889 std::cerr <<
" One or more grid points in x coincide.\n";
890 std::cerr <<
" No interpolation.\n";
894 fX[0] = (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
895 ((xAxis[iX0] - xAxis[iX0 + 1]) * (xAxis[iX0] - xAxis[iX0 + 2]));
897 (x - xAxis[iX0]) * (x - xAxis[iX0 + 2]) /
898 ((xAxis[iX0 + 1] - xAxis[iX0]) * (xAxis[iX0 + 1] - xAxis[iX0 + 2]));
900 (x - xAxis[iX0]) * (x - xAxis[iX0 + 1]) /
901 ((xAxis[iX0 + 2] - xAxis[iX0]) * (xAxis[iX0 + 2] - xAxis[iX0 + 1]));
905 if (xAxis[iX0] == xAxis[iX0 + 1] || xAxis[iX0] == xAxis[iX0 + 2] ||
906 xAxis[iX0] == xAxis[iX0 + 3] || xAxis[iX0 + 1] == xAxis[iX0 + 2] ||
907 xAxis[iX0 + 1] == xAxis[iX0 + 3] ||
908 xAxis[iX0 + 2] == xAxis[iX0 + 3]) {
909 std::cerr <<
"Boxin3:\n";
910 std::cerr <<
" One or more grid points in x coincide.\n";
911 std::cerr <<
" No interpolation.\n";
915 fX[0] = (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
916 ((xAxis[iX0] - xAxis[iX0 + 1]) * (xAxis[iX0] - xAxis[iX0 + 2]));
918 (x - xAxis[iX0]) * (x - xAxis[iX0 + 2]) /
919 ((xAxis[iX0 + 1] - xAxis[iX0]) * (xAxis[iX0 + 1] - xAxis[iX0 + 2]));
921 (x - xAxis[iX0]) * (x - xAxis[iX0 + 1]) /
922 ((xAxis[iX0 + 2] - xAxis[iX0]) * (xAxis[iX0 + 2] - xAxis[iX0 + 1]));
923 fX[0] *= (1. - xLocal);
924 fX[1] = fX[1] * (1. - xLocal) + xLocal * (x - xAxis[iX0 + 2]) *
925 (x - xAxis[iX0 + 3]) /
926 ((xAxis[iX0 + 1] - xAxis[iX0 + 2]) *
927 (xAxis[iX0 + 1] - xAxis[iX0 + 3]));
928 fX[2] = fX[2] * (1. - xLocal) + xLocal * (x - xAxis[iX0 + 1]) *
929 (x - xAxis[iX0 + 3]) /
930 ((xAxis[iX0 + 2] - xAxis[iX0 + 1]) *
931 (xAxis[iX0 + 2] - xAxis[iX0 + 3]));
932 fX[3] = xLocal * (x - xAxis[iX0 + 1]) * (x - xAxis[iX0 + 2]) /
933 ((xAxis[iX0 + 3] - xAxis[iX0 + 1]) *
934 (xAxis[iX0 + 3] - xAxis[iX0 + 2]));
938 if (iOrder == 0 || ny == 1) {
941 double dist =
fabs(y - yAxis[0]);
943 for (
int i = 1; i < ny; i++) {
944 if (
fabs(y - yAxis[i]) < dist) {
945 dist =
fabs(y - yAxis[i]);
956 }
else if (iOrder == 1 || ny == 2) {
960 for (
int i = 1; i < ny; i++) {
961 if ((yAxis[i - 1] - y) * (y - yAxis[i]) >= 0.) {
966 if (yAxis[iGrid] == yAxis[iGrid - 1]) {
967 std::cerr <<
"Boxin3:\n";
968 std::cerr <<
" Incorrect grid; no interpolation.\n";
973 const double yLocal =
974 (y - yAxis[iGrid - 1]) / (yAxis[iGrid] - yAxis[iGrid - 1]);
982 }
else if (iOrder == 2) {
986 for (
int i = 1; i < ny; i++) {
987 if ((yAxis[i - 1] - y) * (y - yAxis[i]) >= 0.) {
992 const double yLocal =
993 (y - yAxis[iGrid - 1]) / (yAxis[iGrid] - yAxis[iGrid - 1]);
997 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
998 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
999 fY[1] = (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1000 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1001 fY[2] = (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1002 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1007 if (yAxis[iY0] == yAxis[iY0 + 1] || yAxis[iY0] == yAxis[iY0 + 2] ||
1008 yAxis[iY0 + 1] == yAxis[iY0 + 2]) {
1009 std::cerr <<
"Boxin3:\n";
1010 std::cerr <<
" One or more grid points in y coincide.\n";
1011 std::cerr <<
" No interpolation.\n";
1015 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1016 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1018 (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1019 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1021 (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1022 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1023 }
else if (iGrid == ny - 1) {
1026 if (yAxis[iY0] == yAxis[iY0 + 1] || yAxis[iY0] == yAxis[iY0 + 2] ||
1027 yAxis[iY0 + 1] == yAxis[iY0 + 2]) {
1028 std::cerr <<
"Boxin3:\n";
1029 std::cerr <<
" One or more grid points in y coincide.\n";
1030 std::cerr <<
" No interpolation.\n";
1034 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1035 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1037 (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1038 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1040 (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1041 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1045 if (yAxis[iY0] == yAxis[iY0 + 1] || yAxis[iY0] == yAxis[iY0 + 2] ||
1046 yAxis[iY0] == yAxis[iY0 + 3] || yAxis[iY0 + 1] == yAxis[iY0 + 2] ||
1047 yAxis[iY0 + 1] == yAxis[iY0 + 3] ||
1048 yAxis[iY0 + 2] == yAxis[iY0 + 3]) {
1049 std::cerr <<
"Boxin3:\n";
1050 std::cerr <<
" One or more grid points in y coincide.\n";
1051 std::cerr <<
" No interpolation.\n";
1055 fY[0] = (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1056 ((yAxis[iY0] - yAxis[iY0 + 1]) * (yAxis[iY0] - yAxis[iY0 + 2]));
1058 (y - yAxis[iY0]) * (y - yAxis[iY0 + 2]) /
1059 ((yAxis[iY0 + 1] - yAxis[iY0]) * (yAxis[iY0 + 1] - yAxis[iY0 + 2]));
1061 (y - yAxis[iY0]) * (y - yAxis[iY0 + 1]) /
1062 ((yAxis[iY0 + 2] - yAxis[iY0]) * (yAxis[iY0 + 2] - yAxis[iY0 + 1]));
1064 fY[0] *= (1. - yLocal);
1065 fY[1] = fY[1] * (1. - yLocal) + yLocal * (y - yAxis[iY0 + 2]) *
1066 (y - yAxis[iY0 + 3]) /
1067 ((yAxis[iY0 + 1] - yAxis[iY0 + 2]) *
1068 (yAxis[iY0 + 1] - yAxis[iY0 + 3]));
1069 fY[2] = fY[2] * (1. - yLocal) + yLocal * (y - yAxis[iY0 + 1]) *
1070 (y - yAxis[iY0 + 3]) /
1071 ((yAxis[iY0 + 2] - yAxis[iY0 + 1]) *
1072 (yAxis[iY0 + 2] - yAxis[iY0 + 3]));
1073 fY[3] = yLocal * (y - yAxis[iY0 + 1]) * (y - yAxis[iY0 + 2]) /
1074 ((yAxis[iY0 + 3] - yAxis[iY0 + 1]) *
1075 (yAxis[iY0 + 3] - yAxis[iY0 + 2]));
1079 if (iOrder == 0 || nz == 1) {
1082 double dist =
fabs(z - zAxis[0]);
1084 for (
int i = 1; i < nz; i++) {
1085 if (
fabs(z - zAxis[i]) < dist) {
1086 dist =
fabs(z - zAxis[i]);
1097 }
else if (iOrder == 1 || nz == 2) {
1101 for (
int i = 1; i < nz; i++) {
1102 if ((zAxis[i - 1] - z) * (z - zAxis[i]) >= 0.) {
1107 if (zAxis[iGrid] == zAxis[iGrid - 1]) {
1108 std::cerr <<
"Boxin3:\n";
1109 std::cerr <<
" Incorrect grid; no interpolation.\n";
1114 const double zLocal =
1115 (z - zAxis[iGrid - 1]) / (zAxis[iGrid] - zAxis[iGrid - 1]);
1120 fZ[0] = 1. - zLocal;
1123 }
else if (iOrder == 2) {
1127 for (
int i = 1; i < nz; i++) {
1128 if ((zAxis[i - 1] - z) * (z - zAxis[i]) >= 0.) {
1133 const double zLocal =
1134 (z - zAxis[iGrid - 1]) / (zAxis[iGrid] - zAxis[iGrid - 1]);
1138 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1139 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1140 fZ[1] = (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1141 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1142 fZ[2] = (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1143 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1148 if (zAxis[iZ0] == zAxis[iZ0 + 1] || zAxis[iZ0] == zAxis[iZ0 + 2] ||
1149 zAxis[iZ0 + 1] == zAxis[iZ0 + 2]) {
1150 std::cerr <<
"Boxin3:\n";
1151 std::cerr <<
" One or more grid points in z coincide.\n";
1152 std::cerr <<
" No interpolation.\n";
1156 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1157 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1159 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1160 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1162 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1163 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1164 }
else if (iGrid == nz - 1) {
1167 if (zAxis[iZ0] == zAxis[iZ0 + 1] || zAxis[iZ0] == zAxis[iZ0 + 2] ||
1168 zAxis[iZ0 + 1] == zAxis[iZ0 + 2]) {
1169 std::cerr <<
"Boxin3:\n";
1170 std::cerr <<
" One or more grid points in z coincide.\n";
1171 std::cerr <<
" No interpolation.\n";
1175 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1176 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1178 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1179 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1181 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1182 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1187 if (zAxis[iZ0] == zAxis[iZ0 + 1] || zAxis[iZ0] == zAxis[iZ0 + 2] ||
1188 zAxis[iZ0] == zAxis[iZ0 + 3] || zAxis[iZ0 + 1] == zAxis[iZ0 + 2] ||
1189 zAxis[iZ0 + 1] == zAxis[iZ0 + 3] ||
1190 zAxis[iZ0 + 2] == zAxis[iZ0 + 3]) {
1191 std::cerr <<
"Boxin3:\n";
1192 std::cerr <<
" One or more grid points in z coincide.\n";
1193 std::cerr <<
" No interpolation.\n";
1198 fZ[0] = (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1199 ((zAxis[iZ0] - zAxis[iZ0 + 1]) * (zAxis[iZ0] - zAxis[iZ0 + 2]));
1201 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 2]) /
1202 ((zAxis[iZ0 + 1] - zAxis[iZ0]) * (zAxis[iZ0 + 1] - zAxis[iZ0 + 2]));
1204 (z - zAxis[iZ0]) * (z - zAxis[iZ0 + 1]) /
1205 ((zAxis[iZ0 + 2] - zAxis[iZ0]) * (zAxis[iZ0 + 2] - zAxis[iZ0 + 1]));
1207 fZ[0] *= (1. - zLocal);
1208 fZ[1] = fZ[1] * (1. - zLocal) + zLocal * (z - zAxis[iZ0 + 2]) *
1209 (z - zAxis[iZ0 + 3]) /
1210 ((zAxis[iZ0 + 1] - zAxis[iZ0 + 2]) *
1211 (zAxis[iZ0 + 1] - zAxis[iZ0 + 3]));
1212 fZ[2] = fZ[2] * (1. - zLocal) + zLocal * (z - zAxis[iZ0 + 1]) *
1213 (z - zAxis[iZ0 + 3]) /
1214 ((zAxis[iZ0 + 2] - zAxis[iZ0 + 1]) *
1215 (zAxis[iZ0 + 2] - zAxis[iZ0 + 3]));
1216 fZ[3] = zLocal * (z - zAxis[iZ0 + 1]) * (z - zAxis[iZ0 + 2]) /
1217 ((zAxis[iZ0 + 3] - zAxis[iZ0 + 1]) *
1218 (zAxis[iZ0 + 3] - zAxis[iZ0 + 2]));
1223 for (
int i = iX0; i <= iX1; ++i) {
1224 for (
int j = iY0; j <= iY1; ++j) {
1225 for (
int k = iZ0; k <= iZ1; ++k) {
1230 f += value[i][j][k] * fX[i - iX0] * fY[j - iY0] * fZ[k - iZ0];
DoubleAc fabs(const DoubleAc &f)
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)
bool Boxin3(std::vector< std::vector< std::vector< double > > > &value, std::vector< double > &xAxis, std::vector< double > &yAxis, std::vector< double > &zAxis, int nx, int ny, int nz, double xx, double yy, double zz, double &f, int iOrder)
double GaussKronrod15(double(*f)(const double), const double a, const double b)
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)