Skip to content

Commit

Permalink
Restore LB boundaries during checkpointing (#4649)
Browse files Browse the repository at this point in the history
Fixes #4647

Description of changes:
- bugfix: reloading LB populations no longer clears LB boundary flags
  • Loading branch information
jngrad authored Jan 12, 2023
2 parents e68047d + ce0df27 commit 3306988
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/core/grid_based_algorithms/lb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "cell_system/CellStructureType.hpp"
#include "communication.hpp"
#include "errorhandling.hpp"
#include "event.hpp"
#include "grid.hpp"
#include "grid_based_algorithms/lb_boundaries.hpp"
#include "halo.hpp"
Expand Down Expand Up @@ -207,6 +208,7 @@ void lb_initialize_fields(std::vector<LB_FluidNode> &lb_fields,
field.boundary = false;
#endif // LB_BOUNDARIES
}
on_lbboundary_change();
}

/** (Re-)allocate memory for the fluid and initialize pointers. */
Expand Down
19 changes: 15 additions & 4 deletions testsuite/python/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ def test_lb_fluid(self):
Check serialization of the LB fluid. The checkpoint file only stores
population information, therefore calling ``lbf.load_checkpoint()``
erases all LBBoundaries information but doesn't remove the objects
contained in ``system.lbboundaries`. This test method is named such
that it is executed after ``self.test_lb_boundaries()``.
contained in ``system.lbboundaries``. A callback should re-introduce
the LB boundary flag after LB populations are reloaded.
'''
lbf = self.get_active_actor_of_type(
espressomd.lb.HydrodynamicInteraction)
cpt_mode = 0 if 'LB.ASCII' in modes else 1
cpt_root = pathlib.Path(self.checkpoint.checkpoint_dir)
cpt_path = str(cpt_root / "lb") + "{}.cpt"

if has_lbb:
# LB boundaries must be correct before LB populations are loaded
self.check_lb_boundaries()

# check exception mechanism with corrupted LB checkpoint files
with self.assertRaisesRegex(RuntimeError, 'EOF found'):
lbf.load_checkpoint(cpt_path.format("-missing-data"), cpt_mode)
Expand Down Expand Up @@ -133,6 +137,10 @@ def test_lb_fluid(self):
self.assertIn(key, state)
self.assertAlmostEqual(reference[key], state[key], delta=1E-7)

if has_lbb:
# LB boundaries must be correct after LB populations are loaded
self.check_lb_boundaries(remove_boundaries=True)

def test_system_variables(self):
cell_system_params = system.cell_system.get_state()
self.assertTrue(cell_system_params['use_verlet_lists'])
Expand Down Expand Up @@ -672,8 +680,7 @@ def test_exclusions(self):
self.assertEqual(list(system.part.by_id(1).exclusions), [2])
self.assertEqual(list(system.part.by_id(2).exclusions), [0, 1])

@ut.skipIf(not has_lbb, "Missing features")
def test_lb_boundaries(self):
def check_lb_boundaries(self, remove_boundaries=False):
# check boundary objects
self.assertEqual(len(system.lbboundaries), 2)
np.testing.assert_allclose(
Expand All @@ -684,14 +691,18 @@ def test_lb_boundaries(self):
system.lbboundaries[0].shape, espressomd.shapes.Wall)
self.assertIsInstance(
system.lbboundaries[1].shape, espressomd.shapes.Wall)

# check boundary flag
lbf = self.get_active_actor_of_type(
espressomd.lb.HydrodynamicInteraction)
np.testing.assert_equal(np.copy(lbf[0, :, :].boundary.astype(int)), 1)
np.testing.assert_equal(np.copy(lbf[-1, :, :].boundary.astype(int)), 2)
np.testing.assert_equal(
np.copy(lbf[1:-1, :, :].boundary.astype(int)), 0)

# remove boundaries
if not remove_boundaries:
return
system.lbboundaries.clear()
self.assertEqual(len(system.lbboundaries), 0)
np.testing.assert_equal(np.copy(lbf[:, :, :].boundary.astype(int)), 0)
Expand Down

0 comments on commit 3306988

Please sign in to comment.