]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement ReferenceCell::contains_points() for the remaining reference cells.
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 11 Jan 2023 19:05:36 +0000 (12:05 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 11 Jan 2023 19:05:36 +0000 (12:05 -0700)
include/deal.II/grid/reference_cell.h

index b149d0dc646f79341e0173896b6135c53147d607..46b34df5245a84d014819bd4210fad95e2942564 100644 (file)
@@ -2172,11 +2172,46 @@ ReferenceCell::contains_point(const Point<dim> &p, const double tolerance) const
     }
   else if (*this == ReferenceCells::Wedge)
     {
-      Assert(false, ExcNotImplemented());
+      // The wedge we use is a triangle extruded into the third
+      // dimension by one unit. So we can use the same logic as for
+      // triangles above (i.e., for the simplex above, using dim==2)
+      // and then check the third dimension separately.
+
+      for (unsigned int d = 0; d < 2; ++d)
+        if (p[d] < -tolerance)
+          return false;
+
+      const double sum = p[0] + p[1];
+      if (sum > 1 + tolerance * std::sqrt(2.0))
+        return false;
+
+      if (p[2] < -tolerance)
+        return false;
+      if (p[2] > 1 + tolerance)
+        return false;
+
+      return true;
     }
   else if (*this == ReferenceCells::Pyramid)
     {
-      Assert(false, ExcNotImplemented());
+      // A pyramid only lives in the upper half-space:
+      if (p[2] < -tolerance)
+        return false;
+
+      // It also only lives in the space below z=1:
+      if (p[2] > 1 + tolerance)
+        return false;
+
+      // Within what's left of the space, a pyramid is a cone that tapers
+      // towards the top. First compute the distance of the point to the
+      // axis in the max norm (this is the right norm because the vertices
+      // of the pyramid are at points +/-1, +/-1):
+      const double distance_from_axis =
+        std::max(std::fabs(p[0]), std::fabs(p[1]));
+
+      // We are inside the pyramid if the distance from the axis is less than
+      // (1-z)
+      return (distance_from_axis < 1 + tolerance - p[2]);
     }
 
   Assert(false, ExcNotImplemented());

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.