diff --git a/src/core/lb/particle_coupling.hpp b/src/core/lb/particle_coupling.hpp index bacdd1061f..d5e7cdf3a5 100644 --- a/src/core/lb/particle_coupling.hpp +++ b/src/core/lb/particle_coupling.hpp @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -93,17 +92,16 @@ class ParticleCoupling { public: ParticleCoupling(LBThermostat const &thermostat, LB::Solver &lb, BoxGeometry const &box_geo, LocalBox const &local_box, - double time_step, double kT = -1.) + double time_step) : m_thermostat{thermostat}, m_lb{lb}, m_box_geo{box_geo}, m_local_box{local_box}, m_time_step{time_step} { - assert(kT >= 0. or kT == -1.); /* Eq. (16) @cite ahlrichs99a, without the gamma term. * The factor 12 comes from the fact that we use random numbers * from -0.5 to 0.5 (equally distributed) which have variance 1/12. * The time step comes from the discretization. */ auto constexpr variance_inv = 12.; - kT = (kT >= 0.) ? kT : lb.get_kT() * Utils::sqr(lb.get_lattice_speed()); + auto const kT = lb.get_kT() * Utils::sqr(lb.get_lattice_speed()); m_thermalized = (kT != 0.); m_noise_pref_wo_gamma = std::sqrt(variance_inv * 2. * kT / time_step); } diff --git a/src/core/unit_tests/lb_particle_coupling_test.cpp b/src/core/unit_tests/lb_particle_coupling_test.cpp index 2d4e6893dc..542587dc89 100644 --- a/src/core/unit_tests/lb_particle_coupling_test.cpp +++ b/src/core/unit_tests/lb_particle_coupling_test.cpp @@ -175,12 +175,13 @@ BOOST_AUTO_TEST_CASE(rng) { auto &thermostat = *espresso::system->thermostat->lb; auto const &box_geo = *espresso::system->box_geo; auto const &local_box = *espresso::system->local_geo; + auto const tau = params.time_step; thermostat.rng_initialize(17u); thermostat.set_rng_counter(11ul); thermostat.gamma = 0.2; + espresso::set_lb_kT(1.); - LB::ParticleCoupling coupling{thermostat, lb, box_geo, local_box, - params.time_step, 1.}; + LB::ParticleCoupling coupling{thermostat, lb, box_geo, local_box, tau}; BOOST_CHECK_EQUAL(thermostat.rng_seed(), 17u); BOOST_CHECK_EQUAL(thermostat.rng_counter(), 11ul); BOOST_CHECK(not thermostat.is_seed_required()); @@ -206,8 +207,9 @@ BOOST_AUTO_TEST_CASE(rng) { BOOST_CHECK(step1_random1 != step2_random1); BOOST_CHECK(step1_random1 != step2_random2); - LB::ParticleCoupling coupling_unthermalized{ - thermostat, lb, box_geo, local_box, params.time_step, 0.}; + espresso::set_lb_kT(0.); + LB::ParticleCoupling coupling_unthermalized{thermostat, lb, box_geo, + local_box, tau}; auto const step3_norandom = coupling_unthermalized.get_noise_term(test_partcl_2); BOOST_CHECK((step3_norandom == Utils::Vector3d{0., 0., 0.})); diff --git a/src/script_interface/thermostat/thermostat.hpp b/src/script_interface/thermostat/thermostat.hpp index 1125f04200..c2494362d8 100644 --- a/src/script_interface/thermostat/thermostat.hpp +++ b/src/script_interface/thermostat/thermostat.hpp @@ -146,9 +146,9 @@ class Interface : public AutoParameters, System::Leaf> { #ifdef PARTICLE_ANISOTROPY static_assert(std::is_same_v); T gamma{}; - try { + if (is_type(v) or is_type(v)) { gamma = T::broadcast(get_value(v)); - } catch (...) { + } else { gamma = get_value(v); } #else