ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
lees_edwards.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 "BoxGeometry.hpp"
23#include "Particle.hpp"
25#include "system/Leaf.hpp"
26
27#include <cmath>
28#include <memory>
29
30namespace LeesEdwards {
32protected:
34
35public:
36 UpdateOffset(BoxGeometry const &box) : m_le{box.lees_edwards_bc()} {}
37
39 [[maybe_unused]] double pos_prefactor = 1.0) const {
40 // Disabled as long as we do not use a two step LE update
41 }
42};
43
44class Push : public UpdateOffset {
45 BoxGeometry const &m_box;
46
47public:
48 Push(BoxGeometry const &box) : UpdateOffset{box}, m_box{box} {}
49
50 void operator()(Particle &p, double pos_prefactor = 1.0) const {
51 // Lees-Edwards acts at the zero step for the velocity half update and at
52 // the midstep for the position.
53 //
54 // The update of the velocity at the end of the time step is triggered by
55 // the flag and occurs in @ref propagate_vel_finalize_p_inst
56 if (p.pos()[m_le.shear_plane_normal] >=
58 p.lees_edwards_flag() = -1; // perform a negative half velocity shift
59 } else if (p.pos()[m_le.shear_plane_normal] < 0) {
60 p.lees_edwards_flag() = 1; // perform a positive half velocity shift
61 } else {
62 p.lees_edwards_flag() = 0;
63 }
64
65 auto const dir = static_cast<double>(p.lees_edwards_flag());
67 p.pos()[m_le.shear_direction] += pos_prefactor * dir * m_le.pos_offset;
68 p.lees_edwards_offset() -= pos_prefactor * dir * m_le.pos_offset;
69 m_box.fold_position(p.pos(), p.image_box());
70 // UpdateOffset::operator()(p,pos_prefactor);
71 }
72};
73
74inline double velocity_shift(short int le_flag, BoxGeometry const &box) {
75 if (box.type() != BoxType::LEES_EDWARDS)
76 return 0.;
77
78 return le_flag * box.lees_edwards_bc().shear_velocity;
79}
80
82 return Utils::unit_vector<double>(box.lees_edwards_bc().shear_direction);
83}
84
86 double pos_offset_at_last_resort) {
87 if (box.type() == BoxType::LEES_EDWARDS) {
88 return shear_direction(box) * std::fabs(box.lees_edwards_bc().pos_offset -
89 pos_offset_at_last_resort);
90 }
91 return {};
92}
93
94class LeesEdwards : public System::Leaf<LeesEdwards> {
95 std::shared_ptr<ActiveProtocol> m_protocol;
96
97public:
98 /** @brief Get currently active Lees-Edwards protocol. */
99 auto get_protocol() const { return m_protocol; }
100
101 /** @brief Set a new Lees-Edwards protocol. */
102 void set_protocol(std::shared_ptr<ActiveProtocol> protocol);
103
104 /** @brief Delete the currently active Lees-Edwards protocol. */
105 void unset_protocol();
106
107 void update_box_params(BoxGeometry &box_geo, double sim_time);
108};
109
110} // namespace LeesEdwards
@ LEES_EDWARDS
Utils::Vector3d const & length() const
Box length.
LeesEdwardsBC const & lees_edwards_bc() const
BoxType type() const
void fold_position(Utils::Vector3d &pos, Utils::Vector3i &image_box) const
Fold coordinates to primary simulation box in-place.
auto get_protocol() const
Get currently active Lees-Edwards protocol.
Push(BoxGeometry const &box)
void operator()(Particle &p, double pos_prefactor=1.0) const
LeesEdwardsBC const & m_le
UpdateOffset(BoxGeometry const &box)
void operator()(Particle &, double pos_prefactor=1.0) const
Abstract class that represents a component of the system.
Utils::Vector3d verlet_list_offset(BoxGeometry const &box, double pos_offset_at_last_resort)
double velocity_shift(short int le_flag, BoxGeometry const &box)
Utils::Vector3d shear_direction(BoxGeometry const &box)
unsigned int shear_plane_normal
unsigned int shear_direction
Struct holding all information for one particle.
Definition Particle.hpp:450
auto const & lees_edwards_offset() const
Definition Particle.hpp:501
auto const & lees_edwards_flag() const
Definition Particle.hpp:503
auto const & v() const
Definition Particle.hpp:488
auto const & image_box() const
Definition Particle.hpp:499
auto const & pos() const
Definition Particle.hpp:486