From fbbcc5f7ef50ccb4c2c53ca2a2b9df390f59958d Mon Sep 17 00:00:00 2001 From: Bruno Date: Wed, 13 Jan 2021 12:48:50 -0500 Subject: [PATCH] Use particles with fully distributed tria --- source/particles/particle_handler.cc | 14 +- .../particle_handler_fully_distributed_01.cc | 147 ++++++++++++++++++ ...ndler_fully_distributed_01.mpirun=2.output | 24 +++ 3 files changed, 178 insertions(+), 7 deletions(-) create mode 100644 tests/particles/particle_handler_fully_distributed_01.cc create mode 100644 tests/particles/particle_handler_fully_distributed_01.mpirun=2.output diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index 93bbed5d12..0f5c9b7ed4 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -490,7 +490,7 @@ namespace Particles AssertDimension(ids.size(), positions.size()); const auto tria = - dynamic_cast *>( + dynamic_cast *>( &(*triangulation)); const auto comm = (tria != nullptr ? tria->get_communicator() : MPI_COMM_WORLD); @@ -1799,8 +1799,8 @@ namespace Particles switch (status) { - case parallel::distributed::Triangulation::CELL_PERSIST: - case parallel::distributed::Triangulation::CELL_REFINE: + case parallel::TriangulationBase::CELL_PERSIST: + case parallel::TriangulationBase::CELL_REFINE: // If the cell persist or is refined store all particles of the // current cell. { @@ -1828,7 +1828,7 @@ namespace Particles } break; - case parallel::distributed::Triangulation::CELL_COARSEN: + case parallel::TriangulationBase::CELL_COARSEN: // If this cell is the parent of children that will be coarsened, // collect the particles of all children. { @@ -1892,7 +1892,7 @@ namespace Particles switch (status) { - case parallel::distributed::Triangulation::CELL_PERSIST: + case parallel::TriangulationBase::CELL_PERSIST: { auto position_hint = particles.end(); for (const auto &particle : loaded_particles_on_cell) @@ -1912,7 +1912,7 @@ namespace Particles } break; - case parallel::distributed::Triangulation::CELL_COARSEN: + case parallel::TriangulationBase::CELL_COARSEN: { typename std::multimap>::iterator @@ -1938,7 +1938,7 @@ namespace Particles } break; - case parallel::distributed::Triangulation::CELL_REFINE: + case parallel::TriangulationBase::CELL_REFINE: { std::vector< typename std::multimap +#include + +#include + +#include +#include + +#include + +#include "../tests.h" + +template +void +test() +{ + { + const MPI_Comm comm = MPI_COMM_WORLD; + + // create a distributed triangulation + parallel::distributed::Triangulation tria_pdt(comm); + + GridGenerator::hyper_cube(tria_pdt); + tria_pdt.refine_global(2); + MappingQ mapping(1); + + + // create a fully distributed triangulation + parallel::fullydistributed::Triangulation tria_pft(comm); + + // extract relevant information from distributed triangulation + auto construction_data = TriangulationDescription::Utilities:: + create_description_from_triangulation(tria_pdt, comm); + + // actually create triangulation + tria_pft.create_triangulation(construction_data); + + // both processes create a particle handler, + // but only the first creates particles + Particles::ParticleHandler particle_handler(tria_pft, + mapping); + + if (Utilities::MPI::this_mpi_process(tria_pft.get_communicator()) == 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( + &tria_pft, 2, 0); + typename Triangulation::active_cell_iterator cell2( + &tria_pft, 2, 0); + + particle_handler.insert_particle(particle1, cell1); + particle_handler.insert_particle(particle2, cell2); + + for (const auto &particle : particle_handler) + deallog << "Before sort particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tria_pft) + << " on process " + << Utilities::MPI::this_mpi_process( + tria_pft.get_communicator()) + << std::flush << std::endl; + } + + + + particle_handler.sort_particles_into_subdomains_and_cells(); + + for (const auto &particle : particle_handler) + deallog << "After sort particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tria_pft) + << " on process " + << Utilities::MPI::this_mpi_process(tria_pft.get_communicator()) + << std::flush << std::endl; + + // Move all points up by 0.5. This will change cell for particle 1 and will + // move particle 2 out of the domain. Note that we need to change the + // coordinate dim-1 despite having a spacedim point. + Point shift; + shift(dim - 1) = 0.5; + for (auto &particle : particle_handler) + particle.set_location(particle.get_location() + shift); + + particle_handler.sort_particles_into_subdomains_and_cells(); + for (const auto &particle : particle_handler) + deallog << "After shift particle id " << particle.get_id() + << " is in cell " << particle.get_surrounding_cell(tria_pft) + << " on process " + << Utilities::MPI::this_mpi_process(tria_pft.get_communicator()) + << std::flush << std::endl; + } + + deallog << "OK" << 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/particles/particle_handler_fully_distributed_01.mpirun=2.output b/tests/particles/particle_handler_fully_distributed_01.mpirun=2.output new file mode 100644 index 0000000000..01df526a8d --- /dev/null +++ b/tests/particles/particle_handler_fully_distributed_01.mpirun=2.output @@ -0,0 +1,24 @@ + +DEAL:0:2d/2d::Before sort particle id 0 is in cell 2.0 on process 0 +DEAL:0:2d/2d::Before sort particle id 1 is in cell 2.0 on process 0 +DEAL:0:2d/2d::After sort particle id 0 is in cell 2.0 on process 0 +DEAL:0:2d/2d::OK +DEAL:0:2d/3d::Before sort particle id 0 is in cell 2.0 on process 0 +DEAL:0:2d/3d::Before sort particle id 1 is in cell 2.0 on process 0 +DEAL:0:2d/3d::After sort particle id 0 is in cell 2.0 on process 0 +DEAL:0:2d/3d::OK +DEAL:0:3d/3d::Before sort particle id 0 is in cell 2.0 on process 0 +DEAL:0:3d/3d::Before sort particle id 1 is in cell 2.0 on process 0 +DEAL:0:3d/3d::After sort particle id 0 is in cell 2.0 on process 0 +DEAL:0:3d/3d::OK + +DEAL:1:2d/2d::After sort particle id 1 is in cell 2.12 on process 1 +DEAL:1:2d/2d::After shift particle id 0 is in cell 2.8 on process 1 +DEAL:1:2d/2d::OK +DEAL:1:2d/3d::After sort particle id 1 is in cell 2.12 on process 1 +DEAL:1:2d/3d::After shift particle id 0 is in cell 2.8 on process 1 +DEAL:1:2d/3d::OK +DEAL:1:3d/3d::After sort particle id 1 is in cell 2.56 on process 1 +DEAL:1:3d/3d::After shift particle id 0 is in cell 2.32 on process 1 +DEAL:1:3d/3d::OK + -- 2.39.5