ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/observables/LBProfileObservable.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_LBPROFILEOBSERVABLE_HPP
20#define OBSERVABLES_LBPROFILEOBSERVABLE_HPP
21
22#include "ProfileObservable.hpp"
23
24#include <utils/Vector.hpp>
25
26#include <array>
27#include <cassert>
28#include <cmath>
29#include <cstddef>
30#include <stdexcept>
31#include <vector>
32
33namespace Observables {
34
36public:
37 LBProfileObservable(double sampling_delta_x, double sampling_delta_y,
38 double sampling_delta_z, double sampling_offset_x,
39 double sampling_offset_y, double sampling_offset_z,
40 int n_x_bins, int n_y_bins, int n_z_bins, double min_x,
41 double max_x, double min_y, double max_y, double min_z,
42 double max_z, bool allow_empty_bins = false)
43 : ProfileObservable(n_x_bins, n_y_bins, n_z_bins, min_x, max_x, min_y,
44 max_y, min_z, max_z),
45 sampling_delta{{sampling_delta_x, sampling_delta_y, sampling_delta_z}},
46 sampling_offset{
47 {sampling_offset_x, sampling_offset_y, sampling_offset_z}},
48 allow_empty_bins(allow_empty_bins) {
49 if (sampling_delta[0] <= 0.)
50 throw std::domain_error("sampling_delta_x has to be > 0");
51 if (sampling_delta[1] <= 0.)
52 throw std::domain_error("sampling_delta_y has to be > 0");
53 if (sampling_delta[2] <= 0.)
54 throw std::domain_error("sampling_delta_z has to be > 0");
55 if (sampling_offset[0] < 0.)
56 throw std::domain_error("sampling_offset_x has to be >= 0");
57 if (sampling_offset[1] < 0.)
58 throw std::domain_error("sampling_offset_y has to be >= 0");
59 if (sampling_offset[2] < 0.)
60 throw std::domain_error("sampling_offset_z has to be >= 0");
61 calculate_sampling_positions();
62 }
63 std::array<double, 3> sampling_delta;
64 std::array<double, 3> sampling_offset;
66 std::vector<Utils::Vector3d> sampling_positions;
68 auto const lim = limits();
69 sampling_positions.clear();
70 assert(Utils::Vector3d(sampling_delta) > Utils::Vector3d::broadcast(0.));
71 assert(Utils::Vector3d(sampling_offset) >= Utils::Vector3d::broadcast(0.));
72 const auto n_samples_x = static_cast<std::size_t>(
73 std::rint((lim[0].second - lim[0].first) / sampling_delta[0]));
74 const auto n_samples_y = static_cast<std::size_t>(
75 std::rint((lim[1].second - lim[1].first) / sampling_delta[1]));
76 const auto n_samples_z = static_cast<std::size_t>(
77 std::rint((lim[2].second - lim[2].first) / sampling_delta[2]));
78 for (std::size_t x = 0; x < n_samples_x; ++x) {
79 for (std::size_t y = 0; y < n_samples_y; ++y) {
80 for (std::size_t z = 0; z < n_samples_z; ++z) {
81 sampling_positions.push_back(Utils::Vector3d{
82 {lim[0].first + sampling_offset[0] +
83 static_cast<double>(x) * sampling_delta[0],
84 lim[1].first + sampling_offset[1] +
85 static_cast<double>(y) * sampling_delta[1],
86 lim[2].first + sampling_offset[2] +
87 static_cast<double>(z) * sampling_delta[2]}});
88 }
89 }
90 }
91 }
92};
93
94} // namespace Observables
95
96#endif
Vector implementation and trait types for boost qvm interoperability.
LBProfileObservable(double sampling_delta_x, double sampling_delta_y, double sampling_delta_z, double sampling_offset_x, double sampling_offset_y, double sampling_offset_z, 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, bool allow_empty_bins=false)
static Vector< T, N > broadcast(T const &s)
Create a vector that has all entries set to one value.
Definition Vector.hpp:110