148 const bool use_vector_data_exchanger_full)
155 const std::size_t n_ghosts =
ghost_dofs.size();
164 std::vector<unsigned int> ghost_numbering(n_ghosts);
168 unsigned int n_unique_ghosts = 0;
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)
177 ghost_origin[i].second = i;
179 std::sort(ghost_origin.begin(), ghost_origin.end());
182 ghost_numbering[ghost_origin[0].second] = 0;
183 for (std::size_t i = 1; i < n_ghosts; ++i)
185 if (ghost_origin[i].
first > ghost_origin[i - 1].
first + 1)
187 ghost_indices.
add_range(last_contiguous_start,
188 ghost_origin[i - 1].
first + 1);
189 last_contiguous_start = ghost_origin[i].first;
191 if (ghost_origin[i].
first > ghost_origin[i - 1].
first)
193 ghost_numbering[ghost_origin[i].second] = n_unique_ghosts;
196 ghost_indices.
add_range(last_contiguous_start,
197 ghost_origin.back().first + 1);
204 for (std::size_t i = 0; i < n_ghosts; ++i)
205 Assert(ghost_numbering[i] ==
214 const unsigned int n_boundary_cells = boundary_cells.size();
215 for (
unsigned int i = 0; i < n_boundary_cells; ++i)
217 unsigned int *data_ptr =
220 const unsigned int *row_end =
223 for (; data_ptr != row_end; ++data_ptr)
224 *data_ptr = ((*data_ptr < n_owned ||
227 n_owned + ghost_numbering[*data_ptr - n_owned]);
234 const unsigned int fe_index =
241 unsigned int *data_ptr =
244 const unsigned int *row_end =
246 for (; data_ptr != row_end; ++data_ptr)
248 ((*data_ptr < n_owned) ?
250 n_owned + ghost_numbering[*data_ptr - n_owned]);
255 std::vector<types::global_dof_index> empty;
265 if (use_vector_data_exchanger_full ==
false)
271 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
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)
288 std::vector<unsigned int> new_active_fe_index;
290 unsigned int position_cell = 0;
291 for (
unsigned int cell = 0;
295 const unsigned int n_comp =
296 (irregular_cells[cell] > 0 ? irregular_cells[cell] :
301 unsigned int fe_index =
303 for (
unsigned int j = 1; j < n_comp; ++j)
308 new_active_fe_index.push_back(fe_index);
309 position_cell += n_comp;
319 std::vector<std::pair<unsigned int, unsigned int>> new_row_starts(
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;
331 std::vector<compressed_constraint_kind> new_hanging_node_constraint_masks;
332 new_hanging_node_constraint_masks.reserve(
335 std::vector<unsigned char> new_face_dof_sign_change_masks;
354 const unsigned int n_lanes_filled =
355 (irregular_cells[i] > 0 ? irregular_cells[i] :
359 this->dofs_per_cell[0];
361 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
363 const unsigned int cell_no = renumbering[position_cell + j];
367 new_hanging_node_constraint_masks.push_back(
371 new_face_dof_sign_change_masks.push_back(
374 for (
unsigned int comp = 0; comp <
n_components; ++comp)
378 .
first = new_dof_indices.size();
381 .
second = new_constraint_indicator.size();
384 new_dof_indices.insert(new_dof_indices.end(),
392 new_constraint_indicator.push_back(
400 new_plain_indices.size();
401 new_plain_indices.insert(new_plain_indices.end(),
410 for (
unsigned int comp = 0; comp <
n_components; ++comp)
414 .
first = new_dof_indices.size();
417 .
second = new_constraint_indicator.size();
422 new_hanging_node_constraint_masks.push_back(
427 new_face_dof_sign_change_masks.push_back(0);
429 position_cell += n_lanes_filled;
436 .first = new_dof_indices.size();
439 .second = new_constraint_indicator.size();
442 new_constraint_indicator.size());
456 const unsigned int index_range =
471 const unsigned int row_length_ind =
479 const std::pair<unsigned short, unsigned short>
487 for (; con_it != end_con; ++con_it)
491 constraint_pool_row_index.size() - 1);
496 unsigned int n_active_cells = 0;
497 for (
unsigned int c = 0;
500 if (irregular_cells[c] > 0)
501 n_active_cells += irregular_cells[c];
514 const std::vector<unsigned char> &irregular_cells)
524 irregular_cells.size());
528 irregular_cells.size());
529 for (
unsigned int i = 0; i < irregular_cells.size(); ++i)
530 if (irregular_cells[i] > 0)
545 std::vector<unsigned int> index_kinds(
546 static_cast<unsigned int>(
550 for (
unsigned int i = 0; i < irregular_cells.size(); ++i)
552 const unsigned int ndofs =
554 const unsigned int n_lanes_filled =
558 bool has_constraints =
false;
559 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
565 has_constraints =
true;
574 bool indices_are_contiguous = (ndofs > 0);
575 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
579 this->dof_indices.data() +
588 indices_are_contiguous =
false;
591 for (
unsigned int i = 1; i < ndofs; ++i)
595 indices_are_contiguous =
false;
600 bool indices_are_interleaved_and_contiguous =
605 this->dof_indices.data() +
607 for (
unsigned int k = 0;
608 k < ndofs && indices_are_interleaved_and_contiguous;
610 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
616 indices_are_interleaved_and_contiguous =
false;
621 if (indices_are_contiguous ||
622 indices_are_interleaved_and_contiguous)
624 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
626 const unsigned int start_index =
639 if (indices_are_interleaved_and_contiguous)
645 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
649 else if (indices_are_contiguous)
653 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
659 int indices_are_interleaved_and_mixed = 2;
664 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
667 for (
unsigned int k = 0;
668 k < ndofs && indices_are_interleaved_and_mixed != 0;
670 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
679 indices_are_interleaved_and_mixed = 0;
682 if (indices_are_interleaved_and_mixed == 2)
684 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
688 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
692 for (
unsigned int j = 0; j < n_lanes_filled; ++j)
695 indices_are_interleaved_and_mixed = 1;
698 if (indices_are_interleaved_and_mixed == 1 ||
721 index_kinds[
static_cast<unsigned int>(
731 auto fix_single_interleaved_indices =
733 if (index_kinds[
static_cast<unsigned int>(
736 index_kinds[
static_cast<unsigned int>(variant)] > 0)
737 for (
unsigned int i = 0; i < irregular_cells.size(); ++i)
749 index_kinds[
static_cast<unsigned int>(
752 index_kinds[
static_cast<unsigned int>(variant)]++;
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>(
771 if (n_interleaved > 0 && index_kinds[
static_cast<unsigned int>(
773 for (
unsigned int i = 0; i < irregular_cells.size(); ++i)
779 index_kinds[
static_cast<unsigned int>(
781 index_kinds[
static_cast<unsigned int>(
787 if (n_interleaved > 0 &&
789 index_kinds[
static_cast<unsigned int>(
792 for (
unsigned int i = 0; i < irregular_cells.size(); ++i)
796 index_kinds[
static_cast<unsigned int>(
805 index_kinds[
static_cast<unsigned int>(
810 for (
unsigned int i = 0; i < irregular_cells.size(); ++i)
821 const unsigned int ndofs =
826 unsigned int *interleaved_dof_indices =
830 this->dof_indices_interleaved.size());
840 for (
unsigned int k = 0; k < ndofs; ++k)
842 const unsigned int *my_dof_indices =
dof_indices + k;
843 const unsigned int *
end =
845 for (; interleaved_dof_indices !=
end;
846 ++interleaved_dof_indices, my_dof_indices += ndofs)
847 *interleaved_dof_indices = *my_dof_indices;
857 const unsigned int n_owned_cells,
858 const unsigned int n_lanes,
861 const bool fill_cell_centric,
863 const bool use_vector_data_exchanger_full)
869 std::vector<types::global_dof_index> ghost_indices;
872 for (
unsigned int cell = 0; cell < n_owned_cells; ++cell)
881 const unsigned int fe_index =
890 ghost_indices.push_back(
893 std::sort(ghost_indices.begin(), ghost_indices.end());
895 compressed_set.
add_indices(ghost_indices.begin(), ghost_indices.end());
897 const bool all_ghosts_equal =
902 std::shared_ptr<const Utilities::MPI::Partitioner> temp_0;
904 if (all_ghosts_equal)
908 temp_0 = std::make_shared<Utilities::MPI::Partitioner>(
914 if (use_vector_data_exchanger_full ==
false)
920 std::make_shared<MatrixFreeFunctions::VectorDataExchange::Full>(
921 temp_0, communicator_sm);
925 std::vector<FaceToCellTopology<1>> all_faces(inner_faces);
926 all_faces.insert(all_faces.end(),
927 ghosted_faces.begin(),
928 ghosted_faces.end());
931 2 * shape_info(0, 0).n_dimensions);
933 for (
unsigned int f = 0; f < all_faces.size(); ++f)
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;
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)
951 fu(face.cells_exterior[0], face.exterior_face_no,
false );
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)
961 const unsigned int f = cell_and_face_to_faces(c, d);
965 const unsigned int cell_m = all_faces[f].cells_interior[0];
966 const unsigned int cell_p = all_faces[f].cells_exterior[0];
968 const bool ext = c == cell_m;
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;
978 fu(p, face_no,
true);
982 const auto process_values =
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;
991 if (all_nodal_and_tensorial)
996 if (!si.nodal_at_cell_boundaries ||
999 all_nodal_and_tensorial =
false;
1002 if (all_nodal_and_tensorial ==
false)
1006 bool has_noncontiguous_cell =
false;
1008 loop([&](
const unsigned int cell_no,
1009 const unsigned int face_no,
1011 const unsigned int index =
1016 const unsigned int stride =
1017 dof_indices_interleave_strides[dof_access_cell][cell_no];
1019 for (unsigned int e = 0; e < n_base_elements; ++e)
1020 for (unsigned int c = 0; c < n_components[e]; ++c)
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;
1027 ghost_indices.push_back(part.local_to_global(
1029 shape.face_to_cell_index_nodal(face_no, j) *
1031 i += shape.dofs_per_component_on_cell * stride;
1036 has_noncontiguous_cell =
true;
1038 has_noncontiguous_cell =
1042 std::sort(ghost_indices.begin(), ghost_indices.end());
1045 ghost_indices.end());
1047 const bool all_ghosts_equal =
1051 if (all_ghosts_equal || has_noncontiguous_cell)
1055 vector_partitioner_values =
1056 std::make_shared<Utilities::MPI::Partitioner>(
1059 vector_partitioner_values.get())
1066 const auto process_gradients =
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;
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;
1087 loop([&](
const unsigned int cell_no,
1088 const unsigned int face_no,
1090 const unsigned int index =
1091 dof_indices_contiguous[dof_access_cell][cell_no];
1093 index >= part.locally_owned_size()))
1095 const unsigned int stride =
1096 dof_indices_interleave_strides[dof_access_cell][cell_no];
1098 for (unsigned int e = 0; e < n_base_elements; ++e)
1099 for (unsigned int c = 0; c < n_components[e]; ++c)
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;
1106 ghost_indices.push_back(part.local_to_global(
1108 shape.face_to_cell_index_hermite(face_no, j) *
1110 i += shape.dofs_per_component_on_cell * stride;
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 =
1122 part.ghost_indices().n_elements(),
1123 part.get_mpi_communicator());
1124 if (all_ghosts_equal)
1125 vector_partitioner_gradients = vector_partitioner;
1128 vector_partitioner_gradients =
1129 std::make_shared<Utilities::MPI::Partitioner>(
1130 part.locally_owned_range(), part.get_mpi_communicator());
1132 vector_partitioner_gradients.get())
1133 ->set_ghost_indices(compressed_set, part.ghost_indices());
1138 std::shared_ptr<const Utilities::MPI::Partitioner> temp_1, temp_2, temp_3,
1142 process_values(temp_1, loop_over_faces);
1145 process_gradients(temp_1, temp_2, loop_over_faces);
1147 if (fill_cell_centric)
1149 ghost_indices.clear();
1151 process_values(temp_3, loop_over_all_faces);
1153 process_gradients(temp_3, temp_4, loop_over_all_faces);
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());
1163 if (use_vector_data_exchanger_full ==
false)
1165 vector_exchanger_face_variants[1] = std::make_shared<
1166 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1168 vector_exchanger_face_variants[2] = std::make_shared<
1169 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1171 vector_exchanger_face_variants[3] = std::make_shared<
1172 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
1174 vector_exchanger_face_variants[4] = std::make_shared<
1175 MatrixFreeFunctions::VectorDataExchange::PartitionerWrapper>(
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);
1348 DoFInfo::make_connectivity_graph(
1350 const std::vector<unsigned int> &renumbering,
1353 unsigned int n_rows = (vector_partitioner->local_range().second -
1354 vector_partitioner->local_range().first) +
1355 vector_partitioner->ghost_indices().n_elements();
1362 std::vector<unsigned int> row_lengths(n_rows);
1363 std::vector<std::mutex> mutexes(n_rows / internal::bucket_size_threading +
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);
1377 for (
unsigned int row = 0; row < n_rows; ++row)
1378 if (row_lengths[row] <= 1)
1379 row_lengths[row] = 0;
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);
1400 std::vector<unsigned int> reverse_numbering(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,