ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CoulombScafacos.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
25
26
#include "
Actor.hpp
"
27
28
#include "
core/communication.hpp
"
29
#include "
core/electrostatics/scafacos.hpp
"
30
#include "
core/scafacos/ScafacosContextBase.hpp
"
31
32
#include "
script_interface/get_value.hpp
"
33
#include "
script_interface/scafacos/scafacos.hpp
"
34
35
#include <iomanip>
36
#include <memory>
37
#include <regex>
38
#include <set>
39
#include <sstream>
40
#include <string>
41
#include <vector>
42
43
namespace
ScriptInterface
{
44
namespace
Coulomb
{
45
46
class
CoulombScafacos
:
public
Actor
<CoulombScafacos, ::CoulombScafacos> {
47
std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
48
49
public
:
50
CoulombScafacos
() {
51
add_parameters
({
52
{
"method_name"
,
AutoParameter::read_only
,
53
[
this
]() {
return
actor
()->get_method(); }},
54
{
"method_params"
,
AutoParameter::read_only
,
55
[
this
]() {
56
auto
const
m_tuned_methods
=
57
std::set<std::string>{
"ewald"
,
"p2nfft"
,
"p3m"
};
58
auto
parameters_string
=
actor
()->get_parameters();
59
auto
const
method_name
=
actor
()->get_method();
60
auto
const
delegate
=
actor
()->get_near_field_delegation();
61
if
(
delegate
and
m_tuned_methods
.contains(
method_name
)) {
62
auto
const
tuned_r_cut
=
actor
()->get_r_cut();
63
auto
const
field_name
=
method_name
+
"_r_cut"
;
64
std::ostringstream
serializer
;
65
serializer
<< std::scientific << std::setprecision(17);
66
serializer
<<
tuned_r_cut
;
67
auto
const
tuned_r_cut_string
=
serializer
.str();
68
auto
const
replacement
=
69
","
+
field_name
+
","
+
tuned_r_cut_string
;
70
if
(
parameters_string
.find(
field_name
) ==
field_name
.npos) {
71
parameters_string
+=
replacement
;
72
}
else
{
73
auto
const
field_pattern
=
74
std::regex(
","
+
field_name
+
",[0-9eE\\-\\+\\.]+"
);
75
parameters_string
= std::regex_replace(
76
parameters_string
, std::regex(
field_pattern
),
replacement
);
77
}
78
}
79
return
Scafacos::deserialize_parameters
(
parameters_string
);
80
}},
81
});
82
}
83
84
~CoulombScafacos
()
override
{
85
m_actor
.reset();
86
m_mpi_env_lock.reset();
87
}
88
89
void
do_construct
(
VariantMap
const
¶ms)
override
{
90
auto
const
method_name
=
get_value<std::string>
(params,
"method_name"
);
91
auto
const
param_list
= params.at(
"method_params"
);
92
auto
const
prefactor =
get_value<double>
(params,
"prefactor"
);
93
94
context
()->
parallel_try_catch
([&]() {
95
ScafacosContextBase::sanity_check_method
(
method_name
);
96
auto
const
method_params
=
Scafacos::serialize_parameters
(
param_list
);
97
m_actor
=
make_coulomb_scafacos
(
method_name
,
method_params
);
98
actor
()->set_prefactor(prefactor);
99
});
100
set_charge_neutrality_tolerance
(params);
101
// MPI communicator is needed to destroy the FFT plans
102
m_mpi_env_lock =
::communication_environment
->get_mpi_env();
103
}
104
105
Variant
do_call_method
(std::string
const
&
name
,
106
VariantMap
const
¶ms)
override
{
107
if
(
name
==
"set_near_field_delegation"
) {
108
auto
const
delegate
=
get_value<bool>
(params,
"delegate"
);
109
context
()->
parallel_try_catch
(
110
[&]() {
actor
()->set_near_field_delegation(
delegate
); });
111
return
{};
112
}
113
if
(
name
==
"get_near_field_delegation"
) {
114
return
actor
()->get_near_field_delegation();
115
}
116
if
(
name
==
"get_available_methods"
) {
117
return
make_vector_of_variants
(
Scafacos::available_methods
());
118
}
119
return
Actor<SIActorClass, CoreActorClass>::do_call_method
(
name
, params);
120
}
121
};
122
123
}
// namespace Coulomb
124
}
// namespace ScriptInterface
125
126
#endif
// ESPRESSO_SCAFACOS
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::Coulomb::Actor
Common interface for electrostatic actors.
Definition
electrostatics/Actor.hpp:45
ScriptInterface::Coulomb::Actor< CoulombScafacos, ::CoulombScafacos >::m_actor
std::shared_ptr< CoreActorClass > m_actor
Definition
electrostatics/Actor.hpp:55
ScriptInterface::Coulomb::Actor< CoulombScafacos, ::CoulombScafacos >::actor
std::shared_ptr< CoreActorClass > actor()
Definition
electrostatics/Actor.hpp:69
ScriptInterface::Coulomb::Actor::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
electrostatics/Actor.impl.hpp:88
ScriptInterface::Coulomb::Actor< CoulombScafacos, ::CoulombScafacos >::set_charge_neutrality_tolerance
void set_charge_neutrality_tolerance(VariantMap const ¶ms)
Definition
electrostatics/Actor.hpp:73
ScriptInterface::Coulomb::CoulombScafacos
Definition
CoulombScafacos.hpp:46
ScriptInterface::Coulomb::CoulombScafacos::~CoulombScafacos
~CoulombScafacos() override
Definition
CoulombScafacos.hpp:84
ScriptInterface::Coulomb::CoulombScafacos::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
CoulombScafacos.hpp:89
ScriptInterface::Coulomb::CoulombScafacos::CoulombScafacos
CoulombScafacos()
Definition
CoulombScafacos.hpp:50
ScriptInterface::Coulomb::CoulombScafacos::do_call_method
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
Definition
CoulombScafacos.hpp:105
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_coulomb_scafacos
std::shared_ptr< CoulombScafacos > make_coulomb_scafacos(std::string const &method, std::string const ¶meters)
Definition
electrostatics/scafacos_impl.cpp:47
get_value.hpp
Actor.hpp
Coulomb
Definition
electrostatics/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
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
electrostatics
CoulombScafacos.hpp
Generated on Sun Jan 4 2026 02:32:23 for ESPResSo by
1.9.8