https://mooseframework.inl.gov
ElemExtremaTest.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "gtest/gtest.h"
11 
12 #include "ElemExtrema.h"
13 #include "TraceRayTools.h"
14 
15 #include "libmesh/elem.h"
16 #include "libmesh/mesh_generation.h"
17 #include "libmesh/replicated_mesh.h"
18 
19 TEST(ElemExtremaTest, Test)
20 {
21  Parallel::Communicator comm;
22  std::unique_ptr<UnstructuredMesh> mesh = std::make_unique<ReplicatedMesh>(comm);
23  MeshTools::Generation::build_cube(*mesh, 2, 2, 2);
24 
25  const Elem * elem = mesh->query_elem_ptr(0);
26  EXPECT_TRUE(elem != nullptr);
27 
28  {
29  ElemExtrema invalid;
30 
31  EXPECT_FALSE(invalid.atExtrema());
32  EXPECT_TRUE(invalid.isInvalid());
33  EXPECT_FALSE(invalid.atVertex());
34  EXPECT_FALSE(invalid.atVertex(0));
35  EXPECT_FALSE(invalid.atEdge());
36  EXPECT_FALSE(invalid.atEdge(0, 1));
37  EXPECT_TRUE(invalid.isValid(elem, elem->vertex_average()));
38 
39  std::stringstream oss;
40  oss << invalid;
41  EXPECT_EQ(oss.str(), "not at extrema");
42  }
43 
44  {
45  ElemExtrema at_vertex;
46  at_vertex.setVertex(0);
47 
48  EXPECT_TRUE(at_vertex.atExtrema());
49  EXPECT_FALSE(at_vertex.isInvalid());
50  EXPECT_TRUE(at_vertex.atVertex());
51  EXPECT_TRUE(at_vertex.atVertex(0));
52  EXPECT_FALSE(at_vertex.atVertex(1));
53  EXPECT_FALSE(at_vertex.atEdge());
54  EXPECT_FALSE(at_vertex.atEdge(0, 1));
55  EXPECT_EQ((unsigned short)0, at_vertex.vertex());
56 
57  const auto & vertex_point = at_vertex.vertexPoint(elem);
58  const auto & point = elem->point(0);
59  for (unsigned int d = 0; d < 3; ++d)
60  EXPECT_NEAR(vertex_point(d), point(d), 1.e-10);
61 
62  std::stringstream oss;
63  oss << at_vertex;
64  EXPECT_EQ(oss.str(), "at vertex 0");
65 
66  EXPECT_TRUE(at_vertex.isValid(elem, elem->point(0)));
67 
68  at_vertex.invalidate();
69  EXPECT_TRUE(at_vertex.isInvalid());
70  }
71 
72  {
73  Point edge_point(0.25, 0, 0);
74  ElemExtrema at_edge_temp;
75 
76  EXPECT_TRUE(TraceRayTools::withinEdge(elem, edge_point, at_edge_temp));
77 
78  ElemExtrema at_edge;
79  at_edge.setEdge(at_edge_temp.edgeVertices());
80 
81  EXPECT_TRUE(at_edge.atExtrema());
82  EXPECT_FALSE(at_edge.isInvalid());
83  EXPECT_FALSE(at_edge.atVertex());
84  EXPECT_TRUE(at_edge.atEdge());
85  EXPECT_TRUE(at_edge.atEdge(at_edge.edgeVertices().first, at_edge.edgeVertices().second));
86  EXPECT_TRUE(at_edge.atEdge(at_edge.edgeVertices().second, at_edge.edgeVertices().first));
87 
88  const auto edge = at_edge.buildEdge(elem);
89  for (unsigned int d = 0; d < 3; ++d)
90  {
91  EXPECT_NEAR(edge->point(0)(d), elem->point(at_edge.edgeVertices().first)(d), 1.e-10);
92  EXPECT_NEAR(edge->point(1)(d), elem->point(at_edge.edgeVertices().second)(d), 1.e-10);
93  }
94 
95  EXPECT_TRUE(at_edge.isValid(elem, edge_point));
96  std::stringstream should_be;
97  should_be << "at edge with vertices " << at_edge.edgeVertices().first << " and "
98  << at_edge.edgeVertices().second;
99  std::stringstream oss;
100  oss << at_edge;
101  EXPECT_EQ(oss.str(), should_be.str());
102  }
103 
104  {
105  ElemExtrema at_edge(0, 1);
106  EXPECT_TRUE(at_edge.first == 0);
107  EXPECT_TRUE(at_edge.second == 1);
108  }
109 }
unsigned short vertex() const
Definition: ElemExtrema.h:96
void setEdge(const unsigned short v1, const unsigned short v2)
Sets the "at edge" state.
Definition: ElemExtrema.h:127
MeshBase & mesh
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&#39;s edge, vertex, or neither.
Definition: ElemExtrema.h:25
std::unique_ptr< const libMesh::Elem > buildEdge(const Elem *elem) const
Definition: ElemExtrema.C:22
bool isInvalid() const
Definition: ElemExtrema.h:48
TEST(ElemExtremaTest, Test)
bool isValid(const Elem *const elem, const Point &point) const
Definition: ElemExtrema.C:49
const std::pair< unsigned short, unsigned short > & edgeVertices() const
Definition: ElemExtrema.h:104
bool atExtrema() const
Definition: ElemExtrema.h:44
void setVertex(const unsigned short vertex)
Sets the "at vertex" state.
Definition: ElemExtrema.h:118
bool atVertex() const
Definition: ElemExtrema.h:56
bool atEdge() const
Definition: ElemExtrema.h:71
const Point & vertexPoint(const libMesh::Elem *elem) const
Definition: ElemExtrema.C:16