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
31
33
36
37#include <utils/Vector.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
49
50class 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
58class LBFluid : public LatticeModel<::LBWalberlaBase, LBVTKHandle> {
59protected:
61 std::shared_ptr<::LB::LBWalberlaParams> m_lb_params;
71
72public:
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; }},
81 [this]() { return m_lb_params->get_agrid(); }},
83 [this]() { return m_lb_params->get_tau(); }},
85 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
87 [this]() { return m_instance->get_kT() / m_conv_energy; }},
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);
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) {
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 &params) override;
126
127 Variant do_call_method(std::string const &name,
128 VariantMap const &params) override;
129
130 [[nodiscard]] auto get_lb_fluid() const { return m_instance; }
131 [[nodiscard]] auto get_lb_params() const { return m_lb_params; }
132
135 return {
136 {"density", 1. / m_conv_dens},
137 {"velocity", 1. / m_conv_speed},
138 {"pressure", 1. / m_conv_press},
139 };
140 }
141
142private:
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
151class LBFluidCPU : public LBFluid {
152protected:
153 void make_instance(VariantMap const &params) override;
154};
155
156#ifdef ESPRESSO_CUDA
157class LBFluidGPU : public LBFluid {
158protected:
159 void make_instance(VariantMap const &params) override;
160};
161#endif // ESPRESSO_CUDA
162
163} // namespace ScriptInterface::walberla
164
165#endif // ESPRESSO_WALBERLA
LBWalberlaBase provides the public interface of the LB waLBerla bridge.
Vector implementation and trait types for boost qvm interoperability.
std::unordered_map< std::string, double > units_map
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Type to indicate no value in Variant.
Definition None.hpp:32
Context * context() const
Responsible context.
std::string_view name() const
void make_instance(VariantMap const &params) override
Definition LBFluid.cpp:136
void make_instance(VariantMap const &params) override
Definition LBFluid.cpp:147
void do_construct(VariantMap const &params) override
Definition LBFluid.cpp:164
::LatticeModel::units_map get_lattice_to_md_units_conversion() const override
Definition LBFluid.hpp:134
Variant do_call_method(std::string const &name, VariantMap const &params) override
Definition LBFluid.cpp:68
std::shared_ptr<::LB::LBWalberlaParams > m_lb_params
Definition LBFluid.hpp:61
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition LBFluid.hpp:53
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
static constexpr const ReadOnly read_only
Recursive variant implementation.
Definition Variant.hpp:84