ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBFluid.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2021-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 <
config/config.hpp
>
23
24
#ifdef ESPRESSO_WALBERLA
25
26
#include "
LatticeModel.hpp
"
27
#include "
LatticeWalberla.hpp
"
28
#include "
VTKHandle.hpp
"
29
30
#include "
core/lb/LBWalberla.hpp
"
31
32
#include <
script_interface/ScriptInterface.hpp
>
33
34
#include <
walberla_bridge/LatticeModel.hpp
>
35
#include <
walberla_bridge/lattice_boltzmann/LBWalberlaBase.hpp
>
36
37
#include <
utils/Vector.hpp
>
38
#include <
utils/math/int_pow.hpp
>
39
40
#include <cstddef>
41
#include <filesystem>
42
#include <memory>
43
#include <stdexcept>
44
#include <string>
45
#include <unordered_map>
46
#include <vector>
47
48
namespace
ScriptInterface::walberla
{
49
50
class
LBVTKHandle
:
public
VTKHandleBase
<::LBWalberlaBase> {
51
static
std::unordered_map<std::string, int>
const
obs_map;
52
53
std::unordered_map<std::string, int>
const
&
get_obs_map
()
const override
{
54
return
obs_map;
55
}
56
};
57
58
class
LBFluid
:
public
LatticeModel
<::LBWalberlaBase, LBVTKHandle> {
59
protected
:
60
using
Base
=
LatticeModel<::LBWalberlaBase, LBVTKHandle>
;
61
std::shared_ptr<::LB::LBWalberlaParams>
m_lb_params
;
62
bool
m_is_active
;
63
double
m_conv_dist
;
64
double
m_conv_visc
;
65
double
m_conv_dens
;
66
double
m_conv_speed
;
67
double
m_conv_press
;
68
double
m_conv_force
;
69
double
m_conv_force_dens
;
70
double
m_conv_energy
;
71
72
public
:
73
LBFluid
() {
74
add_parameters
({
75
{
"lattice"
,
AutoParameter::read_only
, [
this
]() {
return
m_lattice
; }},
76
{
"single_precision"
,
AutoParameter::read_only
,
77
[
this
]() {
return
not
m_instance
->is_double_precision(); }},
78
{
"is_active"
,
AutoParameter::read_only
,
79
[
this
]() {
return
m_is_active
; }},
80
{
"agrid"
,
AutoParameter::read_only
,
81
[
this
]() {
return
m_lb_params
->get_agrid(); }},
82
{
"tau"
,
AutoParameter::read_only
,
83
[
this
]() {
return
m_lb_params
->get_tau(); }},
84
{
"shape"
,
AutoParameter::read_only
,
85
[
this
]() {
return
m_instance
->get_lattice().get_grid_dimensions(); }},
86
{
"kT"
,
AutoParameter::read_only
,
87
[
this
]() {
return
m_instance
->get_kT() /
m_conv_energy
; }},
88
{
"seed"
,
AutoParameter::read_only
,
89
[
this
]() {
return
static_cast<
int
>
(
m_instance
->get_seed()); }},
90
{
"rng_state"
,
91
[
this
](
Variant
const
&v) {
92
auto
const
rng_state
=
get_value<int>
(v);
93
context
()->
parallel_try_catch
([&]() {
94
if
(
rng_state
< 0) {
95
throw
std::domain_error(
"Parameter 'rng_state' must be >= 0"
);
96
}
97
m_instance
->set_rng_state(
static_cast<
uint64_t
>
(
rng_state
));
98
});
99
},
100
[
this
]() {
101
auto
const
opt
=
m_instance
->get_rng_state();
102
return
(
opt
) ?
Variant
{
static_cast<
int
>
(*opt)} :
Variant
{
None
{}};
103
}},
104
{
"density"
,
AutoParameter::read_only
,
105
[
this
]() {
return
m_instance
->get_density() /
m_conv_dens
; }},
106
{
"kinematic_viscosity"
,
107
[
this
](
Variant
const
&v) {
108
auto
const
visc
=
m_conv_visc
*
get_value<double>
(v);
109
m_instance
->set_viscosity(
visc
);
110
},
111
[
this
]() {
return
m_instance
->get_viscosity() /
m_conv_visc
; }},
112
{
"ext_force_density"
,
113
[
this
](
Variant
const
&v) {
114
auto
const
ext_f
=
m_conv_force_dens
*
get_value<Utils::Vector3d>
(v);
115
m_instance
->set_external_force(
ext_f
);
116
},
117
[
this
]() {
118
return
m_instance
->get_external_force() /
m_conv_force_dens
;
119
}},
120
{
"vtk_writers"
,
AutoParameter::read_only
,
121
[
this
]() {
return
serialize_vtk_writers
(); }},
122
});
123
}
124
125
void
do_construct
(
VariantMap
const
¶ms)
override
;
126
127
Variant
do_call_method
(std::string
const
&
name
,
128
VariantMap
const
¶ms)
override
;
129
130
[[
nodiscard
]]
auto
get_lb_fluid
()
const
{
return
m_instance
; }
131
[[
nodiscard
]]
auto
get_lb_params
()
const
{
return
m_lb_params
; }
132
133
::LatticeModel::units_map
134
get_lattice_to_md_units_conversion
()
const override
{
135
return
{
136
{
"density"
, 1. /
m_conv_dens
},
137
{
"velocity"
, 1. /
m_conv_speed
},
138
{
"pressure"
, 1. /
m_conv_press
},
139
};
140
}
141
142
private
:
143
void
load_checkpoint(std::filesystem::path
const
&path,
int
mode
);
144
void
save_checkpoint(std::filesystem::path
const
&path,
int
mode
);
145
std::vector<Variant> get_average_pressure_tensor()
const
;
146
Variant
get_boundary_force_from_shape(std::vector<int>
const
&raster)
const
;
147
Variant
get_boundary_force()
const
;
148
Variant
get_interpolated_velocity(
Utils::Vector3d
const
&pos)
const
;
149
};
150
151
class
LBFluidCPU
:
public
LBFluid
{
152
protected
:
153
void
make_instance
(
VariantMap
const
¶ms)
override
;
154
};
155
156
#ifdef ESPRESSO_CUDA
157
class
LBFluidGPU
:
public
LBFluid
{
158
protected
:
159
void
make_instance
(
VariantMap
const
¶ms)
override
;
160
};
161
#endif
// ESPRESSO_CUDA
162
163
}
// namespace ScriptInterface::walberla
164
165
#endif
// ESPRESSO_WALBERLA
LBWalberlaBase.hpp
LBWalberlaBase provides the public interface of the LB waLBerla bridge.
LBWalberla.hpp
ScriptInterface.hpp
Vector.hpp
Vector implementation and trait types for boost qvm interoperability.
LatticeModel::units_map
std::unordered_map< std::string, double > units_map
Definition
walberla_bridge/include/walberla_bridge/LatticeModel.hpp:33
ScriptInterface::AutoParameters::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:123
ScriptInterface::Context::parallel_try_catch
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
ScriptInterface::None
Type to indicate no value in Variant.
Definition
None.hpp:32
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
ScriptInterface::ObjectHandle::name
std::string_view name() const
Definition
ObjectHandle.cpp:117
ScriptInterface::walberla::LBFluidCPU
Definition
LBFluid.hpp:151
ScriptInterface::walberla::LBFluidCPU::make_instance
void make_instance(VariantMap const ¶ms) override
Definition
LBFluid.cpp:136
ScriptInterface::walberla::LBFluidGPU
Definition
LBFluid.hpp:157
ScriptInterface::walberla::LBFluidGPU::make_instance
void make_instance(VariantMap const ¶ms) override
Definition
LBFluid.cpp:147
ScriptInterface::walberla::LBFluid
Definition
LBFluid.hpp:58
ScriptInterface::walberla::LBFluid::get_lb_params
auto get_lb_params() const
Definition
LBFluid.hpp:131
ScriptInterface::walberla::LBFluid::LBFluid
LBFluid()
Definition
LBFluid.hpp:73
ScriptInterface::walberla::LBFluid::m_is_active
bool m_is_active
Definition
LBFluid.hpp:62
ScriptInterface::walberla::LBFluid::m_conv_visc
double m_conv_visc
Definition
LBFluid.hpp:64
ScriptInterface::walberla::LBFluid::m_conv_force_dens
double m_conv_force_dens
Definition
LBFluid.hpp:69
ScriptInterface::walberla::LBFluid::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
LBFluid.cpp:164
ScriptInterface::walberla::LBFluid::get_lb_fluid
auto get_lb_fluid() const
Definition
LBFluid.hpp:130
ScriptInterface::walberla::LBFluid::m_conv_press
double m_conv_press
Definition
LBFluid.hpp:67
ScriptInterface::walberla::LBFluid::get_lattice_to_md_units_conversion
::LatticeModel::units_map get_lattice_to_md_units_conversion() const override
Definition
LBFluid.hpp:134
ScriptInterface::walberla::LBFluid::m_conv_dens
double m_conv_dens
Definition
LBFluid.hpp:65
ScriptInterface::walberla::LBFluid::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
LBFluid.cpp:68
ScriptInterface::walberla::LBFluid::m_conv_dist
double m_conv_dist
Definition
LBFluid.hpp:63
ScriptInterface::walberla::LBFluid::m_lb_params
std::shared_ptr<::LB::LBWalberlaParams > m_lb_params
Definition
LBFluid.hpp:61
ScriptInterface::walberla::LBFluid::m_conv_energy
double m_conv_energy
Definition
LBFluid.hpp:70
ScriptInterface::walberla::LBFluid::m_conv_speed
double m_conv_speed
Definition
LBFluid.hpp:66
ScriptInterface::walberla::LBFluid::m_conv_force
double m_conv_force
Definition
LBFluid.hpp:68
ScriptInterface::walberla::LBVTKHandle
Definition
LBFluid.hpp:50
ScriptInterface::walberla::LBVTKHandle::get_obs_map
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition
LBFluid.hpp:53
ScriptInterface::walberla::LatticeModel
Definition
script_interface/walberla/LatticeModel.hpp:38
ScriptInterface::walberla::LatticeModel<::LBWalberlaBase, LBVTKHandle >::m_instance
std::shared_ptr< ::LBWalberlaBase > m_instance
Definition
script_interface/walberla/LatticeModel.hpp:41
ScriptInterface::walberla::LatticeModel<::LBWalberlaBase, LBVTKHandle >::serialize_vtk_writers
auto serialize_vtk_writers() const
Definition
script_interface/walberla/LatticeModel.hpp:52
ScriptInterface::walberla::LatticeModel<::LBWalberlaBase, LBVTKHandle >::m_lattice
std::shared_ptr< LatticeWalberla > m_lattice
Definition
script_interface/walberla/LatticeModel.hpp:40
ScriptInterface::walberla::VTKHandleBase
Definition
script_interface/walberla/VTKHandle.hpp:46
Utils::Vector
Definition
Vector.hpp:50
config.hpp
int_pow.hpp
ScriptInterface::walberla
Definition
script_interface/walberla/EKContainer.hpp:49
ScriptInterface::get_value
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
Definition
get_value.hpp:398
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
ScriptInterface::AutoParameter::read_only
static constexpr const ReadOnly read_only
Definition
AutoParameter.hpp:42
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
LatticeModel.hpp
LatticeWalberla.hpp
VTKHandle.hpp
src
script_interface
walberla
LBFluid.hpp
Generated on Sun Jan 4 2026 02:32:25 for ESPResSo by
1.9.8