]> https://gitweb.dealii.org/ - dealii.git/commitdiff
cell_weight: fix bug with AMR in step-68.
authorMarc Fehling <mafehling.git@gmail.com>
Sat, 12 Mar 2022 03:18:17 +0000 (20:18 -0700)
committerMarc Fehling <mafehling.git@gmail.com>
Sat, 12 Mar 2022 03:28:05 +0000 (20:28 -0700)
examples/step-68/step-68.cc
tests/particles/step-68.cc

index a79f2f106f9e1e141020368c9122dc572bed2476..bde1d7d5a47b91762b9bcb2bc00b303a72e96b24 100644 (file)
@@ -350,27 +350,28 @@ namespace Step68
     // should have the status `CELL_PERSIST`. However this function can also
     // be used to distribute load during refinement, therefore we consider
     // refined or coarsened cells as well.
-    if (status == parallel::distributed::Triangulation<dim>::CELL_PERSIST ||
-        status == parallel::distributed::Triangulation<dim>::CELL_REFINE)
+    unsigned int n_particles_in_cell = 0;
+    switch (status)
       {
-        const unsigned int n_particles_in_cell =
-          particle_handler.n_particles_in_cell(cell);
-        return n_particles_in_cell * particle_weight;
-      }
-    else if (status == parallel::distributed::Triangulation<dim>::CELL_COARSEN)
-      {
-        unsigned int n_particles_in_cell = 0;
-
-        for (unsigned int child_index = 0; child_index < cell->n_children();
-             ++child_index)
-          n_particles_in_cell +=
-            particle_handler.n_particles_in_cell(cell->child(child_index));
-
-        return n_particles_in_cell * particle_weight;
+        case parallel::distributed::Triangulation<dim>::CELL_PERSIST:
+        case parallel::distributed::Triangulation<dim>::CELL_REFINE:
+          n_particles_in_cell = particle_handler.n_particles_in_cell(cell);
+          break;
+
+        case parallel::distributed::Triangulation<dim>::CELL_INVALID:
+          break;
+
+        case parallel::distributed::Triangulation<dim>::CELL_COARSEN:
+          for (const auto &child : cell->child_iterators())
+            n_particles_in_cell += particle_handler.n_particles_in_cell(child);
+          break;
+
+        default:
+          Assert(false, ExcInternalError());
+          break;
       }
 
-    Assert(false, ExcInternalError());
-    return 0;
+    return base_weight + particle_weight * n_particles_in_cell;
   }
 
 
index 72713fbc65540d58a9603b5fab1a2316bb54800c..544f59feed2b740d962103ecef55db680eb8bd68 100644 (file)
@@ -278,27 +278,28 @@ namespace Step68
     // should have the status `CELL_PERSIST`. However this function can also
     // be used to distribute load during refinement, therefore we consider
     // refined or coarsened cells as well.
-    if (status == parallel::distributed::Triangulation<dim>::CELL_PERSIST ||
-        status == parallel::distributed::Triangulation<dim>::CELL_REFINE)
+    unsigned int n_particles_in_cell = 0;
+    switch (status)
       {
-        const unsigned int n_particles_in_cell =
-          particle_handler.n_particles_in_cell(cell);
-        return n_particles_in_cell * particle_weight;
-      }
-    else if (status == parallel::distributed::Triangulation<dim>::CELL_COARSEN)
-      {
-        unsigned int n_particles_in_cell = 0;
-
-        for (unsigned int child_index = 0; child_index < cell->n_children();
-             ++child_index)
-          n_particles_in_cell +=
-            particle_handler.n_particles_in_cell(cell->child(child_index));
-
-        return n_particles_in_cell * particle_weight;
+        case parallel::distributed::Triangulation<dim>::CELL_PERSIST:
+        case parallel::distributed::Triangulation<dim>::CELL_REFINE:
+          n_particles_in_cell = particle_handler.n_particles_in_cell(cell);
+          break;
+
+        case parallel::distributed::Triangulation<dim>::CELL_INVALID:
+          break;
+
+        case parallel::distributed::Triangulation<dim>::CELL_COARSEN:
+          for (const auto &child : cell->child_iterators())
+            n_particles_in_cell += particle_handler.n_particles_in_cell(child);
+          break;
+
+        default:
+          Assert(false, ExcInternalError());
+          break;
       }
 
-    Assert(false, ExcInternalError());
-    return 0;
+    return base_weight + particle_weight * n_particles_in_cell;
   }
 
 

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.