OGS
TetRule4.cpp
Go to the documentation of this file.
1 
11 #include "TetRule4.h"
12 
13 #include <array>
14 
15 #include "BaseLib/Logging.h"
16 #include "Line.h"
18 #include "MeshLib/Node.h"
19 #include "Tri.h"
20 
21 namespace MeshLib
22 {
23 const unsigned TetRule4::face_nodes[4][3] = {
24  {0, 2, 1}, // Face 0
25  {0, 1, 3}, // Face 1
26  {1, 2, 3}, // Face 2
27  {2, 0, 3} // Face 3
28 };
29 
30 const unsigned TetRule4::edge_nodes[6][2] = {
31  {0, 1}, // Edge 0
32  {1, 2}, // Edge 1
33  {0, 2}, // Edge 2
34  {0, 3}, // Edge 3
35  {1, 3}, // Edge 4
36  {2, 3} // Edge 5
37 };
38 
39 const Element* TetRule4::getFace(const Element* e, unsigned i)
40 {
41  if (i < n_faces)
42  {
43  std::array<Node*, 3> nodes{};
44  for (unsigned j = 0; j < 3; j++)
45  {
46  nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
47  }
48  return new Tri(nodes, e->getID());
49  }
50  ERR("Error in MeshLib::Element::getFace() - Index {:d} does not exist.", i);
51  return nullptr;
52 }
53 
54 double TetRule4::computeVolume(Node const* const* _nodes)
55 {
56  return MathLib::calcTetrahedronVolume(*_nodes[0], *_nodes[1], *_nodes[2],
57  *_nodes[3]);
58 }
59 
60 bool TetRule4::isPntInElement(Node const* const* nodes,
61  MathLib::Point3d const& pnt, double eps)
62 {
63  return MathLib::isPointInTetrahedron(pnt, *nodes[0], *nodes[1], *nodes[2],
64  *nodes[3], eps);
65 }
66 
67 unsigned TetRule4::identifyFace(Node const* const* _nodes, Node const* nodes[3])
68 {
69  for (unsigned i = 0; i < 4; i++)
70  {
71  unsigned flag(0);
72  for (unsigned j = 0; j < 3; j++)
73  {
74  for (unsigned k = 0; k < 3; k++)
75  {
76  if (_nodes[face_nodes[i][j]] == nodes[k])
77  {
78  flag++;
79  }
80  }
81  }
82  if (flag == 3)
83  {
84  return i;
85  }
86  }
87  return std::numeric_limits<unsigned>::max();
88 }
89 
91 {
92  ElementErrorCode error_code;
95  return error_code;
96 }
97 
98 } // end namespace MeshLib
Definition of the Line class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:44
Definition of the Node class.
Definition of the Tri class.
Collects error flags for mesh elements.
virtual const Node * getNode(unsigned idx) const =0
virtual bool testElementNodeOrder() const =0
virtual std::size_t getID() const final
Returns the ID of the element.
Definition: Element.h:89
static const unsigned face_nodes[4][3]
Constant: Local node index table for faces.
Definition: TetRule4.h:66
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
Definition: TetRule4.cpp:60
static double computeVolume(Node const *const *_nodes)
Calculates the volume of the element.
Definition: TetRule4.cpp:54
static const unsigned n_faces
Constant: The number of faces.
Definition: TetRule4.h:57
static const unsigned edge_nodes[6][2]
Constant: Local node index table for edge.
Definition: TetRule4.h:69
static const Element * getFace(const Element *e, unsigned i)
Returns the i-th face of the element.
Definition: TetRule4.cpp:39
static ElementErrorCode validate(const Element *e)
Definition: TetRule4.cpp:90
static unsigned identifyFace(Node const *const *, Node const *nodes[3])
Returns the ID of a face given an array of nodes.
Definition: TetRule4.cpp:67
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:119
TemplateElement< MeshLib::TriRule3 > Tri
Definition: Tri.h:26