Line data Source code
1 : // The libMesh Finite Element Library.
2 : // Copyright (C) 2002-2026 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 :
20 : // Local includes
21 : #include "libmesh/elem.h"
22 : #include "libmesh/enum_to_string.h"
23 : #include "libmesh/fe.h"
24 : #include "libmesh/fe_interface.h"
25 : #include "libmesh/fe_lagrange_gll_shape_1D.h"
26 : #include "libmesh/fe_macro.h"
27 :
28 :
29 : namespace libMesh
30 : {
31 :
32 : /**
33 : * \returns The number of degrees of freedom that the LAGRANGE_GLL basis of order \p o carries
34 : * on an element of type \p t.
35 : *
36 : * The basis is a tensor product, so it applies only to tensor product element types. On
37 : * these types it has \f$(p+1)^d\f$ degrees of freedom.
38 : *
39 : * Each entity that owns degrees of freedom needs a node, and this limits the order on some
40 : * types. A vertex owns one degree of freedom and an edge owns p-1. Thus a type without mid-edge
41 : * nodes supports only order one. A face owns \f$(p-1)^2\f$, so in three dimensions a type
42 : * without face nodes supports only order one as well. The element owns the interior degrees of
43 : * freedom, so no type needs an interior node. HIERARCHIC has the same limits for the same
44 : * reason.
45 : */
46 255313 : unsigned int lagrange_gll_n_dofs(const ElemType t, const Order o)
47 : {
48 30494 : libmesh_assert_greater (o, 0);
49 :
50 255313 : const unsigned int n = static_cast<unsigned int>(o) + 1;
51 :
52 255313 : libmesh_error_msg_if(n > fe_lagrange_gll_max_points_1D,
53 : "The LAGRANGE_GLL basis of order " << o << " needs " << n
54 : << " Gauss-Lobatto points. The table has at most "
55 : << fe_lagrange_gll_max_points_1D << ".");
56 :
57 255313 : switch (t)
58 : {
59 0 : case NODEELEM:
60 0 : return 1;
61 :
62 : // An edge element has only vertices and an interior, so it needs no other nodes at any
63 : // order
64 5150 : case EDGE2:
65 : case EDGE3:
66 : case EDGE4:
67 5150 : return n;
68 :
69 : // Above order one, the edge degrees of freedom need mid-edge nodes
70 5972 : case QUAD4:
71 : case QUADSHELL4:
72 5972 : libmesh_error_msg_if(o > FIRST,
73 : "The LAGRANGE_GLL basis of order " << o << " puts " << o - 1
74 : << " degrees of freedom on each edge. "
75 : << Utility::enum_to_string(t) << " has no mid-edge nodes. "
76 : "Use QUAD8 or QUAD9.");
77 : libmesh_fallthrough();
78 : case QUAD8:
79 : case QUADSHELL8:
80 : case QUAD9:
81 : case QUADSHELL9:
82 40562 : return n*n;
83 :
84 : // In three dimensions, the face degrees of freedom also need face nodes
85 44276 : case HEX8:
86 44276 : libmesh_error_msg_if(o > FIRST,
87 : "The LAGRANGE_GLL basis of order " << o
88 : << " puts degrees of freedom on the edges and faces of a hexahedron. "
89 : "HEX8 has no edge or face nodes. Use HEX27.");
90 : libmesh_fallthrough();
91 : case HEX20:
92 7564 : libmesh_error_msg_if(o > FIRST,
93 : "The LAGRANGE_GLL basis of order " << o << " puts " << (o - 1)*(o - 1)
94 : << " degrees of freedom on each face. HEX20 has no face nodes. "
95 : "Use HEX27.");
96 : libmesh_fallthrough();
97 : case HEX27:
98 209601 : return n*n*n;
99 :
100 0 : case INVALID_ELEM:
101 0 : return 0;
102 :
103 0 : default:
104 0 : libmesh_error_msg("The LAGRANGE_GLL basis is a tensor product. It does not support "
105 : << Utility::enum_to_string(t) << ".");
106 : }
107 : }
108 :
109 :
110 255313 : unsigned int lagrange_gll_n_dofs(const Elem * e, const Order o)
111 : {
112 30494 : libmesh_assert(e);
113 255313 : return lagrange_gll_n_dofs(e->type(), o);
114 : }
115 :
116 : /**
117 : * \returns The number of degrees of freedom that node \p n of an element of type \p t owns.
118 : *
119 : * A vertex owns the degree of freedom at its own interpolation point. A mid-edge node owns
120 : * the p-1 points inside its edge. A mid-face node owns the \f$(p-1)^2\f$ points inside its face.
121 : * An interior node owns none. The element owns the interior points. This lets static
122 : * condensation eliminate them, and it lets types without an interior node use the basis.
123 : */
124 4070287 : unsigned int lagrange_gll_n_dofs_at_node(const ElemType t,
125 : const Order o,
126 : const unsigned int n)
127 : {
128 299281 : libmesh_assert_greater (o, 0);
129 :
130 4070287 : const unsigned int per_edge = static_cast<unsigned int>(o) - 1;
131 :
132 4070287 : switch (t)
133 : {
134 0 : case NODEELEM:
135 0 : return 1;
136 :
137 20995 : case EDGE2:
138 : case EDGE3:
139 : case EDGE4:
140 20995 : return (n < 2) ? 1 : 0;
141 :
142 294169 : case QUAD4:
143 : case QUADSHELL4:
144 741 : libmesh_assert_less (n, 4);
145 : libmesh_fallthrough();
146 : case QUAD8:
147 : case QUADSHELL8:
148 : case QUAD9:
149 : case QUADSHELL9:
150 318031 : if (n < 4)
151 11869 : return 1;
152 166213 : if (n < 8)
153 136312 : return per_edge;
154 2260 : return 0;
155 :
156 3460886 : case HEX8:
157 2301 : libmesh_assert_less (n, 8);
158 : libmesh_fallthrough();
159 : case HEX20:
160 : case HEX27:
161 3731261 : if (n < 8)
162 83880 : return 1;
163 2578911 : if (n < 20)
164 119223 : return per_edge;
165 950136 : if (n < 26)
166 814665 : return per_edge * per_edge;
167 9921 : return 0;
168 :
169 0 : case INVALID_ELEM:
170 0 : return 0;
171 :
172 0 : default:
173 0 : libmesh_error_msg("The LAGRANGE_GLL basis is a tensor product. It does not support "
174 : << Utility::enum_to_string(t) << ".");
175 : }
176 : }
177 :
178 : /**
179 : * \returns The number of degrees of freedom that the element itself owns. These are the
180 : * \f$(p-1)^d\f$ interpolation points in its interior.
181 : */
182 161072 : unsigned int lagrange_gll_n_dofs_per_elem(const ElemType t, const Order o)
183 : {
184 12039 : libmesh_assert_greater (o, 0);
185 :
186 161072 : const unsigned int per_edge = static_cast<unsigned int>(o) - 1;
187 :
188 161072 : switch (t)
189 : {
190 0 : case NODEELEM:
191 : case INVALID_ELEM:
192 0 : return 0;
193 :
194 7553 : case EDGE2:
195 : case EDGE3:
196 : case EDGE4:
197 7553 : return per_edge;
198 :
199 33146 : case QUAD4:
200 : case QUADSHELL4:
201 : case QUAD8:
202 : case QUADSHELL8:
203 : case QUAD9:
204 : case QUADSHELL9:
205 33146 : return per_edge * per_edge;
206 :
207 120373 : case HEX8:
208 : case HEX20:
209 : case HEX27:
210 120373 : return per_edge * per_edge * per_edge;
211 :
212 0 : default:
213 0 : libmesh_error_msg("The LAGRANGE_GLL basis is a tensor product. It does not support "
214 : << Utility::enum_to_string(t) << ".");
215 : }
216 : }
217 :
218 :
219 : /**
220 : * Evaluates a solution at the nodes of \p elem. Output writers use these nodal values.
221 : *
222 : * Each vertex coefficient is the value at its node. Above order two, the other interpolation
223 : * points are not nodes. Thus this function evaluates the basis at each node.
224 : */
225 0 : void lagrange_gll_nodal_soln(const Elem * elem,
226 : const Order order,
227 : const std::vector<Number> & elem_soln,
228 : std::vector<Number> & nodal_soln,
229 : const bool add_p_level)
230 : {
231 0 : const unsigned int n_nodes = elem->n_nodes();
232 :
233 0 : nodal_soln.resize(n_nodes);
234 :
235 0 : const FEType fe_type(order, LAGRANGE_GLL);
236 :
237 : const unsigned int n_sf =
238 0 : FEInterface::n_shape_functions(fe_type, elem, add_p_level);
239 :
240 0 : std::vector<Point> refspace_nodes;
241 0 : FEBase::get_refspace_nodes(elem->type(), refspace_nodes);
242 0 : libmesh_assert_equal_to (refspace_nodes.size(), n_nodes);
243 0 : libmesh_assert_equal_to (elem_soln.size(), n_sf);
244 :
245 0 : std::fill(nodal_soln.begin(), nodal_soln.end(), 0);
246 :
247 0 : for (const auto n : make_range(n_nodes))
248 0 : for (const auto i : make_range(n_sf))
249 0 : nodal_soln[n] += elem_soln[i] *
250 0 : FEInterface::shape(fe_type, elem, i, refspace_nodes[n], add_p_level);
251 0 : }
252 :
253 0 : LIBMESH_FE_NODAL_SOLN(LAGRANGE_GLL, lagrange_gll_nodal_soln)
254 0 : LIBMESH_FE_SIDE_NODAL_SOLN(LAGRANGE_GLL)
255 :
256 :
257 0 : template <> unsigned int FE<0,LAGRANGE_GLL>::n_dofs(const ElemType t, const Order o) { return lagrange_gll_n_dofs(t, o); }
258 0 : template <> unsigned int FE<1,LAGRANGE_GLL>::n_dofs(const ElemType t, const Order o) { return lagrange_gll_n_dofs(t, o); }
259 0 : template <> unsigned int FE<2,LAGRANGE_GLL>::n_dofs(const ElemType t, const Order o) { return lagrange_gll_n_dofs(t, o); }
260 0 : template <> unsigned int FE<3,LAGRANGE_GLL>::n_dofs(const ElemType t, const Order o) { return lagrange_gll_n_dofs(t, o); }
261 :
262 0 : template <> unsigned int FE<0,LAGRANGE_GLL>::n_dofs(const Elem * e, const Order o) { return lagrange_gll_n_dofs(e, o); }
263 5150 : template <> unsigned int FE<1,LAGRANGE_GLL>::n_dofs(const Elem * e, const Order o) { return lagrange_gll_n_dofs(e, o); }
264 40562 : template <> unsigned int FE<2,LAGRANGE_GLL>::n_dofs(const Elem * e, const Order o) { return lagrange_gll_n_dofs(e, o); }
265 209601 : template <> unsigned int FE<3,LAGRANGE_GLL>::n_dofs(const Elem * e, const Order o) { return lagrange_gll_n_dofs(e, o); }
266 :
267 0 : template <> unsigned int FE<0,LAGRANGE_GLL>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(t, o, n); }
268 15262 : template <> unsigned int FE<1,LAGRANGE_GLL>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(t, o, n); }
269 256113 : template <> unsigned int FE<2,LAGRANGE_GLL>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(t, o, n); }
270 2831336 : template <> unsigned int FE<3,LAGRANGE_GLL>::n_dofs_at_node(const ElemType t, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(t, o, n); }
271 :
272 0 : template <> unsigned int FE<0,LAGRANGE_GLL>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(e.type(), o, n); }
273 5733 : template <> unsigned int FE<1,LAGRANGE_GLL>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(e.type(), o, n); }
274 61918 : template <> unsigned int FE<2,LAGRANGE_GLL>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(e.type(), o, n); }
275 899925 : template <> unsigned int FE<3,LAGRANGE_GLL>::n_dofs_at_node(const Elem & e, const Order o, const unsigned int n) { return lagrange_gll_n_dofs_at_node(e.type(), o, n); }
276 :
277 0 : template <> unsigned int FE<0,LAGRANGE_GLL>::n_dofs_per_elem(const ElemType t, const Order o) { return lagrange_gll_n_dofs_per_elem(t, o); }
278 0 : template <> unsigned int FE<1,LAGRANGE_GLL>::n_dofs_per_elem(const ElemType t, const Order o) { return lagrange_gll_n_dofs_per_elem(t, o); }
279 0 : template <> unsigned int FE<2,LAGRANGE_GLL>::n_dofs_per_elem(const ElemType t, const Order o) { return lagrange_gll_n_dofs_per_elem(t, o); }
280 0 : template <> unsigned int FE<3,LAGRANGE_GLL>::n_dofs_per_elem(const ElemType t, const Order o) { return lagrange_gll_n_dofs_per_elem(t, o); }
281 :
282 0 : template <> unsigned int FE<0,LAGRANGE_GLL>::n_dofs_per_elem(const Elem & e, const Order o) { return lagrange_gll_n_dofs_per_elem(e.type(), o); }
283 7553 : template <> unsigned int FE<1,LAGRANGE_GLL>::n_dofs_per_elem(const Elem & e, const Order o) { return lagrange_gll_n_dofs_per_elem(e.type(), o); }
284 33146 : template <> unsigned int FE<2,LAGRANGE_GLL>::n_dofs_per_elem(const Elem & e, const Order o) { return lagrange_gll_n_dofs_per_elem(e.type(), o); }
285 120373 : template <> unsigned int FE<3,LAGRANGE_GLL>::n_dofs_per_elem(const Elem & e, const Order o) { return lagrange_gll_n_dofs_per_elem(e.type(), o); }
286 :
287 : // The basis is continuous across a shared entity, because the two elements put each
288 : // shared degree of freedom at the same point
289 0 : template <> FEContinuity FE<0,LAGRANGE_GLL>::get_continuity() const { return C_ZERO; }
290 23759 : template <> FEContinuity FE<1,LAGRANGE_GLL>::get_continuity() const { return C_ZERO; }
291 28505 : template <> FEContinuity FE<2,LAGRANGE_GLL>::get_continuity() const { return C_ZERO; }
292 40324 : template <> FEContinuity FE<3,LAGRANGE_GLL>::get_continuity() const { return C_ZERO; }
293 :
294 : // A nodal basis is not hierarchic
295 0 : template <> bool FE<0,LAGRANGE_GLL>::is_hierarchic() const { return false; }
296 60 : template <> bool FE<1,LAGRANGE_GLL>::is_hierarchic() const { return false; }
297 60 : template <> bool FE<2,LAGRANGE_GLL>::is_hierarchic() const { return false; }
298 48 : template <> bool FE<3,LAGRANGE_GLL>::is_hierarchic() const { return false; }
299 :
300 : // Each shape function depends on the orientation of the entity that owns it. Elements
301 : // with different orientations thus need new shape values.
302 0 : template <> bool FE<0,LAGRANGE_GLL>::shapes_need_reinit() const { return true; }
303 960 : template <> bool FE<1,LAGRANGE_GLL>::shapes_need_reinit() const { return true; }
304 4295 : template <> bool FE<2,LAGRANGE_GLL>::shapes_need_reinit() const { return true; }
305 20934 : template <> bool FE<3,LAGRANGE_GLL>::shapes_need_reinit() const { return true; }
306 :
307 : #ifdef LIBMESH_ENABLE_AMR
308 : template <>
309 0 : void FE<2,LAGRANGE_GLL>::compute_constraints (DofConstraints & constraints,
310 : DofMap & dof_map,
311 : const unsigned int variable_number,
312 : const Elem * elem)
313 0 : { compute_proj_constraints(constraints, dof_map, variable_number, elem); }
314 :
315 : template <>
316 0 : void FE<3,LAGRANGE_GLL>::compute_constraints (DofConstraints & constraints,
317 : DofMap & dof_map,
318 : const unsigned int variable_number,
319 : const Elem * elem)
320 0 : { compute_proj_constraints(constraints, dof_map, variable_number, elem); }
321 : #endif // LIBMESH_ENABLE_AMR
322 :
323 :
324 : } // namespace libMesh
|