From 7ab4dbe63862c79aba07282b4679fd6732b34b63 Mon Sep 17 00:00:00 2001 From: Rudolf Weeber Date: Tue, 16 Jun 2026 16:44:57 +0200 Subject: [PATCH 1/2] walberla: fix missing EK species/container tau cross-check (bug-sweep #19) EKContainer::add_in_core validated only floating-point precision and the MPI Cartesian-communicator observer, never comparing the new species' tau against the container's tau. An EKSpecies derives all of its MD<->lattice conversion factors (diffusion, flux, energy, external e-field) from its own tau, while the integrator and the MD-tau veto use the container tau. When the two differ, effective diffusion/flux/mobility are wrong by a factor of tau_species/tau_container with no error raised: ekcontainer.add(species) succeeded silently. Add a tau comparison inside the existing parallel_try_catch lambda, next to the precision/observer checks, throwing std::runtime_error when the species tau differs from the container tau. The check runs under the same coordinated parallel_try_catch on every rank, so it cannot diverge. This PREVENTs the inconsistent input rather than silently rescaling baked-in conversion factors, matching how every other add-time mismatch in this path is treated and the documented contract that tau must be an integer multiple of the MD time step on both classes. Co-Authored-By: Claude Opus 4.8 --- src/script_interface/walberla/EKContainer.hpp | 6 ++++++ testsuite/python/ek_interface.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/script_interface/walberla/EKContainer.hpp b/src/script_interface/walberla/EKContainer.hpp index 265405fc77..74870cbf2a 100644 --- a/src/script_interface/walberla/EKContainer.hpp +++ b/src/script_interface/walberla/EKContainer.hpp @@ -103,6 +103,12 @@ class EKContainer : public ObjectList { throw std::runtime_error( "Cannot mix single and double precision kernels"); } + auto const tau_container = m_ek_container->get_tau(); + auto const tau_species = get_value(obj_ptr->get_parameter("tau")); + if (tau_species != tau_container) { + throw std::runtime_error( + "EK species and EK container must have the same tau"); + } ek_throw_if_expired(obj_ptr->get_mpi_cart_comm_observer()); m_ek_container->add(obj_ptr->get_ekinstance()); }); diff --git a/testsuite/python/ek_interface.py b/testsuite/python/ek_interface.py index fe9313098d..af14777f82 100644 --- a/testsuite/python/ek_interface.py +++ b/testsuite/python/ek_interface.py @@ -333,6 +333,22 @@ def test_ek_container_exceptions(self): ek_solver_incompatible) self.assertEqual(len(self.system.ekcontainer), 1) + def test_ek_tau_mismatch_exception(self): + # the species derives all of its MD<->lattice conversion factors from + # its own tau, while the integrator and the MD-tau veto use the + # container tau; a mismatch silently produces wrong physics, so adding + # a species whose tau differs from the container tau must be rejected + self.assertAlmostEqual( + self.system.ekcontainer.tau, self.params["tau"], delta=self.atol) + ek_species_mismatch = self.make_default_ek_species( + tau=2. * self.params["tau"]) + with self.assertRaisesRegex(RuntimeError, "same tau"): + self.system.ekcontainer.add(ek_species_mismatch) + self.assertEqual(len(self.system.ekcontainer), 0) + # a species with the matching tau can still be added + self.system.ekcontainer.add(self.make_default_ek_species()) + self.assertEqual(len(self.system.ekcontainer), 1) + def test_ek_solver_exceptions(self): ek_solver = self.system.ekcontainer.solver ek_species = self.make_default_ek_species() From b53371717c98e318e92298d9c2e0731253ef7696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 23 Jun 2026 18:00:22 +0200 Subject: [PATCH 2/2] Rewrite test --- testsuite/python/ek_interface.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/testsuite/python/ek_interface.py b/testsuite/python/ek_interface.py index af14777f82..1058ec9247 100644 --- a/testsuite/python/ek_interface.py +++ b/testsuite/python/ek_interface.py @@ -332,21 +332,9 @@ def test_ek_container_exceptions(self): self.system.ekcontainer.solver, ek_solver_incompatible) self.assertEqual(len(self.system.ekcontainer), 1) - - def test_ek_tau_mismatch_exception(self): - # the species derives all of its MD<->lattice conversion factors from - # its own tau, while the integrator and the MD-tau veto use the - # container tau; a mismatch silently produces wrong physics, so adding - # a species whose tau differs from the container tau must be rejected - self.assertAlmostEqual( - self.system.ekcontainer.tau, self.params["tau"], delta=self.atol) - ek_species_mismatch = self.make_default_ek_species( - tau=2. * self.params["tau"]) - with self.assertRaisesRegex(RuntimeError, "same tau"): - self.system.ekcontainer.add(ek_species_mismatch) - self.assertEqual(len(self.system.ekcontainer), 0) - # a species with the matching tau can still be added - self.system.ekcontainer.add(self.make_default_ek_species()) + # the tau value must match for units conversion + with self.assertRaisesRegex(RuntimeError, "EK species and EK container must have the same tau"): + self.system.ekcontainer.add(self.make_default_ek_species(tau=200.)) self.assertEqual(len(self.system.ekcontainer), 1) def test_ek_solver_exceptions(self):