ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/observables/ProfileObservable.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#ifndef OBSERVABLES_PROFILEOBSERVABLE_HPP
20#define OBSERVABLES_PROFILEOBSERVABLE_HPP
21
22#include "Observable.hpp"
23
25
26#include <algorithm>
27#include <array>
28#include <cstddef>
29#include <stdexcept>
30#include <utility>
31#include <vector>
32
33namespace Observables {
34
35/** Cartesian profile observable */
36class ProfileObservable : virtual public Observable {
37private:
38 /** Range of the profile edges. */
39 std::array<std::pair<double, double>, 3> m_limits;
40 /** Number of bins for each coordinate. */
41 std::array<std::size_t, 3> m_n_bins;
42
43public:
44 ProfileObservable(int n_x_bins, int n_y_bins, int n_z_bins, double min_x,
45 double max_x, double min_y, double max_y, double min_z,
46 double max_z)
47 : m_limits{{std::make_pair(min_x, max_x), std::make_pair(min_y, max_y),
48 std::make_pair(min_z, max_z)}},
49 m_n_bins{{static_cast<std::size_t>(n_x_bins),
50 static_cast<std::size_t>(n_y_bins),
51 static_cast<std::size_t>(n_z_bins)}} {
52 if (max_x <= min_x)
53 throw std::runtime_error("max_x has to be > min_x");
54 if (max_y <= min_y)
55 throw std::runtime_error("max_y has to be > min_y");
56 if (max_z <= min_z)
57 throw std::runtime_error("max_z has to be > min_z");
58 if (n_x_bins <= 0)
59 throw std::domain_error("n_x_bins has to be >= 1");
60 if (n_y_bins <= 0)
61 throw std::domain_error("n_y_bins has to be >= 1");
62 if (n_z_bins <= 0)
63 throw std::domain_error("n_z_bins has to be >= 1");
64 }
65
66 std::vector<std::size_t> shape() const override {
67 return {m_n_bins[0], m_n_bins[1], m_n_bins[2]};
68 }
69
70 auto n_bins() const { return m_n_bins; }
71
72 auto limits() const { return m_limits; }
73
74 /** Calculate the bin edges for each dimension */
75 std::array<std::vector<double>, 3> edges() const {
76 std::array<std::vector<double>, 3> profile_edges = {
77 {std::vector<double>(m_n_bins[0u] + 1u),
78 std::vector<double>(m_n_bins[1u] + 1u),
79 std::vector<double>(m_n_bins[2u] + 1u)}};
80 for (auto i = 0u; i < 3u; ++i) {
81 std::ranges::copy(Utils::make_lin_space(m_limits[i].first,
82 m_limits[i].second,
83 m_n_bins[i] + 1u),
84 profile_edges[i].begin());
85 }
86 return profile_edges;
87 }
88};
89
90} // Namespace Observables
91#endif
Base class for observables.
std::array< std::vector< double >, 3 > edges() const
Calculate the bin edges for each dimension.
std::vector< std::size_t > shape() const override
ProfileObservable(int n_x_bins, int n_y_bins, int n_z_bins, double min_x, double max_x, double min_y, double max_y, double min_z, double max_z)
auto make_lin_space(T start, T stop, std::size_t number, bool endpoint=true)
Equally spaced values in interval.