ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/accumulators/Correlator.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 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#ifndef SCRIPT_INTERFACE_CORRELATORS_CORRELATOR_HPP
23#define SCRIPT_INTERFACE_CORRELATORS_CORRELATOR_HPP
24
25#include "AccumulatorBase.hpp"
26
30
32
33#include <utils/Vector.hpp>
34
35#include <memory>
36#include <string>
37#include <utility>
38
39namespace ScriptInterface {
40namespace Accumulators {
41
44
45public:
47 /* Only args can be changed after construction. */
49 {{"tau_lin", m_correlator, &CoreCorr::tau_lin},
50 {"tau_max", m_correlator, &CoreCorr::tau_max},
51 {"compress1", m_correlator, &CoreCorr::compress1},
52 {"compress2", m_correlator, &CoreCorr::compress2},
53 {"corr_operation", m_correlator, &CoreCorr::correlation_operation},
54 {"args", m_correlator, &CoreCorr::set_correlation_args,
55 &CoreCorr::correlation_args},
56 {"obs1", std::as_const(m_obs1)},
57 {"obs2", std::as_const(m_obs2)}});
58 }
59
60 void do_construct(VariantMap const &args) override {
61 set_from_args(m_obs1, args, "obs1");
62 if (args.count("obs2"))
63 set_from_args(m_obs2, args, "obs2");
64 else
65 m_obs2 = m_obs1;
66
67 auto const comp1 = get_value_or<std::string>(args, "compress1", "discard2");
68 auto const comp2 = get_value_or<std::string>(args, "compress2", comp1);
69
71 m_correlator = std::make_shared<CoreCorr>(
72 get_value<int>(args, "tau_lin"), get_value<double>(args, "tau_max"),
73 get_value<int>(args, "delta_N"), comp1, comp2,
74 get_value<std::string>(args, "corr_operation"), m_obs1->observable(),
75 m_obs2->observable(),
76 get_value_or<Utils::Vector3d>(args, "args", {}));
77 });
78 }
79
80 std::shared_ptr<::Accumulators::Correlator> correlator() {
81 return m_correlator;
82 }
83
84 Variant do_call_method(std::string const &method,
85 VariantMap const &parameters) override {
86 if (method == "update") {
88 [&]() { correlator()->update(context()->get_comm()); });
89 }
90 if (method == "finalize") {
92 [&]() { correlator()->finalize(context()->get_comm()); });
93 }
94 if (method == "get_correlation") {
96 return correlator()->get_correlation();
97 }
98 return {};
99 }
100 if (method == "get_lag_times") {
101 if (ObjectHandle::context()->is_head_node()) {
102 return correlator()->get_lag_times();
103 }
104 return {};
105 }
106 if (method == "get_samples_sizes") {
107 if (ObjectHandle::context()->is_head_node()) {
108 return correlator()->get_samples_sizes();
109 }
110 return {};
111 }
112
113 return AccumulatorBase::call_method(method, parameters);
114 }
115
116 std::shared_ptr<::Accumulators::AccumulatorBase> accumulator() override {
117 return m_correlator;
118 }
119
120 std::shared_ptr<const ::Accumulators::AccumulatorBase>
121 accumulator() const override {
122 return std::static_pointer_cast<::Accumulators::AccumulatorBase>(
123 m_correlator);
124 }
125
126private:
127 /* The actual correlator */
128 std::shared_ptr<CoreCorr> m_correlator;
129
130 std::shared_ptr<Observables::Observable> m_obs1;
131 std::shared_ptr<Observables::Observable> m_obs2;
132
133 std::string get_internal_state() const override {
134 return m_correlator->get_internal_state();
135 }
136
137 void set_internal_state(std::string const &state) override {
138 m_correlator->set_internal_state(state);
139 }
140};
141
142} // namespace Accumulators
143} /* namespace ScriptInterface */
144
145#endif
Vector implementation and trait types for boost qvm interoperability.
Variant call_method(std::string const &method, VariantMap const &parameters)
std::shared_ptr<::Accumulators::Correlator > correlator()
std::shared_ptr<::Accumulators::AccumulatorBase > accumulator() override
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
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.
This module computes correlations (and other two time averages) on the fly and from files.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
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:80
void set_from_args(T &dst, VariantMap const &vals, const char *name)