From 3e814d21fef948275471518e7ed3642561eebbe1 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sun, 22 Feb 2015 16:14:18 -0600 Subject: [PATCH] Convert FEValuesView::Scalar to allow for generic scalar types. --- include/deal.II/fe/fe_values.h | 32 +++++++- source/fe/fe_values.cc | 117 ++++++++++++++--------------- source/fe/fe_values.decl.1.inst.in | 4 +- source/fe/fe_values.decl.2.inst.in | 4 +- source/fe/fe_values.impl.1.inst.in | 4 +- source/fe/fe_values.impl.2.inst.in | 4 +- source/fe/fe_values.inst.in | 18 ++--- 7 files changed, 101 insertions(+), 82 deletions(-) diff --git a/include/deal.II/fe/fe_values.h b/include/deal.II/fe/fe_values.h index 11e9e7e737..0c55d046cd 100644 --- a/include/deal.II/fe/fe_values.h +++ b/include/deal.II/fe/fe_values.h @@ -264,11 +264,17 @@ namespace FEValuesViews * FEValuesBase::get_function_values function but it only works on the * selected scalar component. * + * The data type stored by the output vector must be what you get + * when you multiply the values of shape function (i.e., @p + * value_type) times the type used to store the values of the + * unknowns $U_j$ of your finite element vector $U$ (represented + * by the @p fe_function argument). + * * @dealiiRequiresUpdateFlags{update_values} */ template void get_function_values (const InputVector &fe_function, - std::vector &values) const; + std::vector::type> &values) const; /** * Return the gradients of the selected scalar component of the finite @@ -280,11 +286,17 @@ namespace FEValuesViews * FEValuesBase::get_function_gradients function but it only works on the * selected scalar component. * + * The data type stored by the output vector must be what you get + * when you multiply the gradients of shape function (i.e., @p + * gradient_type) times the type used to store the values of the + * unknowns $U_j$ of your finite element vector $U$ (represented + * by the @p fe_function argument). + * * @dealiiRequiresUpdateFlags{update_gradients} */ template void get_function_gradients (const InputVector &fe_function, - std::vector &gradients) const; + std::vector::type> &gradients) const; /** * Return the Hessians of the selected scalar component of the finite @@ -296,11 +308,17 @@ namespace FEValuesViews * FEValuesBase::get_function_hessians function but it only works on the * selected scalar component. * + * The data type stored by the output vector must be what you get + * when you multiply the Hessians of shape function (i.e., @p + * hessian_type) times the type used to store the values of the + * unknowns $U_j$ of your finite element vector $U$ (represented + * by the @p fe_function argument). + * * @dealiiRequiresUpdateFlags{update_hessians} */ template void get_function_hessians (const InputVector &fe_function, - std::vector &hessians) const; + std::vector::type> &hessians) const; /** * Return the Laplacians of the selected scalar component of the finite @@ -313,11 +331,17 @@ namespace FEValuesViews * FEValuesBase::get_function_laplacians function but it only works on the * selected scalar component. * + * The data type stored by the output vector must be what you get + * when you multiply the Laplacians of shape function (i.e., @p + * value_type) times the type used to store the values of the + * unknowns $U_j$ of your finite element vector $U$ (represented + * by the @p fe_function argument). + * * @dealiiRequiresUpdateFlags{update_hessians} */ template void get_function_laplacians (const InputVector &fe_function, - std::vector &laplacians) const; + std::vector::type> &laplacians) const; private: /** diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 858f50a69e..04536aff69 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -445,22 +445,16 @@ namespace FEValuesViews namespace internal { - // put the evaluation part of the get_function_xxx from a local vector - // into separate functions. this reduces the size of the compilation unit - // by a factor more than 2 without affecting the performance at all. - - // remark: up to revision 27774, dof_values used to be extracted as - // VectorType::value_type and not simply double. this did not make a lot - // of sense since they were later extracted and converted to double - // consistently throughout the code since revision 17903 at least. + // Given values of degrees of freedom, evaluate the + // values/gradients/... at quadrature points // ------------------------- scalar functions -------------------------- - template + template void - do_function_values (const ::dealii::Vector &dof_values, + do_function_values (const ::dealii::Vector &dof_values, const Table<2,double> &shape_values, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector &values) + std::vector::type> &values) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -488,12 +482,12 @@ namespace FEValuesViews // same code for gradient and Hessian, template argument 'order' to give // the order of the derivative (= rank of gradient/Hessian tensor) - template + template void - do_function_derivatives (const ::dealii::Vector &dof_values, + do_function_derivatives (const ::dealii::Vector &dof_values, const std::vector > > &shape_derivatives, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &derivatives) + std::vector >::type> &derivatives) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -514,18 +508,19 @@ namespace FEValuesViews const dealii::Tensor *shape_derivative_ptr = &shape_derivatives[shape_function_data[shape_function].row_index][0]; for (unsigned int q_point=0; q_point >::type(*shape_derivative_ptr++); } } - template + template void - do_function_laplacians (const ::dealii::Vector &dof_values, + do_function_laplacians (const ::dealii::Vector &dof_values, const std::vector > > &shape_hessians, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector &laplacians) + std::vector::type> &laplacians) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -553,11 +548,11 @@ namespace FEValuesViews // ----------------------------- vector part --------------------------- - template - void do_function_values (const ::dealii::Vector &dof_values, + template + void do_function_values (const ::dealii::Vector &dof_values, const Table<2,double> &shape_values, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &values) + std::vector >::type> &values) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -601,12 +596,12 @@ namespace FEValuesViews - template + template void - do_function_derivatives (const ::dealii::Vector &dof_values, + do_function_derivatives (const ::dealii::Vector &dof_values, const std::vector > > &shape_derivatives, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &derivatives) + std::vector >::type> &derivatives) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -653,12 +648,12 @@ namespace FEValuesViews - template + template void - do_function_symmetric_gradients (const ::dealii::Vector &dof_values, + do_function_symmetric_gradients (const ::dealii::Vector &dof_values, const std::vector > > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &symmetric_gradients) + std::vector >::type> &symmetric_gradients) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -706,12 +701,12 @@ namespace FEValuesViews - template + template void - do_function_divergences (const ::dealii::Vector &dof_values, + do_function_divergences (const ::dealii::Vector &dof_values, const std::vector > > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector &divergences) + std::vector::type> &divergences) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -756,12 +751,12 @@ namespace FEValuesViews - template + template void - do_function_curls (const ::dealii::Vector &dof_values, + do_function_curls (const ::dealii::Vector &dof_values, const std::vector > > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector::type> &curls) + std::vector::type>::type> &curls) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -948,12 +943,12 @@ namespace FEValuesViews - template + template void - do_function_laplacians (const ::dealii::Vector &dof_values, + do_function_laplacians (const ::dealii::Vector &dof_values, const std::vector > > &shape_hessians, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &laplacians) + std::vector >::type> &laplacians) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -1002,12 +997,12 @@ namespace FEValuesViews // ---------------------- symmetric tensor part ------------------------ - template + template void - do_function_values (const ::dealii::Vector &dof_values, + do_function_values (const ::dealii::Vector &dof_values, const dealii::Table<2,double> &shape_values, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &values) + std::vector >::type> &values) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -1056,12 +1051,12 @@ namespace FEValuesViews - template + template void - do_function_divergences (const ::dealii::Vector &dof_values, + do_function_divergences (const ::dealii::Vector &dof_values, const std::vector > > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &divergences) + std::vector >::type> &divergences) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -1144,12 +1139,12 @@ namespace FEValuesViews // ---------------------- non-symmetric tensor part ------------------------ - template + template void - do_function_values (const ::dealii::Vector &dof_values, + do_function_values (const ::dealii::Vector &dof_values, const dealii::Table<2,double> &shape_values, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &values) + std::vector >::type> &values) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -1200,12 +1195,12 @@ namespace FEValuesViews - template + template void - do_function_divergences (const ::dealii::Vector &dof_values, + do_function_divergences (const ::dealii::Vector &dof_values, const std::vector > > &shape_gradients, const std::vector::ShapeFunctionData> &shape_function_data, - std::vector > &divergences) + std::vector >::type> &divergences) { const unsigned int dofs_per_cell = dof_values.size(); const unsigned int n_quadrature_points = dofs_per_cell > 0 ? @@ -1267,7 +1262,7 @@ namespace FEValuesViews void Scalar:: get_function_values (const InputVector &fe_function, - std::vector &values) const + std::vector::type> &values) const { typedef FEValuesBase FVB; Assert (fe_values.update_flags & update_values, @@ -1278,7 +1273,7 @@ namespace FEValuesViews 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 (dof_values, fe_values.shape_values, shape_function_data, values); @@ -1291,7 +1286,7 @@ namespace FEValuesViews void Scalar:: get_function_gradients (const InputVector &fe_function, - std::vector &gradients) const + std::vector::type> &gradients) const { typedef FEValuesBase FVB; Assert (fe_values.update_flags & update_gradients, @@ -1302,7 +1297,7 @@ namespace FEValuesViews 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_derivatives<1,dim,spacedim> (dof_values, fe_values.shape_gradients, shape_function_data, gradients); @@ -1315,7 +1310,7 @@ namespace FEValuesViews void Scalar:: get_function_hessians (const InputVector &fe_function, - std::vector &hessians) const + std::vector::type> &hessians) const { typedef FEValuesBase FVB; Assert (fe_values.update_flags & update_hessians, @@ -1326,7 +1321,7 @@ namespace FEValuesViews 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_derivatives<2,dim,spacedim> (dof_values, fe_values.shape_hessians, shape_function_data, hessians); @@ -1339,7 +1334,7 @@ namespace FEValuesViews void Scalar:: get_function_laplacians (const InputVector &fe_function, - std::vector &laplacians) const + std::vector::type> &laplacians) const { typedef FEValuesBase FVB; Assert (fe_values.update_flags & update_hessians, @@ -1350,7 +1345,7 @@ namespace FEValuesViews 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_laplacians (dof_values, fe_values.shape_hessians, shape_function_data, laplacians); @@ -1769,7 +1764,7 @@ public: virtual void get_interpolated_dof_values (const IndexSet &in, - Vector &out) const = 0; + Vector &out) const = 0; }; @@ -1838,7 +1833,7 @@ public: virtual void get_interpolated_dof_values (const IndexSet &in, - Vector &out) const; + Vector &out) const; private: /** @@ -1941,7 +1936,7 @@ public: virtual void get_interpolated_dof_values (const IndexSet &in, - Vector &out) const; + Vector &out) const; private: /** @@ -2005,7 +2000,7 @@ template void FEValuesBase::CellIterator:: get_interpolated_dof_values (const IndexSet &in, - Vector &out) const + Vector &out) const { Assert (cell->has_children() == false, ExcNotImplemented()); @@ -2065,7 +2060,7 @@ template void FEValuesBase::TriaCellIterator:: get_interpolated_dof_values (const IndexSet &, - Vector &) const + Vector &) const { Assert (false, ExcMessage (message_string)); } diff --git a/source/fe/fe_values.decl.1.inst.in b/source/fe/fe_values.decl.1.inst.in index b27b838016..30129eb20a 100644 --- a/source/fe/fe_values.decl.1.inst.in +++ b/source/fe/fe_values.decl.1.inst.in @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2010 - 2014 by the deal.II authors +// Copyright (C) 2010 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -27,5 +27,5 @@ for (VEC : SERIAL_VECTORS) virtual void get_interpolated_dof_values (const VEC &in, - Vector &out) const = 0; + Vector &out) const = 0; } diff --git a/source/fe/fe_values.decl.2.inst.in b/source/fe/fe_values.decl.2.inst.in index d0ba5103d4..9a91f9830f 100644 --- a/source/fe/fe_values.decl.2.inst.in +++ b/source/fe/fe_values.decl.2.inst.in @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2010 - 2014 by the deal.II authors +// Copyright (C) 2010 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -27,5 +27,5 @@ for (VEC : SERIAL_VECTORS) virtual void get_interpolated_dof_values (const VEC &in, - Vector &out) const; + Vector &out) const; } diff --git a/source/fe/fe_values.impl.1.inst.in b/source/fe/fe_values.impl.1.inst.in index abeca627c6..7dbdc341cf 100644 --- a/source/fe/fe_values.impl.1.inst.in +++ b/source/fe/fe_values.impl.1.inst.in @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2010 - 2014 by the deal.II authors +// Copyright (C) 2010 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -21,7 +21,7 @@ for (VEC : SERIAL_VECTORS) void FEValuesBase::CellIterator:: get_interpolated_dof_values (const VEC &in, - Vector &out) const + Vector &out) const \{ cell->get_interpolated_dof_values (in, out); \} diff --git a/source/fe/fe_values.impl.2.inst.in b/source/fe/fe_values.impl.2.inst.in index 363bff5a85..5aa37dbc4d 100644 --- a/source/fe/fe_values.impl.2.inst.in +++ b/source/fe/fe_values.impl.2.inst.in @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 2010 - 2014 by the deal.II authors +// Copyright (C) 2010 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -20,7 +20,7 @@ for (VEC : SERIAL_VECTORS) void FEValuesBase::TriaCellIterator:: get_interpolated_dof_values (const VEC &, - Vector &) const + Vector &) const \{ Assert (false, ExcMessage (message_string)); \} diff --git a/source/fe/fe_values.inst.in b/source/fe/fe_values.inst.in index fb06243521..61716fa11f 100644 --- a/source/fe/fe_values.inst.in +++ b/source/fe/fe_values.inst.in @@ -1,6 +1,6 @@ // --------------------------------------------------------------------- // -// Copyright (C) 1998 - 2014 by the deal.II authors +// Copyright (C) 1998 - 2015 by the deal.II authors // // This file is part of the deal.II library. // @@ -70,19 +70,19 @@ for (VEC : SERIAL_VECTORS; deal_II_dimension : DIMENSIONS; deal_II_space_dimensi template void FEValuesViews::Scalar ::get_function_values - (const dealii::VEC&, std::vector&) const; + (const dealii::VEC&, std::vector::type>&) const; template void FEValuesViews::Scalar ::get_function_gradients - (const dealii::VEC&, std::vector >&) const; + (const dealii::VEC&, std::vector>::type>&) const; template void FEValuesViews::Scalar ::get_function_hessians - (const dealii::VEC&, std::vector >&) const; + (const dealii::VEC&, std::vector>::type>&) const; template void FEValuesViews::Scalar ::get_function_laplacians - (const dealii::VEC&, std::vector&) const; + (const dealii::VEC&, std::vector::type> &) const; template void FEValuesViews::Vector @@ -261,16 +261,16 @@ for (deal_II_dimension : DIMENSIONS) #if (deal_II_dimension == DIM_A) || (deal_II_dimension == DIM_B) template void FEValuesViews::Scalar::get_function_values - (const dealii::IndexSet&, std::vector&) const; + (const dealii::IndexSet&, std::vector::type> &) const; template void FEValuesViews::Scalar::get_function_gradients - (const dealii::IndexSet&, std::vector >&) const; + (const dealii::IndexSet&, std::vector >::type>&) const; template void FEValuesViews::Scalar::get_function_hessians - (const dealii::IndexSet&, std::vector >&) const; + (const dealii::IndexSet&, std::vector >::type>&) const; template void FEValuesViews::Scalar::get_function_laplacians - (const dealii::IndexSet&, std::vector&) const; + (const dealii::IndexSet&, std::vector::type>&) const; template void FEValuesViews::Vector::get_function_values -- 2.39.5