ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/accumulators/AccumulatorBase.hpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2010-2026 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 "
script_interface/ScriptInterface.hpp
"
23
#include "
script_interface/auto_parameters/AutoParameters.hpp
"
24
#include "
script_interface/system/System.hpp
"
25
26
#include "
core/accumulators/AccumulatorBase.hpp
"
27
#include "
core/system/System.hpp
"
28
29
#include <memory>
30
#include <stdexcept>
31
#include <string>
32
#include <vector>
33
34
namespace
ScriptInterface
{
35
namespace
Accumulators
{
36
37
class
AccumulatorBase
// LCOV_EXCL_LINE
38
:
public
AutoParameters
<AccumulatorBase> {
39
public
:
40
AccumulatorBase
() {
41
add_parameters
({{
"delta_N"
,
42
[
this
](
const
Variant
&v) {
43
auto
const
delta_N =
get_value<int>
(v);
44
context
()->
parallel_try_catch
([&]() {
45
if
(delta_N < 1) {
46
throw
std::runtime_error(
"delta_N must be >= 1"
);
47
}
48
});
49
accumulator
()->delta_N() = delta_N;
50
},
51
[
this
]() {
return
accumulator
()->delta_N(); }}});
52
}
53
Variant
do_call_method
(std::string
const
&method,
54
VariantMap
const
¶meters)
override
{
55
if
(method ==
"shape"
) {
56
auto
const
shape =
accumulator
()->shape();
57
return
std::vector<int>{shape.begin(), shape.end()};
58
}
59
if
(method ==
"reload_from_checkpoint"
) {
60
accumulator
()->set_internal_state(
61
get_value<std::string>
(parameters,
"state"
));
62
return
{};
63
}
64
return
{};
65
}
66
virtual
std::shared_ptr<const ::Accumulators::AccumulatorBase>
67
accumulator
()
const
= 0;
68
virtual
std::shared_ptr<::Accumulators::AccumulatorBase>
accumulator
() = 0;
69
70
protected
:
71
auto
get_core_system_pointer
(
VariantMap
const
¶ms)
const
{
72
auto
const
*system = &
::System::get_system
();
73
if
(params.contains(
"system"
)) {
74
system =
75
&(
get_value<std::shared_ptr<System::System const>
>(params,
"system"
)
76
->get_system());
77
}
78
return
system;
79
}
80
81
private
:
82
std::string
get_internal_state
()
const override
{
83
return
accumulator
()->get_internal_state();
84
}
85
86
void
set_internal_state
(std::string
const
&state)
override
{
87
call_method
(
"reload_from_checkpoint"
, {{
"state"
, state}});
88
}
89
};
90
91
}
// namespace Accumulators
92
}
// namespace ScriptInterface
AutoParameters.hpp
ScriptInterface.hpp
ScriptInterface::Accumulators::AccumulatorBase::AccumulatorBase
AccumulatorBase()
Definition
script_interface/accumulators/AccumulatorBase.hpp:40
ScriptInterface::Accumulators::AccumulatorBase::get_core_system_pointer
auto get_core_system_pointer(VariantMap const ¶ms) const
Definition
script_interface/accumulators/AccumulatorBase.hpp:71
ScriptInterface::Accumulators::AccumulatorBase::get_internal_state
std::string get_internal_state() const override
Definition
script_interface/accumulators/AccumulatorBase.hpp:82
ScriptInterface::Accumulators::AccumulatorBase::set_internal_state
void set_internal_state(std::string const &state) override
Definition
script_interface/accumulators/AccumulatorBase.hpp:86
ScriptInterface::Accumulators::AccumulatorBase::do_call_method
Variant do_call_method(std::string const &method, VariantMap const ¶meters) override
Definition
script_interface/accumulators/AccumulatorBase.hpp:53
ScriptInterface::Accumulators::AccumulatorBase::accumulator
virtual std::shared_ptr< const ::Accumulators::AccumulatorBase > accumulator() const =0
ScriptInterface::Accumulators::AccumulatorBase::accumulator
virtual std::shared_ptr<::Accumulators::AccumulatorBase > accumulator()=0
ScriptInterface::AutoParameters< AccumulatorBase >::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:123
ScriptInterface::AutoParameters< AccumulatorBase >::AutoParameters
AutoParameters()=default
ScriptInterface::Context::parallel_try_catch
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
ScriptInterface::ObjectHandle::call_method
Variant call_method(const std::string &name, const VariantMap ¶ms)
Call a method on the object.
Definition
ObjectHandle.cpp:55
ScriptInterface::ObjectHandle::context
Context * context() const
Responsible context.
Definition
ObjectHandle.hpp:57
AccumulatorBase.hpp
System.hpp
Accumulators
Definition
core/accumulators/AccumulatorBase.hpp:36
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:34
ScriptInterface::Variant
make_recursive_variant< ObjectRef > Variant
Possible types for parameters.
Definition
Variant.hpp:131
ScriptInterface::get_value
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
Definition
get_value.hpp:398
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
System::get_system
System & get_system()
Definition
core/system/System.cpp:143
System.hpp
src
script_interface
accumulators
AccumulatorBase.hpp
Generated on
for ESPResSo by
1.15.0