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 SCAFACOS_DIPOLES
25
26#include "Actor.hpp"
27
28#include "core/MpiCallbacks.hpp"
32
34
35#include <memory>
36#include <stdexcept>
37#include <string>
38#include <vector>
39
40namespace ScriptInterface {
41namespace Dipoles {
42
43class DipolarScafacos : public Actor<DipolarScafacos, ::DipolarScafacos> {
44 std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
45
46public:
49 {"method_name", AutoParameter::read_only,
50 [this]() { return actor()->get_method(); }},
51 {"method_params", AutoParameter::read_only,
52 [this]() {
54 }},
55 });
56 }
57
58 ~DipolarScafacos() override {
59 m_actor.reset();
60 m_mpi_env_lock.reset();
61 }
62
63 void do_construct(VariantMap const &params) override {
64 auto const method_name = get_value<std::string>(params, "method_name");
65 auto const param_list = params.at("method_params");
66 auto const prefactor = get_value<double>(params, "prefactor");
67
69 if (prefactor <= 0.) {
70 throw std::domain_error("Parameter 'prefactor' must be > 0");
71 }
75 actor()->set_prefactor(prefactor);
76 });
77 // MPI communicator is needed to destroy the FFT plans
78 m_mpi_env_lock = ::Communication::mpiCallbacksHandle()->share_mpi_env();
79 }
80
81 Variant do_call_method(std::string const &name,
82 VariantMap const &params) override {
83 if (name == "get_available_methods") {
85 }
87 }
88};
89
90} // namespace Dipoles
91} // namespace ScriptInterface
92
93#endif // SCAFACOS_DIPOLES
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
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.
boost::string_ref name() const
Context * context() const
Responsible context.
This file contains the defaults for ESPResSo.
This file contains the asynchronous MPI communication.
std::shared_ptr< DipolarScafacos > make_dipolar_scafacos(std::string const &method, std::string const &parameters)
std::shared_ptr< MpiCallbacks > mpiCallbacksHandle()
std::unordered_map< std::string, Variant > deserialize_parameters(std::string const &parameters)
Convert flattened parameters to a map.
Definition scafacos.cpp:150
std::string serialize_parameters(Variant const &pack)
Flatten a parameter map.
Definition scafacos.cpp:121
std::vector< std::string > available_methods()
Fetch list of methods compiled in ScaFaCoS.
Definition scafacos.cpp:49
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
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:88
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:67
static SteepestDescentParameters params
Currently active steepest descent instance.
static void sanity_check_method(std::string const &method_name)
static constexpr const ReadOnly read_only