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
dof_info.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) 2020 - 2025 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
17
19
22
23#include <deal.II/matrix_free/dof_info.templates.h>
25
26#include <iostream>
27
29
30namespace internal
31{
32 namespace MatrixFreeFunctions
33 {
34 // ensure that the type defined in both dof_info.h and
35 // hanging_nodes_internal.h is consistent
36 static_assert(std::is_same_v<compressed_constraint_kind, std::uint8_t>,
37 "Unexpected type for compressed hanging node indicators!");
38
39
40
42 {
43 clear();
44 }
45
46
47
48 void
50 {
51 row_starts.clear();
52 dof_indices.clear();
54 vector_partitioner.reset();
55 ghost_dofs.clear();
56 dofs_per_cell.clear();
57 dofs_per_face.clear();
61 n_components.clear();
62 start_components.clear();
64 plain_dof_indices.clear();
66 for (unsigned int i = 0; i < 3; ++i)
67 {
68 index_storage_variants[i].clear();
69 dof_indices_contiguous[i].clear();
72 }
73 store_plain_indices = false;
76 max_fe_index = 0;
77 fe_index_conversion.clear();
78 }
79
80
81
82 void
83 DoFInfo::get_dof_indices_on_cell_batch(std::vector<unsigned int> &my_rows,
84 const unsigned int cell,
85 const bool apply_constraints) const
86 {
87 const unsigned int n_fe_components = start_components.back();
88 const unsigned int fe_index =
89 dofs_per_cell.size() == 1 ? 0 : cell_active_fe_index[cell];
90 const unsigned int dofs_this_cell = dofs_per_cell[fe_index];
91
92 const unsigned int n_vectorization = vectorization_length;
93 constexpr auto dof_access_index = dof_access_cell;
95 n_vectorization_lanes_filled[dof_access_index].size());
96 const unsigned int n_vectorization_actual =
97 n_vectorization_lanes_filled[dof_access_index][cell];
98
99 // we might have constraints, so the final number
100 // of indices is not known a priori.
101 // conservatively reserve the maximum without constraints
102 my_rows.reserve(n_vectorization * dofs_this_cell);
103 my_rows.resize(0);
104 unsigned int total_size = 0;
105 for (unsigned int v = 0; v < n_vectorization_actual; ++v)
106 {
107 const unsigned int ib =
108 (cell * n_vectorization + v) * n_fe_components;
109 const unsigned int ie =
110 (cell * n_vectorization + v + 1) * n_fe_components;
111
112 auto do_copy = [&](const unsigned int *begin,
113 const unsigned int *end) {
114 const unsigned int shift = total_size;
115 total_size += (end - begin);
116 my_rows.resize(total_size);
117 std::copy(begin, end, my_rows.begin() + shift);
118 };
119
120 // figure out whether the plain indices should be read by checking
121 // the respective entry in the row_starts_plain_indices
122 if (apply_constraints ||
123 row_starts_plain_indices[cell * n_vectorization + v] ==
125 {
126 const unsigned int *begin =
127 dof_indices.data() + row_starts[ib].first;
128 const unsigned int *end =
129 dof_indices.data() + row_starts[ie].first;
130 do_copy(begin, end);
131 }
132 else
133 {
134 const unsigned int *begin =
135 plain_dof_indices.data() +
136 row_starts_plain_indices[cell * n_vectorization + v];
137 const unsigned int *end = begin + dofs_this_cell;
138 do_copy(begin, end);
139 }
140 }
141 }
142
143
144
145 void
146 DoFInfo::assign_ghosts(const std::vector<unsigned int> &boundary_cells,
147 const MPI_Comm communicator_sm,
148 const bool use_vector_data_exchanger_full)
149 {
150 Assert(boundary_cells.size() < row_starts.size(), ExcInternalError());
151
152 // sort ghost dofs and compress out duplicates
153 const unsigned int n_owned = (vector_partitioner->local_range().second -
154 vector_partitioner->local_range().first);
155 const std::size_t n_ghosts = ghost_dofs.size();
156 if constexpr (running_in_debug_mode())
157 {
158 for (const auto dof_index : dof_indices)
159 if (dof_index != numbers::invalid_unsigned_int)
160 AssertIndexRange(dof_index, n_owned + n_ghosts);
161 }
162
163 const unsigned int n_components = start_components.back();
164 std::vector<unsigned int> ghost_numbering(n_ghosts);
165 IndexSet ghost_indices(vector_partitioner->size());
166 if (n_ghosts > 0)
167 {
168 unsigned int n_unique_ghosts = 0;
169 // since we need to go back to the local_to_global indices and
170 // replace the temporary numbering of ghosts by the real number in
171 // the index set, we need to store these values
172 std::vector<std::pair<types::global_dof_index, unsigned int>>
173 ghost_origin(n_ghosts);
174 for (std::size_t i = 0; i < n_ghosts; ++i)
175 {
176 ghost_origin[i].first = ghost_dofs[i];
177 ghost_origin[i].second = i;
178 }
179 std::sort(ghost_origin.begin(), ghost_origin.end());
180
181 types::global_dof_index last_contiguous_start = ghost_origin[0].first;
182 ghost_numbering[ghost_origin[0].second] = 0;
183 for (std::size_t i = 1; i < n_ghosts; ++i)
184 {
185 if (ghost_origin[i].first > ghost_origin[i - 1].first + 1)
186 {
187 ghost_indices.add_range(last_contiguous_start,
188 ghost_origin[i - 1].first + 1);
189 last_contiguous_start = ghost_origin[i].first;
190 }
191 if (ghost_origin[i].first > ghost_origin[i - 1].first)
192 ++n_unique_ghosts;
193 ghost_numbering[ghost_origin[i].second] = n_unique_ghosts;
194 }
195 ++n_unique_ghosts;
196 ghost_indices.add_range(last_contiguous_start,
197 ghost_origin.back().first + 1);
198 ghost_indices.compress();
199
200 // make sure that we got the correct local numbering of the ghost
201 // dofs. the ghost index set should store the same number
202 {
203 AssertDimension(n_unique_ghosts, ghost_indices.n_elements());
204 for (std::size_t i = 0; i < n_ghosts; ++i)
205 Assert(ghost_numbering[i] ==
206 ghost_indices.index_within_set(ghost_dofs[i]),
208 }
209
210 // apply correct numbering for ghost indices: We previously just
211 // enumerated them according to their appearance in the
212 // local_to_global structure. Above, we derived a relation between
213 // this enumeration and the actual number
214 const unsigned int n_boundary_cells = boundary_cells.size();
215 for (unsigned int i = 0; i < n_boundary_cells; ++i)
216 {
217 unsigned int *data_ptr =
218 dof_indices.data() +
219 row_starts[boundary_cells[i] * n_components].first;
220 const unsigned int *row_end =
221 dof_indices.data() +
222 row_starts[(boundary_cells[i] + 1) * n_components].first;
223 for (; data_ptr != row_end; ++data_ptr)
224 *data_ptr = ((*data_ptr < n_owned ||
225 *data_ptr == numbers::invalid_unsigned_int) ?
226 *data_ptr :
227 n_owned + ghost_numbering[*data_ptr - n_owned]);
228
229 // now the same procedure for plain indices
230 if (store_plain_indices == true &&
231 row_starts_plain_indices[boundary_cells[i]] !=
233 {
234 const unsigned int fe_index =
235 (cell_active_fe_index.empty() ||
236 dofs_per_cell.size() == 1) ?
237 0 :
238 cell_active_fe_index[boundary_cells[i]];
239 AssertIndexRange(fe_index, dofs_per_cell.size());
240
241 unsigned int *data_ptr =
242 plain_dof_indices.data() +
243 row_starts_plain_indices[boundary_cells[i]];
244 const unsigned int *row_end =
245 data_ptr + dofs_per_cell[fe_index];
246 for (; data_ptr != row_end; ++data_ptr)
247 *data_ptr =
248 ((*data_ptr < n_owned) ?
249 *data_ptr :
250 n_owned + ghost_numbering[*data_ptr - n_owned]);
251 }
252 }
253 }
254
255 std::vector<types::global_dof_index> empty;
256 ghost_dofs.swap(empty);
257
258 // set the ghost indices now. need to cast away constness here, but that
259 // is uncritical since we reset the Partitioner in the same initialize
260 // call as this call here.
263 vec_part->set_ghost_indices(ghost_indices);
264
265 if (use_vector_data_exchanger_full == false)
266 vector_exchanger = std::make_shared<
269 else
271 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
272 vector_partitioner, communicator_sm);
273 }
274
275
276
277 void
279 const TaskInfo &task_info,
280 const std::vector<unsigned int> &renumbering,
281 const std::vector<unsigned int> &constraint_pool_row_index,
282 const std::vector<unsigned char> &irregular_cells)
283 {
284 // first reorder the active FE index.
285 const bool have_hp = dofs_per_cell.size() > 1;
286 if (cell_active_fe_index.size() > 0)
287 {
288 std::vector<unsigned int> new_active_fe_index;
289 new_active_fe_index.reserve(task_info.cell_partition_data.back());
290 unsigned int position_cell = 0;
291 for (unsigned int cell = 0;
292 cell < task_info.cell_partition_data.back();
293 ++cell)
294 {
295 const unsigned int n_comp =
296 (irregular_cells[cell] > 0 ? irregular_cells[cell] :
298
299 // take maximum FE index among the ones present (we might have
300 // lumped some lower indices into higher ones)
301 unsigned int fe_index =
302 cell_active_fe_index[renumbering[position_cell]];
303 for (unsigned int j = 1; j < n_comp; ++j)
304 fe_index = std::max(
305 fe_index,
306 cell_active_fe_index[renumbering[position_cell + j]]);
307
308 new_active_fe_index.push_back(fe_index);
309 position_cell += n_comp;
310 }
311 std::swap(new_active_fe_index, cell_active_fe_index);
312 }
313 if (have_hp)
315 task_info.cell_partition_data.back());
316
317 const unsigned int n_components = start_components.back();
318
319 std::vector<std::pair<unsigned int, unsigned int>> new_row_starts(
321 task_info.cell_partition_data.back() +
322 1);
323 std::vector<unsigned int> new_dof_indices;
324 std::vector<std::pair<unsigned short, unsigned short>>
325 new_constraint_indicator;
326 std::vector<unsigned int> new_plain_indices, new_rowstart_plain;
327 unsigned int position_cell = 0;
328 new_dof_indices.reserve(dof_indices.size());
329 new_constraint_indicator.reserve(constraint_indicator.size());
330
331 std::vector<compressed_constraint_kind> new_hanging_node_constraint_masks;
332 new_hanging_node_constraint_masks.reserve(
334
335 std::vector<unsigned char> new_face_dof_sign_change_masks;
336 new_face_dof_sign_change_masks.reserve(face_dof_sign_change_masks.size());
337
339 {
340 new_rowstart_plain.resize(vectorization_length *
341 task_info.cell_partition_data.back(),
343 new_plain_indices.reserve(plain_dof_indices.size());
344 }
345
346 // copy the indices and the constraint indicators to the new data field,
347 // where we will go through the cells in the renumbered way. in case the
348 // vectorization length does not exactly match up, we fill invalid
349 // numbers to the rowstart data. for contiguous cell indices, we skip
350 // the rowstarts field completely and directly go into the
351 // new_dof_indices field (this layout is used in FEEvaluation).
352 for (unsigned int i = 0; i < task_info.cell_partition_data.back(); ++i)
353 {
354 const unsigned int n_lanes_filled =
355 (irregular_cells[i] > 0 ? irregular_cells[i] :
357 const unsigned int dofs_per_cell =
358 have_hp ? this->dofs_per_cell[cell_active_fe_index[i]] :
359 this->dofs_per_cell[0];
360
361 for (unsigned int j = 0; j < n_lanes_filled; ++j)
362 {
363 const unsigned int cell_no = renumbering[position_cell + j];
364
365 if (!hanging_node_constraint_masks.empty() &&
367 new_hanging_node_constraint_masks.push_back(
369
370 if (!face_dof_sign_change_masks.empty())
371 new_face_dof_sign_change_masks.push_back(
373
374 for (unsigned int comp = 0; comp < n_components; ++comp)
375 {
376 new_row_starts[(i * vectorization_length + j) * n_components +
377 comp]
378 .first = new_dof_indices.size();
379 new_row_starts[(i * vectorization_length + j) * n_components +
380 comp]
381 .second = new_constraint_indicator.size();
382
383 const unsigned int idx = cell_no * n_components + comp;
384 new_dof_indices.insert(new_dof_indices.end(),
385 dof_indices.data() +
386 row_starts[idx].first,
387 dof_indices.data() +
388 row_starts[idx + 1].first);
389 for (unsigned int index = row_starts[idx].second;
390 index != row_starts[idx + 1].second;
391 ++index)
392 new_constraint_indicator.push_back(
394 }
395
398 {
399 new_rowstart_plain[i * vectorization_length + j] =
400 new_plain_indices.size();
401 new_plain_indices.insert(new_plain_indices.end(),
402 plain_dof_indices.data() +
404 plain_dof_indices.data() +
405 row_starts_plain_indices[cell_no] +
407 }
408 }
409 for (unsigned int j = n_lanes_filled; j < vectorization_length; ++j)
410 for (unsigned int comp = 0; comp < n_components; ++comp)
411 {
412 new_row_starts[(i * vectorization_length + j) * n_components +
413 comp]
414 .first = new_dof_indices.size();
415 new_row_starts[(i * vectorization_length + j) * n_components +
416 comp]
417 .second = new_constraint_indicator.size();
418 }
419
420 for (unsigned int j = n_lanes_filled; j < vectorization_length; ++j)
421 if (hanging_node_constraint_masks.size() > 0)
422 new_hanging_node_constraint_masks.push_back(
424
425 for (unsigned int j = n_lanes_filled; j < vectorization_length; ++j)
426 if (!face_dof_sign_change_masks.empty())
427 new_face_dof_sign_change_masks.push_back(0);
428
429 position_cell += n_lanes_filled;
430 }
431 AssertDimension(position_cell * n_components + 1, row_starts.size());
432
433 AssertDimension(dof_indices.size(), new_dof_indices.size());
434 new_row_starts[task_info.cell_partition_data.back() *
436 .first = new_dof_indices.size();
437 new_row_starts[task_info.cell_partition_data.back() *
439 .second = new_constraint_indicator.size();
440
442 new_constraint_indicator.size());
443
444 new_row_starts.swap(row_starts);
445 new_dof_indices.swap(dof_indices);
446 new_constraint_indicator.swap(constraint_indicator);
447 new_plain_indices.swap(plain_dof_indices);
448 new_rowstart_plain.swap(row_starts_plain_indices);
449 new_hanging_node_constraint_masks.swap(hanging_node_constraint_masks);
450 new_face_dof_sign_change_masks.swap(face_dof_sign_change_masks);
451
452 if constexpr (running_in_debug_mode())
453 {
454 // sanity check 1: all indices should be smaller than the number of
455 // dofs locally owned plus the number of ghosts
456 const unsigned int index_range =
457 (vector_partitioner->local_range().second -
458 vector_partitioner->local_range().first) +
459 vector_partitioner->ghost_indices().n_elements();
460 for (const auto dof_index : dof_indices)
461 if (dof_index != numbers::invalid_unsigned_int)
462 AssertIndexRange(dof_index, index_range);
463
464 // sanity check 2: for the constraint indicators, the first index
465 // should be smaller than the number of indices in the row, and the
466 // second index should be smaller than the number of constraints in
467 // the constraint pool.
468 for (unsigned int row = 0; row < task_info.cell_partition_data.back();
469 ++row)
470 {
471 const unsigned int row_length_ind =
473 .first -
477 .second,
478 constraint_indicator.size() + 1);
479 const std::pair<unsigned short, unsigned short>
480 *con_it =
481 constraint_indicator.data() +
483 *end_con =
484 constraint_indicator.data() +
486 .second;
487 for (; con_it != end_con; ++con_it)
488 {
489 AssertIndexRange(con_it->first, row_length_ind + 1);
490 AssertIndexRange(con_it->second,
491 constraint_pool_row_index.size() - 1);
492 }
493 }
494
495 // sanity check 3: check the number of cells once again
496 unsigned int n_active_cells = 0;
497 for (unsigned int c = 0;
498 c < *(task_info.cell_partition_data.end() - 2);
499 ++c)
500 if (irregular_cells[c] > 0)
501 n_active_cells += irregular_cells[c];
502 else
503 n_active_cells += vectorization_length;
504 AssertDimension(n_active_cells, task_info.n_active_cells);
505 }
506
507 compute_cell_index_compression(irregular_cells);
508 }
509
510
511
512 void
514 const std::vector<unsigned char> &irregular_cells)
515 {
516 const bool have_hp = dofs_per_cell.size() > 1;
517 const unsigned int n_components = start_components.back();
518
520 row_starts.size() % vectorization_length == 1,
522 if (vectorization_length > 1)
524 irregular_cells.size());
526 irregular_cells.size(), IndexStorageVariants::full);
528 irregular_cells.size());
529 for (unsigned int i = 0; i < irregular_cells.size(); ++i)
530 if (irregular_cells[i] > 0)
531 n_vectorization_lanes_filled[dof_access_cell][i] = irregular_cells[i];
532 else
535
537 irregular_cells.size() * vectorization_length,
542 irregular_cells.size() * vectorization_length,
544
545 std::vector<unsigned int> index_kinds(
546 static_cast<unsigned int>(
548 1);
549 std::vector<unsigned int> offsets(vectorization_length);
550 for (unsigned int i = 0; i < irregular_cells.size(); ++i)
551 {
552 const unsigned int ndofs =
553 dofs_per_cell[have_hp ? cell_active_fe_index[i] : 0];
554 const unsigned int n_lanes_filled =
556
557 // check 1: Check if there are constraints -> no compression possible
558 bool has_constraints = false;
559 for (unsigned int j = 0; j < n_lanes_filled; ++j)
560 {
561 const unsigned int cell_no = i * vectorization_length + j;
562 if (row_starts[cell_no * n_components].second !=
563 row_starts[(cell_no + 1) * n_components].second)
564 {
565 has_constraints = true;
566 break;
567 }
568 }
569 if (has_constraints)
572 else
573 {
574 bool indices_are_contiguous = (ndofs > 0);
575 for (unsigned int j = 0; j < n_lanes_filled; ++j)
576 {
577 const unsigned int cell_no = i * vectorization_length + j;
578 const unsigned int *dof_indices =
579 this->dof_indices.data() +
580 row_starts[cell_no * n_components].first;
582 ndofs,
583 row_starts[(cell_no + 1) * n_components].first -
584 row_starts[cell_no * n_components].first);
585 if (ndofs == 0 ||
587 {
588 indices_are_contiguous = false;
589 break;
590 }
591 for (unsigned int i = 1; i < ndofs; ++i)
593 dof_indices[i] != dof_indices[0] + i)
594 {
595 indices_are_contiguous = false;
596 break;
597 }
598 }
599
600 bool indices_are_interleaved_and_contiguous =
601 (ndofs > 1 && n_lanes_filled == vectorization_length);
602
603 {
604 const unsigned int *dof_indices =
605 this->dof_indices.data() +
607 for (unsigned int k = 0;
608 k < ndofs && indices_are_interleaved_and_contiguous;
609 ++k)
610 for (unsigned int j = 0; j < n_lanes_filled; ++j)
611 if (dof_indices[j * ndofs + k] ==
613 dof_indices[j * ndofs + k] !=
614 dof_indices[0] + k * n_lanes_filled + j)
615 {
616 indices_are_interleaved_and_contiguous = false;
617 break;
618 }
619 }
620
621 if (indices_are_contiguous ||
622 indices_are_interleaved_and_contiguous)
623 {
624 for (unsigned int j = 0; j < n_lanes_filled; ++j)
625 {
626 const unsigned int start_index =
629 .first;
630 AssertIndexRange(start_index, dof_indices.size());
632 [i * vectorization_length + j] =
633 this->dof_indices.empty() ?
634 0 :
635 this->dof_indices[start_index];
636 }
637 }
638
639 if (indices_are_interleaved_and_contiguous)
640 {
641 Assert(n_lanes_filled == vectorization_length,
645 for (unsigned int j = 0; j < n_lanes_filled; ++j)
647 j] = n_lanes_filled;
648 }
649 else if (indices_are_contiguous)
650 {
653 for (unsigned int j = 0; j < n_lanes_filled; ++j)
655 j] = 1;
656 }
657 else if (ndofs > 0)
658 {
659 int indices_are_interleaved_and_mixed = 2;
660 const unsigned int *dof_indices =
661 &this->dof_indices[row_starts[i * vectorization_length *
663 .first];
664 for (unsigned int j = 0; j < n_lanes_filled; ++j)
665 offsets[j] =
666 dof_indices[j * ndofs + 1] - dof_indices[j * ndofs];
667 for (unsigned int k = 0;
668 k < ndofs && indices_are_interleaved_and_mixed != 0;
669 ++k)
670 for (unsigned int j = 0; j < n_lanes_filled; ++j)
671 // the first if case is to avoid negative offsets
672 // (invalid)
673 if (dof_indices[j * ndofs + k] ==
675 dof_indices[j * ndofs + 1] < dof_indices[j * ndofs] ||
676 dof_indices[j * ndofs + k] !=
677 dof_indices[j * ndofs] + k * offsets[j])
678 {
679 indices_are_interleaved_and_mixed = 0;
680 break;
681 }
682 if (indices_are_interleaved_and_mixed == 2)
683 {
684 for (unsigned int j = 0; j < n_lanes_filled; ++j)
687 offsets[j];
688 for (unsigned int j = 0; j < n_lanes_filled; ++j)
690 [i * vectorization_length + j] =
691 dof_indices[j * ndofs];
692 for (unsigned int j = 0; j < n_lanes_filled; ++j)
693 if (offsets[j] != vectorization_length)
694 {
695 indices_are_interleaved_and_mixed = 1;
696 break;
697 }
698 if (indices_are_interleaved_and_mixed == 1 ||
699 n_lanes_filled != vectorization_length)
703 else
706 }
707 else
708 {
709 if (n_lanes_filled == vectorization_length)
712 else
715 }
716 }
717 else // ndofs == 0
720 }
721 index_kinds[static_cast<unsigned int>(
723 }
724
725 // Cleanup phase: we want to avoid single cells with different properties
726 // than the bulk of the domain in order to avoid extra checks in the face
727 // identification.
728
729 // Step 1: check whether the interleaved indices were only assigned to
730 // the single cell within a vectorized array.
731 auto fix_single_interleaved_indices =
732 [&](const IndexStorageVariants variant) {
733 if (index_kinds[static_cast<unsigned int>(
735 0 &&
736 index_kinds[static_cast<unsigned int>(variant)] > 0)
737 for (unsigned int i = 0; i < irregular_cells.size(); ++i)
738 {
745 [i * vectorization_length] ==
746 1))
747 {
749 index_kinds[static_cast<unsigned int>(
752 index_kinds[static_cast<unsigned int>(variant)]++;
753 }
754 }
755 };
756
757 fix_single_interleaved_indices(IndexStorageVariants::full);
758 fix_single_interleaved_indices(IndexStorageVariants::contiguous);
759 fix_single_interleaved_indices(IndexStorageVariants::interleaved);
760
761 unsigned int n_interleaved =
762 index_kinds[static_cast<unsigned int>(
764 index_kinds[static_cast<unsigned int>(
766 index_kinds[static_cast<unsigned int>(
768
769 // Step 2: fix single contiguous cell among others with interleaved
770 // storage
771 if (n_interleaved > 0 && index_kinds[static_cast<unsigned int>(
773 for (unsigned int i = 0; i < irregular_cells.size(); ++i)
776 {
779 index_kinds[static_cast<unsigned int>(
781 index_kinds[static_cast<unsigned int>(
783 }
784
785 // Step 3: Interleaved cells are left but also some non-contiguous ones
786 // -> revert all to full storage
787 if (n_interleaved > 0 &&
788 index_kinds[static_cast<unsigned int>(IndexStorageVariants::full)] +
789 index_kinds[static_cast<unsigned int>(
791 0)
792 for (unsigned int i = 0; i < irregular_cells.size(); ++i)
795 {
796 index_kinds[static_cast<unsigned int>(
797 index_storage_variants[2][i])]--;
802 else
805 index_kinds[static_cast<unsigned int>(
807 }
808
809 // Step 4: Copy the interleaved indices into their own data structure
810 for (unsigned int i = 0; i < irregular_cells.size(); ++i)
813 {
816 {
819 continue;
820 }
821 const unsigned int ndofs =
822 dofs_per_cell[have_hp ? cell_active_fe_index[i] : 0];
823 const unsigned int *dof_indices =
824 &this->dof_indices
826 unsigned int *interleaved_dof_indices =
828 [row_starts[i * vectorization_length * n_components].first];
829 AssertDimension(this->dof_indices.size(),
830 this->dof_indices_interleaved.size());
835 this->dof_indices_interleaved.size() + 1);
837 row_starts[i * vectorization_length * n_components].first +
838 ndofs * vectorization_length,
839 this->dof_indices_interleaved.size() + 1);
840 for (unsigned int k = 0; k < ndofs; ++k)
841 {
842 const unsigned int *my_dof_indices = dof_indices + k;
843 const unsigned int *end =
844 interleaved_dof_indices + vectorization_length;
845 for (; interleaved_dof_indices != end;
846 ++interleaved_dof_indices, my_dof_indices += ndofs)
847 *interleaved_dof_indices = *my_dof_indices;
848 }
849 }
850 }
851
852
853
854 void
856 const Table<2, ShapeInfo<double>> &shape_info,
857 const unsigned int n_owned_cells,
858 const unsigned int n_lanes,
859 const std::vector<FaceToCellTopology<1>> &inner_faces,
860 const std::vector<FaceToCellTopology<1>> &ghosted_faces,
861 const bool fill_cell_centric,
862 const MPI_Comm communicator_sm,
863 const bool use_vector_data_exchanger_full)
864 {
866
867 // partitioner 0: no face integrals, simply use the indices present
868 // on the cells
869 std::vector<types::global_dof_index> ghost_indices;
870 {
871 const unsigned int n_components = start_components.back();
872 for (unsigned int cell = 0; cell < n_owned_cells; ++cell)
873 {
874 for (unsigned int i = row_starts[cell * n_components].first;
875 i < row_starts[(cell + 1) * n_components].first;
876 ++i)
877 if (dof_indices[i] >= part.locally_owned_size() &&
879 ghost_indices.push_back(part.local_to_global(dof_indices[i]));
880
881 const unsigned int fe_index =
882 dofs_per_cell.size() == 1 ? 0 :
883 cell_active_fe_index[cell / n_lanes];
884 const unsigned int dofs_this_cell = dofs_per_cell[fe_index];
885
886 for (unsigned int i = row_starts_plain_indices[cell];
887 i < row_starts_plain_indices[cell] + dofs_this_cell;
888 ++i)
889 if (plain_dof_indices[i] >= part.locally_owned_size())
890 ghost_indices.push_back(
892 }
893 std::sort(ghost_indices.begin(), ghost_indices.end());
894 IndexSet compressed_set(part.size());
895 compressed_set.add_indices(ghost_indices.begin(), ghost_indices.end());
896 compressed_set.subtract_set(part.locally_owned_range());
897 const bool all_ghosts_equal =
898 Utilities::MPI::logical_and(compressed_set.n_elements() ==
899 part.ghost_indices().n_elements(),
900 part.get_mpi_communicator());
901
902 std::shared_ptr<const Utilities::MPI::Partitioner> temp_0;
903
904 if (all_ghosts_equal)
905 temp_0 = vector_partitioner;
906 else
907 {
908 temp_0 = std::make_shared<Utilities::MPI::Partitioner>(
910 const_cast<Utilities::MPI::Partitioner *>(temp_0.get())
911 ->set_ghost_indices(compressed_set, part.ghost_indices());
912 }
913
914 if (use_vector_data_exchanger_full == false)
915 vector_exchanger_face_variants[0] = std::make_shared<
917 temp_0);
918 else
920 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
921 temp_0, communicator_sm);
922 }
923
924 // construct a numbering of faces
925 std::vector<FaceToCellTopology<1>> all_faces(inner_faces);
926 all_faces.insert(all_faces.end(),
927 ghosted_faces.begin(),
928 ghosted_faces.end());
929 Table<2, unsigned int> cell_and_face_to_faces(
930 (row_starts.size() - 1) / start_components.back(),
931 2 * shape_info(0, 0).n_dimensions);
932 cell_and_face_to_faces.fill(numbers::invalid_unsigned_int);
933 for (unsigned int f = 0; f < all_faces.size(); ++f)
934 {
935 cell_and_face_to_faces(all_faces[f].cells_interior[0],
936 all_faces[f].interior_face_no) = f;
937 Assert(all_faces[f].cells_exterior[0] !=
940 cell_and_face_to_faces(all_faces[f].cells_exterior[0],
941 all_faces[f].exterior_face_no) = f;
942 }
943
944 // lambda function to detect objects on face pairs
945 const auto loop_over_faces =
946 [&](const std::function<
947 void(const unsigned int, const unsigned int, const bool)> &fu) {
948 for (const auto &face : inner_faces)
949 {
950 AssertIndexRange(face.cells_interior[0], n_owned_cells);
951 fu(face.cells_exterior[0], face.exterior_face_no, false /*flag*/);
952 }
953 };
954
955 const auto loop_over_all_faces =
956 [&](const std::function<
957 void(const unsigned int, const unsigned int, const bool)> &fu) {
958 for (unsigned int c = 0; c < cell_and_face_to_faces.size(0); ++c)
959 for (unsigned int d = 0; d < cell_and_face_to_faces.size(1); ++d)
960 {
961 const unsigned int f = cell_and_face_to_faces(c, d);
963 continue;
964
965 const unsigned int cell_m = all_faces[f].cells_interior[0];
966 const unsigned int cell_p = all_faces[f].cells_exterior[0];
967
968 const bool ext = c == cell_m;
969
970 if (ext && cell_p == numbers::invalid_unsigned_int)
971 continue;
972
973 const unsigned int p = ext ? cell_p : cell_m;
974 const unsigned int face_no = ext ?
975 all_faces[f].exterior_face_no :
976 all_faces[f].interior_face_no;
977
978 fu(p, face_no, true);
979 }
980 };
981
982 const auto process_values =
983 [&](
984 std::shared_ptr<const Utilities::MPI::Partitioner>
985 &vector_partitioner_values,
986 const std::function<void(
987 const std::function<void(
988 const unsigned int, const unsigned int, const bool)> &)> &loop) {
989 bool all_nodal_and_tensorial = shape_info.size(1) == 1;
990
991 if (all_nodal_and_tensorial)
992 for (unsigned int c = 0; c < n_base_elements; ++c)
993 {
994 const auto &si =
995 shape_info(global_base_element_offset + c, 0).data.front();
996 if (!si.nodal_at_cell_boundaries ||
997 (si.element_type ==
999 all_nodal_and_tensorial = false;
1000 }
1001
1002 if (all_nodal_and_tensorial == false)
1003 vector_partitioner_values = vector_partitioner;
1004 else
1005 {
1006 bool has_noncontiguous_cell = false;
1007
1008 loop([&](const unsigned int cell_no,
1009 const unsigned int face_no,
1010 const bool flag) {
1011 const unsigned int index =
1013 if (flag || (index != numbers::invalid_unsigned_int &&
1014 index >= part.locally_owned_size()))
1015 {
1016 const unsigned int stride =
1017 dof_indices_interleave_strides[dof_access_cell][cell_no];
1018 unsigned int i = 0;
1019 for (unsigned int e = 0; e < n_base_elements; ++e)
1020 for (unsigned int c = 0; c < n_components[e]; ++c)
1021 {
1022 const ShapeInfo<double> &shape =
1023 shape_info(global_base_element_offset + e, 0);
1024 for (unsigned int j = 0;
1025 j < shape.dofs_per_component_on_face;
1026 ++j)
1027 ghost_indices.push_back(part.local_to_global(
1028 index + i +
1029 shape.face_to_cell_index_nodal(face_no, j) *
1030 stride));
1031 i += shape.dofs_per_component_on_cell * stride;
1032 }
1033 AssertDimension(i, dofs_per_cell[0] * stride);
1034 }
1036 has_noncontiguous_cell = true;
1037 });
1038 has_noncontiguous_cell =
1039 Utilities::MPI::logical_and(has_noncontiguous_cell,
1040 part.get_mpi_communicator());
1041
1042 std::sort(ghost_indices.begin(), ghost_indices.end());
1043 IndexSet compressed_set(part.size());
1044 compressed_set.add_indices(ghost_indices.begin(),
1045 ghost_indices.end());
1046 compressed_set.subtract_set(part.locally_owned_range());
1047 const bool all_ghosts_equal =
1048 Utilities::MPI::logical_and(compressed_set.n_elements() ==
1049 part.ghost_indices().n_elements(),
1050 part.get_mpi_communicator());
1051 if (all_ghosts_equal || has_noncontiguous_cell)
1052 vector_partitioner_values = vector_partitioner;
1053 else
1054 {
1055 vector_partitioner_values =
1056 std::make_shared<Utilities::MPI::Partitioner>(
1058 const_cast<Utilities::MPI::Partitioner *>(
1059 vector_partitioner_values.get())
1060 ->set_ghost_indices(compressed_set, part.ghost_indices());
1061 }
1062 }
1063 };
1064
1065
1066 const auto process_gradients =
1067 [&](
1068 const std::shared_ptr<const Utilities::MPI::Partitioner>
1069 &vector_partitoner_values,
1070 std::shared_ptr<const Utilities::MPI::Partitioner>
1071 &vector_partitioner_gradients,
1072 const std::function<void(
1073 const std::function<void(
1074 const unsigned int, const unsigned int, const bool)> &)> &loop) {
1075 bool all_hermite = shape_info.size(1) == 1;
1076
1077 if (all_hermite)
1078 for (unsigned int c = 0; c < n_base_elements; ++c)
1079 if (shape_info(global_base_element_offset + c, 0).element_type !=
1081 all_hermite = false;
1082 if (all_hermite == false ||
1083 vector_partitoner_values.get() == vector_partitioner.get())
1084 vector_partitioner_gradients = vector_partitioner;
1085 else
1086 {
1087 loop([&](const unsigned int cell_no,
1088 const unsigned int face_no,
1089 const bool flag) {
1090 const unsigned int index =
1091 dof_indices_contiguous[dof_access_cell][cell_no];
1092 if (flag || (index != numbers::invalid_unsigned_int &&
1093 index >= part.locally_owned_size()))
1094 {
1095 const unsigned int stride =
1096 dof_indices_interleave_strides[dof_access_cell][cell_no];
1097 unsigned int i = 0;
1098 for (unsigned int e = 0; e < n_base_elements; ++e)
1099 for (unsigned int c = 0; c < n_components[e]; ++c)
1100 {
1101 const ShapeInfo<double> &shape =
1102 shape_info(global_base_element_offset + e, 0);
1103 for (unsigned int j = 0;
1104 j < 2 * shape.dofs_per_component_on_face;
1105 ++j)
1106 ghost_indices.push_back(part.local_to_global(
1107 index + i +
1108 shape.face_to_cell_index_hermite(face_no, j) *
1109 stride));
1110 i += shape.dofs_per_component_on_cell * stride;
1111 }
1112 AssertDimension(i, dofs_per_cell[0] * stride);
1113 }
1114 });
1115 std::sort(ghost_indices.begin(), ghost_indices.end());
1116 IndexSet compressed_set(part.size());
1117 compressed_set.add_indices(ghost_indices.begin(),
1118 ghost_indices.end());
1119 compressed_set.subtract_set(part.locally_owned_range());
1120 const bool all_ghosts_equal =
1121 Utilities::MPI::logical_and(compressed_set.n_elements() ==
1122 part.ghost_indices().n_elements(),
1123 part.get_mpi_communicator());
1124 if (all_ghosts_equal)
1125 vector_partitioner_gradients = vector_partitioner;
1126 else
1127 {
1128 vector_partitioner_gradients =
1129 std::make_shared<Utilities::MPI::Partitioner>(
1130 part.locally_owned_range(), part.get_mpi_communicator());
1131 const_cast<Utilities::MPI::Partitioner *>(
1132 vector_partitioner_gradients.get())
1133 ->set_ghost_indices(compressed_set, part.ghost_indices());
1134 }
1135 }
1136 };
1137
1138 std::shared_ptr<const Utilities::MPI::Partitioner> temp_1, temp_2, temp_3,
1139 temp_4;
1140
1141 // partitioner 1: values on faces
1142 process_values(temp_1, loop_over_faces);
1143
1144 // partitioner 2: values and gradients on faces
1145 process_gradients(temp_1, temp_2, loop_over_faces);
1146
1147 if (fill_cell_centric)
1148 {
1149 ghost_indices.clear();
1150 // partitioner 3: values on all faces
1151 process_values(temp_3, loop_over_all_faces);
1152 // partitioner 4: values and gradients on faces
1153 process_gradients(temp_3, temp_4, loop_over_all_faces);
1154 }
1155 else
1156 {
1157 temp_3 = std::make_shared<Utilities::MPI::Partitioner>(
1158 part.locally_owned_range(), part.get_mpi_communicator());
1159 temp_4 = std::make_shared<Utilities::MPI::Partitioner>(
1160 part.locally_owned_range(), part.get_mpi_communicator());
1161 }
1162
1163 if (use_vector_data_exchanger_full == false)
1164 {
1165 vector_exchanger_face_variants[1] = std::make_shared<
1166 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1167 temp_1);
1168 vector_exchanger_face_variants[2] = std::make_shared<
1169 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1170 temp_2);
1171 vector_exchanger_face_variants[3] = std::make_shared<
1172 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1173 temp_3);
1174 vector_exchanger_face_variants[4] = std::make_shared<
1175 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1176 temp_4);
1177 }
1178 else
1179 {
1180 vector_exchanger_face_variants[1] =
1181 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
1182 temp_1, communicator_sm);
1183 vector_exchanger_face_variants[2] =
1184 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
1185 temp_2, communicator_sm);
1186 vector_exchanger_face_variants[3] =
1187 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
1188 temp_3, communicator_sm);
1189 vector_exchanger_face_variants[4] =
1190 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
1191 temp_4, communicator_sm);
1192 }
1193 }
1194
1195
1196
1197 void
1198 DoFInfo::compute_shared_memory_contiguous_indices(
1199 std::array<std::vector<std::pair<unsigned int, unsigned int>>, 3>
1200 &cell_indices_contiguous_sm)
1201 {
1202 AssertDimension(dofs_per_cell.size(), 1);
1203
1204 for (unsigned int i = 0; i < 3; ++i)
1205 {
1206 dof_indices_contiguous_sm[i].resize(
1207 cell_indices_contiguous_sm[i].size());
1208
1209 for (unsigned int j = 0; j < cell_indices_contiguous_sm[i].size();
1210 ++j)
1211 if (cell_indices_contiguous_sm[i][j].first !=
1213 dof_indices_contiguous_sm[i][j] = {
1214 cell_indices_contiguous_sm[i][j].first,
1215 cell_indices_contiguous_sm[i][j].second * dofs_per_cell[0]};
1216 else
1217 dof_indices_contiguous_sm[i][j] = {numbers::invalid_unsigned_int,
1219 }
1220 }
1221
1222
1223
1224 namespace internal
1225 {
1226 // We construct the connectivity graph in parallel. we use one lock for
1227 // 256 degrees of freedom to keep the number of locks down to a
1228 // reasonable level and reduce the cost of locking to some extent.
1229 static constexpr unsigned int bucket_size_threading = 256;
1230
1231
1232
1233 void
1234 compute_row_lengths(const unsigned int begin,
1235 const unsigned int end,
1236 const DoFInfo &dof_info,
1237 std::vector<std::mutex> &mutexes,
1238 std::vector<unsigned int> &row_lengths)
1239 {
1240 std::vector<unsigned int> scratch;
1241 const unsigned int n_components = dof_info.start_components.back();
1242 for (unsigned int block = begin; block < end; ++block)
1243 {
1244 scratch.assign(
1245 dof_info.dof_indices.data() +
1246 dof_info.row_starts[block * n_components].first,
1247 dof_info.dof_indices.data() +
1248 dof_info.row_starts[(block + 1) * n_components].first);
1249 std::sort(scratch.begin(), scratch.end());
1250
1251 const std::vector<unsigned int>::const_iterator end_unique =
1252 std::unique(scratch.begin(), scratch.end());
1253 for (std::vector<unsigned int>::const_iterator it = scratch.begin();
1254 it != end_unique && *it != numbers::invalid_unsigned_int;
1255 /* update in loop body */)
1256 {
1257 // In this code, the procedure is that we insert all elements
1258 // that are within the range of one lock at once
1259 const unsigned int next_bucket =
1261
1262 std::scoped_lock lock(mutexes[*it / bucket_size_threading]);
1263 for (; it != end_unique && *it < next_bucket; ++it)
1264 {
1265 AssertIndexRange(*it, row_lengths.size());
1266 ++row_lengths[*it];
1267 }
1268 }
1269 }
1270 }
1271
1272 void
1273 fill_connectivity_dofs(const unsigned int begin,
1274 const unsigned int end,
1275 const DoFInfo &dof_info,
1276 const std::vector<unsigned int> &row_lengths,
1277 std::vector<std::mutex> &mutexes,
1278 ::SparsityPattern &connectivity_dof)
1279 {
1280 std::vector<unsigned int> scratch;
1281 const unsigned int n_components = dof_info.start_components.back();
1282 for (unsigned int block = begin; block < end; ++block)
1283 {
1284 scratch.assign(
1285 dof_info.dof_indices.data() +
1286 dof_info.row_starts[block * n_components].first,
1287 dof_info.dof_indices.data() +
1288 dof_info.row_starts[(block + 1) * n_components].first);
1289 std::sort(scratch.begin(), scratch.end());
1290
1291 const std::vector<unsigned int>::const_iterator end_unique =
1292 std::unique(scratch.begin(), scratch.end());
1293 for (std::vector<unsigned int>::const_iterator it = scratch.begin();
1294 it != end_unique && *it != numbers::invalid_unsigned_int;
1295 /* update in loop body */)
1296 {
1297 const unsigned int next_bucket =
1299
1300 std::scoped_lock lock(mutexes[*it / bucket_size_threading]);
1301 for (; it != end_unique && *it < next_bucket; ++it)
1302 if (row_lengths[*it] > 0)
1303 connectivity_dof.add(*it, block);
1304 }
1305 }
1306 }
1307
1308
1309
1310 void
1311 fill_connectivity(const unsigned int begin,
1312 const unsigned int end,
1313 const DoFInfo &dof_info,
1314 const std::vector<unsigned int> &renumbering,
1315 const ::SparsityPattern &connectivity_dof,
1316 DynamicSparsityPattern &connectivity)
1317 {
1318 ordered_vector row_entries;
1319 const unsigned int n_components = dof_info.start_components.back();
1320 for (unsigned int block = begin; block < end; ++block)
1321 {
1322 row_entries.clear();
1323
1324 const unsigned int
1325 *it = dof_info.dof_indices.data() +
1326 dof_info.row_starts[block * n_components].first,
1327 *end_cell = dof_info.dof_indices.data() +
1328 dof_info.row_starts[(block + 1) * n_components].first;
1329 for (; it != end_cell; ++it)
1331 {
1332 SparsityPattern::iterator sp = connectivity_dof.begin(*it);
1333 std::vector<types::global_dof_index>::iterator insert_pos =
1334 row_entries.begin();
1335 for (; sp != connectivity_dof.end(*it); ++sp)
1336 if (sp->column() != block)
1337 row_entries.insert(renumbering[sp->column()], insert_pos);
1338 }
1339 connectivity.add_entries(renumbering[block],
1340 row_entries.begin(),
1341 row_entries.end());
1342 }
1343 }
1344
1345 } // namespace internal
1346
1347 void
1348 DoFInfo::make_connectivity_graph(
1349 const TaskInfo &task_info,
1350 const std::vector<unsigned int> &renumbering,
1351 DynamicSparsityPattern &connectivity) const
1352 {
1353 unsigned int n_rows = (vector_partitioner->local_range().second -
1354 vector_partitioner->local_range().first) +
1355 vector_partitioner->ghost_indices().n_elements();
1356
1357 // Avoid square sparsity patterns that allocate the diagonal entry
1358 if (n_rows == task_info.n_active_cells)
1359 ++n_rows;
1360
1361 // first determine row lengths
1362 std::vector<unsigned int> row_lengths(n_rows);
1363 std::vector<std::mutex> mutexes(n_rows / internal::bucket_size_threading +
1364 1);
1366 0,
1367 task_info.n_active_cells,
1368 [this, &mutexes, &row_lengths](const unsigned int begin,
1369 const unsigned int end) {
1370 internal::compute_row_lengths(
1371 begin, end, *this, mutexes, row_lengths);
1372 },
1373 20);
1374
1375 // disregard dofs that only sit on a single cell because they cannot
1376 // couple
1377 for (unsigned int row = 0; row < n_rows; ++row)
1378 if (row_lengths[row] <= 1)
1379 row_lengths[row] = 0;
1380
1381 // Create a temporary sparsity pattern that holds to each degree of
1382 // freedom on which cells it appears, i.e., store the connectivity
1383 // between cells and dofs
1384 SparsityPattern connectivity_dof(n_rows,
1385 task_info.n_active_cells,
1386 row_lengths);
1388 0,
1389 task_info.n_active_cells,
1390 [this, &row_lengths, &mutexes, &connectivity_dof](
1391 const unsigned int begin, const unsigned int end) {
1392 internal::fill_connectivity_dofs(
1393 begin, end, *this, row_lengths, mutexes, connectivity_dof);
1394 },
1395 20);
1396 connectivity_dof.compress();
1397
1398
1399 // Invert renumbering for use in fill_connectivity.
1400 std::vector<unsigned int> reverse_numbering(task_info.n_active_cells);
1401 reverse_numbering = Utilities::invert_permutation(renumbering);
1402
1403 // From the above connectivity between dofs and cells, we can finally
1404 // create a connectivity list between cells. The connectivity graph
1405 // should apply the renumbering, i.e., the entry for cell j is the entry
1406 // for cell renumbering[j] in the original ordering.
1408 0,
1409 task_info.n_active_cells,
1410 [this, &reverse_numbering, &connectivity_dof, &connectivity](
1411 const unsigned int begin, const unsigned int end) {
1412 internal::fill_connectivity(begin,
1413 end,
1414 *this,
1415 reverse_numbering,
1416 connectivity_dof,
1417 connectivity);
1418 },
1419 20);
1420 }
1421
1422
1423
1424 void
1425 DoFInfo::compute_dof_renumbering(
1426 std::vector<types::global_dof_index> &renumbering)
1427 {
1428 const unsigned int locally_owned_size =
1429 vector_partitioner->locally_owned_size();
1430 renumbering.resize(0);
1432
1433 types::global_dof_index counter = 0;
1434 const unsigned int n_components = start_components.back();
1435 const unsigned int n_cell_batches =
1436 n_vectorization_lanes_filled[dof_access_cell].size();
1437 Assert(n_cell_batches <=
1438 (row_starts.size() - 1) / vectorization_length / n_components,
1440 for (unsigned int cell_no = 0; cell_no < n_cell_batches; ++cell_no)
1441 {
1442 // do not renumber in case we have constraints
1443 if (row_starts[cell_no * n_components * vectorization_length]
1444 .second ==
1445 row_starts[(cell_no + 1) * n_components * vectorization_length]
1446 .second)
1447 {
1448 const unsigned int ndofs =
1449 dofs_per_cell.size() == 1 ?
1450 dofs_per_cell[0] :
1451 (dofs_per_cell[cell_active_fe_index.size() > 0 ?
1452 cell_active_fe_index[cell_no] :
1453 0]);
1454 const unsigned int *dof_ind =
1455 dof_indices.data() +
1456 row_starts[cell_no * n_components * vectorization_length].first;
1457 for (unsigned int i = 0; i < ndofs; ++i)
1458 for (unsigned int j = 0;
1459 j < n_vectorization_lanes_filled[dof_access_cell][cell_no];
1460 ++j)
1461 if (dof_ind[j * ndofs + i] < locally_owned_size)
1462 if (renumbering[dof_ind[j * ndofs + i]] ==
1464 renumbering[dof_ind[j * ndofs + i]] = counter++;
1465 }
1466 }
1467
1469 for (types::global_dof_index &dof_index : renumbering)
1470 if (dof_index == numbers::invalid_dof_index)
1471 dof_index = counter++;
1472
1473 // transform indices to global index space
1474 for (types::global_dof_index &dof_index : renumbering)
1475 dof_index = vector_partitioner->local_to_global(dof_index);
1476
1477 AssertDimension(counter, renumbering.size());
1478 }
1479
1480
1481
1482 std::size_t
1483 DoFInfo::memory_consumption() const
1484 {
1485 std::size_t memory = sizeof(*this);
1486 for (const auto &storage : index_storage_variants)
1487 memory += storage.capacity() * sizeof(storage[0]);
1488 memory +=
1489 (row_starts.capacity() * sizeof(std::pair<unsigned int, unsigned int>));
1490 memory += MemoryConsumption::memory_consumption(dof_indices);
1491 memory += MemoryConsumption::memory_consumption(dof_indices_interleaved);
1492 memory += MemoryConsumption::memory_consumption(dof_indices_contiguous);
1493 memory +=
1494 MemoryConsumption::memory_consumption(dof_indices_contiguous_sm);
1495 memory +=
1496 MemoryConsumption::memory_consumption(dof_indices_interleave_strides);
1497 memory +=
1498 MemoryConsumption::memory_consumption(n_vectorization_lanes_filled);
1500 hanging_node_constraint_masks_comp);
1501 memory +=
1502 MemoryConsumption::memory_consumption(hanging_node_constraint_masks);
1503 memory +=
1504 MemoryConsumption::memory_consumption(face_dof_sign_change_masks);
1505 memory += MemoryConsumption::memory_consumption(constrained_dofs);
1506 memory += MemoryConsumption::memory_consumption(row_starts_plain_indices);
1507 memory += MemoryConsumption::memory_consumption(plain_dof_indices);
1508 memory += MemoryConsumption::memory_consumption(constraint_indicator);
1509 memory += MemoryConsumption::memory_consumption(*vector_partitioner);
1510 memory += MemoryConsumption::memory_consumption(n_components);
1511 memory += MemoryConsumption::memory_consumption(start_components);
1512 memory += MemoryConsumption::memory_consumption(component_to_base_index);
1513 memory +=
1514 MemoryConsumption::memory_consumption(component_dof_indices_offset);
1515 memory += MemoryConsumption::memory_consumption(dofs_per_cell);
1516 memory += MemoryConsumption::memory_consumption(dofs_per_face);
1517 memory += MemoryConsumption::memory_consumption(cell_active_fe_index);
1518 memory += MemoryConsumption::memory_consumption(fe_index_conversion);
1519 memory +=
1520 MemoryConsumption::memory_consumption(vector_zero_range_list_index);
1521 memory += MemoryConsumption::memory_consumption(vector_zero_range_list);
1522 memory += MemoryConsumption::memory_consumption(cell_loop_pre_list_index);
1523 memory += MemoryConsumption::memory_consumption(cell_loop_pre_list);
1524 memory +=
1525 MemoryConsumption::memory_consumption(cell_loop_post_list_index);
1526 memory += MemoryConsumption::memory_consumption(cell_loop_post_list);
1527 return memory;
1528 }
1529 } // namespace MatrixFreeFunctions
1530} // namespace internal
1531
1532namespace internal
1533{
1534 namespace MatrixFreeFunctions
1535 {
1536 template void
1537 DoFInfo::read_dof_indices<double>(
1538 const std::vector<types::global_dof_index> &,
1539 const std::vector<types::global_dof_index> &,
1540 const bool,
1541 const ::AffineConstraints<double> &,
1542 const unsigned int,
1543 ConstraintValues<double> &,
1544 bool &);
1545
1546 template void
1547 DoFInfo::read_dof_indices<float>(
1548 const std::vector<types::global_dof_index> &,
1549 const std::vector<types::global_dof_index> &,
1550 const bool,
1551 const ::AffineConstraints<float> &,
1552 const unsigned int,
1553 ConstraintValues<double> &,
1554 bool &);
1555
1556 template bool
1557 DoFInfo::process_hanging_node_constraints<1>(
1558 const HangingNodes<1> &,
1559 const std::vector<std::vector<unsigned int>> &,
1560 const unsigned int,
1562 std::vector<types::global_dof_index> &);
1563 template bool
1564 DoFInfo::process_hanging_node_constraints<2>(
1565 const HangingNodes<2> &,
1566 const std::vector<std::vector<unsigned int>> &,
1567 const unsigned int,
1569 std::vector<types::global_dof_index> &);
1570 template bool
1571 DoFInfo::process_hanging_node_constraints<3>(
1572 const HangingNodes<3> &,
1573 const std::vector<std::vector<unsigned int>> &,
1574 const unsigned int,
1576 std::vector<types::global_dof_index> &);
1577
1578 template void
1579 DoFInfo::compute_face_index_compression<1>(
1580 const std::vector<FaceToCellTopology<1>> &,
1581 bool);
1582 template void
1583 DoFInfo::compute_face_index_compression<2>(
1584 const std::vector<FaceToCellTopology<2>> &,
1585 bool);
1586 template void
1587 DoFInfo::compute_face_index_compression<4>(
1588 const std::vector<FaceToCellTopology<4>> &,
1589 bool);
1590 template void
1591 DoFInfo::compute_face_index_compression<8>(
1592 const std::vector<FaceToCellTopology<8>> &,
1593 bool);
1594 template void
1595 DoFInfo::compute_face_index_compression<16>(
1596 const std::vector<FaceToCellTopology<16>> &,
1597 bool);
1598
1599 template void
1600 DoFInfo::compute_vector_zero_access_pattern<1>(
1601 const TaskInfo &,
1602 const std::vector<FaceToCellTopology<1>> &);
1603 template void
1604 DoFInfo::compute_vector_zero_access_pattern<2>(
1605 const TaskInfo &,
1606 const std::vector<FaceToCellTopology<2>> &);
1607 template void
1608 DoFInfo::compute_vector_zero_access_pattern<4>(
1609 const TaskInfo &,
1610 const std::vector<FaceToCellTopology<4>> &);
1611 template void
1612 DoFInfo::compute_vector_zero_access_pattern<8>(
1613 const TaskInfo &,
1614 const std::vector<FaceToCellTopology<8>> &);
1615 template void
1616 DoFInfo::compute_vector_zero_access_pattern<16>(
1617 const TaskInfo &,
1618 const std::vector<FaceToCellTopology<16>> &);
1619
1620 template void
1621 DoFInfo::print_memory_consumption<std::ostream>(std::ostream &,
1622 const TaskInfo &) const;
1623 template void
1624 DoFInfo::print_memory_consumption<ConditionalOStream>(
1626 const TaskInfo &) const;
1627
1628 template void
1629 DoFInfo::print<double>(const std::vector<double> &,
1630 const std::vector<unsigned int> &,
1631 std::ostream &) const;
1632
1633 template void
1634 DoFInfo::print<float>(const std::vector<float> &,
1635 const std::vector<unsigned int> &,
1636 std::ostream &) const;
1637 } // namespace MatrixFreeFunctions
1638} // namespace internal
1639
*  iterator end()
*  *  iterator begin()
void add_entries(const size_type row, ForwardIterator begin, ForwardIterator end, const bool indices_are_unique_and_sorted=false)
size_type index_within_set(const size_type global_index) const
Definition index_set.h:1977
size_type n_elements() const
Definition index_set.h:1917
void subtract_set(const IndexSet &other)
Definition index_set.cc:496
void add_range(const size_type begin, const size_type end)
Definition index_set.h:1786
void compress() const
Definition index_set.h:1767
void add_indices(const ForwardIterator &begin, const ForwardIterator &end)
Definition index_set.h:1814
void add(const size_type i, const size_type j)
const IndexSet & locally_owned_range() const
const IndexSet & ghost_indices() const
unsigned int locally_owned_size() const
types::global_dof_index local_to_global(const unsigned int local_index) const
virtual MPI_Comm get_mpi_communicator() const override
void set_ghost_indices(const IndexSet &ghost_indices, const IndexSet &larger_ghost_index_set=IndexSet())
types::global_dof_index size() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
constexpr bool running_in_debug_mode()
Definition config.h:76
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
Point< 2 > second
Definition grid_out.cc:4640
Point< 2 > first
Definition grid_out.cc:4639
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
std::size_t size
Definition mpi.cc:733
types::global_dof_index locally_owned_size
Definition mpi.cc:821
std::enable_if_t< std::is_fundamental_v< T >, std::size_t > memory_consumption(const T &t)
bool logical_and(const bool t, const MPI_Comm mpi_communicator)
std::vector< Integer > invert_permutation(const std::vector< Integer > &permutation)
Definition utilities.h:1670
void fill_connectivity_dofs(const unsigned int begin, const unsigned int end, const DoFInfo &dof_info, const std::vector< unsigned int > &row_lengths, std::vector< std::mutex > &mutexes, ::SparsityPattern &connectivity_dof)
Definition dof_info.cc:1273
void fill_connectivity(const unsigned int begin, const unsigned int end, const DoFInfo &dof_info, const std::vector< unsigned int > &renumbering, const ::SparsityPattern &connectivity_dof, DynamicSparsityPattern &connectivity)
Definition dof_info.cc:1311
void compute_row_lengths(const unsigned int begin, const unsigned int end, const DoFInfo &dof_info, std::vector< std::mutex > &mutexes, std::vector< unsigned int > &row_lengths)
Definition dof_info.cc:1234
static constexpr unsigned int bucket_size_threading
Definition dof_info.cc:1229
constexpr compressed_constraint_kind unconstrained_compressed_constraint_kind
constexpr types::global_dof_index invalid_dof_index
Definition types.h:259
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
void apply_to_subranges(const Iterator &begin, const std_cxx20::type_identity_t< Iterator > &end, const Function &f, const unsigned int grainsize)
Definition parallel.h:284
::VectorizedArray< Number, width > max(const ::VectorizedArray< Number, width > &, const ::VectorizedArray< Number, width > &)
void reorder_cells(const TaskInfo &task_info, const std::vector< unsigned int > &renumbering, const std::vector< unsigned int > &constraint_pool_row_index, const std::vector< unsigned char > &irregular_cells)
Definition dof_info.cc:278
std::vector< unsigned char > face_dof_sign_change_masks
Definition dof_info.h:535
std::vector< std::pair< unsigned short, unsigned short > > constraint_indicator
Definition dof_info.h:547
std::vector< std::pair< unsigned int, unsigned int > > row_starts
Definition dof_info.h:495
void compute_tight_partitioners(const Table< 2, ShapeInfo< double > > &shape_info, const unsigned int n_owned_cells, const unsigned int n_lanes, const std::vector< FaceToCellTopology< 1 > > &inner_faces, const std::vector< FaceToCellTopology< 1 > > &ghosted_faces, const bool fill_cell_centric, const MPI_Comm communicator_sm, const bool use_vector_data_exchanger_full)
Definition dof_info.cc:855
std::vector< std::vector< bool > > hanging_node_constraint_masks_comp
Definition dof_info.h:518
void get_dof_indices_on_cell_batch(std::vector< unsigned int > &local_indices, const unsigned int cell_batch, const bool with_constraints=true) const
Definition dof_info.cc:83
void compute_cell_index_compression(const std::vector< unsigned char > &irregular_cells)
Definition dof_info.cc:513
std::vector< unsigned int > dofs_per_cell
Definition dof_info.h:704
void assign_ghosts(const std::vector< unsigned int > &boundary_cells, const MPI_Comm communicator_sm, const bool use_vector_data_exchanger_full)
Definition dof_info.cc:146
std::shared_ptr< const internal::MatrixFreeFunctions::VectorDataExchange::Base > vector_exchanger
Definition dof_info.h:609
std::vector< std::vector< unsigned int > > fe_index_conversion
Definition dof_info.h:732
std::vector< unsigned int > dof_indices
Definition dof_info.h:512
std::shared_ptr< const Utilities::MPI::Partitioner > vector_partitioner
Definition dof_info.h:602
std::vector< compressed_constraint_kind > hanging_node_constraint_masks
Definition dof_info.h:524
std::array< std::vector< unsigned int >, 3 > dof_indices_interleave_strides
Definition dof_info.h:583
std::vector< unsigned int > row_starts_plain_indices
Definition dof_info.h:646
std::vector< unsigned int > dofs_per_face
Definition dof_info.h:709
std::vector< unsigned int > n_components
Definition dof_info.h:674
std::vector< types::global_dof_index > ghost_dofs
Definition dof_info.h:739
std::array< std::vector< unsigned int >, 3 > dof_indices_contiguous
Definition dof_info.h:562
std::vector< unsigned int > cell_active_fe_index
Definition dof_info.h:719
std::array< std::shared_ptr< const internal::MatrixFreeFunctions::VectorDataExchange::Base >, 5 > vector_exchanger_face_variants
Definition dof_info.h:634
std::vector< unsigned int > plain_dof_indices
Definition dof_info.h:656
std::array< std::vector< unsigned char >, 3 > n_vectorization_lanes_filled
Definition dof_info.h:594
std::vector< unsigned int > start_components
Definition dof_info.h:680
std::vector< unsigned int > dof_indices_interleaved
Definition dof_info.h:552
std::array< std::vector< IndexStorageVariants >, 3 > index_storage_variants
Definition dof_info.h:487
std::vector< unsigned int > cell_partition_data
Definition task_info.h:472