From 931a9b82225489d9540309a12356ef26bb463fae Mon Sep 17 00:00:00 2001 From: Menno Fraters Date: Sat, 25 Jan 2020 00:24:23 -0800 Subject: [PATCH] add test with 3 mpi processes and 2 particles. --- tests/particles/generators_10.cc | 136 ++++++++++++++++++ ...erators_10.with_p4est=true.mpirun=3.output | 22 +++ 2 files changed, 158 insertions(+) create mode 100644 tests/particles/generators_10.cc create mode 100644 tests/particles/generators_10.with_p4est=true.mpirun=3.output diff --git a/tests/particles/generators_10.cc b/tests/particles/generators_10.cc new file mode 100644 index 0000000000..df871f6d74 --- /dev/null +++ b/tests/particles/generators_10.cc @@ -0,0 +1,136 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 2018 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 the particle generation using the +// Particles::Generator::probabilistic_locations function +// using different probability distributions. In particular +// check that for a non-random cell selection the domain +// has the expected number of particles according when there +// are more mpi ranks than particles. + +#include + +#include + +#include + +#include +#include + +#include +#include + +#include +#include + +#include "../tests.h" + +template +void +test(Function &probability_density_function) +{ + { + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + + GridGenerator::hyper_cube(tr); + tr.refine_global(1); + + MappingQ mapping(1); + + Particles::ParticleHandler particle_handler(tr, mapping); + + Particles::Generators::probabilistic_locations( + tr, probability_density_function, false, 2, particle_handler, mapping); + + if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) + { + deallog << "Locally owned active cells: " + << tr.n_locally_owned_active_cells() << std::endl; + + deallog << "Global particles: " << particle_handler.n_global_particles() + << std::endl; + + for (const auto &cell : tr.active_cell_iterators()) + { + if (cell->is_locally_owned()) + { + deallog << "Cell " << cell << " has " + << particle_handler.n_particles_in_cell(cell) + << " particles." << std::endl; + } + } + + for (const auto &particle : particle_handler) + { + deallog << "Particle index " << particle.get_id() << " is in cell " + << particle.get_surrounding_cell(tr) << std::endl; + deallog << "Particle location: " << particle.get_location() + << std::endl; + } + } + } + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + initlog(); + + { + deallog.push("2d/2d"); + Functions::ConstantFunction<2> probability_density_function(1.0); + test<2, 2>(probability_density_function); + deallog.pop(); + } + { + deallog.push("2d/3d"); + Functions::ConstantFunction<3> probability_density_function(1.0); + test<2, 3>(probability_density_function); + } + { + deallog.pop(); + deallog.push("3d/3d"); + Functions::ConstantFunction<3> probability_density_function(1.0); + test<3, 3>(probability_density_function); + deallog.pop(); + } + + { + deallog.push("2d/2d"); + Functions::Q1WedgeFunction<2> probability_density_function; + test<2, 2>(probability_density_function); + deallog.pop(); + } + { + deallog.push("2d/3d"); + Functions::Q1WedgeFunction<3> probability_density_function; + test<2, 3>(probability_density_function); + } + { + deallog.pop(); + deallog.push("3d/3d"); + Functions::Q1WedgeFunction<3> probability_density_function; + test<3, 3>(probability_density_function); + deallog.pop(); + } +} diff --git a/tests/particles/generators_10.with_p4est=true.mpirun=3.output b/tests/particles/generators_10.with_p4est=true.mpirun=3.output new file mode 100644 index 0000000000..fdac561e5d --- /dev/null +++ b/tests/particles/generators_10.with_p4est=true.mpirun=3.output @@ -0,0 +1,22 @@ + +DEAL:2d/2d::OK +DEAL:2d/3d::OK +DEAL:3d/3d::OK +DEAL:2d/2d::OK +DEAL:2d/3d::OK +DEAL:3d/3d::OK +EAL:2d/3d::Locally owned active cells: 0 +DEAL:2d/3d::Global particles: 2 +DEAL:2d/3d::OK +DEAL:3d/3d::Locally owned active cells: 0 +DEAL:3d/3d::Global particles: 2 +DEAL:3d/3d::OK +DEAL:2d/2d::Locally owned active cells: 0 +DEAL:2d/2d::Global particles: 2 +DEAL:2d/2d::OK +DEAL:2d/3d::Locally owned active cells: 0 +DEAL:2d/3d::Global particles: 2 +DEAL:2d/3d::OK +DEAL:3d/3d::Locally owned active cells: 0 +DEAL:3d/3d::Global particles: 2 +DEAL:3d/3d::OK -- 2.39.5