From 8c8e6c01afbf0dd4241ac3e0d9e4617f846045a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Tue, 10 Jan 2023 11:47:56 +0100 Subject: [PATCH] core: Reset type tracker on particle clear --- src/core/particle_node.cpp | 7 +++++++ testsuite/python/reaction_methods_interface.py | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/particle_node.cpp b/src/core/particle_node.cpp index 7aa7d53badc..cd30c597787 100644 --- a/src/core/particle_node.cpp +++ b/src/core/particle_node.cpp @@ -322,6 +322,12 @@ int get_particle_node(int p_id) { void clear_particle_node() { particle_node.clear(); } +static void clear_particle_type_map() { + for (auto &kv : ::particle_type_map) { + kv.second.clear(); + } +} + /** * @brief Calculate the largest particle id. * Traversing the @ref particle_node to find the largest particle id @@ -404,6 +410,7 @@ REGISTER_CALLBACK(mpi_remove_all_particles_local) void remove_all_particles() { mpi_call_all(mpi_remove_all_particles_local); clear_particle_node(); + clear_particle_type_map(); } void remove_particle(int p_id) { diff --git a/testsuite/python/reaction_methods_interface.py b/testsuite/python/reaction_methods_interface.py index 9ee30361c4d..d9072b734df 100644 --- a/testsuite/python/reaction_methods_interface.py +++ b/testsuite/python/reaction_methods_interface.py @@ -45,6 +45,9 @@ def check_reaction_parameters(reactions, parameters): else: self.assertEqual(getattr(reaction, key), params[key]) + def count_by_type(types): + return [self.system.number_of_particles(type=x) for x in types] + reaction_forward = { 'gamma': gamma, 'reactant_types': [5], @@ -156,11 +159,15 @@ def check_reaction_parameters(reactions, parameters): potential_energy = method.calculate_particle_insertion_potential_energy( reaction_id=0) self.assertEqual(potential_energy, 0.) + self.assertEqual(count_by_type([5, 2, 3, 0]), [1, 1, 1, 0]) method.delete_particle(p_id=p3.id) + self.assertEqual(count_by_type([5, 2, 3, 0]), [1, 1, 0, 0]) self.assertEqual(len(self.system.part), 2) - method.delete_particle(p_id=p1.id) + p1.remove() + self.assertEqual(count_by_type([5, 2, 3, 0]), [0, 1, 0, 0]) self.assertEqual(len(self.system.part), 1) self.system.part.clear() + self.assertEqual(count_by_type([5, 2, 3, 0]), [0, 0, 0, 0]) # check reaction deletion method.delete_reaction(reaction_id=0)