Skip to content

Commit

Permalink
walberla: Add checks for solver tau
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed May 9, 2023
1 parent 2d594b4 commit ed97498
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/script_interface/walberla/EKContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ class EKContainer : public ObjectList<EKSpecies> {
add_parameters({
{"tau",
[this](Variant const &v) {
auto const tau = get_value<double>(v);
context()->parallel_try_catch([tau]() {
if (tau <= 0.) {
throw std::domain_error("Parameter 'tau' must be > 0");
}
});
EK::ek_container.set_tau(get_value<double>(v));
},
[this]() { return EK::ek_container.get_tau(); }},
[]() { return EK::ek_container.get_tau(); }},
{"solver", [this](Variant const &v) { set_solver(v); },
[this]() { return get_solver(); }},
});
Expand Down
10 changes: 7 additions & 3 deletions testsuite/python/ek_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def setUp(self):
n_ghost_layers=1, agrid=self.params["agrid"])
ek_solver = espressomd.electrokinetics.EKNone(lattice=self.lattice)
self.system.ekcontainer.solver = ek_solver
self.system.ekcontainer.tau = self.system.time_step

def tearDown(self):
self.system.actors.clear()
Expand Down Expand Up @@ -85,9 +86,6 @@ def test_ek_species(self):
ek_species = self.make_default_ek_species()
self.check_ek_species_properties(ek_species)

ek_solver = espressomd.electrokinetics.EKNone(lattice=self.lattice)
self.system.ekcontainer.tau = self.system.time_step
self.system.ekcontainer.solver = ek_solver
self.assertAlmostEqual(
self.system.ekcontainer.tau,
self.system.time_step,
Expand Down Expand Up @@ -228,6 +226,12 @@ def test_ek_solver_exceptions(self):
self.system.ekcontainer.clear()
self.system.ekcontainer.add(incompatible_ek_species)
self.system.ekcontainer.solver = ek_solver
with self.assertRaisesRegex(ValueError, "Parameter 'tau' must be > 0"):
self.system.ekcontainer.tau = 0.
self.assertAlmostEqual(
self.system.ekcontainer.tau,
self.system.time_step,
delta=self.atol)

def test_ek_reactants(self):
ek_species = self.make_default_ek_species()
Expand Down

0 comments on commit ed97498

Please sign in to comment.