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 ESPRESSO_WALBERLA_FFT
25
26#include "EKPoissonSolver.hpp"
27
28#include "LatticeWalberla.hpp"
29
30#include "core/MpiCallbacks.hpp"
32
35
38
40
41#include <memory>
42
44
45class EKFFT : public EKPoissonSolver {
46protected:
47 std::unique_ptr<ResourceManager> m_resources_lock;
48 std::shared_ptr<LatticeWalberla> m_lattice;
51
52public:
53 void make_instance(VariantMap const &args) override {
54 // unit conversions
55 auto const agrid = get_value<double>(m_lattice->get_parameter("agrid"));
56 m_conv_permittivity = Utils::int_pow<2>(agrid);
57 auto const permittivity =
59
62 m_instance->setup_fft(false);
63 }
64
65 void do_construct(VariantMap const &args) override {
66 m_single_precision = get_value_or<bool>(args, "single_precision", false);
70
71 make_instance(args), m_resources_lock = std::make_unique<ResourceManager>();
72 // MPI communicator is needed to destroy the FFT plans
73 m_resources_lock->acquire_lock(::communication_environment->get_mpi_env());
74 for (auto &vtk : m_vtk_writers) {
75 vtk->attach_to_lattice(m_instance, get_lattice_to_md_units_conversion());
76 }
77 }
78
81 {"permittivity",
82 [this](Variant const &v) {
83 m_instance->set_permittivity(get_value<double>(v) *
85 },
86 [this]() {
87 return m_instance->get_permittivity() / m_conv_permittivity;
88 }},
89 {"single_precision", AutoParameter::read_only,
90 [this]() { return m_single_precision; }},
91 {"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
93 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
94 });
95 }
96
97 ~EKFFT() override {
98 m_lattice.reset();
99 m_instance.reset();
100 m_resources_lock.reset();
101 }
102
103 [[nodiscard]] std::shared_ptr<::walberla::PoissonSolver>
105 return m_instance;
106 }
107};
108
109} // namespace ScriptInterface::walberla
110
111#endif // ESPRESSO_WALBERLA_FFT
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
void add_parameters(std::vector< AutoParameter > &&params)
std::unique_ptr< ResourceManager > m_resources_lock
Definition EKFFT.hpp:47
void do_construct(VariantMap const &args) override
Definition EKFFT.hpp:65
std::shared_ptr< LatticeWalberla > m_lattice
Definition EKFFT.hpp:48
void make_instance(VariantMap const &args) override
Definition EKFFT.hpp:53
std::shared_ptr<::walberla::PoissonSolver > get_instance() const noexcept override
Definition EKFFT.hpp:104
::LatticeModel::units_map get_lattice_to_md_units_conversion() const override
std::unique_ptr< CommunicationEnvironment > communication_environment
This file contains the asynchronous MPI communication.
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:133
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
Recursive variant implementation.
Definition Variant.hpp:84