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-2022 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 */
57 OscillatoryShear(double initial_offset, double amplitude, double omega,
58 double time_0)
59 : m_initial_pos_offset{initial_offset}, m_amplitude{amplitude},
60 m_omega{omega}, m_time_0{time_0} {}
61 double pos_offset(double time) const {
63 m_amplitude * std::sin(m_omega * (time - m_time_0));
64 }
65 double shear_velocity(double time) const {
66 return m_omega * m_amplitude * std::cos(m_omega * (time - m_time_0));
67 }
70 double m_omega;
71 double m_time_0;
72};
73
74/** Type which holds the currently active protocol */
75using ActiveProtocol = std::variant<Off, LinearShear, OscillatoryShear>;
76
78public:
79 PosOffsetGetter(double time) : m_time{time} {}
80 template <typename T> double operator()(T const &protocol) const {
81 return protocol.pos_offset(m_time);
82 }
83
84private:
85 double m_time;
86};
87
88inline double get_pos_offset(double time, ActiveProtocol const &protocol) {
89 return std::visit(PosOffsetGetter(time), protocol);
90}
91
92/** Visitor to get shear velocity from the Lees-Edwards protocol */
94public:
95 ShearVelocityGetter(double time) : m_time{time} {}
96 template <typename T> double operator()(T const &protocol) const {
97 return protocol.shear_velocity(m_time);
98 }
99
100private:
101 double m_time;
102};
103
104/** Calculation of current velocity */
105inline double get_shear_velocity(double time, ActiveProtocol const &protocol) {
106 return std::visit(ShearVelocityGetter(time), protocol);
107}
108
109} // namespace LeesEdwards
Vector implementation and trait types for boost qvm interoperability.
double operator()(T const &protocol) const
Definition protocols.hpp:80
Visitor to get shear velocity from the Lees-Edwards protocol.
Definition protocols.hpp:93
double operator()(T const &protocol) const
Definition protocols.hpp:96
std::variant< Off, LinearShear, OscillatoryShear > ActiveProtocol
Type which holds the currently active protocol.
Definition protocols.hpp:75
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:88
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
double shear_velocity(double time) const
Definition protocols.hpp:65
OscillatoryShear(double initial_offset, double amplitude, double omega, double time_0)
Definition protocols.hpp:57
double pos_offset(double time) const
Definition protocols.hpp:61