ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ForceDensityProfile.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_FORCEDENSITYPROFILE_HPP
20#define OBSERVABLES_FORCEDENSITYPROFILE_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 <boost/mpi/collectives/gather.hpp>
31#include <boost/serialization/vector.hpp>
32
33#include <cstddef>
34#include <utility>
35#include <vector>
36
37namespace Observables {
38
40public:
42 std::vector<std::size_t> shape() const override {
43 auto const b = n_bins();
44 return {b[0], b[1], b[2], 3};
45 }
46
47 std::vector<double>
48 evaluate(boost::mpi::communicator const &comm,
49 ParticleReferenceRange const &local_particles,
50 const ParticleObservables::traits<Particle> &traits) const override {
51 using pos_type = decltype(traits.position(std::declval<Particle>()));
52 using force_type = decltype(traits.force(std::declval<Particle>()));
53 auto const &box_geo = *System::get_system().box_geo;
54
55 std::vector<pos_type> local_folded_positions{};
56 local_folded_positions.reserve(local_particles.size());
57 std::vector<force_type> local_forces{};
58 local_forces.reserve(local_particles.size());
59
60 for (auto const &p : local_particles) {
61 local_folded_positions.emplace_back(
62 box_geo.folded_position(traits.position(p)));
63 local_forces.emplace_back(traits.force(p));
64 }
65
66 auto const [global_folded_positions, global_forces] =
67 detail::gather(comm, local_folded_positions, local_forces);
68
69 if (comm.rank() != 0) {
70 return {};
71 }
72
74 detail::accumulate(histogram, global_folded_positions, global_forces);
75 histogram.normalize();
76 return histogram.get_histogram();
77 }
78};
79
80} // Namespace Observables
81
82#endif
std::vector< double > evaluate(boost::mpi::communicator const &comm, ParticleReferenceRange const &local_particles, const ParticleObservables::traits< Particle > &traits) const override
std::vector< std::size_t > shape() 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:47
virtual void normalize()
Normalize histogram.
std::vector< T > get_histogram() const
Get the histogram data.
Definition Histogram.hpp:73
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange
System & get_system()