From 5448e171c125f40140a6aa2a9fb72fa9a67bd085 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 22 Dec 2015 16:31:56 -0600 Subject: [PATCH] Convert internal vector> to Table<2,T>. This should improve data locality and simplify memory management. --- include/deal.II/fe/fe_poly.templates.h | 18 ++++----- include/deal.II/fe/fe_update_flags.h | 6 +-- include/deal.II/fe/fe_values.h | 12 ------ source/fe/fe_poly.cc | 24 ++++++------ source/fe/fe_values.cc | 54 ++++++++++++++------------ 5 files changed, 54 insertions(+), 60 deletions(-) diff --git a/include/deal.II/fe/fe_poly.templates.h b/include/deal.II/fe/fe_poly.templates.h index 945bf378f5..30df2b076e 100644 --- a/include/deal.II/fe/fe_poly.templates.h +++ b/include/deal.II/fe/fe_poly.templates.h @@ -262,7 +262,7 @@ fill_fe_values (const typename Triangulation::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_gradients[k]), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (flags & update_hessians && cell_similarity != CellSimilarity::translation) { @@ -270,7 +270,7 @@ fill_fe_values (const typename Triangulation::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_hessians[k]), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_3rd_derivatives[k]), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); @@ -340,7 +340,7 @@ fill_fe_face_values (const typename Triangulation::cell_iterator mapping.transform (ArrayView >(&fe_data.shape_gradients[k][offset], quadrature.size()), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (flags & update_hessians) { @@ -349,7 +349,7 @@ fill_fe_face_values (const typename Triangulation::cell_iterator quadrature.size()), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterator quadrature.size()), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); @@ -423,7 +423,7 @@ fill_fe_subface_values (const typename Triangulation::cell_iterato quadrature.size()), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (flags & update_hessians) { @@ -432,7 +432,7 @@ fill_fe_subface_values (const typename Triangulation::cell_iterato quadrature.size()), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterato quadrature.size()), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); diff --git a/include/deal.II/fe/fe_update_flags.h b/include/deal.II/fe/fe_update_flags.h index 84d473ddff..cd322cbfa0 100644 --- a/include/deal.II/fe/fe_update_flags.h +++ b/include/deal.II/fe/fe_update_flags.h @@ -528,17 +528,17 @@ namespace internal * Storage type for gradients. The layout of data is the same as for the * #ShapeVector data type. */ - typedef std::vector > > GradientVector; + typedef dealii::Table<2,Tensor<1,spacedim> > GradientVector; /** * Likewise for second order derivatives. */ - typedef std::vector > > HessianVector; + typedef dealii::Table<2,Tensor<2,spacedim> > HessianVector; /** * And the same also applies to the third order derivatives. */ - typedef std::vector > > ThirdDerivativeVector; + typedef dealii::Table<2,Tensor<3,spacedim> > ThirdDerivativeVector; /** * Store the values of the shape functions at the quadrature points. See the diff --git a/include/deal.II/fe/fe_values.h b/include/deal.II/fe/fe_values.h index 02fcf60520..495822167b 100644 --- a/include/deal.II/fe/fe_values.h +++ b/include/deal.II/fe/fe_values.h @@ -4140,10 +4140,6 @@ FEValuesBase::shape_grad (const unsigned int i, ExcAccessToUninitializedField("update_gradients")); Assert (fe->is_primitive (i), ExcShapeFunctionNotPrimitive(i)); - Assert (ifinite_element_output.shape_gradients.size(), - ExcIndexRange (i, 0, this->finite_element_output.shape_gradients.size())); - Assert (jfinite_element_output.shape_gradients[0].size(), - ExcIndexRange (j, 0, this->finite_element_output.shape_gradients[0].size())); // if the entire FE is primitive, // then we can take a short-cut: @@ -4209,10 +4205,6 @@ FEValuesBase::shape_hessian (const unsigned int i, ExcAccessToUninitializedField("update_hessians")); Assert (fe->is_primitive (i), ExcShapeFunctionNotPrimitive(i)); - Assert (ifinite_element_output.shape_hessians.size(), - ExcIndexRange (i, 0, this->finite_element_output.shape_hessians.size())); - Assert (jfinite_element_output.shape_hessians[0].size(), - ExcIndexRange (j, 0, this->finite_element_output.shape_hessians[0].size())); // if the entire FE is primitive, // then we can take a short-cut: @@ -4278,10 +4270,6 @@ FEValuesBase::shape_3rd_derivative (const unsigned int i, ExcAccessToUninitializedField("update_3rd_derivatives")); Assert (fe->is_primitive (i), ExcShapeFunctionNotPrimitive(i)); - Assert (ifinite_element_output.shape_3rd_derivatives.size(), - ExcIndexRange (i, 0, this->finite_element_output.shape_3rd_derivatives.size())); - Assert (jfinite_element_output.shape_3rd_derivatives[0].size(), - ExcIndexRange (j, 0, this->finite_element_output.shape_3rd_derivatives[0].size())); // if the entire FE is primitive, // then we can take a short-cut: diff --git a/source/fe/fe_poly.cc b/source/fe/fe_poly.cc index c3c4c091a0..e9c78aedcb 100644 --- a/source/fe/fe_poly.cc +++ b/source/fe/fe_poly.cc @@ -55,7 +55,7 @@ fill_fe_values (const Triangulation<1,2>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_gradients[k]), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (fe_data.update_each & update_hessians && cell_similarity != CellSimilarity::translation) { @@ -63,7 +63,7 @@ fill_fe_values (const Triangulation<1,2>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_hessians[k]), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_3rd_derivatives[k]), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); @@ -114,7 +114,7 @@ fill_fe_values (const Triangulation<2,3>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_gradients[k]), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (fe_data.update_each & update_hessians && cell_similarity != CellSimilarity::translation) { @@ -122,7 +122,7 @@ fill_fe_values (const Triangulation<2,3>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_hessians[k]), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_3rd_derivatives[k]), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); @@ -174,7 +174,7 @@ fill_fe_values (const Triangulation<1,2>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_gradients[k]), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (fe_data.update_each & update_hessians && cell_similarity != CellSimilarity::translation) { @@ -182,7 +182,7 @@ fill_fe_values (const Triangulation<1,2>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_hessians[k]), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_3rd_derivatives[k]), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); @@ -229,7 +229,7 @@ fill_fe_values (const Triangulation<2,3>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_gradients[k]), mapping_covariant, mapping_internal, - make_array_view(output_data.shape_gradients[k])); + make_array_view(output_data.shape_gradients, k)); if (fe_data.update_each & update_hessians && cell_similarity != CellSimilarity::translation) { @@ -237,7 +237,7 @@ fill_fe_values (const Triangulation<2,3>::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_hessians[k]), mapping_covariant_gradient, mapping_internal, - make_array_view(output_data.shape_hessians[k])); + make_array_view(output_data.shape_hessians, k)); for (unsigned int k=0; kdofs_per_cell; ++k) for (unsigned int i=0; i::cell_iterator &, mapping.transform (make_array_view(fe_data.shape_3rd_derivatives[k]), mapping_covariant_hessian, mapping_internal, - make_array_view(output_data.shape_3rd_derivatives[k])); + make_array_view(output_data.shape_3rd_derivatives, k)); for (unsigned int k=0; kdofs_per_cell; ++k) correct_third_derivatives(output_data, mapping_data, quadrature.size(), k); diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 17165b7226..4392910aea 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -487,7 +487,7 @@ namespace FEValuesViews template void do_function_derivatives (const ::dealii::Vector &dof_values, - const std::vector > > &shape_derivatives, + const Table<2,dealii::Tensor > &shape_derivatives, const std::vector::ShapeFunctionData> &shape_function_data, std::vector >::type> &derivatives) { @@ -520,7 +520,7 @@ namespace FEValuesViews template void do_function_laplacians (const ::dealii::Vector &dof_values, - const std::vector > > &shape_hessians, + const Table<2,dealii::Tensor<2,spacedim> > &shape_hessians, const std::vector::ShapeFunctionData> &shape_function_data, std::vector::type> &laplacians) { @@ -601,7 +601,7 @@ namespace FEValuesViews template void do_function_derivatives (const ::dealii::Vector &dof_values, - const std::vector > > &shape_derivatives, + const Table<2,dealii::Tensor > &shape_derivatives, const std::vector::ShapeFunctionData> &shape_function_data, std::vector >::type> &derivatives) { @@ -655,7 +655,7 @@ namespace FEValuesViews template void do_function_symmetric_gradients (const ::dealii::Vector &dof_values, - const std::vector > > &shape_gradients, + const Table<2,dealii::Tensor<1,spacedim> > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, std::vector >::type> &symmetric_gradients) { @@ -708,7 +708,7 @@ namespace FEValuesViews template void do_function_divergences (const ::dealii::Vector &dof_values, - const std::vector > > &shape_gradients, + const Table<2,dealii::Tensor<1,spacedim> > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, std::vector::type> &divergences) { @@ -758,7 +758,7 @@ namespace FEValuesViews template void do_function_curls (const ::dealii::Vector &dof_values, - const std::vector > > &shape_gradients, + const Table<2,dealii::Tensor<1,spacedim> > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, std::vector::type>::type> &curls) { @@ -950,7 +950,7 @@ namespace FEValuesViews template void do_function_laplacians (const ::dealii::Vector &dof_values, - const std::vector > > &shape_hessians, + const Table<2,dealii::Tensor<2,spacedim> > &shape_hessians, const std::vector::ShapeFunctionData> &shape_function_data, std::vector >::type> &laplacians) { @@ -1058,7 +1058,7 @@ namespace FEValuesViews template void do_function_divergences (const ::dealii::Vector &dof_values, - const std::vector > > &shape_gradients, + const Table<2,dealii::Tensor<1,spacedim> > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, std::vector >::type> &divergences) { @@ -1202,7 +1202,7 @@ namespace FEValuesViews template void do_function_divergences (const ::dealii::Vector &dof_values, - const std::vector > > &shape_gradients, + const Table<2,dealii::Tensor<1,spacedim> > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, std::vector >::type> &divergences) { @@ -2230,19 +2230,25 @@ namespace internal } if (flags & update_gradients) - this->shape_gradients.resize (n_nonzero_shape_components, - std::vector > (n_quadrature_points, - numbers::signaling_nan >())); + { + this->shape_gradients.reinit(n_nonzero_shape_components, + n_quadrature_points); + this->shape_gradients.fill (numbers::signaling_nan >()); + } if (flags & update_hessians) - this->shape_hessians.resize (n_nonzero_shape_components, - std::vector > (n_quadrature_points, - numbers::signaling_nan >())); + { + this->shape_hessians.reinit(n_nonzero_shape_components, + n_quadrature_points); + this->shape_hessians.fill (numbers::signaling_nan >()); + } if (flags & update_3rd_derivatives) - this->shape_3rd_derivatives.resize (n_nonzero_shape_components, - std::vector > (n_quadrature_points, - numbers::signaling_nan >())); + { + this->shape_3rd_derivatives.reinit(n_nonzero_shape_components, + n_quadrature_points); + this->shape_3rd_derivatives.fill (numbers::signaling_nan >()); + } } @@ -2440,10 +2446,10 @@ namespace internal template void do_function_derivatives (const Number *dof_values_ptr, - const std::vector > > &shape_derivatives, + const dealii::Table<2,Tensor > &shape_derivatives, std::vector > &derivatives) { - const unsigned int dofs_per_cell = shape_derivatives.size(); + const unsigned int dofs_per_cell = shape_derivatives.size()[0]; const unsigned int n_quadrature_points = dofs_per_cell > 0 ? shape_derivatives[0].size() : derivatives.size(); AssertDimension(derivatives.size(), n_quadrature_points); @@ -2475,7 +2481,7 @@ namespace internal template void do_function_derivatives (const Number *dof_values_ptr, - const std::vector > > &shape_derivatives, + const dealii::Table<2,Tensor > &shape_derivatives, const FiniteElement &fe, const std::vector &shape_function_to_row_table, VectorSlice > > > &derivatives, @@ -2571,10 +2577,10 @@ namespace internal template void do_function_laplacians (const Number2 *dof_values_ptr, - const std::vector > > &shape_hessians, + const dealii::Table<2,Tensor<2,spacedim> > &shape_hessians, std::vector &laplacians) { - const unsigned int dofs_per_cell = shape_hessians.size(); + const unsigned int dofs_per_cell = shape_hessians.size()[0]; const unsigned int n_quadrature_points = dofs_per_cell > 0 ? shape_hessians[0].size() : laplacians.size(); AssertDimension(laplacians.size(), n_quadrature_points); @@ -2601,7 +2607,7 @@ namespace internal template void do_function_laplacians (const Number *dof_values_ptr, - const std::vector > > &shape_hessians, + const dealii::Table<2,Tensor<2,spacedim> > &shape_hessians, const FiniteElement &fe, const std::vector &shape_function_to_row_table, std::vector &laplacians, -- 2.39.5