ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CoulombScafacos.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
25
26#include "Actor.hpp"
27
31
34
35#include <iomanip>
36#include <memory>
37#include <regex>
38#include <set>
39#include <sstream>
40#include <string>
41#include <vector>
42
43namespace ScriptInterface {
44namespace Coulomb {
45
46class CoulombScafacos : public Actor<CoulombScafacos, ::CoulombScafacos> {
47 std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
48
49public:
52 {"method_name", AutoParameter::read_only,
53 [this]() { return actor()->get_method(); }},
54 {"method_params", AutoParameter::read_only,
55 [this]() {
56 auto const m_tuned_methods =
57 std::set<std::string>{"ewald", "p2nfft", "p3m"};
58 auto parameters_string = actor()->get_parameters();
59 auto const method_name = actor()->get_method();
60 auto const delegate = actor()->get_near_field_delegation();
62 auto const tuned_r_cut = actor()->get_r_cut();
63 auto const field_name = method_name + "_r_cut";
64 std::ostringstream serializer;
65 serializer << std::scientific << std::setprecision(17);
67 auto const tuned_r_cut_string = serializer.str();
68 auto const replacement =
69 "," + field_name + "," + tuned_r_cut_string;
70 if (parameters_string.find(field_name) == field_name.npos) {
72 } else {
73 auto const field_pattern =
74 std::regex("," + field_name + ",[0-9eE\\-\\+\\.]+");
75 parameters_string = std::regex_replace(
77 }
78 }
80 }},
81 });
82 }
83
84 ~CoulombScafacos() override {
85 m_actor.reset();
86 m_mpi_env_lock.reset();
87 }
88
89 void do_construct(VariantMap const &params) override {
90 auto const method_name = get_value<std::string>(params, "method_name");
91 auto const param_list = params.at("method_params");
92 auto const prefactor = get_value<double>(params, "prefactor");
93
98 actor()->set_prefactor(prefactor);
99 });
101 // MPI communicator is needed to destroy the FFT plans
102 m_mpi_env_lock = ::communication_environment->get_mpi_env();
103 }
104
105 Variant do_call_method(std::string const &name,
106 VariantMap const &params) override {
107 if (name == "set_near_field_delegation") {
108 auto const delegate = get_value<bool>(params, "delegate");
110 [&]() { actor()->set_near_field_delegation(delegate); });
111 return {};
112 }
113 if (name == "get_near_field_delegation") {
114 return actor()->get_near_field_delegation();
115 }
116 if (name == "get_available_methods") {
118 }
120 }
121};
122
123} // namespace Coulomb
124} // namespace ScriptInterface
125
126#endif // ESPRESSO_SCAFACOS
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 electrostatic 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
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< CoulombScafacos > make_coulomb_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