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
EKSpeciesSlice.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 "EKSpecies.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 DensityBoundaryType = std::optional<double>;
50using FluxBoundaryType = std::optional<Utils::Vector3d>;
51
53
54 template <typename T> static Variant serialize(std::vector<T> const &values) {
55 if constexpr (std::is_same_v<T, FluxBoundaryType> or
56 std::is_same_v<T, DensityBoundaryType>) {
57 std::vector<Variant> vec;
58 vec.reserve(values.size());
59 for (auto const &opt : values) {
60 if (opt) {
61 vec.emplace_back(*opt);
62 } else {
63 vec.emplace_back(None{});
64 }
65 }
66 return {vec};
67 } else if constexpr (std::is_same_v<T, int> or std::is_same_v<T, double>) {
68 return {values};
69 } else {
71 }
72 }
73
74 template <typename T>
75 static std::vector<T> deserialize(Variant const &variant) {
76 std::vector<T> values;
77 if constexpr (std::is_same_v<T, FluxBoundaryType>) {
79 for (auto const &value : vector_variants) {
80 if (is_none(value)) {
81 values.emplace_back(std::nullopt);
82 } else {
83 values.emplace_back(get_value<Utils::Vector3d>(value));
84 }
85 }
86 } else if constexpr (std::is_same_v<T, DensityBoundaryType>) {
88 for (auto const &value : vector_variants) {
89 if (is_none(value)) {
90 values.emplace_back(std::nullopt);
91 } else {
92 values.emplace_back(get_value<double>(value));
93 }
94 }
95 } else if constexpr (std::is_same_v<T, double>) {
96 if (is_type<std::vector<int>>(variant)) {
98 values.reserve(values_int.size());
99 for (auto const val : values_int) {
100 values.emplace_back(static_cast<double>(val));
101 }
102 } else {
104 }
105 } else {
107 }
108 return values;
109 }
110};
111
112class EKSpeciesSlice : public LatticeSlice<EKFieldSerializer> {
114 std::shared_ptr<LatticeModel> m_ek_species;
115 std::shared_ptr<EKSpecies> m_ek_sip;
116 double m_conv_dens;
117 double m_conv_flux;
118 std::unordered_map<std::string, std::vector<int>> m_shape_val;
119
120public:
121 void do_construct(VariantMap const &params) override {
122 m_ek_sip = get_value<std::shared_ptr<EKSpecies>>(params, "parent_sip");
123 m_ek_species = m_ek_sip->get_ekinstance();
124 assert(m_ek_species);
125 m_conv_dens = m_ek_sip->get_conversion_factor_density();
126 m_conv_flux = m_ek_sip->get_conversion_factor_flux();
129 get_value<Utils::Vector3i>(params, "slice_lower_corner");
131 get_value<Utils::Vector3i>(params, "slice_upper_corner");
132 m_shape_val["density"] = {1};
133 m_shape_val["flux_at_boundary"] = {1};
134 m_shape_val["density_at_boundary"] = {1};
135 m_shape_val["is_boundary"] = {1};
136 }
137
138 Variant do_call_method(std::string const &name,
139 VariantMap const &params) override;
140
141 ::LatticeWalberla const &get_lattice() const override {
142 return m_ek_species->get_lattice();
143 }
144};
145
146} // namespace ScriptInterface::walberla
147
148#endif // WALBERLA
Vector implementation and trait types for boost qvm interoperability.
Interface of a lattice-based electrokinetic model.
Class that runs and controls the BlockForest in waLBerla.
Type to indicate no value in Variant.
boost::string_ref name() const
Variant do_call_method(std::string const &name, VariantMap const &params) override
::LatticeWalberla const & get_lattice() const override
void do_construct(VariantMap const &params) override
This file contains the defaults for ESPResSo.
std::optional< Utils::Vector3d > FluxBoundaryType
std::optional< double > DensityBoundaryType
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)