Skip to content

Commit a22c2fe

Browse files
LB+particles: guard against missed coupling due to round-off error (#4827)
Fixes #4825 Description of changes: * Bugfix: particles outside the simulation box are now properly coupled using PBC. The coordinates are folded before considering shifted positions in the LB particle coupling code. Also, a test that fails without the fix is added. To my understanding, if the particle position is folded, and then all combination of `folded_pos[i]` +/- `box_l[i]` for all Cartesian directions are considered, both the particle in the primary box and all potential halo regions are caught.
2 parents 2d65667 + f22e2fa commit a22c2fe

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/core/lb/particle_coupling.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,12 @@ void ParticleCoupling::kernel(Particle &p) {
249249

250250
// Calculate coupling force
251251
Utils::Vector3d force_on_particle = {};
252+
auto folded_pos = box_geo.folded_position(p.pos());
252253

253254
#ifdef ENGINE
254255
if (not p.swimming().is_engine_force_on_fluid)
255256
#endif
256-
for (auto pos : positions_in_halo(p.pos(), box_geo, agrid)) {
257+
for (auto pos : positions_in_halo(folded_pos, box_geo, agrid)) {
257258
if (in_local_halo(pos, agrid)) {
258259
auto const vel_offset = lb_drift_velocity_offset(p);
259260
auto const drag_force = lb_drag_force(m_lb, p, pos, vel_offset);
@@ -272,7 +273,7 @@ void ParticleCoupling::kernel(Particle &p) {
272273

273274
// couple positions including shifts by one box length to add
274275
// forces to ghost layers
275-
for (auto pos : positions_in_halo(p.pos(), box_geo, agrid)) {
276+
for (auto pos : positions_in_halo(folded_pos, box_geo, agrid)) {
276277
if (in_local_domain(pos)) {
277278
/* Particle is in our LB volume, so this node
278279
* is responsible to adding its force */

testsuite/python/lb.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,16 @@ def test_viscous_coupling_pairs(self):
566566
np.testing.assert_allclose(
567567
np.sum(applied_forces, axis=0), [0, 0, 0])
568568

569+
def test_viscous_coupling_rounding(self):
570+
lbf = self.lb_class(**self.params, **self.lb_params)
571+
self.system.lb = lbf
572+
self.system.thermostat.set_lb(LB_fluid=lbf, seed=3, gamma=self.gamma)
573+
p = self.system.part.add(pos=[-1E-30] * 3, v=[-1, 0, 0])
574+
self.system.integrator.run(1)
575+
for _ in range(20):
576+
self.system.integrator.run(1)
577+
self.assertTrue(np.all(p.f != 0.0))
578+
569579
def test_thermalization_force_balance(self):
570580
system = self.system
571581

0 commit comments

Comments
 (0)