fe_lagrange_shape_1D.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 
19 // C++ inlcludes
20 
21 // Local includes
22 #include "libmesh/fe.h"
23 #include "libmesh/elem.h"
24 
25 namespace libMesh
26 {
27 
28 
29 
30 
31 template <>
33  const Order order,
34  const unsigned int i,
35  const Point& p)
36 {
37  const Real xi = p(0);
38 
39 
40  switch (order)
41  {
42  // Lagrange linears
43  case FIRST:
44  {
45  libmesh_assert_less (i, 2);
46 
47  switch (i)
48  {
49  case 0:
50  return .5*(1. - xi);
51 
52  case 1:
53  return .5*(1. + xi);
54 
55  default:
56  libMesh::err << "Invalid shape function index!" << std::endl;
57  libmesh_error();
58  }
59  }
60 
61 
62 
63  // Lagrange quadratics
64  case SECOND:
65  {
66  libmesh_assert_less (i, 3);
67 
68  switch (i)
69  {
70  case 0:
71  return .5*xi*(xi - 1.);
72 
73  case 1:
74  return .5*xi*(xi + 1);
75 
76  case 2:
77  return (1. - xi*xi);
78 
79  default:
80  libMesh::err << "Invalid shape function index!" << std::endl;
81  libmesh_error();
82  }
83  }
84 
85 
86 
87  // Lagrange cubics
88  case THIRD:
89  {
90  libmesh_assert_less (i, 4);
91 
92  switch (i)
93  {
94  case 0:
95  return 9./16.*(1./9.-xi*xi)*(xi-1.);
96 
97  case 1:
98  return -9./16.*(1./9.-xi*xi)*(xi+1.);
99 
100  case 2:
101  return 27./16.*(1.-xi*xi)*(1./3.-xi);
102 
103  case 3:
104  return 27./16.*(1.-xi*xi)*(1./3.+xi);
105 
106  default:
107  libMesh::err << "Invalid shape function index!" << std::endl;
108  libmesh_error();
109  }
110  }
111 
112  default:
113  {
114  libMesh::err << "ERROR: Unsupported polynomial order!" << std::endl;
115  libmesh_error();
116  }
117  }
118 
119 
120  libmesh_error();
121  return 0.;
122 }
123 
124 
125 
126 template <>
128  const Order order,
129  const unsigned int i,
130  const Point& p)
131 {
132  libmesh_assert(elem);
133 
134  return FE<1,LAGRANGE>::shape(elem->type(), static_cast<Order>(order + elem->p_level()), i, p);
135 }
136 
137 
138 
139 template <>
141  const Order order,
142  const unsigned int i,
143  const unsigned int libmesh_dbg_var(j),
144  const Point& p)
145 {
146  // only d()/dxi in 1D!
147 
148  libmesh_assert_equal_to (j, 0);
149 
150  const Real xi = p(0);
151 
152 
153  switch (order)
154  {
155  // Lagrange linear shape function derivatives
156  case FIRST:
157  {
158  libmesh_assert_less (i, 2);
159 
160  switch (i)
161  {
162  case 0:
163  return -.5;
164 
165  case 1:
166  return .5;
167 
168  default:
169  libMesh::err << "Invalid shape function index!" << std::endl;
170  libmesh_error();
171  }
172  }
173 
174 
175  // Lagrange quadratic shape function derivatives
176  case SECOND:
177  {
178  libmesh_assert_less (i, 3);
179 
180  switch (i)
181  {
182  case 0:
183  return xi-.5;
184 
185  case 1:
186  return xi+.5;
187 
188  case 2:
189  return -2.*xi;
190 
191  default:
192  libMesh::err << "Invalid shape function index!" << std::endl;
193  libmesh_error();
194  }
195  }
196 
197 
198  // Lagrange cubic shape function derivatives
199  case THIRD:
200  {
201  libmesh_assert_less (i, 4);
202 
203  switch (i)
204  {
205  case 0:
206  return -9./16.*(3.*xi*xi-2.*xi-1./9.);
207 
208  case 1:
209  return -9./16.*(-3.*xi*xi-2.*xi+1./9.);
210 
211  case 2:
212  return 27./16.*(3.*xi*xi-2./3.*xi-1.);
213 
214  case 3:
215  return 27./16.*(-3.*xi*xi-2./3.*xi+1.);
216 
217  default:
218  libMesh::err << "Invalid shape function index!" << std::endl;
219  libmesh_error();
220  }
221  }
222 
223 
224  default:
225  {
226  libMesh::err << "ERROR: Unsupported polynomial order!" << std::endl;
227  libmesh_error();
228  }
229  }
230 
231  libmesh_error();
232  return 0.;
233 }
234 
235 
236 
237 template <>
239  const Order order,
240  const unsigned int i,
241  const unsigned int j,
242  const Point& p)
243 {
244  libmesh_assert(elem);
245 
246  return FE<1,LAGRANGE>::shape_deriv(elem->type(),
247  static_cast<Order>(order + elem->p_level()), i, j, p);
248 }
249 
250 
251 
252 
253 template <>
255  const Order order,
256  const unsigned int i,
257  const unsigned int libmesh_dbg_var(j),
258  const Point& p)
259 {
260  // Don't need to switch on j. 1D shape functions
261  // depend on xi only!
262 
263  const Real xi = p(0);
264  libmesh_assert_equal_to (j, 0);
265 
266  switch (order)
267  {
268  // linear Lagrange shape functions
269  case FIRST:
270  {
271  // All second derivatives of linears are zero....
272  return 0.;
273  }
274 
275  // quadratic Lagrange shape functions
276  case SECOND:
277  {
278  switch (i)
279  {
280  case 0:
281  return 1.;
282 
283  case 1:
284  return 1.;
285 
286  case 2:
287  return -2.;
288 
289  default:
290  {
291  libMesh::err << "Invalid shape function index requested!"
292  << std::endl;
293  libmesh_error();
294  }
295  }
296  } // end case SECOND
297 
298  case THIRD:
299  {
300  switch (i)
301  {
302  case 0:
303  return -9./16.*(6.*xi-2);
304 
305  case 1:
306  return -9./16.*(-6*xi-2.);
307 
308  case 2:
309  return 27./16.*(6*xi-2./3.);
310 
311  case 3:
312  return 27./16.*(-6*xi-2./3.);
313 
314  default:
315  {
316  libMesh::err << "Invalid shape function index requested!"
317  << std::endl;
318  libmesh_error();
319  }
320  }
321  } // end case THIRD
322 
323 
324  default:
325  {
326  libMesh::err << "ERROR: Unsupported polynomial order!" << std::endl;
327  libmesh_error();
328  }
329  } // end switch (order)
330 
331  libmesh_error();
332  return 0.;
333 }
334 
335 
336 
337 template <>
339  const Order order,
340  const unsigned int i,
341  const unsigned int j,
342  const Point& p)
343 {
344  libmesh_assert(elem);
345 
347  static_cast<Order>(order + elem->p_level()), i, j, p);
348 }
349 
350 } // namespace libMesh

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:05 UTC

Hosted By:
SourceForge.net Logo