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
39
41
42#include <memory>
43#include <string>
44#include <vector>
45
47
48class EKFFT : public EKPoissonSolver {
49protected:
50 std::unique_ptr<ResourceManager> m_resources_lock;
51 std::shared_ptr<LatticeWalberla> m_lattice;
53 bool m_gpu;
55
56protected:
57 void make_instance(VariantMap const &args) override {
58 // unit conversions
59 auto const agrid = get_value<double>(m_lattice->get_parameter("agrid"));
60 m_conv_permittivity = Utils::int_pow<2>(agrid);
61 auto const permittivity =
63 auto *make_new_instance = &::walberla::new_ek_poisson_fft;
64 if (m_gpu) {
65 std::vector<std::string> required_features;
66 required_features.emplace_back("CUDA");
68#ifdef ESPRESSO_CUDA
69 make_new_instance = &::walberla::new_ek_poisson_fft_cuda;
70#endif
71 }
72 m_instance = make_new_instance(m_lattice->lattice(), permittivity,
74 m_instance->setup_fft(m_gpu and
75 ::communication_environment->is_mpi_gpu_aware());
76 }
77
78public:
79 void do_construct(VariantMap const &args) override {
80 m_gpu = get_value_or<bool>(args, "gpu", false);
81 m_single_precision = get_value_or<bool>(args, "single_precision", m_gpu);
85
86 make_instance(args), m_resources_lock = std::make_unique<ResourceManager>();
87 // MPI communicator is needed to destroy the FFT plans
88 m_resources_lock->acquire_lock(::communication_environment->get_mpi_env());
89 for (auto &vtk : m_vtk_writers) {
90 vtk->attach_to_lattice(m_instance, get_lattice_to_md_units_conversion());
91 }
92 }
93
96 {"permittivity",
97 [this](Variant const &v) {
98 m_instance->set_permittivity(get_value<double>(v) *
100 },
101 [this]() {
102 return m_instance->get_permittivity() / m_conv_permittivity;
103 }},
104 {"single_precision", AutoParameter::read_only,
105 [this]() { return m_single_precision; }},
106 {"gpu", AutoParameter::read_only, [this]() { return m_gpu; }},
107 {"lattice", AutoParameter::read_only, [this]() { return m_lattice; }},
108 {"shape", AutoParameter::read_only,
109 [this]() { return m_instance->get_lattice().get_grid_dimensions(); }},
110 });
111 }
112
113 ~EKFFT() override {
114 m_lattice.reset();
115 m_instance.reset();
116 m_resources_lock.reset();
117 }
118
119 [[nodiscard]] std::shared_ptr<::walberla::PoissonSolver>
121 return m_instance;
122 }
123};
124
125} // namespace ScriptInterface::walberla
126
127#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:50
void do_construct(VariantMap const &args) override
Definition EKFFT.hpp:79
std::shared_ptr< LatticeWalberla > m_lattice
Definition EKFFT.hpp:51
void make_instance(VariantMap const &args) override
Definition EKFFT.hpp:57
std::shared_ptr<::walberla::PoissonSolver > get_instance() const noexcept override
Definition EKFFT.hpp:120
::LatticeModel::units_map get_lattice_to_md_units_conversion() const override
std::unique_ptr< CommunicationEnvironment > communication_environment
This file contains the asynchronous MPI communication.
void check_features(std::vector< std::string > const &features)
Definition CodeInfo.cpp:74
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)
std::shared_ptr< walberla::PoissonSolver > new_ek_poisson_fft_cuda(std::shared_ptr< LatticeWalberla > const &lattice, double permittivity, bool single_precision)
static constexpr const ReadOnly read_only
Recursive variant implementation.
Definition Variant.hpp:84