https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Functions
TraceRayToolsTest.C File Reference

Go to the source code of this file.

Functions

std::unique_ptr< UnstructuredMesh > traceRayToolsTestMesh (const int type)
 
 TEST (TraceRayToolsTest, withinEdge)
 
 TEST (TraceRayToolsTest, withinEdgeOnSide)
 
 TEST (TraceRayToolsTest, atVertex)
 
 TEST (TraceRayToolsTest, atVertexOnSide)
 
 TEST (TraceRayToolsTest, findPointNeighbors)
 
 TEST (TraceRayToolsTest, isWithinSegment)
 

Function Documentation

◆ TEST() [1/6]

TEST ( TraceRayToolsTest  ,
atVertex   
)

Definition at line 152 of file TraceRayToolsTest.C.

153{
154 for (const auto type : TraceRayTools::TRACEABLE_ELEMTYPES)
155 {
156 auto mesh = traceRayToolsTestMesh(type);
157 EXPECT_TRUE(mesh);
158
159 for (const auto elem : mesh->element_ptr_range())
160 {
161 EXPECT_EQ(TraceRayTools::atVertex(elem, elem->vertex_average()),
163 for (const auto n : elem->node_index_range())
164 if (elem->is_vertex(n))
165 {
166 EXPECT_EQ((unsigned short)n, TraceRayTools::atVertex(elem, elem->point(n)));
167 }
168 }
169 }
170}
std::unique_ptr< UnstructuredMesh > traceRayToolsTestMesh(const int type)
MeshBase & mesh
static const unsigned short invalid_vertex
Identifier for an invalid vertex index.
unsigned short atVertex(const Elem *elem, const Point &point)
Determines if a point is at a vertex of an element.
const std::set< int > TRACEABLE_ELEMTYPES
The element types that are traceable.
if(subdm)

◆ TEST() [2/6]

TEST ( TraceRayToolsTest  ,
atVertexOnSide   
)

Definition at line 172 of file TraceRayToolsTest.C.

173{
174 for (const auto type : TraceRayTools::TRACEABLE_ELEMTYPES)
175 {
176 auto mesh = traceRayToolsTestMesh(type);
177 EXPECT_TRUE(mesh);
178
179 for (const auto elem : mesh->element_ptr_range())
180 for (const auto s : elem->side_index_range())
181 {
182 if (elem->dim() > 1)
183 {
184 EXPECT_EQ(
185 TraceRayTools::atVertexOnSide(elem, elem->build_side_ptr(s)->vertex_average(), s),
187 }
188
189 for (const auto n : elem->nodes_on_side(s))
190 if (elem->is_vertex(n))
191 {
192 EXPECT_EQ(TraceRayTools::atVertexOnSide(elem, elem->point(n), s), (unsigned short)n);
193 }
194 }
195 }
196}
for(PetscInt i=0;i< nvars;++i)
unsigned short atVertexOnSide(const Elem *elem, const Point &point, const unsigned short side)
Determines if a point is at a vertex on the side of en element.

◆ TEST() [3/6]

TEST ( TraceRayToolsTest  ,
findPointNeighbors   
)

Definition at line 198 of file TraceRayToolsTest.C.

199{
203 std::vector<const Elem *> active_neighbor_children;
204 std::vector<NeighborInfo> neighbor_info;
205 std::set<const Elem *> libmesh_neighbor_set;
206
207 for (const auto type : TraceRayTools::TRACEABLE_ELEMTYPES)
208 {
209 auto mesh = traceRayToolsTestMesh(type);
210 EXPECT_TRUE(mesh);
211
212 for (const auto elem : mesh->element_ptr_range())
213 {
214 for (const auto n : elem->node_index_range())
215 {
217 elem->point(n),
218 neighbor_set,
219 neighbor_untested_set,
220 neighbor_next_untested_set,
221 active_neighbor_children,
222 neighbor_info);
223 elem->find_point_neighbors(elem->point(n), libmesh_neighbor_set);
224 for (const auto & info : neighbor_info)
225 {
226 for (const auto s : info._sides)
227 EXPECT_TRUE(info._elem->build_side_ptr(s)->contains_point(elem->point(n)));
228 EXPECT_TRUE(libmesh_neighbor_set.count(info._elem));
229 }
230 }
231
232 for (const auto s : elem->side_index_range())
233 {
234 const auto centroid = elem->build_side_ptr(s)->vertex_average();
236 centroid,
237 neighbor_set,
238 neighbor_untested_set,
239 neighbor_next_untested_set,
240 active_neighbor_children,
241 neighbor_info);
242 elem->find_point_neighbors(centroid, libmesh_neighbor_set);
243 for (const auto & info : neighbor_info)
244 {
245 for (const auto other_s : info._sides)
246 EXPECT_TRUE(info._elem->build_side_ptr(other_s)->contains_point(centroid));
247 EXPECT_TRUE(libmesh_neighbor_set.count(info._elem));
248 }
249 }
250
251 if (elem->dim() == 3)
252 for (const auto e : elem->edge_index_range())
253 {
254 const auto centroid = elem->build_edge_ptr(e)->vertex_average();
256 centroid,
257 neighbor_set,
258 neighbor_untested_set,
259 neighbor_next_untested_set,
260 active_neighbor_children,
261 neighbor_info);
262 elem->find_point_neighbors(centroid, libmesh_neighbor_set);
263 for (const auto & info : neighbor_info)
264 {
265 for (const auto s : info._sides)
266 EXPECT_TRUE(info._elem->build_side_ptr(s)->contains_point(centroid));
267 EXPECT_TRUE(libmesh_neighbor_set.count(info._elem));
268 }
269 }
270 }
271 }
272}
MPI_Info info
void findPointNeighbors(const Elem *const elem, const Point &point, MooseUtils::StaticallyAllocatedSet< const Elem *, MAX_POINT_NEIGHBORS > &neighbor_set, MooseUtils::StaticallyAllocatedSet< const Elem *, MAX_POINT_NEIGHBORS > &untested_set, MooseUtils::StaticallyAllocatedSet< const Elem *, MAX_POINT_NEIGHBORS > &next_untested_set, std::vector< const Elem * > active_neighbor_children, std::vector< NeighborInfo > &info)
Rewrite of the find_point_neighbors function in libMesh, instead using a statically allocated set: re...

◆ TEST() [4/6]

TEST ( TraceRayToolsTest  ,
isWithinSegment   
)

Definition at line 274 of file TraceRayToolsTest.C.

275{
276 EXPECT_TRUE(TraceRayTools::isWithinSegment(Point(0, 1, 2), Point(1, 1, 2), Point(0.5, 1, 2)));
277 EXPECT_TRUE(TraceRayTools::isWithinSegment(Point(5, 6, 7), Point(8, 9, 10), Point(5, 6, 7)));
278 EXPECT_TRUE(TraceRayTools::isWithinSegment(Point(2, 3, 4), Point(4, 5, 6), Point(4, 5, 6)));
279 EXPECT_FALSE(TraceRayTools::isWithinSegment(Point(1, 2, 3), Point(4, 5, 6), Point(10, 0, 0)));
280}
bool isWithinSegment(const Point &segment1, const Point &segment2, const Point &point, const Real tolerance=TRACE_TOLERANCE)
Checks whether or not a point is within a line segment.

◆ TEST() [5/6]

TEST ( TraceRayToolsTest  ,
withinEdge   
)

Definition at line 66 of file TraceRayToolsTest.C.

67{
68 ElemExtrema extrema;
69
70 for (const auto type : TraceRayTools::TRACEABLE_ELEMTYPES)
71 {
72 auto mesh = traceRayToolsTestMesh(type);
73 EXPECT_TRUE(mesh);
74
75 if (mesh->mesh_dimension() != 3)
76 continue;
77
78 for (const auto elem : mesh->element_ptr_range())
79 {
80 for (const auto e : elem->edge_index_range())
81 {
82 extrema.invalidate();
83 EXPECT_TRUE(
84 TraceRayTools::withinEdge(elem, elem->build_edge_ptr(e)->vertex_average(), extrema));
85 EXPECT_TRUE(extrema.atEdge(elem->nodes_on_edge(e)[0], elem->nodes_on_edge(e)[1]));
86 }
87 for (const auto n : elem->node_index_range())
88 if (elem->is_vertex(n))
89 {
90 extrema.invalidate();
91 EXPECT_TRUE(TraceRayTools::withinEdge(elem, elem->point(n), extrema));
92
93 bool extrema_correct = false;
94 for (const auto e : elem->edge_index_range())
95 if (!extrema_correct && elem->is_node_on_edge(n, e))
96 extrema_correct =
97 extrema.atEdge(elem->nodes_on_edge(e)[0], elem->nodes_on_edge(e)[1]);
98 EXPECT_TRUE(extrema_correct);
99 }
100 }
101 }
102}
bool withinEdge(const Elem *elem, const Point &point, ElemExtrema &extrema, const Real tolerance=TRACE_TOLERANCE)
Determines if a point is within an edge on an element.
Helper for defining if at an element's edge, vertex, or neither.
Definition ElemExtrema.h:26
bool atEdge() const
Definition ElemExtrema.h:71
void invalidate()
Invalidates the current state.
Definition ElemExtrema.h:87

◆ TEST() [6/6]

TEST ( TraceRayToolsTest  ,
withinEdgeOnSide   
)

Definition at line 104 of file TraceRayToolsTest.C.

105{
106 ElemExtrema extrema;
107
108 for (const auto type : TraceRayTools::TRACEABLE_ELEMTYPES)
109 {
110 auto mesh = traceRayToolsTestMesh(type);
111 EXPECT_TRUE(mesh);
112
113 if (mesh->mesh_dimension() != 3)
114 continue;
115
116 for (const auto elem : mesh->element_ptr_range())
117 {
118 for (const auto s : elem->side_index_range())
119 {
120 extrema.invalidate();
122 elem, elem->build_side_ptr(s)->vertex_average(), s, extrema));
123 EXPECT_TRUE(extrema.isInvalid());
124
125 for (const auto e : elem->edge_index_range())
126 if (elem->is_edge_on_side(e, s))
127 {
128 extrema.invalidate();
130 elem, elem->build_edge_ptr(e)->vertex_average(), s, extrema));
131 }
132 }
133 for (const auto n : elem->node_index_range())
134 if (elem->is_vertex(n))
135 for (const auto s : elem->side_index_range())
136 if (elem->is_node_on_side(n, s))
137 {
138 extrema.invalidate();
139 EXPECT_TRUE(TraceRayTools::withinEdgeOnSide(elem, elem->point(n), s, extrema));
140
141 bool extrema_correct = false;
142 for (const auto e : elem->edge_index_range())
143 if (!extrema_correct && elem->is_node_on_edge(n, e))
144 extrema_correct =
145 extrema.atEdge(elem->nodes_on_edge(e)[0], elem->nodes_on_edge(e)[1]);
146 EXPECT_TRUE(extrema_correct);
147 }
148 }
149 }
150}
bool withinEdgeOnSide(const Elem *const elem, const Point &point, const unsigned short side, ElemExtrema &extrema)
Determines if a point is within an edge on the side of an element.
bool isInvalid() const
Definition ElemExtrema.h:48

◆ traceRayToolsTestMesh()

std::unique_ptr< UnstructuredMesh > traceRayToolsTestMesh ( const int  type)

Definition at line 18 of file TraceRayToolsTest.C.

19{
20 Parallel::Communicator comm;
21 std::unique_ptr<UnstructuredMesh> mesh = std::make_unique<ReplicatedMesh>(comm);
22
23 const unsigned int n = 2;
24 const Real min = 0;
25 const Real max = 1;
26 switch ((ElemType)type)
27 {
28 case EDGE2:
29 case EDGE3:
30 case EDGE4:
31 MeshTools::Generation::build_line(*mesh, n, min, max, (ElemType)type);
32 break;
33 case QUAD4:
34 case QUAD8:
35 case QUAD9:
36 case TRI3:
37 case TRI6:
38 case TRI7:
39 MeshTools::Generation::build_square(*mesh, n, n, min, max, min, max, (ElemType)type);
40 break;
41 case HEX8:
42 case HEX20:
43 case HEX27:
44 case TET4:
45 case TET10:
46 case TET14:
47 case PYRAMID5:
48 case PYRAMID13:
49 case PYRAMID14:
50 case PRISM6:
51 case PRISM15:
52 case PRISM18:
53 MeshTools::Generation::build_cube(
54 *mesh, n, n, n, min, max, min, max, min, max, (ElemType)type);
55 break;
56 default:
57 break;
58 }
59
60 if (mesh)
61 mesh->prepare_for_use();
62
63 return mesh;
64}
auto max(const L &left, const R &right)
auto min(const L &left, const R &right)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().