deal.II version 9.8.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
scratch_data.cc
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2019 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
14
15#include <memory>
16
18
19namespace MeshWorker
20{
21 template <int dim, int spacedim>
41
42
43
44 template <int dim, int spacedim>
48 const Quadrature<dim> &quadrature,
49 const UpdateFlags &update_flags,
50 const UpdateFlags &neighbor_update_flags,
52 const UpdateFlags &face_update_flags,
53 const UpdateFlags &neighbor_face_update_flags)
55 , fe(&fe)
56 , cell_quadrature(quadrature)
59 , cell_update_flags(update_flags)
60 , neighbor_cell_update_flags(neighbor_update_flags)
65 {}
66
67
68
69 template <int dim, int spacedim>
72 const Quadrature<dim> &quadrature,
73 const UpdateFlags &update_flags,
75 const UpdateFlags &face_update_flags)
77 fe.reference_cell().template get_default_linear_mapping<spacedim>(),
78 fe,
79 quadrature,
80 update_flags,
83 {}
84
85
86
87 template <int dim, int spacedim>
90 const Quadrature<dim> &quadrature,
91 const UpdateFlags &update_flags,
92 const UpdateFlags &neighbor_update_flags,
94 const UpdateFlags &face_update_flags,
95 const UpdateFlags &neighbor_face_update_flags)
97 fe.reference_cell().template get_default_linear_mapping<spacedim>(),
98 fe,
99 quadrature,
100 update_flags,
101 neighbor_update_flags,
105 {}
106
107
108
109 template <int dim, int spacedim>
130
131
132
133 template <int dim, int spacedim>
156
157
158
159 template <int dim, int spacedim>
173
174
175
176 template <int dim, int spacedim>
194
195
196
197 template <int dim, int spacedim>
218
219
220
221 template <int dim, int spacedim>
225 {
226 if (hp_capability_enabled == false)
227 {
228 if (!fe_values)
229 fe_values = std::make_unique<FEValues<dim, spacedim>>(
231
232 fe_values->reinit(cell);
233 local_dof_indices.resize(fe_values->dofs_per_cell);
234 cell->get_dof_indices(local_dof_indices);
236 return *fe_values;
237 }
238 else
239 {
240 if (!hp_fe_values)
241 hp_fe_values = std::make_unique<hp::FEValues<dim, spacedim>>(
246
247 hp_fe_values->reinit(cell);
248 const auto &fe_values = hp_fe_values->get_present_fe_values();
249
251 (*fe_collection)[cell->active_fe_index()].n_dofs_per_cell(),
252 fe_values.dofs_per_cell);
253 local_dof_indices.resize(fe_values.dofs_per_cell);
254 cell->get_dof_indices(local_dof_indices);
255
257 return fe_values;
258 }
259 }
260
261
262
263 template <int dim, int spacedim>
267 const unsigned int face_no)
268 {
269 if (hp_capability_enabled == false)
270 {
271 if (!fe_face_values)
272 fe_face_values = std::make_unique<FEFaceValues<dim, spacedim>>(
274
275 fe_face_values->reinit(cell, face_no);
276 local_dof_indices.resize(fe->n_dofs_per_cell());
277 cell->get_dof_indices(local_dof_indices);
279 return *fe_face_values;
280 }
281 else
282 {
283 return reinit(cell, cell, face_no);
284 }
285 }
286
287
288
289 template <int dim, int spacedim>
294 &neighbor_cell,
295 const unsigned int face_no)
296 {
298
300 hp_fe_face_values = std::make_unique<hp::FEFaceValues<dim, spacedim>>(
305
306 if (neighbor_cell == cell)
307 {
308 hp_fe_face_values->reinit(cell, face_no);
309 }
310 else
311 {
312 // When we want to ensure some agreement between the cell face and its
313 // neighbor on the quadrature order and mapping to use on this face,
314 // then we defer to the dominance of one FE over another. This should
315 // ensure that the optimal integration order and mapping order are
316 // selected for this situation.
317 unsigned int dominated_fe_index = fe_collection->find_dominated_fe(
318 {cell->active_fe_index(), neighbor_cell->active_fe_index()});
319
320 // TODO: find_dominated_fe returns invalid_fe_index when no dominated FE
321 // has been found. We want to pass this value to FEFaceValues, but it
322 // expects an invalid_unsigned_int in this case. We need to match the
323 // interfaces in the future.
324 if (dominated_fe_index == numbers::invalid_fe_index)
325 dominated_fe_index = numbers::invalid_unsigned_int;
326
327 hp_fe_face_values->reinit(cell,
328 face_no,
329 dominated_fe_index,
330 dominated_fe_index);
331 }
332
333 const auto &fe_face_values = hp_fe_face_values->get_present_fe_values();
334 const auto &fe = (*fe_collection)[cell->active_fe_index()];
335
336 local_dof_indices.resize(fe.n_dofs_per_cell());
337 cell->get_dof_indices(local_dof_indices);
338
340 return fe_face_values;
341 }
342
343
344
345 template <int dim, int spacedim>
349 const unsigned int face_no,
350 const unsigned int subface_no)
351 {
352 if (subface_no != numbers::invalid_unsigned_int)
353 {
354 if (hp_capability_enabled == false)
355 {
358 std::make_unique<FESubfaceValues<dim, spacedim>>(
360 fe_subface_values->reinit(cell, face_no, subface_no);
361 local_dof_indices.resize(fe->n_dofs_per_cell());
362 cell->get_dof_indices(local_dof_indices);
363
365 return *fe_subface_values;
366 }
367 else
368 {
369 return reinit(cell, cell, face_no, subface_no);
370 }
371 }
372 else
373 return reinit(cell, face_no);
374 }
375
376
377
378 template <int dim, int spacedim>
383 &neighbor_cell,
384 const unsigned int face_no,
385 const unsigned int subface_no)
386 {
388
389 if (subface_no != numbers::invalid_unsigned_int)
390 {
393 std::make_unique<hp::FESubfaceValues<dim, spacedim>>(
398
399 if (neighbor_cell == cell)
400 {
401 hp_fe_subface_values->reinit(cell, face_no, subface_no);
402 }
403 else
404 {
405 // When we want to ensure some agreement between the cell face and
406 // its neighbor on the quadrature order and mapping to use on this
407 // face, then we defer to the dominance of one FE over another. This
408 // should ensure that the optimal integration order and mapping
409 // order are selected for this situation.
410 unsigned int dominated_fe_index = fe_collection->find_dominated_fe(
411 {cell->active_fe_index(), neighbor_cell->active_fe_index()});
412
413 // TODO: find_dominated_fe returns invalid_fe_index when no
414 // dominated FE has been found. We want to pass this value to
415 // FEFaceValues, but it expects an invalid_unsigned_int in this
416 // case. We need to match the interfaces in the future.
417 if (dominated_fe_index == numbers::invalid_fe_index)
418 dominated_fe_index = numbers::invalid_unsigned_int;
419
420 hp_fe_subface_values->reinit(cell,
421 face_no,
422 subface_no,
423 dominated_fe_index,
424 dominated_fe_index);
425 }
426
427 const auto &fe_subface_values =
428 hp_fe_subface_values->get_present_fe_values();
429 const auto &fe = (*fe_collection)[cell->active_fe_index()];
430
431 local_dof_indices.resize(fe.n_dofs_per_cell());
432 cell->get_dof_indices(local_dof_indices);
433
435 return fe_subface_values;
436 }
437 else
438 {
439 return reinit(cell, neighbor_cell, face_no);
440 }
441 }
442
443
444
445 template <int dim, int spacedim>
449 const unsigned int face_no,
451 &cell_neighbor,
452 const unsigned int face_no_neighbor)
453 {
454 return reinit(cell,
455 face_no,
457 cell_neighbor,
458 face_no_neighbor,
460 }
461
462
463
464 template <int dim, int spacedim>
468 const unsigned int face_no,
469 const unsigned int sub_face_no,
471 &cell_neighbor,
472 const unsigned int face_no_neighbor,
473 const unsigned int sub_face_no_neighbor)
474 {
475 if (hp_capability_enabled == false)
476 {
479 std::make_unique<FEInterfaceValues<dim, spacedim>>(
481
482 interface_fe_values->reinit(cell,
483 face_no,
484 sub_face_no,
485 cell_neighbor,
486 face_no_neighbor,
487 sub_face_no_neighbor);
488 }
489 else
490 {
493 std::make_unique<FEInterfaceValues<dim, spacedim>>(
498
499 // When we want to ensure some agreement between the cell face and
500 // its neighbor on the quadrature order and mapping to use on this
501 // face, then we defer to the dominance of one FE over another. This
502 // should ensure that the optimal integration order and mapping
503 // order are selected for this situation.
504 unsigned int dominated_fe_index = fe_collection->find_dominated_fe(
505 {cell->active_fe_index(), cell_neighbor->active_fe_index()});
506
507 // TODO: find_dominated_fe returns invalid_fe_index when no dominated FE
508 // has been found. We want to pass this value to FEFaceValues, but it
509 // expects an invalid_unsigned_int in this case. We need to match the
510 // interfaces in the future.
511 if (dominated_fe_index == numbers::invalid_fe_index)
512 dominated_fe_index = numbers::invalid_unsigned_int;
513
514 interface_fe_values->reinit(cell,
515 face_no,
516 sub_face_no,
517 cell_neighbor,
518 face_no_neighbor,
519 sub_face_no_neighbor,
520 dominated_fe_index,
521 dominated_fe_index);
522 }
523
524 current_fe_values = &interface_fe_values->get_fe_face_values(0);
525 current_neighbor_fe_values = &interface_fe_values->get_fe_face_values(1);
526
527 local_dof_indices = interface_fe_values->get_interface_dof_indices();
528 return *interface_fe_values;
529 }
530
531
532
533 template <int dim, int spacedim>
537 {
538 if (hp_capability_enabled == false)
539 {
541 neighbor_fe_values = std::make_unique<FEValues<dim, spacedim>>(
543
544 neighbor_fe_values->reinit(cell);
545 cell->get_dof_indices(neighbor_dof_indices);
547 return *neighbor_fe_values;
548 }
549 else
550 {
552 neighbor_hp_fe_values = std::make_unique<hp::FEValues<dim, spacedim>>(
557
558 neighbor_hp_fe_values->reinit(cell);
559 const auto &neighbor_fe_values =
560 neighbor_hp_fe_values->get_present_fe_values();
561
563 (*fe_collection)[cell->active_fe_index()].n_dofs_per_cell(),
564 neighbor_fe_values.dofs_per_cell);
565 neighbor_dof_indices.resize(neighbor_fe_values.dofs_per_cell);
566 cell->get_dof_indices(neighbor_dof_indices);
567
569 return neighbor_fe_values;
570 }
571 }
572
573
574
575 template <int dim, int spacedim>
579 const unsigned int face_no)
580 {
581 if (hp_capability_enabled == false)
582 {
585 std::make_unique<FEFaceValues<dim, spacedim>>(
587 neighbor_fe_face_values->reinit(cell, face_no);
588 cell->get_dof_indices(neighbor_dof_indices);
591 }
592 else
593 {
594 return reinit_neighbor(cell, cell, face_no);
595 }
596 }
597
598
599
600 template <int dim, int spacedim>
605 &neighbor_cell,
606 const unsigned int face_no)
607 {
609
612 std::make_unique<hp::FEFaceValues<dim, spacedim>>(
617
618 if (neighbor_cell == cell)
619 {
620 neighbor_hp_fe_face_values->reinit(neighbor_cell, face_no);
621 }
622 else
623 {
624 // When we want to ensure some agreement between the cell face and its
625 // neighbor on the quadrature order and mapping to use on this face,
626 // then we defer to the dominance of one FE over another. This should
627 // ensure that the optimal integration order and mapping order are
628 // selected for this situation.
629 unsigned int dominated_fe_index = fe_collection->find_dominated_fe(
630 {cell->active_fe_index(), neighbor_cell->active_fe_index()});
631
632 // TODO: find_dominated_fe returns invalid_fe_index when no dominated FE
633 // has been found. We want to pass this value to FEFaceValues, but it
634 // expects an invalid_unsigned_int in this case. We need to match the
635 // interfaces in the future.
636 if (dominated_fe_index == numbers::invalid_fe_index)
637 dominated_fe_index = numbers::invalid_unsigned_int;
638
639 neighbor_hp_fe_face_values->reinit(neighbor_cell,
640 face_no,
641 dominated_fe_index,
642 dominated_fe_index);
643 }
644
645 const auto &neighbor_fe_face_values =
646 neighbor_hp_fe_face_values->get_present_fe_values();
647 const auto &neighbor_fe =
648 (*fe_collection)[neighbor_cell->active_fe_index()];
649
650 neighbor_dof_indices.resize(neighbor_fe.n_dofs_per_cell());
651 neighbor_cell->get_dof_indices(neighbor_dof_indices);
652
655 }
656
657
658
659 template <int dim, int spacedim>
663 const unsigned int face_no,
664 const unsigned int subface_no)
665 {
666 if (subface_no != numbers::invalid_unsigned_int)
667 {
668 if (hp_capability_enabled == false)
669 {
672 std::make_unique<FESubfaceValues<dim, spacedim>>(
674 neighbor_fe_subface_values->reinit(cell, face_no, subface_no);
675 cell->get_dof_indices(neighbor_dof_indices);
678 }
679 else
680 {
681 return reinit_neighbor(cell, cell, face_no, subface_no);
682 }
683 }
684 else
685 return reinit_neighbor(cell, face_no);
686 }
687
688
689
690 template <int dim, int spacedim>
695 &neighbor_cell,
696 const unsigned int face_no,
697 const unsigned int subface_no)
698 {
700
701 if (subface_no != numbers::invalid_unsigned_int)
702 {
705 std::make_unique<hp::FESubfaceValues<dim, spacedim>>(
710
711 if (neighbor_cell == cell)
712 {
713 neighbor_hp_fe_subface_values->reinit(neighbor_cell,
714 face_no,
715 subface_no);
716 }
717 else
718 {
719 // When we want to ensure some agreement between the cell face and
720 // its neighbor on the quadrature order and mapping to use on this
721 // face, then we defer to the dominance of one FE over another. This
722 // should ensure that the optimal integration order and mapping
723 // order are selected for this situation.
724 unsigned int dominated_fe_index = fe_collection->find_dominated_fe(
725 {cell->active_fe_index(), neighbor_cell->active_fe_index()});
726
727 // TODO: find_dominated_fe returns invalid_fe_index when no
728 // dominated FE has been found. We want to pass this value to
729 // FEFaceValues, but it expects an invalid_unsigned_int in this
730 // case. We need to match the interfaces in the future.
731 if (dominated_fe_index == numbers::invalid_fe_index)
732 dominated_fe_index = numbers::invalid_unsigned_int;
733
734 neighbor_hp_fe_subface_values->reinit(neighbor_cell,
735 face_no,
736 subface_no,
737 dominated_fe_index,
738 dominated_fe_index);
739 }
740
741 const auto &neighbor_fe_subface_values =
742 neighbor_hp_fe_subface_values->get_present_fe_values();
743 const auto &neighbor_fe =
744 (*fe_collection)[neighbor_cell->active_fe_index()];
745
746 neighbor_dof_indices.resize(neighbor_fe.n_dofs_per_cell());
747 neighbor_cell->get_dof_indices(neighbor_dof_indices);
748
751 }
752 else
753 {
754 return reinit_neighbor(cell, neighbor_cell, face_no);
755 }
756 }
757
758
759
760 template <int dim, int spacedim>
763 {
764 Assert(current_fe_values != nullptr,
765 ExcMessage("You have to initialize the cache using one of the "
766 "reinit functions first!"));
767 return *current_fe_values;
768 }
769
770
771
772 template <int dim, int spacedim>
775 {
776 Assert(interface_fe_values != nullptr,
777 ExcMessage("You have to initialize the cache using one of the "
778 "reinit functions first!"));
779 return *interface_fe_values;
780 }
781
782
783
784 template <int dim, int spacedim>
787 {
789 ExcMessage("You have to initialize the cache using one of the "
790 "reinit functions first!"));
792 }
793
794
795
796 template <int dim, int spacedim>
797 const std::vector<Point<spacedim>> &
799 {
800 return get_current_fe_values().get_quadrature_points();
801 }
802
803
804
805 template <int dim, int spacedim>
806 const std::vector<double> &
808 {
809 return get_current_fe_values().get_JxW_values();
810 }
811
812
813
814 template <int dim, int spacedim>
815 const std::vector<double> &
820
821
822
823 template <int dim, int spacedim>
824 const std::vector<Tensor<1, spacedim>> &
826 {
827 return get_current_fe_values().get_normal_vectors();
828 }
829
830
831
832 template <int dim, int spacedim>
833 const std::vector<Tensor<1, spacedim>> &
838
839
840
841 template <int dim, int spacedim>
842 const std::vector<types::global_dof_index> &
847
848
849
850 template <int dim, int spacedim>
851 unsigned int
856
857
858
859 template <int dim, int spacedim>
860 const std::vector<types::global_dof_index> &
865
866
867
868 template <int dim, int spacedim>
869 unsigned int
874
875
876
877 template <int dim, int spacedim>
883
884
885
886 template <int dim, int spacedim>
887 const GeneralDataStorage &
892
893
894
895 template <int dim, int spacedim>
903
904
905
906 template <int dim, int spacedim>
914
915
916
917 template <int dim, int spacedim>
918 const Quadrature<dim> &
924
925
926
927 template <int dim, int spacedim>
928 const Quadrature<dim - 1> &
934
935
936
937 template <int dim, int spacedim>
945
946
947
948 template <int dim, int spacedim>
956
957
958
959 template <int dim, int spacedim>
966
967
968
969 template <int dim, int spacedim>
970 const hp::QCollection<dim - 1> &
976
977
978
979 template <int dim, int spacedim>
980 bool
985
986
987
988 template <int dim, int spacedim>
989 UpdateFlags
994
995
996
997 template <int dim, int spacedim>
998 UpdateFlags
1003
1004
1005
1006 template <int dim, int spacedim>
1007 UpdateFlags
1012
1013
1014
1015 template <int dim, int spacedim>
1016 UpdateFlags
1021
1022} // namespace MeshWorker
1023
1024// Explicit instantiations
1025namespace MeshWorker
1026{
1027#include "meshworker/scratch_data.inst"
1028}
Abstract base class for mapping classes.
Definition mapping.h:318
GeneralDataStorage user_data_storage
hp::QCollection< dim - 1 > face_quadrature_collection
bool has_hp_capabilities() const
const hp::MappingCollection< dim, spacedim > & get_mapping_collection() const
const FEValuesBase< dim, spacedim > & get_current_fe_values() const
GeneralDataStorage & get_general_data_storage()
const Quadrature< dim - 1 > & get_face_quadrature() const
const std::vector< Tensor< 1, spacedim > > & get_neighbor_normal_vectors()
unsigned int n_dofs_per_cell() const
std::unique_ptr< hp::FESubfaceValues< dim, spacedim > > hp_fe_subface_values
unsigned int n_neighbor_dofs_per_cell() const
std::unique_ptr< FEValues< dim, spacedim > > neighbor_fe_values
std::unique_ptr< FEFaceValues< dim, spacedim > > fe_face_values
std::unique_ptr< FEValues< dim, spacedim > > fe_values
const std::vector< double > & get_JxW_values() const
const Mapping< dim, spacedim > & get_mapping() const
ObserverPointer< const Mapping< dim, spacedim > > mapping
std::unique_ptr< FEInterfaceValues< dim, spacedim > > interface_fe_values
const std::vector< double > & get_neighbor_JxW_values() const
Quadrature< dim > cell_quadrature
ObserverPointer< const hp::FECollection< dim, spacedim > > fe_collection
const FiniteElement< dim, spacedim > & get_fe() const
std::unique_ptr< FEFaceValues< dim, spacedim > > neighbor_fe_face_values
const hp::QCollection< dim > & get_cell_quadrature_collection() const
std::vector< types::global_dof_index > neighbor_dof_indices
const std::vector< types::global_dof_index > & get_neighbor_dof_indices() const
UpdateFlags get_face_update_flags() const
std::unique_ptr< hp::FEValues< dim, spacedim > > hp_fe_values
ObserverPointer< const FEValuesBase< dim, spacedim > > current_fe_values
UpdateFlags neighbor_cell_update_flags
UpdateFlags get_neighbor_cell_update_flags() const
const hp::FECollection< dim, spacedim > & get_fe_collection() const
const std::vector< Tensor< 1, spacedim > > & get_normal_vectors() const
const FEValues< dim, spacedim > & reinit_neighbor(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell)
std::unique_ptr< hp::FEFaceValues< dim, spacedim > > neighbor_hp_fe_face_values
ObserverPointer< const FiniteElement< dim, spacedim > > fe
std::vector< types::global_dof_index > local_dof_indices
const std::vector< Point< spacedim > > & get_quadrature_points() const
std::unique_ptr< hp::FEValues< dim, spacedim > > neighbor_hp_fe_values
ObserverPointer< const FEValuesBase< dim, spacedim > > current_neighbor_fe_values
const FEValuesBase< dim, spacedim > & get_current_neighbor_fe_values() const
const std::vector< types::global_dof_index > & get_local_dof_indices() const
Quadrature< dim - 1 > face_quadrature
const FEInterfaceValues< dim, spacedim > & get_current_interface_fe_values() const
hp::QCollection< dim > cell_quadrature_collection
UpdateFlags get_cell_update_flags() const
UpdateFlags neighbor_face_update_flags
const Quadrature< dim > & get_cell_quadrature() const
const hp::QCollection< dim - 1 > & get_face_quadrature_collection() const
ScratchData(const Mapping< dim, spacedim > &mapping, const FiniteElement< dim, spacedim > &fe, const Quadrature< dim > &quadrature, const UpdateFlags &update_flags, const Quadrature< dim - 1 > &face_quadrature=Quadrature< dim - 1 >(), const UpdateFlags &face_update_flags=update_default)
std::unique_ptr< FESubfaceValues< dim, spacedim > > neighbor_fe_subface_values
ObserverPointer< const hp::MappingCollection< dim, spacedim > > mapping_collection
const FEValues< dim, spacedim > & reinit(const typename DoFHandler< dim, spacedim >::active_cell_iterator &cell)
std::unique_ptr< hp::FESubfaceValues< dim, spacedim > > neighbor_hp_fe_subface_values
std::unique_ptr< FESubfaceValues< dim, spacedim > > fe_subface_values
GeneralDataStorage internal_data_storage
UpdateFlags get_neighbor_face_update_flags() const
std::unique_ptr< hp::FEFaceValues< dim, spacedim > > hp_fe_face_values
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcOnlyAvailableWithoutHP()
static ::ExceptionBase & ExcNotInitialized()
static ::ExceptionBase & ExcMessage(std::string arg1)
static ::ExceptionBase & ExcOnlyAvailableWithHP()
typename ActiveSelector::active_cell_iterator active_cell_iterator
const Mapping< dim, spacedim > & get_default_linear_mapping(const Triangulation< dim, spacedim > &triangulation)
Definition mapping.cc:314
constexpr unsigned int invalid_unsigned_int
Definition types.h:236
constexpr types::fe_index invalid_fe_index
Definition types.h:258