Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
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;
62 new_instance->bind_system(m_system.lock());
63 new_instance->activate();
64 if (old_instance) {
65 old_instance->deactivate();
66 }
67 m_instance = new_instance;
68 },
69 [this]() {
70 switch (get_system().propagation->integ_switch) {
72 return Variant{
73 std::dynamic_pointer_cast<SteepestDescent>(m_instance)};
74#ifdef NPT
76 return Variant{
77 std::dynamic_pointer_cast<VelocityVerletIsoNPT>(m_instance)};
78#endif
79 case INTEG_METHOD_BD:
80 return Variant{
81 std::dynamic_pointer_cast<BrownianDynamics>(m_instance)};
82#ifdef STOKESIAN_DYNAMICS
83 case INTEG_METHOD_SD:
84 return Variant{
85 std::dynamic_pointer_cast<StokesianDynamics>(m_instance)};
86#endif // STOKESIAN_DYNAMICS
87 default: {
88 auto ptr = std::dynamic_pointer_cast<VelocityVerlet>(m_instance);
89 assert(ptr.get());
90 return Variant{ptr};
91 }
92 }
93 }},
94 });
95}
96
98 auto const &params = *m_params;
99 for (auto const &key : get_parameter_insertion_order()) {
100 if (params.contains(key)) {
101 // NOLINTNEXTLINE(readability-simplify-boolean-expr)
102 if (not(key == "time_step" and
103 system.propagation->integ_switch == INTEG_METHOD_NVT and
104 system.get_time_step() == -1. and
108 }
109 }
110 }
111 auto use_default_integrator = not params.contains("integrator");
112 m_params.reset();
114 if (not context()->is_head_node()) {
115 return;
116 }
117 set_parameter("integrator",
118 context()->make_shared("Integrators::VelocityVerlet", {}));
119 }
120}
121
122} // namespace Integrators
123} // 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.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
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.