Program Listing for File velocity.hpp

Return to documentation for file (cosm/convergence/velocity.hpp)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include <numeric>
#include <vector>

#include "rcppsw/math/vector2.hpp"
#include "rcppsw/rcppsw.hpp"

#include "cosm/convergence/convergence_measure.hpp"

/*******************************************************************************
 * Namespaces/Decls
 ******************************************************************************/
namespace cosm::convergence {

/*******************************************************************************
 * Class Definitions
 ******************************************************************************/
class velocity final : public convergence_measure {
 public:
  explicit velocity(double epsilon) : convergence_measure(epsilon) {}

  /*
   * \brief Compute the velocity.
   */
  bool operator()(const std::vector<rmath::vector2d>& locs) {
    rmath::vector2d center =
        std::accumulate(locs.begin(), locs.end(), rmath::vector2d()) /
        locs.size();
    update_raw((center - m_prev_center).length());
    set_norm(rmath::normalize(raw_min(), raw_max(), raw()));
    m_prev_center = center;

    return update_convergence_state();
  }

 private:
  /* clang-format off */
  rmath::vector2d m_prev_center{};
  /* clang-format on */
};

} /* namespace cosm::convergence */