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
29
namespace
Observables
{
30
class
TotalForce
:
public
PidObservable
{
31
public
:
32
using
PidObservable::PidObservable
;
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
Observables::PidObservable
Particle-based observable.
Definition
core/observables/PidObservable.hpp:54
Observables::PidObservable::PidObservable
PidObservable(std::vector< int > ids)
Definition
core/observables/PidObservable.hpp:64
Observables::TotalForce
Definition
TotalForce.hpp:30
Observables::TotalForce::shape
std::vector< std::size_t > shape() const override
Definition
TotalForce.hpp:33
Observables::TotalForce::evaluate
std::vector< double > evaluate(boost::mpi::communicator const &comm, ParticleReferenceRange const &local_particles, const ParticleObservables::traits< Particle > &) const override
Definition
TotalForce.hpp:36
Utils::Vector
Definition
Vector.hpp:48
Observables
Definition
BondAngles.hpp:36
Observables::ParticleReferenceRange
std::vector< std::reference_wrapper< Particle const > > ParticleReferenceRange
Definition
core/observables/PidObservable.hpp:47
PidObservable.hpp
ParticleObservables::traits
Definition
properties.hpp:27
src
core
observables
TotalForce.hpp
Generated on Fri Nov 22 2024 02:13:54 for ESPResSo by
1.9.8