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 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 <optional>
41#include <variant>
42
43namespace LB {
44
45bool LBWalberla::is_gpu() const { return lb_fluid->is_gpu(); }
46
47double LBWalberla::get_kT() const { return lb_fluid->get_kT(); }
48
50 return lb_fluid->get_pressure_tensor();
51}
52
53void LBWalberla::propagate() { lb_fluid->integrate(); }
54
55void LBWalberla::ghost_communication() { lb_fluid->ghost_communication(); }
56
58 lb_fluid->ghost_communication_vel();
59}
60
62 lb_fluid->ghost_communication_vel();
63}
64
65void LBWalberla::lebc_sanity_checks(unsigned int shear_direction,
66 unsigned int shear_plane_normal) const {
67 lb_fluid->check_lebc(shear_direction, shear_plane_normal);
68}
69
70std::optional<Utils::Vector3d>
72 bool consider_points_in_halo) const {
73 return lb_fluid->get_velocity_at_pos(pos, consider_points_in_halo);
74}
75
76std::optional<double>
78 bool consider_points_in_halo) const {
79 return lb_fluid->get_density_at_pos(pos, consider_points_in_halo);
80}
81
83 return lb_fluid->get_momentum();
84}
85
87 Utils::Vector3d const &force) {
88 return lb_fluid->add_force_at_pos(pos, force);
89}
90
91void LBWalberla::add_forces_at_pos(std::vector<Utils::Vector3d> const &pos,
92 std::vector<Utils::Vector3d> const &forces) {
93 lb_fluid->add_forces_at_pos(pos, forces);
94}
95
96std::vector<Utils::Vector3d>
97LBWalberla::get_velocities_at_pos(std::vector<Utils::Vector3d> const &pos) {
98 return lb_fluid->get_velocities_at_pos(pos);
99}
100
101void LBWalberla::veto_time_step(double time_step) const {
102 walberla_tau_sanity_checks("LB", lb_params->get_tau(), time_step);
103}
104
105void LBWalberla::veto_kT(double kT) const {
106 auto const energy_conversion =
107 Utils::int_pow<2>(lb_params->get_agrid() / lb_params->get_tau());
108 auto const lb_kT = lb_fluid->get_kT() * energy_conversion;
109 if (not ::Thermostat::are_kT_equal(lb_kT, kT)) {
110 throw std::runtime_error("Temperature change not supported by LB");
111 }
112}
113
114void LBWalberla::sanity_checks(System::System const &system) const {
115 auto const agrid = lb_params->get_agrid();
116 auto [lb_left, lb_right] = lb_fluid->get_lattice().get_local_domain();
117 lb_left *= agrid;
118 lb_right *= agrid;
119 auto const &md_left = system.local_geo->my_left();
120 auto const &md_right = system.local_geo->my_right();
121 walberla_agrid_sanity_checks("LB", md_left, md_right, lb_left, lb_right,
122 agrid);
123 // LB time step and MD time step must agree
124 walberla_tau_sanity_checks("LB", lb_params->get_tau(),
125 system.get_time_step());
126}
127
129
131 auto const energy_conversion =
132 Utils::int_pow<2>(lb_params->get_agrid() / lb_params->get_tau());
133 auto const kT = lb_fluid->get_kT() * energy_conversion;
134 auto const seed = lb_fluid->get_seed();
136}
137
139 LBWalberlaParams &params, double kT,
140 unsigned int seed) {
141 auto const &system = ::System::get_system();
142 auto le_protocol = system.lees_edwards->get_protocol();
143 if (le_protocol and
144 not std::holds_alternative<LeesEdwards::Off>(*le_protocol)) {
145 if (kT != 0.) {
146 throw std::runtime_error(
147 "Lees-Edwards LB doesn't support thermalization");
148 }
149 auto const &le_bc = system.box_geo->lees_edwards_bc();
150 auto lees_edwards_object = std::make_unique<LeesEdwardsPack>(
151 le_bc.shear_direction, le_bc.shear_plane_normal,
152 [&params, le_protocol, &system]() {
153 return get_pos_offset(system.get_sim_time(), *le_protocol) /
154 params.get_agrid();
155 },
156 [&params, le_protocol, &system]() {
157 return get_shear_velocity(system.get_sim_time(), *le_protocol) *
158 (params.get_tau() / params.get_agrid());
159 });
160 lb.set_collision_model(std::move(lees_edwards_object));
161 } else {
162 lb.set_collision_model(kT, seed);
163 }
165}
166
167} // namespace LB
168
169#endif // 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 defaults for ESPResSo.
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()
static SteepestDescentParameters params
Currently active steepest descent instance.
void update_collision_model()
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)
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()