]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Applied suggestions. To be squashed. 7408/head
authorMarc Fehling <marc.fehling@gmx.net>
Thu, 29 Nov 2018 12:21:55 +0000 (13:21 +0100)
committerMarc Fehling <marc.fehling@gmx.net>
Thu, 29 Nov 2018 17:39:39 +0000 (18:39 +0100)
include/deal.II/hp/dof_handler.h
source/hp/dof_handler.cc

index 6f8b91ac5ea2a009cfa06255d474d9e9f38440da..bd39addf1361c0634af8714bb8c46a5c1bb6699a 100644 (file)
@@ -31,8 +31,6 @@
 #include <deal.II/dofs/dof_iterator_selector.h>
 #include <deal.II/dofs/number_cache.h>
 
-#include <deal.II/grid/cell_id.h>
-
 #include <deal.II/hp/dof_faces.h>
 #include <deal.II/hp/dof_level.h>
 #include <deal.II/hp/fe_collection.h>
@@ -126,7 +124,13 @@ namespace hp
    *   the parent.
    * - When coarsening cells, the (now active) parent cell will be assigned
    *   an active FE index that is determined from its (no longer active)
-   *   children, following the FiniteElementDomination logic.
+   *   children, following the FiniteElementDomination logic: We choose the
+   *   least dominant among all elements that dominate all of those used on the
+   *   children. See FECollection::find_least_dominating_fe_in_collection() for
+   *   further information on this topic.
+   *
+   * @note Finite elements need to be assigned to each cell by calling
+   * distribute_dofs() first to make this functionality available.
    *
    *
    * <h3>Active FE indices and parallel meshes</h3>
@@ -1106,16 +1110,16 @@ namespace hp
     std::vector<unsigned int> vertex_dof_offsets;
 
     /**
-     * Container to temporarily store the CellID and active FE index of
+     * Container to temporarily store the iterator and active FE index of
      * cells that will be refined.
      */
-    std::vector<std::pair<CellId, unsigned int>> refined_cells_fe_index;
+    std::map<const cell_iterator, const unsigned int> refined_cells_fe_index;
 
     /**
-     * Container to temporarily store the CellID and active FE index of
-     * cells that will be coarsened.
+     * Container to temporarily store the iterator and active FE index of
+     * parent cells that will remain after coarsening.
      */
-    std::vector<std::pair<CellId, unsigned int>> coarsened_cells_fe_index;
+    std::map<const cell_iterator, const unsigned int> coarsened_cells_fe_index;
 
     /**
      * A list of connections with which this object connects to the
index 0dd1cf0790a7852bf07b90f4aad72bdbb7b6be1e..28ffcf3ac1e15bf6cc2c80422f68500deff9b7f5 100644 (file)
@@ -1731,6 +1731,8 @@ namespace hp
   void
   DoFHandler<dim, spacedim>::pre_refinement_fe_index_update()
   {
+    // Finite elements need to be assigned to each cell by calling
+    // distribute_dofs() first to make this functionality available.
     if (fe_collection.size() > 0)
       {
         Assert(refined_cells_fe_index.empty(), ExcInternalError());
@@ -1745,29 +1747,25 @@ namespace hp
             &(*tria)));
 
         std::vector<types::subdomain_id> saved_subdomain_ids;
-        if (shared_tria != nullptr)
-          if (shared_tria->with_artificial_cells())
-            {
-              saved_subdomain_ids.resize(shared_tria->n_active_cells());
-
-              typename parallel::shared::Triangulation<dim, spacedim>::
-                active_cell_iterator cell = shared_tria->begin_active(),
-                                     endc = shared_tria->end();
+        if (shared_tria != nullptr && shared_tria->with_artificial_cells())
+          {
+            saved_subdomain_ids.resize(shared_tria->n_active_cells());
 
-              const std::vector<types::subdomain_id> &true_subdomain_ids =
-                shared_tria->get_true_subdomain_ids_of_cells();
+            const std::vector<types::subdomain_id> &true_subdomain_ids =
+              shared_tria->get_true_subdomain_ids_of_cells();
 
-              for (unsigned int index = 0; cell != endc; ++cell, ++index)
-                {
-                  saved_subdomain_ids[index] = cell->subdomain_id();
-                  cell->set_subdomain_id(true_subdomain_ids[index]);
-                }
+            for (auto &cell : active_cell_iterators())
+              {
+                const unsigned int index   = cell->active_cell_index();
+                saved_subdomain_ids[index] = cell->subdomain_id();
+                cell->set_subdomain_id(true_subdomain_ids[index]);
+              }
 
-              // Make sure every processor knows the active_fe_indices
-              // on both its own cells and all ghost cells.
-              dealii::internal::hp::DoFHandlerImplementation::Implementation::
-                communicate_active_fe_indices(*this);
-            }
+            // Make sure every processor knows the active_fe_indices
+            // on both its own cells and all ghost cells.
+            dealii::internal::hp::DoFHandlerImplementation::Implementation::
+              communicate_active_fe_indices(*this);
+          }
 
         // Store active_fe_index information for all cells that will be
         // affected by refinement/coarsening.
@@ -1777,28 +1775,24 @@ namespace hp
               {
                 // Store the active_fe_index of each cell that will be refined
                 // to and distribute it later on its children.
-                refined_cells_fe_index.push_back(
-                  {cell->id(), cell->active_fe_index()});
+                refined_cells_fe_index.insert({cell, cell->active_fe_index()});
               }
             else if (cell->coarsen_flag_set())
               {
                 // From all cells that will be coarsened, determine their parent
                 // and calculate its proper active_fe_index, so that it can be
                 // set after refinement.
+                // But first, check if that particular cell has a parent at all.
+                Assert(cell->level() > 0, ExcInternalError());
                 const auto &parent = cell->parent();
                 // Check if the active_fe_index for the current cell has been
                 // determined already.
-                if (std::find_if(
-                      coarsened_cells_fe_index.cbegin(),
-                      coarsened_cells_fe_index.cend(),
-                      [&parent](
-                        const std::pair<CellId, unsigned int> &element) {
-                        return element.first == parent->id();
-                      }) == coarsened_cells_fe_index.cend())
+                if (coarsened_cells_fe_index.find(parent) ==
+                    coarsened_cells_fe_index.end())
                   {
                     std::set<unsigned int> fe_indices_children;
                     for (unsigned int child_index = 0;
-                         child_index < GeometryInfo<dim>::max_children_per_cell;
+                         child_index < parent->n_children();
                          ++child_index)
                       fe_indices_children.insert(
                         parent->child(child_index)->active_fe_index());
@@ -1814,22 +1808,20 @@ namespace hp
                         "that dominates all children of a cell you are trying "
                         "to coarsen!"));
 
-                    coarsened_cells_fe_index.push_back(
-                      {parent->id(), fe_index});
+                    coarsened_cells_fe_index.insert({parent, fe_index});
                   }
               }
           }
 
         // Finally, restore current subdomain_ids.
-        if (shared_tria != nullptr)
-          if (shared_tria->with_artificial_cells())
+        if (shared_tria != nullptr && shared_tria->with_artificial_cells())
+          for (auto &cell : active_cell_iterators())
             {
-              typename parallel::shared::Triangulation<dim, spacedim>::
-                active_cell_iterator cell = shared_tria->begin_active(),
-                                     endc = shared_tria->end();
-
-              for (unsigned int index = 0; cell != endc; ++cell, ++index)
-                cell->set_subdomain_id(saved_subdomain_ids[index]);
+              if (cell->is_artificial())
+                cell->set_subdomain_id(numbers::invalid_subdomain_id);
+              else
+                cell->set_subdomain_id(
+                  saved_subdomain_ids[cell->active_cell_index()]);
             }
       }
   }
@@ -1839,21 +1831,21 @@ namespace hp
   void
   DoFHandler<dim, spacedim>::post_refinement_fe_index_update()
   {
+    // Finite elements need to be assigned to each cell by calling
+    // distribute_dofs() first to make this functionality available.
     if (fe_collection.size() > 0)
       {
         // Distribute active_fe_indices from all refined cells on their
         // respective children.
-        for (auto &pair : refined_cells_fe_index)
+        for (const auto &pair : refined_cells_fe_index)
           {
-            typename hp::DoFHandler<dim, spacedim>::cell_iterator parent(
-              *(pair.first.to_cell(*tria)), this);
+            const cell_iterator parent(*(pair.first), this);
 
             for (unsigned int child_index = 0;
-                 child_index < GeometryInfo<dim>::max_children_per_cell;
+                 child_index < parent->n_children();
                  ++child_index)
               {
-                typename hp::DoFHandler<dim, spacedim>::cell_iterator child =
-                  parent->child(child_index);
+                const cell_iterator child = parent->child(child_index);
 
                 if (child->is_locally_owned())
                   {
@@ -1865,10 +1857,9 @@ namespace hp
 
         // Set active_fe_indices on coarsened cells that have been determined
         // before the actual coarsening happened.
-        for (auto &pair : coarsened_cells_fe_index)
+        for (const auto &pair : coarsened_cells_fe_index)
           {
-            typename hp::DoFHandler<dim, spacedim>::cell_iterator cell(
-              *(pair.first.to_cell(*tria)), this);
+            const cell_iterator cell(*(pair.first), this);
 
             if (cell->is_locally_owned())
               {

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.