ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CoulombP3M.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 P3M
25
26
#include "
Actor.hpp
"
27
28
#include "
core/electrostatics/p3m.hpp
"
29
#include "
core/electrostatics/p3m.impl.hpp
"
30
#include "
core/p3m/FFTBackendLegacy.hpp
"
31
#include "
core/p3m/FFTBuffersLegacy.hpp
"
32
33
#include "
script_interface/get_value.hpp
"
34
35
#include <memory>
36
#include <stdexcept>
37
#include <string>
38
#include <utility>
39
40
#ifdef FFTW3_H
41
#error "The FFTW3 library shouldn't be visible in this translation unit"
42
#endif
43
44
namespace
ScriptInterface
{
45
namespace
Coulomb
{
46
47
template
<Arch Architecture>
48
class
CoulombP3M
:
public
Actor
<CoulombP3M<Architecture>, ::CoulombP3M> {
49
int
m_tune_timings;
50
bool
m_tune;
51
bool
m_tune_verbose;
52
bool
m_check_complex_residuals;
53
bool
m_single_precision;
54
55
public
:
56
using
Base
=
Actor<CoulombP3M<Architecture>
,
::CoulombP3M
>;
57
using
Base::actor
;
58
using
Base::add_parameters
;
59
using
Base::context
;
60
61
protected
:
62
using
Base::m_actor
;
63
using
Base::set_charge_neutrality_tolerance
;
64
65
public
:
66
CoulombP3M
() {
67
add_parameters
({
68
{
"single_precision"
,
AutoParameter::read_only
,
69
[
this
]() {
return
not
actor
()->is_double_precision(); }},
70
{
"alpha_L"
,
AutoParameter::read_only
,
71
[
this
]() {
return
actor
()->p3m_params.alpha_L; }},
72
{
"r_cut_iL"
,
AutoParameter::read_only
,
73
[
this
]() {
return
actor
()->p3m_params.r_cut_iL; }},
74
{
"mesh"
,
AutoParameter::read_only
,
75
[
this
]() {
return
actor
()->p3m_params.mesh; }},
76
{
"mesh_off"
,
AutoParameter::read_only
,
77
[
this
]() {
return
actor
()->p3m_params.mesh_off; }},
78
{
"cao"
,
AutoParameter::read_only
,
79
[
this
]() {
return
actor
()->p3m_params.cao; }},
80
{
"accuracy"
,
AutoParameter::read_only
,
81
[
this
]() {
return
actor
()->p3m_params.accuracy; }},
82
{
"epsilon"
,
AutoParameter::read_only
,
83
[
this
]() {
return
actor
()->p3m_params.epsilon; }},
84
{
"a"
,
AutoParameter::read_only
,
85
[
this
]() {
return
actor
()->p3m_params.a; }},
86
{
"alpha"
,
AutoParameter::read_only
,
87
[
this
]() {
return
actor
()->p3m_params.alpha; }},
88
{
"r_cut"
,
AutoParameter::read_only
,
89
[
this
]() {
return
actor
()->p3m_params.r_cut; }},
90
{
"is_tuned"
,
AutoParameter::read_only
,
91
[
this
]() {
return
actor
()->is_tuned(); }},
92
{
"verbose"
,
AutoParameter::read_only
,
93
[
this
]() {
return
m_tune_verbose; }},
94
{
"timings"
,
AutoParameter::read_only
,
95
[
this
]() {
return
m_tune_timings; }},
96
{
"tune"
,
AutoParameter::read_only
, [
this
]() {
return
m_tune; }},
97
{
"check_complex_residuals"
,
AutoParameter::read_only
,
98
[
this
]() {
return
m_check_complex_residuals; }},
99
});
100
}
101
102
void
do_construct
(
VariantMap
const
&
params
)
override
{
103
m_tune =
get_value<bool>
(
params
,
"tune"
);
104
m_tune_timings =
get_value<int>
(
params
,
"timings"
);
105
m_tune_verbose =
get_value<bool>
(
params
,
"verbose"
);
106
m_check_complex_residuals =
107
get_value<bool>
(
params
,
"check_complex_residuals"
);
108
auto
const
single_precision
=
get_value<bool>
(
params
,
"single_precision"
);
109
context
()->
parallel_try_catch
([&]() {
110
if
(
Architecture
==
Arch::GPU
and
not
single_precision
) {
111
throw
std::invalid_argument(
112
"P3M GPU only implemented in single-precision mode"
);
113
}
114
auto
p3m =
P3MParameters
{!
get_value_or<bool>
(
params
,
"is_tuned"
, !m_tune),
115
get_value<double>
(
params
,
"epsilon"
),
116
get_value<double>
(
params
,
"r_cut"
),
117
get_value<Utils::Vector3i>
(
params
,
"mesh"
),
118
get_value<Utils::Vector3d>
(
params
,
"mesh_off"
),
119
get_value<int>
(
params
,
"cao"
),
120
get_value<double>
(
params
,
"alpha"
),
121
get_value<double>
(
params
,
"accuracy"
)};
122
make_handle(
single_precision
, std::move(p3m),
123
get_value<double>
(
params
,
"prefactor"
), m_tune_timings,
124
m_tune_verbose, m_check_complex_residuals);
125
});
126
set_charge_neutrality_tolerance
(
params
);
127
}
128
129
private
:
130
template
<
typename
FloatType,
class
...
Args
>
131
void
make_handle_impl(
Args
&&...
args
) {
132
m_actor
=
new_p3m_handle
<FloatType,
Architecture
,
FFTBackendLegacy
,
133
FFTBuffersLegacy
>(std::forward<Args>(
args
)...);
134
}
135
template
<
class
...
Args
>
136
void
make_handle(
bool
single_precision
,
Args
&&...
args
) {
137
if
(
single_precision
) {
138
make_handle_impl<
float
,
Args
...>(std::forward<Args>(
args
)...);
139
}
else
{
140
make_handle_impl<
double
,
Args
...>(std::forward<Args>(
args
)...);
141
}
142
}
143
};
144
145
}
// namespace Coulomb
146
}
// namespace ScriptInterface
147
148
#endif
// P3M
FFTBackendLegacy.hpp
FFTBuffersLegacy.hpp
FFTBackendLegacy
Historic FFT backend based on FFTW3.
Definition
FFTBackendLegacy.hpp:45
FFTBuffersLegacy
Buffers for FFTBackendLegacy.
Definition
FFTBuffersLegacy.hpp:39
ScriptInterface::AutoParameters::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:115
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< CoulombP3M< Architecture >, ::CoulombP3M >::m_actor
std::shared_ptr< CoreActorClass > m_actor
Definition
electrostatics/Actor.hpp:55
ScriptInterface::Coulomb::Actor< CoulombP3M< Architecture >, ::CoulombP3M >::actor
std::shared_ptr< CoreActorClass > actor()
Definition
electrostatics/Actor.hpp:67
ScriptInterface::Coulomb::Actor< CoulombP3M< Architecture >, ::CoulombP3M >::set_charge_neutrality_tolerance
void set_charge_neutrality_tolerance(VariantMap const ¶ms)
Definition
electrostatics/Actor.hpp:71
ScriptInterface::Coulomb::CoulombP3M
Definition
CoulombP3M.hpp:48
ScriptInterface::Coulomb::CoulombP3M::do_construct
void do_construct(VariantMap const ¶ms) override
Definition
CoulombP3M.hpp:102
ScriptInterface::Coulomb::CoulombP3M::CoulombP3M
CoulombP3M()
Definition
CoulombP3M.hpp:66
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:58
config.hpp
This file contains the defaults for ESPResSo.
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:400
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:69
Arch::GPU
@ GPU
p3m.hpp
P3M algorithm for long-range Coulomb interaction.
p3m.impl.hpp
new_p3m_handle
std::shared_ptr< CoulombP3M > new_p3m_handle(P3MParameters &&p3m, Args &&...args)
Definition
p3m.impl.hpp:189
params
static SteepestDescentParameters params
Currently active steepest descent instance.
Definition
steepest_descent.cpp:44
CoulombP3M
P3M solver.
Definition
p3m.hpp:55
P3MParameters
Structure to hold P3M parameters and some dependent variables.
Definition
p3m/common.hpp:59
ScriptInterface::AutoParameter::read_only
static constexpr const ReadOnly read_only
Definition
AutoParameter.hpp:42
src
script_interface
electrostatics
CoulombP3M.hpp
Generated on Fri Nov 22 2024 02:13:54 for ESPResSo by
1.9.8