Debian Codegraph @

include/deal.II/non_matching/fe_values.h

raw
1 // ------------------------------------------------------------------------
2 //
3 // SPDX-License-Identifier: LGPL-2.1-or-later
4 // Copyright (C) 2021 - 2024 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_non_matching_fe_values
16 #define dealii_non_matching_fe_values
17
18 #include <deal.II/base/bounding_box.h>
19 #include <deal.II/base/observer_pointer.h>
20
21 #include <deal.II/dofs/dof_handler.h>
22
23 #include <deal.II/fe/fe_interface_values.h>
24 #include <deal.II/fe/fe_update_flags.h>
25 #include <deal.II/fe/fe_values.h>
26
27 #include <deal.II/grid/tria_iterator.h>
28
29 #include <deal.II/hp/fe_collection.h>
30 #include <deal.II/hp/mapping_collection.h>
31 #include <deal.II/hp/q_collection.h>
32
33 #include <deal.II/non_matching/fe_immersed_values.h>
34 #include <deal.II/non_matching/mesh_classifier.h>
35 #include <deal.II/non_matching/quadrature_generator.h>
36
37 #include <deque>
38 #include <optional>
39
40 DEAL_II_NAMESPACE_OPEN
41
42 namespace NonMatching
43 {
44 /**
45 * Struct storing UpdateFlags for the 3 regions of a cell, $K$, that is
46 * defined by the sign of a level set function, $\psi$:
47 * @f[
48 * N = \{x \in K : \psi(x) < 0 \}, \\
49 * P = \{x \in K : \psi(x) > 0 \}, \\
50 * S = \{x \in K : \psi(x) = 0 \}.
51 * @f]
52 * As in the QuadratureGenerator class, we refer to $N$, $P$ and $S$ as the
53 * inside, outside, and surface region. RegionUpdateFlags is used to describe
54 * how the FEValues objects, which are created by NonMatching::FEValues,
55 * should be updated.
56 */
57 struct RegionUpdateFlags
58 {
59 /**
60 * Constructor, sets the UpdateFlags for each region to update_default.
61 */
62 RegionUpdateFlags();
63
64 /**
65 * Flags for the region $\{x \in K : \psi(x) < 0 \}$
66 */
67 UpdateFlags inside;
68
69 /**
70 * Flags for the region $\{x \in K : \psi(x) > 0 \}$
71 */
72 UpdateFlags outside;
73
74 /**
75 * Flags for the region $\{x \in K : \psi(x) = 0 \}$
76 */
77 UpdateFlags surface;
78 };
79
80
81 /**
82 * This class is intended to facilitate assembling in immersed (in the sense
83 * of cut) finite element methods when the domain is described by a level set
84 * function, $\psi : \mathbb{R}^{dim} \to \mathbb{R}$. In this type of
85 * method, we typically need to integrate over 3 different regions of each
86 * cell, $K$:
87 * @f[
88 * N = \{x \in K : \psi(x) < 0 \}, \\
89 * P = \{x \in K : \psi(x) > 0 \}, \\
90 * S = \{x \in K : \psi(x) = 0 \}.
91 * @f]
92 * Thus we need quadrature rules for these 3 regions:
93 * @image html immersed_quadratures.svg
94 * As in the QuadratureGenerator class, we refer to $N$, $P$, and $S$ as the
95 * inside, outside, and surface regions. The constructor of this class takes a
96 * discrete level set function described by a DoFHandler and a Vector. When
97 * the reinit() function is called, the QuadratureGenerator will be called in
98 * the background to create these immersed quadrature rules. This class then
99 * creates dealii::FEValues objects for the inside/outside regions and an
100 * FEImmersedSurfaceValues object for the surface region. These objects can
101 * then be accessed through one of the functions: get_inside_fe_values(),
102 * get_outside_fe_values(), or
103 * get_surface_fe_values().
104 * Since a cut between a cell and the domain can be arbitrarily small, the
105 * underlying algorithm may generate a quadrature rule with 0 points. This
106 * can, for example, happen if the relative size of the cut is similar to the
107 * floating-point accuracy. Since the FEValues-like objects are not allowed to
108 * contain 0 points, the object that get_inside/outside/surface_fe_values()
109 * returns is wrapped in a std::optional. This requires us to check if
110 * the returned FEValues-like object contains a value before we use it:
111 * @code
112 * NonMatching::FEValues<dim> fe_values(...);
113 *
114 * for (const auto &cell : dof_handler.active_cell_iterators())
115 * {
116 * fe_values.reinit(cell);
117 *
118 * const std::optional<FEValues<dim>> &fe_values_inside =
119 * fe_values.get_inside_fe_values();
120 *
121 * if (fe_values_inside)
122 * {
123 * // Assemble locally
124 * for (const unsigned int q_index :
125 * fe_values_inside->quadrature_point_indices())
126 * {
127 * // ...
128 * }
129 * }
130 * }
131 * @endcode
132 *
133 * Of course, it is somewhat expensive to generate the immersed quadrature
134 * rules and create FEValues objects with the generated quadratures. To reduce
135 * the amount of work, the reinit() function of this class uses the
136 * MeshClassifier passed to the constructor to check how the incoming cell
137 * relates to the level set function. It only generates the immersed
138 * quadrature rules if the cell is intersected. If the cell is completely
139 * inside or outside, it returns a cached FEValues object created with a
140 * quadrature over the reference cell: $[0, 1]^{dim}$.
141 */
142 template <int dim>
143 class FEValues
144 {
145 public:
146 using AdditionalData = typename QuadratureGenerator<dim>::AdditionalData;
147
148 /**
149 * Constructor.
150 *
151 * @param fe_collection Collection of FiniteElements to be used.
152 * @param quadrature 1-dimensional quadrature rule used to generate the
153 * immersed quadrature rules. See the QuadratureGenerator class. On the non
154 * intersected elements a tensor product of this quadrature will be used.
155 * @param mesh_classifier Object used to determine when the immersed
156 * quadrature rules need to be generated.
157 * @param region_update_flags Struct storing UpdateFlags for the
158 * inside/outside/surface region of the cell.
159 * @param dof_handler The DoFHandler associated with the discrete level set
160 * function.
161 * @param level_set The degrees of freedom of the discrete level set function.
162 * @param additional_data Additional data passed to the QuadratureGenerator
163 * class.
164 *
165 * @note Pointers to @p fe_collection, @p mesh_classifier, @p dof_handler,
166 * and @p level_set are stored internally, so these need to have a longer life
167 * span than the instance of this class.
168 */
169 template <typename Number>
170 FEValues(const hp::FECollection<dim> &fe_collection,
171 const Quadrature<1> &quadrature,
172 const RegionUpdateFlags region_update_flags,
173 const MeshClassifier<dim> &mesh_classifier,
174 const DoFHandler<dim> &dof_handler,
175 const ReadVector<Number> &level_set,
176 const AdditionalData &additional_data = AdditionalData());
177
178 /**
179 * Constructor.
180 *
181 * @param mapping_collection Collection of Mappings to be used.
182 * @param fe_collection Collection of FiniteElements to be used.
183 * @param q_collection Collection of Quadrature rules over $[0, 1]^{dim}$
184 * that should be used when a cell is not intersected and we do not need to
185 * generate immersed quadrature rules.
186 * @param q_collection_1d Collection of 1-dimensional quadrature rules used
187 * to generate the immersed quadrature rules. See the QuadratureGenerator
188 * class.
189 * @param mesh_classifier Object used to determine when the immersed
190 * quadrature rules need to be generated.
191 * @param region_update_flags Struct storing UpdateFlags for the
192 * inside/outside/surface region of the cell.
193 * @param dof_handler The DoFHandler associated with the discrete level set
194 * function.
195 * @param level_set The degrees of freedom of the discrete level set function.
196 * @param additional_data Additional data passed to the QuadratureGenerator
197 * class.
198 *
199 * @note Pointers to @p mapping_collection, @p fe_collection,
200 * @p mesh_classifier, @p dof_handler, and @p level_set are stored
201 * internally, so these need to have a longer life span than the instance of
202 * this class.
203 */
204 template <typename Number>
205 FEValues(const hp::MappingCollection<dim> &mapping_collection,
206 const hp::FECollection<dim> &fe_collection,
207 const hp::QCollection<dim> &q_collection,
208 const hp::QCollection<1> &q_collection_1d,
209 const RegionUpdateFlags region_update_flags,
210 const MeshClassifier<dim> &mesh_classifier,
211 const DoFHandler<dim> &dof_handler,
212 const ReadVector<Number> &level_set,
213 const AdditionalData &additional_data = AdditionalData());
214
215 /**
216 * Reinitialize the various FEValues-like objects for the 3 different
217 * regions of the cell. After calling this function an FEValues-like object
218 * can be retrieved for each region using the functions
219 * get_inside_fe_values(), get_outside_fe_values(), or
220 * get_surface_fe_values().
221 *
222 * If the @p q_index argument is left at its default value, then we use
223 * that quadrature formula within the hp::QCollection passed to the
224 * constructor of this class with index given by
225 * <code>cell-@>active_fe_index()</code>, i.e. the same index as that of
226 * the finite element. In this case, there should be a corresponding
227 * quadrature formula for each finite element in the hp::FECollection. As
228 * a special case, if the quadrature collection contains only a single
229 * element (a frequent case if one wants to use the same quadrature object
230 * for all finite elements in an hp-discretization, even if that may not
231 * be the most efficient), then this single quadrature is used unless a
232 * different value for this argument is specified. On the other hand, if a
233 * value is given for this argument, it overrides the choice of
234 * <code>cell-@>active_fe_index()</code> or the choice for the single
235 * quadrature.
236 *
237 * If the @p mapping_index argument is left at its default value, then we
238 * use that mapping object within the hp::MappingCollection passed to the
239 * constructor of this class with index given by
240 * <code>cell-@>active_fe_index()</code>, i.e. the same index as that of
241 * the finite element. As above, if the mapping collection contains only a
242 * single element (a frequent case if one wants to use a $Q_1$ mapping for
243 * all finite elements in an hp-discretization), then this single mapping
244 * is used unless a different value for this argument is specified.
245 */
246 template <bool level_dof_access>
247 void
248 reinit(
249 const TriaIterator<DoFCellAccessor<dim, dim, level_dof_access>> &cell,
250 const unsigned int q_index = numbers::invalid_unsigned_int,
251 const unsigned int mapping_index = numbers::invalid_unsigned_int);
252
253 /**
254 * Like the previous function, but for non-DoFHandler iterators. The reason
255 * this function exists is so that one can use NonMatching::FEValues for
256 * Triangulation objects too.
257 *
258 * Since <code>cell-@>active_fe_index()</code> doesn't make sense for
259 * triangulation iterators, this function chooses the zero-th finite
260 * element, mapping, and quadrature object from the relevant constructions
261 * passed to the constructor of this object. The only exception is if you
262 * specify a value different from the default value for any of these last
263 * three arguments.
264 */
265 void
266 reinit(const TriaIterator<CellAccessor<dim, dim>> &cell,
267 const unsigned int q_index = numbers::invalid_unsigned_int,
268 const unsigned int mapping_index = numbers::invalid_unsigned_int,
269 const unsigned int fe_index = numbers::invalid_unsigned_int);
270
271 /**
272 * Return an dealii::FEValues object reinitialized with a quadrature for the
273 * inside region of the cell: $\{x \in K : \psi(x) < 0 \}$.
274 *
275 * @note If the quadrature rule over the region is empty, e.g. because the
276 * cell is completely located in the outside domain, the returned
277 * optional will not contain a value.
278 */
279 const std::optional<dealii::FEValues<dim>> &
280 get_inside_fe_values() const;
281
282 /**
283 * Return an dealii::FEValues object reinitialized with a quadrature for the
284 * outside region of the cell: $\{x \in K : \psi(x) > 0 \}$.
285 *
286 * @note If the quadrature rule over the region is empty, e.g. because the
287 * cell is completely located in the inside domain, the returned
288 * optional will not contain a value.
289 */
290 const std::optional<dealii::FEValues<dim>> &
291 get_outside_fe_values() const;
292
293 /**
294 * Return an dealii::FEValues object reinitialized with a quadrature for the
295 * surface region of the cell: $\{x \in K : \psi(x) = 0 \}$.
296 *
297 * @note If the quadrature rule over the region is empty, e.g. because the
298 * cell is not intersected, the returned optional will not contain a value.
299 */
300 const std::optional<FEImmersedSurfaceValues<dim>> &
301 get_surface_fe_values() const;
302
303 private:
304 /**
305 * Internal function called by the reinit() functions.
306 */
307 template <typename CellIteratorType>
308 void
309 reinit_internal(const CellIteratorType &cell,
310 const unsigned int q_index,
311 const unsigned int mapping_index,
312 const unsigned int fe_index);
313
314 /**
315 * Do work common to the constructors. The incoming QCollection should be
316 * quadratures integrating over $[0, 1]^{dim}$. These will be used on the
317 * non-intersected cells.
318 */
319 void
320 initialize(const hp::QCollection<dim> &q_collection);
321
322 /**
323 * A pointer to the collection of mappings to be used.
324 */
325 const ObserverPointer<const hp::MappingCollection<dim>> mapping_collection;
326
327 /**
328 * A pointer to the collection of finite elements to be used.
329 */
330 const ObserverPointer<const hp::FECollection<dim>> fe_collection;
331
332 /**
333 * Collection of 1-dimensional quadrature rules that are used by
334 * QuadratureGenerator as base for generating the immersed quadrature rules.
335 */
336 const hp::QCollection<1> q_collection_1D;
337
338 /**
339 * Location of the last cell that reinit was called with.
340 */
341 LocationToLevelSet current_cell_location;
342
343 /**
344 * Active fe index of the last cell that reinit was called with.
345 */
346 unsigned int active_fe_index;
347
348 /**
349 * The update flags passed to the constructor.
350 */
351 const RegionUpdateFlags region_update_flags;
352
353 /**
354 * Pointer to the MeshClassifier passed to the constructor.
355 */
356 const ObserverPointer<const MeshClassifier<dim>> mesh_classifier;
357
358 /**
359 * For each element in the FECollection passed to the constructor,
360 * this object contains an dealii::FEValues object created with a quadrature
361 * rule over the full reference cell: $[0, 1]^{dim}$ and UpdateFlags for the
362 * inside region. Thus, these optionals should always contain a value.
363 *
364 * When LocationToLevelSet of the cell is INSIDE (and we do not need
365 * to generate an immersed quadrature), we return the dealii::FEValues
366 * object in this container corresponding to the cell's active_fe_index.
367 *
368 * This container is a std::deque, which is compatible with the `FEValues`
369 * class that does not have a copy-constructor.
370 */
371 std::deque<std::optional<dealii::FEValues<dim>>>
372 fe_values_inside_full_quadrature;
373
374 /**
375 * For each element in the FECollection passed to the constructor,
376 * this object contains an dealii::FEValues object created with a quadrature
377 * rule over the full reference cell: $[0, 1]^{dim}$ and UpdateFlags for the
378 * outside region. Thus, these optionals should always contain a value.
379 *
380 * When LocationToLevelSet of the cell is OUTSIDE (and we do not need
381 * to generate an immersed quadrature), we return the dealii::FEValues
382 * object in this container corresponding to the cell's active_fe_index.
383 *
384 * This container is a std::deque, which is compatible with the `FEValues`
385 * class that does not have a copy-constructor.
386 */
387 std::deque<std::optional<dealii::FEValues<dim>>>
388 fe_values_outside_full_quadrature;
389
390 /**
391 * FEValues object created with a quadrature rule integrating over the
392 * inside region, $\{x \in B : \psi(x) < 0 \}$, that was generated in the
393 * last call to reinit(..). If the cell in the last call was not intersected
394 * or if 0 quadrature points were generated, this optional will not contain
395 * a value.
396 */
397 std::optional<dealii::FEValues<dim>> fe_values_inside;
398
399 /**
400 * FEValues object created with a quadrature rule integrating over the
401 * outside region, $\{x \in B : \psi(x) > 0 \}$, that was generated in the
402 * last call to reinit(..). If the cell in the last call was not intersected
403 * or if 0 quadrature points were generated, this optional will not contain
404 * a value.
405 */
406 std::optional<dealii::FEValues<dim>> fe_values_outside;
407
408 /**
409 * FEImmersedSurfaceValues object created with a quadrature rule integrating
410 * over the surface region, $\{x \in B : \psi(x) = 0 \}$, that was generated
411 * in the last call to reinit(..). If the cell in the last call was not
412 * intersected or if 0 quadrature points were generated, this optional will
413 * not contain a value.
414 */
415 std::optional<NonMatching::FEImmersedSurfaceValues<dim>> fe_values_surface;
416
417 /**
418 * Object that generates the immersed quadrature rules.
419 */
420 DiscreteQuadratureGenerator<dim> quadrature_generator;
421 };
422
423
424
425 /**
426 * This class is intended to facilitate assembling interface terms on faces in
427 * immersed (in the sense of cut) finite element methods. These types of terms
428 * occur mainly in cut discontinuous Galerkin methods. This class works
429 * analogously to NonMatching::FEValues. The domain is assumed to be described
430 * by a level set function,
431 * $\psi : \mathbb{R}^{dim} \to \mathbb{R}$,
432 * and this class assumes that we want to integrate over two different regions
433 * of each face, $F$:
434 * @f[
435 * N = \{x \in F : \psi(x) < 0 \}, \\
436 * P = \{x \in F : \psi(x) > 0 \},
437 * @f]
438 * which we as before refer to as the "inside" and "outside" regions of the
439 * face.
440 * @image html non_matching_fe_interface_values.svg
441 * When calling one of the reinit functions of this class, this class
442 * will create quadrature rules over these regions in the background and set
443 * up dealii::FEInterfaceValues objects with these quadratures. These objects
444 * can then be accessed through one of the functions: get_inside_fe_values()
445 * or get_outside_fe_values(). For the same reason as described in
446 * NonMatching::FEValues, the returned the FEInterfaceValues objects that
447 * get_inside/outside_fe_values() returns is wrapped in a
448 * std::optional. Assembling using this class would then typically be
449 * done in the following way:
450 *
451 * @code
452 * NonMatching::FEInterfaceValues<dim> fe_interface_values(...)
453 *
454 * for (const auto &cell : dof_handler.active_cell_iterators())
455 * {
456 * for (const unsigned int face_index : cell->face_indices())
457 * {
458 * if (cell->at_boundary(face_index))
459 * fe_interface_values.reinit(cell, face_index);
460 * else
461 * fe_interface_values.reinit(cell,
462 * face_index,
463 * subface_index,
464 * cell->neighbor(face_index),
465 * cell->neighbor_of_neighbor(face_index),
466 * neighbor_subface_index);
467 *
468 * const std::optional<dealii::FEInterfaceValues<dim>>
469 * &inside_fe_values = fe_interface_values.get_inside_fe_values();
470 *
471 * // Check if the returned optional contains a value
472 * if (inside_fe_values)
473 * {
474 * // Assemble locally
475 * }
476 * }
477 * }
478 * @endcode
479 *
480 * To reduce the amount of work, the reinit() function of this class uses the
481 * MeshClassifier passed to the constructor to check how the incoming cell
482 * relates to the level set function. The immersed quadrature rules are only
483 * generated if the cell is intersected. If the cell is completely inside or
484 * outside, it returns a cached FEInterfaceValues object created with a
485 * quadrature over the reference cell: $[0, 1]^{dim-1}$.
486 */
487 template <int dim>
488 class FEInterfaceValues
489 {
490 public:
491 using AdditionalData =
492 typename FaceQuadratureGenerator<dim>::AdditionalData;
493
494 /**
495 * Constructor.
496 *
497 * @param fe_collection Collection of FiniteElements to be used.
498 * @param quadrature 1-dimensional quadrature rule used to generate the
499 * immersed quadrature rules. See the QuadratureGenerator class. On the non
500 * intersected faces a tensor product of this quadrature will be used.
501 * @param mesh_classifier Object used to determine when the immersed
502 * quadrature rules need to be generated.
503 * @param region_update_flags Struct storing UpdateFlags for the
504 * inside/outside region of the cell.
505 * @param dof_handler The DoFHandler associated with the discrete level set
506 * function.
507 * @param level_set The degrees of freedom of the discrete level set function.
508 * @param additional_data Additional data passed to the QuadratureGenerator
509 * class.
510 *
511 * @note Pointers to @p fe_collection, @p mesh_classifier, @p dof_handler,
512 * and @p level_set are stored internally, so these need to have a longer life
513 * span than the instance of this class.
514 */
515 template <typename Number>
516 FEInterfaceValues(const hp::FECollection<dim> &fe_collection,
517 const Quadrature<1> &quadrature,
518 const RegionUpdateFlags region_update_flags,
519 const MeshClassifier<dim> &mesh_classifier,
520 const DoFHandler<dim> &dof_handler,
521 const ReadVector<Number> &level_set,
522 const AdditionalData &additional_data = AdditionalData());
523
524 /**
525 * Constructor.
526 *
527 * @param mapping_collection Collection of Mappings to be used.
528 * @param fe_collection Collection of FiniteElements to be used.
529 * @param q_collection Collection of Quadrature rules over $[0, 1]^{dim-1}$
530 * that should be used when a face is not intersected and we do not need to
531 * generate immersed quadrature rules.
532 * @param q_collection_1d Collection of 1-dimensional quadrature rules used
533 * to generate the immersed quadrature rules. See the QuadratureGenerator
534 * class.
535 * @param mesh_classifier Object used to determine when the immersed
536 * quadrature rules need to be generated.
537 * @param region_update_flags Struct storing UpdateFlags for the
538 * inside/outside region of the cell.
539 * @param dof_handler The DoFHandler associated with the discrete level set
540 * function.
541 * @param level_set The degrees of freedom of the discrete level set function.
542 * @param additional_data Additional data passed to the QuadratureGenerator
543 * class.
544 *
545 * @note Pointers to @p mapping_collection, @p fe_collection,
546 * @p mesh_classifier, @p dof_handler, and @p level_set are stored
547 * internally, so these need to have a longer life span than the instance of
548 * this class.
549 */
550 template <typename Number>
551 FEInterfaceValues(const hp::MappingCollection<dim> &mapping_collection,
552 const hp::FECollection<dim> &fe_collection,
553 const hp::QCollection<dim - 1> &q_collection,
554 const hp::QCollection<1> &q_collection_1d,
555 const RegionUpdateFlags region_update_flags,
556 const MeshClassifier<dim> &mesh_classifier,
557 const DoFHandler<dim> &dof_handler,
558 const ReadVector<Number> &level_set,
559 const AdditionalData &additional_data = AdditionalData());
560
561 /**
562 * Reinitialize on the shared face between two neighboring cells.
563 * After calling this function, an FEInterfaceValues object can be retrieved
564 * for each region using the functions get_inside_fe_values() or
565 * get_outside_fe_values().
566 *
567 * @note Currently @p cell and @p cell_neighbor need to have the same
568 * finite element associated with them.
569 *
570 * @note Specifying sub_face_no/sub_face_no_neighbor is currently not
571 * implemented, the passed values of these must equal
572 * numbers::invalid_unsigned_int.
573 */
574 template <typename CellIteratorType, typename CellNeighborIteratorType>
575 void
576 reinit(const CellIteratorType &cell,
577 const unsigned int face_no,
578 const unsigned int sub_face_no,
579 const CellNeighborIteratorType &cell_neighbor,
580 const unsigned int face_no_neighbor,
581 const unsigned int sub_face_no_neighbor,
582 const unsigned int q_index = numbers::invalid_unsigned_int,
583 const unsigned int mapping_index = numbers::invalid_unsigned_int,
584 const unsigned int fe_index = numbers::invalid_unsigned_int);
585
586
587 /**
588 * Reinitialize on a face on the boundary of the domain,
589 * when there is no neighbor and a single face @p face_no of
590 * the @p cell. After calling this function, an
591 * FEInterfaceValues object can be retrieved for each region using the
592 * functions get_inside_fe_values() or get_outside_fe_values().
593 */
594 template <typename CellIteratorType>
595 void
596 reinit(const CellIteratorType &cell,
597 const unsigned int face_no,
598 const unsigned int q_index = numbers::invalid_unsigned_int,
599 const unsigned int mapping_index = numbers::invalid_unsigned_int,
600 const unsigned int fe_index = numbers::invalid_unsigned_int);
601
602 /**
603 * Return an dealii::FEInterfaceValues object reinitialized with a
604 * quadrature for the inside region of the cell:
605 * $\{x \in K : \psi(x) < 0 \}$.
606 *
607 * @note If the quadrature rule over the region is empty, e.g. because the
608 * cell is completely located in the outside domain, the returned
609 * optional will not contain a value.
610 */
611 const std::optional<dealii::FEInterfaceValues<dim>> &
612 get_inside_fe_values() const;
613
614 /**
615 * Return an dealii::FEInterfaceValues object reinitialized with a
616 * quadrature for the outside region of the cell:
617 * $\{x \in K : \psi(x) > 0 \}$.
618 *
619 * @note If the quadrature rule over the region is empty, e.g. because the
620 * cell is completely located in the inside domain, the returned
621 * optional will not contain a value.
622 */
623 const std::optional<dealii::FEInterfaceValues<dim>> &
624 get_outside_fe_values() const;
625
626 private:
627 /**
628 * Do work common to the constructors. The incoming QCollection should be
629 * quadratures integrating over $[0, 1]^{dim-1}$. These will be used on the
630 * non-intersected cells.
631 */
632 void
633 initialize(const hp::QCollection<dim - 1> &q_collection);
634
635 /**
636 * Do work that is common two the two reinit functions of the class.
637 * @p call_reinit is a std::function that describes how we should call
638 * reinit on a single dealii::FEInterfaceValues object, which is what
639 * differs between the two reinit functions.
640 */
641 template <typename CellAccessorType>
642 void
643 do_reinit(const TriaIterator<CellAccessorType> &cell,
644 const unsigned int face_no,
645 const unsigned int q_index,
646 const unsigned int active_fe_index,
647 const std::function<void(dealii::FEInterfaceValues<dim> &,
648 const unsigned int)> &call_reinit);
649
650 /**
651 * A pointer to the collection of mappings to be used.
652 */
653 const ObserverPointer<const hp::MappingCollection<dim>> mapping_collection;
654
655 /**
656 * A pointer to the collection of finite elements to be used.
657 */
658 const ObserverPointer<const hp::FECollection<dim>> fe_collection;
659
660 /**
661 * Collection of 1-dimensional quadrature rules that are used by
662 * QuadratureGenerator as base for generating the immersed quadrature rules.
663 */
664 const hp::QCollection<1> q_collection_1D;
665
666 /**
667 * Location of the last face that reinit was called with.
668 */
669 LocationToLevelSet current_face_location;
670
671 /**
672 * The update flags passed to the constructor.
673 */
674 const RegionUpdateFlags region_update_flags;
675
676 /**
677 * Pointer to the MeshClassifier passed to the constructor.
678 */
679 const ObserverPointer<const MeshClassifier<dim>> mesh_classifier;
680
681 /**
682 * FEInterfaceValues corresponding to cells with LocationToLevelSet
683 * INSIDE (not needed to generate an immersed quadrature).
684 */
685 std::optional<dealii::FEInterfaceValues<dim>>
686 fe_values_inside_full_quadrature;
687
688 /**
689 * FEInterfaceValues corresponding to cells with LocationToLevelSet
690 * OUTSIDE (not needed to generate an immersed quadrature).
691 */
692 std::optional<dealii::FEInterfaceValues<dim>>
693 fe_values_outside_full_quadrature;
694
695 /**
696 * FEInterfaceValues object created with a quadrature rule integrating over
697 * the inside region, $\{x \in B : \psi(x) < 0 \}$, that was generated in
698 * the last call to reinit(..). If the cell in the last call was not
699 * intersected or if 0 quadrature points were generated, this optional will
700 * not contain a value.
701 */
702 std::optional<dealii::FEInterfaceValues<dim>> fe_values_inside;
703
704 /**
705 * FEInterfaceValues object created with a quadrature rule integrating over
706 * the outside region, $\{x \in B : \psi(x) > 0 \}$, that was generated in
707 * the last call to reinit(..). If the cell in the last call was not
708 * intersected or if 0 quadrature points were generated, this optional will
709 * not contain a value.
710 */
711 std::optional<dealii::FEInterfaceValues<dim>> fe_values_outside;
712
713 /**
714 * Object that generates the immersed quadrature rules.
715 */
716 DiscreteFaceQuadratureGenerator<dim> face_quadrature_generator;
717 };
718
719
720 #ifndef DOXYGEN
721
722 /*---------------------- Inline functions ---------------------*/
723
724 template <int dim>
725 template <typename CellIteratorType>
726 inline void
727 FEInterfaceValues<dim>::reinit(const CellIteratorType &cell,
728 const unsigned int face_no,
729 const unsigned int q_index,
730 const unsigned int mapping_index,
731 const unsigned int active_fe_index)
732 {
733 // Lambda describing how we should call reinit on a single
734 // dealii::FEInterfaceValues object.
735 const auto reinit_operation =
736 [&](dealii::FEInterfaceValues<dim> &fe_interface_values,
737 const unsigned int q_index) {
738 fe_interface_values.reinit(
739 cell, face_no, q_index, mapping_index, active_fe_index);
740 };
741
742 do_reinit(cell, face_no, q_index, active_fe_index, reinit_operation);
743 }
744
745
746
747 template <int dim>
748 template <typename CellIteratorType, typename CellNeighborIteratorType>
749 inline void
750 FEInterfaceValues<dim>::reinit(const CellIteratorType &cell,
751 const unsigned int face_no,
752 const unsigned int sub_face_no,
753 const CellNeighborIteratorType &cell_neighbor,
754 const unsigned int face_no_neighbor,
755 const unsigned int sub_face_no_neighbor,
756 const unsigned int q_index,
757 const unsigned int mapping_index,
758 const unsigned int active_fe_index)
759 {
760 Assert(sub_face_no == numbers::invalid_unsigned_int, ExcNotImplemented());
761 Assert(sub_face_no_neighbor == numbers::invalid_unsigned_int,
762 ExcNotImplemented());
763
764 // Lambda describing how we should call reinit on a single
765 // dealii::FEInterfaceValues object.
766 const auto reinit_operation =
767 [&](dealii::FEInterfaceValues<dim> &fe_interface_values,
768 const unsigned int q_index) {
769 fe_interface_values.reinit(cell,
770 face_no,
771 sub_face_no,
772 cell_neighbor,
773 face_no_neighbor,
774 sub_face_no_neighbor,
775 q_index,
776 mapping_index,
777 active_fe_index);
778 };
779
780 do_reinit(cell, face_no, q_index, active_fe_index, reinit_operation);
781 }
782
783 #endif
784
785 } // namespace NonMatching
786 DEAL_II_NAMESPACE_CLOSE
787
788 #endif