Debian Codegraph @

include/deal.II/grid/tria_accessor.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 1998 - 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_accessor_h
16 #define dealii_tria_accessor_h
17
18
19 #include <deal.II/base/config.h>
20
21 #include <deal.II/base/bounding_box.h>
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/geometry_info.h>
24 #include <deal.II/base/point.h>
25 #include <deal.II/base/template_constraints.h>
26
27 #include <deal.II/grid/cell_id.h>
28 #include <deal.II/grid/reference_cell.h>
29 #include <deal.II/grid/tria_faces.h>
30 #include <deal.II/grid/tria_iterator.h>
31 #include <deal.II/grid/tria_iterator_base.h>
32 #include <deal.II/grid/tria_iterator_selector.h>
33 #include <deal.II/grid/tria_levels.h>
34
35 #include <boost/container/small_vector.hpp>
36
37 #include <cmath>
38 #include <limits>
39 #include <utility>
40
41
42 DEAL_II_NAMESPACE_OPEN
43
44 // Forward declarations
45 #ifndef DOXYGEN
46 template <int dim, int spacedim>
47 DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
48 class Triangulation;
49 template <typename Accessor>
50 class TriaRawIterator;
51 template <typename Accessor>
52 class TriaIterator;
53 template <typename Accessor>
54 class TriaActiveIterator;
55
56 namespace parallel
57 {
58 template <int dim, int spacedim>
59 DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
60 class TriangulationBase;
61 }
62
63 template <int dim, int spacedim>
64 DEAL_II_CXX20_REQUIRES((concepts::is_valid_dim_spacedim<dim, spacedim>))
65 class DoFHandler;
66 template <int dim, int spacedim, bool lda>
67 class DoFCellAccessor;
68
69
70 template <int dim, int spacedim>
71 class Manifold;
72
73 template <int dim, int spacedim>
74 class Mapping;
75 #endif
76
77 namespace internal
78 {
79 namespace TriangulationImplementation
80 {
81 class TriaObjects;
82 struct Implementation;
83 struct ImplementationMixedMesh;
84 } // namespace TriangulationImplementation
85
86 namespace TriaAccessorImplementation
87 {
88 struct Implementation;
89
90 /**
91 * Implementation of a type with which to store the level of an accessor
92 * object. We only need it for the case that <tt>structdim == dim</tt>.
93 * Otherwise, an empty object is sufficient.
94 */
95 template <int structdim, int dim>
96 struct PresentLevelType
97 {
98 struct type
99 {
100 /**
101 * Default constructor.
102 */
103 type() = default;
104
105 /**
106 * Dummy constructor. Only level zero is allowed.
107 */
108 type(const int level)
109 {
110 Assert(level == 0, ExcInternalError());
111 (void)level; // removes -Wunused-parameter warning in optimized mode
112 }
113
114 /**
115 * Dummy conversion operator. Returns level zero.
116 */
117 operator int() const
118 {
119 return 0;
120 }
121
122 void
123 operator++() const
124 {
125 DEAL_II_ASSERT_UNREACHABLE();
126 }
127
128 void
129 operator--() const
130 {
131 DEAL_II_ASSERT_UNREACHABLE();
132 }
133 };
134 };
135
136
137 /**
138 * Implementation of a type with which to store the level of an accessor
139 * object. We only need it for the case that <tt>structdim == dim</tt>.
140 * Otherwise, an empty object is sufficient.
141 */
142 template <int dim>
143 struct PresentLevelType<dim, dim>
144 {
145 using type = int;
146 };
147 } // namespace TriaAccessorImplementation
148 } // namespace internal
149 template <int structdim, int dim, int spacedim>
150 class TriaAccessor;
151 template <int dim, int spacedim>
152 class TriaAccessor<0, dim, spacedim>;
153 template <int spacedim>
154 class TriaAccessor<0, 1, spacedim>;
155
156 /**
157 * A namespace that contains exception classes used by the accessor classes.
158 */
159 namespace TriaAccessorExceptions
160 {
161 /**
162 * @ingroup Exceptions
163 */
164 DeclExceptionMsg(ExcCellNotUsed,
165 "The operation you are attempting can only be performed for "
166 "(cell, face, or edge) iterators that point to valid "
167 "objects. These objects need not necessarily be active, "
168 "i.e., have no children, but they need to be part of a "
169 "triangulation. (The objects pointed to by an iterator "
170 "may -- after coarsening -- also be objects that used "
171 "to be part of a triangulation, but are now no longer "
172 "used. Their memory location may have been retained "
173 "for re-use upon the next mesh refinement, but is "
174 "currently unused.)");
175 /**
176 * The cell is not an
177 * @ref GlossActive "active"
178 * cell, but it already has children. Some operations, like setting
179 * refinement flags or accessing degrees of freedom are only possible on
180 * active cells.
181 *
182 * @ingroup Exceptions
183 */
184 DeclExceptionMsg(ExcCellNotActive,
185 "The operation you are attempting can only be performed for "
186 "(cell, face, or edge) iterators that point to 'active' "
187 "objects. 'Active' objects are those that do not have "
188 "children (in the case of cells), or that are part of "
189 "an active cell (in the case of faces or edges). However, "
190 "the object on which you are trying the current "
191 "operation is not 'active' in this sense.");
192 /**
193 * Trying to access the children of a cell which is in fact active.
194 *
195 * @ingroup Exceptions
196 */
197 DeclExceptionMsg(ExcCellHasNoChildren,
198 "The operation you are attempting can only be performed for "
199 "(cell, face, or edge) iterators that have children, "
200 "but the object on which you are trying the current "
201 "operation does not have any.");
202 /**
203 * Trying to access the parent of a cell which is in the coarsest level of
204 * the triangulation.
205 *
206 * @ingroup Exceptions
207 */
208 DeclExceptionMsg(ExcCellHasNoParent,
209 "The operation you are attempting can only be performed for "
210 "(cell, face, or edge) iterators that have a parent object, "
211 "but the object on which you are trying the current "
212 "operation does not have one -- i.e., it is on the "
213 "coarsest level of the triangulation.");
214 /**
215 * @ingroup Exceptions
216 */
217 DeclException1(ExcCantSetChildren,
218 int,
219 << "You can only set the child index if the cell does not "
220 << "currently have children registered; or you can clear it. "
221 << "The given index was " << arg1
222 << " (-1 means: clear children).");
223 /**
224 * @ingroup Exceptions
225 */
226 template <typename AccessorType>
227 DeclException1(ExcDereferenceInvalidObject,
228 AccessorType,
229 << "You tried to dereference an iterator for which this "
230 << "is not possible. More information on this iterator: "
231 << "index=" << arg1.index() << ", state="
232 << (arg1.state() == IteratorState::valid ?
233 "valid" :
234 (arg1.state() == IteratorState::past_the_end ?
235 "past_the_end" :
236 "invalid")));
237 /**
238 * @ingroup Exceptions
239 */
240 DeclExceptionMsg(ExcCantCompareIterators,
241 "Iterators can only be compared if they point to the same "
242 "triangulation, or if neither of them are associated "
243 "with a triangulation.");
244 // TODO: Write documentation!
245 /**
246 * @ingroup Exceptions
247 */
248 DeclException0(ExcNeighborIsCoarser);
249 // TODO: Write documentation!
250 /**
251 * @ingroup Exceptions
252 */
253 DeclException0(ExcNeighborIsNotCoarser);
254 /**
255 * You are trying to access the level of a face, but faces have no inherent
256 * level. The level of a face can only be determined by the level of an
257 * adjacent face, which in turn implies that a face can have several levels.
258 *
259 * @ingroup Exceptions
260 */
261 DeclException0(ExcFacesHaveNoLevel);
262 /**
263 * You are trying to get the periodic neighbor for a face, which does not
264 * have a periodic neighbor. For more information on this, refer to
265 * @ref GlossPeriodicConstraints "entry for periodic boundaries".
266 * @ingroup Exceptions
267 */
268 DeclException0(ExcNoPeriodicNeighbor);
269 // TODO: Write documentation!
270 /**
271 * @ingroup Exceptions
272 */
273 DeclException1(
274 ExcSetOnlyEvenChildren,
275 int,
276 << "You can only set the child index of an even numbered child."
277 << "The number of the child given was " << arg1 << '.');
278 } // namespace TriaAccessorExceptions
279
280
281 /**
282 * A base class for the accessor classes used by TriaRawIterator and derived
283 * classes.
284 *
285 * This class offers only the basic functionality required by the iterators
286 * (stores the necessary data members, offers comparison operators and the
287 * like), but has no functionality to actually dereference data. This is done
288 * in the derived classes.
289 *
290 * In the implementation, the behavior of this class differs between the cases
291 * where <tt>structdim==dim</tt> (cells of a mesh) and
292 * <tt>structdim&lt;dim</tt> (faces and edges). For the latter, #present_level
293 * is always equal to zero and the constructors may not receive a positive
294 * value there. For cells, any level is possible, but only those within the
295 * range of the levels of the Triangulation are reasonable. Furthermore, the
296 * function objects() returns either the container with all cells on the same
297 * level or the container with all objects of this dimension
298 * (<tt>structdim&lt;dim</tt>).
299 *
300 * Some internals of this class are discussed in
301 * @ref IteratorAccessorInternals.
302 *
303 * @ingroup grid
304 * @ingroup Accessors
305 */
306 template <int structdim, int dim, int spacedim = dim>
307 class TriaAccessorBase
308 {
309 public:
310 /**
311 * Dimension of the space the object represented by this accessor lives in.
312 * For example, if this accessor represents a quadrilateral that is part of
313 * a two-dimensional surface in four-dimensional space, then this value is
314 * four.
315 */
316 static constexpr unsigned int space_dimension = spacedim;
317
318 /**
319 * Dimensionality of the object that the thing represented by this accessor
320 * is part of. For example, if this accessor represents a line that is part
321 * of a hexahedron, then this value will be three.
322 */
323 static constexpr unsigned int dimension = dim;
324
325 /**
326 * Dimensionality of the current object represented by this accessor. For
327 * example, if it is line (irrespective of whether it is part of a 2d or 3d
328 * subobject), then this value equals 1.
329 */
330 static const unsigned int structure_dimension = structdim;
331
332 /**
333 * Copy operator. These operators are usually used in a context like
334 * <tt>iterator a,b; *a=*b;</tt>. Presumably, the intent here is to copy the
335 * object pointed to
336 * by @p b to the object pointed to by @p a. However, the result of
337 * dereferencing an iterator is not an object but an accessor; consequently,
338 * this operation is not useful for iterators on triangulations.
339 * Consequently, this operator is declared as deleted and can not be used.
340 */
341 void
342 operator=(const TriaAccessorBase *) = delete;
343
344 protected:
345 /**
346 * Declare the data type that this accessor class expects to get passed from
347 * the iterator classes. Since the pure triangulation iterators need no
348 * additional data, this data type is @p void.
349 */
350 using AccessorData = void;
351
352 /**
353 * Constructor. Protected, thus only callable from friend classes.
354 */
355 TriaAccessorBase(const Triangulation<dim, spacedim> *parent = nullptr,
356 const int level = -1,
357 const int index = -1,
358 const AccessorData * = nullptr);
359
360 /**
361 * Copy constructor. Creates an object with exactly the same data.
362 */
363 TriaAccessorBase(const TriaAccessorBase &);
364
365 /**
366 * Copy operator. Since this is only called from iterators, do not return
367 * anything, since the iterator will return itself.
368 *
369 * This method is protected, since it is only to be called from the iterator
370 * class.
371 */
372 void
373 copy_from(const TriaAccessorBase &);
374
375 /**
376 * Copy operator. Creates an object with exactly the same data.
377 */
378 TriaAccessorBase &
379 operator=(const TriaAccessorBase &);
380
381 /**
382 * Comparison operator for accessors. This operator is used when comparing
383 * iterators into objects of a triangulation, for example when putting
384 * them into a `std::map`.
385 *
386 * If #structure_dimension is less than #dimension, we simply compare the
387 * index of such an object because faces and edges do not have levels. If
388 * #structure_dimension equals #dimension, we compare the level first, and
389 * the index only if levels are equal.
390 */
391 bool
392 operator<(const TriaAccessorBase &other) const;
393
394 protected:
395 /**
396 * Compare for equality.
397 */
398 bool
399 operator==(const TriaAccessorBase &) const;
400
401 /**
402 * Compare for inequality.
403 */
404 bool
405 operator!=(const TriaAccessorBase &) const;
406
407 /**
408 * @name Advancement of iterators
409 */
410 /**
411 * @{
412 */
413 /**
414 * This operator advances the iterator to the next element.
415 *
416 * For @p dim=1 only: The next element is next on this level if there are
417 * more. If the present element is the last on this level, the first on the
418 * next level is accessed.
419 */
420 void
421 operator++();
422
423 /**
424 * This operator moves the iterator to the previous element.
425 *
426 * For @p dim=1 only: The previous element is previous on this level if
427 * <tt>index>0</tt>. If the present element is the first on this level, the
428 * last on the previous level is accessed.
429 */
430 void
431 operator--();
432 /**
433 * @}
434 */
435
436 /**
437 * Access to the other objects of a Triangulation with same dimension.
438 */
439 dealii::internal::TriangulationImplementation::TriaObjects &
440 objects() const;
441
442 public:
443 /**
444 * Data type to be used for passing parameters from iterators to the
445 * accessor classes in a unified way, no matter what the type of number of
446 * these parameters is.
447 */
448 using LocalData = void *;
449
450 /**
451 * @name Iterator address and state
452 */
453 /**
454 * @{
455 */
456
457 /**
458 * For cells, this function returns the level within the mesh hierarchy at
459 * which this cell is located. For all other objects, the function returns
460 * zero.
461 *
462 * @note Within a Triangulation object, cells are uniquely identified by a
463 * pair <code>(level, index)</code> where the former is the cell's
464 * refinement level and the latter is the index of the cell within this
465 * refinement level (the former being what this function returns).
466 * Consequently, there may be multiple cells on different refinement levels
467 * but with the same index within their level. Contrary to this, if the
468 * current object corresponds to a face or edge, then the object is uniquely
469 * identified solely by its index as faces and edges do not have a
470 * refinement level. For these objects, the current function always returns
471 * zero as the level.
472 */
473 int
474 level() const;
475
476 /**
477 * Return the index of the element presently pointed to on the present
478 * level.
479 *
480 * Within a Triangulation object, cells are uniquely identified by a pair
481 * <code>(level, index)</code> where the former is the cell's refinement
482 * level and the latter is the index of the cell within this refinement
483 * level (the latter being what this function returns). Consequently, there
484 * may be multiple cells on different refinement levels but with the same
485 * index within their level. Contrary to this, if the current object
486 * corresponds to a face or edge, then the object is uniquely identified
487 * solely by its index as faces and edges do not have a refinement level.
488 *
489 * @note The indices objects returned by this function are not a contiguous
490 * set of numbers on each level: going from cell to cell, some of the
491 * indices in a level may be unused.
492 *
493 * @note If the triangulation is actually of type
494 * parallel::distributed::Triangulation then the indices are relatively only
495 * to that part of the distributed triangulation that is stored on the
496 * current processor. In other words, cells living in the partitions of the
497 * triangulation stored on different processors may have the same index even
498 * if they refer to the same cell, and the may have different indices even
499 * if they do refer to the same cell (e.g., if a cell is owned by one
500 * processor but is a ghost cell on another).
501 */
502 int
503 index() const;
504
505 /**
506 * Return the state of the iterator. For the different states an accessor
507 * can be in, refer to the TriaRawIterator documentation.
508 */
509 IteratorState::IteratorStates
510 state() const;
511
512 /**
513 * Return a reference to the triangulation which the object pointed to by this
514 * class belongs to.
515 */
516 const Triangulation<dim, spacedim> &
517 get_triangulation() const;
518
519 /**
520 * @}
521 */
522 protected:
523 /**
524 * The level if this is a cell (<tt>structdim==dim</tt>). Else, contains
525 * zero.
526 */
527 typename dealii::internal::TriaAccessorImplementation::
528 PresentLevelType<structdim, dim>::type present_level;
529
530 /**
531 * Used to store the index of the element presently pointed to on the level
532 * presently used.
533 */
534 int present_index;
535
536 /**
537 * Pointer to the triangulation which we act on.
538 */
539 const Triangulation<dim, spacedim> *tria;
540
541 private:
542 template <typename Accessor>
543 friend class TriaRawIterator;
544 template <typename Accessor>
545 friend class TriaIterator;
546 template <typename Accessor>
547 friend class TriaActiveIterator;
548 };
549
550
551
552 /**
553 * A class that represents accessor objects to iterators that don't make sense
554 * such as quad iterators in on 1d meshes. This class can not be used to
555 * create objects (it will in fact throw an exception if this should ever be
556 * attempted but it sometimes allows code to be written in a simpler way in a
557 * dimension independent way. For example, it allows to write code that works
558 * on quad iterators that is dimension independent -- i.e., also compiles
559 * in 1d -- because quad iterators
560 * (via the current class) exist and are syntactically correct. You can not
561 * expect, however, to ever create an actual object of one of these iterators
562 * in 1d, meaning you need to expect to wrap the code block in which you use
563 * quad iterators into something like <code>if (dim@>1)</code> -- which makes
564 * eminent sense anyway.
565 *
566 * This class provides the minimal interface necessary for Accessor classes to
567 * interact with Iterator classes. However, this is only for syntactic
568 * correctness, none of the functions do anything but generate errors.
569 *
570 * @ingroup Accessors
571 */
572 template <int structdim, int dim, int spacedim = dim>
573 class InvalidAccessor
574 {
575 public:
576 /**
577 * Dimension of the space the object represented by this accessor lives in.
578 * For example, if this accessor represents a quadrilateral that is part of
579 * a two-dimensional surface in four-dimensional space, then this value is
580 * four.
581 */
582 static constexpr unsigned int space_dimension = spacedim;
583
584 /**
585 * Dimensionality of the object that the thing represented by this accessor
586 * is part of. For example, if this accessor represents a line that is part
587 * of a hexahedron, then this value will be three.
588 */
589 static constexpr unsigned int dimension = dim;
590
591 /**
592 * Dimensionality of the current object represented by this accessor. For
593 * example, if it is line (irrespective of whether it is part of a 2d or 3d
594 * subobject), then this value equals 1.
595 */
596 static const unsigned int structure_dimension = structdim;
597
598 /**
599 * Declare the data type that this accessor class expects to get passed from
600 * the iterator classes. Since the pure triangulation iterators need no
601 * additional data, this data type is @p void.
602 */
603 using AccessorData = void;
604
605 /**
606 * Constructor. This class is used for iterators that do not make
607 * sense in a given dimension, for example quads for 1d meshes. Consequently,
608 * while the creation of such objects is syntactically valid, they make no
609 * semantic sense, and we generate an exception when such an object is
610 * actually generated.
611 */
612 InvalidAccessor(const void *parent = nullptr,
613 const int level = -1,
614 const int index = -1,
615 const AccessorData *local_data = nullptr);
616
617 /**
618 * Copy constructor. This class is used for iterators that do not make
619 * sense in a given dimension, for example quads for 1d meshes. Consequently,
620 * while the creation of such objects is syntactically valid, they make no
621 * semantic sense, and we generate an exception when such an object is
622 * actually generated.
623 */
624 InvalidAccessor(const InvalidAccessor &);
625
626 /**
627 * Conversion from other accessors to the current invalid one. This of
628 * course also leads to a run-time error.
629 */
630 template <typename OtherAccessor>
631 InvalidAccessor(const OtherAccessor &);
632
633 /**
634 * Dummy copy operation.
635 */
636 void
637 copy_from(const InvalidAccessor &);
638
639 /**
640 * Dummy comparison operators.
641 */
642 bool
643 operator==(const InvalidAccessor &) const;
644 bool
645 operator!=(const InvalidAccessor &) const;
646
647 /**
648 * Dummy operators to make things compile. Does nothing.
649 */
650 void
651 operator++() const;
652 void
653 operator--() const;
654
655 /**
656 * Return the state of the iterator. For the different states an accessor
657 * can be in, refer to the TriaRawIterator documentation.
658 */
659 static IteratorState::IteratorStates
660 state();
661
662
663 /**
664 * Level of this object. Vertices have no level, so this function always
665 * returns zero.
666 */
667 static int
668 level();
669
670 /**
671 * Index of this object. Returns the global index of the vertex this object
672 * points to.
673 */
674 static int
675 index();
676
677 /**
678 * Dummy function representing whether the accessor points to a used or an
679 * unused object.
680 */
681 bool
682 used() const;
683
684 /**
685 * Dummy function representing whether the accessor points to an object that
686 * has children.
687 */
688 bool
689 has_children() const;
690
691 /**
692 * Dummy function that always returns numbers::flat_manifold_id.
693 */
694 types::manifold_id
695 manifold_id() const;
696
697 /**
698 * Dummy function that always returns numbers::invalid_unsigned_int.
699 */
700 unsigned int
701 user_index() const;
702
703 /**
704 * Dummy function that always throws.
705 */
706 void
707 set_user_index(const unsigned int p) const;
708
709 /**
710 * Dummy function that always throws.
711 */
712 void
713 set_manifold_id(const types::manifold_id) const;
714
715 /**
716 * Dummy function to extract vertices. Returns the origin.
717 */
718 Point<spacedim> &
719 vertex(const unsigned int i) const;
720
721 /**
722 * Dummy function to extract lines. Returns a default-constructed line
723 * iterator.
724 */
725 void *
726 line(const unsigned int i) const;
727
728 /**
729 * Dummy function to extract quads. Returns a default-constructed quad
730 * iterator.
731 */
732 void *
733 quad(const unsigned int i) const;
734 };
735
736
737
738 /**
739 * A class that provides access to objects in a triangulation such as its
740 * vertices, sub-objects, children, geometric information, etc. This class
741 * represents objects of dimension <code>structdim</code> (i.e. 1 for lines, 2
742 * for quads, 3 for hexes) in a triangulation of dimensionality
743 * <code>dim</code> (i.e. 1 for a triangulation of lines, 2 for a
744 * triangulation of quads, and 3 for a triangulation of hexes) that is
745 * embedded in a space of dimensionality <code>spacedim</code> (for
746 * <code>spacedim==dim</code> the triangulation represents a domain in
747 * $R^{dim}$, for <code>spacedim@>dim</code> the triangulation is of a
748 * manifold embedded in a higher dimensional space).
749 *
750 * There is a specialization of this class for the case where
751 * @p structdim equals zero, i.e., for vertices of a triangulation.
752 *
753 * @ingroup Accessors
754 */
755 template <int structdim, int dim, int spacedim>
756 class TriaAccessor : public TriaAccessorBase<structdim, dim, spacedim>
757 {
758 public:
759 /**
760 * Propagate alias from base class to this class.
761 */
762 using AccessorData =
763 typename TriaAccessorBase<structdim, dim, spacedim>::AccessorData;
764
765 /**
766 * Constructor.
767 */
768 TriaAccessor(const Triangulation<dim, spacedim> *parent = nullptr,
769 const int level = -1,
770 const int index = -1,
771 const AccessorData *local_data = nullptr);
772
773 /**
774 * The copy constructor is not deleted but copied constructed elements should
775 * not be modified, also the comments to the copy assignment operator.
776 */
777 TriaAccessor(const TriaAccessor &) = default;
778
779 /**
780 * Move constructor.
781 */
782 TriaAccessor(TriaAccessor &&) = default; // NOLINT
783
784 /**
785 * Conversion constructor. This constructor exists to make certain
786 * constructs simpler to write in dimension independent code. For example,
787 * it allows assigning a face iterator to a line iterator, an operation that
788 * is useful in 2d but doesn't make any sense in 3d. The constructor here
789 * exists for the purpose of making the code conform to C++ but it will
790 * unconditionally abort; in other words, assigning a face iterator to a
791 * line iterator is better put into an if-statement that checks that the
792 * dimension is two, and assign to a quad iterator in 3d (an operator that,
793 * without this constructor would be illegal if we happen to compile for
794 * 2d).
795 */
796 template <int structdim2, int dim2, int spacedim2>
797 TriaAccessor(const InvalidAccessor<structdim2, dim2, spacedim2> &);
798
799 /**
800 * Another conversion operator between objects that don't make sense, just
801 * like the previous one.
802 */
803 template <int structdim2, int dim2, int spacedim2>
804 TriaAccessor(const TriaAccessor<structdim2, dim2, spacedim2> &);
805
806 /**
807 * Copy operator. These operators are usually used in a context like
808 * <tt>iterator a,b; *a=*b;</tt>. Presumably, the intent here is to copy the
809 * object pointed to
810 * by @p b to the object pointed to by @p a. However, the result of
811 * dereferencing an iterator is not an object but an accessor; consequently,
812 * this operation is not useful for iterators on triangulations.
813 * Consequently, this operator is declared as deleted and can not be used.
814 */
815 TriaAccessor &
816 operator=(const TriaAccessor &) = delete;
817
818 /**
819 * Move assignment operator. Moving is allowed.
820 */
821 TriaAccessor &
822 operator=(TriaAccessor &&) = default; // NOLINT
823
824 /**
825 * Defaulted destructor.
826 */
827 ~TriaAccessor() = default;
828
829 /**
830 * Test for the element being used or not. The return value is @p true for
831 * all iterators that are either normal iterators or active iterators, only
832 * raw iterators can return @p false. Since raw iterators are only used in
833 * the interiors of the library, you will not usually need this function.
834 */
835 bool
836 used() const;
837
838 /**
839 * @name Accessing sub-objects
840 */
841 /**
842 * @{
843 */
844
845 /**
846 * Pointer to the @p ith vertex bounding this object. Throw an exception if
847 * <code>dim=1</code>.
848 */
849 TriaIterator<TriaAccessor<0, dim, spacedim>>
850 vertex_iterator(const unsigned int i) const;
851
852 /**
853 * Return the global index of i-th vertex of the current object. The
854 * convention regarding the numbering of vertices is laid down in the
855 * documentation of the GeometryInfo class.
856 *
857 * Note that the returned value is only the index of the geometrical vertex.
858 * It has nothing to do with possible degrees of freedom associated with it.
859 * For this, see the @p DoFAccessor::vertex_dof_index functions.
860 *
861 * @note Despite the name, the index returned here is only global in the
862 * sense that it is specific to a particular Triangulation object or, in the
863 * case the triangulation is actually of type
864 * parallel::distributed::Triangulation, specific to that part of the
865 * distributed triangulation stored on the current processor.
866 */
867 unsigned int
868 vertex_index(const unsigned int i) const;
869
870 /**
871 * Return a reference to the @p ith vertex. The reference is not const,
872 * i.e., it is possible to call this function on the left hand side of an
873 * assignment, thereby moving the vertex of a cell within the triangulation.
874 * Of course, doing so requires that you ensure that the new location of the
875 * vertex remains useful -- for example, avoiding inverted or otherwise
876 * distorted (see also
877 * @ref GlossDistorted "this glossary entry").
878 *
879 * @note When a cell is refined, its children inherit the position of the
880 * vertex positions of those vertices they share with the parent cell (plus
881 * the locations of the new vertices on edges, faces, and cell interiors
882 * that are created for the new child cells). If the vertex of a cell is
883 * moved, this implies that its children will also use these new locations.
884 * On the other hand, imagine a 2d situation where you have one cell that is
885 * refined (with four children) and then you move the central vertex
886 * connecting all four children. If you coarsen these four children again to
887 * the parent cell, then the location of the moved vertex is lost and if, in
888 * a later step, you refine the parent cell again, the then again new vertex
889 * will be placed again at the same position as the first time around --
890 * i.e., not at the location you had previously moved it to.
891 *
892 * @note The behavior described above is relevant if you have a
893 * parallel::distributed::Triangulation object. There, refining a mesh
894 * always involves a re-partitioning. In other words, vertices of locally
895 * owned cells (see
896 * @ref GlossLocallyOwnedCell "this glossary entry")
897 * that you may have moved to a different location on one processor may be
898 * moved to a different processor upon mesh refinement (even if these
899 * particular cells were not refined) which will re-create their position
900 * based on the position of the coarse cells they previously had, not based
901 * on the position these vertices had on the processor that previously owned
902 * them. In other words, in parallel computations, you will probably have to
903 * move nodes explicitly after every mesh refinement because vertex
904 * positions may or may not be preserved across the re-partitioning that
905 * accompanies mesh refinement.
906 */
907 Point<spacedim> &
908 vertex(const unsigned int i) const;
909
910 /**
911 * Pointer to the @p ith line bounding this object.
912 */
913 typename dealii::internal::TriangulationImplementation::
914 Iterators<dim, spacedim>::line_iterator
915 line(const unsigned int i) const;
916
917 /**
918 * Line index of the @p ith line bounding this object.
919 *
920 * Implemented only for <tt>structdim>1</tt>, otherwise an exception
921 * generated.
922 */
923 unsigned int
924 line_index(const unsigned int i) const;
925
926 /**
927 * Pointer to the @p ith quad bounding this object.
928 */
929 typename dealii::internal::TriangulationImplementation::
930 Iterators<dim, spacedim>::quad_iterator
931 quad(const unsigned int i) const;
932
933 /**
934 * Quad index of the @p ith quad bounding this object.
935 *
936 * Implemented only for <tt>structdim>2</tt>, otherwise an exception
937 * generated.
938 */
939 unsigned int
940 quad_index(const unsigned int i) const;
941 /**
942 * @}
943 */
944
945 /**
946 * @name Orientation of sub-objects
947 */
948 /**
949 * @{
950 */
951
952 /**
953 * Return an integer representation that uniquely encodes the orientation,
954 * flip, and rotation of a @p face.
955 *
956 * @ingroup reordering
957 */
958 types::geometric_orientation
959 combined_face_orientation(const unsigned int face) const;
960
961 /**
962 * Return whether the face with index @p face has its normal pointing in the
963 * standard direction (@p true) or whether it is the opposite (@p false).
964 * Which is the standard direction is documented with the GeometryInfo
965 * class. In 1d and 2d, this is always @p true, but in 3d it may be
966 * different, see the respective discussion in the documentation of the
967 * GeometryInfo class.
968 *
969 * This function is really only for internal use in the library unless you
970 * absolutely know what this is all about.
971 */
972 bool
973 face_orientation(const unsigned int face) const;
974
975 /**
976 * Return whether the face with index @p face is rotated by 180 degrees (@p
977 * true) or not (@p false). In 1d and 2d, this is always @p false, but in
978 * 3d it may be different, see the respective discussion in the
979 * documentation of the GeometryInfo class.
980 *
981 * This function is really only for internal use in the library unless you
982 * absolutely know what this is all about.
983 */
984 bool
985 face_flip(const unsigned int face) const;
986
987 /**
988 * Return whether the face with index @p face is rotated by 90 degrees (@p
989 * true) or not (@p false). In 1d and 2d, this is always @p false, but in
990 * 3d it may be different, see the respective discussion in the
991 * documentation of the GeometryInfo class.
992 *
993 * This function is really only for internal use in the library unless you
994 * absolutely know what this is all about.
995 */
996 bool
997 face_rotation(const unsigned int face) const;
998
999 /**
1000 * Return whether the line with index @p line is oriented in standard
1001 * direction.
1002 *
1003 * @warning This function is really only for internal use in the library
1004 * unless you absolutely know what this is all about.
1005 *
1006 * @note This function queries ReferenceCell::face_to_cell_line_orientation().
1007 */
1008 types::geometric_orientation
1009 line_orientation(const unsigned int line) const;
1010 /**
1011 * @}
1012 */
1013
1014 /**
1015 * @name Accessing children
1016 */
1017 /**
1018 * @{
1019 */
1020
1021 /**
1022 * Test whether the object has children.
1023 */
1024 bool
1025 has_children() const;
1026
1027 /**
1028 * Return the number of immediate children of this object. The number of
1029 * children of an unrefined cell is zero.
1030 */
1031 unsigned int
1032 n_children() const;
1033
1034 /**
1035 * Compute and return the number of active descendants of this objects. For
1036 * example, if all of the eight children of a hex are further refined
1037 * isotropically exactly once, the returned number will be 64, not 80.
1038 *
1039 * If the present cell is not refined, one is returned.
1040 *
1041 * If one considers a triangulation as a forest where the root of each tree
1042 * are the coarse mesh cells and nodes have descendants (the children of a
1043 * cell), then this function returns the number of terminal nodes in the
1044 * sub-tree originating from the current object; consequently, if the
1045 * current object is not further refined, the answer is one.
1046 */
1047 unsigned int
1048 n_active_descendants() const;
1049
1050 /**
1051 * Return the number of times that this object is refined. Note that not all
1052 * its children are refined that often (which is why we prepend @p max_),
1053 * the returned number is rather the maximum number of refinement in any
1054 * branch of children of this object.
1055 *
1056 * For example, if this object is refined, and one of its children is
1057 * refined exactly one more time, then <tt>max_refinement_depth</tt> should
1058 * return 2.
1059 *
1060 * If this object is not refined (i.e. it is active), then the return value
1061 * is zero.
1062 */
1063 unsigned int
1064 max_refinement_depth() const;
1065
1066 /**
1067 * Return an iterator to the @p ith child.
1068 */
1069 TriaIterator<TriaAccessor<structdim, dim, spacedim>>
1070 child(const unsigned int i) const;
1071
1072 /**
1073 * Return the child number of @p child on the current cell. This is the
1074 * inverse function of TriaAccessor::child().
1075 */
1076 unsigned int
1077 child_iterator_to_index(
1078 const TriaIterator<TriaAccessor<structdim, dim, spacedim>> &child) const;
1079
1080 /**
1081 * Return an iterator to that object that is identical to the ith child for
1082 * isotropic refinement. If the current object is refined isotropically,
1083 * then the returned object is the ith child. If the current object is
1084 * refined anisotropically, the returned child may in fact be a grandchild
1085 * of the object, or may not exist at all (in which case an exception is
1086 * generated).
1087 */
1088 TriaIterator<TriaAccessor<structdim, dim, spacedim>>
1089 isotropic_child(const unsigned int i) const;
1090
1091 /**
1092 * Return the RefinementCase of this cell.
1093 */
1094 RefinementCase<structdim>
1095 refinement_case() const;
1096
1097 /**
1098 * Index of the @p ith child. The level of the child is one higher than that
1099 * of the present cell, if the children of a cell are accessed. The children
1100 * of faces have no level. If the child does not exist, -1 is returned.
1101 */
1102 int
1103 child_index(const unsigned int i) const;
1104
1105 /**
1106 * Index of the @p ith isotropic child. See the isotropic_child() function
1107 * for a definition of this concept. If the child does not exist, -1 is
1108 * returned.
1109 */
1110 int
1111 isotropic_child_index(const unsigned int i) const;
1112 /**
1113 * @}
1114 */
1115
1116 /**
1117 * @name Dealing with boundary indicators
1118 */
1119 /**
1120 * @{
1121 */
1122
1123 /**
1124 * Return the boundary indicator of this object.
1125 *
1126 * If the return value is the special value
1127 * numbers::internal_face_boundary_id, then this object is in the interior
1128 * of the domain.
1129 *
1130 * @see
1131 * @ref GlossBoundaryIndicator "Glossary entry on boundary indicators"
1132 */
1133 types::boundary_id
1134 boundary_id() const;
1135
1136 /**
1137 * Set the boundary indicator of the current object. The same applies as for
1138 * the boundary_id() function.
1139 *
1140 * This function only sets the boundary object of the current object itself,
1141 * not the indicators of the ones that bound it. For example, in 3d, if this
1142 * function is called on a face, then the boundary indicator of the 4 edges
1143 * that bound the face remain unchanged. If you want to set the boundary
1144 * indicators of face and edges at the same time, use the
1145 * set_all_boundary_ids() function. You can see the result of not using the
1146 * correct function in the results section of step-49.
1147 *
1148 * @warning You should never set the boundary indicator of an interior face
1149 * (a face not at the boundary of the domain), or set the boundary
1150 * indicator of an exterior face to numbers::internal_face_boundary_id (this
1151 * value is reserved for another purpose). Algorithms may not work or
1152 * produce very confusing results if boundary cells have a boundary
1153 * indicator of numbers::internal_face_boundary_id or if interior cells have
1154 * boundary indicators other than numbers::internal_face_boundary_id.
1155 * Unfortunately, the current object has no means of finding out whether it
1156 * really is at the boundary of the domain and so cannot determine whether
1157 * the value you are trying to set makes sense under the current
1158 * circumstances.
1159 *
1160 * @see
1161 * @ref GlossBoundaryIndicator "Glossary entry on boundary indicators"
1162 */
1163 void
1164 set_boundary_id(const types::boundary_id) const;
1165
1166 /**
1167 * Do as set_boundary_id() but also set the boundary indicators of the
1168 * objects that bound the current object. For example, in 3d, if
1169 * set_boundary_id() is called on a face, then the boundary indicator of the
1170 * 4 edges that bound the face remain unchanged. In contrast, if you call
1171 * the current function, the boundary indicators of face and edges are all
1172 * set to the given value.
1173 *
1174 * This function is useful if you set boundary indicators of faces in 3d (in
1175 * 2d, the function does the same as set_boundary_id()) and you do so
1176 * because you want a curved boundary object to represent the part of the
1177 * boundary that corresponds to the current face. In that case, the
1178 * Triangulation class needs to figure out where to put new vertices upon
1179 * mesh refinement, and higher order Mapping objects also need to figure out
1180 * where new interpolation points for a curved boundary approximation should
1181 * be. In either case, the two classes first determine where interpolation
1182 * points on the edges of a boundary face should be, asking the boundary
1183 * object, before asking the boundary object for the interpolation points
1184 * corresponding to the interior of the boundary face. For this to work
1185 * properly, it is not sufficient to have set the boundary indicator for the
1186 * face alone, but you also need to set the boundary indicators of the edges
1187 * that bound the face. This function does all of this at once. You can see
1188 * the result of not using the correct function in the results section of
1189 * step-49.
1190 *
1191 * @see
1192 * @ref GlossBoundaryIndicator "Glossary entry on boundary indicators"
1193 */
1194 void
1195 set_all_boundary_ids(const types::boundary_id) const;
1196
1197 /**
1198 * Return whether this object is at the boundary. Obviously, the use of this
1199 * function is only possible for <tt>dim@>structdim</tt>; however, for
1200 * <tt>dim==structdim</tt>, an object is a cell and the CellAccessor class
1201 * offers another possibility to determine whether a cell is at the boundary
1202 * or not.
1203 */
1204 bool
1205 at_boundary() const;
1206
1207 /**
1208 * Return a constant reference to the manifold object used for this object.
1209 *
1210 * As explained in the
1211 * @ref manifold
1212 * topic, the process involved in finding the appropriate manifold
1213 * description involves querying both the manifold or boundary
1214 * indicators. See there for more information.
1215 */
1216 const Manifold<dim, spacedim> &
1217 get_manifold() const;
1218
1219 /**
1220 * @}
1221 */
1222
1223 /**
1224 * @name Dealing with manifold indicators
1225 */
1226 /**
1227 * @{
1228 */
1229
1230 /**
1231 * Return the manifold indicator of this object.
1232 *
1233 * If the return value is the special value numbers::flat_manifold_id, then
1234 * this object is associated with a standard Cartesian Manifold Description.
1235 *
1236 * @see
1237 * @ref GlossManifoldIndicator "Glossary entry on manifold indicators"
1238 */
1239 types::manifold_id
1240 manifold_id() const;
1241
1242 /**
1243 * Set the manifold indicator. The same applies as for the
1244 * <tt>manifold_id()</tt> function.
1245 *
1246 * Note that it only sets the manifold object of the current object itself,
1247 * not the indicators of the ones that bound it, nor of its children. For
1248 * example, in 3d, if this function is called on a face, then the manifold
1249 * indicator of the 4 edges that bound the face remain unchanged. If you
1250 * want to set the manifold indicators of face, edges and all children at
1251 * the same time, use the set_all_manifold_ids() function.
1252 *
1253 *
1254 * @ingroup manifold
1255 *
1256 * @see
1257 * @ref GlossManifoldIndicator "Glossary entry on manifold indicators"
1258 */
1259 void
1260 set_manifold_id(const types::manifold_id) const;
1261
1262 /**
1263 * Do as set_manifold_id() but also set the manifold indicators of the
1264 * objects that bound the current object. For example, in 3d, if
1265 * set_manifold_id() is called on a face, then the manifold indicator of the
1266 * 4 edges that bound the face remain unchanged. On the other hand, the
1267 * manifold indicators of face and edges are all set at the same time using
1268 * the current function.
1269 *
1270 * @ingroup manifold
1271 *
1272 * @see
1273 * @ref GlossManifoldIndicator "Glossary entry on manifold indicators"
1274 */
1275 void
1276 set_all_manifold_ids(const types::manifold_id) const;
1277
1278 /**
1279 * @}
1280 */
1281
1282
1283 /**
1284 * @name User data
1285 */
1286 /**
1287 * @{
1288 */
1289 /**
1290 * Read the user flag. See
1291 * @ref GlossUserFlags
1292 * for more information.
1293 */
1294 bool
1295 user_flag_set() const;
1296
1297 /**
1298 * Set the user flag. See
1299 * @ref GlossUserFlags
1300 * for more information.
1301 */
1302 void
1303 set_user_flag() const;
1304
1305 /**
1306 * Clear the user flag. See
1307 * @ref GlossUserFlags
1308 * for more information.
1309 */
1310 void
1311 clear_user_flag() const;
1312
1313 /**
1314 * Set the user flag for this and all descendants. See
1315 * @ref GlossUserFlags
1316 * for more information.
1317 */
1318 void
1319 recursively_set_user_flag() const;
1320
1321 /**
1322 * Clear the user flag for this and all descendants. See
1323 * @ref GlossUserFlags
1324 * for more information.
1325 */
1326 void
1327 recursively_clear_user_flag() const;
1328
1329 /**
1330 * Reset the user data to zero, independent if pointer or index. See
1331 * @ref GlossUserData
1332 * for more information.
1333 */
1334 void
1335 clear_user_data() const;
1336
1337 /**
1338 * Set the user pointer to @p p.
1339 *
1340 * @note User pointers and user indices are mutually exclusive. Therefore,
1341 * you can only use one of them, unless you call
1342 * Triangulation::clear_user_data() in between.
1343 *
1344 * See
1345 * @ref GlossUserData
1346 * for more information.
1347 */
1348 void
1349 set_user_pointer(void *p) const;
1350
1351 /**
1352 * Reset the user pointer to `nullptr`. See
1353 * @ref GlossUserData
1354 * for more information.
1355 */
1356 void
1357 clear_user_pointer() const;
1358
1359 /**
1360 * Access the value of the user pointer. It is in the responsibility of the
1361 * user to make sure that the pointer points to something useful and always
1362 * requires casting to a known type, e.g.,
1363 *
1364 * @code
1365 * auto *a = static_cast<A*>(cell->user_pointer());
1366 * @endcode
1367 *
1368 * @note User pointers and user indices are mutually exclusive. Therefore, you
1369 * can only use one of them, unless you call Triangulation::clear_user_data()
1370 * in between.
1371 *
1372 * See
1373 * @ref GlossUserData
1374 * for more information.
1375 */
1376 void *
1377 user_pointer() const;
1378
1379 /**
1380 * Set the user pointer of this object and all its children to the given
1381 * value. This is useful for example if all cells of a certain subdomain, or
1382 * all faces of a certain part of the boundary should have user pointers
1383 * pointing to objects describing this part of the domain or boundary.
1384 *
1385 * Note that the user pointer is not inherited under mesh refinement, so
1386 * after mesh refinement there might be cells or faces that don't have user
1387 * pointers pointing to the describing object. In this case, simply loop
1388 * over all the elements of the coarsest level that has this information,
1389 * and use this function to recursively set the user pointer of all finer
1390 * levels of the triangulation.
1391 *
1392 * @note User pointers and user indices are mutually exclusive. Therefore,
1393 * you can only use one of them, unless you call
1394 * Triangulation::clear_user_data() in between.
1395 *
1396 * See
1397 * @ref GlossUserData
1398 * for more information.
1399 */
1400 void
1401 recursively_set_user_pointer(void *p) const;
1402
1403 /**
1404 * Clear the user pointer of this object and all of its descendants. The
1405 * same holds as said for the recursively_set_user_pointer() function. See
1406 * @ref GlossUserData
1407 * for more information.
1408 */
1409 void
1410 recursively_clear_user_pointer() const;
1411
1412 /**
1413 * Set the user index to @p p.
1414 *
1415 * @note User pointers and user indices are mutually exclusive. Therefore,
1416 * you can only use one of them, unless you call
1417 * Triangulation::clear_user_data() in between. See
1418 * @ref GlossUserData
1419 * for more information.
1420 */
1421 void
1422 set_user_index(const unsigned int p) const;
1423
1424 /**
1425 * Reset the user index to 0. See
1426 * @ref GlossUserData
1427 * for more information.
1428 */
1429 void
1430 clear_user_index() const;
1431
1432 /**
1433 * Access the value of the user index.
1434 *
1435 * @note User pointers and user indices are mutually exclusive. Therefore,
1436 * you can only use one of them, unless you call
1437 * Triangulation::clear_user_data() in between.
1438 *
1439 * See
1440 * @ref GlossUserData
1441 * for more information.
1442 */
1443 unsigned int
1444 user_index() const;
1445
1446 /**
1447 * Set the user index of this object and all its children.
1448 *
1449 * Note that the user index is not inherited under mesh refinement, so after
1450 * mesh refinement there might be cells or faces that don't have the
1451 * expected user indices. In this case, simply loop over all the elements of
1452 * the coarsest level that has this information, and use this function to
1453 * recursively set the user index of all finer levels of the triangulation.
1454 *
1455 * @note User pointers and user indices are mutually exclusive. Therefore,
1456 * you can only use one of them, unless you call
1457 * Triangulation::clear_user_data() in between.
1458 *
1459 * See
1460 * @ref GlossUserData
1461 * for more information.
1462 */
1463 void
1464 recursively_set_user_index(const unsigned int p) const;
1465
1466 /**
1467 * Clear the user index of this object and all of its descendants. The same
1468 * holds as said for the recursively_set_user_index() function.
1469 *
1470 * See
1471 * @ref GlossUserData
1472 * for more information.
1473 */
1474 void
1475 recursively_clear_user_index() const;
1476 /**
1477 * @}
1478 */
1479
1480 /**
1481 * @name Geometric information about an object
1482 */
1483 /**
1484 * @{
1485 */
1486
1487 /**
1488 * Diameter of the object.
1489 *
1490 * The diameter of an object is computed to be the largest diagonal of the
1491 * current object. If this object is a quadrilateral, then there are two
1492 * such diagonal, and if it is a hexahedron, then there are four diagonals
1493 * that connect "opposite" points. For triangles and tetrahedra, the function
1494 * simply returns the length of the longest edge.
1495 *
1496 * The situation is more difficult for wedges and pyramids: For wedges, we
1497 * return the length of the longest diagonal of the three quadrilateral faces
1498 * or the longest edge length of the two triangular faces. For pyramids,
1499 * the same principle is applied.
1500 *
1501 * In all of these cases, this definition of "diameter" is
1502 * not necessarily the true diameter in the sense of the largest distance
1503 * between points inside the object. Indeed, one can often construct objects
1504 * for which it is not, though these are generally quite deformed compared to
1505 * the reference shape. Furthermore, for objects that may use higher order
1506 * mappings, one may have bulging faces that also create trouble for
1507 * computing an exact representation of the diameter of the object. That said,
1508 * the definition used above is completely sufficient for most computations.
1509 */
1510 double
1511 diameter() const;
1512
1513 /**
1514 * Return a pair of Point and double corresponding to the center and
1515 * the radius of a reasonably small enclosing ball of the object.
1516 *
1517 * The function implements Ritter's O(n) algorithm to get a reasonably
1518 * small enclosing ball around the vertices of the object.
1519 * The initial guess for the enclosing ball is taken to be the ball
1520 * which contains the largest diagonal of the object as its diameter.
1521 * Starting from such an initial guess, the algorithm tests whether all
1522 * the vertices of the object (except the vertices of the largest diagonal)
1523 * are geometrically within the ball.
1524 * If any vertex (v) is found to be geometrically outside the ball,
1525 * a new iterate of the ball is constructed by shifting its center and
1526 * increasing the radius so as to geometrically enclose both the previous
1527 * ball and the vertex (v). The algorithm terminates when all the vertices
1528 * are geometrically inside the ball.
1529 *
1530 * If a vertex (v) is geometrically inside a particular iterate of the ball,
1531 * then it will continue to be so in the subsequent iterates of
1532 * the ball (this is true \a by \a construction).
1533 *
1534 * @note This function assumes d-linear mapping from the reference cell.
1535 *
1536 * <a href="http://geomalgorithms.com/a08-_containers.html">see this</a> and
1537 * [Ritter 1990]
1538 */
1539 std::pair<Point<spacedim>, double>
1540 enclosing_ball() const;
1541
1542 /**
1543 * Return the smallest bounding box that encloses the object.
1544 *
1545 * Notice that this method is not aware of any mapping you may be using to
1546 * do your computations. If you are using a mapping object that modifies the
1547 * position of the vertices, like MappingQEulerian, or MappingFEField, then
1548 * you should call the function Mapping::get_bounding_box() instead.
1549 */
1550 BoundingBox<spacedim>
1551 bounding_box() const;
1552
1553 /**
1554 * Length of an object in the direction of the given axis, specified in the
1555 * local coordinate system. See the documentation of GeometryInfo for the
1556 * meaning and enumeration of the local axes.
1557 *
1558 * Note that the "length" of an object can be interpreted in a variety of
1559 * ways. Here, we choose it as the maximal length of any of the edges of the
1560 * object that are parallel to the chosen axis on the reference cell.
1561 */
1562 double
1563 extent_in_direction(const unsigned int axis) const;
1564
1565 /**
1566 * Return the minimal distance between any two vertices.
1567 */
1568 double
1569 minimum_vertex_distance() const;
1570
1571 /**
1572 * Return a point belonging to the Manifold<dim,spacedim> where this object
1573 * lives, given its parametric coordinates on the reference @p structdim
1574 * cell. This function queries the underlying manifold object, and can be
1575 * used to obtain the exact geometrical location of arbitrary points on this
1576 * object.
1577 *
1578 * Notice that the argument @p coordinates are the coordinates on the
1579 * <em>reference cell</em>, given in reference coordinates. In other words,
1580 * the argument provides a weighting between the different vertices. For
1581 * example, for lines, calling this function with argument Point<1>(.5), is
1582 * equivalent to asking the line for its center.
1583 */
1584 Point<spacedim>
1585 intermediate_point(const Point<structdim> &coordinates) const;
1586
1587 /**
1588 * This function computes a fast approximate transformation from the real to
1589 * the unit cell by inversion of an affine approximation of the $d$-linear
1590 * function from the reference $d$-dimensional cell.
1591 *
1592 * The affine approximation of the unit to real cell mapping is found by a
1593 * least squares fit of an affine function to the $2^d$ vertices of the
1594 * present object. For any valid mesh cell whose geometry is not degenerate,
1595 * this operation results in a unique affine mapping. Thus, this function
1596 * will return a finite result for all given input points, even in cases
1597 * where the actual transformation by an actual bi-/trilinear or higher
1598 * order mapping might be singular. Besides only approximating the mapping
1599 * from the vertex points, this function also ignores the attached manifold
1600 * descriptions. The result is only exact in case the transformation from
1601 * the unit to the real cell is indeed affine, such as in one dimension or
1602 * for Cartesian and affine (parallelogram) meshes in 2d/3d.
1603 *
1604 * For exact transformations to the unit cell, use
1605 * Mapping::transform_real_to_unit_cell().
1606 *
1607 * @note If dim<spacedim we first project p onto the plane.
1608 */
1609 Point<structdim>
1610 real_to_unit_cell_affine_approximation(const Point<spacedim> &point) const;
1611
1612 /**
1613 * Center of the object. The center of an object is defined to be the
1614 * average of the locations of the vertices, which is also where a $Q_1$
1615 * mapping would map the center of the reference cell. However, you can also
1616 * ask this function to instead return the average of the vertices as
1617 * computed by the underlying Manifold object associated with the current
1618 * object, by setting to true the optional parameter @p respect_manifold.
1619 * Manifolds would then typically pull back the coordinates of the vertices
1620 * to a reference domain (not necessarily the reference cell), compute the
1621 * average there, and then push forward the coordinates of the averaged
1622 * point to the physical space again; the resulting point is guaranteed to
1623 * lie within the manifold, even if the manifold is curved.
1624 *
1625 * When the object uses a different manifold description as its surrounding,
1626 * like when part of the bounding objects of this TriaAccessor use a
1627 * non-flat manifold description but the object itself is flat, the result
1628 * given by the TriaAccessor::center() function may not be accurate enough,
1629 * even when parameter @p respect_manifold is set to true. If you find this
1630 * to be case, than you can further refine the computation of the center by
1631 * setting to true the second additional parameter @p
1632 * interpolate_from_surrounding. This computes the location of the center by
1633 * a so-called transfinite interpolation from the center of all the bounding
1634 * objects. For a 2d object, it puts a weight of <code>1/2</code> on each of
1635 * the four surrounding lines and a weight <code>-1/4</code> on the four
1636 * vertices. This corresponds to a linear interpolation between the
1637 * descriptions of the four faces, subtracting the contribution of the
1638 * vertices that is added twice when coming through both lines adjacent to
1639 * the vertex. In 3d, the weights for faces are <code>1/2</code>, the
1640 * weights for lines are <code>-1/4</code>, and the weights for vertices are
1641 * <code>1/8</code>. For further information, also confer to the
1642 * TransfiniteInterpolationManifold class that is able to not only apply
1643 * this beneficial description to a single cell but all children of a coarse
1644 * cell.
1645 */
1646 Point<spacedim>
1647 center(const bool respect_manifold = false,
1648 const bool interpolate_from_surrounding = false) const;
1649
1650 /**
1651 * Return the barycenter (also called centroid)
1652 * of the object. The barycenter for an object $K$
1653 * of dimension $d$ in $D$ space dimensions is given by the $D$-dimensional
1654 * vector $\mathbf x_K$ defined by
1655 * @f[
1656 * \mathbf x_K = \frac{1}{|K|} \int_K \mathbf x \; \textrm{d}x
1657 * @f]
1658 * where the measure of the object is given by
1659 * @f[
1660 * |K| = \int_K \mathbf 1 \; \textrm{d}x.
1661 * @f]
1662 * This function assumes that $K$ is mapped by a $d$-linear function from
1663 * the reference $d$-dimensional cell. Then the integrals above can be
1664 * pulled back to the reference cell and evaluated exactly (if through
1665 * lengthy and, compared to the center() function, expensive computations).
1666 */
1667 Point<spacedim>
1668 barycenter() const;
1669
1670 /**
1671 * Compute the `structdim`-dimensional measure of the object. For a
1672 * `dim`-dimensional cell in `dim`-dimensional space, this equals its volume.
1673 * On the other hand, for a 2d cell in 3d space, or if the current object
1674 * pointed to is a 2d face of a 3d cell in 3d space, then the function
1675 * computes the area the object occupies. For a one-dimensional (i.e.,
1676 * `structdim = 1`) object, regardless of `dim` and `spacedim`, return its
1677 * length. Similarly, the measure of any vertex (i.e., `structdim = 0`
1678 * objects) is 1.
1679 *
1680 * The function only computes the measure of cells, faces or edges assumed
1681 * to be represented by (bi-/tri-)linear mappings. In other words, it only
1682 * takes into account the locations of the vertices that bound the current
1683 * object but not how the interior of the object may actually be mapped. In
1684 * most simple cases, this is exactly what you want. However, for objects
1685 * that are not "straight", e.g. 2d cells embedded in 3d space as part of a
1686 * triangulation of a curved domain, two-dimensional faces of 3d cells that
1687 * are not just parallelograms, or for faces that are at the boundary of a
1688 * domain that is not just bounded by straight line segments or planes, this
1689 * function only computes the dim-dimensional measure of a (bi-/tri-)linear
1690 * interpolation of the "real" object as defined by the manifold or boundary
1691 * object describing the real geometry of the object in question. If you
1692 * want to consider the "real" geometry, you will need to compute the
1693 * measure by integrating a function equal to one over the object, which
1694 * after applying quadrature equals the summing the JxW values returned by
1695 * the FEValues or FEFaceValues object you will want to use for the
1696 * integral.
1697 *
1698 * @note There is no analytic formula for the area of a bilinear face (i.e.,
1699 * something with a quadrilateral reference cell) in 3D. This function uses
1700 * the quadrature defined by QGauss<2>(4) to approximate the measure in this
1701 * case.
1702 */
1703 double
1704 measure() const;
1705
1706 /**
1707 * Return true if the current object is a translation of the given argument.
1708 *
1709 * @note For the purpose of a triangulation, cells, faces, etc are only
1710 * characterized by their vertices. The current function therefore only
1711 * compares the locations of vertices. For many practical applications,
1712 * however, it is not only the vertices that determine whether one cell is a
1713 * translation of another, but also how the cell is mapped from the
1714 * reference cell to its location in real space. For example, if we are
1715 * using higher order mappings, then not only do the vertices have to be
1716 * translations of each other, but also the points along edges. In these
1717 * questions, therefore, it would be appropriate to ask the mapping, not the
1718 * current function, whether two objects are translations of each other.
1719 */
1720 bool
1721 is_translation_of(
1722 const TriaIterator<TriaAccessor<structdim, dim, spacedim>> &o) const;
1723
1724 /**
1725 * Reference cell type of the current object.
1726 */
1727 ReferenceCell
1728 reference_cell() const;
1729
1730 /**
1731 * Number of vertices.
1732 */
1733 unsigned int
1734 n_vertices() const;
1735
1736 /**
1737 * Number of lines.
1738 */
1739 unsigned int
1740 n_lines() const;
1741
1742 /**
1743 * Return the number of faces for a cell. This function is only
1744 * implemented for cells (i.e., `structdim==dim`) to avoid the question
1745 * of what exactly is meant in a construct such as
1746 * `cell->face(f)->n_faces()`. If you want to ask how many bounding
1747 * lines a face of a 3d cell has, use `cell->face(f)->n_lines()`; if
1748 * you want to ask about the number of vertices of a face of a 2d cell,
1749 * use `cell->face(f)->n_vertices()`.
1750 */
1751 unsigned int
1752 n_faces() const;
1753
1754 /**
1755 * Return an object that can be thought of as an array containing all indices
1756 * from zero to n_vertices().
1757 */
1758 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
1759 vertex_indices() const;
1760
1761 /**
1762 * Return an object that can be thought of as an array containing all indices
1763 * from zero to n_lines().
1764 */
1765 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
1766 line_indices() const;
1767
1768 /**
1769 * Return an object that can be thought of as an array containing all indices
1770 * from zero to n_faces().
1771 *
1772 * @note Only implemented for cells (structdim==dim).
1773 */
1774 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
1775 face_indices() const;
1776
1777 /**
1778 * @}
1779 */
1780
1781 private:
1782 /**
1783 * Like set_boundary_id but without checking for internal faces or invalid
1784 * ids.
1785 */
1786 void
1787 set_boundary_id_internal(const types::boundary_id id) const;
1788
1789 /**
1790 * Set the indices of those objects that bound the current
1791 * object. For example, if the current object represents a cell,
1792 * then the argument denotes the indices of the faces that bound the
1793 * cell. If the current object represents a line, the argument
1794 * denotes the indices of the vertices that bound it. And so on.
1795 */
1796 void
1797 set_bounding_object_indices(
1798 const std::initializer_list<int> &new_indices) const;
1799
1800 /**
1801 * The same as above but for `unsigned int`.
1802 */
1803 void
1804 set_bounding_object_indices(
1805 const std::initializer_list<unsigned int> &new_indices) const;
1806
1807 /**
1808 * Set the flag indicating, what <code>line_orientation()</code> will
1809 * return.
1810 *
1811 * It is only possible to set the line_orientation of faces in 3d (i.e.
1812 * <code>structdim==2 && dim==3</code>).
1813 */
1814 void
1815 set_line_orientation(const unsigned int line,
1816 const types::geometric_orientation orientation) const;
1817
1818 /**
1819 * Set the combined face orientation (i.e., the integer that uniquely encodes
1820 * the orientation, flip, and rotation). This function is only implemented for
1821 * objects which have faces, i.e., for structdim == dim.
1822 * For more information see the
1823 * @ref GlossCombinedOrientation "combined orientation glossary entry".
1824 *
1825 * @ingroup reordering
1826 */
1827 void
1828 set_combined_face_orientation(
1829 const unsigned int face,
1830 const types::geometric_orientation combined_orientation) const;
1831
1832 /**
1833 * Set the @p used flag. Only for internal use in the library.
1834 */
1835 void
1836 set_used_flag() const;
1837
1838 /**
1839 * Clear the @p used flag. Only for internal use in the library.
1840 */
1841 void
1842 clear_used_flag() const;
1843
1844 /**
1845 * Set the @p RefinementCase<dim> this TriaObject is refined with. Not
1846 * defined for <tt>structdim=1</tt> as lines are always refined resulting in
1847 * 2 children lines (isotropic refinement).
1848 *
1849 * You should know quite exactly what you are doing if you touch this
1850 * function. It is exclusively for internal use in the library.
1851 */
1852 void
1853 set_refinement_case(const RefinementCase<structdim> &ref_case) const;
1854
1855 /**
1856 * Clear the RefinementCase<dim> of this TriaObject, i.e. reset it to
1857 * RefinementCase<dim>::no_refinement.
1858 *
1859 * You should know quite exactly what you are doing if you touch this
1860 * function. It is exclusively for internal use in the library.
1861 */
1862 void
1863 clear_refinement_case() const;
1864
1865 /**
1866 * Set the index of the ith child. Since the children come at least in
1867 * pairs, we need to store the index of only every second child, i.e. of the
1868 * even numbered children. Make sure, that the index of child i=0 is set
1869 * first. Calling this function for odd numbered children is not allowed.
1870 */
1871 void
1872 set_children(const unsigned int i, const int index) const;
1873
1874 /**
1875 * Clear the child field, i.e. set it to a value which indicates that this
1876 * cell has no children.
1877 */
1878 void
1879 clear_children() const;
1880
1881 private:
1882 friend class Triangulation<dim, spacedim>;
1883
1884 friend struct dealii::internal::TriangulationImplementation::Implementation;
1885 friend struct dealii::internal::TriangulationImplementation::
1886 ImplementationMixedMesh;
1887 friend struct dealii::internal::TriaAccessorImplementation::Implementation;
1888 };
1889
1890
1891
1892 /**
1893 * This class is a specialization of <code>TriaAccessor<structdim, dim,
1894 * spacedim></code>
1895 * for the case that @p structdim is zero. This
1896 * class represents vertices in a triangulation of dimensionality
1897 * <code>dim</code> (i.e. 1 for a triangulation of lines, 2 for a
1898 * triangulation of quads, and 3 for a triangulation of hexes) that is
1899 * embedded in a space of dimensionality <code>spacedim</code> (for
1900 * <code>spacedim==dim</code> the triangulation represents a domain in
1901 * ${\mathbb R}^\text{dim}$, for <code>spacedim@>dim</code> the triangulation
1902 * is of a manifold embedded in a higher dimensional space).
1903 *
1904 * There is a further specialization of this class for the case that
1905 * @p dim equals one, i.e., for vertices of a one-dimensional triangulation,
1906 * since in that case vertices are also faces.
1907 *
1908 * @ingroup Accessors
1909 */
1910 template <int dim, int spacedim>
1911 class TriaAccessor<0, dim, spacedim>
1912 {
1913 public:
1914 /**
1915 * Dimension of the space the object represented by this accessor lives in.
1916 * For example, if this accessor represents a quad that is part of a
1917 * two-dimensional surface in four-dimensional space, then this value is four.
1918 */
1919 static constexpr unsigned int space_dimension = spacedim;
1920
1921 /**
1922 * Dimensionality of the object that the thing represented by this accessor
1923 * is part of. For example, if this accessor represents a line that is part
1924 * of a hexahedron, then this value will be three.
1925 */
1926 static constexpr unsigned int dimension = dim;
1927
1928 /**
1929 * Dimensionality of the current object represented by this accessor. For
1930 * example, if it is line (irrespective of whether it is part of a quad or
1931 * hex, and what dimension we are in), then this value equals 1.
1932 */
1933 static const unsigned int structure_dimension = 0;
1934
1935 /**
1936 * Pointer to internal data.
1937 */
1938 using AccessorData = void;
1939
1940 /**
1941 * Constructor. The second argument is the global index of the vertex we
1942 * point to.
1943 */
1944 TriaAccessor(const Triangulation<dim, spacedim> *tria,
1945 const unsigned int vertex_index);
1946
1947 /**
1948 * Constructor. This constructor exists in order to maintain interface
1949 * compatibility with the other accessor classes. @p index can be used to
1950 * set the global index of the vertex we point to.
1951 */
1952 TriaAccessor(const Triangulation<dim, spacedim> *tria = nullptr,
1953 const int level = 0,
1954 const int index = 0,
1955 const AccessorData * = nullptr);
1956
1957 /**
1958 * Constructor. Should never be called and thus produces an error.
1959 */
1960 template <int structdim2, int dim2, int spacedim2>
1961 TriaAccessor(const TriaAccessor<structdim2, dim2, spacedim2> &);
1962
1963 /**
1964 * Constructor. Should never be called and thus produces an error.
1965 */
1966 template <int structdim2, int dim2, int spacedim2>
1967 TriaAccessor(const InvalidAccessor<structdim2, dim2, spacedim2> &);
1968
1969 /**
1970 * Return the state of the iterator.
1971 */
1972 IteratorState::IteratorStates
1973 state() const;
1974
1975 /**
1976 * Level of this object. Vertices have no level, so this function always
1977 * returns zero.
1978 */
1979 static int
1980 level();
1981
1982 /**
1983 * Index of this object. Returns the global index of the vertex this object
1984 * points to.
1985 */
1986 int
1987 index() const;
1988
1989 /**
1990 * Return a reference to the triangulation which the object pointed to by this
1991 * class belongs to.
1992 */
1993 const Triangulation<dim, spacedim> &
1994 get_triangulation() const;
1995
1996 /**
1997 * @name Advancement of iterators
1998 */
1999 /**
2000 * @{
2001 */
2002 /**
2003 * This operator advances the iterator to the next element.
2004 */
2005 void
2006 operator++();
2007
2008 /**
2009 * This operator moves the iterator to the previous element.
2010 */
2011 void
2012 operator--();
2013 /**
2014 * Compare for equality.
2015 */
2016 bool
2017 operator==(const TriaAccessor &) const;
2018
2019 /**
2020 * Compare for inequality.
2021 */
2022 bool
2023 operator!=(const TriaAccessor &) const;
2024
2025 /**
2026 * @}
2027 */
2028
2029
2030 /**
2031 * @name Accessing sub-objects
2032 */
2033 /**
2034 * @{
2035 */
2036
2037 /**
2038 * Return the global index of i-th vertex of the current object. If @p i is
2039 * zero, this returns the index of the current point to which this object
2040 * refers. Otherwise, it throws an exception.
2041 *
2042 * Note that the returned value is only the index of the geometrical vertex.
2043 * It has nothing to do with possible degrees of freedom associated with it.
2044 * For this, see the @p DoFAccessor::vertex_dof_index functions.
2045 *
2046 * @note Despite the name, the index returned here is only global in the
2047 * sense that it is specific to a particular Triangulation object or, in the
2048 * case the triangulation is actually of type
2049 * parallel::distributed::Triangulation, specific to that part of the
2050 * distributed triangulation stored on the current processor.
2051 */
2052 unsigned int
2053 vertex_index(const unsigned int i = 0) const;
2054
2055 /**
2056 * Return a reference to the @p ith vertex. If i is zero, this returns a
2057 * reference to the current point to which this object refers. Otherwise, it
2058 * throws an exception.
2059 */
2060 Point<spacedim> &
2061 vertex(const unsigned int i = 0) const;
2062
2063 /**
2064 * Pointer to the @p ith line bounding this object. Will point to an invalid
2065 * object.
2066 */
2067 typename dealii::internal::TriangulationImplementation::
2068 Iterators<dim, spacedim>::line_iterator static line(const unsigned int);
2069
2070 /**
2071 * Line index of the @p ith line bounding this object. Throws an exception.
2072 */
2073 static unsigned int
2074 line_index(const unsigned int i);
2075
2076 /**
2077 * Pointer to the @p ith quad bounding this object.
2078 */
2079 static typename dealii::internal::TriangulationImplementation::
2080 Iterators<dim, spacedim>::quad_iterator
2081 quad(const unsigned int i);
2082
2083 /**
2084 * Quad index of the @p ith quad bounding this object. Throws an exception.
2085 */
2086 static unsigned int
2087 quad_index(const unsigned int i);
2088
2089 /**
2090 * @}
2091 */
2092
2093
2094 /**
2095 * @name Geometric information about an object
2096 */
2097 /**
2098 * @{
2099 */
2100
2101 /**
2102 * Diameter of the object. This function always returns zero.
2103 */
2104 double
2105 diameter() const;
2106
2107 /**
2108 * Length of an object in the direction of the given axis, specified in the
2109 * local coordinate system. See the documentation of GeometryInfo for the
2110 * meaning and enumeration of the local axes.
2111 *
2112 * This function always returns zero.
2113 */
2114 double
2115 extent_in_direction(const unsigned int axis) const;
2116
2117 /**
2118 * Return the center of this object, which of course coincides with the
2119 * location of the vertex this object refers to. The parameters @p
2120 * respect_manifold and @p interpolate_from_surrounding are not used. They
2121 * are there to provide the same interface as
2122 * <code>TriaAccessor<structdim,dim,spacedim></code>.
2123 */
2124 Point<spacedim>
2125 center(const bool respect_manifold = false,
2126 const bool interpolate_from_surrounding = false) const;
2127
2128 /**
2129 * Compute the `structdim`-dimensional measure of the present object. Since,
2130 * in this context, `structdim = 0`, this function always returns 1.
2131 *
2132 * @note This is consistent with what ReferenceCells::Vertex::volume()
2133 * returns.
2134 */
2135 double
2136 measure() const;
2137 /**
2138 * @}
2139 */
2140
2141 /**
2142 * @name Orientation of sub-objects
2143 */
2144 /**
2145 * @{
2146 */
2147
2148 /**
2149 * @brief Always return 0
2150 *
2151 * @ingroup reordering
2152 */
2153 static types::geometric_orientation
2154 combined_face_orientation(const unsigned int face);
2155
2156 /**
2157 * @brief Always return false
2158 */
2159 static bool
2160 face_orientation(const unsigned int face);
2161
2162 /**
2163 * @brief Always return false
2164 */
2165 static bool
2166 face_flip(const unsigned int face);
2167
2168 /**
2169 * @brief Always return false
2170 */
2171 static bool
2172 face_rotation(const unsigned int face);
2173
2174 /**
2175 * @brief Always return numbers::reverse_line_orientation
2176 */
2177 static types::geometric_orientation
2178 line_orientation(const unsigned int line);
2179
2180 /**
2181 * @}
2182 */
2183
2184 /**
2185 * @name Accessing children
2186 */
2187 /**
2188 * @{
2189 */
2190
2191 /**
2192 * Test whether the object has children. Always false.
2193 */
2194 static bool
2195 has_children();
2196
2197 /**
2198 * Return the number of immediate children of this object. This is always
2199 * zero.
2200 */
2201 static unsigned int
2202 n_children();
2203
2204 /**
2205 * Compute and return the number of active descendants of this objects.
2206 * Always zero.
2207 */
2208 static unsigned int
2209 n_active_descendants();
2210
2211 /**
2212 * Return the number of times that this object is refined. Always 0.
2213 */
2214 static unsigned int
2215 max_refinement_depth();
2216
2217 /**
2218 * @brief Return an invalid unsigned integer.
2219 */
2220 static unsigned int
2221 child_iterator_to_index(const TriaIterator<TriaAccessor<0, dim, spacedim>> &);
2222
2223 /**
2224 * @brief Return an invalid object.
2225 */
2226 static TriaIterator<TriaAccessor<0, dim, spacedim>>
2227 child(const unsigned int);
2228
2229 /**
2230 * @brief Return an invalid object.
2231 */
2232 static TriaIterator<TriaAccessor<0, dim, spacedim>>
2233 isotropic_child(const unsigned int);
2234
2235 /**
2236 * Always return no refinement.
2237 */
2238 static RefinementCase<0>
2239 refinement_case();
2240
2241 /**
2242 * @brief Returns -1
2243 */
2244 static int
2245 child_index(const unsigned int i);
2246
2247 /**
2248 * @brief Returns -1
2249 */
2250 static int
2251 isotropic_child_index(const unsigned int i);
2252 /**
2253 * @}
2254 */
2255
2256 /**
2257 * Return whether the vertex pointed to here is used.
2258 */
2259 bool
2260 used() const;
2261
2262 protected:
2263 /**
2264 * Copy operator. Since this is only called from iterators, do not return
2265 * anything, since the iterator will return itself.
2266 *
2267 * This method is protected, since it is only to be called from the iterator
2268 * class.
2269 */
2270 void
2271 copy_from(const TriaAccessor &);
2272
2273 /**
2274 * Comparison operator for accessors. This operator is used when comparing
2275 * iterators into objects of a triangulation, for example when putting
2276 * them into a `std::map`.
2277 *
2278 * This operator simply compares the global index of the vertex the
2279 * current object points to.
2280 */
2281 bool
2282 operator<(const TriaAccessor &other) const;
2283
2284 /**
2285 * Pointer to the triangulation we operate on.
2286 */
2287 const Triangulation<dim, spacedim> *tria;
2288
2289 /**
2290 * The global vertex index of the vertex this object corresponds to.
2291 */
2292 unsigned int global_vertex_index;
2293
2294 private:
2295 template <typename Accessor>
2296 friend class TriaRawIterator;
2297 template <typename Accessor>
2298 friend class TriaIterator;
2299 template <typename Accessor>
2300 friend class TriaActiveIterator;
2301 };
2302
2303
2304
2305 /**
2306 * This class is a specialization of <code>TriaAccessor<structdim, dim,
2307 * spacedim></code>
2308 * for the case that @p structdim is zero and @p dim is one. This
2309 * class represents vertices in a one-dimensional triangulation that is
2310 * embedded in a space of dimensionality <code>spacedim</code> (for
2311 * <code>spacedim==dim==1</code> the triangulation represents a domain in
2312 * ${\mathbb R}^\text{dim}$, for <code>spacedim@>dim==1</code> the triangulation
2313 * is of a manifold embedded in a higher dimensional space).
2314 *
2315 * The current specialization of the TriaAccessor<0,dim,spacedim> class
2316 * for vertices of a one-dimensional triangulation exists
2317 * since in the @p dim == 1 case vertices are also faces.
2318 *
2319 * @ingroup Accessors
2320 */
2321 template <int spacedim>
2322 class TriaAccessor<0, 1, spacedim>
2323 {
2324 public:
2325 /**
2326 * Dimension of the space the object represented by this accessor lives in.
2327 * For example, if this accessor represents a quad that is part of a
2328 * two-dimensional surface in four-dimensional space, then this value is four.
2329 */
2330 static constexpr unsigned int space_dimension = spacedim;
2331
2332 /**
2333 * Dimensionality of the object that the thing represented by this accessor
2334 * is part of. For example, if this accessor represents a line that is part
2335 * of a hexahedron, then this value will be three.
2336 */
2337 static constexpr unsigned int dimension = 1;
2338
2339 /**
2340 * Dimensionality of the current object represented by this accessor. For
2341 * example, if it is line (irrespective of whether it is part of a 2d or 3d
2342 * subobject), then this value equals 1.
2343 */
2344 static const unsigned int structure_dimension = 0;
2345
2346 /**
2347 * Pointer to internal data.
2348 */
2349 using AccessorData = void;
2350
2351 /**
2352 * Whether the vertex represented here is at the left end of the domain, the
2353 * right end, or in the interior.
2354 */
2355 enum VertexKind
2356 {
2357 /**
2358 * Left vertex.
2359 */
2360 left_vertex,
2361 /**
2362 * Interior vertex.
2363 */
2364 interior_vertex,
2365 /**
2366 * Right vertex.
2367 */
2368 right_vertex
2369 };
2370
2371 /**
2372 * Constructor.
2373 *
2374 * Since there is no mapping from vertices to cells, an accessor object for
2375 * a point has no way to figure out whether it is at the boundary of the
2376 * domain or not. Consequently, the second argument must be passed by the
2377 * object that generates this accessor -- e.g. a 1d cell that can figure out
2378 * whether its left or right vertex are at the boundary.
2379 *
2380 * The third argument is the global index of the vertex we point to.
2381 */
2382 TriaAccessor(const Triangulation<1, spacedim> *tria,
2383 const VertexKind vertex_kind,
2384 const unsigned int vertex_index);
2385
2386 /**
2387 * Constructor. This constructor exists in order to maintain interface
2388 * compatibility with the other accessor classes. However, it doesn't do
2389 * anything useful here and so may not actually be called.
2390 */
2391 TriaAccessor(const Triangulation<1, spacedim> *tria = nullptr,
2392 const int = 0,
2393 const int = 0,
2394 const AccessorData * = nullptr);
2395
2396 /**
2397 * Constructor. Should never be called and thus produces an error.
2398 */
2399 template <int structdim2, int dim2, int spacedim2>
2400 TriaAccessor(const TriaAccessor<structdim2, dim2, spacedim2> &);
2401
2402 /**
2403 * Constructor. Should never be called and thus produces an error.
2404 */
2405 template <int structdim2, int dim2, int spacedim2>
2406 TriaAccessor(const InvalidAccessor<structdim2, dim2, spacedim2> &);
2407
2408 /**
2409 * Copy operator. Since this is only called from iterators, do not return
2410 * anything, since the iterator will return itself.
2411 */
2412 void
2413 copy_from(const TriaAccessor &);
2414
2415 /**
2416 * Copy operator. We need this function to support generic
2417 * programming, but it just throws an exception because it cannot do
2418 * the required operations.
2419 */
2420 void
2421 copy_from(const TriaAccessorBase<0, 1, spacedim> &);
2422
2423 /**
2424 * Return the state of the iterator. Since an iterator to points can not be
2425 * incremented or decremented, its state remains constant, and in particular
2426 * equal to IteratorState::valid.
2427 */
2428 static IteratorState::IteratorStates
2429 state();
2430
2431 /**
2432 * Level of this object. Vertices have no level, so this function always
2433 * returns zero.
2434 */
2435 static int
2436 level();
2437
2438 /**
2439 * Index of this object. Returns the global index of the vertex this object
2440 * points to.
2441 */
2442 int
2443 index() const;
2444
2445 /**
2446 * Return a reference to the triangulation which the object pointed to by this
2447 * class belongs to.
2448 */
2449 const Triangulation<1, spacedim> &
2450 get_triangulation() const;
2451
2452 /**
2453 * @name Advancement of iterators
2454 */
2455 /**
2456 * @{
2457 */
2458 /**
2459 * This operator advances the iterator to the next element. For points, this
2460 * operation is not defined, so you can't iterate over point iterators.
2461 */
2462 void
2463 operator++() const;
2464
2465 /**
2466 * This operator moves the iterator to the previous element. For points,
2467 * this operation is not defined, so you can't iterate over point iterators.
2468 */
2469 void
2470 operator--() const;
2471 /**
2472 * Compare for equality.
2473 */
2474 bool
2475 operator==(const TriaAccessor &) const;
2476
2477 /**
2478 * Compare for inequality.
2479 */
2480 bool
2481 operator!=(const TriaAccessor &) const;
2482
2483 /**
2484 * Comparison operator for accessors. This operator is used when comparing
2485 * iterators into objects of a triangulation, for example when putting
2486 * them into a `std::map`.
2487 *
2488 * This operator simply compares the global index of the vertex the
2489 * current object points to.
2490 */
2491 bool
2492 operator<(const TriaAccessor &other) const;
2493
2494 /**
2495 * @}
2496 */
2497
2498 /**
2499 * @name Accessing sub-objects
2500 */
2501 /**
2502 * @{
2503 */
2504
2505 /**
2506 * Return the global index of i-th vertex of the current object. If i is
2507 * zero, this returns the index of the current point to which this object
2508 * refers. Otherwise, it throws an exception.
2509 *
2510 * Note that the returned value is only the index of the geometrical vertex.
2511 * It has nothing to do with possible degrees of freedom associated with it.
2512 * For this, see the @p DoFAccessor::vertex_dof_index functions.
2513 *
2514 * @note Despite the name, the index returned here is only global in the
2515 * sense that it is specific to a particular Triangulation object or, in the
2516 * case the triangulation is actually of type
2517 * parallel::distributed::Triangulation, specific to that part of the
2518 * distributed triangulation stored on the current processor.
2519 */
2520 unsigned int
2521 vertex_index(const unsigned int i = 0) const;
2522
2523 /**
2524 * Return a reference to the @p ith vertex. If i is zero, this returns a
2525 * reference to the current point to which this object refers. Otherwise, it
2526 * throws an exception.
2527 */
2528 Point<spacedim> &
2529 vertex(const unsigned int i = 0) const;
2530
2531 /**
2532 * Return the center of this object, which of course coincides with the
2533 * location of the vertex this object refers to.
2534 */
2535 Point<spacedim>
2536 center() const;
2537
2538 /**
2539 * Pointer to the @p ith line bounding this object. Will point to an invalid
2540 * object.
2541 */
2542 typename dealii::internal::TriangulationImplementation::
2543 Iterators<1, spacedim>::line_iterator static line(const unsigned int);
2544
2545 /**
2546 * Line index of the @p ith line bounding this object.
2547 *
2548 * Implemented only for <tt>structdim>1</tt>, otherwise an exception
2549 * generated.
2550 */
2551 static unsigned int
2552 line_index(const unsigned int i);
2553
2554 /**
2555 * Pointer to the @p ith quad bounding this object.
2556 */
2557 static typename dealii::internal::TriangulationImplementation::
2558 Iterators<1, spacedim>::quad_iterator
2559 quad(const unsigned int i);
2560
2561 /**
2562 * Quad index of the @p ith quad bounding this object.
2563 *
2564 * Implemented only for <tt>structdim>2</tt>, otherwise an exception
2565 * generated.
2566 */
2567 static unsigned int
2568 quad_index(const unsigned int i);
2569
2570 /**
2571 * @}
2572 */
2573
2574 /**
2575 * @name Geometric information about an object
2576 */
2577 /**
2578 * @{
2579 */
2580
2581 /**
2582 * Return 1.
2583 *
2584 * @note This is consistent with what ReferenceCells::Vertex::volume()
2585 * returns.
2586 */
2587 static double
2588 measure();
2589
2590 /**
2591 * @}
2592 */
2593
2594 /**
2595 * Return whether this point is at the boundary of the one-dimensional
2596 * triangulation we deal with here.
2597 */
2598 bool
2599 at_boundary() const;
2600
2601 /**
2602 * Return the boundary indicator of this object. The convention for one
2603 * dimensional triangulations is that left end vertices (of each line
2604 * segment from which the triangulation may be constructed) have boundary
2605 * indicator zero, and right end vertices have boundary indicator one,
2606 * unless explicitly set differently.
2607 *
2608 * If the return value is the special value
2609 * numbers::internal_face_boundary_id, then this object is in the interior
2610 * of the domain.
2611 *
2612 * @see
2613 * @ref GlossBoundaryIndicator "Glossary entry on boundary indicators"
2614 */
2615 types::boundary_id
2616 boundary_id() const;
2617
2618 /**
2619 * Return a constant reference to the manifold object used for this object.
2620 */
2621 const Manifold<1, spacedim> &
2622 get_manifold() const;
2623
2624 /**
2625 * Return the manifold indicator of this object.
2626 *
2627 * @see
2628 * @ref GlossManifoldIndicator "Glossary entry on manifold indicators".
2629 */
2630 types::manifold_id
2631 manifold_id() const;
2632
2633
2634 /**
2635 * @name User data
2636 */
2637 /**
2638 * @{
2639 */
2640 /**
2641 * Read the user flag. See
2642 * @ref GlossUserFlags
2643 * for more information.
2644 */
2645 bool
2646 user_flag_set() const;
2647
2648 /**
2649 * Set the user flag. See
2650 * @ref GlossUserFlags
2651 * for more information.
2652 */
2653 void
2654 set_user_flag() const;
2655
2656 /**
2657 * Clear the user flag. See
2658 * @ref GlossUserFlags
2659 * for more information.
2660 */
2661 void
2662 clear_user_flag() const;
2663
2664 /**
2665 * Set the user flag for this and all descendants. See
2666 * @ref GlossUserFlags
2667 * for more information.
2668 */
2669 void
2670 recursively_set_user_flag() const;
2671
2672 /**
2673 * Clear the user flag for this and all descendants. See
2674 * @ref GlossUserFlags
2675 * for more information.
2676 */
2677 void
2678 recursively_clear_user_flag() const;
2679
2680 /**
2681 * Reset the user data to zero, independent if pointer or index. See
2682 * @ref GlossUserData
2683 * for more information.
2684 */
2685 void
2686 clear_user_data() const;
2687
2688 /**
2689 * Set the user pointer to @p p.
2690 *
2691 * @note User pointers and user indices are mutually exclusive. Therefore,
2692 * you can only use one of them, unless you call
2693 * Triangulation::clear_user_data() in between.
2694 *
2695 * See
2696 * @ref GlossUserData
2697 * for more information.
2698 */
2699 void
2700 set_user_pointer(void *p) const;
2701
2702 /**
2703 * Reset the user pointer to `nullptr`. See
2704 * @ref GlossUserData
2705 * for more information.
2706 */
2707 void
2708 clear_user_pointer() const;
2709
2710 /**
2711 * Access the value of the user pointer. It is in the responsibility of the
2712 * user to make sure that the pointer points to something useful. You should
2713 * use the new style cast operator to maintain a minimum of type safety,
2714 * e.g.
2715 *
2716 * @note User pointers and user indices are mutually exclusive. Therefore,
2717 * you can only use one of them, unless you call
2718 * Triangulation::clear_user_data() in between. <tt>A
2719 * *a=static_cast<A*>(cell->user_pointer());</tt>.
2720 *
2721 * See
2722 * @ref GlossUserData
2723 * for more information.
2724 */
2725 void *
2726 user_pointer() const;
2727
2728 /**
2729 * Set the user pointer of this object and all its children to the given
2730 * value. This is useful for example if all cells of a certain subdomain, or
2731 * all faces of a certain part of the boundary should have user pointers
2732 * pointing to objects describing this part of the domain or boundary.
2733 *
2734 * Note that the user pointer is not inherited under mesh refinement, so
2735 * after mesh refinement there might be cells or faces that don't have user
2736 * pointers pointing to the describing object. In this case, simply loop
2737 * over all the elements of the coarsest level that has this information,
2738 * and use this function to recursively set the user pointer of all finer
2739 * levels of the triangulation.
2740 *
2741 * @note User pointers and user indices are mutually exclusive. Therefore,
2742 * you can only use one of them, unless you call
2743 * Triangulation::clear_user_data() in between.
2744 *
2745 * See
2746 * @ref GlossUserData
2747 * for more information.
2748 */
2749 void
2750 recursively_set_user_pointer(void *p) const;
2751
2752 /**
2753 * Clear the user pointer of this object and all of its descendants. The
2754 * same holds as said for the recursively_set_user_pointer() function. See
2755 * @ref GlossUserData
2756 * for more information.
2757 */
2758 void
2759 recursively_clear_user_pointer() const;
2760
2761 /**
2762 * Set the user index to @p p.
2763 *
2764 * @note User pointers and user indices are mutually exclusive. Therefore,
2765 * you can only use one of them, unless you call
2766 * Triangulation::clear_user_data() in between. See
2767 * @ref GlossUserData
2768 * for more information.
2769 */
2770 void
2771 set_user_index(const unsigned int p) const;
2772
2773 /**
2774 * Reset the user index to 0. See
2775 * @ref GlossUserData
2776 * for more information.
2777 */
2778 void
2779 clear_user_index() const;
2780
2781 /**
2782 * Access the value of the user index.
2783 *
2784 * @note User pointers and user indices are mutually exclusive. Therefore,
2785 * you can only use one of them, unless you call
2786 * Triangulation::clear_user_data() in between.
2787 *
2788 * See
2789 * @ref GlossUserData
2790 * for more information.
2791 */
2792 unsigned int
2793 user_index() const;
2794
2795 /**
2796 * Set the user index of this object and all its children.
2797 *
2798 * Note that the user index is not inherited under mesh refinement, so after
2799 * mesh refinement there might be cells or faces that don't have the
2800 * expected user indices. In this case, simply loop over all the elements of
2801 * the coarsest level that has this information, and use this function to
2802 * recursively set the user index of all finer levels of the triangulation.
2803 *
2804 * @note User pointers and user indices are mutually exclusive. Therefore,
2805 * you can only use one of them, unless you call
2806 * Triangulation::clear_user_data() in between.
2807 *
2808 * See
2809 * @ref GlossUserData
2810 * for more information.
2811 */
2812 void
2813 recursively_set_user_index(const unsigned int p) const;
2814
2815 /**
2816 * Clear the user index of this object and all of its descendants. The same
2817 * holds as said for the recursively_set_user_index() function.
2818 *
2819 * See
2820 * @ref GlossUserData
2821 * for more information.
2822 */
2823 void
2824 recursively_clear_user_index() const;
2825 /**
2826 * @}
2827 */
2828
2829 /**
2830 * @name Orientation of sub-objects
2831 */
2832 /**
2833 * @{
2834 */
2835
2836 /**
2837 * @brief Always return 0
2838 *
2839 * @ingroup reordering
2840 */
2841 static types::geometric_orientation
2842 combined_face_orientation(const unsigned int face);
2843
2844 /**
2845 * @brief Always return false
2846 */
2847 static bool
2848 face_orientation(const unsigned int face);
2849
2850 /**
2851 * @brief Always return false
2852 */
2853 static bool
2854 face_flip(const unsigned int face);
2855
2856 /**
2857 * @brief Always return false
2858 */
2859 static bool
2860 face_rotation(const unsigned int face);
2861
2862 /**
2863 * @brief Always return numbers::reverse_line_orientation
2864 */
2865 static types::geometric_orientation
2866 line_orientation(const unsigned int line);
2867
2868 /**
2869 * @}
2870 */
2871
2872 /**
2873 * @name Accessing children
2874 */
2875 /**
2876 * @{
2877 */
2878
2879 /**
2880 * Test whether the object has children. Always false.
2881 */
2882 static bool
2883 has_children();
2884
2885 /**
2886 * Return the number of immediate children of this object.This is always
2887 * zero in dimension 0.
2888 */
2889 static unsigned int
2890 n_children();
2891
2892 /**
2893 * Compute and return the number of active descendants of this objects.
2894 * Always zero.
2895 */
2896 static unsigned int
2897 n_active_descendants();
2898
2899 /**
2900 * Return the number of times that this object is refined. Always 0.
2901 */
2902 static unsigned int
2903 max_refinement_depth();
2904
2905 /**
2906 * @brief Return an invalid unsigned integer.
2907 */
2908 static unsigned int
2909 child_iterator_to_index(const TriaIterator<TriaAccessor<0, 1, spacedim>> &);
2910
2911 /**
2912 * @brief Return an invalid object
2913 */
2914 static TriaIterator<TriaAccessor<0, 1, spacedim>>
2915 child(const unsigned int);
2916
2917 /**
2918 * @brief Return an invalid object
2919 */
2920 static TriaIterator<TriaAccessor<0, 1, spacedim>>
2921 isotropic_child(const unsigned int);
2922
2923 /**
2924 * Always return no refinement.
2925 */
2926 static RefinementCase<0>
2927 refinement_case();
2928
2929 /**
2930 * @brief Returns -1
2931 */
2932 static int
2933 child_index(const unsigned int i);
2934
2935 /**
2936 * @brief Returns -1
2937 */
2938 static int
2939 isotropic_child_index(const unsigned int i);
2940 /**
2941 * @}
2942 */
2943
2944 /**
2945 * @name Dealing with boundary indicators
2946 */
2947 /**
2948 * @{
2949 */
2950
2951 /**
2952 * Set the boundary indicator. The same applies as for the
2953 * <tt>boundary_id()</tt> function.
2954 *
2955 * @warning You should never set the boundary indicator of an interior face
2956 * (a face not at the boundary of the domain), or set the boundary
2957 * indicator of an exterior face to numbers::internal_face_boundary_id (this
2958 * value is reserved for another purpose). Algorithms may not work or
2959 * produce very confusing results if boundary cells have a boundary
2960 * indicator of numbers::internal_face_boundary_id or if interior cells have
2961 * boundary indicators other than numbers::internal_face_boundary_id.
2962 * Unfortunately, the current object has no means of finding out whether it
2963 * really is at the boundary of the domain and so cannot determine whether
2964 * the value you are trying to set makes sense under the current
2965 * circumstances.
2966 *
2967 * @see
2968 * @ref GlossBoundaryIndicator "Glossary entry on boundary indicators"
2969 */
2970 void
2971 set_boundary_id(const types::boundary_id) const;
2972
2973 /**
2974 * Set the manifold indicator of this vertex. This does nothing so far since
2975 * manifolds are only used to refine and map objects, but vertices are not
2976 * refined and the mapping is trivial. This function is here only to allow
2977 * dimension independent programming.
2978 */
2979 void
2980 set_manifold_id(const types::manifold_id);
2981
2982 /**
2983 * Set the boundary indicator of this object and all of its
2984 * lower-dimensional sub-objects. Since this object only represents a single
2985 * vertex, there are no lower-dimensional object and this function is
2986 * equivalent to calling set_boundary_id() with the same argument.
2987 *
2988 * @see
2989 * @ref GlossBoundaryIndicator "Glossary entry on boundary indicators"
2990 */
2991 void
2992 set_all_boundary_ids(const types::boundary_id) const;
2993
2994 /**
2995 * Set the manifold indicator of this object and all of its
2996 * lower-dimensional sub-objects. Since this object only represents a single
2997 * vertex, there are no lower-dimensional object and this function is
2998 * equivalent to calling set_manifold_id() with the same argument.
2999 *
3000 * @ingroup manifold
3001 *
3002 * @see
3003 * @ref GlossManifoldIndicator "Glossary entry on manifold indicators"
3004 */
3005 void
3006 set_all_manifold_ids(const types::manifold_id);
3007 /**
3008 * @}
3009 */
3010
3011 /**
3012 * Return whether the vertex pointed to here is used.
3013 */
3014 bool
3015 used() const;
3016
3017 /**
3018 * Reference cell type of the current object.
3019 */
3020 ReferenceCell
3021 reference_cell() const;
3022
3023 /**
3024 * Number of vertices.
3025 */
3026 unsigned int
3027 n_vertices() const;
3028
3029 /**
3030 * Number of lines.
3031 */
3032 unsigned int
3033 n_lines() const;
3034
3035 /**
3036 * Return an object that can be thought of as an array containing all indices
3037 * from zero to n_vertices().
3038 */
3039 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
3040 vertex_indices() const;
3041
3042 /**
3043 * Return an object that can be thought of as an array containing all indices
3044 * from zero to n_lines().
3045 */
3046 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
3047 line_indices() const;
3048
3049 protected:
3050 /**
3051 * Pointer to the triangulation we operate on.
3052 */
3053 const Triangulation<1, spacedim> *tria;
3054
3055 /**
3056 * Whether this is a left end, right end, or interior vertex. This
3057 * information is provided by the cell at the time of creation.
3058 */
3059 VertexKind vertex_kind;
3060
3061 /**
3062 * The global vertex index of the vertex this object corresponds to.
3063 */
3064 unsigned int global_vertex_index;
3065 };
3066
3067
3068
3069 /**
3070 * This class allows access to a cell: a line in one dimension, a quad in two
3071 * dimension, etc.
3072 *
3073 * The following refers to any dimension:
3074 *
3075 * This class allows access to a <tt>cell</tt>, which is a line in 1d and a
3076 * quad in 2d. Cells have more functionality than lines or quads by
3077 * themselves, for example they can be flagged for refinement, they have
3078 * neighbors, they have the possibility to check whether they are at the
3079 * boundary etc. This class offers access to all this data.
3080 *
3081 * @ingroup grid
3082 * @ingroup Accessors
3083 */
3084 template <int dim, int spacedim = dim>
3085 class CellAccessor : public TriaAccessor<dim, dim, spacedim>
3086 {
3087 public:
3088 /**
3089 * Propagate the AccessorData type into the present class.
3090 */
3091 using AccessorData = typename TriaAccessor<dim, dim, spacedim>::AccessorData;
3092
3093 /**
3094 * Define the type of the container this is part of.
3095 */
3096 using Container = Triangulation<dim, spacedim>;
3097
3098 /**
3099 * @name Constructors
3100 */
3101 /**
3102 * @{
3103 */
3104
3105 /**
3106 * Constructor.
3107 */
3108 CellAccessor(const Triangulation<dim, spacedim> *parent = nullptr,
3109 const int level = -1,
3110 const int index = -1,
3111 const AccessorData *local_data = nullptr);
3112
3113 /**
3114 * Copy constructor.
3115 */
3116 CellAccessor(const TriaAccessor<dim, dim, spacedim> &cell_accessor);
3117
3118 /**
3119 * Conversion constructor. This constructor exists to make certain
3120 * constructs simpler to write in dimension independent code. For example,
3121 * it allows assigning a face iterator to a line iterator, an operation that
3122 * is useful in 2d but doesn't make any sense in 3d. The constructor here
3123 * exists for the purpose of making the code conform to C++ but it will
3124 * unconditionally abort; in other words, assigning a face iterator to a
3125 * line iterator is better put into an if-statement that checks that the
3126 * dimension is two, and assign to a quad iterator in 3d (an operator that,
3127 * without this constructor would be illegal if we happen to compile for
3128 * 2d).
3129 */
3130 template <int structdim2, int dim2, int spacedim2>
3131 CellAccessor(const InvalidAccessor<structdim2, dim2, spacedim2> &);
3132
3133 /**
3134 * Another conversion operator between objects that don't make sense, just
3135 * like the previous one.
3136 */
3137 template <int structdim2, int dim2, int spacedim2>
3138 CellAccessor(const TriaAccessor<structdim2, dim2, spacedim2> &);
3139
3140 /**
3141 * Copy constructor.
3142 */
3143 CellAccessor(const CellAccessor<dim, spacedim> &) = default;
3144
3145 /**
3146 * Move constructor.
3147 */
3148 // NOLINTNEXTLINE OSX does not compile with noexcept
3149 CellAccessor(CellAccessor<dim, spacedim> &&) = default;
3150
3151 /**
3152 * Destructor.
3153 */
3154 ~CellAccessor() = default;
3155
3156 /**
3157 * Copy operator. These operators are usually used in a context like
3158 * <tt>iterator a,b; *a=*b;</tt>. Presumably, the intent here is to copy the
3159 * object pointed to
3160 * by @p b to the object pointed to by @p a. However, the result of
3161 * dereferencing an iterator is not an object but an accessor; consequently,
3162 * this operation is not useful for iterators on triangulations.
3163 * Consequently, this operator is declared as deleted and can not be used.
3164 */
3165 CellAccessor<dim, spacedim> &
3166 operator=(const CellAccessor<dim, spacedim> &) = delete;
3167
3168 /**
3169 * Move assignment operator.
3170 */
3171 // NOLINTNEXTLINE OSX does not compile with noexcept
3172 CellAccessor<dim, spacedim> &
3173 operator=(CellAccessor<dim, spacedim> &&) = default; // NOLINT
3174
3175 /**
3176 * @}
3177 */
3178
3179 /**
3180 * @name Converting iterators
3181 */
3182 /**
3183 * @{
3184 */
3185
3186 /**
3187 * A function that converts a Triangulation active cell iterator to a
3188 * DoFHandler active cell iterator, or a DoFHandler active cell iterator
3189 * to an active cell iterator of another DoFHandler. The @p iterator must be
3190 * associated with the triangulation of the @p dof_handler.
3191 *
3192 * @param dof_handler The DoFHandler for the output active cell iterator.
3193 * @return An active cell iterator for the @p dof_handler, matching the cell
3194 * referenced by the input @p iterator. The type of the
3195 * returned object is a DoFHandler::active_cell_iterator.
3196 */
3197 TriaActiveIterator<DoFCellAccessor<dim, spacedim, false>>
3198 as_dof_handler_iterator(const DoFHandler<dim, spacedim> &dof_handler) const;
3199
3200 /**
3201 * A function similar to as_dof_handler_iterator(). It converts
3202 * a Triangulation active/level cell iterator to a
3203 * DoFHandler active level cell iterator, or a DoFHandler level active/cell
3204 * iterator to a level cell iterator of another DoFHandler. The
3205 * @p iterator must be associated with the triangulation of the
3206 * @p dof_handler.
3207 */
3208 TriaIterator<DoFCellAccessor<dim, spacedim, true>>
3209 as_dof_handler_level_iterator(
3210 const DoFHandler<dim, spacedim> &dof_handler) const;
3211
3212
3213 /**
3214 * @}
3215 */
3216
3217 /**
3218 * @name Accessing sub-objects and neighbors
3219 */
3220 /**
3221 * @{
3222 */
3223
3224 /**
3225 * Return a pointer to the @p ith child. Overloaded version which returns a
3226 * more reasonable iterator class.
3227 */
3228 TriaIterator<CellAccessor<dim, spacedim>>
3229 child(const unsigned int i) const;
3230
3231 /**
3232 * Return an array of iterators to all children of this cell.
3233 */
3234 boost::container::small_vector<TriaIterator<CellAccessor<dim, spacedim>>,
3235 GeometryInfo<dim>::max_children_per_cell>
3236 child_iterators() const;
3237
3238 /**
3239 * Return an iterator to the @p ith face of this cell.
3240 */
3241 TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>
3242 face(const unsigned int i) const;
3243
3244 /**
3245 * Return the face number of @p face on the current cell. This is the
3246 * inverse function of TriaAccessor::face().
3247 */
3248 unsigned int
3249 face_iterator_to_index(
3250 const TriaIterator<TriaAccessor<dim - 1, dim, spacedim>> &face) const;
3251
3252 /**
3253 * Return an array of iterators to all faces of this cell.
3254 */
3255 boost::container::small_vector<
3256 TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>,
3257 #ifndef _MSC_VER // MSVC prior to 2022 cannot use a constexpr function this way
3258 ReferenceCells::max_n_faces<dim>()
3259 #else
3260 GeometryInfo<dim>::faces_per_cell
3261 #endif
3262 >
3263 face_iterators() const;
3264
3265 /**
3266 * Return the (global) index of the @p ith face of this cell.
3267 *
3268 * @note Despite the name, the index returned here is only global in the
3269 * sense that it is specific to a particular Triangulation object or, in the
3270 * case the triangulation is actually of type
3271 * parallel::distributed::Triangulation, specific to that part of the
3272 * distributed triangulation stored on the current processor.
3273 */
3274 unsigned int
3275 face_index(const unsigned int i) const;
3276
3277 /**
3278 * Return an iterator to that cell that neighbors the present cell on the
3279 * given face and subface number.
3280 *
3281 * To succeed, the present cell must not be further refined, and the
3282 * neighbor on the given face must be further refined exactly once; the
3283 * returned cell is then a child of that neighbor.
3284 *
3285 * The function may not be called in 1d, since there we have no subfaces.
3286 * The implementation of this function is rather straightforward in 2d, by
3287 * first determining which face of the neighbor cell the present cell is
3288 * bordering on (this is what the @p neighbor_of_neighbor function does),
3289 * and then asking @p GeometryInfo::child_cell_on_subface for the index of
3290 * the child.
3291 *
3292 * However, the situation is more complicated in 3d, since there faces may
3293 * have more than one orientation, and we have to use @p face_orientation,
3294 * @p face_flip and @p face_rotation for both this and the neighbor cell to
3295 * figure out which cell we want to have.
3296 *
3297 * This can lead to surprising results: if we are sitting on a cell and are
3298 * asking for a cell behind subface <tt>sf</tt>, then this means that we are
3299 * considering the subface for the face in the natural direction for the
3300 * present cell. However, if the face as seen from this cell has
3301 * <tt>face_orientation()==false</tt>, then the child of the face that
3302 * separates the present cell from the neighboring cell's child is not
3303 * necessarily the @p sf-th child of the face of this cell. This is so
3304 * because the @p subface_no on a cell corresponds to the subface with
3305 * respect to the intrinsic ordering of the present cell, whereas children
3306 * of face iterators are computed with respect to the intrinsic ordering of
3307 * faces; these two orderings are only identical if the face orientation is
3308 * @p true, and reversed otherwise.
3309 *
3310 * Similarly, effects of <tt>face_flip()==true</tt> and
3311 * <tt>face_rotation()==true()</tt>, both of which indicate a non-standard
3312 * face have to be considered.
3313 *
3314 * Fortunately, this is only very rarely of concern, since usually one
3315 * simply wishes to loop over all finer neighbors at a given face of an
3316 * active cell. Only in the process of refinement of a Triangulation we want
3317 * to set neighbor information for both our child cells and the neighbor's
3318 * children. Since we can respect orientation of faces from our current cell
3319 * in that case, we do NOT respect face_orientation, face_flip and
3320 * face_rotation of the present cell within this function, i.e. the returned
3321 * neighbor's child is behind subface @p subface concerning the intrinsic
3322 * ordering of the given face.
3323 */
3324 TriaIterator<CellAccessor<dim, spacedim>>
3325 neighbor_child_on_subface(const unsigned int face_no,
3326 const unsigned int subface_no) const;
3327
3328 /**
3329 * Return an iterator to the neighboring cell on the other side of the face
3330 * with number @p face_no. If the neighbor does not exist,
3331 * i.e., if the face with number @p face_no of the current object is at the boundary, then
3332 * an invalid iterator is returned. In detail, the smallest cell `neighbor`
3333 * for which `cell->face(face_no)` is a subset of
3334 * `neighbor->face(opposite_face_no)`, where `opposite_face_no` is the face
3335 * number opposite to `face_no`.
3336 *
3337 * Consequently, the index @p face_no must be less than n_faces().
3338 *
3339 * For example, consider the following situation:
3340 * @image html limit_level_difference_at_vertices_anisotropic.png ""
3341 *
3342 * Here, if you are on cell `1.3` and ask for its left neighbor (which is,
3343 * according to the conventions spelled out in the GeometryInfo class, its
3344 * <i>zeroth</i> neighbor), then you will get the parent cell of `3.5`, since
3345 * this is the smallest cell for which we have `(1.3)->face(0) ==
3346 * (3.5)->parent()->face(1)`. Note, that you will not obtain the parent cell
3347 * of `2.8`.
3348 *
3349 * Further, if you ask for the right (i.e. the <i>first</i>) neighbor of cell
3350 * `4.1`, then you will get cell `1.3`. Consequently, there are two
3351 * neighboring cells that differ by three in their levels. In fact, using
3352 * anisotropic refinement it is possible to generate arbitrary large
3353 * differences in the level of neighboring cells. Perform e.g. arbitrarily
3354 * many `y`-refinements of cell `4.1` and its children. While the second and
3355 * third neighbors are being refined as well, due to the avoidance of multiple
3356 * hanging nodes, cell `1.3` always remains as neighbor of the resulting
3357 * right-most child.
3358 *
3359 * On the other hand, if you were at cell `3.3` and ask for its third
3360 * neighbor, cell `4.1` will be returned, since it is the smallest cell that
3361 * fulfills the described property. This shows, that the neighbor <i>can</i>
3362 * have a higher level than the cell itself.
3363 *
3364 * However, using only isotropic refinement, the neighbor will have <i>at
3365 * most</i> the level as the cell itself. This can be verified in the bottom
3366 * half of the image, where only isotropic refinement was done: The first
3367 * neighbor of `3.3` is given by `2.6`. Further refinement of `2.6` will
3368 * generate a new first neighbor with level 3, but any further refinements of
3369 * that child will not affect the neighbor of cell `3.3`. Due to the avoidance
3370 * of multiple hanging nodes on a mesh, it is also impossible to obtain a
3371 * coarser cell than `2.6` as the first neighbor of `3.3`. Consequently, the
3372 * neighbor of a fully isotropic refined mesh has either the same level as the
3373 * cell itself, or is exactly one level coarser.
3374 */
3375 TriaIterator<CellAccessor<dim, spacedim>>
3376 neighbor(const unsigned int face_no) const;
3377
3378 /**
3379 * Return the cell index of the neighboring cell on the other side of the face
3380 * with index @p face_no. If the neighbor does not exist, this function returns -1.
3381 *
3382 * This function is equivalent to <tt>cell->neighbor(face_no)->index()</tt>.
3383 * See neighbor() for more details.
3384 */
3385 int
3386 neighbor_index(const unsigned int face_no) const;
3387
3388 /**
3389 * Return the level of the neighboring cell on the other side of the face with
3390 * number @p face_no. If the neighbor does not exist, this function returns -1.
3391 *
3392 * This function is equivalent to `cell->neighbor(face_no)->level()`.
3393 * See neighbor() for more details.
3394 */
3395 int
3396 neighbor_level(const unsigned int face_no) const;
3397
3398 /**
3399 * Return the how-many'th neighbor this cell is of
3400 * <tt>cell->neighbor(face_no)</tt>, i.e. return @p other_face_no such that
3401 * <tt>cell->neighbor(face_no)->neighbor(other_face_no)==cell</tt>. This
3402 * function is the right one if you want to know how to get back from a
3403 * neighbor to the present cell.
3404 *
3405 * Note that this operation is only useful if the neighbor is not coarser
3406 * than the present cell. If the neighbor is coarser this function throws an
3407 * exception. Use the @p neighbor_of_coarser_neighbor function in that case.
3408 */
3409 unsigned int
3410 neighbor_of_neighbor(const unsigned int face_no) const;
3411
3412 /**
3413 * Return, whether the neighbor is coarser then the present cell. This is
3414 * important in case of anisotropic refinement where this information does
3415 * not depend on the levels of the cells.
3416 *
3417 * Note, that in an anisotropic setting, a cell can only be coarser than
3418 * another one at a given face, not on a general basis. The face of the
3419 * finer cell is contained in the corresponding face of the coarser cell,
3420 * the finer face is either a child or a grandchild of the coarser face.
3421 */
3422 bool
3423 neighbor_is_coarser(const unsigned int face_no) const;
3424
3425 /**
3426 * This function is a generalization of the @p neighbor_of_neighbor function
3427 * for the case of a coarser neighbor. It returns a pair of numbers, face_no
3428 * and subface_no, with the following property, if the neighbor is not
3429 * refined: <tt>cell->neighbor(neighbor)->neighbor_child_on_subface(face_no,
3430 * subface_no)==cell</tt>. In 3d, a coarser neighbor can still be refined.
3431 * In that case subface_no denotes the child index of the neighbors face
3432 * that relates to our face:
3433 * <tt>cell->neighbor(neighbor)->face(face_no)->child(subface_no)==cell->face(neighbor)</tt>.
3434 * This case in 3d and how it can happen is discussed in the introduction of
3435 * the step-30 tutorial program.
3436 *
3437 * This function is impossible for <tt>dim==1</tt>.
3438 */
3439 std::pair<unsigned int, unsigned int>
3440 neighbor_of_coarser_neighbor(const unsigned int neighbor) const;
3441
3442 /**
3443 * This function is a generalization of the @p neighbor_of_neighbor and the
3444 * @p neighbor_of_coarser_neighbor functions. It checks whether the neighbor
3445 * is coarser or not and calls the respective function. In both cases, only
3446 * the face_no is returned.
3447 */
3448 unsigned int
3449 neighbor_face_no(const unsigned int neighbor) const;
3450
3451 /**
3452 * Compatibility interface with DoFCellAccessor. Always returns @p false.
3453 */
3454 static bool
3455 is_level_cell();
3456
3457 /**
3458 * @}
3459 */
3460 /**
3461 * @name Dealing with periodic neighbors
3462 */
3463 /**
3464 * @{
3465 */
3466 /**
3467 * If the cell has a periodic neighbor at its @c ith face, this function
3468 * returns true, otherwise, the returned value is false.
3469 */
3470 bool
3471 has_periodic_neighbor(const unsigned int i) const;
3472
3473 /**
3474 * For a cell with its @c ith face at a periodic boundary,
3475 * see
3476 * @ref GlossPeriodicConstraints "the entry for periodic boundaries",
3477 * this function returns an iterator to the cell on the other side
3478 * of the periodic boundary. If there is no periodic boundary at the @c ith
3479 * face, an exception will be thrown.
3480 * In order to avoid running into an exception, check the result of
3481 * has_periodic_neighbor() for the @c ith face prior to using this function.
3482 * The behavior of periodic_neighbor() is similar to neighbor(), in
3483 * the sense that the returned cell has at most the same level of refinement
3484 * as the current cell. On distributed meshes, by calling
3485 * Triangulation::add_periodicity(),
3486 * we can make sure that the element on the other side of the periodic
3487 * boundary exists in this rank as a ghost cell or a locally owned cell.
3488 */
3489 TriaIterator<CellAccessor<dim, spacedim>>
3490 periodic_neighbor(const unsigned int i) const;
3491
3492 /**
3493 * For a cell whose @c ith face is not at a boundary, this function returns
3494 * the same result as neighbor(). If the @c ith face is at a periodic boundary
3495 * this function returns the same result as periodic_neighbor(). If neither of
3496 * the aforementioned conditions are met, i.e. the @c ith face is on a
3497 * nonperiodic boundary, an exception will be thrown.
3498 */
3499 TriaIterator<CellAccessor<dim, spacedim>>
3500 neighbor_or_periodic_neighbor(const unsigned int i) const;
3501
3502 /**
3503 * Return an iterator to the periodic neighbor of the cell at a given
3504 * face and subface number. The general guidelines for using this function
3505 * is similar to the function neighbor_child_on_subface(). The
3506 * implementation of this function is consistent with
3507 * periodic_neighbor_of_coarser_periodic_neighbor(). For instance,
3508 * assume that we are sitting on a cell named @c cell1, whose neighbor behind
3509 * the @c ith face is one level coarser. Let us name this coarser neighbor
3510 * @c cell2. Then, by calling
3511 * periodic_neighbor_of_coarser_periodic_neighbor(), from @c cell1, we get
3512 * a @c face_num and a @c subface_num. Now, if we call
3513 * periodic_neighbor_child_on_subface() from cell2, with the above face_num
3514 * and subface_num, we get an iterator to @c cell1.
3515 */
3516 TriaIterator<CellAccessor<dim, spacedim>>
3517 periodic_neighbor_child_on_subface(const unsigned int face_no,
3518 const unsigned int subface_no) const;
3519
3520 /**
3521 * This function is a generalization of
3522 * periodic_neighbor_of_periodic_neighbor()
3523 * for those cells which have a coarser periodic neighbor. The returned
3524 * pair of numbers can be used in periodic_neighbor_child_on_subface()
3525 * to get back to the current cell. In other words, the following
3526 * assertion should be true, for a cell with coarser periodic neighbor:
3527 * cell->periodic_neighbor(i)->periodic_neighbor_child_on_subface(face_no,
3528 * subface_no)==cell
3529 */
3530 std::pair<unsigned int, unsigned int>
3531 periodic_neighbor_of_coarser_periodic_neighbor(const unsigned face_no) const;
3532
3533 /**
3534 * This function returns the index of the periodic neighbor at the
3535 * @c ith face of the current cell. If there is no periodic neighbor
3536 * at the given face, the returned value is -1.
3537 */
3538 int
3539 periodic_neighbor_index(const unsigned int i) const;
3540
3541 /**
3542 * This function returns the level of the periodic neighbor at the
3543 * @c ith face of the current cell. If there is no periodic neighbor
3544 * at the given face, the returned value is -1.
3545 */
3546 int
3547 periodic_neighbor_level(const unsigned int i) const;
3548
3549 /**
3550 * For a cell with a periodic neighbor at its @c ith face, this function
3551 * returns the face number of that periodic neighbor such that the
3552 * current cell is the periodic neighbor of that neighbor. In other words
3553 * the following assertion holds for those cells which have a periodic
3554 * neighbor with the same or a higher level of refinement as the current
3555 * cell:
3556 * @c {cell->periodic_neighbor(i)->
3557 * periodic_neighbor(cell->periodic_neighbor_of_periodic_neighbor(i))==cell}
3558 * For the cells with a coarser periodic neighbor, one should use
3559 * periodic_neighbor_of_coarser_periodic_neighbor() and
3560 * periodic_neighbor_child_on_subface()
3561 * to get back to the current cell.
3562 */
3563 unsigned int
3564 periodic_neighbor_of_periodic_neighbor(const unsigned int i) const;
3565
3566 /**
3567 * If a cell has a periodic neighbor at its @c ith face, this function
3568 * returns the face number of the periodic neighbor, which is connected
3569 * to the @c ith face of this cell.
3570 */
3571 unsigned int
3572 periodic_neighbor_face_no(const unsigned int i) const;
3573
3574 /**
3575 * This function returns true if the element on the other side of the
3576 * periodic boundary is coarser and returns false otherwise. The
3577 * implementation allows this function to work in the case of
3578 * anisotropic refinement.
3579 */
3580 bool
3581 periodic_neighbor_is_coarser(const unsigned int i) const;
3582
3583 /**
3584 * @}
3585 */
3586
3587 /**
3588 * @name Dealing with boundary indicators
3589 */
3590 /**
3591 * @{
3592 */
3593
3594 /**
3595 * Return whether the @p ith vertex or face (depending on the dimension) is
3596 * part of the boundary. This is true, if the @p ith neighbor does not
3597 * exist.
3598 */
3599 bool
3600 at_boundary(const unsigned int i) const;
3601
3602 /**
3603 * Return whether the cell is at the boundary. Being at the boundary is
3604 * defined by one face being on the boundary. Note that this does not catch
3605 * cases where only one vertex of a 2d or 3d subobject is at the boundary,
3606 * or where only one line of a hex is at the boundary while the interiors of
3607 * all faces are in the interior of the domain. For the latter case, the @p
3608 * has_boundary_lines function is the right one to ask.
3609 */
3610 bool
3611 at_boundary() const;
3612
3613 /**
3614 * This is a slight variation to the @p at_boundary function: for 1 and 2
3615 * dimensions, it is equivalent, for three dimensions it returns whether at
3616 * least one of the 12 lines of the hexahedron is at a boundary. This, of
3617 * course, includes the case where a whole face is at the boundary, but also
3618 * some other cases.
3619 */
3620 bool
3621 has_boundary_lines() const;
3622 /**
3623 * @}
3624 */
3625
3626 /**
3627 * @name Dealing with refinement indicators
3628 */
3629 /**
3630 * @{
3631 */
3632
3633 /**
3634 * Return the @p RefinementCase<dim> this cell was flagged to be refined
3635 * with. The return value of this function can be compared to a bool to
3636 * check if this cell is flagged for any kind of refinement. For example, if
3637 * you have previously called cell->set_refine_flag() for a cell, then you
3638 * will enter the 'if' block in the following snippet:
3639 *
3640 * @code
3641 * if (cell->refine_flag_set())
3642 * {
3643 * // yes, this cell is marked for refinement.
3644 * }
3645 * @endcode
3646 */
3647 RefinementCase<dim>
3648 refine_flag_set() const;
3649
3650 /**
3651 * Flag the cell pointed to for refinement. This function is only allowed
3652 * for active cells. Keeping the default value for @p ref_case will mark
3653 * this cell for isotropic refinement.
3654 *
3655 * If you choose anisotropic refinement, for example by passing as argument
3656 * one of the flags RefinementCase::cut_x, RefinementCase::cut_y,
3657 * RefinementCase::cut_z, or a combination of these, then keep in mind
3658 * that refining in x-, y-, or z-direction happens with regard to the
3659 * <em>local</em> coordinate system of the cell. In other words, these
3660 * flags determine which edges and faces of the cell will be cut into new
3661 * edges and faces. On the other hand, this process is independent of
3662 * how the cell is oriented within the <em>global</em> coordinate system,
3663 * and you should not assume any particular orientation of the cell's
3664 * local coordinate system within the global coordinate system of the
3665 * space it lives in.
3666 */
3667 void
3668 set_refine_flag(const RefinementCase<dim> ref_case =
3669 RefinementCase<dim>::isotropic_refinement) const;
3670
3671 /**
3672 * Clear the refinement flag.
3673 */
3674 void
3675 clear_refine_flag() const;
3676
3677 /**
3678 * Return the @p IsotropicRefinementChoices this cell was flagged to be refined
3679 * with.
3680 */
3681 std::uint8_t
3682 refine_choice() const;
3683
3684 /**
3685 * Set the @p IsotropicRefinementChoices this cell is flagged to be refined
3686 * with.
3687 */
3688 void
3689 set_refine_choice(const std::uint8_t refinement_choice = static_cast<char>(
3690 IsotropicRefinementChoice::isotropic_refinement)) const;
3691
3692 /**
3693 * Clear the @p IsotropicRefinementChoices flag.
3694 */
3695 void
3696 clear_refine_choice() const;
3697
3698 /**
3699 * Modify the refinement flag of the cell to ensure (at least) the given
3700 * refinement case @p face_refinement_case at face <tt>face_no</tt>, taking
3701 * into account orientation, flip and rotation of the face. Return, whether
3702 * the refinement flag had to be modified. This function is only allowed for
3703 * active cells.
3704 */
3705 bool
3706 flag_for_face_refinement(
3707 const unsigned int face_no,
3708 const RefinementCase<dim - 1> &face_refinement_case =
3709 RefinementCase<dim - 1>::isotropic_refinement) const;
3710
3711 /**
3712 * Modify the refinement flag of the cell to ensure that line
3713 * <tt>face_no</tt> will be refined. Return, whether the refinement flag had
3714 * to be modified. This function is only allowed for active cells.
3715 */
3716 bool
3717 flag_for_line_refinement(const unsigned int line_no) const;
3718
3719 /**
3720 * Return the SubfaceCase of face <tt>face_no</tt>. Note that this is not
3721 * identical to asking <tt>cell->face(face_no)->refinement_case()</tt> since
3722 * the latter returns a RefinementCase<dim-1> and thus only considers one
3723 * (anisotropic) refinement, whereas this function considers the complete
3724 * refinement situation including possible refinement of the face's
3725 * children. This function may only be called for active cells in 2d and 3d.
3726 */
3727 internal::SubfaceCase<dim>
3728 subface_case(const unsigned int face_no) const;
3729
3730 /**
3731 * Return whether the coarsen flag is set or not.
3732 */
3733 bool
3734 coarsen_flag_set() const;
3735
3736 /**
3737 * Flag the cell pointed to for coarsening. This function is only allowed
3738 * for active cells.
3739 */
3740 void
3741 set_coarsen_flag() const;
3742
3743 /**
3744 * Clear the coarsen flag.
3745 */
3746 void
3747 clear_coarsen_flag() const;
3748 /**
3749 * @}
3750 */
3751
3752 /**
3753 * @name Dealing with material indicators
3754 */
3755 /**
3756 * @{
3757 */
3758
3759 /**
3760 * Return the material id of this cell.
3761 *
3762 * For a typical use of this function, see the
3763 * @ref step_28 "step-28"
3764 * tutorial program.
3765 *
3766 * See the
3767 * @ref GlossMaterialId "glossary"
3768 * for more information.
3769 */
3770 types::material_id
3771 material_id() const;
3772
3773 /**
3774 * Set the material id of this cell.
3775 *
3776 * For a typical use of this function, see the
3777 * @ref step_28 "step-28"
3778 * tutorial program.
3779 *
3780 * See the
3781 * @ref GlossMaterialId "glossary"
3782 * for more information.
3783 */
3784 void
3785 set_material_id(const types::material_id new_material_id) const;
3786
3787 /**
3788 * Set the material id of this cell and all its children (and
3789 * grand-children, and so on) to the given value.
3790 *
3791 * See the
3792 * @ref GlossMaterialId "glossary"
3793 * for more information.
3794 */
3795 void
3796 recursively_set_material_id(const types::material_id new_material_id) const;
3797 /**
3798 * @}
3799 */
3800
3801 /**
3802 * @name Dealing with subdomain indicators
3803 */
3804 /**
3805 * @{
3806 */
3807
3808 /**
3809 * Return the subdomain id of this cell.
3810 *
3811 * See the
3812 * @ref GlossSubdomainId "glossary"
3813 * for more information.
3814 *
3815 * @note The subdomain of a cell is a property only defined for active
3816 * cells, i.e., cells that are not further refined. Consequently, you can
3817 * only call this function if the cell it refers to has no children. For
3818 * multigrid methods in parallel, it is also important to know which
3819 * processor owns non-active cells, and for this you can call
3820 * level_subdomain_id().
3821 */
3822 types::subdomain_id
3823 subdomain_id() const;
3824
3825 /**
3826 * Set the subdomain id of this cell.
3827 *
3828 * See the
3829 * @ref GlossSubdomainId "glossary"
3830 * for more information. This function should not be called if you use a
3831 * parallel::distributed::Triangulation object.
3832 *
3833 * @note The subdomain of a cell is a property only defined for active
3834 * cells, i.e., cells that are not further refined. Consequently, you can
3835 * only call this function if the cell it refers to has no children. For
3836 * multigrid methods in parallel, it is also important to know which
3837 * processor owns non-active cells, and for this you can call
3838 * level_subdomain_id().
3839 */
3840 void
3841 set_subdomain_id(const types::subdomain_id new_subdomain_id) const;
3842
3843 /**
3844 * Get the level subdomain id of this cell. This is used for parallel
3845 * multigrid where not only the global mesh (consisting of the active cells)
3846 * is partitioned among processors, but also the individual levels of the
3847 * hierarchy of recursively refined cells that make up the mesh. In
3848 * other words, the level subdomain id is a property that is also defined
3849 * for non-active cells if a multigrid hierarchy is used.
3850 */
3851 types::subdomain_id
3852 level_subdomain_id() const;
3853
3854 /**
3855 * Set the level subdomain id of this cell. This is used for parallel
3856 * multigrid.
3857 */
3858 void
3859 set_level_subdomain_id(
3860 const types::subdomain_id new_level_subdomain_id) const;
3861
3862
3863 /**
3864 * Set the subdomain id of this cell (if it is active) or all its terminal
3865 * children (and grand-children, and so on, as long as they have no children
3866 * of their own) to the given value. Since the subdomain id is a concept
3867 * that is only defined for cells that are active (i.e., have no children of
3868 * their own), this function only sets the subdomain ids for all children
3869 * and grand children of this cell that are actually active, skipping
3870 * intermediate child cells.
3871 *
3872 * See the
3873 * @ref GlossSubdomainId "glossary"
3874 * for more information. This function should not be called if you use a
3875 * parallel::distributed::Triangulation object since there the subdomain id
3876 * is implicitly defined by which processor you're on.
3877 */
3878 void
3879 recursively_set_subdomain_id(
3880 const types::subdomain_id new_subdomain_id) const;
3881 /**
3882 * @}
3883 */
3884
3885 /**
3886 * Return a globally unique cell index for the current cell,
3887 * assuming it is not artificial. The value is identical to
3888 * active_cell_index() if the cell is part of a serial
3889 * triangulation.
3890 *
3891 * In the context of parallel triangulations, locally-owned cells
3892 * are enumerated contiguously within each subdomain of the
3893 * mesh. This ensures that the index returned by this function can
3894 * be used as the index into vectors with a total of
3895 * Triangulation::n_globally_active_cells() entries, and for which
3896 * every process stores a contiguous part. If such a cell-data
3897 * vector has been set up with
3898 * parallel::TriangulationBase::global_active_cell_index_partitioner(),
3899 * the index returned by this function can then be used to access
3900 * the correct vector entry.
3901 */
3902 types::global_cell_index
3903 global_active_cell_index() const;
3904
3905 /**
3906 * Return a globally unique index for a non-artificial level cell.
3907 *
3908 * @note Similar to global_active_cell_index(), with the difference
3909 * that the cell-data vector has been set up with
3910 * parallel::TriangulationBase::global_level_cell_index_partitioner().
3911 */
3912 types::global_cell_index
3913 global_level_cell_index() const;
3914
3915 /**
3916 * @name Dealing with codim 1 cell orientation
3917 */
3918 /**
3919 * @{
3920 */
3921
3922 /**
3923 * Return the orientation of this cell. This function always returns
3924 * `true` if `dim==spacedim`. It can return `true` or `false` if
3925 * `dim==spacedim-1`. The function cannot be called (and will abort
3926 * with an error) if called for `dim<spacedim-1`.
3927 *
3928 * For the meaning of this flag, see
3929 * @ref GlossDirectionFlag.
3930 */
3931 bool
3932 direction_flag() const;
3933
3934 /**
3935 * Return the how many-th active cell the current cell is (assuming the
3936 * current cell is indeed active). This is useful, for example, if you are
3937 * accessing the elements of a vector with as many entries as there are
3938 * active cells. Such vectors are used for estimating the error on each cell
3939 * of a triangulation, for specifying refinement criteria passed to the
3940 * functions in GridRefinement, and for generating cell-wise output.
3941 *
3942 * The function throws an exception if the current cell is not active.
3943 *
3944 * @note If the triangulation this function is called on is of type
3945 * parallel::distributed::Triangulation, then active cells may be locally
3946 * owned, ghost cells, or artificial (see
3947 * @ref GlossLocallyOwnedCell,
3948 * @ref GlossGhostCell,
3949 * and
3950 * @ref GlossArtificialCell).
3951 * This function counts over all of them, including ghost and artificial
3952 * active cells. This implies that the index returned by this function
3953 * uniquely identifies a cell within the triangulation on a single
3954 * processor, but does not uniquely identify the cell among the (parts of
3955 * the) triangulation that is shared among processors. If you would like to
3956 * identify active cells across processors, you need to consider the CellId
3957 * of a cell returned by CellAccessor::id().
3958 */
3959 unsigned int
3960 active_cell_index() const;
3961
3962 /**
3963 * Return the index of the parent of this cell within the level of the
3964 * triangulation to which the parent cell belongs. The level of the parent
3965 * is of course one lower than that of the present cell. If the parent does
3966 * not exist (i.e., if the object is at the coarsest level of the mesh
3967 * hierarchy), an exception is generated.
3968 */
3969 int
3970 parent_index() const;
3971
3972 /**
3973 * Return an iterator to the parent. If the parent does not exist (i.e., if
3974 * the object is at the coarsest level of the mesh hierarchy), an exception
3975 * is generated.
3976 */
3977 TriaIterator<CellAccessor<dim, spacedim>>
3978 parent() const;
3979
3980 /**
3981 * @}
3982 */
3983
3984 /**
3985 * @name Other functions
3986 */
3987 /**
3988 * @{
3989 */
3990
3991 /**
3992 * Test that the cell has no children (this is the criterion for whether a
3993 * cell is called "active").
3994 *
3995 * See the
3996 * @ref GlossActive "glossary"
3997 * for more information.
3998 */
3999 bool
4000 is_active() const;
4001
4002 /**
4003 * Return whether this cell is owned by the current processor or is owned by
4004 * another processor. The function always returns true if applied to an
4005 * object of type dealii::Triangulation, but may yield false if the
4006 * triangulation is of type parallel::distributed::Triangulation.
4007 *
4008 * See the
4009 * @ref GlossGhostCell "glossary"
4010 * and the
4011 * @ref distributed
4012 * topic for more information.
4013 *
4014 * @post The returned value is equal to <code>!is_ghost() &&
4015 * !is_artificial()</code>.
4016 *
4017 * @note Whether a cell is a ghost cell, artificial, or is locally owned or
4018 * is a property that only pertains to cells that are active. Consequently,
4019 * you can only call this function if the cell it refers to has no children.
4020 */
4021 bool
4022 is_locally_owned() const;
4023
4024 /**
4025 * Return true if either the Triangulation is not distributed or if
4026 * level_subdomain_id() is equal to the id of the current processor.
4027 */
4028 bool
4029 is_locally_owned_on_level() const;
4030
4031 /**
4032 * Return true if:
4033 * <ol>
4034 * <li>This cell exists in the global mesh (i.e., it is not artificial),
4035 * and</li>
4036 * <li>This cell is owned by another processor (i.e., has a subdomain_id
4037 * different from Triangulation::locally_owned_subdomain())</li>
4038 * </ol>
4039 *
4040 * In all other cases the returned value is false. In particular, only
4041 * parallel Triangulations (i.e., Triangulations inheriting from
4042 * parallel::TriangulationBase) can have ghost cells, so for a serial
4043 * Triangulation the returned value is false.
4044 *
4045 * See the
4046 * @ref GlossGhostCell "glossary"
4047 * and the
4048 * @ref distributed
4049 * topic for more information.
4050 *
4051 * @post The returned value is equal to <code>!is_locally_owned() &&
4052 * !is_artificial()</code>.
4053 *
4054 * @note For parallel::distributed::Triangulation and
4055 * parallel::fullydistributed::Triangulation, ghost cells are always adjacent
4056 * to locally owned cells. For parallel::shared::Triangulation they may not
4057 * be, dependent on whether or not the triangulation uses artificial cells -
4058 * see parallel::shared::Triangulation::Triangulation() for more information.
4059 *
4060 * @note Whether a cell is a ghost cell, artificial, or is locally owned
4061 * is a property that only pertains to cells that are active. Consequently,
4062 * you can only call this function if the cell it refers to has no children.
4063 */
4064 bool
4065 is_ghost() const;
4066
4067 /**
4068 * Return true if either the Triangulation is not distributed or if the
4069 * cell is not artificial and the level_subdomain_id() is not equal to the id
4070 * of the current processor.
4071 */
4072 bool
4073 is_ghost_on_level() const;
4074
4075 /**
4076 * Return whether this cell is artificial, i.e. it isn't one of the cells
4077 * owned by the current processor, and it also doesn't border on one. As a
4078 * consequence, it exists in the mesh to ensure that each processor has all
4079 * coarse mesh cells and that the 2:1 ratio of neighboring cells is
4080 * maintained, but it is not one of the cells we should work on on the
4081 * current processor. In particular, there is no guarantee that this cell
4082 * isn't, in fact, further refined on one of the other processors.
4083 *
4084 * This function only makes sense if the triangulation used is of kind
4085 * parallel::distributed::Triangulation. In all other cases, the returned
4086 * value is always false.
4087 *
4088 * See the
4089 * @ref GlossArtificialCell "glossary"
4090 * and the
4091 * @ref distributed
4092 * topic for more information.
4093 *
4094 * @post The returned value is equal to <code>!is_ghost() &&
4095 * !is_locally_owned()</code>.
4096 *
4097 * @note Whether a cell is a ghost cell, artificial, or is locally owned is
4098 * a property that only pertains to cells that are active. Consequently, you
4099 * can only call this function if the cell it refers to has no children.
4100 */
4101 bool
4102 is_artificial() const;
4103
4104 /**
4105 * Similar to is_artificial() but checking the conditions on the levels.
4106 *
4107 * @post The returned value is equal to <code>!is_ghost_on_level() &&
4108 * !is_locally_owned_on_level()</code>.
4109 */
4110 bool
4111 is_artificial_on_level() const;
4112
4113 /**
4114 * Test whether the point @p p is inside this cell. Points on the boundary
4115 * are counted as being inside the cell.
4116 *
4117 * Note that this function assumes that the mapping between unit cell and
4118 * real cell is (bi-, tri-)linear, i.e. that faces in 2d and edges in 3d are
4119 * straight lines. If you have higher order transformations, results may be
4120 * different as to whether a point is in- or outside the cell in real space.
4121 *
4122 * In case of codim>0, the point is first projected to the manifold where
4123 * the cell is embedded and then check if this projection is inside the
4124 * cell.
4125 */
4126 bool
4127 point_inside(const Point<spacedim> &p) const;
4128
4129 /**
4130 * Set the neighbor @p i of this cell to the cell pointed to by @p pointer.
4131 *
4132 * This function shouldn't really be public (but needs to for various
4133 * reasons in order not to make a long list of functions friends): it
4134 * modifies internal data structures and may leave things. Do not use it
4135 * from application codes.
4136 */
4137 void
4138 set_neighbor(const unsigned int i,
4139 const TriaIterator<CellAccessor<dim, spacedim>> &pointer) const;
4140
4141 /**
4142 * Return a unique ID for the current cell. This ID is constructed from the
4143 * path in the hierarchy from the coarse parent cell and works correctly in
4144 * parallel computations using objects of type
4145 * parallel::distributed::Triangulation. This function is therefore useful
4146 * in providing a unique identifier for cells (active or not) that also
4147 * works for parallel triangulations. See the documentation of the CellId
4148 * class for more information.
4149 *
4150 * @note This operation takes O(level) time to compute. In most practical
4151 * cases, the number of levels of a triangulation will depend
4152 * logarithmically on the number of cells in the triangulation.
4153 */
4154 CellId
4155 id() const;
4156
4157 using TriaAccessor<dim, dim, spacedim>::diameter;
4158
4159 /**
4160 * The same as TriaAccessor::diameter() but also taking a Mapping class.
4161 */
4162 double
4163 diameter(const Mapping<dim, spacedim> &mapping) const;
4164
4165 /**
4166 * @}
4167 */
4168
4169
4170 /**
4171 * @ingroup Exceptions
4172 */
4173 DeclException0(ExcRefineCellNotActive);
4174 /**
4175 * @ingroup Exceptions
4176 */
4177 DeclException0(ExcCellFlaggedForRefinement);
4178 /**
4179 * @ingroup Exceptions
4180 */
4181 DeclException0(ExcCellFlaggedForCoarsening);
4182
4183 protected:
4184 /**
4185 * This function assumes that the neighbor is not coarser than the current
4186 * cell. In this case it returns the neighbor_of_neighbor() value. If,
4187 * however, the neighbor is coarser this function returns an
4188 * <code>invalid_unsigned_int</code>.
4189 *
4190 * This function is not for public use. Use the function
4191 * neighbor_of_neighbor() instead which throws an exception if called for a
4192 * coarser neighbor. If neighbor is indeed coarser (you get to know this by
4193 * e.g. the neighbor_is_coarser() function) then the
4194 * neighbor_of_coarser_neighbor() function should be call. If you'd like to
4195 * know only the <code>face_no</code> which is required to get back from the
4196 * neighbor to the present cell then simply use the neighbor_face_no()
4197 * function which can be used for coarser as well as non-coarser neighbors.
4198 */
4199 unsigned int
4200 neighbor_of_neighbor_internal(const unsigned int neighbor) const;
4201
4202 /**
4203 * As for any codim>0 we can use a similar code and c++ does not allow
4204 * partial templates. we use this auxiliary function that is then called
4205 * from point_inside.
4206 */
4207 template <int dim_, int spacedim_>
4208 bool
4209 point_inside_codim(const Point<spacedim_> &p) const;
4210
4211
4212
4213 private:
4214 /**
4215 * Set the active cell index of a cell. This is done at the end of
4216 * refinement.
4217 */
4218 void
4219 set_active_cell_index(const unsigned int active_cell_index) const;
4220
4221 /**
4222 * Set global active cell index for a cell.
4223 */
4224 void
4225 set_global_active_cell_index(const types::global_cell_index index) const;
4226
4227 /**
4228 * Set global level cell index for a level cell.
4229 */
4230 void
4231 set_global_level_cell_index(const types::global_cell_index index) const;
4232
4233 /**
4234 * Set the parent of a cell.
4235 */
4236 void
4237 set_parent(const unsigned int parent_index);
4238
4239 /**
4240 * Set the orientation of this cell. This function can only be
4241 * called if the argument is `true` if `dim==spacedim`. It can be
4242 * called with either `true` or `false` if `dim==spacedim-1`. The
4243 * function cannot be called (and will abort with an error) if called
4244 * for `dim<spacedim-1`.
4245 *
4246 * For the meaning of this flag, see
4247 * @ref GlossDirectionFlag.
4248 */
4249 void
4250 set_direction_flag(const bool new_direction_flag) const;
4251
4252 friend class Triangulation<dim, spacedim>;
4253
4254 friend class parallel::TriangulationBase<dim, spacedim>;
4255
4256 friend struct dealii::internal::TriangulationImplementation::Implementation;
4257 friend struct dealii::internal::TriangulationImplementation::
4258 ImplementationMixedMesh;
4259 };
4260
4261
4262
4263 /* ----- declaration of explicit specializations and general templates ----- */
4264
4265
4266 template <int structdim, int dim, int spacedim>
4267 template <typename OtherAccessor>
4268 InvalidAccessor<structdim, dim, spacedim>::InvalidAccessor(
4269 const OtherAccessor &)
4270 {
4271 Assert(false,
4272 ExcMessage("You are attempting an illegal conversion between "
4273 "iterator/accessor types. The constructor you call "
4274 "only exists to make certain template constructs "
4275 "easier to write as dimension independent code but "
4276 "the conversion is not valid in the current context."));
4277 }
4278
4279
4280
4281 template <int structdim, int dim, int spacedim>
4282 template <int structdim2, int dim2, int spacedim2>
4283 TriaAccessor<structdim, dim, spacedim>::TriaAccessor(
4284 const InvalidAccessor<structdim2, dim2, spacedim2> &)
4285 {
4286 Assert(false,
4287 ExcMessage("You are attempting an illegal conversion between "
4288 "iterator/accessor types. The constructor you call "
4289 "only exists to make certain template constructs "
4290 "easier to write as dimension independent code but "
4291 "the conversion is not valid in the current context."));
4292 }
4293
4294
4295
4296 template <int dim, int spacedim>
4297 template <int structdim2, int dim2, int spacedim2>
4298 CellAccessor<dim, spacedim>::CellAccessor(
4299 const InvalidAccessor<structdim2, dim2, spacedim2> &)
4300 {
4301 Assert(false,
4302 ExcMessage("You are attempting an illegal conversion between "
4303 "iterator/accessor types. The constructor you call "
4304 "only exists to make certain template constructs "
4305 "easier to write as dimension independent code but "
4306 "the conversion is not valid in the current context."));
4307 }
4308
4309
4310
4311 template <int structdim, int dim, int spacedim>
4312 template <int structdim2, int dim2, int spacedim2>
4313 TriaAccessor<structdim, dim, spacedim>::TriaAccessor(
4314 const TriaAccessor<structdim2, dim2, spacedim2> &)
4315 {
4316 Assert(false,
4317 ExcMessage("You are attempting an illegal conversion between "
4318 "iterator/accessor types. The constructor you call "
4319 "only exists to make certain template constructs "
4320 "easier to write as dimension independent code but "
4321 "the conversion is not valid in the current context."));
4322 }
4323
4324
4325
4326 template <int dim, int spacedim>
4327 template <int structdim2, int dim2, int spacedim2>
4328 CellAccessor<dim, spacedim>::CellAccessor(
4329 const TriaAccessor<structdim2, dim2, spacedim2> &)
4330 {
4331 Assert(false,
4332 ExcMessage("You are attempting an illegal conversion between "
4333 "iterator/accessor types. The constructor you call "
4334 "only exists to make certain template constructs "
4335 "easier to write as dimension independent code but "
4336 "the conversion is not valid in the current context."));
4337 }
4338
4339
4340 #ifndef DOXYGEN
4341
4342 template <>
4343 bool
4344 CellAccessor<1, 1>::point_inside(const Point<1> &) const;
4345 template <>
4346 bool
4347 CellAccessor<2, 2>::point_inside(const Point<2> &) const;
4348 template <>
4349 bool
4350 CellAccessor<3, 3>::point_inside(const Point<3> &) const;
4351 template <>
4352 bool
4353 CellAccessor<1, 2>::point_inside(const Point<2> &) const;
4354 template <>
4355 bool
4356 CellAccessor<1, 3>::point_inside(const Point<3> &) const;
4357 template <>
4358 bool
4359 CellAccessor<2, 3>::point_inside(const Point<3> &) const;
4360 // -------------------------------------------------------------------
4361
4362 template <>
4363 void
4364 TriaAccessor<3, 3, 3>::set_all_manifold_ids(const types::manifold_id) const;
4365
4366
4367
4368 namespace internal
4369 {
4370 namespace TriaAccessorImplementation
4371 {
4372 /**
4373 * Compute the diameter for a given set of vertices. The vertices are
4374 * interpreted, depending on their count, as the vertices of a particular
4375 * reference cell.
4376 */
4377 template <int dim, int spacedim>
4378 inline double
4379 diameter(
4380 const boost::container::small_vector<Point<spacedim>,
4381 GeometryInfo<dim>::vertices_per_cell>
4382 vertices)
4383 {
4384 const ReferenceCell reference_cell =
4385 ReferenceCell::n_vertices_to_type(dim, vertices.size());
4386
4387 if (reference_cell == ReferenceCells::Line)
4388 // Return the distance between the two vertices
4389 return (vertices[1] - vertices[0]).norm();
4390 else if (reference_cell == ReferenceCells::Triangle)
4391 // Return the longest of the three edges
4392 return std::max({(vertices[1] - vertices[0]).norm(),
4393 (vertices[2] - vertices[1]).norm(),
4394 (vertices[2] - vertices[0]).norm()});
4395 else if (reference_cell == ReferenceCells::Quadrilateral)
4396 // Return the longer one of the two diagonals of the quadrilateral
4397 return std::max({(vertices[3] - vertices[0]).norm(),
4398 (vertices[2] - vertices[1]).norm()});
4399 else if (reference_cell == ReferenceCells::Tetrahedron)
4400 // Return the longest of the six edges of the tetrahedron
4401 return std::max({(vertices[1] - vertices[0]).norm(),
4402 (vertices[2] - vertices[0]).norm(),
4403 (vertices[2] - vertices[1]).norm(),
4404 (vertices[3] - vertices[0]).norm(),
4405 (vertices[3] - vertices[1]).norm(),
4406 (vertices[3] - vertices[2]).norm()});
4407 else if (reference_cell == ReferenceCells::Pyramid)
4408 // Return ...
4409 return std::max({// the longest diagonal of the quadrilateral base
4410 // of the pyramid or ...
4411 (vertices[3] - vertices[0]).norm(),
4412 (vertices[2] - vertices[1]).norm(),
4413 // the longest edge connected with the apex of the
4414 // pyramid
4415 (vertices[4] - vertices[0]).norm(),
4416 (vertices[4] - vertices[1]).norm(),
4417 (vertices[4] - vertices[2]).norm(),
4418 (vertices[4] - vertices[3]).norm()});
4419 else if (reference_cell == ReferenceCells::Wedge)
4420 // Return ...
4421 return std::max({// the longest of the 2*3=6 diagonals of the three
4422 // quadrilateral sides of the wedge or ...
4423 (vertices[4] - vertices[0]).norm(),
4424 (vertices[3] - vertices[1]).norm(),
4425 (vertices[5] - vertices[1]).norm(),
4426 (vertices[4] - vertices[2]).norm(),
4427 (vertices[5] - vertices[0]).norm(),
4428 (vertices[3] - vertices[2]).norm(),
4429 // the longest of the 3*2=6 edges of the two
4430 // triangular faces of the wedge
4431 (vertices[1] - vertices[0]).norm(),
4432 (vertices[2] - vertices[1]).norm(),
4433 (vertices[2] - vertices[0]).norm(),
4434 (vertices[4] - vertices[3]).norm(),
4435 (vertices[5] - vertices[4]).norm(),
4436 (vertices[5] - vertices[3]).norm()});
4437 else if (reference_cell == ReferenceCells::Hexahedron)
4438 // Return the longest of the four diagonals of the hexahedron
4439 return std::max({(vertices[7] - vertices[0]).norm(),
4440 (vertices[6] - vertices[1]).norm(),
4441 (vertices[2] - vertices[5]).norm(),
4442 (vertices[3] - vertices[4]).norm()});
4443
4444 DEAL_II_NOT_IMPLEMENTED();
4445 return -1e10;
4446 }
4447 } // namespace TriaAccessorImplementation
4448 } // namespace internal
4449
4450
4451 /*--------------------- Functions: TriaAccessorBase -------------------------*/
4452
4453 template <int structdim, int dim, int spacedim>
4454 inline TriaAccessorBase<structdim, dim, spacedim>::TriaAccessorBase(
4455 const Triangulation<dim, spacedim> *tria,
4456 const int level,
4457 const int index,
4458 const AccessorData *)
4459 : present_level((structdim == dim) ? level : 0)
4460 , present_index(index)
4461 , tria(tria)
4462 {
4463 // non-cells have no level, so a 0
4464 // should have been passed, or a -1
4465 // for an end-iterator, or -2 for
4466 // an invalid (default constructed)
4467 // iterator
4468 if (structdim != dim)
4469 {
4470 Assert((level == 0) || (level == -1) || (level == -2),
4471 ExcInternalError());
4472 }
4473 }
4474
4475
4476 template <int structdim, int dim, int spacedim>
4477 inline TriaAccessorBase<structdim, dim, spacedim>::TriaAccessorBase(
4478 const TriaAccessorBase<structdim, dim, spacedim> &a)
4479 : present_level(a.present_level)
4480 , present_index(a.present_index)
4481 , tria(a.tria)
4482 {}
4483
4484
4485 template <int structdim, int dim, int spacedim>
4486 inline void
4487 TriaAccessorBase<structdim, dim, spacedim>::copy_from(
4488 const TriaAccessorBase<structdim, dim, spacedim> &a)
4489 {
4490 present_level = a.present_level;
4491 present_index = a.present_index;
4492 tria = a.tria;
4493
4494 if (structdim != dim)
4495 {
4496 Assert((present_level == 0) || (present_level == -1) ||
4497 (present_level == -2),
4498 ExcInternalError());
4499 }
4500 }
4501
4502
4503
4504 template <int structdim, int dim, int spacedim>
4505 inline TriaAccessorBase<structdim, dim, spacedim> &
4506 TriaAccessorBase<structdim, dim, spacedim>::operator=(
4507 const TriaAccessorBase<structdim, dim, spacedim> &a)
4508 {
4509 present_level = a.present_level;
4510 present_index = a.present_index;
4511 tria = a.tria;
4512
4513 if (structdim != dim)
4514 {
4515 Assert((present_level == 0) || (present_level == -1) ||
4516 (present_level == -2),
4517 ExcInternalError());
4518 }
4519 return *this;
4520 }
4521
4522
4523
4524 template <int structdim, int dim, int spacedim>
4525 inline bool
4526 TriaAccessorBase<structdim, dim, spacedim>::operator==(
4527 const TriaAccessorBase<structdim, dim, spacedim> &a) const
4528 {
4529 Assert(tria == a.tria || tria == nullptr || a.tria == nullptr,
4530 TriaAccessorExceptions::ExcCantCompareIterators());
4531 return ((tria == a.tria) && (present_level == a.present_level) &&
4532 (present_index == a.present_index));
4533 }
4534
4535
4536
4537 template <int structdim, int dim, int spacedim>
4538 inline bool
4539 TriaAccessorBase<structdim, dim, spacedim>::operator!=(
4540 const TriaAccessorBase<structdim, dim, spacedim> &a) const
4541 {
4542 Assert(tria == a.tria || tria == nullptr || a.tria == nullptr,
4543 TriaAccessorExceptions::ExcCantCompareIterators());
4544 return ((tria != a.tria) || (present_level != a.present_level) ||
4545 (present_index != a.present_index));
4546 }
4547
4548
4549
4550 template <int structdim, int dim, int spacedim>
4551 inline bool
4552 TriaAccessorBase<structdim, dim, spacedim>::operator<(
4553 const TriaAccessorBase<structdim, dim, spacedim> &other) const
4554 {
4555 Assert(tria == other.tria, TriaAccessorExceptions::ExcCantCompareIterators());
4556
4557 if (present_level != other.present_level)
4558 return (present_level < other.present_level);
4559
4560 return (present_index < other.present_index);
4561 }
4562
4563
4564
4565 template <int structdim, int dim, int spacedim>
4566 inline int
4567 TriaAccessorBase<structdim, dim, spacedim>::level() const
4568 {
4569 // This is always zero or invalid
4570 // if the object is not a cell
4571 return present_level;
4572 }
4573
4574
4575
4576 template <int structdim, int dim, int spacedim>
4577 inline int
4578 TriaAccessorBase<structdim, dim, spacedim>::index() const
4579 {
4580 return present_index;
4581 }
4582
4583
4584
4585 template <int structdim, int dim, int spacedim>
4586 inline IteratorState::IteratorStates
4587 TriaAccessorBase<structdim, dim, spacedim>::state() const
4588 {
4589 if ((present_level >= 0) && (present_index >= 0))
4590 return IteratorState::valid;
4591 else if (present_index == -1)
4592 return IteratorState::past_the_end;
4593 else
4594 return IteratorState::invalid;
4595 }
4596
4597
4598
4599 template <int structdim, int dim, int spacedim>
4600 inline const Triangulation<dim, spacedim> &
4601 TriaAccessorBase<structdim, dim, spacedim>::get_triangulation() const
4602 {
4603 return *tria;
4604 }
4605
4606
4607
4608 template <int structdim, int dim, int spacedim>
4609 inline void
4610 TriaAccessorBase<structdim, dim, spacedim>::operator++()
4611 {
4612 // this iterator is used for
4613 // objects without level
4614 ++this->present_index;
4615
4616 if (structdim != dim)
4617 {
4618 // is index still in the range of
4619 // the vector? (note that we don't
4620 // have to set the level, since
4621 // dim!=1 and the object therefore
4622 // has no level)
4623 if (this->present_index >= static_cast<int>(objects().n_objects()))
4624 this->present_index = -1;
4625 }
4626 else
4627 {
4628 while (this->present_index >=
4629 static_cast<int>(
4630 this->tria->levels[this->present_level]->cells.n_objects()))
4631 {
4632 // no -> go one level up until we find
4633 // one with more than zero cells
4634 ++this->present_level;
4635 this->present_index = 0;
4636 // highest level reached?
4637 if (this->present_level >=
4638 static_cast<int>(this->tria->levels.size()))
4639 {
4640 // return with past the end pointer
4641 this->present_level = this->present_index = -1;
4642 return;
4643 }
4644 }
4645 }
4646 }
4647
4648
4649 template <int structdim, int dim, int spacedim>
4650 inline void
4651 TriaAccessorBase<structdim, dim, spacedim>::operator--()
4652 {
4653 // same as operator++
4654 --this->present_index;
4655
4656 if (structdim != dim)
4657 {
4658 if (this->present_index < 0)
4659 this->present_index = -1;
4660 }
4661 else
4662 {
4663 while (this->present_index < 0)
4664 {
4665 // no -> go one level down
4666 --this->present_level;
4667 // lowest level reached?
4668 if (this->present_level == -1)
4669 {
4670 // return with past the end pointer
4671 this->present_level = this->present_index = -1;
4672 return;
4673 }
4674 // else
4675 this->present_index =
4676 this->tria->levels[this->present_level]->cells.n_objects() - 1;
4677 }
4678 }
4679 }
4680
4681
4682
4683 template <int structdim, int dim, int spacedim>
4684 inline dealii::internal::TriangulationImplementation::TriaObjects &
4685 TriaAccessorBase<structdim, dim, spacedim>::objects() const
4686 {
4687 if (structdim == dim)
4688 return this->tria->levels[this->present_level]->cells;
4689
4690 if (structdim == 1 && dim > 1)
4691 return this->tria->faces->lines;
4692
4693 if (structdim == 2 && dim > 2)
4694 return this->tria->faces->quads;
4695
4696 DEAL_II_ASSERT_UNREACHABLE();
4697
4698 return this->tria->levels[this->present_level]->cells;
4699 }
4700
4701
4702
4703 /*---------------------- Functions: InvalidAccessor -------------------------*/
4704
4705 template <int structdim, int dim, int spacedim>
4706 InvalidAccessor<structdim, dim, spacedim>::InvalidAccessor(const void *,
4707 const int,
4708 const int,
4709 const AccessorData *)
4710 {
4711 Assert(false,
4712 ExcMessage("You are attempting an invalid conversion between "
4713 "iterator/accessor types. The constructor you call "
4714 "only exists to make certain template constructs "
4715 "easier to write as dimension independent code but "
4716 "the conversion is not valid in the current context."));
4717 }
4718
4719
4720
4721 template <int structdim, int dim, int spacedim>
4722 InvalidAccessor<structdim, dim, spacedim>::InvalidAccessor(
4723 const InvalidAccessor &)
4724 {
4725 Assert(false,
4726 ExcMessage("You are attempting an invalid conversion between "
4727 "iterator/accessor types. The constructor you call "
4728 "only exists to make certain template constructs "
4729 "easier to write as dimension independent code but "
4730 "the conversion is not valid in the current context."));
4731 }
4732
4733
4734
4735 template <int structdim, int dim, int spacedim>
4736 void
4737 InvalidAccessor<structdim, dim, spacedim>::copy_from(const InvalidAccessor &)
4738 {
4739 // nothing to do here. we could
4740 // throw an exception but we can't
4741 // get here without first creating
4742 // an object which would have
4743 // already thrown
4744 }
4745
4746
4747
4748 template <int structdim, int dim, int spacedim>
4749 bool
4750 InvalidAccessor<structdim, dim, spacedim>::operator==(
4751 const InvalidAccessor &) const
4752 {
4753 // nothing to do here. we could
4754 // throw an exception but we can't
4755 // get here without first creating
4756 // an object which would have
4757 // already thrown
4758 return false;
4759 }
4760
4761
4762
4763 template <int structdim, int dim, int spacedim>
4764 bool
4765 InvalidAccessor<structdim, dim, spacedim>::operator!=(
4766 const InvalidAccessor &) const
4767 {
4768 // nothing to do here. we could
4769 // throw an exception but we can't
4770 // get here without first creating
4771 // an object which would have
4772 // already thrown
4773 return true;
4774 }
4775
4776
4777
4778 template <int structdim, int dim, int spacedim>
4779 bool
4780 InvalidAccessor<structdim, dim, spacedim>::used() const
4781 {
4782 // nothing to do here. we could
4783 // throw an exception but we can't
4784 // get here without first creating
4785 // an object which would have
4786 // already thrown
4787 return false;
4788 }
4789
4790
4791
4792 template <int structdim, int dim, int spacedim>
4793 bool
4794 InvalidAccessor<structdim, dim, spacedim>::has_children() const
4795 {
4796 // nothing to do here. we could
4797 // throw an exception but we can't
4798 // get here without first creating
4799 // an object which would have
4800 // already thrown
4801 return false;
4802 }
4803
4804
4805
4806 template <int structdim, int dim, int spacedim>
4807 void
4808 InvalidAccessor<structdim, dim, spacedim>::operator++() const
4809 {}
4810
4811
4812
4813 template <int structdim, int dim, int spacedim>
4814 void
4815 InvalidAccessor<structdim, dim, spacedim>::operator--() const
4816 {}
4817
4818
4819
4820 template <int structdim, int dim, int spacedim>
4821 types::manifold_id
4822 InvalidAccessor<structdim, dim, spacedim>::manifold_id() const
4823 {
4824 return numbers::flat_manifold_id;
4825 }
4826
4827
4828
4829 template <int structdim, int dim, int spacedim>
4830 unsigned int
4831 InvalidAccessor<structdim, dim, spacedim>::user_index() const
4832 {
4833 return numbers::invalid_unsigned_int;
4834 }
4835
4836
4837
4838 template <int structdim, int dim, int spacedim>
4839 void
4840 InvalidAccessor<structdim, dim, spacedim>::set_user_index(
4841 const unsigned int) const
4842 {
4843 Assert(false,
4844 ExcMessage("You are trying to set the user index of an "
4845 "invalid object."));
4846 }
4847
4848
4849
4850 template <int structdim, int dim, int spacedim>
4851 void
4852 InvalidAccessor<structdim, dim, spacedim>::set_manifold_id(
4853 const types::manifold_id) const
4854 {
4855 Assert(false,
4856 ExcMessage("You are trying to set the manifold id of an "
4857 "invalid object."));
4858 }
4859
4860
4861
4862 template <int structdim, int dim, int spacedim>
4863 inline Point<spacedim> &
4864 InvalidAccessor<structdim, dim, spacedim>::vertex(const unsigned int) const
4865 {
4866 // nothing to do here. we could throw an exception but we can't get here
4867 // without first creating an object which would have already thrown
4868 static Point<spacedim> invalid_vertex;
4869 return invalid_vertex;
4870 }
4871
4872
4873 template <int structdim, int dim, int spacedim>
4874 inline void *
4875 InvalidAccessor<structdim, dim, spacedim>::line(const unsigned int) const
4876 {
4877 // nothing to do here. we could throw an exception but we can't get here
4878 // without first creating an object which would have already thrown
4879 return nullptr;
4880 }
4881
4882
4883
4884 template <int structdim, int dim, int spacedim>
4885 inline void *
4886 InvalidAccessor<structdim, dim, spacedim>::quad(const unsigned int) const
4887 {
4888 // nothing to do here. we could throw an exception but we can't get here
4889 // without first creating an object which would have already thrown
4890 return nullptr;
4891 }
4892
4893
4894 /*------------------------ Functions: TriaAccessor ---------------------------*/
4895
4896
4897 namespace internal
4898 {
4899 namespace TriaAccessorImplementation
4900 {
4901 // make sure that if in the following we
4902 // write TriaAccessor
4903 // we mean the *class*
4904 // dealii::TriaAccessor, not the
4905 // enclosing namespace
4906 // dealii::internal::TriaAccessor
4907 using dealii::TriaAccessor;
4908
4909 /**
4910 * A class with the same purpose as the similarly named class of the
4911 * Triangulation class. See there for more information.
4912 */
4913 struct Implementation
4914 {
4915 /**
4916 * Implementation of the function of some name in the parent class.
4917 */
4918 template <int structdim, int dim, int spacedim>
4919 inline static void
4920 set_combined_face_orientation(
4921 const TriaAccessor<structdim, dim, spacedim> &accessor,
4922 const unsigned int face_no,
4923 const types::geometric_orientation combined_orientation)
4924 {
4925 Assert(structdim == dim,
4926 ExcMessage("This function can only be used on objects that are "
4927 "cells and not on objects which bound cells."));
4928 AssertIndexRange(face_no, accessor.n_faces());
4929 AssertIndexRange(combined_orientation,
4930 accessor.reference_cell().n_face_orientations(
4931 face_no));
4932
4933 // face_orientations is not set up in 1d
4934 if (dim != 1)
4935 accessor.tria->levels[accessor.present_level]
4936 ->face_orientations.set_combined_orientation(
4937 accessor.present_index * ReferenceCells::max_n_faces<dim>() +
4938 face_no,
4939 combined_orientation);
4940 }
4941
4942
4943
4944 template <int dim, int spacedim>
4945 static std::array<unsigned int, 1>
4946 get_line_indices_of_cell(const TriaAccessor<1, dim, spacedim> &)
4947 {
4948 DEAL_II_ASSERT_UNREACHABLE();
4949 return {};
4950 }
4951
4952
4953
4954 template <int structdim, int dim, int spacedim>
4955 static std::array<unsigned int, 4>
4956 get_line_indices_of_cell(const TriaAccessor<2, dim, spacedim> &cell)
4957 {
4958 // For 2d cells the access cell->line_orientation() is already
4959 // efficient
4960 std::array<unsigned int, 4> line_indices = {};
4961 for (const unsigned int line : cell.line_indices())
4962 line_indices[line] = cell.line_index(line);
4963 return line_indices;
4964 }
4965
4966 /**
4967 * A helper function to provide faster access to cell->line_index() in
4968 * 3d
4969 */
4970 template <int structdim, int dim, int spacedim>
4971 static std::array<unsigned int, 12>
4972 get_line_indices_of_cell(
4973 const TriaAccessor<structdim, dim, spacedim> &cell)
4974 {
4975 std::array<unsigned int, 12> line_indices = {};
4976
4977 // For hexahedra, the classical access via quads -> lines is too
4978 // inefficient. Unroll this code here to allow the compiler to inline
4979 // the necessary functions.
4980 const auto ref_cell = cell.reference_cell();
4981 if (ref_cell == ReferenceCells::Hexahedron)
4982 {
4983 for (unsigned int f = 4; f < 6; ++f)
4984 {
4985 const auto orientation =
4986 cell.get_triangulation()
4987 .levels[cell.level()]
4988 ->face_orientations.get_combined_orientation(
4989 cell.index() * ReferenceCells::max_n_faces<dim>() + f);
4990
4991 // It might seem superfluous to spell out the four indices
4992 // that get later consumed by a for loop over these four
4993 // elements; however, for the compiler it is easier to inline
4994 // the statement of standard_to_real_face_line() when next to
4995 // each other, as opposed to be interleaved with a
4996 // line_index() call.
4997 const std::array<unsigned int, 4> my_indices{
4998 {ref_cell.standard_to_real_face_line(0, f, orientation),
4999 ref_cell.standard_to_real_face_line(1, f, orientation),
5000 ref_cell.standard_to_real_face_line(2, f, orientation),
5001 ref_cell.standard_to_real_face_line(3, f, orientation)}};
5002 const auto quad = cell.quad(f);
5003 for (unsigned int l = 0; l < 4; ++l)
5004 line_indices[4 * (f - 4) + l] =
5005 quad->line_index(my_indices[l]);
5006 }
5007 for (unsigned int f = 0; f < 2; ++f)
5008 {
5009 const auto orientation =
5010 cell.get_triangulation()
5011 .levels[cell.level()]
5012 ->face_orientations.get_combined_orientation(
5013 cell.index() * ReferenceCells::max_n_faces<dim>() + f);
5014 const std::array<unsigned int, 2> my_indices{
5015 {ref_cell.standard_to_real_face_line(0, f, orientation),
5016 ref_cell.standard_to_real_face_line(1, f, orientation)}};
5017 const auto quad = cell.quad(f);
5018 line_indices[8 + f] = quad->line_index(my_indices[0]);
5019 line_indices[10 + f] = quad->line_index(my_indices[1]);
5020 }
5021 }
5022 else if (ref_cell == ReferenceCells::Tetrahedron)
5023 {
5024 std::array<unsigned int, 3> orientations{
5025 {cell.combined_face_orientation(0),
5026 cell.combined_face_orientation(1),
5027 cell.combined_face_orientation(2)}};
5028 const std::array<unsigned int, 6> my_indices{
5029 {ref_cell.standard_to_real_face_line(0, 0, orientations[0]),
5030 ref_cell.standard_to_real_face_line(1, 0, orientations[0]),
5031 ref_cell.standard_to_real_face_line(2, 0, orientations[0]),
5032 ref_cell.standard_to_real_face_line(1, 1, orientations[1]),
5033 ref_cell.standard_to_real_face_line(2, 1, orientations[1]),
5034 ref_cell.standard_to_real_face_line(1, 2, orientations[2])}};
5035 line_indices[0] = cell.quad(0)->line_index(my_indices[0]);
5036 line_indices[1] = cell.quad(0)->line_index(my_indices[1]);
5037 line_indices[2] = cell.quad(0)->line_index(my_indices[2]);
5038 line_indices[3] = cell.quad(1)->line_index(my_indices[3]);
5039 line_indices[4] = cell.quad(1)->line_index(my_indices[4]);
5040 line_indices[5] = cell.quad(2)->line_index(my_indices[5]);
5041 }
5042 else
5043 // For other shapes (wedges, pyramids), we do not currently
5044 // implement an optimized function.
5045 for (unsigned int l = 0; l < std::min(12U, cell.n_lines()); ++l)
5046 line_indices[l] = cell.line_index(l);
5047
5048 return line_indices;
5049 }
5050
5051
5052
5053 /**
5054 * A helper function to provide faster access to
5055 * cell->line_orientation(), 1d specialization
5056 */
5057 template <int dim, int spacedim>
5058 static std::array<types::geometric_orientation, 1>
5059 get_line_orientations_of_cell(const TriaAccessor<1, dim, spacedim> &)
5060 {
5061 DEAL_II_ASSERT_UNREACHABLE();
5062 return {};
5063 }
5064
5065
5066
5067 /**
5068 * A helper function to provide faster access to
5069 * cell->line_orientation(), 2d specialization
5070 */
5071 template <int dim, int spacedim>
5072 static std::array<types::geometric_orientation, 4>
5073 get_line_orientations_of_cell(const TriaAccessor<2, dim, spacedim> &cell)
5074 {
5075 // For 2d cells the access cell->line_orientation() is already
5076 // efficient
5077 std::array<types::geometric_orientation, 4> line_orientations = {};
5078 for (const unsigned int line : cell.line_indices())
5079 line_orientations[line] = cell.line_orientation(line);
5080 return line_orientations;
5081 }
5082
5083
5084
5085 /**
5086 * A helper function to provide faster access to
5087 * cell->line_orientation(), 3d specialization
5088 */
5089 template <int dim, int spacedim>
5090 static std::array<types::geometric_orientation, 12>
5091 get_line_orientations_of_cell(const TriaAccessor<3, dim, spacedim> &cell)
5092 {
5093 std::array<types::geometric_orientation, 12> line_orientations = {};
5094
5095 // For hexahedra, the classical access via quads -> lines is too
5096 // inefficient. Unroll this code here to allow the compiler to inline
5097 // the necessary functions.
5098 const auto ref_cell = cell.reference_cell();
5099 if (ref_cell == ReferenceCells::Hexahedron)
5100 {
5101 for (unsigned int f = 4; f < 6; ++f)
5102 {
5103 const auto orientation =
5104 cell.get_triangulation()
5105 .levels[cell.level()]
5106 ->face_orientations.get_combined_orientation(
5107 cell.index() * ReferenceCells::max_n_faces<dim>() + f);
5108
5109 // It might seem superfluous to spell out the four indices and
5110 // orientations that get later consumed by a for loop over
5111 // these four elements; however, for the compiler it is easier
5112 // to inline the statement of standard_to_real_face_line()
5113 // when next to each other, as opposed to be interleaved with
5114 // a line_index() call.
5115 const std::array<unsigned int, 4> my_indices{
5116 {ref_cell.standard_to_real_face_line(0, f, orientation),
5117 ref_cell.standard_to_real_face_line(1, f, orientation),
5118 ref_cell.standard_to_real_face_line(2, f, orientation),
5119 ref_cell.standard_to_real_face_line(3, f, orientation)}};
5120 const auto quad = cell.quad(f);
5121 const std::array<types::geometric_orientation, 4>
5122 my_orientations{{ref_cell.face_to_cell_line_orientation(
5123 0,
5124 f,
5125 orientation,
5126 quad->line_orientation(my_indices[0])),
5127 ref_cell.face_to_cell_line_orientation(
5128 1,
5129 f,
5130 orientation,
5131 quad->line_orientation(my_indices[1])),
5132 ref_cell.face_to_cell_line_orientation(
5133 2,
5134 f,
5135 orientation,
5136 quad->line_orientation(my_indices[2])),
5137 ref_cell.face_to_cell_line_orientation(
5138 3,
5139 f,
5140 orientation,
5141 quad->line_orientation(my_indices[3]))}};
5142 for (unsigned int l = 0; l < 4; ++l)
5143 line_orientations[4 * (f - 4) + l] = my_orientations[l];
5144 }
5145 for (unsigned int f = 0; f < 2; ++f)
5146 {
5147 const auto orientation =
5148 cell.get_triangulation()
5149 .levels[cell.level()]
5150 ->face_orientations.get_combined_orientation(
5151 cell.index() * ReferenceCells::max_n_faces<3>() + f);
5152 const std::array<unsigned int, 2> my_indices{
5153 {ref_cell.standard_to_real_face_line(0, f, orientation),
5154 ref_cell.standard_to_real_face_line(1, f, orientation)}};
5155 const auto quad = cell.quad(f);
5156 const std::array<types::geometric_orientation, 2>
5157 my_orientations{{ref_cell.face_to_cell_line_orientation(
5158 0,
5159 f,
5160 orientation,
5161 quad->line_orientation(my_indices[0])),
5162 ref_cell.face_to_cell_line_orientation(
5163 1,
5164 f,
5165 orientation,
5166 quad->line_orientation(my_indices[1]))}};
5167 line_orientations[8 + f] = my_orientations[0];
5168 line_orientations[10 + f] = my_orientations[1];
5169 }
5170 }
5171 else if (ref_cell == ReferenceCells::Tetrahedron)
5172 {
5173 std::array<unsigned int, 3> orientations{
5174 {cell.combined_face_orientation(0),
5175 cell.combined_face_orientation(1),
5176 cell.combined_face_orientation(2)}};
5177 const std::array<unsigned int, 6> my_indices{
5178 {ref_cell.standard_to_real_face_line(0, 0, orientations[0]),
5179 ref_cell.standard_to_real_face_line(1, 0, orientations[0]),
5180 ref_cell.standard_to_real_face_line(2, 0, orientations[0]),
5181 ref_cell.standard_to_real_face_line(1, 1, orientations[1]),
5182 ref_cell.standard_to_real_face_line(2, 1, orientations[1]),
5183 ref_cell.standard_to_real_face_line(1, 2, orientations[2])}};
5184 line_orientations[0] = ref_cell.face_to_cell_line_orientation(
5185 0,
5186 0,
5187 orientations[0],
5188 cell.quad(0)->line_orientation(my_indices[0]));
5189 line_orientations[1] = ref_cell.face_to_cell_line_orientation(
5190 1,
5191 0,
5192 orientations[0],
5193 cell.quad(0)->line_orientation(my_indices[1]));
5194 line_orientations[2] = ref_cell.face_to_cell_line_orientation(
5195 2,
5196 0,
5197 orientations[0],
5198 cell.quad(0)->line_orientation(my_indices[2]));
5199 line_orientations[3] = ref_cell.face_to_cell_line_orientation(
5200 1,
5201 1,
5202 orientations[1],
5203 cell.quad(1)->line_orientation(my_indices[3]));
5204 line_orientations[4] = ref_cell.face_to_cell_line_orientation(
5205 2,
5206 1,
5207 orientations[1],
5208 cell.quad(1)->line_orientation(my_indices[4]));
5209 line_orientations[5] = ref_cell.face_to_cell_line_orientation(
5210 1,
5211 2,
5212 orientations[2],
5213 cell.quad(2)->line_orientation(my_indices[5]));
5214 }
5215 else
5216 // For other shapes (wedges, pyramids), we do not currently
5217 // implement an optimized function
5218 for (unsigned int l = 0; l < std::min(12U, cell.n_lines()); ++l)
5219 line_orientations[l] = cell.line_orientation(l);
5220
5221 return line_orientations;
5222 }
5223 };
5224 } // namespace TriaAccessorImplementation
5225 } // namespace internal
5226
5227
5228
5229 template <int structdim, int dim, int spacedim>
5230 inline TriaAccessor<structdim, dim, spacedim>::TriaAccessor(
5231 const Triangulation<dim, spacedim> *parent,
5232 const int level,
5233 const int index,
5234 const AccessorData *local_data)
5235 : TriaAccessorBase<structdim, dim, spacedim>(parent, level, index, local_data)
5236 {}
5237
5238
5239
5240 template <int structdim, int dim, int spacedim>
5241 inline bool
5242 TriaAccessor<structdim, dim, spacedim>::used() const
5243 {
5244 Assert(this->state() == IteratorState::valid,
5245 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5246 *this));
5247 return this->objects().used[this->present_index];
5248 }
5249
5250
5251
5252 template <int structdim, int dim, int spacedim>
5253 inline TriaIterator<TriaAccessor<0, dim, spacedim>>
5254 TriaAccessor<structdim, dim, spacedim>::vertex_iterator(
5255 const unsigned int i) const
5256 {
5257 return TriaIterator<TriaAccessor<0, dim, spacedim>>(this->tria,
5258 0,
5259 vertex_index(i));
5260 }
5261
5262
5263
5264 template <int structdim, int dim, int spacedim>
5265 inline ReferenceCell
5266 TriaAccessor<structdim, dim, spacedim>::reference_cell() const
5267 {
5268 if (structdim == 0)
5269 return ReferenceCells::Vertex;
5270 else if (structdim == 1)
5271 return ReferenceCells::Line;
5272 else if (structdim == dim)
5273 return this->tria->levels[this->present_level]
5274 ->reference_cell[this->present_index];
5275 else
5276 return this->tria->faces->get_quad_type(this->present_index);
5277 }
5278
5279
5280
5281 template <int structdim, int dim, int spacedim>
5282 inline unsigned int
5283 TriaAccessor<structdim, dim, spacedim>::vertex_index(
5284 const unsigned int corner) const
5285 {
5286 AssertIndexRange(corner, this->n_vertices());
5287
5288 if constexpr (structdim == 1)
5289 {
5290 // This branch needs to be first (and not combined with the structdim ==
5291 // dim branch) so that we can get line vertex indices when setting up the
5292 // cell vertex index cache
5293 return this->objects()
5294 .cells[this->present_index * ReferenceCells::max_n_faces<1>() + corner];
5295 }
5296 else if constexpr (structdim == dim)
5297 {
5298 // This branch should only be used after the cell vertex index cache is
5299 // set up
5300 const auto my_index = static_cast<std::size_t>(this->present_index) *
5301 ReferenceCells::max_n_vertices<dim>();
5302 AssertIndexRange(my_index + corner,
5303 this->tria->levels[this->present_level]
5304 ->cell_vertex_indices_cache.size());
5305 const unsigned int vertex_index =
5306 this->tria->levels[this->present_level]
5307 ->cell_vertex_indices_cache[my_index + corner];
5308 Assert(vertex_index != numbers::invalid_unsigned_int, ExcInternalError());
5309 return vertex_index;
5310 }
5311 else if constexpr (structdim == 2)
5312 {
5313 const auto [line_index, vertex_index] =
5314 this->reference_cell().standard_vertex_to_face_and_vertex_index(corner);
5315 const auto vertex_within_line_index =
5316 this->reference_cell().standard_to_real_face_vertex(
5317 vertex_index, line_index, this->line_orientation(line_index));
5318
5319 return this->line(line_index)->vertex_index(vertex_within_line_index);
5320 }
5321 else
5322 {
5323 DEAL_II_ASSERT_UNREACHABLE();
5324 return numbers::invalid_unsigned_int;
5325 }
5326 }
5327
5328
5329
5330 template <int structdim, int dim, int spacedim>
5331 inline Point<spacedim> &
5332 TriaAccessor<structdim, dim, spacedim>::vertex(const unsigned int i) const
5333 {
5334 return const_cast<Point<spacedim> &>(this->tria->vertices[vertex_index(i)]);
5335 }
5336
5337
5338
5339 template <int structdim, int dim, int spacedim>
5340 inline typename dealii::internal::TriangulationImplementation::
5341 Iterators<dim, spacedim>::line_iterator
5342 TriaAccessor<structdim, dim, spacedim>::line(const unsigned int i) const
5343 {
5344 // checks happen in line_index
5345 return typename dealii::internal::TriangulationImplementation::
5346 Iterators<dim, spacedim>::line_iterator(this->tria, 0, line_index(i));
5347 }
5348
5349
5350
5351 template <int structdim, int dim, int spacedim>
5352 inline unsigned int
5353 TriaAccessor<structdim, dim, spacedim>::line_index(const unsigned int i) const
5354 {
5355 (void)i;
5356 AssertIndexRange(i, this->n_lines());
5357 Assert(structdim != 1,
5358 ExcMessage("You can't ask for the index of a line bounding a "
5359 "one-dimensional cell because it is not bounded by "
5360 "lines."));
5361
5362 if constexpr (structdim == 2)
5363 {
5364 return this->objects()
5365 .cells[this->present_index * ReferenceCells::max_n_faces<2>() + i];
5366 }
5367 else if constexpr (structdim == 3)
5368 {
5369 const auto [face_index, line_index] =
5370 this->reference_cell().standard_line_to_face_and_line_index(i);
5371 const auto line_within_face_index =
5372 this->reference_cell().standard_to_real_face_line(
5373 line_index, face_index, this->combined_face_orientation(face_index));
5374
5375 return this->quad(face_index)->line_index(line_within_face_index);
5376 }
5377
5378 DEAL_II_ASSERT_UNREACHABLE();
5379 return numbers::invalid_unsigned_int;
5380 }
5381
5382
5383
5384 template <int structdim, int dim, int spacedim>
5385 inline typename dealii::internal::TriangulationImplementation::
5386 Iterators<dim, spacedim>::quad_iterator
5387 TriaAccessor<structdim, dim, spacedim>::quad(const unsigned int i) const
5388 {
5389 // checks happen in quad_index
5390 return typename dealii::internal::TriangulationImplementation::
5391 Iterators<dim, spacedim>::quad_iterator(this->tria, 0, quad_index(i));
5392 }
5393
5394
5395
5396 template <int structdim, int dim, int spacedim>
5397 inline unsigned int
5398 TriaAccessor<structdim, dim, spacedim>::quad_index(const unsigned int i) const
5399 {
5400 Assert(structdim == 3,
5401 ExcMessage("You can't ask for the index of a quad bounding "
5402 "a one- or two-dimensional cell because it is not "
5403 "bounded by quads."));
5404 // work around a bogus GCC-9 warning which considers i unused except in 3d
5405 (void)i;
5406 if constexpr (structdim == 3)
5407 {
5408 AssertIndexRange(i, n_faces());
5409 return this->tria->levels[this->present_level]
5410 ->cells
5411 .cells[this->present_index * ReferenceCells::max_n_faces<3>() + i];
5412 }
5413 else
5414 return numbers::invalid_unsigned_int;
5415 }
5416
5417
5418
5419 template <int structdim, int dim, int spacedim>
5420 inline types::geometric_orientation
5421 TriaAccessor<structdim, dim, spacedim>::combined_face_orientation(
5422 const unsigned int face) const
5423 {
5424 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5425 AssertIndexRange(face, n_faces());
5426 Assert(structdim == dim,
5427 ExcMessage("This function can only be used on objects "
5428 "that are cells, but not on faces or edges "
5429 "that bound cells."));
5430 // work around a bogus GCC-9 warning which considers face unused except in 3d
5431 (void)face;
5432
5433 if constexpr (structdim == 1)
5434 return numbers::default_geometric_orientation;
5435 else if constexpr (structdim == 2)
5436 {
5437 // if all elements are quads (or if we have a very special consistently
5438 // oriented triangular mesh) then we do not store this array
5439 if (this->tria->levels[this->present_level]
5440 ->face_orientations.n_objects() == 0)
5441 return numbers::default_geometric_orientation;
5442 else
5443 return this->tria->levels[this->present_level]
5444 ->face_orientations.get_combined_orientation(
5445 this->present_index * ReferenceCells::max_n_faces<dim>() + face);
5446 }
5447 else
5448 return this->tria->levels[this->present_level]
5449 ->face_orientations.get_combined_orientation(
5450 this->present_index * ReferenceCells::max_n_faces<dim>() + face);
5451 }
5452
5453
5454
5455 template <int structdim, int dim, int spacedim>
5456 inline bool
5457 TriaAccessor<structdim, dim, spacedim>::face_orientation(
5458 const unsigned int face) const
5459 {
5460 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5461 AssertIndexRange(face, n_faces());
5462 Assert(structdim == dim,
5463 ExcMessage("This function can only be used on objects "
5464 "that are cells, but not on faces or edges "
5465 "that bound cells."));
5466 // work around a bogus GCC-9 warning which considers face unused in 1d
5467 (void)face;
5468
5469 if constexpr (structdim == 1)
5470 // in 1d 'faces' are vertices and those are always consistently oriented
5471 return true;
5472 else if constexpr (structdim == 2)
5473 return this->line_orientation(face) ==
5474 numbers::default_geometric_orientation;
5475 else
5476 return this->tria->levels[this->present_level]
5477 ->face_orientations.get_orientation(
5478 this->present_index * ReferenceCells::max_n_faces<structdim>() + face);
5479 }
5480
5481
5482
5483 template <int structdim, int dim, int spacedim>
5484 inline bool
5485 TriaAccessor<structdim, dim, spacedim>::face_flip(const unsigned int face) const
5486 {
5487 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5488 Assert(structdim == dim,
5489 ExcMessage("This function can only be used on objects "
5490 "that are cells, but not on faces or edges "
5491 "that bound cells."));
5492 AssertIndexRange(face, n_faces());
5493 // work around a bogus GCC-9 warning which considers face unused except in 3d
5494 (void)face;
5495
5496 if constexpr (structdim == 3)
5497 return this->tria->levels[this->present_level]->face_orientations.get_flip(
5498 this->present_index * ReferenceCells::max_n_faces<structdim>() + face);
5499 else
5500 // In 1d and 2d, face_flip is always false as faces can only be
5501 // 'flipped' in 3d.
5502 return false;
5503 }
5504
5505
5506 template <int structdim, int dim, int spacedim>
5507 inline bool
5508 TriaAccessor<structdim, dim, spacedim>::face_rotation(
5509 const unsigned int face) const
5510 {
5511 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5512 Assert(structdim == dim,
5513 ExcMessage("This function can only be used on objects "
5514 "that are cells, but not on faces or edges "
5515 "that bound cells."));
5516 AssertIndexRange(face, n_faces());
5517 // work around a bogus GCC-9 warning which considers face unused except in 3d
5518 (void)face;
5519
5520 if constexpr (structdim == 3)
5521 return this->tria->levels[this->present_level]
5522 ->face_orientations.get_rotation(
5523 this->present_index * ReferenceCells::max_n_faces<structdim>() + face);
5524 else
5525 // In 1d and 2d, face_rotation is always false as faces can only be
5526 // 'rotated' in 3d.
5527 return false;
5528 }
5529
5530
5531
5532 template <int structdim, int dim, int spacedim>
5533 inline types::geometric_orientation
5534 TriaAccessor<structdim, dim, spacedim>::line_orientation(
5535 const unsigned int line) const
5536 {
5537 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5538 AssertIndexRange(line, this->n_lines());
5539 // work around a bogus GCC-9 warning which considers line unused in 1d
5540 (void)line;
5541
5542 if constexpr (structdim == 1)
5543 return numbers::default_geometric_orientation;
5544 else if constexpr (structdim == 2 && dim == 2)
5545 // lines in 2d are faces
5546 {
5547 const auto combined_orientation = combined_face_orientation(line);
5548 Assert(combined_orientation == numbers::default_geometric_orientation ||
5549 combined_orientation == numbers::reverse_line_orientation,
5550 ExcInternalError());
5551 return combined_orientation;
5552 }
5553 else if constexpr (structdim == 2 && dim == 3)
5554 {
5555 // line orientations in 3d are stored in their own array as bools: here
5556 // 'true' is the default orientation and 'false' is the reversed one
5557 // (which matches set_line_orientation())
5558 const auto index =
5559 this->present_index * ReferenceCells::max_n_lines<2>() + line;
5560 Assert(index < this->tria->faces->quads_line_orientations.size(),
5561 ExcInternalError());
5562 return this->tria->faces->quads_line_orientations[index] ?
5563 numbers::default_geometric_orientation :
5564 numbers::reverse_line_orientation;
5565 }
5566 else if constexpr (structdim == 3 && dim == 3)
5567 {
5568 const auto reference_cell = this->reference_cell();
5569 // First pick a face on which this line is a part of, and the
5570 // index of the line within.
5571 const auto [face_index, line_index] =
5572 reference_cell.standard_line_to_face_and_line_index(line);
5573 const auto line_within_face_index =
5574 reference_cell.standard_to_real_face_line(
5575 line_index, face_index, this->combined_face_orientation(face_index));
5576
5577 // Then query how that line is oriented within that face:
5578 return reference_cell.face_to_cell_line_orientation(
5579 line_index,
5580 face_index,
5581 this->combined_face_orientation(face_index),
5582 this->quad(face_index)->line_orientation(line_within_face_index));
5583 }
5584 else
5585 {
5586 DEAL_II_ASSERT_UNREACHABLE();
5587 return false;
5588 }
5589 }
5590
5591
5592
5593 template <int structdim, int dim, int spacedim>
5594 inline void
5595 TriaAccessor<structdim, dim, spacedim>::set_line_orientation(
5596 const unsigned int line,
5597 const types::geometric_orientation value) const
5598 {
5599 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5600 AssertIndexRange(line, this->n_lines());
5601 Assert(dim != 1,
5602 ExcMessage("In 1d lines are cells and thus do not need to have their "
5603 "orientations set."));
5604 Assert(dim != 2,
5605 ExcMessage("In 2d lines are faces, and, for compatibility with other "
5606 "dimensions, their orientations should be set via "
5607 "set_combined_face_orientation()."));
5608 // work around a bogus GCC-9 warning which considers line and value unused
5609 // except in 3d
5610 (void)line;
5611 (void)value;
5612
5613 if constexpr (dim == 3)
5614 {
5615 // We set line orientations per face, not per cell, so this only works for
5616 // faces in 3d.
5617 Assert(structdim == 2, ExcNotImplemented());
5618 const auto index =
5619 this->present_index * ReferenceCells::max_n_lines<2>() + line;
5620 Assert(index < this->tria->faces->quads_line_orientations.size(),
5621 ExcInternalError());
5622 this->tria->faces->quads_line_orientations[index] =
5623 value == numbers::default_geometric_orientation;
5624 }
5625 }
5626
5627
5628
5629 template <int structdim, int dim, int spacedim>
5630 inline void
5631 TriaAccessor<structdim, dim, spacedim>::set_combined_face_orientation(
5632 const unsigned int face,
5633 const types::geometric_orientation combined_orientation) const
5634 {
5635 Assert(used(), TriaAccessorExceptions::ExcCellNotUsed());
5636 AssertIndexRange(face, this->n_faces());
5637
5638 dealii::internal::TriaAccessorImplementation::Implementation::
5639 set_combined_face_orientation(*this, face, combined_orientation);
5640 }
5641
5642
5643
5644 template <int structdim, int dim, int spacedim>
5645 void
5646 TriaAccessor<structdim, dim, spacedim>::set_used_flag() const
5647 {
5648 Assert(this->state() == IteratorState::valid,
5649 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5650 *this));
5651 this->objects().used[this->present_index] = true;
5652 }
5653
5654
5655
5656 template <int structdim, int dim, int spacedim>
5657 void
5658 TriaAccessor<structdim, dim, spacedim>::clear_used_flag() const
5659 {
5660 Assert(this->state() == IteratorState::valid,
5661 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5662 *this));
5663 this->objects().used[this->present_index] = false;
5664 }
5665
5666
5667 template <int structdim, int dim, int spacedim>
5668 int
5669 TriaAccessor<structdim, dim, spacedim>::child_index(const unsigned int i) const
5670 {
5671 Assert(has_children(), TriaAccessorExceptions::ExcCellHasNoChildren());
5672 AssertIndexRange(i, n_children());
5673
5674 // each set of two children are stored
5675 // consecutively, so we only have to find
5676 // the location of the set of children
5677 const unsigned int n_sets_of_two =
5678 GeometryInfo<structdim>::max_children_per_cell / 2;
5679 return this->objects().children[n_sets_of_two * this->present_index + i / 2] +
5680 i % 2;
5681 }
5682
5683
5684
5685 template <int structdim, int dim, int spacedim>
5686 int
5687 TriaAccessor<structdim, dim, spacedim>::isotropic_child_index(
5688 const unsigned int i) const
5689 {
5690 AssertIndexRange(i, GeometryInfo<structdim>::max_children_per_cell);
5691
5692 switch (structdim)
5693 {
5694 case 1:
5695 return child_index(i);
5696 case 2:
5697 {
5698 const RefinementCase<2> this_refinement_case(
5699 static_cast<std::uint8_t>(refinement_case()));
5700
5701 Assert(this_refinement_case != RefinementCase<2>::no_refinement,
5702 TriaAccessorExceptions::ExcCellHasNoChildren());
5703
5704 if (this_refinement_case == RefinementCase<2>::cut_xy)
5705 return child_index(i);
5706 else if ((this_refinement_case == RefinementCase<2>::cut_x) &&
5707 (child(i % 2)->refinement_case() ==
5708 RefinementCase<2>::cut_y))
5709 return child(i % 2)->child_index(i / 2);
5710 else if ((this_refinement_case == RefinementCase<2>::cut_y) &&
5711 (child(i / 2)->refinement_case() ==
5712 RefinementCase<2>::cut_x))
5713 return child(i / 2)->child_index(i % 2);
5714 else
5715 Assert(
5716 false,
5717 ExcMessage(
5718 "This cell has no grandchildren equivalent to isotropic refinement"));
5719 break;
5720 }
5721
5722 case 3:
5723 DEAL_II_NOT_IMPLEMENTED();
5724 }
5725 return -1;
5726 }
5727
5728
5729
5730 template <int structdim, int dim, int spacedim>
5731 RefinementCase<structdim>
5732 TriaAccessor<structdim, dim, spacedim>::refinement_case() const
5733 {
5734 Assert(this->state() == IteratorState::valid,
5735 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5736 *this));
5737
5738 switch (structdim)
5739 {
5740 case 1:
5741 return (RefinementCase<structdim>(
5742 this->objects().children[this->present_index] != -1 ?
5743 // cast the branches
5744 // here first to uchar
5745 // and then (above) to
5746 // RefinementCase<structdim>
5747 // so that the
5748 // conversion is valid
5749 // even for the case
5750 // structdim>1 (for
5751 // which this part of
5752 // the code is dead
5753 // anyway)
5754 static_cast<std::uint8_t>(RefinementCase<1>::cut_x) :
5755 static_cast<std::uint8_t>(RefinementCase<1>::no_refinement)));
5756
5757 default:
5758 Assert(static_cast<unsigned int>(this->present_index) <
5759 this->objects().refinement_cases.size(),
5760 ExcIndexRange(this->present_index,
5761 0,
5762 this->objects().refinement_cases.size()));
5763
5764 return (static_cast<RefinementCase<structdim>>(
5765 this->objects().refinement_cases[this->present_index]));
5766 }
5767 }
5768
5769
5770
5771 template <int structdim, int dim, int spacedim>
5772 inline TriaIterator<TriaAccessor<structdim, dim, spacedim>>
5773 TriaAccessor<structdim, dim, spacedim>::child(const unsigned int i) const
5774
5775 {
5776 // checking of 'i' happens in child_index
5777 const TriaIterator<TriaAccessor<structdim, dim, spacedim>> q(
5778 this->tria, (dim == structdim ? this->level() + 1 : 0), child_index(i));
5779
5780 Assert((q.state() == IteratorState::past_the_end) || q->used(),
5781 ExcInternalError());
5782
5783 return q;
5784 }
5785
5786
5787
5788 template <int structdim, int dim, int spacedim>
5789 inline unsigned int
5790 TriaAccessor<structdim, dim, spacedim>::child_iterator_to_index(
5791 const TriaIterator<TriaAccessor<structdim, dim, spacedim>> &child) const
5792 {
5793 const auto n_children = this->n_children();
5794 for (unsigned int child_n = 0; child_n < n_children; ++child_n)
5795 if (this->child(child_n) == child)
5796 return child_n;
5797
5798 Assert(false,
5799 ExcMessage("The given child is not a child of the current object."));
5800 return numbers::invalid_unsigned_int;
5801 }
5802
5803
5804
5805 template <int structdim, int dim, int spacedim>
5806 inline TriaIterator<TriaAccessor<structdim, dim, spacedim>>
5807 TriaAccessor<structdim, dim, spacedim>::isotropic_child(
5808 const unsigned int i) const
5809 {
5810 // checking of 'i' happens in child() or
5811 // child_index() called below
5812 switch (structdim)
5813 {
5814 case 1:
5815 // no anisotropic refinement in 1d
5816 return child(i);
5817
5818 case 2:
5819 {
5820 const RefinementCase<2> this_refinement_case(
5821 static_cast<std::uint8_t>(refinement_case()));
5822
5823 Assert(this_refinement_case != RefinementCase<2>::no_refinement,
5824 TriaAccessorExceptions::ExcCellHasNoChildren());
5825
5826 if (this_refinement_case == RefinementCase<2>::cut_xy)
5827 return child(i);
5828 else if ((this_refinement_case == RefinementCase<2>::cut_x) &&
5829 (child(i % 2)->refinement_case() ==
5830 RefinementCase<2>::cut_y))
5831 return child(i % 2)->child(i / 2);
5832 else if ((this_refinement_case == RefinementCase<2>::cut_y) &&
5833 (child(i / 2)->refinement_case() ==
5834 RefinementCase<2>::cut_x))
5835 return child(i / 2)->child(i % 2);
5836 else
5837 Assert(
5838 false,
5839 ExcMessage(
5840 "This cell has no grandchildren equivalent to isotropic refinement"));
5841 break;
5842 }
5843
5844 default:
5845 DEAL_II_NOT_IMPLEMENTED();
5846 }
5847 // we don't get here but have to return
5848 // something...
5849 return child(0);
5850 }
5851
5852
5853
5854 template <int structdim, int dim, int spacedim>
5855 inline bool
5856 TriaAccessor<structdim, dim, spacedim>::has_children() const
5857 {
5858 Assert(this->state() == IteratorState::valid,
5859 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5860 *this));
5861
5862 // each set of two children are stored
5863 // consecutively, so we only have to find
5864 // the location of the set of children
5865 const unsigned int n_sets_of_two =
5866 GeometryInfo<structdim>::max_children_per_cell / 2;
5867 return (this->objects().children[n_sets_of_two * this->present_index] != -1);
5868 }
5869
5870
5871
5872 template <int structdim, int dim, int spacedim>
5873 inline unsigned int
5874 TriaAccessor<structdim, dim, spacedim>::n_children() const
5875 {
5876 Assert(this->state() == IteratorState::valid,
5877 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5878 *this));
5879 if (reference_cell() == ReferenceCells::Tetrahedron)
5880 return GeometryInfo<structdim>::n_children(
5881 RefinementCase<structdim>::isotropic_refinement);
5882 else
5883 return GeometryInfo<structdim>::n_children(refinement_case());
5884 }
5885
5886
5887
5888 template <int structdim, int dim, int spacedim>
5889 inline void
5890 TriaAccessor<structdim, dim, spacedim>::set_refinement_case(
5891 const RefinementCase<structdim> &refinement_case) const
5892 {
5893 Assert(this->state() == IteratorState::valid,
5894 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5895 *this));
5896 Assert(static_cast<unsigned int>(this->present_index) <
5897 this->objects().refinement_cases.size(),
5898 ExcIndexRange(this->present_index,
5899 0,
5900 this->objects().refinement_cases.size()));
5901
5902 this->objects().refinement_cases[this->present_index] = refinement_case;
5903 }
5904
5905
5906 template <int structdim, int dim, int spacedim>
5907 inline void
5908 TriaAccessor<structdim, dim, spacedim>::clear_refinement_case() const
5909 {
5910 Assert(this->state() == IteratorState::valid,
5911 TriaAccessorExceptions::ExcDereferenceInvalidObject<TriaAccessor>(
5912 *this));
5913 Assert(static_cast<unsigned int>(this->present_index) <
5914 this->objects().refinement_cases.size(),
5915 ExcIndexRange(this->present_index,
5916 0,
5917 this->objects().refinement_cases.size()));
5918
5919 this->objects().refinement_cases[this->present_index] =
5920 RefinementCase<structdim>::no_refinement;
5921 }
5922
5923
5924
5925 template <int structdim, int dim, int spacedim>
5926 void
5927 TriaAccessor<structdim, dim, spacedim>::set_children(const unsigned int i,
5928 const int index) const
5929 {
5930 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
5931 Assert(i % 2 == 0, TriaAccessorExceptions::ExcSetOnlyEvenChildren(i));
5932
5933 // each set of two children are stored
5934 // consecutively, so we only have to find
5935 // the location of the set of children
5936 const unsigned int n_sets_of_two =
5937 GeometryInfo<structdim>::max_children_per_cell / 2;
5938
5939 Assert(
5940 // clearing the child index for a cell
5941 (index == -1) ||
5942 // if setting the child index for the i'th child (with i==0),
5943 // then the index must be a non-negative number
5944 (i == 0 && !this->has_children() && (index >= 0)) ||
5945 // if setting the child index for the i'th child (with i>0),
5946 // then the previously stored index must be the invalid
5947 // index
5948 (i > 0 && this->has_children() && (index >= 0) &&
5949 this->objects().children[n_sets_of_two * this->present_index + i / 2] ==
5950 -1),
5951 TriaAccessorExceptions::ExcCantSetChildren(index));
5952
5953 this->objects().children[n_sets_of_two * this->present_index + i / 2] = index;
5954 }
5955
5956
5957
5958 template <int structdim, int dim, int spacedim>
5959 void
5960 TriaAccessor<structdim, dim, spacedim>::clear_children() const
5961 {
5962 // each set of two children are stored
5963 // consecutively, so we only have to find
5964 // the location of the set of children
5965 const unsigned int n_sets_of_two =
5966 GeometryInfo<structdim>::max_children_per_cell / 2;
5967
5968 for (unsigned int i = 0; i < n_sets_of_two; ++i)
5969 set_children(2 * i, -1);
5970 }
5971
5972
5973
5974 template <int structdim, int dim, int spacedim>
5975 inline bool
5976 TriaAccessor<structdim, dim, spacedim>::user_flag_set() const
5977 {
5978 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
5979 return this->objects().user_flags[this->present_index];
5980 }
5981
5982
5983
5984 template <int structdim, int dim, int spacedim>
5985 inline void
5986 TriaAccessor<structdim, dim, spacedim>::set_user_flag() const
5987 {
5988 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
5989 this->objects().user_flags[this->present_index] = true;
5990 }
5991
5992
5993
5994 template <int structdim, int dim, int spacedim>
5995 inline void
5996 TriaAccessor<structdim, dim, spacedim>::clear_user_flag() const
5997 {
5998 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
5999 this->objects().user_flags[this->present_index] = false;
6000 }
6001
6002
6003
6004 template <int structdim, int dim, int spacedim>
6005 void
6006 TriaAccessor<structdim, dim, spacedim>::recursively_set_user_flag() const
6007 {
6008 set_user_flag();
6009
6010 if (this->has_children())
6011 for (unsigned int c = 0; c < this->n_children(); ++c)
6012 this->child(c)->recursively_set_user_flag();
6013 }
6014
6015
6016
6017 template <int structdim, int dim, int spacedim>
6018 void
6019 TriaAccessor<structdim, dim, spacedim>::recursively_clear_user_flag() const
6020 {
6021 clear_user_flag();
6022
6023 if (this->has_children())
6024 for (unsigned int c = 0; c < this->n_children(); ++c)
6025 this->child(c)->recursively_clear_user_flag();
6026 }
6027
6028
6029
6030 template <int structdim, int dim, int spacedim>
6031 void
6032 TriaAccessor<structdim, dim, spacedim>::clear_user_data() const
6033 {
6034 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6035 this->objects().clear_user_data(this->present_index);
6036 }
6037
6038
6039
6040 template <int structdim, int dim, int spacedim>
6041 void
6042 TriaAccessor<structdim, dim, spacedim>::set_user_pointer(void *p) const
6043 {
6044 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6045 this->objects().user_pointer(this->present_index) = p;
6046 }
6047
6048
6049
6050 template <int structdim, int dim, int spacedim>
6051 void
6052 TriaAccessor<structdim, dim, spacedim>::clear_user_pointer() const
6053 {
6054 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6055 this->objects().user_pointer(this->present_index) = nullptr;
6056 }
6057
6058
6059
6060 template <int structdim, int dim, int spacedim>
6061 void *
6062 TriaAccessor<structdim, dim, spacedim>::user_pointer() const
6063 {
6064 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6065 return this->objects().user_pointer(this->present_index);
6066 }
6067
6068
6069
6070 template <int structdim, int dim, int spacedim>
6071 void
6072 TriaAccessor<structdim, dim, spacedim>::recursively_set_user_pointer(
6073 void *p) const
6074 {
6075 set_user_pointer(p);
6076
6077 if (this->has_children())
6078 for (unsigned int c = 0; c < this->n_children(); ++c)
6079 this->child(c)->recursively_set_user_pointer(p);
6080 }
6081
6082
6083
6084 template <int structdim, int dim, int spacedim>
6085 void
6086 TriaAccessor<structdim, dim, spacedim>::recursively_clear_user_pointer() const
6087 {
6088 clear_user_pointer();
6089
6090 if (this->has_children())
6091 for (unsigned int c = 0; c < this->n_children(); ++c)
6092 this->child(c)->recursively_clear_user_pointer();
6093 }
6094
6095
6096
6097 template <int structdim, int dim, int spacedim>
6098 void
6099 TriaAccessor<structdim, dim, spacedim>::set_user_index(
6100 const unsigned int p) const
6101 {
6102 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6103 this->objects().user_index(this->present_index) = p;
6104 }
6105
6106
6107
6108 template <int structdim, int dim, int spacedim>
6109 void
6110 TriaAccessor<structdim, dim, spacedim>::clear_user_index() const
6111 {
6112 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6113 this->objects().user_index(this->present_index) = 0;
6114 }
6115
6116
6117
6118 template <int structdim, int dim, int spacedim>
6119 unsigned int
6120 TriaAccessor<structdim, dim, spacedim>::user_index() const
6121 {
6122 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6123 return this->objects().user_index(this->present_index);
6124 }
6125
6126
6127
6128 template <int structdim, int dim, int spacedim>
6129 void
6130 TriaAccessor<structdim, dim, spacedim>::recursively_set_user_index(
6131 const unsigned int p) const
6132 {
6133 set_user_index(p);
6134
6135 if (this->has_children())
6136 for (unsigned int c = 0; c < this->n_children(); ++c)
6137 this->child(c)->recursively_set_user_index(p);
6138 }
6139
6140
6141
6142 template <int structdim, int dim, int spacedim>
6143 void
6144 TriaAccessor<structdim, dim, spacedim>::recursively_clear_user_index() const
6145 {
6146 clear_user_index();
6147
6148 if (this->has_children())
6149 for (unsigned int c = 0; c < this->n_children(); ++c)
6150 this->child(c)->recursively_clear_user_index();
6151 }
6152
6153
6154
6155 template <int structdim, int dim, int spacedim>
6156 inline unsigned int
6157 TriaAccessor<structdim, dim, spacedim>::max_refinement_depth() const
6158 {
6159 if (!this->has_children())
6160 return 0;
6161
6162 unsigned int max_depth = 1;
6163 for (unsigned int c = 0; c < n_children(); ++c)
6164 max_depth = std::max(max_depth, child(c)->max_refinement_depth() + 1);
6165 return max_depth;
6166 }
6167
6168
6169
6170 template <int structdim, int dim, int spacedim>
6171 unsigned int
6172 TriaAccessor<structdim, dim, spacedim>::n_active_descendants() const
6173 {
6174 if (!this->has_children())
6175 return 1;
6176 else
6177 {
6178 unsigned int sum = 0;
6179 for (unsigned int c = 0; c < n_children(); ++c)
6180 sum += this->child(c)->n_active_descendants();
6181 return sum;
6182 }
6183 }
6184
6185
6186
6187 template <int structdim, int dim, int spacedim>
6188 types::boundary_id
6189 TriaAccessor<structdim, dim, spacedim>::boundary_id() const
6190 {
6191 Assert(structdim < dim, ExcImpossibleInDim(dim));
6192 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6193
6194 return this->objects()
6195 .boundary_or_material_id[this->present_index]
6196 .boundary_id;
6197 }
6198
6199
6200
6201 template <int structdim, int dim, int spacedim>
6202 void
6203 TriaAccessor<structdim, dim, spacedim>::set_boundary_id(
6204 const types::boundary_id boundary_ind) const
6205 {
6206 Assert(structdim < dim, ExcImpossibleInDim(dim));
6207 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6208 Assert(boundary_ind != numbers::internal_face_boundary_id,
6209 ExcMessage("You are trying to set the boundary_id to an invalid "
6210 "value (numbers::internal_face_boundary_id is reserved)."));
6211 Assert(this->at_boundary(),
6212 ExcMessage("You are trying to set the boundary_id of an "
6213 "internal object, which is not allowed!"));
6214
6215 this->objects().boundary_or_material_id[this->present_index].boundary_id =
6216 boundary_ind;
6217 }
6218
6219
6220
6221 template <int structdim, int dim, int spacedim>
6222 void
6223 TriaAccessor<structdim, dim, spacedim>::set_boundary_id_internal(
6224 const types::boundary_id boundary_ind) const
6225 {
6226 Assert(structdim < dim, ExcImpossibleInDim(dim));
6227 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6228
6229 this->objects().boundary_or_material_id[this->present_index].boundary_id =
6230 boundary_ind;
6231 }
6232
6233
6234
6235 template <int structdim, int dim, int spacedim>
6236 void
6237 TriaAccessor<structdim, dim, spacedim>::set_all_boundary_ids(
6238 const types::boundary_id boundary_ind) const
6239 {
6240 set_boundary_id(boundary_ind);
6241
6242 switch (structdim)
6243 {
6244 case 1:
6245 // 1d objects have no sub-objects
6246 // where we have to do anything
6247 break;
6248
6249 case 2:
6250 // for boundary quads also set
6251 // boundary_id of bounding lines
6252 for (unsigned int i = 0; i < this->n_lines(); ++i)
6253 this->line(i)->set_boundary_id(boundary_ind);
6254 break;
6255
6256 default:
6257 DEAL_II_NOT_IMPLEMENTED();
6258 }
6259 }
6260
6261
6262
6263 template <int structdim, int dim, int spacedim>
6264 bool
6265 TriaAccessor<structdim, dim, spacedim>::at_boundary() const
6266 {
6267 // error checking is done
6268 // in boundary_id()
6269 return (boundary_id() != numbers::internal_face_boundary_id);
6270 }
6271
6272
6273
6274 template <int structdim, int dim, int spacedim>
6275 const Manifold<dim, spacedim> &
6276 TriaAccessor<structdim, dim, spacedim>::get_manifold() const
6277 {
6278 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6279 return this->tria->get_manifold(this->manifold_id());
6280 }
6281
6282
6283 template <int structdim, int dim, int spacedim>
6284 types::manifold_id
6285 TriaAccessor<structdim, dim, spacedim>::manifold_id() const
6286 {
6287 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6288
6289 return this->objects().manifold_id[this->present_index];
6290 }
6291
6292
6293
6294 template <int structdim, int dim, int spacedim>
6295 void
6296 TriaAccessor<structdim, dim, spacedim>::set_manifold_id(
6297 const types::manifold_id manifold_ind) const
6298 {
6299 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
6300
6301 this->objects().manifold_id[this->present_index] = manifold_ind;
6302 }
6303
6304
6305 template <int structdim, int dim, int spacedim>
6306 void
6307 TriaAccessor<structdim, dim, spacedim>::set_all_manifold_ids(
6308 const types::manifold_id manifold_ind) const
6309 {
6310 set_manifold_id(manifold_ind);
6311
6312 if (this->has_children())
6313 for (unsigned int c = 0; c < this->n_children(); ++c)
6314 this->child(c)->set_all_manifold_ids(manifold_ind);
6315
6316 switch (structdim)
6317 {
6318 case 1:
6319 if (dim == 1)
6320 {
6321 (*this->tria->vertex_to_manifold_id_map_1d)[vertex_index(0)] =
6322 manifold_ind;
6323 (*this->tria->vertex_to_manifold_id_map_1d)[vertex_index(1)] =
6324 manifold_ind;
6325 }
6326 break;
6327
6328 case 2:
6329 // for quads/simplices also set manifold_id of bounding lines
6330 for (unsigned int i = 0; i < this->n_lines(); ++i)
6331 this->line(i)->set_manifold_id(manifold_ind);
6332 break;
6333 default:
6334 DEAL_II_NOT_IMPLEMENTED();
6335 }
6336 }
6337
6338
6339
6340 template <int structdim, int dim, int spacedim>
6341 double
6342 TriaAccessor<structdim, dim, spacedim>::diameter() const
6343 {
6344 boost::container::small_vector<Point<spacedim>,
6345 # ifndef _MSC_VER
6346 ReferenceCells::max_n_vertices<structdim>()
6347 # else
6348 GeometryInfo<structdim>::vertices_per_cell
6349 # endif
6350 >
6351 vertices(this->n_vertices());
6352
6353 for (unsigned int v = 0; v < vertices.size(); ++v)
6354 vertices[v] = this->vertex(v);
6355
6356 return internal::TriaAccessorImplementation::diameter<structdim, spacedim>(
6357 vertices);
6358 }
6359
6360
6361
6362 template <int dim, int spacedim>
6363 double
6364 CellAccessor<dim, spacedim>::diameter(
6365 const Mapping<dim, spacedim> &mapping) const
6366 {
6367 return internal::TriaAccessorImplementation::diameter<dim, spacedim>(
6368 mapping.get_vertices(typename Triangulation<dim, spacedim>::cell_iterator(
6369 this->tria, this->level(), this->index())));
6370 }
6371
6372
6373
6374 template <int structdim, int dim, int spacedim>
6375 std::pair<Point<spacedim>, double>
6376 TriaAccessor<structdim, dim, spacedim>::enclosing_ball() const
6377 {
6378 // If the object is one dimensional,
6379 // the enclosing ball is the initial iterate
6380 // i.e., the ball's center and diameter are
6381 // the center and the diameter of the object.
6382 if (structdim == 1)
6383 return std::make_pair((this->vertex(1) + this->vertex(0)) * 0.5,
6384 (this->vertex(1) - this->vertex(0)).norm() * 0.5);
6385
6386 // The list is_initial_guess_vertex contains bool values and has
6387 // the same size as the number of vertices per object.
6388 // The entries of is_initial_guess_vertex are set true only for those
6389 // two vertices corresponding to the largest diagonal which is being used
6390 // to construct the initial ball.
6391 // We employ this mask to skip these two vertices while enlarging the ball.
6392 std::vector<bool> is_initial_guess_vertex(this->n_vertices());
6393
6394 // First let all the vertices be outside
6395 std::fill(is_initial_guess_vertex.begin(),
6396 is_initial_guess_vertex.end(),
6397 false);
6398
6399 // Get an initial guess by looking at the largest diagonal
6400 Point<spacedim> center;
6401 double radius = 0;
6402
6403 switch (structdim)
6404 {
6405 case 2:
6406 {
6407 const Point<spacedim> p30(this->vertex(3) - this->vertex(0));
6408 const Point<spacedim> p21(this->vertex(2) - this->vertex(1));
6409 if (p30.norm() > p21.norm())
6410 {
6411 center = this->vertex(0) + 0.5 * p30;
6412 radius = p30.norm() / 2.;
6413 is_initial_guess_vertex[3] = true;
6414 is_initial_guess_vertex[0] = true;
6415 }
6416 else
6417 {
6418 center = this->vertex(1) + 0.5 * p21;
6419 radius = p21.norm() / 2.;
6420 is_initial_guess_vertex[2] = true;
6421 is_initial_guess_vertex[1] = true;
6422 }
6423 break;
6424 }
6425 case 3:
6426 {
6427 const Point<spacedim> p70(this->vertex(7) - this->vertex(0));
6428 const Point<spacedim> p61(this->vertex(6) - this->vertex(1));
6429 const Point<spacedim> p25(this->vertex(2) - this->vertex(5));
6430 const Point<spacedim> p34(this->vertex(3) - this->vertex(4));
6431 const std::vector<double> diagonals = {p70.norm(),
6432 p61.norm(),
6433 p25.norm(),
6434 p34.norm()};
6435 const std::vector<double>::const_iterator it =
6436 std::max_element(diagonals.begin(), diagonals.end());
6437 if (it == diagonals.begin())
6438 {
6439 center = this->vertex(0) + 0.5 * p70;
6440 is_initial_guess_vertex[7] = true;
6441 is_initial_guess_vertex[0] = true;
6442 }
6443 else if (it == diagonals.begin() + 1)
6444 {
6445 center = this->vertex(1) + 0.5 * p61;
6446 is_initial_guess_vertex[6] = true;
6447 is_initial_guess_vertex[1] = true;
6448 }
6449 else if (it == diagonals.begin() + 2)
6450 {
6451 center = this->vertex(5) + 0.5 * p25;
6452 is_initial_guess_vertex[2] = true;
6453 is_initial_guess_vertex[5] = true;
6454 }
6455 else
6456 {
6457 center = this->vertex(4) + 0.5 * p34;
6458 is_initial_guess_vertex[3] = true;
6459 is_initial_guess_vertex[4] = true;
6460 }
6461 radius = *it * 0.5;
6462 break;
6463 }
6464 default:
6465 DEAL_II_NOT_IMPLEMENTED();
6466 return std::pair<Point<spacedim>, double>();
6467 }
6468
6469 // For each vertex that is found to be geometrically outside the ball
6470 // enlarge the ball so that the new ball contains both the previous ball
6471 // and the given vertex.
6472 for (const unsigned int v : this->vertex_indices())
6473 if (!is_initial_guess_vertex[v])
6474 {
6475 const double distance = center.distance(this->vertex(v));
6476 if (distance > radius)
6477 {
6478 // we found a vertex which is outside of the ball
6479 // extend it (move center and change radius)
6480 const Point<spacedim> pCV(center - this->vertex(v));
6481 radius = (distance + radius) * 0.5;
6482 center = this->vertex(v) + pCV * (radius / distance);
6483
6484 // Now the new ball constructed in this block
6485 // encloses the vertex (v) that was found to be geometrically
6486 // outside the old ball.
6487 }
6488 }
6489 if constexpr (running_in_debug_mode())
6490 {
6491 bool all_vertices_within_ball = true;
6492
6493 // Set all_vertices_within_ball false if any of the vertices of the object
6494 // are geometrically outside the ball
6495 for (const unsigned int v : this->vertex_indices())
6496 if (center.distance(this->vertex(v)) >
6497 radius + 100. * std::numeric_limits<double>::epsilon())
6498 {
6499 all_vertices_within_ball = false;
6500 break;
6501 }
6502 // If all the vertices are not within the ball throw error
6503 Assert(all_vertices_within_ball, ExcInternalError());
6504 }
6505 return std::make_pair(center, radius);
6506 }
6507
6508
6509 template <int structdim, int dim, int spacedim>
6510 double
6511 TriaAccessor<structdim, dim, spacedim>::minimum_vertex_distance() const
6512 {
6513 switch (structdim)
6514 {
6515 case 1:
6516 return (this->vertex(1) - this->vertex(0)).norm();
6517 case 2:
6518 case 3:
6519 {
6520 double min = std::numeric_limits<double>::max();
6521 for (const unsigned int i : this->vertex_indices())
6522 for (unsigned int j = i + 1; j < this->n_vertices(); ++j)
6523 min = std::min(min,
6524 (this->vertex(i) - this->vertex(j)) *
6525 (this->vertex(i) - this->vertex(j)));
6526 return std::sqrt(min);
6527 }
6528 default:
6529 DEAL_II_NOT_IMPLEMENTED();
6530 return -1e10;
6531 }
6532 }
6533
6534
6535 template <int structdim, int dim, int spacedim>
6536 bool
6537 TriaAccessor<structdim, dim, spacedim>::is_translation_of(
6538 const TriaIterator<TriaAccessor<structdim, dim, spacedim>> &o) const
6539 {
6540 // go through the vertices and check... The
6541 // cell is a translation of the previous
6542 // one in case the distance between the
6543 // individual vertices in the two cell is
6544 // the same for all the vertices. So do the
6545 // check by first getting the distance on
6546 // the first vertex, and then checking
6547 // whether all others have the same down to
6548 // rounding errors (we have to be careful
6549 // here because the calculation of the
6550 // displacement between one cell and the
6551 // next can already result in the loss of
6552 // one or two digits), so we choose 1e-12
6553 // times the distance between the zeroth
6554 // vertices here.
6555 bool is_translation = true;
6556 const Tensor<1, spacedim> dist = o->vertex(0) - this->vertex(0);
6557 const double tol_square = 1e-24 * dist.norm_square();
6558 for (unsigned int i = 1; i < this->n_vertices(); ++i)
6559 {
6560 const Tensor<1, spacedim> dist_new =
6561 (o->vertex(i) - this->vertex(i)) - dist;
6562 if (dist_new.norm_square() > tol_square)
6563 {
6564 is_translation = false;
6565 break;
6566 }
6567 }
6568 return is_translation;
6569 }
6570
6571
6572
6573 template <int structdim, int dim, int spacedim>
6574 unsigned int
6575 TriaAccessor<structdim, dim, spacedim>::n_vertices() const
6576 {
6577 return this->reference_cell().n_vertices();
6578 }
6579
6580
6581
6582 template <int structdim, int dim, int spacedim>
6583 unsigned int
6584 TriaAccessor<structdim, dim, spacedim>::n_lines() const
6585 {
6586 return this->reference_cell().n_lines();
6587 }
6588
6589
6590
6591 template <int structdim, int dim, int spacedim>
6592 unsigned int
6593 TriaAccessor<structdim, dim, spacedim>::n_faces() const
6594 {
6595 Assert(structdim == dim,
6596 ExcMessage("This function can only be used on objects "
6597 "that are cells, but not on faces or edges "
6598 "that bound cells."));
6599
6600 return this->reference_cell().n_faces();
6601 }
6602
6603
6604
6605 template <int structdim, int dim, int spacedim>
6606 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
6607 TriaAccessor<structdim, dim, spacedim>::vertex_indices() const
6608 {
6609 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
6610 n_vertices());
6611 }
6612
6613
6614
6615 template <int structdim, int dim, int spacedim>
6616 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
6617 TriaAccessor<structdim, dim, spacedim>::line_indices() const
6618 {
6619 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
6620 n_lines());
6621 }
6622
6623
6624
6625 template <int structdim, int dim, int spacedim>
6626 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
6627 TriaAccessor<structdim, dim, spacedim>::face_indices() const
6628 {
6629 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
6630 n_faces());
6631 }
6632
6633
6634
6635 /*----------------- Functions: TriaAccessor<0,dim,spacedim> -----------------*/
6636
6637 template <int dim, int spacedim>
6638 inline TriaAccessor<0, dim, spacedim>::TriaAccessor(
6639 const Triangulation<dim, spacedim> *tria,
6640 const unsigned int vertex_index)
6641 : tria(tria)
6642 , global_vertex_index(vertex_index)
6643 {}
6644
6645
6646
6647 template <int dim, int spacedim>
6648 inline TriaAccessor<0, dim, spacedim>::TriaAccessor(
6649 const Triangulation<dim, spacedim> *tria,
6650 const int /*level*/,
6651 const int index,
6652 const AccessorData *)
6653 : tria(tria)
6654 , global_vertex_index(index)
6655 {}
6656
6657
6658
6659 template <int dim, int spacedim>
6660 template <int structdim2, int dim2, int spacedim2>
6661 inline TriaAccessor<0, dim, spacedim>::TriaAccessor(
6662 const TriaAccessor<structdim2, dim2, spacedim2> &)
6663 : tria(nullptr)
6664 , global_vertex_index(numbers::invalid_unsigned_int)
6665 {
6666 Assert(false, ExcImpossibleInDim(0));
6667 }
6668
6669
6670
6671 template <int dim, int spacedim>
6672 template <int structdim2, int dim2, int spacedim2>
6673 inline TriaAccessor<0, dim, spacedim>::TriaAccessor(
6674 const InvalidAccessor<structdim2, dim2, spacedim2> &)
6675 : tria(nullptr)
6676 , global_vertex_index(numbers::invalid_unsigned_int)
6677 {
6678 Assert(false, ExcImpossibleInDim(0));
6679 }
6680
6681
6682
6683 template <int dim, int spacedim>
6684 inline void
6685 TriaAccessor<0, dim, spacedim>::copy_from(const TriaAccessor &t)
6686 {
6687 tria = t.tria;
6688 global_vertex_index = t.global_vertex_index;
6689 }
6690
6691
6692
6693 template <int dim, int spacedim>
6694 inline bool
6695 TriaAccessor<0, dim, spacedim>::operator<(
6696 const TriaAccessor<0, dim, spacedim> &other) const
6697 {
6698 Assert(tria == other.tria, TriaAccessorExceptions::ExcCantCompareIterators());
6699
6700 return (global_vertex_index < other.global_vertex_index);
6701 }
6702
6703
6704
6705 template <int dim, int spacedim>
6706 inline IteratorState::IteratorStates
6707 TriaAccessor<0, dim, spacedim>::state() const
6708 {
6709 if (global_vertex_index != numbers::invalid_unsigned_int)
6710 return IteratorState::valid;
6711 else
6712 return IteratorState::past_the_end;
6713 }
6714
6715
6716
6717 template <int dim, int spacedim>
6718 inline int
6719 TriaAccessor<0, dim, spacedim>::level()
6720 {
6721 return 0;
6722 }
6723
6724
6725
6726 template <int dim, int spacedim>
6727 inline int
6728 TriaAccessor<0, dim, spacedim>::index() const
6729 {
6730 return global_vertex_index;
6731 }
6732
6733
6734
6735 template <int dim, int spacedim>
6736 inline const Triangulation<dim, spacedim> &
6737 TriaAccessor<0, dim, spacedim>::get_triangulation() const
6738 {
6739 return *tria;
6740 }
6741
6742
6743
6744 template <int dim, int spacedim>
6745 inline void
6746 TriaAccessor<0, dim, spacedim>::operator++()
6747 {
6748 ++global_vertex_index;
6749 if (global_vertex_index >= tria->n_vertices())
6750 global_vertex_index = numbers::invalid_unsigned_int;
6751 }
6752
6753
6754
6755 template <int dim, int spacedim>
6756 inline void
6757 TriaAccessor<0, dim, spacedim>::operator--()
6758 {
6759 if (global_vertex_index != numbers::invalid_unsigned_int)
6760 {
6761 if (global_vertex_index != 0)
6762 --global_vertex_index;
6763 else
6764 global_vertex_index = numbers::invalid_unsigned_int;
6765 }
6766 }
6767
6768
6769
6770 template <int dim, int spacedim>
6771 inline bool
6772 TriaAccessor<0, dim, spacedim>::operator==(const TriaAccessor &t) const
6773 {
6774 const bool result =
6775 ((tria == t.tria) && (global_vertex_index == t.global_vertex_index));
6776
6777 return result;
6778 }
6779
6780
6781
6782 template <int dim, int spacedim>
6783 inline bool
6784 TriaAccessor<0, dim, spacedim>::operator!=(const TriaAccessor &t) const
6785 {
6786 return !(*this == t);
6787 }
6788
6789
6790
6791 template <int dim, int spacedim>
6792 inline unsigned int
6793 TriaAccessor<0, dim, spacedim>::vertex_index(const unsigned int) const
6794 {
6795 return global_vertex_index;
6796 }
6797
6798
6799
6800 template <int dim, int spacedim>
6801 inline Point<spacedim> &
6802 TriaAccessor<0, dim, spacedim>::vertex(const unsigned int) const
6803 {
6804 return const_cast<Point<spacedim> &>(
6805 this->tria->vertices[global_vertex_index]);
6806 }
6807
6808
6809
6810 template <int dim, int spacedim>
6811 inline typename dealii::internal::TriangulationImplementation::
6812 Iterators<dim, spacedim>::line_iterator
6813 TriaAccessor<0, dim, spacedim>::line(const unsigned int)
6814 {
6815 return typename dealii::internal::TriangulationImplementation::
6816 Iterators<dim, spacedim>::line_iterator();
6817 }
6818
6819
6820
6821 template <int dim, int spacedim>
6822 inline unsigned int
6823 TriaAccessor<0, dim, spacedim>::line_index(const unsigned int)
6824 {
6825 Assert(false, ExcImpossibleInDim(0));
6826 return numbers::invalid_unsigned_int;
6827 }
6828
6829
6830
6831 template <int dim, int spacedim>
6832 inline typename dealii::internal::TriangulationImplementation::
6833 Iterators<dim, spacedim>::quad_iterator
6834 TriaAccessor<0, dim, spacedim>::quad(const unsigned int)
6835 {
6836 return typename dealii::internal::TriangulationImplementation::
6837 Iterators<dim, spacedim>::quad_iterator();
6838 }
6839
6840
6841
6842 template <int dim, int spacedim>
6843 inline unsigned int
6844 TriaAccessor<0, dim, spacedim>::quad_index(const unsigned int)
6845 {
6846 Assert(false, ExcImpossibleInDim(0));
6847 return numbers::invalid_unsigned_int;
6848 }
6849
6850
6851
6852 template <int dim, int spacedim>
6853 inline double
6854 TriaAccessor<0, dim, spacedim>::diameter() const
6855 {
6856 return 0.;
6857 }
6858
6859
6860
6861 template <int dim, int spacedim>
6862 inline double
6863 TriaAccessor<0, dim, spacedim>::extent_in_direction(const unsigned int) const
6864 {
6865 return 0.;
6866 }
6867
6868
6869
6870 template <int dim, int spacedim>
6871 inline Point<spacedim>
6872 TriaAccessor<0, dim, spacedim>::center(const bool, const bool) const
6873 {
6874 return this->tria->vertices[global_vertex_index];
6875 }
6876
6877
6878
6879 template <int dim, int spacedim>
6880 inline double
6881 TriaAccessor<0, dim, spacedim>::measure() const
6882 {
6883 return 1.0;
6884 }
6885
6886
6887
6888 template <int dim, int spacedim>
6889 inline types::geometric_orientation
6890 TriaAccessor<0, dim, spacedim>::combined_face_orientation(
6891 const unsigned int /*face*/)
6892 {
6893 return numbers::default_geometric_orientation;
6894 }
6895
6896
6897
6898 template <int dim, int spacedim>
6899 inline bool
6900 TriaAccessor<0, dim, spacedim>::face_orientation(const unsigned int /*face*/)
6901 {
6902 return false;
6903 }
6904
6905
6906
6907 template <int dim, int spacedim>
6908 inline bool
6909 TriaAccessor<0, dim, spacedim>::face_flip(const unsigned int /*face*/)
6910 {
6911 return false;
6912 }
6913
6914
6915
6916 template <int dim, int spacedim>
6917 inline bool
6918 TriaAccessor<0, dim, spacedim>::face_rotation(const unsigned int /*face*/)
6919 {
6920 return false;
6921 }
6922
6923
6924
6925 template <int dim, int spacedim>
6926 inline types::geometric_orientation
6927 TriaAccessor<0, dim, spacedim>::line_orientation(const unsigned int /*line*/)
6928 {
6929 return numbers::reverse_line_orientation;
6930 }
6931
6932
6933
6934 template <int dim, int spacedim>
6935 inline bool
6936 TriaAccessor<0, dim, spacedim>::has_children()
6937 {
6938 return false;
6939 }
6940
6941
6942
6943 template <int dim, int spacedim>
6944 inline unsigned int
6945 TriaAccessor<0, dim, spacedim>::n_children()
6946 {
6947 return 0;
6948 }
6949
6950
6951
6952 template <int dim, int spacedim>
6953 inline unsigned int
6954 TriaAccessor<0, dim, spacedim>::n_active_descendants()
6955 {
6956 return 0;
6957 }
6958
6959
6960
6961 template <int dim, int spacedim>
6962 inline unsigned int
6963 TriaAccessor<0, dim, spacedim>::max_refinement_depth()
6964 {
6965 return 0;
6966 }
6967
6968
6969
6970 template <int dim, int spacedim>
6971 inline unsigned int
6972 TriaAccessor<0, dim, spacedim>::child_iterator_to_index(
6973 const TriaIterator<TriaAccessor<0, dim, spacedim>> &)
6974 {
6975 return numbers::invalid_unsigned_int;
6976 }
6977
6978
6979
6980 template <int dim, int spacedim>
6981 inline TriaIterator<TriaAccessor<0, dim, spacedim>>
6982 TriaAccessor<0, dim, spacedim>::child(const unsigned int)
6983 {
6984 return TriaIterator<TriaAccessor<0, dim, spacedim>>();
6985 }
6986
6987
6988
6989 template <int dim, int spacedim>
6990 inline TriaIterator<TriaAccessor<0, dim, spacedim>>
6991 TriaAccessor<0, dim, spacedim>::isotropic_child(const unsigned int)
6992 {
6993 return TriaIterator<TriaAccessor<0, dim, spacedim>>();
6994 }
6995
6996
6997
6998 template <int dim, int spacedim>
6999 inline RefinementCase<0>
7000 TriaAccessor<0, dim, spacedim>::refinement_case()
7001 {
7002 return {RefinementPossibilities<0>::no_refinement};
7003 }
7004
7005
7006
7007 template <int dim, int spacedim>
7008 inline int
7009 TriaAccessor<0, dim, spacedim>::child_index(const unsigned int)
7010 {
7011 return -1;
7012 }
7013
7014
7015
7016 template <int dim, int spacedim>
7017 inline int
7018 TriaAccessor<0, dim, spacedim>::isotropic_child_index(const unsigned int)
7019 {
7020 return -1;
7021 }
7022
7023
7024
7025 template <int dim, int spacedim>
7026 inline bool
7027 TriaAccessor<0, dim, spacedim>::used() const
7028 {
7029 return tria->vertex_used(global_vertex_index);
7030 }
7031
7032
7033
7034 /*------------------- Functions: TriaAccessor<0,1,spacedim> -----------------*/
7035
7036 template <int spacedim>
7037 inline TriaAccessor<0, 1, spacedim>::TriaAccessor(
7038 const Triangulation<1, spacedim> *tria,
7039 const VertexKind vertex_kind,
7040 const unsigned int vertex_index)
7041 : tria(tria)
7042 , vertex_kind(vertex_kind)
7043 , global_vertex_index(vertex_index)
7044 {}
7045
7046
7047
7048 template <int spacedim>
7049 inline TriaAccessor<0, 1, spacedim>::TriaAccessor(
7050 const Triangulation<1, spacedim> *tria,
7051 const int level,
7052 const int index,
7053 const AccessorData *)
7054 : tria(tria)
7055 , vertex_kind(interior_vertex)
7056 , global_vertex_index(numbers::invalid_unsigned_int)
7057 {
7058 // in general, calling this constructor should yield an error -- users should
7059 // instead call the one immediately above. however, if you create something
7060 // like Triangulation<1>::face_iterator() then this calls the default
7061 // constructor of the iterator which calls the accessor with argument list
7062 // (0,-2,-2,0), so in this particular case accept this call and create an
7063 // object that corresponds to the default constructed (invalid) vertex
7064 // accessor
7065 (void)level;
7066 (void)index;
7067 Assert((level == -2) && (index == -2),
7068 ExcMessage(
7069 "This constructor can not be called for face iterators in 1d, "
7070 "except to default-construct iterator objects."));
7071 }
7072
7073
7074
7075 template <int spacedim>
7076 template <int structdim2, int dim2, int spacedim2>
7077 inline TriaAccessor<0, 1, spacedim>::TriaAccessor(
7078 const TriaAccessor<structdim2, dim2, spacedim2> &)
7079 : tria(nullptr)
7080 , vertex_kind(interior_vertex)
7081 , global_vertex_index(numbers::invalid_unsigned_int)
7082 {
7083 Assert(false, ExcImpossibleInDim(0));
7084 }
7085
7086
7087
7088 template <int spacedim>
7089 template <int structdim2, int dim2, int spacedim2>
7090 inline TriaAccessor<0, 1, spacedim>::TriaAccessor(
7091 const InvalidAccessor<structdim2, dim2, spacedim2> &)
7092 : tria(nullptr)
7093 , vertex_kind(interior_vertex)
7094 , global_vertex_index(numbers::invalid_unsigned_int)
7095 {
7096 Assert(false, ExcImpossibleInDim(0));
7097 }
7098
7099
7100
7101 template <int spacedim>
7102 inline void
7103 TriaAccessor<0, 1, spacedim>::copy_from(const TriaAccessor &t)
7104 {
7105 tria = t.tria;
7106 vertex_kind = t.vertex_kind;
7107 global_vertex_index = t.global_vertex_index;
7108 }
7109
7110
7111
7112 template <int spacedim>
7113 inline void
7114 TriaAccessor<0, 1, spacedim>::copy_from(
7115 const TriaAccessorBase<0, 1, spacedim> &)
7116 {
7117 // We cannot convert from TriaAccessorBase to
7118 // TriaAccessor<0,1,spacedim> because the latter is not derived from
7119 // the former. We should never get here.
7120 DEAL_II_ASSERT_UNREACHABLE();
7121 }
7122
7123
7124
7125 template <int spacedim>
7126 inline bool
7127 TriaAccessor<0, 1, spacedim>::operator<(
7128 const TriaAccessor<0, 1, spacedim> &other) const
7129 {
7130 Assert(tria == other.tria, TriaAccessorExceptions::ExcCantCompareIterators());
7131
7132 return (global_vertex_index < other.global_vertex_index);
7133 }
7134
7135
7136
7137 template <int spacedim>
7138 inline IteratorState::IteratorStates
7139 TriaAccessor<0, 1, spacedim>::state()
7140 {
7141 return IteratorState::valid;
7142 }
7143
7144
7145 template <int spacedim>
7146 inline int
7147 TriaAccessor<0, 1, spacedim>::level()
7148 {
7149 return 0;
7150 }
7151
7152
7153
7154 template <int spacedim>
7155 inline int
7156 TriaAccessor<0, 1, spacedim>::index() const
7157 {
7158 return global_vertex_index;
7159 }
7160
7161
7162
7163 template <int spacedim>
7164 inline const Triangulation<1, spacedim> &
7165 TriaAccessor<0, 1, spacedim>::get_triangulation() const
7166 {
7167 return *tria;
7168 }
7169
7170
7171
7172 template <int spacedim>
7173 inline void
7174 TriaAccessor<0, 1, spacedim>::operator++() const
7175 {
7176 DEAL_II_NOT_IMPLEMENTED();
7177 }
7178
7179
7180 template <int spacedim>
7181 inline void
7182 TriaAccessor<0, 1, spacedim>::operator--() const
7183 {
7184 DEAL_II_NOT_IMPLEMENTED();
7185 }
7186
7187
7188
7189 template <int spacedim>
7190 inline bool
7191 TriaAccessor<0, 1, spacedim>::operator==(const TriaAccessor &t) const
7192 {
7193 const bool result =
7194 ((tria == t.tria) && (global_vertex_index == t.global_vertex_index));
7195 // if we point to the same vertex,
7196 // make sure we know the same about
7197 // it
7198 if (result == true)
7199 Assert(vertex_kind == t.vertex_kind, ExcInternalError());
7200
7201 return result;
7202 }
7203
7204
7205
7206 template <int spacedim>
7207 inline bool
7208 TriaAccessor<0, 1, spacedim>::operator!=(const TriaAccessor &t) const
7209 {
7210 return !(*this == t);
7211 }
7212
7213
7214
7215 template <int spacedim>
7216 inline unsigned int
7217 TriaAccessor<0, 1, spacedim>::vertex_index(const unsigned int i) const
7218 {
7219 AssertIndexRange(i, 1);
7220 (void)i;
7221 return global_vertex_index;
7222 }
7223
7224
7225
7226 template <int spacedim>
7227 inline Point<spacedim> &
7228 TriaAccessor<0, 1, spacedim>::vertex(const unsigned int i) const
7229 {
7230 AssertIndexRange(i, 1);
7231 (void)i;
7232 return const_cast<Point<spacedim> &>(
7233 this->tria->vertices[global_vertex_index]);
7234 }
7235
7236
7237
7238 template <int spacedim>
7239 inline Point<spacedim>
7240 TriaAccessor<0, 1, spacedim>::center() const
7241 {
7242 return this->tria->vertices[global_vertex_index];
7243 }
7244
7245
7246
7247 template <int spacedim>
7248 inline typename dealii::internal::TriangulationImplementation::
7249 Iterators<1, spacedim>::line_iterator
7250 TriaAccessor<0, 1, spacedim>::line(const unsigned int)
7251 {
7252 return {};
7253 }
7254
7255
7256 template <int spacedim>
7257 inline unsigned int
7258 TriaAccessor<0, 1, spacedim>::line_index(const unsigned int)
7259 {
7260 Assert(false, ExcImpossibleInDim(0));
7261 return numbers::invalid_unsigned_int;
7262 }
7263
7264
7265 template <int spacedim>
7266 inline typename dealii::internal::TriangulationImplementation::
7267 Iterators<1, spacedim>::quad_iterator
7268 TriaAccessor<0, 1, spacedim>::quad(const unsigned int)
7269 {
7270 return {};
7271 }
7272
7273
7274
7275 template <int spacedim>
7276 inline unsigned int
7277 TriaAccessor<0, 1, spacedim>::quad_index(const unsigned int)
7278 {
7279 Assert(false, ExcImpossibleInDim(0));
7280 return numbers::invalid_unsigned_int;
7281 }
7282
7283
7284
7285 template <int spacedim>
7286 inline double
7287 TriaAccessor<0, 1, spacedim>::measure()
7288 {
7289 return 1.0;
7290 }
7291
7292
7293
7294 template <int spacedim>
7295 inline bool
7296 TriaAccessor<0, 1, spacedim>::at_boundary() const
7297 {
7298 return vertex_kind != interior_vertex;
7299 }
7300
7301
7302 template <int spacedim>
7303 inline types::boundary_id
7304 TriaAccessor<0, 1, spacedim>::boundary_id() const
7305 {
7306 switch (vertex_kind)
7307 {
7308 case left_vertex:
7309 case right_vertex:
7310 {
7311 Assert(tria->vertex_to_boundary_id_map_1d->find(
7312 this->vertex_index()) !=
7313 tria->vertex_to_boundary_id_map_1d->end(),
7314 ExcInternalError());
7315
7316 return (*tria->vertex_to_boundary_id_map_1d)[this->vertex_index()];
7317 }
7318
7319 default:
7320 return numbers::internal_face_boundary_id;
7321 }
7322 }
7323
7324
7325
7326 template <int spacedim>
7327 inline const Manifold<1, spacedim> &
7328 TriaAccessor<0, 1, spacedim>::get_manifold() const
7329 {
7330 return this->tria->get_manifold(this->manifold_id());
7331 }
7332
7333
7334
7335 template <int spacedim>
7336 inline types::manifold_id
7337 TriaAccessor<0, 1, spacedim>::manifold_id() const
7338 {
7339 if (tria->vertex_to_manifold_id_map_1d->find(this->vertex_index()) !=
7340 tria->vertex_to_manifold_id_map_1d->end())
7341 return (*tria->vertex_to_manifold_id_map_1d)[this->vertex_index()];
7342 else
7343 return numbers::flat_manifold_id;
7344 }
7345
7346
7347 template <int spacedim>
7348 inline types::geometric_orientation
7349 TriaAccessor<0, 1, spacedim>::combined_face_orientation(
7350 const unsigned int /*face*/)
7351 {
7352 return numbers::reverse_line_orientation;
7353 }
7354
7355
7356 template <int spacedim>
7357 inline bool
7358 TriaAccessor<0, 1, spacedim>::face_orientation(const unsigned int /*face*/)
7359 {
7360 return false;
7361 }
7362
7363
7364
7365 template <int spacedim>
7366 inline bool
7367 TriaAccessor<0, 1, spacedim>::face_flip(const unsigned int /*face*/)
7368 {
7369 return false;
7370 }
7371
7372
7373
7374 template <int spacedim>
7375 inline bool
7376 TriaAccessor<0, 1, spacedim>::face_rotation(const unsigned int /*face*/)
7377 {
7378 return false;
7379 }
7380
7381
7382
7383 template <int spacedim>
7384 inline types::geometric_orientation
7385 TriaAccessor<0, 1, spacedim>::line_orientation(const unsigned int /*line*/)
7386 {
7387 return numbers::reverse_line_orientation;
7388 }
7389
7390
7391
7392 template <int spacedim>
7393 inline bool
7394 TriaAccessor<0, 1, spacedim>::has_children()
7395 {
7396 return false;
7397 }
7398
7399
7400
7401 template <int spacedim>
7402 inline unsigned int
7403 TriaAccessor<0, 1, spacedim>::n_children()
7404 {
7405 return 0;
7406 }
7407
7408
7409
7410 template <int spacedim>
7411 inline unsigned int
7412 TriaAccessor<0, 1, spacedim>::n_active_descendants()
7413 {
7414 return 0;
7415 }
7416
7417
7418
7419 template <int spacedim>
7420 inline unsigned int
7421 TriaAccessor<0, 1, spacedim>::max_refinement_depth()
7422 {
7423 return 0;
7424 }
7425
7426
7427
7428 template <int spacedim>
7429 inline unsigned int
7430 TriaAccessor<0, 1, spacedim>::child_iterator_to_index(
7431 const TriaIterator<TriaAccessor<0, 1, spacedim>> &)
7432 {
7433 return numbers::invalid_unsigned_int;
7434 }
7435
7436
7437
7438 template <int spacedim>
7439 inline TriaIterator<TriaAccessor<0, 1, spacedim>>
7440 TriaAccessor<0, 1, spacedim>::child(const unsigned int)
7441 {
7442 return TriaIterator<TriaAccessor<0, 1, spacedim>>();
7443 }
7444
7445
7446 template <int spacedim>
7447 inline TriaIterator<TriaAccessor<0, 1, spacedim>>
7448 TriaAccessor<0, 1, spacedim>::isotropic_child(const unsigned int)
7449 {
7450 return TriaIterator<TriaAccessor<0, 1, spacedim>>();
7451 }
7452
7453
7454 template <int spacedim>
7455 inline RefinementCase<0>
7456 TriaAccessor<0, 1, spacedim>::refinement_case()
7457 {
7458 return {RefinementPossibilities<0>::no_refinement};
7459 }
7460
7461 template <int spacedim>
7462 inline int
7463 TriaAccessor<0, 1, spacedim>::child_index(const unsigned int)
7464 {
7465 return -1;
7466 }
7467
7468
7469 template <int spacedim>
7470 inline int
7471 TriaAccessor<0, 1, spacedim>::isotropic_child_index(const unsigned int)
7472 {
7473 return -1;
7474 }
7475
7476
7477
7478 template <int spacedim>
7479 inline void
7480 TriaAccessor<0, 1, spacedim>::set_boundary_id(const types::boundary_id b) const
7481 {
7482 Assert(tria->vertex_to_boundary_id_map_1d->find(this->vertex_index()) !=
7483 tria->vertex_to_boundary_id_map_1d->end(),
7484 ExcMessage("You can't set the boundary_id of a face of a cell that is "
7485 "not actually at the boundary."));
7486
7487 (*tria->vertex_to_boundary_id_map_1d)[this->vertex_index()] = b;
7488 }
7489
7490
7491
7492 template <int spacedim>
7493 inline void
7494 TriaAccessor<0, 1, spacedim>::set_manifold_id(const types::manifold_id b)
7495 {
7496 (*tria->vertex_to_manifold_id_map_1d)[this->vertex_index()] = b;
7497 }
7498
7499
7500
7501 template <int spacedim>
7502 inline void
7503 TriaAccessor<0, 1, spacedim>::set_all_boundary_ids(
7504 const types::boundary_id b) const
7505 {
7506 set_boundary_id(b);
7507 }
7508
7509
7510
7511 template <int spacedim>
7512 inline void
7513 TriaAccessor<0, 1, spacedim>::set_all_manifold_ids(const types::manifold_id b)
7514 {
7515 set_manifold_id(b);
7516 }
7517
7518
7519
7520 template <int spacedim>
7521 inline bool
7522 TriaAccessor<0, 1, spacedim>::used() const
7523 {
7524 return tria->vertex_used(global_vertex_index);
7525 }
7526
7527
7528
7529 template <int spacedim>
7530 inline ReferenceCell
7531 TriaAccessor<0, 1, spacedim>::reference_cell() const
7532 {
7533 return ReferenceCells::Vertex;
7534 }
7535
7536
7537
7538 template <int spacedim>
7539 unsigned int
7540 TriaAccessor<0, 1, spacedim>::n_vertices() const
7541 {
7542 return 1;
7543 }
7544
7545
7546
7547 template <int spacedim>
7548 unsigned int
7549 TriaAccessor<0, 1, spacedim>::n_lines() const
7550 {
7551 return 0;
7552 }
7553
7554
7555
7556 template <int spacedim>
7557 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
7558 TriaAccessor<0, 1, spacedim>::vertex_indices() const
7559 {
7560 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
7561 n_vertices());
7562 }
7563
7564
7565
7566 template <int spacedim>
7567 std_cxx20::ranges::iota_view<unsigned int, unsigned int>
7568 TriaAccessor<0, 1, spacedim>::line_indices() const
7569 {
7570 return std_cxx20::ranges::iota_view<unsigned int, unsigned int>(0U,
7571 n_lines());
7572 }
7573
7574 /*------------------ Functions: CellAccessor<dim,spacedim> ------------------*/
7575
7576
7577 template <int dim, int spacedim>
7578 inline CellAccessor<dim, spacedim>::CellAccessor(
7579 const Triangulation<dim, spacedim> *parent,
7580 const int level,
7581 const int index,
7582 const AccessorData *local_data)
7583 : TriaAccessor<dim, dim, spacedim>(parent, level, index, local_data)
7584 {}
7585
7586
7587
7588 template <int dim, int spacedim>
7589 inline CellAccessor<dim, spacedim>::CellAccessor(
7590 const TriaAccessor<dim, dim, spacedim> &cell_accessor)
7591 : TriaAccessor<dim, dim, spacedim>(
7592 static_cast<const TriaAccessor<dim, dim, spacedim> &>(cell_accessor))
7593 {}
7594
7595
7596
7597 template <int dim, int spacedim>
7598 inline TriaIterator<CellAccessor<dim, spacedim>>
7599 CellAccessor<dim, spacedim>::child(const unsigned int i) const
7600 {
7601 TriaIterator<CellAccessor<dim, spacedim>> q(this->tria,
7602 this->present_level + 1,
7603 this->child_index(i));
7604
7605 Assert((q.state() == IteratorState::past_the_end) || q->used(),
7606 ExcInternalError());
7607
7608 return q;
7609 }
7610
7611
7612
7613 template <int dim, int spacedim>
7614 inline boost::container::small_vector<TriaIterator<CellAccessor<dim, spacedim>>,
7615 GeometryInfo<dim>::max_children_per_cell>
7616 CellAccessor<dim, spacedim>::child_iterators() const
7617 {
7618 boost::container::small_vector<TriaIterator<CellAccessor<dim, spacedim>>,
7619 GeometryInfo<dim>::max_children_per_cell>
7620 child_iterators(this->n_children());
7621
7622 for (unsigned int i = 0; i < this->n_children(); ++i)
7623 child_iterators[i] = this->child(i);
7624
7625 return child_iterators;
7626 }
7627
7628
7629
7630 template <int dim, int spacedim>
7631 inline TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>
7632 CellAccessor<dim, spacedim>::face(const unsigned int i) const
7633 {
7634 AssertIndexRange(i, this->n_faces());
7635 if constexpr (dim == 1)
7636 {
7637 using VertexKind = typename TriaAccessor<0, 1, spacedim>::VertexKind;
7638 VertexKind vertex_kind = VertexKind::interior_vertex;
7639 if (i == 0 && at_boundary(0))
7640 vertex_kind = VertexKind::left_vertex;
7641 if (i == 1 && at_boundary(1))
7642 vertex_kind = VertexKind::right_vertex;
7643 TriaAccessor<0, 1, spacedim> a(&this->get_triangulation(),
7644 vertex_kind,
7645 this->vertex_index(i));
7646 return TriaIterator<TriaAccessor<0, 1, spacedim>>(a);
7647 }
7648 else if constexpr (dim == 2)
7649 return this->line(i);
7650 else if constexpr (dim == 3)
7651 return this->quad(i);
7652 else
7653 {
7654 Assert(false, ExcNotImplemented());
7655 return {};
7656 }
7657 }
7658
7659
7660
7661 template <int dim, int spacedim>
7662 inline unsigned int
7663 CellAccessor<dim, spacedim>::face_iterator_to_index(
7664 const TriaIterator<TriaAccessor<dim - 1, dim, spacedim>> &face) const
7665 {
7666 for (const unsigned int face_n : this->face_indices())
7667 if (this->face(face_n) == face)
7668 return face_n;
7669
7670 Assert(false,
7671 ExcMessage("The given face is not a face of the current cell."));
7672 return numbers::invalid_unsigned_int;
7673 }
7674
7675
7676
7677 template <int dim, int spacedim>
7678 inline boost::container::small_vector<
7679 TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>,
7680 # ifndef _MSC_VER
7681 ReferenceCells::max_n_faces<dim>()
7682 # else
7683 GeometryInfo<dim>::faces_per_cell
7684 # endif
7685 >
7686 CellAccessor<dim, spacedim>::face_iterators() const
7687 {
7688 boost::container::small_vector<
7689 TriaIterator<TriaAccessor<dim - 1, dim, spacedim>>,
7690 # ifndef _MSC_VER
7691 ReferenceCells::max_n_faces<dim>()
7692 # else
7693 GeometryInfo<dim>::faces_per_cell
7694 # endif
7695 >
7696 face_iterators(this->n_faces());
7697
7698 for (const unsigned int i : this->face_indices())
7699 face_iterators[i] = this->face(i);
7700
7701 return face_iterators;
7702 }
7703
7704
7705
7706 template <int dim, int spacedim>
7707 inline unsigned int
7708 CellAccessor<dim, spacedim>::face_index(const unsigned int i) const
7709 {
7710 switch (dim)
7711 {
7712 case 1:
7713 return this->vertex_index(i);
7714
7715 case 2:
7716 return this->line_index(i);
7717
7718 case 3:
7719 return this->quad_index(i);
7720
7721 default:
7722 return numbers::invalid_unsigned_int;
7723 }
7724 }
7725
7726
7727
7728 template <int dim, int spacedim>
7729 inline int
7730 CellAccessor<dim, spacedim>::neighbor_index(const unsigned int face_no) const
7731 {
7732 AssertIndexRange(face_no, this->n_faces());
7733 return this->tria->levels[this->present_level]
7734 ->neighbors[this->present_index * ReferenceCells::max_n_faces<dim>() +
7735 face_no]
7736 .second;
7737 }
7738
7739
7740
7741 template <int dim, int spacedim>
7742 inline int
7743 CellAccessor<dim, spacedim>::neighbor_level(const unsigned int face_no) const
7744 {
7745 AssertIndexRange(face_no, this->n_faces());
7746 return this->tria->levels[this->present_level]
7747 ->neighbors[this->present_index * ReferenceCells::max_n_faces<dim>() +
7748 face_no]
7749 .first;
7750 }
7751
7752
7753
7754 template <int dim, int spacedim>
7755 inline RefinementCase<dim>
7756 CellAccessor<dim, spacedim>::refine_flag_set() const
7757 {
7758 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
7759 // cells flagged for refinement must be active
7760 // (the @p set_refine_flag function checks this,
7761 // but activity may change when refinement is
7762 // executed and for some reason the refine
7763 // flag is not cleared).
7764 Assert(this->is_active() || !this->tria->levels[this->present_level]
7765 ->refine_flags[this->present_index],
7766 ExcRefineCellNotActive());
7767 return RefinementCase<dim>(
7768 this->tria->levels[this->present_level]->refine_flags[this->present_index]);
7769 }
7770
7771
7772
7773 template <int dim, int spacedim>
7774 inline void
7775 CellAccessor<dim, spacedim>::set_refine_flag(
7776 const RefinementCase<dim> refinement_case) const
7777 {
7778 Assert(this->used() && this->is_active(), ExcRefineCellNotActive());
7779 Assert(!coarsen_flag_set(), ExcCellFlaggedForCoarsening());
7780
7781 this->tria->levels[this->present_level]->refine_flags[this->present_index] =
7782 refinement_case;
7783 }
7784
7785
7786
7787 template <int dim, int spacedim>
7788 inline void
7789 CellAccessor<dim, spacedim>::clear_refine_flag() const
7790 {
7791 Assert(this->used() && this->is_active(), ExcRefineCellNotActive());
7792 this->tria->levels[this->present_level]->refine_flags[this->present_index] =
7793 RefinementCase<dim>::no_refinement;
7794 }
7795
7796
7797 template <int dim, int spacedim>
7798 inline std::uint8_t
7799 CellAccessor<dim, spacedim>::refine_choice() const
7800 {
7801 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
7802 if (this->tria->levels[this->present_level]->refine_choice.size() == 0)
7803 return 0U;
7804 return this->tria->levels[this->present_level]
7805 ->refine_choice[this->present_index];
7806 }
7807
7808
7809 template <int dim, int spacedim>
7810 inline void
7811 CellAccessor<dim, spacedim>::set_refine_choice(
7812 const std::uint8_t refinement_choice) const
7813 {
7814 Assert(this->used() && this->is_active(), ExcRefineCellNotActive());
7815 if (this->tria->levels[this->present_level]->refine_choice.size() != 0)
7816 this->tria->levels[this->present_level]
7817 ->refine_choice[this->present_index] = refinement_choice;
7818 }
7819
7820
7821 template <int dim, int spacedim>
7822 inline void
7823 CellAccessor<dim, spacedim>::clear_refine_choice() const
7824 {
7825 Assert(this->used() && this->is_active(), ExcRefineCellNotActive());
7826 if (this->tria->levels[this->present_level]->refine_choice.size() != 0)
7827 this->tria->levels[this->present_level]
7828 ->refine_choice[this->present_index] =
7829 static_cast<char>(IsotropicRefinementChoice::isotropic_refinement);
7830 }
7831
7832
7833 template <int dim, int spacedim>
7834 inline bool
7835 CellAccessor<dim, spacedim>::flag_for_face_refinement(
7836 const unsigned int face_no,
7837 const RefinementCase<dim - 1> &face_refinement_case) const
7838 {
7839 Assert(dim > 1, ExcImpossibleInDim(dim));
7840 AssertIndexRange(face_no, this->n_faces());
7841 AssertIndexRange(face_refinement_case,
7842 RefinementCase<dim>::isotropic_refinement + 1);
7843
7844 // the new refinement case is a combination
7845 // of the minimum required one for the given
7846 // face refinement and the already existing
7847 // flagged refinement case
7848 RefinementCase<dim> old_ref_case = refine_flag_set();
7849 RefinementCase<dim> new_ref_case =
7850 (old_ref_case |
7851 GeometryInfo<dim>::min_cell_refinement_case_for_face_refinement(
7852 face_refinement_case,
7853 face_no,
7854 this->face_orientation(face_no),
7855 this->face_flip(face_no),
7856 this->face_rotation(face_no)));
7857 set_refine_flag(new_ref_case);
7858 // return, whether we had to change the
7859 // refinement flag
7860 return new_ref_case != old_ref_case;
7861 }
7862
7863
7864
7865 template <int dim, int spacedim>
7866 inline bool
7867 CellAccessor<dim, spacedim>::flag_for_line_refinement(
7868 const unsigned int line_no) const
7869 {
7870 Assert(dim > 1, ExcImpossibleInDim(dim));
7871 AssertIndexRange(line_no, this->n_lines());
7872
7873 // the new refinement case is a combination
7874 // of the minimum required one for the given
7875 // line refinement and the already existing
7876 // flagged refinement case
7877 RefinementCase<dim>
7878 old_ref_case = refine_flag_set(),
7879 new_ref_case =
7880 old_ref_case |
7881 GeometryInfo<dim>::min_cell_refinement_case_for_line_refinement(line_no);
7882 set_refine_flag(new_ref_case);
7883 // return, whether we had to change the
7884 // refinement flag
7885 return new_ref_case != old_ref_case;
7886 }
7887
7888
7889
7890 template <int dim, int spacedim>
7891 inline internal::SubfaceCase<dim>
7892 CellAccessor<dim, spacedim>::subface_case(const unsigned int face_no) const
7893 {
7894 Assert(is_active(), TriaAccessorExceptions::ExcCellNotActive());
7895 AssertIndexRange(face_no, this->n_faces());
7896
7897 if constexpr (dim == 1)
7898 return internal::SubfaceCase<1>::case_none;
7899 else if constexpr (dim == 2)
7900 return ((face(face_no)->has_children()) ?
7901 internal::SubfaceCase<2>::case_x :
7902 internal::SubfaceCase<2>::case_none);
7903 else if constexpr (dim == 3)
7904 {
7905 switch (static_cast<std::uint8_t>(face(face_no)->refinement_case()))
7906 {
7907 case RefinementCase<3>::no_refinement:
7908 return internal::SubfaceCase<3>::case_none;
7909 case RefinementCase<3>::cut_x:
7910 if (face(face_no)->child(0)->has_children())
7911 {
7912 Assert(face(face_no)->child(0)->refinement_case() ==
7913 RefinementCase<2>::cut_y,
7914 ExcInternalError());
7915 if (face(face_no)->child(1)->has_children())
7916 {
7917 Assert(face(face_no)->child(1)->refinement_case() ==
7918 RefinementCase<2>::cut_y,
7919 ExcInternalError());
7920 return internal::SubfaceCase<3>::case_x1y2y;
7921 }
7922 else
7923 return internal::SubfaceCase<3>::case_x1y;
7924 }
7925 else
7926 {
7927 if (face(face_no)->child(1)->has_children())
7928 {
7929 Assert(face(face_no)->child(1)->refinement_case() ==
7930 RefinementCase<2>::cut_y,
7931 ExcInternalError());
7932 return internal::SubfaceCase<3>::case_x2y;
7933 }
7934 else
7935 return internal::SubfaceCase<3>::case_x;
7936 }
7937 case RefinementCase<3>::cut_y:
7938 if (face(face_no)->child(0)->has_children())
7939 {
7940 Assert(face(face_no)->child(0)->refinement_case() ==
7941 RefinementCase<2>::cut_x,
7942 ExcInternalError());
7943 if (face(face_no)->child(1)->has_children())
7944 {
7945 Assert(face(face_no)->child(1)->refinement_case() ==
7946 RefinementCase<2>::cut_x,
7947 ExcInternalError());
7948 return internal::SubfaceCase<3>::case_y1x2x;
7949 }
7950 else
7951 return internal::SubfaceCase<3>::case_y1x;
7952 }
7953 else
7954 {
7955 if (face(face_no)->child(1)->has_children())
7956 {
7957 Assert(face(face_no)->child(1)->refinement_case() ==
7958 RefinementCase<2>::cut_x,
7959 ExcInternalError());
7960 return internal::SubfaceCase<3>::case_y2x;
7961 }
7962 else
7963 return internal::SubfaceCase<3>::case_y;
7964 }
7965 case RefinementCase<3>::cut_xy:
7966 return internal::SubfaceCase<3>::case_xy;
7967 default:
7968 DEAL_II_ASSERT_UNREACHABLE();
7969 }
7970 }
7971
7972 // we should never get here
7973 DEAL_II_ASSERT_UNREACHABLE();
7974 return internal::SubfaceCase<dim>::case_none;
7975 }
7976
7977
7978
7979 template <int dim, int spacedim>
7980 inline bool
7981 CellAccessor<dim, spacedim>::coarsen_flag_set() const
7982 {
7983 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
7984 // cells flagged for coarsening must be active
7985 // (the @p set_refine_flag function checks this,
7986 // but activity may change when refinement is
7987 // executed and for some reason the refine
7988 // flag is not cleared).
7989 Assert(this->is_active() || !this->tria->levels[this->present_level]
7990 ->coarsen_flags[this->present_index],
7991 ExcRefineCellNotActive());
7992 return this->tria->levels[this->present_level]
7993 ->coarsen_flags[this->present_index];
7994 }
7995
7996
7997
7998 template <int dim, int spacedim>
7999 inline void
8000 CellAccessor<dim, spacedim>::set_coarsen_flag() const
8001 {
8002 Assert(this->used() && this->is_active(), ExcRefineCellNotActive());
8003 Assert(!refine_flag_set(), ExcCellFlaggedForRefinement());
8004
8005 this->tria->levels[this->present_level]->coarsen_flags[this->present_index] =
8006 true;
8007 }
8008
8009
8010
8011 template <int dim, int spacedim>
8012 inline void
8013 CellAccessor<dim, spacedim>::clear_coarsen_flag() const
8014 {
8015 Assert(this->used() && this->is_active(), ExcRefineCellNotActive());
8016 this->tria->levels[this->present_level]->coarsen_flags[this->present_index] =
8017 false;
8018 }
8019
8020
8021
8022 template <int dim, int spacedim>
8023 inline TriaIterator<CellAccessor<dim, spacedim>>
8024 CellAccessor<dim, spacedim>::neighbor(const unsigned int face_no) const
8025 {
8026 TriaIterator<CellAccessor<dim, spacedim>> q(this->tria,
8027 neighbor_level(face_no),
8028 neighbor_index(face_no));
8029
8030 Assert((q.state() == IteratorState::past_the_end) || q->used(),
8031 ExcInternalError());
8032
8033 return q;
8034 }
8035
8036
8037
8038 template <int dim, int spacedim>
8039 inline bool
8040 CellAccessor<dim, spacedim>::is_active() const
8041 {
8042 return !this->has_children();
8043 }
8044
8045
8046
8047 template <int dim, int spacedim>
8048 inline bool
8049 CellAccessor<dim, spacedim>::is_locally_owned() const
8050 {
8051 Assert(this->is_active(),
8052 ExcMessage("is_locally_owned() can only be called on active cells!"));
8053 # ifndef DEAL_II_WITH_MPI
8054 return true;
8055 # else
8056
8057 // Serial triangulations report invalid_subdomain_id as their locally owned
8058 // subdomain, so the first condition checks whether we have a serial
8059 // triangulation, in which case all cells are locally owned. The second
8060 // condition compares the subdomain id in the parallel case.
8061 const types::subdomain_id locally_owned_subdomain =
8062 this->tria->locally_owned_subdomain();
8063 return (locally_owned_subdomain == numbers::invalid_subdomain_id ||
8064 this->subdomain_id() == locally_owned_subdomain);
8065
8066 # endif
8067 }
8068
8069
8070 template <int dim, int spacedim>
8071 inline bool
8072 CellAccessor<dim, spacedim>::is_locally_owned_on_level() const
8073 {
8074 # ifndef DEAL_II_WITH_MPI
8075 return true;
8076 # else
8077
8078 // Serial triangulations report invalid_subdomain_id as their locally owned
8079 // subdomain, so the first condition checks whether we have a serial
8080 // triangulation, in which case all cells are locally owned. The second
8081 // condition compares the subdomain id in the parallel case.
8082 const types::subdomain_id locally_owned_subdomain =
8083 this->tria->locally_owned_subdomain();
8084 return (locally_owned_subdomain == numbers::invalid_subdomain_id ||
8085 this->level_subdomain_id() == locally_owned_subdomain);
8086
8087 # endif
8088 }
8089
8090
8091 template <int dim, int spacedim>
8092 inline bool
8093 CellAccessor<dim, spacedim>::is_ghost() const
8094 {
8095 Assert(this->is_active(),
8096 ExcMessage("is_ghost() can only be called on active cells!"));
8097 if (this->has_children())
8098 return false;
8099
8100 # ifndef DEAL_II_WITH_MPI
8101 return false;
8102 # else
8103
8104 // Serial triangulations report invalid_subdomain_id as their locally owned
8105 // subdomain, so the first condition rules out that case as all cells to a
8106 // serial triangulation are locally owned and none is ghosted. The second
8107 // and third conditions check whether the cell's subdomain is not the
8108 // locally owned one and not artificial.
8109 const types::subdomain_id locally_owned_subdomain =
8110 this->tria->locally_owned_subdomain();
8111 const types::subdomain_id subdomain_id = this->subdomain_id();
8112 return (locally_owned_subdomain != numbers::invalid_subdomain_id &&
8113 subdomain_id != locally_owned_subdomain &&
8114 subdomain_id != numbers::artificial_subdomain_id);
8115
8116 # endif
8117 }
8118
8119
8120 template <int dim, int spacedim>
8121 inline bool
8122 CellAccessor<dim, spacedim>::is_ghost_on_level() const
8123 {
8124 # ifndef DEAL_II_WITH_MPI
8125 return false;
8126 # else
8127
8128 // Serial triangulations report invalid_subdomain_id as their locally owned
8129 // subdomain, so the first condition checks whether we have a serial
8130 // triangulation, in which case all cells are locally owned. The second
8131 // condition compares the subdomain id in the parallel case.
8132 const types::subdomain_id locally_owned_subdomain =
8133 this->tria->locally_owned_subdomain();
8134 const types::subdomain_id subdomain_id = this->level_subdomain_id();
8135 return (locally_owned_subdomain != numbers::invalid_subdomain_id &&
8136 subdomain_id != locally_owned_subdomain &&
8137 subdomain_id != numbers::artificial_subdomain_id);
8138
8139 # endif
8140 }
8141
8142
8143
8144 template <int dim, int spacedim>
8145 inline bool
8146 CellAccessor<dim, spacedim>::is_artificial() const
8147 {
8148 Assert(this->is_active(),
8149 ExcMessage("is_artificial() can only be called on active cells!"));
8150 # ifndef DEAL_II_WITH_MPI
8151 return false;
8152 # else
8153
8154 // Serial triangulations report invalid_subdomain_id as their locally owned
8155 // subdomain, so the first condition rules out that case as all cells to a
8156 // serial triangulation are locally owned and none is artificial.
8157 return (this->tria->locally_owned_subdomain() !=
8158 numbers::invalid_subdomain_id &&
8159 this->subdomain_id() == numbers::artificial_subdomain_id);
8160
8161 # endif
8162 }
8163
8164
8165
8166 template <int dim, int spacedim>
8167 inline bool
8168 CellAccessor<dim, spacedim>::is_artificial_on_level() const
8169 {
8170 # ifndef DEAL_II_WITH_MPI
8171 return false;
8172 # else
8173 return (this->tria->locally_owned_subdomain() !=
8174 numbers::invalid_subdomain_id &&
8175 this->level_subdomain_id() == numbers::artificial_subdomain_id);
8176 # endif
8177 }
8178
8179
8180
8181 template <int dim, int spacedim>
8182 inline types::subdomain_id
8183 CellAccessor<dim, spacedim>::subdomain_id() const
8184 {
8185 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
8186 Assert(this->is_active(),
8187 ExcMessage("subdomain_id() can only be called on active cells!"));
8188 return this->tria->levels[this->present_level]
8189 ->subdomain_ids[this->present_index];
8190 }
8191
8192
8193
8194 template <int dim, int spacedim>
8195 inline types::subdomain_id
8196 CellAccessor<dim, spacedim>::level_subdomain_id() const
8197 {
8198 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
8199 return this->tria->levels[this->present_level]
8200 ->level_subdomain_ids[this->present_index];
8201 }
8202
8203
8204
8205 template <int dim, int spacedim>
8206 inline unsigned int
8207 CellAccessor<dim, spacedim>::neighbor_face_no(const unsigned int neighbor) const
8208 {
8209 const unsigned int n2 = neighbor_of_neighbor_internal(neighbor);
8210 if (n2 != numbers::invalid_unsigned_int)
8211 // return this value as the
8212 // neighbor is not coarser
8213 return n2;
8214 else
8215 // the neighbor is coarser
8216 return neighbor_of_coarser_neighbor(neighbor).first;
8217 }
8218
8219
8220
8221 template <int dim, int spacedim>
8222 inline bool
8223 CellAccessor<dim, spacedim>::is_level_cell()
8224 {
8225 return false;
8226 }
8227
8228
8229
8230 template <int dim, int spacedim>
8231 inline unsigned int
8232 CellAccessor<dim, spacedim>::active_cell_index() const
8233 {
8234 Assert(this->is_active(), TriaAccessorExceptions::ExcCellNotActive());
8235 return this->tria->levels[this->present_level]
8236 ->active_cell_indices[this->present_index];
8237 }
8238
8239
8240
8241 template <int dim, int spacedim>
8242 inline types::global_cell_index
8243 CellAccessor<dim, spacedim>::global_active_cell_index() const
8244 {
8245 Assert(this->used(), TriaAccessorExceptions::ExcCellNotUsed());
8246 Assert(this->is_active(),
8247 ExcMessage(
8248 "global_active_cell_index() can only be called on active cells!"));
8249
8250 return this->tria->levels[this->present_level]
8251 ->global_active_cell_indices[this->present_index];
8252 }
8253
8254
8255
8256 template <int dim, int spacedim>
8257 inline types::global_cell_index
8258 CellAccessor<dim, spacedim>::global_level_cell_index() const
8259 {
8260 return this->tria->levels[this->present_level]
8261 ->global_level_cell_indices[this->present_index];
8262 }
8263
8264 #endif // DOXYGEN
8265
8266 DEAL_II_NAMESPACE_CLOSE
8267
8268
8269 #endif