ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
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 ESPRESSO_WALBERLA
25
26#include "LBFluid.hpp"
27
28#include "LatticeSlice.hpp"
29
32
36
37#include <utils/Vector.hpp>
39
40#include <cassert>
41#include <memory>
42#include <optional>
43#include <string>
44#include <type_traits>
45#include <unordered_map>
46#include <vector>
47
49
50using VelocityBounceBackType = std::optional<Utils::Vector3d>;
51
53 template <typename T> static Variant serialize(std::vector<T> const &values) {
54 if constexpr (std::is_same_v<T, VelocityBounceBackType>) {
55 std::vector<Variant> vec;
56 vec.reserve(values.size());
57 for (auto const &opt : values) {
58 if (opt) {
59 vec.emplace_back(*opt);
60 } else {
61 vec.emplace_back(None{});
62 }
63 }
64 return {vec};
65 } else if constexpr (std::is_same_v<T, int> or std::is_same_v<T, double>) {
66 return {values};
67 } else {
69 }
70 }
71
72 template <typename T>
73 static std::vector<T> deserialize(Variant const &variant) {
74 std::vector<T> values;
75 if constexpr (std::is_same_v<T, VelocityBounceBackType>) {
77 for (auto const &value : vector_variants) {
78 if (is_none(value)) {
79 values.emplace_back(std::nullopt);
80 } else {
81 values.emplace_back(get_value<Utils::Vector3d>(value));
82 }
83 }
84 } else if constexpr (std::is_same_v<T, double>) {
85 if (is_type<std::vector<int>>(variant)) {
87 values.reserve(values_int.size());
88 for (auto const val : values_int) {
89 values.emplace_back(static_cast<double>(val));
90 }
91 } else {
93 }
94 } else {
96 }
97 return values;
98 }
99};
100
101class LBFluidSlice : public LatticeSlice<LBFieldSerializer> {
103 std::shared_ptr<LatticeModel> m_lb_fluid;
104 std::shared_ptr<LBFluid> m_lb_sip;
105 std::optional<ResourceObserver> m_mpi_cart_comm_observer;
106 double m_conv_dens;
107 double m_conv_press;
108 double m_conv_force;
109 double m_conv_velocity;
110 std::unordered_map<std::string, std::vector<int>> m_shape_val;
111
112public:
113 void do_construct(VariantMap const &params) override {
114 m_lb_sip = get_value<std::shared_ptr<LBFluid>>(params, "parent_sip");
115 m_lb_fluid = m_lb_sip->get_lb_fluid();
116 m_mpi_cart_comm_observer = m_lb_sip->get_mpi_cart_comm_observer();
117 auto const lb_params = m_lb_sip->get_lb_params();
118 auto const tau = lb_params->get_tau();
119 auto const agrid = lb_params->get_agrid();
120 m_conv_dens = Utils::int_pow<3>(agrid);
121 m_conv_press = Utils::int_pow<1>(agrid) * Utils::int_pow<2>(tau);
122 m_conv_force = Utils::int_pow<2>(tau) / Utils::int_pow<1>(agrid);
123 m_conv_velocity = Utils::int_pow<1>(tau) / Utils::int_pow<1>(agrid);
124 m_shape = get_value<std::vector<int>>(params, "shape");
126 get_value<Utils::Vector3i>(params, "slice_lower_corner");
128 get_value<Utils::Vector3i>(params, "slice_upper_corner");
129 m_shape_val["density"] = {1};
130 m_shape_val["population"] = {static_cast<int>(m_lb_fluid->stencil_size())};
131 m_shape_val["velocity"] = {3};
132 m_shape_val["velocity_at_boundary"] = {1};
133 m_shape_val["is_boundary"] = {1};
134 m_shape_val["last_applied_force"] = {3};
135 m_shape_val["pressure_tensor"] = {3, 3};
136 m_shape_val["pressure_tensor_neq"] = {3, 3};
137 }
138
139 Variant do_call_method(std::string const &name,
140 VariantMap const &params) override;
141
142 ::LatticeWalberla const &get_lattice() const override {
143 return m_lb_fluid->get_lattice();
144 }
145};
146
147} // namespace ScriptInterface::walberla
148
149#endif // ESPRESSO_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.
Definition None.hpp:32
std::string_view 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
std::optional< Utils::Vector3d > VelocityBounceBackType
constexpr bool is_none(Variant const &v)
Definition Variant.hpp:163
constexpr bool is_type(Variant const &v)
Check is a Variant holds a specific type.
Definition Variant.hpp:159
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
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:148
Recursive variant implementation.
Definition Variant.hpp:84
static Variant serialize(std::vector< T > const &values)
static std::vector< T > deserialize(Variant const &variant)