ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ElectrostaticLayerCorrection.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_P3M
25
26#include "Actor.hpp"
27
28#include "CoulombP3M.hpp"
29
31
33
34#include <memory>
35#include <string>
36#include <variant>
37
38namespace ScriptInterface {
39namespace Coulomb {
40
42 : public Actor<ElectrostaticLayerCorrection,
43 ::ElectrostaticLayerCorrection> {
44
45 using BaseSolver = std::variant<std::shared_ptr<CoulombP3M>>;
46 BaseSolver m_solver;
47
49 std::visit([this](auto &solver) { solver->bind_system(m_system.lock()); },
50 m_solver);
51 }
52
53public:
56 {"maxPWerror", AutoParameter::read_only,
57 [this]() { return actor()->elc.maxPWerror; }},
58 {"gap_size", AutoParameter::read_only,
59 [this]() { return actor()->elc.gap_size; }},
60 {"far_cut", AutoParameter::read_only,
61 [this]() { return actor()->elc.far_cut; }},
62 {"neutralize", AutoParameter::read_only,
63 [this]() { return actor()->elc.neutralize; }},
64 {"delta_mid_top", AutoParameter::read_only,
65 [this]() { return actor()->elc.delta_mid_top; }},
66 {"delta_mid_bot", AutoParameter::read_only,
67 [this]() { return actor()->elc.delta_mid_bot; }},
68 {"const_pot", AutoParameter::read_only,
69 [this]() { return actor()->elc.const_pot; }},
70 {"pot_diff", AutoParameter::read_only,
71 [this]() { return actor()->elc.pot_diff; }},
73 [this]() {
74 return std::visit([](auto &solver) { return Variant{solver}; },
75 m_solver);
76 }},
77 });
78 }
79
80 void do_construct(VariantMap const &params) override {
82 auto so_ptr = get_value<ObjectRef>(params, "actor");
84 if (auto so = std::dynamic_pointer_cast<CoulombP3M>(so_ptr)) {
85 solver = so->actor();
86 m_solver = so;
87 return;
88 }
89 throw std::invalid_argument("Parameter 'actor' of type " +
90 std::string{so_ptr->name()} +
91 " isn't supported by ELC");
92 });
94 auto elc = elc_data{get_value<double>(params, "maxPWerror"),
95 get_value<double>(params, "gap_size"),
96 get_value<double>(params, "far_cut"),
97 get_value<bool>(params, "neutralize"),
98 get_value<double>(params, "delta_mid_top"),
99 get_value<double>(params, "delta_mid_bot"),
100 get_value<bool>(params, "const_pot"),
101 get_value<double>(params, "pot_diff")};
102 m_actor =
103 std::make_shared<CoreActorClass>(std::move(elc), std::move(solver));
104 });
106 }
107};
108
109} // namespace Coulomb
110} // namespace ScriptInterface
111
112#endif // ESPRESSO_P3M
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
Common interface for electrostatic actors.
Context * context() const
Responsible context.
Main system class.
ELC algorithm for long-range Coulomb interactions.
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::variant< std::shared_ptr< CoulombP3M > > BaseSolver
Definition elc.hpp:193
static constexpr const ReadOnly read_only
Recursive variant implementation.
Definition Variant.hpp:84
Parameters for the ELC method.
Definition elc.hpp:63