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 "ParticleRange.hpp"
24#include "system/Leaf.hpp"
25
26#include <algorithm>
27#include <memory>
28#include <stdexcept>
29#include <vector>
30
31class ParticleRange;
32class Observable_stat;
33
34namespace Constraints {
35class Constraints : public System::Leaf<Constraints> {
36 using container_type = std::vector<std::shared_ptr<Constraint>>;
37
38public:
39 using value_type = container_type::value_type;
40 using iterator = container_type::iterator;
41 using const_iterator = container_type::const_iterator;
42
43private:
44 void reset_forces() const {
45 for (auto const &constraint : *this) {
46 constraint->reset_force();
47 }
48 }
49
50 container_type m_constraints;
51
52public:
53 bool contains(std::shared_ptr<Constraint> const &constraint) const noexcept {
54 return std::ranges::find(*this, constraint) != end();
55 }
56 void add(std::shared_ptr<Constraint> const &constraint);
57 void remove(std::shared_ptr<Constraint> const &constraint);
58
59 iterator begin() { return m_constraints.begin(); }
60 iterator end() { return m_constraints.end(); }
61 const_iterator begin() const { return m_constraints.begin(); }
62 const_iterator end() const { return m_constraints.end(); }
63
64 void add_forces(ParticleRange &particles, double time) const;
65
66 void add_energy(ParticleRange const &particles, double time,
67 Observable_stat &obs_energy) const;
68
69 void veto_boxl_change() const {
70 if (not m_constraints.empty()) {
71 throw std::runtime_error("The box size can not be changed because there "
72 "are active constraints.");
73 }
74 }
75
76 void on_boxl_change() const { veto_boxl_change(); }
77};
78} // namespace Constraints
bool contains(std::shared_ptr< Constraint > const &constraint) const noexcept
container_type::const_iterator const_iterator
container_type::value_type value_type
Observable for the pressure and energy.
A range of particles.
Abstract class that represents a component of the system.