libMesh
fe_monomial_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 // C++ includes
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 libmesh_dbg_var(order),
34  const unsigned int i,
35  const Point & p)
36 {
37  const Real xi = p(0);
38 
39  libmesh_assert_less_equal (i, static_cast<unsigned int>(order));
40 
41  // monomials. since they are hierarchic we only need one case block.
42  switch (i)
43  {
44  case 0:
45  return 1.;
46 
47  case 1:
48  return xi;
49 
50  case 2:
51  return xi*xi;
52 
53  case 3:
54  return xi*xi*xi;
55 
56  case 4:
57  return xi*xi*xi*xi;
58 
59  default:
60  Real val = 1.;
61  for (unsigned int index = 0; index != i; ++index)
62  val *= xi;
63  return val;
64  }
65 }
66 
67 
68 
69 template <>
71  const Order order,
72  const unsigned int i,
73  const Point & p,
74  const bool add_p_level)
75 {
76  libmesh_assert(elem);
77 
78  return FE<1,MONOMIAL>::shape(elem->type(), static_cast<Order>(order + add_p_level * elem->p_level()), i, p);
79 }
80 
81 
82 
83 template <>
85  const Order libmesh_dbg_var(order),
86  const unsigned int i,
87  const unsigned int libmesh_dbg_var(j),
88  const Point & p)
89 {
90  // only d()/dxi in 1D!
91 
92  libmesh_assert_equal_to (j, 0);
93 
94  const Real xi = p(0);
95 
96  libmesh_assert_less_equal (i, static_cast<unsigned int>(order));
97 
98  // monomials. since they are hierarchic we only need one case block.
99  switch (i)
100  {
101  case 0:
102  return 0.;
103 
104  case 1:
105  return 1.;
106 
107  case 2:
108  return 2.*xi;
109 
110  case 3:
111  return 3.*xi*xi;
112 
113  case 4:
114  return 4.*xi*xi*xi;
115 
116  default:
117  Real val = i;
118  for (unsigned int index = 1; index != i; ++index)
119  val *= xi;
120  return val;
121  }
122 }
123 
124 
125 
126 template <>
128  const Order order,
129  const unsigned int i,
130  const unsigned int j,
131  const Point & p,
132  const bool add_p_level)
133 {
134  libmesh_assert(elem);
135 
136  return FE<1,MONOMIAL>::shape_deriv(elem->type(),
137  static_cast<Order>(order + add_p_level * elem->p_level()), i, j, p);
138 }
139 
140 
141 #ifdef LIBMESH_ENABLE_SECOND_DERIVATIVES
142 
143 template <>
145  const Order libmesh_dbg_var(order),
146  const unsigned int i,
147  const unsigned int libmesh_dbg_var(j),
148  const Point & p)
149 {
150  // only d()/dxi in 1D!
151 
152  libmesh_assert_equal_to (j, 0);
153 
154  const Real xi = p(0);
155 
156  libmesh_assert_less_equal (i, static_cast<unsigned int>(order));
157 
158  switch (i)
159  {
160  case 0:
161  case 1:
162  return 0.;
163 
164  case 2:
165  return 2.;
166 
167  case 3:
168  return 6.*xi;
169 
170  case 4:
171  return 12.*xi*xi;
172 
173  default:
174  Real val = 2.;
175  for (unsigned int index = 2; index != i; ++index)
176  val *= (index+1) * xi;
177  return val;
178  }
179 }
180 
181 
182 
183 template <>
185  const Order order,
186  const unsigned int i,
187  const unsigned int j,
188  const Point & p,
189  const bool add_p_level)
190 {
191  libmesh_assert(elem);
192 
194  static_cast<Order>(order + add_p_level * elem->p_level()), i, j, p);
195 }
196 
197 #endif
198 
199 } // namespace libMesh
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::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