]> https://gitweb.dealii.org/ - dealii.git/commitdiff
allow ghost cell in MF 18061/head
authorMichał Wichrowski <mtwichrowski@gmail.com>
Thu, 30 Jan 2025 13:32:07 +0000 (14:32 +0100)
committerMichał Wichrowski <mtwichrowski@gmail.com>
Thu, 30 Jan 2025 13:32:07 +0000 (14:32 +0100)
include/deal.II/matrix_free/matrix_free.h
include/deal.II/matrix_free/matrix_free.templates.h

index 48d3e5f83ef2fcc7f45ba4b4cfe5585af13fecdc..556b3ee0d3816248326b7522195caafdee0909fd 100644 (file)
@@ -249,6 +249,7 @@ public:
       , cell_vectorization_categories_strict(
           cell_vectorization_categories_strict)
       , allow_ghosted_vectors_in_loops(allow_ghosted_vectors_in_loops)
+      , store_ghost_cells(false)
       , communicator_sm(MPI_COMM_SELF)
     {}
 
@@ -275,6 +276,7 @@ public:
       , cell_vectorization_categories_strict(
           other.cell_vectorization_categories_strict)
       , allow_ghosted_vectors_in_loops(other.allow_ghosted_vectors_in_loops)
+      , store_ghost_cells(other.store_ghost_cells)
       , communicator_sm(other.communicator_sm)
     {}
 
@@ -303,6 +305,7 @@ public:
       cell_vectorization_categories_strict =
         other.cell_vectorization_categories_strict;
       allow_ghosted_vectors_in_loops = other.allow_ghosted_vectors_in_loops;
+      store_ghost_cells              = other.store_ghost_cells;
       communicator_sm                = other.communicator_sm;
 
       return *this;
@@ -547,6 +550,13 @@ public:
      */
     bool allow_ghosted_vectors_in_loops;
 
+    /**
+     * Option to control whether data should be generated on ghost cells.
+     * If set to true, the data on ghost cells will be generated.
+     * The default value is false.
+     */
+    bool store_ghost_cells;
+
     /**
      * Shared-memory MPI communicator. Default: MPI_COMM_SELF.
      */
index fd2db2c568c25c90e01acb3d55bc93b763942b9e..f55e4e8bf013ac72d55bb71779d38d19a24aa150 100644 (file)
@@ -949,6 +949,7 @@ MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_handlers(
   const AdditionalData                            &additional_data)
 {
   cell_level_index.clear();
+  auto ghosted_cell_index = cell_level_index;
   dof_handlers.resize(dof_handler_in.size());
   for (unsigned int no = 0; no < dof_handler_in.size(); ++no)
     dof_handlers[no] = dof_handler_in[no];
@@ -970,6 +971,9 @@ MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_handlers(
       for (const auto &cell : tria.cell_iterators_on_level(0))
         internal::MatrixFreeFunctions::resolve_cell(cell, cell_level_index);
 
+      Assert(additional_data.store_ghost_cells == false,
+             ExcMessage(
+               "Storing ghost cells is only supported for level operator."));
       Assert(task_info.n_procs > 1 ||
                cell_level_index.size() == tria.n_active_cells(),
              ExcInternalError());
@@ -983,12 +987,23 @@ MatrixFree<dim, Number, VectorizedArrayType>::initialize_dof_handlers(
           for (const auto &cell : tria.cell_iterators_on_level(level))
             if (cell->is_locally_owned_on_level())
               cell_level_index.emplace_back(cell->level(), cell->index());
+            else if (additional_data.store_ghost_cells == true &&
+                     cell->is_ghost_on_level())
+              ghosted_cell_index.emplace_back(cell->level(), cell->index());
         }
     }
 
   // All these are cells local to this processor. Therefore, set
   // cell_level_index_end_local to the size of cell_level_index.
   cell_level_index_end_local = cell_level_index.size();
+
+  Assert(ghosted_cell_index.size() == 0 || additional_data.store_ghost_cells,
+         ExcInternalError());
+
+  // If ghost cells are stored, add them to the end of the cell_level_index
+  cell_level_index.insert(cell_level_index.end(),
+                          ghosted_cell_index.begin(),
+                          ghosted_cell_index.end());
 }
 
 

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.