]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Explicitly check the result of a dynamic_cast. 6132/head
authorDavid Wells <wellsd2@rpi.edu>
Sat, 31 Mar 2018 20:33:54 +0000 (16:33 -0400)
committerDavid Wells <wellsd2@rpi.edu>
Sat, 31 Mar 2018 23:17:57 +0000 (19:17 -0400)
source/fe/fe_system.cc

index 81c9671f1dbe67bb80ebcd91c7b01d66584f8e97..75ff4b20081a2b3abb70cc3a0c2bedb96d9b4d53 100644 (file)
@@ -1883,80 +1883,86 @@ get_subface_interpolation_matrix (const FiniteElement<dim,spacedim> &x_source_fe
   // FESystem(FESystem(FE_Q(r),2),1,FE_Q(s),1)
   const FESystem<dim,spacedim> *fe_other_system
     = dynamic_cast<const FESystem<dim,spacedim>*>(&x_source_fe);
+  if (fe_other_system != nullptr)
+    {
+      // clear matrix, since we will not get to set all elements
+      interpolation_matrix = 0;
 
-  // clear matrix, since we will not get to set all elements
-  interpolation_matrix = 0;
-
-  // loop over all the base elements of this and the other element, counting
-  // their multiplicities
-  unsigned int base_index       = 0,
-               base_index_other = 0;
-  unsigned int multiplicity       = 0,
-               multiplicity_other = 0;
+      // loop over all the base elements of this and the other element, counting
+      // their multiplicities
+      unsigned int base_index       = 0,
+                   base_index_other = 0;
+      unsigned int multiplicity       = 0,
+                   multiplicity_other = 0;
 
-  FullMatrix<double> base_to_base_interpolation;
+      FullMatrix<double> base_to_base_interpolation;
 
-  while (true)
-    {
-      const FiniteElement<dim,spacedim>
-      &base       = base_element(base_index),
-       &base_other = fe_other_system->base_element(base_index_other);
+      while (true)
+        {
+          const FiniteElement<dim,spacedim>
+          &base       = base_element(base_index),
+           &base_other = fe_other_system->base_element(base_index_other);
 
-      Assert (base.n_components() == base_other.n_components(),
-              ExcNotImplemented());
+          Assert (base.n_components() == base_other.n_components(),
+                  ExcNotImplemented());
 
-      // get the interpolation from the bases
-      base_to_base_interpolation.reinit (base_other.dofs_per_face,
-                                         base.dofs_per_face);
-      base.get_subface_interpolation_matrix (base_other,
-                                             subface,
-                                             base_to_base_interpolation);
+          // get the interpolation from the bases
+          base_to_base_interpolation.reinit (base_other.dofs_per_face,
+                                             base.dofs_per_face);
+          base.get_subface_interpolation_matrix (base_other,
+                                                 subface,
+                                                 base_to_base_interpolation);
 
-      // now translate entries. we'd like to have something like
-      // face_base_to_system_index, but that doesn't exist. rather, all we
-      // have is the reverse. well, use that then
-      for (unsigned int i=0; i<this->dofs_per_face; ++i)
-        if (this->face_system_to_base_index(i).first
-            ==
-            std::make_pair (base_index, multiplicity))
-          for (unsigned int j=0; j<fe_other_system->dofs_per_face; ++j)
-            if (fe_other_system->face_system_to_base_index(j).first
+          // now translate entries. we'd like to have something like
+          // face_base_to_system_index, but that doesn't exist. rather, all we
+          // have is the reverse. well, use that then
+          for (unsigned int i=0; i<this->dofs_per_face; ++i)
+            if (this->face_system_to_base_index(i).first
                 ==
-                std::make_pair (base_index_other, multiplicity_other))
-              interpolation_matrix(j, i)
-                = base_to_base_interpolation(fe_other_system->face_system_to_base_index(j).second,
-                                             this->face_system_to_base_index(i).second);
-
-      // advance to the next base element for this and the other fe_system;
-      // see if we can simply advance the multiplicity by one, or if have to
-      // move on to the next base element
-      ++multiplicity;
-      if (multiplicity == this->element_multiplicity(base_index))
-        {
-          multiplicity = 0;
-          ++base_index;
-        }
-      ++multiplicity_other;
-      if (multiplicity_other ==
-          fe_other_system->element_multiplicity(base_index_other))
-        {
-          multiplicity_other = 0;
-          ++base_index_other;
-        }
+                std::make_pair (base_index, multiplicity))
+              for (unsigned int j=0; j<fe_other_system->dofs_per_face; ++j)
+                if (fe_other_system->face_system_to_base_index(j).first
+                    ==
+                    std::make_pair (base_index_other, multiplicity_other))
+                  interpolation_matrix(j, i)
+                    = base_to_base_interpolation(fe_other_system->face_system_to_base_index(j).second,
+                                                 this->face_system_to_base_index(i).second);
 
-      // see if we have reached the end of the present element. if so, we
-      // should have reached the end of the other one as well
-      if (base_index == this->n_base_elements())
-        {
-          Assert (base_index_other == fe_other_system->n_base_elements(),
+          // advance to the next base element for this and the other fe_system;
+          // see if we can simply advance the multiplicity by one, or if have to
+          // move on to the next base element
+          ++multiplicity;
+          if (multiplicity == this->element_multiplicity(base_index))
+            {
+              multiplicity = 0;
+              ++base_index;
+            }
+          ++multiplicity_other;
+          if (multiplicity_other ==
+              fe_other_system->element_multiplicity(base_index_other))
+            {
+              multiplicity_other = 0;
+              ++base_index_other;
+            }
+
+          // see if we have reached the end of the present element. if so, we
+          // should have reached the end of the other one as well
+          if (base_index == this->n_base_elements())
+            {
+              Assert (base_index_other == fe_other_system->n_base_elements(),
+                      ExcInternalError());
+              break;
+            }
+
+          // if we haven't reached the end of this element, we shouldn't have
+          // reached the end of the other one either
+          Assert (base_index_other != fe_other_system->n_base_elements(),
                   ExcInternalError());
-          break;
         }
-
-      // if we haven't reached the end of this element, we shouldn't have
-      // reached the end of the other one either
-      Assert (base_index_other != fe_other_system->n_base_elements(),
-              ExcInternalError());
+    }
+  else
+    {
+      Assert(fe_other_system != nullptr, ExcInternalError());
     }
 }
 

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.