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 <functional>
31#include <memory>
32#include <optional>
33#include <vector>
34
35namespace LB {
36
37struct Solver : public System::Leaf<Solver> {
38 struct Implementation;
39 struct Conversions {
40 double pos_to_lb;
41 double vel_to_md;
43 };
44
45 Solver();
46
47 /** @brief Return true if a LB solver is active. */
48 [[nodiscard]] bool is_solver_set() const;
49
50 /** @brief Remove the LB solver. */
51 void reset();
52
53 /**
54 * @brief Set the LB solver.
55 * For developers: a specialization must exist for every new LB type.
56 */
57 template <typename LB, class... Args> void set(Args... args);
58
59 /**
60 * @brief Connector to the implementation internal state.
61 * For developers: use this mechanism to access the underlying variant.
62 */
63 template <class Connector> void connect(Connector &&connector) const {
64 assert(impl != nullptr);
65 connector(*this->impl);
66 }
67
68 /**
69 * @brief Propagate the LB fluid.
70 */
71 void propagate();
72
73 /**
74 * @brief Perform a full ghost communication.
75 */
77
78 /**
79 * @brief Perform a ghost communication of the PDF field.
80 */
82
83 /**
84 * @brief Perform a ghost communication of the velocity field.
85 */
87
88 /**
89 * @brief Perform a full initialization of the lattice-Boltzmann system.
90 * All derived parameters and the fluid are reset to their default values.
91 */
92 void init() const {}
93
94 /**
95 * @brief Perform LB parameter and boundary velocity checks.
96 */
97 void sanity_checks() const;
98
99 /**
100 * @brief Check if a MD time step is compatible with the LB tau.
101 */
102 void veto_time_step(double time_step) const;
103
104 /**
105 * @brief Check if a thermostat is compatible with the LB temperature.
106 */
107 void veto_kT(double kT) const;
108
109 /**
110 * @brief Perform LB LEbc parameter checks.
111 */
112 void lebc_sanity_checks(unsigned int shear_direction,
113 unsigned int shear_plane_normal) const;
114
115 bool is_gpu() const;
116
117 /**
118 * @brief Get the LB time step.
119 */
120 double get_tau() const;
121
122 /**
123 * @brief Get the LB grid spacing.
124 */
125 double get_agrid() const;
126
127 /**
128 * @brief Get the thermal energy parameter of the LB fluid.
129 */
130 double get_kT() const;
131
132 /**
133 * @brief Get the lattice speed (agrid/tau).
134 */
135 auto get_lattice_speed() const { return get_agrid() / get_tau(); }
136
138
140
141 /** @brief Make a functor to check if a position is in the local domain. */
142 std::function<bool(Utils::Vector3d const &)>
143 make_lattice_position_checker(bool consider_points_in_halo) const;
144
145 /**
146 * @brief Calculate the interpolated fluid velocity in LB units.
147 * Use this function in MPI-parallel code. The LB ghost layer is ignored.
148 * @param pos Position in MD units at which the velocity is calculated.
149 * @retval interpolated fluid velocity in LB units.
150 */
151 std::optional<Utils::Vector3d>
153
154 /**
155 * @brief Calculate the interpolated fluid density in LB units.
156 * Use this function in MPI-parallel code. The LB ghost layer is ignored.
157 * @param pos Position in MD units at which the density is calculated.
158 * @retval interpolated fluid density in LB units.
159 */
160 std::optional<double>
162
163 /**
164 * @brief Calculate the interpolated fluid densities in LB units.
165 * The LB ghost layer is used.
166 * Achieved by linear interpolation (eq. 11 in @cite ahlrichs99a).
167 * @param pos Positions in MD units at which the velocities are calculated.
168 * @retval interpolated fluid densities in LB units.
169 */
170 std::vector<double>
171 get_interpolated_densities(std::vector<Utils::Vector3d> const &pos) const;
172
173 /**
174 * @brief Calculate the interpolated fluid velocity in MD units.
175 * Special method used only for particle coupling. Uses the LB ghost layer.
176 * Achieved by linear interpolation (eq. 11 in @cite ahlrichs99a).
177 * @param pos Position in MD units at which the velocity is calculated.
178 * @retval interpolated fluid velocity in MD units.
179 */
182
183 /**
184 * @brief Calculate the interpolated fluid velocities in MD units.
185 * Special method used only for particle coupling. Uses the LB ghost layer.
186 * Achieved by linear interpolation (eq. 11 in @cite ahlrichs99a).
187 * @param pos Positions in MD units at which the velocities are calculated.
188 * @retval interpolated fluid velocities in MD units.
189 */
190 std::vector<Utils::Vector3d> get_coupling_interpolated_velocities(
191 std::vector<Utils::Vector3d> const &pos) const;
192
193 void add_forces_at_pos(std::vector<Utils::Vector3d> const &pos,
194 std::vector<Utils::Vector3d> const &forces);
195
196 /**
197 * @brief Add a force density to the fluid at the given position.
198 * @param pos Position at which the force density is to be applied.
199 * @param force_density Force density to apply.
200 */
201 void add_force_density(Utils::Vector3d const &pos,
202 Utils::Vector3d const &force_density);
203
204 void on_boxl_change();
205 void on_node_grid_change();
207 void on_timestep_change();
211 void veto_boxl_change() const;
212
213private:
214 /** @brief Pointer-to-implementation. */
215 std::unique_ptr<Implementation> impl;
216 Conversions m_conv{};
217};
218
219} // 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.
std::vector< double > get_interpolated_densities(std::vector< Utils::Vector3d > const &pos) const
Calculate the interpolated fluid densities in LB units.
void add_force_density(Utils::Vector3d const &pos, Utils::Vector3d const &force_density)
Add a force density to the fluid at the given position.
std::function< bool(Utils::Vector3d const &)> make_lattice_position_checker(bool consider_points_in_halo) const
Make a functor to check if a position is in the local domain.
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:63
void sanity_checks() const
Perform LB parameter and boundary velocity checks.
Definition lb/Solver.cpp:92
void on_timestep_change()
void on_boxl_change()
void ghost_communication()
Perform a full ghost communication.
Definition lb/Solver.cpp:77
void propagate()
Propagate the LB fluid.
Definition lb/Solver.cpp:72
void reset()
Remove the LB solver.
Definition lb/Solver.cpp:67
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:65
void ghost_communication_pdf()
Perform a ghost communication of the PDF field.
Definition lb/Solver.cpp:82
void init() const
Perform a full initialization of the lattice-Boltzmann system.
Definition lb/Solver.hpp:92
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:99
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:87
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
Calculate the interpolated fluid velocities in MD units.
bool is_gpu() const
double get_kT() const
Get the thermal energy parameter of the LB fluid.