IC2NW4EHRU42VTEF6RNOC26DVB3BKSA6JLGMO6CUXGIHHOZ3KTCQC
T y0 = interpolate<dir - 1>(i, di);
T y1 = interpolate<dir - 1>(i + DI, di);
T y2 = interpolate<dir - 1>(i + 2 * DI, di);
const T x = di[dir] - order / T(2);
#ifdef CCTK_DEBUG
assert(fabs(x) <= T(0.5));
#endif
const T y0 = interpolate<dir - 1>(i, di);
const T y1 = interpolate<dir - 1>(i + DI, di);
const T y2 = interpolate<dir - 1>(i + 2 * DI, di);
}
}
case 3: {
const T x = di[dir] - order / T(2);
#ifdef CCTK_DEBUG
assert(fabs(x) <= T(0.5));
#endif
const T y0 = interpolate<dir - 1>(i, di);
const T y1 = interpolate<dir - 1>(i + DI, di);
const T y2 = interpolate<dir - 1>(i + 2 * DI, di);
const T y3 = interpolate<dir - 1>(i + 3 * DI, di);
switch (derivs[dir]) {
case 0:
return (-1 / T(16) + 1 / T(24) * x + 1 / T(4) * pow(x, 2) -
1 / T(6) * pow(x, 3)) *
y0 +
(9 / T(16) - 9 / T(8) * x - 1 / T(4) * pow(x, 2) +
1 / T(2) * pow(x, 3)) *
y1 +
(9 / T(16) + 9 / T(8) * x - 1 / T(4) * pow(x, 2) -
1 / T(2) * pow(x, 3)) *
y2 +
(-1 / T(16) - 1 / T(24) * x + 1 / T(4) * pow(x, 2) +
1 / T(6) * pow(x, 3)) *
y3;
case 1:
return ((1 / T(24) + 1 / T(2) * x - 1 / T(2) * pow(x, 2)) * y0 +
(-9 / T(8) - 1 / T(2) * x + 3 / T(2) * pow(x, 2)) * y1 +
(9 / T(8) - 1 / T(2) * x - 3 / T(2) * pow(x, 2)) * y2 +
(-1 / T(24) + 1 / T(2) * x + 1 / T(2) * pow(x, 2)) * y3) /
dx[dir];
case 2:
return ((1 / T(2) - x) * y0 + (-1 / T(2) + 3 * x) * y1 +
(-1 / T(2) - 3 * x) * y2 + (1 / T(2) + x) * y3) /
pow(dx[dir], 2);
case 4: {
const T x = di[dir] - order / T(2);
#ifdef CCTK_DEBUG
assert(fabs(x) <= T(0.5));
#endif
const T y0 = interpolate<dir - 1>(i, di);
const T y1 = interpolate<dir - 1>(i + DI, di);
const T y2 = interpolate<dir - 1>(i + 2 * DI, di);
const T y3 = interpolate<dir - 1>(i + 3 * DI, di);
const T y4 = interpolate<dir - 1>(i + 4 * DI, di);
switch (derivs[dir]) {
case 0:
return (1 / T(12) * x - 1 / T(24) * pow(x, 2) - 1 / T(12) * pow(x, 3) +
1 / T(24) * pow(x, 4)) *
y0 +
(-2 / T(3) * x + 2 / T(3) * pow(x, 2) + 1 / T(6) * pow(x, 3) -
1 / T(6) * pow(x, 4)) *
y1 +
(1 - 5 / T(4) * pow(x, 2) + 1 / T(4) * pow(x, 4)) * y2 +
(2 / T(3) * x + 2 / T(3) * pow(x, 2) - 1 / T(6) * pow(x, 3) -
1 / T(6) * pow(x, 4)) *
y3 +
(-1 / T(12) * x - 1 / T(24) * pow(x, 2) + 1 / T(12) * pow(x, 3) +
1 / T(24) * pow(x, 4)) *
y4;
case 1:
return ((1 / T(12) - 1 / T(12) * x - 1 / T(4) * pow(x, 2) +
1 / T(6) * pow(x, 3)) *
y0 +
(-2 / T(3) + 4 / T(3) * x + 1 / T(2) * pow(x, 2) -
2 / T(3) * pow(x, 3)) *
y1 +
(-5 / T(2) * x + pow(x, 3)) * y2 +
(2 / T(3) + 4 / T(3) * x - 1 / T(2) * pow(x, 2) -
2 / T(3) * pow(x, 3)) *
y3 +
(-1 / T(12) - 1 / T(12) * x + 1 / T(4) * pow(x, 2) +
1 / T(6) * pow(x, 3)) *
y4) /
dx[dir];
case 2:
return ((-1 / T(12) - 1 / T(2) * x + 1 / T(2) * pow(x, 2)) * y0 +
(4 / T(3) + x - 2 * pow(x, 2)) * y1 +
(-5 / T(2) + 3 * pow(x, 2)) * y2 +
(4 / T(3) - x - 2 * pow(x, 2)) * y3 +
(-1 / T(12) + 1 / T(2) * x + 1 / T(2) * pow(x, 2)) * y4) /
pow(dx[dir], 2);
}
switch (interpolation_order) {
case 0: {
constexpr int order = 0;
#pragma omp simd
for (int n = 0; n < np; ++n) {
vect<int, dim> i;
vect<CCTK_REAL, dim> di;
for (int d = 0; d < dim; ++d) {
CCTK_REAL x = particles[n].pos(d);
CCTK_REAL ri = (x - x0[d]) / dx[d];
i[d] = lrint(ri - (order / CCTK_REAL(2)));
di[d] = ri - i[d];
}
const interpolator<CCTK_REAL, order> interp{vars, vi, derivs, dx};
varresult.at(n) = interp.interpolate<dim - 1>(i, di);
}
break;
}
case 1: {
constexpr int order = 1;
for (int n = 0; n < np; ++n) {
vect<int, dim> i;
vect<CCTK_REAL, dim> di;
for (int d = 0; d < dim; ++d) {
CCTK_REAL x = particles[n].pos(d);
CCTK_REAL ri = (x - x0[d]) / dx[d];
i[d] = lrint(ri - (order / CCTK_REAL(2)));
di[d] = ri - i[d];
for (int n = 0; n < np; ++n) {
vect<int, dim> i;
vect<CCTK_REAL, dim> di;
for (int d = 0; d < dim; ++d) {
CCTK_REAL x = particles[n].pos(d);
CCTK_REAL ri = (x - x0[d]) / dx[d];
i[d] = lrint(ri - (order / CCTK_REAL(2)));
di[d] = ri - i[d];
}
const interpolator<CCTK_REAL, order> interp{vars, vi, derivs, dx};
varresult.at(n) = interp.interpolate<dim - 1>(i, di);
}
break;
}
case 2: {
constexpr int order = 2;
#pragma omp simd
for (int n = 0; n < np; ++n) {
vect<int, dim> i;
vect<CCTK_REAL, dim> di;
for (int d = 0; d < dim; ++d) {
CCTK_REAL x = particles[n].pos(d);
CCTK_REAL ri = (x - x0[d]) / dx[d];
i[d] = lrint(ri - (order / CCTK_REAL(2)));
di[d] = ri - i[d];
}
const interpolator<CCTK_REAL, order> interp{vars, vi, derivs, dx};
varresult.at(n) = interp.interpolate<dim - 1>(i, di);
}
break;
}
case 3: {
constexpr int order = 3;
#pragma omp simd
for (int n = 0; n < np; ++n) {
vect<int, dim> i;
vect<CCTK_REAL, dim> di;
for (int d = 0; d < dim; ++d) {
CCTK_REAL x = particles[n].pos(d);
CCTK_REAL ri = (x - x0[d]) / dx[d];
i[d] = lrint(ri - (order / CCTK_REAL(2)));
di[d] = ri - i[d];
}
const interpolator<CCTK_REAL, order> interp{vars, vi, derivs, dx};
varresult.at(n) = interp.interpolate<dim - 1>(i, di);
// const vect<int, dim> DI{1, 0, 0};
// const vect<int, dim> DJ{0, 1, 0};
// const vect<int, dim> DK{0, 0, 1};
// const auto interp0{[&](const vect<int, dim> i) {
// return vars(i[0], i[1], i[2], vi);
// }};
// const auto interp1{[&](const vect<int, dim> i) {
// if (derivs[0] == 0)
// return (1 - di[0]) * interp0(i) + di[0] * interp0(i + DI);
// if (derivs[0] == 1)
// return (-interp0(i) + interp0(i + DI)) / dx[0];
// return 0 * interp0(i);
// }};
// const auto interp2{[&](const vect<int, dim> i) {
// if (derivs[1] == 0)
// return (1 - di[1]) * interp1(i) + di[1] * interp1(i + DJ);
// if (derivs[1] == 1)
// return (-interp1(i) + interp1(i + DJ)) / dx[1];
// return 0 * interp1(i);
// }};
// const auto interp3{[&](const vect<int, dim> i) {
// if (derivs[2] == 0)
// return (1 - di[2]) * interp2(i) + di[2] * interp2(i + DK);
// if (derivs[2] == 1)
// return (-interp2(i) + interp2(i + DK)) / dx[2];
// return 0 * interp2(i);
// }};
// varresult.at(n) = interp3(i);
const interpolator<CCTK_REAL, order> interp{vars, vi, derivs, dx};
varresult.at(n) = interp.interpolate<dim - 1>(i, di);
break;
}
case 4: {
constexpr int order = 4;
#pragma omp simd
for (int n = 0; n < np; ++n) {
vect<int, dim> i;
vect<CCTK_REAL, dim> di;
for (int d = 0; d < dim; ++d) {
CCTK_REAL x = particles[n].pos(d);
CCTK_REAL ri = (x - x0[d]) / dx[d];
i[d] = lrint(ri - (order / CCTK_REAL(2)));
di[d] = ri - i[d];
}
const interpolator<CCTK_REAL, order> interp{vars, vi, derivs, dx};
varresult.at(n) = interp.interpolate<dim - 1>(i, di);
}
break;
}
default:
assert(0);