Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore constraints event handling #4778

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/constraints/Constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ template <class ParticleRange, class Constraint> class Constraints {
}

void on_boxl_change() const {
if (not this->empty()) {
if (not m_constraints.empty()) {
throw std::runtime_error("The box size can not be changed because there "
"are active constraints.");
}
Expand Down
3 changes: 3 additions & 0 deletions src/core/event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "collision.hpp"
#include "communication.hpp"
#include "config/config.hpp"
#include "constraints.hpp"
#include "cuda/init.hpp"
#include "cuda/utils.hpp"
#include "electrostatics/coulomb.hpp"
Expand Down Expand Up @@ -241,6 +242,8 @@ void on_boxl_change(bool skip_method_adaption) {
system.dipoles.on_boxl_change();
#endif
}

Constraints::constraints.on_boxl_change();
}

void on_cell_structure_change() {
Expand Down
14 changes: 14 additions & 0 deletions testsuite/python/constraint_shape_based.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class ShapeBasedConstraintTest(ut.TestCase):
box_l = 30.
system = espressomd.System(box_l=3 * [box_l])

def setUp(self):
self.system.box_l = 3 * [self.box_l]

def tearDown(self):
self.system.part.clear()
self.system.constraints.clear()
Expand Down Expand Up @@ -1067,6 +1070,17 @@ def test_torus(self):
system.non_bonded_inter[0, 1].lennard_jones.set_params(
epsilon=0.0, sigma=0.0, cutoff=0.0, shift=0)

def test_exceptions(self):
system = self.system
wall = espressomd.shapes.Wall(normal=[0., 1., 0.], dist=0.)
constraint = espressomd.constraints.ShapeBasedConstraint(
shape=wall, particle_type=1)
system.constraints.add(constraint)
with self.assertRaisesRegex(RuntimeError, "there are active constraints"):
system.box_l = 0.5 * system.box_l
system.constraints.remove(constraint)
system.box_l = 0.75 * system.box_l


if __name__ == "__main__":
ut.main()
1 change: 1 addition & 0 deletions testsuite/python/integrator_steepest_descent.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def setUp(self):

def tearDown(self):
self.system.part.clear()
self.system.constraints.clear()
self.system.integrator.set_vv()

def test_relaxation_integrator(self):
Expand Down