face_quad8.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 // C++ includes
19 
20 // Local includes
21 #include "libmesh/side.h"
22 #include "libmesh/edge_edge3.h"
23 #include "libmesh/face_quad8.h"
24 
25 namespace libMesh
26 {
27 
28 
29 
30 
31 // ------------------------------------------------------------
32 // Quad8 class static member initializations
33 const unsigned int Quad8::side_nodes_map[4][3] =
34  {
35  {0, 1, 4}, // Side 0
36  {1, 2, 5}, // Side 1
37  {2, 3, 6}, // Side 2
38  {3, 0, 7} // Side 3
39  };
40 
41 
42 #ifdef LIBMESH_ENABLE_AMR
43 
44 const float Quad8::_embedding_matrix[4][8][8] =
45  {
46  // embedding matrix for child 0
47  {
48  // 0 1 2 3 4 5 6 7
49  { 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000 }, // 0
50  { 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000 }, // 1
51  { -0.250000, -0.250000, -0.250000, -0.250000, 0.500000, 0.500000, 0.500000, 0.500000 }, // 2
52  { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000 }, // 3
53  { 0.375000, -0.125000, 0.00000, 0.00000, 0.750000, 0.00000, 0.00000, 0.00000 }, // 4
54  { -0.187500, -0.187500, -0.187500, -0.187500, 0.750000, 0.375000, 0.250000, 0.375000 }, // 5
55  { -0.187500, -0.187500, -0.187500, -0.187500, 0.375000, 0.250000, 0.375000, 0.750000 }, // 6
56  { 0.375000, 0.00000, 0.00000, -0.125000, 0.00000, 0.00000, 0.00000, 0.750000 } // 7
57  },
58 
59  // embedding matrix for child 1
60  {
61  // 0 1 2 3 4 5 6 7
62  { 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000 }, // 0
63  { 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000 }, // 1
64  { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000 }, // 2
65  { -0.250000, -0.250000, -0.250000, -0.250000, 0.500000, 0.500000, 0.500000, 0.500000 }, // 3
66  { -0.125000, 0.375000, 0.00000, 0.00000, 0.750000, 0.00000, 0.00000, 0.00000 }, // 4
67  { 0.00000, 0.375000, -0.125000, 0.00000, 0.00000, 0.750000, 0.00000, 0.00000 }, // 5
68  { -0.187500, -0.187500, -0.187500, -0.187500, 0.375000, 0.750000, 0.375000, 0.250000 }, // 6
69  { -0.187500, -0.187500, -0.187500, -0.187500, 0.750000, 0.375000, 0.250000, 0.375000 } // 7
70  },
71 
72  // embedding matrix for child 2
73  {
74  // 0 1 2 3 4 5 6 7
75  { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000 }, // 0
76  { -0.250000, -0.250000, -0.250000, -0.250000, 0.500000, 0.500000, 0.500000, 0.500000 }, // 1
77  { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000 }, // 2
78  { 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000 }, // 3
79  { -0.187500, -0.187500, -0.187500, -0.187500, 0.375000, 0.250000, 0.375000, 0.750000 }, // 4
80  { -0.187500, -0.187500, -0.187500, -0.187500, 0.250000, 0.375000, 0.750000, 0.375000 }, // 5
81  { 0.00000, 0.00000, -0.125000, 0.375000, 0.00000, 0.00000, 0.750000, 0.00000 }, // 6
82  { -0.125000, 0.00000, 0.00000, 0.375000, 0.00000, 0.00000, 0.00000, 0.750000 } // 7
83  },
84 
85  // embedding matrix for child 3
86  {
87  // 0 1 2 3 4 5 6 7
88  { -0.250000, -0.250000, -0.250000, -0.250000, 0.500000, 0.500000, 0.500000, 0.500000 }, // 0
89  { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000, 0.00000 }, // 1
90  { 0.00000, 0.00000, 1.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000 }, // 2
91  { 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 0.00000, 1.00000, 0.00000 }, // 3
92  { -0.187500, -0.187500, -0.187500, -0.187500, 0.375000, 0.750000, 0.375000, 0.250000 }, // 4
93  { 0.00000, -0.125000, 0.375000, 0.00000, 0.00000, 0.750000, 0.00000, 0.00000 }, // 5
94  { 0.00000, 0.00000, 0.375000, -0.125000, 0.00000, 0.00000, 0.750000, 0.00000 }, // 6
95  { -0.187500, -0.187500, -0.187500, -0.187500, 0.250000, 0.375000, 0.750000, 0.375000 } // 7
96  }
97  };
98 
99 
100 #endif
101 
102 
103 // ------------------------------------------------------------
104 // Quad8 class member functions
105 
106 bool Quad8::is_vertex(const unsigned int i) const
107 {
108  if (i < 4)
109  return true;
110  return false;
111 }
112 
113 bool Quad8::is_edge(const unsigned int i) const
114 {
115  if (i < 4)
116  return false;
117  return true;
118 }
119 
120 bool Quad8::is_face(const unsigned int) const
121 {
122  return false;
123 }
124 
125 bool Quad8::is_node_on_side(const unsigned int n,
126  const unsigned int s) const
127 {
128  libmesh_assert_less (s, n_sides());
129  for (unsigned int i = 0; i != 3; ++i)
130  if (side_nodes_map[s][i] == n)
131  return true;
132  return false;
133 }
134 
135 
136 
138 {
139  // make sure corners form a parallelogram
140  Point v = this->point(1) - this->point(0);
141  if (!v.relative_fuzzy_equals(this->point(2) - this->point(3)))
142  return false;
143  // make sure sides are straight
144  v /= 2;
145  if (!v.relative_fuzzy_equals(this->point(4) - this->point(0)) ||
146  !v.relative_fuzzy_equals(this->point(6) - this->point(3)))
147  return false;
148  v = (this->point(3) - this->point(0))/2;
149  if (!v.relative_fuzzy_equals(this->point(7) - this->point(0)) ||
150  !v.relative_fuzzy_equals(this->point(5) - this->point(1)))
151  return false;
152  return true;
153 }
154 
155 
156 
157 dof_id_type Quad8::key (const unsigned int s) const
158 {
159  libmesh_assert_less (s, this->n_sides());
160 
161  switch (s)
162  {
163  case 0:
164 
165  return
166  this->compute_key (this->node_id(4));
167 
168  case 1:
169 
170  return
171  this->compute_key (this->node_id(5));
172 
173  case 2:
174 
175  return
176  this->compute_key (this->node_id(6));
177 
178  case 3:
179 
180  return
181  this->compute_key (this->node_id(7));
182 
183  default:
184  libmesh_error_msg("Invalid side s = " << s);
185  }
186 }
187 
188 
189 
190 unsigned int Quad8::which_node_am_i(unsigned int side,
191  unsigned int side_node) const
192 {
193  libmesh_assert_less (side, this->n_sides());
194  libmesh_assert_less (side_node, 3);
195 
196  return Quad8::side_nodes_map[side][side_node];
197 }
198 
199 
200 
201 std::unique_ptr<Elem> Quad8::build_side_ptr (const unsigned int i,
202  bool proxy)
203 {
204  libmesh_assert_less (i, this->n_sides());
205 
206  if (proxy)
207  return libmesh_make_unique<Side<Edge3,Quad8>>(this,i);
208 
209  else
210  {
211  std::unique_ptr<Elem> edge = libmesh_make_unique<Edge3>();
212  edge->subdomain_id() = this->subdomain_id();
213 
214  // Set the nodes
215  for (unsigned n=0; n<edge->n_nodes(); ++n)
216  edge->set_node(n) = this->node_ptr(Quad8::side_nodes_map[i][n]);
217 
218  return edge;
219  }
220 }
221 
222 
223 
224 
225 
226 
227 void Quad8::connectivity(const unsigned int sf,
228  const IOPackage iop,
229  std::vector<dof_id_type> & conn) const
230 {
231  libmesh_assert_less (sf, this->n_sub_elem());
232  libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE);
233 
234  switch (iop)
235  {
236  // Note: TECPLOT connectivity is output as four triangles with
237  // a central quadrilateral. Therefore, the first four connectivity
238  // arrays are degenerate quads (triangles in Tecplot).
239  case TECPLOT:
240  {
241  // Create storage
242  conn.resize(4);
243 
244  switch(sf)
245  {
246  case 0:
247  // linear sub-tri 0
248  conn[0] = this->node_id(0)+1;
249  conn[1] = this->node_id(4)+1;
250  conn[2] = this->node_id(7)+1;
251  conn[3] = this->node_id(7)+1;
252 
253  return;
254 
255  case 1:
256  // linear sub-tri 1
257  conn[0] = this->node_id(4)+1;
258  conn[1] = this->node_id(1)+1;
259  conn[2] = this->node_id(5)+1;
260  conn[3] = this->node_id(5)+1;
261 
262  return;
263 
264  case 2:
265  // linear sub-tri 2
266  conn[0] = this->node_id(5)+1;
267  conn[1] = this->node_id(2)+1;
268  conn[2] = this->node_id(6)+1;
269  conn[3] = this->node_id(6)+1;
270 
271  return;
272 
273  case 3:
274  // linear sub-tri 3
275  conn[0] = this->node_id(7)+1;
276  conn[1] = this->node_id(6)+1;
277  conn[2] = this->node_id(3)+1;
278  conn[3] = this->node_id(3)+1;
279 
280  return;
281 
282  case 4:
283  // linear sub-quad
284  conn[0] = this->node_id(4)+1;
285  conn[1] = this->node_id(5)+1;
286  conn[2] = this->node_id(6)+1;
287  conn[3] = this->node_id(7)+1;
288 
289  return;
290 
291  default:
292  libmesh_error_msg("Invalid sf = " << sf);
293  }
294  }
295 
296 
297  // Note: VTK connectivity is output as four triangles with
298  // a central quadrilateral. Therefore most of the connectivity
299  // arrays have length three.
300  case VTK:
301  {
302  // Create storage
303  conn.resize(8);
304  conn[0] = this->node_id(0);
305  conn[1] = this->node_id(1);
306  conn[2] = this->node_id(2);
307  conn[3] = this->node_id(3);
308  conn[4] = this->node_id(4);
309  conn[5] = this->node_id(5);
310  conn[6] = this->node_id(6);
311  conn[7] = this->node_id(7);
312  return;
313  /*
314  conn.resize(3);
315 
316  switch (sf)
317  {
318  case 0:
319  // linear sub-tri 0
320  conn[0] = this->node_id(0);
321  conn[1] = this->node_id(4);
322  conn[2] = this->node_id(7);
323 
324  return;
325 
326  case 1:
327  // linear sub-tri 1
328  conn[0] = this->node_id(4);
329  conn[1] = this->node_id(1);
330  conn[2] = this->node_id(5);
331 
332  return;
333 
334  case 2:
335  // linear sub-tri 2
336  conn[0] = this->node_id(5);
337  conn[1] = this->node_id(2);
338  conn[2] = this->node_id(6);
339 
340  return;
341 
342  case 3:
343  // linear sub-tri 3
344  conn[0] = this->node_id(7);
345  conn[1] = this->node_id(6);
346  conn[2] = this->node_id(3);
347 
348  return;
349 
350  case 4:
351  conn.resize(4);
352 
353  // linear sub-quad
354  conn[0] = this->node_id(4);
355  conn[1] = this->node_id(5);
356  conn[2] = this->node_id(6);
357  conn[3] = this->node_id(7);
358  */
359  // return;
360 
361  // default:
362  // libmesh_error_msg("Invalid sf = " << sf);
363  // }
364  }
365 
366  default:
367  libmesh_error_msg("Unsupported IO package " << iop);
368  }
369 }
370 
371 
372 
374 {
375  // This might have curved edges, or might be a curved surface in
376  // 3-space, in which case the full bounding box can be larger than
377  // the bounding box of just the nodes.
378  //
379  //
380  // FIXME - I haven't yet proven the formula below to be correct for
381  // biquadratics - RHS
382  Point pmin, pmax;
383 
384  for (unsigned d=0; d<LIBMESH_DIM; ++d)
385  {
386  Real center = this->point(0)(d);
387  for (unsigned int p=1; p != 8; ++p)
388  center += this->point(p)(d);
389  center /= 8;
390 
391  Real hd = std::abs(center - this->point(0)(d));
392  for (unsigned int p=0; p != 8; ++p)
393  hd = std::max(hd, std::abs(center - this->point(p)(d)));
394 
395  pmin(d) = center - hd;
396  pmax(d) = center + hd;
397  }
398 
399  return BoundingBox(pmin, pmax);
400 }
401 
402 
404 {
405  // Make copies of our points. It makes the subsequent calculations a bit
406  // shorter and avoids dereferencing the same pointer multiple times.
407  Point
408  x0 = point(0),
409  x1 = point(1),
410  x2 = point(2),
411  x3 = point(3),
412  x4 = point(4),
413  x5 = point(5),
414  x6 = point(6),
415  x7 = point(7);
416 
417  // Construct constant data vectors.
418  // \vec{x}_{\xi} = \vec{a1}*eta**2 + \vec{b1}*xi*eta + \vec{c1}*xi + \vec{d1}*eta + \vec{e1}
419  // \vec{x}_{\eta} = \vec{a2}*xi**2 + \vec{b2}*xi*eta + \vec{c2}*xi + \vec{d2}*eta + \vec{e2}
420  // This is copy-pasted directly from the output of a Python script.
421  Point
422  a1 = -x0/4 + x1/4 + x2/4 - x3/4 - x5/2 + x7/2,
423  b1 = -x0/2 - x1/2 + x2/2 + x3/2 + x4 - x6,
424  c1 = x0/2 + x1/2 + x2/2 + x3/2 - x4 - x6,
425  d1 = x0/4 - x1/4 + x2/4 - x3/4,
426  e1 = x5/2 - x7/2,
427  a2 = -x0/4 - x1/4 + x2/4 + x3/4 + x4/2 - x6/2,
428  b2 = -x0/2 + x1/2 + x2/2 - x3/2 - x5 + x7,
429  c2 = x0/4 - x1/4 + x2/4 - x3/4,
430  d2 = x0/2 + x1/2 + x2/2 + x3/2 - x5 - x7,
431  e2 = -x4/2 + x6/2;
432 
433  // 3x3 quadrature, exact for bi-quintics
434  const unsigned int N = 3;
435  const Real q[N] = {-std::sqrt(15)/5., 0., std::sqrt(15)/5.};
436  const Real w[N] = {5./9, 8./9, 5./9};
437 
438  Real vol=0.;
439  for (unsigned int i=0; i<N; ++i)
440  for (unsigned int j=0; j<N; ++j)
441  vol += w[i] * w[j] * cross_norm(q[j]*q[j]*a1 + q[i]*q[j]*b1 + q[i]*c1 + q[j]*d1 + e1,
442  q[i]*q[i]*a2 + q[i]*q[j]*b2 + q[i]*c2 + q[j]*d2 + e2);
443 
444  return vol;
445 }
446 
447 
448 
449 unsigned short int Quad8::second_order_adjacent_vertex (const unsigned int n,
450  const unsigned int v) const
451 {
452  libmesh_assert_greater_equal (n, this->n_vertices());
453  libmesh_assert_less (n, this->n_nodes());
454  libmesh_assert_less (v, 2);
455  // use the matrix from \p face_quad.C
456  return _second_order_adjacent_vertices[n-this->n_vertices()][v];
457 }
458 
459 
460 
461 std::pair<unsigned short int, unsigned short int>
462 Quad8::second_order_child_vertex (const unsigned int n) const
463 {
464  libmesh_assert_greater_equal (n, this->n_vertices());
465  libmesh_assert_less (n, this->n_nodes());
466  /*
467  * the _second_order_vertex_child_* vectors are
468  * stored in face_quad.C, since they are identical
469  * for Quad8 and Quad9 (for the first 4 higher-order nodes)
470  */
471  return std::pair<unsigned short int, unsigned short int>
474 }
475 
476 } // namespace libMesh
double abs(double a)
virtual unsigned int n_nodes() const libmesh_override
Definition: face_quad8.h:68
static const float _embedding_matrix[4][8][8]
Definition: face_quad8.h:209
virtual bool is_node_on_side(const unsigned int n, const unsigned int s) const libmesh_override
Definition: face_quad8.C:125
virtual void connectivity(const unsigned int sf, const IOPackage iop, std::vector< dof_id_type > &conn) const libmesh_override
Definition: face_quad8.C:227
virtual std::pair< unsigned short int, unsigned short int > second_order_child_vertex(const unsigned int n) const libmesh_override
Definition: face_quad8.C:462
virtual dof_id_type key() const libmesh_override
Definition: face_quad.C:75
T cross_norm(const TypeVector< T > &b, const TypeVector< T > &c)
Definition: type_vector.h:1092
virtual unsigned int n_sub_elem() const libmesh_override
Definition: face_quad8.h:73
static const unsigned int side_nodes_map[4][3]
Definition: face_quad8.h:172
virtual bool is_vertex(const unsigned int i) const libmesh_override
Definition: face_quad8.C:106
virtual std::unique_ptr< Elem > build_side_ptr(const unsigned int i, bool proxy) libmesh_override
Definition: face_quad8.C:201
long double max(long double a, double b)
virtual unsigned int n_vertices() const libmesh_override
Definition: face_quad.h:90
const Node * node_ptr(const unsigned int i) const
Definition: elem.h:1875
virtual bool is_edge(const unsigned int i) const libmesh_override
Definition: face_quad8.C:113
static const unsigned short int _second_order_vertex_child_index[9]
Definition: face_quad.h:190
static const unsigned short int _second_order_vertex_child_number[9]
Definition: face_quad.h:185
subdomain_id_type subdomain_id() const
Definition: elem.h:1952
static const unsigned short int _second_order_adjacent_vertices[4][2]
Definition: face_quad.h:180
virtual Real volume() const libmesh_override
Definition: face_quad8.C:403
virtual unsigned short int second_order_adjacent_vertex(const unsigned int n, const unsigned int v) const libmesh_override
Definition: face_quad8.C:449
std::unique_ptr< Elem > side(const unsigned int i) const
Definition: elem.h:2106
virtual BoundingBox loose_bounding_box() const libmesh_override
Definition: face_quad8.C:373
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Point & point(const unsigned int i) const
Definition: elem.h:1810
virtual unsigned int which_node_am_i(unsigned int side, unsigned int side_node) const libmesh_override
Definition: face_quad8.C:190
virtual unsigned int n_sides() const libmesh_override
Definition: face_quad.h:85
virtual bool has_affine_map() const libmesh_override
Definition: face_quad8.C:137
dof_id_type node_id(const unsigned int i) const
Definition: elem.h:1832
static dof_id_type compute_key(dof_id_type n0)
Definition: elem.h:2622
A geometric point in (x,y,z) space.
Definition: point.h:38
bool relative_fuzzy_equals(const TypeVector< T > &rhs, Real tol=TOLERANCE) const
Definition: type_vector.h:987
uint8_t dof_id_type
Definition: id_types.h:64
virtual bool is_face(const unsigned int i) const libmesh_override
Definition: face_quad8.C:120