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;
48
49class LBFluid : public LatticeModel<::LBWalberlaBase, LBVTKHandle> {
50protected:
52 std::shared_ptr<::LB::LBWalberlaParams> m_lb_params;
54 int m_seed;
63
64public:
67 {"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
68 {"single_precision", AutoParameter::read_only,
69 [this]() { return not m_instance->is_double_precision(); }},
70 {"is_active", AutoParameter::read_only,
71 [this]() { return m_is_active; }},
73 [this]() { return m_lb_params->get_agrid(); }},
75 [this]() { return m_lb_params->get_tau(); }},
77 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
79 [this]() { return m_instance->get_kT() / m_conv_energy; }},
80 {"seed", AutoParameter::read_only, [this]() { return m_seed; }},
81 {"rng_state",
82 [this](Variant const &v) {
83 auto const rng_state = get_value<int>(v);
85 if (rng_state < 0) {
86 throw std::domain_error("Parameter 'rng_state' must be >= 0");
87 }
88 m_instance->set_rng_state(static_cast<uint64_t>(rng_state));
89 });
90 },
91 [this]() {
92 auto const opt = m_instance->get_rng_state();
93 return (opt) ? Variant{static_cast<int>(*opt)} : Variant{None{}};
94 }},
95 {"density", AutoParameter::read_only,
96 [this]() { return m_instance->get_density() / m_conv_dens; }},
97 {"kinematic_viscosity",
98 [this](Variant const &v) {
99 auto const visc = m_conv_visc * get_value<double>(v);
100 m_instance->set_viscosity(visc);
101 },
102 [this]() { return m_instance->get_viscosity() / m_conv_visc; }},
103 {"ext_force_density",
104 [this](Variant const &v) {
105 auto const ext_f = m_conv_force_dens * get_value<Utils::Vector3d>(v);
106 m_instance->set_external_force(ext_f);
107 },
108 [this]() {
109 return m_instance->get_external_force() / m_conv_force_dens;
110 }},
111 {"vtk_writers", AutoParameter::read_only,
112 [this]() { return serialize_vtk_writers(); }},
113 });
114 }
115
116 void do_construct(VariantMap const &params) override;
117
118 Variant do_call_method(std::string const &name,
119 VariantMap const &params) override;
120
121 [[nodiscard]] auto get_lb_fluid() const { return m_instance; }
122 [[nodiscard]] auto get_lb_params() const { return m_lb_params; }
123
125 return {
126 {"density", 1. / m_conv_dens},
127 {"velocity", 1. / m_conv_speed},
128 {"pressure", 1. / m_conv_press},
129 };
130 }
131
132private:
133 void load_checkpoint(std::string const &filename, int mode);
134 void save_checkpoint(std::string const &filename, int mode);
135 std::vector<Variant> get_average_pressure_tensor() const;
136 Variant get_interpolated_velocity(Utils::Vector3d const &pos) const;
137};
138
139class LBFluidCPU : public LBFluid {
140protected:
141 void make_instance(VariantMap const &params) override;
142};
143
144#ifdef CUDA
145class LBFluidGPU : public LBFluid {
146protected:
147 void make_instance(VariantMap const &params) override;
148};
149#endif // CUDA
150
151class LBVTKHandle : public VTKHandleBase<::LBWalberlaBase> {
152 static std::unordered_map<std::string, int> const obs_map;
153
154 std::unordered_map<std::string, int> const &get_obs_map() const override {
155 return obs_map;
156 }
157};
158
159} // namespace ScriptInterface::walberla
160
161#endif // WALBERLA
LBWalberlaBase provides the public interface of the LB waLBerla bridge.
Vector implementation and trait types for boost qvm interoperability.
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
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:149
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:52
::LatticeModel::units_map get_latice_to_md_units_conversion() const override
Definition LBFluid.hpp:124
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition LBFluid.hpp:154
This file contains the defaults for ESPResSo.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
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:80
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only