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
32
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
44namespace ScriptInterface {
45namespace Coulomb {
46
47template <Arch Architecture>
48class 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
55public:
57 using Base::actor;
59 using Base::context;
60
61protected:
62 using Base::m_actor;
64
65public:
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; }},
75 [this]() { return actor()->p3m_params.mesh; }},
76 {"mesh_off", AutoParameter::read_only,
77 [this]() { return actor()->p3m_params.mesh_off; }},
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; }},
85 [this]() { return actor()->p3m_params.a; }},
87 [this]() { return actor()->p3m_params.alpha; }},
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([&]() {
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"),
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 });
127 }
128
129private:
130 template <typename FloatType, class... Args>
131 void make_handle_impl(Args &&...args) {
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
Historic FFT backend based on FFTW3.
Buffers for FFTBackendLegacy.
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Common interface for electrostatic actors.
void do_construct(VariantMap const &params) override
Context * context() const
Responsible context.
This file contains the defaults for ESPResSo.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
P3M algorithm for long-range Coulomb interaction.
std::shared_ptr< CoulombP3M > new_p3m_handle(P3MParameters &&p3m, Args &&...args)
Definition p3m.impl.hpp:189
static SteepestDescentParameters params
Currently active steepest descent instance.
P3M solver.
Definition p3m.hpp:55
Structure to hold P3M parameters and some dependent variables.
static constexpr const ReadOnly read_only