]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify some code. 17043/head
authorWolfgang Bangerth <bangerth@colostate.edu>
Sat, 18 May 2024 15:32:56 +0000 (09:32 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Sat, 18 May 2024 15:32:56 +0000 (09:32 -0600)
include/deal.II/fe/fe_tools.templates.h

index 898aea2e2b2916ebfb9eb0166a24c09177eade5e..851bc31ae784ff1ee61f08f3f09dfe601304f512 100644 (file)
@@ -379,23 +379,19 @@ namespace FETools
       const FiniteElement<dim, spacedim> *fe5,
       const unsigned int                  N5)
     {
-      std::vector<const FiniteElement<dim, spacedim> *> fe_list;
-      std::vector<unsigned int>                         multiplicities;
+      std::vector<const FiniteElement<dim, spacedim> *> fe_list = {
+        fe1, fe2, fe3, fe4, fe5};
+      std::vector<unsigned int> multiplicities = {N1, N2, N3, N4, N5};
 
-      fe_list.push_back(fe1);
-      multiplicities.push_back(N1);
-
-      fe_list.push_back(fe2);
-      multiplicities.push_back(N2);
-
-      fe_list.push_back(fe3);
-      multiplicities.push_back(N3);
-
-      fe_list.push_back(fe4);
-      multiplicities.push_back(N4);
+      // This function is occasionally called with nullptr values for the
+      // finite elements. Drop those again.
+      while ((fe_list.size() > 0) && (fe_list.back() == nullptr))
+        {
+          Assert(multiplicities.back() == 0, ExcInternalError());
+          fe_list.pop_back();
+          multiplicities.pop_back();
+        }
 
-      fe_list.push_back(fe5);
-      multiplicities.push_back(N5);
       return compute_restriction_is_additive_flags(fe_list, multiplicities);
     }
 
@@ -621,23 +617,18 @@ namespace FETools
                                const unsigned int                  N5,
                                const bool do_tensor_product)
     {
-      std::vector<const FiniteElement<dim, spacedim> *> fe_list;
-      std::vector<unsigned int>                         multiplicities;
-
-      fe_list.push_back(fe1);
-      multiplicities.push_back(N1);
+      std::vector<const FiniteElement<dim, spacedim> *> fe_list = {
+        fe1, fe2, fe3, fe4, fe5};
+      std::vector<unsigned int> multiplicities = {N1, N2, N3, N4, N5};
 
-      fe_list.push_back(fe2);
-      multiplicities.push_back(N2);
-
-      fe_list.push_back(fe3);
-      multiplicities.push_back(N3);
-
-      fe_list.push_back(fe4);
-      multiplicities.push_back(N4);
-
-      fe_list.push_back(fe5);
-      multiplicities.push_back(N5);
+      // This function is occasionally called with nullptr values for the
+      // finite elements. Drop those again.
+      while ((fe_list.size() > 0) && (fe_list.back() == nullptr))
+        {
+          Assert(multiplicities.back() == 0, ExcInternalError());
+          fe_list.pop_back();
+          multiplicities.pop_back();
+        }
 
       return compute_nonzero_components(fe_list,
                                         multiplicities,

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.