--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2017 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.
+//
+// ---------------------------------------------------------------------
+
+
+
+// like particle_handler_05, but check that the properties of particles are
+// correctly transferred during grid
+// refinement/coarsening. Note that this in particular tests for a bug, where
+// references to the property pool where lost during particle transfer.
+
+#include <deal.II/distributed/tria.h>
+
+#include <deal.II/fe/mapping_q.h>
+
+#include <deal.II/grid/grid_generator.h>
+#include <deal.II/grid/grid_tools.h>
+
+#include <deal.II/particles/particle_handler.h>
+
+#include "../tests.h"
+
+template <int dim, int spacedim>
+void
+create_regular_particle_distribution(
+ Particles::ParticleHandler<dim, spacedim> & particle_handler,
+ const parallel::distributed::Triangulation<dim, spacedim> &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<spacedim> position;
+ Point<dim> reference_position;
+ unsigned int id = i * particles_per_direction + j;
+
+ position[0] = static_cast<double>(i) /
+ static_cast<double>(particles_per_direction - 1);
+ position[1] = static_cast<double>(j) /
+ static_cast<double>(particles_per_direction - 1);
+
+ if (dim > 2)
+ for (unsigned int k = 0; k < particles_per_direction; ++k)
+ {
+ position[2] = static_cast<double>(j) /
+ static_cast<double>(particles_per_direction - 1);
+ id = i * particles_per_direction * particles_per_direction +
+ j * particles_per_direction + k;
+ Particles::Particle<dim, spacedim> particle(position,
+ reference_position,
+ id);
+
+ typename parallel::distributed::Triangulation<dim, spacedim>::
+ active_cell_iterator cell =
+ GridTools::find_active_cell_around_point(
+ tr, particle.get_location());
+
+ Particles::ParticleIterator<dim, spacedim> pit =
+ particle_handler.insert_particle(particle, cell);
+
+ for (unsigned int i = 0; i < spacedim; ++i)
+ pit->get_properties()[i] = pit->get_location()[i];
+ }
+ else
+ {
+ Particles::Particle<dim, spacedim> particle(position,
+ reference_position,
+ id);
+
+ typename parallel::distributed::Triangulation<dim, spacedim>::
+ active_cell_iterator cell =
+ GridTools::find_active_cell_around_point(
+ tr, particle.get_location());
+
+ Particles::ParticleIterator<dim, spacedim> pit =
+ particle_handler.insert_particle(particle, cell);
+
+ for (unsigned int i = 0; i < spacedim; ++i)
+ pit->get_properties()[i] = pit->get_location()[i];
+ }
+ }
+}
+
+template <int dim, int spacedim>
+void
+test()
+{
+ {
+ parallel::distributed::Triangulation<dim, spacedim> tr(MPI_COMM_WORLD);
+
+ GridGenerator::hyper_cube(tr);
+ MappingQ<dim, spacedim> mapping(1);
+
+ const unsigned int n_properties = spacedim;
+ Particles::ParticleHandler<dim, spacedim> particle_handler(tr,
+ mapping,
+ n_properties);
+
+ // TODO: Move this into the Particle handler class. Unfortunately, there are
+ // some interactions with the SolutionTransfer class that prevent us from
+ // doing this at the moment. When doing this, check that transferring a
+ // solution and particles during the same refinement is possible (in
+ // particular that the order of serialization/deserialization is preserved).
+ tr.signals.pre_distributed_refinement.connect(std::bind(
+ &Particles::ParticleHandler<dim,
+ spacedim>::register_store_callback_function,
+ &particle_handler));
+
+ tr.signals.post_distributed_refinement.connect(std::bind(
+ &Particles::ParticleHandler<dim,
+ spacedim>::register_load_callback_function,
+ &particle_handler,
+ false));
+
+ create_regular_particle_distribution(particle_handler, tr);
+
+ for (auto particle = particle_handler.begin();
+ particle != particle_handler.end();
+ ++particle)
+ deallog << "Before refinement particle id " << particle->get_id()
+ << " has first property " << particle->get_properties()[0]
+ << " and second property " << particle->get_properties()[1]
+ << std::endl;
+
+ // Check that all particles are moved to children
+ tr.refine_global(1);
+
+ for (auto particle = particle_handler.begin();
+ particle != particle_handler.end();
+ ++particle)
+ deallog << "After refinement particle id " << particle->get_id()
+ << " has first property " << particle->get_properties()[0]
+ << " and second property " << particle->get_properties()[1]
+ << std::endl;
+
+ // Reverse the refinement and check again
+ for (auto cell = tr.begin_active(); cell != tr.end(); ++cell)
+ cell->set_coarsen_flag();
+
+ tr.execute_coarsening_and_refinement();
+
+ for (auto particle = particle_handler.begin();
+ particle != particle_handler.end();
+ ++particle)
+ deallog << "After coarsening particle id " << particle->get_id()
+ << " has first property " << particle->get_properties()[0]
+ << " and second property " << particle->get_properties()[1]
+ << 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();
+}
--- /dev/null
+
+DEAL:0:2d/2d::Before refinement particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:2d/2d::Before refinement particle id 1 has first property 0.00000 and second property 0.500000
+DEAL:0:2d/2d::Before refinement particle id 2 has first property 0.00000 and second property 1.00000
+DEAL:0:2d/2d::Before refinement particle id 3 has first property 0.500000 and second property 0.00000
+DEAL:0:2d/2d::Before refinement particle id 4 has first property 0.500000 and second property 0.500000
+DEAL:0:2d/2d::Before refinement particle id 5 has first property 0.500000 and second property 1.00000
+DEAL:0:2d/2d::Before refinement particle id 6 has first property 1.00000 and second property 0.00000
+DEAL:0:2d/2d::Before refinement particle id 7 has first property 1.00000 and second property 0.500000
+DEAL:0:2d/2d::Before refinement particle id 8 has first property 1.00000 and second property 1.00000
+DEAL:0:2d/2d::After refinement particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:2d/2d::After refinement particle id 1 has first property 0.00000 and second property 0.500000
+DEAL:0:2d/2d::After refinement particle id 3 has first property 0.500000 and second property 0.00000
+DEAL:0:2d/2d::After refinement particle id 4 has first property 0.500000 and second property 0.500000
+DEAL:0:2d/2d::After refinement particle id 6 has first property 1.00000 and second property 0.00000
+DEAL:0:2d/2d::After refinement particle id 7 has first property 1.00000 and second property 0.500000
+DEAL:0:2d/2d::After refinement particle id 2 has first property 0.00000 and second property 1.00000
+DEAL:0:2d/2d::After refinement particle id 5 has first property 0.500000 and second property 1.00000
+DEAL:0:2d/2d::After refinement particle id 8 has first property 1.00000 and second property 1.00000
+DEAL:0:2d/2d::After coarsening particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:2d/2d::After coarsening particle id 1 has first property 0.00000 and second property 0.500000
+DEAL:0:2d/2d::After coarsening particle id 3 has first property 0.500000 and second property 0.00000
+DEAL:0:2d/2d::After coarsening particle id 4 has first property 0.500000 and second property 0.500000
+DEAL:0:2d/2d::After coarsening particle id 6 has first property 1.00000 and second property 0.00000
+DEAL:0:2d/2d::After coarsening particle id 7 has first property 1.00000 and second property 0.500000
+DEAL:0:2d/2d::After coarsening particle id 2 has first property 0.00000 and second property 1.00000
+DEAL:0:2d/2d::After coarsening particle id 5 has first property 0.500000 and second property 1.00000
+DEAL:0:2d/2d::After coarsening particle id 8 has first property 1.00000 and second property 1.00000
+DEAL:0:2d/2d::OK
+DEAL:0:2d/3d::Before refinement particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:2d/3d::Before refinement particle id 1 has first property 0.00000 and second property 0.500000
+DEAL:0:2d/3d::Before refinement particle id 2 has first property 0.00000 and second property 1.00000
+DEAL:0:2d/3d::Before refinement particle id 3 has first property 0.500000 and second property 0.00000
+DEAL:0:2d/3d::Before refinement particle id 4 has first property 0.500000 and second property 0.500000
+DEAL:0:2d/3d::Before refinement particle id 5 has first property 0.500000 and second property 1.00000
+DEAL:0:2d/3d::Before refinement particle id 6 has first property 1.00000 and second property 0.00000
+DEAL:0:2d/3d::Before refinement particle id 7 has first property 1.00000 and second property 0.500000
+DEAL:0:2d/3d::Before refinement particle id 8 has first property 1.00000 and second property 1.00000
+DEAL:0:2d/3d::After refinement particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:2d/3d::After refinement particle id 1 has first property 0.00000 and second property 0.500000
+DEAL:0:2d/3d::After refinement particle id 3 has first property 0.500000 and second property 0.00000
+DEAL:0:2d/3d::After refinement particle id 4 has first property 0.500000 and second property 0.500000
+DEAL:0:2d/3d::After refinement particle id 6 has first property 1.00000 and second property 0.00000
+DEAL:0:2d/3d::After refinement particle id 7 has first property 1.00000 and second property 0.500000
+DEAL:0:2d/3d::After refinement particle id 2 has first property 0.00000 and second property 1.00000
+DEAL:0:2d/3d::After refinement particle id 5 has first property 0.500000 and second property 1.00000
+DEAL:0:2d/3d::After refinement particle id 8 has first property 1.00000 and second property 1.00000
+DEAL:0:2d/3d::After coarsening particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:2d/3d::After coarsening particle id 1 has first property 0.00000 and second property 0.500000
+DEAL:0:2d/3d::After coarsening particle id 3 has first property 0.500000 and second property 0.00000
+DEAL:0:2d/3d::After coarsening particle id 4 has first property 0.500000 and second property 0.500000
+DEAL:0:2d/3d::After coarsening particle id 6 has first property 1.00000 and second property 0.00000
+DEAL:0:2d/3d::After coarsening particle id 7 has first property 1.00000 and second property 0.500000
+DEAL:0:2d/3d::After coarsening particle id 2 has first property 0.00000 and second property 1.00000
+DEAL:0:2d/3d::After coarsening particle id 5 has first property 0.500000 and second property 1.00000
+DEAL:0:2d/3d::After coarsening particle id 8 has first property 1.00000 and second property 1.00000
+DEAL:0:2d/3d::OK
+DEAL:0:3d/3d::Before refinement particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 1 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 2 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 3 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 4 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 5 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 6 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 7 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 8 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 9 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 10 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 11 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 12 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 13 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 14 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 15 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 16 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 17 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 18 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 19 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 20 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::Before refinement particle id 21 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 22 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 23 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::Before refinement particle id 24 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 25 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::Before refinement particle id 26 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 1 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 2 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 3 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 4 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 5 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 9 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 10 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 11 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 12 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 13 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 14 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 18 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 19 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 20 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::After refinement particle id 21 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 22 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 23 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::After refinement particle id 6 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 7 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 8 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 15 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 16 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 17 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 24 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 25 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::After refinement particle id 26 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 0 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 1 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 2 has first property 0.00000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 3 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 4 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 5 has first property 0.00000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 9 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 10 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 11 has first property 0.500000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 12 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 13 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 14 has first property 0.500000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 18 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 19 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 20 has first property 1.00000 and second property 0.00000
+DEAL:0:3d/3d::After coarsening particle id 21 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 22 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 23 has first property 1.00000 and second property 0.500000
+DEAL:0:3d/3d::After coarsening particle id 6 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 7 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 8 has first property 0.00000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 15 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 16 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 17 has first property 0.500000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 24 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 25 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::After coarsening particle id 26 has first property 1.00000 and second property 1.00000
+DEAL:0:3d/3d::OK