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 "SymplecticEuler.hpp"
28#include "VelocityVerlet.hpp"
30
34
35#include <memory>
36#include <string>
37
38namespace ScriptInterface {
39namespace Integrators {
40
43 {"time_step",
44 [this](Variant const &v) {
46 [&]() { get_system().set_time_step(get_value<double>(v)); });
47 },
48 [this]() { return get_system().get_time_step(); }},
49 {"time",
50 [&](Variant const &v) {
51 get_system().set_sim_time(get_value<double>(v));
52 },
53 [this]() { return get_system().get_sim_time(); }},
54 {"force_cap",
55 [this](Variant const &v) {
56 get_system().set_force_cap(get_value<double>(v));
57 },
58 [this]() { return get_system().get_force_cap(); }},
59 {"integrator",
60 [this](Variant const &v) {
61 auto const old_instance = m_instance;
63 new_instance->bind_system(m_system.lock());
64 new_instance->activate();
65 if (old_instance) {
66 old_instance->deactivate();
67 }
68 m_instance = new_instance;
69 },
70 [this]() {
71 switch (get_system().propagation->integ_switch) {
73 return Variant{
74 std::dynamic_pointer_cast<SteepestDescent>(m_instance)};
75#ifdef ESPRESSO_NPT
78 return Variant{
79 std::dynamic_pointer_cast<VelocityVerletIsoNPT>(m_instance)};
80#endif
81 case INTEG_METHOD_BD:
82 return Variant{
83 std::dynamic_pointer_cast<BrownianDynamics>(m_instance)};
84#ifdef ESPRESSO_STOKESIAN_DYNAMICS
85 case INTEG_METHOD_SD:
86 return Variant{
87 std::dynamic_pointer_cast<StokesianDynamics>(m_instance)};
88#endif // ESPRESSO_STOKESIAN_DYNAMICS
90 return Variant{
91 std::dynamic_pointer_cast<SymplecticEuler>(m_instance)};
92 default: {
93 auto ptr = std::dynamic_pointer_cast<VelocityVerlet>(m_instance);
94 assert(ptr.get());
95 return Variant{ptr};
96 }
97 }
98 }},
99 });
100}
101
103 auto const &params = *m_params;
104 for (auto const &key : get_parameter_insertion_order()) {
105 if (params.contains(key)) {
106 // NOLINTNEXTLINE(readability-simplify-boolean-expr)
107 if (not(key == "time_step" and
108 system.propagation->integ_switch == INTEG_METHOD_NVT and
109 system.get_time_step() == -1. and
113 }
114 }
115 }
116 auto use_default_integrator = not params.contains("integrator");
117 m_params.reset();
119 if (not context()->is_head_node()) {
120 return;
121 }
122 set_parameter("integrator",
123 context()->make_shared("Integrators::VelocityVerlet", {}));
124 }
125}
126
127} // namespace Integrators
128} // namespace ScriptInterface
@ INTEG_METHOD_NPT_ISO_AND
@ INTEG_METHOD_SD
@ INTEG_METHOD_STEEPEST_DESCENT
@ INTEG_METHOD_NVT
@ INTEG_METHOD_SYMPLECTIC_EULER
@ INTEG_METHOD_BD
@ INTEG_METHOD_NPT_ISO_MTK
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.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
static SteepestDescentParameters params
Currently active steepest descent instance.
Recursive variant implementation.
Definition Variant.hpp:84