]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Clean test
authorBruno Blais <blais.bruno@gmail.com>
Sat, 1 Jul 2023 16:54:10 +0000 (12:54 -0400)
committerBruno Blais <blais.bruno@gmail.com>
Sat, 1 Jul 2023 16:54:10 +0000 (12:54 -0400)
source/distributed/fully_distributed_tria.cc
source/particles/particle_handler.cc
tests/serialization/particle_handler_03.cc
tests/serialization/particle_handler_04.cc
tests/serialization/particle_handler_04.mpirun=1.output

index 9f423208734757ef7b0af97ebc0406a318012183..38b488c20b58113628911851ad5a6bf25ef4ced5 100644 (file)
@@ -456,7 +456,8 @@ namespace parallel
     void Triangulation<dim, spacedim>::save(const std::string &filename) const
     {
 #ifdef DEAL_II_WITH_MPI
-      //AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() == 0,
+      // AssertThrow(this->cell_attached_data.pack_callbacks_variable.size() ==
+      // 0,
       //            ExcNotImplemented());
 
       Assert(
index 6a9e0fa3542d98aedea7b3bea4cca57c272c4360..a0a4c168141c74d4c06f0f0ea36b311e0a7776bb 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)
@@ -2197,14 +2197,13 @@ 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);
       };
 
     handle = distributed_triangulation->register_data_attach(
       callback_function, /*returns_variable_size_data=*/true);
-
   }
 
 
@@ -2261,7 +2260,7 @@ namespace Particles
     // First prepare container for insertion
     clear();
 
-//#ifdef DEAL_II_WITH_P4EST
+    //#ifdef DEAL_II_WITH_P4EST
     // If we are resuming from a checkpoint, we first have to register the
     // store function again, to set the triangulation to the same state as
     // before the serialization. Only afterwards we know how to deserialize the
@@ -2289,9 +2288,9 @@ namespace Particles
         handle = numbers::invalid_unsigned_int;
         update_cached_numbers();
       }
-//#else
-//    (void)serialization;
-//#endif
+    //#else
+    //    (void)serialization;
+    //#endif
   }
 
 
@@ -2355,7 +2354,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)
   {
index 18584f3c0081cef9fb3f2de75cf0a991af6c72df..403c37448f96a4a7c8517c0976d38a191580ed80 100644 (file)
@@ -30,7 +30,7 @@ template <int dim, int spacedim>
 void
 create_regular_particle_distribution(
   Particles::ParticleHandler<dim, spacedim> &particle_handler,
-  const Triangulation<dim, spacedim>        &tr,
+  const Triangulation<dim, spacedim> &       tr,
   const unsigned int                         particles_per_direction = 3)
 {
   for (unsigned int i = 0; i < particles_per_direction; ++i)
index 3f035603f750e16ce910f88aed2454403e9f71a9..359bb7c5f18e0794f684fbeeffeb812377b68b6f 100644 (file)
 
 #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()
 {
+  // Generate fulllydistributed triangulation from serial triangulation
   Triangulation<dim, spacedim> basetria;
   GridGenerator::hyper_cube(basetria);
   basetria.refine_global(2);
@@ -99,33 +45,29 @@ test()
 
   MappingQ<dim, spacedim> mapping(1);
 
+  // Create ParticleHandler and insert two particles
   Particles::ParticleHandler<dim, spacedim> particle_handler(tr, mapping);
-       std::vector<Point<spacedim>> position(2);
-        std::vector<Point<dim>>      reference_position(2);
-
-        for (unsigned int i = 0; i < dim; ++i)
-          {
-            position[0](i) = 0.125;
-            position[1](i) = 0.525;
-          }
-
-        Particles::Particle<dim, spacedim> particle1(position[0],
-                                                     reference_position[0],
-                                                     0);
-        Particles::Particle<dim, spacedim> particle2(position[1],
-                                                     reference_position[1],
-                                                     1);
-
-        typename Triangulation<dim, spacedim>::active_cell_iterator cell1(&tr,
-                                                                          2,
-                                                                          0);
-        typename Triangulation<dim, spacedim>::active_cell_iterator cell2(&tr,
-                                                                          2,
-                                                                          0);
+  std::vector<Point<spacedim>>              position(2);
+  std::vector<Point<dim>>                   reference_position(2);
+
+  for (unsigned int i = 0; i < dim; ++i)
+    {
+      position[0](i) = 0.125;
+      position[1](i) = 0.525;
+    }
+
+  Particles::Particle<dim, spacedim> particle1(position[0],
+                                               reference_position[0],
+                                               0);
+  Particles::Particle<dim, spacedim> particle2(position[1],
+                                               reference_position[1],
+                                               1);
+
+  typename Triangulation<dim, spacedim>::active_cell_iterator cell1(&tr, 2, 0);
+  typename Triangulation<dim, spacedim>::active_cell_iterator cell2(&tr, 2, 0);
   particle_handler.insert_particle(particle1, cell1);
   particle_handler.insert_particle(particle2, cell2);
 
-  //create_regular_particle_distribution(particle_handler, tr);
   particle_handler.sort_particles_into_subdomains_and_cells();
 
   for (auto particle = particle_handler.begin();
@@ -137,8 +79,8 @@ test()
 
   particle_handler.prepare_for_serialization();
 
-  // save data to archive
-  std::ofstream oss("data.particles");
+  // save additional particle data to archive
+  std::ostringstream oss;
   {
     boost::archive::text_oarchive oa(oss, boost::archive::no_header);
 
@@ -148,13 +90,11 @@ test()
     // archive and stream closed when
     // destructors are called
   }
-  oss.close();
-  //deallog << oss.str() << std::endl;
+  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);
@@ -166,12 +106,12 @@ test()
     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
+  // verify correctness of the serialization. Note that the boost
+  // archive of the ParticleHandler has to be read before the triangulation (otherwise it
   // does not know if something was stored in the user data of the
   // triangulation).
   {
-    std::ifstream            iss("data.particles");
+    std::istringstream                 iss(oss.str());
     boost::archive::text_iarchive ia(iss, boost::archive::no_header);
 
     ia >> particle_handler;
@@ -179,7 +119,8 @@ test()
     particle_handler.deserialize();
   }
 
-  deallog << "After deserialization global number of particles is: " << particle_handler.n_global_particles() << std::endl;
+  deallog << "After deserialization global number of particles is: "
+          << particle_handler.n_global_particles() << std::endl;
   for (auto particle = particle_handler.begin();
        particle != particle_handler.end();
        ++particle)
index db908b1579688b48997c2d0e4896e312f2492de4..7c8ec417b60898caf49e329b8ad312675bc2eb38 100644 (file)
@@ -1,6 +1,8 @@
 
 DEAL:0:2d/2d::Before serialization particle id 0 is in cell 2.0
 DEAL:0:2d/2d::Before serialization particle id 1 is in cell 2.12
+DEAL:0:2d/2d::0 0 2 1 2
+
 DEAL:0:2d/2d::After deserialization global number of particles is: 2
 DEAL:0:2d/2d::After serialization particle id 0 is in cell 2.0
 DEAL:0:2d/2d::After serialization particle id 1 is in cell 2.12
@@ -8,6 +10,8 @@ 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 1 is in cell 2.12
+DEAL:0:2d/3d::0 0 2 1 2
+
 DEAL:0:2d/3d::After deserialization global number of particles is: 2
 DEAL:0:2d/3d::After serialization particle id 0 is in cell 2.0
 DEAL:0:2d/3d::After serialization particle id 1 is in cell 2.12
@@ -15,6 +19,8 @@ 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.56
+DEAL:0:3d/3d::0 0 2 1 2
+
 DEAL:0:3d/3d::After deserialization global number of particles is: 2
 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.56

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.