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-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#pragma once
21
25
28
29#include <memory>
30#include <string>
31#include <vector>
32
33namespace ScriptInterface {
34namespace Accumulators {
35
36class AccumulatorBase : public AutoParameters<AccumulatorBase> {
37public:
39 add_parameters({{"delta_N",
40 [this](const Variant &v) {
41 accumulator()->delta_N() = get_value<int>(v);
42 },
43 [this]() { return accumulator()->delta_N(); }}});
44 }
45 Variant do_call_method(std::string const &method,
46 VariantMap const &parameters) override {
47 if (method == "shape") {
48 auto const shape = accumulator()->shape();
49 return std::vector<int>{shape.begin(), shape.end()};
50 }
51 if (method == "reload_from_checkpoint") {
52 accumulator()->set_internal_state(
54 return {};
55 }
56 return {};
57 }
58 virtual std::shared_ptr<const ::Accumulators::AccumulatorBase>
59 accumulator() const = 0;
60 virtual std::shared_ptr<::Accumulators::AccumulatorBase> accumulator() = 0;
61
62protected:
64 auto const *system = &::System::get_system();
65 if (params.contains("system")) {
66 system =
68 ->get_system());
69 }
70 return system;
71 }
72
73private:
74 std::string get_internal_state() const override {
75 return accumulator()->get_internal_state();
76 }
77
78 void set_internal_state(std::string const &state) override {
79 call_method("reload_from_checkpoint", {{"state", state}});
80 }
81};
82
83} // namespace Accumulators
84} // namespace ScriptInterface
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
virtual std::shared_ptr< const ::Accumulators::AccumulatorBase > accumulator() const =0
virtual std::shared_ptr<::Accumulators::AccumulatorBase > accumulator()=0
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &&params)
Variant call_method(const std::string &name, const VariantMap &params)
Call a method on the object.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
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
System & get_system()
static SteepestDescentParameters params
Currently active steepest descent instance.