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 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 <memory>
41#include <stdexcept>
42#include <string>
43#include <vector>
44
46
47class LBVTKHandle : public VTKHandleBase<::LBWalberlaBase> {
48 static std::unordered_map<std::string, int> const obs_map;
49
50 std::unordered_map<std::string, int> const &get_obs_map() const override {
51 return obs_map;
52 }
53};
54
55class LBFluid : public LatticeModel<::LBWalberlaBase, LBVTKHandle> {
56protected:
58 std::shared_ptr<::LB::LBWalberlaParams> m_lb_params;
68
69public:
72 {"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
73 {"single_precision", AutoParameter::read_only,
74 [this]() { return not m_instance->is_double_precision(); }},
75 {"is_active", AutoParameter::read_only,
76 [this]() { return m_is_active; }},
78 [this]() { return m_lb_params->get_agrid(); }},
80 [this]() { return m_lb_params->get_tau(); }},
82 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
84 [this]() { return m_instance->get_kT() / m_conv_energy; }},
86 [this]() { return static_cast<int>(m_instance->get_seed()); }},
87 {"rng_state",
88 [this](Variant const &v) {
89 auto const rng_state = get_value<int>(v);
91 if (rng_state < 0) {
92 throw std::domain_error("Parameter 'rng_state' must be >= 0");
93 }
94 m_instance->set_rng_state(static_cast<uint64_t>(rng_state));
95 });
96 },
97 [this]() {
98 auto const opt = m_instance->get_rng_state();
99 return (opt) ? Variant{static_cast<int>(*opt)} : Variant{None{}};
100 }},
101 {"density", AutoParameter::read_only,
102 [this]() { return m_instance->get_density() / m_conv_dens; }},
103 {"kinematic_viscosity",
104 [this](Variant const &v) {
105 auto const visc = m_conv_visc * get_value<double>(v);
106 m_instance->set_viscosity(visc);
107 },
108 [this]() { return m_instance->get_viscosity() / m_conv_visc; }},
109 {"ext_force_density",
110 [this](Variant const &v) {
111 auto const ext_f = m_conv_force_dens * get_value<Utils::Vector3d>(v);
112 m_instance->set_external_force(ext_f);
113 },
114 [this]() {
115 return m_instance->get_external_force() / m_conv_force_dens;
116 }},
117 {"vtk_writers", AutoParameter::read_only,
118 [this]() { return serialize_vtk_writers(); }},
119 });
120 }
121
122 void do_construct(VariantMap const &params) override;
123
124 Variant do_call_method(std::string const &name,
125 VariantMap const &params) override;
126
127 [[nodiscard]] auto get_lb_fluid() const { return m_instance; }
128 [[nodiscard]] auto get_lb_params() const { return m_lb_params; }
129
131 return {
132 {"density", 1. / m_conv_dens},
133 {"velocity", 1. / m_conv_speed},
134 {"pressure", 1. / m_conv_press},
135 };
136 }
137
138private:
139 void load_checkpoint(std::string const &filename, int mode);
140 void save_checkpoint(std::string const &filename, int mode);
141 std::vector<Variant> get_average_pressure_tensor() const;
142 Variant get_interpolated_velocity(Utils::Vector3d const &pos) const;
143};
144
145class LBFluidCPU : public LBFluid {
146protected:
147 void make_instance(VariantMap const &params) override;
148};
149
150#ifdef CUDA
151class LBFluidGPU : public LBFluid {
152protected:
153 void make_instance(VariantMap const &params) override;
154};
155#endif // CUDA
156
157} // namespace ScriptInterface::walberla
158
159#endif // 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.
boost::string_ref name() const
Context * context() const
Responsible context.
void make_instance(VariantMap const &params) override
Definition LBFluid.cpp:127
void make_instance(VariantMap const &params) override
Definition LBFluid.cpp:138
void do_construct(VariantMap const &params) override
Definition LBFluid.cpp:155
Variant do_call_method(std::string const &name, VariantMap const &params) override
Definition LBFluid.cpp:66
std::shared_ptr<::LB::LBWalberlaParams > m_lb_params
Definition LBFluid.hpp:58
::LatticeModel::units_map get_latice_to_md_units_conversion() const override
Definition LBFluid.hpp:130
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition LBFluid.hpp:50
This file contains the defaults for ESPResSo.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:67
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only