ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBFluidSlice.cpp
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#include <config/config.hpp>
21
22#ifdef ESPRESSO_WALBERLA
23
24#include "LBFluidSlice.hpp"
25
26#include "LatticeSlice.impl.hpp"
27
28#include <stdexcept>
29#include <string>
30#include <type_traits>
31#include <variant>
32#include <vector>
33
35
36Variant LBFluidSlice::do_call_method(std::string const &name,
37 VariantMap const &params) {
38 if (name == "get_slice_size") {
40 }
41 if (name == "get_slice_ranges") {
42 return {std::vector<Variant>{m_slice_lower_corner, m_slice_upper_corner}};
43 }
44 if (name == "get_lb_sip") {
45 return {m_lb_sip};
46 }
47 if (name == "get_value_shape") {
48 auto const name = get_value<std::string>(params, "name");
49 if (not m_shape_val.contains(name)) {
51 throw std::runtime_error("Unknown fluid property '" + name + "'");
52 });
53 }
54 return m_shape_val.at(name);
55 }
56 if (name == "get_lattice_speed") {
57 return 1. / m_conv_velocity;
58 }
59
60 // slice getter/setter callback
61 auto const call = [this, &params](auto method_ptr,
62 std::vector<int> const &data_dims,
63 double units = 1.) -> Variant {
64 auto &obj = *m_lb_fluid;
65 if constexpr (std::is_invocable_v<decltype(method_ptr), LatticeModel *,
66 Utils::Vector3i const &,
67 Utils::Vector3i const &>) {
69 } else {
71 return {};
72 }
73 };
74
75 if (name == "get_population") {
76 auto const pop_size = m_shape_val.at("population");
78 }
79 if (name == "set_population") {
80 auto const pop_size = m_shape_val.at("population");
82 }
83 if (name == "get_density") {
84 return call(&LatticeModel::get_slice_density, {1}, 1. / m_conv_dens);
85 }
86 if (name == "set_density") {
87 return call(&LatticeModel::set_slice_density, {1}, m_conv_dens);
88 }
89 if (name == "get_velocity") {
90 return call(&LatticeModel::get_slice_velocity, {3}, 1. / m_conv_velocity);
91 }
92 if (name == "set_velocity") {
93 return call(&LatticeModel::set_slice_velocity, {3}, m_conv_velocity);
94 }
95 if (name == "get_is_boundary") {
96 return call(&LatticeModel::get_slice_is_boundary, {1});
97 }
98 if (name == "get_velocity_at_boundary") {
100 1. / m_conv_velocity);
101 }
102 if (name == "set_velocity_at_boundary") {
104 m_conv_velocity);
105 m_lb_fluid->reallocate_ubb_field();
106 return retval;
107 }
108 if (name == "get_pressure_tensor") {
109 return call(&LatticeModel::get_slice_pressure_tensor, {3, 3},
110 1. / m_conv_press);
111 }
112 if (name == "get_pressure_tensor_neq") {
113 auto variant = do_call_method("get_pressure_tensor", params);
114 if (context()->is_head_node()) {
115 auto constexpr c_sound_sq = 1. / 3.;
116 auto const density = m_lb_fluid->get_density();
117 auto const diagonal_term = density * c_sound_sq / m_conv_press;
118 // modify existing variant in-place
119 auto &vec = *(std::get_if<std::vector<double>>(
120 &(std::get_if<std::vector<Variant>>(&variant)->at(0))));
121 for (auto it = vec.begin(); it < vec.end(); it += 9) {
122 *(it + 0) -= diagonal_term;
123 *(it + 4) -= diagonal_term;
124 *(it + 8) -= diagonal_term;
125 }
126 }
127 return variant;
128 }
129 if (name == "get_last_applied_force") {
131 1. / m_conv_force);
132 }
133 if (name == "set_last_applied_force") {
134 return call(&LatticeModel::set_slice_last_applied_force, {3}, m_conv_force);
135 }
136
137 return {};
138}
139
140} // namespace ScriptInterface::walberla
141
142#endif // ESPRESSO_WALBERLA
Interface of a lattice-based fluid model.
virtual std::vector< double > get_slice_velocity(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice velocity.
virtual void set_slice_velocity_at_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< std::optional< Utils::Vector3d > > const &velocity)=0
Set slice velocity boundary conditions.
virtual std::vector< double > get_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice density.
virtual std::vector< double > get_slice_population(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice population.
virtual std::vector< std::optional< Utils::Vector3d > > get_slice_velocity_at_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice velocity boundary conditions.
virtual void set_slice_population(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &population)=0
Set slice population.
virtual std::vector< double > get_slice_pressure_tensor(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get slice pressure tensor.
virtual void set_slice_density(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &density)=0
Set slice density.
virtual void set_slice_velocity(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &velocity)=0
Set slice velocity.
virtual std::vector< bool > get_slice_is_boundary(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Check if slice has velocity boundary conditions.
virtual void set_slice_last_applied_force(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner, std::vector< double > const &force)=0
Set stored force that was applied on slice in the last time step.
virtual std::vector< double > get_slice_last_applied_force(Utils::Vector3i const &lower_corner, Utils::Vector3i const &upper_corner) const =0
Get stored force that was applied on slice in the last time step.
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Context * context() const
Responsible context.
std::string_view name() const
Variant do_call_method(std::string const &name, VariantMap const &params) override
Variant gather_3d(std::vector< int > const &data_dims, LatticeModel const &lattice_model, std::vector< T >(LatticeModel::*getter)(Utils::Vector3i const &, Utils::Vector3i const &) const, double units_conversion=1.) const
void scatter_3d(Variant const &grid_values, std::vector< int > const &data_dims, LatticeModel &lattice_model, void(LatticeModel::*setter)(Utils::Vector3i const &, Utils::Vector3i const &, std::vector< T > const &), double units_conversion=1.)
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.
Recursive variant implementation.
Definition Variant.hpp:84