From 358f8234db50c1d3e5656648939e1e53a9bbe892 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 21 Jul 2015 09:28:51 -0500 Subject: [PATCH] Make the CellSimilarity argument const also in Mapping. Logically, these arguments are intended to be input arguments, so make them const. Also, don't make them a reference as they are simply integral values. That said, the original intention of having a reference was so that mappings can indicate situations where cell similarity has to be disregarded. Consequently, let the fill_fe_values() functions return a cell similarity value that will then simply be assigned to the same variable again. --- include/deal.II/fe/mapping.h | 5 ++-- include/deal.II/fe/mapping_cartesian.h | 5 ++-- include/deal.II/fe/mapping_fe_field.h | 5 ++-- include/deal.II/fe/mapping_q.h | 5 ++-- include/deal.II/fe/mapping_q1.h | 5 ++-- include/deal.II/fe/mapping_q1_eulerian.h | 5 ++-- include/deal.II/fe/mapping_q_eulerian.h | 5 ++-- source/fe/fe_values.cc | 31 ++++++++++++-------- source/fe/mapping_cartesian.cc | 6 ++-- source/fe/mapping_fe_field.cc | 19 ++++++++----- source/fe/mapping_q.cc | 36 +++++++++++++++--------- source/fe/mapping_q1.cc | 5 ++-- source/fe/mapping_q1_eulerian.cc | 18 +++++++----- source/fe/mapping_q_eulerian.cc | 17 +++++++---- 14 files changed, 104 insertions(+), 63 deletions(-) diff --git a/include/deal.II/fe/mapping.h b/include/deal.II/fe/mapping.h index 83620efdda..a70abd7b6d 100644 --- a/include/deal.II/fe/mapping.h +++ b/include/deal.II/fe/mapping.h @@ -640,7 +640,8 @@ private: * The function above adjusted with the variable cell_normal_vectors for the * case of codimension 1 */ - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, InternalDataBase &internal, @@ -650,7 +651,7 @@ private: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &cell_normal_vectors, - CellSimilarity::Similarity &cell_similarity + const CellSimilarity::Similarity cell_similarity ) const=0; diff --git a/include/deal.II/fe/mapping_cartesian.h b/include/deal.II/fe/mapping_cartesian.h index 4c34310afb..57e61bb60f 100644 --- a/include/deal.II/fe/mapping_cartesian.h +++ b/include/deal.II/fe/mapping_cartesian.h @@ -69,7 +69,8 @@ public: get_subface_data (const UpdateFlags flags, const Quadrature& quadrature) const; - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, typename Mapping::InternalDataBase &mapping_data, @@ -79,7 +80,7 @@ public: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &, - CellSimilarity::Similarity &cell_similarity) const ; + const CellSimilarity::Similarity cell_similarity) const ; virtual void diff --git a/include/deal.II/fe/mapping_fe_field.h b/include/deal.II/fe/mapping_fe_field.h index 23fbcdf404..450a617d86 100644 --- a/include/deal.II/fe/mapping_fe_field.h +++ b/include/deal.II/fe/mapping_fe_field.h @@ -412,7 +412,8 @@ protected: /** * Implementation of the interface in Mapping. */ - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, typename Mapping::InternalDataBase &mapping_data, @@ -422,7 +423,7 @@ protected: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &cell_normal_vectors, - CellSimilarity::Similarity &cell_similarity) const ; + const CellSimilarity::Similarity cell_similarity) const ; /** * Implementation of the interface in Mapping. diff --git a/include/deal.II/fe/mapping_q.h b/include/deal.II/fe/mapping_q.h index 2efd1563f8..ff30ce782d 100644 --- a/include/deal.II/fe/mapping_q.h +++ b/include/deal.II/fe/mapping_q.h @@ -193,7 +193,8 @@ protected: /** * Implementation of the interface in Mapping. */ - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, typename Mapping::InternalDataBase &mapping_data, @@ -203,7 +204,7 @@ protected: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &cell_normal_vectors, - CellSimilarity::Similarity &cell_similarity) const ; + const CellSimilarity::Similarity cell_similarity) const ; /** * Implementation of the interface in Mapping. diff --git a/include/deal.II/fe/mapping_q1.h b/include/deal.II/fe/mapping_q1.h index 5134eb8143..5ac2510d8b 100644 --- a/include/deal.II/fe/mapping_q1.h +++ b/include/deal.II/fe/mapping_q1.h @@ -304,7 +304,8 @@ public: /** * Implementation of the interface in Mapping. */ - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, typename Mapping::InternalDataBase &mapping_data, @@ -314,7 +315,7 @@ public: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &cell_normal_vectors, - CellSimilarity::Similarity &cell_similarity) const; + const CellSimilarity::Similarity cell_similarity) const; /** * Implementation of the interface in Mapping. diff --git a/include/deal.II/fe/mapping_q1_eulerian.h b/include/deal.II/fe/mapping_q1_eulerian.h index 4fde32ddcb..f3b2da3097 100644 --- a/include/deal.II/fe/mapping_q1_eulerian.h +++ b/include/deal.II/fe/mapping_q1_eulerian.h @@ -125,7 +125,8 @@ protected: * Implementation of the interface in MappingQ1. Overrides the function in * the base class, since we cannot use any cell similarity for this class. */ - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, typename Mapping::InternalDataBase &mapping_data, @@ -135,7 +136,7 @@ protected: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &cell_normal_vectors, - CellSimilarity::Similarity &cell_similarity) const; + const CellSimilarity::Similarity cell_similarity) const; /** * Reference to the vector of shifts. diff --git a/include/deal.II/fe/mapping_q_eulerian.h b/include/deal.II/fe/mapping_q_eulerian.h index 723220360d..e03f1f5035 100644 --- a/include/deal.II/fe/mapping_q_eulerian.h +++ b/include/deal.II/fe/mapping_q_eulerian.h @@ -140,7 +140,8 @@ protected: * Implementation of the interface in MappingQ. Overrides the function in * the base class, since we cannot use any cell similarity for this class. */ - virtual void + virtual + CellSimilarity::Similarity fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &quadrature, typename Mapping::InternalDataBase &mapping_data, @@ -150,7 +151,7 @@ protected: std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &cell_normal_vectors, - CellSimilarity::Similarity &cell_similarity) const; + const CellSimilarity::Similarity cell_similarity) const; /** * Reference to the vector of shifts. diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 4bb89384eb..2cbedfbbba 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -3512,17 +3512,26 @@ FEValues::reinit (const TriaIterator > &c template void FEValues::do_reinit () { - this->get_mapping().fill_fe_values(*this->present_cell, - quadrature, - *this->mapping_data, - this->quadrature_points, - this->JxW_values, - this->jacobians, - this->jacobian_grads, - this->inverse_jacobians, - this->normal_vectors, - this->cell_similarity); - + // first call the mapping and let it generate the data + // specific to the mapping. also let it inspect the + // cell similarity flag and, if necessary, update + // it + this->cell_similarity + = this->get_mapping().fill_fe_values(*this->present_cell, + quadrature, + *this->mapping_data, + this->quadrature_points, + this->JxW_values, + this->jacobians, + this->jacobian_grads, + this->inverse_jacobians, + this->normal_vectors, + this->cell_similarity); + + // then call the finite element and, with the data + // already filled by the mapping, let it compute the + // data for the mapped shape function values, gradients, + // etc. this->get_fe().fill_fe_values(this->get_mapping(), *this->present_cell, quadrature, diff --git a/source/fe/mapping_cartesian.cc b/source/fe/mapping_cartesian.cc index 82fc6e53ef..78600e6de3 100644 --- a/source/fe/mapping_cartesian.cc +++ b/source/fe/mapping_cartesian.cc @@ -315,7 +315,7 @@ MappingCartesian::compute_fill (const typename Triangulation -void +CellSimilarity::Similarity MappingCartesian:: fill_fe_values (const typename Triangulation::cell_iterator &cell, const Quadrature &q, @@ -326,7 +326,7 @@ fill_fe_values (const typename Triangulation::cell_iterator &cell, std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &, - CellSimilarity::Similarity &cell_similarity) const + const CellSimilarity::Similarity cell_similarity) const { // convert data object to internal // data for this class. fails with @@ -386,6 +386,8 @@ fill_fe_values (const typename Triangulation::cell_iterator &cell, for (unsigned int j=0; j::get_subface_data (const UpdateFlags upda // Note that the CellSimilarity flag is modifyable, since MappingFEField can need to // recalculate data even when cells are similar. template -void +CellSimilarity::Similarity MappingFEField::fill_fe_values ( const typename Triangulation::cell_iterator &cell, const Quadrature &q, @@ -384,7 +384,7 @@ MappingFEField::fill_fe_values ( std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &normal_vectors, - CellSimilarity::Similarity &cell_similarity) const + const CellSimilarity::Similarity cell_similarity) const { AssertDimension(fe->dofs_per_cell, local_dof_values.get().size()); Assert(local_dof_values.get().size()>0, ExcMessage("Cannot do anything with zero degrees of freedom")); @@ -394,12 +394,16 @@ MappingFEField::fill_fe_values ( Assert (dynamic_cast (&mapping_data) != 0, ExcInternalError()); InternalData &data = static_cast (mapping_data); - if (get_degree() > 1) - cell_similarity = CellSimilarity::invalid_next_cell; - const unsigned int n_q_points=q.size(); - - compute_fill (cell, n_q_points, QProjector::DataSetDescriptor::cell (), cell_similarity, + const CellSimilarity::Similarity updated_cell_similarity + = (get_degree() == 1 + ? + cell_similarity + : + CellSimilarity::invalid_next_cell); + + compute_fill (cell, n_q_points, QProjector::DataSetDescriptor::cell (), + updated_cell_similarity, data, quadrature_points); const UpdateFlags update_flags(data.current_update_flags()); @@ -543,6 +547,7 @@ MappingFEField::fill_fe_values ( inverse_jacobians[point] = data.covariant[point].transpose(); } + return updated_cell_similarity; } diff --git a/source/fe/mapping_q.cc b/source/fe/mapping_q.cc index 9065f1ece1..d3ab675169 100644 --- a/source/fe/mapping_q.cc +++ b/source/fe/mapping_q.cc @@ -247,7 +247,7 @@ MappingQ::get_subface_data (const UpdateFlags update_flags, // Note that the CellSimilarity flag is modifyable, since MappingQ can need to // recalculate data even when cells are similar. template -void +CellSimilarity::Similarity MappingQ::fill_fe_values ( const typename Triangulation::cell_iterator &cell, const Quadrature &q, @@ -258,7 +258,7 @@ MappingQ::fill_fe_values ( std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &normal_vectors, - CellSimilarity::Similarity &cell_similarity) const + const CellSimilarity::Similarity cell_similarity) const { // convert data object to internal data for this class. fails with an // exception if that is not possible @@ -271,27 +271,35 @@ MappingQ::fill_fe_values ( || cell->has_boundary_lines()); // depending on this result, use this or the other data object for the - // mapping. furthermore, we need to ensure that the flag indicating whether + // mapping. + typename MappingQ1::InternalData * + p_data = (data.use_mapping_q1_on_current_cell + ? + &data.mapping_q1_data + : + &data); + + // call the base class. we need to ensure that the flag indicating whether // we can use some similarity has to be modified - for a general MappingQ, // the data needs to be recomputed anyway since then the mapping changes the // data. this needs to be known also for later operations, so modify the // variable here. this also affects the calculation of the next cell -- if // we use Q1 data on the next cell, the data will still be invalid. - typename MappingQ1::InternalData *p_data=0; - if (data.use_mapping_q1_on_current_cell) - p_data=&data.mapping_q1_data; - else - { - p_data=&data; - if (get_degree() > 1) - cell_similarity = CellSimilarity::invalid_next_cell; - } - + const CellSimilarity::Similarity updated_cell_similarity + = ((data.use_mapping_q1_on_current_cell == false) + && + (get_degree() > 1) + ? + CellSimilarity::invalid_next_cell + : + cell_similarity); MappingQ1::fill_fe_values(cell, q, *p_data, quadrature_points, JxW_values, jacobians, jacobian_grads, inverse_jacobians, - normal_vectors, cell_similarity); + normal_vectors, + updated_cell_similarity); + return updated_cell_similarity; } diff --git a/source/fe/mapping_q1.cc b/source/fe/mapping_q1.cc index 5927a3e70e..73dea53ebf 100644 --- a/source/fe/mapping_q1.cc +++ b/source/fe/mapping_q1.cc @@ -732,7 +732,7 @@ MappingQ1::compute_mapping_support_points( template -void +CellSimilarity::Similarity MappingQ1::fill_fe_values ( const typename Triangulation::cell_iterator &cell, const Quadrature &q, @@ -743,7 +743,7 @@ MappingQ1::fill_fe_values ( std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &normal_vectors, - CellSimilarity::Similarity &cell_similarity) const + const CellSimilarity::Similarity cell_similarity) const { // ensure that the following static_cast is really correct: Assert (dynamic_cast(&mapping_data) != 0, @@ -906,6 +906,7 @@ MappingQ1::fill_fe_values ( inverse_jacobians[point] = data.covariant[point].transpose(); } + return cell_similarity; } diff --git a/source/fe/mapping_q1_eulerian.cc b/source/fe/mapping_q1_eulerian.cc index f30ef43d46..dc7a768dd8 100644 --- a/source/fe/mapping_q1_eulerian.cc +++ b/source/fe/mapping_q1_eulerian.cc @@ -111,7 +111,7 @@ MappingQ1Eulerian::clone () const template -void +CellSimilarity::Similarity MappingQ1Eulerian::fill_fe_values ( const typename Triangulation::cell_iterator &cell, const Quadrature &q, @@ -122,16 +122,20 @@ MappingQ1Eulerian::fill_fe_values ( std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &normal_vectors, - CellSimilarity::Similarity &cell_similarity) const + const CellSimilarity::Similarity) const { - // disable any previously detected - // similarity and then enter the - // respective function of the base class. - cell_similarity = CellSimilarity::invalid_next_cell; + // call the function of the base class, but ignoring + // any potentially detected cell similarity between + // the current and the previous cell MappingQ1::fill_fe_values (cell, q, mapping_data, quadrature_points, JxW_values, jacobians, jacobian_grads, inverse_jacobians, - normal_vectors, cell_similarity); + normal_vectors, + CellSimilarity::invalid_next_cell); + // also return the updated flag since any detected + // similarity wasn't based on the mapped field, but + // the original vertices which are meaningless + return CellSimilarity::invalid_next_cell; } diff --git a/source/fe/mapping_q_eulerian.cc b/source/fe/mapping_q_eulerian.cc index 6082fa9157..69444b6994 100644 --- a/source/fe/mapping_q_eulerian.cc +++ b/source/fe/mapping_q_eulerian.cc @@ -176,7 +176,7 @@ compute_mapping_support_points template -void +CellSimilarity::Similarity MappingQEulerian::fill_fe_values ( const typename Triangulation::cell_iterator &cell, const Quadrature &q, @@ -187,15 +187,20 @@ MappingQEulerian::fill_fe_values ( std::vector > &jacobian_grads, std::vector > &inverse_jacobians, std::vector > &normal_vectors, - CellSimilarity::Similarity &cell_similarity) const + const CellSimilarity::Similarity ) const { - // disable any previously detected similarity and hand on to the respective - // function of the base class. - cell_similarity = CellSimilarity::invalid_next_cell; + // call the function of the base class, but ignoring + // any potentially detected cell similarity between + // the current and the previous cell MappingQ::fill_fe_values (cell, q, mapping_data, quadrature_points, JxW_values, jacobians, jacobian_grads, inverse_jacobians, - normal_vectors, cell_similarity); + normal_vectors, + CellSimilarity::invalid_next_cell); + // also return the updated flag since any detected + // similarity wasn't based on the mapped field, but + // the original vertices which are meaningless + return CellSimilarity::invalid_next_cell; } -- 2.39.5