]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid dynamic_cast in ghost/artificial cell queries
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Thu, 19 Sep 2019 11:06:39 +0000 (13:06 +0200)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Tue, 24 Sep 2019 13:42:26 +0000 (15:42 +0200)
include/deal.II/grid/tria_accessor.templates.h

index 59cdaf16da4fac933e9dac45734dbb2a73904b59..fe9e0e9c0d85a08ead1ef9da45c2d130ca3dc572 100644 (file)
@@ -3566,17 +3566,10 @@ CellAccessor<dim, spacedim>::is_locally_owned() const
 #ifndef DEAL_II_WITH_MPI
   return true;
 #else
-  if (is_artificial())
-    return false;
-
-  const parallel::TriangulationBase<dim, spacedim> *pt =
-    dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
-      this->tria);
 
-  if (pt == nullptr)
-    return true;
-  else
-    return (this->subdomain_id() == pt->locally_owned_subdomain());
+  return (this->tria->locally_owned_subdomain() ==
+            numbers::invalid_subdomain_id ||
+          this->subdomain_id() == this->tria->locally_owned_subdomain());
 
 #endif
 }
@@ -3590,14 +3583,9 @@ CellAccessor<dim, spacedim>::is_locally_owned_on_level() const
   return true;
 #else
 
-  const parallel::TriangulationBase<dim, spacedim> *pt =
-    dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
-      this->tria);
-
-  if (pt == nullptr)
-    return true;
-  else
-    return (this->level_subdomain_id() == pt->locally_owned_subdomain());
+  return (this->tria->locally_owned_subdomain() ==
+            numbers::invalid_subdomain_id ||
+          this->level_subdomain_id() == this->tria->locally_owned_subdomain());
 
 #endif
 }
@@ -3609,21 +3597,17 @@ CellAccessor<dim, spacedim>::is_ghost() const
 {
   Assert(this->active(),
          ExcMessage("is_ghost() can only be called on active cells!"));
-  if (is_artificial() || this->has_children())
+  if (this->has_children())
     return false;
 
 #ifndef DEAL_II_WITH_MPI
   return false;
 #else
 
-  const parallel::TriangulationBase<dim, spacedim> *pt =
-    dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
-      this->tria);
-
-  if (pt == nullptr)
-    return false;
-  else
-    return (this->subdomain_id() != pt->locally_owned_subdomain());
+  return (this->tria->locally_owned_subdomain() !=
+            numbers::invalid_subdomain_id &&
+          this->subdomain_id() != this->tria->locally_owned_subdomain() &&
+          this->subdomain_id() != numbers::artificial_subdomain_id);
 
 #endif
 }
@@ -3640,14 +3624,9 @@ CellAccessor<dim, spacedim>::is_artificial() const
   return false;
 #else
 
-  const parallel::TriangulationBase<dim, spacedim> *pt =
-    dynamic_cast<const parallel::TriangulationBase<dim, spacedim> *>(
-      this->tria);
-
-  if (pt == nullptr)
-    return false;
-  else
-    return this->subdomain_id() == numbers::artificial_subdomain_id;
+  return (this->tria->locally_owned_subdomain() !=
+            numbers::invalid_subdomain_id &&
+          this->subdomain_id() == numbers::artificial_subdomain_id);
 
 #endif
 }

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.