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
22
#include "
script_interface/ScriptInterface.hpp
"
23
24
#include "
BrownianDynamics.hpp
"
25
#include "
SteepestDescent.hpp
"
26
#include "
StokesianDynamics.hpp
"
27
#include "
SymplecticEuler.hpp
"
28
#include "
VelocityVerlet.hpp
"
29
#include "
VelocityVerletIsoNPT.hpp
"
30
31
#include "
core/PropagationMode.hpp
"
32
#include "
core/integrators/Propagation.hpp
"
33
#include "
core/system/System.hpp
"
34
35
#include <memory>
36
#include <string>
37
38
namespace
ScriptInterface
{
39
namespace
Integrators {
40
41
IntegratorHandle::IntegratorHandle
() {
42
add_parameters
({
43
{
"time_step"
,
44
[
this
](
Variant
const
&v) {
45
context
()->
parallel_try_catch
(
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;
62
auto
const
new_instance
=
get_value<std::shared_ptr<Integrator>
>(v);
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) {
72
case
INTEG_METHOD_STEEPEST_DESCENT
:
73
return
Variant
{
74
std::dynamic_pointer_cast<SteepestDescent>(m_instance)};
75
#ifdef ESPRESSO_NPT
76
case
INTEG_METHOD_NPT_ISO_AND
:
77
case
INTEG_METHOD_NPT_ISO_MTK
:
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
89
case
INTEG_METHOD_SYMPLECTIC_EULER
:
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
102
void
IntegratorHandle::on_bind_system
(
::System::System
&
system
) {
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
110
is_type<double>
(
params
.at(
key
))
and
111
get_value<double>
(
is_type<double>
(
params
.at(
key
))) == -1.)) {
112
do_set_parameter
(
key
,
params
.at(
key
));
113
}
114
}
115
}
116
auto
use_default_integrator
=
not
params
.contains(
"integrator"
);
117
m_params.reset();
118
if
(
use_default_integrator
) {
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
BrownianDynamics.hpp
IntegratorHandle.hpp
PropagationMode.hpp
INTEG_METHOD_NPT_ISO_AND
@ INTEG_METHOD_NPT_ISO_AND
Definition
PropagationMode.hpp:48
INTEG_METHOD_SD
@ INTEG_METHOD_SD
Definition
PropagationMode.hpp:52
INTEG_METHOD_STEEPEST_DESCENT
@ INTEG_METHOD_STEEPEST_DESCENT
Definition
PropagationMode.hpp:50
INTEG_METHOD_NVT
@ INTEG_METHOD_NVT
Definition
PropagationMode.hpp:47
INTEG_METHOD_SYMPLECTIC_EULER
@ INTEG_METHOD_SYMPLECTIC_EULER
Definition
PropagationMode.hpp:53
INTEG_METHOD_BD
@ INTEG_METHOD_BD
Definition
PropagationMode.hpp:51
INTEG_METHOD_NPT_ISO_MTK
@ INTEG_METHOD_NPT_ISO_MTK
Definition
PropagationMode.hpp:49
Propagation.hpp
ScriptInterface.hpp
SteepestDescent.hpp
StokesianDynamics.hpp
SymplecticEuler.hpp
VelocityVerletIsoNPT.hpp
VelocityVerlet.hpp
ScriptInterface::AutoParameters< IntegratorHandle, System::Leaf >::do_set_parameter
void do_set_parameter(const std::string &name, const Variant &value) final
Definition
AutoParameters.hpp:154
ScriptInterface::AutoParameters< IntegratorHandle, System::Leaf >::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:123
ScriptInterface::AutoParameters< IntegratorHandle, System::Leaf >::get_parameter_insertion_order
auto const & get_parameter_insertion_order() const
Definition
AutoParameters.hpp:137
ScriptInterface::Context::parallel_try_catch
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
ScriptInterface::Integrators::IntegratorHandle::on_bind_system
void on_bind_system(::System::System &system) override
Definition
IntegratorHandle.cpp:102
ScriptInterface::Integrators::IntegratorHandle::IntegratorHandle
IntegratorHandle()
Definition
IntegratorHandle.cpp:41
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
ScriptInterface::ObjectHandle::set_parameter
void set_parameter(const std::string &name, const Variant &value)
Set single parameter.
Definition
ObjectHandle.cpp:44
ScriptInterface::System::Leaf::get_system
auto const & get_system() const
Definition
script_interface/system/Leaf.hpp:53
ScriptInterface::System::Leaf::m_system
std::weak_ptr<::System::System > m_system
Definition
script_interface/system/Leaf.hpp:51
System::System
Main system class.
Definition
core/system/System.hpp:79
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
System.hpp
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:33
params
static SteepestDescentParameters params
Currently active steepest descent instance.
Definition
steepest_descent.cpp:44
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
src
script_interface
integrators
IntegratorHandle.cpp
Generated on Mon Dec 8 2025 02:32:29 for ESPResSo by
1.9.8