19#ifndef CORE_CONSTRAINTS_CONSTRAINTS_HPP
20#define CORE_CONSTRAINTS_CONSTRAINTS_HPP
24#include "system/System.hpp"
33template <
class ParticleRange,
class Constra
int>
class Constraints {
34 using container_type = std::vector<std::shared_ptr<Constraint>>;
38 using iterator =
typename container_type::iterator;
42 void reset_forces()
const {
43 for (
auto const &constraint : *
this) {
44 constraint->reset_force();
48 container_type m_constraints;
51 bool contains(std::shared_ptr<Constraint>
const &constraint)
const noexcept {
52 return std::find(begin(), end(), constraint) != end();
54 void add(std::shared_ptr<Constraint>
const &constraint) {
56 auto const &box_geo = *system.box_geo;
57 if (not constraint->fits_in_box(box_geo.length())) {
58 throw std::runtime_error(
"Constraint not compatible with box size.");
60 assert(not contains(constraint));
61 m_constraints.emplace_back(constraint);
62 system.on_constraint_change();
64 void remove(std::shared_ptr<Constraint>
const &constraint) {
66 assert(contains(constraint));
67 m_constraints.erase(std::remove(begin(), end(), constraint), end());
68 system.on_constraint_change();
78 if (m_constraints.empty())
83 for (
auto &p : particles) {
86 for (
auto const &constraint : *
this) {
87 force += constraint->force(p,
pos, time);
90 p.force_and_torque() +=
force;
96 if (m_constraints.empty())
99 for (
auto const &p : particles) {
102 for (
auto const &constraint : *
this) {
103 constraint->add_energy(p,
pos, time, obs_energy);
109 if (not m_constraints.empty()) {
110 throw std::runtime_error(
"The box size can not be changed because there "
111 "are active constraints.");
__shared__ int pos[MAXDEPTH *THREADS5/WARPSIZE]
auto folded_position(Utils::Vector3d const &p) const
Calculate coordinates folded to primary simulation box.
typename container_type::const_iterator const_iterator
void add_energy(BoxGeometry const &box_geo, ParticleRange const &particles, double time, Observable_stat &obs_energy) const
typename container_type::value_type value_type
const_iterator end() const
bool contains(std::shared_ptr< Constraint > const &constraint) const noexcept
const_iterator begin() const
void add(std::shared_ptr< Constraint > const &constraint)
void veto_boxl_change() const
void on_boxl_change() const
void add_forces(BoxGeometry const &box_geo, ParticleRange &particles, double time) const
typename container_type::iterator iterator
void remove(std::shared_ptr< Constraint > const &constraint)
Observable for the pressure and energy.
Force information on a particle.