From: Fernando Herrera Date: Sun, 18 Aug 2024 02:25:19 +0000 (-0600) Subject: Add empty() function to deal.II/hp/collection.h and use it instead of size() == 0 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42ccce4acc9dd5c6b59c5eac3542004641cf5837;p=dealii.git Add empty() function to deal.II/hp/collection.h and use it instead of size() == 0 This only changes files in the source directory --- diff --git a/include/deal.II/hp/collection.h b/include/deal.II/hp/collection.h index 0f65f10a98..92431efcca 100644 --- a/include/deal.II/hp/collection.h +++ b/include/deal.II/hp/collection.h @@ -252,6 +252,12 @@ namespace hp unsigned int size() const; + /** + * This is equivalent to size() == 0 + */ + bool + empty() const; + /** * Determine an estimate for the memory consumption (in bytes) of this * object. @@ -312,6 +318,15 @@ namespace hp + template + inline bool + Collection::empty() const + { + return this->size() == 0; + } + + + template inline const T & Collection::operator[](const unsigned int index) const diff --git a/source/distributed/cell_weights.cc b/source/distributed/cell_weights.cc index 9707262e65..16a88760f4 100644 --- a/source/distributed/cell_weights.cc +++ b/source/distributed/cell_weights.cc @@ -175,7 +175,7 @@ namespace parallel (void)triangulation; // Skip if the DoFHandler has not been initialized yet. - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) return 0; // Convert cell type from Triangulation to DoFHandler to be able diff --git a/source/hp/fe_collection.cc b/source/hp/fe_collection.cc index ca1e1342d8..2669f7e7e6 100644 --- a/source/hp/fe_collection.cc +++ b/source/hp/fe_collection.cc @@ -67,7 +67,7 @@ namespace hp // check that the new element has the right number of components. only check // with the first element, since all the other elements have already passed // the test against the first element - Assert(this->size() == 0 || + Assert(this->empty() || new_fe.n_components() == this->operator[](0).n_components(), ExcMessage("All elements inside a collection need to have the " "same number of vector components!")); diff --git a/source/hp/refinement.cc b/source/hp/refinement.cc index 8e57fd28da..44199edb3f 100644 --- a/source/hp/refinement.cc +++ b/source/hp/refinement.cc @@ -48,7 +48,7 @@ namespace hp void full_p_adaptivity(const DoFHandler &dof_handler) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -68,7 +68,7 @@ namespace hp p_adaptivity_from_flags(const DoFHandler &dof_handler, const std::vector &p_flags) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -117,7 +117,7 @@ namespace hp const ComparisonFunction> &compare_coarsen) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -156,7 +156,7 @@ namespace hp const ComparisonFunction> &compare_coarsen) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -253,7 +253,7 @@ namespace hp const ComparisonFunction> &compare_coarsen) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -447,7 +447,7 @@ namespace hp p_adaptivity_from_regularity(const DoFHandler &dof_handler, const Vector &sobolev_indices) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -509,7 +509,7 @@ namespace hp const ComparisonFunction> &compare_coarsen) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -550,7 +550,7 @@ namespace hp const double gamma_h, const double gamma_n) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -677,7 +677,7 @@ namespace hp void force_p_over_h(const DoFHandler &dof_handler) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -698,7 +698,7 @@ namespace hp void choose_p_over_h(const DoFHandler &dof_handler) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return; @@ -811,7 +811,7 @@ namespace hp const unsigned int max_difference, const unsigned int contains_fe_index) { - if (dof_handler.get_fe_collection().size() == 0) + if (dof_handler.get_fe_collection().empty()) // nothing to do return false;