]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Minor particle cleanups.
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 22 Mar 2022 18:20:00 +0000 (12:20 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 22 Mar 2022 23:50:21 +0000 (17:50 -0600)
include/deal.II/particles/particle_handler.h
source/particles/generators.cc
source/particles/particle_handler.cc

index ba6a23d947cb2a9c6a94bdf82da19f92a0255833..63949a1d238d23de9afc26b68b06e8b7e78ee42e 100644 (file)
@@ -166,7 +166,7 @@ namespace Particles
      * particles to be newly inserted.
      */
     void
-    reserve(std::size_t n_particles);
+    reserve(const std::size_t n_particles);
 
     /**
      * Update all internally cached numbers. Note that all functions that
index 1be90a7290c1d3943fd3766d3b01267f42b5ac21..bf82f2e63dcbea29d82120f0e1f35adf64ccfabf 100644 (file)
@@ -110,8 +110,8 @@ namespace Particles
 
 
       // This function generates a random position in the given cell and
-      // returns the position and its coordinates in the unit cell. It first
-      // tries to generate a random and uniformly distributed point in the
+      // returns the position and its coordinates in the reference cell. It
+      // first tries to generate a random and uniformly distributed point in
       // real space, but if that fails (e.g. because the cell has a bad aspect
       // ratio) it reverts to generating a random point in the unit cell.
       template <int dim, int spacedim>
@@ -135,10 +135,9 @@ namespace Particles
         // Generate random points in these bounds until one is within the cell
         // or we exceed the maximum number of attempts.
         const unsigned int n_attempts = 100;
-        Point<spacedim>    position;
-        Point<dim>         position_unit;
         for (unsigned int i = 0; i < n_attempts; ++i)
           {
+            Point<spacedim> position;
             for (unsigned int d = 0; d < spacedim; ++d)
               {
                 position[d] = uniform_distribution_01(random_number_generator) *
@@ -148,11 +147,11 @@ namespace Particles
 
             try
               {
-                position_unit =
+                const Point<dim> position_unit =
                   mapping.transform_real_to_unit_cell(cell, position);
 
                 if (cell->reference_cell().contains_point(position_unit))
-                  return std::make_pair(position, position_unit);
+                  return {position, position_unit};
               }
             catch (typename Mapping<dim>::ExcTransformationFailed &)
               {
@@ -162,17 +161,22 @@ namespace Particles
 
         // If the above algorithm has not worked (e.g. because of badly
         // deformed cells), retry generating particles
-        // randomly within the reference cell. This is not generating a
+        // randomly within the reference cell and then mapping it to to
+        // real space. This is not generating a
         // uniform distribution in real space, but will always succeed.
+        Point<dim> position_unit;
         for (unsigned int d = 0; d < dim; ++d)
           position_unit[d] = uniform_distribution_01(random_number_generator);
 
-        position = mapping.transform_unit_to_real_cell(cell, position_unit);
+        const Point<spacedim> position =
+          mapping.transform_unit_to_real_cell(cell, position_unit);
 
-        return std::make_pair(position, position_unit);
+        return {position, position_unit};
       }
     } // namespace
 
+
+
     template <int dim, int spacedim>
     void
     regular_reference_locations(
index 1d7a9b703d77c79b1ae6873f517a9b9e534baa68..e699ac108b7b471ca8a124a53c2742c4662a95d9 100644 (file)
@@ -223,7 +223,7 @@ namespace Particles
 
   template <int dim, int spacedim>
   void
-  ParticleHandler<dim, spacedim>::reserve(std::size_t n_particles)
+  ParticleHandler<dim, spacedim>::reserve(const std::size_t n_particles)
   {
     property_pool->reserve(n_particles);
   }

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.