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 initialization of the lattice-Boltzmann system.
73 * All derived parameters and the fluid are reset to their default values.
74 */
75 void init() const {}
76
77 /**
78 * @brief Perform LB parameter and boundary velocity checks.
79 */
80 void sanity_checks() const;
81
82 /**
83 * @brief Check if a MD time step is compatible with the LB tau.
84 */
85 void veto_time_step(double time_step) const;
86
87 /**
88 * @brief Check if a thermostat is compatible with the LB temperature.
89 */
90 void veto_kT(double kT) const;
91
92 /**
93 * @brief Perform LB LEbc parameter checks.
94 */
95 void lebc_sanity_checks(unsigned int shear_direction,
96 unsigned int shear_plane_normal) const;
97
98 bool is_gpu() const;
99
100 /**
101 * @brief Get the LB time step.
102 */
103 double get_tau() const;
104
105 /**
106 * @brief Get the LB grid spacing.
107 */
108 double get_agrid() const;
109
110 /**
111 * @brief Get the thermal energy parameter of the LB fluid.
112 */
113 double get_kT() const;
114
115 /**
116 * @brief Get the lattice speed (agrid/tau).
117 */
118 auto get_lattice_speed() const { return get_agrid() / get_tau(); }
119
121
123
124 /**
125 * @brief Calculate the interpolated fluid velocity in LB units.
126 * Use this function in MPI-parallel code. The LB ghost layer is ignored.
127 * @param pos Position in MD units at which the velocity is to be calculated.
128 * @retval interpolated fluid velocity.
129 */
130 std::optional<Utils::Vector3d>
132
133 /**
134 * @brief Calculate the interpolated fluid density in LB units.
135 * Use this function in MPI-parallel code. The LB ghost layer is ignored.
136 * @param pos Position in MD units at which the density is to be calculated.
137 * @retval interpolated fluid density.
138 */
139 std::optional<double>
141
142 /**
143 * @brief Calculate the interpolated fluid velocity in MD units.
144 * Special method used only for particle coupling. Uses the LB ghost layer.
145 * Achieved by linear interpolation (eq. 11 in @cite ahlrichs99a).
146 * @param pos Position in MD units at which the velocity is to be calculated.
147 * @retval interpolated fluid velocity.
148 */
151
152 std::vector<Utils::Vector3d> get_coupling_interpolated_velocities(
153 std::vector<Utils::Vector3d> const &pos) const;
154
155 void add_forces_at_pos(std::vector<Utils::Vector3d> const &pos,
156 std::vector<Utils::Vector3d> const &forces);
157
158 /**
159 * @brief Add a force density to the fluid at the given position.
160 * @param pos Position at which the force density is to be applied.
161 * @param force_density Force density to apply.
162 */
164 Utils::Vector3d const &force_density);
165
166 void on_boxl_change();
167 void on_node_grid_change();
169 void on_timestep_change();
171 void veto_boxl_change() const;
172
173private:
174 /** @brief Pointer-to-implementation. */
175 std::unique_ptr<Implementation> impl;
176 Conversions m_conv{};
177};
178
179} // namespace LB
Vector implementation and trait types for boost qvm interoperability.
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
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.
Definition lb/Solver.cpp:96
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:76
void on_timestep_change()
void on_boxl_change()
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 init() const
Perform a full initialization of the lattice-Boltzmann system.
Definition lb/Solver.hpp:75
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.
Definition lb/Solver.cpp:90
double get_agrid() const
Get the LB grid spacing.
Utils::VectorXd< 9 > get_pressure_tensor() const
void veto_time_step(double time_step) const
Check if a MD time step is compatible with the LB tau.
Definition lb/Solver.cpp:83
auto get_lattice_speed() const
Get the lattice speed (agrid/tau).
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.