From: Wolfgang Bangerth Date: Thu, 29 Mar 2018 01:43:45 +0000 (-0600) Subject: Convert the various Mapping::get_*_data() functions to return std::unique_ptr. X-Git-Tag: v9.0.0-rc1~249^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F6115%2Fhead;p=dealii.git Convert the various Mapping::get_*_data() functions to return std::unique_ptr. This required a number of adjustments in places where we used the fact that we used covariant return types all over the place. We can't do this any more, and so in a number of places we have to convert things by hand back to the (known) derived type. --- diff --git a/include/deal.II/fe/mapping.h b/include/deal.II/fe/mapping.h index 43909e94fc..d8ccca1377 100644 --- a/include/deal.II/fe/mapping.h +++ b/include/deal.II/fe/mapping.h @@ -646,7 +646,7 @@ protected: * the returned object, knowing its real (derived) type. */ virtual - InternalDataBase * + std::unique_ptr get_data (const UpdateFlags update_flags, const Quadrature &quadrature) const = 0; @@ -678,7 +678,7 @@ protected: * the returned object, knowing its real (derived) type. */ virtual - InternalDataBase * + std::unique_ptr get_face_data (const UpdateFlags update_flags, const Quadrature &quadrature) const = 0; @@ -711,7 +711,7 @@ protected: * the returned object, knowing its real (derived) type. */ virtual - InternalDataBase * + std::unique_ptr get_subface_data (const UpdateFlags update_flags, const Quadrature &quadrature) const = 0; diff --git a/include/deal.II/fe/mapping_cartesian.h b/include/deal.II/fe/mapping_cartesian.h index a4e2d1dea5..00941fcec8 100644 --- a/include/deal.II/fe/mapping_cartesian.h +++ b/include/deal.II/fe/mapping_cartesian.h @@ -200,19 +200,19 @@ private: // documentation can be found in Mapping::get_data() virtual - typename Mapping::InternalDataBase * + std::unique_ptr::InternalDataBase> get_data (const UpdateFlags, const Quadrature &quadrature) const override; // documentation can be found in Mapping::get_face_data() virtual - typename Mapping::InternalDataBase * + std::unique_ptr::InternalDataBase> get_face_data (const UpdateFlags flags, const Quadrature& quadrature) const override; // documentation can be found in Mapping::get_subface_data() virtual - typename Mapping::InternalDataBase * + std::unique_ptr::InternalDataBase> get_subface_data (const UpdateFlags flags, const Quadrature& quadrature) const override; diff --git a/include/deal.II/fe/mapping_fe_field.h b/include/deal.II/fe/mapping_fe_field.h index b8cf1f593b..c7235ef21e 100644 --- a/include/deal.II/fe/mapping_fe_field.h +++ b/include/deal.II/fe/mapping_fe_field.h @@ -445,19 +445,19 @@ private: // documentation can be found in Mapping::get_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_data (const UpdateFlags, const Quadrature &quadrature) const override; // documentation can be found in Mapping::get_face_data() virtual - typename Mapping::InternalDataBase * + std::unique_ptr::InternalDataBase> get_face_data (const UpdateFlags flags, const Quadrature& quadrature) const override; // documentation can be found in Mapping::get_subface_data() virtual - typename Mapping::InternalDataBase * + std::unique_ptr::InternalDataBase> get_subface_data (const UpdateFlags flags, const Quadrature& quadrature) const override; diff --git a/include/deal.II/fe/mapping_manifold.h b/include/deal.II/fe/mapping_manifold.h index 080f5606c7..8114da8670 100644 --- a/include/deal.II/fe/mapping_manifold.h +++ b/include/deal.II/fe/mapping_manifold.h @@ -341,19 +341,19 @@ public: // documentation can be found in Mapping::get_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_data (const UpdateFlags, const Quadrature &quadrature) const override; // documentation can be found in Mapping::get_face_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_face_data (const UpdateFlags flags, const Quadrature& quadrature) const override; // documentation can be found in Mapping::get_subface_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_subface_data (const UpdateFlags flags, const Quadrature& quadrature) const override; diff --git a/include/deal.II/fe/mapping_q.h b/include/deal.II/fe/mapping_q.h index 16c0d25254..95d2fcbe45 100644 --- a/include/deal.II/fe/mapping_q.h +++ b/include/deal.II/fe/mapping_q.h @@ -277,19 +277,19 @@ protected: // documentation can be found in Mapping::get_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_data (const UpdateFlags, const Quadrature &quadrature) const override; // documentation can be found in Mapping::get_face_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_face_data (const UpdateFlags flags, const Quadrature& quadrature) const override; // documentation can be found in Mapping::get_subface_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_subface_data (const UpdateFlags flags, const Quadrature& quadrature) const override; diff --git a/include/deal.II/fe/mapping_q_generic.h b/include/deal.II/fe/mapping_q_generic.h index 2465adf57c..1effee1047 100644 --- a/include/deal.II/fe/mapping_q_generic.h +++ b/include/deal.II/fe/mapping_q_generic.h @@ -534,19 +534,19 @@ public: // documentation can be found in Mapping::get_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_data (const UpdateFlags, const Quadrature &quadrature) const override; // documentation can be found in Mapping::get_face_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_face_data (const UpdateFlags flags, const Quadrature& quadrature) const override; // documentation can be found in Mapping::get_subface_data() virtual - InternalData * + std::unique_ptr::InternalDataBase> get_subface_data (const UpdateFlags flags, const Quadrature& quadrature) const override; diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index eddc47f642..c02b0f01cd 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -3964,8 +3964,8 @@ FEValues::initialize (const UpdateFlags update_flags) *this->mapping, quadrature, this->finite_element_output); - Threads::Task::InternalDataBase * > - mapping_get_data; + Threads::Task::InternalDataBase>> + mapping_get_data; if (flags & update_mapping) mapping_get_data = Threads::new_task (&Mapping::get_data, *this->mapping, @@ -3977,7 +3977,7 @@ FEValues::initialize (const UpdateFlags update_flags) // then collect answers from the two task above this->fe_data = std::move(fe_get_data.return_value()); if (flags & update_mapping) - this->mapping_data.reset (mapping_get_data.return_value()); + this->mapping_data = std::move(mapping_get_data.return_value()); else this->mapping_data = std_cxx14::make_unique::InternalDataBase> (); } @@ -4214,8 +4214,8 @@ FEFaceValues::initialize (const UpdateFlags update_flags) *this->mapping, this->quadrature, this->finite_element_output); - Threads::Task::InternalDataBase *> - mapping_get_data; + Threads::Task::InternalDataBase>> + mapping_get_data; if (flags & update_mapping) mapping_get_data = Threads::new_task (&Mapping::get_face_data, *this->mapping, @@ -4227,7 +4227,7 @@ FEFaceValues::initialize (const UpdateFlags update_flags) // then collect answers from the two task above this->fe_data = std::move(fe_get_data.return_value()); if (flags & update_mapping) - this->mapping_data.reset (mapping_get_data.return_value()); + this->mapping_data = std::move(mapping_get_data.return_value()); else this->mapping_data = std_cxx14::make_unique::InternalDataBase> (); } @@ -4382,8 +4382,8 @@ FESubfaceValues::initialize (const UpdateFlags update_flags) *this->mapping, this->quadrature, this->finite_element_output); - Threads::Task::InternalDataBase *> - mapping_get_data; + Threads::Task::InternalDataBase>> + mapping_get_data; if (flags & update_mapping) mapping_get_data = Threads::new_task (&Mapping::get_subface_data, *this->mapping, @@ -4395,7 +4395,7 @@ FESubfaceValues::initialize (const UpdateFlags update_flags) // then collect answers from the two task above this->fe_data = std::move(fe_get_data.return_value()); if (flags & update_mapping) - this->mapping_data.reset (mapping_get_data.return_value()); + this->mapping_data = std::move(mapping_get_data.return_value()); else this->mapping_data = std_cxx14::make_unique::InternalDataBase> (); } diff --git a/source/fe/mapping_cartesian.cc b/source/fe/mapping_cartesian.cc index 938d0732f9..688d806c1a 100644 --- a/source/fe/mapping_cartesian.cc +++ b/source/fe/mapping_cartesian.cc @@ -89,29 +89,28 @@ MappingCartesian::requires_update_flags (const UpdateFlags in) co template -typename Mapping::InternalDataBase * +std::unique_ptr::InternalDataBase> MappingCartesian::get_data (const UpdateFlags update_flags, const Quadrature &q) const { - InternalData *data = new InternalData (q); + auto data = std_cxx14::make_unique (q); // store the flags in the internal data object so we can access them // in fill_fe_*_values(). use the transitive hull of the required // flags data->update_each = requires_update_flags(update_flags); - return data; + return std::move(data); } template -typename Mapping::InternalDataBase * +std::unique_ptr::InternalDataBase> MappingCartesian::get_face_data (const UpdateFlags update_flags, const Quadrature& quadrature) const { - InternalData *data - = new InternalData (QProjector::project_to_all_faces(quadrature)); + auto data = std_cxx14::make_unique (QProjector::project_to_all_faces(quadrature)); // verify that we have computed the transitive hull of the required // flags and that FEValues has faithfully passed them on to us @@ -122,18 +121,17 @@ MappingCartesian::get_face_data (const UpdateFlags update_flags, // in fill_fe_*_values() data->update_each = update_flags; - return data; + return std::move(data); } template -typename Mapping::InternalDataBase * +std::unique_ptr::InternalDataBase> MappingCartesian::get_subface_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data - = new InternalData (QProjector::project_to_all_subfaces(quadrature)); + auto data = std_cxx14::make_unique (QProjector::project_to_all_subfaces(quadrature)); // verify that we have computed the transitive hull of the required // flags and that FEValues has faithfully passed them on to us @@ -144,7 +142,7 @@ MappingCartesian::get_subface_data (const UpdateFlags update_flag // in fill_fe_*_values() data->update_each = update_flags; - return data; + return std::move(data); } diff --git a/source/fe/mapping_fe_field.cc b/source/fe/mapping_fe_field.cc index a0cd998dbb..018cd4688e 100644 --- a/source/fe/mapping_fe_field.cc +++ b/source/fe/mapping_fe_field.cc @@ -476,45 +476,45 @@ MappingFEField::compute_face_data template typename -MappingFEField::InternalData * +std::unique_ptr::InternalDataBase> MappingFEField::get_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data = new InternalData(euler_dof_handler->get_fe(), fe_mask); + auto data = std_cxx14::make_unique(euler_dof_handler->get_fe(), fe_mask); this->compute_data (update_flags, quadrature, quadrature.size(), *data); - return data; + return std::move(data); } template -typename Mapping::InternalDataBase * +std::unique_ptr::InternalDataBase> MappingFEField::get_face_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data = new InternalData(euler_dof_handler->get_fe(), fe_mask); + auto data = std_cxx14::make_unique(euler_dof_handler->get_fe(), fe_mask); const Quadrature q (QProjector::project_to_all_faces(quadrature)); this->compute_face_data (update_flags, q, quadrature.size(), *data); - return data; + return std::move(data); } template -typename Mapping::InternalDataBase * +std::unique_ptr::InternalDataBase> MappingFEField::get_subface_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data = new InternalData(euler_dof_handler->get_fe(), fe_mask); + auto data = std_cxx14::make_unique(euler_dof_handler->get_fe(), fe_mask); const Quadrature q (QProjector::project_to_all_subfaces(quadrature)); this->compute_face_data (update_flags, q, quadrature.size(), *data); - return data; + return std::move(data); } @@ -1779,12 +1779,16 @@ 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::unique_ptr mdata (get_data(update_quadrature_points | update_jacobians, - point_quadrature)); + std::unique_ptr::InternalDataBase> + mdata (get_data(update_quadrature_points | update_jacobians, + point_quadrature)); + Assert (dynamic_cast(mdata.get()) != nullptr, + ExcInternalError()); - update_internal_dofs(cell, *mdata); + update_internal_dofs(cell, + dynamic_cast(*mdata)); - return do_transform_unit_to_real_cell(*mdata); + return do_transform_unit_to_real_cell(dynamic_cast(*mdata)); } @@ -1840,12 +1844,15 @@ transform_real_to_unit_cell (const typename Triangulation::cell_it UpdateFlags update_flags = update_quadrature_points | update_jacobians; if (spacedim>dim) update_flags |= update_jacobian_grads; - std::unique_ptr + std::unique_ptr::InternalDataBase> mdata (get_data(update_flags,point_quadrature)); + Assert (dynamic_cast(mdata.get()) != nullptr, + ExcInternalError()); - update_internal_dofs(cell, *mdata); + update_internal_dofs(cell, dynamic_cast(*mdata)); - return do_transform_real_to_unit_cell(cell, p, initial_p_unit, *mdata); + return do_transform_real_to_unit_cell(cell, p, initial_p_unit, + dynamic_cast(*mdata)); } diff --git a/source/fe/mapping_manifold.cc b/source/fe/mapping_manifold.cc index 1d9944b06a..9e78a77627 100644 --- a/source/fe/mapping_manifold.cc +++ b/source/fe/mapping_manifold.cc @@ -300,44 +300,44 @@ MappingManifold::requires_update_flags (const UpdateFlags in) cons template -typename MappingManifold::InternalData * +std::unique_ptr::InternalDataBase> MappingManifold::get_data (const UpdateFlags update_flags, const Quadrature &q) const { - InternalData *data = new InternalData(); + auto data = std_cxx14::make_unique(); data->initialize (this->requires_update_flags(update_flags), q, q.size()); - return data; + return std::move(data); } template -typename MappingManifold::InternalData * +std::unique_ptr::InternalDataBase> MappingManifold::get_face_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data = new InternalData(); + auto data = std_cxx14::make_unique(); data->initialize_face (this->requires_update_flags(update_flags), QProjector::project_to_all_faces(quadrature), quadrature.size()); - return data; + return std::move(data); } template -typename MappingManifold::InternalData * +std::unique_ptr::InternalDataBase> MappingManifold::get_subface_data (const UpdateFlags update_flags, const Quadrature& quadrature) const { - InternalData *data = new InternalData(); + auto data = std_cxx14::make_unique(); data->initialize_face (this->requires_update_flags(update_flags), QProjector::project_to_all_subfaces(quadrature), quadrature.size()); - return data; + return std::move(data); } diff --git a/source/fe/mapping_q.cc b/source/fe/mapping_q.cc index 7ce2efea80..007f13a469 100644 --- a/source/fe/mapping_q.cc +++ b/source/fe/mapping_q.cc @@ -144,73 +144,79 @@ MappingQ::requires_update_flags (const UpdateFlags in) const template -typename MappingQ::InternalData * +std::unique_ptr::InternalDataBase> MappingQ::get_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data = new InternalData; + auto data = std_cxx14::make_unique(); // build the Q1 and Qp internal data objects in parallel - Threads::Task::InternalData *> - do_get_data = Threads::new_task (&MappingQGeneric::get_data, - *qp_mapping, - update_flags, - quadrature); + Threads::Task::InternalDataBase>> + do_get_data = Threads::new_task (&MappingQGeneric::get_data, + *qp_mapping, + update_flags, + quadrature); if (!use_mapping_q_on_all_cells) - data->mapping_q1_data.reset (q1_mapping->get_data (update_flags, quadrature)); + data->mapping_q1_data.reset (dynamic_cast::InternalData *> + (q1_mapping->get_data (update_flags, quadrature).release())); // wait for the task above to finish and use returned value - data->mapping_qp_data.reset (do_get_data.return_value()); - return data; + data->mapping_qp_data.reset (dynamic_cast::InternalData *> + (do_get_data.return_value().release())); + return std::move(data); } template -typename MappingQ::InternalData * +std::unique_ptr::InternalDataBase> MappingQ::get_face_data (const UpdateFlags update_flags, const Quadrature& quadrature) const { - InternalData *data = new InternalData; + auto data = std_cxx14::make_unique(); // build the Q1 and Qp internal data objects in parallel - Threads::Task::InternalData *> - do_get_data = Threads::new_task (&MappingQGeneric::get_face_data, - *qp_mapping, - update_flags, - quadrature); + Threads::Task::InternalDataBase>> + do_get_data = Threads::new_task (&MappingQGeneric::get_face_data, + *qp_mapping, + update_flags, + quadrature); if (!use_mapping_q_on_all_cells) - data->mapping_q1_data.reset (q1_mapping->get_face_data (update_flags, quadrature)); + data->mapping_q1_data.reset (dynamic_cast::InternalData *> + (q1_mapping->get_face_data (update_flags, quadrature).release())); // wait for the task above to finish and use returned value - data->mapping_qp_data.reset (do_get_data.return_value()); - return data; + data->mapping_qp_data.reset (dynamic_cast::InternalData *> + (do_get_data.return_value().release())); + return std::move(data); } template -typename MappingQ::InternalData * +std::unique_ptr::InternalDataBase> MappingQ::get_subface_data (const UpdateFlags update_flags, const Quadrature& quadrature) const { - InternalData *data = new InternalData; + auto data = std_cxx14::make_unique(); // build the Q1 and Qp internal data objects in parallel - Threads::Task::InternalData *> - do_get_data = Threads::new_task (&MappingQGeneric::get_subface_data, - *qp_mapping, - update_flags, - quadrature); + Threads::Task::InternalDataBase>> + do_get_data = Threads::new_task (&MappingQGeneric::get_subface_data, + *qp_mapping, + update_flags, + quadrature); if (!use_mapping_q_on_all_cells) - data->mapping_q1_data.reset (q1_mapping->get_subface_data (update_flags, quadrature)); + data->mapping_q1_data.reset (dynamic_cast::InternalData *> + (q1_mapping->get_subface_data (update_flags, quadrature).release())); // wait for the task above to finish and use returned value - data->mapping_qp_data.reset (do_get_data.return_value()); - return data; + data->mapping_qp_data.reset (dynamic_cast::InternalData *> + (do_get_data.return_value().release())); + return std::move(data); } diff --git a/source/fe/mapping_q_generic.cc b/source/fe/mapping_q_generic.cc index c0ac749a4e..077f0c07c3 100644 --- a/source/fe/mapping_q_generic.cc +++ b/source/fe/mapping_q_generic.cc @@ -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 (get_data(update_flags, - point_quadrature)); + std::unique_ptr mdata (dynamic_cast(get_data(update_flags, + point_quadrature).release())); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -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 (get_data(update_flags, - point_quadrature)); + std::unique_ptr mdata (dynamic_cast(get_data(update_flags, + point_quadrature).release())); 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 (get_data(update_flags, - point_quadrature)); + std::unique_ptr mdata (dynamic_cast(get_data(update_flags, + point_quadrature).release())); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2295,6 +2295,8 @@ transform_real_to_unit_cell_internal return internal::MappingQGenericImplementation::do_transform_real_to_unit_cell_internal<3>(cell, p, initial_p_unit, *mdata); } + + template <> Point<1> MappingQGeneric<1, 2>:: @@ -2311,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 (get_data(update_flags, - point_quadrature)); + std::unique_ptr mdata (dynamic_cast(get_data(update_flags, + point_quadrature).release())); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2321,6 +2323,8 @@ transform_real_to_unit_cell_internal return internal::MappingQGenericImplementation::do_transform_real_to_unit_cell_internal_codim1<1>(cell, p, initial_p_unit, *mdata); } + + template <> Point<2> MappingQGeneric<2, 3>:: @@ -2337,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 (get_data(update_flags, - point_quadrature)); + std::unique_ptr mdata (dynamic_cast(get_data(update_flags, + point_quadrature).release())); mdata->mapping_support_points = this->compute_mapping_support_points (cell); @@ -2554,44 +2558,44 @@ MappingQGeneric::requires_update_flags (const UpdateFlags in) cons template -typename MappingQGeneric::InternalData * +std::unique_ptr::InternalDataBase> MappingQGeneric::get_data (const UpdateFlags update_flags, const Quadrature &q) const { - InternalData *data = new InternalData(polynomial_degree); + auto data = std_cxx14::make_unique(polynomial_degree); data->initialize (this->requires_update_flags(update_flags), q, q.size()); - return data; + return std::move(data); } template -typename MappingQGeneric::InternalData * +std::unique_ptr::InternalDataBase> MappingQGeneric::get_face_data (const UpdateFlags update_flags, const Quadrature &quadrature) const { - InternalData *data = new InternalData(polynomial_degree); + auto data = std_cxx14::make_unique(polynomial_degree); data->initialize_face (this->requires_update_flags(update_flags), QProjector::project_to_all_faces(quadrature), quadrature.size()); - return data; + return std::move(data); } template -typename MappingQGeneric::InternalData * +std::unique_ptr::InternalDataBase> MappingQGeneric::get_subface_data (const UpdateFlags update_flags, const Quadrature& quadrature) const { - InternalData *data = new InternalData(polynomial_degree); + auto data = std_cxx14::make_unique(polynomial_degree); data->initialize_face (this->requires_update_flags(update_flags), QProjector::project_to_all_subfaces(quadrature), quadrature.size()); - return data; + return std::move(data); }