ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
core/constraints/Constraints.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include "Constraint.hpp"
23#include "system/Leaf.hpp"
24
25#include <algorithm>
26#include <memory>
27#include <stdexcept>
28#include <vector>
29
30class ParticleRange;
31class Observable_stat;
32
33namespace Constraints {
34class Constraints : public System::Leaf<Constraints> {
35 using container_type = std::vector<std::shared_ptr<Constraint>>;
36
37public:
38 using value_type = typename container_type::value_type;
39 using iterator = typename container_type::iterator;
40 using const_iterator = typename container_type::const_iterator;
41
42private:
43 void reset_forces() const {
44 for (auto const &constraint : *this) {
45 constraint->reset_force();
46 }
47 }
48
49 container_type m_constraints;
50
51public:
52 bool contains(std::shared_ptr<Constraint> const &constraint) const noexcept {
53 return std::find(begin(), end(), constraint) != end();
54 }
55 void add(std::shared_ptr<Constraint> const &constraint);
56 void remove(std::shared_ptr<Constraint> const &constraint);
57
58 iterator begin() { return m_constraints.begin(); }
59 iterator end() { return m_constraints.end(); }
60 const_iterator begin() const { return m_constraints.begin(); }
61 const_iterator end() const { return m_constraints.end(); }
62
63 void add_forces(ParticleRange &particles, double time) const;
64
65 void add_energy(ParticleRange const &particles, double time,
66 Observable_stat &obs_energy) const;
67
68 void veto_boxl_change() const {
69 if (not m_constraints.empty()) {
70 throw std::runtime_error("The box size can not be changed because there "
71 "are active constraints.");
72 }
73 }
74
75 void on_boxl_change() const { veto_boxl_change(); }
76};
77} // namespace Constraints
bool contains(std::shared_ptr< Constraint > const &constraint) const noexcept
typename container_type::const_iterator const_iterator
typename container_type::value_type value_type
typename container_type::iterator iterator
Observable for the pressure and energy.
A range of particles.
Abstract class that represents a component of the system.