fe_lagrange_shape_1D.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++ inlcludes 00020 00021 // Local includes 00022 #include "libmesh/fe.h" 00023 #include "libmesh/elem.h" 00024 00025 namespace libMesh 00026 { 00027 00028 00029 00030 00031 template <> 00032 Real FE<1,LAGRANGE>::shape(const ElemType, 00033 const Order order, 00034 const unsigned int i, 00035 const Point& p) 00036 { 00037 const Real xi = p(0); 00038 00039 00040 switch (order) 00041 { 00042 // Lagrange linears 00043 case FIRST: 00044 { 00045 libmesh_assert_less (i, 2); 00046 00047 switch (i) 00048 { 00049 case 0: 00050 return .5*(1. - xi); 00051 00052 case 1: 00053 return .5*(1. + xi); 00054 00055 default: 00056 libMesh::err << "Invalid shape function index!" << std::endl; 00057 libmesh_error(); 00058 } 00059 } 00060 00061 00062 00063 // Lagrange quadratics 00064 case SECOND: 00065 { 00066 libmesh_assert_less (i, 3); 00067 00068 switch (i) 00069 { 00070 case 0: 00071 return .5*xi*(xi - 1.); 00072 00073 case 1: 00074 return .5*xi*(xi + 1); 00075 00076 case 2: 00077 return (1. - xi*xi); 00078 00079 default: 00080 libMesh::err << "Invalid shape function index!" << std::endl; 00081 libmesh_error(); 00082 } 00083 } 00084 00085 00086 00087 // Lagrange cubics 00088 case THIRD: 00089 { 00090 libmesh_assert_less (i, 4); 00091 00092 switch (i) 00093 { 00094 case 0: 00095 return 9./16.*(1./9.-xi*xi)*(xi-1.); 00096 00097 case 1: 00098 return -9./16.*(1./9.-xi*xi)*(xi+1.); 00099 00100 case 2: 00101 return 27./16.*(1.-xi*xi)*(1./3.-xi); 00102 00103 case 3: 00104 return 27./16.*(1.-xi*xi)*(1./3.+xi); 00105 00106 default: 00107 libMesh::err << "Invalid shape function index!" << std::endl; 00108 libmesh_error(); 00109 } 00110 } 00111 00112 default: 00113 { 00114 libMesh::err << "ERROR: Unsupported polynomial order!" << std::endl; 00115 libmesh_error(); 00116 } 00117 } 00118 00119 00120 libmesh_error(); 00121 return 0.; 00122 } 00123 00124 00125 00126 template <> 00127 Real FE<1,LAGRANGE>::shape(const Elem* elem, 00128 const Order order, 00129 const unsigned int i, 00130 const Point& p) 00131 { 00132 libmesh_assert(elem); 00133 00134 return FE<1,LAGRANGE>::shape(elem->type(), static_cast<Order>(order + elem->p_level()), i, p); 00135 } 00136 00137 00138 00139 template <> 00140 Real FE<1,LAGRANGE>::shape_deriv(const ElemType, 00141 const Order order, 00142 const unsigned int i, 00143 const unsigned int libmesh_dbg_var(j), 00144 const Point& p) 00145 { 00146 // only d()/dxi in 1D! 00147 00148 libmesh_assert_equal_to (j, 0); 00149 00150 const Real xi = p(0); 00151 00152 00153 switch (order) 00154 { 00155 // Lagrange linear shape function derivatives 00156 case FIRST: 00157 { 00158 libmesh_assert_less (i, 2); 00159 00160 switch (i) 00161 { 00162 case 0: 00163 return -.5; 00164 00165 case 1: 00166 return .5; 00167 00168 default: 00169 libMesh::err << "Invalid shape function index!" << std::endl; 00170 libmesh_error(); 00171 } 00172 } 00173 00174 00175 // Lagrange quadratic shape function derivatives 00176 case SECOND: 00177 { 00178 libmesh_assert_less (i, 3); 00179 00180 switch (i) 00181 { 00182 case 0: 00183 return xi-.5; 00184 00185 case 1: 00186 return xi+.5; 00187 00188 case 2: 00189 return -2.*xi; 00190 00191 default: 00192 libMesh::err << "Invalid shape function index!" << std::endl; 00193 libmesh_error(); 00194 } 00195 } 00196 00197 00198 // Lagrange cubic shape function derivatives 00199 case THIRD: 00200 { 00201 libmesh_assert_less (i, 4); 00202 00203 switch (i) 00204 { 00205 case 0: 00206 return -9./16.*(3.*xi*xi-2.*xi-1./9.); 00207 00208 case 1: 00209 return -9./16.*(-3.*xi*xi-2.*xi+1./9.); 00210 00211 case 2: 00212 return 27./16.*(3.*xi*xi-2./3.*xi-1.); 00213 00214 case 3: 00215 return 27./16.*(-3.*xi*xi-2./3.*xi+1.); 00216 00217 default: 00218 libMesh::err << "Invalid shape function index!" << std::endl; 00219 libmesh_error(); 00220 } 00221 } 00222 00223 00224 default: 00225 { 00226 libMesh::err << "ERROR: Unsupported polynomial order!" << std::endl; 00227 libmesh_error(); 00228 } 00229 } 00230 00231 libmesh_error(); 00232 return 0.; 00233 } 00234 00235 00236 00237 template <> 00238 Real FE<1,LAGRANGE>::shape_deriv(const Elem* elem, 00239 const Order order, 00240 const unsigned int i, 00241 const unsigned int j, 00242 const Point& p) 00243 { 00244 libmesh_assert(elem); 00245 00246 return FE<1,LAGRANGE>::shape_deriv(elem->type(), 00247 static_cast<Order>(order + elem->p_level()), i, j, p); 00248 } 00249 00250 00251 00252 00253 template <> 00254 Real FE<1,LAGRANGE>::shape_second_deriv(const ElemType, 00255 const Order order, 00256 const unsigned int i, 00257 const unsigned int libmesh_dbg_var(j), 00258 const Point& p) 00259 { 00260 // Don't need to switch on j. 1D shape functions 00261 // depend on xi only! 00262 00263 const Real xi = p(0); 00264 libmesh_assert_equal_to (j, 0); 00265 00266 switch (order) 00267 { 00268 // linear Lagrange shape functions 00269 case FIRST: 00270 { 00271 // All second derivatives of linears are zero.... 00272 return 0.; 00273 } 00274 00275 // quadratic Lagrange shape functions 00276 case SECOND: 00277 { 00278 switch (i) 00279 { 00280 case 0: 00281 return 1.; 00282 00283 case 1: 00284 return 1.; 00285 00286 case 2: 00287 return -2.; 00288 00289 default: 00290 { 00291 libMesh::err << "Invalid shape function index requested!" 00292 << std::endl; 00293 libmesh_error(); 00294 } 00295 } 00296 } // end case SECOND 00297 00298 case THIRD: 00299 { 00300 switch (i) 00301 { 00302 case 0: 00303 return -9./16.*(6.*xi-2); 00304 00305 case 1: 00306 return -9./16.*(-6*xi-2.); 00307 00308 case 2: 00309 return 27./16.*(6*xi-2./3.); 00310 00311 case 3: 00312 return 27./16.*(-6*xi-2./3.); 00313 00314 default: 00315 { 00316 libMesh::err << "Invalid shape function index requested!" 00317 << std::endl; 00318 libmesh_error(); 00319 } 00320 } 00321 } // end case THIRD 00322 00323 00324 default: 00325 { 00326 libMesh::err << "ERROR: Unsupported polynomial order!" << std::endl; 00327 libmesh_error(); 00328 } 00329 } // end switch (order) 00330 00331 libmesh_error(); 00332 return 0.; 00333 } 00334 00335 00336 00337 template <> 00338 Real FE<1,LAGRANGE>::shape_second_deriv(const Elem* elem, 00339 const Order order, 00340 const unsigned int i, 00341 const unsigned int j, 00342 const Point& p) 00343 { 00344 libmesh_assert(elem); 00345 00346 return FE<1,LAGRANGE>::shape_second_deriv(elem->type(), 00347 static_cast<Order>(order + elem->p_level()), i, j, p); 00348 } 00349 00350 } // namespace libMesh
Site Created By: libMesh Developers
Last modified: February 05 2013 19:54:46 UTC
Hosted By: