OGS
PyramidRule5.cpp
Go to the documentation of this file.
1 
11 #include "PyramidRule5.h"
12 
13 #include "BaseLib/Logging.h"
15 #include "MeshLib/Node.h"
16 #include "Quad.h"
17 #include "Tri.h"
18 
19 namespace MeshLib
20 {
21 const unsigned PyramidRule5::face_nodes[5][4] = {
22  {0, 1, 4, 99}, // Face 0
23  {1, 2, 4, 99}, // Face 1
24  {2, 3, 4, 99}, // Face 2
25  {3, 0, 4, 99}, // Face 3
26  {0, 3, 2, 1} // Face 4
27 };
28 
29 const unsigned PyramidRule5::edge_nodes[8][2] = {
30  {0, 1}, // Edge 0
31  {1, 2}, // Edge 1
32  {2, 3}, // Edge 2
33  {0, 3}, // Edge 3
34  {0, 4}, // Edge 4
35  {1, 4}, // Edge 5
36  {2, 4}, // Edge 6
37  {3, 4} // Edge 7
38 };
39 
40 const unsigned PyramidRule5::n_face_nodes[5] = {3, 3, 3, 3, 4};
41 
42 const Element* PyramidRule5::getFace(const Element* e, unsigned i)
43 {
44  if (i < e->getNumberOfFaces())
45  {
46  unsigned nFaceNodes(PyramidRule5::n_face_nodes[i]);
47  auto** nodes = new Node*[nFaceNodes];
48  for (unsigned j = 0; j < nFaceNodes; j++)
49  {
50  nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
51  }
52 
53  if (i < 4)
54  {
55  return new Tri(nodes, e->getID());
56  }
57 
58  return new Quad(nodes, e->getID());
59  }
60  ERR("Error in MeshLib::Element::getFace() - Index {:d} does not exist.", i);
61  return nullptr;
62 }
63 
64 double PyramidRule5::computeVolume(Node const* const* _nodes)
65 {
67  *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[4]) +
69  *_nodes[2], *_nodes[3], *_nodes[0], *_nodes[4]);
70 }
71 
72 bool PyramidRule5::isPntInElement(Node const* const* nodes,
73  MathLib::Point3d const& pnt,
74  double eps)
75 {
77  pnt, *nodes[0], *nodes[1], *nodes[2], *nodes[4], eps) ||
79  pnt, *nodes[0], *nodes[2], *nodes[3], *nodes[4], eps));
80 }
81 
82 unsigned PyramidRule5::identifyFace(Node const* const* _nodes,
83  Node const* nodes[3])
84 {
85  for (unsigned i = 0; i < 5; i++)
86  {
87  unsigned flag(0);
88  for (unsigned j = 0; j < 4; j++)
89  {
90  for (unsigned k = 0; k < 3; k++)
91  {
92  if (face_nodes[i][j] != 99 &&
93  _nodes[face_nodes[i][j]] == nodes[k])
94  {
95  flag++;
96  }
97  }
98  }
99  if (flag == 3)
100  {
101  return i;
102  }
103  }
104  return std::numeric_limits<unsigned>::max();
105 }
106 
108 {
109  ElementErrorCode error_code;
111 
112  std::unique_ptr<MeshLib::Quad const> const base{
113  dynamic_cast<MeshLib::Quad const*>(e->getFace(4))};
114  if (base)
115  {
116  error_code |= base->validate();
118  }
119  else
120  {
121  error_code.set(ElementErrorFlag::NodeOrder);
122  }
123 
124  return error_code;
125 }
126 
127 } // end namespace MeshLib
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of the Node class.
Definition of the Quad class.
Definition of the Tri class.
Collects error flags for mesh elements.
void set(ElementErrorFlag e)
Set a specific flag.
virtual const Node * getNode(unsigned idx) const =0
virtual bool testElementNodeOrder() const =0
virtual const Element * getFace(unsigned i) const =0
Returns the i-th face of the element.
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:82
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
static const unsigned face_nodes[5][4]
Constant: Local node index table for faces.
Definition: PyramidRule5.h:68
static unsigned identifyFace(Node const *const *, Node const *nodes[3])
Returns the ID of a face given an array of nodes.
static const unsigned n_face_nodes[5]
Constant: Table for the number of nodes for each face.
Definition: PyramidRule5.h:74
static double computeVolume(Node const *const *_nodes)
Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
static const Element * getFace(const Element *e, unsigned i)
Returns the i-th face of the element.
static ElementErrorCode validate(const Element *e)
static const unsigned edge_nodes[8][2]
Constant: Local node index table for edge.
Definition: PyramidRule5.h:71
double calcTetrahedronVolume(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &d)
bool isPointInTetrahedron(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &d, double eps)
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition: Element.cpp:121
TemplateElement< MeshLib::TriRule3 > Tri
Definition: Tri.h:26
TemplateElement< MeshLib::QuadRule4 > Quad
Definition: Quad.h:28