libMesh
cell_pyramid5.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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 // C++ includes
20 
21 // Local includes
22 #include "libmesh/side.h"
23 #include "libmesh/cell_pyramid5.h"
24 #include "libmesh/edge_edge2.h"
25 #include "libmesh/face_tri3.h"
26 #include "libmesh/face_quad4.h"
27 
28 namespace libMesh
29 {
30 
31 
32 
33 
34 // ------------------------------------------------------------
35 // Pyramid5 class static member initializations
36 const unsigned int Pyramid5::side_nodes_map[5][4] =
37  {
38  {0, 1, 4, 99}, // Side 0
39  {1, 2, 4, 99}, // Side 1
40  {2, 3, 4, 99}, // Side 2
41  {3, 0, 4, 99}, // Side 3
42  {0, 3, 2, 1} // Side 4
43  };
44 
45 const unsigned int Pyramid5::edge_nodes_map[8][2] =
46  {
47  {0, 1}, // Edge 0
48  {1, 2}, // Edge 1
49  {2, 3}, // Edge 2
50  {0, 3}, // Edge 3
51  {0, 4}, // Edge 4
52  {1, 4}, // Edge 5
53  {2, 4}, // Edge 6
54  {3, 4} // Edge 7
55  };
56 
57 
58 
59 // ------------------------------------------------------------
60 // Pyramid5 class member functions
61 
62 bool Pyramid5::is_vertex(const unsigned int) const
63 {
64  return true;
65 }
66 
67 bool Pyramid5::is_edge(const unsigned int) const
68 {
69  return false;
70 }
71 
72 bool Pyramid5::is_face(const unsigned int) const
73 {
74  return false;
75 }
76 
77 bool Pyramid5::is_node_on_side(const unsigned int n,
78  const unsigned int s) const
79 {
80  libmesh_assert_less (s, n_sides());
81  for (unsigned int i = 0; i != 4; ++i)
82  if (side_nodes_map[s][i] == n)
83  return true;
84  return false;
85 }
86 
87 bool Pyramid5::is_node_on_edge(const unsigned int n,
88  const unsigned int e) const
89 {
90  libmesh_assert_less (e, n_edges());
91  for (unsigned int i = 0; i != 2; ++i)
92  if (edge_nodes_map[e][i] == n)
93  return true;
94  return false;
95 }
96 
97 
98 
99 bool Pyramid5::has_affine_map() const
100 {
101  // Point v = this->point(3) - this->point(0);
102  // return (v.relative_fuzzy_equals(this->point(2) - this->point(1)));
103  return false;
104 }
105 
106 
107 
108 UniquePtr<Elem> Pyramid5::build_side_ptr (const unsigned int i,
109  bool proxy)
110 {
111  libmesh_assert_less (i, this->n_sides());
112 
113  if (proxy)
114  {
115  switch (i)
116  {
117  case 0:
118  case 1:
119  case 2:
120  case 3:
121  return UniquePtr<Elem>(new Side<Tri3,Pyramid5>(this,i));
122 
123  case 4:
124  return UniquePtr<Elem>(new Side<Quad4,Pyramid5>(this,i));
125 
126  default:
127  libmesh_error_msg("Invalid side i = " << i);
128  }
129  }
130 
131  else
132  {
133  // Create NULL pointer to be initialized, returned later.
134  Elem * face = libmesh_nullptr;
135 
136  switch (i)
137  {
138  case 0: // triangular face 1
139  case 1: // triangular face 2
140  case 2: // triangular face 3
141  case 3: // triangular face 4
142  {
143  face = new Tri3;
144  break;
145  }
146  case 4: // the quad face at z=0
147  {
148  face = new Quad4;
149  break;
150  }
151  default:
152  libmesh_error_msg("Invalid side i = " << i);
153  }
154 
155  face->subdomain_id() = this->subdomain_id();
156 
157  // Set the nodes
158  for (unsigned n=0; n<face->n_nodes(); ++n)
159  face->set_node(n) = this->node_ptr(Pyramid5::side_nodes_map[i][n]);
160 
161  return UniquePtr<Elem>(face);
162  }
163 
164  libmesh_error_msg("We'll never get here!");
165  return UniquePtr<Elem>();
166 }
167 
168 
169 
170 UniquePtr<Elem> Pyramid5::build_edge_ptr (const unsigned int i)
171 {
172  libmesh_assert_less (i, this->n_edges());
173 
174  return UniquePtr<Elem>(new SideEdge<Edge2,Pyramid5>(this,i));
175 }
176 
177 
178 
179 void Pyramid5::connectivity(const unsigned int libmesh_dbg_var(sc),
180  const IOPackage iop,
181  std::vector<dof_id_type> & conn) const
182 {
183  libmesh_assert(_nodes);
184  libmesh_assert_less (sc, this->n_sub_elem());
185  libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE);
186 
187  switch (iop)
188  {
189  case TECPLOT:
190  {
191  conn.resize(8);
192  conn[0] = this->node_id(0)+1;
193  conn[1] = this->node_id(1)+1;
194  conn[2] = this->node_id(2)+1;
195  conn[3] = this->node_id(3)+1;
196  conn[4] = this->node_id(4)+1;
197  conn[5] = this->node_id(4)+1;
198  conn[6] = this->node_id(4)+1;
199  conn[7] = this->node_id(4)+1;
200  return;
201  }
202 
203  case VTK:
204  {
205  conn.resize(5);
206  conn[0] = this->node_id(3);
207  conn[1] = this->node_id(2);
208  conn[2] = this->node_id(1);
209  conn[3] = this->node_id(0);
210  conn[4] = this->node_id(4);
211  return;
212  }
213 
214  default:
215  libmesh_error_msg("Unsupported IO package " << iop);
216  }
217 }
218 
219 
220 Real Pyramid5::volume () const
221 {
222  // The pyramid with a bilinear base has volume given by the
223  // formula in: "Calculation of the Volume of a General Hexahedron
224  // for Flow Predictions", AIAA Journal v.23, no.6, 1984, p.954-
225  Point
226  x0 = point(0), x1 = point(1), x2 = point(2),
227  x3 = point(3), x4 = point(4);
228 
229  // Construct various edge and diagonal vectors.
230  Point v40 = x0 - x4;
231  Point v13 = x3 - x1;
232  Point v02 = x2 - x0;
233  Point v03 = x3 - x0;
234  Point v01 = x1 - x0;
235 
236  // Finally, ready to return the volume!
237  return
238  triple_product(v40, v13, v02) / 6. +
239  triple_product(v02, v01, v03) / 12.;
240 }
241 
242 } // namespace libMesh
const class libmesh_nullptr_t libmesh_nullptr
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(j)
T triple_product(const TypeVector< T > &a, const TypeVector< T > &b, const TypeVector< T > &c)
Definition: type_vector.h:1051
PetscErrorCode Vec Mat libmesh_dbg_var(j)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IOPackage
libMesh interfaces with several different software packages for the purposes of creating, reading, and writing mesh files.