cell_hex.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 #include <algorithm> // for std::min, std::max
21 
22 // Local includes
23 #include "libmesh/cell_hex.h"
24 #include "libmesh/cell_hex8.h"
25 #include "libmesh/face_quad4.h"
27 
28 
29 namespace libMesh
30 {
31 
32 
33 
34 // ------------------------------------------------------------
35 // Hex class static member initializations
36 
37 
38 // We need to require C++11...
39 const Real Hex::_master_points[27][3] =
40  {
41  {-1, -1, -1},
42  {1, -1, -1},
43  {1, 1, -1},
44  {-1, 1, -1},
45  {-1, -1, 1},
46  {1, -1, 1},
47  {1, 1, 1},
48  {-1, 1, 1},
49  {0, -1, -1},
50  {1, 0, -1},
51  {0, 1, -1},
52  {-1, 0, -1},
53  {-1, -1, 0},
54  {1, -1, 0},
55  {1, 1, 0},
56  {-1, 1, 0},
57  {0, -1, 1},
58  {1, 0, 1},
59  {0, 1, 1},
60  {-1, 0, 1},
61  {0, 0, -1},
62  {0, -1, 0},
63  {1, 0, 0},
64  {0, 1, 0},
65  {-1, 0, 0},
66  {0, 0, 1}
67  };
68 
69 
70 
71 
72 // ------------------------------------------------------------
73 // Hex class member functions
74 dof_id_type Hex::key (const unsigned int s) const
75 {
76  libmesh_assert_less (s, this->n_sides());
77 
78  return this->compute_key(this->node_id(Hex8::side_nodes_map[s][0]),
79  this->node_id(Hex8::side_nodes_map[s][1]),
80  this->node_id(Hex8::side_nodes_map[s][2]),
81  this->node_id(Hex8::side_nodes_map[s][3]));
82 }
83 
84 
85 
86 unsigned int Hex::which_node_am_i(unsigned int side,
87  unsigned int side_node) const
88 {
89  libmesh_assert_less (side, this->n_sides());
90  libmesh_assert_less (side_node, 4);
91 
92  return Hex8::side_nodes_map[side][side_node];
93 }
94 
95 
96 
97 std::unique_ptr<Elem> Hex::side_ptr (const unsigned int i)
98 {
99  libmesh_assert_less (i, this->n_sides());
100 
101  std::unique_ptr<Elem> face = libmesh_make_unique<Quad4>();
102 
103  for (unsigned n=0; n<face->n_nodes(); ++n)
104  face->set_node(n) = this->node_ptr(Hex8::side_nodes_map[i][n]);
105 
106  return face;
107 }
108 
109 
110 
111 void Hex::side_ptr (std::unique_ptr<Elem> & side,
112  const unsigned int i)
113 {
114  this->simple_build_side_ptr<Hex8>(side, i, QUAD4);
115 }
116 
117 
118 
119 bool Hex::is_child_on_side(const unsigned int c,
120  const unsigned int s) const
121 {
122  libmesh_assert_less (c, this->n_children());
123  libmesh_assert_less (s, this->n_sides());
124 
125  // This array maps the Hex8 node numbering to the Hex8 child
126  // numbering. I.e.
127  // node 6 touches child 7, and
128  // node 7 touches child 6, etc.
129  const unsigned int node_child_map[8] = { 0, 1, 3, 2, 4, 5, 7, 6 };
130 
131  for (unsigned int i = 0; i != 4; ++i)
132  if (node_child_map[Hex8::side_nodes_map[s][i]] == c)
133  return true;
134 
135  return false;
136 }
137 
138 
139 
140 bool Hex::is_edge_on_side(const unsigned int e,
141  const unsigned int s) const
142 {
143  libmesh_assert_less (e, this->n_edges());
144  libmesh_assert_less (s, this->n_sides());
145 
146  return (is_node_on_side(Hex8::edge_nodes_map[e][0],s) &&
148 }
149 
150 
151 
152 unsigned int Hex::opposite_side(const unsigned int side_in) const
153 {
154  libmesh_assert_less (side_in, 6);
155  static const unsigned char hex_opposites[6] = {5, 3, 4, 1, 2, 0};
156  return hex_opposites[side_in];
157 }
158 
159 
160 
161 unsigned int Hex::opposite_node(const unsigned int node_in,
162  const unsigned int side_in) const
163 {
164  libmesh_assert_less (node_in, 26);
165  libmesh_assert_less (node_in, this->n_nodes());
166  libmesh_assert_less (side_in, this->n_sides());
167  libmesh_assert(this->is_node_on_side(node_in, side_in));
168 
169  static const unsigned char side05_nodes_map[] =
170  {4, 5, 6, 7, 0, 1, 2, 3, 16, 17, 18, 19, 255, 255, 255, 255, 8, 9, 10, 11, 25, 255, 255, 255, 255, 20};
171  static const unsigned char side13_nodes_map[] =
172  {3, 2, 1, 0, 7, 6, 5, 4, 10, 255, 8, 255, 15, 14, 13, 12, 18, 255, 16, 255, 255, 23, 255, 21, 255, 255};
173  static const unsigned char side24_nodes_map[] =
174  {1, 0, 3, 2, 5, 4, 7, 6, 255, 11, 255, 9, 13, 12, 15, 14, 255, 19, 255, 17, 255, 255, 24, 255, 22, 255};
175 
176  switch (side_in)
177  {
178  case 0:
179  case 5:
180  return side05_nodes_map[node_in];
181  case 1:
182  case 3:
183  return side13_nodes_map[node_in];
184  case 2:
185  case 4:
186  return side24_nodes_map[node_in];
187  default:
188  libmesh_error_msg("Unsupported side_in = " << side_in);
189  }
190 }
191 
192 
193 
195 {
196  switch (q)
197  {
198 
203  case DIAGONAL:
204  {
205  // Diagonal between node 0 and node 6
206  const Real d06 = this->length(0,6);
207 
208  // Diagonal between node 3 and node 5
209  const Real d35 = this->length(3,5);
210 
211  // Diagonal between node 1 and node 7
212  const Real d17 = this->length(1,7);
213 
214  // Diagonal between node 2 and node 4
215  const Real d24 = this->length(2,4);
216 
217  // Find the biggest and smallest diagonals
218  const Real min = std::min(d06, std::min(d35, std::min(d17, d24)));
219  const Real max = std::max(d06, std::max(d35, std::max(d17, d24)));
220 
221  libmesh_assert_not_equal_to (max, 0.0);
222 
223  return min / max;
224 
225  break;
226  }
227 
232  case TAPER:
233  {
234 
238  const Real d01 = this->length(0,1);
239  const Real d12 = this->length(1,2);
240  const Real d23 = this->length(2,3);
241  const Real d03 = this->length(0,3);
242  const Real d45 = this->length(4,5);
243  const Real d56 = this->length(5,6);
244  const Real d67 = this->length(6,7);
245  const Real d47 = this->length(4,7);
246  const Real d04 = this->length(0,4);
247  const Real d15 = this->length(1,5);
248  const Real d37 = this->length(3,7);
249  const Real d26 = this->length(2,6);
250 
251  std::vector<Real> edge_ratios(12);
252  // Front
253  edge_ratios[0] = std::min(d01, d45) / std::max(d01, d45);
254  edge_ratios[1] = std::min(d04, d15) / std::max(d04, d15);
255 
256  // Right
257  edge_ratios[2] = std::min(d15, d26) / std::max(d15, d26);
258  edge_ratios[3] = std::min(d12, d56) / std::max(d12, d56);
259 
260  // Back
261  edge_ratios[4] = std::min(d67, d23) / std::max(d67, d23);
262  edge_ratios[5] = std::min(d26, d37) / std::max(d26, d37);
263 
264  // Left
265  edge_ratios[6] = std::min(d04, d37) / std::max(d04, d37);
266  edge_ratios[7] = std::min(d03, d47) / std::max(d03, d47);
267 
268  // Bottom
269  edge_ratios[8] = std::min(d01, d23) / std::max(d01, d23);
270  edge_ratios[9] = std::min(d03, d12) / std::max(d03, d12);
271 
272  // Top
273  edge_ratios[10] = std::min(d45, d67) / std::max(d45, d67);
274  edge_ratios[11] = std::min(d56, d47) / std::max(d56, d47);
275 
276  return *(std::min_element(edge_ratios.begin(), edge_ratios.end())) ;
277 
278  break;
279  }
280 
281 
286  case STRETCH:
287  {
288  const Real sqrt3 = 1.73205080756888;
289 
293  const Real d06 = this->length(0,6);
294  const Real d17 = this->length(1,7);
295  const Real d35 = this->length(3,5);
296  const Real d24 = this->length(2,4);
297  const Real max_diag = std::max(d06, std::max(d17, std::max(d35, d24)));
298 
299  libmesh_assert_not_equal_to ( max_diag, 0.0 );
300 
304  std::vector<Real> edges(12);
305  edges[0] = this->length(0,1);
306  edges[1] = this->length(1,2);
307  edges[2] = this->length(2,3);
308  edges[3] = this->length(0,3);
309  edges[4] = this->length(4,5);
310  edges[5] = this->length(5,6);
311  edges[6] = this->length(6,7);
312  edges[7] = this->length(4,7);
313  edges[8] = this->length(0,4);
314  edges[9] = this->length(1,5);
315  edges[10] = this->length(2,6);
316  edges[11] = this->length(3,7);
317 
318  const Real min_edge = *(std::min_element(edges.begin(), edges.end()));
319  return sqrt3 * min_edge / max_diag ;
320  }
321 
322 
327  default:
328  return Elem::quality(q);
329  }
330 }
331 
332 
333 
334 std::pair<Real, Real> Hex::qual_bounds (const ElemQuality q) const
335 {
336  std::pair<Real, Real> bounds;
337 
338  switch (q)
339  {
340 
341  case ASPECT_RATIO:
342  bounds.first = 1.;
343  bounds.second = 4.;
344  break;
345 
346  case SKEW:
347  bounds.first = 0.;
348  bounds.second = 0.5;
349  break;
350 
351  case SHEAR:
352  case SHAPE:
353  bounds.first = 0.3;
354  bounds.second = 1.;
355  break;
356 
357  case CONDITION:
358  bounds.first = 1.;
359  bounds.second = 8.;
360  break;
361 
362  case JACOBIAN:
363  bounds.first = 0.5;
364  bounds.second = 1.;
365  break;
366 
367  case DISTORTION:
368  bounds.first = 0.6;
369  bounds.second = 1.;
370  break;
371 
372  case TAPER:
373  bounds.first = 0.;
374  bounds.second = 0.4;
375  break;
376 
377  case STRETCH:
378  bounds.first = 0.25;
379  bounds.second = 1.;
380  break;
381 
382  case DIAGONAL:
383  bounds.first = 0.65;
384  bounds.second = 1.;
385  break;
386 
387  case SIZE:
388  bounds.first = 0.5;
389  bounds.second = 1.;
390  break;
391 
392  default:
393  libMesh::out << "Warning: Invalid quality measure chosen." << std::endl;
394  bounds.first = -1;
395  bounds.second = -1;
396  }
397 
398  return bounds;
399 }
400 
401 
402 
403 const unsigned short int Hex::_second_order_vertex_child_number[27] =
404  {
405  99,99,99,99,99,99,99,99, // Vertices
406  0,1,2,0,0,1,2,3,4,5,6,5, // Edges
407  0,0,1,2,0,4, // Faces
408  0 // Interior
409  };
410 
411 
412 
413 const unsigned short int Hex::_second_order_vertex_child_index[27] =
414  {
415  99,99,99,99,99,99,99,99, // Vertices
416  1,2,3,3,4,5,6,7,5,6,7,7, // Edges
417  2,5,6,7,7,6, // Faces
418  6 // Interior
419  };
420 
421 
422 const unsigned short int Hex::_second_order_adjacent_vertices[12][2] =
423  {
424  { 0, 1}, // vertices adjacent to node 8
425  { 1, 2}, // vertices adjacent to node 9
426  { 2, 3}, // vertices adjacent to node 10
427  { 0, 3}, // vertices adjacent to node 11
428 
429  { 0, 4}, // vertices adjacent to node 12
430  { 1, 5}, // vertices adjacent to node 13
431  { 2, 6}, // vertices adjacent to node 14
432  { 3, 7}, // vertices adjacent to node 15
433 
434  { 4, 5}, // vertices adjacent to node 16
435  { 5, 6}, // vertices adjacent to node 17
436  { 6, 7}, // vertices adjacent to node 18
437  { 4, 7} // vertices adjacent to node 19
438  };
439 
440 
441 #ifdef LIBMESH_ENABLE_AMR
442 
443 // We number 125 "possible node locations" for a 2x2x2 refinement of
444 // hexes with up to 3x3x3 nodes each
445 const int Hex::_child_node_lookup[8][27] =
446  {
447  // node lookup for child 0 (near node 0)
448  { 0, 2, 12, 10, 50, 52, 62, 60, 1, 7, 11, 5, 25, 27, 37, 35,
449  51, 57, 61, 55, 6, 26, 32, 36, 30, 56, 31},
450 
451  // node lookup for child 1 (near node 1)
452  { 2, 4, 14, 12, 52, 54, 64, 62, 3, 9, 13, 7, 27, 29, 39, 37,
453  53, 59, 63, 57, 8, 28, 34, 38, 32, 58, 33},
454 
455  // node lookup for child 2 (near node 3)
456  { 10, 12, 22, 20, 60, 62, 72, 70, 11, 17, 21, 15, 35, 37, 47, 45,
457  61, 67, 71, 65, 16, 36, 42, 46, 40, 66, 41},
458 
459  // node lookup for child 3 (near node 2)
460  { 12, 14, 24, 22, 62, 64, 74, 72, 13, 19, 23, 17, 37, 39, 49, 47,
461  63, 69, 73, 67, 18, 38, 44, 48, 42, 68, 43},
462 
463  // node lookup for child 4 (near node 4)
464  { 50, 52, 62, 60, 100, 102, 112, 110, 51, 57, 61, 55, 75, 77, 87, 85,
465  101, 107, 111, 105, 56, 76, 82, 86, 80, 106, 81},
466 
467  // node lookup for child 5 (near node 5)
468  { 52, 54, 64, 62, 102, 104, 114, 112, 53, 59, 63, 57, 77, 79, 89, 87,
469  103, 109, 113, 107, 58, 78, 84, 88, 82, 108, 93},
470 
471  // node lookup for child 6 (near node 7)
472  { 60, 62, 72, 70, 110, 112, 122, 120, 61, 67, 71, 65, 85, 87, 97, 95,
473  111, 117, 121, 115, 66, 86, 92, 96, 90, 116, 91},
474 
475  // node lookup for child 7 (near node 6)
476  { 62, 64, 74, 72, 112, 114, 124, 122, 63, 69, 73, 67, 87, 89, 99, 97,
477  113, 119, 123, 117, 68, 88, 94, 98, 92, 118, 103}
478  };
479 
480 #endif // LIBMESH_ENABLE_AMR
481 
482 
483 } // namespace libMesh
virtual unsigned int opposite_side(const unsigned int s) const override final
Definition: cell_hex.C:152
static const Real _master_points[27][3]
Definition: cell_hex.h:192
virtual dof_id_type key() const
Definition: elem.C:401
virtual std::pair< Real, Real > qual_bounds(const ElemQuality q) const override
Definition: cell_hex.C:334
static const unsigned short int _second_order_adjacent_vertices[12][2]
Definition: cell_hex.h:177
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_children() const override final
Definition: cell_hex.h:93
long double max(long double a, double b)
static const unsigned int side_nodes_map[num_sides][nodes_per_side]
Definition: cell_hex8.h:165
Real length(const unsigned int n1, const unsigned int n2) const
Definition: elem.C:390
virtual bool is_child_on_side(const unsigned int c, const unsigned int s) const override final
Definition: cell_hex.C:119
virtual unsigned int n_nodes() const =0
static const int _child_node_lookup[8][27]
Definition: cell_hex.h:198
static const unsigned int edge_nodes_map[num_edges][nodes_per_edge]
Definition: cell_hex8.h:171
virtual std::unique_ptr< Elem > side_ptr(const unsigned int i) override final
Definition: cell_hex.C:97
virtual unsigned int n_edges() const override final
Definition: cell_hex.h:83
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual unsigned int n_sides() const override final
Definition: cell_hex.h:73
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1957
virtual Real quality(const ElemQuality q) const
Definition: elem.C:1403
virtual Real quality(const ElemQuality q) const override
Definition: cell_hex.C:194
static const unsigned short int _second_order_vertex_child_number[27]
Definition: cell_hex.h:182
static const unsigned short int _second_order_vertex_child_index[27]
Definition: cell_hex.h:187
virtual unsigned int opposite_node(const unsigned int n, const unsigned int s) const override final
Definition: cell_hex.C:161
static dof_id_type compute_key(dof_id_type n0)
Definition: elem.h:2754
OStreamProxy out(std::cout)
virtual unsigned int which_node_am_i(unsigned int side, unsigned int side_node) const override
Definition: cell_hex.C:86
long double min(long double a, double b)
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
virtual bool is_edge_on_side(const unsigned int e, const unsigned int s) const override final
Definition: cell_hex.C:140