ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
DipolarScafacos.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 ESPRESSO_SCAFACOS_DIPOLES
25
26#include "Actor.hpp"
27
31
33
34#include <memory>
35#include <stdexcept>
36#include <string>
37#include <vector>
38
39namespace ScriptInterface {
40namespace Dipoles {
41
42class DipolarScafacos : public Actor<DipolarScafacos, ::DipolarScafacos> {
43 std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
44
45public:
48 {"method_name", AutoParameter::read_only,
49 [this]() { return actor()->get_method(); }},
50 {"method_params", AutoParameter::read_only,
51 [this]() {
53 }},
54 });
55 }
56
57 ~DipolarScafacos() override {
58 m_actor.reset();
59 m_mpi_env_lock.reset();
60 }
61
62 void do_construct(VariantMap const &params) override {
63 auto const method_name = get_value<std::string>(params, "method_name");
64 auto const param_list = params.at("method_params");
65 auto const prefactor = get_value<double>(params, "prefactor");
66
68 if (prefactor <= 0.) {
69 throw std::domain_error("Parameter 'prefactor' must be > 0");
70 }
74 actor()->set_prefactor(prefactor);
75 });
76 // MPI communicator is needed to destroy the FFT plans
77 m_mpi_env_lock = ::communication_environment->get_mpi_env();
78 }
79
80 Variant do_call_method(std::string const &name,
81 VariantMap const &params) override {
82 if (name == "get_available_methods") {
84 }
86 }
87};
88
89} // namespace Dipoles
90} // namespace ScriptInterface
91
92#endif // ESPRESSO_SCAFACOS_DIPOLES
ScafacosContextBase provides the public interface of the ScaFaCoS bridge.
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Common interface for magnetostatic actors.
Variant do_call_method(std::string const &name, VariantMap const &params) override
void do_construct(VariantMap const &params) override
Variant do_call_method(std::string const &name, VariantMap const &params) override
VariantMap get_parameters() const
Get current parameters.
Context * context() const
Responsible context.
std::string_view name() const
std::unique_ptr< CommunicationEnvironment > communication_environment
This file contains the asynchronous MPI communication.
std::shared_ptr< DipolarScafacos > make_dipolar_scafacos(std::string const &method, std::string const &parameters)
std::unordered_map< std::string, Variant > deserialize_parameters(std::string const &parameters)
Convert flattened parameters to a map.
Definition scafacos.cpp:153
std::string serialize_parameters(Variant const &pack)
Flatten a parameter map.
Definition scafacos.cpp:124
std::vector< std::string > available_methods()
Fetch list of methods compiled in ScaFaCoS.
Definition scafacos.cpp:50
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
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:148
static SteepestDescentParameters params
Currently active steepest descent instance.
static void sanity_check_method(std::string const &method_name)
static constexpr const ReadOnly read_only
Recursive variant implementation.
Definition Variant.hpp:84