version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10:01+00:00
\(\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
tools.h
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) 2020 - 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
13#ifndef dealii_matrix_free_tools_h
14#define dealii_matrix_free_tools_h
15
16#include <deal.II/base/config.h>
17
18#include <deal.II/grid/tria.h>
19
25
26#include <Kokkos_Core.hpp>
27
28
30
36{
37 namespace internal
38 {
39 template <int dim, typename Number, bool is_face_>
41 {
42 public:
44
45 std::vector<unsigned int> dof_numbers;
46 std::vector<unsigned int> quad_numbers;
47 std::vector<unsigned int> n_components;
48 std::vector<unsigned int> first_selected_components;
49 std::vector<unsigned int> batch_type;
50 static const bool is_face = is_face_;
51
52 std::function<std::vector<std::unique_ptr<FEEvalType>>(
53 const std::pair<unsigned int, unsigned int> &)>
55 std::function<void(std::vector<std::unique_ptr<FEEvalType>> &,
56 const unsigned int)>
58 std::function<void(std::vector<std::unique_ptr<FEEvalType>> &)>
60 };
61 } // namespace internal
62
68 template <int dim, typename AdditionalData>
69 void
71 AdditionalData &additional_data);
72
73
74
86 template <int dim,
87 int fe_degree,
88 int n_q_points_1d,
89 int n_components,
90 typename Number,
91 typename VectorizedArrayType,
92 typename VectorType>
93 void
96 VectorType &diagonal_global,
97 const std::function<void(FEEvaluation<dim,
98 fe_degree,
99 n_q_points_1d,
100 n_components,
101 Number,
102 VectorizedArrayType> &)>
103 &cell_operation,
104 const unsigned int dof_handler_index = 0,
105 const unsigned int quadrature_index = 0,
106 const unsigned int first_selected_component = 0,
107 const unsigned int first_vector_component = 0);
108
112 template <int dim,
113 int fe_degree,
114 int n_q_points_1d,
115 int n_components,
116 typename Number,
117 typename MemorySpace,
118 typename QuadOperation>
119 void
121 const Portable::MatrixFree<dim, Number> &matrix_free,
123 const QuadOperation &quad_operation,
124 EvaluationFlags::EvaluationFlags evaluation_flags,
125 EvaluationFlags::EvaluationFlags integration_flags,
126 const unsigned int dof_handler_index = 0,
127 const unsigned int quadrature_index = 0,
128 const unsigned int first_selected_component = 0,
129 const unsigned int first_vector_component = 0);
130
134 template <typename CLASS,
135 int dim,
136 int fe_degree,
137 int n_q_points_1d,
138 int n_components,
139 typename Number,
140 typename VectorizedArrayType,
141 typename VectorType>
142 void
145 VectorType &diagonal_global,
146 void (CLASS::*cell_operation)(FEEvaluation<dim,
147 fe_degree,
148 n_q_points_1d,
149 n_components,
150 Number,
151 VectorizedArrayType> &) const,
152 const CLASS *owning_class,
153 const unsigned int dof_handler_index = 0,
154 const unsigned int quadrature_index = 0,
155 const unsigned int first_selected_component = 0,
156 const unsigned int first_vector_component = 0);
157
158
159
170 template <int dim,
171 int fe_degree,
172 int n_q_points_1d,
173 int n_components,
174 typename Number,
175 typename VectorizedArrayType,
176 typename VectorType>
177 void
180 VectorType &diagonal_global,
181 const std::function<void(FEEvaluation<dim,
182 fe_degree,
183 n_q_points_1d,
184 n_components,
185 Number,
186 VectorizedArrayType> &)>
187 &cell_operation,
188 const std::function<void(FEFaceEvaluation<dim,
189 fe_degree,
190 n_q_points_1d,
191 n_components,
192 Number,
193 VectorizedArrayType> &,
195 fe_degree,
196 n_q_points_1d,
197 n_components,
198 Number,
199 VectorizedArrayType> &)>
200 &face_operation,
201 const std::function<void(FEFaceEvaluation<dim,
202 fe_degree,
203 n_q_points_1d,
204 n_components,
205 Number,
206 VectorizedArrayType> &)>
207 &boundary_operation,
208 const unsigned int dof_handler_index = 0,
209 const unsigned int quadrature_index = 0,
210 const unsigned int first_selected_component = 0,
211 const unsigned int first_vector_component = 0);
212
213
214
218 template <typename CLASS,
219 int dim,
220 int fe_degree,
221 int n_q_points_1d,
222 int n_components,
223 typename Number,
224 typename VectorizedArrayType,
225 typename VectorType>
226 void
229 VectorType &diagonal_global,
230 void (CLASS::*cell_operation)(FEEvaluation<dim,
231 fe_degree,
232 n_q_points_1d,
233 n_components,
234 Number,
235 VectorizedArrayType> &) const,
236 void (CLASS::*face_operation)(FEFaceEvaluation<dim,
237 fe_degree,
238 n_q_points_1d,
239 n_components,
240 Number,
241 VectorizedArrayType> &,
243 fe_degree,
244 n_q_points_1d,
245 n_components,
246 Number,
247 VectorizedArrayType> &)
248 const,
249 void (CLASS::*boundary_operation)(FEFaceEvaluation<dim,
250 fe_degree,
251 n_q_points_1d,
252 n_components,
253 Number,
254 VectorizedArrayType> &)
255 const,
256 const CLASS *owning_class,
257 const unsigned int dof_handler_index = 0,
258 const unsigned int quadrature_index = 0,
259 const unsigned int first_selected_component = 0,
260 const unsigned int first_vector_component = 0);
261
262
263
272 template <int dim,
273 int fe_degree,
274 int n_q_points_1d,
275 int n_components,
276 typename Number,
277 typename VectorizedArrayType,
278 typename MatrixType>
279 void
282 const AffineConstraints<Number> &constraints,
283 MatrixType &matrix,
284 const std::function<void(FEEvaluation<dim,
285 fe_degree,
286 n_q_points_1d,
287 n_components,
288 Number,
289 VectorizedArrayType> &)>
290 &cell_operation,
291 const unsigned int dof_handler_index = 0,
292 const unsigned int quadrature_index = 0,
293 const unsigned int first_selected_component = 0);
294
295
296
300 template <typename CLASS,
301 int dim,
302 int fe_degree,
303 int n_q_points_1d,
304 int n_components,
305 typename Number,
306 typename VectorizedArrayType,
307 typename MatrixType>
308 void
311 const AffineConstraints<Number> &constraints,
312 MatrixType &matrix,
313 void (CLASS::*cell_operation)(FEEvaluation<dim,
314 fe_degree,
315 n_q_points_1d,
316 n_components,
317 Number,
318 VectorizedArrayType> &) const,
319 const CLASS *owning_class,
320 const unsigned int dof_handler_index = 0,
321 const unsigned int quadrature_index = 0,
322 const unsigned int first_selected_component = 0);
323
342 template <int dim,
343 int fe_degree,
344 int n_q_points_1d,
345 int n_components,
346 typename Number,
347 typename MatrixType,
348 typename QuadOperation>
349 void
351 MatrixType &matrix,
352 const QuadOperation &quad_operation,
353 EvaluationFlags::EvaluationFlags evaluation_flags,
354 EvaluationFlags::EvaluationFlags integration_flags,
355 const unsigned int dof_handler_index = 0,
356 const unsigned int quadrature_index = 0,
357 const unsigned int first_selected_component = 0);
358
359
360 namespace internal
361 {
366 template <int dim,
367 typename Number,
368 typename VectorizedArrayType,
369 typename VectorType,
370 typename VectorType2>
371 void
375 &data_cell,
377 &data_face,
379 &data_boundary,
380 VectorType &diagonal_global,
381 std::vector<VectorType2 *> &diagonal_global_components);
382
387 template <int dim,
388 typename Number,
389 typename VectorizedArrayType,
390 typename MatrixType>
391 void
394 const AffineConstraints<Number> &constraints,
396 &cell_operation,
398 &face_operation,
400 &boundary_operation,
401 MatrixType &matrix);
402 } // namespace internal
403
404
405
415 template <int dim,
416 int fe_degree,
417 int n_q_points_1d,
418 int n_components,
419 typename Number,
420 typename VectorizedArrayType,
421 typename MatrixType>
422 void
425 const AffineConstraints<Number> &constraints,
426 MatrixType &matrix,
427 const std::function<void(FEEvaluation<dim,
428 fe_degree,
429 n_q_points_1d,
430 n_components,
431 Number,
432 VectorizedArrayType> &)>
433 &cell_operation,
434 const std::function<void(FEFaceEvaluation<dim,
435 fe_degree,
436 n_q_points_1d,
437 n_components,
438 Number,
439 VectorizedArrayType> &,
441 fe_degree,
442 n_q_points_1d,
443 n_components,
444 Number,
445 VectorizedArrayType> &)>
446 &face_operation,
447 const std::function<void(FEFaceEvaluation<dim,
448 fe_degree,
449 n_q_points_1d,
450 n_components,
451 Number,
452 VectorizedArrayType> &)>
453 &boundary_operation,
454 const unsigned int dof_handler_index = 0,
455 const unsigned int quadrature_index = 0,
456 const unsigned int first_selected_component = 0);
457
458
459
463 template <typename CLASS,
464 int dim,
465 int fe_degree,
466 int n_q_points_1d,
467 int n_components,
468 typename Number,
469 typename VectorizedArrayType,
470 typename MatrixType>
471 void
474 const AffineConstraints<Number> &constraints,
475 MatrixType &matrix,
476 void (CLASS::*cell_operation)(FEEvaluation<dim,
477 fe_degree,
478 n_q_points_1d,
479 n_components,
480 Number,
481 VectorizedArrayType> &) const,
482 void (CLASS::*face_operation)(FEFaceEvaluation<dim,
483 fe_degree,
484 n_q_points_1d,
485 n_components,
486 Number,
487 VectorizedArrayType> &,
489 fe_degree,
490 n_q_points_1d,
491 n_components,
492 Number,
493 VectorizedArrayType> &)
494 const,
495 void (CLASS::*boundary_operation)(FEFaceEvaluation<dim,
496 fe_degree,
497 n_q_points_1d,
498 n_components,
499 Number,
500 VectorizedArrayType> &)
501 const,
502 const CLASS *owning_class,
503 const unsigned int dof_handler_index = 0,
504 const unsigned int quadrature_index = 0,
505 const unsigned int first_selected_component = 0);
506
507
508
517 template <int dim,
518 typename Number,
519 typename VectorizedArrayType = VectorizedArray<Number>>
521 {
522 public:
528 {
532 AdditionalData(const unsigned int dof_index = 0)
534 {}
535
539 unsigned int dof_index;
540 };
541
551 void
553 const AdditionalData &additional_data = AdditionalData())
554 {
555 this->matrix_free = &matrix_free;
556
557 std::vector<unsigned int> valid_fe_indices;
558
559 const auto &fe_collection =
560 matrix_free.get_dof_handler(additional_data.dof_index)
561 .get_fe_collection();
562
563 for (unsigned int i = 0; i < fe_collection.size(); ++i)
564 if (fe_collection[i].n_dofs_per_cell() > 0)
565 valid_fe_indices.push_back(i);
566
567 // TODO: relax this so that arbitrary number of valid
568 // FEs can be accepted
569 AssertDimension(valid_fe_indices.size(), 1);
570
571 fe_index_valid = *valid_fe_indices.begin();
572 }
573
579 template <typename VectorTypeOut, typename VectorTypeIn>
580 void
581 cell_loop(const std::function<void(
583 VectorTypeOut &,
584 const VectorTypeIn &,
585 const std::pair<unsigned int, unsigned int> &)> &cell_operation,
586 VectorTypeOut &dst,
587 const VectorTypeIn &src,
588 const bool zero_dst_vector = false) const
589 {
590 const auto ebd_cell_operation = [&](const auto &matrix_free,
591 auto &dst,
592 const auto &src,
593 const auto &range) {
594 const auto category = matrix_free.get_cell_range_category(range);
595
596 if (category != fe_index_valid)
597 return;
598
599 cell_operation(matrix_free, dst, src, range);
600 };
601
602 matrix_free->template cell_loop<VectorTypeOut, VectorTypeIn>(
603 ebd_cell_operation, dst, src, zero_dst_vector);
604 }
605
613 template <typename VectorTypeOut, typename VectorTypeIn>
614 void
615 loop(const std::function<
617 VectorTypeOut &,
618 const VectorTypeIn &,
619 const std::pair<unsigned int, unsigned int> &)> &cell_operation,
620 const std::function<
622 VectorTypeOut &,
623 const VectorTypeIn &,
624 const std::pair<unsigned int, unsigned int> &)> &face_operation,
625 const std::function<
627 VectorTypeOut &,
628 const VectorTypeIn &,
629 const std::pair<unsigned int, unsigned int> &,
630 const bool)> &boundary_operation,
631 VectorTypeOut &dst,
632 const VectorTypeIn &src,
633 const bool zero_dst_vector = false) const
634 {
635 const auto ebd_cell_operation = [&](const auto &matrix_free,
636 auto &dst,
637 const auto &src,
638 const auto &range) {
639 const auto category = matrix_free.get_cell_range_category(range);
640
641 if (category != fe_index_valid)
642 return;
643
644 cell_operation(matrix_free, dst, src, range);
645 };
646
647 const auto ebd_internal_or_boundary_face_operation =
648 [&](const auto &matrix_free,
649 auto &dst,
650 const auto &src,
651 const auto &range) {
652 const auto category = matrix_free.get_face_range_category(range);
653
654 const unsigned int type =
655 static_cast<unsigned int>(category.first == fe_index_valid) +
656 static_cast<unsigned int>(category.second == fe_index_valid);
657
658 if (type == 0)
659 return; // deactivated face -> nothing to do
660
661 if (type == 1) // boundary face
662 boundary_operation(
663 matrix_free, dst, src, range, category.first == fe_index_valid);
664 else if (type == 2) // internal face
665 face_operation(matrix_free, dst, src, range);
666 };
667
668 matrix_free->template loop<VectorTypeOut, VectorTypeIn>(
669 ebd_cell_operation,
670 ebd_internal_or_boundary_face_operation,
671 ebd_internal_or_boundary_face_operation,
672 dst,
673 src,
674 zero_dst_vector);
675 }
676
677 private:
683
687 unsigned int fe_index_valid;
688 };
689
690 // implementations
691
692#ifndef DOXYGEN
693
694 template <int dim, typename AdditionalData>
695 void
697 AdditionalData &additional_data)
698 {
699 // ... determine if we are on an active or a multigrid level
700 const unsigned int level = additional_data.mg_level;
701 const bool is_mg = (level != numbers::invalid_unsigned_int);
702
703 // ... create empty list for the category of each cell
704 if (is_mg)
705 additional_data.cell_vectorization_category.assign(
706 std::distance(tria.begin(level), tria.end(level)), 0);
707 else
708 additional_data.cell_vectorization_category.assign(tria.n_active_cells(),
709 0);
710
711 // ... set up scaling factor
712 std::vector<unsigned int> factors(GeometryInfo<dim>::faces_per_cell);
713
714 auto bids = tria.get_boundary_ids();
715 std::sort(bids.begin(), bids.end());
716
717 {
718 unsigned int n_bids = bids.size() + 1;
719 int offset = 1;
720 for (unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell;
721 i++, offset = offset * n_bids)
722 factors[i] = offset;
723 }
724
725 const auto to_category = [&](const auto &cell) {
726 unsigned int c_num = 0;
727 for (unsigned int i = 0; i < GeometryInfo<dim>::faces_per_cell; ++i)
728 {
729 const auto face = cell->face(i);
730 if (face->at_boundary() && !cell->has_periodic_neighbor(i))
731 c_num +=
732 factors[i] * (1 + std::distance(bids.begin(),
733 std::find(bids.begin(),
734 bids.end(),
735 face->boundary_id())));
736 }
737 return c_num;
738 };
739
740 if (!is_mg)
741 {
742 for (auto cell = tria.begin_active(); cell != tria.end(); ++cell)
743 {
744 if (cell->is_locally_owned())
745 additional_data
746 .cell_vectorization_category[cell->active_cell_index()] =
747 to_category(cell);
748 }
749 }
750 else
751 {
752 for (auto cell = tria.begin(level); cell != tria.end(level); ++cell)
753 {
754 if (cell->is_locally_owned_on_level())
755 additional_data.cell_vectorization_category[cell->index()] =
756 to_category(cell);
757 }
758 }
759
760 // ... finalize set up of matrix_free
761 additional_data.hold_all_faces_to_owned_cells = true;
762 additional_data.cell_vectorization_categories_strict = true;
763 additional_data.mapping_update_flags_faces_by_cells =
764 additional_data.mapping_update_flags_inner_faces |
765 additional_data.mapping_update_flags_boundary_faces;
766 }
767
768 namespace internal
769 {
770 template <typename Number>
771 struct LocalCSR
772 {
773 std::vector<unsigned int> row_lid_to_gid;
774 std::vector<unsigned int> row;
775 std::vector<unsigned int> col;
776 std::vector<Number> val;
777
778 std::vector<unsigned int> inverse_lookup_rows;
779 std::vector<std::pair<unsigned int, unsigned int>> inverse_lookup_origins;
780 };
781
782 template <int dim, typename VectorizedArrayType, bool is_face>
783 class ComputeDiagonalHelper
784 {
785 public:
786 using FEEvaluationType =
788
789 using Number = typename VectorizedArrayType::value_type;
790 static const unsigned int n_lanes = VectorizedArrayType::size();
791
792 ComputeDiagonalHelper()
793 : phi(nullptr)
794 , matrix_free(nullptr)
795 , dofs_per_component(0)
796 , n_components(0)
797 {}
798
799 ComputeDiagonalHelper(const ComputeDiagonalHelper &)
800 : phi(nullptr)
801 , matrix_free(nullptr)
802 , dofs_per_component(0)
803 , n_components(0)
804 {}
805
806 void
807 initialize(
808 FEEvaluationType &phi,
810 const unsigned int n_components)
811 {
812 // if we are in hp mode and the number of unknowns changed, we must
813 // clear the map of entries
814 if (dofs_per_component !=
815 phi.get_shape_info().dofs_per_component_on_cell)
816 {
817 locally_relevant_constraints_hn_map.clear();
818 dofs_per_component =
819 phi.get_shape_info().dofs_per_component_on_cell;
820 }
821 this->n_components = n_components;
822 this->dofs_per_cell = n_components * dofs_per_component;
823 this->phi = &phi;
824 this->matrix_free = &matrix_free;
825 }
826
827 void
828 reinit(const unsigned int cell)
829 {
830 // STEP 1: get relevant information from FEEvaluation
831 const auto &matrix_free = *this->matrix_free;
832 const auto &dof_info = phi->get_dof_info();
833 const unsigned int n_fe_components = dof_info.start_components.back();
834
835 // if we have a block vector with components with the same DoFHandler,
836 // each component is described with same set of constraints and
837 // we consider the shift in components only during access of the global
838 // vector
839 const unsigned int first_selected_component =
840 n_fe_components == 1 ? 0 : phi->get_first_selected_component();
841
842 this->n_lanes_filled =
843 is_face ? matrix_free.n_active_entries_per_face_batch(cell) :
844 matrix_free.n_active_entries_per_cell_batch(cell);
845
846 // STEP 2: setup CSR storage of transposed locally-relevant
847 // constraint matrix
848
849 const std::array<unsigned int, n_lanes> &cells =
850 this->phi->get_cell_ids();
851
852 inverse_lookup_count.resize(dofs_per_cell);
853 for (unsigned int v = 0; v < n_lanes_filled; ++v)
854 {
857
858 const unsigned int *dof_indices;
859 unsigned int index_indicators, next_index_indicators;
860
861 const unsigned int start =
862 cells[v] * n_fe_components + first_selected_component;
863 dof_indices =
864 dof_info.dof_indices.data() + dof_info.row_starts[start].first;
865 index_indicators = dof_info.row_starts[start].second;
866 next_index_indicators = dof_info.row_starts[start + 1].second;
867
868 // STEP 2a: setup locally-relevant constraint matrix in a
869 // coordinate list (COO)
870 locally_relevant_constraints.clear();
871
872 if (n_components == 1 || n_fe_components == 1)
873 {
874 unsigned int ind_local = 0;
875 for (; index_indicators != next_index_indicators;
876 ++index_indicators, ++ind_local)
877 {
878 const std::pair<unsigned short, unsigned short> indicator =
879 dof_info.constraint_indicator[index_indicators];
880
881 for (unsigned int j = 0; j < indicator.first;
882 ++j, ++ind_local)
883 locally_relevant_constraints.emplace_back(ind_local,
884 dof_indices[j],
885 1.0);
886
887 dof_indices += indicator.first;
888
889 const Number *data_val =
890 matrix_free.constraint_pool_begin(indicator.second);
891 const Number *end_pool =
892 matrix_free.constraint_pool_end(indicator.second);
893
894 for (; data_val != end_pool; ++data_val, ++dof_indices)
895 locally_relevant_constraints.emplace_back(ind_local,
896 *dof_indices,
897 *data_val);
898 }
899
900 AssertIndexRange(ind_local, dofs_per_component + 1);
901
902 for (; ind_local < dofs_per_component;
903 ++dof_indices, ++ind_local)
904 locally_relevant_constraints.emplace_back(ind_local,
905 *dof_indices,
906 1.0);
907 }
908 else
909 {
910 // case with vector-valued finite elements where all
911 // components are included in one single vector. Assumption:
912 // first come all entries to the first component, then all
913 // entries to the second one, and so on. This is ensured by
914 // the way MatrixFree reads out the indices.
915 for (unsigned int comp = 0; comp < n_components; ++comp)
916 {
917 unsigned int ind_local = 0;
918
919 // check whether there is any constraint on the current
920 // cell
921 for (; index_indicators != next_index_indicators;
922 ++index_indicators, ++ind_local)
923 {
924 const std::pair<unsigned short, unsigned short>
925 indicator =
926 dof_info.constraint_indicator[index_indicators];
927
928 // run through values up to next constraint
929 for (unsigned int j = 0; j < indicator.first;
930 ++j, ++ind_local)
931 locally_relevant_constraints.emplace_back(
932 comp * dofs_per_component + ind_local,
933 dof_indices[j],
934 1.0);
935 dof_indices += indicator.first;
936
937 const Number *data_val =
938 matrix_free.constraint_pool_begin(indicator.second);
939 const Number *end_pool =
940 matrix_free.constraint_pool_end(indicator.second);
941
942 for (; data_val != end_pool; ++data_val, ++dof_indices)
943 locally_relevant_constraints.emplace_back(
944 comp * dofs_per_component + ind_local,
945 *dof_indices,
946 *data_val);
947 }
948
949 AssertIndexRange(ind_local, dofs_per_component + 1);
950
951 // get the dof values past the last constraint
952 for (; ind_local < dofs_per_component;
953 ++dof_indices, ++ind_local)
954 locally_relevant_constraints.emplace_back(
955 comp * dofs_per_component + ind_local,
956 *dof_indices,
957 1.0);
958
959 if (comp + 1 < n_components)
960 next_index_indicators =
961 dof_info.row_starts[start + comp + 2].second;
962 }
963 }
964
965 // we only need partial sortedness for the algorithm below in that
966 // all entries for a particular row must be adjacent. this is
967 // ensured by the way we fill the field, but check it again
968 for (unsigned int i = 1; i < locally_relevant_constraints.size();
969 ++i)
970 Assert(std::get<0>(locally_relevant_constraints[i]) >=
971 std::get<0>(locally_relevant_constraints[i - 1]),
973
974 // STEP 2c: apply hanging-node constraints
975 if (dof_info.hanging_node_constraint_masks.size() > 0 &&
976 dof_info.hanging_node_constraint_masks_comp.size() > 0 &&
977 dof_info.hanging_node_constraint_masks_comp
978 [phi->get_active_fe_index()][first_selected_component])
979 {
980 const auto mask =
981 dof_info.hanging_node_constraint_masks[cells[v]];
982
983 // cell has hanging nodes
984 if (mask != ::internal::MatrixFreeFunctions::
986 {
987 // check if hanging node internpolation matrix has been set
988 // up
989 if (locally_relevant_constraints_hn_map.find(mask) ==
990 locally_relevant_constraints_hn_map.end())
991 fill_constraint_type_into_map(mask);
992
993 const auto &locally_relevant_constraints_hn =
994 locally_relevant_constraints_hn_map[mask];
995
996 locally_relevant_constraints_tmp.clear();
997 if (locally_relevant_constraints_tmp.capacity() <
998 locally_relevant_constraints.size())
999 locally_relevant_constraints_tmp.reserve(
1000 locally_relevant_constraints.size() +
1001 locally_relevant_constraints_hn.size());
1002
1003 // combine with other constraints: to avoid binary
1004 // searches, we first build a list of where constraints
1005 // are pointing to, and then merge the two lists
1006 constraint_position.assign(dofs_per_cell,
1008 for (auto &a : locally_relevant_constraints)
1009 if (constraint_position[std::get<0>(a)] ==
1011 constraint_position[std::get<0>(a)] =
1012 std::distance(locally_relevant_constraints.data(),
1013 &a);
1014 is_constrained_hn.assign(dofs_per_cell, false);
1015 for (auto &hn : locally_relevant_constraints_hn)
1016 is_constrained_hn[std::get<0>(hn)] = 1;
1017
1018 // not constrained from hanging nodes
1019 for (const auto &a : locally_relevant_constraints)
1020 if (is_constrained_hn[std::get<0>(a)] == 0)
1021 locally_relevant_constraints_tmp.push_back(a);
1022
1023 // dof is constrained by hanging nodes: build transitive
1024 // closure
1025 for (const auto &hn : locally_relevant_constraints_hn)
1026 if (constraint_position[std::get<1>(hn)] !=
1028 {
1029 AssertIndexRange(constraint_position[std::get<1>(hn)],
1030 locally_relevant_constraints.size());
1031 auto other = locally_relevant_constraints.begin() +
1032 constraint_position[std::get<1>(hn)];
1033 AssertDimension(std::get<0>(*other), std::get<1>(hn));
1034
1035 for (; other != locally_relevant_constraints.end() &&
1036 std::get<0>(*other) == std::get<1>(hn);
1037 ++other)
1038 locally_relevant_constraints_tmp.emplace_back(
1039 std::get<0>(hn),
1040 std::get<1>(*other),
1041 std::get<2>(hn) * std::get<2>(*other));
1042 }
1043
1044 std::swap(locally_relevant_constraints,
1045 locally_relevant_constraints_tmp);
1046 }
1047 }
1048
1049 // STEP 2d: transpose COO
1050 std::sort(locally_relevant_constraints.begin(),
1051 locally_relevant_constraints.end(),
1052 [](const auto &a, const auto &b) {
1053 if (std::get<1>(a) < std::get<1>(b))
1054 return true;
1055 return (std::get<1>(a) == std::get<1>(b)) &&
1056 (std::get<0>(a) < std::get<0>(b));
1057 });
1058
1059 // STEP 2e: translate COO to CRS
1060 auto &c_pool = c_pools[v];
1061 {
1062 c_pool.row_lid_to_gid.clear();
1063 c_pool.row.clear();
1064 c_pool.row.push_back(0);
1065 c_pool.col.clear();
1066 c_pool.val.clear();
1067
1068 if (locally_relevant_constraints.size() > 0)
1069 c_pool.row_lid_to_gid.emplace_back(
1070 std::get<1>(locally_relevant_constraints.front()));
1071 for (const auto &j : locally_relevant_constraints)
1072 {
1073 if (c_pool.row_lid_to_gid.back() != std::get<1>(j))
1074 {
1075 c_pool.row_lid_to_gid.push_back(std::get<1>(j));
1076 c_pool.row.push_back(c_pool.val.size());
1077 }
1078
1079 c_pool.col.emplace_back(std::get<0>(j));
1080 c_pool.val.emplace_back(std::get<2>(j));
1081 }
1082
1083 if (c_pool.val.size() > 0)
1084 c_pool.row.push_back(c_pool.val.size());
1085
1086 c_pool.inverse_lookup_rows.clear();
1087 c_pool.inverse_lookup_rows.resize(1 + dofs_per_cell);
1088 for (const unsigned int i : c_pool.col)
1089 c_pool.inverse_lookup_rows[1 + i]++;
1090 // transform to offsets
1091 std::partial_sum(c_pool.inverse_lookup_rows.begin(),
1092 c_pool.inverse_lookup_rows.end(),
1093 c_pool.inverse_lookup_rows.begin());
1094 AssertDimension(c_pool.inverse_lookup_rows.back(),
1095 c_pool.col.size());
1096
1097 c_pool.inverse_lookup_origins.resize(c_pool.col.size());
1098 std::fill(inverse_lookup_count.begin(),
1099 inverse_lookup_count.end(),
1100 0u);
1101 for (unsigned int row = 0; row < c_pool.row.size() - 1; ++row)
1102 for (unsigned int col = c_pool.row[row];
1103 col < c_pool.row[row + 1];
1104 ++col)
1105 {
1106 const unsigned int index = c_pool.col[col];
1107 c_pool.inverse_lookup_origins
1108 [c_pool.inverse_lookup_rows[index] +
1109 inverse_lookup_count[index]] = std::make_pair(row, col);
1110 ++inverse_lookup_count[index];
1111 }
1112 }
1113 }
1114
1115 // STEP 3: compute element matrix A_e, apply
1116 // locally-relevant constraints C_e^T * A_e * C_e, and get the
1117 // the diagonal entry
1118 // (C_e^T * A_e * C_e)(i,i)
1119 // or
1120 // C_e^T(i,:) * A_e * C_e(:,i).
1121 //
1122 // Since, we compute the element matrix column-by-column and as a
1123 // result never actually have the full element matrix, we actually
1124 // perform following steps:
1125 // 1) loop over all columns of the element matrix
1126 // a) compute column i
1127 // b) compute for each j (rows of C_e^T):
1128 // (C_e^T(j,:) * A_e(:,i)) * C_e(i,j)
1129 // or
1130 // (C_e^T(j,:) * A_e(:,i)) * C_e^T(j,i)
1131 // This gives a contribution the j-th entry of the
1132 // locally-relevant diagonal and comprises the multiplication
1133 // by the locally-relevant constraint matrix from the left and
1134 // the right. There is no contribution to the j-th vector
1135 // entry if the j-th row of C_e^T is empty or C_e^T(j,i) is
1136 // zero.
1137
1138 // set size locally-relevant diagonal
1139 for (unsigned int v = 0; v < n_lanes_filled; ++v)
1140 diagonals_local_constrained[v].assign(
1141 c_pools[v].row_lid_to_gid.size() *
1142 (n_fe_components == 1 ? n_components : 1),
1143 Number(0.0));
1144
1145 // check if fast path can be taken via FEEvaluation
1146 bool use_fast_path = true;
1147
1148 for (unsigned int v = 0; v < n_lanes_filled; ++v)
1149 {
1150 auto &c_pool = c_pools[v];
1151
1152 for (unsigned int i = 0; i < c_pool.row.size() - 1; ++i)
1153 {
1154 if ((c_pool.row[i + 1] - c_pool.row[i]) > 1)
1155 {
1156 use_fast_path = false;
1157 break;
1158 }
1159 else if (((c_pool.row[i + 1] - c_pool.row[i]) == 1) &&
1160 (c_pool.val[c_pool.row[i]] != 1.0))
1161 {
1162 use_fast_path = false;
1163 break;
1164 }
1165 }
1166
1167 if (use_fast_path == false)
1168 break;
1169 }
1170
1171 this->has_simple_constraints_ = use_fast_path;
1172 }
1173
1174 void
1175 fill_constraint_type_into_map(
1176 const ::internal::MatrixFreeFunctions::compressed_constraint_kind
1177 mask)
1178 {
1179 auto &constraints_hn = locally_relevant_constraints_hn_map[mask];
1180
1181 // assume that we constrain one face, i.e., (fe_degree + 1)^(dim-1)
1182 // unknowns - we might have more or less entries, but this is a good
1183 // first guess
1184 const unsigned int degree =
1185 phi->get_shape_info().data.front().fe_degree;
1186 constraints_hn.reserve(Utilities::pow(degree + 1, dim - 1));
1187
1188 // 1) collect hanging-node constraints for cell assuming
1189 // scalar finite element
1190 values_dofs.resize(dofs_per_component);
1191 std::array<
1193 VectorizedArrayType::size()>
1194 constraint_mask;
1195 constraint_mask.fill(::internal::MatrixFreeFunctions::
1197 constraint_mask[0] = mask;
1198
1199 for (unsigned int i = 0; i < dofs_per_component; ++i)
1200 {
1201 for (unsigned int j = 0; j < dofs_per_component; ++j)
1202 values_dofs[j] = VectorizedArrayType();
1203 values_dofs[i] = Number(1);
1204
1206 dim,
1207 Number,
1208 VectorizedArrayType>::apply(1,
1209 degree,
1210 phi->get_shape_info(),
1211 false,
1212 constraint_mask,
1213 values_dofs.data());
1214
1215 const Number tolerance =
1216 std::max(Number(1e-12),
1217 std::numeric_limits<Number>::epsilon() * 16);
1218 for (unsigned int j = 0; j < dofs_per_component; ++j)
1219 if (std::abs(values_dofs[j][0]) > tolerance &&
1220 (j != i ||
1221 std::abs(values_dofs[j][0] - Number(1)) > tolerance))
1222 constraints_hn.emplace_back(j, i, values_dofs[j][0]);
1223 }
1224
1225 // 2) extend for multiple components
1226 const unsigned int n_hn_constraints = constraints_hn.size();
1227 constraints_hn.resize(n_hn_constraints * n_components);
1228
1229 for (unsigned int c = 1; c < n_components; ++c)
1230 for (unsigned int i = 0; i < n_hn_constraints; ++i)
1231 constraints_hn[c * n_hn_constraints + i] = std::make_tuple(
1232 std::get<0>(constraints_hn[i]) + c * dofs_per_component,
1233 std::get<1>(constraints_hn[i]) + c * dofs_per_component,
1234 std::get<2>(constraints_hn[i]));
1235 }
1236
1237 void
1238 prepare_basis_vector(const unsigned int i)
1239 {
1240 this->i = i;
1241
1242 // compute i-th column of element stiffness matrix:
1243 // this could be simply performed as done at the moment with
1244 // matrix-free operator evaluation applied to a ith-basis vector
1245 VectorizedArrayType *dof_values = phi->begin_dof_values();
1246 for (unsigned int j = 0; j < dofs_per_cell; ++j)
1247 dof_values[j] = VectorizedArrayType();
1248 dof_values[i] = Number(1);
1249 }
1250
1251 void
1252 zero_basis_vector()
1253 {
1254 VectorizedArrayType *dof_values = phi->begin_dof_values();
1255 for (unsigned int j = 0; j < dofs_per_cell; ++j)
1256 dof_values[j] = VectorizedArrayType();
1257 }
1258
1259 void
1260 submit()
1261 {
1262 // if we have a block vector with components with the same DoFHandler,
1263 // we need to figure out which component and which DoF within the
1264 // component are we currently considering
1265 const unsigned int n_fe_components =
1266 phi->get_dof_info().start_components.back();
1267 const unsigned int comp =
1268 n_fe_components == 1 ? i / dofs_per_component : 0;
1269 const unsigned int i_comp =
1270 n_fe_components == 1 ? (i % dofs_per_component) : i;
1271
1272 // apply local constraint matrix from left and from right:
1273 // loop over all rows of transposed constrained matrix
1274 for (unsigned int v = 0; v < n_lanes_filled; ++v)
1275 {
1276 const auto &c_pool = c_pools[v];
1277
1278 for (unsigned int jj = c_pool.inverse_lookup_rows[i_comp];
1279 jj < c_pool.inverse_lookup_rows[i_comp + 1];
1280 ++jj)
1281 {
1282 const unsigned int j = c_pool.inverse_lookup_origins[jj].first;
1283 // apply constraint matrix from the left
1284 Number temp = 0.0;
1285 for (unsigned int k = c_pool.row[j]; k < c_pool.row[j + 1]; ++k)
1286 temp += c_pool.val[k] *
1287 phi->begin_dof_values()[comp * dofs_per_component +
1288 c_pool.col[k]][v];
1289
1290 // apply constraint matrix from the right
1291 diagonals_local_constrained
1292 [v][j + comp * c_pools[v].row_lid_to_gid.size()] +=
1293 temp * c_pool.val[c_pool.inverse_lookup_origins[jj].second];
1294 }
1295 }
1296 }
1297
1298 template <typename VectorType>
1299 inline void
1300 distribute_local_to_global(std::vector<VectorType *> &diagonal_global)
1301 {
1302 // STEP 4: assembly results: add into global vector
1303 const unsigned int n_fe_components =
1304 phi->get_dof_info().start_components.back();
1305
1306 if (n_fe_components == 1)
1307 AssertDimension(diagonal_global.size(), n_components);
1308
1309 for (unsigned int v = 0; v < n_lanes_filled; ++v)
1310 // if we have a block vector with components with the same
1311 // DoFHandler, we need to loop over all components manually and
1312 // need to apply the correct shift
1313 for (unsigned int j = 0; j < c_pools[v].row.size() - 1; ++j)
1314 for (unsigned int comp = 0;
1315 comp < (n_fe_components == 1 ?
1316 static_cast<unsigned int>(n_components) :
1317 1);
1318 ++comp)
1319 if (c_pools[v].row_lid_to_gid[j] != numbers::invalid_unsigned_int)
1321 *diagonal_global[n_fe_components == 1 ? comp : 0],
1322 c_pools[v].row_lid_to_gid[j],
1323 diagonals_local_constrained
1324 [v][j + comp * c_pools[v].row_lid_to_gid.size()]);
1325 }
1326
1327 bool
1328 has_simple_constraints() const
1329 {
1330 return has_simple_constraints_;
1331 }
1332
1333 private:
1334 FEEvaluationType *phi;
1336
1337 unsigned int dofs_per_component;
1338 unsigned int dofs_per_cell;
1339 unsigned int n_components;
1340
1341 unsigned int i;
1342
1343 unsigned int n_lanes_filled;
1344
1345 std::array<internal::LocalCSR<Number>, n_lanes> c_pools;
1346
1347 // local storage: buffer so that we access the global vector once
1348 // note: may be larger then dofs_per_cell in the presence of
1349 // constraints!
1350 std::array<std::vector<Number>, n_lanes> diagonals_local_constrained;
1351
1352 std::map<
1354 std::vector<std::tuple<unsigned int, unsigned int, Number>>>
1355 locally_relevant_constraints_hn_map;
1356
1357 // scratch arrays
1359
1360 std::vector<std::tuple<unsigned int, unsigned int, Number>>
1361 locally_relevant_constraints;
1362 std::vector<std::tuple<unsigned int, unsigned int, Number>>
1363 locally_relevant_constraints_tmp;
1364 std::vector<unsigned int> constraint_position;
1365 std::vector<unsigned char> is_constrained_hn;
1366 std::vector<unsigned int> inverse_lookup_count;
1367
1368 bool has_simple_constraints_;
1369 };
1370
1371 template <bool is_face,
1372 int dim,
1373 typename Number,
1374 typename VectorizedArrayType>
1375 bool
1376 is_fe_nothing(
1378 const std::pair<unsigned int, unsigned int> &range,
1379 const unsigned int dof_handler_index,
1380 const unsigned int quadrature_index,
1381 const unsigned int first_selected_component,
1382 const unsigned int fe_degree,
1383 const unsigned int n_q_points_1d,
1384 const bool is_interior_face = true)
1385 {
1386 const unsigned int static_n_q_points =
1387 is_face ? Utilities::pow(n_q_points_1d, dim - 1) :
1388 Utilities::pow(n_q_points_1d, dim);
1389
1390 const unsigned int active_fe_index =
1391 is_face ?
1392 matrix_free.get_face_active_fe_index(range,
1393 is_interior_face,
1394 dof_handler_index) :
1395 matrix_free.get_cell_active_fe_index(range, dof_handler_index);
1396
1397 const auto init_data = ::internal::
1398 extract_initialization_data<is_face, dim, Number, VectorizedArrayType>(
1399 matrix_free,
1400 dof_handler_index,
1401 first_selected_component,
1402 quadrature_index,
1403 fe_degree,
1404 static_n_q_points,
1405 active_fe_index,
1406 numbers::invalid_unsigned_int /*active_quad_index*/,
1407 numbers::invalid_unsigned_int /*face_type*/);
1408
1409 return init_data.shape_info->dofs_per_component_on_cell == 0;
1410 }
1411
1412
1413
1417 template <int dim,
1418 int fe_degree,
1419 int n_q_points_1d,
1420 int n_components,
1421 typename Number,
1422 typename QuadOperation>
1423 class ComputeDiagonalCellAction
1424 {
1425 public:
1426 ComputeDiagonalCellAction(
1427 const unsigned int dof_handler_index,
1428 const QuadOperation &quad_operation,
1429 const EvaluationFlags::EvaluationFlags evaluation_flags,
1430 const EvaluationFlags::EvaluationFlags integration_flags)
1431 : m_dof_handler_index(dof_handler_index)
1432 , m_quad_operation(quad_operation)
1433 , m_evaluation_flags(evaluation_flags)
1434 , m_integration_flags(integration_flags)
1435 {}
1436
1437 KOKKOS_FUNCTION void
1441 {
1442 Portable::
1443 FEEvaluation<dim, fe_degree, n_q_points_1d, n_components, Number>
1444 fe_eval(data, m_dof_handler_index);
1446 *gpu_data = &data->precomputed_data[m_dof_handler_index];
1447 const int cell = data->cell_index - gpu_data->first_cell;
1448
1449 constexpr int dofs_per_cell = decltype(fe_eval)::tensor_dofs_per_cell;
1450 constexpr int scalar_dofs_per_cell = dofs_per_cell / n_components;
1451 typename decltype(fe_eval)::value_type diagonal[scalar_dofs_per_cell] =
1452 {};
1453 for (unsigned int i = 0; i < dofs_per_cell; ++i)
1454 {
1455 // scalar DoF and component of the i-th unit vector
1456 const unsigned int scalar_dof = i / n_components;
1457 const unsigned int c = i % n_components;
1458
1459 // position of (scalar_dof, c) in local_to_global, which is
1460 // ordered by component
1461 const unsigned int local_index =
1462 scalar_dof + scalar_dofs_per_cell * c;
1463
1464 // Dirichlet constrained DoFs are not written, so their diagonal
1465 // entry need not be computed
1466 if (gpu_data->local_to_global(local_index, cell) ==
1468 continue;
1469
1470 Kokkos::parallel_for(
1471 Kokkos::TeamThreadRange(data->team_member, scalar_dofs_per_cell),
1472 [&](unsigned int j) {
1473 typename decltype(fe_eval)::value_type val = {};
1474
1475 if constexpr (n_components == 1)
1476 {
1477 val = (i == j) ? 1 : 0;
1478 }
1479 else
1480 {
1481 val[c] = (scalar_dof == j) ? 1 : 0;
1482 }
1483
1484 fe_eval.submit_dof_value(val, j);
1485 });
1486
1487 data->team_member.team_barrier();
1488
1489 Portable::internal::
1490 resolve_hanging_nodes<dim, fe_degree, false, Number>(
1491 data->team_member,
1492 gpu_data->constraint_weights,
1493 gpu_data->constraint_mask(cell * n_components + c),
1494 Kokkos::subview(data->shared_data[m_dof_handler_index].values,
1495 Kokkos::ALL,
1496 c));
1497
1498 fe_eval.evaluate(m_evaluation_flags);
1499 data->for_each_quad_point(
1500 [&](const int &q_point) { m_quad_operation(&fe_eval, q_point); });
1501 fe_eval.integrate(m_integration_flags);
1502
1503 Portable::internal::
1504 resolve_hanging_nodes<dim, fe_degree, true, Number>(
1505 data->team_member,
1506 gpu_data->constraint_weights,
1507 gpu_data->constraint_mask(cell * n_components + c),
1508 Kokkos::subview(data->shared_data[m_dof_handler_index].values,
1509 Kokkos::ALL,
1510 c));
1511
1512 Kokkos::single(Kokkos::PerTeam(data->team_member), [&] {
1513 if constexpr (n_components == 1)
1514 diagonal[i] = fe_eval.get_dof_value(i);
1515 else
1516 diagonal[scalar_dof][c] = fe_eval.get_dof_value(scalar_dof)[c];
1517 });
1518
1519 data->team_member.team_barrier();
1520 }
1521
1522 Kokkos::single(Kokkos::PerTeam(data->team_member), [&] {
1523 for (unsigned int i = 0; i < scalar_dofs_per_cell; ++i)
1524 fe_eval.submit_dof_value(diagonal[i], i);
1525 });
1526
1527 data->team_member.team_barrier();
1528
1529 // We need to do the same as distribute_local_to_global but without
1530 // constraints since we have already taken care of them earlier
1531 if (gpu_data->use_coloring)
1532 {
1533 Kokkos::parallel_for(
1534 Kokkos::TeamThreadRange(data->team_member, dofs_per_cell),
1535 [&](const int &i) {
1536 const types::global_dof_index index =
1537 gpu_data->local_to_global(i, cell);
1538 if (index != numbers::invalid_unsigned_int)
1539 dst[index] += data->shared_data[m_dof_handler_index].values(
1540 i % scalar_dofs_per_cell, i / scalar_dofs_per_cell);
1541 });
1542 }
1543 else
1544 {
1545 Kokkos::parallel_for(
1546 Kokkos::TeamThreadRange(data->team_member, dofs_per_cell),
1547 [&](const int &i) {
1548 const types::global_dof_index index =
1549 gpu_data->local_to_global(i, cell);
1550 if (index != numbers::invalid_unsigned_int)
1551 Kokkos::atomic_add(&dst[index],
1552 data->shared_data[m_dof_handler_index]
1553 .values(i % scalar_dofs_per_cell,
1554 i / scalar_dofs_per_cell));
1555 });
1556 }
1557 };
1558
1559 static constexpr unsigned int n_q_points =
1560 ::Utilities::pow(n_q_points_1d, dim);
1561
1562 private:
1563 const unsigned int m_dof_handler_index;
1564 const QuadOperation m_quad_operation;
1565 const EvaluationFlags::EvaluationFlags m_evaluation_flags;
1566 const EvaluationFlags::EvaluationFlags m_integration_flags;
1567 };
1568
1573 template <int dim,
1574 int fe_degree,
1575 int n_q_points_1d,
1576 int n_components,
1577 typename Number,
1578 typename QuadOperation,
1579 typename LocalMatrix,
1580 typename LocalMap>
1581 struct ComputeMatrixCellAction
1582 {
1583 static constexpr unsigned int n_q_points =
1584 Utilities::pow(n_q_points_1d, dim);
1585
1586 unsigned int dof_handler_index;
1587 QuadOperation quad_operation;
1588 EvaluationFlags::EvaluationFlags evaluation_flags;
1589 EvaluationFlags::EvaluationFlags integration_flags;
1590 LocalMatrix matrix;
1591 LocalMap row_map;
1592 LocalMap column_map;
1593
1598 {
1599 Portable::
1600 FEEvaluation<dim, fe_degree, n_q_points_1d, n_components, Number>
1601 phi(data, dof_handler_index);
1602 constexpr unsigned int scalar_dofs =
1603 decltype(phi)::tensor_dofs_per_cell / n_components;
1604 constexpr unsigned int dofs_per_cell =
1605 decltype(phi)::tensor_dofs_per_cell;
1606 const auto &team = data->team_member;
1607 const auto &cell_data = data->precomputed_data[dof_handler_index];
1608 const unsigned int cell = team.league_rank();
1609
1610 // local_to_global is ordered by component, with lexicographic scalar
1611 // DoFs within each component. All team members process each column.
1612 for (unsigned int j = 0; j < dofs_per_cell; ++j)
1613 {
1614 const auto index = cell_data.local_to_global(j, cell);
1615 if (index == numbers::invalid_unsigned_int)
1616 continue;
1617 const unsigned int component = j / scalar_dofs;
1618 Kokkos::parallel_for(
1619 Kokkos::TeamThreadRange(team, scalar_dofs),
1620 [&](const unsigned int i) {
1621 typename decltype(phi)::value_type value = {};
1622 if constexpr (n_components == 1)
1623 value = (i == j) ? Number(1.) : Number();
1624 else
1625 value[component] =
1626 (i == j % scalar_dofs) ? Number(1.) : Number();
1627 phi.submit_dof_value(value, i);
1628 });
1629 team.team_barrier();
1630
1631 Portable::internal::
1632 resolve_hanging_nodes<dim, fe_degree, false, Number>(
1633 team,
1634 cell_data.constraint_weights,
1635 cell_data.constraint_mask(cell * n_components + component),
1636 Kokkos::subview(data->shared_data[dof_handler_index].values,
1637 Kokkos::ALL,
1638 component));
1639
1640 phi.evaluate(evaluation_flags);
1641 data->for_each_quad_point(
1642 [&](const int q) { quad_operation(&phi, q); });
1643 phi.integrate(integration_flags);
1644
1645 // The operator can couple components, so transpose the constraint
1646 // interpolation for every output component.
1647 for (unsigned int c = 0; c < n_components; ++c)
1649 resolve_hanging_nodes<dim, fe_degree, true, Number>(
1650 team,
1651 cell_data.constraint_weights,
1652 cell_data.constraint_mask(cell * n_components + c),
1653 Kokkos::subview(data->shared_data[dof_handler_index].values,
1654 Kokkos::ALL,
1655 c));
1656
1657 const auto column = column_map.getLocalElement(index);
1658 Kokkos::parallel_for(
1659 Kokkos::TeamThreadRange(team, dofs_per_cell),
1660 [&](const unsigned int i) {
1661 const auto row_index = cell_data.local_to_global(i, cell);
1662 if (row_index != numbers::invalid_unsigned_int)
1663 {
1664 const auto row = row_map.getLocalElement(row_index);
1665 const Number value =
1666 data->shared_data[dof_handler_index].values(
1667 i % scalar_dofs, i / scalar_dofs);
1668 matrix.sumIntoValues(row, &column, 1, &value, false, true);
1669 }
1670 });
1671 // Do not overwrite the shared values until this column is read.
1672 team.team_barrier();
1673 }
1674 }
1675 };
1676
1677 } // namespace internal
1678
1679
1680
1681 template <int dim,
1682 int fe_degree,
1683 int n_q_points_1d,
1684 int n_components,
1685 typename Number,
1686 typename MatrixType,
1687 typename QuadOperation>
1688 void
1690 MatrixType &matrix,
1691 const QuadOperation &quad_operation,
1692 EvaluationFlags::EvaluationFlags evaluation_flags,
1693 EvaluationFlags::EvaluationFlags integration_flags,
1694 const unsigned int dof_handler_index,
1695 const unsigned int quadrature_index,
1696 const unsigned int first_selected_component)
1697 {
1698 AssertThrow(quadrature_index == 0, ExcNotImplemented());
1699 AssertThrow(first_selected_component == 0, ExcNotImplemented());
1701 Utilities::MPI::n_mpi_processes(matrix.get_mpi_communicator()) == 1,
1702 ExcMessage("Portable compute_matrix() currently requires a single MPI "
1703 "process."));
1704 static_assert(fe_degree >= 0);
1705 static_assert(n_q_points_1d >= fe_degree + 1);
1706
1708 matrix_free.initialize_dof_vector(dst, dof_handler_index);
1709 AssertDimension(matrix.m(), dst.size());
1710 AssertDimension(matrix.n(), dst.size());
1711 // MatrixFree indices must be global indices for the Tpetra map lookup.
1712 const auto &partitioner =
1713 matrix_free.get_vector_partitioner(dof_handler_index);
1714 AssertThrow(!partitioner || partitioner->locally_owned_size() == dst.size(),
1715 ExcMessage("Portable compute_matrix() requires all DoFs to be "
1716 "locally owned."));
1717
1718 matrix = 0.;
1719 matrix.resume_fill();
1720 {
1721 // Tpetra requires releasing device views before subsequent host access.
1722 const auto local_matrix = matrix.trilinos_matrix().getLocalMatrixDevice();
1723 const auto row_map = matrix.trilinos_matrix().getRowMap()->getLocalMap();
1724 const auto column_map =
1725 matrix.trilinos_matrix().getColMap()->getLocalMap();
1726 internal::ComputeMatrixCellAction<dim,
1727 fe_degree,
1728 n_q_points_1d,
1729 n_components,
1730 Number,
1731 QuadOperation,
1732 decltype(local_matrix),
1733 decltype(row_map)>
1734 cell_action{dof_handler_index,
1735 quad_operation,
1736 evaluation_flags,
1737 integration_flags,
1738 local_matrix,
1739 row_map,
1740 column_map};
1741 matrix_free.cell_loop(cell_action, dst, dst);
1742
1743 // Use MatrixFree's stored constraints, just as compute_diagonal() does.
1744 // The cell action above leaves all entries as 0.
1745 matrix_free.set_constrained_values(Number(1.), dst, dof_handler_index);
1746 const auto constrained = dst.get_values();
1747 Kokkos::parallel_for(
1748 "MatrixFreeTools::compute_matrix constrained diagonal",
1749 Kokkos::RangePolicy<
1750 typename MemorySpace::Default::kokkos_space::execution_space>(
1751 0, dst.locally_owned_size()),
1752 KOKKOS_LAMBDA(const unsigned int i) {
1753 if (constrained[i] != Number())
1754 {
1755 const auto row = row_map.getLocalElement(i);
1756 const auto column = column_map.getLocalElement(i);
1757 const Number one = Number(1.);
1758 local_matrix.replaceValues(row, &column, 1, &one);
1759 }
1760 });
1761 Kokkos::fence();
1762 }
1763 matrix.compress(VectorOperation::add);
1764 }
1765
1766
1767
1768 template <int dim,
1769 int fe_degree,
1770 int n_q_points_1d,
1771 int n_components,
1772 typename Number,
1773 typename MemorySpace,
1774 typename QuadOperation>
1775 void
1777 const Portable::MatrixFree<dim, Number> &matrix_free,
1779 const QuadOperation &quad_operation,
1780 EvaluationFlags::EvaluationFlags evaluation_flags,
1781 EvaluationFlags::EvaluationFlags integration_flags,
1782 const unsigned int dof_handler_index,
1783 const unsigned int quadrature_index,
1784 const unsigned int first_selected_component,
1785 const unsigned int first_vector_component)
1786 {
1787 Assert(quadrature_index == 0, ExcNotImplemented());
1788 Assert(first_selected_component == 0, ExcNotImplemented());
1789 Assert(first_vector_component == 0, ExcNotImplemented());
1790
1791 matrix_free.initialize_dof_vector(diagonal_global, dof_handler_index);
1792
1793
1794 internal::ComputeDiagonalCellAction<dim,
1795 fe_degree,
1796 n_q_points_1d,
1797 n_components,
1798 Number,
1799 QuadOperation>
1800 cell_action(dof_handler_index,
1801 quad_operation,
1802 evaluation_flags,
1803 integration_flags);
1805 matrix_free.cell_loop(cell_action, dummy, diagonal_global);
1806
1807 matrix_free.set_constrained_values(Number(1.),
1808 diagonal_global,
1809 dof_handler_index);
1810 }
1811
1812 template <int dim,
1813 int fe_degree,
1814 int n_q_points_1d,
1815 int n_components,
1816 typename Number,
1817 typename VectorizedArrayType,
1818 typename VectorType>
1819 void
1822 VectorType &diagonal_global,
1823 const std::function<void(FEEvaluation<dim,
1824 fe_degree,
1825 n_q_points_1d,
1826 n_components,
1827 Number,
1828 VectorizedArrayType> &)>
1829 &cell_operation,
1830 const unsigned int dof_handler_index,
1831 const unsigned int quadrature_index,
1832 const unsigned int first_selected_component,
1833 const unsigned int first_vector_component)
1834 {
1835 compute_diagonal<dim,
1836 fe_degree,
1837 n_q_points_1d,
1838 n_components,
1839 Number,
1840 VectorizedArrayType,
1841 VectorType>(matrix_free,
1842 diagonal_global,
1843 cell_operation,
1844 {},
1845 {},
1846 dof_handler_index,
1847 quadrature_index,
1848 first_selected_component,
1849 first_vector_component);
1850 }
1851
1852 template <typename CLASS,
1853 int dim,
1854 int fe_degree,
1855 int n_q_points_1d,
1856 int n_components,
1857 typename Number,
1858 typename VectorizedArrayType,
1859 typename VectorType>
1860 void
1863 VectorType &diagonal_global,
1864 void (CLASS::*cell_operation)(FEEvaluation<dim,
1865 fe_degree,
1866 n_q_points_1d,
1867 n_components,
1868 Number,
1869 VectorizedArrayType> &) const,
1870 const CLASS *owning_class,
1871 const unsigned int dof_handler_index,
1872 const unsigned int quadrature_index,
1873 const unsigned int first_selected_component,
1874 const unsigned int first_vector_component)
1875 {
1876 compute_diagonal<dim,
1877 fe_degree,
1878 n_q_points_1d,
1879 n_components,
1880 Number,
1881 VectorizedArrayType,
1882 VectorType>(
1883 matrix_free,
1884 diagonal_global,
1885 [&](auto &phi) { (owning_class->*cell_operation)(phi); },
1886 dof_handler_index,
1887 quadrature_index,
1888 first_selected_component,
1889 first_vector_component);
1890 }
1891
1892 template <int dim,
1893 int fe_degree,
1894 int n_q_points_1d,
1895 int n_components,
1896 typename Number,
1897 typename VectorizedArrayType,
1898 typename VectorType>
1899 void
1902 VectorType &diagonal_global,
1903 const std::function<void(FEEvaluation<dim,
1904 fe_degree,
1905 n_q_points_1d,
1906 n_components,
1907 Number,
1908 VectorizedArrayType> &)>
1909 &cell_operation,
1910 const std::function<void(FEFaceEvaluation<dim,
1911 fe_degree,
1912 n_q_points_1d,
1913 n_components,
1914 Number,
1915 VectorizedArrayType> &,
1916 FEFaceEvaluation<dim,
1917 fe_degree,
1918 n_q_points_1d,
1919 n_components,
1920 Number,
1921 VectorizedArrayType> &)>
1922 &face_operation,
1923 const std::function<void(FEFaceEvaluation<dim,
1924 fe_degree,
1925 n_q_points_1d,
1926 n_components,
1927 Number,
1928 VectorizedArrayType> &)>
1929 &boundary_operation,
1930 const unsigned int dof_handler_index,
1931 const unsigned int quadrature_index,
1932 const unsigned int first_selected_component,
1933 const unsigned int first_vector_component)
1934 {
1935 std::vector<typename ::internal::BlockVectorSelector<
1936 VectorType,
1937 IsBlockVector<VectorType>::value>::BaseVectorType *>
1938 diagonal_global_components(n_components);
1939
1940 for (unsigned int d = 0; d < n_components; ++d)
1941 diagonal_global_components[d] = ::internal::
1942 BlockVectorSelector<VectorType, IsBlockVector<VectorType>::value>::
1943 get_vector_component(diagonal_global, d + first_vector_component);
1944
1945 const auto &dof_info = matrix_free.get_dof_info(dof_handler_index);
1946
1947 if (dof_info.start_components.back() == 1)
1948 for (unsigned int comp = 0; comp < n_components; ++comp)
1949 {
1950 Assert(diagonal_global_components[comp] != nullptr,
1951 ExcMessage("The finite element underlying this FEEvaluation "
1952 "object is scalar, but you requested " +
1953 std::to_string(n_components) +
1954 " components via the template argument in "
1955 "FEEvaluation. In that case, you must pass an "
1956 "std::vector<VectorType> or a BlockVector to " +
1957 "read_dof_values and distribute_local_to_global."));
1959 *diagonal_global_components[comp], matrix_free, dof_info);
1960 }
1961 else
1962 {
1964 *diagonal_global_components[0], matrix_free, dof_info);
1965 }
1966
1967 using FEEvalType = FEEvaluation<dim,
1968 fe_degree,
1969 n_q_points_1d,
1970 n_components,
1971 Number,
1972 VectorizedArrayType>;
1973
1974 using FEFaceEvalType = FEFaceEvaluation<dim,
1975 fe_degree,
1976 n_q_points_1d,
1977 n_components,
1978 Number,
1979 VectorizedArrayType>;
1980
1981 internal::ComputeMatrixScratchData<dim, VectorizedArrayType, false>
1982 data_cell;
1983
1984 data_cell.dof_numbers = {dof_handler_index};
1985 data_cell.quad_numbers = {quadrature_index};
1986 data_cell.n_components = {n_components};
1987 data_cell.first_selected_components = {first_selected_component};
1988 data_cell.batch_type = {0};
1989
1990 data_cell.op_create =
1991 [&](const std::pair<unsigned int, unsigned int> &range) {
1992 std::vector<
1993 std::unique_ptr<FEEvaluationData<dim, VectorizedArrayType, false>>>
1994 phi;
1995
1996 if (!internal::is_fe_nothing<false>(matrix_free,
1997 range,
1998 dof_handler_index,
1999 quadrature_index,
2000 first_selected_component,
2001 fe_degree,
2002 n_q_points_1d))
2003 phi.emplace_back(
2004 std::make_unique<FEEvalType>(matrix_free,
2005 range,
2006 dof_handler_index,
2007 quadrature_index,
2008 first_selected_component));
2009
2010 return phi;
2011 };
2012
2013 data_cell.op_reinit = [](auto &phi, const unsigned batch) {
2014 if (phi.size() == 1)
2015 static_cast<FEEvalType &>(*phi[0]).reinit(batch);
2016 };
2017
2018 if (cell_operation)
2019 data_cell.op_compute = [&](auto &phi) {
2020 cell_operation(static_cast<FEEvalType &>(*phi[0]));
2021 };
2022
2023 internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2024 data_face;
2025
2026 data_face.dof_numbers = {dof_handler_index, dof_handler_index};
2027 data_face.quad_numbers = {quadrature_index, quadrature_index};
2028 data_face.n_components = {n_components, n_components};
2029 data_face.first_selected_components = {first_selected_component,
2030 first_selected_component};
2031 data_face.batch_type = {1, 2};
2032
2033 data_face.op_create =
2034 [&](const std::pair<unsigned int, unsigned int> &range) {
2035 std::vector<
2036 std::unique_ptr<FEEvaluationData<dim, VectorizedArrayType, true>>>
2037 phi;
2038
2039 if (!internal::is_fe_nothing<true>(matrix_free,
2040 range,
2041 dof_handler_index,
2042 quadrature_index,
2043 first_selected_component,
2044 fe_degree,
2045 n_q_points_1d,
2046 true) &&
2047 !internal::is_fe_nothing<true>(matrix_free,
2048 range,
2049 dof_handler_index,
2050 quadrature_index,
2051 first_selected_component,
2052 fe_degree,
2053 n_q_points_1d,
2054 false))
2055 {
2056 phi.emplace_back(
2057 std::make_unique<FEFaceEvalType>(matrix_free,
2058 range,
2059 true,
2060 dof_handler_index,
2061 quadrature_index,
2062 first_selected_component));
2063 phi.emplace_back(
2064 std::make_unique<FEFaceEvalType>(matrix_free,
2065 range,
2066 false,
2067 dof_handler_index,
2068 quadrature_index,
2069 first_selected_component));
2070 }
2071
2072 return phi;
2073 };
2074
2075 data_face.op_reinit = [](auto &phi, const unsigned batch) {
2076 if (phi.size() == 2)
2077 {
2078 static_cast<FEFaceEvalType &>(*phi[0]).reinit(batch);
2079 static_cast<FEFaceEvalType &>(*phi[1]).reinit(batch);
2080 }
2081 };
2082
2083 if (face_operation)
2084 data_face.op_compute = [&](auto &phi) {
2085 face_operation(static_cast<FEFaceEvalType &>(*phi[0]),
2086 static_cast<FEFaceEvalType &>(*phi[1]));
2087 };
2088
2089 internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2090 data_boundary;
2091
2092 data_boundary.dof_numbers = {dof_handler_index};
2093 data_boundary.quad_numbers = {quadrature_index};
2094 data_boundary.n_components = {n_components};
2095 data_boundary.first_selected_components = {first_selected_component};
2096 data_boundary.batch_type = {1};
2097
2098 data_boundary.op_create =
2099 [&](const std::pair<unsigned int, unsigned int> &range) {
2100 std::vector<
2101 std::unique_ptr<FEEvaluationData<dim, VectorizedArrayType, true>>>
2102 phi;
2103
2104 if (!internal::is_fe_nothing<true>(matrix_free,
2105 range,
2106 dof_handler_index,
2107 quadrature_index,
2108 first_selected_component,
2109 fe_degree,
2110 n_q_points_1d,
2111 true))
2112 phi.emplace_back(
2113 std::make_unique<FEFaceEvalType>(matrix_free,
2114 range,
2115 true,
2116 dof_handler_index,
2117 quadrature_index,
2118 first_selected_component));
2119
2120 return phi;
2121 };
2122
2123 data_boundary.op_reinit = [](auto &phi, const unsigned batch) {
2124 if (phi.size() == 1)
2125 static_cast<FEFaceEvalType &>(*phi[0]).reinit(batch);
2126 };
2127
2128 if (boundary_operation)
2129 data_boundary.op_compute = [&](auto &phi) {
2130 boundary_operation(static_cast<FEFaceEvalType &>(*phi[0]));
2131 };
2132
2133 internal::compute_diagonal(matrix_free,
2134 data_cell,
2135 data_face,
2136 data_boundary,
2137 diagonal_global,
2138 diagonal_global_components);
2139 }
2140
2141 namespace internal
2142 {
2143 template <int dim,
2144 typename Number,
2145 typename VectorizedArrayType,
2146 typename VectorType,
2147 typename VectorType2>
2148 void
2151 const internal::ComputeMatrixScratchData<dim, VectorizedArrayType, false>
2152 &data_cell,
2153 const internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2154 &data_face,
2155 const internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2156 &data_boundary,
2157 VectorType &diagonal_global,
2158 std::vector<VectorType2 *> &diagonal_global_components)
2159 {
2160 // TODO: can we remove diagonal_global_components as argument?
2161
2162 int dummy = 0;
2163
2164 using Helper =
2165 internal::ComputeDiagonalHelper<dim, VectorizedArrayType, false>;
2166
2167 using HelperFace =
2168 internal::ComputeDiagonalHelper<dim, VectorizedArrayType, true>;
2169
2172 scratch_data_internal;
2174
2175 const auto batch_operation =
2176 [&](auto &data,
2177 auto &scratch_data,
2178 const std::pair<unsigned int, unsigned int> &range) {
2179 if (!data.op_compute)
2180 return; // nothing to do
2181
2182 auto phi = data.op_create(range);
2183
2184 const unsigned int n_blocks = phi.size();
2185
2186 auto &helpers = scratch_data.get();
2187 helpers.resize(n_blocks);
2188
2189 for (unsigned int b = 0; b < n_blocks; ++b)
2190 helpers[b].initialize(*phi[b], matrix_free, data.n_components[b]);
2191
2192 for (unsigned int batch = range.first; batch < range.second; ++batch)
2193 {
2194 data.op_reinit(phi, batch);
2195
2196 for (unsigned int b = 0; b < n_blocks; ++b)
2197 helpers[b].reinit(batch);
2198
2199 if (n_blocks > 1)
2200 {
2201 Assert(std::all_of(helpers.begin(),
2202 helpers.end(),
2203 [](const auto &helper) {
2204 return helper.has_simple_constraints();
2205 }),
2207 }
2208
2209 for (unsigned int b = 0; b < n_blocks; ++b)
2210 {
2211 for (unsigned int i = 0;
2212 i < phi[b]->get_shape_info().dofs_per_component_on_cell *
2213 data.n_components[b];
2214 ++i)
2215 {
2216 for (unsigned int bb = 0; bb < n_blocks; ++bb)
2217 if (b == bb)
2218 helpers[bb].prepare_basis_vector(i);
2219 else
2220 helpers[bb].zero_basis_vector();
2221
2222 data.op_compute(phi);
2223 helpers[b].submit();
2224 }
2225
2226 helpers[b].distribute_local_to_global(
2227 diagonal_global_components);
2228 }
2229 }
2230 };
2231
2232 const auto cell_operation_wrapped =
2233 [&](const auto &, auto &, const auto &, const auto range) {
2234 batch_operation(data_cell, scratch_data, range);
2235 };
2236
2237 const auto face_operation_wrapped =
2238 [&](const auto &, auto &, const auto &, const auto range) {
2239 batch_operation(data_face, scratch_data_internal, range);
2240 };
2241
2242 const auto boundary_operation_wrapped =
2243 [&](const auto &, auto &, const auto &, const auto range) {
2244 batch_operation(data_boundary, scratch_data_bc, range);
2245 };
2246
2247 if (data_face.op_compute || data_boundary.op_compute)
2248 matrix_free.template loop<VectorType, int>(cell_operation_wrapped,
2249 face_operation_wrapped,
2250 boundary_operation_wrapped,
2251 diagonal_global,
2252 dummy,
2253 false);
2254 else
2255 matrix_free.template cell_loop<VectorType, int>(cell_operation_wrapped,
2256 diagonal_global,
2257 dummy,
2258 false);
2259 }
2260 } // namespace internal
2261
2262 template <typename CLASS,
2263 int dim,
2264 int fe_degree,
2265 int n_q_points_1d,
2266 int n_components,
2267 typename Number,
2268 typename VectorizedArrayType,
2269 typename VectorType>
2270 void
2273 VectorType &diagonal_global,
2274 void (CLASS::*cell_operation)(FEEvaluation<dim,
2275 fe_degree,
2276 n_q_points_1d,
2277 n_components,
2278 Number,
2279 VectorizedArrayType> &) const,
2280 void (CLASS::*face_operation)(FEFaceEvaluation<dim,
2281 fe_degree,
2282 n_q_points_1d,
2283 n_components,
2284 Number,
2285 VectorizedArrayType> &,
2286 FEFaceEvaluation<dim,
2287 fe_degree,
2288 n_q_points_1d,
2289 n_components,
2290 Number,
2291 VectorizedArrayType> &)
2292 const,
2293 void (CLASS::*boundary_operation)(FEFaceEvaluation<dim,
2294 fe_degree,
2295 n_q_points_1d,
2296 n_components,
2297 Number,
2298 VectorizedArrayType> &)
2299 const,
2300 const CLASS *owning_class,
2301 const unsigned int dof_handler_index,
2302 const unsigned int quadrature_index,
2303 const unsigned int first_selected_component,
2304 const unsigned int first_vector_component)
2305 {
2306 compute_diagonal<dim,
2307 fe_degree,
2308 n_q_points_1d,
2309 n_components,
2310 Number,
2311 VectorizedArrayType,
2312 VectorType>(
2313 matrix_free,
2314 diagonal_global,
2315 [&](auto &phi) { (owning_class->*cell_operation)(phi); },
2316 [&](auto &phi_m, auto &phi_p) {
2317 (owning_class->*face_operation)(phi_m, phi_p);
2318 },
2319 [&](auto &phi) { (owning_class->*boundary_operation)(phi); },
2320 dof_handler_index,
2321 quadrature_index,
2322 first_selected_component,
2323 first_vector_component);
2324 }
2325
2326 namespace internal
2327 {
2332 template <
2333 typename MatrixType,
2334 typename Number,
2335 std::enable_if_t<std::is_same_v<
2336 std::remove_const_t<
2337 std::remove_reference_t<typename MatrixType::value_type>>,
2338 std::remove_const_t<std::remove_reference_t<Number>>>> * = nullptr>
2340 create_new_affine_constraints_if_needed(
2341 const MatrixType &,
2342 const AffineConstraints<Number> &constraints,
2344 {
2345 return constraints;
2346 }
2347
2353 template <
2354 typename MatrixType,
2355 typename Number,
2356 std::enable_if_t<!std::is_same_v<
2357 std::remove_const_t<
2358 std::remove_reference_t<typename MatrixType::value_type>>,
2359 std::remove_const_t<std::remove_reference_t<Number>>>> * = nullptr>
2361 create_new_affine_constraints_if_needed(
2362 const MatrixType &,
2363 const AffineConstraints<Number> &constraints,
2365 &new_constraints)
2366 {
2367 new_constraints =
2368 std::make_unique<AffineConstraints<typename MatrixType::value_type>>();
2369 new_constraints->copy_from(constraints);
2370
2371 return *new_constraints;
2372 }
2373 } // namespace internal
2374
2375 template <int dim,
2376 int fe_degree,
2377 int n_q_points_1d,
2378 int n_components,
2379 typename Number,
2380 typename VectorizedArrayType,
2381 typename MatrixType>
2382 void
2385 const AffineConstraints<Number> &constraints_in,
2386 MatrixType &matrix,
2387 const std::function<void(FEEvaluation<dim,
2388 fe_degree,
2389 n_q_points_1d,
2390 n_components,
2391 Number,
2392 VectorizedArrayType> &)>
2393 &cell_operation,
2394 const unsigned int dof_handler_index,
2395 const unsigned int quadrature_index,
2396 const unsigned int first_selected_component)
2397 {
2398 compute_matrix<dim,
2399 fe_degree,
2400 n_q_points_1d,
2401 n_components,
2402 Number,
2403 VectorizedArrayType,
2404 MatrixType>(matrix_free,
2405 constraints_in,
2406 matrix,
2407 cell_operation,
2408 {},
2409 {},
2410 dof_handler_index,
2411 quadrature_index,
2412 first_selected_component);
2413 }
2414
2415 template <typename CLASS,
2416 int dim,
2417 int fe_degree,
2418 int n_q_points_1d,
2419 int n_components,
2420 typename Number,
2421 typename VectorizedArrayType,
2422 typename MatrixType>
2423 void
2426 const AffineConstraints<Number> &constraints,
2427 MatrixType &matrix,
2428 void (CLASS::*cell_operation)(FEEvaluation<dim,
2429 fe_degree,
2430 n_q_points_1d,
2431 n_components,
2432 Number,
2433 VectorizedArrayType> &) const,
2434 const CLASS *owning_class,
2435 const unsigned int dof_handler_index,
2436 const unsigned int quadrature_index,
2437 const unsigned int first_selected_component)
2438 {
2439 compute_matrix<dim,
2440 fe_degree,
2441 n_q_points_1d,
2442 n_components,
2443 Number,
2444 VectorizedArrayType,
2445 MatrixType>(
2446 matrix_free,
2447 constraints,
2448 matrix,
2449 [&](auto &phi) { (owning_class->*cell_operation)(phi); },
2450 dof_handler_index,
2451 quadrature_index,
2452 first_selected_component);
2453 }
2454
2455 template <int dim,
2456 int fe_degree,
2457 int n_q_points_1d,
2458 int n_components,
2459 typename Number,
2460 typename VectorizedArrayType,
2461 typename MatrixType>
2462 void
2465 const AffineConstraints<Number> &constraints_in,
2466 MatrixType &matrix,
2467 const std::function<void(FEEvaluation<dim,
2468 fe_degree,
2469 n_q_points_1d,
2470 n_components,
2471 Number,
2472 VectorizedArrayType> &)>
2473 &cell_operation,
2474 const std::function<void(FEFaceEvaluation<dim,
2475 fe_degree,
2476 n_q_points_1d,
2477 n_components,
2478 Number,
2479 VectorizedArrayType> &,
2480 FEFaceEvaluation<dim,
2481 fe_degree,
2482 n_q_points_1d,
2483 n_components,
2484 Number,
2485 VectorizedArrayType> &)>
2486 &face_operation,
2487 const std::function<void(FEFaceEvaluation<dim,
2488 fe_degree,
2489 n_q_points_1d,
2490 n_components,
2491 Number,
2492 VectorizedArrayType> &)>
2493 &boundary_operation,
2494 const unsigned int dof_handler_index,
2495 const unsigned int quadrature_index,
2496 const unsigned int first_selected_component)
2497 {
2498 using FEEvalType = FEEvaluation<dim,
2499 fe_degree,
2500 n_q_points_1d,
2501 n_components,
2502 Number,
2503 VectorizedArrayType>;
2504
2505 using FEFaceEvalType = FEFaceEvaluation<dim,
2506 fe_degree,
2507 n_q_points_1d,
2508 n_components,
2509 Number,
2510 VectorizedArrayType>;
2511
2512 internal::ComputeMatrixScratchData<dim, VectorizedArrayType, false>
2513 data_cell;
2514
2515 data_cell.dof_numbers = {dof_handler_index};
2516 data_cell.quad_numbers = {quadrature_index};
2517 data_cell.n_components = {n_components};
2518 data_cell.first_selected_components = {first_selected_component};
2519 data_cell.batch_type = {0};
2520
2521 data_cell.op_create =
2522 [&](const std::pair<unsigned int, unsigned int> &range) {
2523 std::vector<
2524 std::unique_ptr<FEEvaluationData<dim, VectorizedArrayType, false>>>
2525 phi;
2526
2527 if (!internal::is_fe_nothing<false>(matrix_free,
2528 range,
2529 dof_handler_index,
2530 quadrature_index,
2531 first_selected_component,
2532 fe_degree,
2533 n_q_points_1d))
2534 phi.emplace_back(
2535 std::make_unique<FEEvalType>(matrix_free,
2536 range,
2537 dof_handler_index,
2538 quadrature_index,
2539 first_selected_component));
2540
2541 return phi;
2542 };
2543
2544 data_cell.op_reinit = [](auto &phi, const unsigned batch) {
2545 if (phi.size() == 1)
2546 static_cast<FEEvalType &>(*phi[0]).reinit(batch);
2547 };
2548
2549 if (cell_operation)
2550 data_cell.op_compute = [&](auto &phi) {
2551 cell_operation(static_cast<FEEvalType &>(*phi[0]));
2552 };
2553
2554 internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2555 data_face;
2556
2557 data_face.dof_numbers = {dof_handler_index, dof_handler_index};
2558 data_face.quad_numbers = {quadrature_index, quadrature_index};
2559 data_face.n_components = {n_components, n_components};
2560 data_face.first_selected_components = {first_selected_component,
2561 first_selected_component};
2562 data_face.batch_type = {1, 2};
2563
2564 data_face.op_create =
2565 [&](const std::pair<unsigned int, unsigned int> &range) {
2566 std::vector<
2567 std::unique_ptr<FEEvaluationData<dim, VectorizedArrayType, true>>>
2568 phi;
2569
2570 if (!internal::is_fe_nothing<true>(matrix_free,
2571 range,
2572 dof_handler_index,
2573 quadrature_index,
2574 first_selected_component,
2575 fe_degree,
2576 n_q_points_1d,
2577 true) &&
2578 !internal::is_fe_nothing<true>(matrix_free,
2579 range,
2580 dof_handler_index,
2581 quadrature_index,
2582 first_selected_component,
2583 fe_degree,
2584 n_q_points_1d,
2585 false))
2586 {
2587 phi.emplace_back(
2588 std::make_unique<FEFaceEvalType>(matrix_free,
2589 range,
2590 true,
2591 dof_handler_index,
2592 quadrature_index,
2593 first_selected_component));
2594 phi.emplace_back(
2595 std::make_unique<FEFaceEvalType>(matrix_free,
2596 range,
2597 false,
2598 dof_handler_index,
2599 quadrature_index,
2600 first_selected_component));
2601 }
2602
2603 return phi;
2604 };
2605
2606 data_face.op_reinit = [](auto &phi, const unsigned batch) {
2607 if (phi.size() == 2)
2608 {
2609 static_cast<FEFaceEvalType &>(*phi[0]).reinit(batch);
2610 static_cast<FEFaceEvalType &>(*phi[1]).reinit(batch);
2611 }
2612 };
2613
2614 if (face_operation)
2615 data_face.op_compute = [&](auto &phi) {
2616 face_operation(static_cast<FEFaceEvalType &>(*phi[0]),
2617 static_cast<FEFaceEvalType &>(*phi[1]));
2618 };
2619
2620 internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2621 data_boundary;
2622
2623 data_boundary.dof_numbers = {dof_handler_index};
2624 data_boundary.quad_numbers = {quadrature_index};
2625 data_boundary.n_components = {n_components};
2626 data_boundary.first_selected_components = {first_selected_component};
2627 data_boundary.batch_type = {1};
2628
2629 data_boundary.op_create =
2630 [&](const std::pair<unsigned int, unsigned int> &range) {
2631 std::vector<
2632 std::unique_ptr<FEEvaluationData<dim, VectorizedArrayType, true>>>
2633 phi;
2634
2635 if (!internal::is_fe_nothing<true>(matrix_free,
2636 range,
2637 dof_handler_index,
2638 quadrature_index,
2639 first_selected_component,
2640 fe_degree,
2641 n_q_points_1d,
2642 true))
2643 phi.emplace_back(
2644 std::make_unique<FEFaceEvalType>(matrix_free,
2645 range,
2646 true,
2647 dof_handler_index,
2648 quadrature_index,
2649 first_selected_component));
2650
2651 return phi;
2652 };
2653
2654 data_boundary.op_reinit = [](auto &phi, const unsigned batch) {
2655 if (phi.size() == 1)
2656 static_cast<FEFaceEvalType &>(*phi[0]).reinit(batch);
2657 };
2658
2659 if (boundary_operation)
2660 data_boundary.op_compute = [&](auto &phi) {
2661 boundary_operation(static_cast<FEFaceEvalType &>(*phi[0]));
2662 };
2663
2664 internal::compute_matrix(
2665 matrix_free, constraints_in, data_cell, data_face, data_boundary, matrix);
2666 }
2667
2668 namespace internal
2669 {
2670 template <int dim,
2671 typename Number,
2672 typename VectorizedArrayType,
2673 typename MatrixType>
2674 void
2677 const AffineConstraints<Number> &constraints_in,
2678 const internal::ComputeMatrixScratchData<dim, VectorizedArrayType, false>
2679 &data_cell,
2680 const internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2681 &data_face,
2682 const internal::ComputeMatrixScratchData<dim, VectorizedArrayType, true>
2683 &data_boundary,
2684 MatrixType &matrix)
2685 {
2686 std::unique_ptr<AffineConstraints<typename MatrixType::value_type>>
2687 constraints_for_matrix;
2689 internal::create_new_affine_constraints_if_needed(
2690 matrix, constraints_in, constraints_for_matrix);
2691
2692 const auto batch_operation =
2693 [&matrix_free, &constraints, &matrix](
2694 auto &data, const std::pair<unsigned int, unsigned int> &range) {
2695 if (!data.op_compute)
2696 return; // nothing to do
2697
2698 auto phi = data.op_create(range);
2699
2700 const unsigned int n_blocks = phi.size();
2701
2702 if (n_blocks == 0)
2703 return;
2704
2705 Table<1, unsigned int> dofs_per_cell(n_blocks);
2706
2707 Table<1, std::vector<types::global_dof_index>> dof_indices(n_blocks);
2709 n_blocks, VectorizedArrayType::size());
2710 Table<1, std::vector<unsigned int>> lexicographic_numbering(n_blocks);
2711 Table<2,
2712 std::array<FullMatrix<typename MatrixType::value_type>,
2713 VectorizedArrayType::size()>>
2714 matrices(n_blocks, n_blocks);
2715
2716 for (unsigned int b = 0; b < n_blocks; ++b)
2717 {
2718 const auto &fe = matrix_free.get_dof_handler(data.dof_numbers[b])
2719 .get_fe(phi[b]->get_active_fe_index());
2720
2721 const auto component_base =
2722 matrix_free.get_dof_info(data.dof_numbers[b])
2723 .component_to_base_index[data.first_selected_components[b]];
2724 const auto component_in_base =
2725 data.first_selected_components[b] -
2726 matrix_free.get_dof_info(data.dof_numbers[b])
2727 .start_components[component_base];
2728
2729 const auto &shape_info = matrix_free.get_shape_info(
2730 data.dof_numbers[b],
2731 data.quad_numbers[b],
2732 component_base,
2733 phi[b]->get_active_fe_index(),
2734 phi[b]->get_active_quadrature_index());
2735
2736 dofs_per_cell[b] =
2737 shape_info.dofs_per_component_on_cell * data.n_components[b];
2738
2739 dof_indices[b].resize(fe.n_dofs_per_cell());
2740
2741 for (unsigned int v = 0; v < VectorizedArrayType::size(); ++v)
2742 dof_indices_mf[b][v].resize(dofs_per_cell[b]);
2743
2744 lexicographic_numbering[b].insert(
2745 lexicographic_numbering[b].begin(),
2746 shape_info.lexicographic_numbering.begin() +
2747 component_in_base * shape_info.dofs_per_component_on_cell,
2748 shape_info.lexicographic_numbering.begin() +
2749 (component_in_base + data.n_components[b]) *
2750 shape_info.dofs_per_component_on_cell);
2751 }
2752
2753 for (unsigned int bj = 0; bj < n_blocks; ++bj)
2754 for (unsigned int bi = 0; bi < n_blocks; ++bi)
2755 std::fill_n(matrices[bi][bj].begin(),
2756 VectorizedArrayType::size(),
2758 dofs_per_cell[bi], dofs_per_cell[bj]));
2759
2760 for (auto batch = range.first; batch < range.second; ++batch)
2761 {
2762 data.op_reinit(phi, batch);
2763
2764 const unsigned int n_filled_lanes =
2765 data.is_face ?
2766 matrix_free.n_active_entries_per_face_batch(batch) :
2767 matrix_free.n_active_entries_per_cell_batch(batch);
2768
2769 for (unsigned int v = 0; v < n_filled_lanes; ++v)
2770 for (unsigned int b = 0; b < n_blocks; ++b)
2771 {
2772 const unsigned int cell_index =
2773 (data.batch_type[b] == 0) ?
2774 (batch * VectorizedArrayType::size() + v) :
2775 ((data.batch_type[b] == 1) ?
2776 matrix_free.get_face_info(batch).cells_interior[v] :
2777 matrix_free.get_face_info(batch).cells_exterior[v]);
2778
2779 const auto cell_iterator = matrix_free.get_cell_iterator(
2780 cell_index / VectorizedArrayType::size(),
2781 cell_index % VectorizedArrayType::size(),
2782 data.dof_numbers[b]);
2783
2784 if (matrix_free.get_mg_level() !=
2786 cell_iterator->get_mg_dof_indices(dof_indices[b]);
2787 else
2788 cell_iterator->get_dof_indices(dof_indices[b]);
2789
2790 for (unsigned int j = 0; j < dofs_per_cell[b]; ++j)
2791 dof_indices_mf[b][v][j] =
2792 dof_indices[b][lexicographic_numbering[b][j]];
2793 }
2794
2795 for (unsigned int bj = 0; bj < n_blocks; ++bj)
2796 {
2797 for (unsigned int j = 0; j < dofs_per_cell[bj]; ++j)
2798 {
2799 for (unsigned int bi = 0; bi < n_blocks; ++bi)
2800 for (unsigned int i = 0; i < dofs_per_cell[bi]; ++i)
2801 phi[bi]->begin_dof_values()[i] =
2802 (bj == bi) ? static_cast<Number>(i == j) : 0.0;
2803
2804 data.op_compute(phi);
2805
2806 for (unsigned int bi = 0; bi < n_blocks; ++bi)
2807 for (unsigned int i = 0; i < dofs_per_cell[bi]; ++i)
2808 for (unsigned int v = 0; v < n_filled_lanes; ++v)
2809 matrices[bi][bj][v](i, j) =
2810 phi[bi]->begin_dof_values()[i][v];
2811 }
2812
2813 for (unsigned int v = 0; v < n_filled_lanes; ++v)
2814 for (unsigned int bi = 0; bi < n_blocks; ++bi)
2815 if (bi == bj)
2816 // specialization for blocks on the diagonal
2817 // to writing into diagonal elements of the
2818 // matrix if the corresponding degree of freedom
2819 // is constrained, see also the documentation
2820 // of AffineConstraints::distribute_local_to_global()
2821 constraints.distribute_local_to_global(
2822 matrices[bi][bi][v], dof_indices_mf[bi][v], matrix);
2823 else
2824 constraints.distribute_local_to_global(
2825 matrices[bi][bj][v],
2826 dof_indices_mf[bi][v],
2827 dof_indices_mf[bj][v],
2828 matrix);
2829 }
2830 }
2831 };
2832
2833 const auto cell_operation_wrapped =
2834 [&](const auto &, auto &, const auto &, const auto range) {
2835 batch_operation(data_cell, range);
2836 };
2837
2838 const auto face_operation_wrapped =
2839 [&](const auto &, auto &, const auto &, const auto range) {
2840 batch_operation(data_face, range);
2841 };
2842
2843 const auto boundary_operation_wrapped =
2844 [&](const auto &, auto &, const auto &, const auto range) {
2845 batch_operation(data_boundary, range);
2846 };
2847
2848 if (data_face.op_compute || data_boundary.op_compute)
2849 {
2850 matrix_free.template loop<MatrixType, MatrixType>(
2851 cell_operation_wrapped,
2852 face_operation_wrapped,
2853 boundary_operation_wrapped,
2854 matrix,
2855 matrix);
2856 }
2857 else
2858 matrix_free.template cell_loop<MatrixType, MatrixType>(
2859 cell_operation_wrapped, matrix, matrix);
2860
2861 matrix.compress(VectorOperation::add);
2862 }
2863 } // namespace internal
2864
2865 template <typename CLASS,
2866 int dim,
2867 int fe_degree,
2868 int n_q_points_1d,
2869 int n_components,
2870 typename Number,
2871 typename VectorizedArrayType,
2872 typename MatrixType>
2873 void
2876 const AffineConstraints<Number> &constraints,
2877 MatrixType &matrix,
2878 void (CLASS::*cell_operation)(FEEvaluation<dim,
2879 fe_degree,
2880 n_q_points_1d,
2881 n_components,
2882 Number,
2883 VectorizedArrayType> &) const,
2884 void (CLASS::*face_operation)(FEFaceEvaluation<dim,
2885 fe_degree,
2886 n_q_points_1d,
2887 n_components,
2888 Number,
2889 VectorizedArrayType> &,
2890 FEFaceEvaluation<dim,
2891 fe_degree,
2892 n_q_points_1d,
2893 n_components,
2894 Number,
2895 VectorizedArrayType> &)
2896 const,
2897 void (CLASS::*boundary_operation)(FEFaceEvaluation<dim,
2898 fe_degree,
2899 n_q_points_1d,
2900 n_components,
2901 Number,
2902 VectorizedArrayType> &)
2903 const,
2904 const CLASS *owning_class,
2905 const unsigned int dof_handler_index,
2906 const unsigned int quadrature_index,
2907 const unsigned int first_selected_component)
2908 {
2909 compute_matrix<dim,
2910 fe_degree,
2911 n_q_points_1d,
2912 n_components,
2913 Number,
2914 VectorizedArrayType,
2915 MatrixType>(
2916 matrix_free,
2917 constraints,
2918 matrix,
2919 [&](auto &phi) { (owning_class->*cell_operation)(phi); },
2920 [&](auto &phi_m, auto &phi_p) {
2921 (owning_class->*face_operation)(phi_m, phi_p);
2922 },
2923 [&](auto &phi) { (owning_class->*boundary_operation)(phi); },
2924 dof_handler_index,
2925 quadrature_index,
2926 first_selected_component);
2927 }
2928
2929#endif // DOXYGEN
2930
2931} // namespace MatrixFreeTools
2932
2934
2935
2936#endif
*  *  iterator begin()
*  *  Point< dim > operator()(const Point< dim > &p) const * 
***mech_lbc_system increment_interpolation_handlers push_back(scale_z_handler)
void distribute_local_to_global(const InVector &local_vector, const std::vector< size_type > &local_dof_indices, OutVector &global_vector) const
void copy_from(const AffineConstraints< other_number > &other)
size_type locally_owned_size() const
virtual size_type size() const override
void loop(const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, VectorTypeOut &, const VectorTypeIn &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, VectorTypeOut &, const VectorTypeIn &, const std::pair< unsigned int, unsigned int > &)> &face_operation, const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, VectorTypeOut &, const VectorTypeIn &, const std::pair< unsigned int, unsigned int > &, const bool)> &boundary_operation, VectorTypeOut &dst, const VectorTypeIn &src, const bool zero_dst_vector=false) const
Definition tools.h:615
ObserverPointer< const MatrixFree< dim, Number, VectorizedArrayType > > matrix_free
Definition tools.h:682
void cell_loop(const std::function< void(const MatrixFree< dim, Number, VectorizedArrayType > &, VectorTypeOut &, const VectorTypeIn &, const std::pair< unsigned int, unsigned int > &)> &cell_operation, VectorTypeOut &dst, const VectorTypeIn &src, const bool zero_dst_vector=false) const
Definition tools.h:581
void reinit(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const AdditionalData &additional_data=AdditionalData())
Definition tools.h:552
std::vector< unsigned int > n_components
Definition tools.h:47
std::vector< unsigned int > quad_numbers
Definition tools.h:46
std::vector< unsigned int > batch_type
Definition tools.h:49
std::vector< unsigned int > dof_numbers
Definition tools.h:45
std::function< void(std::vector< std::unique_ptr< FEEvalType > > &, const unsigned int)> op_reinit
Definition tools.h:57
std::function< void(std::vector< std::unique_ptr< FEEvalType > > &)> op_compute
Definition tools.h:59
std::function< std::vector< std::unique_ptr< FEEvalType > >(const std::pair< unsigned int, unsigned int > &)> op_create
Definition tools.h:54
std::vector< unsigned int > first_selected_components
Definition tools.h:48
unsigned int n_active_entries_per_cell_batch(const unsigned int cell_batch_index) const
unsigned int get_mg_level() const
void clear()
const internal::MatrixFreeFunctions::DoFInfo & get_dof_info(const unsigned int dof_handler_index_component=0) const
const Number * constraint_pool_begin(const unsigned int pool_index) const
const DoFHandler< dim > & get_dof_handler(const unsigned int dof_handler_index=0) const
DoFHandler< dim >::cell_iterator get_cell_iterator(const unsigned int cell_batch_index, const unsigned int lane_index, const unsigned int dof_handler_index=0) const
unsigned int get_face_active_fe_index(const std::pair< unsigned int, unsigned int > range, const bool is_interior_face=true, const unsigned int dof_handler_index=numbers::invalid_unsigned_int) const
unsigned int get_cell_active_fe_index(const std::pair< unsigned int, unsigned int > range, const unsigned int dof_handler_index=numbers::invalid_unsigned_int) const
const Number * constraint_pool_end(const unsigned int pool_index) const
unsigned int n_active_entries_per_face_batch(const unsigned int face_batch_index) const
const internal::MatrixFreeFunctions::ShapeInfo< Number > & get_shape_info(const unsigned int dof_handler_index_component=0, const unsigned int quad_index=0, const unsigned int fe_base_element=0, const unsigned int hp_active_fe_index=0, const unsigned int hp_active_quad_index=0) const
void initialize_dof_vector(LinearAlgebra::distributed::Vector< Number, MemorySpaceType > &vec, const unsigned int dof_handler_index=0) const
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_vector_partitioner(const unsigned int dof_handler_index=0) const
void set_constrained_values(const Number value, VectorType &dst, const unsigned int dof_handler_index=0) const
void cell_loop(const Functor &func, const VectorType &src, VectorType &dst) const
A class that provides a separate storage location on each thread that accesses the object.
cell_iterator begin(const unsigned int level=0) const
unsigned int n_active_cells() const
cell_iterator end() const
virtual std::vector< types::boundary_id > get_boundary_ids() const
active_cell_iterator begin_active(const unsigned int level=0) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_HOST_DEVICE
Definition config.h:171
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
unsigned int level
Definition grid_out.cc:4642
unsigned int cell_index
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
void cell_action(IteratorType cell, DoFInfoBox< dim, DOFINFO > &dof_info, INFOBOX &info, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &cell_worker, const std::function< void(DOFINFO &, typename INFOBOX::CellInfo &)> &boundary_worker, const std::function< void(DOFINFO &, DOFINFO &, typename INFOBOX::CellInfo &, typename INFOBOX::CellInfo &)> &face_worker, const LoopControl &loop_control)
Definition loop.h:314
std::vector< index_type > data
Definition mpi.cc:734
std::size_t size
Definition mpi.cc:733
EvaluationFlags
The EvaluationFlags enum.
@ matrix
Contents is actually a matrix.
constexpr types::blas_int one
Tpetra::Vector< Number, LO, GO, NodeType< MemorySpace > > VectorType
Tpetra::CrsMatrix< Number, LO, GO, NodeType< MemorySpace > > MatrixType
std::enable_if_t< IsBlockVector< VectorType >::value, unsigned int > n_blocks(const VectorType &vector)
Definition operators.h:47
void compute_diagonal(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const internal::ComputeMatrixScratchData< dim, VectorizedArrayType, false > &data_cell, const internal::ComputeMatrixScratchData< dim, VectorizedArrayType, true > &data_face, const internal::ComputeMatrixScratchData< dim, VectorizedArrayType, true > &data_boundary, VectorType &diagonal_global, std::vector< VectorType2 * > &diagonal_global_components)
void compute_matrix(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const AffineConstraints< Number > &constraints, const internal::ComputeMatrixScratchData< dim, VectorizedArrayType, false > &cell_operation, const internal::ComputeMatrixScratchData< dim, VectorizedArrayType, true > &face_operation, const internal::ComputeMatrixScratchData< dim, VectorizedArrayType, true > &boundary_operation, MatrixType &matrix)
void compute_matrix(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, const AffineConstraints< Number > &constraints, MatrixType &matrix, const std::function< void(FEEvaluation< dim, fe_degree, n_q_points_1d, n_components, Number, VectorizedArrayType > &)> &cell_operation, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0)
void compute_diagonal(const MatrixFree< dim, Number, VectorizedArrayType > &matrix_free, VectorType &diagonal_global, const std::function< void(FEEvaluation< dim, fe_degree, n_q_points_1d, n_components, Number, VectorizedArrayType > &)> &cell_operation, const unsigned int dof_handler_index=0, const unsigned int quadrature_index=0, const unsigned int first_selected_component=0, const unsigned int first_vector_component=0)
void categorize_by_boundary_ids(const Triangulation< dim > &tria, AdditionalData &additional_data)
SymmetricTensor< 2, dim, Number > b(const Tensor< 2, dim, Number > &F)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
*  *  *  ScaleZFunction< dim, Number, components >::ScaleZFunction *  component(component)
*  *  if(update_pressure &update_flags) *  compute_pressure(constitutive_request
*  *  *  RotationFunction< dim, Number >::RotationFunction Number(dim)
*  *  *  *  std::vector< Number > ThermoPlasticMaterial< dim, ViscoplasticYieldLaw, Number >::get_state_parameters   const
void resolve_hanging_nodes(const Kokkos::TeamPolicy< MemorySpace::Default::kokkos_space::execution_space >::member_type &team_member, Kokkos::View< Number *, MemorySpace::Default::kokkos_space > constraint_weights, const ::internal::MatrixFreeFunctions::ConstraintKinds constraint_mask, ViewType values)
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > DeviceVector
unsigned int n_mpi_processes(const MPI_Comm mpi_communicator)
Definition mpi.cc:103
constexpr T pow(const T base, const int iexp)
Definition utilities.h:966
std::uint8_t compressed_constraint_kind
Definition dof_info.h:84
constexpr compressed_constraint_kind unconstrained_compressed_constraint_kind
void vector_access_add(VectorType &vec, const unsigned int entry, const typename VectorType::value_type &val)
void reinit(MatrixBlock< MatrixType > &v, const BlockSparsityPattern &p)
void check_vector_compatibility(const VectorType &vec, const MatrixFree< dim, Number, VectorizedArrayType > &, const internal::MatrixFreeFunctions::DoFInfo &dof_info)
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
STL namespace.
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
::VectorizedArray< Number, width > pow(const ::VectorizedArray< Number, width > &, const Number p)
::VectorizedArray< Number, width > abs(const ::VectorizedArray< Number, width > &)
Kokkos::View< Number *, MemorySpace::Default::kokkos_space > constraint_weights
Kokkos::View<::internal::MatrixFreeFunctions::ConstraintKinds *, MemorySpace::Default::kokkos_space > constraint_mask
Kokkos::View< types::global_dof_index **, MemorySpace::Default::kokkos_space > local_to_global
std::vector< unsigned int > component_to_base_index
Definition dof_info.h:686
std::vector< unsigned int > start_components
Definition dof_info.h:680