ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/observables/Observable.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016-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#ifndef OBSERVABLES_OBSERVABLE_HPP
21#define OBSERVABLES_OBSERVABLE_HPP
22
23#include <cstddef>
24#include <functional>
25#include <numeric>
26#include <vector>
27
28#include <boost/mpi/communicator.hpp>
29
30namespace Observables {
31
32/** Base class for observables.
33 *
34 * An observable extracts raw data from a system or compute a statistic based
35 * on the state of a system, and returns an array of doubles.
36 *
37 * Observables typically don't have setters or getters to access and modify
38 * their member variables, and usually only have a default constructor with no
39 * argument. Each observable class has a corresponding interface in
40 * @ref ScriptInterface::Observables, where setters and getters are defined.
41 */
43public:
44 Observable() = default;
45 virtual ~Observable() = default;
46 /** Calculate the set of values measured by the observable */
47 virtual std::vector<double>
48 operator()(boost::mpi::communicator const &comm) const = 0;
49
50 /** Size of the flat array returned by the observable */
51 std::size_t n_values() const {
52 auto const v = shape();
53 return std::accumulate(v.begin(), v.end(), 1u, std::multiplies<>());
54 }
55
56 /** Dimensions needed to reshape the flat array returned by the observable */
57 virtual std::vector<std::size_t> shape() const = 0;
58};
59
60} // Namespace Observables
61#endif
Base class for observables.
virtual std::vector< double > operator()(boost::mpi::communicator const &comm) const =0
Calculate the set of values measured by the observable.
virtual std::vector< std::size_t > shape() const =0
Dimensions needed to reshape the flat array returned by the observable.
virtual ~Observable()=default
std::size_t n_values() const
Size of the flat array returned by the observable.