libMesh
cell_pyramid5.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 // Local includes
20 #include "libmesh/cell_pyramid5.h"
21 #include "libmesh/edge_edge2.h"
22 #include "libmesh/face_tri3.h"
23 #include "libmesh/face_quad4.h"
24 #include "libmesh/enum_io_package.h"
25 #include "libmesh/enum_order.h"
26 #include "libmesh/cell_hex8.h"
27 
28 namespace libMesh
29 {
30 
31 
32 
33 
34 // ------------------------------------------------------------
35 // Pyramid5 class static member initializations
36 const int Pyramid5::num_nodes;
37 const int Pyramid5::nodes_per_side;
38 const int Pyramid5::nodes_per_edge;
39 
41  {
42  {0, 1, 4, 99}, // Side 0
43  {1, 2, 4, 99}, // Side 1
44  {2, 3, 4, 99}, // Side 2
45  {3, 0, 4, 99}, // Side 3
46  {0, 3, 2, 1} // Side 4
47  };
48 
50  {
51  {0, 1}, // Edge 0
52  {1, 2}, // Edge 1
53  {2, 3}, // Edge 2
54  {0, 3}, // Edge 3
55  {0, 4}, // Edge 4
56  {1, 4}, // Edge 5
57  {2, 4}, // Edge 6
58  {3, 4} // Edge 7
59  };
60 
61 // ------------------------------------------------------------
62 // Pyramid5 class member functions
63 
64 bool Pyramid5::is_vertex(const unsigned int libmesh_dbg_var(n)) const
65 {
66  libmesh_assert_not_equal_to (n, invalid_uint);
67  return true;
68 }
69 
70 bool Pyramid5::is_edge(const unsigned int) const
71 {
72  return false;
73 }
74 
75 bool Pyramid5::is_face(const unsigned int) const
76 {
77  return false;
78 }
79 
80 bool Pyramid5::is_node_on_side(const unsigned int n,
81  const unsigned int s) const
82 {
83  libmesh_assert_less (s, n_sides());
84  return std::find(std::begin(side_nodes_map[s]),
85  std::end(side_nodes_map[s]),
86  n) != std::end(side_nodes_map[s]);
87 }
88 
89 std::vector<unsigned>
90 Pyramid5::nodes_on_side(const unsigned int s) const
91 {
92  libmesh_assert_less(s, n_sides());
93  auto trim = (s == 4) ? 0 : 1;
94  return {std::begin(side_nodes_map[s]), std::end(side_nodes_map[s]) - trim};
95 }
96 
97 std::vector<unsigned>
98 Pyramid5::nodes_on_edge(const unsigned int e) const
99 {
100  libmesh_assert_less(e, n_edges());
101  return {std::begin(edge_nodes_map[e]), std::end(edge_nodes_map[e])};
102 }
103 
104 bool Pyramid5::is_node_on_edge(const unsigned int n,
105  const unsigned int e) const
106 {
107  libmesh_assert_less (e, n_edges());
108  return std::find(std::begin(edge_nodes_map[e]),
109  std::end(edge_nodes_map[e]),
110  n) != std::end(edge_nodes_map[e]);
111 }
112 
113 
114 
116 {
117  // Point v = this->point(3) - this->point(0);
118  // return (v.relative_fuzzy_equals(this->point(2) - this->point(1)));
119  return false;
120 }
121 
122 
123 
125 {
126  return FIRST;
127 }
128 
129 
130 
131 std::unique_ptr<Elem> Pyramid5::build_side_ptr (const unsigned int i)
132 {
133  libmesh_assert_less (i, this->n_sides());
134 
135  std::unique_ptr<Elem> face;
136 
137  switch (i)
138  {
139  case 0: // triangular face 1
140  case 1: // triangular face 2
141  case 2: // triangular face 3
142  case 3: // triangular face 4
143  {
144  face = std::make_unique<Tri3>();
145  break;
146  }
147  case 4: // the quad face at z=0
148  {
149  face = std::make_unique<Quad4>();
150  break;
151  }
152  default:
153  libmesh_error_msg("Invalid side i = " << i);
154  }
155 
156  // Set the nodes
157  for (auto n : face->node_index_range())
158  face->set_node(n, this->node_ptr(Pyramid5::side_nodes_map[i][n]));
159 
160  face->set_interior_parent(this);
161  face->inherit_data_from(*this);
162 
163  return face;
164 }
165 
166 
167 
168 void Pyramid5::build_side_ptr (std::unique_ptr<Elem> & side,
169  const unsigned int i)
170 {
171  this->side_ptr(side, i);
172  side->set_interior_parent(this);
173  side->inherit_data_from(*this);
174 }
175 
176 
177 
178 std::unique_ptr<Elem> Pyramid5::build_edge_ptr (const unsigned int i)
179 {
180  return this->simple_build_edge_ptr<Edge2,Pyramid5>(i);
181 }
182 
183 
184 
185 void Pyramid5::build_edge_ptr (std::unique_ptr<Elem> & edge, const unsigned int i)
186 {
187  this->simple_build_edge_ptr<Pyramid5>(edge, i, EDGE2);
188 }
189 
190 
191 
192 void Pyramid5::connectivity(const unsigned int libmesh_dbg_var(sc),
193  const IOPackage iop,
194  std::vector<dof_id_type> & conn) const
195 {
197  libmesh_assert_less (sc, this->n_sub_elem());
198  libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE);
199 
200  switch (iop)
201  {
202  case TECPLOT:
203  {
204  conn.resize(8);
205  conn[0] = this->node_id(0)+1;
206  conn[1] = this->node_id(1)+1;
207  conn[2] = this->node_id(2)+1;
208  conn[3] = this->node_id(3)+1;
209  conn[4] = this->node_id(4)+1;
210  conn[5] = this->node_id(4)+1;
211  conn[6] = this->node_id(4)+1;
212  conn[7] = this->node_id(4)+1;
213  return;
214  }
215 
216  case VTK:
217  {
218  conn.resize(5);
219  conn[0] = this->node_id(3);
220  conn[1] = this->node_id(2);
221  conn[2] = this->node_id(1);
222  conn[3] = this->node_id(0);
223  conn[4] = this->node_id(4);
224  return;
225  }
226 
227  default:
228  libmesh_error_msg("Unsupported IO package " << iop);
229  }
230 }
231 
232 
234 {
235  // Call Hex8 static helper function, passing 4 copies of the final
236  // vertex point, effectively treating the Pyramid as a degenerate
237  // hexahedron. In my testing, this still seems to give correct
238  // results.
240  point(0), point(1), point(2), point(3),
241  point(4), point(4), point(4), point(4));
242 }
243 
244 
245 
247 {
248  // The pyramid with a bilinear base has volume given by the
249  // formula in: "Calculation of the Volume of a General Hexahedron
250  // for Flow Predictions", AIAA Journal v.23, no.6, 1984, p.954-
251  Point
252  x0 = point(0), x1 = point(1), x2 = point(2),
253  x3 = point(3), x4 = point(4);
254 
255  // Construct various edge and diagonal vectors.
256  Point v40 = x0 - x4;
257  Point v13 = x3 - x1;
258  Point v02 = x2 - x0;
259  Point v03 = x3 - x0;
260  Point v01 = x1 - x0;
261 
262  // Finally, ready to return the volume!
263  return
264  triple_product(v40, v13, v02) / 6. +
265  triple_product(v02, v01, v03) / 12.;
266 }
267 
270 {
271  return Elem::loose_bounding_box();
272 }
273 
274 void Pyramid5::permute(unsigned int perm_num)
275 {
276  libmesh_assert_less (perm_num, 4);
277 
278  for (unsigned int i = 0; i != perm_num; ++i)
279  {
280  swap4nodes(0,1,2,3);
281  swap4neighbors(0,1,2,3);
282  }
283 }
284 
285 
286 void Pyramid5::flip(BoundaryInfo * boundary_info)
287 {
288  libmesh_assert(boundary_info);
289 
290  swap2nodes(0,1);
291  swap2nodes(2,3);
292  swap2neighbors(1,3);
293  swap2boundarysides(1,3,boundary_info);
294  swap2boundaryedges(1,3,boundary_info);
295  swap2boundaryedges(4,5,boundary_info);
296  swap2boundaryedges(6,7,boundary_info);
297 }
298 
299 
300 ElemType Pyramid5::side_type (const unsigned int s) const
301 {
302  libmesh_assert_less (s, 5);
303  if (s < 4)
304  return TRI3;
305  return QUAD4;
306 }
307 
308 
309 } // namespace libMesh
virtual std::unique_ptr< Elem > build_edge_ptr(const unsigned int i) override
Builds a EDGE2 built coincident with edge i.
ElemType side_type(const unsigned int s) const override final
virtual Point true_centroid() const override
We compute the centroid of the Pyramid by treating it as a degenerate Hex8 element.
virtual void connectivity(const unsigned int sc, const IOPackage iop, std::vector< dof_id_type > &conn) const override
ElemType
Defines an enum for geometric element types.
void swap2boundaryedges(unsigned short e1, unsigned short e2, BoundaryInfo *boundary_info) const
Swaps two edges in boundary_info, if it is non-null.
Definition: elem.C:3550
virtual std::vector< unsigned int > nodes_on_edge(const unsigned int e) const override
Definition: cell_pyramid5.C:98
Order
defines an enum for polynomial orders.
Definition: enum_order.h:40
Node ** _nodes
Pointers to the nodes we are connected to.
Definition: elem.h:2245
virtual bool is_face(const unsigned int i) const override
Definition: cell_pyramid5.C:75
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition: libmesh.h:310
static const int num_edges
Definition: cell_pyramid.h:78
virtual BoundingBox loose_bounding_box() const override
Builds a bounding box out of the nodal positions.
static const int nodes_per_edge
static const unsigned int edge_nodes_map[num_edges][nodes_per_edge]
This maps the node of the edge to element node numbers.
IOPackage
libMesh interfaces with several different software packages for the purposes of creating, reading, and writing mesh files.
virtual void flip(BoundaryInfo *) override final
Flips the element (by swapping node and neighbor pointers) to have a mapping Jacobian of opposite sig...
virtual BoundingBox loose_bounding_box() const
Definition: elem.C:3465
void swap2boundarysides(unsigned short s1, unsigned short s2, BoundaryInfo *boundary_info) const
Swaps two sides in boundary_info, if it is non-null.
Definition: elem.C:3534
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const override
Definition: cell_pyramid5.C:80
virtual Real volume() const override
Specialization for computing the volume of a pyramid.
virtual unsigned int n_sides() const override
Definition: cell_pyramid.h:90
virtual bool is_node_on_edge(const unsigned int n, const unsigned int e) const override
virtual bool has_affine_map() const override
virtual bool is_edge(const unsigned int i) const override
Definition: cell_pyramid5.C:70
The libMesh namespace provides an interface to certain functionality in the library.
static const int num_nodes
Geometric constants for Pyramid5.
virtual std::unique_ptr< Elem > side_ptr(const unsigned int i) override
Definition: cell_pyramid.C:158
virtual std::vector< unsigned int > nodes_on_side(const unsigned int s) const override
Definition: cell_pyramid5.C:90
T triple_product(const TypeVector< T > &a, const TypeVector< T > &b, const TypeVector< T > &c)
Definition: type_vector.h:1029
void swap4nodes(unsigned int n1, unsigned int n2, unsigned int n3, unsigned int n4)
Swaps four node_ptrs, "rotating" them.
Definition: elem.h:2143
void swap2nodes(unsigned int n1, unsigned int n2)
Swaps two node_ptrs.
Definition: elem.h:2092
The BoundaryInfo class contains information relevant to boundary conditions including storing faces...
Definition: boundary_info.h:57
libmesh_assert(ctx)
static const int nodes_per_side
static const int num_sides
Geometric constants for all Pyramids.
Definition: cell_pyramid.h:77
void swap2neighbors(unsigned int n1, unsigned int n2)
Swaps two neighbor_ptrs.
Definition: elem.h:2102
Defines a Cartesian bounding box by the two corner extremum.
Definition: bounding_box.h:40
virtual void permute(unsigned int perm_num) override final
Permutes the element (by swapping node and neighbor pointers) according to the specified index...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int n_edges() const override
Definition: cell_pyramid.h:100
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i) override
Builds a QUAD4 or TRI3 built coincident with face i.
virtual bool is_vertex(const unsigned int i) const override
Definition: cell_pyramid5.C:64
void swap4neighbors(unsigned int n1, unsigned int n2, unsigned int n3, unsigned int n4)
Swaps four neighbor_ptrs, "rotating" them.
Definition: elem.h:2153
static Point centroid_from_points(const Point &x0, const Point &x1, const Point &x2, const Point &x3, const Point &x4, const Point &x5, const Point &x6, const Point &x7)
Class static helper function that computes the centroid of a hexahedral region from a set of input po...
Definition: cell_hex8.C:336
static const unsigned int side_nodes_map[num_sides][nodes_per_side]
This maps the node of the side to element node numbers.
virtual unsigned int n_sub_elem() const override
Definition: cell_pyramid5.h:83
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:39
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:2475
const Point & point(const unsigned int i) const
Definition: elem.h:2453
virtual Order default_order() const override