Loading [MathJax]/extensions/TeX/AMSmath.js
ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
FluxDensityProfile.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_FLUXDENSITYPROFILE_HPP
20#define OBSERVABLES_FLUXDENSITYPROFILE_HPP
21
22#include "BoxGeometry.hpp"
23#include "Particle.hpp"
25#include "system/System.hpp"
26#include "utils_histogram.hpp"
27
28#include <utils/Histogram.hpp>
29
30#include <cstddef>
31#include <utility>
32#include <vector>
33
34namespace Observables {
36public:
38 std::vector<std::size_t> shape() const override {
39 auto const b = n_bins();
40 return {b[0], b[1], b[2], 3};
41 }
42
43 std::vector<double>
44 evaluate(boost::mpi::communicator const &comm,
45 ParticleReferenceRange const &local_particles,
46 const ParticleObservables::traits<Particle> &traits) const override {
47 using pos_type = decltype(traits.position(std::declval<Particle>()));
48 using vel_type = decltype(traits.velocity(std::declval<Particle>()));
49 auto const &box_geo = *System::get_system().box_geo;
50
51 std::vector<pos_type> local_folded_positions{};
52 std::vector<vel_type> local_velocities{};
53 local_folded_positions.reserve(local_particles.size());
54 local_velocities.reserve(local_particles.size());
55
56 for (auto const &p : local_particles) {
57 local_folded_positions.emplace_back(
58 box_geo.folded_position(traits.position(p)));
59 local_velocities.emplace_back(traits.velocity(p));
60 }
61
62 auto const [global_folded_positions, global_velocities] =
63 detail::gather(comm, local_folded_positions, local_velocities);
64
65 if (comm.rank() != 0) {
66 return {};
67 }
68
70 detail::accumulate(histogram, global_folded_positions, global_velocities);
71 histogram.normalize();
72 return histogram.get_histogram();
73 }
74};
75
76} // Namespace Observables
77
78#endif
std::vector< std::size_t > shape() const override
std::vector< double > evaluate(boost::mpi::communicator const &comm, ParticleReferenceRange const &local_particles, const ParticleObservables::traits< Particle > &traits) const override
PidProfileObservable(std::vector< int > const &ids, 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)
std::shared_ptr< BoxGeometry > box_geo
Histogram in Cartesian coordinates.
Definition Histogram.hpp:46
virtual void normalize()
Normalize histogram.
std::vector< T > get_histogram() const
Get the histogram data.
Definition Histogram.hpp:74
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange
System & get_system()