From: David Wells Date: Sat, 13 May 2023 12:50:21 +0000 (-0400) Subject: Make FEValues::get_function_values() use ReadVector. X-Git-Tag: relicensing~820^2~7 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd9d33318c43c661e83d5ff5af21e1b3b429abc5;p=dealii.git Make FEValues::get_function_values() use ReadVector. --- diff --git a/include/deal.II/dofs/dof_accessor.h b/include/deal.II/dofs/dof_accessor.h index 001fb7beac..3914d83dff 100644 --- a/include/deal.II/dofs/dof_accessor.h +++ b/include/deal.II/dofs/dof_accessor.h @@ -24,6 +24,8 @@ #include +#include + #include #include @@ -1589,11 +1591,11 @@ public: * caller to assure that the types of the numbers stored in input and output * vectors are compatible and with similar accuracy. */ - template + template void - get_dof_values(const InputVector &values, - ForwardIterator local_values_begin, - ForwardIterator local_values_end) const; + get_dof_values(const ReadVector &values, + ForwardIterator local_values_begin, + ForwardIterator local_values_end) const; /** * Collect the values of the given vector restricted to the dofs of this cell @@ -1683,12 +1685,12 @@ public: * interpolation is presently only provided for cells by the finite element * classes. */ - template + template void get_interpolated_dof_values( - const InputVector & values, - Vector & interpolated_values, - const types::fe_index fe_index = numbers::invalid_fe_index) const; + const ReadVector &values, + Vector & interpolated_values, + const types::fe_index fe_index = numbers::invalid_fe_index) const; /** * This function is the counterpart to get_interpolated_dof_values(): you diff --git a/include/deal.II/dofs/dof_accessor.templates.h b/include/deal.II/dofs/dof_accessor.templates.h index d5505c5fca..4ee7bd40e5 100644 --- a/include/deal.II/dofs/dof_accessor.templates.h +++ b/include/deal.II/dofs/dof_accessor.templates.h @@ -2524,12 +2524,12 @@ DoFCellAccessor::get_dof_values( template -template +template inline void DoFCellAccessor::get_dof_values( - const InputVector &values, - ForwardIterator local_values_begin, - ForwardIterator local_values_end) const + const ReadVector &values, + ForwardIterator local_values_begin, + ForwardIterator local_values_end) const { (void)local_values_end; Assert(this->is_artificial() == false, @@ -2547,11 +2547,17 @@ DoFCellAccessor::get_dof_values( dof_indices(this->get_fe().n_dofs_per_cell()); internal::DoFAccessorImplementation::get_cell_dof_indices( *this, dof_indices, this->active_fe_index()); - dealii::internal::DoFAccessorImplementation::Implementation:: - extract_subvector_to(values, - dof_indices.data(), - dof_indices.data() + dof_indices.size(), - local_values_begin); + + boost::container::small_vector values_temp(local_values_end - + local_values_begin); + auto view = make_array_view(values_temp.begin(), values_temp.end()); + values.extract_subvector_to(make_array_view(dof_indices.begin(), + dof_indices.end()), + view); + using view_type = std::remove_reference_t; + ArrayView values_view2(&*local_values_begin, + local_values_end - local_values_begin); + std::copy(values_temp.begin(), values_temp.end(), values_view2.begin()); } diff --git a/include/deal.II/fe/fe_values.h b/include/deal.II/fe/fe_values.h index 39eb362fe1..9dd445848c 100644 --- a/include/deal.II/fe/fe_values.h +++ b/include/deal.II/fe/fe_values.h @@ -41,6 +41,8 @@ #include +#include + #include #include #include @@ -419,12 +421,10 @@ namespace FEValuesViews * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector &fe_function, - std::vector> - &values) const; + get_function_values(const ReadVector & fe_function, + std::vector> &values) const; /** * Same as above, but using a vector of local degree-of-freedom values. In @@ -1108,12 +1108,10 @@ namespace FEValuesViews * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector &fe_function, - std::vector> - &values) const; + get_function_values(const ReadVector & fe_function, + std::vector> &values) const; /** * Same as above, but using a vector of local degree-of-freedom values. In @@ -1682,12 +1680,10 @@ namespace FEValuesViews * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector &fe_function, - std::vector> - &values) const; + get_function_values(const ReadVector & fe_function, + std::vector> &values) const; /** * Same as above, but using a vector of local degree-of-freedom values. In @@ -2058,12 +2054,10 @@ namespace FEValuesViews * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector &fe_function, - std::vector> - &values) const; + get_function_values(const ReadVector & fe_function, + std::vector> &values) const; /** * Same as above, but using a vector of local degree-of-freedom values. In @@ -2717,19 +2711,12 @@ public: * @post values[q] will contain the value of the field * described by fe_function at the $q$th quadrature point. * - * @note The actual data type of the input vector may be either a - * Vector<T>, BlockVector<T>, or one of the PETSc or Trilinos - * vector wrapper classes. It represents a global vector of DoF values - * associated with the DoFHandler object with which this FEValues object was - * last initialized. - * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector & fe_function, - std::vector &values) const; + get_function_values(const ReadVector &fe_function, + std::vector & values) const; /** * This function does the same as the other get_function_values(), but @@ -2744,11 +2731,10 @@ public: * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector & fe_function, - std::vector> &values) const; + get_function_values(const ReadVector & fe_function, + std::vector> &values) const; /** * Generate function values from an arbitrary vector. This function @@ -2806,12 +2792,11 @@ public: * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector & fe_function, - const ArrayView &indices, - std::vector & values) const; + get_function_values(const ReadVector &fe_function, + const ArrayView &indices, + std::vector &values) const; /** * Generate vector function values from an arbitrary vector. @@ -2821,12 +2806,11 @@ public: * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector & fe_function, - const ArrayView & indices, - std::vector> &values) const; + get_function_values(const ReadVector &fe_function, + const ArrayView &indices, + std::vector> &values) const; /** @@ -2850,13 +2834,12 @@ public: * * @dealiiRequiresUpdateFlags{update_values} */ - template + template void - get_function_values( - const InputVector & fe_function, - const ArrayView & indices, - ArrayView> values, - const bool quadrature_points_fastest) const; + get_function_values(const ReadVector &fe_function, + const ArrayView &indices, + ArrayView> values, + const bool quadrature_points_fastest) const; /** @} */ /// @name Access to derivatives of global finite element fields @@ -3882,11 +3865,10 @@ protected: * Call @p get_interpolated_dof_values of the iterator with the * given arguments. */ - template + template void - get_interpolated_dof_values( - const VectorType & in, - Vector &out) const; + get_interpolated_dof_values(const ReadVector &in, + Vector & out) const; /** * Call @p get_interpolated_dof_values of the iterator with the diff --git a/source/dofs/dof_accessor_get.cc b/source/dofs/dof_accessor_get.cc index 9ec01541ef..a414969a05 100644 --- a/source/dofs/dof_accessor_get.cc +++ b/source/dofs/dof_accessor_get.cc @@ -41,12 +41,12 @@ DEAL_II_NAMESPACE_OPEN template -template +template void DoFCellAccessor::get_interpolated_dof_values( - const InputVector & values, - Vector & interpolated_values, - const types::fe_index fe_index_) const + const ReadVector &values, + Vector & interpolated_values, + const types::fe_index fe_index_) const { const types::fe_index fe_index = (this->dof_handler->hp_capability_enabled == false && @@ -78,7 +78,7 @@ DoFCellAccessor::get_interpolated_dof_values( } else { - Vector tmp(dofs_per_cell); + Vector tmp(dofs_per_cell); this->get_dof_values(values, tmp); FullMatrix interpolation( @@ -130,8 +130,8 @@ DoFCellAccessor::get_interpolated_dof_values( // anyway (and in fact is of size zero, see the assertion above) if (fe.n_dofs_per_cell() > 0) { - Vector tmp1(dofs_per_cell); - Vector tmp2(dofs_per_cell); + Vector tmp1(dofs_per_cell); + Vector tmp2(dofs_per_cell); interpolated_values = 0; @@ -177,7 +177,7 @@ DoFCellAccessor::get_interpolated_dof_values( for (unsigned int i = 0; i < dofs_per_cell; ++i) if (fe.restriction_is_additive(i)) interpolated_values(i) += tmp2(i); - else if (tmp2(i) != number()) + else if (tmp2(i) != Number()) interpolated_values(i) = tmp2(i); } } diff --git a/source/dofs/dof_accessor_get.inst.in b/source/dofs/dof_accessor_get.inst.in index f7d6073794..0c6127dd39 100644 --- a/source/dofs/dof_accessor_get.inst.in +++ b/source/dofs/dof_accessor_get.inst.in @@ -15,19 +15,19 @@ -for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; lda : BOOL) +for (S : REAL_AND_COMPLEX_SCALARS; deal_II_dimension : DIMENSIONS; lda : BOOL) { template void DoFCellAccessor:: - get_interpolated_dof_values(const VEC &, - Vector &, + get_interpolated_dof_values(const ReadVector &, + Vector &, const types::fe_index) const; #if deal_II_dimension != 3 template void DoFCellAccessor:: - get_interpolated_dof_values(const VEC &, - Vector &, + get_interpolated_dof_values(const ReadVector &, + Vector &, const types::fe_index) const; #endif @@ -35,7 +35,7 @@ for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; lda : BOOL) #if deal_II_dimension == 3 template void DoFCellAccessor<1, 3, lda>::get_interpolated_dof_values( - const VEC &, Vector &, const types::fe_index) const; + const ReadVector &, Vector &, const types::fe_index) const; #endif } diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 4d7bc738e8..2f2117f344 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -1540,25 +1540,21 @@ namespace FEValuesViews template - template + template void Scalar::get_function_values( - const InputVector &fe_function, - std::vector> &values) - const + const ReadVector & fe_function, + std::vector> &values) const { Assert(fe_values->update_flags & update_values, (typename FEValuesBase::ExcAccessToUninitializedField( "update_values"))); Assert(fe_values->present_cell.is_initialized(), (typename FEValuesBase::ExcNotReinited())); - AssertDimension(fe_function.size(), - fe_values->present_cell.n_dofs_for_dof_handler()); // get function values of dofs on this cell and call internal worker // function - dealii::Vector dof_values( - fe_values->dofs_per_cell); + dealii::Vector dof_values(fe_values->dofs_per_cell); fe_values->present_cell.get_interpolated_dof_values(fe_function, dof_values); internal::do_function_values( @@ -1813,24 +1809,20 @@ namespace FEValuesViews template - template + template void Vector::get_function_values( - const InputVector &fe_function, - std::vector> &values) - const + const ReadVector & fe_function, + std::vector> &values) const { Assert(fe_values->update_flags & update_values, (typename FEValuesBase::ExcAccessToUninitializedField( "update_values"))); Assert(fe_values->present_cell.is_initialized(), (typename FEValuesBase::ExcNotReinited())); - AssertDimension(fe_function.size(), - fe_values->present_cell.n_dofs_for_dof_handler()); // get function values of dofs on this cell - dealii::Vector dof_values( - fe_values->dofs_per_cell); + dealii::Vector dof_values(fe_values->dofs_per_cell); fe_values->present_cell.get_interpolated_dof_values(fe_function, dof_values); internal::do_function_values( @@ -2258,24 +2250,20 @@ namespace FEValuesViews template - template + template void SymmetricTensor<2, dim, spacedim>::get_function_values( - const InputVector &fe_function, - std::vector> &values) - const + const ReadVector & fe_function, + std::vector> &values) const { Assert(fe_values->update_flags & update_values, (typename FEValuesBase::ExcAccessToUninitializedField( "update_values"))); Assert(fe_values->present_cell.is_initialized(), (typename FEValuesBase::ExcNotReinited())); - AssertDimension(fe_function.size(), - fe_values->present_cell.n_dofs_for_dof_handler()); // get function values of dofs on this cell - dealii::Vector dof_values( - fe_values->dofs_per_cell); + dealii::Vector dof_values(fe_values->dofs_per_cell); fe_values->present_cell.get_interpolated_dof_values(fe_function, dof_values); internal::do_function_values( @@ -2368,24 +2356,20 @@ namespace FEValuesViews template - template + template void Tensor<2, dim, spacedim>::get_function_values( - const InputVector &fe_function, - std::vector> &values) - const + const ReadVector & fe_function, + std::vector> &values) const { Assert(fe_values->update_flags & update_values, (typename FEValuesBase::ExcAccessToUninitializedField( "update_values"))); Assert(fe_values->present_cell.is_initialized(), (typename FEValuesBase::ExcNotReinited())); - AssertDimension(fe_function.size(), - fe_values->present_cell.n_dofs_for_dof_handler()); // get function values of dofs on this cell - dealii::Vector dof_values( - fe_values->dofs_per_cell); + dealii::Vector dof_values(fe_values->dofs_per_cell); fe_values->present_cell.get_interpolated_dof_values(fe_function, dof_values); internal::do_function_values( @@ -2645,11 +2629,11 @@ FEValuesBase::CellIteratorContainer::n_dofs_for_dof_handler() template -template +template void FEValuesBase::CellIteratorContainer::get_interpolated_dof_values( - const VectorType & in, - Vector &out) const + const ReadVector &in, + Vector & out) const { Assert(is_initialized(), ExcNotReinited()); Assert(dof_handler != nullptr, ExcNeedsDoFHandler()); @@ -3265,13 +3249,12 @@ namespace internal template -template +template void FEValuesBase::get_function_values( - const InputVector & fe_function, - std::vector &values) const + const ReadVector &fe_function, + std::vector & values) const { - using Number = typename InputVector::value_type; Assert(this->update_flags & update_values, ExcAccessToUninitializedField("update_values")); AssertDimension(fe->n_components(), 1); @@ -3290,24 +3273,22 @@ FEValuesBase::get_function_values( template -template +template void FEValuesBase::get_function_values( - const InputVector & fe_function, + const ReadVector & fe_function, const ArrayView &indices, - std::vector & values) const + std::vector & values) const { - using Number = typename InputVector::value_type; Assert(this->update_flags & update_values, ExcAccessToUninitializedField("update_values")); AssertDimension(fe->n_components(), 1); AssertDimension(indices.size(), dofs_per_cell); boost::container::small_vector dof_values(dofs_per_cell); - for (unsigned int i = 0; i < dofs_per_cell; ++i) - dof_values[i] = internal::get_vector_element(fe_function, indices[i]); - internal::do_function_values(make_array_view(dof_values.begin(), - dof_values.end()), + auto view = make_array_view(dof_values.begin(), dof_values.end()); + fe_function.extract_subvector_to(indices, view); + internal::do_function_values(view, this->finite_element_output.shape_values, values); } @@ -3315,13 +3296,12 @@ FEValuesBase::get_function_values( template -template +template void FEValuesBase::get_function_values( - const InputVector & fe_function, - std::vector> &values) const + const ReadVector & fe_function, + std::vector> &values) const { - using Number = typename InputVector::value_type; Assert(present_cell.is_initialized(), ExcNotReinited()); Assert(this->update_flags & update_values, @@ -3342,14 +3322,13 @@ FEValuesBase::get_function_values( template -template +template void FEValuesBase::get_function_values( - const InputVector & fe_function, - const ArrayView & indices, - std::vector> &values) const + const ReadVector & fe_function, + const ArrayView &indices, + std::vector> & values) const { - using Number = typename InputVector::value_type; // Size of indices must be a multiple of dofs_per_cell such that an integer // number of function values is generated in each point. Assert(indices.size() % dofs_per_cell == 0, @@ -3358,10 +3337,10 @@ FEValuesBase::get_function_values( ExcAccessToUninitializedField("update_values")); boost::container::small_vector dof_values(dofs_per_cell); - for (unsigned int i = 0; i < dofs_per_cell; ++i) - dof_values[i] = internal::get_vector_element(fe_function, indices[i]); + auto view = make_array_view(dof_values.begin(), dof_values.end()); + fe_function.extract_subvector_to(indices, view); internal::do_function_values( - make_array_view(dof_values.begin(), dof_values.end()), + view, this->finite_element_output.shape_values, *fe, this->finite_element_output.shape_function_to_row_table, @@ -3373,15 +3352,14 @@ FEValuesBase::get_function_values( template -template +template void FEValuesBase::get_function_values( - const InputVector & fe_function, - const ArrayView & indices, - ArrayView> values, + const ReadVector & fe_function, + const ArrayView &indices, + ArrayView> values, const bool quadrature_points_fastest) const { - using Number = typename InputVector::value_type; Assert(this->update_flags & update_values, ExcAccessToUninitializedField("update_values")); @@ -3390,11 +3368,11 @@ FEValuesBase::get_function_values( Assert(indices.size() % dofs_per_cell == 0, ExcNotMultiple(indices.size(), dofs_per_cell)); - boost::container::small_vector dof_values(indices.size()); - for (unsigned int i = 0; i < indices.size(); ++i) - dof_values[i] = internal::get_vector_element(fe_function, indices[i]); + boost::container::small_vector dof_values(dofs_per_cell); + auto view = make_array_view(dof_values.begin(), dof_values.end()); + fe_function.extract_subvector_to(indices, view); internal::do_function_values( - make_array_view(dof_values.begin(), dof_values.end()), + view, this->finite_element_output.shape_values, *fe, this->finite_element_output.shape_function_to_row_table, diff --git a/source/fe/fe_values.inst.in b/source/fe/fe_values.inst.in index 04e7ea0aaa..54ba212b8f 100644 --- a/source/fe/fe_values.inst.in +++ b/source/fe/fe_values.inst.in @@ -88,6 +88,65 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS; deal_II_space_dimension>> &); # endif } +for (S : REAL_AND_COMPLEX_SCALARS; deal_II_dimension : DIMENSIONS; + deal_II_space_dimension : SPACE_DIMENSIONS) + { +# if deal_II_dimension <= deal_II_space_dimension + template void + FEValuesViews::Scalar:: + get_function_values(const dealii::ReadVector &, + std::vector::type> &) + const; + + template void + FEValuesViews::Vector:: + get_function_values( + const dealii::ReadVector &, + std::vector< + ProductType>::type> &) + const; + + template void FEValuesViews::SymmetricTensor<2, + deal_II_dimension, + deal_II_space_dimension>:: + get_function_values( + const dealii::ReadVector &, + std::vector>::type> &) const; + + template void + FEValuesViews::Tensor<2, deal_II_dimension, deal_II_space_dimension>:: + get_function_values( + const dealii::ReadVector &, + std::vector< + ProductType>::type> &) + const; + + template void FEValuesBase:: + get_function_values(const ReadVector &, std::vector &) const; + + template void FEValuesBase:: + get_function_values(const ReadVector &, + const ArrayView &, + std::vector &) const; + + template void FEValuesBase:: + get_function_values(const ReadVector &, std::vector> &) + const; + + template void FEValuesBase:: + get_function_values(const ReadVector &, + const ArrayView &, + std::vector> &) const; + + template void FEValuesBase:: + get_function_values(const ReadVector &, + const ArrayView &, + ArrayView>, + bool) const; +# endif + } @@ -96,12 +155,6 @@ for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; { # if deal_II_dimension <= deal_II_space_dimension template void - FEValuesViews::Scalar:: - get_function_values( - const dealii::VEC &, - std::vector::type> &) - const; - template void FEValuesViews::Scalar:: get_function_gradients( const dealii::VEC &, @@ -133,14 +186,6 @@ for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; const; template void - FEValuesViews::Vector:: - get_function_values( - const dealii::VEC &, - std::vector< - ProductType>::type> &) - const; - template void FEValuesViews::Vector:: get_function_gradients( const dealii::VEC &, @@ -192,14 +237,6 @@ for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; dealii::Tensor<4, deal_II_space_dimension>>::type> &) const; - template void FEValuesViews::SymmetricTensor<2, - deal_II_dimension, - deal_II_space_dimension>:: - get_function_values( - const dealii::VEC &, - std::vector>::type> &) const; template void FEValuesViews:: SymmetricTensor<2, deal_II_dimension, deal_II_space_dimension>:: get_function_divergences( @@ -210,14 +247,6 @@ for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; const; template void - FEValuesViews::Tensor<2, deal_II_dimension, deal_II_space_dimension>:: - get_function_values( - const dealii::VEC &, - std::vector< - ProductType>::type> &) - const; - template void FEValuesViews::Tensor<2, deal_II_dimension, deal_II_space_dimension>:: get_function_divergences( const dealii::VEC &, @@ -358,29 +387,6 @@ for (VEC : VECTOR_TYPES; deal_II_dimension : DIMENSIONS; { # if deal_II_dimension <= deal_II_space_dimension - template void FEValuesBase:: - get_function_values(const VEC &, std::vector &) - const; - template void FEValuesBase:: - get_function_values(const VEC &, - const ArrayView &, - std::vector &) const; - - template void FEValuesBase:: - get_function_values(const VEC &, - std::vector> &) const; - - template void FEValuesBase:: - get_function_values(const VEC &, - const ArrayView &, - std::vector> &) const; - - template void FEValuesBase:: - get_function_values(const VEC &, - const ArrayView &, - ArrayView>, - bool) const; - template void FEValuesBase:: get_function_gradients( const VEC &,