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
:
public
AutoParameters
<AccumulatorBase> {
38
public
:
39
AccumulatorBase
() {
40
add_parameters
({{
"delta_N"
,
41
[
this
](
const
Variant
&v) {
42
auto
const
delta_N =
get_value<int>
(v);
43
context
()->
parallel_try_catch
([&]() {
44
if
(delta_N < 1) {
45
throw
std::runtime_error(
"delta_N must be >= 1"
);
46
}
47
});
48
accumulator
()->delta_N() = delta_N;
49
},
50
[
this
]() {
return
accumulator
()->delta_N(); }}});
51
}
52
Variant
do_call_method
(std::string
const
&
method
,
53
VariantMap
const
&
parameters
)
override
{
54
if
(
method
==
"shape"
) {
55
auto
const
shape =
accumulator
()->shape();
56
return
std::vector<int>{shape.begin(), shape.end()};
57
}
58
if
(
method
==
"reload_from_checkpoint"
) {
59
accumulator
()->set_internal_state(
60
get_value<std::string>
(
parameters
,
"state"
));
61
return
{};
62
}
63
return
{};
64
}
65
virtual
std::shared_ptr<const ::Accumulators::AccumulatorBase>
66
accumulator
()
const
= 0;
67
virtual
std::shared_ptr<::Accumulators::AccumulatorBase>
accumulator
() = 0;
68
69
protected
:
70
auto
get_core_system_pointer
(
VariantMap
const
¶ms)
const
{
71
auto
const
*
system
= &
::System::get_system
();
72
if
(params.contains(
"system"
)) {
73
system
=
74
&(
get_value<std::shared_ptr<System::System const>
>(params,
"system"
)
75
->get_system());
76
}
77
return
system
;
78
}
79
80
private
:
81
std::string
get_internal_state
()
const override
{
82
return
accumulator
()->get_internal_state();
83
}
84
85
void
set_internal_state
(std::string
const
&
state
)
override
{
86
call_method
(
"reload_from_checkpoint"
, {{
"state"
,
state
}});
87
}
88
};
89
90
}
// namespace Accumulators
91
}
// namespace ScriptInterface
AutoParameters.hpp
ScriptInterface.hpp
ScriptInterface::Accumulators::AccumulatorBase
Definition
script_interface/accumulators/AccumulatorBase.hpp:37
ScriptInterface::Accumulators::AccumulatorBase::AccumulatorBase
AccumulatorBase()
Definition
script_interface/accumulators/AccumulatorBase.hpp:39
ScriptInterface::Accumulators::AccumulatorBase::get_core_system_pointer
auto get_core_system_pointer(VariantMap const ¶ms) const
Definition
script_interface/accumulators/AccumulatorBase.hpp:70
ScriptInterface::Accumulators::AccumulatorBase::get_internal_state
std::string get_internal_state() const override
Definition
script_interface/accumulators/AccumulatorBase.hpp:81
ScriptInterface::Accumulators::AccumulatorBase::set_internal_state
void set_internal_state(std::string const &state) override
Definition
script_interface/accumulators/AccumulatorBase.hpp:85
ScriptInterface::Accumulators::AccumulatorBase::do_call_method
Variant do_call_method(std::string const &method, VariantMap const ¶meters) override
Definition
script_interface/accumulators/AccumulatorBase.hpp:52
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
Bind parameters in the script interface.
Definition
AutoParameters.hpp:94
ScriptInterface::AutoParameters< AccumulatorBase >::add_parameters
void add_parameters(std::vector< AutoParameter > &¶ms)
Definition
AutoParameters.hpp:123
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
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
AccumulatorBase.hpp
System.hpp
Accumulators
Definition
core/accumulators/AccumulatorBase.hpp:36
ScriptInterface
Definition
script_interface/accumulators/AccumulatorBase.hpp:34
ScriptInterface::VariantMap
std::unordered_map< std::string, Variant > VariantMap
Definition
Variant.hpp:133
System::get_system
System & get_system()
Definition
core/system/System.cpp:142
System.hpp
ScriptInterface::impl::recursive_variant
Recursive variant implementation.
Definition
Variant.hpp:84
src
script_interface
accumulators
AccumulatorBase.hpp
Generated on Tue Aug 18 2026 01:33:37 for ESPResSo by
1.9.8