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 ESPRESSO_WALBERLA
25
26
#include "
LatticeModel.hpp
"
27
#include "
LatticeWalberla.hpp
"
28
#include "
VTKHandle.hpp
"
29
30
#include <
walberla_bridge/LatticeModel.hpp
>
31
#include <
walberla_bridge/LatticeWalberla.hpp
>
32
#include <
walberla_bridge/electrokinetics/EKinWalberlaBase.hpp
>
33
34
#include <
script_interface/ScriptInterface.hpp
>
35
36
#include <
utils/math/int_pow.hpp
>
37
38
#include <filesystem>
39
#include <memory>
40
#include <stdexcept>
41
#include <string>
42
#include <unordered_map>
43
44
namespace
ScriptInterface::walberla
{
45
46
class
EKVTKHandle
:
public
VTKHandleBase
<::EKinWalberlaBase> {
47
static
std::unordered_map<std::string, int>
const
obs_map;
48
49
std::unordered_map<std::string, int>
const
&
get_obs_map
()
const override
{
50
return
obs_map;
51
}
52
};
53
54
class
EKSpecies
:
public
LatticeModel
<::EKinWalberlaBase, EKVTKHandle> {
55
protected
:
56
using
Base
=
LatticeModel<::EKinWalberlaBase, EKVTKHandle>
;
57
double
m_conv_diffusion
;
58
double
m_conv_ext_efield
;
59
double
m_conv_energy
;
60
double
m_conv_density
;
61
double
m_conv_flux
;
62
double
m_tau
;
63
double
m_density
;
64
65
public
:
66
EKSpecies
() {
67
add_parameters
(
68
{{
"lattice"
,
AutoParameter::read_only
, [
this
]() {
return
m_lattice
; }},
69
{
"diffusion"
,
70
[
this
](
Variant
const
&v) {
71
m_instance
->set_diffusion(
get_value<double>
(v) *
m_conv_diffusion
);
72
},
73
[
this
]() {
return
m_instance
->get_diffusion() /
m_conv_diffusion
; }},
74
{
"kT"
,
75
[
this
](
Variant
const
&v) {
76
context
()->
parallel_try_catch
([&]() {
77
auto
const
kT =
get_value<double>
(v);
78
if
(kT < 0.) {
79
throw
std::domain_error(
"Parameter 'kT' must be >= 0"
);
80
}
81
m_instance
->set_kT(kT *
m_conv_energy
);
82
});
83
},
84
[
this
]() {
return
m_instance
->get_kT() /
m_conv_energy
; }},
85
{
"valency"
,
86
[
this
](
Variant
const
&v) {
87
m_instance
->set_valency(
get_value<double>
(v));
88
},
89
[
this
]() {
return
m_instance
->get_valency(); }},
90
{
"ext_efield"
,
91
[
this
](
Variant
const
&v) {
92
m_instance
->set_ext_efield(
get_value<Utils::Vector3d>
(v) *
93
m_conv_ext_efield
);
94
},
95
[
this
]() {
96
return
m_instance
->get_ext_efield() /
m_conv_ext_efield
;
97
}},
98
{
"advection"
,
99
[
this
](
Variant
const
&v) {
100
m_instance
->set_advection(
get_value<bool>
(v));
101
},
102
[
this
]() {
return
m_instance
->get_advection(); }},
103
{
"friction_coupling"
,
104
[
this
](
Variant
const
&v) {
105
m_instance
->set_friction_coupling(
get_value<bool>
(v));
106
},
107
[
this
]() {
return
m_instance
->get_friction_coupling(); }},
108
{
"single_precision"
,
AutoParameter::read_only
,
109
[
this
]() {
return
not
m_instance
->is_double_precision(); }},
110
{
"tau"
,
AutoParameter::read_only
, [
this
]() {
return
m_tau
; }},
111
{
"density"
,
AutoParameter::read_only
,
112
[
this
]() {
return
m_density
/
m_conv_density
; }},
113
{
"thermalized"
,
AutoParameter::read_only
,
114
[
this
]() {
return
m_instance
->is_thermalized(); }},
115
{
"seed"
,
AutoParameter::read_only
,
116
[
this
]() {
return
static_cast<
int
>
(
m_instance
->get_seed()); }},
117
{
"rng_state"
,
118
[
this
](
Variant
const
&v) {
119
auto
const
rng_state
=
get_value<int>
(v);
120
context
()->
parallel_try_catch
([&]() {
121
if
(
rng_state
< 0) {
122
throw
std::domain_error(
"Parameter 'rng_state' must be >= 0"
);
123
}
124
m_instance
->set_rng_state(
static_cast<
uint64_t
>
(
rng_state
));
125
});
126
},
127
[
this
]() {
128
auto
const
opt
=
m_instance
->get_rng_state();
129
return
(
opt
) ?
Variant
{
static_cast<
int
>
(*opt)} :
Variant
{
None
{}};
130
}},
131
{
"shape"
,
AutoParameter::read_only
,
132
[
this
]() {
return
m_instance
->get_lattice().get_grid_dimensions(); }},
133
{
"vtk_writers"
,
AutoParameter::read_only
,
134
[
this
]() {
return
serialize_vtk_writers
(); }}});
135
}
136
137
void
do_construct
(
VariantMap
const
&
params
)
override
;
138
139
[[
nodiscard
]]
auto
get_ekinstance
()
const
{
return
m_instance
; }
140
[[
nodiscard
]]
auto
get_lattice
()
const
{
return
m_lattice
; }
141
142
Variant
do_call_method
(std::string
const
&
method
,
143
VariantMap
const
&
parameters
)
override
;
144
145
[[
nodiscard
]]
auto
get_conversion_factor_density
()
const
noexcept
{
146
return
m_conv_density
;
147
}
148
[[
nodiscard
]]
auto
get_conversion_factor_flux
()
const
noexcept
{
149
return
m_conv_flux
;
150
}
151
152
::LatticeModel::units_map
153
get_lattice_to_md_units_conversion
()
const override
{
154
return
{
155
{
"density"
, 1. /
m_conv_density
},
156
{
"flux"
, 1. /
m_conv_flux
},
157
};
158
}
159
160
private
:
161
void
load_checkpoint(std::filesystem::path
const
&path,
int
mode
);
162
void
save_checkpoint(std::filesystem::path
const
&path,
int
mode
);
163
};
164
165
class
EKSpeciesCPU
:
public
EKSpecies
{
166
protected
:
167
void
make_instance
(
VariantMap
const
&
params
)
override
;
168
};
169
170
#ifdef ESPRESSO_CUDA
171
class
EKSpeciesGPU
:
public
EKSpecies
{
172
protected
:
173
void
make_instance
(
VariantMap
const
&
params
)
override
;
174
};
175
#endif
// ESPRESSO_CUDA
176
177
}
// namespace ScriptInterface::walberla
178
179
#endif
// ESPRESSO_WALBERLA
EKinWalberlaBase.hpp
ScriptInterface.hpp
LatticeModel::units_map
std::unordered_map< std::string, double > units_map
Definition
walberla_bridge/include/walberla_bridge/LatticeModel.hpp:33
ScriptInterface::AutoParameters::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:123
ScriptInterface::Context::parallel_try_catch
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
ScriptInterface::None
Type to indicate no value in Variant.
Definition
None.hpp:32
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
ScriptInterface::walberla::EKSpeciesCPU
Definition
EKSpecies.hpp:165
ScriptInterface::walberla::EKSpeciesCPU::make_instance
void make_instance(VariantMap const ¶ms) override
Definition
EKSpecies.cpp:102
ScriptInterface::walberla::EKSpeciesGPU
Definition
EKSpecies.hpp:171
ScriptInterface::walberla::EKSpeciesGPU::make_instance
void make_instance(VariantMap const ¶ms) override
Definition
EKSpecies.cpp:123
ScriptInterface::walberla::EKSpecies
Definition
EKSpecies.hpp:54
ScriptInterface::walberla::EKSpecies::get_conversion_factor_flux
auto get_conversion_factor_flux() const noexcept
Definition
EKSpecies.hpp:148
ScriptInterface::walberla::EKSpecies::m_conv_density
double m_conv_density
Definition
EKSpecies.hpp:60
ScriptInterface::walberla::EKSpecies::m_conv_diffusion
double m_conv_diffusion
Definition
EKSpecies.hpp:57
ScriptInterface::walberla::EKSpecies::get_ekinstance
auto get_ekinstance() const
Definition
EKSpecies.hpp:139
ScriptInterface::walberla::EKSpecies::get_conversion_factor_density
auto get_conversion_factor_density() const noexcept
Definition
EKSpecies.hpp:145
ScriptInterface::walberla::EKSpecies::m_density
double m_density
Definition
EKSpecies.hpp:63
ScriptInterface::walberla::EKSpecies::m_conv_flux
double m_conv_flux
Definition
EKSpecies.hpp:61
ScriptInterface::walberla::EKSpecies::get_lattice_to_md_units_conversion
::LatticeModel::units_map get_lattice_to_md_units_conversion() const override
Definition
EKSpecies.hpp:153
ScriptInterface::walberla::EKSpecies::get_lattice
auto get_lattice() const
Definition
EKSpecies.hpp:140
ScriptInterface::walberla::EKSpecies::EKSpecies
EKSpecies()
Definition
EKSpecies.hpp:66
ScriptInterface::walberla::EKSpecies::do_call_method
Variant do_call_method(std::string const &method, VariantMap const ¶meters) override
Definition
EKSpecies.cpp:52
ScriptInterface::walberla::EKSpecies::m_conv_energy
double m_conv_energy
Definition
EKSpecies.hpp:59
ScriptInterface::walberla::EKSpecies::m_conv_ext_efield
double m_conv_ext_efield
Definition
EKSpecies.hpp:58
ScriptInterface::walberla::EKSpecies::m_tau
double m_tau
Definition
EKSpecies.hpp:62
ScriptInterface::walberla::EKSpecies::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
EKSpecies.cpp:144
ScriptInterface::walberla::EKVTKHandle
Definition
EKSpecies.hpp:46
ScriptInterface::walberla::EKVTKHandle::get_obs_map
std::unordered_map< std::string, int > const & get_obs_map() const override
Definition
EKSpecies.hpp:49
ScriptInterface::walberla::LatticeModel
Definition
script_interface/walberla/LatticeModel.hpp:38
ScriptInterface::walberla::LatticeModel<::EKinWalberlaBase, EKVTKHandle >::m_instance
std::shared_ptr< ::EKinWalberlaBase > m_instance
Definition
script_interface/walberla/LatticeModel.hpp:41
ScriptInterface::walberla::LatticeModel<::EKinWalberlaBase, EKVTKHandle >::serialize_vtk_writers
auto serialize_vtk_writers() const
Definition
script_interface/walberla/LatticeModel.hpp:52
ScriptInterface::walberla::LatticeModel<::EKinWalberlaBase, EKVTKHandle >::m_lattice
std::shared_ptr< LatticeWalberla > m_lattice
Definition
script_interface/walberla/LatticeModel.hpp:40
ScriptInterface::walberla::VTKHandleBase
Definition
script_interface/walberla/VTKHandle.hpp:46
config.hpp
int_pow.hpp
ScriptInterface::walberla
Definition
script_interface/walberla/EKContainer.hpp:49
ScriptInterface::get_value
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
Definition
get_value.hpp:398
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
params
static SteepestDescentParameters params
Currently active steepest descent instance.
Definition
steepest_descent.cpp:44
ScriptInterface::AutoParameter::read_only
static constexpr const ReadOnly read_only
Definition
AutoParameter.hpp:42
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
LatticeModel.hpp
LatticeWalberla.hpp
VTKHandle.hpp
src
script_interface
walberla
EKSpecies.hpp
Generated on Sun Dec 7 2025 02:31:13 for ESPResSo by
1.9.8