From 9ac204c5e467e5554f137358f109973b9bad6b44 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Micha=C5=82=20Wichrowski?= Date: Thu, 30 Jan 2025 14:32:07 +0100 Subject: [PATCH] allow ghost cell in MF --- include/deal.II/matrix_free/matrix_free.h | 10 ++++++++++ .../deal.II/matrix_free/matrix_free.templates.h | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/deal.II/matrix_free/matrix_free.h b/include/deal.II/matrix_free/matrix_free.h index 48d3e5f83e..556b3ee0d3 100644 --- a/include/deal.II/matrix_free/matrix_free.h +++ b/include/deal.II/matrix_free/matrix_free.h @@ -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. */ diff --git a/include/deal.II/matrix_free/matrix_free.templates.h b/include/deal.II/matrix_free/matrix_free.templates.h index fd2db2c568..f55e4e8bf0 100644 --- a/include/deal.II/matrix_free/matrix_free.templates.h +++ b/include/deal.II/matrix_free/matrix_free.templates.h @@ -949,6 +949,7 @@ MatrixFree::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::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::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()); } -- 2.39.5