56 bool start_with_centroid,
57 const Real tangential_tolerance,
58 bool & contact_point_on_side,
59 bool & search_succeeded)
62 search_succeeded =
true;
64 const Elem * primary_elem = p_info.
_elem;
66 const Elem * side = p_info.
_side;
69 unsigned int dim = side->dim() + 1;
71 const std::vector<libMesh::Point> & phys_point = fe_side->get_xyz();
73 const std::vector<RealGradient> & dxyz_dxi = fe_side->get_dxyzdxi();
74 const std::vector<RealGradient> & d2xyz_dxi2 = fe_side->get_d2xyzdxi2();
75 const std::vector<RealGradient> & d2xyz_dxieta = fe_side->get_d2xyzdxideta();
77 const std::vector<RealGradient> & dxyz_deta = fe_side->get_dxyzdeta();
78 const std::vector<RealGradient> & d2xyz_deta2 = fe_side->get_d2xyzdeta2();
79 const std::vector<RealGradient> & d2xyz_detaxi = fe_side->get_d2xyzdxideta();
83 const Node * nearest_node = side->node_ptr(0);
86 primary_elem->master_point(primary_elem->get_node_index(nearest_node));
89 const std::vector<RealGradient> & elem_dxyz_dxi = fe_elem->get_dxyzdxi();
91 fe_elem->reinit(primary_elem, &elem_points);
92 fe_side->reinit(side, &elem_points);
94 p_info.
_normal = elem_dxyz_dxi[0];
95 if (nearest_node->id() == primary_elem->node_id(0))
108 contact_point_on_side =
true;
114 if (start_with_centroid)
115 ref_point = FEMap::inverse_map(
dim - 1, side, side->vertex_average(), TOLERANCE,
false);
119 std::vector<libMesh::Point> points = {ref_point};
120 fe_side->reinit(side, &points);
121 RealGradient d = secondary_point - phys_point[0];
123 Real update_size = std::numeric_limits<Real>::max();
126 for (
unsigned int it = 0; it < 3 && update_size > TOLERANCE * 1e3; ++it)
128 DenseMatrix<Real> jac(
dim - 1,
dim - 1);
129 jac(0, 0) = -(dxyz_dxi[0] * dxyz_dxi[0]);
133 jac(1, 0) = -(dxyz_dxi[0] * dxyz_deta[0]);
134 jac(0, 1) = -(dxyz_deta[0] * dxyz_dxi[0]);
135 jac(1, 1) = -(dxyz_deta[0] * dxyz_deta[0]);
138 DenseVector<Real> rhs(
dim - 1);
139 rhs(0) = dxyz_dxi[0] * d;
142 rhs(1) = dxyz_deta[0] * d;
144 DenseVector<Real> update(
dim - 1);
145 jac.lu_solve(rhs, update);
147 ref_point(0) -= update(0);
150 ref_point(1) -= update(1);
152 points[0] = ref_point;
153 fe_side->reinit(side, &points);
154 d = secondary_point - phys_point[0];
156 update_size = update.l2_norm();
159 update_size = std::numeric_limits<Real>::max();
164 const auto max_newton_its = 25;
165 const auto tolerance_newton = 1e3 * TOLERANCE * TOLERANCE;
166 for (; nit < max_newton_its && update_size > tolerance_newton; nit++)
168 d = secondary_point - phys_point[0];
170 DenseMatrix<Real> jac(
dim - 1,
dim - 1);
171 jac(0, 0) = (d2xyz_dxi2[0] * d) - (dxyz_dxi[0] * dxyz_dxi[0]);
175 jac(1, 0) = (d2xyz_dxieta[0] * d) - (dxyz_dxi[0] * dxyz_deta[0]);
177 jac(0, 1) = (d2xyz_detaxi[0] * d) - (dxyz_deta[0] * dxyz_dxi[0]);
178 jac(1, 1) = (d2xyz_deta2[0] * d) - (dxyz_deta[0] * dxyz_deta[0]);
181 DenseVector<Real> rhs(
dim - 1);
182 rhs(0) = -dxyz_dxi[0] * d;
185 rhs(1) = -dxyz_deta[0] * d;
187 DenseVector<Real> update(
dim - 1);
188 jac.lu_solve(rhs, update);
197 ref_point(0) += mult * update(0);
200 ref_point(1) += mult * update(1);
202 points[0] = ref_point;
203 fe_side->reinit(side, &points);
204 d = secondary_point - phys_point[0];
207 update_size = update.l2_norm();
211 catch (std::exception & e)
214 if (!strstr(e.what(),
"Jacobian") && !strstr(e.what(),
"det != 0"))
217 ref_point(0) -= mult * update(0);
219 ref_point(1) -= mult * update(1);
225 mooseWarning(
"We could not solve for the contact point.", e.what());
227 update_size = update.l2_norm();
228 d = (secondary_point - phys_point[0]) * mult;
236 nit = max_newton_its;
242 if (nit == max_newton_its && update_size > tolerance_newton)
244 search_succeeded =
false;
246 const auto initial_point =
248 Moose::err <<
"Warning! Newton solve for contact point failed to converge!\nLast update "
250 << update_size <<
"\nInitial point guess: " << initial_point
251 <<
"\nLast considered point: " << phys_point[0]
252 <<
"\nThis potential contact pair (face, point) will be discarded." << std::endl;
263 p_info.
_normal = dxyz_dxi[0].cross(dxyz_deta[0]);
264 if (!MooseUtils::absoluteFuzzyEqual(p_info.
_normal.norm(), 0))
270 if (std::fabs(p_info.
_normal.norm()) > 1e-15)
275 const Real dot(d * p_info.
_normal);
279 contact_point_on_side = side->on_reference_element(ref_point);
283 if (!contact_point_on_side)
289 fe_side->reinit(side, &points);
292 RealGradient off_face = closest_point_on_face - p_info.
_closest_point;
293 Real tangential_distance = off_face.norm();
295 if (tangential_distance <= tangential_tolerance)
297 contact_point_on_side =
true;
301 const std::vector<std::vector<Real>> & phi = fe_side->get_phi();
302 const std::vector<std::vector<RealGradient>> & grad_phi = fe_side->get_dphi();
305 fe_side->reinit(side, &points);
328 std::vector<const Node *> & off_edge_nodes)
330 const ElemType t(side->type());
331 off_edge_nodes.clear();
345 off_edge_nodes.push_back(side->node_ptr(0));
350 off_edge_nodes.push_back(side->node_ptr(1));
362 if (
xi <= 0.0 &&
eta <= 0.0)
366 off_edge_nodes.push_back(side->node_ptr(0));
368 else if (
xi > 0.0 &&
xi < 1.0 &&
eta < 0.0)
371 off_edge_nodes.push_back(side->node_ptr(0));
372 off_edge_nodes.push_back(side->node_ptr(1));
374 else if (
eta > 0.0 &&
eta < 1.0 &&
xi < 0.0)
377 off_edge_nodes.push_back(side->node_ptr(2));
378 off_edge_nodes.push_back(side->node_ptr(0));
380 else if (
xi >= 1.0 && (
eta -
xi) <= -1.0)
384 off_edge_nodes.push_back(side->node_ptr(1));
386 else if (
eta >= 1.0 && (
eta -
xi) >= 1.0)
390 off_edge_nodes.push_back(side->node_ptr(2));
392 else if ((
xi +
eta) > 1.0)
394 Real delta = (
xi +
eta - 1.0) / 2.0;
397 off_edge_nodes.push_back(side->node_ptr(1));
398 off_edge_nodes.push_back(side->node_ptr(2));
414 off_edge_nodes.push_back(side->node_ptr(0));
419 off_edge_nodes.push_back(side->node_ptr(3));
423 off_edge_nodes.push_back(side->node_ptr(3));
424 off_edge_nodes.push_back(side->node_ptr(0));
433 off_edge_nodes.push_back(side->node_ptr(1));
438 off_edge_nodes.push_back(side->node_ptr(2));
442 off_edge_nodes.push_back(side->node_ptr(1));
443 off_edge_nodes.push_back(side->node_ptr(2));
451 off_edge_nodes.push_back(side->node_ptr(0));
452 off_edge_nodes.push_back(side->node_ptr(1));
457 off_edge_nodes.push_back(side->node_ptr(2));
458 off_edge_nodes.push_back(side->node_ptr(3));