From: Wolfgang Bangerth Date: Tue, 28 Apr 2020 18:17:57 +0000 (-0600) Subject: Fix copying hp::FEValues objects. X-Git-Tag: v9.2.0-rc1~156^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3601e0370661b69fc98e2f0fe5f25f0e5ec59393;p=dealii.git Fix copying hp::FEValues objects. --- diff --git a/include/deal.II/hp/fe_values.h b/include/deal.II/hp/fe_values.h index 10ffea6706..4841d7ad86 100644 --- a/include/deal.II/hp/fe_values.h +++ b/include/deal.II/hp/fe_values.h @@ -87,6 +87,18 @@ namespace hp const QCollection & q_collection, const UpdateFlags update_flags); + /** + * Copy constructor. + */ + FEValuesBase(const FEValuesBase &other); + + /** + * Copy operator. While objects of this type can be copy-constructed, + * they cannot be copied and consequently this operator is disabled. + */ + FEValuesBase & + operator=(const FEValuesBase &) = delete; + /** * For timing purposes it may be useful to create all required FE*Values * objects in advance, rather than computing them on request via lazy @@ -196,7 +208,7 @@ namespace hp * Initially, all entries have zero pointers, and we will allocate them * lazily as needed in select_fe_values() or precalculate_fe_values(). */ - Table<3, std::shared_ptr> fe_values_table; + Table<3, std::unique_ptr> fe_values_table; /** * Set of indices pointing at the fe_values object selected last time diff --git a/source/hp/fe_values.cc b/source/hp/fe_values.cc index ff1c635a00..04291740bb 100644 --- a/source/hp/fe_values.cc +++ b/source/hp/fe_values.cc @@ -13,6 +13,7 @@ // // --------------------------------------------------------------------- +#include #include #include @@ -64,6 +65,38 @@ namespace hp + template + FEValuesBase::FEValuesBase( + const FEValuesBase &other) + : fe_collection(other.fe_collection) + , mapping_collection(other.mapping_collection) + , q_collection(other.q_collection) + , fe_values_table(fe_collection->size(), + mapping_collection->size(), + q_collection.size()) + , present_fe_values_index(other.present_fe_values_index) + , update_flags(other.update_flags) + { + // We've already resized the `fe_values_table` correctly above, but right + // now it just contains nullptrs. Create copies of the objects that + // `other.fe_values_table` stores + for (unsigned int fe_index = 0; fe_index < fe_collection->size(); + ++fe_index) + for (unsigned int m_index = 0; m_index < mapping_collection->size(); + ++m_index) + for (unsigned int q_index = 0; q_index < q_collection.size(); ++q_index) + if (other.fe_values_table[fe_index][m_index][q_index].get() != + nullptr) + fe_values_table[fe_index][m_index][q_index] = + std_cxx14::make_unique( + (*mapping_collection)[m_index], + (*fe_collection)[fe_index], + q_collection[q_index], + update_flags); + } + + + template FEValuesType & FEValuesBase::select_fe_values( @@ -86,10 +119,11 @@ namespace hp // of indices if (fe_values_table(present_fe_values_index).get() == nullptr) fe_values_table(present_fe_values_index) = - std::make_shared((*mapping_collection)[mapping_index], - (*fe_collection)[fe_index], - q_collection[q_index], - update_flags); + std_cxx14::make_unique( + (*mapping_collection)[mapping_index], + (*fe_collection)[fe_index], + q_collection[q_index], + update_flags); // now there definitely is one! return *fe_values_table(present_fe_values_index); @@ -121,7 +155,7 @@ namespace hp task_group += Threads::new_task([&, fe_index, mapping_index, q_index]() { fe_values_table(TableIndices<3>(fe_index, mapping_index, q_index)) = - std::make_shared( + std_cxx14::make_unique( (*mapping_collection)[mapping_index], (*fe_collection)[fe_index], q_collection[q_index],