ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBWalberlaBase.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-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/**
23 * @file
24 * @ref LBWalberlaBase provides the public interface of the LB
25 * waLBerla bridge. It relies on type erasure to hide the waLBerla
26 * implementation details from the ESPResSo core. It is implemented
27 * by @ref walberla::LBWalberlaImpl.
28 */
29
32
33#include <utils/Vector.hpp>
34
35#include <cstddef>
36#include <functional>
37#include <memory>
38#include <optional>
39#include <vector>
40
41/** @brief Interface of a lattice-based fluid model. */
43public:
44 ~LBWalberlaBase() override = default;
45
46 /**
47 * @brief Integrate LB for one time step.
48 * The ghost layer may be out-of-date after integration.
49 * Call @ref ghost_communication() to refresh them before
50 * calling any getter function that reads from the halo region.
51 */
52 virtual void integrate() = 0;
53
54 /** @brief Perform a full ghost communication. */
55 virtual void ghost_communication() = 0;
56
57 /** @brief Perform a ghost communication of the PDF field. */
58 virtual void ghost_communication_pdf() = 0;
59
60 /** @brief Perform a ghost communication of the velocity field. */
61 virtual void ghost_communication_vel() = 0;
62
63 /** @brief Perform a ghost communication of the last applied forces field. */
64 virtual void ghost_communication_laf() = 0;
65
66 /** @brief Number of discretized velocities in the PDF. */
67 virtual std::size_t stencil_size() const noexcept = 0;
68
69 /** @brief Whether kernels use double-precision floating point numbers. */
70 [[nodiscard]] virtual bool is_double_precision() const noexcept = 0;
71
72 /** @brief Make a functor to check if a position is in the local domain. */
73 virtual std::function<bool(Utils::Vector3d const &)>
74 make_lattice_position_checker(bool consider_points_in_halo) const = 0;
75
76 /** @brief Get interpolated velocities at a position. */
77 virtual std::optional<Utils::Vector3d>
78 get_velocity_at_pos(Utils::Vector3d const &position,
79 bool consider_points_in_halo = false) const = 0;
80
81 /** @brief Get interpolated velocities at positions. */
82 virtual std::vector<Utils::Vector3d>
83 get_velocities_at_pos(std::vector<Utils::Vector3d> const &pos) = 0;
84
85 /** @brief Get interpolated densities at a position. */
86 virtual std::optional<double>
87 get_density_at_pos(Utils::Vector3d const &position,
88 bool consider_points_in_halo = false) const = 0;
89
90 /** @brief Get interpolated densities at positions. */
91 virtual std::vector<double>
92 get_densities_at_pos(std::vector<Utils::Vector3d> const &pos) = 0;
93
94 /**
95 * @brief Interpolate a force to the stored forces to be applied on nodes
96 * in the next time step.
97 */
98 virtual bool add_force_at_pos(Utils::Vector3d const &position,
99 Utils::Vector3d const &force) = 0;
100
101 /**
102 * @brief Interpolate forces to the stored forces to be applied on nodes
103 * in the next time step.
104 */
105 virtual void
106 add_forces_at_pos(std::vector<Utils::Vector3d> const &positions,
107 std::vector<Utils::Vector3d> const &forces) = 0;
108
109 /** @brief Get stored force to be applied on node in the next time step. */
110 virtual std::optional<Utils::Vector3d>
111 get_node_force_to_be_applied(Utils::Vector3i const &node) const = 0;
112
113 /** @brief Get stored force that was applied on node in the last time step. */
114 virtual std::optional<Utils::Vector3d>
115 get_node_last_applied_force(Utils::Vector3i const &node,
116 bool consider_ghosts = false) const = 0;
117
118 /** @brief Set stored force that was applied on node in the last time step. */
119 virtual bool set_node_last_applied_force(Utils::Vector3i const &node,
120 Utils::Vector3d const &force) = 0;
121
122 /** @brief Get stored force that was applied on slice in the last time step.
123 */
124 virtual std::vector<double>
125 get_slice_last_applied_force(Utils::Vector3i const &lower_corner,
126 Utils::Vector3i const &upper_corner) const = 0;
127
128 /** @brief Set stored force that was applied on slice in the last time step.
129 */
130 virtual void
131 set_slice_last_applied_force(Utils::Vector3i const &lower_corner,
132 Utils::Vector3i const &upper_corner,
133 std::vector<double> const &force) = 0;
134
135 /** @brief Get node population. */
136 virtual std::optional<std::vector<double>>
137 get_node_population(Utils::Vector3i const &node,
138 bool consider_ghosts = false) const = 0;
139
140 /** @brief Set node population. */
141 virtual bool set_node_population(Utils::Vector3i const &node,
142 std::vector<double> const &population) = 0;
143
144 /** @brief Get slice population. */
145 virtual std::vector<double>
146 get_slice_population(Utils::Vector3i const &lower_corner,
147 Utils::Vector3i const &upper_corner) const = 0;
148
149 /** @brief Set slice population. */
150 virtual void set_slice_population(Utils::Vector3i const &lower_corner,
151 Utils::Vector3i const &upper_corner,
152 std::vector<double> const &population) = 0;
153
154 /** @brief Get node velocity. */
155 virtual std::optional<Utils::Vector3d>
156 get_node_velocity(Utils::Vector3i const &node,
157 bool consider_ghosts = false) const = 0;
158
159 /** @brief Set node velocity. */
160 virtual bool set_node_velocity(Utils::Vector3i const &node,
161 Utils::Vector3d const &v) = 0;
162
163 /** @brief Get slice velocity. */
164 virtual std::vector<double>
165 get_slice_velocity(Utils::Vector3i const &lower_corner,
166 Utils::Vector3i const &upper_corner) const = 0;
167
168 /** @brief Set slice velocity. */
169 virtual void set_slice_velocity(Utils::Vector3i const &lower_corner,
170 Utils::Vector3i const &upper_corner,
171 std::vector<double> const &velocity) = 0;
172
173 /** @brief Get node density. */
174 virtual std::optional<double>
175 get_node_density(Utils::Vector3i const &node,
176 bool consider_ghosts = false) const = 0;
177
178 /** @brief Set node density. */
179 virtual bool set_node_density(Utils::Vector3i const &node,
180 double density) = 0;
181
182 /** @brief Get slice density. */
183 virtual std::vector<double>
184 get_slice_density(Utils::Vector3i const &lower_corner,
185 Utils::Vector3i const &upper_corner) const = 0;
186
187 /** @brief Set slice density. */
188 virtual void set_slice_density(Utils::Vector3i const &lower_corner,
189 Utils::Vector3i const &upper_corner,
190 std::vector<double> const &density) = 0;
191
192 /** @brief Get node velocity boundary conditions. */
193 virtual std::optional<Utils::Vector3d>
195 bool consider_ghosts = false) const = 0;
196
197 /** @brief Set node velocity boundary conditions. */
198 virtual bool
200 Utils::Vector3d const &velocity) = 0;
201
202 /** @brief Get slice velocity boundary conditions. */
203 virtual std::vector<std::optional<Utils::Vector3d>>
204 get_slice_velocity_at_boundary(Utils::Vector3i const &lower_corner,
205 Utils::Vector3i const &upper_corner) const = 0;
206
207 /** @brief Set slice velocity boundary conditions. */
209 Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner,
210 std::vector<std::optional<Utils::Vector3d>> const &velocity) = 0;
211
212 /** @brief Get (stored) force applied on node due to boundary condition. */
213 virtual std::optional<Utils::Vector3d>
214 get_node_boundary_force(Utils::Vector3i const &node) const = 0;
215
216 /** @brief Remove a node from the boundaries. */
217 virtual bool remove_node_from_boundary(Utils::Vector3i const &node) = 0;
218
219 /** @brief Check if node has velocity boundary conditions. */
220 virtual std::optional<bool>
221 get_node_is_boundary(Utils::Vector3i const &node,
222 bool consider_ghosts = false) const = 0;
223
224 /** @brief Check if slice has velocity boundary conditions. */
225 virtual std::vector<bool>
226 get_slice_is_boundary(Utils::Vector3i const &lower_corner,
227 Utils::Vector3i const &upper_corner) const = 0;
228
229 /** @brief Rebuild the UBB field. This is an expensive operation. */
230 virtual void reallocate_ubb_field() = 0;
231
232 /** @brief Clear the boundary flag field and the UBB field. */
233 virtual void clear_boundaries() = 0;
234
235 /** @brief Update boundary conditions from a rasterized shape. */
236 virtual void update_boundary_from_shape(std::vector<int> const &,
237 std::vector<double> const &) = 0;
238
239 /** @brief Configure the default collision model. */
240 virtual void set_collision_model(double kT, unsigned int seed) = 0;
241
242 /** @brief Configure a thermalized collision model for Lees-Edwards. */
243 virtual void
244 set_collision_model(std::unique_ptr<LeesEdwardsPack> &&lees_edwards_pack) = 0;
245
246 /** @brief Check Lees-Edwards boundary conditions. */
247 virtual void check_lebc(unsigned int shear_direction,
248 unsigned int shear_plane_normal) const = 0;
249
250 /** @brief Get node pressure tensor. */
251 virtual std::optional<Utils::VectorXd<9>>
252 get_node_pressure_tensor(Utils::Vector3i const &node) const = 0;
253
254 /** @brief Get slice pressure tensor. */
255 virtual std::vector<double>
256 get_slice_pressure_tensor(Utils::Vector3i const &lower_corner,
257 Utils::Vector3i const &upper_corner) const = 0;
258
259 /** @brief Calculate boundary force from a rasterized shape. */
260 virtual Utils::Vector3d
261 get_boundary_force_from_shape(std::vector<int> const &raster_flat) const = 0;
262
263 /** @brief Calculate boundary force of the local domain. */
264 virtual Utils::Vector3d get_boundary_force() const = 0;
265
266 /** @brief Calculate average pressure tensor of the local domain. */
267 virtual Utils::VectorXd<9> get_pressure_tensor() const = 0;
268
269 /** @brief Calculate momentum of the local domain. */
270 virtual Utils::Vector3d get_momentum() const = 0;
271
272 /** @brief Set a global external force. */
273 virtual void set_external_force(Utils::Vector3d const &ext_force) = 0;
274
275 /** @brief Get the global external force. */
276 virtual Utils::Vector3d get_external_force() const noexcept = 0;
277
278 /** @brief Set the fluid viscosity. */
279 virtual void set_viscosity(double viscosity) = 0;
280
281 /** @brief Get the fluid viscosity. */
282 virtual double get_viscosity() const noexcept = 0;
283
284 /** @brief Get the fluid density. */
285 virtual double get_density() const noexcept = 0;
286
287 /** @brief Get the fluid temperature (if thermalized). */
288 virtual double get_kT() const noexcept = 0;
289
290 /** @brief Get the RNG seed (if thermalized). */
291 virtual unsigned int get_seed() const noexcept = 0;
292
293 /** @brief Set the RNG counter (if thermalized). */
294 [[nodiscard]] virtual std::optional<uint64_t> get_rng_state() const = 0;
295
296 /** @brief Set the RNG counter (if thermalized). */
297 virtual void set_rng_state(uint64_t counter) = 0;
298
299 /** @brief Get the velocity field id */
300 [[nodiscard]] virtual std::size_t get_velocity_field_id() const noexcept = 0;
301
302 /** @brief Get the force field id */
303 [[nodiscard]] virtual std::size_t get_force_field_id() const noexcept = 0;
304
305 /** @brief Get whether the kernels run on GPUs. */
306 [[nodiscard]] virtual bool is_gpu() const noexcept = 0;
307};
Vector implementation and trait types for boost qvm interoperability.
Interface of a lattice-based fluid model.
virtual bool remove_node_from_boundary(Utils::Vector3i const &node)=0
Remove a node from the boundaries.
virtual std::optional< Utils::Vector3d > get_node_velocity(Utils::Vector3i const &node, bool consider_ghosts=false) const =0
Get node velocity.
virtual bool set_node_last_applied_force(Utils::Vector3i const &node, Utils::Vector3d const &force)=0
Set stored force that was applied on node in the last time step.
virtual std::optional< Utils::Vector3d > get_node_velocity_at_boundary(Utils::Vector3i const &node, bool consider_ghosts=false) const =0
Get node velocity boundary conditions.
virtual bool add_force_at_pos(Utils::Vector3d const &position, Utils::Vector3d const &force)=0
Interpolate a force to the stored forces to be applied on nodes in the next time step.
virtual std::optional< Utils::Vector3d > get_node_last_applied_force(Utils::Vector3i const &node, bool consider_ghosts=false) const =0
Get stored force that was applied on node in the last time step.
virtual double get_density() const noexcept=0
Get the fluid density.
virtual std::optional< Utils::Vector3d > get_velocity_at_pos(Utils::Vector3d const &position, bool consider_points_in_halo=false) const =0
Get interpolated velocities at a position.
virtual Utils::Vector3d get_boundary_force() const =0
Calculate boundary force of the local domain.
virtual Utils::VectorXd< 9 > get_pressure_tensor() const =0
Calculate average pressure tensor of the local domain.
virtual bool is_gpu() const noexcept=0
Get whether the kernels run on GPUs.
virtual std::optional< bool > get_node_is_boundary(Utils::Vector3i const &node, bool consider_ghosts=false) const =0
Check if node has velocity boundary conditions.
virtual std::optional< double > get_density_at_pos(Utils::Vector3d const &position, bool consider_points_in_halo=false) const =0
Get interpolated densities at a position.
virtual std::vector< double > get_slice_velocity(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice velocity.
virtual void set_slice_velocity_at_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< std::optional< Utils::Vector3d > > const &velocity)=0
Set slice velocity boundary conditions.
virtual void clear_boundaries()=0
Clear the boundary flag field and the UBB field.
virtual std::optional< uint64_t > get_rng_state() const =0
Set the RNG counter (if thermalized).
virtual std::vector< double > get_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice density.
virtual std::size_t stencil_size() const noexcept=0
Number of discretized velocities in the PDF.
virtual void set_collision_model(double kT, unsigned int seed)=0
Configure the default collision model.
virtual bool set_node_velocity_at_boundary(Utils::Vector3i const &node, Utils::Vector3d const &velocity)=0
Set node velocity boundary conditions.
virtual Utils::Vector3d get_momentum() const =0
Calculate momentum of the local domain.
virtual bool is_double_precision() const noexcept=0
Whether kernels use double-precision floating point numbers.
virtual std::optional< double > get_node_density(Utils::Vector3i const &node, bool consider_ghosts=false) const =0
Get node density.
virtual std::size_t get_velocity_field_id() const noexcept=0
Get the velocity field id.
virtual std::vector< double > get_slice_population(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice population.
virtual void add_forces_at_pos(std::vector< Utils::Vector3d > const &positions, std::vector< Utils::Vector3d > const &forces)=0
Interpolate forces to the stored forces to be applied on nodes in the next time step.
virtual std::vector< std::optional< Utils::Vector3d > > get_slice_velocity_at_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice velocity boundary conditions.
virtual std::optional< std::vector< double > > get_node_population(Utils::Vector3i const &node, bool consider_ghosts=false) const =0
Get node population.
virtual void reallocate_ubb_field()=0
Rebuild the UBB field.
virtual void set_slice_population(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &population)=0
Set slice population.
virtual void ghost_communication_laf()=0
Perform a ghost communication of the last applied forces field.
virtual std::optional< Utils::Vector3d > get_node_force_to_be_applied(Utils::Vector3i const &node) const =0
Get stored force to be applied on node in the next time step.
virtual bool set_node_population(Utils::Vector3i const &node, std::vector< double > const &population)=0
Set node population.
virtual unsigned int get_seed() const noexcept=0
Get the RNG seed (if thermalized).
virtual double get_kT() const noexcept=0
Get the fluid temperature (if thermalized).
virtual void set_rng_state(uint64_t counter)=0
Set the RNG counter (if thermalized).
virtual std::size_t get_force_field_id() const noexcept=0
Get the force field id.
virtual std::function< bool(Utils::Vector3d const &)> make_lattice_position_checker(bool consider_points_in_halo) const =0
Make a functor to check if a position is in the local domain.
virtual Utils::Vector3d get_external_force() const noexcept=0
Get the global external force.
virtual void update_boundary_from_shape(std::vector< int > const &, std::vector< double > const &)=0
Update boundary conditions from a rasterized shape.
virtual std::vector< double > get_slice_pressure_tensor(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice pressure tensor.
virtual Utils::Vector3d get_boundary_force_from_shape(std::vector< int > const &raster_flat) const =0
Calculate boundary force from a rasterized shape.
virtual void set_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &density)=0
Set slice density.
virtual void integrate()=0
Integrate LB for one time step.
virtual void set_viscosity(double viscosity)=0
Set the fluid viscosity.
virtual bool set_node_density(Utils::Vector3i const &node, double density)=0
Set node density.
virtual void check_lebc(unsigned int shear_direction, unsigned int shear_plane_normal) const =0
Check Lees-Edwards boundary conditions.
virtual void ghost_communication()=0
Perform a full ghost communication.
virtual void set_external_force(Utils::Vector3d const &ext_force)=0
Set a global external force.
virtual void set_slice_velocity(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &velocity)=0
Set slice velocity.
virtual std::optional< Utils::Vector3d > get_node_boundary_force(Utils::Vector3i const &node) const =0
Get (stored) force applied on node due to boundary condition.
virtual std::vector< bool > get_slice_is_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Check if slice has velocity boundary conditions.
virtual bool set_node_velocity(Utils::Vector3i const &node, Utils::Vector3d const &v)=0
Set node velocity.
virtual std::vector< double > get_densities_at_pos(std::vector< Utils::Vector3d > const &pos)=0
Get interpolated densities at positions.
virtual double get_viscosity() const noexcept=0
Get the fluid viscosity.
virtual void set_slice_last_applied_force(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &force)=0
Set stored force that was applied on slice in the last time step.
virtual void ghost_communication_pdf()=0
Perform a ghost communication of the PDF field.
virtual std::vector< Utils::Vector3d > get_velocities_at_pos(std::vector< Utils::Vector3d > const &pos)=0
Get interpolated velocities at positions.
virtual std::optional< Utils::VectorXd< 9 > > get_node_pressure_tensor(Utils::Vector3i const &node) const =0
Get node pressure tensor.
virtual void ghost_communication_vel()=0
Perform a ghost communication of the velocity field.
virtual std::vector< double > get_slice_last_applied_force(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get stored force that was applied on slice in the last time step.
~LBWalberlaBase() override=default
Abstract representation of a lattice-based model.
STL namespace.
static Utils::Vector3d velocity(Particle const &p_ref, Particle const &p_vs)
Velocity of the virtual site.
Definition relative.cpp:65
Pack Lees-Edwards parameters for LB.