ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
DipolarP3M.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 DP3M
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 Dipoles {
46
47template <Arch Architecture>
48class DipolarP3M : public Actor<DipolarP3M<Architecture>, ::DipolarP3M> {
49 int m_tune_timings;
50 bool m_tune;
51 bool m_tune_verbose;
52
53public:
55 using Base::actor;
57 using Base::context;
58
59protected:
60 using Base::m_actor;
61
62public:
65 {"single_precision", AutoParameter::read_only,
66 [this]() { return not actor()->is_double_precision(); }},
67 {"alpha_L", AutoParameter::read_only,
68 [this]() { return actor()->dp3m_params.alpha_L; }},
69 {"r_cut_iL", AutoParameter::read_only,
70 [this]() { return actor()->dp3m_params.r_cut_iL; }},
72 [this]() { return actor()->dp3m_params.mesh; }},
73 {"mesh_off", AutoParameter::read_only,
74 [this]() { return actor()->dp3m_params.mesh_off; }},
76 [this]() { return actor()->dp3m_params.cao; }},
77 {"accuracy", AutoParameter::read_only,
78 [this]() { return actor()->dp3m_params.accuracy; }},
79 {"epsilon", AutoParameter::read_only,
80 [this]() { return actor()->dp3m_params.epsilon; }},
82 [this]() { return actor()->dp3m_params.a; }},
84 [this]() { return actor()->dp3m_params.alpha; }},
86 [this]() { return actor()->dp3m_params.r_cut; }},
87 {"is_tuned", AutoParameter::read_only,
88 [this]() { return actor()->is_tuned(); }},
89 {"verbose", AutoParameter::read_only,
90 [this]() { return m_tune_verbose; }},
91 {"timings", AutoParameter::read_only,
92 [this]() { return m_tune_timings; }},
93 {"tune", AutoParameter::read_only, [this]() { return m_tune; }},
94 });
95 }
96
97 void do_construct(VariantMap const &params) override {
98 m_tune = get_value<bool>(params, "tune");
99 m_tune_timings = get_value<int>(params, "timings");
100 m_tune_verbose = get_value<bool>(params, "verbose");
101 auto const single_precision = get_value<bool>(params, "single_precision");
102 static_assert(Architecture == Arch::CPU, "GPU not implemented");
103 context()->parallel_try_catch([&]() {
104 auto p3m = P3MParameters{!get_value_or<bool>(params, "is_tuned", !m_tune),
105 get_value<double>(params, "epsilon"),
106 get_value<double>(params, "r_cut"),
109 get_value<int>(params, "cao"),
110 get_value<double>(params, "alpha"),
111 get_value<double>(params, "accuracy")};
112 make_handle(single_precision, std::move(p3m),
113 get_value<double>(params, "prefactor"), m_tune_timings,
114 m_tune_verbose);
115 });
116 }
117
118private:
119 template <typename FloatType, class... Args>
120 void make_handle_impl(Args &&...args) {
122 FFTBuffersLegacy>(std::forward<Args>(args)...);
123 }
124 template <class... Args>
125 void make_handle(bool single_precision, Args &&...args) {
126 if (single_precision) {
127 make_handle_impl<float, Args...>(std::forward<Args>(args)...);
128 } else {
129 make_handle_impl<double, Args...>(std::forward<Args>(args)...);
130 }
131 }
132};
133
134} // namespace Dipoles
135} // namespace ScriptInterface
136
137#endif // DP3M
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 magnetostatic actors.
void do_construct(VariantMap const &params) override
Context * context() const
Responsible context.
This file contains the defaults for ESPResSo.
P3M algorithm for long-range magnetic dipole-dipole interaction.
std::shared_ptr< DipolarP3M > new_dp3m_handle(P3MParameters &&p3m, Args &&...args)
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
static SteepestDescentParameters params
Currently active steepest descent instance.
Dipolar P3M solver.
Definition dp3m.hpp:59
Structure to hold P3M parameters and some dependent variables.
static constexpr const ReadOnly read_only