ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CylindricalDensityProfile.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_CYLINDRICALDENSITYPROFILE_HPP
20#define OBSERVABLES_CYLINDRICALDENSITYPROFILE_HPP
21
23
24#include "BoxGeometry.hpp"
25#include "system/System.hpp"
26#include "utils_histogram.hpp"
27
28#include <utils/Histogram.hpp>
30
31#include <cstddef>
32#include <vector>
33
34namespace Observables {
36public:
38 std::vector<double>
39 evaluate(boost::mpi::communicator const &comm,
40 ParticleReferenceRange const &local_particles,
41 const ParticleObservables::traits<Particle> &traits) const override {
42 using pos_type = Utils::Vector3d;
43 auto const &box_geo = *System::get_system().box_geo;
44
45 std::vector<pos_type> local_folded_positions{};
46 local_folded_positions.reserve(local_particles.size());
47
48 for (auto const &p : local_particles) {
49 auto const pos = box_geo.folded_position(traits.position(p));
50 auto const pos_shifted = pos - transform_params->center();
51
52 local_folded_positions.emplace_back(
54 pos_shifted, transform_params->axis(),
55 transform_params->orientation()));
56 }
57
58 auto const global_folded_positions =
59 detail::gather(comm, local_folded_positions);
60
61 if (comm.rank() != 0) {
62 return {};
63 }
64
66
67 for (auto const &vec : global_folded_positions) {
68 for (auto const &p : vec) {
69 histogram.update(p);
70 }
71 }
72
73 histogram.normalize();
74 return histogram.get_histogram();
75 }
76};
77
78} // Namespace Observables
79
80#endif
std::vector< double > evaluate(boost::mpi::communicator const &comm, ParticleReferenceRange const &local_particles, const ParticleObservables::traits< Particle > &traits) const override
CylindricalPidProfileObservable(std::vector< int > const &ids, std::shared_ptr< Utils::CylindricalTransformationParameters > transform_params, int n_r_bins, int n_phi_bins, int n_z_bins, double min_r, double max_r, double min_phi, double max_phi, double min_z, double max_z)
std::shared_ptr< Utils::CylindricalTransformationParameters > transform_params
std::shared_ptr< BoxGeometry > box_geo
Histogram in cylindrical coordinates.
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
Convert coordinates from the Cartesian system to the cylindrical system.
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange
System & get_system()
VectorXd< 3 > Vector3d
Definition Vector.hpp:164
Vector3d transform_coordinate_cartesian_to_cylinder(Vector3d const &pos)
Coordinate transformation from Cartesian to cylindrical coordinates.