From 22512b1e753ae56fc060a9b17fd2ba052669c0d1 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 23 Jul 2015 17:07:07 -0500 Subject: [PATCH] Simplify code. There are a couple of places where we call a get_data() function that returns a pointer to a base class when we know that the actual data type is a pointer to derived class. We need to cast right back to the derived class. This can be avoided by using covariant return types where the get_data() function returns a pointer to derived right away. --- include/deal.II/fe/mapping_q.h | 12 +++++++++++- include/deal.II/fe/mapping_q1.h | 12 +++++++++++- source/fe/mapping_q.cc | 12 +++++------- source/fe/mapping_q1.cc | 20 ++++++++------------ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/include/deal.II/fe/mapping_q.h b/include/deal.II/fe/mapping_q.h index ff30ce782d..75a3b3e8d3 100644 --- a/include/deal.II/fe/mapping_q.h +++ b/include/deal.II/fe/mapping_q.h @@ -298,8 +298,18 @@ private: std::vector > &points) const; + /** + * Implementation of the Mapping::get_data() interface. + * + * As allowed by C++ (using a feature called "covariant return + * types"), this function returns a pointer to a + * MappingQ::InternalData object since these objects are + * derived from the Mapping::InternalDataBase class, pointers to + * which are returned by the Mapping::get_data() function. This + * makes some uses of this function simpler. + */ virtual - typename Mapping::InternalDataBase * + InternalData * get_data (const UpdateFlags, const Quadrature &quadrature) const; diff --git a/include/deal.II/fe/mapping_q1.h b/include/deal.II/fe/mapping_q1.h index 5ac2510d8b..57da023f1c 100644 --- a/include/deal.II/fe/mapping_q1.h +++ b/include/deal.II/fe/mapping_q1.h @@ -538,8 +538,18 @@ private: */ virtual UpdateFlags update_each (const UpdateFlags flags) const; + /** + * Implementation of the Mapping::get_data() interface. + * + * As allowed by C++ (using a feature called "covariant return + * types"), this function returns a pointer to a + * MappingQ1::InternalData object since these objects are + * derived from the Mapping::InternalDataBase class, pointers to + * which are returned by the Mapping::get_data() function. This + * makes some uses of this function simpler. + */ virtual - typename Mapping::InternalDataBase * + InternalData * get_data (const UpdateFlags, const Quadrature &quadrature) const; diff --git a/source/fe/mapping_q.cc b/source/fe/mapping_q.cc index d3ab675169..18047e52e7 100644 --- a/source/fe/mapping_q.cc +++ b/source/fe/mapping_q.cc @@ -194,7 +194,7 @@ MappingQ::compute_shapes_virtual (const std::vector > & template -typename Mapping::InternalDataBase * +typename MappingQ::InternalData * MappingQ::get_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { @@ -1044,9 +1044,8 @@ transform_unit_to_real_cell (const typename Triangulation::cell_it // the right size and transformation shape values already computed at point // p. const Quadrature point_quadrature(p); - std_cxx11::unique_ptr - mdata (dynamic_cast ( - get_data(update_transformation_values, point_quadrature))); + std_cxx11::unique_ptr mdata (get_data(update_transformation_values, + point_quadrature)); mdata->use_mapping_q1_on_current_cell = !(use_mapping_q_on_all_cells || cell->has_boundary_lines()); @@ -1130,9 +1129,8 @@ transform_real_to_unit_cell (const typename Triangulation::cell_it UpdateFlags update_flags = update_transformation_values|update_transformation_gradients; if (spacedim>dim) update_flags |= update_jacobian_grads; - std_cxx11::unique_ptr - mdata (dynamic_cast ( - get_data(update_flags,point_quadrature))); + std_cxx11::unique_ptr mdata (get_data(update_flags, + point_quadrature)); mdata->use_mapping_q1_on_current_cell = false; diff --git a/source/fe/mapping_q1.cc b/source/fe/mapping_q1.cc index 73dea53ebf..f2b6ce4537 100644 --- a/source/fe/mapping_q1.cc +++ b/source/fe/mapping_q1.cc @@ -491,7 +491,7 @@ MappingQ1::compute_data (const UpdateFlags update_flags, template -typename Mapping::InternalDataBase * +typename MappingQ1::InternalData * MappingQ1::get_data (const UpdateFlags update_flags, const Quadrature &q) const { @@ -1427,16 +1427,13 @@ MappingQ1::transform_unit_to_real_cell ( const typename Triangulation::cell_iterator &cell, const Point &p) const { - // Use the get_data function to - // create an InternalData with data - // vectors of the right size and - // transformation shape values - // already computed at point p. + // Use the get_data function to create an InternalData with data + // vectors of the right size and transformation shape values already + // computed at point p. const Quadrature point_quadrature(p); - std_cxx11::unique_ptr - mdata (dynamic_cast ( - get_data(update_transformation_values, point_quadrature))); + std_cxx11::unique_ptr mdata (get_data(update_transformation_values, + point_quadrature)); // compute the mapping support // points @@ -1670,9 +1667,8 @@ transform_real_to_unit_cell (const typename Triangulation::cell_it if (spacedim>dim) update_flags |= update_jacobian_grads; - std_cxx11::unique_ptr - mdata(dynamic_cast ( - MappingQ1::get_data(update_flags, point_quadrature))); + std_cxx11::unique_ptr mdata(get_data(update_flags, + point_quadrature)); compute_mapping_support_points (cell, mdata->mapping_support_points); // The support points have to be at -- 2.39.5