ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
IntegratorHandle.cpp
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#include "IntegratorHandle.hpp"
21
23
24#include "BrownianDynamics.hpp"
25#include "SteepestDescent.hpp"
26#include "StokesianDynamics.hpp"
27#include "VelocityVerlet.hpp"
29
33
34#include <memory>
35#include <string>
36
37namespace ScriptInterface {
38namespace Integrators {
39
42 {"time_step",
43 [this](Variant const &v) {
45 [&]() { get_system().set_time_step(get_value<double>(v)); });
46 },
47 [this]() { return get_system().get_time_step(); }},
48 {"time",
49 [&](Variant const &v) {
50 get_system().set_sim_time(get_value<double>(v));
51 },
52 [this]() { return get_system().get_sim_time(); }},
53 {"force_cap",
54 [this](Variant const &v) {
55 get_system().set_force_cap(get_value<double>(v));
56 },
57 [this]() { return get_system().get_force_cap(); }},
58 {"integrator",
59 [this](Variant const &v) {
60 auto const old_instance = m_instance;
61 m_instance = get_value<std::shared_ptr<Integrator>>(v);
62 if (old_instance) {
63 old_instance->deactivate();
64 }
65 m_instance->bind_system(m_system.lock());
66 m_instance->activate();
67 },
68 [this]() {
69 switch (get_system().propagation->integ_switch) {
71 return Variant{
72 std::dynamic_pointer_cast<SteepestDescent>(m_instance)};
73#ifdef NPT
75 return Variant{
76 std::dynamic_pointer_cast<VelocityVerletIsoNPT>(m_instance)};
77#endif
78 case INTEG_METHOD_BD:
79 return Variant{
80 std::dynamic_pointer_cast<BrownianDynamics>(m_instance)};
81#ifdef STOKESIAN_DYNAMICS
82 case INTEG_METHOD_SD:
83 return Variant{
84 std::dynamic_pointer_cast<StokesianDynamics>(m_instance)};
85#endif // STOKESIAN_DYNAMICS
86 default: {
87 auto ptr = std::dynamic_pointer_cast<VelocityVerlet>(m_instance);
88 assert(ptr.get());
89 return Variant{ptr};
90 }
91 }
92 }},
93 });
94}
95
97 auto const &params = *m_params;
98 for (auto const &key : get_parameter_insertion_order()) {
99 if (params.contains(key)) {
100 // NOLINTNEXTLINE(readability-simplify-boolean-expr)
101 if (not(key == "time_step" and
102 system.propagation->integ_switch == INTEG_METHOD_NVT and
103 system.get_time_step() == -1. and
104 is_type<double>(params.at(key)) and
105 get_value<double>(is_type<double>(params.at(key))) == -1.)) {
106 do_set_parameter(key, params.at(key));
107 }
108 }
109 }
110 auto use_default_integrator = not params.contains("integrator");
111 m_params.reset();
112 if (use_default_integrator) {
113 if (not context()->is_head_node()) {
114 return;
115 }
116 set_parameter("integrator",
117 context()->make_shared("Integrators::VelocityVerlet", {}));
118 }
119}
120
121} // namespace Integrators
122} // namespace ScriptInterface
@ INTEG_METHOD_SD
@ INTEG_METHOD_NPT_ISO
@ INTEG_METHOD_STEEPEST_DESCENT
@ INTEG_METHOD_NVT
@ INTEG_METHOD_BD
void do_set_parameter(const std::string &name, const Variant &value) final
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
void on_bind_system(::System::System &system) override
Context * context() const
Responsible context.
void set_parameter(const std::string &name, const Variant &value)
Set single parameter.
std::weak_ptr<::System::System > m_system
Main system class.
auto get_time_step() const
Get time_step.
std::shared_ptr< Propagation > propagation
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
static SteepestDescentParameters params
Currently active steepest descent instance.