ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LBVelocityProfile.cpp
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#include "LBVelocityProfile.hpp"
20
21#include "system/System.hpp"
22#include "utils_histogram.hpp"
23
24#include <utils/Histogram.hpp>
25#include <utils/Vector.hpp>
26
27#include <stdexcept>
28#include <vector>
29
30namespace Observables {
31
32std::vector<double>
33LBVelocityProfile::operator()(boost::mpi::communicator const &comm) const {
34 using vel_type = Utils::Vector3d;
35
36 decltype(sampling_positions) local_positions{};
37 std::vector<vel_type> local_velocities{};
38
39 auto const &lb = System::get_system().lb;
40 auto const vel_conv = lb.get_lattice_speed();
41
42 for (auto const &pos : sampling_positions) {
43 if (auto const vel = lb.get_interpolated_velocity(pos)) {
44 local_positions.emplace_back(pos);
45 local_velocities.emplace_back((*vel) * vel_conv);
46 }
47 }
48
49 auto const [global_positions, global_velocities] =
50 detail::gather(comm, local_positions, local_velocities);
51
52 if (comm.rank() != 0) {
53 return {};
54 }
55
57 detail::accumulate(histogram, global_positions, global_velocities);
58 try {
59 return detail::normalize_by_bin_size(histogram, allow_empty_bins);
60 } catch (detail::empty_bin_exception const &) {
61 throw std::runtime_error(
62 "Decrease sampling delta(s), some bins have no hit");
63 }
64}
65
66} // namespace Observables
Vector implementation and trait types for boost qvm interoperability.
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
std::vector< double > operator()(boost::mpi::communicator const &comm) const override
Histogram in Cartesian coordinates.
Definition Histogram.hpp:47
System & get_system()
VectorXd< 3 > Vector3d
Definition Vector.hpp:157
auto get_lattice_speed() const
Get the lattice speed (agrid/tau).