OGS
QuadRule4.cpp
Go to the documentation of this file.
1 
11 #include "QuadRule4.h"
12 
14 #include "MeshLib/Node.h"
15 
16 namespace MeshLib
17 {
18 const unsigned QuadRule4::edge_nodes[4][2] = {
19  {0, 1}, // Edge 0
20  {1, 2}, // Edge 1
21  {2, 3}, // Edge 2
22  {3, 0} // Edge 3
23 };
24 
25 double QuadRule4::computeVolume(Node const* const* _nodes)
26 {
27  return MathLib::calcTriangleArea(*_nodes[0], *_nodes[1], *_nodes[2]) +
28  MathLib::calcTriangleArea(*_nodes[2], *_nodes[3], *_nodes[0]);
29 }
30 
31 bool QuadRule4::isPntInElement(Node const* const* nodes,
32  MathLib::Point3d const& pnt,
33  double eps)
34 {
35  return (
36  MathLib::isPointInTriangle(pnt, *nodes[0], *nodes[1], *nodes[2], eps) ||
37  MathLib::isPointInTriangle(pnt, *nodes[0], *nodes[2], *nodes[3], eps));
38 }
39 
40 unsigned QuadRule4::identifyFace(Node const* const* _nodes,
41  Node const* nodes[3])
42 {
43  for (unsigned i = 0; i < 4; i++)
44  {
45  unsigned flag(0);
46  for (unsigned j = 0; j < 2; j++)
47  {
48  for (unsigned k = 0; k < 2; k++)
49  {
50  if (_nodes[edge_nodes[i][j]] == nodes[k])
51  {
52  flag++;
53  }
54  }
55  }
56  if (flag == 2)
57  {
58  return i;
59  }
60  }
61  return std::numeric_limits<unsigned>::max();
62 }
63 
65 {
66  ElementErrorCode error_code;
68  Node const* const* _nodes = e->getNodes();
69  error_code[ElementErrorFlag::NonCoplanar] =
70  (!MathLib::isCoplanar(*_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3]));
71  // for collapsed quads (i.e. reduced to a line) this test might result
72  // "false" as all four points are actually located on a line.
73  if (!error_code[ElementErrorFlag::ZeroVolume])
74  {
75  error_code[ElementErrorFlag::NonConvex] =
77  *_nodes[0], *_nodes[2], *_nodes[1], *_nodes[3]) &&
79  *_nodes[1], *_nodes[3], *_nodes[0], *_nodes[2])));
80  }
82  return error_code;
83 }
84 
85 } // end namespace MeshLib
Definition of the Node class.
Collects error flags for mesh elements.
virtual Node *const * getNodes() const =0
Get array of element nodes.
virtual bool testElementNodeOrder() const =0
static ElementErrorCode validate(const Element *e)
Definition: QuadRule4.cpp:64
static double computeVolume(Node const *const *_nodes)
Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
Definition: QuadRule4.cpp:25
static unsigned identifyFace(Node const *const *, Node const *nodes[3])
Returns the ID of a face given an array of nodes.
Definition: QuadRule4.cpp:40
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
Definition: QuadRule4.cpp:31
static const unsigned edge_nodes[4][2]
Constant: Local node index table for edge.
Definition: QuadRule4.h:59
double calcTriangleArea(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
bool isCoplanar(const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
Checks if the four given points are located on a plane.
bool dividedByPlane(const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
bool isPointInTriangle(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri, MathLib::TriangleTest algorithm)
bool hasZeroVolume(MeshLib::Element const &element)
Returns true if the element has zero length/area/volume.
Definition: Element.cpp:121