From: Peter Munch Date: Fri, 23 Oct 2020 06:22:20 +0000 (+0200) Subject: MatrixFree: introduce get_vector_data() X-Git-Tag: v9.3.0-rc1~980^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ecf562bb390d3cfe2878b801608b66648f192b6a;p=dealii.git MatrixFree: introduce get_vector_data() --- diff --git a/include/deal.II/matrix_free/fe_evaluation.h b/include/deal.II/matrix_free/fe_evaluation.h index 97abf46ad5..a1be617d7b 100644 --- a/include/deal.II/matrix_free/fe_evaluation.h +++ b/include/deal.II/matrix_free/fe_evaluation.h @@ -1170,8 +1170,8 @@ protected: */ template void - read_write_operation(const VectorOperation &operation, - VectorType * vectors[], + read_write_operation(const VectorOperation & operation, + const std::array &vectors, const std::bitset &mask, const bool apply_constraints = true) const; @@ -1186,7 +1186,7 @@ protected: void read_write_operation_contiguous( const VectorOperation & operation, - VectorType * vectors[], + const std::array & vectors, const std::bitset &mask) const; /** @@ -1198,8 +1198,9 @@ protected: */ template void - read_write_operation_global(const VectorOperation &operation, - VectorType * vectors[]) const; + read_write_operation_global( + const VectorOperation & operation, + const std::array &vectors) const; /** * This field stores the values for local degrees of freedom (e.g. after @@ -4180,8 +4181,8 @@ template inline void FEEvaluationBase:: - read_write_operation(const VectorOperation &operation, - VectorType * src[], + read_write_operation(const VectorOperation & operation, + const std::array &src, const std::bitset &mask, const bool apply_constraints) const { @@ -4545,8 +4546,9 @@ template inline void FEEvaluationBase:: - read_write_operation_global(const VectorOperation &operation, - VectorType * src[]) const + read_write_operation_global( + const VectorOperation & operation, + const std::array &src) const { Assert(!local_dof_indices.empty(), ExcNotInitialized()); @@ -4578,7 +4580,7 @@ inline void FEEvaluationBase:: read_write_operation_contiguous( const VectorOperation & operation, - VectorType * src[], + const std::array & src, const std::bitset &mask) const { // This functions processes the functions read_dof_values, @@ -4813,6 +4815,56 @@ FEEvaluationBase:: } } +namespace internal +{ + template ::value, + VectorType>::type * = nullptr> + decltype(std::declval().begin()) + get_beginning(VectorType &vec) + { + return vec.begin(); + } + + template ::value, + VectorType>::type * = nullptr> + typename VectorType::value_type * + get_beginning(VectorType &) + { + return nullptr; + } + + template + std::array::type, + IsBlockVector::type>:: + value>::BaseVectorType *, + n_components> + get_vector_data(VectorType &src, const unsigned int first_index) + { + // select between block vectors and non-block vectors. Note that the number + // of components is checked in the internal data + std::array::type, + IsBlockVector::type>:: + value>::BaseVectorType *, + n_components> + src_data; + for (unsigned int d = 0; d < n_components; ++d) + src_data[d] = internal::BlockVectorSelector< + typename std::remove_const::type, + IsBlockVector::type>::value>:: + get_vector_component( + const_cast::type &>(src), + d + first_index); + + return src_data; + } +} // namespace internal + template :: read_dof_values(const VectorType &src, const unsigned int first_index) { - // select between block vectors and non-block vectors. Note that the number - // of components is checked in the internal data - typename internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::BaseVectorType *src_data[n_components]; - for (unsigned int d = 0; d < n_components; ++d) - src_data[d] = - internal::BlockVectorSelector::value>:: - get_vector_component(const_cast(src), d + first_index); + const auto src_data = + internal::get_vector_data(src, first_index); internal::VectorReader reader; read_write_operation(reader, @@ -4859,16 +4903,8 @@ inline void FEEvaluationBase:: read_dof_values_plain(const VectorType &src, const unsigned int first_index) { - // select between block vectors and non-block vectors. Note that the number - // of components is checked in the internal data - typename internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::BaseVectorType *src_data[n_components]; - for (unsigned int d = 0; d < n_components; ++d) - src_data[d] = - internal::BlockVectorSelector::value>:: - get_vector_component(const_cast(src), d + first_index); + const auto src_data = + internal::get_vector_data(src, first_index); internal::VectorReader reader; read_write_operation(reader, @@ -4901,16 +4937,8 @@ FEEvaluationBase:: internal::ExcAccessToUninitializedField()); # endif - // select between block vectors and non-block vectors. Note that the number - // of components is checked in the internal data - typename internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::BaseVectorType *dst_data[n_components]; - for (unsigned int d = 0; d < n_components; ++d) - dst_data[d] = internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::get_vector_component(dst, - d + first_index); + const auto dst_data = + internal::get_vector_data(dst, first_index); internal::VectorDistributorLocalToGlobal distributor; @@ -4936,16 +4964,8 @@ FEEvaluationBase:: internal::ExcAccessToUninitializedField()); # endif - // select between block vectors and non-block vectors. Note that the number - // of components is checked in the internal data - typename internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::BaseVectorType *dst_data[n_components]; - for (unsigned int d = 0; d < n_components; ++d) - dst_data[d] = internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::get_vector_component(dst, - d + first_index); + const auto dst_data = + internal::get_vector_data(dst, first_index); internal::VectorSetter setter; read_write_operation(setter, dst_data, mask); @@ -4971,16 +4991,8 @@ FEEvaluationBase:: internal::ExcAccessToUninitializedField()); # endif - // select between block vectors and non-block vectors. Note that the number - // of components is checked in the internal data - typename internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::BaseVectorType *dst_data[n_components]; - for (unsigned int d = 0; d < n_components; ++d) - dst_data[d] = internal::BlockVectorSelector< - VectorType, - IsBlockVector::value>::get_vector_component(dst, - d + first_index); + const auto dst_data = + internal::get_vector_data(dst, first_index); internal::VectorSetter setter; read_write_operation(setter, dst_data, mask, false); @@ -7708,26 +7720,6 @@ namespace internal { return false; } - - template ::value, - VectorType>::type * = nullptr> - decltype(std::declval().begin()) - get_beginning(VectorType &vec) - { - return vec.begin(); - } - - template ::value, - VectorType>::type * = nullptr> - typename VectorType::value_type * - get_beginning(VectorType &) - { - return nullptr; - } } // namespace internal