From d847f6d37e7be08166938d6bdb0eabbbfcbdff7a Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Fri, 7 Jan 2022 22:27:01 +0100 Subject: [PATCH] Add reinit methods to MeshWorker::CopyData to support hp-FE --- include/deal.II/meshworker/copy_data.h | 104 +++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 6 deletions(-) diff --git a/include/deal.II/meshworker/copy_data.h b/include/deal.II/meshworker/copy_data.h index 3f7bd1514d..1945437804 100644 --- a/include/deal.II/meshworker/copy_data.h +++ b/include/deal.II/meshworker/copy_data.h @@ -50,6 +50,13 @@ namespace MeshWorker int n_dof_indices = n_matrices> struct CopyData { + /** + * Default constructor. All of the @p matrices, @p vectors and + * @p local_dof_indices are empty, and should be initialized using + * one of the reinit() functions. + */ + explicit CopyData() = default; + /** * Initialize everything with the same @p size. This is usually the number * of local degrees of freedom. @@ -70,6 +77,45 @@ namespace MeshWorker CopyData(const CopyData &other) = default; + /** + * Reinitialize everything the same @p size. This is usually the number of + * local degrees of freedom. + */ + void + reinit(const unsigned int size); + + /** + * Reinitialize the @p index'th matrix, vector and local DoF index vector + * with the same @p size. This is usually the number of local degrees of + * freedom. + * + * @note In the event that there are a different number of @p matrices, + * @p vectors and @p local_dof_indices, this function will not throw an + * error when the index is over the size of one or two of these data + * structures. However, if the index exceeds the size of all three of them + * then an error will be thrown. + */ + void + reinit(const unsigned int index, const unsigned int size); + + /** + * Reinitialize the @p index'th matrix with @p size_rows `x` @p size_columns, + * and the vector and local DoF index vector with @p size_columns. These + * sizes usually correspond to some local degrees of freedom (e.g., the + * number of cell DoFs for @p size_rows and number of neighbor cell DoFs + * for @p size_columns). + * + * @note In the event that there are a different number of @p matrices, + * @p vectors and @p local_dof_indices, this function will not throw an + * error when the index is over the size of one or two of these data + * structures. However, if the index exceeds the size of all three of them + * then an error will be thrown. + */ + void + reinit(const unsigned int index, + const unsigned int size_rows, + const unsigned int size_columns); + /** * An array of local matrices. */ @@ -96,12 +142,7 @@ namespace MeshWorker CopyData::CopyData( const unsigned int size) { - for (auto &m : matrices) - m.reinit({size, size}); - for (auto &v : vectors) - v.reinit(size); - for (auto &d : local_dof_indices) - d.resize(size); + reinit(size); } @@ -122,6 +163,57 @@ namespace MeshWorker local_dof_indices[i].resize(dof_indices_sizes[i++]); } + + + template + void + CopyData::reinit( + const unsigned int size) + { + for (auto &m : matrices) + m.reinit({size, size}); + for (auto &v : vectors) + v.reinit(size); + for (auto &d : local_dof_indices) + d.resize(size); + } + + + + template + void + CopyData::reinit( + const unsigned int index, + const unsigned int size) + { + reinit(index, size, size); + } + + + + template + void + CopyData::reinit( + const unsigned int index, + const unsigned int size_rows, + const unsigned int size_columns) + { + // We permit different numbers of matrices, vectors and DoF index vectors. + // So we have to be a bit permissive here. + constexpr const int max_index = + std::max(std::max(n_matrices, n_vectors), n_dof_indices); + Assert(index < max_index, ExcIndexRange(index, 0, max_index)); + + if (index < n_matrices) + matrices[index].reinit({size_rows, size_columns}); + + if (index < n_vectors) + vectors[index].reinit(size_columns); + + if (index < n_dof_indices) + local_dof_indices[index].resize(size_columns); + } + #endif // DOXYGEN } // namespace MeshWorker -- 2.39.5