ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
Constraints.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2010-2026 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
#include "
Constraints.hpp
"
21
#include "
BoxGeometry.hpp
"
22
#include "
Constraint.hpp
"
23
#include "
Observable_stat.hpp
"
24
#include "
ParticleRange.hpp
"
25
#include "system/System.hpp"
26
27
#include <cassert>
28
#include <memory>
29
#include <stdexcept>
30
#include <vector>
31
32
namespace
Constraints
{
33
34
void
Constraints::add
(std::shared_ptr<Constraint>
const
&constraint) {
35
auto
&
system
= get_system();
36
if
(
not
constraint->fits_in_box(
system
.box_geo->length())) {
37
throw
std::runtime_error(
"Constraint not compatible with box size."
);
38
}
39
assert
(
not
contains(constraint));
40
m_constraints.emplace_back(constraint);
41
system
.on_constraint_change();
42
}
43
void
Constraints::remove
(std::shared_ptr<Constraint>
const
&constraint) {
44
auto
&
system
= get_system();
45
assert
(contains(constraint));
46
std::erase(m_constraints, constraint);
47
system
.on_constraint_change();
48
}
49
void
Constraints::add_forces
(
ParticleRange
&particles,
double
time)
const
{
50
if
(m_constraints.empty())
51
return
;
52
53
reset_forces();
54
auto
const
&box_geo = *get_system().
box_geo
;
55
56
for
(
auto
&p : particles) {
57
auto
const
pos = box_geo.folded_position(p.pos());
58
ParticleForce
force{};
59
for
(
auto
const
&constraint : *
this
) {
60
force += constraint->force(p, pos, time);
61
}
62
63
p.force_and_torque() += force;
64
}
65
}
66
67
void
Constraints::add_energy
(
ParticleRange
const
&particles,
double
time,
68
Observable_stat
&
obs_energy
)
const
{
69
if
(m_constraints.empty())
70
return
;
71
72
auto
const
&box_geo = *get_system().
box_geo
;
73
74
for
(
auto
const
&p : particles) {
75
auto
const
pos = box_geo.folded_position(p.pos());
76
77
for
(
auto
const
&constraint : *
this
) {
78
constraint->add_energy(p, pos, time,
obs_energy
);
79
}
80
}
81
}
82
83
}
// namespace Constraints
BoxGeometry.hpp
Observable_stat.hpp
ParticleRange.hpp
Constraints::Constraints::remove
void remove(std::shared_ptr< Constraint > const &constraint)
Definition
Constraints.cpp:43
Constraints::Constraints::add_energy
void add_energy(ParticleRange const &particles, double time, Observable_stat &obs_energy) const
Definition
Constraints.cpp:67
Constraints::Constraints::add_forces
void add_forces(ParticleRange &particles, double time) const
Definition
Constraints.cpp:49
Constraints::Constraints::add
void add(std::shared_ptr< Constraint > const &constraint)
Definition
Constraints.cpp:34
Observable_stat
Observable for the pressure and energy.
Definition
Observable_stat.hpp:31
ParticleRange
A range of particles.
Definition
ParticleRange.hpp:38
System::System::box_geo
std::shared_ptr< BoxGeometry > box_geo
Definition
core/system/System.hpp:323
stream
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
Definition
common_cuda.cu:34
Constraints
Definition
core/constraints/Constraint.hpp:30
Constraint.hpp
Constraints.hpp
ParticleForce
Force information on a particle.
Definition
Particle.hpp:330
src
core
constraints
Constraints.cpp
Generated on Thu Mar 5 2026 02:40:45 for ESPResSo by
1.9.8