Skip to content

Commit

Permalink
core: Add initial_pos_offset to Oscillatory LEbc
Browse files Browse the repository at this point in the history
  • Loading branch information
jngrad committed Apr 5, 2022
1 parent 833131d commit cd6765a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
16 changes: 11 additions & 5 deletions src/core/lees_edwards/protocols.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ struct Off {

/** Lees-Edwards protocol for linear shearing */
struct LinearShear {
LinearShear() : m_initial_pos_offset{0}, m_shear_velocity{0}, m_time_0{0} {}
LinearShear()
: m_initial_pos_offset{0.}, m_shear_velocity{0.}, m_time_0{0.} {}
LinearShear(double initial_offset, double shear_velocity, double time_0)
: m_initial_pos_offset{initial_offset},
m_shear_velocity{shear_velocity}, m_time_0{time_0} {}
Expand All @@ -52,15 +53,20 @@ struct LinearShear {

/** Lees-Edwards protocol for oscillatory shearing */
struct OscillatoryShear {
OscillatoryShear() : m_amplitude{0}, m_omega{0}, m_time_0{0} {}
OscillatoryShear(double amplitude, double omega, double time_0)
: m_amplitude{amplitude}, m_omega{omega}, m_time_0{time_0} {}
OscillatoryShear()
: m_initial_pos_offset{0.}, m_amplitude{0.}, m_omega{0.}, m_time_0{0.} {}
OscillatoryShear(double initial_offset, double amplitude, double omega,
double time_0)
: m_initial_pos_offset{initial_offset},
m_amplitude{amplitude}, m_omega{omega}, m_time_0{time_0} {}
double pos_offset(double time) const {
return m_amplitude * std::sin(m_omega * (time - m_time_0));
return m_initial_pos_offset +
m_amplitude * std::sin(m_omega * (time - m_time_0));
}
double shear_velocity(double time) const {
return m_omega * m_amplitude * std::cos(m_omega * (time - m_time_0));
}
double m_initial_pos_offset;
double m_amplitude;
double m_omega;
double m_time_0;
Expand Down
6 changes: 4 additions & 2 deletions src/core/unit_tests/lees_edwards_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,12 @@ BOOST_AUTO_TEST_CASE(protocol_lin) {

BOOST_AUTO_TEST_CASE(protocol_osc) {
auto const t0 = 1.2;
auto const x0 = 0.1;
auto const a = 3.1;
auto const o = 2.1;
auto osc = OscillatoryShear(a, o, t0);
BOOST_CHECK_CLOSE(get_pos_offset(3.3, osc), a * sin(o * (3.3 - t0)), tol);
auto osc = OscillatoryShear(x0, a, o, t0);
BOOST_CHECK_CLOSE(get_pos_offset(3.3, osc), x0 + a * sin(o * (3.3 - t0)),
tol);
BOOST_CHECK_CLOSE(get_shear_velocity(3.3, osc), a * o * cos(o * (3.3 - t0)),
tol);
}
2 changes: 2 additions & 0 deletions src/python/espressomd/lees_edwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class OscillatoryShear(ScriptInterfaceHelper):
Parameters
----------
initial_pos_offset : :obj:`float`
Positional offset at the Lees--Edwards boundary at t=0.
amplitude : :obj:`float`
Maximum amplitude of the positional offset at the Lees--Edwards boundary.
omega : :obj:`float`
Expand Down
5 changes: 4 additions & 1 deletion src/script_interface/lees_edwards/OscillatoryShear.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ class OscillatoryShear : public Protocol {
: m_protocol{std::make_shared<::LeesEdwards::ActiveProtocol>(
::LeesEdwards::OscillatoryShear())} {
add_parameters(
{{"amplitude",
{{"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},
Expand Down
9 changes: 5 additions & 4 deletions testsuite/python/lees_edwards.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@


np.random.seed(42)
params_lin = {'shear_velocity': 1.2, 'initial_pos_offset': 0.1, 'time_0': 0.1}
params_osc = {'amplitude': 2.3, 'omega': 2.51, 'time_0': -2.1}
params_lin = {'initial_pos_offset': 0.1, 'time_0': 0.1, 'shear_velocity': 1.2}
params_osc = {'initial_pos_offset': 0.1, 'time_0': -2.1, 'amplitude': 2.3,
'omega': 2.51}
lin_protocol = espressomd.lees_edwards.LinearShear(**params_lin)
osc_protocol = espressomd.lees_edwards.OscillatoryShear(**params_osc)
off_protocol = espressomd.lees_edwards.Off()
Expand Down Expand Up @@ -113,7 +114,7 @@ def test_protocols(self):
# check that LE offsets are recalculated on simulation time change
for time in [0., 2.3]:
system.time = time
expected_pos = params_osc['amplitude'] * \
expected_pos = params_osc['initial_pos_offset'] + params_osc['amplitude'] * \
np.sin(params_osc['omega'] * (time - params_osc['time_0']))
expected_vel = params_osc['amplitude'] * params_osc['omega'] * \
np.cos(params_osc['omega'] * (time - params_osc['time_0']))
Expand All @@ -124,7 +125,7 @@ def test_protocols(self):
# Check that time change during integration updates offsets
system.integrator.run(1)
time = system.time
expected_pos = params_osc['amplitude'] * \
expected_pos = params_osc['initial_pos_offset'] + params_osc['amplitude'] * \
np.sin(params_osc['omega'] * (time - params_osc['time_0']))
expected_vel = params_osc['amplitude'] * params_osc['omega'] * \
np.cos(params_osc['omega'] * (time - params_osc['time_0']))
Expand Down

0 comments on commit cd6765a

Please sign in to comment.