Skip to content

Commit

Permalink
core: apply code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Jan 19, 2024
1 parent d5b68bc commit d84950c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/core/lb/particle_coupling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include <utils/Vector.hpp>
#include <utils/math/sqr.hpp>

#include <cassert>
#include <cmath>
#include <unordered_set>
#include <vector>
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 6 additions & 4 deletions src/core/unit_tests/lb_particle_coupling_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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.}));
Expand Down
4 changes: 2 additions & 2 deletions src/script_interface/thermostat/thermostat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ class Interface : public AutoParameters<Interface<CoreClass>, System::Leaf> {
#ifdef PARTICLE_ANISOTROPY
static_assert(std::is_same_v<T, Utils::Vector3d>);
T gamma{};
try {
if (is_type<int>(v) or is_type<double>(v)) {
gamma = T::broadcast(get_value<double>(v));
} catch (...) {
} else {
gamma = get_value<T>(v);
}
#else
Expand Down

0 comments on commit d84950c

Please sign in to comment.