ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
DensityProfile.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_DENSITYPROFILE_HPP
20#define OBSERVABLES_DENSITYPROFILE_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 <utility>
31#include <vector>
32
33namespace Observables {
34
36public:
38
39 std::vector<double>
40 evaluate(boost::mpi::communicator const &comm,
41 ParticleReferenceRange const &local_particles,
42 const ParticleObservables::traits<Particle> &traits) const override {
43 using pos_type = decltype(traits.position(std::declval<Particle>()));
44 auto const &box_geo = *System::get_system().box_geo;
45
46 std::vector<pos_type> local_folded_positions{};
47 local_folded_positions.reserve(local_particles.size());
48
49 for (auto const &p : local_particles) {
50 local_folded_positions.emplace_back(
51 box_geo.folded_position(traits.position(p)));
52 }
53
54 auto const global_folded_positions =
55 detail::gather(comm, local_folded_positions);
56
57 if (comm.rank() != 0) {
58 return {};
59 }
60
62
63 for (auto const &vec : global_folded_positions) {
64 for (auto const &p : vec) {
65 histogram.update(p);
66 }
67 }
68
69 histogram.normalize();
70 return histogram.get_histogram();
71 }
72};
73} // Namespace Observables
74
75#endif
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
void update(std::span< const U > pos)
Add data to the histogram.
Definition Histogram.hpp:93
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange
System & get_system()