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
EKSpecies.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-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
33
35
37
38#include <memory>
39#include <stdexcept>
40#include <string>
41#include <unordered_map>
42
44
45class EKVTKHandle : public VTKHandleBase<::EKinWalberlaBase> {
46 static std::unordered_map<std::string, int> const obs_map;
47
48 std::unordered_map<std::string, int> const &get_obs_map() const override {
49 return obs_map;
50 }
51};
52
53class EKSpecies : public LatticeModel<::EKinWalberlaBase, EKVTKHandle> {
54protected:
61 double m_tau;
62 double m_density;
63
64 void make_instance(VariantMap const &params) override;
65
66public:
69 {{"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
70 {"diffusion",
71 [this](Variant const &v) {
73 },
74 [this]() { return m_instance->get_diffusion() / m_conv_diffusion; }},
75 {"kT",
76 [this](Variant const &v) {
78 auto const kT = get_value<double>(v);
79 if (kT < 0.) {
80 throw std::domain_error("Parameter 'kT' must be >= 0");
81 }
82 m_instance->set_kT(kT * m_conv_energy);
83 });
84 },
85 [this]() { return m_instance->get_kT() / m_conv_energy; }},
86 {"valency",
87 [this](Variant const &v) {
88 m_instance->set_valency(get_value<double>(v));
89 },
90 [this]() { return m_instance->get_valency(); }},
91 {"ext_efield",
92 [this](Variant const &v) {
93 m_instance->set_ext_efield(get_value<Utils::Vector3d>(v) *
95 },
96 [this]() {
97 return m_instance->get_ext_efield() / m_conv_ext_efield;
98 }},
99 {"advection",
100 [this](Variant const &v) {
101 m_instance->set_advection(get_value<bool>(v));
102 },
103 [this]() { return m_instance->get_advection(); }},
104 {"friction_coupling",
105 [this](Variant const &v) {
106 m_instance->set_friction_coupling(get_value<bool>(v));
107 },
108 [this]() { return m_instance->get_friction_coupling(); }},
109 {"single_precision", AutoParameter::read_only,
110 [this]() { return not m_instance->is_double_precision(); }},
111 {"tau", AutoParameter::read_only, [this]() { return m_tau; }},
112 {"density", AutoParameter::read_only,
113 [this]() { return m_density / m_conv_density; }},
114 {"thermalized", AutoParameter::read_only,
115 [this]() { return m_instance->is_thermalized(); }},
117 [this]() { return static_cast<int>(m_instance->get_seed()); }},
118 {"rng_state",
119 [this](Variant const &v) {
120 auto const rng_state = get_value<int>(v);
121 context()->parallel_try_catch([&]() {
122 if (rng_state < 0) {
123 throw std::domain_error("Parameter 'rng_state' must be >= 0");
124 }
125 m_instance->set_rng_state(static_cast<uint64_t>(rng_state));
126 });
127 },
128 [this]() {
129 auto const opt = m_instance->get_rng_state();
130 return (opt) ? Variant{static_cast<int>(*opt)} : Variant{None{}};
131 }},
132 {"shape", AutoParameter::read_only,
133 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
134 {"vtk_writers", AutoParameter::read_only,
135 [this]() { return serialize_vtk_writers(); }}});
136 }
137
138 void do_construct(VariantMap const &params) override;
139
140 [[nodiscard]] auto get_ekinstance() const { return m_instance; }
141 [[nodiscard]] auto get_lattice() const { return m_lattice; }
142
143 Variant do_call_method(std::string const &method,
144 VariantMap const &parameters) override;
145
152
154 return {
155 {"density", 1. / m_conv_density},
156 {"flux", 1. / m_conv_flux},
157 };
158 }
159
160private:
161 void load_checkpoint(std::string const &filename, int mode);
162 void save_checkpoint(std::string const &filename, int mode);
163};
164
165} // namespace ScriptInterface::walberla
166
167#endif // WALBERLA
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.
Context * context() const
Responsible context.
auto get_conversion_factor_flux() const noexcept
auto get_conversion_factor_density() const noexcept
void make_instance(VariantMap const &params) override
Definition EKSpecies.cpp:89
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
Definition EKSpecies.cpp:49
::LatticeModel::units_map get_latice_to_md_units_conversion() const override
void do_construct(VariantMap const &params) override
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition EKSpecies.hpp:48
This file contains the defaults for ESPResSo.
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
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
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only