OGS
HexRule8.cpp
Go to the documentation of this file.
1 
11 #include "HexRule8.h"
12 
13 #include <array>
14 
15 #include "BaseLib/Logging.h"
16 #include "Line.h"
18 #include "MeshLib/Node.h"
19 #include "Quad.h"
20 
21 namespace MeshLib
22 {
23 const unsigned HexRule8::face_nodes[6][4] = {
24  {0, 3, 2, 1}, // Face 0
25  {0, 1, 5, 4}, // Face 1
26  {1, 2, 6, 5}, // Face 2
27  {2, 3, 7, 6}, // Face 3
28  {3, 0, 4, 7}, // Face 4
29  {4, 5, 6, 7} // Face 5
30 };
31 
32 const unsigned HexRule8::edge_nodes[12][2] = {
33  {0, 1}, // Edge 0
34  {1, 2}, // Edge 1
35  {2, 3}, // Edge 2
36  {0, 3}, // Edge 3
37  {4, 5}, // Edge 4
38  {5, 6}, // Edge 5
39  {6, 7}, // Edge 6
40  {4, 7}, // Edge 7
41  {0, 4}, // Edge 8
42  {1, 5}, // Edge 9
43  {2, 6}, // Edge 10
44  {3, 7} // Edge 11
45 };
46 
47 const Element* HexRule8::getFace(const Element* e, unsigned i)
48 {
49  if (i < n_faces)
50  {
51  std::array<Node*, 4> nodes{};
52  for (unsigned j = 0; j < 4; j++)
53  {
54  nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
55  }
56  return new Quad(nodes, e->getID());
57  }
58  ERR("Error in MeshLib::Element::getFace() - Index {:d} does not exist.", i);
59  return nullptr;
60 }
61 
62 double HexRule8::computeVolume(Node const* const* _nodes)
63 {
65  *_nodes[4], *_nodes[7], *_nodes[5], *_nodes[0]) +
67  *_nodes[5], *_nodes[3], *_nodes[1], *_nodes[0]) +
69  *_nodes[5], *_nodes[7], *_nodes[3], *_nodes[0]) +
71  *_nodes[5], *_nodes[7], *_nodes[6], *_nodes[2]) +
73  *_nodes[1], *_nodes[3], *_nodes[5], *_nodes[2]) +
75  *_nodes[3], *_nodes[7], *_nodes[5], *_nodes[2]);
76 }
77 
78 bool HexRule8::isPntInElement(Node const* const* nodes,
79  MathLib::Point3d const& pnt,
80  double eps)
81 {
83  pnt, *nodes[4], *nodes[7], *nodes[5], *nodes[0], eps) ||
85  pnt, *nodes[5], *nodes[3], *nodes[1], *nodes[0], eps) ||
87  pnt, *nodes[5], *nodes[7], *nodes[3], *nodes[0], eps) ||
89  pnt, *nodes[5], *nodes[7], *nodes[6], *nodes[2], eps) ||
91  pnt, *nodes[1], *nodes[3], *nodes[5], *nodes[2], eps) ||
93  pnt, *nodes[3], *nodes[7], *nodes[5], *nodes[2], eps));
94 }
95 
96 unsigned HexRule8::identifyFace(Node const* const* _nodes, Node const* nodes[3])
97 {
98  for (unsigned i = 0; i < 6; i++)
99  {
100  unsigned flag(0);
101  for (unsigned j = 0; j < 4; j++)
102  {
103  for (unsigned k = 0; k < 3; k++)
104  {
105  if (_nodes[face_nodes[i][j]] == nodes[k])
106  {
107  flag++;
108  }
109  }
110  }
111  if (flag == 3)
112  {
113  return i;
114  }
115  }
116  return std::numeric_limits<unsigned>::max();
117 }
118 
120 {
121  ElementErrorCode error_code;
123 
124  for (unsigned i = 0; i < 6; ++i)
125  {
126  if (error_code.all())
127  {
128  break;
129  }
130 
131  const MeshLib::Element* quad(e->getFace(i));
132  error_code |= quad->validate();
133  delete quad;
134  }
136  return error_code;
137 }
138 
139 } // end namespace MeshLib
Definition of the Line class.
void ERR(char const *fmt, Args const &... args)
Definition: Logging.h:42
Definition of the Node class.
Definition of the Quad class.
Collects error flags for mesh elements.
virtual const Node * getNode(unsigned idx) const =0
virtual ElementErrorCode validate() 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 const Element * getFace(const Element *e, unsigned i)
Returns the i-th face of the element.
Definition: HexRule8.cpp:47
static unsigned identifyFace(Node const *const *, Node const *nodes[3])
Returns the ID of a face given an array of nodes.
Definition: HexRule8.cpp:96
static const unsigned edge_nodes[12][2]
Constant: Local node index table for edge.
Definition: HexRule8.h:74
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
Definition: HexRule8.cpp:78
static double computeVolume(Node const *const *_nodes)
Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
Definition: HexRule8.cpp:62
static ElementErrorCode validate(const Element *e)
Definition: HexRule8.cpp:119
static const unsigned face_nodes[6][4]
Constant: Local node index table for faces.
Definition: HexRule8.h:71
static const unsigned n_faces
Constant: The number of faces.
Definition: HexRule8.h:62
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::QuadRule4 > Quad
Definition: Quad.h:28