cell_hex8.C
Go to the documentation of this file.00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2012 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 // C++ includes 00020 00021 // Local includes 00022 #include "libmesh/side.h" 00023 #include "libmesh/cell_hex8.h" 00024 #include "libmesh/edge_edge2.h" 00025 #include "libmesh/face_quad4.h" 00026 00027 namespace libMesh 00028 { 00029 00030 00031 00032 00033 // ------------------------------------------------------------ 00034 // Hex8 class static member initializations 00035 const unsigned int Hex8::side_nodes_map[6][4] = 00036 { 00037 {0, 3, 2, 1}, // Side 0 00038 {0, 1, 5, 4}, // Side 1 00039 {1, 2, 6, 5}, // Side 2 00040 {2, 3, 7, 6}, // Side 3 00041 {3, 0, 4, 7}, // Side 4 00042 {4, 5, 6, 7} // Side 5 00043 }; 00044 00045 const unsigned int Hex8::edge_nodes_map[12][2] = 00046 { 00047 {0, 1}, // Side 0 00048 {1, 2}, // Side 1 00049 {2, 3}, // Side 2 00050 {0, 3}, // Side 3 00051 {0, 4}, // Side 4 00052 {1, 5}, // Side 5 00053 {2, 6}, // Side 6 00054 {3, 7}, // Side 7 00055 {4, 5}, // Side 8 00056 {5, 6}, // Side 9 00057 {6, 7}, // Side 10 00058 {4, 7} // Side 11 00059 }; 00060 00061 00062 // ------------------------------------------------------------ 00063 // Hex8 class member functions 00064 00065 bool Hex8::is_vertex(const unsigned int) const 00066 { 00067 return true; 00068 } 00069 00070 bool Hex8::is_edge(const unsigned int) const 00071 { 00072 return false; 00073 } 00074 00075 bool Hex8::is_face(const unsigned int) const 00076 { 00077 return false; 00078 } 00079 00080 bool Hex8::is_node_on_side(const unsigned int n, 00081 const unsigned int s) const 00082 { 00083 libmesh_assert_less (s, n_sides()); 00084 for (unsigned int i = 0; i != 4; ++i) 00085 if (side_nodes_map[s][i] == n) 00086 return true; 00087 return false; 00088 } 00089 00090 bool Hex8::is_node_on_edge(const unsigned int n, 00091 const unsigned int e) const 00092 { 00093 libmesh_assert_less (e, n_edges()); 00094 for (unsigned int i = 0; i != 2; ++i) 00095 if (edge_nodes_map[e][i] == n) 00096 return true; 00097 return false; 00098 } 00099 00100 00101 00102 bool Hex8::has_affine_map() const 00103 { 00104 // Make sure x-edge endpoints are affine 00105 Point v = this->point(1) - this->point(0); 00106 if (!v.relative_fuzzy_equals(this->point(2) - this->point(3)) || 00107 !v.relative_fuzzy_equals(this->point(5) - this->point(4)) || 00108 !v.relative_fuzzy_equals(this->point(6) - this->point(7))) 00109 return false; 00110 // Make sure xz-faces are identical parallelograms 00111 v = this->point(4) - this->point(0); 00112 if (!v.relative_fuzzy_equals(this->point(7) - this->point(3))) 00113 return false; 00114 // If all the above checks out, the map is affine 00115 return true; 00116 } 00117 00118 00119 00120 AutoPtr<Elem> Hex8::build_side (const unsigned int i, 00121 bool proxy) const 00122 { 00123 libmesh_assert_less (i, this->n_sides()); 00124 00125 if (proxy) 00126 { 00127 AutoPtr<Elem> ap(new Side<Quad4,Hex8>(this,i)); 00128 return ap; 00129 } 00130 00131 else 00132 { 00133 AutoPtr<Elem> face(new Quad4); 00134 00135 // Think of a unit cube: (-1,1) x (-1,1)x (-1,1) 00136 switch (i) 00137 { 00138 case 0: // the face at z = -1 00139 { 00140 face->set_node(0) = this->get_node(0); 00141 face->set_node(1) = this->get_node(3); 00142 face->set_node(2) = this->get_node(2); 00143 face->set_node(3) = this->get_node(1); 00144 00145 return face; 00146 } 00147 case 1: // the face at y = -1 00148 { 00149 face->set_node(0) = this->get_node(0); 00150 face->set_node(1) = this->get_node(1); 00151 face->set_node(2) = this->get_node(5); 00152 face->set_node(3) = this->get_node(4); 00153 00154 return face; 00155 } 00156 case 2: // the face at x = 1 00157 { 00158 face->set_node(0) = this->get_node(1); 00159 face->set_node(1) = this->get_node(2); 00160 face->set_node(2) = this->get_node(6); 00161 face->set_node(3) = this->get_node(5); 00162 00163 return face; 00164 } 00165 case 3: // the face at y = 1 00166 { 00167 face->set_node(0) = this->get_node(2); 00168 face->set_node(1) = this->get_node(3); 00169 face->set_node(2) = this->get_node(7); 00170 face->set_node(3) = this->get_node(6); 00171 00172 return face; 00173 } 00174 case 4: // the face at x = -1 00175 { 00176 face->set_node(0) = this->get_node(3); 00177 face->set_node(1) = this->get_node(0); 00178 face->set_node(2) = this->get_node(4); 00179 face->set_node(3) = this->get_node(7); 00180 00181 return face; 00182 } 00183 case 5: // the face at z = 1 00184 { 00185 face->set_node(0) = this->get_node(4); 00186 face->set_node(1) = this->get_node(5); 00187 face->set_node(2) = this->get_node(6); 00188 face->set_node(3) = this->get_node(7); 00189 00190 return face; 00191 } 00192 default: 00193 { 00194 libmesh_error(); 00195 return face; 00196 } 00197 } 00198 } 00199 00200 // We'll never get here. 00201 libmesh_error(); 00202 AutoPtr<Elem> ap(NULL); return ap; 00203 } 00204 00205 00206 00207 AutoPtr<Elem> Hex8::build_edge (const unsigned int i) const 00208 { 00209 libmesh_assert_less (i, this->n_edges()); 00210 00211 AutoPtr<Elem> ap(new SideEdge<Edge2,Hex8>(this,i)); 00212 return ap; 00213 } 00214 00215 00216 00217 void Hex8::connectivity(const unsigned int libmesh_dbg_var(sc), 00218 const IOPackage iop, 00219 std::vector<dof_id_type>& conn) const 00220 { 00221 libmesh_assert(_nodes); 00222 libmesh_assert_less (sc, this->n_sub_elem()); 00223 libmesh_assert_not_equal_to (iop, INVALID_IO_PACKAGE); 00224 00225 conn.resize(8); 00226 00227 switch (iop) 00228 { 00229 case TECPLOT: 00230 { 00231 conn[0] = this->node(0)+1; 00232 conn[1] = this->node(1)+1; 00233 conn[2] = this->node(2)+1; 00234 conn[3] = this->node(3)+1; 00235 conn[4] = this->node(4)+1; 00236 conn[5] = this->node(5)+1; 00237 conn[6] = this->node(6)+1; 00238 conn[7] = this->node(7)+1; 00239 return; 00240 } 00241 00242 case VTK: 00243 { 00244 conn[0] = this->node(0); 00245 conn[1] = this->node(1); 00246 conn[2] = this->node(2); 00247 conn[3] = this->node(3); 00248 conn[4] = this->node(4); 00249 conn[5] = this->node(5); 00250 conn[6] = this->node(6); 00251 conn[7] = this->node(7); 00252 return; 00253 } 00254 00255 default: 00256 libmesh_error(); 00257 } 00258 00259 libmesh_error(); 00260 } 00261 00262 00263 00264 #ifdef LIBMESH_ENABLE_AMR 00265 00266 const float Hex8::_embedding_matrix[8][8][8] = 00267 { 00268 // The 8 children of the Hex-type elements can be thought of as being 00269 // associated with the 8 vertices of the Hex. Some of the children are 00270 // numbered the same as their corresponding vertex, while some are 00271 // not. The children which are numbered differently have been marked 00272 // with ** in the comments below. 00273 00274 // embedding matrix for child 0 (child 0 is associated with vertex 0) 00275 { 00276 // 0 1 2 3 4 5 6 7 00277 { 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // 0 00278 { 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // 1 00279 { .25, .25, .25, .25, 0.0, 0.0, 0.0, 0.0}, // 2 00280 { 0.5, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0}, // 3 00281 { 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0}, // 4 00282 { .25, .25, 0.0, 0.0, .25, .25, 0.0, 0.0}, // 5 00283 {.125, .125, .125, .125, .125, .125, .125, .125}, // 6 00284 { .25, 0.0, 0.0, .25, .25, 0.0, 0.0, .25} // 7 00285 }, 00286 00287 // embedding matrix for child 1 (child 1 is associated with vertex 1) 00288 { 00289 // 0 1 2 3 4 5 6 7 00290 { 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // 0 00291 { 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // 1 00292 { 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0}, // 2 00293 { .25, .25, .25, .25, 0.0, 0.0, 0.0, 0.0}, // 3 00294 { .25, .25, 0.0, 0.0, .25, .25, 0.0, 0.0}, // 4 00295 { 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0}, // 5 00296 { 0.0, .25, .25, 0.0, 0.0, .25, .25, 0.0}, // 6 00297 {.125, .125, .125, .125, .125, .125, .125, .125} // 7 00298 }, 00299 00300 // embedding matrix for child 2 (child 2 is associated with vertex 3**) 00301 { 00302 // 0 1 2 3 4 5 6 7 00303 { 0.5, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0}, // 0 00304 { .25, .25, .25, .25, 0.0, 0.0, 0.0, 0.0}, // 1 00305 { 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0}, // 2 00306 { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0}, // 3 00307 { .25, 0.0, 0.0, .25, .25, 0.0, 0.0, .25}, // 4 00308 {.125, .125, .125, .125, .125, .125, .125, .125}, // 5 00309 { 0.0, 0.0, .25, .25, 0.0, 0.0, .25, .25}, // 6 00310 { 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5} // 7 00311 }, 00312 00313 // embedding matrix for child 3 (child 3 is associated with vertex 2**) 00314 { 00315 // 0 1 2 3 4 5 6 7 00316 { .25, .25, .25, .25, 0.0, 0.0, 0.0, 0.0}, // 0 00317 { 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0, 0.0}, // 1 00318 { 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0}, // 2 00319 { 0.0, 0.0, 0.5, 0.5, 0.0, 0.0, 0.0, 0.0}, // 3 00320 {.125, .125, .125, .125, .125, .125, .125, .125}, // 4 00321 { 0.0, .25, .25, 0.0, 0.0, .25, .25, 0.0}, // 5 00322 { 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0}, // 6 00323 { 0.0, 0.0, .25, .25, 0.0, 0.0, .25, .25} // 7 00324 }, 00325 00326 // embedding matrix for child 4 (child 4 is associated with vertex 4) 00327 { 00328 // 0 1 2 3 4 5 6 7 00329 { 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0}, // 0 00330 { .25, .25, 0.0, 0.0, .25, .25, 0.0, 0.0}, // 1 00331 {.125, .125, .125, .125, .125, .125, .125, .125}, // 2 00332 { .25, 0.0, 0.0, .25, .25, 0.0, 0.0, .25}, // 3 00333 { 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0}, // 4 00334 { 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0}, // 5 00335 { 0.0, 0.0, 0.0, 0.0, .25, .25, .25, .25}, // 6 00336 { 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.5} // 7 00337 }, 00338 00339 // embedding matrix for child 5 (child 5 is associated with vertex 5) 00340 { 00341 // 0 1 2 3 4 5 6 7 00342 { .25, .25, 0.0, 0.0, .25, .25, 0.0, 0.0}, // 0 00343 { 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0}, // 1 00344 { 0.0, .25, .25, 0.0, 0.0, .25, .25, 0.0}, // 2 00345 {.125, .125, .125, .125, .125, .125, .125, .125}, // 3 00346 { 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0, 0.0}, // 4 00347 { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0}, // 5 00348 { 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0}, // 6 00349 { 0.0, 0.0, 0.0, 0.0, .25, .25, .25, .25} // 7 00350 }, 00351 00352 // embedding matrix for child 6 (child 6 is associated with vertex 7**) 00353 { 00354 // 0 1 2 3 4 5 6 7 00355 { .25, 0.0, 0.0, .25, .25, 0.0, 0.0, .25}, // 0 00356 {.125, .125, .125, .125, .125, .125, .125, .125}, // 1 00357 { 0.0, 0.0, .25, .25, 0.0, 0.0, .25, .25}, // 2 00358 { 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5}, // 3 00359 { 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.5}, // 4 00360 { 0.0, 0.0, 0.0, 0.0, .25, .25, .25, .25}, // 5 00361 { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5}, // 6 00362 { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0} // 7 00363 }, 00364 00365 // embedding matrix for child 7 (child 7 is associated with vertex 6**) 00366 { 00367 // 0 1 2 3 4 5 6 7 00368 {.125, .125, .125, .125, .125, .125, .125, .125}, // 0 00369 { 0.0, .25, .25, 0.0, 0.0, .25, .25, 0.0}, // 1 00370 { 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0}, // 2 00371 { 0.0, 0.0, .25, .25, 0.0, 0.0, .25, .25}, // 3 00372 { 0.0, 0.0, 0.0, 0.0, .25, .25, .25, .25}, // 4 00373 { 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.0}, // 5 00374 { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0}, // 6 00375 { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5} // 7 00376 } 00377 }; 00378 00379 00380 00381 00382 #endif 00383 00384 00385 00386 Real Hex8::volume () const 00387 { 00388 // Compute the volume of the tri-linear hex by splitting it 00389 // into 6 sub-pyramids and applying the formula in: 00390 // "Calculation of the Volume of a General Hexahedron 00391 // for Flow Predictions", AIAA Journal v.23, no.6, 1984, p.954- 00392 00393 static const unsigned char sub_pyr[6][4] = 00394 { 00395 {0, 3, 2, 1}, 00396 {6, 7, 4, 5}, 00397 {0, 1, 5, 4}, 00398 {3, 7, 6, 2}, 00399 {0, 4, 7, 3}, 00400 {1, 2, 6, 5} 00401 }; 00402 00403 // The centroid is a convenient point to use 00404 // for the apex of all the pyramids. 00405 const Point R = this->centroid(); 00406 Node* pyr_base[4]; 00407 00408 Real vol=0.; 00409 00410 // Compute the volume using 6 sub-pyramids 00411 for (unsigned int n=0; n<6; ++n) 00412 { 00413 // Set the nodes of the pyramid base 00414 for (unsigned int i=0; i<4; ++i) 00415 pyr_base[i] = this->_nodes[sub_pyr[n][i]]; 00416 00417 // Compute diff vectors 00418 Point a ( *pyr_base[0] - R ); 00419 Point b ( *pyr_base[1] - *pyr_base[3] ); 00420 Point c ( *pyr_base[2] - *pyr_base[0] ); 00421 Point d ( *pyr_base[3] - *pyr_base[0] ); 00422 Point e ( *pyr_base[1] - *pyr_base[0] ); 00423 00424 // Compute pyramid volume 00425 Real sub_vol = (1./6.)*(a*(b.cross(c))) + (1./12.)*(c*(d.cross(e))); 00426 00427 libmesh_assert (sub_vol>0.); 00428 00429 vol += sub_vol; 00430 } 00431 00432 return vol; 00433 } 00434 00435 } // namespace libMesh
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:45 UTC
Hosted By: