--- /dev/null
+// ---------------------------------------------------------------------
+//
+// Copyright (C) 2010 - 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.
+//
+// ---------------------------------------------------------------------
+
+
+// Check and illustrate the serialization process for
+// ParticleHandler. This specific test is like the _01 test, but in
+// addition serializes the data of the particles individually, using
+// the Particles::ParticleAccessor::serialize() function that had been
+// declared but not implemented at the time this test was written.
+
+#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 "serialization.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());
+
+ particle_handler.insert_particle(particle, cell);
+ }
+ 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());
+
+ particle_handler.insert_particle(particle, cell);
+ }
+ }
+}
+
+
+
+template <int dim, int spacedim>
+void
+test()
+{
+ parallel::distributed::Triangulation<dim, spacedim> tr(MPI_COMM_WORLD);
+ GridGenerator::hyper_cube(tr);
+ tr.refine_global(2);
+ MappingQ<dim, spacedim> mapping(1);
+
+ Particles::ParticleHandler<dim, spacedim> 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;
+
+ // 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_save.connect(std::bind(
+ &Particles::ParticleHandler<dim,
+ spacedim>::register_store_callback_function,
+ &particle_handler));
+
+ // save data to archive
+ std::ostringstream oss;
+ {
+ boost::archive::text_oarchive oa(oss, boost::archive::no_header);
+ oa << particle_handler;
+
+ // now also write the particles by hand into the stream. this is
+ // unnecessary, since it has been done already in the previous
+ // line, but it tests ParticleAccessor::serialize
+ for (auto &cell : tr.active_cell_iterators())
+ {
+ const boost::iterator_range<
+ typename Particles::ParticleHandler<dim, spacedim>::particle_iterator>
+ particle_range = particle_handler.particles_in_cell(cell);
+
+ for (auto &particle : particle_range)
+ oa << particle;
+ }
+
+ 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;
+
+
+ // 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.post_distributed_load.connect(std::bind(
+ &Particles::ParticleHandler<dim, spacedim>::register_load_callback_function,
+ &particle_handler,
+ true));
+
+ // 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");
+
+ // now also read the particles by hand into the stream. the same
+ // comment applied as where we were writing them
+ for (auto &cell : tr.active_cell_iterators())
+ {
+ const boost::iterator_range<
+ typename Particles::ParticleHandler<dim, spacedim>::particle_iterator>
+ particle_range = particle_handler.particles_in_cell(cell);
+
+ for (auto &particle : particle_range)
+ ia >> particle;
+ }
+ }
+
+ 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();
+}
--- /dev/null
+
+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 0 0 0 0 0 0 2 0 0 0.00000000000000000e+00 0.00000000000000000e+00 2 0.00000000000000000e+00 -0.00000000000000000e+00 0 0 2 5.00000000000000000e-01 0.00000000000000000e+00 2 1.00000000000000000e+00 -0.00000000000000000e+00 3 0 2 0.00000000000000000e+00 5.00000000000000000e-01 2 0.00000000000000000e+00 1.00000000000000000e+00 1 0 2 5.00000000000000000e-01 5.00000000000000000e-01 2 1.00000000000000000e+00 1.00000000000000000e+00 4 0 2 1.00000000000000000e+00 0.00000000000000000e+00 2 1.00000000000000000e+00 -0.00000000000000000e+00 6 0 2 1.00000000000000000e+00 5.00000000000000000e-01 2 1.00000000000000000e+00 1.00000000000000000e+00 7 0 2 0.00000000000000000e+00 1.00000000000000000e+00 2 0.00000000000000000e+00 1.00000000000000000e+00 2 0 2 5.00000000000000000e-01 1.00000000000000000e+00 2 1.00000000000000000e+00 1.00000000000000000e+00 5 0 2 1.00000000000000000e+00 1.00000000000000000e+00 2 1.00000000000000000e+00 1.00000000000000000e+00 8 0
+
+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 0 0 0 0 0 0 3 0 0 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0 0 0 0 2 0 0 0.00000000000000000e+00 0.00000000000000000e+00 0 0 3 5.00000000000000000e-01 0.00000000000000000e+00 0.00000000000000000e+00 2 1.00000000000000000e+00 0.00000000000000000e+00 3 0 3 0.00000000000000000e+00 5.00000000000000000e-01 0.00000000000000000e+00 2 0.00000000000000000e+00 1.00000000000000000e+00 1 0 3 5.00000000000000000e-01 5.00000000000000000e-01 0.00000000000000000e+00 2 1.00000000000000000e+00 1.00000000000000000e+00 4 0 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 2 1.00000000000000000e+00 0.00000000000000000e+00 6 0 3 1.00000000000000000e+00 5.00000000000000000e-01 0.00000000000000000e+00 2 1.00000000000000000e+00 1.00000000000000000e+00 7 0 3 0.00000000000000000e+00 1.00000000000000000e+00 0.00000000000000000e+00 2 0.00000000000000000e+00 1.00000000000000000e+00 2 0 3 5.00000000000000000e-01 1.00000000000000000e+00 0.00000000000000000e+00 2 1.00000000000000000e+00 1.00000000000000000e+00 5 0 3 1.00000000000000000e+00 1.00000000000000000e+00 0.00000000000000000e+00 2 1.00000000000000000e+00 1.00000000000000000e+00 8 0
+
+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 0 0 0 0 0 0 3 0 0 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 0 0 3 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 1 0 3 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 0.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 2 0 3 5.00000000000000000e-01 0.00000000000000000e+00 0.00000000000000000e+00 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 9 0 3 5.00000000000000000e-01 0.00000000000000000e+00 0.00000000000000000e+00 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 10 0 3 5.00000000000000000e-01 0.00000000000000000e+00 0.00000000000000000e+00 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 11 0 3 0.00000000000000000e+00 5.00000000000000000e-01 5.00000000000000000e-01 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 0 3 0.00000000000000000e+00 5.00000000000000000e-01 5.00000000000000000e-01 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 4 0 3 0.00000000000000000e+00 5.00000000000000000e-01 5.00000000000000000e-01 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 5 0 3 5.00000000000000000e-01 5.00000000000000000e-01 5.00000000000000000e-01 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 12 0 3 5.00000000000000000e-01 5.00000000000000000e-01 5.00000000000000000e-01 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 13 0 3 5.00000000000000000e-01 5.00000000000000000e-01 5.00000000000000000e-01 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 14 0 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 18 0 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 19 0 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 3 1.00000000000000000e+00 0.00000000000000000e+00 0.00000000000000000e+00 20 0 3 1.00000000000000000e+00 5.00000000000000000e-01 5.00000000000000000e-01 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 21 0 3 1.00000000000000000e+00 5.00000000000000000e-01 5.00000000000000000e-01 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 22 0 3 1.00000000000000000e+00 5.00000000000000000e-01 5.00000000000000000e-01 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 23 0 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 6 0 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 7 0 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 0.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 8 0 3 5.00000000000000000e-01 1.00000000000000000e+00 1.00000000000000000e+00 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 15 0 3 5.00000000000000000e-01 1.00000000000000000e+00 1.00000000000000000e+00 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 16 0 3 5.00000000000000000e-01 1.00000000000000000e+00 1.00000000000000000e+00 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 17 0 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 24 0 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 25 0 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 3 1.00000000000000000e+00 1.00000000000000000e+00 1.00000000000000000e+00 26 0
+
+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::