ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/accumulators/MeanVarianceCalculator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2026 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "AccumulatorBase.hpp"
25
28
31
32#include <memory>
33#include <string>
34#include <utility>
35
36namespace ScriptInterface {
37namespace Accumulators {
38
40public:
41 MeanVarianceCalculator() { add_parameters({{"obs", std::as_const(m_obs)}}); }
42
43 void do_construct(VariantMap const &params) override {
44 set_from_args(m_obs, params, "obs");
45
46 if (m_obs)
48 m_accumulator =
49 std::make_shared<::Accumulators::MeanVarianceCalculator>(
51 get_value_or<int>(params, "delta_N", 1), m_obs->observable());
52 });
53 }
54
55 std::shared_ptr<::Accumulators::MeanVarianceCalculator>
57 return m_accumulator;
58 }
59
60 std::shared_ptr<const ::Accumulators::MeanVarianceCalculator>
62 return m_accumulator;
63 }
64
65 Variant do_call_method(std::string const &method,
66 VariantMap const &parameters) override {
67 if (method == "update") {
69 [&]() { mean_variance_calculator()->update(context()->get_comm()); });
70 return {};
71 }
72 if (method == "mean") {
73 if (context()->is_head_node()) {
74 return mean_variance_calculator()->mean();
75 }
76 return {};
77 }
78 if (method == "variance") {
79 if (context()->is_head_node()) {
80 return mean_variance_calculator()->variance();
81 }
82 return {};
83 }
84 if (method == "std_error") {
85 if (context()->is_head_node()) {
86 return mean_variance_calculator()->std_error();
87 }
88 return {};
89 }
91 }
92
93 std::shared_ptr<::Accumulators::AccumulatorBase> accumulator() override {
94 return m_accumulator;
95 }
96
97 std::shared_ptr<const ::Accumulators::AccumulatorBase>
98 accumulator() const override {
99 return std::static_pointer_cast<::Accumulators::AccumulatorBase>(
100 m_accumulator);
101 }
102
103private:
104 /* The actual accumulator */
105 std::shared_ptr<::Accumulators::MeanVarianceCalculator> m_accumulator;
106 std::shared_ptr<Observables::Observable> m_obs;
107};
108
109} // namespace Accumulators
110} // namespace ScriptInterface
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
std::shared_ptr<::Accumulators::MeanVarianceCalculator > mean_variance_calculator()
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
std::shared_ptr< const ::Accumulators::MeanVarianceCalculator > mean_variance_calculator() const
std::shared_ptr< const ::Accumulators::AccumulatorBase > accumulator() const override
void add_parameters(std::vector< AutoParameter > &&params)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual bool is_head_node() const =0
Context * context() const
Responsible context.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
void set_from_args(T &dst, VariantMap const &vals, const char *name)
Recursive variant implementation.
Definition Variant.hpp:84