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 P3M
25
26#include "Actor.hpp"
27
28#include "CoulombP3M.hpp"
29
31
33
34#include "boost/variant.hpp"
35
36#include <memory>
37#include <string>
38
39namespace ScriptInterface {
40namespace Coulomb {
41
43 : public Actor<ElectrostaticLayerCorrection,
44 ::ElectrostaticLayerCorrection> {
45
46 using BaseSolver = boost::variant<
47#ifdef CUDA
48 std::shared_ptr<CoulombP3MGPU>,
49#endif // CUDA
50 std::shared_ptr<CoulombP3M>>;
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()->elc.maxPWerror; }},
64 {"gap_size", AutoParameter::read_only,
65 [this]() { return actor()->elc.gap_size; }},
66 {"far_cut", AutoParameter::read_only,
67 [this]() { return actor()->elc.far_cut; }},
68 {"neutralize", AutoParameter::read_only,
69 [this]() { return actor()->elc.neutralize; }},
70 {"delta_mid_top", AutoParameter::read_only,
71 [this]() { return actor()->elc.delta_mid_top; }},
72 {"delta_mid_bot", AutoParameter::read_only,
73 [this]() { return actor()->elc.delta_mid_bot; }},
74 {"const_pot", AutoParameter::read_only,
75 [this]() { return actor()->elc.const_pot; }},
76 {"pot_diff", AutoParameter::read_only,
77 [this]() { return actor()->elc.pot_diff; }},
79 [this]() {
80 return boost::apply_visitor(
81 [](auto &solver) { return Variant{solver}; }, m_solver);
82 }},
83 });
84 }
85
86 void do_construct(VariantMap const &params) override {
88 auto so_ptr = get_value<ObjectRef>(params, "actor");
90#ifdef CUDA
91 if (auto so_solver = std::dynamic_pointer_cast<CoulombP3MGPU>(so_ptr)) {
92 solver = so_solver->actor();
93 m_solver = so_solver;
94 } else
95#endif // CUDA
96 if (auto so_solver = std::dynamic_pointer_cast<CoulombP3M>(so_ptr)) {
97 solver = so_solver->actor();
98 m_solver = so_solver;
99 } else {
100 throw std::invalid_argument("Parameter 'actor' of type " +
101 so_ptr->name().to_string() +
102 " isn't supported by ELC");
103 }
104 });
105 context()->parallel_try_catch([&]() {
106 auto elc = elc_data{get_value<double>(params, "maxPWerror"),
107 get_value<double>(params, "gap_size"),
108 get_value<double>(params, "far_cut"),
109 get_value<bool>(params, "neutralize"),
110 get_value<double>(params, "delta_mid_top"),
111 get_value<double>(params, "delta_mid_bot"),
112 get_value<bool>(params, "const_pot"),
113 get_value<double>(params, "pot_diff")};
114 m_actor =
115 std::make_shared<CoreActorClass>(std::move(elc), std::move(solver));
116 });
118 }
119};
120
121} // namespace Coulomb
122} // namespace ScriptInterface
123
124#endif // 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.
This file contains the defaults for ESPResSo.
ELC algorithm for long-range Coulomb interactions.
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< CoulombP3MGPU >, std::shared_ptr< CoulombP3M > > BaseSolver
Definition elc.hpp:173
static constexpr const ReadOnly read_only
Parameters for the ELC method.
Definition elc.hpp:63