Skip to Content.
Sympa Menu

opal - [Opal] Error in interpolateTrilinearly of FM3DH5BlockBase

opal AT lists.psi.ch

Subject: The OPAL Discussion Forum

List archive

[Opal] Error in interpolateTrilinearly of FM3DH5BlockBase


Chronological Thread  
  • From: "Ting Yau" <2100011354 AT alumni.pku.edu.cn>
  • To: opal AT lists.psi.ch
  • Subject: [Opal] Error in interpolateTrilinearly of FM3DH5BlockBase
  • Date: Wed, 17 Jun 2026 10:07:44 +0200

Dear OPAL developers,
My name is youteman, and I work for the CIAE.

I'm working on axial injection of compact Cyclotron.While using the BANDRF
type cyclotron in opal,I found that the field applied to the particle is not
equal to the field imported by .h5part file.

I assumed that the interpolate function in BANDRF might has some bugs,and
checked the source code for this section on GitHub and found that the issue
lies here.
(https://github.com/OPALX-project/OPAL/blob/master/src/Classic/Fields/FM3DH5BlockBase.h#L224)

double _FM3DH5BlockBase::getWeightedData (
const std::vector<double>& data,
const IndexTriplet& idx,
unsigned short corner
) const {
unsigned short switchX = ((corner & HX) >> 2);
unsigned short switchY = ((corner & HY) >> 1);
unsigned short switchZ = (corner & HZ);
double factorX = 0.5 + (1 - 2 * switchX) * (0.5 - idx.weight(0));
double factorY = 0.5 + (1 - 2 * switchY) * (0.5 - idx.weight(1));
double factorZ = 0.5 + (1 - 2 * switchZ) * (0.5 - idx.weight(2));

unsigned long i = idx.i + switchX, j = idx.j + switchY, k = idx.k +
switchZ;

return factorX * factorY * factorZ * data[getIndex(i, j, k)];
}

IndexTriplet getIndex(const Vector_t &X) const {
IndexTriplet idx;
long double difference = (long double)(X(0)) - (long double)
(xbegin_m);
idx.i = std::min(
(unsigned int)((difference) / (long double)(hx_m)),
num_gridpx_m-2
);
idx.weight(0) = std::fmod(
(long double)difference,
(long double)hx_m
);

difference = (long double)(X(1)) - (long double)(ybegin_m);
idx.j = std::min(
(unsigned int)((difference) / (long double)(hy_m)),
num_gridpy_m-2
);
idx.weight(1) = std::fmod(
(long double)difference,
(long double)hy_m
);

difference = (long double)(X(2)) - (long double)(zbegin_m);
idx.k = std::min(
(unsigned int)((difference) / (long double)(hz_m)),
num_gridpz_m-2
);
idx.weight(2) = std::fmod(
(long double)difference,
(long double)hz_m
);
return idx;
}

The idx.weight used to calculate factorX/Y/Z is not normalized against the
grid size hx_m. Therefore, when the grid size in the imported h5part field
file is not 1 mm, the interpolation function becomes incorrect.

Best regards,

Youteman


  • [Opal] Error in interpolateTrilinearly of FM3DH5BlockBase, Ting Yau, 06/17/2026

Archive powered by MHonArc 2.6.24.

Top of Page