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 <filesystem>
41#include <memory>
42#include <stdexcept>
43#include <string>
44#include <unordered_map>
45#include <vector>
46
48
49class LBVTKHandle : public VTKHandleBase<::LBWalberlaBase> {
50 static std::unordered_map<std::string, int> const obs_map;
51
52 std::unordered_map<std::string, int> const &get_obs_map() const override {
53 return obs_map;
54 }
55};
56
57class LBFluid : public LatticeModel<::LBWalberlaBase, LBVTKHandle> {
58protected:
60 std::shared_ptr<::LB::LBWalberlaParams> m_lb_params;
70
71public:
74 {"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
75 {"single_precision", AutoParameter::read_only,
76 [this]() { return not m_instance->is_double_precision(); }},
77 {"is_active", AutoParameter::read_only,
78 [this]() { return m_is_active; }},
80 [this]() { return m_lb_params->get_agrid(); }},
82 [this]() { return m_lb_params->get_tau(); }},
84 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
86 [this]() { return m_instance->get_kT() / m_conv_energy; }},
88 [this]() { return static_cast<int>(m_instance->get_seed()); }},
89 {"rng_state",
90 [this](Variant const &v) {
91 auto const rng_state = get_value<int>(v);
93 if (rng_state < 0) {
94 throw std::domain_error("Parameter 'rng_state' must be >= 0");
95 }
96 m_instance->set_rng_state(static_cast<uint64_t>(rng_state));
97 });
98 },
99 [this]() {
100 auto const opt = m_instance->get_rng_state();
101 return (opt) ? Variant{static_cast<int>(*opt)} : Variant{None{}};
102 }},
103 {"density", AutoParameter::read_only,
104 [this]() { return m_instance->get_density() / m_conv_dens; }},
105 {"kinematic_viscosity",
106 [this](Variant const &v) {
107 auto const visc = m_conv_visc * get_value<double>(v);
108 m_instance->set_viscosity(visc);
109 },
110 [this]() { return m_instance->get_viscosity() / m_conv_visc; }},
111 {"ext_force_density",
112 [this](Variant const &v) {
114 m_instance->set_external_force(ext_f);
115 },
116 [this]() {
117 return m_instance->get_external_force() / m_conv_force_dens;
118 }},
119 {"vtk_writers", AutoParameter::read_only,
120 [this]() { return serialize_vtk_writers(); }},
121 });
122 }
123
124 void do_construct(VariantMap const &params) override;
125
126 Variant do_call_method(std::string const &name,
127 VariantMap const &params) override;
128
129 [[nodiscard]] auto get_lb_fluid() const { return m_instance; }
130 [[nodiscard]] auto get_lb_params() const { return m_lb_params; }
131
134 return {
135 {"density", 1. / m_conv_dens},
136 {"velocity", 1. / m_conv_speed},
137 {"pressure", 1. / m_conv_press},
138 };
139 }
140
141private:
142 void load_checkpoint(std::filesystem::path const &path, int mode);
143 void save_checkpoint(std::filesystem::path const &path, int mode);
144 std::vector<Variant> get_average_pressure_tensor() const;
145 Variant get_boundary_force_from_shape(std::vector<int> const &raster) const;
146 Variant get_boundary_force() const;
147 Variant get_interpolated_velocity(Utils::Vector3d const &pos) const;
148};
149
150class LBFluidCPU : public LBFluid {
151protected:
152 void make_instance(VariantMap const &params) override;
153};
154
155#ifdef ESPRESSO_CUDA
156class LBFluidGPU : public LBFluid {
157protected:
158 void make_instance(VariantMap const &params) override;
159};
160#endif // ESPRESSO_CUDA
161
162} // namespace ScriptInterface::walberla
163
164#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:133
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:60
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition LBFluid.hpp:52
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 SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only
Recursive variant implementation.
Definition Variant.hpp:84