ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBWalberla.cpp
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#include "config/config.hpp"
20
21#ifdef ESPRESSO_WALBERLA
22
23#include "LBWalberla.hpp"
24
25#include "BoxGeometry.hpp"
26#include "LocalBox.hpp"
27#include "communication.hpp"
28#include "errorhandling.hpp"
29#include "integrate.hpp"
30#include "system/System.hpp"
31#include "thermostat.hpp"
32
34
36
37#include <utils/Vector.hpp>
39
40#include <functional>
41#include <optional>
42#include <stdexcept>
43#include <utility>
44#include <variant>
45#include <vector>
46
47namespace LB {
48
49bool LBWalberla::is_gpu() const { return lb_fluid->is_gpu(); }
50
51double LBWalberla::get_kT() const { return lb_fluid->get_kT(); }
52
54 return lb_fluid->get_pressure_tensor();
55}
56
57void LBWalberla::propagate() { lb_fluid->integrate(); }
58
59void LBWalberla::ghost_communication() { lb_fluid->ghost_communication(); }
60
62 lb_fluid->ghost_communication_vel();
63}
64
66 lb_fluid->ghost_communication_vel();
67}
68
69void LBWalberla::lebc_sanity_checks(unsigned int shear_direction,
70 unsigned int shear_plane_normal) const {
71 lb_fluid->check_lebc(shear_direction, shear_plane_normal);
72}
73
74std::function<bool(Utils::Vector3d const &)>
75LBWalberla::make_lattice_position_checker(bool consider_points_in_halo) const {
76 return lb_fluid->make_lattice_position_checker(consider_points_in_halo);
77}
78
79std::optional<Utils::Vector3d>
81 bool consider_points_in_halo) const {
82 return lb_fluid->get_velocity_at_pos(pos, consider_points_in_halo);
83}
84
85std::optional<double>
87 bool consider_points_in_halo) const {
88 return lb_fluid->get_density_at_pos(pos, consider_points_in_halo);
89}
90
92 return lb_fluid->get_momentum();
93}
94
96 Utils::Vector3d const &force) {
97 return lb_fluid->add_force_at_pos(pos, force);
98}
99
100void LBWalberla::add_forces_at_pos(std::vector<Utils::Vector3d> const &pos,
101 std::vector<Utils::Vector3d> const &forces) {
102 lb_fluid->add_forces_at_pos(pos, forces);
103}
104
105std::vector<double>
106LBWalberla::get_densities_at_pos(std::vector<Utils::Vector3d> const &pos) {
107 return lb_fluid->get_densities_at_pos(pos);
108}
109
110std::vector<Utils::Vector3d>
111LBWalberla::get_velocities_at_pos(std::vector<Utils::Vector3d> const &pos) {
112 return lb_fluid->get_velocities_at_pos(pos);
113}
114
115void LBWalberla::veto_time_step(double time_step) const {
116 walberla_tau_sanity_checks("LB", lb_params->get_tau(), time_step);
117}
118
119void LBWalberla::veto_kT(double kT) const {
120 auto const energy_conversion =
121 Utils::int_pow<2>(lb_params->get_agrid() / lb_params->get_tau());
122 auto const lb_kT = lb_fluid->get_kT() * energy_conversion;
123 if (not(::Thermostat::are_kT_equal(lb_kT, kT))) {
124 throw std::runtime_error("Temperature change not supported by LB");
125 }
126}
127
128void LBWalberla::sanity_checks(System::System const &system) const {
129 auto const agrid = lb_params->get_agrid();
130 auto [lb_left, lb_right] = lb_fluid->get_lattice().get_local_domain();
131 lb_left *= agrid;
132 lb_right *= agrid;
133 auto const &md_left = system.local_geo->my_left();
134 auto const &md_right = system.local_geo->my_right();
135 walberla_agrid_sanity_checks("LB", md_left, md_right, lb_left, lb_right,
136 agrid);
137 // LB time step and MD time step must agree
138 walberla_tau_sanity_checks("LB", lb_params->get_tau(),
139 system.get_time_step());
140}
141
143
145 auto const energy_conversion =
146 Utils::int_pow<2>(lb_params->get_agrid() / lb_params->get_tau());
147 auto const kT = lb_fluid->get_kT() * energy_conversion;
148 auto const seed = lb_fluid->get_seed();
150}
151
153 LBWalberlaParams &params, double kT,
154 unsigned int seed) {
155 auto const &system = ::System::get_system();
156 auto le_protocol = system.lees_edwards->get_protocol();
157 if (le_protocol and
158 not std::holds_alternative<LeesEdwards::Off>(*le_protocol)) {
159 if (kT != 0.) {
160 throw std::runtime_error(
161 "Lees-Edwards LB doesn't support thermalization");
162 }
163 auto const &le_bc = system.box_geo->lees_edwards_bc();
164 auto lees_edwards_object = std::make_unique<LeesEdwardsPack>(
165 le_bc.shear_direction, le_bc.shear_plane_normal,
166 [&params, le_protocol, &system]() {
167 return get_pos_offset(system.get_sim_time(), *le_protocol) /
168 params.get_agrid();
169 },
170 [&params, le_protocol, &system]() {
171 return get_shear_velocity(system.get_sim_time(), *le_protocol) *
172 (params.get_tau() / params.get_agrid());
173 });
174 lb.set_collision_model(std::move(lees_edwards_object));
175 } else {
176 lb.set_collision_model(kT, seed);
177 }
179}
180
181} // namespace LB
182
183#endif // ESPRESSO_WALBERLA
LBWalberlaBase provides the public interface of the LB waLBerla bridge.
Vector implementation and trait types for boost qvm interoperability.
Interface of a lattice-based fluid model.
virtual void set_collision_model(double kT, unsigned int seed)=0
Configure the default collision model.
virtual void ghost_communication()=0
Perform a full ghost communication.
Main system class.
auto get_time_step() const
Get time_step.
std::shared_ptr< LocalBox > local_geo
This file contains the errorhandling code for severe errors, like a broken bond or illegal parameter ...
void walberla_agrid_sanity_checks(std::string method, Utils::Vector3d const &geo_left, Utils::Vector3d const &geo_right, Utils::Vector3d const &lattice_left, Utils::Vector3d const &lattice_right, double agrid)
void walberla_tau_sanity_checks(std::string method, double tau, double time_step)
Molecular dynamics integrator.
System & get_system()
bool are_kT_equal(double old_kT, double new_kT)
Check that two kT values are close up to a small tolerance.
static SteepestDescentParameters params
Currently active steepest descent instance.
void update_collision_model()
std::vector< double > get_densities_at_pos(std::vector< Utils::Vector3d > const &pos)
bool is_gpu() const
Utils::Vector3d get_momentum() const
std::shared_ptr< LBWalberlaBase > lb_fluid
Utils::VectorXd< 9 > get_pressure_tensor() const
void ghost_communication_vel()
std::optional< Utils::Vector3d > get_velocity_at_pos(Utils::Vector3d const &pos, bool consider_points_in_halo) const
void veto_time_step(double time_step) const
void add_forces_at_pos(std::vector< Utils::Vector3d > const &pos, std::vector< Utils::Vector3d > const &forces)
void veto_kT(double kT) const
std::optional< double > get_density_at_pos(Utils::Vector3d const &pos, bool consider_points_in_halo) const
double get_kT() const
std::shared_ptr< LBWalberlaParams > lb_params
std::vector< Utils::Vector3d > get_velocities_at_pos(std::vector< Utils::Vector3d > const &pos)
std::function< bool(Utils::Vector3d const &)> make_lattice_position_checker(bool consider_points_in_halo) const
void ghost_communication()
void ghost_communication_pdf()
void sanity_checks(System::System const &system) const
void lebc_sanity_checks(unsigned int shear_direction, unsigned int shear_plane_normal) const
bool add_force_at_pos(Utils::Vector3d const &pos, Utils::Vector3d const &force)
void on_lees_edwards_change()