1#ifndef UTOPIA_MODELS_SIMPLEFLOCKING_UTILS_HH
2#define UTOPIA_MODELS_SIMPLEFLOCKING_UTILS_HH
11#include <spdlog/spdlog.h>
19constexpr double NaN = std::numeric_limits<double>::quiet_NaN();
25template<
class RNG,
class T=
double>
27 return std::uniform_real_distribution<T>(-
M_PI, +
M_PI)(*rng);
41template<
class Container>
45 [](
auto angle){ return constrain_angle(angle); }
57template<
class Container>
60 return std::numeric_limits<double>::quiet_NaN();
63 using Vec =
typename Container::value_type;
77template<
class Container>
80 std::is_floating_point<typename Container::value_type>::value,
81 "need angles specified as floating-point types!"
84 const auto sin_sum = std::accumulate(
86 [](
auto a1,
auto a2){ return a1 + std::sin(a2); }
88 const auto cos_sum = std::accumulate(
90 [](
auto a1,
auto a2){ return a1 + std::cos(a2); }
107template<
class Container = std::vector<
double>>
110 return std::numeric_limits<double>::quiet_NaN();
128template<
class Container = std::vector<
double>>
131 return std::make_pair(
NaN,
NaN);
137 const auto r = std::min(
140 const auto std = std::sqrt(-2. * std::log(
r));
142 return std::make_pair(
mean,
std);
OutputIt transform(const Utopia::ExecPolicy policy, InputIt first1, InputIt last1, OutputIt d_first, UnaryOperation unary_op)
Apply a unary operator to a range and store the result in a new range.
Definition parallel.hh:368
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition SimpleFlocking.hh:15
double absolute_group_velocity(const Container &velocities)
Computes the absolute group velocity from a container of velocity vectors.
Definition utils.hh:58
T random_angle(const std::shared_ptr< RNG > &rng)
Returns a uniformly random angle value in [-π, +π)
Definition utils.hh:26
void constrain_angles(Container &angles)
In-place constrains all angles in a container to interval [-π, +π)
Definition utils.hh:42
auto _circular_sin_cos_sum(const Container &angles)
Compute sum of sine and cosine values from angles in a container.
Definition utils.hh:78
T constrain_angle(T angle)
Constrains an angle value to interval [-π, +π)
Definition utils.hh:32
auto circular_mean_and_std(const Container &angles)
Computes the circular mean and std from a sample of (constrained) angles.
Definition utils.hh:129
constexpr double NaN
Definition utils.hh:19
auto circular_mean(const Container &angles)
Computes the circular mean from a sample of (constrained) angles.
Definition utils.hh:108
constexpr double TAU
Definition utils.hh:18
Definition parallel.hh:235