libMesh
cell_pyramid.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/cell_pyramid.h"
23 #include "libmesh/cell_pyramid5.h"
24 #include "libmesh/face_tri3.h"
25 #include "libmesh/face_quad4.h"
26 
27 namespace libMesh
28 {
29 
30 // ------------------------------------------------------------
31 // Pyramid class static member initializations
32 
33 
34 // We need to require C++11...
35 const Real Pyramid::_master_points[14][3] =
36  {
37  {-1, -1, 0},
38  {1, -1, 0},
39  {1, 1, 0},
40  {-1, 1, 0},
41  {0, 0, 1},
42  {0, -1, 0},
43  {1, 0, 0},
44  {0, 1, 0},
45  {-1, 0, 0},
46  {0, -0.5, 0.5},
47  {0.5, 0, 0.5},
48  {0, 0.5, 0.5},
49  {-0.5, 0, 0.5}
50  };
51 
52 
53 
54 
55 // ------------------------------------------------------------
56 // Pyramid class member functions
57 dof_id_type Pyramid::key (const unsigned int s) const
58 {
59  libmesh_assert_less (s, this->n_sides());
60 
61  switch (s)
62  {
63  case 0: // triangular face 1
64  case 1: // triangular face 2
65  case 2: // triangular face 3
66  case 3: // triangular face 4
67  return this->compute_key (this->node_id(Pyramid5::side_nodes_map[s][0]),
68  this->node_id(Pyramid5::side_nodes_map[s][1]),
69  this->node_id(Pyramid5::side_nodes_map[s][2]));
70 
71  case 4: // the quad face at z=0
72  return this->compute_key (this->node_id(Pyramid5::side_nodes_map[s][0]),
73  this->node_id(Pyramid5::side_nodes_map[s][1]),
74  this->node_id(Pyramid5::side_nodes_map[s][2]),
75  this->node_id(Pyramid5::side_nodes_map[s][3]));
76 
77  default:
78  libmesh_error_msg("Invalid side s = " << s);
79  }
80 
81  libmesh_error_msg("We'll never get here!");
82  return 0;
83 }
84 
85 
86 
87 unsigned int Pyramid::which_node_am_i(unsigned int side,
88  unsigned int side_node) const
89 {
90  libmesh_assert_less (side, this->n_sides());
91 
92  // Never more than 4 nodes per side.
93  libmesh_assert_less(side_node, 4);
94 
95  // Some sides have 3 nodes.
96  libmesh_assert(side == 4 || side_node < 3);
97 
98  return Pyramid5::side_nodes_map[side][side_node];
99 }
100 
101 
102 
103 UniquePtr<Elem> Pyramid::side_ptr (const unsigned int i)
104 {
105  libmesh_assert_less (i, this->n_sides());
106 
107  // To be returned wrapped in a UniquePtr
108  Elem * face = libmesh_nullptr;
109 
110  // Set up the type of element
111  switch (i)
112  {
113  case 0: // triangular face 1
114  case 1: // triangular face 2
115  case 2: // triangular face 3
116  case 3: // triangular face 4
117  {
118  face = new Tri3;
119  break;
120  }
121  case 4: // the quad face at z=0
122  {
123  face = new Quad4;
124  break;
125  }
126  default:
127  libmesh_error_msg("Invalid side i = " << i);
128  }
129 
130  // Set the nodes
131  for (unsigned n=0; n<face->n_nodes(); ++n)
132  face->set_node(n) = this->node_ptr(Pyramid5::side_nodes_map[i][n]);
133 
134  return UniquePtr<Elem>(face);
135 }
136 
137 
138 
139 bool Pyramid::is_child_on_side(const unsigned int c,
140  const unsigned int s) const
141 {
142  libmesh_assert_less (c, this->n_children());
143  libmesh_assert_less (s, this->n_sides());
144 
145  for (unsigned int i = 0; i != 4; ++i)
146  if (Pyramid5::side_nodes_map[s][i] == c)
147  return true;
148  return false;
149 }
150 
151 
152 
153 bool Pyramid::is_edge_on_side(const unsigned int e,
154  const unsigned int s) const
155 {
156  libmesh_assert_less (e, this->n_edges());
157  libmesh_assert_less (s, this->n_sides());
158 
159  return (is_node_on_side(Pyramid5::edge_nodes_map[e][0],s) &&
160  is_node_on_side(Pyramid5::edge_nodes_map[e][1],s));
161 }
162 
163 
164 
165 } // namespace libMesh
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const =0
The Tri3 is an element in 2D composed of 3 nodes.
Definition: face_tri3.h:54
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:1941
The QUAD4 is an element in 2D composed of 4 nodes.
Definition: face_quad4.h:49
UniquePtr< Elem > side(const unsigned int i) const
Definition: elem.h:2105
virtual unsigned int n_sides() const libmesh_override
Definition: cell_pyramid.h:77
This is the base class from which all geometric element types are derived.
Definition: elem.h:89
const class libmesh_nullptr_t libmesh_nullptr
The libMesh namespace provides an interface to certain functionality in the library.
virtual UniquePtr< Elem > side_ptr(const unsigned int i) libmesh_override
Definition: cell_pyramid.C:103
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual unsigned int n_nodes() const =0
virtual unsigned int which_node_am_i(unsigned int side, unsigned int side_node) const libmesh_override
Definition: cell_pyramid.C:87
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const libmesh_override
Definition: cell_pyramid.C:139
virtual dof_id_type key() const
Definition: elem.C:503
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1874
virtual bool is_edge_on_side(const unsigned int e, const unsigned int s) const libmesh_override
Definition: cell_pyramid.C:153
virtual unsigned int n_edges() const libmesh_override
Definition: cell_pyramid.h:87
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
static const Real _master_points[14][3]
Master element node locations.
Definition: cell_pyramid.h:147
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:1831
virtual unsigned int n_children() const libmesh_override
Definition: cell_pyramid.h:97
static dof_id_type compute_key(dof_id_type n0)
Definition: elem.h:2621
uint8_t dof_id_type
Definition: id_types.h:64