From: Pasquale Africa Date: Sat, 1 Jul 2023 15:10:45 +0000 (+0000) Subject: Try with p::f::T X-Git-Tag: relicensing~802^2~8 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9a4c86280f353f67507628953b3d25efe27774fa;p=dealii.git Try with p::f::T --- diff --git a/source/grid/grid_tools.inst.in b/source/grid/grid_tools.inst.in index a317867e47..cfb53224b7 100644 --- a/source/grid/grid_tools.inst.in +++ b/source/grid/grid_tools.inst.in @@ -60,6 +60,27 @@ for (X : TRIANGULATIONS; deal_II_dimension : DIMENSIONS; } +// instantiate find_active_cell_around_point for +// parallel::fullydistributed::Triangulation +for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) + { +#if deal_II_dimension <= deal_II_space_dimension + namespace GridTools + \{ + parallel::fullydistributed::Triangulation< + deal_II_dimension, + deal_II_space_dimension>::active_cell_iterator + find_active_cell_around_point( + const parallel::fullydistributed::Triangulation< + deal_II_dimension, + deal_II_space_dimension> &, + const Point &p); + \} + +#endif + } + + // now also instantiate a few additional functions for // parallel::distributed::Triangulation for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 8ed8460ced..3a31e770d9 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) @@ -2179,11 +2179,12 @@ namespace Particles void ParticleHandler::register_data_attach() { - parallel::distributed::Triangulation + parallel::DistributedTriangulationBase *distributed_triangulation = - const_cast *>( - dynamic_cast - *>(&(*triangulation))); + const_cast *>( + dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &(*triangulation))); (void)distributed_triangulation; Assert( @@ -2197,7 +2198,7 @@ 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); }; @@ -2243,11 +2244,12 @@ namespace Particles ParticleHandler::notify_ready_to_unpack( const bool serialization) { - parallel::distributed::Triangulation + parallel::DistributedTriangulationBase *distributed_triangulation = - const_cast *>( - dynamic_cast - *>(&(*triangulation))); + const_cast *>( + dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &(*triangulation))); (void)distributed_triangulation; Assert( @@ -2354,7 +2356,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_04.cc b/tests/serialization/particle_handler_04.cc new file mode 100644 index 0000000000..0c35d033cb --- /dev/null +++ b/tests/serialization/particle_handler_04.cc @@ -0,0 +1,183 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2010 - 2021 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + +// check and illustrate the serialization process for ParticleHandler + +#include + +#include + +#include +#include + +#include + +#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() +{ + Triangulation basetria; + GridGenerator::hyper_cube(basetria); + basetria.refine_global(2); + + auto construction_data = + TriangulationDescription::Utilities::create_description_from_triangulation( + basetria, MPI_COMM_WORLD); + + parallel::fullydistributed::Triangulation tr(MPI_COMM_WORLD); + tr.create_triangulation(construction_data); + + MappingQ mapping(1); + + Particles::ParticleHandler particle_handler(tr, mapping); + + create_regular_particle_distribution(particle_handler, tr); + particle_handler.sort_particles_into_subdomains_and_cells(); + + for (auto particle = particle_handler.begin(); + particle != particle_handler.end(); + ++particle) + deallog << "Before serialization particle id " << particle->get_id() + << " is in cell " << particle->get_surrounding_cell(tr) + << std::endl; + + // 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 + // destructors are called + } + 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); + + // This should not produce any output + for (auto particle = particle_handler.begin(); + particle != particle_handler.end(); + ++particle) + 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 + // does not know if something was stored in the user data of the + // triangulation). + { + std::istringstream iss(oss.str()); + boost::archive::text_iarchive ia(iss, boost::archive::no_header); + + ia >> particle_handler; + tr.load("checkpoint"); + particle_handler.deserialize(); + } + + for (auto particle = particle_handler.begin(); + particle != particle_handler.end(); + ++particle) + deallog << "After serialization particle id " << particle->get_id() + << " is in cell " << particle->get_surrounding_cell(tr) + << std::endl; + + deallog << "OK" << std::endl << std::endl; +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + MPILogInitAll all; + + deallog.push("2d/2d"); + test<2, 2>(); + deallog.pop(); + deallog.push("2d/3d"); + test<2, 3>(); + deallog.pop(); + deallog.push("3d/3d"); + test<3, 3>(); + deallog.pop(); +} diff --git a/tests/serialization/particle_handler_04.with_p4est=true.mpirun=1.output b/tests/serialization/particle_handler_04.with_p4est=true.mpirun=1.output new file mode 100644 index 0000000000..a97ab8fe8f --- /dev/null +++ b/tests/serialization/particle_handler_04.with_p4est=true.mpirun=1.output @@ -0,0 +1,103 @@ + +DEAL:0:2d/2d::Before serialization particle id 0 is in cell 2.0 +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 serialization particle id 0 is in cell 2.0 +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 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 serialization particle id 0 is in cell 2.0 +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.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 serialization particle id 0 is in cell 2.0 +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::