ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
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;
46
47class EKSpecies : public LatticeModel<::EKinWalberlaBase, EKVTKHandle> {
48protected:
55 double m_tau;
56 double m_density;
57
58 void make_instance(VariantMap const &params) override;
59
60public:
63 {{"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
64 {"diffusion",
65 [this](Variant const &v) {
66 m_instance->set_diffusion(get_value<double>(v) * m_conv_diffusion);
67 },
68 [this]() { return m_instance->get_diffusion() / m_conv_diffusion; }},
69 {"kT",
70 [this](Variant const &v) {
72 auto const kT = get_value<double>(v);
73 if (kT < 0.) {
74 throw std::domain_error("Parameter 'kT' must be >= 0");
75 }
76 m_instance->set_kT(kT * m_conv_energy);
77 });
78 },
79 [this]() { return m_instance->get_kT() / m_conv_energy; }},
80 {"valency",
81 [this](Variant const &v) {
82 m_instance->set_valency(get_value<double>(v));
83 },
84 [this]() { return m_instance->get_valency(); }},
85 {"ext_efield",
86 [this](Variant const &v) {
87 m_instance->set_ext_efield(get_value<Utils::Vector3d>(v) *
89 },
90 [this]() {
91 return m_instance->get_ext_efield() / m_conv_ext_efield;
92 }},
93 {"advection",
94 [this](Variant const &v) {
95 m_instance->set_advection(get_value<bool>(v));
96 },
97 [this]() { return m_instance->get_advection(); }},
98 {"friction_coupling",
99 [this](Variant const &v) {
100 m_instance->set_friction_coupling(get_value<bool>(v));
101 },
102 [this]() { return m_instance->get_friction_coupling(); }},
103 {"single_precision", AutoParameter::read_only,
104 [this]() { return not m_instance->is_double_precision(); }},
105 {"tau", AutoParameter::read_only, [this]() { return m_tau; }},
106 {"density", AutoParameter::read_only,
107 [this]() { return m_density / m_conv_density; }},
108 {"thermalized", AutoParameter::read_only,
109 [this]() { return m_instance->is_thermalized(); }},
111 [this]() { return static_cast<int>(m_instance->get_seed()); }},
112 {"rng_state",
113 [this](Variant const &v) {
114 auto const rng_state = get_value<int>(v);
115 context()->parallel_try_catch([&]() {
116 if (rng_state < 0) {
117 throw std::domain_error("Parameter 'rng_state' must be >= 0");
118 }
119 m_instance->set_rng_state(static_cast<uint64_t>(rng_state));
120 });
121 },
122 [this]() {
123 auto const opt = m_instance->get_rng_state();
124 return (opt) ? Variant{static_cast<int>(*opt)} : Variant{None{}};
125 }},
126 {"shape", AutoParameter::read_only,
127 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
128 {"vtk_writers", AutoParameter::read_only,
129 [this]() { return serialize_vtk_writers(); }}});
130 }
131
132 void do_construct(VariantMap const &params) override;
133
134 [[nodiscard]] auto get_ekinstance() const { return m_instance; }
135 [[nodiscard]] auto get_lattice() const { return m_lattice; }
136
137 Variant do_call_method(std::string const &method,
138 VariantMap const &parameters) override;
139
140 [[nodiscard]] auto get_conversion_factor_density() const noexcept {
141 return m_conv_density;
142 }
143 [[nodiscard]] auto get_conversion_factor_flux() const noexcept {
144 return m_conv_flux;
145 }
146
148 return {
149 {"density", 1. / m_conv_density},
150 {"flux", 1. / m_conv_flux},
151 };
152 }
153
154private:
155 void load_checkpoint(std::string const &filename, int mode);
156 void save_checkpoint(std::string const &filename, int mode);
157};
158
159class EKVTKHandle : public VTKHandleBase<::EKinWalberlaBase> {
160 static std::unordered_map<std::string, int> const obs_map;
161
162 std::unordered_map<std::string, int> const &get_obs_map() const override {
163 return obs_map;
164 }
165};
166
167} // namespace ScriptInterface::walberla
168
169#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:91
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
This file contains the defaults for ESPResSo.
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