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#pragma once
23
24#include "AccumulatorBase.hpp"
25
30
33
34#include <utils/Vector.hpp>
35
36#include <memory>
37#include <string>
38#include <utility>
39
40namespace ScriptInterface {
41namespace Accumulators {
42
45
46public:
48 /* Only args can be changed after construction. */
50 {{"tau_lin", m_correlator, &CoreCorr::tau_lin},
51 {"tau_max", m_correlator, &CoreCorr::tau_max},
52 {"compress1", m_correlator, &CoreCorr::compress1},
53 {"compress2", m_correlator, &CoreCorr::compress2},
54 {"corr_operation", m_correlator, &CoreCorr::correlation_operation},
55 {"args", m_correlator, &CoreCorr::set_correlation_args,
56 &CoreCorr::correlation_args},
57 {"obs1", std::as_const(m_obs1)},
58 {"obs2", std::as_const(m_obs2)}});
59 }
60
61 void do_construct(VariantMap const &args) override {
62 set_from_args(m_obs1, args, "obs1");
63 if (args.contains("obs2"))
64 set_from_args(m_obs2, args, "obs2");
65 else
66 m_obs2 = m_obs1;
67
68 auto const comp1 = get_value_or<std::string>(args, "compress1", "discard2");
69 auto const comp2 = get_value_or<std::string>(args, "compress2", comp1);
70
72 m_correlator = std::make_shared<CoreCorr>(
73 get_core_system_pointer(args), get_value<int>(args, "delta_N"),
74 get_value<int>(args, "tau_lin"), get_value<double>(args, "tau_max"),
75 comp1, comp2, get_value<std::string>(args, "corr_operation"),
76 m_obs1->observable(), m_obs2->observable(),
77 get_value_or<Utils::Vector3d>(args, "args", {}));
78 });
79 }
80
81 std::shared_ptr<::Accumulators::Correlator> correlator() {
82 return m_correlator;
83 }
84
85 Variant do_call_method(std::string const &method,
86 VariantMap const &parameters) override {
87 if (method == "update") {
89 [&]() { correlator()->update(context()->get_comm()); });
90 return {};
91 }
92 if (method == "finalize") {
94 [&]() { correlator()->finalize(context()->get_comm()); });
95 return {};
96 }
97 if (method == "get_correlation") {
99 return correlator()->get_correlation();
100 }
101 return {};
102 }
103 if (method == "get_lag_times") {
104 if (ObjectHandle::context()->is_head_node()) {
105 return correlator()->get_lag_times();
106 }
107 return {};
108 }
109 if (method == "get_samples_sizes") {
110 if (ObjectHandle::context()->is_head_node()) {
111 return correlator()->get_samples_sizes();
112 }
113 return {};
114 }
115
116 return AccumulatorBase::do_call_method(method, parameters);
117 }
118
119 std::shared_ptr<::Accumulators::AccumulatorBase> accumulator() override {
120 return m_correlator;
121 }
122
123 std::shared_ptr<const ::Accumulators::AccumulatorBase>
124 accumulator() const override {
125 return std::static_pointer_cast<::Accumulators::AccumulatorBase>(
126 m_correlator);
127 }
128
129private:
130 /* The actual correlator */
131 std::shared_ptr<CoreCorr> m_correlator;
132
133 std::shared_ptr<Observables::Observable> m_obs1;
134 std::shared_ptr<Observables::Observable> m_obs2;
135};
136
137} // namespace Accumulators
138} // namespace ScriptInterface
Vector implementation and trait types for boost qvm interoperability.
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
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: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
void set_from_args(T &dst, VariantMap const &vals, const char *name)