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