From 381e96849b73fe832a255f0f42edbfda4d1a9a50 Mon Sep 17 00:00:00 2001 From: Bruno Blais Date: Sat, 1 Jul 2023 12:54:10 -0400 Subject: [PATCH] Clean test --- source/distributed/fully_distributed_tria.cc | 3 +- source/particles/particle_handler.cc | 35 +++--- tests/serialization/particle_handler_03.cc | 2 +- tests/serialization/particle_handler_04.cc | 115 +++++------------- .../particle_handler_04.mpirun=1.output | 6 + 5 files changed, 54 insertions(+), 107 deletions(-) diff --git a/source/distributed/fully_distributed_tria.cc b/source/distributed/fully_distributed_tria.cc index 9f42320873..38b488c20b 100644 --- a/source/distributed/fully_distributed_tria.cc +++ b/source/distributed/fully_distributed_tria.cc @@ -456,7 +456,8 @@ namespace parallel void Triangulation::save(const std::string &filename) const { #ifdef DEAL_II_WITH_MPI - //AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() == 0, + // AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() == + // 0, // ExcNotImplemented()); Assert( diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 6a9e0fa354..a0a4c16814 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -77,7 +77,7 @@ namespace Particles template ParticleHandler::ParticleHandler( const Triangulation &triangulation, - const Mapping &mapping, + const Mapping & mapping, const unsigned int n_properties) : triangulation(&triangulation, typeid(*this).name()) , mapping(&mapping, typeid(*this).name()) @@ -117,7 +117,7 @@ namespace Particles void ParticleHandler::initialize( const Triangulation &new_triangulation, - const Mapping &new_mapping, + const Mapping & new_mapping, const unsigned int n_properties) { clear(); @@ -577,7 +577,7 @@ namespace Particles template typename ParticleHandler::particle_iterator ParticleHandler::insert_particle( - const Particle &particle, + const Particle & particle, const typename Triangulation::active_cell_iterator &cell) { return insert_particle(particle.get_location(), @@ -623,7 +623,7 @@ namespace Particles template typename ParticleHandler::particle_iterator ParticleHandler::insert_particle( - const void *&data, + const void *& data, const typename Triangulation::active_cell_iterator &cell) { Assert(triangulation != nullptr, ExcInternalError()); @@ -648,8 +648,8 @@ namespace Particles template typename ParticleHandler::particle_iterator ParticleHandler::insert_particle( - const Point &position, - const Point &reference_position, + const Point & position, + const Point & reference_position, const types::particle_index particle_index, const typename Triangulation::active_cell_iterator &cell, const ArrayView &properties) @@ -764,8 +764,8 @@ namespace Particles ParticleHandler::insert_global_particles( const std::vector> &positions, const std::vector>> - &global_bounding_boxes, - const std::vector> &properties, + & global_bounding_boxes, + const std::vector> & properties, const std::vector &ids) { if (!properties.empty()) @@ -1190,7 +1190,7 @@ namespace Particles compare_particle_association( const unsigned int a, const unsigned int b, - const Tensor<1, dim> &particle_direction, + const Tensor<1, dim> & particle_direction, const std::vector> ¢er_directions) { const double scalar_product_a = center_directions[a] * particle_direction; @@ -1663,7 +1663,7 @@ namespace Particles const std::map< types::subdomain_id, std::vector::active_cell_iterator>> - &send_cells, + & send_cells, const bool build_cache) { Assert(triangulation != nullptr, ExcInternalError()); @@ -2067,7 +2067,7 @@ namespace Particles template void ParticleHandler::register_additional_store_load_functions( - const std::function &size_callb, + const std::function & size_callb, const std::function &store_callb, const std::function &load_callb) @@ -2197,14 +2197,13 @@ namespace Particles const auto callback_function = [this]( const typename Triangulation::cell_iterator - &cell_iterator, + & cell_iterator, const typename Triangulation::CellStatus cell_status) { return this->pack_callback(cell_iterator, cell_status); }; handle = distributed_triangulation->register_data_attach( callback_function, /*returns_variable_size_data=*/true); - } @@ -2261,7 +2260,7 @@ namespace Particles // First prepare container for insertion clear(); -//#ifdef DEAL_II_WITH_P4EST + //#ifdef DEAL_II_WITH_P4EST // If we are resuming from a checkpoint, we first have to register the // store function again, to set the triangulation to the same state as // before the serialization. Only afterwards we know how to deserialize the @@ -2289,9 +2288,9 @@ namespace Particles handle = numbers::invalid_unsigned_int; update_cached_numbers(); } -//#else -// (void)serialization; -//#endif + //#else + // (void)serialization; + //#endif } @@ -2355,7 +2354,7 @@ namespace Particles template void ParticleHandler::unpack_callback( - const typename Triangulation::cell_iterator &cell, + const typename Triangulation::cell_iterator & cell, const typename Triangulation::CellStatus status, const boost::iterator_range::const_iterator> &data_range) { diff --git a/tests/serialization/particle_handler_03.cc b/tests/serialization/particle_handler_03.cc index 18584f3c00..403c37448f 100644 --- a/tests/serialization/particle_handler_03.cc +++ b/tests/serialization/particle_handler_03.cc @@ -30,7 +30,7 @@ template void create_regular_particle_distribution( Particles::ParticleHandler &particle_handler, - const Triangulation &tr, + const Triangulation & tr, const unsigned int particles_per_direction = 3) { for (unsigned int i = 0; i < particles_per_direction; ++i) diff --git a/tests/serialization/particle_handler_04.cc b/tests/serialization/particle_handler_04.cc index 3f035603f7..359bb7c5f1 100644 --- a/tests/serialization/particle_handler_04.cc +++ b/tests/serialization/particle_handler_04.cc @@ -27,65 +27,11 @@ #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() { + // Generate fulllydistributed triangulation from serial triangulation Triangulation basetria; GridGenerator::hyper_cube(basetria); basetria.refine_global(2); @@ -99,33 +45,29 @@ 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); + 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(); @@ -137,8 +79,8 @@ test() particle_handler.prepare_for_serialization(); - // save data to archive - std::ofstream oss("data.particles"); + // save additional particle data to archive + std::ostringstream oss; { boost::archive::text_oarchive oa(oss, boost::archive::no_header); @@ -148,13 +90,11 @@ test() // archive and stream closed when // destructors are called } - oss.close(); - //deallog << oss.str() << std::endl; + deallog << oss.str() << std::endl; // Now remove all information in tr and particle_handler, // this is like creating new objects after a restart tr.clear(); - //GridGenerator::hyper_cube(tr); particle_handler.clear(); particle_handler.initialize(tr, mapping); @@ -166,12 +106,12 @@ 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 deserialization of - // the particle handler has to happen before the triangulation (otherwise it + // 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 // triangulation). { - std::ifstream iss("data.particles"); + std::istringstream iss(oss.str()); boost::archive::text_iarchive ia(iss, boost::archive::no_header); ia >> particle_handler; @@ -179,7 +119,8 @@ test() particle_handler.deserialize(); } - deallog << "After deserialization global number of particles is: " << particle_handler.n_global_particles() << std::endl; + 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 db908b1579..7c8ec417b6 100644 --- a/tests/serialization/particle_handler_04.mpirun=1.output +++ b/tests/serialization/particle_handler_04.mpirun=1.output @@ -1,6 +1,8 @@ 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::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 @@ -8,6 +10,8 @@ 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::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 @@ -15,6 +19,8 @@ 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::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 -- 2.39.5