Loading [MathJax]/extensions/tex2jax.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
ICCStar.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 ELECTROSTATICS
25
28
29#include <utils/Vector.hpp>
30
35
36#include <memory>
37#include <stdexcept>
38#include <string>
39
40namespace ScriptInterface {
41namespace Coulomb {
42
43class ICCStar : public AutoParameters<ICCStar, System::Leaf> {
45 std::shared_ptr<CoreActorClass> m_actor;
46
47public:
51 [this]() { return actor()->icc_cfg.n_icc; }},
52 {"max_iterations", AutoParameter::read_only,
53 [this]() { return actor()->icc_cfg.max_iterations; }},
54 {"eps_out", AutoParameter::read_only,
55 [this]() { return actor()->icc_cfg.eps_out; }},
57 [this]() { return actor()->icc_cfg.areas; }},
58 {"epsilons", AutoParameter::read_only,
59 [this]() { return actor()->icc_cfg.epsilons; }},
60 {"sigmas", AutoParameter::read_only,
61 [this]() { return actor()->icc_cfg.sigmas; }},
62 {"convergence", AutoParameter::read_only,
63 [this]() { return actor()->icc_cfg.convergence; }},
64 {"normals", AutoParameter::read_only,
65 [this]() {
66 return make_vector_of_variants(actor()->icc_cfg.normals);
67 }},
68 {"ext_field", AutoParameter::read_only,
69 [this]() { return actor()->icc_cfg.ext_field; }},
70 {"relaxation", AutoParameter::read_only,
71 [this]() { return actor()->icc_cfg.relaxation; }},
72 {"citeration", AutoParameter::read_only,
73 [this]() { return actor()->icc_cfg.citeration; }},
74 {"first_id", AutoParameter::read_only,
75 [this]() { return actor()->icc_cfg.first_id; }},
76 });
77 }
78
79 void do_construct(VariantMap const &params) override {
80 auto const n_icc = get_value<int>(params, "n_icc");
81 // by default, sigmas are zeros
82 std::vector<double> sigmas{};
83 if (params.count("sigmas")) {
84 sigmas = get_value<std::vector<double>>(params, "sigmas");
85 } else if (n_icc >= 1) {
86 sigmas.resize(n_icc);
87 }
89 n_icc,
90 get_value<int>(params, "max_iterations"),
91 get_value<double>(params, "eps_out"),
93 get_value<std::vector<double>>(params, "epsilons"),
94 sigmas,
95 get_value<double>(params, "convergence"),
98 get_value<double>(params, "relaxation"),
99 0,
100 get_value<int>(params, "first_id"),
101 };
102 context()->parallel_try_catch([&]() {
103 m_actor = std::make_shared<CoreActorClass>(std::move(icc_parameters));
104 });
105 }
106
107 Variant do_call_method(std::string const &name,
108 VariantMap const &params) override {
109 if (name == "activate") {
110 context()->parallel_try_catch([&]() {
111 auto &system = get_system();
112 add_actor(context()->get_comm(), m_system.lock(),
113 system.coulomb.impl->extension, m_actor,
114 [&system]() { system.on_coulomb_change(); });
115 });
116 return {};
117 }
118 return {};
119 }
120
121 std::shared_ptr<CoreActorClass> actor() { return m_actor; }
122 std::shared_ptr<CoreActorClass const> actor() const { return m_actor; }
123};
124
125} // namespace Coulomb
126} // namespace ScriptInterface
127
128#endif // ELECTROSTATICS
ScriptInterface::Context decorates ScriptInterface::ObjectHandle objects with a context: a creation p...
Vector implementation and trait types for boost qvm interoperability.
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
std::shared_ptr< CoreActorClass > actor()
Definition ICCStar.hpp:121
void do_construct(VariantMap const &params) override
Definition ICCStar.hpp:79
Variant do_call_method(std::string const &name, VariantMap const &params) override
Definition ICCStar.hpp:107
std::shared_ptr< CoreActorClass const > actor() const
Definition ICCStar.hpp:122
boost::string_ref name() const
Context * context() const
Responsible context.
std::weak_ptr<::System::System > m_system
This file contains the defaults for ESPResSo.
ICC is a method that allows to take into account the influence of arbitrarily shaped dielectric inter...
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
void add_actor(boost::mpi::communicator const &comm, std::shared_ptr< System::System > const &system, std::optional< Variant > &active_actor, std::shared_ptr< T > const &actor, F &&on_actor_change)
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only
ICC data structure.
Definition icc.hpp:61