Unverified Commit 7a485cc4 authored by Florian Weik's avatar Florian Weik Committed by GitHub

Merge pull request #2415 from RudolfWeeber/fold_coord

Core: fold_coordinate rewrite to avoid rounding corner cases
parents c64a2ecf 28477228
Pipeline #4478 passed with stages
in 94 minutes and 48 seconds
......@@ -214,19 +214,13 @@ Vector3d get_mi_vector(T const &a, U const &b) {
template <typename T1, typename T2, typename T3>
void fold_coordinate(T1 &pos, T2 &vel, T3 &image_box, int dir) {
if (PERIODIC(dir)) {
int img_count = (int)floor(pos[dir] * box_l_i[dir]);
image_box[dir] += img_count;
pos[dir] = pos[dir] - img_count * box_l[dir];
if (pos[dir] * box_l_i[dir] < -ROUND_ERROR_PREC ||
pos[dir] * box_l_i[dir] >= 1 + ROUND_ERROR_PREC) {
runtimeErrorMsg() << "particle coordinate out of range, pos = "
<< pos[dir] << ", image box = " << image_box[dir];
image_box[dir] = 0;
pos[dir] = 0;
return;
while (pos[dir] < 0) {
pos[dir] += box_l[dir];
image_box[dir] -= 1;
}
while (pos[dir] >= box_l[dir]) {
pos[dir] -= box_l[dir];
image_box[dir] += 1;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment