ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
DipolarLayerCorrection.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 DIPOLES
25
26#include "Actor.hpp"
27
28#include "DipolarDirectSum.hpp"
29#include "DipolarP3M.hpp"
30
32
34
35#include "boost/variant.hpp"
36
37#include <memory>
38#include <string>
39
40namespace ScriptInterface {
41namespace Dipoles {
42
44 : public Actor<DipolarLayerCorrection, ::DipolarLayerCorrection> {
46 using BaseSolver = boost::variant<
47#ifdef DP3M
48 std::shared_ptr<DipolarP3M>,
49#endif
50 std::shared_ptr<DipolarDSR>>;
51 BaseSolver m_solver;
52
53 void on_bind_system(::System::System &system) override {
54 boost::apply_visitor(
55 [this](auto &solver) { solver->bind_system(m_system.lock()); },
56 m_solver);
57 }
58
59public:
62 {"maxPWerror", AutoParameter::read_only,
63 [this]() { return actor()->dlc.maxPWerror; }},
64 {"gap_size", AutoParameter::read_only,
65 [this]() { return actor()->dlc.gap_size; }},
66 {"far_cut", AutoParameter::read_only,
67 [this]() { return actor()->dlc.far_cut; }},
69 [this]() {
70 return boost::apply_visitor(
71 [](auto &solver) { return Variant{solver}; }, m_solver);
72 }},
73 });
74 }
75
76 void do_construct(VariantMap const &params) override {
78 auto so_ptr = get_value<ObjectRef>(params, "actor");
80#ifdef DP3M
81 if (auto so_solver = std::dynamic_pointer_cast<DipolarP3M>(so_ptr)) {
82 solver = so_solver->actor();
83 m_solver = so_solver;
84 } else
85#endif // DP3M
86 if (auto so_solver = std::dynamic_pointer_cast<DipolarDSR>(so_ptr)) {
87 solver = so_solver->actor();
88 m_solver = so_solver;
89 } else {
90 throw std::invalid_argument("Parameter 'actor' of type " +
91 so_ptr->name().to_string() +
92 " isn't supported by DLC");
93 }
94 });
96 auto dlc = dlc_data(get_value<double>(params, "maxPWerror"),
97 get_value<double>(params, "gap_size"),
98 get_value<double>(params, "far_cut"));
99 m_actor =
100 std::make_shared<CoreActorClass>(std::move(dlc), std::move(solver));
101 });
102 }
103};
104
105} // namespace Dipoles
106} // namespace ScriptInterface
107
108#endif // DIPOLES
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Common interface for magnetostatic actors.
void on_bind_system(::System::System &system) override
void do_construct(VariantMap const &params) override
Context * context() const
Responsible context.
Main system class.
This file contains the defaults for ESPResSo.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
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:80
static SteepestDescentParameters params
Currently active steepest descent instance.
std::variant< std::shared_ptr< DipolarP3M >, std::shared_ptr< DipolarDirectSum > > BaseSolver
Definition dlc.hpp:83
static constexpr const ReadOnly read_only
Parameters for the DLC method.
Definition dlc.hpp:47