ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ElectrostaticLayerCorrection.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2022 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_P3M
25
26
#include "
Actor.hpp
"
27
28
#include "
CoulombP3M.hpp
"
29
30
#include "
core/electrostatics/elc.hpp
"
31
32
#include "
script_interface/get_value.hpp
"
33
34
#include <memory>
35
#include <string>
36
#include <variant>
37
38
namespace
ScriptInterface
{
39
namespace
Coulomb
{
40
41
class
ElectrostaticLayerCorrection
42
:
public
Actor
<ElectrostaticLayerCorrection,
43
::ElectrostaticLayerCorrection> {
44
45
using
BaseSolver = std::variant<
46
#ifdef ESPRESSO_CUDA
47
std::shared_ptr<CoulombP3M<Arch::CUDA>>,
48
#endif
// ESPRESSO_CUDA
49
std::shared_ptr<CoulombP3M<Arch::CPU>>>;
50
BaseSolver m_solver;
51
52
void
on_bind_system
(
::System::System
&)
override
{
53
std::visit([
this
](
auto
&solver) { solver->bind_system(m_system.lock()); },
54
m_solver);
55
}
56
57
public
:
58
ElectrostaticLayerCorrection
() {
59
add_parameters
({
60
{
"maxPWerror"
,
AutoParameter::read_only
,
61
[
this
]() {
return
actor
()->elc.maxPWerror; }},
62
{
"gap_size"
,
AutoParameter::read_only
,
63
[
this
]() {
return
actor
()->elc.gap_size; }},
64
{
"far_cut"
,
AutoParameter::read_only
,
65
[
this
]() {
return
actor
()->elc.far_cut; }},
66
{
"neutralize"
,
AutoParameter::read_only
,
67
[
this
]() {
return
actor
()->elc.neutralize; }},
68
{
"delta_mid_top"
,
AutoParameter::read_only
,
69
[
this
]() {
return
actor
()->elc.delta_mid_top; }},
70
{
"delta_mid_bot"
,
AutoParameter::read_only
,
71
[
this
]() {
return
actor
()->elc.delta_mid_bot; }},
72
{
"const_pot"
,
AutoParameter::read_only
,
73
[
this
]() {
return
actor
()->elc.const_pot; }},
74
{
"pot_diff"
,
AutoParameter::read_only
,
75
[
this
]() {
return
actor
()->elc.pot_diff; }},
76
{
"actor"
,
AutoParameter::read_only
,
77
[
this
]() {
78
return
std::visit([](
auto
&solver) {
return
Variant
{solver}; },
79
m_solver);
80
}},
81
});
82
}
83
84
void
do_construct
(
VariantMap
const
&
params
)
override
{
85
::ElectrostaticLayerCorrection::BaseSolver
solver;
86
auto
so_ptr
=
get_value<ObjectRef>
(
params
,
"actor"
);
87
context
()->
parallel_try_catch
([&]() {
88
#ifdef ESPRESSO_CUDA
89
if
(
auto
so
= std::dynamic_pointer_cast<
CoulombP3M<Arch::CUDA>
>(
so_ptr
)) {
90
solver =
so
->actor();
91
m_solver =
so
;
92
return
;
93
}
94
#endif
// ESPRESSO_CUDA
95
if
(
auto
so
= std::dynamic_pointer_cast<
CoulombP3M<Arch::CPU>
>(
so_ptr
)) {
96
solver =
so
->actor();
97
m_solver =
so
;
98
return
;
99
}
100
throw
std::invalid_argument(
"Parameter 'actor' of type "
+
101
std::string{
so_ptr
->name()} +
102
" isn't supported by ELC"
);
103
});
104
context
()->
parallel_try_catch
([&]() {
105
auto
elc =
elc_data
{
get_value<double>
(
params
,
"maxPWerror"
),
106
get_value<double>
(
params
,
"gap_size"
),
107
get_value<double>
(
params
,
"far_cut"
),
108
get_value<bool>
(
params
,
"neutralize"
),
109
get_value<double>
(
params
,
"delta_mid_top"
),
110
get_value<double>
(
params
,
"delta_mid_bot"
),
111
get_value<bool>
(
params
,
"const_pot"
),
112
get_value<double>
(
params
,
"pot_diff"
)};
113
m_actor
=
114
std::make_shared<CoreActorClass>(std::move(elc), std::move(solver));
115
});
116
set_charge_neutrality_tolerance
(
params
);
117
}
118
};
119
120
}
// namespace Coulomb
121
}
// namespace ScriptInterface
122
123
#endif
// ESPRESSO_P3M
CoulombP3M.hpp
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::Coulomb::Actor
Common interface for electrostatic actors.
Definition
electrostatics/Actor.hpp:45
ScriptInterface::Coulomb::Actor< ElectrostaticLayerCorrection, ::ElectrostaticLayerCorrection >::m_actor
std::shared_ptr< CoreActorClass > m_actor
Definition
electrostatics/Actor.hpp:55
ScriptInterface::Coulomb::Actor< ElectrostaticLayerCorrection, ::ElectrostaticLayerCorrection >::actor
std::shared_ptr< CoreActorClass > actor()
Definition
electrostatics/Actor.hpp:69
ScriptInterface::Coulomb::Actor< ElectrostaticLayerCorrection, ::ElectrostaticLayerCorrection >::set_charge_neutrality_tolerance
void set_charge_neutrality_tolerance(VariantMap const ¶ms)
Definition
electrostatics/Actor.hpp:73
ScriptInterface::Coulomb::CoulombP3M
Definition
CoulombP3M.hpp:42
ScriptInterface::Coulomb::ElectrostaticLayerCorrection
Definition
ElectrostaticLayerCorrection.hpp:43
ScriptInterface::Coulomb::ElectrostaticLayerCorrection::on_bind_system
void on_bind_system(::System::System &) override
Definition
ElectrostaticLayerCorrection.hpp:52
ScriptInterface::Coulomb::ElectrostaticLayerCorrection::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
ElectrostaticLayerCorrection.hpp:84
ScriptInterface::Coulomb::ElectrostaticLayerCorrection::ElectrostaticLayerCorrection
ElectrostaticLayerCorrection()
Definition
ElectrostaticLayerCorrection.hpp:58
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
System::System
Main system class.
Definition
core/system/System.hpp:79
config.hpp
elc.hpp
ELC algorithm for long-range Coulomb interactions.
get_value.hpp
Actor.hpp
Coulomb
Definition
electrostatics/actor.hpp:30
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:33
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
ElectrostaticLayerCorrection::BaseSolver
std::variant< std::shared_ptr< CoulombP3M > > BaseSolver
Definition
elc.hpp:193
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
elc_data
Parameters for the ELC method.
Definition
elc.hpp:63
src
script_interface
electrostatics
ElectrostaticLayerCorrection.hpp
Generated on Sun Dec 7 2025 02:31:13 for ESPResSo by
1.9.8