From a7173b7ee0fe097fce88a0421f54b65d17a3bd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Wed, 20 Dec 2023 12:41:18 +0100 Subject: [PATCH] Encapsulate Lees-Edwards --- src/core/integrate.cpp | 56 +++++++++--------- src/core/lees_edwards/lees_edwards.hpp | 26 +++++---- src/core/lees_edwards/protocols.hpp | 23 ++++---- src/core/system/System.cpp | 2 + src/core/system/System.hpp | 4 ++ src/core/system/System.impl.hpp | 1 + src/core/virtual_sites.cpp | 1 - src/python/espressomd/system.py | 2 +- .../lees_edwards/LeesEdwards.hpp | 57 +++++++++++-------- .../lees_edwards/LinearShear.hpp | 24 ++++---- src/script_interface/lees_edwards/Off.hpp | 6 +- .../lees_edwards/OscillatoryShear.hpp | 30 ++++------ .../lees_edwards/Protocol.hpp | 6 +- src/script_interface/system/System.cpp | 3 + src/script_interface/walberla/LBFluid.cpp | 11 ++-- testsuite/python/lb_planar_couette.py | 2 +- 16 files changed, 128 insertions(+), 126 deletions(-) diff --git a/src/core/integrate.cpp b/src/core/integrate.cpp index dcb5e81a113..9b2bcd50bb2 100644 --- a/src/core/integrate.cpp +++ b/src/core/integrate.cpp @@ -92,54 +92,40 @@ volatile std::sig_atomic_t ctrl_C = 0; } // namespace namespace LeesEdwards { -/** @brief Currently active Lees-Edwards protocol. */ -static std::shared_ptr protocol = nullptr; - -std::weak_ptr get_protocol() { return protocol; } /** * @brief Update the Lees-Edwards parameters of the box geometry * for the current simulation time. */ -static void update_box_params(BoxGeometry &box_geo, double sim_time) { +void LeesEdwards::update_box_params(BoxGeometry &box_geo, double sim_time) { if (box_geo.type() == BoxType::LEES_EDWARDS) { - assert(protocol != nullptr); - box_geo.lees_edwards_update(get_pos_offset(sim_time, *protocol), - get_shear_velocity(sim_time, *protocol)); + assert(m_protocol != nullptr); + box_geo.lees_edwards_update(get_pos_offset(sim_time, *m_protocol), + get_shear_velocity(sim_time, *m_protocol)); } } -void set_protocol(std::shared_ptr new_protocol) { - auto &system = System::get_system(); +void LeesEdwards::set_protocol(std::shared_ptr protocol) { + auto &system = get_system(); auto &cell_structure = *system.cell_structure; auto &box_geo = *system.box_geo; box_geo.set_type(BoxType::LEES_EDWARDS); - protocol = std::move(new_protocol); - LeesEdwards::update_box_params(box_geo, system.get_sim_time()); + m_protocol = std::move(protocol); + update_box_params(box_geo, system.get_sim_time()); system.propagation->recalc_forces = true; cell_structure.set_resort_particles(Cells::RESORT_LOCAL); } -void unset_protocol() { - auto &system = System::get_system(); +void LeesEdwards::unset_protocol() { + auto &system = get_system(); auto &cell_structure = *system.cell_structure; auto &box_geo = *system.box_geo; - protocol = nullptr; + m_protocol = nullptr; box_geo.set_type(BoxType::CUBOID); system.propagation->recalc_forces = true; cell_structure.set_resort_particles(Cells::RESORT_LOCAL); } -template void run_kernel(BoxGeometry const &box_geo) { - if (box_geo.type() == BoxType::LEES_EDWARDS) { - auto &system = System::get_system(); - auto &cell_structure = *system.cell_structure; - auto const kernel = Kernel{box_geo}; - auto const particles = cell_structure.local_particles(); - std::for_each(particles.begin(), particles.end(), - [&kernel](auto &p) { kernel(p); }); - } -} } // namespace LeesEdwards void Propagation::update_default_propagation() { @@ -515,14 +501,19 @@ int System::System::integrate(int n_steps, int reuse_forces) { save_old_position(particles, cell_structure->ghost_particles()); #endif - LeesEdwards::update_box_params(*box_geo, sim_time); + lees_edwards->update_box_params(*box_geo, sim_time); bool early_exit = integrator_step_1(particles, propagation, ::temperature, time_step); if (early_exit) break; sim_time += time_step; - LeesEdwards::run_kernel(*box_geo); + if (box_geo->type() == BoxType::LEES_EDWARDS) { + auto const kernel = LeesEdwards::Push{*box_geo}; + for (auto &p : particles) { + kernel(p); + } + } #ifdef NPT if (propagation.integ_switch != INTEG_METHOD_NPT_ISO) @@ -572,7 +563,12 @@ int System::System::integrate(int n_steps, int reuse_forces) { if (propagation.integ_switch == INTEG_METHOD_BD) { resort_particles_if_needed(*this); } - LeesEdwards::run_kernel(*box_geo); + if (box_geo->type() == BoxType::LEES_EDWARDS) { + auto const kernel = LeesEdwards::UpdateOffset{*box_geo}; + for (auto &p : particles) { + kernel(p); + } + } #ifdef BOND_CONSTRAINT // SHAKE velocity updates if (n_rigidbonds) { @@ -647,7 +643,7 @@ int System::System::integrate(int n_steps, int reuse_forces) { } } // for-loop over integration steps - LeesEdwards::update_box_params(*box_geo, sim_time); + lees_edwards->update_box_params(*box_geo, sim_time); #ifdef CALIPER CALI_CXX_MARK_LOOP_END(integration_loop); #endif @@ -734,5 +730,5 @@ int System::System::integrate_with_signal_handler(int n_steps, int reuse_forces, void System::System::set_sim_time(double value) { sim_time = value; propagation->recalc_forces = true; - LeesEdwards::update_box_params(*box_geo, sim_time); + lees_edwards->update_box_params(*box_geo, sim_time); } diff --git a/src/core/lees_edwards/lees_edwards.hpp b/src/core/lees_edwards/lees_edwards.hpp index 631c945a3f7..49f592d9984 100644 --- a/src/core/lees_edwards/lees_edwards.hpp +++ b/src/core/lees_edwards/lees_edwards.hpp @@ -16,17 +16,17 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_LEES_EDWARDS_LEES_EDWARDS_HPP -#define CORE_LEES_EDWARDS_LEES_EDWARDS_HPP + +#pragma once #include "BoxGeometry.hpp" #include "Particle.hpp" #include "lees_edwards/protocols.hpp" +#include "system/Leaf.hpp" #include #include -#include namespace LeesEdwards { class UpdateOffset { protected: @@ -90,14 +90,20 @@ inline Utils::Vector3d verlet_list_offset(BoxGeometry const &box, return {}; } -/** @brief Get currently active Lees-Edwards protocol. */ -std::weak_ptr get_protocol(); +class LeesEdwards : public System::Leaf { + std::shared_ptr m_protocol; + +public: + /** @brief Get currently active Lees-Edwards protocol. */ + auto get_protocol() const { return m_protocol; } -/** @brief Set a new Lees-Edwards protocol. */ -void set_protocol(std::shared_ptr new_protocol); + /** @brief Set a new Lees-Edwards protocol. */ + void set_protocol(std::shared_ptr protocol); -/** @brief Delete the currently active Lees-Edwards protocol. */ -void unset_protocol(); + /** @brief Delete the currently active Lees-Edwards protocol. */ + void unset_protocol(); + + void update_box_params(BoxGeometry &box_geo, double sim_time); +}; } // namespace LeesEdwards -#endif diff --git a/src/core/lees_edwards/protocols.hpp b/src/core/lees_edwards/protocols.hpp index 29737168b40..8c4fc0f936c 100644 --- a/src/core/lees_edwards/protocols.hpp +++ b/src/core/lees_edwards/protocols.hpp @@ -16,14 +16,13 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef CORE_LEES_EDWARDS_PROTOCOLS_HPP -#define CORE_LEES_EDWARDS_PROTOCOLS_HPP -#include +#pragma once -#include +#include #include +#include namespace LeesEdwards { @@ -73,12 +72,12 @@ struct OscillatoryShear { }; /** Type which holds the currently active protocol */ -using ActiveProtocol = boost::variant; +using ActiveProtocol = std::variant; -class PosOffsetGetter : public boost::static_visitor { +class PosOffsetGetter { public: PosOffsetGetter(double time) : m_time{time} {} - template double operator()(const T &protocol) const { + template double operator()(T const &protocol) const { return protocol.pos_offset(m_time); } @@ -87,14 +86,14 @@ class PosOffsetGetter : public boost::static_visitor { }; inline double get_pos_offset(double time, ActiveProtocol const &protocol) { - return boost::apply_visitor(PosOffsetGetter(time), protocol); + return std::visit(PosOffsetGetter(time), protocol); } /** Visitor to get shear velocity from the Lees-Edwards protocol */ -class ShearVelocityGetter : public boost::static_visitor { +class ShearVelocityGetter { public: ShearVelocityGetter(double time) : m_time{time} {} - template double operator()(const T &protocol) const { + template double operator()(T const &protocol) const { return protocol.shear_velocity(m_time); } @@ -104,9 +103,7 @@ class ShearVelocityGetter : public boost::static_visitor { /** Calculation of current velocity */ inline double get_shear_velocity(double time, ActiveProtocol const &protocol) { - return boost::apply_visitor(ShearVelocityGetter(time), protocol); + return std::visit(ShearVelocityGetter(time), protocol); } } // namespace LeesEdwards - -#endif diff --git a/src/core/system/System.cpp b/src/core/system/System.cpp index 9ed35a47530..075bbb30be0 100644 --- a/src/core/system/System.cpp +++ b/src/core/system/System.cpp @@ -65,6 +65,7 @@ System::System(Private) { comfixed = std::make_shared(); galilei = std::make_shared(); bond_breakage = std::make_shared(); + lees_edwards = std::make_shared(); reinit_thermo = true; time_step = -1.; sim_time = 0.; @@ -75,6 +76,7 @@ System::System(Private) { void System::initialize() { auto handle = shared_from_this(); cell_structure->bind_system(handle); + lees_edwards->bind_system(handle); #ifdef CUDA gpu.bind_system(handle); gpu.initialize(); diff --git a/src/core/system/System.hpp b/src/core/system/System.hpp index 41772a84f2b..0e6174457ce 100644 --- a/src/core/system/System.hpp +++ b/src/core/system/System.hpp @@ -47,6 +47,9 @@ class Observable_stat; namespace BondBreakage { class BondBreakage; } +namespace LeesEdwards { +class LeesEdwards; +} namespace System { @@ -254,6 +257,7 @@ class System : public std::enable_shared_from_this { std::shared_ptr comfixed; std::shared_ptr galilei; std::shared_ptr bond_breakage; + std::shared_ptr lees_edwards; protected: /** @brief Whether the thermostat has to be reinitialized before integration. diff --git a/src/core/system/System.impl.hpp b/src/core/system/System.impl.hpp index 3a4962573e2..3a2c1e9f662 100644 --- a/src/core/system/System.impl.hpp +++ b/src/core/system/System.impl.hpp @@ -30,6 +30,7 @@ #include "galilei/ComFixed.hpp" #include "galilei/Galilei.hpp" #include "integrators/Propagation.hpp" +#include "lees_edwards/lees_edwards.hpp" #include "nonbonded_interactions/nonbonded_interaction_data.hpp" #include "BoxGeometry.hpp" diff --git a/src/core/virtual_sites.cpp b/src/core/virtual_sites.cpp index bf136b37cee..370beeeef9f 100644 --- a/src/core/virtual_sites.cpp +++ b/src/core/virtual_sites.cpp @@ -29,7 +29,6 @@ #include "Particle.hpp" #include "communication.hpp" #include "errorhandling.hpp" -#include "integrate.hpp" #include "nonbonded_interactions/nonbonded_interaction_data.hpp" #include diff --git a/src/python/espressomd/system.py b/src/python/espressomd/system.py index 75d12c3417e..1fd8802017c 100644 --- a/src/python/espressomd/system.py +++ b/src/python/espressomd/system.py @@ -237,7 +237,7 @@ def _restore_object(cls, so_callback, so_callback_args, state): def __getstate__(self): checkpointable_properties = [ - "non_bonded_inter", "bonded_inter", "lees_edwards", + "non_bonded_inter", "bonded_inter", "part", "auto_update_accumulators", "constraints", ] diff --git a/src/script_interface/lees_edwards/LeesEdwards.hpp b/src/script_interface/lees_edwards/LeesEdwards.hpp index 579b4493f6f..d4ddd81fb99 100644 --- a/src/script_interface/lees_edwards/LeesEdwards.hpp +++ b/src/script_interface/lees_edwards/LeesEdwards.hpp @@ -16,18 +16,18 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCRIPT_INTERFACE_LEES_EDWARDS_LEES_EDWARDS_HPP -#define SCRIPT_INTERFACE_LEES_EDWARDS_LEES_EDWARDS_HPP + +#pragma once #include "Protocol.hpp" #include "core/BoxGeometry.hpp" #include "core/lees_edwards/LeesEdwardsBC.hpp" #include "core/lees_edwards/lees_edwards.hpp" -#include "core/system/System.hpp" #include "script_interface/ScriptInterface.hpp" #include "script_interface/auto_parameters/AutoParameters.hpp" +#include "script_interface/system/Leaf.hpp" #include #include @@ -35,32 +35,32 @@ namespace ScriptInterface { namespace LeesEdwards { -class LeesEdwards : public AutoParameters { +class LeesEdwards : public AutoParameters { + std::shared_ptr<::LeesEdwards::LeesEdwards> m_lees_edwards; std::shared_ptr m_protocol; - LeesEdwardsBC const &m_lebc; + std::unique_ptr m_params; public: - LeesEdwards() - : m_protocol{nullptr}, - m_lebc{System::get_system().box_geo->lees_edwards_bc()} { + LeesEdwards() { add_parameters( {{"protocol", [this](Variant const &value) { if (is_none(value)) { - auto const &system = System::get_system(); + auto const &system = get_system(); context()->parallel_try_catch([&system]() { auto constexpr invalid_dir = LeesEdwardsBC::invalid_dir; system.lb.lebc_sanity_checks(invalid_dir, invalid_dir); }); m_protocol = nullptr; system.box_geo->set_lees_edwards_bc(LeesEdwardsBC{}); - ::LeesEdwards::unset_protocol(); + m_lees_edwards->unset_protocol(); return; } context()->parallel_try_catch([this]() { auto constexpr invalid_dir = LeesEdwardsBC::invalid_dir; - if (m_lebc.shear_direction == invalid_dir or - m_lebc.shear_plane_normal == invalid_dir) { + auto const &lebc = get_lebc(); + if (lebc.shear_direction == invalid_dir or + lebc.shear_plane_normal == invalid_dir) { throw std::runtime_error( "Parameters 'shear_plane_normal' and 'shear_direction' " "must be initialized together with 'protocol' on first " @@ -68,7 +68,7 @@ class LeesEdwards : public AutoParameters { } }); m_protocol = get_value>(value); - ::LeesEdwards::set_protocol(m_protocol->protocol()); + m_lees_edwards->set_protocol(m_protocol->protocol()); }, [this]() { if (m_protocol) @@ -76,13 +76,13 @@ class LeesEdwards : public AutoParameters { return make_variant(none); }}, {"shear_velocity", AutoParameter::read_only, - [this]() { return m_lebc.shear_velocity; }}, + [this]() { return get_lebc().shear_velocity; }}, {"pos_offset", AutoParameter::read_only, - [this]() { return m_lebc.pos_offset; }}, + [this]() { return get_lebc().pos_offset; }}, {"shear_direction", AutoParameter::read_only, - [this]() { return get_shear_name(m_lebc.shear_direction); }}, + [this]() { return get_shear_name(get_lebc().shear_direction); }}, {"shear_plane_normal", AutoParameter::read_only, - [this]() { return get_shear_name(m_lebc.shear_plane_normal); }}}); + [this]() { return get_shear_name(get_lebc().shear_plane_normal); }}}); } Variant do_call_method(std::string const &name, @@ -103,21 +103,19 @@ class LeesEdwards : public AutoParameters { throw std::invalid_argument("Parameters 'shear_direction' and " "'shear_plane_normal' must differ"); } - auto const &system = System::get_system(); + auto const &system = get_system(); system.lb.lebc_sanity_checks(shear_direction, shear_plane_normal); // update box geometry and cell structure system.box_geo->set_lees_edwards_bc( LeesEdwardsBC{0., 0., shear_direction, shear_plane_normal}); - ::LeesEdwards::set_protocol(m_protocol->protocol()); + m_lees_edwards->set_protocol(m_protocol->protocol()); }); } return {}; } void do_construct(VariantMap const ¶ms) override { - if (not params.empty()) { - do_call_method("set_boundary_conditions", params); - } + m_params = std::make_unique(params); } private: @@ -147,9 +145,20 @@ class LeesEdwards : public AutoParameters { } return {none}; } + + LeesEdwardsBC const &get_lebc() const { + return get_system().box_geo->lees_edwards_bc(); + } + + void on_bind_system(::System::System &system) override { + m_lees_edwards = system.lees_edwards; + auto const ¶ms = *m_params; + if (not params.empty()) { + do_call_method("set_boundary_conditions", params); + } + m_params.reset(); + } }; } // namespace LeesEdwards } // namespace ScriptInterface - -#endif diff --git a/src/script_interface/lees_edwards/LinearShear.hpp b/src/script_interface/lees_edwards/LinearShear.hpp index 270a84dcc33..ceaa279da8d 100644 --- a/src/script_interface/lees_edwards/LinearShear.hpp +++ b/src/script_interface/lees_edwards/LinearShear.hpp @@ -16,34 +16,32 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCRIPT_INTERFACE_LEES_EDWARDS_LINEAR_SHEAR_HPP -#define SCRIPT_INTERFACE_LEES_EDWARDS_LINEAR_SHEAR_HPP + +#pragma once #include "core/lees_edwards/lees_edwards.hpp" #include "script_interface/ScriptInterface.hpp" #include "script_interface/auto_parameters/AutoParameters.hpp" -#include - #include +#include namespace ScriptInterface { namespace LeesEdwards { class LinearShear : public Protocol { + using CoreClass = ::LeesEdwards::LinearShear; + public: LinearShear() - : m_protocol{std::make_shared<::LeesEdwards::ActiveProtocol>( - ::LeesEdwards::LinearShear())} { + : m_protocol{ + std::make_shared<::LeesEdwards::ActiveProtocol>(CoreClass())} { add_parameters( {{"initial_pos_offset", - boost::get<::LeesEdwards::LinearShear>(*m_protocol) - .m_initial_pos_offset}, - {"shear_velocity", - boost::get<::LeesEdwards::LinearShear>(*m_protocol).m_shear_velocity}, - {"time_0", - boost::get<::LeesEdwards::LinearShear>(*m_protocol).m_time_0}}); + std::get(*m_protocol).m_initial_pos_offset}, + {"shear_velocity", std::get(*m_protocol).m_shear_velocity}, + {"time_0", std::get(*m_protocol).m_time_0}}); } std::shared_ptr<::LeesEdwards::ActiveProtocol> protocol() override { return m_protocol; @@ -55,5 +53,3 @@ class LinearShear : public Protocol { } // namespace LeesEdwards } // namespace ScriptInterface - -#endif diff --git a/src/script_interface/lees_edwards/Off.hpp b/src/script_interface/lees_edwards/Off.hpp index d5de550e72d..8d77b60bb26 100644 --- a/src/script_interface/lees_edwards/Off.hpp +++ b/src/script_interface/lees_edwards/Off.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCRIPT_INTERFACE_LEES_EDWARDS_OFF_HPP -#define SCRIPT_INTERFACE_LEES_EDWARDS_OFF_HPP + +#pragma once #include "core/lees_edwards/lees_edwards.hpp" @@ -44,5 +44,3 @@ class Off : public Protocol { } // namespace LeesEdwards } // namespace ScriptInterface - -#endif diff --git a/src/script_interface/lees_edwards/OscillatoryShear.hpp b/src/script_interface/lees_edwards/OscillatoryShear.hpp index 7bf9923b193..d860c6c77cd 100644 --- a/src/script_interface/lees_edwards/OscillatoryShear.hpp +++ b/src/script_interface/lees_edwards/OscillatoryShear.hpp @@ -16,36 +16,32 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCRIPT_INTERFACE_LEES_EDWARDS_OSCILLATORY_SHEAR_HPP -#define SCRIPT_INTERFACE_LEES_EDWARDS_OSCILLATORY_SHEAR_HPP + +#pragma once #include "core/lees_edwards/lees_edwards.hpp" #include "script_interface/ScriptInterface.hpp" #include "script_interface/auto_parameters/AutoParameters.hpp" -#include - #include +#include namespace ScriptInterface { namespace LeesEdwards { class OscillatoryShear : public Protocol { + using CoreClass = ::LeesEdwards::OscillatoryShear; + public: OscillatoryShear() - : m_protocol{std::make_shared<::LeesEdwards::ActiveProtocol>( - ::LeesEdwards::OscillatoryShear())} { - add_parameters( - {{"initial_pos_offset", - boost::get<::LeesEdwards::OscillatoryShear>(*m_protocol) - .m_initial_pos_offset}, - {"amplitude", - boost::get<::LeesEdwards::OscillatoryShear>(*m_protocol).m_amplitude}, - {"omega", - boost::get<::LeesEdwards::OscillatoryShear>(*m_protocol).m_omega}, - {"time_0", - boost::get<::LeesEdwards::OscillatoryShear>(*m_protocol).m_time_0}}); + : m_protocol{ + std::make_shared<::LeesEdwards::ActiveProtocol>(CoreClass())} { + add_parameters({{"initial_pos_offset", + std::get(*m_protocol).m_initial_pos_offset}, + {"amplitude", std::get(*m_protocol).m_amplitude}, + {"omega", std::get(*m_protocol).m_omega}, + {"time_0", std::get(*m_protocol).m_time_0}}); } std::shared_ptr<::LeesEdwards::ActiveProtocol> protocol() override { return m_protocol; @@ -57,5 +53,3 @@ class OscillatoryShear : public Protocol { } // namespace LeesEdwards } // namespace ScriptInterface - -#endif diff --git a/src/script_interface/lees_edwards/Protocol.hpp b/src/script_interface/lees_edwards/Protocol.hpp index faa09aa5a9e..e4af81552c9 100644 --- a/src/script_interface/lees_edwards/Protocol.hpp +++ b/src/script_interface/lees_edwards/Protocol.hpp @@ -16,8 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -#ifndef SCRIPT_INTERFACE_LEES_EDWARDS_PROTOCOL_HPP -#define SCRIPT_INTERFACE_LEES_EDWARDS_PROTOCOL_HPP + +#pragma once #include "core/lees_edwards/lees_edwards.hpp" @@ -36,5 +36,3 @@ class Protocol : public AutoParameters { } // namespace LeesEdwards } // namespace ScriptInterface - -#endif diff --git a/src/script_interface/system/System.cpp b/src/script_interface/system/System.cpp index 01a5f6584a3..1a8f1a45225 100644 --- a/src/script_interface/system/System.cpp +++ b/src/script_interface/system/System.cpp @@ -43,6 +43,7 @@ #include "script_interface/galilei/ComFixed.hpp" #include "script_interface/galilei/Galilei.hpp" #include "script_interface/integrators/IntegratorHandle.hpp" +#include "script_interface/lees_edwards/LeesEdwards.hpp" #include "script_interface/magnetostatics/Container.hpp" #include @@ -75,6 +76,7 @@ struct System::Leaves { std::shared_ptr comfixed; std::shared_ptr galilei; std::shared_ptr bond_breakage; + std::shared_ptr lees_edwards; #ifdef ELECTROSTATICS std::shared_ptr electrostatics; #endif @@ -145,6 +147,7 @@ System::System() : m_instance{}, m_leaves{std::make_shared()} { add_parameter("comfixed", &Leaves::comfixed); add_parameter("galilei", &Leaves::galilei); add_parameter("bond_breakage", &Leaves::bond_breakage); + add_parameter("lees_edwards", &Leaves::lees_edwards); #ifdef ELECTROSTATICS add_parameter("electrostatics", &Leaves::electrostatics); #endif diff --git a/src/script_interface/walberla/LBFluid.cpp b/src/script_interface/walberla/LBFluid.cpp index e800962bbe6..44c5bbcd698 100644 --- a/src/script_interface/walberla/LBFluid.cpp +++ b/src/script_interface/walberla/LBFluid.cpp @@ -170,21 +170,20 @@ void LBFluid::do_construct(VariantMap const ¶ms) { } m_instance = new_lb_walberla(lb_lattice, lb_visc, lb_dens, single_precision); - if (auto le_protocol = LeesEdwards::get_protocol().lock()) { + auto const &system = ::System::get_system(); + if (auto le_protocol = system.lees_edwards->get_protocol()) { if (lb_kT != 0.) { throw std::runtime_error( "Lees-Edwards LB doesn't support thermalization"); } - auto const &le_bc = ::System::get_system().box_geo->lees_edwards_bc(); + auto const &le_bc = system.box_geo->lees_edwards_bc(); auto lees_edwards_object = std::make_unique( le_bc.shear_direction, le_bc.shear_plane_normal, - [this, le_protocol]() { - auto const &system = ::System::get_system(); + [this, le_protocol, &system]() { return get_pos_offset(system.get_sim_time(), *le_protocol) / m_lb_params->get_agrid(); }, - [this, le_protocol]() { - auto const &system = ::System::get_system(); + [this, le_protocol, &system]() { return get_shear_velocity(system.get_sim_time(), *le_protocol) * (m_lb_params->get_tau() / m_lb_params->get_agrid()); }); diff --git a/testsuite/python/lb_planar_couette.py b/testsuite/python/lb_planar_couette.py index dfdabd4eb72..bb72e47b73c 100644 --- a/testsuite/python/lb_planar_couette.py +++ b/testsuite/python/lb_planar_couette.py @@ -70,7 +70,7 @@ def setUp(self): def tearDown(self): self.system.lb = None - self.system.lees_edwards = espressomd.lees_edwards.LeesEdwards() + self.system.lees_edwards.protocol = None def check_profile(self, u_getter, **kwargs): system = self.system