]> https://gitweb.dealii.org/ - dealii.git/commitdiff
DoFHandler::distribute_dofs: only go through entities once
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Fri, 16 Jul 2021 16:43:58 +0000 (18:43 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Sat, 17 Jul 2021 09:33:17 +0000 (11:33 +0200)
source/dofs/dof_handler_policy.cc

index d3a2734cba80ce135bba552398f0a5244a89bcf6..b3be8df8334aca4e842d519fa69dc422f7d3abbe 100644 (file)
@@ -1696,46 +1696,43 @@ namespace internal
           Assert(dof_handler.get_triangulation().n_levels() > 0,
                  ExcMessage("Empty triangulation"));
 
-          // Step 1: distribute dofs on all cells, but definitely
-          // exclude artificial cells
+          // distribute dofs on all cells excluding artificial ones
           types::global_dof_index next_free_dof = 0;
 
           std::vector<types::global_dof_index> dof_indices;
 
           for (auto cell : dof_handler.active_cell_iterators())
-            if (!cell->is_artificial())
-              if ((subdomain_id == numbers::invalid_subdomain_id) ||
-                  (cell->subdomain_id() == subdomain_id))
-                {
-                  dof_indices.resize(cell->get_fe().n_dofs_per_cell());
-
-                  // the cache is not assigned yet, so we must bypass it
-                  internal::DoFAccessorImplementation::Implementation::
-                    get_dof_indices(*cell,
-                                    dof_indices,
-                                    cell->active_fe_index());
+            if (!cell->is_artificial() &&
+                ((subdomain_id == numbers::invalid_subdomain_id) ||
+                 (cell->subdomain_id() == subdomain_id)))
+              {
+                dof_indices.resize(cell->get_fe().n_dofs_per_cell());
 
-                  for (auto &dof_index : dof_indices)
-                    if (dof_index == numbers::invalid_dof_index)
+                DoFAccessorImplementation::Implementation::process_dof_indices(
+                  *cell,
+                  dof_indices,
+                  cell->active_fe_index(),
+                  DoFAccessorImplementation::Implementation::
+                    DoFIndexProcessor<dim, spacedim, false>(),
+                  [&next_free_dof](auto &stored_index, auto &) {
+                    if (stored_index == numbers::invalid_dof_index)
                       {
-                        dof_index = next_free_dof;
-
+                        stored_index = next_free_dof;
                         Assert(
                           next_free_dof !=
                             std::numeric_limits<types::global_dof_index>::max(),
                           ExcMessage(
                             "You have reached the maximal number of degrees of "
-                            "freedom that can be stored in the chosen data type. "
-                            "In practice, this can only happen if you are using "
-                            "32-bit data types. You will have to re-compile "
-                            "deal.II with the `DEAL_II_WITH_64BIT_INDICES' "
-                            "flag set to `ON'."));
+                            "freedom that can be stored in the chosen data "
+                            "type. In practice, this can only happen if you "
+                            "are using 32-bit data types. You will have to "
+                            "re-compile deal.II with the "
+                            "`DEAL_II_WITH_64BIT_INDICES' flag set to `ON'."));
                         ++next_free_dof;
                       }
-
-
-                  cell->set_dof_indices(dof_indices);
-                }
+                  },
+                  false);
+              }
 
           return next_free_dof;
         }

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.