From 8f7b16a360da215a19a67ade5a96d5c10a75ab28 Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Sun, 21 May 2023 22:28:27 +0200 Subject: [PATCH] Do not use Number::size() by switching to more generic access methods --- .../deal.II/matrix_free/fe_evaluation_data.h | 165 +++++------------- 1 file changed, 43 insertions(+), 122 deletions(-) diff --git a/include/deal.II/matrix_free/fe_evaluation_data.h b/include/deal.II/matrix_free/fe_evaluation_data.h index 605ee88f4e..e7ec7754d1 100644 --- a/include/deal.II/matrix_free/fe_evaluation_data.h +++ b/include/deal.II/matrix_free/fe_evaluation_data.h @@ -561,9 +561,14 @@ public: * VectorizedArray fields of length MatrixFree::n_cell_batches() + * MatrixFree::n_ghost_cell_batches() for cell data. It is implemented * both for cells and faces (access data to the associated cell). + * + * The underlying type can be both the Number type as given by the class + * template (i.e., VectorizedArrayType) as well as std::array with as many + * entries as n_lanes. */ - Number - read_cell_data(const AlignedVector &array) const; + template + T + read_cell_data(const AlignedVector &array) const; /** * Provides a unified interface to set data in a vector of @@ -571,26 +576,9 @@ public: * MatrixFree::n_ghost_cell_batches() for cell data. It is implemented * both for cells and faces (access data to the associated cell). */ - void - set_cell_data(AlignedVector &array, const Number &value) const; - - /** - * The same as above, just for std::array of length of Number for - * arbitrary data type. - */ - template - std::array - read_cell_data( - const AlignedVector> &array) const; - - /** - * The same as above, just for std::array of length of Number for - * arbitrary data type. - */ template void - set_cell_data(AlignedVector> &array, - const std::array & value) const; + set_cell_data(AlignedVector &array, const T &value) const; /** * Provides a unified interface to access data in a vector of @@ -600,8 +588,9 @@ public: * * @note Only implemented for faces. */ - Number - read_face_data(const AlignedVector &array) const; + template + T + read_face_data(const AlignedVector &array) const; /** * Provides a unified interface to set data in a vector of @@ -611,26 +600,9 @@ public: * * @note Only implemented for faces. */ - void - set_face_data(AlignedVector &array, const Number &value) const; - - /** - * The same as above, just for std::array of length of Number for - * arbitrary data type. - */ - template - std::array - read_face_data( - const AlignedVector> &array) const; - - /** - * The same as above, just for std::array of length of Number for - * arbitrary data type. - */ template void - set_face_data(AlignedVector> &array, - const std::array & value) const; + set_face_data(AlignedVector &array, const T &value) const; /** @} */ @@ -1664,13 +1636,13 @@ FEEvaluationData::quadrature_point_indices() const namespace internal { template inline void process_cell_or_face_data(const std::array indices, - GlobalVectorType & array, - VectorizedArrayType2 & out, + VectorOfArrayType & array, + ArrayType & out, const FU & fu) { for (unsigned int i = 0; i < N; ++i) @@ -1680,50 +1652,33 @@ namespace internal fu(out[i], array[indices[i] / N][indices[i] % N]); } } -} // namespace internal - - - -template -inline Number -FEEvaluationData::read_cell_data( - const AlignedVector &array) const -{ - Number out = Number(1.); - internal::process_cell_or_face_data(this->get_cell_ids(), - array, - out, - [](auto &local, const auto &global) { - local = global; - }); - return out; -} - - -template -inline void -FEEvaluationData::set_cell_data( - AlignedVector &array, - const Number & in) const -{ - internal::process_cell_or_face_data(this->get_cell_ids(), - array, - in, - [](const auto &local, auto &global) { - global = local; - }); -} + template + inline void + set_valid_element_to_array(const std::array indices, + const VectorOfArrayType & array, + ArrayType & out) + { + // set all entries in array to a valid element + int index = 0; + for (; index < N; ++index) + if (indices[index] != numbers::invalid_unsigned_int) + break; + for (unsigned int i = 0; i < N; ++i) + out[i] = array[indices[index] / N][indices[index] % N]; + } +} // namespace internal template template -inline std::array +inline T FEEvaluationData::read_cell_data( - const AlignedVector> &array) const + const AlignedVector &array) const { - std::array out; + T out; + internal::set_valid_element_to_array(this->get_cell_ids(), array, out); internal::process_cell_or_face_data(this->get_cell_ids(), array, out, @@ -1738,9 +1693,8 @@ FEEvaluationData::read_cell_data( template template inline void -FEEvaluationData::set_cell_data( - AlignedVector> &array, - const std::array & in) const +FEEvaluationData::set_cell_data(AlignedVector &array, + const T &in) const { internal::process_cell_or_face_data(this->get_cell_ids(), array, @@ -1752,46 +1706,14 @@ FEEvaluationData::set_cell_data( -template -inline Number -FEEvaluationData::read_face_data( - const AlignedVector &array) const -{ - Number out = Number(1.); - internal::process_cell_or_face_data(this->get_face_ids(), - array, - out, - [](auto &local, const auto &global) { - local = global; - }); - return out; -} - - - -template -inline void -FEEvaluationData::set_face_data( - AlignedVector &array, - const Number & in) const -{ - internal::process_cell_or_face_data(this->get_face_ids(), - array, - in, - [](const auto &local, auto &global) { - global = local; - }); -} - - - template template -inline std::array +inline T FEEvaluationData::read_face_data( - const AlignedVector> &array) const + const AlignedVector &array) const { - std::array out; + T out; + internal::set_valid_element_to_array(this->get_cell_ids(), array, out); internal::process_cell_or_face_data(this->get_face_ids(), array, out, @@ -1806,9 +1728,8 @@ FEEvaluationData::read_face_data( template template inline void -FEEvaluationData::set_face_data( - AlignedVector> &array, - const std::array & in) const +FEEvaluationData::set_face_data(AlignedVector &array, + const T &in) const { internal::process_cell_or_face_data(this->get_face_ids(), array, -- 2.39.5