https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
MeshBaseDiagnosticsUtils Namespace Reference

Functions

void checkNonConformalMesh (const std::unique_ptr< libMesh::MeshBase > &mesh, const ConsoleStream &console, const unsigned int num_outputs, const Real conformality_tol, unsigned int &num_nonconformal_nodes)
 
bool checkFirstOrderEdgeOverlap (const Elem &edge1, const Elem &edge2, Point &intersection_point, const Real intersection_tol)
 
void checkNonConformalMesh (const std::unique_ptr< MeshBase > &mesh, const ConsoleStream &console, const unsigned int num_outputs, const Real conformality_tol, unsigned int &num_nonconformal_nodes)
 

Function Documentation

◆ checkFirstOrderEdgeOverlap()

bool MeshBaseDiagnosticsUtils::checkFirstOrderEdgeOverlap ( const Elem &  edge1,
const Elem &  edge2,
Point &  intersection_point,
const Real  intersection_tol 
)

Definition at line 72 of file MeshBaseDiagnosticsUtils.C.

76{
77 // check that the two elements are of type EDGE2
78 mooseAssert(edge1.type() == EDGE2, "Elements must be of type EDGE2");
79 mooseAssert(edge2.type() == EDGE2, "Elements must be of type EDGE2");
80 // Get nodes from the two edges
81 const Point & p1 = edge1.point(0);
82 const Point & p2 = edge1.point(1);
83 const Point & p3 = edge2.point(0);
84 const Point & p4 = edge2.point(1);
85
86 // Check that the two edges are not sharing a node
87 if (p1 == p3 || p1 == p4 || p2 == p3 || p2 == p4)
88 return false;
89
90 /*
91 There's a chance that they overlap. Find shortest line that connects two edges and if its length
92 is close enough to 0 return true The shortest line between the two edges will be perpendicular
93 to both.
94 */
95 const auto d1343 = (p1 - p3) * (p4 - p3);
96 const auto d4321 = (p4 - p3) * (p2 - p1);
97 const auto d1321 = (p1 - p3) * (p2 - p1);
98 const auto d4343 = (p4 - p3) * (p4 - p3);
99 const auto d2121 = (p2 - p1) * (p2 - p1);
100
101 const auto denominator = d2121 * d4343 - d4321 * d4321;
102 const auto numerator = d1343 * d4321 - d1321 * d4343;
103
104 if (std::fabs(denominator) < intersection_tol)
105 // This indicates that the two lines are parallel so they don't intersect
106 return false;
107
108 const auto mua = numerator / denominator;
109 const auto mub = (d1343 + (mua * d4321)) / d4343;
110
111 // Use these values to solve for the two points that define the shortest line segment
112 const auto pa = p1 + mua * (p2 - p1);
113 const auto pb = p3 + mub * (p4 - p3);
114
115 // This method assume the two lines are infinite. This check to make sure na and nb are part of
116 // their respective line segments
117 if (mua < 0 || mua > 1)
118 return false;
119 if (mub < 0 || mub > 1)
120 return false;
121
122 // Calculate distance between these two nodes
123 const auto distance = (pa - pb).norm();
124 if (distance < intersection_tol)
125 {
126 intersection_point = pa;
127 return true;
128 }
129 else
130 return false;
131}
Real distance(const Point &p)

Referenced by MeshDiagnosticsGenerator::checkNonMatchingEdges().

◆ checkNonConformalMesh() [1/2]

void MeshBaseDiagnosticsUtils::checkNonConformalMesh ( const std::unique_ptr< libMesh::MeshBase > &  mesh,
const ConsoleStream console,
const unsigned int  num_outputs,
const Real  conformality_tol,
unsigned int num_nonconformal_nodes 
)

◆ checkNonConformalMesh() [2/2]

void MeshBaseDiagnosticsUtils::checkNonConformalMesh ( const std::unique_ptr< MeshBase > &  mesh,
const ConsoleStream console,
const unsigned int  num_outputs,
const Real  conformality_tol,
unsigned int num_nonconformal_nodes 
)

Definition at line 23 of file MeshBaseDiagnosticsUtils.C.

28{
29 num_nonconformal_nodes = 0;
30 auto pl = mesh->sub_point_locator();
31 pl->set_close_to_point_tol(conformality_tol);
32
33 if (!mesh->is_serial())
34 mooseError("Only serialized/replicated meshes are supported");
35
36 // loop on nodes, assumes a replicated mesh
37 for (auto & node : mesh->node_ptr_range())
38 {
39 // find all the elements around this node
40 std::set<const Elem *> elements;
41 (*pl)(*node, elements);
42
43 // loop through the set of elements near this node
44 for (auto & elem : elements)
45 {
46 // If the node is not part of this element's nodes, it is a
47 // case of non-conformality
48 bool found_conformal = false;
49
50 for (auto & elem_node : elem->node_ref_range())
51 {
52 if (*node == elem_node)
53 {
54 found_conformal = true;
55 break;
56 }
57 }
58 if (!found_conformal)
59 {
60 num_nonconformal_nodes++;
61 if (num_nonconformal_nodes < num_outputs)
62 console << "Non-conformality detected at : " << *node << std::endl;
63 else if (num_nonconformal_nodes == num_outputs)
64 console << "Maximum output reached, log is silenced" << std::endl;
65 }
66 }
67 }
68 pl->unset_close_to_point_tol();
69}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
MeshBase & mesh