face_quad8.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 // 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  libmesh_error_msg("We'll never get here!");
188  return 0;
189 }
190 
191 
192 
194  bool proxy)
195 {
196  libmesh_assert_less (i, this->n_sides());
197 
198  if (proxy)
199  return UniquePtr<Elem>(new Side<Edge3,Quad8>(this,i));
200 
201  else
202  {
203  Elem * edge = new Edge3;
204  edge->subdomain_id() = this->subdomain_id();
205 
206  // Set the nodes
207  for (unsigned n=0; n<edge->n_nodes(); ++n)
208  edge->set_node(n) = this->node_ptr(Quad8::side_nodes_map[i][n]);
209 
210  return UniquePtr<Elem>(edge);
211  }
212 
213  libmesh_error_msg("We'll never get here!");
214  return UniquePtr<Elem>();
215 }
216 
217 
218 
219 
220 
221 
222 void Quad8::connectivity(const unsigned int sf,
223  const IOPackage iop,
224  std::vector<dof_id_type> & conn) const
225 {
226  libmesh_assert_less (sf, this->n_sub_elem());
227  libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE);
228 
229  switch (iop)
230  {
231  // Note: TECPLOT connectivity is output as four triangles with
232  // a central quadrilateral. Therefore, the first four connectivity
233  // arrays are degenerate quads (triangles in Tecplot).
234  case TECPLOT:
235  {
236  // Create storage
237  conn.resize(4);
238 
239  switch(sf)
240  {
241  case 0:
242  // linear sub-tri 0
243  conn[0] = this->node_id(0)+1;
244  conn[1] = this->node_id(4)+1;
245  conn[2] = this->node_id(7)+1;
246  conn[3] = this->node_id(7)+1;
247 
248  return;
249 
250  case 1:
251  // linear sub-tri 1
252  conn[0] = this->node_id(4)+1;
253  conn[1] = this->node_id(1)+1;
254  conn[2] = this->node_id(5)+1;
255  conn[3] = this->node_id(5)+1;
256 
257  return;
258 
259  case 2:
260  // linear sub-tri 2
261  conn[0] = this->node_id(5)+1;
262  conn[1] = this->node_id(2)+1;
263  conn[2] = this->node_id(6)+1;
264  conn[3] = this->node_id(6)+1;
265 
266  return;
267 
268  case 3:
269  // linear sub-tri 3
270  conn[0] = this->node_id(7)+1;
271  conn[1] = this->node_id(6)+1;
272  conn[2] = this->node_id(3)+1;
273  conn[3] = this->node_id(3)+1;
274 
275  return;
276 
277  case 4:
278  // linear sub-quad
279  conn[0] = this->node_id(4)+1;
280  conn[1] = this->node_id(5)+1;
281  conn[2] = this->node_id(6)+1;
282  conn[3] = this->node_id(7)+1;
283 
284  return;
285 
286  default:
287  libmesh_error_msg("Invalid sf = " << sf);
288  }
289  }
290 
291 
292  // Note: VTK connectivity is output as four triangles with
293  // a central quadrilateral. Therefore most of the connectivity
294  // arrays have length three.
295  case VTK:
296  {
297  // Create storage
298  conn.resize(8);
299  conn[0] = this->node_id(0);
300  conn[1] = this->node_id(1);
301  conn[2] = this->node_id(2);
302  conn[3] = this->node_id(3);
303  conn[4] = this->node_id(4);
304  conn[5] = this->node_id(5);
305  conn[6] = this->node_id(6);
306  conn[7] = this->node_id(7);
307  return;
308  /*
309  conn.resize(3);
310 
311  switch (sf)
312  {
313  case 0:
314  // linear sub-tri 0
315  conn[0] = this->node_id(0);
316  conn[1] = this->node_id(4);
317  conn[2] = this->node_id(7);
318 
319  return;
320 
321  case 1:
322  // linear sub-tri 1
323  conn[0] = this->node_id(4);
324  conn[1] = this->node_id(1);
325  conn[2] = this->node_id(5);
326 
327  return;
328 
329  case 2:
330  // linear sub-tri 2
331  conn[0] = this->node_id(5);
332  conn[1] = this->node_id(2);
333  conn[2] = this->node_id(6);
334 
335  return;
336 
337  case 3:
338  // linear sub-tri 3
339  conn[0] = this->node_id(7);
340  conn[1] = this->node_id(6);
341  conn[2] = this->node_id(3);
342 
343  return;
344 
345  case 4:
346  conn.resize(4);
347 
348  // linear sub-quad
349  conn[0] = this->node_id(4);
350  conn[1] = this->node_id(5);
351  conn[2] = this->node_id(6);
352  conn[3] = this->node_id(7);
353  */
354  // return;
355 
356  // default:
357  // libmesh_error_msg("Invalid sf = " << sf);
358  // }
359  }
360 
361  default:
362  libmesh_error_msg("Unsupported IO package " << iop);
363  }
364 }
365 
366 
367 
369 {
370  // This might have curved edges, or might be a curved surface in
371  // 3-space, in which case the full bounding box can be larger than
372  // the bounding box of just the nodes.
373  //
374  //
375  // FIXME - I haven't yet proven the formula below to be correct for
376  // biquadratics - RHS
377  Point pmin, pmax;
378 
379  for (unsigned d=0; d<LIBMESH_DIM; ++d)
380  {
381  Real center = this->point(0)(d);
382  for (unsigned int p=1; p != 8; ++p)
383  center += this->point(p)(d);
384  center /= 8;
385 
386  Real hd = std::abs(center - this->point(0)(d));
387  for (unsigned int p=0; p != 8; ++p)
388  hd = std::max(hd, std::abs(center - this->point(p)(d)));
389 
390  pmin(d) = center - hd;
391  pmax(d) = center + hd;
392  }
393 
394  return BoundingBox(pmin, pmax);
395 }
396 
397 
399 {
400  // Make copies of our points. It makes the subsequent calculations a bit
401  // shorter and avoids dereferencing the same pointer multiple times.
402  Point
403  x0 = point(0),
404  x1 = point(1),
405  x2 = point(2),
406  x3 = point(3),
407  x4 = point(4),
408  x5 = point(5),
409  x6 = point(6),
410  x7 = point(7);
411 
412  // Construct constant data vectors.
413  // \vec{x}_{\xi} = \vec{a1}*eta**2 + \vec{b1}*xi*eta + \vec{c1}*xi + \vec{d1}*eta + \vec{e1}
414  // \vec{x}_{\eta} = \vec{a2}*xi**2 + \vec{b2}*xi*eta + \vec{c2}*xi + \vec{d2}*eta + \vec{e2}
415  // This is copy-pasted directly from the output of a Python script.
416  Point
417  a1 = -x0/4 + x1/4 + x2/4 - x3/4 - x5/2 + x7/2,
418  b1 = -x0/2 - x1/2 + x2/2 + x3/2 + x4 - x6,
419  c1 = x0/2 + x1/2 + x2/2 + x3/2 - x4 - x6,
420  d1 = x0/4 - x1/4 + x2/4 - x3/4,
421  e1 = x5/2 - x7/2,
422  a2 = -x0/4 - x1/4 + x2/4 + x3/4 + x4/2 - x6/2,
423  b2 = -x0/2 + x1/2 + x2/2 - x3/2 - x5 + x7,
424  c2 = x0/4 - x1/4 + x2/4 - x3/4,
425  d2 = x0/2 + x1/2 + x2/2 + x3/2 - x5 - x7,
426  e2 = -x4/2 + x6/2;
427 
428  // 3x3 quadrature, exact for bi-quintics
429  const unsigned int N = 3;
430  const Real q[N] = {-std::sqrt(15)/5., 0., std::sqrt(15)/5.};
431  const Real w[N] = {5./9, 8./9, 5./9};
432 
433  Real vol=0.;
434  for (unsigned int i=0; i<N; ++i)
435  for (unsigned int j=0; j<N; ++j)
436  vol += w[i] * w[j] * cross_norm(q[j]*q[j]*a1 + q[i]*q[j]*b1 + q[i]*c1 + q[j]*d1 + e1,
437  q[i]*q[i]*a2 + q[i]*q[j]*b2 + q[i]*c2 + q[j]*d2 + e2);
438 
439  return vol;
440 }
441 
442 
443 
444 unsigned short int Quad8::second_order_adjacent_vertex (const unsigned int n,
445  const unsigned int v) const
446 {
447  libmesh_assert_greater_equal (n, this->n_vertices());
448  libmesh_assert_less (n, this->n_nodes());
449  libmesh_assert_less (v, 2);
450  // use the matrix from \p face_quad.C
451  return _second_order_adjacent_vertices[n-this->n_vertices()][v];
452 }
453 
454 
455 
456 std::pair<unsigned short int, unsigned short int>
457 Quad8::second_order_child_vertex (const unsigned int n) const
458 {
459  libmesh_assert_greater_equal (n, this->n_vertices());
460  libmesh_assert_less (n, this->n_nodes());
461  /*
462  * the _second_order_vertex_child_* vectors are
463  * stored in face_quad.C, since they are identical
464  * for Quad8 and Quad9 (for the first 4 higher-order nodes)
465  */
466  return std::pair<unsigned short int, unsigned short int>
469 }
470 
471 } // namespace libMesh
double abs(double a)
virtual Node *& set_node(const unsigned int i)
Definition: elem.h:1723
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:202
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:222
virtual std::pair< unsigned short int, unsigned short int > second_order_child_vertex(const unsigned int n) const libmesh_override
Definition: face_quad8.C:457
virtual dof_id_type key() const libmesh_override
Definition: face_quad.C:63
T cross_norm(const TypeVector< T > &b, const TypeVector< T > &c)
Definition: type_vector.h:1068
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:165
virtual bool is_vertex(const unsigned int i) const libmesh_override
Definition: face_quad8.C:106
The base class for all geometric element types.
Definition: elem.h:86
long double max(long double a, double b)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
virtual unsigned int n_nodes() const =0
virtual UniquePtr< Elem > build_side_ptr(const unsigned int i, bool proxy) libmesh_override
Definition: face_quad8.C:193
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:1658
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:184
static const unsigned short int _second_order_vertex_child_number[9]
Definition: face_quad.h:179
subdomain_id_type subdomain_id() const
Definition: elem.h:1733
A 1D geometric element with 3 nodes.
Definition: edge_edge3.h:43
static const unsigned short int _second_order_adjacent_vertices[4][2]
Definition: face_quad.h:174
virtual Real volume() const libmesh_override
Definition: face_quad8.C:398
Proxy class for efficiently representing an Elem&#39;s side.
Definition: side.h:48
virtual unsigned short int second_order_adjacent_vertex(const unsigned int n, const unsigned int v) const libmesh_override
Definition: face_quad8.C:444
virtual BoundingBox loose_bounding_box() const libmesh_override
Definition: face_quad8.C:368
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const Point & point(const unsigned int i) const
Definition: elem.h:1595
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:1617
static dof_id_type compute_key(dof_id_type n0)
Definition: elem.h:2336
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:963
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