From e4ce92a24fb0cc49de909acef504c94a743f11ac Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Thu, 5 Dec 2024 17:40:27 -0500 Subject: [PATCH] enforce_bc: handle multiple displacements --- src/madness/mra/mraimpl.h | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/madness/mra/mraimpl.h b/src/madness/mra/mraimpl.h index e24b4ac0198..9d92fd40541 100644 --- a/src/madness/mra/mraimpl.h +++ b/src/madness/mra/mraimpl.h @@ -3217,20 +3217,23 @@ template static inline bool enforce_bc(bool is_periodic, Level n, Translation& l) { - Translation two2n = 1ul << n; - if (l < 0) { - if (is_periodic) - l += two2n; // Periodic BC - else - return false; // Zero BC - } - else if (l >= two2n) { - if (is_periodic) - l -= two2n; // Periodic BC - else - return false; // Zero BC - } - return true; + const Translation two2n = 1ul << n; + if (l < 0) { + if (is_periodic) { + do { + l += two2n; // Periodic BC + } while (l < 0); + } else + return false; // Zero BC + } else if (l >= two2n) { + if (is_periodic) { + do { + l -= two2n; // Periodic BC + } while (l >= two2n); + } else + return false; // Zero BC + } + return true; } static inline bool enforce_in_volume(Level n, Translation& l) {