ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
protocols.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021-2026 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <utils/Vector.hpp>
23
24#include <cmath>
25#include <variant>
26
27namespace LeesEdwards {
28
29// Protocols determining shear rate and positional offset as a function of time
30
31/** Lees-Edwards protocol for un-altered periodic boundary conditions */
32struct Off {
33 double shear_velocity(double) const { return 0.; }
34 double pos_offset(double) const { return 0.; }
35};
36
37/** Lees-Edwards protocol for linear shearing */
41 LinearShear(double initial_offset, double shear_velocity, double time_0)
43 m_time_0{time_0} {}
44 double shear_velocity(double) const { return m_shear_velocity; }
45 double pos_offset(double time) const {
47 }
50 double m_time_0;
51};
52
53/** Lees-Edwards protocol for oscillatory shearing */
58 OscillatoryShear(double initial_offset, double amplitude, double omega,
59 double time_0, double decay_rate = 0.)
60 : m_initial_pos_offset{initial_offset}, m_amplitude{amplitude},
61 m_omega{omega}, m_time_0{time_0}, m_decay_rate{decay_rate} {}
62 double pos_offset(double time) const {
64 m_amplitude * std::exp(-(time - m_time_0) * m_decay_rate) *
65 std::sin(m_omega * (time - m_time_0));
66 }
67 double shear_velocity(double time) const {
68 return -m_decay_rate * std::exp(-(time - m_time_0) * m_decay_rate) *
69 m_amplitude * std::sin(m_omega * (time - m_time_0)) +
70 std::exp(-(time - m_time_0) * m_decay_rate) * m_omega * m_amplitude *
71 std::cos(m_omega * (time - m_time_0));
72 }
75 double m_omega;
76 double m_time_0;
78};
79
80/** Type which holds the currently active protocol */
81using ActiveProtocol = std::variant<Off, LinearShear, OscillatoryShear>;
82
84public:
85 PosOffsetGetter(double time) : m_time{time} {}
86 template <typename T> double operator()(T const &protocol) const {
87 return protocol.pos_offset(m_time);
88 }
89
90private:
91 double m_time;
92};
93
94inline double get_pos_offset(double time, ActiveProtocol const &protocol) {
95 return std::visit(PosOffsetGetter(time), protocol);
96}
97
98/** Visitor to get shear velocity from the Lees-Edwards protocol */
100public:
101 ShearVelocityGetter(double time) : m_time{time} {}
102 template <typename T> double operator()(T const &protocol) const {
103 return protocol.shear_velocity(m_time);
104 }
105
106private:
107 double m_time;
108};
109
110/** Calculation of current velocity */
111inline double get_shear_velocity(double time, ActiveProtocol const &protocol) {
112 return std::visit(ShearVelocityGetter(time), protocol);
113}
114
115} // namespace LeesEdwards
Vector implementation and trait types for boost qvm interoperability.
double operator()(T const &protocol) const
Definition protocols.hpp:86
Visitor to get shear velocity from the Lees-Edwards protocol.
Definition protocols.hpp:99
double operator()(T const &protocol) const
std::variant< Off, LinearShear, OscillatoryShear > ActiveProtocol
Type which holds the currently active protocol.
Definition protocols.hpp:81
double get_shear_velocity(double time, ActiveProtocol const &protocol)
Calculation of current velocity.
double get_pos_offset(double time, ActiveProtocol const &protocol)
Definition protocols.hpp:94
Lees-Edwards protocol for linear shearing.
Definition protocols.hpp:38
double pos_offset(double time) const
Definition protocols.hpp:45
double shear_velocity(double) const
Definition protocols.hpp:44
LinearShear(double initial_offset, double shear_velocity, double time_0)
Definition protocols.hpp:41
Lees-Edwards protocol for un-altered periodic boundary conditions.
Definition protocols.hpp:32
double pos_offset(double) const
Definition protocols.hpp:34
double shear_velocity(double) const
Definition protocols.hpp:33
Lees-Edwards protocol for oscillatory shearing.
Definition protocols.hpp:54
OscillatoryShear(double initial_offset, double amplitude, double omega, double time_0, double decay_rate=0.)
Definition protocols.hpp:58
double shear_velocity(double time) const
Definition protocols.hpp:67
double pos_offset(double time) const
Definition protocols.hpp:62