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 <boost/range/algorithm.hpp>
27
28#include <array>
29#include <cstddef>
30#include <stdexcept>
31#include <utility>
32#include <vector>
33
34namespace Observables {
35
36/** Cartesian profile observable */
37class ProfileObservable : virtual public Observable {
38private:
39 /** Range of the profile edges. */
40 std::array<std::pair<double, double>, 3> m_limits;
41 /** Number of bins for each coordinate. */
42 std::array<std::size_t, 3> m_n_bins;
43
44public:
45 ProfileObservable(int n_x_bins, int n_y_bins, int n_z_bins, double min_x,
46 double max_x, double min_y, double max_y, double min_z,
47 double max_z)
48 : m_limits{{std::make_pair(min_x, max_x), std::make_pair(min_y, max_y),
49 std::make_pair(min_z, max_z)}},
50 m_n_bins{{static_cast<std::size_t>(n_x_bins),
51 static_cast<std::size_t>(n_y_bins),
52 static_cast<std::size_t>(n_z_bins)}} {
53 if (max_x <= min_x)
54 throw std::runtime_error("max_x has to be > min_x");
55 if (max_y <= min_y)
56 throw std::runtime_error("max_y has to be > min_y");
57 if (max_z <= min_z)
58 throw std::runtime_error("max_z has to be > min_z");
59 if (n_x_bins <= 0)
60 throw std::domain_error("n_x_bins has to be >= 1");
61 if (n_y_bins <= 0)
62 throw std::domain_error("n_y_bins has to be >= 1");
63 if (n_z_bins <= 0)
64 throw std::domain_error("n_z_bins has to be >= 1");
65 }
66
67 std::vector<std::size_t> shape() const override {
68 return {m_n_bins[0], m_n_bins[1], m_n_bins[2]};
69 }
70
71 auto n_bins() const { return m_n_bins; }
72
73 auto limits() const { return m_limits; }
74
75 /** Calculate the bin edges for each dimension */
76 std::array<std::vector<double>, 3> edges() const {
77 std::array<std::vector<double>, 3> profile_edges = {
78 {std::vector<double>(m_n_bins[0] + 1),
79 std::vector<double>(m_n_bins[1] + 1),
80 std::vector<double>(m_n_bins[2] + 1)}};
81 boost::copy(Utils::make_lin_space(m_limits[0].first, m_limits[0].second,
82 m_n_bins[0] + 1),
83 profile_edges[0].begin());
84 boost::copy(Utils::make_lin_space(m_limits[1].first, m_limits[1].second,
85 m_n_bins[1] + 1),
86 profile_edges[1].begin());
87 boost::copy(Utils::make_lin_space(m_limits[2].first, m_limits[2].second,
88 m_n_bins[2] + 1),
89 profile_edges[2].begin());
90 return profile_edges;
91 }
92};
93
94} // Namespace Observables
95#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.