ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
lb/Solver.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 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 "system/Leaf.hpp"
23
24#include "utils.hpp"
25
26#include <utils/Vector.hpp>
27
28#include <cassert>
29#include <cmath>
30#include <memory>
31#include <optional>
32
33namespace LB {
34
35struct Solver : public System::Leaf<Solver> {
36 struct Implementation;
37 struct Conversions {
38 double pos_to_lb;
39 double vel_to_md;
41 };
42
43 Solver();
44
45 /** @brief Return true if a LB solver is active. */
46 [[nodiscard]] bool is_solver_set() const;
47
48 /** @brief Remove the LB solver. */
49 void reset();
50
51 /**
52 * @brief Set the LB solver.
53 * For developers: a specialization must exist for every new LB type.
54 */
55 template <typename LB, class... Args> void set(Args... args);
56
57 /**
58 * @brief Connector to the implementation internal state.
59 * For developers: use this mechanism to access the underlying variant.
60 */
61 template <class Connector> void connect(Connector &&connector) const {
62 assert(impl != nullptr);
63 connector(*this->impl);
64 }
65
66 /**
67 * @brief Propagate the LB fluid.
68 */
69 void propagate();
70
71 /**
72 * @brief Perform a full ghost communication.
73 */
75
76 /**
77 * @brief Perform a ghost communication of the PDF field.
78 */
80
81 /**
82 * @brief Perform a ghost communication of the velocity field.
83 */
85
86 /**
87 * @brief Perform a full initialization of the lattice-Boltzmann system.
88 * All derived parameters and the fluid are reset to their default values.
89 */
90 void init() const {}
91
92 /**
93 * @brief Perform LB parameter and boundary velocity checks.
94 */
95 void sanity_checks() const;
96
97 /**
98 * @brief Check if a MD time step is compatible with the LB tau.
99 */
100 void veto_time_step(double time_step) const;
101
102 /**
103 * @brief Check if a thermostat is compatible with the LB temperature.
104 */
105 void veto_kT(double kT) const;
106
107 /**
108 * @brief Perform LB LEbc parameter checks.
109 */
110 void lebc_sanity_checks(unsigned int shear_direction,
111 unsigned int shear_plane_normal) const;
112
113 bool is_gpu() const;
114
115 /**
116 * @brief Get the LB time step.
117 */
118 double get_tau() const;
119
120 /**
121 * @brief Get the LB grid spacing.
122 */
123 double get_agrid() const;
124
125 /**
126 * @brief Get the thermal energy parameter of the LB fluid.
127 */
128 double get_kT() const;
129
130 /**
131 * @brief Get the lattice speed (agrid/tau).
132 */
133 auto get_lattice_speed() const { return get_agrid() / get_tau(); }
134
136
138
139 /**
140 * @brief Calculate the interpolated fluid velocity in LB units.
141 * Use this function in MPI-parallel code. The LB ghost layer is ignored.
142 * @param pos Position in MD units at which the velocity is to be calculated.
143 * @retval interpolated fluid velocity.
144 */
145 std::optional<Utils::Vector3d>
147
148 /**
149 * @brief Calculate the interpolated fluid density in LB units.
150 * Use this function in MPI-parallel code. The LB ghost layer is ignored.
151 * @param pos Position in MD units at which the density is to be calculated.
152 * @retval interpolated fluid density.
153 */
154 std::optional<double>
156
157 /**
158 * @brief Calculate the interpolated fluid velocity in MD units.
159 * Special method used only for particle coupling. Uses the LB ghost layer.
160 * Achieved by linear interpolation (eq. 11 in @cite ahlrichs99a).
161 * @param pos Position in MD units at which the velocity is to be calculated.
162 * @retval interpolated fluid velocity.
163 */
166
167 std::vector<Utils::Vector3d> get_coupling_interpolated_velocities(
168 std::vector<Utils::Vector3d> const &pos) const;
169
170 void add_forces_at_pos(std::vector<Utils::Vector3d> const &pos,
171 std::vector<Utils::Vector3d> const &forces);
172
173 /**
174 * @brief Add a force density to the fluid at the given position.
175 * @param pos Position at which the force density is to be applied.
176 * @param force_density Force density to apply.
177 */
178 void add_force_density(Utils::Vector3d const &pos,
179 Utils::Vector3d const &force_density);
180
181 void on_boxl_change();
182 void on_node_grid_change();
184 void on_timestep_change();
188 void veto_boxl_change() const;
189
190private:
191 /** @brief Pointer-to-implementation. */
192 std::unique_ptr<Implementation> impl;
193 Conversions m_conv{};
194};
195
196} // namespace LB
Vector implementation and trait types for boost qvm interoperability.
Abstract class that represents a component of the system.
void veto_boxl_change() const
void lebc_sanity_checks(unsigned int shear_direction, unsigned int shear_plane_normal) const
Perform LB LEbc parameter checks.
void add_force_density(Utils::Vector3d const &pos, Utils::Vector3d const &force_density)
Add a force density to the fluid at the given position.
Utils::Vector3d get_coupling_interpolated_velocity(Utils::Vector3d const &pos) const
Calculate the interpolated fluid velocity in MD units.
void connect(Connector &&connector) const
Connector to the implementation internal state.
Definition lb/Solver.hpp:61
void sanity_checks() const
Perform LB parameter and boundary velocity checks.
Definition lb/Solver.cpp:91
void on_timestep_change()
void on_boxl_change()
void ghost_communication()
Perform a full ghost communication.
Definition lb/Solver.cpp:76
void propagate()
Propagate the LB fluid.
Definition lb/Solver.cpp:71
void reset()
Remove the LB solver.
Definition lb/Solver.cpp:66
std::optional< Utils::Vector3d > get_interpolated_velocity(Utils::Vector3d const &pos) const
Calculate the interpolated fluid velocity in LB units.
bool is_solver_set() const
Return true if a LB solver is active.
Definition lb/Solver.cpp:64
void ghost_communication_pdf()
Perform a ghost communication of the PDF field.
Definition lb/Solver.cpp:81
void init() const
Perform a full initialization of the lattice-Boltzmann system.
Definition lb/Solver.hpp:90
double get_tau() const
Get the LB time step.
void on_temperature_change()
std::optional< double > get_interpolated_density(Utils::Vector3d const &pos) const
Calculate the interpolated fluid density in LB units.
void add_forces_at_pos(std::vector< Utils::Vector3d > const &pos, std::vector< Utils::Vector3d > const &forces)
void set(Args... args)
Set the LB solver.
void veto_kT(double kT) const
Check if a thermostat is compatible with the LB temperature.
double get_agrid() const
Get the LB grid spacing.
Utils::VectorXd< 9 > get_pressure_tensor() const
void update_collision_model()
void veto_time_step(double time_step) const
Check if a MD time step is compatible with the LB tau.
Definition lb/Solver.cpp:98
auto get_lattice_speed() const
Get the lattice speed (agrid/tau).
void ghost_communication_vel()
Perform a ghost communication of the velocity field.
Definition lb/Solver.cpp:86
void on_lees_edwards_change()
void on_node_grid_change()
Utils::Vector3d get_momentum() const
void on_cell_structure_change()
std::vector< Utils::Vector3d > get_coupling_interpolated_velocities(std::vector< Utils::Vector3d > const &pos) const
bool is_gpu() const
double get_kT() const
Get the thermal energy parameter of the LB fluid.