cell_pyramid.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 
82 
83 
84 unsigned int Pyramid::which_node_am_i(unsigned int side,
85  unsigned int side_node) const
86 {
87  libmesh_assert_less (side, this->n_sides());
88 
89  // Never more than 4 nodes per side.
90  libmesh_assert_less(side_node, 4);
91 
92  // Some sides have 3 nodes.
93  libmesh_assert(side == 4 || side_node < 3);
94 
95  return Pyramid5::side_nodes_map[side][side_node];
96 }
97 
98 
99 
100 std::unique_ptr<Elem> Pyramid::side_ptr (const unsigned int i)
101 {
102  libmesh_assert_less (i, this->n_sides());
103 
104  // Return value
105  std::unique_ptr<Elem> face;
106 
107  // Set up the type of element
108  switch (i)
109  {
110  case 0: // triangular face 1
111  case 1: // triangular face 2
112  case 2: // triangular face 3
113  case 3: // triangular face 4
114  {
115  face = libmesh_make_unique<Tri3>();
116  break;
117  }
118  case 4: // the quad face at z=0
119  {
120  face = libmesh_make_unique<Quad4>();
121  break;
122  }
123  default:
124  libmesh_error_msg("Invalid side i = " << i);
125  }
126 
127  // Set the nodes
128  for (unsigned n=0; n<face->n_nodes(); ++n)
129  face->set_node(n) = this->node_ptr(Pyramid5::side_nodes_map[i][n]);
130 
131  return face;
132 }
133 
134 
135 
136 void Pyramid::side_ptr (std::unique_ptr<Elem> & side,
137  const unsigned int i)
138 {
139  libmesh_assert_less (i, this->n_sides());
140 
141  switch (i)
142  {
143  case 0: // triangular face 1
144  case 1: // triangular face 2
145  case 2: // triangular face 3
146  case 3: // triangular face 4
147  {
148  if (!side.get() || side->type() != TRI3)
149  {
150  side = this->side_ptr(i);
151  return;
152  }
153  break;
154  }
155 
156  case 4: // the quad face at z=0
157  {
158  if (!side.get() || side->type() != QUAD4)
159  {
160  side = this->side_ptr(i);
161  return;
162  }
163  break;
164  }
165 
166  default:
167  libmesh_error_msg("Invalid side i = " << i);
168  }
169 
170  side->subdomain_id() = this->subdomain_id();
171 
172  // Set the nodes
173  for (auto n : side->node_index_range())
174  side->set_node(n) = this->node_ptr(Pyramid5::side_nodes_map[i][n]);
175 }
176 
177 
178 
179 bool Pyramid::is_child_on_side(const unsigned int c,
180  const unsigned int s) const
181 {
182  libmesh_assert_less (c, this->n_children());
183  libmesh_assert_less (s, this->n_sides());
184 
185  for (unsigned int i = 0; i != 4; ++i)
186  if (Pyramid5::side_nodes_map[s][i] == c)
187  return true;
188  return false;
189 }
190 
191 
192 
193 bool Pyramid::is_edge_on_side(const unsigned int e,
194  const unsigned int s) const
195 {
196  libmesh_assert_less (e, this->n_edges());
197  libmesh_assert_less (s, this->n_sides());
198 
199  return (is_node_on_side(Pyramid5::edge_nodes_map[e][0],s) &&
201 }
202 
203 
204 
205 } // namespace libMesh
virtual dof_id_type key() const
Definition: elem.C:401
static const unsigned int edge_nodes_map[num_edges][nodes_per_edge]
unsigned short int side
Definition: xdr_io.C:50
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const =0
virtual unsigned int n_sides() const override
Definition: cell_pyramid.h:83
virtual std::unique_ptr< Elem > side_ptr(const unsigned int i) override
Definition: cell_pyramid.C:100
virtual bool is_edge_on_side(const unsigned int e, const unsigned int s) const override
Definition: cell_pyramid.C:193
virtual unsigned int which_node_am_i(unsigned int side, unsigned int side_node) const override
Definition: cell_pyramid.C:84
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const override
Definition: cell_pyramid.C:179
virtual unsigned int n_children() const override
Definition: cell_pyramid.h:103
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
subdomain_id_type subdomain_id() const
Definition: elem.h:2034
virtual unsigned int n_edges() const override
Definition: cell_pyramid.h:93
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1957
static const Real _master_points[14][3]
Definition: cell_pyramid.h:156
static const unsigned int side_nodes_map[num_sides][nodes_per_side]
static dof_id_type compute_key(dof_id_type n0)
Definition: elem.h:2754
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:1914
std::unique_ptr< Elem > side(const unsigned int i) const
Definition: elem.h:2202
uint8_t dof_id_type
Definition: id_types.h:64