Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
LBFluidSlice.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 "LBFluid.hpp"
27
28#include "LatticeSlice.hpp"
29
32
35
36#include <utils/Vector.hpp>
38
39#include <cassert>
40#include <memory>
41#include <optional>
42#include <string>
43#include <type_traits>
44#include <unordered_map>
45#include <vector>
46
48
49using VelocityBounceBackType = std::optional<Utils::Vector3d>;
50
52 template <typename T> static Variant serialize(std::vector<T> const &values) {
53 if constexpr (std::is_same_v<T, VelocityBounceBackType>) {
54 std::vector<Variant> vec;
55 vec.reserve(values.size());
56 for (auto const &opt : values) {
57 if (opt) {
58 vec.emplace_back(*opt);
59 } else {
60 vec.emplace_back(None{});
61 }
62 }
63 return {vec};
64 } else if constexpr (std::is_same_v<T, int> or std::is_same_v<T, double>) {
65 return {values};
66 } else {
68 }
69 }
70
71 template <typename T>
72 static std::vector<T> deserialize(Variant const &variant) {
73 std::vector<T> values;
74 if constexpr (std::is_same_v<T, VelocityBounceBackType>) {
76 for (auto const &value : vector_variants) {
77 if (is_none(value)) {
78 values.emplace_back(std::nullopt);
79 } else {
80 values.emplace_back(get_value<Utils::Vector3d>(value));
81 }
82 }
83 } else if constexpr (std::is_same_v<T, double>) {
84 if (is_type<std::vector<int>>(variant)) {
86 values.reserve(values_int.size());
87 for (auto const val : values_int) {
88 values.emplace_back(static_cast<double>(val));
89 }
90 } else {
92 }
93 } else {
95 }
96 return values;
97 }
98};
99
100class LBFluidSlice : public LatticeSlice<LBFieldSerializer> {
102 std::shared_ptr<LatticeModel> m_lb_fluid;
103 std::shared_ptr<LBFluid> m_lb_sip;
104 double m_conv_dens;
105 double m_conv_press;
106 double m_conv_force;
107 double m_conv_velocity;
108 std::unordered_map<std::string, std::vector<int>> m_shape_val;
109
110public:
111 void do_construct(VariantMap const &params) override {
112 m_lb_sip = get_value<std::shared_ptr<LBFluid>>(params, "parent_sip");
113 m_lb_fluid = m_lb_sip->get_lb_fluid();
114 auto const lb_params = m_lb_sip->get_lb_params();
115 auto const tau = lb_params->get_tau();
116 auto const agrid = lb_params->get_agrid();
117 m_conv_dens = Utils::int_pow<3>(agrid);
118 m_conv_press = Utils::int_pow<1>(agrid) * Utils::int_pow<2>(tau);
119 m_conv_force = Utils::int_pow<2>(tau) / Utils::int_pow<1>(agrid);
120 m_conv_velocity = Utils::int_pow<1>(tau) / Utils::int_pow<1>(agrid);
123 get_value<Utils::Vector3i>(params, "slice_lower_corner");
125 get_value<Utils::Vector3i>(params, "slice_upper_corner");
126 m_shape_val["density"] = {1};
127 m_shape_val["population"] = {static_cast<int>(m_lb_fluid->stencil_size())};
128 m_shape_val["velocity"] = {3};
129 m_shape_val["velocity_at_boundary"] = {1};
130 m_shape_val["is_boundary"] = {1};
131 m_shape_val["last_applied_force"] = {3};
132 m_shape_val["pressure_tensor"] = {3, 3};
133 m_shape_val["pressure_tensor_neq"] = {3, 3};
134 }
135
136 Variant do_call_method(std::string const &name,
137 VariantMap const &params) override;
138
139 ::LatticeWalberla const &get_lattice() const override {
140 return m_lb_fluid->get_lattice();
141 }
142};
143
144} // namespace ScriptInterface::walberla
145
146#endif // WALBERLA
LBWalberlaBase provides the public interface of the LB waLBerla bridge.
Vector implementation and trait types for boost qvm interoperability.
Interface of a lattice-based fluid model.
Class that runs and controls the BlockForest in waLBerla.
Type to indicate no value in Variant.
boost::string_ref name() const
::LatticeWalberla const & get_lattice() const override
Variant do_call_method(std::string const &name, VariantMap const &params) override
void do_construct(VariantMap const &params) override
This file contains the defaults for ESPResSo.
std::optional< Utils::Vector3d > VelocityBounceBackType
bool is_type(Variant const &v)
Check is a Variant holds a specific type.
Definition Variant.hpp:111
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:69
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:88
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
bool is_none(Variant const &v)
Definition Variant.hpp:115
static SteepestDescentParameters params
Currently active steepest descent instance.
static Variant serialize(std::vector< T > const &values)
static std::vector< T > deserialize(Variant const &variant)