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
20#pragma once
21
22#include "ProfileObservable.hpp"
23
24#include "SanityChecksLB.hpp"
25
26#include <utils/Vector.hpp>
27
28#include <array>
29#include <cassert>
30#include <cmath>
31#include <cstddef>
32#include <stdexcept>
33#include <vector>
34
35namespace Observables {
36
38public:
42 int n_x_bins, int n_y_bins, int n_z_bins, double min_x,
43 double max_x, double min_y, double max_y, double min_z,
44 double max_z, bool allow_empty_bins = false)
46 max_y, min_z, max_z),
48 sampling_offset{
50 allow_empty_bins(allow_empty_bins), lb_sanity_checks() {
51 if (sampling_delta[0] <= 0.)
52 throw std::domain_error("sampling_delta_x has to be > 0");
53 if (sampling_delta[1] <= 0.)
54 throw std::domain_error("sampling_delta_y has to be > 0");
55 if (sampling_delta[2] <= 0.)
56 throw std::domain_error("sampling_delta_z has to be > 0");
57 if (sampling_offset[0] < 0.)
58 throw std::domain_error("sampling_offset_x has to be >= 0");
59 if (sampling_offset[1] < 0.)
60 throw std::domain_error("sampling_offset_y has to be >= 0");
61 if (sampling_offset[2] < 0.)
62 throw std::domain_error("sampling_offset_z has to be >= 0");
63 }
64 std::array<double, 3> sampling_delta;
65 std::array<double, 3> sampling_offset;
67
68protected:
70 mutable std::vector<Utils::Vector3d> sampling_positions;
71
72public:
73 void calculate_sampling_positions(auto const &box_geo, auto const &lb) const {
75 assert(Utils::Vector3d(sampling_offset) >= Utils::Vector3d::broadcast(0.));
76
77 lb_sanity_checks = SanityChecksLB(box_geo, lb);
78 sampling_positions.clear();
79
80 auto const lb_position_checker = lb.make_lattice_position_checker(false);
81 auto const lim = limits();
82 const auto n_samples_x = static_cast<std::size_t>(
83 std::rint((lim[0].second - lim[0].first) / sampling_delta[0]));
84 const auto n_samples_y = static_cast<std::size_t>(
85 std::rint((lim[1].second - lim[1].first) / sampling_delta[1]));
86 const auto n_samples_z = static_cast<std::size_t>(
87 std::rint((lim[2].second - lim[2].first) / sampling_delta[2]));
88
89 for (std::size_t x = 0; x < n_samples_x; ++x) {
90 for (std::size_t y = 0; y < n_samples_y; ++y) {
91 for (std::size_t z = 0; z < n_samples_z; ++z) {
92 Utils::Vector3d const pos = {
93 {lim[0].first + sampling_offset[0] +
94 static_cast<double>(x) * sampling_delta[0],
95 lim[1].first + sampling_offset[1] +
96 static_cast<double>(y) * sampling_delta[1],
97 lim[2].first + sampling_offset[2] +
98 static_cast<double>(z) * sampling_delta[2]}};
99 if (lb_position_checker(pos)) {
100 sampling_positions.emplace_back(pos);
101 }
102 }
103 }
104 }
105 }
106};
107
108} // namespace Observables
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)
void calculate_sampling_positions(auto const &box_geo, auto const &lb) const
Bookkeeping of the box gometry and LB object memory address.
static DEVICE_QUALIFIER constexpr Vector< T, N > broadcast(typename Base::value_type const &value) noexcept
Create a vector that has all entries set to the same value.
Definition Vector.hpp:132
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
static bool lb_sanity_checks(LB::Solver const &lb)