19#ifndef SRC_PARTICLE_OBSERVABLES_ALGORITHMS_HPP
20#define SRC_PARTICLE_OBSERVABLES_ALGORITHMS_HPP
37 template <
class Particle>
auto operator()(
Particle const &p)
const {
42template <
class ValueOp,
class WeightOp>
struct WeightedSum {
43 template <
class ParticleRange>
45 using particle_type =
typename ParticleRange::value_type;
46 using value_op_type =
decltype(ValueOp{}(std::declval<particle_type>()));
47 using weight_op_type =
decltype(WeightOp{}(std::declval<particle_type>()));
48 auto func = [](
auto const &sum,
auto const &p) {
49 auto const w = WeightOp{}(p);
50 return std::make_pair(sum.first + ValueOp{}(p)*w, sum.second + w);
53 return std::accumulate(std::begin(particles), std::end(particles),
54 std::pair<value_op_type, weight_op_type>(), func);
60 template <
class ParticleRange>
62 auto const ws = detail::WeightedSum<ValueOp, WeightOp>()(particles);
64 return std::make_pair(ws.first, ws.second);
67 template <
typename T>
auto operator()(T
const &acc, T
const &val)
const {
68 return std::make_pair(acc.first + val.first, acc.second + val.second);
72template <
class ValueOp>
struct Sum {
73 template <
class ParticleRange>
75 return std::make_pair(
76 detail::WeightedSum<ValueOp, detail::One>()(particles).first, 0.0);
79 template <
typename T>
auto operator()(T
const &acc, T
const &val)
const {
85 template <
class ParticleRange>
87 auto const ws = detail::WeightedSum<ValueOp, WeightOp>()(particles);
88 return std::make_pair((ws.second) ? ws.first / ws.second : ws.first,
92 template <
typename T>
auto operator()(T
const &acc, T
const &val)
const {
93 auto const value = acc.first * acc.second + val.first * val.second;
94 auto const weight = acc.second + val.second;
100 template <
class ParticleRange>
105 template <
typename T>
auto operator()(T
const &acc, T
const &val)
const {
110template <
class ValueOp>
struct Map {
111 template <
class ParticleRange>
113 using particle_type =
typename ParticleRange::value_type;
114 using value_op_type =
decltype(ValueOp{}(std::declval<particle_type>()));
115 std::vector<value_op_type> res;
116 std::transform(std::begin(particles), std::end(particles),
117 std::back_inserter(res),
118 [](
auto const &p) {
return ValueOp{}(p); });
static double weight(int type, double r_cut, double k, double r)
auto operator()(ParticleRange const &particles) const
auto operator()(T const &acc, T const &val) const
auto operator()(ParticleRange const &particles) const
auto operator()(ParticleRange const &particles) const
auto operator()(T const &acc, T const &val) const
auto operator()(ParticleRange const &particles) const
auto operator()(T const &acc, T const &val) const
auto operator()(ParticleRange const &particles) const
auto operator()(T const &acc, T const &val) const
Struct holding all information for one particle.