From d9af8621d6e22d93486899de37e50bc5f91207b6 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Tue, 3 Apr 2018 23:55:10 +0200 Subject: [PATCH] Use dynamic_unique_cast --- include/deal.II/fe/fe_enriched.h | 4 ++-- source/fe/fe_enriched.cc | 21 ++++++++++----------- source/fe/mapping_q.cc | 1 - source/fe/mapping_q_generic.cc | 28 ++++++++++++++-------------- 4 files changed, 26 insertions(+), 28 deletions(-) diff --git a/include/deal.II/fe/fe_enriched.h b/include/deal.II/fe/fe_enriched.h index 8e6bc535ec..0bb960451b 100644 --- a/include/deal.II/fe/fe_enriched.h +++ b/include/deal.II/fe/fe_enriched.h @@ -476,7 +476,7 @@ protected: * ownership), we store the cast result in a std::unique_ptr to indicate * that InternalData owns the object. */ - InternalData ( std::unique_ptr::InternalData> fesystem_data); + InternalData (std::unique_ptr::InternalData> fesystem_data); /** * Give read-access to the pointer to a @p InternalData of the @p @@ -553,7 +553,7 @@ protected: */ template std::unique_ptr::InternalDataBase> - setup_data (std::unique_ptr::InternalDataBase> &&fes_data, + setup_data (std::unique_ptr::InternalData> fes_data, const UpdateFlags flags, const Quadrature &quadrature) const; diff --git a/source/fe/fe_enriched.cc b/source/fe/fe_enriched.cc index 164daa8a2f..67f191c078 100644 --- a/source/fe/fe_enriched.cc +++ b/source/fe/fe_enriched.cc @@ -289,21 +289,17 @@ FE_Enriched::requires_update_flags (const UpdateFlags flags) const template template std::unique_ptr::InternalDataBase> -FE_Enriched::setup_data (std::unique_ptr::InternalDataBase> &&fes_data, +FE_Enriched::setup_data (std::unique_ptr::InternalData> fes_data, const UpdateFlags flags, const Quadrature &quadrature) const { - Assert ((dynamic_cast::InternalData *> (fes_data.get()) != nullptr), - ExcInternalError()); - // Pass ownership of the FiniteElement::InternalDataBase object // that fes_data points to, to the new InternalData object. - typename FESystem::InternalData *data_fesystem = - static_cast::InternalData *> (fes_data.release()); - auto data = std_cxx14::make_unique(std::unique_ptr::InternalData>(data_fesystem)); + auto update_each_flags = fes_data->update_each; + auto data = std_cxx14::make_unique(std::move(fes_data)); // copy update_each from FESystem data: - data->update_each = data_fesystem->update_each; + data->update_each = update_each_flags; // resize cache array according to requested flags data->enrichment.resize(this->n_base_elements()); @@ -337,7 +333,8 @@ FE_Enriched::get_face_data (const UpdateFlags update_flags, const Quadrature &quadrature, internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const { - return setup_data(std::unique_ptr::InternalDataBase>(fe_system->get_face_data(update_flags,mapping,quadrature,output_data)), + auto data = fe_system->get_face_data(update_flags,mapping,quadrature,output_data); + return setup_data(Utilities::dynamic_unique_cast::InternalData>(std::move(data)), update_flags, quadrature); } @@ -350,7 +347,8 @@ FE_Enriched::get_subface_data (const UpdateFlags update_flags const Quadrature &quadrature, dealii::internal::FEValuesImplementation::FiniteElementRelatedData &output_data) const { - return setup_data(std::unique_ptr::InternalDataBase>(fe_system->get_subface_data(update_flags,mapping,quadrature,output_data)), + auto data = fe_system->get_subface_data(update_flags,mapping,quadrature,output_data); + return setup_data(Utilities::dynamic_unique_cast::InternalData>(std::move(data)), update_flags, quadrature); } @@ -363,7 +361,8 @@ FE_Enriched::get_data (const UpdateFlags flags, const Quadrature &quadrature, internal::FEValuesImplementation::FiniteElementRelatedData< dim, spacedim > &output_data) const { - return setup_data(std::unique_ptr::InternalDataBase>(fe_system->get_data(flags,mapping,quadrature,output_data)), + auto data = fe_system->get_data(flags,mapping,quadrature,output_data); + return setup_data(Utilities::dynamic_unique_cast::InternalData>(std::move(data)), flags, quadrature); } diff --git a/source/fe/mapping_q.cc b/source/fe/mapping_q.cc index 136dc8e7ab..58647c239d 100644 --- a/source/fe/mapping_q.cc +++ b/source/fe/mapping_q.cc @@ -164,7 +164,6 @@ MappingQ::get_data (const UpdateFlags update_flags, // wait for the task above to finish and use returned value data->mapping_qp_data = Utilities::dynamic_unique_cast::InternalData> (std::move(do_get_data.return_value())); - return std::move(data); } diff --git a/source/fe/mapping_q_generic.cc b/source/fe/mapping_q_generic.cc index 077f0c07c3..80db371403 100644 --- a/source/fe/mapping_q_generic.cc +++ b/source/fe/mapping_q_generic.cc @@ -2222,8 +2222,8 @@ Point<1> MappingQGeneric<1,1>:: transform_real_to_unit_cell_internal (const Triangulation<1,1>::cell_iterator &cell, - const Point<1> &p, - const Point<1> &initial_p_unit) const + const Point<1> &p, + const Point<1> &initial_p_unit) const { const int dim = 1; const int spacedim = 1; @@ -2233,8 +2233,8 @@ transform_real_to_unit_cell_internal UpdateFlags update_flags = update_quadrature_points | update_jacobians; if (spacedim>dim) update_flags |= update_jacobian_grads; - std::unique_ptr mdata (dynamic_cast(get_data(update_flags, - point_quadrature).release())); + auto mdata = Utilities::dynamic_unique_cast(get_data(update_flags, + point_quadrature)); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2248,8 +2248,8 @@ Point<2> MappingQGeneric<2, 2>:: transform_real_to_unit_cell_internal (const Triangulation<2, 2>::cell_iterator &cell, - const Point<2> &p, - const Point<2> &initial_p_unit) const + const Point<2> &p, + const Point<2> &initial_p_unit) const { const int dim = 2; const int spacedim = 2; @@ -2259,8 +2259,8 @@ transform_real_to_unit_cell_internal UpdateFlags update_flags = update_quadrature_points | update_jacobians; if (spacedim>dim) update_flags |= update_jacobian_grads; - std::unique_ptr mdata (dynamic_cast(get_data(update_flags, - point_quadrature).release())); + auto mdata = Utilities::dynamic_unique_cast(get_data(update_flags, + point_quadrature)); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2285,8 +2285,8 @@ transform_real_to_unit_cell_internal UpdateFlags update_flags = update_quadrature_points | update_jacobians; if (spacedim>dim) update_flags |= update_jacobian_grads; - std::unique_ptr mdata (dynamic_cast(get_data(update_flags, - point_quadrature).release())); + auto mdata = Utilities::dynamic_unique_cast(get_data(update_flags, + point_quadrature)); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2313,8 +2313,8 @@ transform_real_to_unit_cell_internal UpdateFlags update_flags = update_quadrature_points | update_jacobians; if (spacedim>dim) update_flags |= update_jacobian_grads; - std::unique_ptr mdata (dynamic_cast(get_data(update_flags, - point_quadrature).release())); + auto mdata = Utilities::dynamic_unique_cast(get_data(update_flags, + point_quadrature)); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2341,8 +2341,8 @@ transform_real_to_unit_cell_internal UpdateFlags update_flags = update_quadrature_points | update_jacobians; if (spacedim>dim) update_flags |= update_jacobian_grads; - std::unique_ptr mdata (dynamic_cast(get_data(update_flags, - point_quadrature).release())); + auto mdata = Utilities::dynamic_unique_cast(get_data(update_flags, + point_quadrature)); mdata->mapping_support_points = this->compute_mapping_support_points (cell); -- 2.39.5