25 const Elem & element = surface_elem.
elem();
26 const Point & normal = surface_elem.
normal();
35 if (element.n_sides() == 0)
37 const auto t = element.build_side_ptr(0)->type();
38 return t == EDGE2 || t == NODEELEM;
40 "SBMUtils::distanceFrom only handles EDGE2 and NODEELEM element sides.");
43 const auto vec_to_first = element.point(0) - pt;
44 const auto scale = vec_to_first * normal;
45 const auto projection = normal *
scale;
48 if (element.contains_point(pt + projection))
52 Real min_dist = std::numeric_limits<Real>::max();
55 const unsigned int n_edges = element.n_sides();
56 for (
unsigned int j = 0; j < n_edges; ++j)
58 std::unique_ptr<const Elem> curr_edge = element.build_side_ptr(j);
60 switch (curr_edge->type())
64 const Point & p1 = *curr_edge->node_ptr(0);
65 const Point & p2 = *curr_edge->node_ptr(1);
67 const Point edge = p2 - p1;
68 Real t = ((pt - p1) * edge) / (edge * edge);
69 t = std::clamp(t, 0.0, 1.0);
70 const Point proj = p1 + t * edge;
71 const Real dist = (pt - proj).norm();
76 closest_vec = proj - pt;
83 const Point &
p = *curr_edge->node_ptr(0);
84 const Real dist = (pt -
p).norm();
94 mooseAssert(
false,
"unreachable: side type validated by the precondition above");
libMesh::Point distanceFrom(const SurfaceElement &surface_elem, const libMesh::Point &pt)
Returns the vector from pt to the nearest point on the surface element: the normal projection if it f...