From 3e62ef3cb20fef60a4bc31cd9b63b29af257e790 Mon Sep 17 00:00:00 2001 From: Pasquale Africa Date: Mon, 3 Jul 2023 02:40:55 +0000 Subject: [PATCH] Make particle handler serialization test consistent --- tests/serialization/particle_handler_04.cc | 96 +++++++++++------- .../particle_handler_04.mpirun=1.output | 99 ++++++++++++++++--- 2 files changed, 150 insertions(+), 45 deletions(-) diff --git a/tests/serialization/particle_handler_04.cc b/tests/serialization/particle_handler_04.cc index deb5b72a68..706a5d9892 100644 --- a/tests/serialization/particle_handler_04.cc +++ b/tests/serialization/particle_handler_04.cc @@ -15,10 +15,8 @@ // check and illustrate the serialization process for ParticleHandler -// when the triangulation is fully distributed. -// In this case, find_active_cell_around_point() currently cannot be used to -// locate the cells around the particles and so we use a more naive insertion -// mechanism. +// for fully distributed triangulations + #include #include @@ -30,6 +28,61 @@ #include "serialization.h" +template +void +create_regular_particle_distribution( + Particles::ParticleHandler &particle_handler, + const parallel::fullydistributed::Triangulation &tr, + const unsigned int particles_per_direction = 3) +{ + for (unsigned int i = 0; i < particles_per_direction; ++i) + for (unsigned int j = 0; j < particles_per_direction; ++j) + { + Point position; + Point reference_position; + unsigned int id = i * particles_per_direction + j; + + position[0] = static_cast(i) / + static_cast(particles_per_direction - 1); + position[1] = static_cast(j) / + static_cast(particles_per_direction - 1); + + if (dim > 2) + for (unsigned int k = 0; k < particles_per_direction; ++k) + { + position[2] = static_cast(j) / + static_cast(particles_per_direction - 1); + id = i * particles_per_direction * particles_per_direction + + j * particles_per_direction + k; + Particles::Particle particle(position, + reference_position, + id); + + typename parallel::fullydistributed:: + Triangulation::active_cell_iterator cell = + GridTools::find_active_cell_around_point( + tr, particle.get_location()); + + particle_handler.insert_particle(particle, cell); + } + else + { + Particles::Particle particle(position, + reference_position, + id); + + typename parallel::fullydistributed::Triangulation:: + active_cell_iterator cell = + GridTools::find_active_cell_around_point( + tr, particle.get_location()); + + particle_handler.insert_particle(particle, cell); + } + } +} + + + template void test() @@ -48,29 +101,9 @@ test() MappingQ mapping(1); - // Create ParticleHandler and insert two particles Particles::ParticleHandler particle_handler(tr, mapping); - std::vector> position(2); - std::vector> reference_position(2); - - for (unsigned int i = 0; i < dim; ++i) - { - position[0](i) = 0.125; - position[1](i) = 0.525; - } - - Particles::Particle particle1(position[0], - reference_position[0], - 0); - Particles::Particle particle2(position[1], - reference_position[1], - 1); - - typename Triangulation::active_cell_iterator cell1(&tr, 2, 0); - typename Triangulation::active_cell_iterator cell2(&tr, 2, 0); - particle_handler.insert_particle(particle1, cell1); - particle_handler.insert_particle(particle2, cell2); + create_regular_particle_distribution(particle_handler, tr); particle_handler.sort_particles_into_subdomains_and_cells(); for (auto particle = particle_handler.begin(); @@ -80,14 +113,13 @@ test() << " is in cell " << particle->get_surrounding_cell(tr) << std::endl; - particle_handler.prepare_for_serialization(); - - // save additional particle data to archive + // save data to archive std::ostringstream oss; { boost::archive::text_oarchive oa(oss, boost::archive::no_header); oa << particle_handler; + particle_handler.prepare_for_serialization(); tr.save("checkpoint"); // archive and stream closed when @@ -109,9 +141,9 @@ test() deallog << "In between particle id " << particle->get_id() << " is in cell " << particle->get_surrounding_cell(tr) << std::endl; - // verify correctness of the serialization. Note that the boost - // archive of the ParticleHandler has to be read before the triangulation - // (otherwise it does not know if something was stored in the user data of the + // verify correctness of the serialization. Note that the deserialization of + // the particle handler has to happen before the triangulation (otherwise it + // does not know if something was stored in the user data of the // triangulation). { std::istringstream iss(oss.str()); @@ -122,8 +154,6 @@ test() particle_handler.deserialize(); } - deallog << "After deserialization global number of particles is: " - << particle_handler.n_global_particles() << std::endl; for (auto particle = particle_handler.begin(); particle != particle_handler.end(); ++particle) diff --git a/tests/serialization/particle_handler_04.mpirun=1.output b/tests/serialization/particle_handler_04.mpirun=1.output index 7c8ec417b6..a97ab8fe8f 100644 --- a/tests/serialization/particle_handler_04.mpirun=1.output +++ b/tests/serialization/particle_handler_04.mpirun=1.output @@ -1,28 +1,103 @@ DEAL:0:2d/2d::Before serialization particle id 0 is in cell 2.0 -DEAL:0:2d/2d::Before serialization particle id 1 is in cell 2.12 -DEAL:0:2d/2d::0 0 2 1 2 +DEAL:0:2d/2d::Before serialization particle id 3 is in cell 2.1 +DEAL:0:2d/2d::Before serialization particle id 1 is in cell 2.2 +DEAL:0:2d/2d::Before serialization particle id 4 is in cell 2.3 +DEAL:0:2d/2d::Before serialization particle id 6 is in cell 2.5 +DEAL:0:2d/2d::Before serialization particle id 7 is in cell 2.7 +DEAL:0:2d/2d::Before serialization particle id 2 is in cell 2.10 +DEAL:0:2d/2d::Before serialization particle id 5 is in cell 2.11 +DEAL:0:2d/2d::Before serialization particle id 8 is in cell 2.15 +DEAL:0:2d/2d::0 0 9 1 9 -DEAL:0:2d/2d::After deserialization global number of particles is: 2 DEAL:0:2d/2d::After serialization particle id 0 is in cell 2.0 -DEAL:0:2d/2d::After serialization particle id 1 is in cell 2.12 +DEAL:0:2d/2d::After serialization particle id 3 is in cell 2.1 +DEAL:0:2d/2d::After serialization particle id 1 is in cell 2.2 +DEAL:0:2d/2d::After serialization particle id 4 is in cell 2.3 +DEAL:0:2d/2d::After serialization particle id 6 is in cell 2.5 +DEAL:0:2d/2d::After serialization particle id 7 is in cell 2.7 +DEAL:0:2d/2d::After serialization particle id 2 is in cell 2.10 +DEAL:0:2d/2d::After serialization particle id 5 is in cell 2.11 +DEAL:0:2d/2d::After serialization particle id 8 is in cell 2.15 DEAL:0:2d/2d::OK DEAL:0:2d/2d:: DEAL:0:2d/3d::Before serialization particle id 0 is in cell 2.0 -DEAL:0:2d/3d::Before serialization particle id 1 is in cell 2.12 -DEAL:0:2d/3d::0 0 2 1 2 +DEAL:0:2d/3d::Before serialization particle id 3 is in cell 2.1 +DEAL:0:2d/3d::Before serialization particle id 1 is in cell 2.2 +DEAL:0:2d/3d::Before serialization particle id 4 is in cell 2.3 +DEAL:0:2d/3d::Before serialization particle id 6 is in cell 2.5 +DEAL:0:2d/3d::Before serialization particle id 7 is in cell 2.7 +DEAL:0:2d/3d::Before serialization particle id 2 is in cell 2.10 +DEAL:0:2d/3d::Before serialization particle id 5 is in cell 2.11 +DEAL:0:2d/3d::Before serialization particle id 8 is in cell 2.15 +DEAL:0:2d/3d::0 0 9 1 9 -DEAL:0:2d/3d::After deserialization global number of particles is: 2 DEAL:0:2d/3d::After serialization particle id 0 is in cell 2.0 -DEAL:0:2d/3d::After serialization particle id 1 is in cell 2.12 +DEAL:0:2d/3d::After serialization particle id 3 is in cell 2.1 +DEAL:0:2d/3d::After serialization particle id 1 is in cell 2.2 +DEAL:0:2d/3d::After serialization particle id 4 is in cell 2.3 +DEAL:0:2d/3d::After serialization particle id 6 is in cell 2.5 +DEAL:0:2d/3d::After serialization particle id 7 is in cell 2.7 +DEAL:0:2d/3d::After serialization particle id 2 is in cell 2.10 +DEAL:0:2d/3d::After serialization particle id 5 is in cell 2.11 +DEAL:0:2d/3d::After serialization particle id 8 is in cell 2.15 DEAL:0:2d/3d::OK DEAL:0:2d/3d:: DEAL:0:3d/3d::Before serialization particle id 0 is in cell 2.0 -DEAL:0:3d/3d::Before serialization particle id 1 is in cell 2.56 -DEAL:0:3d/3d::0 0 2 1 2 +DEAL:0:3d/3d::Before serialization particle id 1 is in cell 2.0 +DEAL:0:3d/3d::Before serialization particle id 2 is in cell 2.0 +DEAL:0:3d/3d::Before serialization particle id 9 is in cell 2.1 +DEAL:0:3d/3d::Before serialization particle id 10 is in cell 2.1 +DEAL:0:3d/3d::Before serialization particle id 11 is in cell 2.1 +DEAL:0:3d/3d::Before serialization particle id 3 is in cell 2.6 +DEAL:0:3d/3d::Before serialization particle id 4 is in cell 2.6 +DEAL:0:3d/3d::Before serialization particle id 5 is in cell 2.6 +DEAL:0:3d/3d::Before serialization particle id 12 is in cell 2.7 +DEAL:0:3d/3d::Before serialization particle id 13 is in cell 2.7 +DEAL:0:3d/3d::Before serialization particle id 14 is in cell 2.7 +DEAL:0:3d/3d::Before serialization particle id 18 is in cell 2.9 +DEAL:0:3d/3d::Before serialization particle id 19 is in cell 2.9 +DEAL:0:3d/3d::Before serialization particle id 20 is in cell 2.9 +DEAL:0:3d/3d::Before serialization particle id 21 is in cell 2.15 +DEAL:0:3d/3d::Before serialization particle id 22 is in cell 2.15 +DEAL:0:3d/3d::Before serialization particle id 23 is in cell 2.15 +DEAL:0:3d/3d::Before serialization particle id 6 is in cell 2.54 +DEAL:0:3d/3d::Before serialization particle id 7 is in cell 2.54 +DEAL:0:3d/3d::Before serialization particle id 8 is in cell 2.54 +DEAL:0:3d/3d::Before serialization particle id 15 is in cell 2.55 +DEAL:0:3d/3d::Before serialization particle id 16 is in cell 2.55 +DEAL:0:3d/3d::Before serialization particle id 17 is in cell 2.55 +DEAL:0:3d/3d::Before serialization particle id 24 is in cell 2.63 +DEAL:0:3d/3d::Before serialization particle id 25 is in cell 2.63 +DEAL:0:3d/3d::Before serialization particle id 26 is in cell 2.63 +DEAL:0:3d/3d::0 0 27 3 27 -DEAL:0:3d/3d::After deserialization global number of particles is: 2 DEAL:0:3d/3d::After serialization particle id 0 is in cell 2.0 -DEAL:0:3d/3d::After serialization particle id 1 is in cell 2.56 +DEAL:0:3d/3d::After serialization particle id 1 is in cell 2.0 +DEAL:0:3d/3d::After serialization particle id 2 is in cell 2.0 +DEAL:0:3d/3d::After serialization particle id 9 is in cell 2.1 +DEAL:0:3d/3d::After serialization particle id 10 is in cell 2.1 +DEAL:0:3d/3d::After serialization particle id 11 is in cell 2.1 +DEAL:0:3d/3d::After serialization particle id 3 is in cell 2.6 +DEAL:0:3d/3d::After serialization particle id 4 is in cell 2.6 +DEAL:0:3d/3d::After serialization particle id 5 is in cell 2.6 +DEAL:0:3d/3d::After serialization particle id 12 is in cell 2.7 +DEAL:0:3d/3d::After serialization particle id 13 is in cell 2.7 +DEAL:0:3d/3d::After serialization particle id 14 is in cell 2.7 +DEAL:0:3d/3d::After serialization particle id 18 is in cell 2.9 +DEAL:0:3d/3d::After serialization particle id 19 is in cell 2.9 +DEAL:0:3d/3d::After serialization particle id 20 is in cell 2.9 +DEAL:0:3d/3d::After serialization particle id 21 is in cell 2.15 +DEAL:0:3d/3d::After serialization particle id 22 is in cell 2.15 +DEAL:0:3d/3d::After serialization particle id 23 is in cell 2.15 +DEAL:0:3d/3d::After serialization particle id 6 is in cell 2.54 +DEAL:0:3d/3d::After serialization particle id 7 is in cell 2.54 +DEAL:0:3d/3d::After serialization particle id 8 is in cell 2.54 +DEAL:0:3d/3d::After serialization particle id 15 is in cell 2.55 +DEAL:0:3d/3d::After serialization particle id 16 is in cell 2.55 +DEAL:0:3d/3d::After serialization particle id 17 is in cell 2.55 +DEAL:0:3d/3d::After serialization particle id 24 is in cell 2.63 +DEAL:0:3d/3d::After serialization particle id 25 is in cell 2.63 +DEAL:0:3d/3d::After serialization particle id 26 is in cell 2.63 DEAL:0:3d/3d::OK DEAL:0:3d/3d:: -- 2.39.5