ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
TotalForce.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_TotalForce_HPP
20#define OBSERVABLES_TotalForce_HPP
21
22#include "PidObservable.hpp"
23
24#include <boost/mpi/collectives/reduce.hpp>
25
26#include <cstddef>
27#include <vector>
28
29namespace Observables {
30class TotalForce : public PidObservable {
31public:
33 std::vector<std::size_t> shape() const override { return {3}; }
34
35 std::vector<double>
36 evaluate(boost::mpi::communicator const &comm,
37 ParticleReferenceRange const &local_particles,
38 const ParticleObservables::traits<Particle> &) const override {
39 Utils::Vector3d local_force{};
40 for (auto const &p : local_particles) {
41 if (p.get().is_virtual())
42 continue;
43 local_force += p.get().force();
44 }
45
46 decltype(local_force) global_force;
47 boost::mpi::reduce(comm, local_force, global_force, std::plus<>(), 0);
48
49 return global_force.as_vector();
50 }
51};
52} // Namespace Observables
53#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 > &) const override
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange