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 &lb = System::get_system().lb;
40 auto const vel_conv = lb.get_lattice_speed();
41 lb.ghost_communication_vel();
42
43 for (auto const &pos : sampling_positions) {
44 if (auto const vel = lb.get_interpolated_velocity(pos)) {
45 local_positions.emplace_back(pos);
46 local_velocities.emplace_back((*vel) * vel_conv);
47 }
48 }
49
50 auto const [global_positions, global_velocities] =
51 detail::gather(comm, local_positions, local_velocities);
52
53 if (comm.rank() != 0) {
54 return {};
55 }
56
58 detail::accumulate(histogram, global_positions, global_velocities);
59 try {
60 return detail::normalize_by_bin_size(histogram, allow_empty_bins);
61 } catch (detail::empty_bin_exception const &) {
62 throw std::runtime_error(
63 "Decrease sampling delta(s), some bins have no hit");
64 }
65}
66
67} // namespace Observables
Vector implementation and trait types for boost qvm interoperability.
std::vector< double > operator()(boost::mpi::communicator const &comm) const override
Histogram in Cartesian coordinates.
Definition Histogram.hpp:46
System & get_system()
VectorXd< 3 > Vector3d
Definition Vector.hpp:164
auto get_lattice_speed() const
Get the lattice speed (agrid/tau).