OGS
PrismRule6.cpp
Go to the documentation of this file.
1 
11 #include "PrismRule6.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 PrismRule6::face_nodes[5][4] = {
22  {0, 2, 1, 99}, // Face 0
23  {0, 1, 4, 3}, // Face 1
24  {1, 2, 5, 4}, // Face 2
25  {2, 0, 3, 5}, // Face 3
26  {3, 4, 5, 99} // Face 4
27 };
28 
29 const unsigned PrismRule6::edge_nodes[9][2] = {
30  {0, 1}, // Edge 0
31  {1, 2}, // Edge 1
32  {0, 2}, // Edge 2
33  {0, 3}, // Edge 3
34  {1, 4}, // Edge 4
35  {2, 5}, // Edge 5
36  {3, 4}, // Edge 6
37  {4, 5}, // Edge 7
38  {3, 5} // Edge 8
39 };
40 
41 const unsigned PrismRule6::n_face_nodes[5] = {3, 4, 4, 4, 3};
42 
43 const Element* PrismRule6::getFace(const Element* e, unsigned i)
44 {
45  if (i < n_faces)
46  {
47  unsigned nFaceNodes(PrismRule6::n_face_nodes[i]);
48  auto** nodes = new Node*[nFaceNodes];
49  for (unsigned j = 0; j < nFaceNodes; j++)
50  {
51  nodes[j] = const_cast<Node*>(e->getNode(face_nodes[i][j]));
52  }
53 
54  if (i == 0 || i == 4)
55  {
56  return new Tri(nodes, e->getID());
57  }
58 
59  return new Quad(nodes);
60  }
61  ERR("Error in MeshLib::Element::getFace() - Index {:d} does not exist.", i);
62  return nullptr;
63 }
64 
65 double PrismRule6::computeVolume(Node const* const* _nodes)
66 {
68  *_nodes[0], *_nodes[1], *_nodes[2], *_nodes[3]) +
70  *_nodes[1], *_nodes[4], *_nodes[2], *_nodes[3]) +
72  *_nodes[2], *_nodes[4], *_nodes[5], *_nodes[3]);
73 }
74 
75 bool PrismRule6::isPntInElement(Node const* const* nodes,
76  MathLib::Point3d const& pnt,
77  double eps)
78 {
80  pnt, *nodes[0], *nodes[1], *nodes[2], *nodes[3], eps) ||
82  pnt, *nodes[1], *nodes[4], *nodes[2], *nodes[3], eps) ||
84  pnt, *nodes[2], *nodes[4], *nodes[5], *nodes[3], eps));
85 }
86 
87 unsigned PrismRule6::identifyFace(Node const* const* _nodes,
88  Node const* nodes[3])
89 {
90  for (unsigned i = 0; i < 5; i++)
91  {
92  unsigned flag(0);
93  for (unsigned j = 0; j < 4; j++)
94  {
95  for (unsigned k = 0; k < 3; k++)
96  {
97  if (face_nodes[i][j] != 99 &&
98  _nodes[face_nodes[i][j]] == nodes[k])
99  {
100  flag++;
101  }
102  }
103  }
104  if (flag == 3)
105  {
106  return i;
107  }
108  }
109  return std::numeric_limits<unsigned>::max();
110 }
111 
113 {
114  ElementErrorCode error_code;
116 
117  for (unsigned i = 1; i < 4; ++i)
118  {
119  const auto* quad(dynamic_cast<const MeshLib::Quad*>(e->getFace(i)));
120  if (quad)
121  {
122  error_code |= quad->validate();
123  }
124  else
125  {
126  error_code.set(ElementErrorFlag::NodeOrder);
127  }
128  delete quad;
129  }
131  return error_code;
132 }
133 
134 } // 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 ElementErrorCode validate(const Element *e)
Definition: PrismRule6.cpp:112
static const unsigned face_nodes[5][4]
Constant: Local node index table for faces.
Definition: PrismRule6.h:69
static const unsigned n_faces
Constant: The number of faces.
Definition: PrismRule6.h:60
static const unsigned n_face_nodes[5]
Constant: Table for the number of nodes for each face.
Definition: PrismRule6.h:75
static const unsigned edge_nodes[9][2]
Constant: Local node index table for edge.
Definition: PrismRule6.h:72
static double computeVolume(Node const *const *_nodes)
Calculates the volume of a convex hexahedron by partitioning it into six tetrahedra.
Definition: PrismRule6.cpp:65
static bool isPntInElement(Node const *const *nodes, MathLib::Point3d const &pnt, double eps)
Definition: PrismRule6.cpp:75
static const Element * getFace(const Element *e, unsigned i)
Returns the i-th face of the element.
Definition: PrismRule6.cpp:43
static unsigned identifyFace(Node const *const *, Node const *nodes[3])
Returns the ID of a face given an array of nodes.
Definition: PrismRule6.cpp:87
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