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/libmesh_config.h"
22 :
23 : #ifdef LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
24 :
25 : #include "libmesh/elem.h"
26 : #include "libmesh/enum_to_string.h"
27 : #include "libmesh/fe.h"
28 : #include "libmesh/fe_interface.h"
29 : #include "libmesh/fe_macro.h"
30 :
31 : namespace libMesh
32 : {
33 :
34 : // ------------------------------------------------------------
35 : // Bernstein-specific implementations, Steffen Petersen 2005
36 :
37 : // Anonymous namespace for local helper functions
38 : namespace {
39 :
40 0 : void bernstein_nodal_soln(const Elem * elem,
41 : const Order order,
42 : const std::vector<Number> & elem_soln,
43 : std::vector<Number> & nodal_soln,
44 : const bool add_p_level)
45 : {
46 0 : const unsigned int n_nodes = elem->n_nodes();
47 :
48 0 : const ElemType elem_type = elem->type();
49 :
50 0 : nodal_soln.resize(n_nodes);
51 :
52 0 : const Order totalorder = order + add_p_level*elem->p_level();
53 :
54 : // FEType object to be passed to various FEInterface functions below.
55 0 : FEType fe_type(order, BERNSTEIN);
56 :
57 0 : switch (totalorder)
58 : {
59 : // Constant shape functions
60 0 : case CONSTANT:
61 : {
62 0 : libmesh_assert_equal_to (elem_soln.size(), 1);
63 :
64 0 : std::fill(nodal_soln.begin(), nodal_soln.end(), elem_soln[0]);
65 :
66 0 : return;
67 : }
68 :
69 :
70 : // For other bases do interpolation at the nodes
71 : // explicitly.
72 0 : case FIRST:
73 : case SECOND:
74 : case THIRD:
75 : case FOURTH:
76 : case FIFTH:
77 : case SIXTH:
78 : {
79 : const unsigned int n_sf =
80 0 : FEInterface::n_shape_functions(fe_type, elem);
81 :
82 0 : std::vector<Point> refspace_nodes;
83 0 : FEBase::get_refspace_nodes(elem_type,refspace_nodes);
84 0 : libmesh_assert_equal_to (refspace_nodes.size(), n_nodes);
85 0 : libmesh_assert_equal_to (elem_soln.size(), n_sf);
86 :
87 : // Zero before summation
88 0 : std::fill(nodal_soln.begin(), nodal_soln.end(), 0);
89 :
90 0 : for (unsigned int n=0; n<n_nodes; n++)
91 : // u_i = Sum (alpha_i phi_i)
92 0 : for (unsigned int i=0; i<n_sf; i++)
93 0 : nodal_soln[n] += elem_soln[i] *
94 0 : FEInterface::shape(fe_type, elem, i, refspace_nodes[n]);
95 :
96 0 : return;
97 : }
98 :
99 0 : default:
100 0 : libmesh_error_msg("ERROR: Invalid total order " << totalorder);
101 : }
102 : } // bernstein_nodal_soln()
103 :
104 :
105 :
106 31708656 : unsigned int BERNSTEIN_n_dofs(const ElemType t, const Order o)
107 : {
108 31708656 : switch (t)
109 : {
110 244365 : case NODEELEM:
111 244365 : return 1;
112 94562 : case EDGE2:
113 : case EDGE3:
114 : case EDGE4:
115 349288 : return (o+1);
116 9391 : case QUAD4:
117 : case QUADSHELL4:
118 9391 : libmesh_assert_less (o, 2);
119 : libmesh_fallthrough();
120 : case QUAD8:
121 : case QUADSHELL8:
122 : {
123 119344 : if (o == 1)
124 9391 : return 4;
125 82626 : else if (o == 2)
126 20658 : return 8;
127 : else
128 0 : libmesh_error_msg("ERROR: Invalid Order " << Utility::enum_to_string(o) << " selected for BERNSTEIN FE family!");
129 : }
130 5409169 : case QUAD9:
131 : case QUADSHELL9:
132 18621402 : return ((o+1)*(o+1));
133 831 : case QUAD16:
134 : {
135 2484 : if (o == 3)
136 831 : return 16;
137 : else
138 0 : libmesh_error_msg("ERROR: Invalid Order " << Utility::enum_to_string(o) << " selected for BERNSTEIN FE family!");
139 : }
140 :
141 279927 : case HEX8:
142 279927 : libmesh_assert_less (o, 2);
143 : libmesh_fallthrough();
144 : case HEX20:
145 : {
146 3771624 : if (o == 1)
147 279927 : return 8;
148 2653434 : else if (o == 2)
149 663360 : return 20;
150 : else
151 0 : libmesh_error_msg("ERROR: Invalid Order " << Utility::enum_to_string(o) << " selected for BERNSTEIN FE family!");
152 : }
153 1994023 : case HEX27:
154 8043134 : return ((o+1)*(o+1)*(o+1));
155 8769 : case TRI3:
156 : case TRISHELL3:
157 8769 : libmesh_assert_less (o, 2);
158 : libmesh_fallthrough();
159 : case TRI6:
160 : case TRI7:
161 243062 : return ((o+1)*(o+2)/2);
162 32044 : case TET4:
163 32044 : libmesh_assert_less (o, 2);
164 : libmesh_fallthrough();
165 : case TET10:
166 : case TET14:
167 41634 : libmesh_assert_less (o, 3);
168 157821 : return ((o+1)*(o+2)*(o+3)/6);
169 0 : case INVALID_ELEM:
170 0 : return 0;
171 0 : default:
172 0 : libmesh_error_msg("ERROR: Invalid ElemType " << Utility::enum_to_string(t) << " selected for BERNSTEIN FE family!");
173 : }
174 : } // BERNSTEIN_n_dofs()
175 :
176 :
177 :
178 23357468 : unsigned int BERNSTEIN_n_dofs(const Elem * e, const Order o)
179 : {
180 8829597 : libmesh_assert(e);
181 31708656 : return BERNSTEIN_n_dofs(e->type(), o);
182 : }
183 :
184 :
185 :
186 6843527 : unsigned int BERNSTEIN_n_dofs_at_node(const ElemType t,
187 : const Order o,
188 : const unsigned int n)
189 : {
190 6843527 : switch (t)
191 : {
192 184751 : case NODEELEM:
193 184751 : return 1;
194 :
195 10024 : case EDGE2:
196 : case EDGE3:
197 10024 : switch (n)
198 : {
199 1988 : case 0:
200 : case 1:
201 1988 : return 1;
202 672 : case 2:
203 672 : libmesh_assert (o>1);
204 2576 : return (o-1);
205 0 : default:
206 0 : libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for EDGE2/3!");
207 : }
208 2492 : case EDGE4:
209 2492 : switch (n)
210 : {
211 350 : case 0:
212 : case 1:
213 350 : return 1;
214 154 : case 2:
215 154 : libmesh_assert (o>2);
216 588 : return (o-1)/2; // floor
217 588 : case 3:
218 154 : libmesh_assert (o>2);
219 588 : return o/2; // "ceiling", add extra DoFs here first
220 0 : default:
221 0 : libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for EDGE4!");
222 : }
223 78344 : case TRI3:
224 2464 : libmesh_assert_less (n, 3);
225 2464 : libmesh_assert_less (o, 2);
226 : libmesh_fallthrough();
227 : case TRI6:
228 : // Internal DoFs are associated with the elem on a Tri6, or node 6 on a Tri7
229 14770 : libmesh_assert_less (n, 6);
230 : libmesh_fallthrough();
231 : case TRI7:
232 104958 : switch (n)
233 : {
234 15316 : case 0:
235 : case 1:
236 : case 2:
237 15316 : return 1;
238 :
239 11760 : case 3:
240 : case 4:
241 : case 5:
242 42672 : return (o-1);
243 :
244 2002 : case 6:
245 7294 : return ((o-1)*(o-2)/2);
246 0 : default:
247 0 : libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for TRI!");
248 : }
249 3568533 : case QUAD4:
250 1596 : libmesh_assert_less (n, 4);
251 1596 : libmesh_assert_less (o, 2);
252 : libmesh_fallthrough();
253 : case QUAD8:
254 1596 : libmesh_assert_less (n, 8);
255 1596 : libmesh_assert_less (o, 3);
256 : libmesh_fallthrough();
257 : case QUAD9:
258 : {
259 4923425 : switch (n)
260 : {
261 611896 : case 0:
262 : case 1:
263 : case 2:
264 : case 3:
265 611896 : return 1;
266 :
267 595484 : case 4:
268 : case 5:
269 : case 6:
270 : case 7:
271 2161947 : return (o-1);
272 :
273 149108 : case 8:
274 541451 : return ((o-1)*(o-1));
275 :
276 0 : default:
277 0 : libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for QUAD9!");
278 : }
279 : }
280 : // only some orders make sense for o > 3. Just avoiding that for now.
281 5978 : case QUAD16:
282 5978 : libmesh_assert_less (n, 16);
283 5978 : libmesh_assert_equal_to (o, 3);
284 5978 : return 1;
285 :
286 460724 : case HEX8:
287 4956 : libmesh_assert_less (n, 8);
288 4956 : libmesh_assert_less (o, 2);
289 : libmesh_fallthrough();
290 : case HEX20:
291 4956 : libmesh_assert_less (n, 20);
292 4956 : libmesh_assert_less (o, 3);
293 : libmesh_fallthrough();
294 : case HEX27:
295 599756 : switch (n)
296 : {
297 46948 : case 0:
298 : case 1:
299 : case 2:
300 : case 3:
301 : case 4:
302 : case 5:
303 : case 6:
304 : case 7:
305 46948 : return 1;
306 :
307 61224 : case 8:
308 : case 9:
309 : case 10:
310 : case 11:
311 : case 12:
312 : case 13:
313 : case 14:
314 : case 15:
315 : case 16:
316 : case 17:
317 : case 18:
318 : case 19:
319 255904 : return (o-1);
320 :
321 30648 : case 20:
322 : case 21:
323 : case 22:
324 : case 23:
325 : case 24:
326 : case 25:
327 128104 : return ((o-1)*(o-1));
328 :
329 5168 : case 26:
330 21604 : return ((o-1)*(o-1)*(o-1));
331 :
332 0 : default:
333 0 : libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for HEX27!");
334 : }
335 390852 : case TET4:
336 21588 : libmesh_assert_less (n, 4);
337 21588 : libmesh_assert_less (o, 2);
338 : libmesh_fallthrough();
339 : case TET10:
340 72114 : libmesh_assert_less (n, 10);
341 : libmesh_fallthrough();
342 : case TET14:
343 142744 : libmesh_assert_less (o, 3);
344 369264 : switch (n)
345 : {
346 65352 : case 0:
347 : case 1:
348 : case 2:
349 : case 3:
350 65352 : return 1;
351 :
352 57288 : case 4:
353 : case 5:
354 : case 6:
355 : case 7:
356 : case 8:
357 : case 9:
358 206976 : return (o-1);
359 :
360 20104 : case 10:
361 : case 11:
362 : case 12:
363 : case 13:
364 20104 : return 0;
365 :
366 0 : default:
367 0 : libmesh_error_msg("ERROR: Invalid node ID " << n << " selected for TET4/10/14!");
368 : }
369 0 : case INVALID_ELEM:
370 0 : return 0;
371 0 : default:
372 0 : libmesh_error_msg("ERROR: Invalid ElemType " << Utility::enum_to_string(t) << " selected for BERNSTEIN FE family!");
373 : }
374 : } // BERNSTEIN_n_dofs_at_node()
375 :
376 :
377 :
378 480793 : unsigned int BERNSTEIN_n_dofs_at_node(const Elem & e,
379 : const Order o,
380 : const unsigned int n)
381 : {
382 656629 : return BERNSTEIN_n_dofs_at_node(e.type(), o, n);
383 : }
384 :
385 :
386 :
387 1273151 : unsigned int BERNSTEIN_n_dofs_per_elem(const ElemType t, const Order o)
388 : {
389 921962 : switch (t)
390 : {
391 180939 : case NODEELEM:
392 : case EDGE2:
393 : case EDGE3:
394 : case EDGE4:
395 180939 : return 0;
396 1414 : case TRI3:
397 : case TRISHELL3:
398 : case QUAD4:
399 : case QUADSHELL4:
400 : case QUAD16:
401 1414 : return 0;
402 1750 : case TRI6:
403 6328 : return ((o-1)*(o-2)/2);
404 1750 : case TRI7:
405 1750 : return 0;
406 0 : case QUAD8:
407 : case QUADSHELL8:
408 0 : if (o <= 2)
409 0 : return 0;
410 : libmesh_fallthrough();
411 : case QUAD9:
412 : case QUADSHELL9:
413 147944 : return 0;
414 588 : case HEX8:
415 588 : libmesh_assert_less (o, 2);
416 588 : return 0;
417 0 : case HEX20:
418 0 : libmesh_assert_less (o, 3);
419 0 : return 0;
420 3980 : case HEX27:
421 3980 : return 0;
422 4508 : case TET4:
423 4508 : libmesh_assert_less (o, 2);
424 : libmesh_fallthrough();
425 : case TET10:
426 : case TET14:
427 12824 : libmesh_assert_less (o, 3);
428 12824 : return 0;
429 0 : case INVALID_ELEM:
430 0 : return 0;
431 0 : default:
432 0 : libmesh_error_msg("ERROR: Invalid ElemType " << Utility::enum_to_string(t) << " selected for BERNSTEIN FE family!");
433 : }
434 : } // BERNSTEIN_n_dofs_per_elem
435 :
436 :
437 :
438 921962 : unsigned int BERNSTEIN_n_dofs_per_elem(const Elem & e, const Order o)
439 : {
440 1273151 : return BERNSTEIN_n_dofs_per_elem(e.type(), o);
441 : }
442 :
443 : } // anonymous namespace
444 :
445 :
446 : // Instantiate (side_) nodal_soln() function for every dimension
447 0 : LIBMESH_FE_NODAL_SOLN(BERNSTEIN, bernstein_nodal_soln)
448 0 : LIBMESH_FE_SIDE_NODAL_SOLN(BERNSTEIN)
449 :
450 : // Instantiate n_dofs*() functions for every dimension
451 39825334 : LIBMESH_DEFAULT_NDOFS(BERNSTEIN)
452 :
453 : // Bernstein FEMs are C^0 continuous
454 0 : template <> FEContinuity FE<0,BERNSTEIN>::get_continuity() const { return C_ZERO; }
455 2694 : template <> FEContinuity FE<1,BERNSTEIN>::get_continuity() const { return C_ZERO; }
456 10513 : template <> FEContinuity FE<2,BERNSTEIN>::get_continuity() const { return C_ZERO; }
457 17523 : template <> FEContinuity FE<3,BERNSTEIN>::get_continuity() const { return C_ZERO; }
458 :
459 : // Bernstein FEMs are not hierarchic
460 0 : template <> bool FE<0,BERNSTEIN>::is_hierarchic() const { return false; }
461 20 : template <> bool FE<1,BERNSTEIN>::is_hierarchic() const { return false; }
462 69 : template <> bool FE<2,BERNSTEIN>::is_hierarchic() const { return false; }
463 37 : template <> bool FE<3,BERNSTEIN>::is_hierarchic() const { return false; }
464 :
465 : #ifdef LIBMESH_ENABLE_AMR
466 : // compute_constraints() specializations are only needed for 2 and 3D
467 : template <>
468 1064 : void FE<2,BERNSTEIN>::compute_constraints (DofConstraints & constraints,
469 : DofMap & dof_map,
470 : const unsigned int variable_number,
471 : const Elem * elem)
472 1064 : { compute_proj_constraints(constraints, dof_map, variable_number, elem); }
473 :
474 : template <>
475 4256 : void FE<3,BERNSTEIN>::compute_constraints (DofConstraints & constraints,
476 : DofMap & dof_map,
477 : const unsigned int variable_number,
478 : const Elem * elem)
479 4256 : { compute_proj_constraints(constraints, dof_map, variable_number, elem); }
480 : #endif // #ifdef LIBMESH_ENABLE_AMR
481 :
482 : // Bernstein shapes need reinit only for approximation orders >= 3,
483 : // but we might reach that with p refinement
484 0 : template <> bool FE<0,BERNSTEIN>::shapes_need_reinit() const { return true; }
485 284 : template <> bool FE<1,BERNSTEIN>::shapes_need_reinit() const { return true; }
486 2951 : template <> bool FE<2,BERNSTEIN>::shapes_need_reinit() const { return true; }
487 9379 : template <> bool FE<3,BERNSTEIN>::shapes_need_reinit() const { return true; }
488 :
489 : } // namespace libMesh
490 :
491 : #endif //LIBMESH_ENABLE_HIGHER_ORDER_SHAPES
|