ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
EKFFT.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022-2023 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 WALBERLA
25#ifdef WALBERLA_FFT
26
27#include "EKPoissonSolver.hpp"
28#include "LatticeWalberla.hpp"
29
30#include "core/MpiCallbacks.hpp"
32
35
38
40
41#include <memory>
42
44
45class EKFFT : public EKPoissonSolver {
46 std::unique_ptr<ResourceManager> m_resources_lock;
47 std::shared_ptr<::walberla::PoissonSolver> m_instance;
48 std::shared_ptr<LatticeWalberla> m_lattice;
49 double m_conv_permittivity;
50 bool m_single_precision;
51
52public:
53 void do_construct(VariantMap const &args) override {
54 m_single_precision = get_value_or<bool>(args, "single_precision", false);
55 m_lattice = get_value<decltype(m_lattice)>(args, "lattice");
56
57 // unit conversions
58 auto const agrid = get_value<double>(m_lattice->get_parameter("agrid"));
59 m_conv_permittivity = Utils::int_pow<2>(agrid);
60 auto const permittivity =
61 get_value<double>(args, "permittivity") * m_conv_permittivity;
62
64 m_lattice->lattice(), permittivity, m_single_precision);
65 m_resources_lock = std::make_unique<ResourceManager>();
66 // MPI communicator is needed to destroy the FFT plans
67 m_resources_lock->acquire_lock(
68 Communication::mpiCallbacksHandle()->share_mpi_env());
69 }
70
73 {"permittivity",
74 [this](Variant const &v) {
75 m_instance->set_permittivity(get_value<double>(v) *
76 m_conv_permittivity);
77 },
78 [this]() {
79 return m_instance->get_permittivity() / m_conv_permittivity;
80 }},
81 {"single_precision", AutoParameter::read_only,
82 [this]() { return m_single_precision; }},
83 {"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
84 });
85 }
86
87 ~EKFFT() override {
88 m_lattice.reset();
89 m_instance.reset();
90 m_resources_lock.reset();
91 }
92
93 [[nodiscard]] std::shared_ptr<::walberla::PoissonSolver>
94 get_instance() const noexcept override {
95 return m_instance;
96 }
97};
98
99} // namespace ScriptInterface::walberla
100
101#endif // WALBERLA_FFT
102#endif // WALBERLA
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
void add_parameters(std::vector< AutoParameter > &&params)
void do_construct(VariantMap const &args) override
Definition EKFFT.hpp:53
std::shared_ptr<::walberla::PoissonSolver > get_instance() const noexcept override
Definition EKFFT.hpp:94
This file contains the defaults for ESPResSo.
This file contains the asynchronous MPI communication.
std::shared_ptr< MpiCallbacks > mpiCallbacksHandle()
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:80
std::shared_ptr< walberla::PoissonSolver > new_ek_poisson_fft(std::shared_ptr< LatticeWalberla > const &lattice, double permittivity, bool single_precision)
static constexpr const ReadOnly read_only