]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Try with p::f::T
authorPasquale Africa <pafrica@sissa.it>
Sat, 1 Jul 2023 15:10:45 +0000 (15:10 +0000)
committerPasquale Africa <pafrica@sissa.it>
Sat, 1 Jul 2023 15:10:45 +0000 (15:10 +0000)
source/grid/grid_tools.inst.in
source/particles/particle_handler.cc
tests/serialization/particle_handler_04.cc [new file with mode: 0644]
tests/serialization/particle_handler_04.with_p4est=true.mpirun=1.output [new file with mode: 0644]

index a317867e4717d11f93294014b3114581b25ae83b..cfb53224b7cea940e939064603501be29dad8f45 100644 (file)
@@ -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<deal_II_space_dimension> &p);
+    \}
+
+#endif
+  }
+
+
 // now also instantiate a few additional functions for
 // parallel::distributed::Triangulation
 for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS)
index 8ed8460ced542ddea4389fa9101a9a051615a3fa..3a31e770d92c5688895fe3094d458a233f0bf264 100644 (file)
@@ -77,7 +77,7 @@ namespace Particles
   template <int dim, int spacedim>
   ParticleHandler<dim, spacedim>::ParticleHandler(
     const Triangulation<dim, spacedim> &triangulation,
-    const Mapping<dim, spacedim> &      mapping,
+    const Mapping<dim, spacedim>       &mapping,
     const unsigned int                  n_properties)
     : triangulation(&triangulation, typeid(*this).name())
     , mapping(&mapping, typeid(*this).name())
@@ -117,7 +117,7 @@ namespace Particles
   void
   ParticleHandler<dim, spacedim>::initialize(
     const Triangulation<dim, spacedim> &new_triangulation,
-    const Mapping<dim, spacedim> &      new_mapping,
+    const Mapping<dim, spacedim>       &new_mapping,
     const unsigned int                  n_properties)
   {
     clear();
@@ -577,7 +577,7 @@ namespace Particles
   template <int dim, int spacedim>
   typename ParticleHandler<dim, spacedim>::particle_iterator
   ParticleHandler<dim, spacedim>::insert_particle(
-    const Particle<dim, spacedim> &                                    particle,
+    const Particle<dim, spacedim>                                     &particle,
     const typename Triangulation<dim, spacedim>::active_cell_iterator &cell)
   {
     return insert_particle(particle.get_location(),
@@ -623,7 +623,7 @@ namespace Particles
   template <int dim, int spacedim>
   typename ParticleHandler<dim, spacedim>::particle_iterator
   ParticleHandler<dim, spacedim>::insert_particle(
-    const void *&                                                      data,
+    const void                                                       *&data,
     const typename Triangulation<dim, spacedim>::active_cell_iterator &cell)
   {
     Assert(triangulation != nullptr, ExcInternalError());
@@ -648,8 +648,8 @@ namespace Particles
   template <int dim, int spacedim>
   typename ParticleHandler<dim, spacedim>::particle_iterator
   ParticleHandler<dim, spacedim>::insert_particle(
-    const Point<spacedim> &     position,
-    const Point<dim> &          reference_position,
+    const Point<spacedim>      &position,
+    const Point<dim>           &reference_position,
     const types::particle_index particle_index,
     const typename Triangulation<dim, spacedim>::active_cell_iterator &cell,
     const ArrayView<const double> &properties)
@@ -764,8 +764,8 @@ namespace Particles
   ParticleHandler<dim, spacedim>::insert_global_particles(
     const std::vector<Point<spacedim>> &positions,
     const std::vector<std::vector<BoundingBox<spacedim>>>
-      &                                       global_bounding_boxes,
-    const std::vector<std::vector<double>> &  properties,
+                                             &global_bounding_boxes,
+    const std::vector<std::vector<double>>   &properties,
     const std::vector<types::particle_index> &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<Tensor<1, dim>> &center_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<typename Triangulation<dim, spacedim>::active_cell_iterator>>
-      &        send_cells,
+              &send_cells,
     const bool build_cache)
   {
     Assert(triangulation != nullptr, ExcInternalError());
@@ -2067,7 +2067,7 @@ namespace Particles
   template <int dim, int spacedim>
   void
   ParticleHandler<dim, spacedim>::register_additional_store_load_functions(
-    const std::function<std::size_t()> &                            size_callb,
+    const std::function<std::size_t()>                             &size_callb,
     const std::function<void *(const particle_iterator &, void *)> &store_callb,
     const std::function<const void *(const particle_iterator &, const void *)>
       &load_callb)
@@ -2179,11 +2179,12 @@ namespace Particles
   void
   ParticleHandler<dim, spacedim>::register_data_attach()
   {
-    parallel::distributed::Triangulation<dim, spacedim>
+    parallel::DistributedTriangulationBase<dim, spacedim>
       *distributed_triangulation =
-        const_cast<parallel::distributed::Triangulation<dim, spacedim> *>(
-          dynamic_cast<const parallel::distributed::Triangulation<dim, spacedim>
-                         *>(&(*triangulation)));
+        const_cast<parallel::DistributedTriangulationBase<dim, spacedim> *>(
+          dynamic_cast<
+            const parallel::DistributedTriangulationBase<dim, spacedim> *>(
+            &(*triangulation)));
     (void)distributed_triangulation;
 
     Assert(
@@ -2197,7 +2198,7 @@ namespace Particles
     const auto callback_function =
       [this](
         const typename Triangulation<dim, spacedim>::cell_iterator
-          &                                                     cell_iterator,
+                                                               &cell_iterator,
         const typename Triangulation<dim, spacedim>::CellStatus cell_status) {
         return this->pack_callback(cell_iterator, cell_status);
       };
@@ -2243,11 +2244,12 @@ namespace Particles
   ParticleHandler<dim, spacedim>::notify_ready_to_unpack(
     const bool serialization)
   {
-    parallel::distributed::Triangulation<dim, spacedim>
+    parallel::DistributedTriangulationBase<dim, spacedim>
       *distributed_triangulation =
-        const_cast<parallel::distributed::Triangulation<dim, spacedim> *>(
-          dynamic_cast<const parallel::distributed::Triangulation<dim, spacedim>
-                         *>(&(*triangulation)));
+        const_cast<parallel::DistributedTriangulationBase<dim, spacedim> *>(
+          dynamic_cast<
+            const parallel::DistributedTriangulationBase<dim, spacedim> *>(
+            &(*triangulation)));
     (void)distributed_triangulation;
 
     Assert(
@@ -2354,7 +2356,7 @@ namespace Particles
   template <int dim, int spacedim>
   void
   ParticleHandler<dim, spacedim>::unpack_callback(
-    const typename Triangulation<dim, spacedim>::cell_iterator &    cell,
+    const typename Triangulation<dim, spacedim>::cell_iterator     &cell,
     const typename Triangulation<dim, spacedim>::CellStatus         status,
     const boost::iterator_range<std::vector<char>::const_iterator> &data_range)
   {
diff --git a/tests/serialization/particle_handler_04.cc b/tests/serialization/particle_handler_04.cc
new file mode 100644 (file)
index 0000000..0c35d03
--- /dev/null
@@ -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 <deal.II/distributed/fully_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::fullydistributed::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::fullydistributed::
+                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::fullydistributed::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()
+{
+  Triangulation<dim, spacedim> 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<dim, spacedim> tr(MPI_COMM_WORLD);
+  tr.create_triangulation(construction_data);
+
+  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;
+
+  // 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 (file)
index 0000000..a97ab8f
--- /dev/null
@@ -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::

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.