Program Listing for File angular_order.hpp
↰ Return to documentation for file (cosm/convergence/angular_order.hpp
)
#pragma once
/*******************************************************************************
* Includes
******************************************************************************/
#include <vector>
#include "rcppsw/math/radians.hpp"
#include "rcppsw/rcppsw.hpp"
#include "cosm/convergence/convergence_measure.hpp"
/*******************************************************************************
* Namespaces/Decls
******************************************************************************/
namespace cosm::convergence {
/*******************************************************************************
* Class Definitions
******************************************************************************/
class angular_order final : public convergence_measure {
public:
explicit angular_order(double epsilon) : convergence_measure(epsilon) {}
bool operator()(const std::vector<rmath::radians>& headings,
RCPPSW_UNUSED size_t n_threads) {
double y = 0.0;
double x = 0.0;
#pragma omp parallel for num_threads(n_threads)
for (auto it = headings.begin(); it < headings.end(); ++it) {
y += std::sin((*it).v());
x += std::cos((*it).v());
} /* for(it..) */
update_raw(std::fabs(std::atan2(y, x)) / headings.size());
set_norm(rmath::normalize(raw_min(), raw_max(), raw()));
return update_convergence_state();
}
};
} /* namespace cosm::convergence */