ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
DipolarLayerCorrection.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_DIPOLES
25
26
#include "
Actor.hpp
"
27
28
#include "
DipolarDirectSum.hpp
"
29
#include "
DipolarP3M.hpp
"
30
31
#include "
core/magnetostatics/dlc.hpp
"
32
33
#include "
script_interface/get_value.hpp
"
34
35
#include <memory>
36
#include <string>
37
#include <variant>
38
39
namespace
ScriptInterface
{
40
namespace
Dipoles
{
41
42
class
DipolarLayerCorrection
43
:
public
Actor
<DipolarLayerCorrection, ::DipolarLayerCorrection> {
44
using
DipolarDSR
=
DipolarDirectSum
;
45
using
BaseSolver = std::variant<
46
#ifdef ESPRESSO_DP3M
47
std::shared_ptr<DipolarP3M<Arch::CPU>>,
48
#endif
49
std::shared_ptr<DipolarDSR>>;
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
DipolarLayerCorrection
() {
59
add_parameters
({
60
{
"maxPWerror"
,
AutoParameter::read_only
,
61
[
this
]() {
return
actor
()->dlc.maxPWerror; }},
62
{
"gap_size"
,
AutoParameter::read_only
,
63
[
this
]() {
return
actor
()->dlc.gap_size; }},
64
{
"far_cut"
,
AutoParameter::read_only
,
65
[
this
]() {
return
actor
()->dlc.far_cut; }},
66
{
"actor"
,
AutoParameter::read_only
,
67
[
this
]() {
68
return
std::visit([](
auto
&solver) {
return
Variant
{solver}; },
69
m_solver);
70
}},
71
});
72
}
73
74
void
do_construct
(
VariantMap
const
&
params
)
override
{
75
::DipolarLayerCorrection::BaseSolver
solver;
76
auto
so_ptr
=
get_value<ObjectRef>
(
params
,
"actor"
);
77
context
()->
parallel_try_catch
([&]() {
78
#ifdef ESPRESSO_DP3M
79
if
(
auto
so
= std::dynamic_pointer_cast<
DipolarP3M<Arch::CPU>
>(
so_ptr
)) {
80
solver =
so
->actor();
81
m_solver =
so
;
82
return
;
83
}
84
#endif
// ESPRESSO_DP3M
85
if
(
auto
so
= std::dynamic_pointer_cast<DipolarDSR>(
so_ptr
)) {
86
solver =
so
->actor();
87
m_solver =
so
;
88
return
;
89
}
90
throw
std::invalid_argument(
"Parameter 'actor' of type "
+
91
std::string{
so_ptr
->name()} +
92
" isn't supported by DLC"
);
93
});
94
context
()->
parallel_try_catch
([&]() {
95
auto
dlc =
dlc_data
(
get_value<double>
(
params
,
"maxPWerror"
),
96
get_value<double>
(
params
,
"gap_size"
),
97
get_value<double>
(
params
,
"far_cut"
));
98
m_actor
=
99
std::make_shared<CoreActorClass>(std::move(dlc), std::move(solver));
100
});
101
}
102
};
103
104
}
// namespace Dipoles
105
}
// namespace ScriptInterface
106
107
#endif
// ESPRESSO_DIPOLES
DipolarDirectSum.hpp
DipolarP3M.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::Dipoles::Actor
Common interface for magnetostatic actors.
Definition
magnetostatics/Actor.hpp:45
ScriptInterface::Dipoles::Actor< DipolarLayerCorrection, ::DipolarLayerCorrection >::actor
std::shared_ptr< CoreActorClass > actor()
Definition
magnetostatics/Actor.hpp:73
ScriptInterface::Dipoles::Actor< DipolarLayerCorrection, ::DipolarLayerCorrection >::m_actor
std::shared_ptr< CoreActorClass > m_actor
Definition
magnetostatics/Actor.hpp:54
ScriptInterface::Dipoles::DipolarDirectSum
Definition
DipolarDirectSum.hpp:38
ScriptInterface::Dipoles::DipolarLayerCorrection
Definition
DipolarLayerCorrection.hpp:43
ScriptInterface::Dipoles::DipolarLayerCorrection::DipolarLayerCorrection
DipolarLayerCorrection()
Definition
DipolarLayerCorrection.hpp:58
ScriptInterface::Dipoles::DipolarLayerCorrection::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
DipolarLayerCorrection.hpp:74
ScriptInterface::Dipoles::DipolarLayerCorrection::on_bind_system
void on_bind_system(::System::System &) override
Definition
DipolarLayerCorrection.hpp:52
ScriptInterface::Dipoles::DipolarP3M
Definition
DipolarP3M.hpp:46
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
dlc.hpp
get_value.hpp
Actor.hpp
Dipoles
Definition
magnetostatics/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
DipolarLayerCorrection::BaseSolver
std::variant< std::shared_ptr< DipolarP3M >, std::shared_ptr< DipolarDirectSum > > BaseSolver
Definition
dlc.hpp:83
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
dlc_data
Parameters for the DLC method.
Definition
dlc.hpp:47
src
script_interface
magnetostatics
DipolarLayerCorrection.hpp
Generated on Sun Dec 7 2025 02:31:13 for ESPResSo by
1.9.8