Debian Codegraph @

include/deal.II/grid/reference_cell.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2020 - 2025 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // Part of the source code is dual licensed under Apache-2.0 WITH
9 // LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10 // governing the source code and code contributions can be found in
11 // LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12 //
13 // ------------------------------------------------------------------------
14
15 #ifndef dealii_tria_reference_cell_h
16 #define dealii_tria_reference_cell_h
17
18 #include <deal.II/base/config.h>
19
20 #include <deal.II/base/array_view.h>
21 #include <deal.II/base/geometry_info.h>
22 #include <deal.II/base/ndarray.h>
23 #include <deal.II/base/point.h>
24 #include <deal.II/base/tensor.h>
25 #include <deal.II/base/types.h>
26 #include <deal.II/base/utilities.h>
27
28 #include <deal.II/grid/tria_orientation.h>
29
30 #include <boost/container/small_vector.hpp>
31
32 #include <iosfwd>
33 #include <string>
34
35 DEAL_II_NAMESPACE_OPEN
36
37 // Forward declarations
38 #ifndef DOXYGEN
39 template <int dim, int spacedim>
40 class Mapping;
41
42 template <int dim>
43 class Quadrature;
44
45 class ReferenceCell;
46 #endif
47
48
49 namespace internal
50 {
51 /**
52 * A helper function to create a ReferenceCell object from an integer.
53 * ReferenceCell objects are "singletons" (actually, "multitons" -- there are
54 * multiple, but they are only a handful and these are all that can be used).
55 * What is then necessary is to have a way to create these with their internal
56 * id to distinguish the few possible ones in existence. We could do this via
57 * a public constructor of ReferenceCell, but that would allow users to create
58 * ones outside the range we envision, and we don't want to do that. Rather,
59 * the constructor that takes an integer is made `private` but we have this
60 * one function in an internal namespace that is a friend of the class and can
61 * be used to create the objects.
62 */
63 constexpr ReferenceCell
64 make_reference_cell_from_int(const std::uint8_t kind);
65 } // namespace internal
66
67
68
69 /**
70 * Enum of different choices for istropic refinement.
71 * There are 3 different ways to refine a tetrahedral, here we save the
72 * different possibilities. It is different to RefinementPossibilities are these
73 * are options in the case that an isotropic refinement is conducted.
74 */
75 enum class IsotropicRefinementChoice : std::uint8_t
76 {
77 /**
78 * Decide where to perform a cut based on the shortest edge length.
79 */
80 isotropic_refinement = 0,
81 /**
82 * Perform a cut in the along the edge (6,8).
83 */
84 cut_tet_68 = 1,
85 /**
86 * Perform a cut in the along the edge (5,7).
87 */
88 cut_tet_57 = 2,
89 /**
90 * Perform a cut in the along the edge (4,9).
91 */
92 cut_tet_49 = 3,
93 };
94
95
96
97 /**
98 * A type that describes the kinds of reference cells that can be
99 * used. This includes quadrilaterals and hexahedra (i.e.,
100 * "hypercubes"), triangles and tetrahedra (simplices), and the
101 * pyramids and wedges necessary when using mixed 3d meshes. This
102 * class then describes geometric, topological, and other kinds of
103 * information about these kinds of reference cells. This includes how
104 * many vertices or faces a certain kind of reference cell has
105 * (topological information), where these vertices lie, what the
106 * cell's volume or center of mass is (geometric information), and how
107 * to output these cells in various output formats or what appropriate
108 * quadrature rules are. The documentation of this class is separated
109 * into a number of sections to group the many member functions into
110 * different categories such as those mentioned above.
111 *
112 * Objects of this type should not be created in user code, and as a
113 * consequence the class does not have a user-accessible constructor
114 * other than the default constructor (which creates an invalid object).
115 * Rather, there is a finite number of specific reference cell objects
116 * defined in the ReferenceCells namespace that completely enumerate
117 * all of the possible values. User codes should therefore rely
118 * exclusively on assigning ReferenceCell objects from these special
119 * objects, and comparing against those special objects.
120 *
121 * The purposes and intents of this class are described in the
122 * @ref GlossReferenceCell "reference cell"
123 * glossary entry.
124 *
125 * @ingroup grid geomprimitives reordering
126 */
127 class ReferenceCell
128 {
129 public:
130 /**
131 * Return the correct ReferenceCell for a given structural
132 * dimension and number of vertices. For example, if `dim==2` and
133 * `n_vertices==4`, this function will return ReferenceCells::Quadrilateral.
134 * But if `dim==3` and `n_vertices==4`, it will return
135 * ReferenceCells::Tetrahedron.
136 */
137 static ReferenceCell
138 n_vertices_to_type(const int dim, const unsigned int n_vertices);
139
140 /**
141 * Default constructor. Initialize this object as an invalid object. The
142 * end result is that the current object equals ReferenceCells::Invalid.
143 *
144 * Generally, ReferenceCell objects are created by assignment from
145 * the special objects in namespace ReferenceCells, which is the only
146 * way to obtain a valid object.
147 */
148 constexpr ReferenceCell();
149
150 /**
151 * @name Querying information about the kind of reference cells
152 * @{
153 */
154
155 /**
156 * Return `true` if the object is a ReferenceCells::Vertex,
157 * ReferenceCells::Line, ReferenceCells::Quadrilateral, or
158 * ReferenceCells::Hexahedron.
159 */
160 bool
161 is_hyper_cube() const;
162
163 /**
164 * Return true if the object is a Vertex, Line, Triangle, or Tetrahedron.
165 */
166 bool
167 is_simplex() const;
168
169 /**
170 * Return the dimension of the reference cell represented by the current
171 * object.
172 */
173 unsigned int
174 get_dimension() const;
175
176 /**
177 * @}
178 */
179
180 /**
181 * @name Shape functions, mappings, quadratures defined on a reference cell
182 * @{
183 */
184
185 /**
186 * Compute the value of the $i$-th linear shape function at location $\xi$
187 * for the current reference-cell type.
188 *
189 * @pre The template argument `dim` must equal the dimension
190 * of the space in which the reference cell you are querying
191 * lives (i.e., it must equal the result of get_dimension()).
192 *
193 * For ReferenceCells::Vertex, the reference cell is a zero-dimensional point
194 * in a zero-dimensional space: i.e., asking about the value of a polynomial
195 * doesn't make sense since there cannot be any independent variables. To
196 * enable dimension-independent programming we define the zero-dimensional
197 * value to be 1.
198 */
199 template <int dim>
200 double
201 d_linear_shape_function(const Point<dim> &xi, const unsigned int i) const;
202
203 /**
204 * Compute the gradient of the $i$-th linear shape function at location
205 * $\xi$ for the current reference-cell type.
206 *
207 * @pre The template argument `dim` must equal the dimension
208 * of the space in which the reference cell you are querying
209 * lives (i.e., it must equal the result of get_dimension()).
210 */
211 template <int dim>
212 Tensor<1, dim>
213 d_linear_shape_function_gradient(const Point<dim> &xi,
214 const unsigned int i) const;
215
216 /**
217 * Return a default mapping of degree @p degree matching the current
218 * reference cell. If this reference cell is a hypercube, then the returned
219 * mapping is a MappingQ; otherwise, it is an object of type
220 * MappingFE initialized with FE_SimplexP (if the reference cell is a
221 * triangle or tetrahedron), with FE_PyramidP (if the reference
222 * cell is a pyramid), or with FE_WedgeP (if the reference cell is
223 * a wedge).
224 */
225 template <int dim, int spacedim = dim>
226 std::unique_ptr<Mapping<dim, spacedim>>
227 get_default_mapping(const unsigned int degree) const;
228
229 /**
230 * Return a default linear mapping matching the current reference cell.
231 * If this reference cell is a hypercube, then the returned mapping
232 * is a MappingQ1; otherwise, it is an object of type MappingFE
233 * initialized with FE_SimplexP (if the reference cell is a triangle or
234 * tetrahedron), with FE_PyramidP (if the reference cell is a
235 * pyramid), or with FE_WedgeP (if the reference cell is a wedge).
236 * In other words, the term "linear" in the name of the function has to be
237 * understood as $d$-linear (i.e., bilinear or trilinear) for some of the
238 * coordinate directions.
239 */
240 template <int dim, int spacedim = dim>
241 const Mapping<dim, spacedim> &
242 get_default_linear_mapping() const;
243
244 /**
245 * Return a Gauss-type quadrature matching the given reference cell (QGauss,
246 * QGaussSimplex, QGaussPyramid, QGaussWedge).
247 *
248 * @param[in] n_points_1d The number of quadrature points in each direction
249 * (QGauss) or an indication of what polynomial degree needs to be
250 * integrated exactly for the other types.
251 *
252 * @pre The template argument `dim` must equal the dimension
253 * of the space in which the reference cell you are querying
254 * lives (i.e., it must equal the result of get_dimension()).
255 */
256 template <int dim>
257 Quadrature<dim>
258 get_gauss_type_quadrature(const unsigned n_points_1d) const;
259
260 /**
261 * Return a quadrature object that has a single quadrature point at the
262 * barycenter of the cell with quadrature weight equal to the volume of the
263 * reference cell. This quadrature formula is exact for integrals of constant
264 * and linear integrands.
265 *
266 * The object returned by this function generalizes what the QMidpoint class
267 * represents to other reference cells.
268 *
269 * @pre The template argument `dim` must equal the dimension
270 * of the space in which the reference cell you are querying
271 * lives (i.e., it must equal the result of get_dimension()).
272 */
273 template <int dim>
274 Quadrature<dim>
275 get_midpoint_quadrature() const;
276
277 /**
278 * Return a quadrature rule whose quadrature points are the vertices of the
279 * given reference cell. For 1d line segments, this corresponds to the
280 * quadrature points of the trapezoidal rule, which by taking tensor products
281 * easily generalizes also to other hypercube elements (see also QTrapezoid).
282 * For all reference cell shapes, the quadrature points are ordered
283 * in the same order as the vertices of the reference cell.
284 *
285 * @note The weights of the quadrature object are left unfilled and
286 * consequently the object cannot usefully be used for actually
287 * computing integrals. This is in contrast to, for example, the QTrapezoid
288 * class that correctly sets quadrature weights.
289 *
290 * @pre The template argument `dim` must equal the dimension
291 * of the space in which the reference cell you are querying
292 * lives (i.e., it must equal the result of get_dimension()).
293 */
294 template <int dim>
295 const Quadrature<dim> &
296 get_nodal_type_quadrature() const;
297
298 /**
299 * @}
300 */
301
302 /**
303 * @name Querying the number of building blocks of a reference cell
304 * @{
305 */
306
307 /**
308 * Return the number of vertices that make up the reference
309 * cell in question. A vertex is a "corner" (a zero-dimensional
310 * object) of the reference cell.
311 */
312 unsigned int
313 n_vertices() const;
314
315 /**
316 * Return an object that can be thought of as an array containing all
317 * indices from zero to n_vertices().
318 */
319 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
320 vertex_indices() const;
321
322 /**
323 * Return the location of the `v`th vertex of the reference
324 * cell that corresponds to the current object.
325 *
326 * Because the ReferenceCell class does not have a `dim` argument,
327 * it has to be explicitly specified in the call to this function.
328 *
329 * @pre The template argument `dim` must equal the dimension
330 * of the space in which the reference cell you are querying
331 * lives (i.e., it must equal the result of get_dimension()).
332 */
333 template <int dim>
334 Point<dim>
335 vertex(const unsigned int v) const;
336
337 /**
338 * Return the number of lines that make up the reference
339 * cell in question. A line is an "edge" (a one-dimensional
340 * object) of the reference cell.
341 */
342 unsigned int
343 n_lines() const;
344
345 /**
346 * Return an object that can be thought of as an array containing all
347 * indices from zero to n_lines().
348 */
349 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
350 line_indices() const;
351
352 /**
353 * Return the number of faces that make up the reference
354 * cell in question. A face is a `(dim-1)`-dimensional
355 * object bounding the reference cell.
356 */
357 unsigned int
358 n_faces() const;
359
360 /**
361 * Return an object that can be thought of as an array containing all
362 * indices from zero to n_faces().
363 */
364 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
365 face_indices() const;
366
367 /**
368 * Return the number of refinement directions of the cell.
369 */
370 unsigned int
371 n_isotropic_refinement_choices() const;
372
373 /**
374 * Return the refinement possibility @p ref_choice.
375 */
376 IsotropicRefinementChoice
377 get_isotropic_refinement_choice(const unsigned int ref_choice) const;
378
379 /**
380 * Return the number of cells one would get by isotropically
381 * refining the current cell. Here, "isotropic refinement"
382 * means that we subdivide in each "direction" of a cell.
383 * For example, a square would be refined into four children
384 * by introducing new vertices along each edge and a new
385 * vertex in the cell center. For triangles, one would introduce
386 * new vertices at the center of each edge, and connect them to
387 * obtain four children. Similar constructions can be done for
388 * the other reference cell types.
389 */
390 unsigned int
391 n_isotropic_children() const;
392
393 /**
394 * Return the number of cells one would get by refining the
395 * current cell with the given refinement case.
396 *
397 * @pre The template argument `dim` must equal the dimension
398 * of the space in which the reference cell you are querying
399 * lives (i.e., it must equal the result of get_dimension()).
400 */
401 template <int dim>
402 unsigned int
403 n_children(const RefinementCase<dim> ref_case =
404 RefinementCase<dim>::isotropic_refinement) const;
405
406 /**
407 * Return an object that can be thought of as an array containing all
408 * indices from zero to n_isotropic_children().
409 */
410 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
411 isotropic_child_indices() const;
412
413 /**
414 * Convert an internal::SubfaceCase into its equivalent RefinementCase. For
415 * example, SubfacePossibilities<3>::Possibilities::y1x2x is is geometrically
416 * equivalent to RefinementPossibilities<3>::cut_xy.
417 */
418 template <int dim>
419 std::pair<unsigned int, RefinementCase<dim - 1>>
420 equivalent_refinement_case(
421 const types::geometric_orientation combined_face_orientation,
422 const internal::SubfaceCase<dim> subface_case,
423 const unsigned int subface_no) const;
424
425 /**
426 * Return the reference-cell type of face @p face_no of the current
427 * object. For example, if the current object is
428 * ReferenceCells::Tetrahedron, then `face_no` must be between
429 * in the interval $[0,4)$ and the function will always return
430 * ReferenceCells::Triangle. If the current object is
431 * ReferenceCells::Hexahedron, then `face_no` must be between
432 * in the interval $[0,6)$ and the function will always return
433 * ReferenceCells::Quadrilateral. For wedges and pyramids, the
434 * returned object may be either ReferenceCells::Triangle or
435 * ReferenceCells::Quadrilateral, depending on the given index.
436 */
437 ReferenceCell
438 face_reference_cell(const unsigned int face_no) const;
439
440 /**
441 * @}
442 */
443
444 /**
445 * @name Relationships between objects in the cell and on faces
446 * @{
447 */
448
449 /**
450 * Return the default combined face orientation flag (i.e., the default set of
451 * orientations, defined by orientation, rotate, and flip for a face in 3d).
452 *
453 * @deprecated Use numbers::default_geometric_orientation instead.
454 */
455 DEAL_II_DEPRECATED_EARLY_WITH_COMMENT(
456 "Use numbers::default_geometric_orientation instead.")
457 static constexpr types::geometric_orientation
458 default_combined_face_orientation();
459
460 /**
461 * Return the reversed (non-default orientation) line orientation flag. As
462 * lines only have two possible orientations, this function and
463 * ReferenceCell::default_combined_face_orientation() encode all of its
464 * possible orientation states.
465 *
466 * @deprecated Use numbers::reverse_line_orientation instead.
467 */
468 DEAL_II_DEPRECATED_EARLY_WITH_COMMENT(
469 "Use numbers::reverse_line_orientation instead.")
470 static constexpr types::geometric_orientation
471 reversed_combined_line_orientation();
472
473 /**
474 * Return which child cells are adjacent to a certain face of the
475 * parent cell.
476 *
477 * @deprecated Use the version of this function which takes the orientation as
478 * the third parameter instead.
479 */
480 DEAL_II_DEPRECATED_EARLY_WITH_COMMENT(
481 "Use the version of this function which takes the orientation as the third "
482 "parameter instead.")
483 unsigned int
484 child_cell_on_face(const unsigned int face, const unsigned int subface) const;
485
486 /**
487 * Return which child cells are adjacent to a certain face of the
488 * parent cell.
489 *
490 * For example, in 2d the layout of a quadrilateral cell is as follows:
491 * @verbatim
492 * 3
493 * 2-->--3
494 * | |
495 * 0 ^ ^ 1
496 * | |
497 * 0-->--1
498 * 2
499 * @endverbatim
500 * Vertices and faces are indicated with their numbers, faces also with
501 * their directions.
502 *
503 * Now, when refined, the layout is like this:
504 * @verbatim
505 * *---*---*
506 * | 2 | 3 |
507 * *---*---*
508 * | 0 | 1 |
509 * *---*---*
510 * @endverbatim
511 *
512 * Thus, the child cells on face 0 are (ordered in the direction of the
513 * face) 0 and 2, on face 3 they are 2 and 3, etc.
514 *
515 * For three spatial dimensions, the exact order of the children is laid
516 * down in the general documentation of this class.
517 *
518 * The <tt>face_orientation</tt> argument is meant exclusively for
519 * quadrilaterals and hexahedra at the moment. It determines how this function
520 * handles faces oriented in the standard and non-standard orientation. It
521 * represents a bit-code for the overall <tt>face_orientation</tt>,
522 * <tt>face_flip</tt> and <tt>face_rotation</tt> and defaults to the standard
523 * orientation. The concept of combined orientations is explained in this
524 * @ref GlossCombinedOrientation "glossary" entry.
525 */
526 unsigned int
527 child_cell_on_face(
528 const unsigned int face,
529 const unsigned int subface,
530 const types::geometric_orientation combined_orientation) const;
531
532 /**
533 * For a given vertex in a cell, return a pair of a face index and a
534 * vertex index within this face.
535 *
536 * @note In practice, a vertex is of course generally part of more than one
537 * face, and one could return different faces and the corresponding
538 * index within. Which face this function chooses is often not of
539 * importance (and not exposed by this function on purpose).
540 */
541 std::array<unsigned int, 2>
542 standard_vertex_to_face_and_vertex_index(const unsigned int vertex) const;
543
544 /**
545 * For a given line in a cell, return a pair of a face index and a
546 * line index within this face.
547 *
548 * @note In practice, a line is of course generally part of more than one
549 * face, and one could return different faces and the corresponding
550 * index within. Which face this function chooses is often not of
551 * importance (and not exposed by this function on purpose).
552 */
553 std::array<unsigned int, 2>
554 standard_line_to_face_and_line_index(const unsigned int line) const;
555
556 /**
557 * Map line vertex number to cell vertex number, i.e., return the cell vertex
558 * number of the <tt>vertex</tt>th vertex of line <tt>line</tt>.
559 *
560 * The order of the lines, as well as their direction (which in turn
561 * determines which vertices are first and second on a line) is the canonical
562 * one in deal.II, as described in the general documentation of this class.
563 */
564 unsigned int
565 line_to_cell_vertices(const unsigned int line,
566 const unsigned int vertex) const;
567
568 /**
569 * Map face line number to cell line number.
570 */
571 unsigned int
572 face_to_cell_lines(const unsigned int face,
573 const unsigned int line,
574 const types::geometric_orientation face_orientation) const;
575
576 /**
577 * Map face vertex number to cell vertex number.
578 */
579 unsigned int
580 face_to_cell_vertices(
581 const unsigned int face,
582 const unsigned int vertex,
583 const types::geometric_orientation face_orientation) const;
584
585 /**
586 * For a given face, in standard orientation, return the location of one
587 * of its vertices in the ambient space of the cell. For example, for a
588 * square or triangular 2d cell, the zeroth vertex of its zeroth face
589 * is located at $(0,0)$ -- a location in 2d space.
590 *
591 * @param[in] face The number of face. This number must be between zero
592 * and `n_faces()`.
593 * @param[in] vertex The number of the vertex within the face. This number
594 * must be between zero and `face_reference_cell(face).n_vertices()`.
595 * @return The location of the vertex so identified in `dim`-dimensional
596 * space.
597 *
598 * @pre The template argument `dim` must equal the dimension
599 * of the space in which the reference cell you are querying
600 * lives (i.e., it must equal the result of get_dimension()).
601 *
602 * @post The output of calling `reference_cell.face_vertex_location<dim>(f,v)`
603 * is identical to calling
604 * `reference_cell.vertex<dim>(
605 * reference_cell.face_to_cell_vertices(
606 f, v, numbers::default_geometric_orientation))`.
607 */
608 template <int dim>
609 Point<dim>
610 face_vertex_location(const unsigned int face,
611 const unsigned int vertex) const;
612
613 /**
614 * Correct vertex index depending on face orientation.
615 */
616 unsigned int
617 standard_to_real_face_vertex(
618 const unsigned int vertex,
619 const unsigned int face,
620 const types::geometric_orientation face_orientation) const;
621
622 /**
623 * Correct line index depending on face orientation.
624 */
625 unsigned int
626 standard_to_real_face_line(
627 const unsigned int line,
628 const unsigned int face,
629 const types::geometric_orientation face_orientation) const;
630
631 /**
632 * Return whether the line with index @p line is oriented in standard
633 * direction within a cell, given the @p face_orientation of the face within
634 * the current cell, and @p line_orientation for the line within that face.
635 *
636 * @deprecated Use face_to_cell_line_orientation() instead.
637 */
638 DEAL_II_DEPRECATED_EARLY_WITH_COMMENT(
639 "Use face_to_cell_line_orientation() instead.")
640 types::geometric_orientation
641 standard_vs_true_line_orientation(
642 const unsigned int line,
643 const unsigned int face,
644 const types::geometric_orientation face_orientation,
645 const types::geometric_orientation line_orientation) const;
646
647 /**
648 * @brief Convert a line orientation defined relative to a face to the
649 * canonical per-cell line orientation.
650 *
651 * Line orientations are used in both face and line contexts. Since a line is
652 * always shared by two faces, it may need to be reversed (relative to the
653 * first face) on the second face to guarantee that the per-face lines always
654 * point in their canonical directions (e.g., so that lines 0 and 1 of a
655 * quadrilateral point up and lines 2 and 3 point right) and that the vertex
656 * ordering on that line remains correct.
657 *
658 * To achieve this, this function computes the per-cell line orientation based
659 * on the face's number, orientation and line number.
660 *
661 * @param[in] face_line_no The index of the line on the face.
662 *
663 * @param[in] face_no The number of the face.
664 *
665 * @param[in] face_orientation The orientation of the face.
666 *
667 * @param[in] line_orientation The orientation of the line on the given face.
668 */
669 types::geometric_orientation
670 face_to_cell_line_orientation(
671 const unsigned int face_line_no,
672 const unsigned int face_no,
673 const types::geometric_orientation face_orientation,
674 const types::geometric_orientation line_orientation) const;
675
676 /**
677 * @}
678 */
679
680 /**
681 * @name Geometric properties of reference cells
682 * @name Querying the number of building blocks of a reference cell
683 * @{
684 */
685
686 /**
687 * Return the $d$-dimensional volume of the reference cell that corresponds
688 * to the current object, where $d$ is the dimension of the space it lives
689 * in. For example, since the quadrilateral reference cell is $[0,1]^2$,
690 * its volume is one, whereas the volume of the reference triangle is
691 * 0.5 because it occupies the area $\{0 \le x,y \le 1, x+y\le 1\}$.
692 *
693 * For ReferenceCells::Vertex, the reference cell is a zero-dimensional
694 * point in a zero-dimensional space. As a consequence, one cannot
695 * meaningfully define a volume for it. The function returns one for
696 * this case, because this makes it possible to define useful quadrature
697 * rules based on the center of a reference cell and its volume.
698 */
699 double
700 volume() const;
701
702 /**
703 * Return the $d - 1$-dimensional measure of the face of a reference cell that
704 * corresponds to the current object, where $d$ is the dimension of the space
705 * it lives in.
706 *
707 * In this context the measure of a face depends on both the type of reference
708 * cell as well as the face number (i.e., `*this` and @p face_no). For
709 * example, the measures of the sides of a ReferenceCells::Triangle are $1$,
710 * $\sqrt{2}$, and $1$, respectively, whereas the measures of the sides of a
711 * ReferenceCells::Quadrilateral are all $1$.
712 *
713 * @note Like ReferenceCell::volume(), this function defines vertices to have
714 * a measure of $1$ to enable the definition of one-dimensional face
715 * quadratures.
716 */
717 double
718 face_measure(const unsigned int face_no) const;
719
720 /**
721 * Return the barycenter (i.e., the center of mass) of the reference
722 * cell that corresponds to the current object. The function is not
723 * called `center()` because one can define the center of an object
724 * in a number of different ways whereas the barycenter of a
725 * reference cell $K$ is unambiguously defined as
726 * @f[
727 * \mathbf x_K = \frac{1}{V} \int_K \mathbf x \; dx
728 * @f]
729 * where $V$ is the volume of the reference cell (see also the volume()
730 * function).
731 *
732 * @pre The template argument `dim` must equal the dimension
733 * of the space in which the reference cell you are querying
734 * lives (i.e., it must equal the result of get_dimension()).
735 */
736 template <int dim>
737 Point<dim>
738 barycenter() const;
739
740 /**
741 * Return true if the given point is inside the reference cell of the present
742 * space dimension up to some tolerance. This function accepts an additional
743 * parameter (which defaults to zero) which specifies by how much the point
744 * position may actually be outside the true reference cell. This is useful
745 * because in practice we may often not be able to compute the coordinates of
746 * a point in reference coordinates exactly, but only up to numerical
747 * roundoff. For example, strictly speaking one would expect that for points
748 * on the boundary of the reference cell, the function would return `true` if
749 * the tolerance was zero. But in practice, this may or may not actually be
750 * true; for example, the point $(1/3, 2/3)$ is on the boundary of the
751 * reference triangle because $1/3+2/3 \le 1$, but since neither of its
752 * coordinates are exactly representable in floating point arithmetic, the
753 * floating point representations of $1/3$ and $2/3$ may or may not add up to
754 * anything that is less than or equal to one.
755 *
756 * The tolerance parameter may be less than zero, indicating that the point
757 * should be safely inside the cell.
758 *
759 * @pre The template argument `dim` must equal the dimension
760 * of the space in which the reference cell you are querying
761 * lives (i.e., it must equal the result of get_dimension()).
762 */
763 template <int dim>
764 bool
765 contains_point(const Point<dim> &p, const double tolerance = 0) const;
766
767 /**
768 * Return the point on the surface of the reference cell closest (in the
769 * Euclidean norm) to @p p.
770 *
771 * @pre The template argument `dim` must equal the dimension
772 * of the space in which the reference cell you are querying
773 * lives (i.e., it must equal the result of get_dimension()).
774 */
775 template <int dim>
776 Point<dim>
777 closest_point(const Point<dim> &p) const;
778
779 /**
780 * Return $i$-th unit tangent vector to a face of the reference cell.
781 * The vectors are arranged in such an order that the
782 * cross product between the two vectors returns the face normal vector.
783 *
784 * @pre $i$ must be between zero and `dim-1`.
785 *
786 * @pre The template argument `dim` must equal the dimension
787 * of the space in which the reference cell you are querying
788 * lives (i.e., it must equal the result of get_dimension()).
789 */
790 template <int dim>
791 Tensor<1, dim>
792 face_tangent_vector(const unsigned int face_no, const unsigned int i) const;
793
794 /**
795 * Return $i$-th unit tangent vector to a face of the reference cell.
796 * The vectors are arranged in such an order that the
797 * cross product between the two vectors returns the face normal vector.
798 *
799 * @pre $i$ must be between zero and `dim-1`.
800 *
801 * @pre The template argument `dim` must equal the dimension
802 * of the space in which the reference cell you are querying
803 * lives (i.e., it must equal the result of get_dimension()).
804 *
805 * @deprecated Use face_tangent_vector() instead.
806 */
807 template <int dim>
808 DEAL_II_DEPRECATED_EARLY_WITH_COMMENT("Use face_tangent_vector() instead.")
809 Tensor<1, dim> unit_tangential_vectors(const unsigned int face_no,
810 const unsigned int i) const;
811
812 /**
813 * Return the unit normal vector of a face of the reference cell.
814 *
815 * @pre The template argument `dim` must equal the dimension
816 * of the space in which the reference cell you are querying
817 * lives (i.e., it must equal the result of get_dimension()).
818 */
819 template <int dim>
820 Tensor<1, dim>
821 face_normal_vector(const unsigned int face_no) const;
822
823 /**
824 * Return the unit normal vector of a face of the reference cell.
825 *
826 * @pre The template argument `dim` must equal the dimension
827 * of the space in which the reference cell you are querying
828 * lives (i.e., it must equal the result of get_dimension()).
829 *
830 * @deprecated Use face_normal_vector() instead.
831 */
832 template <int dim>
833 DEAL_II_DEPRECATED_EARLY_WITH_COMMENT("Use face_normal_vector() instead.")
834 Tensor<1, dim> unit_normal_vectors(const unsigned int face_no) const;
835
836 /**
837 * Return the number of orientations for a face in the ReferenceCell. For
838 * example, for hexahedra this is 8 for every face since quadrilaterals have
839 * 8 possible orientations.
840 */
841 unsigned int
842 n_face_orientations(const unsigned int face_no) const;
843
844 /**
845 * Determine the orientation of the current entity described by its
846 * vertices @p vertices_1 relative to an entity described by @p vertices_0.
847 * The two arrays given as arguments can be arrays of global vertex
848 * indices or local vertex indices, arrays of vertex locations, or
849 * arrays of any other objects identifying the vertices and the order
850 * in which they are encountered in a cell.
851 *
852 * The size of the arrays, i.e., the template argument `N`,
853 * must be equal to or larger than the number of vertices of the current
854 * entity. If it is larger, only those elements of the input and output
855 * arrays are read from or written to that correspond to valid vertex
856 * indices.
857 *
858 * @deprecated Use get_combined_orientation() instead.
859 */
860 template <typename T, std::size_t N>
861 DEAL_II_DEPRECATED types::geometric_orientation
862 compute_orientation(const std::array<T, N> &vertices_0,
863 const std::array<T, N> &vertices_1) const;
864
865 /**
866 * Determine the relative orientation of the current entity described by its
867 * vertices @p vertices_1 relative to an entity described by @p vertices_0.
868 * Relative orientations are special cases of permutations since every
869 * vertex has to appear in the list of vertices of a reoriented cell
870 * as well; however, not every permutation can denote the same cell:
871 * For example, a square's vertices can be rotated by 90, 180, or
872 * 270 degrees, and the cell can be inverted (in essence looking
873 * at it from the other side), but one can't just exchange the order of two
874 * adjacent vertices because then the resulting cell is no longer a square
875 * but an object with two edges that cross each other.
876 *
877 * The two arrays given as arguments can be arrays of global vertex
878 * indices or local vertex indices, arrays of vertex locations, or
879 * arrays of any other objects identifying the vertices and the order
880 * in which they are encountered in a cell.
881 *
882 * The size of the input arrays must be equal to the number of vertices of
883 * the current entity.
884 *
885 * @returns A number that describes a relative orientation. For more
886 * information see @ref GlossCombinedOrientation "the combined orientation
887 * glossary entry".
888 */
889 template <typename T>
890 types::geometric_orientation
891 get_combined_orientation(const ArrayView<const T> &vertices_0,
892 const ArrayView<const T> &vertices_1) const;
893
894
895 /**
896 * Inverse function of compute_orientation(): Given a set of
897 * vertex-associated objects (such as vertex indices, locations, etc.) and
898 * a desired orientation permutation, return the permuted vertex information.
899 *
900 * The size of the input and output arrays, i.e., the template argument `N`,
901 * must be equal to or larger than the number of vertices of the current
902 * entity. If it is larger, only those elements of the input and output
903 * arrays are read from or written to that correspond to valid vertex
904 * indices.
905 *
906 * @deprecated Use permute_by_combined_orientation() instead.
907 */
908 template <typename T, std::size_t N>
909 DEAL_II_DEPRECATED std::array<T, N>
910 permute_according_orientation(const std::array<T, N> &vertices,
911 const unsigned int orientation) const;
912
913 /**
914 * This is the inverse function to get_combined_orientation(): Given a set of
915 * vertex-associated objects (such as vertex indices, locations, etc.) and
916 * a desired orientation permutation, return the permuted vertex information.
917 *
918 * The size of the input array must be equal to the number of vertices of
919 * the current entity. The output is an array or permuted quantities of
920 * the same size. It is a vector that can store up to and including as many
921 * elements as cells can have vertices (namely eight, as in the case of
922 * hexahedra in 3d).
923 */
924 template <typename T>
925 boost::container::small_vector<T, 8>
926 permute_by_combined_orientation(
927 const ArrayView<const T> &vertices,
928 const types::geometric_orientation orientation) const;
929
930 /**
931 * Return the inverse orientation. This is the value such that calling
932 * permute_by_combined_orientation() with <tt>o</tt> and then calling it again
933 * with get_inverse_combined_orientation(o) is the identity operation.
934 */
935 types::geometric_orientation
936 get_inverse_combined_orientation(
937 const types::geometric_orientation orientation) const;
938
939 /**
940 * Return a vector of faces a given @p vertex_index belongs to.
941 */
942 ArrayView<const unsigned int>
943 faces_for_given_vertex(const unsigned int vertex_index) const;
944
945 /**
946 * Return a vector of line indices for all new faces required for isotropic
947 * refinement.
948 */
949 constexpr dealii::ndarray<unsigned int, 12, 4>
950 new_isotropic_child_face_lines(const unsigned int refinement_choice) const;
951
952 /**
953 * Return a vector of vertex indices for all new face lines required for
954 * isotropic refinement.
955 */
956 constexpr dealii::ndarray<unsigned int, 12, 4, 2>
957 new_isotropic_child_face_line_vertices(
958 const unsigned int refinement_choice) const;
959
960 /**
961 * Return a vector of face indices for all new cells required for isotropic
962 * refinement.
963 */
964 constexpr dealii::ndarray<unsigned int, 8, 6>
965 new_isotropic_child_cell_faces(const unsigned int refinement_choice) const;
966
967 /**
968 * Return a vector of vertex indices for all new cells required for isotropic
969 * refinement.
970 */
971 constexpr dealii::ndarray<unsigned int, 8, 4>
972 new_isotropic_child_cell_vertices(const unsigned int refinement_choice) const;
973
974 /**
975 * @}
976 */
977
978 /**
979 * @name Translating between deal.II indexing and formats used by other programs
980 * @{
981 */
982
983 /**
984 * Map an ExodusII vertex number to a deal.II vertex number.
985 */
986 unsigned int
987 exodusii_vertex_to_deal_vertex(const unsigned int vertex_n) const;
988
989 /**
990 * Map an ExodusII face number to a deal.II face number.
991 */
992 unsigned int
993 exodusii_face_to_deal_face(const unsigned int face_n) const;
994
995 /**
996 * Map a UNV vertex number to a deal.II vertex number.
997 */
998 unsigned int
999 unv_vertex_to_deal_vertex(const unsigned int vertex_n) const;
1000
1001 /**
1002 * Return a VTK linear shape constant that corresponds to the reference cell.
1003 */
1004 unsigned int
1005 vtk_linear_type() const;
1006
1007 /**
1008 * Return a VTK quadratic shape constant that corresponds to the reference
1009 * cell.
1010 */
1011 unsigned int
1012 vtk_quadratic_type() const;
1013
1014 /**
1015 * Return a VTK Lagrange shape constant that corresponds to the reference
1016 * cell.
1017 */
1018 unsigned int
1019 vtk_lagrange_type() const;
1020
1021 /**
1022 * Given a set of node indices of the form $(i)$ or $(i,j)$ or $(i,j,k)$
1023 * (depending on whether the reference cell is in 1d, 2d, or 3d), return
1024 * the index the VTK format uses for this node for cells that are
1025 * subdivided as many times in each of the coordinate directions as
1026 * described by the second argument. For a uniformly subdivided cell,
1027 * the second argument is an array whose elements will all be equal.
1028 *
1029 * The last argument, @p legacy_format, indicates whether to use the
1030 * old, VTK legacy format (when `true`) or the new, VTU format (when
1031 * `false`).
1032 *
1033 * @pre The template argument `dim` must equal the dimension
1034 * of the space in which the reference cell you are querying
1035 * lives (i.e., it must equal the result of get_dimension()).
1036 */
1037 template <int dim>
1038 unsigned int
1039 vtk_lexicographic_to_node_index(
1040 const std::array<unsigned, dim> &node_indices,
1041 const std::array<unsigned, dim> &nodes_per_direction,
1042 const bool legacy_format) const;
1043
1044 /**
1045 * Map a VTK vertex number to a deal.II vertex number.
1046 */
1047 unsigned int
1048 vtk_vertex_to_deal_vertex(const unsigned int vertex_index) const;
1049
1050 /**
1051 * Return the GMSH element type code that corresponds to the reference cell.
1052 */
1053 unsigned int
1054 gmsh_element_type() const;
1055
1056 /**
1057 * @}
1058 */
1059
1060 /**
1061 * @name Other functions
1062 * @{
1063 */
1064
1065 /**
1066 * Return a text representation of the reference cell represented by the
1067 * current object.
1068 */
1069 std::string
1070 to_string() const;
1071
1072 /**
1073 * Conversion operator to an integer.
1074 */
1075 constexpr operator std::uint8_t() const;
1076
1077 /**
1078 * Operator for equality comparison.
1079 */
1080 constexpr bool
1081 operator==(const ReferenceCell &type) const;
1082
1083 /**
1084 * Operator for inequality comparison.
1085 */
1086 constexpr bool
1087 operator!=(const ReferenceCell &type) const;
1088
1089 /**
1090 * Write and read the data of this object from a stream for the purpose
1091 * of serialization using the [BOOST serialization
1092 * library](https://www.boost.org/doc/libs/1_74_0/libs/serialization/doc/index.html).
1093 */
1094 template <class Archive>
1095 void
1096 serialize(Archive &archive, const unsigned int /*version*/);
1097
1098 /**
1099 * Return the number of bytes used by an instance of this class.
1100 */
1101 static constexpr std::size_t
1102 memory_consumption();
1103
1104 /**
1105 * @}
1106 */
1107
1108 private:
1109 /**
1110 * The variable that stores what this object actually corresponds to.
1111 */
1112 std::uint8_t kind;
1113
1114 /**
1115 * Constructor. This is the constructor used to create the different
1116 * `static` member variables of this class. It is `private` but can
1117 * be called by a function in an internal namespace that is a `friend`
1118 * of this class.
1119 */
1120 constexpr ReferenceCell(const std::uint8_t kind);
1121
1122 /**
1123 * Table containing all 'vertex' permutations for a vertex. Defined
1124 * analogously to line_vertex_permutations et al to make things work the same
1125 * way in 1d.
1126 */
1127 static constexpr ndarray<unsigned int, 1, 1> vertex_vertex_permutations = {
1128 {{{0}}}};
1129
1130 /**
1131 * Table containing all vertex permutations for a line.
1132 */
1133 static constexpr ndarray<unsigned int, 2, 2> line_vertex_permutations = {
1134 {{{0, 1}}, {{1, 0}}}};
1135
1136 /**
1137 * Table containing all vertex permutations for a triangle.
1138 */
1139 static constexpr ndarray<unsigned int, 6, 3> triangle_vertex_permutations = {
1140 {{{0, 1, 2}},
1141 {{0, 2, 1}},
1142 {{2, 0, 1}},
1143 {{2, 1, 0}},
1144 {{1, 2, 0}},
1145 {{1, 0, 2}}}};
1146
1147 /**
1148 * Table containing all vertex permutations for a quadrilateral.
1149 */
1150 static constexpr ndarray<unsigned int, 8, 4>
1151 quadrilateral_vertex_permutations = {{
1152 {{0, 1, 2, 3}},
1153 {{0, 2, 1, 3}},
1154 {{2, 0, 3, 1}},
1155 {{2, 3, 0, 1}},
1156 {{3, 2, 1, 0}},
1157 {{3, 1, 2, 0}},
1158 {{1, 3, 0, 2}},
1159 {{1, 0, 3, 2}},
1160 }};
1161
1162 /**
1163 * A kind of constructor -- not quite private because it can be
1164 * called by anyone, but at least hidden in an internal namespace.
1165 */
1166 friend constexpr ReferenceCell
1167 internal::make_reference_cell_from_int(const std::uint8_t);
1168
1169 friend std::ostream &
1170 operator<<(std::ostream &out, const ReferenceCell &reference_cell);
1171
1172 friend std::istream &
1173 operator>>(std::istream &in, ReferenceCell &reference_cell);
1174 };
1175
1176
1177 /**
1178 * Output operator that writes the @p reference_cell object to the stream
1179 * in a text format in which the object is represented by an integer. The
1180 * details of which integer value represents each kind of reference cell
1181 * is unimportant and consequently not specified. If you want a string
1182 * representation of what a ReferenceCell is, use ReferenceCell::to_string().
1183 */
1184 std::ostream &
1185 operator<<(std::ostream &out, const ReferenceCell &reference_cell);
1186
1187 /**
1188 * Input operator that reads the @p reference_cell object from the stream
1189 * in a text format in which the object is represented by an integer. Which
1190 * specific integer value represents which reference cell is unspecified,
1191 * but the function uses the same translation as the corresponding
1192 * output `operator<<`.
1193 */
1194 std::istream &
1195 operator>>(std::istream &in, ReferenceCell &reference_cell);
1196
1197
1198 inline constexpr ReferenceCell::ReferenceCell(const std::uint8_t kind)
1199 : kind(kind)
1200 {}
1201
1202
1203
1204 inline constexpr ReferenceCell::operator std::uint8_t() const
1205 {
1206 return kind;
1207 }
1208
1209
1210
1211 inline constexpr bool
1212 ReferenceCell::operator==(const ReferenceCell &type) const
1213 {
1214 return kind == type.kind;
1215 }
1216
1217
1218
1219 inline constexpr bool
1220 ReferenceCell::operator!=(const ReferenceCell &type) const
1221 {
1222 return kind != type.kind;
1223 }
1224
1225
1226
1227 namespace internal
1228 {
1229 inline constexpr ReferenceCell
1230 make_reference_cell_from_int(const std::uint8_t kind)
1231 {
1232 #ifndef DEAL_II_CXX14_CONSTEXPR_BUG
1233 // Make sure these are the only indices from which objects can be
1234 // created.
1235 Assert((kind == std::numeric_limits<std::uint8_t>::max()) || (kind < 8),
1236 ExcInternalError());
1237 #endif
1238
1239 // Call the private constructor, which we can from here because this
1240 // function is a 'friend'.
1241 return {kind};
1242 }
1243 } // namespace internal
1244
1245
1246
1247 /**
1248 * A namespace in which we define objects that correspond to specific
1249 * reference cells. The objects defined here are a complete enumeration
1250 * of all possible reference cells that can be used in deal.II.
1251 *
1252 * @relates ReferenceCell
1253 */
1254 namespace ReferenceCells
1255 {
1256 constexpr ReferenceCell Vertex = internal::make_reference_cell_from_int(0);
1257 constexpr ReferenceCell Line = internal::make_reference_cell_from_int(1);
1258 constexpr ReferenceCell Triangle = internal::make_reference_cell_from_int(2);
1259 constexpr ReferenceCell Quadrilateral =
1260 internal::make_reference_cell_from_int(3);
1261 constexpr ReferenceCell Tetrahedron =
1262 internal::make_reference_cell_from_int(4);
1263 constexpr ReferenceCell Pyramid = internal::make_reference_cell_from_int(5);
1264 constexpr ReferenceCell Wedge = internal::make_reference_cell_from_int(6);
1265 constexpr ReferenceCell Hexahedron =
1266 internal::make_reference_cell_from_int(7);
1267 constexpr ReferenceCell Invalid = internal::make_reference_cell_from_int(
1268 std::numeric_limits<std::uint8_t>::max());
1269
1270 /**
1271 * Return the correct simplex reference cell type for the given dimension
1272 * `dim`. Depending on the template argument `dim`, this function returns a
1273 * reference to either Vertex, Line, Triangle, or Tetrahedron.
1274 */
1275 template <int dim>
1276 constexpr const ReferenceCell &
1277 get_simplex();
1278
1279 /**
1280 * Return the correct hypercube reference cell type for the given dimension
1281 * `dim`. Depending on the template argument `dim`, this function returns a
1282 * reference to either Vertex, Quadrilateral, or Hexahedron.
1283 */
1284 template <int dim>
1285 constexpr const ReferenceCell &
1286 get_hypercube();
1287
1288 /**
1289 * Return the maximum number of vertices an object of dimension `structdim`
1290 * can have. This is always the number of vertices of a
1291 * `structdim`-dimensional hypercube.
1292 *
1293 * @see ReferenceCells::max_n_faces()
1294 */
1295 template <int structdim>
1296 constexpr unsigned int
1297 max_n_vertices();
1298
1299 /**
1300 * Return the maximum number of lines an object of dimension `structdim` can
1301 * have. This is always the number of lines of a `structdim`-dimensional
1302 * hypercube.
1303 *
1304 * @see ReferenceCells::max_n_faces()
1305 */
1306 template <int structdim>
1307 constexpr unsigned int
1308 max_n_lines();
1309
1310 /**
1311 * Return the maximum number of faces an object of dimension `structdim` can
1312 * have. This is always the number of faces of a `structdim`-dimensional
1313 * hypercube.
1314 *
1315 * @note The primary use case of this and the other maxima functions is to
1316 * enable simple array indexing to per-face data by cell index and face
1317 * number, e.g.,
1318 *
1319 * @code
1320 * cell->index() * ReferenceCells::max_n_faces<dim>() + face_no;
1321 * @endcode
1322 *
1323 * is a unique index to the `face_no`th face of the current cell.
1324 */
1325 template <int structdim>
1326 constexpr unsigned int
1327 max_n_faces();
1328 } // namespace ReferenceCells
1329
1330
1331
1332 inline constexpr ReferenceCell::ReferenceCell()
1333 : ReferenceCell(ReferenceCells::Invalid)
1334 {}
1335
1336
1337
1338 template <class Archive>
1339 inline void
1340 ReferenceCell::serialize(Archive &archive, const unsigned int /*version*/)
1341 {
1342 archive &kind;
1343 }
1344
1345
1346
1347 inline constexpr std::size_t
1348 ReferenceCell::memory_consumption()
1349 {
1350 return sizeof(ReferenceCells::Invalid);
1351 }
1352
1353
1354
1355 inline ArrayView<const unsigned int>
1356 ReferenceCell::faces_for_given_vertex(const unsigned int vertex) const
1357 {
1358 AssertIndexRange(vertex, n_vertices());
1359 switch (this->kind)
1360 {
1361 case ReferenceCells::Line:
1362 return {&GeometryInfo<2>::vertex_to_face[vertex][0], 1};
1363 case ReferenceCells::Quadrilateral:
1364 return {&GeometryInfo<2>::vertex_to_face[vertex][0], 2};
1365 case ReferenceCells::Triangle:
1366 {
1367 static constexpr ndarray<unsigned int, 3, 2> table = {
1368 {{{0, 2}}, {{0, 1}}, {{1, 2}}}};
1369 return table[vertex];
1370 }
1371 case ReferenceCells::Tetrahedron:
1372 {
1373 static constexpr ndarray<unsigned int, 4, 3> table = {
1374 {{{0, 1, 2}}, {{0, 1, 3}}, {{0, 2, 3}}, {{1, 2, 3}}}};
1375
1376 return table[vertex];
1377 }
1378 case ReferenceCells::Pyramid:
1379 {
1380 static constexpr unsigned int X = numbers::invalid_unsigned_int;
1381 static constexpr ndarray<unsigned int, 5, 4> table = {
1382 {{{0, 1, 3, X}},
1383 {{0, 2, 3, X}},
1384 {{0, 1, 4, X}},
1385 {{0, 2, 4, X}},
1386 {{1, 2, 3, 4}}}};
1387
1388 return {&table[vertex][0], vertex == 4 ? 4u : 3u};
1389 }
1390 case ReferenceCells::Wedge:
1391 {
1392 AssertIndexRange(vertex, 6);
1393 static constexpr ndarray<unsigned int, 6, 3> table = {{{{0, 2, 4}},
1394 {{0, 2, 3}},
1395 {{0, 3, 4}},
1396 {{1, 2, 4}},
1397 {{1, 2, 3}},
1398 {{1, 3, 4}}}};
1399
1400 return table[vertex];
1401 }
1402 case ReferenceCells::Hexahedron:
1403 return {&GeometryInfo<3>::vertex_to_face[vertex][0], 3};
1404 default:
1405 DEAL_II_NOT_IMPLEMENTED();
1406 }
1407
1408 return {};
1409 }
1410
1411
1412 constexpr dealii::ndarray<unsigned int, 12, 4>
1413 ReferenceCell::new_isotropic_child_face_lines(
1414 const unsigned int refienement_choice) const
1415 {
1416 // AssertIndexRange(refienement_choice, n_isotropic_refinement_choices());
1417 const unsigned int X = numbers::invalid_unsigned_int;
1418 switch (this->kind)
1419 {
1420 case ReferenceCells::Tetrahedron:
1421 {
1422 constexpr dealii::ndarray<unsigned int, 3, 12, 4> new_quad_lines_tet =
1423 {{// new line is (6,8)
1424 {{{{2, 3, 8, X}},
1425 {{0, 9, 5, X}},
1426 {{1, 6, 11, X}},
1427 {{4, 10, 7, X}},
1428 {{2, 12, 5, X}},
1429 {{1, 9, 12, X}},
1430 {{4, 8, 12, X}},
1431 {{6, 12, 10, X}},
1432 {{X, X, X, X}},
1433 {{X, X, X, X}},
1434 {{X, X, X, X}},
1435 {{X, X, X, X}}}},
1436 // new line is (5,7)
1437 {{{{2, 3, 8, X}},
1438 {{0, 9, 5, X}},
1439 {{1, 6, 11, X}},
1440 {{4, 10, 7, X}},
1441 {{0, 3, 12, X}},
1442 {{1, 12, 8, X}},
1443 {{4, 12, 9, X}},
1444 {{7, 11, 12, X}},
1445 {{X, X, X, X}},
1446 {{X, X, X, X}},
1447 {{X, X, X, X}},
1448 {{X, X, X, X}}}},
1449 // new line is (4,9)
1450 {{{{2, 3, 8, X}},
1451 {{0, 9, 5, X}},
1452 {{1, 6, 11, X}},
1453 {{4, 10, 7, X}},
1454 {{0, 12, 11, X}},
1455 {{2, 6, 12, X}},
1456 {{3, 12, 7, X}},
1457 {{5, 10, 12, X}},
1458 {{X, X, X, X}},
1459 {{X, X, X, X}},
1460 {{X, X, X, X}},
1461 {{X, X, X, X}}}}}};
1462 return new_quad_lines_tet[refienement_choice];
1463 }
1464
1465 case ReferenceCells::Hexahedron:
1466 {
1467 constexpr dealii::ndarray<unsigned int, 12, 4> new_quad_lines_hex = {
1468 {{{10, 28, 16, 24}},
1469 {{28, 14, 17, 25}},
1470 {{11, 29, 24, 20}},
1471 {{29, 15, 25, 21}},
1472 {{18, 26, 0, 28}},
1473 {{26, 22, 1, 29}},
1474 {{19, 27, 28, 4}},
1475 {{27, 23, 29, 5}},
1476 {{2, 24, 8, 26}},
1477 {{24, 6, 9, 27}},
1478 {{3, 25, 26, 12}},
1479 {{25, 7, 27, 13}}}};
1480 return new_quad_lines_hex;
1481 }
1482 default:
1483 DEAL_II_NOT_IMPLEMENTED();
1484 }
1485
1486 return {};
1487 }
1488
1489
1490
1491 constexpr dealii::ndarray<unsigned int, 12, 4, 2>
1492 ReferenceCell::new_isotropic_child_face_line_vertices(
1493 const unsigned int refienement_choice) const
1494 {
1495 // AssertIndexRange(refienement_choice, n_isotropic_refinement_choices());
1496 const unsigned int X = numbers::invalid_unsigned_int;
1497 switch (this->kind)
1498 {
1499 case ReferenceCells::Tetrahedron:
1500 {
1501 constexpr dealii::ndarray<unsigned int, 3, 12, 4, 2> table_tet = {
1502 {// new line is (6, 8)
1503 {{{{{{6, 4}}, {{4, 7}}, {{7, 6}}, {{X, X}}}},
1504 {{{{4, 5}}, {{5, 8}}, {{8, 4}}, {{X, X}}}},
1505 {{{{5, 6}}, {{6, 9}}, {{9, 5}}, {{X, X}}}},
1506 {{{{7, 8}}, {{8, 9}}, {{9, 7}}, {{X, X}}}},
1507 {{{{4, 6}}, {{6, 8}}, {{8, 4}}, {{X, X}}}},
1508 {{{{6, 5}}, {{5, 8}}, {{8, 6}}, {{X, X}}}},
1509 {{{{8, 7}}, {{7, 6}}, {{6, 8}}, {{X, X}}}},
1510 {{{{9, 6}}, {{6, 8}}, {{8, 9}}, {{X, X}}}},
1511 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1512 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1513 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1514 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}}}},
1515 // new line is (5, 7)
1516 {{{{{{6, 4}}, {{4, 7}}, {{7, 6}}, {{X, X}}}},
1517 {{{{4, 5}}, {{5, 8}}, {{8, 4}}, {{X, X}}}},
1518 {{{{5, 6}}, {{6, 9}}, {{9, 5}}, {{X, X}}}},
1519 {{{{7, 8}}, {{8, 9}}, {{9, 7}}, {{X, X}}}},
1520 {{{{5, 4}}, {{4, 7}}, {{7, 5}}, {{X, X}}}},
1521 {{{{6, 5}}, {{5, 7}}, {{7, 6}}, {{X, X}}}},
1522 {{{{8, 7}}, {{7, 5}}, {{5, 8}}, {{X, X}}}},
1523 {{{{7, 9}}, {{9, 5}}, {{5, 7}}, {{X, X}}}},
1524 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1525 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1526 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1527 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}}}},
1528 // new line is (4, 9)
1529 {{{{{{6, 4}}, {{4, 7}}, {{7, 6}}, {{X, X}}}},
1530 {{{{4, 5}}, {{5, 8}}, {{8, 4}}, {{X, X}}}},
1531 {{{{5, 6}}, {{6, 9}}, {{9, 5}}, {{X, X}}}},
1532 {{{{7, 8}}, {{8, 9}}, {{9, 7}}, {{X, X}}}},
1533 {{{{5, 4}}, {{4, 9}}, {{9, 5}}, {{X, X}}}},
1534 {{{{4, 6}}, {{6, 9}}, {{9, 4}}, {{X, X}}}},
1535 {{{{7, 4}}, {{4, 9}}, {{9, 7}}, {{X, X}}}},
1536 {{{{4, 8}}, {{8, 9}}, {{9, 4}}, {{X, X}}}},
1537 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1538 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1539 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}},
1540 {{{{X, X}}, {{X, X}}, {{X, X}}, {{X, X}}}}}}}};
1541 return table_tet[refienement_choice];
1542 }
1543
1544 case ReferenceCells::Hexahedron:
1545 {
1546 constexpr dealii::ndarray<unsigned int, 12, 4, 2> table_hex = {
1547 {{{{{10, 22}}, {{24, 26}}, {{10, 24}}, {{22, 26}}}},
1548 {{{{24, 26}}, {{11, 23}}, {{24, 11}}, {{26, 23}}}},
1549 {{{{22, 14}}, {{26, 25}}, {{22, 26}}, {{14, 25}}}},
1550 {{{{26, 25}}, {{23, 15}}, {{26, 23}}, {{25, 15}}}},
1551 {{{{8, 24}}, {{20, 26}}, {{8, 20}}, {{24, 26}}}},
1552 {{{{20, 26}}, {{12, 25}}, {{20, 12}}, {{26, 25}}}},
1553 {{{{24, 9}}, {{26, 21}}, {{24, 26}}, {{9, 21}}}},
1554 {{{{26, 21}}, {{25, 13}}, {{26, 25}}, {{21, 13}}}},
1555 {{{{16, 20}}, {{22, 26}}, {{16, 22}}, {{20, 26}}}},
1556 {{{{22, 26}}, {{17, 21}}, {{22, 17}}, {{26, 21}}}},
1557 {{{{20, 18}}, {{26, 23}}, {{20, 26}}, {{18, 23}}}},
1558 {{{{26, 23}}, {{21, 19}}, {{26, 21}}, {{23, 19}}}}}};
1559 return table_hex;
1560 }
1561 default:
1562 DEAL_II_NOT_IMPLEMENTED();
1563 }
1564
1565 return {};
1566 }
1567
1568
1569
1570 constexpr dealii::ndarray<unsigned int, 8, 6>
1571 ReferenceCell::new_isotropic_child_cell_faces(
1572 const unsigned int refienement_choice) const
1573 {
1574 // AssertIndexRange(refienement_choice, n_isotropic_refinement_choices());
1575 const unsigned int X = numbers::invalid_unsigned_int;
1576 switch (this->kind)
1577 {
1578 case ReferenceCells::Tetrahedron:
1579 {
1580 constexpr dealii::ndarray<unsigned int, 3, 8, 6> cell_quads_tet = {
1581 {// new line is (6, 8)
1582 {{{{8, 13, 16, 0, X, X}},
1583 {{9, 12, 1, 21, X, X}},
1584 {{10, 2, 17, 20, X, X}},
1585 {{3, 14, 18, 22, X, X}},
1586 {{11, 1, 4, 5, X, X}},
1587 {{15, 0, 4, 6, X, X}},
1588 {{19, 7, 6, 3, X, X}},
1589 {{23, 5, 2, 7, X, X}}}},
1590 // new line is (5, 7)
1591 {{
1592 {{8, 13, 16, 0, X, X}},
1593 {{9, 12, 1, 21, X, X}},
1594 {{10, 2, 17, 20, X, X}},
1595 {{3, 14, 18, 22, X, X}},
1596 {{11, 4, 0, 5, X, X}},
1597 {{15, 4, 1, 6, X, X}},
1598 {{19, 2, 5, 7, X, X}},
1599 {{23, 6, 7, 3, X, X}},
1600 }},
1601 // new line is (4, 9)
1602 {{
1603 {{8, 13, 16, 0, X, X}},
1604 {{9, 12, 1, 21, X, X}},
1605 {{10, 2, 17, 20, X, X}},
1606 {{3, 14, 18, 22, X, X}},
1607 {{11, 4, 5, 2, X, X}},
1608 {{15, 6, 7, 3, X, X}},
1609 {{19, 5, 0, 6, X, X}},
1610 {{23, 1, 4, 7, X, X}},
1611 }}}};
1612 return cell_quads_tet[refienement_choice];
1613 }
1614
1615 case ReferenceCells::Hexahedron:
1616 {
1617 constexpr dealii::ndarray<unsigned int, 8, 6> cell_quads_hex = {{
1618 {{12, 0, 20, 4, 28, 8}}, // bottom children
1619 {{0, 16, 22, 6, 29, 9}}, //
1620 {{13, 1, 4, 24, 30, 10}}, //
1621 {{1, 17, 6, 26, 31, 11}}, //
1622 {{14, 2, 21, 5, 8, 32}}, // top children
1623 {{2, 18, 23, 7, 9, 33}}, //
1624 {{15, 3, 5, 25, 10, 34}}, //
1625 {{3, 19, 7, 27, 11, 35}} //
1626 }};
1627 return cell_quads_hex;
1628 }
1629 default:
1630 DEAL_II_NOT_IMPLEMENTED();
1631 }
1632
1633 return {};
1634 }
1635
1636
1637
1638 constexpr dealii::ndarray<unsigned int, 8, 4>
1639 ReferenceCell::new_isotropic_child_cell_vertices(
1640 const unsigned int refienement_choice) const
1641 {
1642 // AssertIndexRange(refienement_choice, n_isotropic_refinement_choices());
1643
1644 switch (this->kind)
1645 {
1646 case ReferenceCells::Tetrahedron:
1647 {
1648 constexpr dealii::ndarray<unsigned int, 3, 8, 4> cell_vertices_tet = {
1649 {// new line is (6,8)
1650 {{{{0, 4, 6, 7}},
1651 {{4, 1, 5, 8}},
1652 {{6, 5, 2, 9}},
1653 {{7, 8, 9, 3}},
1654 {{4, 5, 6, 8}},
1655 {{4, 7, 8, 6}},
1656 {{6, 9, 7, 8}},
1657 {{5, 8, 9, 6}}}},
1658 // new line is (5,7)
1659 {{{{0, 4, 6, 7}},
1660 {{4, 1, 5, 8}},
1661 {{6, 5, 2, 9}},
1662 {{7, 8, 9, 3}},
1663 {{4, 5, 6, 7}},
1664 {{4, 7, 8, 5}},
1665 {{6, 9, 7, 5}},
1666 {{5, 8, 9, 7}}}},
1667 // new line is (4,9)
1668 {{{{0, 4, 6, 7}},
1669 {{4, 1, 5, 8}},
1670 {{6, 5, 2, 9}},
1671 {{7, 8, 9, 3}},
1672 {{4, 5, 6, 9}},
1673 {{4, 7, 8, 9}},
1674 {{6, 9, 7, 4}},
1675 {{5, 8, 9, 4}}}}}};
1676 return cell_vertices_tet[refienement_choice];
1677 }
1678 default:
1679 DEAL_II_NOT_IMPLEMENTED();
1680 }
1681
1682 return {};
1683 }
1684
1685
1686
1687 inline bool
1688 ReferenceCell::is_hyper_cube() const
1689 {
1690 return (*this == ReferenceCells::Vertex || *this == ReferenceCells::Line ||
1691 *this == ReferenceCells::Quadrilateral ||
1692 *this == ReferenceCells::Hexahedron);
1693 }
1694
1695
1696
1697 inline bool
1698 ReferenceCell::is_simplex() const
1699 {
1700 return (*this == ReferenceCells::Vertex || *this == ReferenceCells::Line ||
1701 *this == ReferenceCells::Triangle ||
1702 *this == ReferenceCells::Tetrahedron);
1703 }
1704
1705
1706
1707 inline unsigned int
1708 ReferenceCell::get_dimension() const
1709 {
1710 switch (this->kind)
1711 {
1712 case ReferenceCells::Vertex:
1713 return 0;
1714 case ReferenceCells::Line:
1715 return 1;
1716 case ReferenceCells::Triangle:
1717 case ReferenceCells::Quadrilateral:
1718 return 2;
1719 case ReferenceCells::Tetrahedron:
1720 case ReferenceCells::Pyramid:
1721 case ReferenceCells::Wedge:
1722 case ReferenceCells::Hexahedron:
1723 return 3;
1724 default:
1725 DEAL_II_NOT_IMPLEMENTED();
1726 }
1727
1728 return numbers::invalid_unsigned_int;
1729 }
1730
1731
1732
1733 template <int dim>
1734 Quadrature<dim>
1735 ReferenceCell::get_midpoint_quadrature() const
1736 {
1737 Assert(dim == get_dimension(),
1738 ExcMessage("You can only call this function with arguments for "
1739 "which 'dim' equals the dimension of the space in which "
1740 "the current reference cell lives. You have dim=" +
1741 std::to_string(dim) + " but the reference cell is " +
1742 std::to_string(get_dimension()) + " dimensional."));
1743
1744 return Quadrature<dim>(std::vector<Point<dim>>({barycenter<dim>()}),
1745 std::vector<double>({volume()}));
1746 }
1747
1748
1749
1750 inline unsigned int
1751 ReferenceCell::n_vertices() const
1752 {
1753 switch (this->kind)
1754 {
1755 case ReferenceCells::Vertex:
1756 return 1;
1757 case ReferenceCells::Line:
1758 return 2;
1759 case ReferenceCells::Triangle:
1760 return 3;
1761 case ReferenceCells::Quadrilateral:
1762 return 4;
1763 case ReferenceCells::Tetrahedron:
1764 return 4;
1765 case ReferenceCells::Pyramid:
1766 return 5;
1767 case ReferenceCells::Wedge:
1768 return 6;
1769 case ReferenceCells::Hexahedron:
1770 return 8;
1771 default:
1772 DEAL_II_NOT_IMPLEMENTED();
1773 }
1774
1775 return numbers::invalid_unsigned_int;
1776 }
1777
1778
1779
1780 inline unsigned int
1781 ReferenceCell::n_lines() const
1782 {
1783 switch (this->kind)
1784 {
1785 case ReferenceCells::Vertex:
1786 return 0;
1787 case ReferenceCells::Line:
1788 return 1;
1789 case ReferenceCells::Triangle:
1790 return 3;
1791 case ReferenceCells::Quadrilateral:
1792 return 4;
1793 case ReferenceCells::Tetrahedron:
1794 return 6;
1795 case ReferenceCells::Pyramid:
1796 return 8;
1797 case ReferenceCells::Wedge:
1798 return 9;
1799 case ReferenceCells::Hexahedron:
1800 return 12;
1801 default:
1802 DEAL_II_NOT_IMPLEMENTED();
1803 }
1804
1805 return numbers::invalid_unsigned_int;
1806 }
1807
1808
1809
1810 template <int dim>
1811 Point<dim>
1812 ReferenceCell::vertex(const unsigned int v) const
1813 {
1814 Assert(dim == get_dimension(),
1815 ExcMessage("You can only call this function with arguments for "
1816 "which 'dim' equals the dimension of the space in which "
1817 "the current reference cell lives. You have dim=" +
1818 std::to_string(dim) + " but the reference cell is " +
1819 std::to_string(get_dimension()) + " dimensional."));
1820 AssertIndexRange(v, n_vertices());
1821
1822 switch (dim)
1823 {
1824 case 0:
1825 {
1826 if (*this == ReferenceCells::Vertex)
1827 return Point<dim>();
1828 break;
1829 }
1830 case 1:
1831 {
1832 static const Point<dim> vertices[2] = {
1833 Point<dim>(), // the origin
1834 Point<dim>::unit_vector(0) // unit point along x-axis
1835 };
1836 if (*this == ReferenceCells::Line)
1837 return vertices[v];
1838 break;
1839 }
1840 case 2:
1841 {
1842 switch (this->kind)
1843 {
1844 case ReferenceCells::Triangle:
1845 {
1846 static const Point<dim> vertices[3] = {
1847 Point<dim>(), // the origin
1848 Point<dim>::unit_vector(0), // unit point along x-axis
1849 Point<dim>::unit_vector(1) // unit point along y-axis
1850 };
1851 return vertices[v];
1852 }
1853 case ReferenceCells::Quadrilateral:
1854 {
1855 static const Point<dim> vertices[4] = {
1856 // First the two points on the x-axis
1857 Point<dim>(),
1858 Point<dim>::unit_vector(0),
1859 // Then these two points shifted in the y-direction
1860 Point<dim>() + Point<dim>::unit_vector(1),
1861 Point<dim>::unit_vector(0) + Point<dim>::unit_vector(1)};
1862 return vertices[v];
1863 }
1864 }
1865 break;
1866 }
1867 case 3:
1868 {
1869 switch (this->kind)
1870 {
1871 case ReferenceCells::Tetrahedron:
1872 {
1873 static const Point<dim> vertices[4] = {
1874 Point<dim>(), // the origin
1875 Point<dim>::unit_vector(0), // unit point along x-axis
1876 Point<dim>::unit_vector(1), // unit point along y-axis
1877 Point<dim>::unit_vector(2) // unit point along z-axis
1878 };
1879 return vertices[v];
1880 }
1881 case ReferenceCells::Pyramid:
1882 {
1883 static const Point<dim> vertices[5] = {
1884 Point<dim>{-1.0, -1.0, 0.0},
1885 Point<dim>{+1.0, -1.0, 0.0},
1886 Point<dim>{-1.0, +1.0, 0.0},
1887 Point<dim>{+1.0, +1.0, 0.0},
1888 Point<dim>{+0.0, +0.0, 1.0}};
1889 return vertices[v];
1890 }
1891 case ReferenceCells::Wedge:
1892 {
1893 static const Point<dim> vertices[6] = {
1894 // First the three points on the triangular base of the
1895 // wedge:
1896 Point<dim>(),
1897 Point<dim>::unit_vector(0),
1898 Point<dim>::unit_vector(1),
1899 // And now everything shifted in the z-direction again
1900 Point<dim>() + Point<dim>::unit_vector(2),
1901 Point<dim>::unit_vector(0) + Point<dim>::unit_vector(2),
1902 Point<dim>::unit_vector(1) + Point<dim>::unit_vector(2)};
1903 return vertices[v];
1904 }
1905 case ReferenceCells::Hexahedron:
1906 {
1907 static const Point<dim> vertices[8] = {
1908 // First the two points on the x-axis
1909 Point<dim>(),
1910 Point<dim>::unit_vector(0),
1911 // Then these two points shifted in the y-direction
1912 Point<dim>() + Point<dim>::unit_vector(1),
1913 Point<dim>::unit_vector(0) + Point<dim>::unit_vector(1),
1914 // And now all four points shifted in the z-direction
1915 Point<dim>() + Point<dim>::unit_vector(2),
1916 Point<dim>::unit_vector(0) + Point<dim>::unit_vector(2),
1917 Point<dim>() + Point<dim>::unit_vector(1) +
1918 Point<dim>::unit_vector(2),
1919 Point<dim>::unit_vector(0) + Point<dim>::unit_vector(1) +
1920 Point<dim>::unit_vector(2)};
1921 return vertices[v];
1922 }
1923 }
1924 break;
1925 }
1926 default:
1927 DEAL_II_NOT_IMPLEMENTED();
1928 }
1929
1930 DEAL_II_NOT_IMPLEMENTED();
1931 return Point<dim>();
1932 }
1933
1934
1935 inline unsigned int
1936 ReferenceCell::n_faces() const
1937 {
1938 switch (this->kind)
1939 {
1940 case ReferenceCells::Vertex:
1941 return 0;
1942 case ReferenceCells::Line:
1943 return 2;
1944 case ReferenceCells::Triangle:
1945 return 3;
1946 case ReferenceCells::Quadrilateral:
1947 return 4;
1948 case ReferenceCells::Tetrahedron:
1949 return 4;
1950 case ReferenceCells::Pyramid:
1951 return 5;
1952 case ReferenceCells::Wedge:
1953 return 5;
1954 case ReferenceCells::Hexahedron:
1955 return 6;
1956 default:
1957 DEAL_II_NOT_IMPLEMENTED();
1958 }
1959
1960 return numbers::invalid_unsigned_int;
1961 }
1962
1963
1964
1965 inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
1966 ReferenceCell::face_indices() const
1967 {
1968 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
1969 n_faces());
1970 }
1971
1972
1973
1974 inline unsigned int
1975 ReferenceCell::n_isotropic_refinement_choices() const
1976 {
1977 switch (this->kind)
1978 {
1979 case ReferenceCells::Vertex:
1980 return 1;
1981 case ReferenceCells::Line:
1982 return 1;
1983 case ReferenceCells::Triangle:
1984 return 1;
1985 case ReferenceCells::Quadrilateral:
1986 return 1;
1987 case ReferenceCells::Tetrahedron:
1988 return 3;
1989 case ReferenceCells::Pyramid:
1990 return 1;
1991 case ReferenceCells::Wedge:
1992 return 1;
1993 case ReferenceCells::Hexahedron:
1994 return 1;
1995 default:
1996 DEAL_II_ASSERT_UNREACHABLE();
1997 }
1998
1999 return numbers::invalid_unsigned_int;
2000 }
2001
2002
2003
2004 inline IsotropicRefinementChoice
2005 ReferenceCell::get_isotropic_refinement_choice(
2006 const unsigned int ref_choice) const
2007 {
2008 AssertIndexRange(ref_choice, n_isotropic_refinement_choices());
2009 switch (this->kind)
2010 {
2011 case ReferenceCells::Tetrahedron:
2012 {
2013 static constexpr ndarray<IsotropicRefinementChoice, 3>
2014 isotropic_ref_choices = {{IsotropicRefinementChoice::cut_tet_68,
2015 IsotropicRefinementChoice::cut_tet_57,
2016 IsotropicRefinementChoice::cut_tet_49}};
2017 return isotropic_ref_choices[ref_choice];
2018 }
2019 default:
2020 {
2021 DEAL_II_NOT_IMPLEMENTED();
2022 }
2023 }
2024
2025 return IsotropicRefinementChoice::isotropic_refinement;
2026 }
2027
2028
2029
2030 inline unsigned int
2031 ReferenceCell::n_isotropic_children() const
2032 {
2033 switch (this->kind)
2034 {
2035 case ReferenceCells::Vertex:
2036 return 0;
2037 case ReferenceCells::Line:
2038 return 2;
2039 case ReferenceCells::Triangle:
2040 return 4;
2041 case ReferenceCells::Quadrilateral:
2042 return 4;
2043 case ReferenceCells::Tetrahedron:
2044 return 8;
2045 case ReferenceCells::Pyramid:
2046 // We haven't yet decided how to refine pyramids. Update this when we
2047 // have
2048 return 0;
2049 case ReferenceCells::Wedge:
2050 return 8;
2051 case ReferenceCells::Hexahedron:
2052 return 8;
2053 default:
2054 DEAL_II_ASSERT_UNREACHABLE();
2055 }
2056
2057 return numbers::invalid_unsigned_int;
2058 }
2059
2060
2061
2062 template <int dim>
2063 unsigned int
2064 ReferenceCell::n_children(const RefinementCase<dim> ref_case) const
2065 {
2066 Assert(dim == get_dimension(),
2067 ExcMessage("You can only call this function with arguments for "
2068 "which 'dim' equals the dimension of the space in which "
2069 "the current reference cell lives. You have dim=" +
2070 std::to_string(dim) + " but the reference cell is " +
2071 std::to_string(get_dimension()) + " dimensional."));
2072
2073 // Use GeometryInfo here to keep it the single source of truth
2074 if (this->is_hyper_cube())
2075 return GeometryInfo<dim>::n_children(ref_case);
2076 else
2077 return this->n_isotropic_children();
2078 }
2079
2080
2081
2082 inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
2083 ReferenceCell::isotropic_child_indices() const
2084 {
2085 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(
2086 0U, n_isotropic_children());
2087 }
2088
2089
2090
2091 inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
2092 ReferenceCell::vertex_indices() const
2093 {
2094 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
2095 n_vertices());
2096 }
2097
2098
2099
2100 inline std_cxx20::ranges::iota_view<unsigned int, unsigned int>
2101 ReferenceCell::line_indices() const
2102 {
2103 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
2104 n_lines());
2105 }
2106
2107
2108
2109 inline ReferenceCell
2110 ReferenceCell::face_reference_cell(const unsigned int face_no) const
2111 {
2112 AssertIndexRange(face_no, n_faces());
2113
2114 switch (this->kind)
2115 {
2116 case ReferenceCells::Vertex:
2117 return ReferenceCells::Invalid;
2118 case ReferenceCells::Line:
2119 return ReferenceCells::Vertex;
2120 case ReferenceCells::Triangle:
2121 case ReferenceCells::Quadrilateral:
2122 return ReferenceCells::Line;
2123 case ReferenceCells::Tetrahedron:
2124 return ReferenceCells::Triangle;
2125 case ReferenceCells::Pyramid:
2126 if (face_no == 0)
2127 return ReferenceCells::Quadrilateral;
2128 else
2129 return ReferenceCells::Triangle;
2130 case ReferenceCells::Wedge:
2131 if (face_no > 1)
2132 return ReferenceCells::Quadrilateral;
2133 else
2134 return ReferenceCells::Triangle;
2135 case ReferenceCells::Hexahedron:
2136 return ReferenceCells::Quadrilateral;
2137 default:
2138 DEAL_II_NOT_IMPLEMENTED();
2139 }
2140
2141 return ReferenceCells::Invalid;
2142 }
2143
2144
2145
2146 inline constexpr types::geometric_orientation
2147 ReferenceCell::default_combined_face_orientation()
2148 {
2149 return numbers::default_geometric_orientation;
2150 }
2151
2152
2153
2154 inline constexpr types::geometric_orientation
2155 ReferenceCell::reversed_combined_line_orientation()
2156 {
2157 // For a reversed line 'orientation' is false and neither flip nor rotate are
2158 // defined.
2159 return numbers::reverse_line_orientation;
2160 }
2161
2162
2163
2164 inline unsigned int
2165 ReferenceCell::child_cell_on_face(const unsigned int face,
2166 const unsigned int subface) const
2167 {
2168 return child_cell_on_face(face,
2169 subface,
2170 numbers::default_geometric_orientation);
2171 }
2172
2173
2174
2175 inline unsigned int
2176 ReferenceCell::child_cell_on_face(
2177 const unsigned int face,
2178 const unsigned int subface,
2179 const types::geometric_orientation combined_orientation) const
2180 {
2181 AssertIndexRange(face, n_faces());
2182 AssertIndexRange(subface, face_reference_cell(face).n_isotropic_children());
2183
2184 switch (this->kind)
2185 {
2186 case ReferenceCells::Vertex:
2187 case ReferenceCells::Line:
2188 {
2189 DEAL_II_NOT_IMPLEMENTED();
2190 break;
2191 }
2192 case ReferenceCells::Triangle:
2193 {
2194 static constexpr ndarray<unsigned int, 3, 2> subcells = {
2195 {{{0, 1}}, {{1, 2}}, {{2, 0}}}};
2196
2197 Assert(combined_orientation ==
2198 numbers::default_geometric_orientation ||
2199 combined_orientation == numbers::reverse_line_orientation,
2200 ExcInternalError());
2201 return subcells[face][combined_orientation ==
2202 numbers::default_geometric_orientation ?
2203 subface :
2204 1 - subface];
2205 }
2206 case ReferenceCells::Quadrilateral:
2207 {
2208 const auto [face_orientation, face_rotation, face_flip] =
2209 internal::split_face_orientation(combined_orientation);
2210
2211 return GeometryInfo<2>::child_cell_on_face(
2212 RefinementCase<2>(RefinementPossibilities<2>::isotropic_refinement),
2213 face,
2214 subface,
2215 face_orientation,
2216 face_flip,
2217 face_rotation);
2218 }
2219 case ReferenceCells::Tetrahedron:
2220 case ReferenceCells::Pyramid:
2221 case ReferenceCells::Wedge:
2222 {
2223 DEAL_II_NOT_IMPLEMENTED();
2224 break;
2225 }
2226 case ReferenceCells::Hexahedron:
2227 {
2228 const auto [face_orientation, face_rotation, face_flip] =
2229 internal::split_face_orientation(combined_orientation);
2230
2231 return GeometryInfo<3>::child_cell_on_face(
2232 RefinementCase<3>(RefinementPossibilities<3>::isotropic_refinement),
2233 face,
2234 subface,
2235 face_orientation,
2236 face_flip,
2237 face_rotation);
2238 }
2239 default:
2240 DEAL_II_NOT_IMPLEMENTED();
2241 }
2242
2243 return numbers::invalid_unsigned_int;
2244 }
2245
2246
2247
2248 inline std::array<unsigned int, 2>
2249 ReferenceCell::standard_vertex_to_face_and_vertex_index(
2250 const unsigned int vertex) const
2251 {
2252 AssertIndexRange(vertex, n_vertices());
2253 // Work around a GCC warning at higher optimization levels by making all of
2254 // these tables the same size
2255 constexpr unsigned int X = numbers::invalid_unsigned_int;
2256
2257 switch (this->kind)
2258 {
2259 case ReferenceCells::Vertex:
2260 case ReferenceCells::Line:
2261 DEAL_II_NOT_IMPLEMENTED();
2262 break;
2263 case ReferenceCells::Triangle:
2264 {
2265 static constexpr ndarray<unsigned int, 6, 2> table = {
2266 {{{0, 0}}, {{0, 1}}, {{1, 1}}, {{X, X}}, {{X, X}}, {{X, X}}}};
2267
2268 return table[vertex];
2269 }
2270 case ReferenceCells::Quadrilateral:
2271 {
2272 return GeometryInfo<2>::standard_quad_vertex_to_line_vertex_index(
2273 vertex);
2274 }
2275 case ReferenceCells::Tetrahedron:
2276 {
2277 static constexpr ndarray<unsigned int, 6, 2> table = {
2278 {{{0, 0}}, {{0, 1}}, {{0, 2}}, {{1, 2}}, {{X, X}}, {{X, X}}}};
2279
2280 return table[vertex];
2281 }
2282 case ReferenceCells::Pyramid:
2283 {
2284 static constexpr ndarray<unsigned int, 6, 2> table = {
2285 {{{0, 0}}, {{0, 1}}, {{0, 2}}, {{0, 3}}, {{1, 2}}, {{X, X}}}};
2286
2287 return table[vertex];
2288 }
2289 case ReferenceCells::Wedge:
2290 {
2291 static constexpr ndarray<unsigned int, 6, 2> table = {
2292 {{{0, 1}}, {{0, 0}}, {{0, 2}}, {{1, 0}}, {{1, 1}}, {{1, 2}}}};
2293
2294 return table[vertex];
2295 }
2296 case ReferenceCells::Hexahedron:
2297 {
2298 return GeometryInfo<3>::standard_hex_vertex_to_quad_vertex_index(
2299 vertex);
2300 }
2301 default:
2302 DEAL_II_NOT_IMPLEMENTED();
2303 }
2304
2305 return {};
2306 }
2307
2308
2309
2310 inline std::array<unsigned int, 2>
2311 ReferenceCell::standard_line_to_face_and_line_index(
2312 const unsigned int line) const
2313 {
2314 AssertIndexRange(line, n_lines());
2315
2316 switch (this->kind)
2317 {
2318 case ReferenceCells::Vertex:
2319 case ReferenceCells::Line:
2320 case ReferenceCells::Triangle:
2321 case ReferenceCells::Quadrilateral:
2322 {
2323 DEAL_II_NOT_IMPLEMENTED();
2324 break;
2325 }
2326 case ReferenceCells::Tetrahedron:
2327 {
2328 static const std::array<unsigned int, 2> table[6] = {
2329 {{0, 0}}, {{0, 1}}, {{0, 2}}, {{1, 1}}, {{1, 2}}, {{2, 1}}};
2330
2331 return table[line];
2332 }
2333 case ReferenceCells::Pyramid:
2334 {
2335 static const std::array<unsigned int, 2> table[8] = {{{0, 0}},
2336 {{0, 1}},
2337 {{0, 2}},
2338 {{0, 3}},
2339 {{1, 2}},
2340 {{2, 1}},
2341 {{1, 1}},
2342 {{2, 2}}};
2343
2344 return table[line];
2345 }
2346 case ReferenceCells::Wedge:
2347 {
2348 static const std::array<unsigned int, 2> table[9] = {{{0, 0}},
2349 {{0, 2}},
2350 {{0, 1}},
2351 {{1, 0}},
2352 {{1, 1}},
2353 {{1, 2}},
2354 {{2, 0}},
2355 {{2, 1}},
2356 {{3, 1}}};
2357
2358 return table[line];
2359 }
2360 case ReferenceCells::Hexahedron:
2361 {
2362 return GeometryInfo<3>::standard_hex_line_to_quad_line_index(line);
2363 }
2364 default:
2365 DEAL_II_NOT_IMPLEMENTED();
2366 }
2367
2368 return {};
2369 }
2370
2371
2372 inline unsigned int
2373 ReferenceCell::line_to_cell_vertices(const unsigned int line,
2374 const unsigned int vertex) const
2375 {
2376 AssertIndexRange(vertex, 2);
2377 AssertIndexRange(line, n_lines());
2378
2379 switch (this->kind)
2380 {
2381 case ReferenceCells::Vertex:
2382 case ReferenceCells::Line:
2383 return vertex;
2384 case ReferenceCells::Triangle:
2385 {
2386 static constexpr ndarray<unsigned int, 3, 2> table = {
2387 {{{0, 1}}, {{1, 2}}, {{2, 0}}}};
2388 return table[line][vertex];
2389 }
2390 case ReferenceCells::Quadrilateral:
2391 {
2392 static constexpr ndarray<unsigned int, 4, 2> table = {
2393 {{{0, 2}}, {{1, 3}}, {{0, 1}}, {{2, 3}}}};
2394 return table[line][vertex];
2395 }
2396 case ReferenceCells::Tetrahedron:
2397 {
2398 static constexpr ndarray<unsigned int, 6, 2> table = {
2399 {{{0, 1}}, {{1, 2}}, {{2, 0}}, {{0, 3}}, {{1, 3}}, {{2, 3}}}};
2400 return table[line][vertex];
2401 }
2402 case ReferenceCells::Pyramid:
2403 {
2404 static constexpr ndarray<unsigned int, 8, 2> table = {{{{0, 2}},
2405 {{1, 3}},
2406 {{0, 1}},
2407 {{2, 3}},
2408 {{4, 0}},
2409 {{1, 4}},
2410 {{2, 4}},
2411 {{4, 3}}}};
2412 return table[line][vertex];
2413 }
2414 case ReferenceCells::Wedge:
2415 {
2416 static constexpr ndarray<unsigned int, 9, 2> table = {{{{1, 0}},
2417 {{2, 1}},
2418 {{0, 2}},
2419 {{3, 4}},
2420 {{4, 5}},
2421 {{5, 3}},
2422 {{0, 3}},
2423 {{1, 4}},
2424 {{2, 5}}}};
2425 return table[line][vertex];
2426 }
2427 case ReferenceCells::Hexahedron:
2428 {
2429 // first four lines comprise the bottom face, next four are the top,
2430 // and the last four are 'bottom to top'
2431 static constexpr ndarray<unsigned int, 12, 2> table = {{{{0, 2}},
2432 {{1, 3}},
2433 {{0, 1}},
2434 {{2, 3}},
2435 {{4, 6}},
2436 {{5, 7}},
2437 {{4, 5}},
2438 {{6, 7}},
2439 {{0, 4}},
2440 {{1, 5}},
2441 {{2, 6}},
2442 {{3, 7}}}};
2443 return table[line][vertex];
2444 }
2445
2446 default:
2447 DEAL_II_NOT_IMPLEMENTED();
2448 }
2449
2450 return numbers::invalid_unsigned_int;
2451 }
2452
2453
2454 inline unsigned int
2455 ReferenceCell::face_to_cell_lines(
2456 const unsigned int face,
2457 const unsigned int line,
2458 const types::geometric_orientation combined_face_orientation) const
2459 {
2460 AssertIndexRange(face, n_faces());
2461 AssertIndexRange(line, face_reference_cell(face).n_lines());
2462
2463 static constexpr unsigned int X = numbers::invalid_unsigned_int;
2464
2465 switch (this->kind)
2466 {
2467 case ReferenceCells::Vertex:
2468 {
2469 DEAL_II_NOT_IMPLEMENTED();
2470 break;
2471 }
2472 case ReferenceCells::Line:
2473 {
2474 const auto [face_orientation, face_rotation, face_flip] =
2475 internal::split_face_orientation(combined_face_orientation);
2476
2477 return GeometryInfo<1>::face_to_cell_lines(
2478 face, line, face_orientation, face_flip, face_rotation);
2479 }
2480 case ReferenceCells::Triangle:
2481 {
2482 return face;
2483 }
2484 case ReferenceCells::Quadrilateral:
2485 {
2486 const auto [face_orientation, face_rotation, face_flip] =
2487 internal::split_face_orientation(combined_face_orientation);
2488
2489 return GeometryInfo<2>::face_to_cell_lines(
2490 face, line, face_orientation, face_flip, face_rotation);
2491 }
2492 case ReferenceCells::Tetrahedron:
2493 {
2494 static constexpr ndarray<unsigned int, 4, 3> table = {
2495 {{{0, 1, 2}}, {{0, 3, 4}}, {{2, 5, 3}}, {{1, 4, 5}}}};
2496
2497 return table[face][standard_to_real_face_line(
2498 line, face, combined_face_orientation)];
2499 }
2500 case ReferenceCells::Pyramid:
2501 {
2502 static constexpr ndarray<unsigned int, 5, 4> table = {
2503 {{{0, 1, 2, 3}},
2504 {{0, 6, 4, X}},
2505 {{1, 5, 7, X}},
2506 {{2, 4, 5, X}},
2507 {{3, 7, 6, X}}}};
2508
2509 return table[face][standard_to_real_face_line(
2510 line, face, combined_face_orientation)];
2511 }
2512 case ReferenceCells::Wedge:
2513 {
2514 static constexpr ndarray<unsigned int, 5, 4> table = {
2515 {{{0, 2, 1, X}},
2516 {{3, 4, 5, X}},
2517 {{6, 7, 0, 3}},
2518 {{7, 8, 1, 4}},
2519 {{8, 6, 5, 2}}}};
2520
2521 return table[face][standard_to_real_face_line(
2522 line, face, combined_face_orientation)];
2523 }
2524 case ReferenceCells::Hexahedron:
2525 {
2526 const auto [face_orientation, face_rotation, face_flip] =
2527 internal::split_face_orientation(combined_face_orientation);
2528
2529 return GeometryInfo<3>::face_to_cell_lines(
2530 face, line, face_orientation, face_flip, face_rotation);
2531 }
2532 default:
2533 DEAL_II_NOT_IMPLEMENTED();
2534 }
2535
2536 return numbers::invalid_unsigned_int;
2537 }
2538
2539
2540
2541 inline unsigned int
2542 ReferenceCell::face_to_cell_vertices(
2543 const unsigned int face,
2544 const unsigned int vertex,
2545 const types::geometric_orientation combined_face_orientation) const
2546 {
2547 AssertIndexRange(face, n_faces());
2548 AssertIndexRange(vertex, face_reference_cell(face).n_vertices());
2549 AssertIndexRange(combined_face_orientation, n_face_orientations(face));
2550
2551 switch (this->kind)
2552 {
2553 case ReferenceCells::Vertex:
2554 {
2555 DEAL_II_NOT_IMPLEMENTED();
2556 break;
2557 }
2558 case ReferenceCells::Line:
2559 {
2560 const auto [face_orientation, face_rotation, face_flip] =
2561 internal::split_face_orientation(combined_face_orientation);
2562
2563 return GeometryInfo<1>::face_to_cell_vertices(
2564 face, vertex, face_orientation, face_flip, face_rotation);
2565 }
2566 case ReferenceCells::Triangle:
2567 {
2568 static constexpr ndarray<unsigned int, 3, 2> table = {
2569 {{{0, 1}}, {{1, 2}}, {{2, 0}}}};
2570
2571 return table[face][combined_face_orientation ==
2572 numbers::default_geometric_orientation ?
2573 vertex :
2574 (1 - vertex)];
2575 }
2576 case ReferenceCells::Quadrilateral:
2577 {
2578 const auto [face_orientation, face_rotation, face_flip] =
2579 internal::split_face_orientation(combined_face_orientation);
2580
2581 return GeometryInfo<2>::face_to_cell_vertices(
2582 face, vertex, face_orientation, face_flip, face_rotation);
2583 }
2584 case ReferenceCells::Tetrahedron:
2585 {
2586 static constexpr ndarray<unsigned int, 4, 3> table = {
2587 {{{0, 1, 2}}, {{1, 0, 3}}, {{0, 2, 3}}, {{2, 1, 3}}}};
2588
2589 return table[face][standard_to_real_face_vertex(
2590 vertex, face, combined_face_orientation)];
2591 }
2592 case ReferenceCells::Pyramid:
2593 {
2594 constexpr auto X = numbers::invalid_unsigned_int;
2595 static constexpr ndarray<unsigned int, 5, 4> table = {
2596 {{{0, 1, 2, 3}},
2597 {{0, 2, 4, X}},
2598 {{3, 1, 4, X}},
2599 {{1, 0, 4, X}},
2600 {{2, 3, 4, X}}}};
2601
2602 return table[face][standard_to_real_face_vertex(
2603 vertex, face, combined_face_orientation)];
2604 }
2605 case ReferenceCells::Wedge:
2606 {
2607 constexpr auto X = numbers::invalid_unsigned_int;
2608 static constexpr ndarray<unsigned int, 6, 4> table = {
2609 {{{1, 0, 2, X}},
2610 {{3, 4, 5, X}},
2611 {{0, 1, 3, 4}},
2612 {{1, 2, 4, 5}},
2613 {{2, 0, 5, 3}}}};
2614
2615 return table[face][standard_to_real_face_vertex(
2616 vertex, face, combined_face_orientation)];
2617 }
2618 case ReferenceCells::Hexahedron:
2619 {
2620 const auto [face_orientation, face_rotation, face_flip] =
2621 internal::split_face_orientation(combined_face_orientation);
2622
2623 return GeometryInfo<3>::face_to_cell_vertices(
2624 face, vertex, face_orientation, face_flip, face_rotation);
2625 }
2626 default:
2627 DEAL_II_NOT_IMPLEMENTED();
2628 }
2629
2630 return numbers::invalid_unsigned_int;
2631 }
2632
2633
2634
2635 template <int dim>
2636 Point<dim>
2637 ReferenceCell::face_vertex_location(const unsigned int face,
2638 const unsigned int vertex) const
2639 {
2640 Assert(dim == get_dimension(),
2641 ExcMessage("You can only call this function with arguments for "
2642 "which 'dim' equals the dimension of the space in which "
2643 "the current reference cell lives. You have dim=" +
2644 std::to_string(dim) + " but the reference cell is " +
2645 std::to_string(get_dimension()) + " dimensional."));
2646 return this->template vertex<dim>(face_to_cell_vertices(
2647 face, vertex, numbers::default_geometric_orientation));
2648 }
2649
2650
2651
2652 inline unsigned int
2653 ReferenceCell::standard_to_real_face_vertex(
2654 const unsigned int vertex,
2655 const unsigned int face,
2656 const types::geometric_orientation face_orientation) const
2657 {
2658 AssertIndexRange(face, n_faces());
2659 AssertIndexRange(vertex, face_reference_cell(face).n_vertices());
2660
2661 switch (this->kind)
2662 {
2663 case ReferenceCells::Vertex:
2664 DEAL_II_NOT_IMPLEMENTED();
2665 break;
2666 case ReferenceCells::Line:
2667 Assert(face_orientation == numbers::default_geometric_orientation,
2668 ExcMessage(
2669 "In 1D, all faces must have the default orientation."));
2670 return vertex;
2671 case ReferenceCells::Triangle:
2672 case ReferenceCells::Quadrilateral:
2673 return line_vertex_permutations[face_orientation][vertex];
2674 case ReferenceCells::Tetrahedron:
2675 return triangle_vertex_permutations[face_orientation][vertex];
2676 case ReferenceCells::Pyramid:
2677 // face 0 is a quadrilateral
2678 if (face == 0)
2679 return quadrilateral_vertex_permutations[face_orientation][vertex];
2680 else
2681 return triangle_vertex_permutations[face_orientation][vertex];
2682 case ReferenceCells::Wedge:
2683 // faces 0 and 1 are triangles
2684 if (face > 1)
2685 return quadrilateral_vertex_permutations[face_orientation][vertex];
2686 else
2687 return triangle_vertex_permutations[face_orientation][vertex];
2688 case ReferenceCells::Hexahedron:
2689 return quadrilateral_vertex_permutations[face_orientation][vertex];
2690 default:
2691 DEAL_II_NOT_IMPLEMENTED();
2692 }
2693
2694 DEAL_II_NOT_IMPLEMENTED();
2695 return numbers::invalid_unsigned_int;
2696 }
2697
2698
2699
2700 inline unsigned int
2701 ReferenceCell::standard_to_real_face_line(
2702 const unsigned int line,
2703 const unsigned int face,
2704 const types::geometric_orientation combined_face_orientation) const
2705 {
2706 AssertIndexRange(face, n_faces());
2707 AssertIndexRange(line, face_reference_cell(face).n_lines());
2708
2709 static constexpr ndarray<unsigned int, 6, 3> triangle_table = {{{{0, 1, 2}},
2710 {{2, 1, 0}},
2711 {{2, 0, 1}},
2712 {{1, 0, 2}},
2713 {{1, 2, 0}},
2714 {{0, 2, 1}}}};
2715
2716
2717 switch (this->kind)
2718 {
2719 case ReferenceCells::Vertex:
2720 case ReferenceCells::Line:
2721 case ReferenceCells::Triangle:
2722 case ReferenceCells::Quadrilateral:
2723 DEAL_II_NOT_IMPLEMENTED();
2724 break;
2725 case ReferenceCells::Tetrahedron:
2726 return triangle_table[combined_face_orientation][line];
2727 case ReferenceCells::Pyramid:
2728 if (face == 0) // The quadrilateral face
2729 {
2730 const auto [face_orientation, face_rotation, face_flip] =
2731 internal::split_face_orientation(combined_face_orientation);
2732
2733 return GeometryInfo<3>::standard_to_real_face_line(line,
2734 face_orientation,
2735 face_flip,
2736 face_rotation);
2737 }
2738 else // One of the triangular faces
2739 {
2740 return triangle_table[combined_face_orientation][line];
2741 }
2742 case ReferenceCells::Wedge:
2743 if (face > 1) // One of the quadrilateral faces
2744 {
2745 const auto [face_orientation, face_rotation, face_flip] =
2746 internal::split_face_orientation(combined_face_orientation);
2747
2748 return GeometryInfo<3>::standard_to_real_face_line(line,
2749 face_orientation,
2750 face_flip,
2751 face_rotation);
2752 }
2753 else // One of the triangular faces
2754 return triangle_table[combined_face_orientation][line];
2755 case ReferenceCells::Hexahedron:
2756 {
2757 static constexpr ndarray<unsigned int, 8, 4> table = {{
2758 {{0, 1, 2, 3}},
2759 {{2, 3, 0, 1}},
2760 {{3, 2, 0, 1}},
2761 {{0, 1, 3, 2}},
2762 {{1, 0, 3, 2}},
2763 {{3, 2, 1, 0}},
2764 {{2, 3, 1, 0}},
2765 {{1, 0, 2, 3}},
2766 }};
2767 return table[combined_face_orientation][line];
2768 }
2769 default:
2770 DEAL_II_NOT_IMPLEMENTED();
2771 }
2772
2773 return numbers::invalid_unsigned_int;
2774 }
2775
2776
2777
2778 namespace ReferenceCells
2779 {
2780 template <int dim>
2781 inline constexpr const ReferenceCell &
2782 get_simplex()
2783 {
2784 switch (dim)
2785 {
2786 case 0:
2787 return ReferenceCells::Vertex;
2788 case 1:
2789 return ReferenceCells::Line;
2790 case 2:
2791 return ReferenceCells::Triangle;
2792 case 3:
2793 return ReferenceCells::Tetrahedron;
2794 default:
2795 DEAL_II_NOT_IMPLEMENTED();
2796 }
2797 return ReferenceCells::Invalid;
2798 }
2799
2800
2801
2802 template <int dim>
2803 inline constexpr const ReferenceCell &
2804 get_hypercube()
2805 {
2806 switch (dim)
2807 {
2808 case 0:
2809 return ReferenceCells::Vertex;
2810 case 1:
2811 return ReferenceCells::Line;
2812 case 2:
2813 return ReferenceCells::Quadrilateral;
2814 case 3:
2815 return ReferenceCells::Hexahedron;
2816 default:
2817 DEAL_II_NOT_IMPLEMENTED();
2818 }
2819 return ReferenceCells::Invalid;
2820 }
2821
2822
2823
2824 template <int structdim>
2825 inline constexpr unsigned int
2826 max_n_vertices()
2827 {
2828 return GeometryInfo<structdim>::vertices_per_cell;
2829 }
2830
2831
2832
2833 template <int structdim>
2834 inline constexpr unsigned int
2835 max_n_lines()
2836 {
2837 return GeometryInfo<structdim>::lines_per_cell;
2838 }
2839
2840
2841
2842 template <int structdim>
2843 inline constexpr unsigned int
2844 max_n_faces()
2845 {
2846 return GeometryInfo<structdim>::faces_per_cell;
2847 }
2848 } // namespace ReferenceCells
2849
2850
2851 inline ReferenceCell
2852 ReferenceCell::n_vertices_to_type(const int dim, const unsigned int n_vertices)
2853 {
2854 AssertIndexRange(dim, 4);
2855 AssertIndexRange(n_vertices, 9);
2856
2857 const auto X = ReferenceCells::Invalid;
2858 static const ndarray<ReferenceCell, 4, 9> table = {
2859 {// dim 0
2860 {{X, ReferenceCells::Vertex, X, X, X, X, X, X, X}},
2861 // dim 1
2862 {{X, X, ReferenceCells::Line, X, X, X, X, X, X}},
2863 // dim 2
2864 {{X,
2865 X,
2866 X,
2867 ReferenceCells::Triangle,
2868 ReferenceCells::Quadrilateral,
2869 X,
2870 X,
2871 X,
2872 X}},
2873 // dim 3
2874 {{X,
2875 X,
2876 X,
2877 X,
2878 ReferenceCells::Tetrahedron,
2879 ReferenceCells::Pyramid,
2880 ReferenceCells::Wedge,
2881 X,
2882 ReferenceCells::Hexahedron}}}};
2883 Assert(table[dim][n_vertices] != ReferenceCells::Invalid,
2884 ExcMessage("The combination of dim = " + std::to_string(dim) +
2885 " and n_vertices = " + std::to_string(n_vertices) +
2886 " does not correspond to a known reference cell type."));
2887 return table[dim][n_vertices];
2888 }
2889
2890
2891
2892 template <int dim>
2893 inline double
2894 ReferenceCell::d_linear_shape_function(const Point<dim> &xi,
2895 const unsigned int i) const
2896 {
2897 Assert(dim == get_dimension(),
2898 ExcMessage("You can only call this function with arguments for "
2899 "which 'dim' equals the dimension of the space in which "
2900 "the current reference cell lives. You have dim=" +
2901 std::to_string(dim) + " but the reference cell is " +
2902 std::to_string(get_dimension()) + " dimensional."));
2903 AssertIndexRange(i, n_vertices());
2904 switch (this->kind)
2905 {
2906 case ReferenceCells::Vertex:
2907 return 1.0;
2908 case ReferenceCells::Line:
2909 case ReferenceCells::Quadrilateral:
2910 case ReferenceCells::Hexahedron:
2911 if constexpr (dim > 0)
2912 return GeometryInfo<dim>::d_linear_shape_function(xi, i);
2913 DEAL_II_ASSERT_UNREACHABLE();
2914 // see also BarycentricPolynomials<2>::compute_value
2915 case ReferenceCells::Triangle:
2916 {
2917 switch (i)
2918 {
2919 case 0:
2920 return 1.0 - xi[std::min(0, dim - 1)] -
2921 xi[std::min(1, dim - 1)];
2922 case 1:
2923 return xi[std::min(0, dim - 1)];
2924 case 2:
2925 return xi[std::min(1, dim - 1)];
2926 default:
2927 DEAL_II_ASSERT_UNREACHABLE();
2928 }
2929 }
2930 // see also BarycentricPolynomials<3>::compute_value
2931 case ReferenceCells::Tetrahedron:
2932 {
2933 switch (i)
2934 {
2935 case 0:
2936 return 1.0 - xi[std::min(0, dim - 1)] -
2937 xi[std::min(1, dim - 1)] - xi[std::min(2, dim - 1)];
2938 case 1:
2939 return xi[std::min(0, dim - 1)];
2940 case 2:
2941 return xi[std::min(1, dim - 1)];
2942 case 3:
2943 return xi[std::min(2, dim - 1)];
2944 default:
2945 DEAL_II_ASSERT_UNREACHABLE();
2946 }
2947 }
2948 // see also ScalarLagrangePolynomialPyramid::compute_value()
2949 case ReferenceCells::Pyramid:
2950 {
2951 const double Q14 = 0.25;
2952
2953 const double r = xi[std::min(0, dim - 1)];
2954 const double s = xi[std::min(1, dim - 1)];
2955 const double t = xi[std::min(2, dim - 1)];
2956
2957 const double ratio =
2958 (std::fabs(t - 1.0) > 1.0e-14 ? (r * s * t) / (1.0 - t) : 0.0);
2959
2960 if (i == 0)
2961 return Q14 * ((1.0 - r) * (1.0 - s) - t + ratio);
2962 if (i == 1)
2963 return Q14 * ((1.0 + r) * (1.0 - s) - t - ratio);
2964 if (i == 2)
2965 return Q14 * ((1.0 - r) * (1.0 + s) - t - ratio);
2966 if (i == 3)
2967 return Q14 * ((1.0 + r) * (1.0 + s) - t + ratio);
2968 else
2969 return t;
2970 }
2971 // see also ScalarLagrangePolynomialWedge::compute_value()
2972 case ReferenceCells::Wedge:
2973 return ReferenceCell(ReferenceCells::Triangle)
2974 .d_linear_shape_function<2>(Point<2>(xi[std::min(0, dim - 1)],
2975 xi[std::min(1, dim - 1)]),
2976 i % 3) *
2977 ReferenceCell(ReferenceCells::Line)
2978 .d_linear_shape_function<1>(Point<1>(xi[std::min(2, dim - 1)]),
2979 i / 3);
2980 default:
2981 DEAL_II_NOT_IMPLEMENTED();
2982 }
2983
2984 DEAL_II_ASSERT_UNREACHABLE();
2985 return 0.0;
2986 }
2987
2988
2989
2990 template <int dim>
2991 inline Tensor<1, dim>
2992 ReferenceCell::d_linear_shape_function_gradient(const Point<dim> &xi,
2993 const unsigned int i) const
2994 {
2995 Assert(dim == get_dimension(),
2996 ExcMessage("You can only call this function with arguments for "
2997 "which 'dim' equals the dimension of the space in which "
2998 "the current reference cell lives. You have dim=" +
2999 std::to_string(dim) + " but the reference cell is " +
3000 std::to_string(get_dimension()) + " dimensional."));
3001 switch (this->kind)
3002 {
3003 case ReferenceCells::Vertex:
3004 case ReferenceCells::Line:
3005 case ReferenceCells::Quadrilateral:
3006 case ReferenceCells::Hexahedron:
3007 return GeometryInfo<dim>::d_linear_shape_function_gradient(xi, i);
3008 // see also BarycentricPolynomials<2>::compute_grad()
3009 case ReferenceCells::Triangle:
3010 switch (i)
3011 {
3012 case 0:
3013 return Point<dim>(-1.0, -1.0);
3014 case 1:
3015 return Point<dim>(+1.0, +0.0);
3016 case 2:
3017 return Point<dim>(+0.0, +1.0);
3018 default:
3019 DEAL_II_ASSERT_UNREACHABLE();
3020 }
3021 default:
3022 DEAL_II_NOT_IMPLEMENTED();
3023 }
3024
3025 return Point<dim>(+0.0, +0.0, +0.0);
3026 }
3027
3028
3029
3030 inline double
3031 ReferenceCell::volume() const
3032 {
3033 switch (this->kind)
3034 {
3035 case ReferenceCells::Vertex:
3036 return 1;
3037 case ReferenceCells::Line:
3038 return 1;
3039 case ReferenceCells::Triangle:
3040 return 1. / 2.;
3041 case ReferenceCells::Quadrilateral:
3042 return 1;
3043 case ReferenceCells::Tetrahedron:
3044 return 1. / 6.;
3045 case ReferenceCells::Pyramid:
3046 return 4. / 3.;
3047 case ReferenceCells::Wedge:
3048 return 1. / 2.;
3049 case ReferenceCells::Hexahedron:
3050 return 1;
3051 default:
3052 DEAL_II_NOT_IMPLEMENTED();
3053 }
3054
3055 return 0.0;
3056 }
3057
3058
3059
3060 inline double
3061 ReferenceCell::face_measure(const unsigned int face_no) const
3062 {
3063 AssertIndexRange(face_no, n_faces());
3064 constexpr double X = std::numeric_limits<double>::signaling_NaN();
3065
3066 static const std::array<double, 5> tri_faces{
3067 {1.0, std::sqrt(2.0), 1.0, X, X}};
3068 static const std::array<double, 5> tet_faces{
3069 {0.5, 0.5, 0.5, std::sqrt(3.0) / 2.0, X}};
3070 static const std::array<double, 5> pyramid_faces{
3071 {4, std::sqrt(2.0), std::sqrt(2.0), std::sqrt(2.0), std::sqrt(2.0)}};
3072 static const std::array<double, 5> wedge_faces{
3073 {0.5, 0.5, 1.0, std::sqrt(2.0), 1.0}};
3074
3075 switch (this->kind)
3076 {
3077 case ReferenceCells::Vertex:
3078 case ReferenceCells::Line:
3079 case ReferenceCells::Quadrilateral:
3080 case ReferenceCells::Hexahedron:
3081 return 1.0;
3082 case ReferenceCells::Triangle:
3083 return tri_faces[face_no];
3084 case ReferenceCells::Tetrahedron:
3085 return tet_faces[face_no];
3086 case ReferenceCells::Pyramid:
3087 return pyramid_faces[face_no];
3088 case ReferenceCells::Wedge:
3089 return wedge_faces[face_no];
3090 }
3091 DEAL_II_ASSERT_UNREACHABLE();
3092 return X;
3093 }
3094
3095
3096
3097 template <int dim>
3098 inline Point<dim>
3099 ReferenceCell::barycenter() const
3100 {
3101 Assert(dim == get_dimension(),
3102 ExcMessage("You can only call this function with arguments for "
3103 "which 'dim' equals the dimension of the space in which "
3104 "the current reference cell lives. You have dim=" +
3105 std::to_string(dim) + " but the reference cell is " +
3106 std::to_string(get_dimension()) + " dimensional."));
3107
3108 switch (this->kind)
3109 {
3110 case ReferenceCells::Vertex:
3111 return Point<dim>();
3112 case ReferenceCells::Line:
3113 return Point<dim>(1. / 2.);
3114 case ReferenceCells::Triangle:
3115 return Point<dim>(1. / 3., 1. / 3.);
3116 case ReferenceCells::Quadrilateral:
3117 return Point<dim>(1. / 2., 1. / 2.);
3118 case ReferenceCells::Tetrahedron:
3119 return Point<dim>(1. / 4., 1. / 4., 1. / 4.);
3120 case ReferenceCells::Pyramid:
3121 return Point<dim>(0, 0, 1. / 4.);
3122 case ReferenceCells::Wedge:
3123 return Point<dim>(1. / 3, 1. / 3, 1. / 2.);
3124 case ReferenceCells::Hexahedron:
3125 return Point<dim>(1. / 2., 1. / 2., 1. / 2.);
3126 default:
3127 DEAL_II_NOT_IMPLEMENTED();
3128 }
3129
3130 return Point<dim>();
3131 }
3132
3133
3134
3135 template <int dim>
3136 inline bool
3137 ReferenceCell::contains_point(const Point<dim> &p, const double tolerance) const
3138 {
3139 Assert(dim == get_dimension(),
3140 ExcMessage("You can only call this function with arguments for "
3141 "which 'dim' equals the dimension of the space in which "
3142 "the current reference cell lives. You have dim=" +
3143 std::to_string(dim) + " but the reference cell is " +
3144 std::to_string(get_dimension()) + " dimensional."));
3145
3146 // Introduce abbreviations to silence compiler warnings about invalid
3147 // array accesses (that can't happen, of course, but the compiler
3148 // doesn't know that).
3149 constexpr unsigned int x_coordinate = 0;
3150 constexpr unsigned int y_coordinate = (dim >= 2 ? 1 : 0);
3151 constexpr unsigned int z_coordinate = (dim >= 3 ? 2 : 0);
3152
3153 switch (this->kind)
3154 {
3155 case ReferenceCells::Vertex:
3156 {
3157 // Vertices are special cases in that they do not actually
3158 // have coordinates. Error out if this function is called
3159 // with a vertex:
3160 Assert(false,
3161 ExcMessage("Vertices are zero-dimensional objects and "
3162 "as a consequence have no coordinates. You "
3163 "cannot meaningfully ask whether a point is "
3164 "inside a vertex (within a certain tolerance) "
3165 "without coordinate values."));
3166 return false;
3167 }
3168 case ReferenceCells::Line:
3169 case ReferenceCells::Quadrilateral:
3170 case ReferenceCells::Hexahedron:
3171 {
3172 for (unsigned int d = 0; d < dim; ++d)
3173 if ((p[d] < -tolerance) || (p[d] > 1 + tolerance))
3174 return false;
3175 return true;
3176 }
3177 case ReferenceCells::Triangle:
3178 case ReferenceCells::Tetrahedron:
3179 {
3180 // First make sure that we are in the first quadrant or octant
3181 for (unsigned int d = 0; d < dim; ++d)
3182 if (p[d] < -tolerance)
3183 return false;
3184
3185 // Now we also need to make sure that we are below the diagonal line
3186 // or plane that delineates the simplex. This diagonal is given by
3187 // sum(p[d])<=1, and a diagonal a distance eps away is given by
3188 // sum(p[d])<=1+eps*sqrt(d). (For example, the point at (1,1) is a
3189 // distance of 1/sqrt(2) away from the diagonal. That is, its
3190 // sum satisfies
3191 // sum(p[d]) = 2 <= 1 + (1/sqrt(2)) * sqrt(2)
3192 // in other words, it satisfies the predicate with eps=1/sqrt(2).)
3193 double sum = 0;
3194 for (unsigned int d = 0; d < dim; ++d)
3195 sum += p[d];
3196 return (sum <= 1 + tolerance * std::sqrt(1. * dim));
3197 }
3198 case ReferenceCells::Pyramid:
3199 {
3200 // A pyramid only lives in the upper half-space:
3201 if (p[z_coordinate] < -tolerance)
3202 return false;
3203
3204 // It also only lives in the space below z=1:
3205 if (p[z_coordinate] > 1 + tolerance)
3206 return false;
3207
3208 // Within what's left of the space, a pyramid is a cone that tapers
3209 // towards the top. First compute the distance of the point to the
3210 // axis in the max norm (this is the right norm because the vertices
3211 // of the pyramid are at points +/-1, +/-1):
3212 const double distance_from_axis =
3213 std::max(std::fabs(p[x_coordinate]), std::fabs(p[y_coordinate]));
3214
3215 // We are inside the pyramid if the distance from the axis is less
3216 // than (1-z)
3217 return (distance_from_axis <= 1 + tolerance - p[z_coordinate]);
3218 }
3219 case ReferenceCells::Wedge:
3220 {
3221 // The wedge we use is a triangle extruded into the third
3222 // dimension by one unit. So we can use the same logic as for
3223 // triangles above (i.e., for the simplex above, using dim==2)
3224 // and then check the third dimension separately.
3225
3226 if ((p[x_coordinate] < -tolerance) || (p[y_coordinate] < -tolerance))
3227 return false;
3228
3229 const double sum = p[x_coordinate] + p[y_coordinate];
3230 if (sum > 1 + tolerance * std::sqrt(2.0))
3231 return false;
3232
3233 if (p[z_coordinate] < -tolerance)
3234 return false;
3235 if (p[z_coordinate] > 1 + tolerance)
3236 return false;
3237
3238 return true;
3239 }
3240 default:
3241 DEAL_II_NOT_IMPLEMENTED();
3242 }
3243
3244 return false;
3245 }
3246
3247
3248
3249 template <int dim>
3250 inline Tensor<1, dim>
3251 ReferenceCell::unit_tangential_vectors(const unsigned int face_no,
3252 const unsigned int i) const
3253 {
3254 return face_tangent_vector<dim>(face_no, i);
3255 }
3256
3257
3258
3259 template <int dim>
3260 inline Tensor<1, dim>
3261 ReferenceCell::face_tangent_vector(const unsigned int face_no,
3262 const unsigned int i) const
3263 {
3264 AssertIndexRange(face_no, n_faces());
3265 Assert(dim == get_dimension(),
3266 ExcMessage("You can only call this function with arguments for "
3267 "which 'dim' equals the dimension of the space in which "
3268 "the current reference cell lives. You have dim=" +
3269 std::to_string(dim) + " but the reference cell is " +
3270 std::to_string(get_dimension()) + " dimensional."));
3271
3272 // Simplify the 1d case by setting tangents (which are used for boundary forms
3273 // and thus Jacobians) equal to the unit vector
3274 if constexpr (dim == 1)
3275 {
3276 return Tensor<1, dim>{{1.0}};
3277 }
3278
3279 AssertIndexRange(i, dim - 1);
3280
3281 switch (this->kind)
3282 {
3283 case ReferenceCells::Vertex:
3284 case ReferenceCells::Line:
3285 case ReferenceCells::Quadrilateral:
3286 case ReferenceCells::Hexahedron:
3287 AssertIndexRange(face_no, GeometryInfo<dim>::faces_per_cell);
3288 return GeometryInfo<dim>::unit_tangential_vectors[face_no][i];
3289 case ReferenceCells::Triangle:
3290 {
3291 AssertIndexRange(face_no, 3);
3292 static const std::array<Tensor<1, dim>, 3> table = {
3293 {Point<dim>(1, 0),
3294 Point<dim>(-std::sqrt(0.5), +std::sqrt(0.5)),
3295 Point<dim>(0, -1)}};
3296
3297 return table[face_no];
3298 }
3299 case ReferenceCells::Tetrahedron:
3300 {
3301 AssertIndexRange(face_no, 4);
3302 static const ndarray<Tensor<1, dim>, 4, 2> table = {
3303 {{{Point<dim>(0, 1, 0), Point<dim>(1, 0, 0)}},
3304 {{Point<dim>(1, 0, 0), Point<dim>(0, 0, 1)}},
3305 {{Point<dim>(0, 0, 1), Point<dim>(0, 1, 0)}},
3306 {{Point<dim>(-std::pow(1.0 / 3.0, 1.0 / 4.0),
3307 +std::pow(1.0 / 3.0, 1.0 / 4.0),
3308 0),
3309 Point<dim>(-std::pow(1.0 / 3.0, 1.0 / 4.0),
3310 0,
3311 +std::pow(1.0 / 3.0, 1.0 / 4.0))}}}};
3312
3313 return table[face_no][i];
3314 }
3315 case ReferenceCells::Pyramid:
3316 {
3317 AssertIndexRange(face_no, 5);
3318 static const ndarray<Tensor<1, dim>, 5, 2> table = {
3319 {{{Point<dim>(0, 1, 0), Point<dim>(1, 0, 0)}},
3320 {{Point<dim>(+1.0 / std::sqrt(2.0), 0, +1.0 / std::sqrt(2.0)),
3321 Point<dim>(0, 1, 0)}},
3322 {{Point<dim>(+1.0 / std::sqrt(2.0), 0, -1.0 / std::sqrt(2.0)),
3323 Point<dim>(0, 1, 0)}},
3324 {{Point<dim>(1, 0, 0),
3325 Point<dim>(0, +1.0 / std::sqrt(2.0), +1.0 / std::sqrt(2.0))}},
3326 {{Point<dim>(1, 0, 0),
3327 Point<dim>(0, +1.0 / std::sqrt(2.0), -1.0 / std::sqrt(2.0))}}}};
3328
3329 return table[face_no][i];
3330 }
3331 case ReferenceCells::Wedge:
3332 {
3333 AssertIndexRange(face_no, 5);
3334 static const ndarray<Tensor<1, dim>, 5, 2> table = {
3335 {{{Point<dim>(0, 1, 0), Point<dim>(1, 0, 0)}},
3336 {{Point<dim>(1, 0, 0), Point<dim>(0, 1, 0)}},
3337 {{Point<dim>(1, 0, 0), Point<dim>(0, 0, 1)}},
3338 {{Point<dim>(-1 / std::sqrt(2.0), +1 / std::sqrt(2.0), 0),
3339 Point<dim>(0, 0, 1)}},
3340 {{Point<dim>(0, 0, 1), Point<dim>(0, 1, 0)}}}};
3341
3342 return table[face_no][i];
3343 }
3344 default:
3345 DEAL_II_NOT_IMPLEMENTED();
3346 }
3347
3348
3349 return {};
3350 }
3351
3352
3353
3354 template <int dim>
3355 inline Tensor<1, dim>
3356 ReferenceCell::unit_normal_vectors(const unsigned int face_no) const
3357 {
3358 return face_normal_vector<dim>(face_no);
3359 }
3360
3361
3362
3363 template <int dim>
3364 inline Tensor<1, dim>
3365 ReferenceCell::face_normal_vector(const unsigned int face_no) const
3366 {
3367 Assert(dim == get_dimension(),
3368 ExcMessage("You can only call this function with arguments for "
3369 "which 'dim' equals the dimension of the space in which "
3370 "the current reference cell lives. You have dim=" +
3371 std::to_string(dim) + " but the reference cell is " +
3372 std::to_string(get_dimension()) + " dimensional."));
3373
3374 if (is_hyper_cube())
3375 {
3376 AssertIndexRange(face_no, GeometryInfo<dim>::faces_per_cell);
3377 return GeometryInfo<dim>::unit_normal_vector[face_no];
3378 }
3379 else if (dim == 2)
3380 {
3381 Assert(*this == ReferenceCells::Triangle, ExcInternalError());
3382
3383 // Return the rotated vector
3384 return cross_product_2d(face_tangent_vector<dim>(face_no, 0));
3385 }
3386 else if (dim == 3)
3387 {
3388 return cross_product_3d(face_tangent_vector<dim>(face_no, 0),
3389 face_tangent_vector<dim>(face_no, 1));
3390 }
3391
3392 DEAL_II_NOT_IMPLEMENTED();
3393
3394 return {};
3395 }
3396
3397
3398
3399 inline unsigned int
3400 ReferenceCell::n_face_orientations(const unsigned int face_no) const
3401 {
3402 AssertIndexRange(face_no, n_faces());
3403 if (get_dimension() == 1)
3404 return 1;
3405 if (get_dimension() == 2)
3406 return 2;
3407 else if (face_reference_cell(face_no) == ReferenceCells::Quadrilateral)
3408 return 8;
3409 else if (face_reference_cell(face_no) == ReferenceCells::Triangle)
3410 return 6;
3411
3412 DEAL_II_ASSERT_UNREACHABLE();
3413 return numbers::invalid_unsigned_int;
3414 }
3415
3416
3417
3418 inline types::geometric_orientation
3419 ReferenceCell::standard_vs_true_line_orientation(
3420 const unsigned int line,
3421 const unsigned int face,
3422 const types::geometric_orientation combined_face_orientation,
3423 const types::geometric_orientation line_orientation) const
3424 {
3425 return face_to_cell_line_orientation(line,
3426 face,
3427 combined_face_orientation,
3428 line_orientation);
3429 }
3430
3431
3432 inline types::geometric_orientation
3433 ReferenceCell::face_to_cell_line_orientation(
3434 const unsigned int face_line_no,
3435 const unsigned int face_no,
3436 const types::geometric_orientation combined_face_orientation,
3437 const types::geometric_orientation line_orientation) const
3438 {
3439 constexpr auto D = numbers::default_geometric_orientation;
3440 constexpr auto R = numbers::reverse_line_orientation;
3441 if (*this == ReferenceCells::Hexahedron)
3442 {
3443 static constexpr dealii::ndarray<types::geometric_orientation, 2, 8>
3444 table{{{{D, D, D, R, R, R, R, D}}, {{D, D, R, D, R, R, D, R}}}};
3445 // We use face_line_no / 2 here since lines i and i + 1 are parallel and,
3446 // on a given face, have the same relative orientations.
3447 const bool match =
3448 line_orientation == table[face_line_no / 2][combined_face_orientation];
3449
3450 return match ? numbers::default_geometric_orientation :
3451 numbers::reverse_line_orientation;
3452 }
3453 else if (*this == ReferenceCells::Tetrahedron)
3454 {
3455 static constexpr unsigned int X = numbers::invalid_unsigned_int;
3456 static constexpr dealii::ndarray<unsigned int, 4, 3> combined_lines{
3457 {{{0, 0, 0}}, {{X, 0, 1}}, {{X, 0, X}}, {{X, X, X}}}};
3458
3459 const auto combined_line = combined_lines[face_no][face_line_no];
3460
3461 Assert(combined_line != X,
3462 ExcMessage(
3463 "This function can only be called for following face-line "
3464 "combinations: (0,0), (0,1), (0,2), (1,1), (1,2), (2,1),"));
3465
3466 static constexpr dealii::ndarray<types::geometric_orientation, 2, 6>
3467 table{{{{D, R, D, R, D, R}}, {{R, D, R, D, R, D}}}};
3468
3469 const bool match =
3470 line_orientation == table[combined_line][combined_face_orientation];
3471
3472 return match ? numbers::default_geometric_orientation :
3473 numbers::reverse_line_orientation;
3474 }
3475 else
3476 // TODO: This might actually be wrong for some of the other
3477 // kinds of objects. We should check this
3478 return numbers::default_geometric_orientation;
3479 }
3480
3481
3482
3483 namespace internal
3484 {
3485 template <typename T>
3486 class NoPermutation : public dealii::ExceptionBase
3487 {
3488 public:
3489 /**
3490 * Constructor.
3491 */
3492 NoPermutation(const ReferenceCell &entity_type,
3493 const ArrayView<const T> &vertices_0,
3494 const ArrayView<const T> &vertices_1)
3495 : entity_type(entity_type)
3496 , vertices_0(vertices_0)
3497 , vertices_1(vertices_1)
3498 {
3499 Assert(vertices_0.size() >= entity_type.n_vertices(), ExcInternalError());
3500 Assert(vertices_1.size() >= entity_type.n_vertices(), ExcInternalError());
3501 }
3502
3503 /**
3504 * Destructor.
3505 */
3506 virtual ~NoPermutation() noexcept override = default;
3507
3508 /**
3509 * Print error message to @p out.
3510 */
3511 virtual void
3512 print_info(std::ostream &out) const override
3513 {
3514 out << '[';
3515
3516 const unsigned int n_vertices = entity_type.n_vertices();
3517
3518 for (unsigned int i = 0; i < n_vertices; ++i)
3519 {
3520 out << vertices_0[i];
3521 if (i + 1 != n_vertices)
3522 out << ',';
3523 }
3524
3525 out << "] is not a valid permutation of [";
3526
3527 for (unsigned int i = 0; i < n_vertices; ++i)
3528 {
3529 out << vertices_1[i];
3530 if (i + 1 != n_vertices)
3531 out << ',';
3532 }
3533
3534 out << "]." << std::endl;
3535 }
3536
3537 /**
3538 * Entity type.
3539 */
3540 const ReferenceCell entity_type;
3541
3542 /**
3543 * First set of values.
3544 */
3545 const ArrayView<const T> vertices_0;
3546
3547 /**
3548 * Second set of values.
3549 */
3550 const ArrayView<const T> vertices_1;
3551 };
3552
3553 /**
3554 * This exception is raised whenever the types of two reference cell objects
3555 * were assumed to be equal, but were not.
3556 *
3557 * Parameters to the constructor are the first and second reference cells,
3558 * both of type <tt>ReferenceCell</tt>.
3559 */
3560 DeclException2(
3561 ExcNonMatchingReferenceCellTypes,
3562 ReferenceCell,
3563 ReferenceCell,
3564 << "The reference-cell type used on this cell (" << arg1.to_string()
3565 << ") does not match the reference-cell type of the finite element "
3566 << "associated with this cell (" << arg2.to_string() << "). "
3567 << "Did you accidentally use simplex elements on hypercube meshes "
3568 << "(or the other way around), or are you using a mixed mesh and "
3569 << "assigned a simplex element to a hypercube cell (or the other "
3570 << "way around) via the active_fe_index?");
3571 } // namespace internal
3572
3573
3574
3575 template <typename T, std::size_t N>
3576 inline types::geometric_orientation
3577 ReferenceCell::compute_orientation(const std::array<T, N> &vertices_0,
3578 const std::array<T, N> &vertices_1) const
3579 {
3580 Assert(N >= n_vertices(),
3581 ExcMessage("The number of array elements must be equal to or "
3582 "greater than the number of vertices of the cell "
3583 "referenced by this object."));
3584
3585 // Call the non-deprecated function, taking care of calling it only with
3586 // those array elements that we actually care about (see the note
3587 // in the documentation about the arguments potentially being
3588 // larger arrays than necessary).
3589 return get_combined_orientation(
3590 make_array_view(vertices_0.begin(), vertices_0.begin() + n_vertices()),
3591 make_array_view(vertices_1.begin(), vertices_1.begin() + n_vertices()));
3592 }
3593
3594
3595
3596 template <typename T>
3597 types::geometric_orientation
3598 ReferenceCell::get_combined_orientation(
3599 const ArrayView<const T> &vertices_0,
3600 const ArrayView<const T> &vertices_1) const
3601 {
3602 Assert(vertices_0.size() == n_vertices(),
3603 ExcMessage("The number of array elements must be equal to "
3604 "the number of vertices of the cell "
3605 "referenced by this object."));
3606 Assert(vertices_1.size() == n_vertices(),
3607 ExcMessage("The number of array elements must be equal to "
3608 "the number of vertices of the cell "
3609 "referenced by this object."));
3610
3611 auto compute_orientation = [&](const auto &table) {
3612 for (types::geometric_orientation o = 0; o < table.size(); ++o)
3613 {
3614 bool match = true;
3615 for (unsigned int j = 0; j < table[o].size(); ++j)
3616 match = (match && vertices_0[j] == vertices_1[table[o][j]]);
3617
3618 if (match)
3619 return o;
3620 }
3621
3622 // Do not use `this` in Assert because nvcc when using C++20 assumes that
3623 // `this` is an integer and we get the following error: invalid type
3624 // argument of unary '*' (have 'int')
3625 [[maybe_unused]] const auto &ref_cell = *this;
3626 Assert(false,
3627 (internal::NoPermutation<T>(ref_cell, vertices_0, vertices_1)));
3628 return std::numeric_limits<types::geometric_orientation>::max();
3629 };
3630
3631 switch (this->kind)
3632 {
3633 case ReferenceCells::Vertex:
3634 return compute_orientation(vertex_vertex_permutations);
3635 case ReferenceCells::Line:
3636 return compute_orientation(line_vertex_permutations);
3637 case ReferenceCells::Triangle:
3638 return compute_orientation(triangle_vertex_permutations);
3639 case ReferenceCells::Quadrilateral:
3640 return compute_orientation(quadrilateral_vertex_permutations);
3641 default:
3642 DEAL_II_NOT_IMPLEMENTED();
3643 }
3644
3645 Assert(false, (internal::NoPermutation<T>(*this, vertices_0, vertices_1)));
3646 return std::numeric_limits<types::geometric_orientation>::max();
3647 }
3648
3649
3650
3651 template <typename T, std::size_t N>
3652 inline std::array<T, N>
3653 ReferenceCell::permute_according_orientation(
3654 const std::array<T, N> &vertices,
3655 const unsigned int orientation) const
3656 {
3657 Assert(N >= n_vertices(),
3658 ExcMessage("The number of array elements must be equal to or "
3659 "greater than the number of vertices of the cell "
3660 "referenced by this object."));
3661
3662 // Call the non-deprecated function, taking care of calling it only with
3663 // those array elements that we actually care about (see the note
3664 // in the documentation about the arguments potentially being
3665 // larger arrays than necessary).
3666 const auto permutation = permute_by_combined_orientation(
3667 make_array_view(vertices.begin(), vertices.begin() + n_vertices()),
3668 orientation);
3669
3670 std::array<T, N> temp;
3671 std::copy(permutation.begin(), permutation.end(), temp.begin());
3672
3673 return temp;
3674 }
3675
3676
3677
3678 template <typename T>
3679 boost::container::small_vector<T, 8>
3680 ReferenceCell::permute_by_combined_orientation(
3681 const ArrayView<const T> &vertices,
3682 const types::geometric_orientation orientation) const
3683 {
3684 AssertDimension(vertices.size(), n_vertices());
3685 boost::container::small_vector<T, 8> result(n_vertices());
3686
3687 auto permute = [&](const auto &table) {
3688 AssertIndexRange(orientation, table.size());
3689 for (unsigned int j = 0; j < table[orientation].size(); ++j)
3690 result[j] = vertices[table[orientation][j]];
3691 };
3692
3693 switch (this->kind)
3694 {
3695 case ReferenceCells::Vertex:
3696 permute(vertex_vertex_permutations);
3697 break;
3698 case ReferenceCells::Line:
3699 permute(line_vertex_permutations);
3700 break;
3701 case ReferenceCells::Triangle:
3702 permute(triangle_vertex_permutations);
3703 break;
3704 case ReferenceCells::Quadrilateral:
3705 permute(quadrilateral_vertex_permutations);
3706 break;
3707 default:
3708 DEAL_II_NOT_IMPLEMENTED();
3709 }
3710
3711 return result;
3712 }
3713
3714
3715
3716 inline types::geometric_orientation
3717 ReferenceCell::get_inverse_combined_orientation(
3718 const types::geometric_orientation orientation) const
3719 {
3720 switch (this->kind)
3721 {
3722 case ReferenceCells::Vertex:
3723 // Things are always default-oriented in 1D
3724 return orientation;
3725
3726 case ReferenceCells::Line:
3727 // the 1d orientations are the identity and a flip: i.e., the identity
3728 // and an involutory mapping
3729 return orientation;
3730
3731 case ReferenceCells::Triangle:
3732 {
3733 AssertIndexRange(orientation, 6);
3734 constexpr std::array<types::geometric_orientation, 6> inverses{
3735 {0, 1, 4, 3, 2, 5}};
3736 return inverses[orientation];
3737 }
3738 case ReferenceCells::Quadrilateral:
3739 {
3740 AssertIndexRange(orientation, 8);
3741 constexpr std::array<types::geometric_orientation, 8> inverses{
3742 {0, 1, 6, 3, 4, 5, 2, 7}};
3743 return inverses[orientation];
3744 }
3745 default:
3746 DEAL_II_NOT_IMPLEMENTED();
3747 }
3748
3749 return std::numeric_limits<types::geometric_orientation>::max();
3750 }
3751
3752
3753
3754 template <>
3755 unsigned int
3756 ReferenceCell::vtk_lexicographic_to_node_index<0>(
3757 const std::array<unsigned, 0> &node_indices,
3758 const std::array<unsigned, 0> &nodes_per_direction,
3759 const bool legacy_format) const;
3760
3761 template <>
3762 unsigned int
3763 ReferenceCell::vtk_lexicographic_to_node_index<1>(
3764 const std::array<unsigned, 1> &node_indices,
3765 const std::array<unsigned, 1> &nodes_per_direction,
3766 const bool legacy_format) const;
3767
3768 template <>
3769 unsigned int
3770 ReferenceCell::vtk_lexicographic_to_node_index<2>(
3771 const std::array<unsigned, 2> &node_indices,
3772 const std::array<unsigned, 2> &nodes_per_direction,
3773 const bool legacy_format) const;
3774
3775 template <>
3776 unsigned int
3777 ReferenceCell::vtk_lexicographic_to_node_index<3>(
3778 const std::array<unsigned, 3> &node_indices,
3779 const std::array<unsigned, 3> &nodes_per_direction,
3780 const bool legacy_format) const;
3781
3782 DEAL_II_NAMESPACE_CLOSE
3783
3784 #endif