libMesh
fe_hierarchic_shape_1D.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 // Local includes
20 #include "libmesh/fe.h"
21 #include "libmesh/elem.h"
22 #include "libmesh/utility.h"
23 
24 // Anonymous namespace for functions shared by HIERARCHIC and
25 // L2_HIERARCHIC implementations. Implementations appear at the bottom
26 // of this file.
27 namespace
28 {
29 using namespace libMesh;
30 
31 Real fe_hierarchic_1D_shape(const ElemType,
32  const Order libmesh_dbg_var(order),
33  const unsigned int i,
34  const Point & p);
35 
36 Real fe_hierarchic_1D_shape_deriv(const ElemType,
37  const Order libmesh_dbg_var(order),
38  const unsigned int i,
39  const unsigned int libmesh_dbg_var(j),
40  const Point & p);
41 
42 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
43 
44 Real fe_hierarchic_1D_shape_second_deriv(const ElemType,
45  const Order libmesh_dbg_var(order),
46  const unsigned int i,
47  const unsigned int libmesh_dbg_var(j),
48  const Point & p);
49 
50 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
51 
52 } // anonymous namespace
53 
54 
55 
56 namespace libMesh
57 {
58 
59 template <>
61  const Order order,
62  const unsigned int i,
63  const Point & p)
64 {
65  return fe_hierarchic_1D_shape(elem_type, order, i, p);
66 }
67 
68 
69 
70 template <>
72  const Order order,
73  const unsigned int i,
74  const Point & p)
75 {
76  return fe_hierarchic_1D_shape(elem_type, order, i, p);
77 }
78 
79 
80 
81 template <>
83  const Order order,
84  const unsigned int i,
85  const Point & p,
86  const bool add_p_level)
87 {
88  libmesh_assert(elem);
89 
90  return fe_hierarchic_1D_shape(elem->type(), static_cast<Order>(order + add_p_level * elem->p_level()), i, p);
91 }
92 
93 
94 
95 template <>
97  const Order order,
98  const unsigned int i,
99  const Point & p,
100  const bool add_p_level)
101 {
102  libmesh_assert(elem);
103 
104  return fe_hierarchic_1D_shape(elem->type(), static_cast<Order>(order + add_p_level * elem->p_level()), i, p);
105 }
106 
107 
108 
109 template <>
111  const Order order,
112  const unsigned int i,
113  const unsigned int j,
114  const Point & p)
115 {
116  return fe_hierarchic_1D_shape_deriv(elem_type, order, i, j, p);
117 }
118 
119 
120 
121 template <>
123  const Order order,
124  const unsigned int i,
125  const unsigned int j,
126  const Point & p)
127 {
128  return fe_hierarchic_1D_shape_deriv(elem_type, order, i, j, p);
129 }
130 
131 
132 
133 template <>
135  const Order order,
136  const unsigned int i,
137  const unsigned int j,
138  const Point & p,
139  const bool add_p_level)
140 {
141  libmesh_assert(elem);
142 
143  return fe_hierarchic_1D_shape_deriv(elem->type(),
144  static_cast<Order>(order + add_p_level * elem->p_level()), i, j, p);
145 }
146 
147 
148 template <>
150  const Order order,
151  const unsigned int i,
152  const unsigned int j,
153  const Point & p,
154  const bool add_p_level)
155 {
156  libmesh_assert(elem);
157 
158  return fe_hierarchic_1D_shape_deriv(elem->type(),
159  static_cast<Order>(order + add_p_level * elem->p_level()), i, j, p);
160 }
161 
162 
163 
164 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
165 
166 template <>
168  const Order order,
169  const unsigned int i,
170  const unsigned int j,
171  const Point & p)
172 {
173  return fe_hierarchic_1D_shape_second_deriv(elem_type, order, i, j, p);
174 }
175 
176 
177 
178 
179 template <>
181  const Order order,
182  const unsigned int i,
183  const unsigned int j,
184  const Point & p)
185 {
186  return fe_hierarchic_1D_shape_second_deriv(elem_type, order, i, j, p);
187 }
188 
189 
190 template <>
192  const Order order,
193  const unsigned int i,
194  const unsigned int j,
195  const Point & p,
196  const bool add_p_level)
197 {
198  libmesh_assert(elem);
199 
200  return fe_hierarchic_1D_shape_second_deriv(elem->type(),
201  static_cast<Order>(order + add_p_level * elem->p_level()), i, j, p);
202 }
203 
204 
205 
206 template <>
208  const Order order,
209  const unsigned int i,
210  const unsigned int j,
211  const Point & p,
212  const bool add_p_level)
213 {
214  libmesh_assert(elem);
215 
216  return fe_hierarchic_1D_shape_second_deriv(elem->type(),
217  static_cast<Order>(order + add_p_level * elem->p_level()), i, j, p);
218 }
219 
220 #endif
221 
222 } // namespace libMesh
223 
224 
225 
226 namespace
227 {
228 using namespace libMesh;
229 
230 Real fe_hierarchic_1D_shape(const ElemType,
231  const Order libmesh_dbg_var(order),
232  const unsigned int i,
233  const Point & p)
234 {
235  libmesh_assert_less (i, order+1u);
236 
237  // Declare that we are using our own special power function
238  // from the Utility namespace. This saves typing later.
239  using Utility::pow;
240 
241  const Real xi = p(0);
242 
243  Real returnval = 1.;
244 
245  switch (i)
246  {
247  case 0:
248  returnval = .5*(1. - xi);
249  break;
250  case 1:
251  returnval = .5*(1. + xi);
252  break;
253  // All even-terms have the same form.
254  // (xi^p - 1.)/p!
255  case 2:
256  returnval = (xi*xi - 1.)/2.;
257  break;
258  case 4:
259  returnval = (pow<4>(xi) - 1.)/24.;
260  break;
261  case 6:
262  returnval = (pow<6>(xi) - 1.)/720.;
263  break;
264 
265  // All odd-terms have the same form.
266  // (xi^p - xi)/p!
267  case 3:
268  returnval = (xi*xi*xi - xi)/6.;
269  break;
270  case 5:
271  returnval = (pow<5>(xi) - xi)/120.;
272  break;
273  case 7:
274  returnval = (pow<7>(xi) - xi)/5040.;
275  break;
276  default:
277  Real denominator = 1.;
278  for (unsigned int n=1; n <= i; ++n)
279  {
280  returnval *= xi;
281  denominator *= n;
282  }
283  // Odd:
284  if (i % 2)
285  returnval = (returnval - xi)/denominator;
286  // Even:
287  else
288  returnval = (returnval - 1.)/denominator;
289  break;
290  }
291 
292  return returnval;
293 }
294 
295 
296 
297 Real fe_hierarchic_1D_shape_deriv(const ElemType,
298  const Order libmesh_dbg_var(order),
299  const unsigned int i,
300  const unsigned int libmesh_dbg_var(j),
301  const Point & p)
302 {
303  // only d()/dxi in 1D!
304 
305  libmesh_assert_equal_to (j, 0);
306  libmesh_assert_less (i, order+1u);
307 
308  // Declare that we are using our own special power function
309  // from the Utility namespace. This saves typing later.
310  using Utility::pow;
311 
312  const Real xi = p(0);
313 
314  Real returnval = 1.;
315 
316  switch (i)
317  {
318  case 0:
319  returnval = -.5;
320  break;
321  case 1:
322  returnval = .5;
323  break;
324  // All even-terms have the same form.
325  // xi^(p-1)/(p-1)!
326  case 2:
327  returnval = xi;
328  break;
329  case 4:
330  returnval = pow<3>(xi)/6.;
331  break;
332  case 6:
333  returnval = pow<5>(xi)/120.;
334  break;
335  // All odd-terms have the same form.
336  // (p*xi^(p-1) - 1.)/p!
337  case 3:
338  returnval = (3*xi*xi - 1.)/6.;
339  break;
340  case 5:
341  returnval = (5.*pow<4>(xi) - 1.)/120.;
342  break;
343  case 7:
344  returnval = (7.*pow<6>(xi) - 1.)/5040.;
345  break;
346  default:
347  Real denominator = 1.;
348  for (unsigned int n=1; n != i; ++n)
349  {
350  returnval *= xi;
351  denominator *= n;
352  }
353  // Odd:
354  if (i % 2)
355  returnval = (i * returnval - 1.)/denominator/i;
356  // Even:
357  else
358  returnval = returnval/denominator;
359  break;
360  }
361 
362  return returnval;
363 }
364 
365 
366 
367 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
368 
369 Real fe_hierarchic_1D_shape_second_deriv(const ElemType,
370  const Order libmesh_dbg_var(order),
371  const unsigned int i,
372  const unsigned int libmesh_dbg_var(j),
373  const Point & p)
374 {
375  // only d2()/d2xi in 1D!
376 
377  libmesh_assert_equal_to (j, 0);
378  libmesh_assert_less (i, order+1u);
379 
380  // Declare that we are using our own special power function
381  // from the Utility namespace. This saves typing later.
382  using Utility::pow;
383 
384  const Real xi = p(0);
385 
386  Real returnval = 1.;
387 
388  switch (i)
389  {
390  case 0:
391  case 1:
392  returnval = 0;
393  break;
394  // All terms have the same form.
395  // xi^(p-2)/(p-2)!
396  case 2:
397  returnval = 1;
398  break;
399  case 3:
400  returnval = xi;
401  break;
402  case 4:
403  returnval = pow<2>(xi)/2.;
404  break;
405  case 5:
406  returnval = pow<3>(xi)/6.;
407  break;
408  case 6:
409  returnval = pow<4>(xi)/24.;
410  break;
411  case 7:
412  returnval = pow<5>(xi)/120.;
413  break;
414 
415  default:
416  Real denominator = 1.;
417  for (unsigned int n=1; n != i; ++n)
418  {
419  returnval *= xi;
420  denominator *= n;
421  }
422  // Odd:
423  if (i % 2)
424  returnval = (i * returnval - 1.)/denominator/i;
425  // Even:
426  else
427  returnval = returnval/denominator;
428  break;
429  }
430 
431  return returnval;
432 }
433 
434 #endif // LIBMESH_ENABLE_SECOND_DERIVATIVES
435 
436 } // anonymous namespace
libMesh::FE::shape_second_deriv
static OutputShape shape_second_deriv(const ElemType t, const Order o, const unsigned int i, const unsigned int j, const Point &p)
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::Order
Order
Definition: enum_order.h:40
libMesh::Elem::p_level
unsigned int p_level() const
Definition: elem.h:2512
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::FE::shape
static OutputShape shape(const ElemType t, const Order o, const unsigned int i, const Point &p)
libMesh::FE::shape_deriv
static OutputShape shape_deriv(const ElemType t, const Order o, const unsigned int i, const unsigned int j, const Point &p)
libMesh::Point
A Point defines a location in LIBMESH_DIM dimensional Real space.
Definition: point.h:38
libMesh::Utility::pow
T pow(const T &x)
Definition: utility.h:246
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::Elem::type
virtual ElemType type() const =0
libMesh::ElemType
ElemType
Defines an enum for geometric element types.
Definition: enum_elem_type.h:33