ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
DipolarScafacos.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_SCAFACOS_DIPOLES
25
26
#include "
Actor.hpp
"
27
28
#include "
core/communication.hpp
"
29
#include "
core/magnetostatics/scafacos.hpp
"
30
#include "
core/scafacos/ScafacosContextBase.hpp
"
31
32
#include "
script_interface/scafacos/scafacos.hpp
"
33
34
#include <memory>
35
#include <stdexcept>
36
#include <string>
37
#include <vector>
38
39
namespace
ScriptInterface
{
40
namespace
Dipoles
{
41
42
class
DipolarScafacos
:
public
Actor
<DipolarScafacos, ::DipolarScafacos> {
43
std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
44
45
public
:
46
DipolarScafacos
() {
47
add_parameters
({
48
{
"method_name"
,
AutoParameter::read_only
,
49
[
this
]() {
return
actor
()->get_method(); }},
50
{
"method_params"
,
AutoParameter::read_only
,
51
[
this
]() {
52
return
Scafacos::deserialize_parameters
(
actor
()->
get_parameters
());
53
}},
54
});
55
}
56
57
~DipolarScafacos
()
override
{
58
m_actor
.reset();
59
m_mpi_env_lock.reset();
60
}
61
62
void
do_construct
(
VariantMap
const
&
params
)
override
{
63
auto
const
method_name
=
get_value<std::string>
(
params
,
"method_name"
);
64
auto
const
param_list
=
params
.at(
"method_params"
);
65
auto
const
prefactor =
get_value<double>
(
params
,
"prefactor"
);
66
67
context
()->
parallel_try_catch
([&]() {
68
if
(prefactor <= 0.) {
69
throw
std::domain_error(
"Parameter 'prefactor' must be > 0"
);
70
}
71
ScafacosContextBase::sanity_check_method
(
method_name
);
72
auto
const
method_params
=
Scafacos::serialize_parameters
(
param_list
);
73
m_actor
=
make_dipolar_scafacos
(
method_name
,
method_params
);
74
actor
()->set_prefactor(prefactor);
75
});
76
// MPI communicator is needed to destroy the FFT plans
77
m_mpi_env_lock =
::communication_environment
->get_mpi_env();
78
}
79
80
Variant
do_call_method
(std::string
const
&
name
,
81
VariantMap
const
&
params
)
override
{
82
if
(
name
==
"get_available_methods"
) {
83
return
make_vector_of_variants
(
Scafacos::available_methods
());
84
}
85
return
Actor<SIActorClass, CoreActorClass>::do_call_method
(
name
,
params
);
86
}
87
};
88
89
}
// namespace Dipoles
90
}
// namespace ScriptInterface
91
92
#endif
// ESPRESSO_SCAFACOS_DIPOLES
ScafacosContextBase.hpp
ScafacosContextBase provides the public interface of the ScaFaCoS bridge.
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::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
magnetostatics/Actor.impl.hpp:40
ScriptInterface::Dipoles::Actor< DipolarScafacos, ::DipolarScafacos >::actor
std::shared_ptr< CoreActorClass > actor()
Definition
magnetostatics/Actor.hpp:73
ScriptInterface::Dipoles::Actor< DipolarScafacos, ::DipolarScafacos >::m_actor
std::shared_ptr< CoreActorClass > m_actor
Definition
magnetostatics/Actor.hpp:54
ScriptInterface::Dipoles::DipolarScafacos
Definition
DipolarScafacos.hpp:42
ScriptInterface::Dipoles::DipolarScafacos::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
DipolarScafacos.hpp:62
ScriptInterface::Dipoles::DipolarScafacos::DipolarScafacos
DipolarScafacos()
Definition
DipolarScafacos.hpp:46
ScriptInterface::Dipoles::DipolarScafacos::~DipolarScafacos
~DipolarScafacos() override
Definition
DipolarScafacos.hpp:57
ScriptInterface::Dipoles::DipolarScafacos::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
DipolarScafacos.hpp:80
ScriptInterface::ObjectHandle::get_parameters
VariantMap get_parameters() const
Get current parameters.
Definition
ObjectHandle.hpp:90
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
ScriptInterface::ObjectHandle::name
std::string_view name() const
Definition
ObjectHandle.cpp:117
communication_environment
std::unique_ptr< CommunicationEnvironment > communication_environment
Definition
communication.cpp:70
config.hpp
communication.hpp
This file contains the asynchronous MPI communication.
scafacos.hpp
make_dipolar_scafacos
std::shared_ptr< DipolarScafacos > make_dipolar_scafacos(std::string const &method, std::string const ¶meters)
Definition
magnetostatics/scafacos_impl.cpp:44
Actor.hpp
Dipoles
Definition
magnetostatics/actor.hpp:30
ScriptInterface::Scafacos::deserialize_parameters
std::unordered_map< std::string, Variant > deserialize_parameters(std::string const ¶meters)
Convert flattened parameters to a map.
Definition
scafacos.cpp:153
ScriptInterface::Scafacos::serialize_parameters
std::string serialize_parameters(Variant const &pack)
Flatten a parameter map.
Definition
scafacos.cpp:124
ScriptInterface::Scafacos::available_methods
std::vector< std::string > available_methods()
Fetch list of methods compiled in ScaFaCoS.
Definition
scafacos.cpp:50
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
ScriptInterface::make_vector_of_variants
auto make_vector_of_variants(std::vector< T > const &v)
Definition
Variant.hpp:148
scafacos.hpp
params
static SteepestDescentParameters params
Currently active steepest descent instance.
Definition
steepest_descent.cpp:44
ScafacosContextBase::sanity_check_method
static void sanity_check_method(std::string const &method_name)
Definition
ScafacosContextBase.cpp:39
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
src
script_interface
magnetostatics
DipolarScafacos.hpp
Generated on Sun Dec 7 2025 02:31:13 for ESPResSo by
1.9.8