17#ifndef dealii_face_setup_internal_h
18#define dealii_face_setup_internal_h
41 namespace MatrixFreeFunctions
83 const unsigned int mg_level,
84 const bool hold_all_faces_to_owned_cells,
85 const bool build_inner_faces,
86 std::vector<std::pair<unsigned int, unsigned int>> &cell_levels);
97 const std::vector<std::pair<unsigned int, unsigned int>> &cell_levels,
108 const unsigned int face_no,
109 const typename ::Triangulation<dim>::cell_iterator &cell,
110 const unsigned int number_cell_interior,
111 const typename ::Triangulation<dim>::cell_iterator &neighbor,
112 const unsigned int number_cell_exterior,
113 const bool is_mixed_mesh);
143 template <
int vectorization_w
idth>
147 const std::vector<bool> & hard_vectorization_boundary,
148 std::vector<unsigned int> & face_partition_data,
159 : use_active_cells(true)
166 FaceSetup<dim>::initialize(
168 const unsigned int mg_level,
169 const bool hold_all_faces_to_owned_cells,
170 const bool build_inner_faces,
171 std::vector<std::pair<unsigned int, unsigned int>> &cell_levels)
177 if (use_active_cells)
178 for (
const auto &cell_level : cell_levels)
180 typename ::Triangulation<dim>::cell_iterator dcell(
189 at_processor_boundary.resize(cell_levels.size(),
false);
192 FaceCategory::locally_active_done_elsewhere);
196 std::map<types::subdomain_id, FaceIdentifier>
197 inner_faces_at_proc_boundary;
203 for (
unsigned int i = 0; i < cell_levels.size(); ++i)
205 if (i > 0 && cell_levels[i] == cell_levels[i - 1])
207 typename ::Triangulation<dim>::cell_iterator dcell(
209 for (
const unsigned int f : dcell->face_indices())
211 if (dcell->at_boundary(f) && !dcell->has_periodic_neighbor(f))
213 typename ::Triangulation<dim>::cell_iterator neighbor =
214 dcell->neighbor_or_periodic_neighbor(f);
220 const CellId id_mine = dcell->id();
221 if (use_active_cells && neighbor->has_children())
222 for (
unsigned int c = 0;
223 c < (dcell->has_periodic_neighbor(f) ?
224 dcell->periodic_neighbor(f)
225 ->face(dcell->periodic_neighbor_face_no(f))
227 dcell->face(f)->n_children());
230 typename ::Triangulation<dim>::cell_iterator
232 dcell->at_boundary(f) ?
233 dcell->periodic_neighbor_child_on_subface(f, c) :
234 dcell->neighbor_child_on_subface(f, c);
236 neighbor_c->subdomain_id();
237 if (my_domain < neigh_domain)
238 inner_faces_at_proc_boundary[neigh_domain]
239 .n_hanging_faces_larger_subdomain++;
240 else if (my_domain > neigh_domain)
241 inner_faces_at_proc_boundary[neigh_domain]
242 .n_hanging_faces_smaller_subdomain++;
247 use_active_cells ? neighbor->subdomain_id() :
248 neighbor->level_subdomain_id();
249 if (neighbor->level() < dcell->level() &&
252 if (my_domain < neigh_domain)
253 inner_faces_at_proc_boundary[neigh_domain]
254 .n_hanging_faces_smaller_subdomain++;
255 else if (my_domain > neigh_domain)
256 inner_faces_at_proc_boundary[neigh_domain]
257 .n_hanging_faces_larger_subdomain++;
259 else if (neighbor->level() == dcell->level() &&
260 my_domain != neigh_domain)
266 const CellId id_neigh = neighbor->id();
267 if (my_domain < neigh_domain)
268 inner_faces_at_proc_boundary[neigh_domain]
269 .shared_faces.emplace_back(id_mine, id_neigh);
271 inner_faces_at_proc_boundary[neigh_domain]
272 .shared_faces.emplace_back(id_neigh, id_mine);
281 for (
auto &inner_face : inner_faces_at_proc_boundary)
283 Assert(inner_face.first != my_domain,
285 std::sort(inner_face.second.shared_faces.begin(),
286 inner_face.second.shared_faces.end());
287 inner_face.second.shared_faces.erase(
288 std::unique(inner_face.second.shared_faces.begin(),
289 inner_face.second.shared_faces.end()),
290 inner_face.second.shared_faces.end());
295# if defined(DEAL_II_WITH_MPI) && defined(DEBUG)
297 if (const ::parallel::TriangulationBase<dim> *ptria =
298 dynamic_cast<const ::parallel::TriangulationBase<dim>
300 comm = ptria->get_communicator();
303 unsigned int mysize = inner_face.second.shared_faces.size();
306 int ierr = MPI_Sendrecv(&mysize,
315 600 + inner_face.first,
320 mysize = inner_face.second.n_hanging_faces_smaller_subdomain;
321 ierr = MPI_Sendrecv(&mysize,
330 700 + inner_face.first,
335 mysize = inner_face.second.n_hanging_faces_larger_subdomain;
336 ierr = MPI_Sendrecv(&mysize,
345 800 + inner_face.first,
367 std::vector<std::tuple<CellId, CellId, unsigned int>> other_range(
368 inner_face.second.shared_faces.size());
369 for (
unsigned int i = 0; i < other_range.size(); ++i)
371 std::make_tuple(inner_face.second.shared_faces[i].second,
372 inner_face.second.shared_faces[i].first,
374 std::sort(other_range.begin(), other_range.end());
382 unsigned int n_faces_lower_proc = 0, n_faces_higher_proc = 0;
383 std::vector<signed char> assignment(other_range.size(), 0);
384 if (inner_face.second.shared_faces.size() > 0)
388 unsigned int count = 0;
389 for (
unsigned int i = 1;
390 i < inner_face.second.shared_faces.size();
392 if (inner_face.second.shared_faces[i].first ==
393 inner_face.second.shared_faces[i - 1 - count].first)
400 for (
unsigned int k = 0; k <= count; ++k)
401 assignment[i - 1 - k] = 1;
402 n_faces_higher_proc += count + 1;
412 for (
unsigned int i = 1; i < other_range.size(); ++i)
413 if (std::get<0>(other_range[i]) ==
414 std::get<0>(other_range[i - 1 - count]))
421 for (
unsigned int k = 0; k <= count; ++k)
424 .shared_faces[std::get<2>(
428 .shared_faces[std::get<2>(
429 other_range[i - 1 - k])]
434 if (assignment[std::get<2>(
435 other_range[i - 1 - k])] == 0)
437 assignment[std::get<2>(
438 other_range[i - 1 - k])] = -1;
439 ++n_faces_lower_proc;
453 n_faces_lower_proc +=
454 inner_face.second.n_hanging_faces_smaller_subdomain;
455 n_faces_higher_proc +=
456 inner_face.second.n_hanging_faces_larger_subdomain;
457 const unsigned int n_total_faces_at_proc_boundary =
458 (inner_face.second.shared_faces.size() +
459 inner_face.second.n_hanging_faces_smaller_subdomain +
460 inner_face.second.n_hanging_faces_larger_subdomain);
461 unsigned int split_index = n_total_faces_at_proc_boundary / 2;
462 if (split_index < n_faces_lower_proc)
464 else if (split_index <
465 n_total_faces_at_proc_boundary - n_faces_higher_proc)
466 split_index -= n_faces_lower_proc;
468 split_index = n_total_faces_at_proc_boundary -
469 n_faces_higher_proc - n_faces_lower_proc;
472# if defined(DEAL_II_WITH_MPI) && defined(DEBUG)
473 ierr = MPI_Sendrecv(&split_index,
482 900 + inner_face.first,
487 ierr = MPI_Sendrecv(&n_faces_lower_proc,
496 1000 + inner_face.first,
501 ierr = MPI_Sendrecv(&n_faces_higher_proc,
510 1100 + inner_face.first,
518 std::vector<std::pair<CellId, CellId>> owned_faces_lower,
520 for (
unsigned int i = 0; i < assignment.size(); ++i)
521 if (assignment[i] < 0)
522 owned_faces_lower.push_back(
523 inner_face.second.shared_faces[i]);
524 else if (assignment[i] > 0)
525 owned_faces_higher.push_back(
526 inner_face.second.shared_faces[i]);
528 inner_face.second.shared_faces.size() + 1 -
529 owned_faces_lower.size() -
530 owned_faces_higher.size());
532 unsigned int i = 0, c = 0;
533 for (; i < assignment.size() && c < split_index; ++i)
534 if (assignment[i] == 0)
536 owned_faces_lower.push_back(
537 inner_face.second.shared_faces[i]);
540 for (; i < assignment.size(); ++i)
541 if (assignment[i] == 0)
543 owned_faces_higher.push_back(
544 inner_face.second.shared_faces[i]);
549 std::vector<std::pair<CellId, CellId>> check_faces;
550 check_faces.insert(check_faces.end(),
551 owned_faces_lower.begin(),
552 owned_faces_lower.end());
553 check_faces.insert(check_faces.end(),
554 owned_faces_higher.begin(),
555 owned_faces_higher.end());
556 std::sort(check_faces.begin(), check_faces.end());
558 inner_face.second.shared_faces.size());
559 for (
unsigned int i = 0; i < check_faces.size(); ++i)
560 Assert(check_faces[i] == inner_face.second.shared_faces[i],
565 if (my_domain < inner_face.first)
566 inner_face.second.shared_faces.swap(owned_faces_lower);
568 inner_face.second.shared_faces.swap(owned_faces_higher);
570 std::sort(inner_face.second.shared_faces.begin(),
571 inner_face.second.shared_faces.end());
577 std::set<std::pair<unsigned int, unsigned int>> ghost_cells;
578 for (
unsigned int i = 0; i < cell_levels.size(); ++i)
580 typename ::Triangulation<dim>::cell_iterator dcell(
582 if (use_active_cells)
584 for (
const auto f : dcell->face_indices())
586 if (dcell->at_boundary(f) && !dcell->has_periodic_neighbor(f))
587 face_is_owned[dcell->face(f)->index()] =
588 FaceCategory::locally_active_at_boundary;
589 else if (!build_inner_faces)
594 else if ((dcell->at_boundary(f) ==
false ||
595 dcell->has_periodic_neighbor(f)) &&
597 dcell->neighbor_or_periodic_neighbor(f)->level() <
600 face_is_owned[dcell->face(f)->index()] =
601 FaceCategory::multigrid_refinement_edge;
605 typename ::Triangulation<dim>::cell_iterator neighbor =
606 dcell->neighbor_or_periodic_neighbor(f);
609 if (use_active_cells && neighbor->has_children() &&
610 hold_all_faces_to_owned_cells ==
false)
613 bool add_to_ghost =
false;
615 id1 = use_active_cells ? dcell->subdomain_id() :
616 dcell->level_subdomain_id(),
617 id2 = use_active_cells ?
618 (neighbor->has_children() ?
619 dcell->neighbor_child_on_subface(f, 0)
621 neighbor->subdomain_id()) :
622 neighbor->level_subdomain_id();
630 (use_active_cells ==
false || neighbor->is_active())) ||
631 dcell->level() > neighbor->level() ||
633 inner_faces_at_proc_boundary[id2].shared_faces.begin(),
634 inner_faces_at_proc_boundary[id2].shared_faces.end(),
635 std::make_pair(id1 < id2 ? dcell->
id() : neighbor->id(),
636 id1 < id2 ? neighbor->id() :
639 face_is_owned[dcell->face(f)->index()] =
640 FaceCategory::locally_active_done_here;
641 if (dcell->level() == neighbor->level())
644 ->face(dcell->has_periodic_neighbor(f) ?
645 dcell->periodic_neighbor_face_no(f) :
646 dcell->neighbor_face_no(f))
648 FaceCategory::locally_active_done_here;
654 if (use_active_cells)
656 (dcell->subdomain_id() != neighbor->subdomain_id());
658 add_to_ghost = (dcell->level_subdomain_id() !=
659 neighbor->level_subdomain_id());
661 else if (hold_all_faces_to_owned_cells ==
true)
664 face_is_owned[dcell->face(f)->index()] =
665 FaceCategory::ghosted;
666 if (use_active_cells)
668 if (neighbor->has_children())
669 for (
unsigned int s = 0;
670 s < dcell->face(f)->n_children();
672 if (dcell->at_boundary(f))
675 ->periodic_neighbor_child_on_subface(f,
678 dcell->subdomain_id())
683 if (dcell->neighbor_child_on_subface(f, s)
685 dcell->subdomain_id())
689 add_to_ghost = (dcell->subdomain_id() !=
690 neighbor->subdomain_id());
693 add_to_ghost = (dcell->level_subdomain_id() !=
694 neighbor->level_subdomain_id());
699 if (use_active_cells && neighbor->has_children())
700 for (
unsigned int s = 0;
701 s < dcell->face(f)->n_children();
704 typename ::Triangulation<dim>::cell_iterator
706 dcell->at_boundary(f) ?
707 dcell->periodic_neighbor_child_on_subface(f,
709 dcell->neighbor_child_on_subface(f, s);
710 if (neighbor_child->subdomain_id() !=
711 dcell->subdomain_id())
713 std::pair<unsigned int, unsigned int>(
714 neighbor_child->level(),
715 neighbor_child->index()));
719 std::pair<unsigned int, unsigned int>(
720 neighbor->level(), neighbor->index()));
721 at_processor_boundary[i] =
true;
729 for (
const auto &ghost_cell : ghost_cells)
730 cell_levels.push_back(ghost_cell);
737 FaceSetup<dim>::generate_faces(
739 const std::vector<std::pair<unsigned int, unsigned int>> &cell_levels,
740 TaskInfo & task_info)
746 std::map<std::pair<unsigned int, unsigned int>,
unsigned int>
748 for (
unsigned int cell = 0; cell < cell_levels.size(); ++cell)
749 if (cell == 0 || cell_levels[cell] != cell_levels[cell - 1])
751 typename ::Triangulation<dim>::cell_iterator dcell(
753 cell_levels[cell].
first,
754 cell_levels[cell].
second);
755 std::pair<unsigned int, unsigned int> level_index(dcell->level(),
757 map_to_vectorized[level_index] = cell;
761 const unsigned int vectorization_length = task_info.vectorization_length;
762 task_info.face_partition_data.resize(
763 task_info.cell_partition_data.size() - 1, 0);
764 task_info.boundary_partition_data.resize(
765 task_info.cell_partition_data.size() - 1, 0);
766 std::vector<unsigned char> face_visited(face_is_owned.size(), 0);
767 for (
unsigned int partition = 0;
768 partition < task_info.cell_partition_data.size() - 2;
771 unsigned int boundary_counter = 0;
772 unsigned int inner_counter = 0;
773 for (
unsigned int cell = task_info.cell_partition_data[partition] *
774 vectorization_length;
775 cell < task_info.cell_partition_data[
partition + 1] *
776 vectorization_length;
778 if (cell == 0 || cell_levels[cell] != cell_levels[cell - 1])
780 typename ::Triangulation<dim>::cell_iterator dcell(
782 cell_levels[cell].
first,
783 cell_levels[cell].
second);
784 for (
const auto f : dcell->face_indices())
787 if (face_is_owned[dcell->face(f)->index()] ==
788 FaceCategory::locally_active_at_boundary)
792 FaceToCellTopology<1> info;
793 info.cells_interior[0] = cell;
795 info.interior_face_no = f;
796 info.exterior_face_no = dcell->face(f)->boundary_id();
799 (dcell->face(f)->reference_cell() !=
804 info.face_orientation = 0;
805 boundary_faces.push_back(info);
807 face_visited[dcell->face(f)->index()]++;
812 typename ::Triangulation<dim>::cell_iterator
813 neighbor = dcell->neighbor_or_periodic_neighbor(f);
814 if (use_active_cells && neighbor->has_children())
816 for (
unsigned int c = 0;
817 c < dcell->face(f)->n_children();
820 typename ::Triangulation<
821 dim>::cell_iterator neighbor_c =
822 dcell->at_boundary(f) ?
823 dcell->periodic_neighbor_child_on_subface(
825 dcell->neighbor_child_on_subface(f, c);
827 neighbor_c->subdomain_id();
828 const unsigned int neighbor_face_no =
829 dcell->has_periodic_neighbor(f) ?
830 dcell->periodic_neighbor_face_no(f) :
831 dcell->neighbor_face_no(f);
832 if (neigh_domain != dcell->subdomain_id() ||
834 [dcell->face(f)->child(c)->index()] ==
837 std::pair<unsigned int, unsigned int>
838 level_index(neighbor_c->level(),
839 neighbor_c->index());
841 [dcell->face(f)->child(c)->index()] ==
842 FaceCategory::locally_active_done_here)
845 inner_faces.push_back(create_face(
848 map_to_vectorized[level_index],
853 else if (face_is_owned[dcell->face(f)
856 FaceCategory::ghosted)
858 inner_ghost_faces.push_back(create_face(
861 map_to_vectorized[level_index],
868 face_is_owned[dcell->face(f)
871 locally_active_done_elsewhere ||
872 face_is_owned[dcell->face(f)
874 FaceCategory::ghosted,
880 [dcell->face(f)->child(c)->index()] = 1;
887 use_active_cells ? dcell->subdomain_id() :
888 dcell->level_subdomain_id();
890 use_active_cells ? neighbor->subdomain_id() :
891 neighbor->level_subdomain_id();
892 if (neigh_domain != my_domain ||
893 face_visited[dcell->face(f)->index()] == 1)
895 std::pair<unsigned int, unsigned int>
896 level_index(neighbor->level(),
898 if (face_is_owned[dcell->face(f)->index()] ==
899 FaceCategory::locally_active_done_here)
901 Assert(use_active_cells ||
906 inner_faces.push_back(create_face(
911 map_to_vectorized[level_index],
914 else if (face_is_owned[dcell->face(f)
916 FaceCategory::ghosted)
918 inner_ghost_faces.push_back(create_face(
923 map_to_vectorized[level_index],
929 face_visited[dcell->face(f)->index()] = 1;
930 if (dcell->has_periodic_neighbor(f))
934 dcell->periodic_neighbor_face_no(f))
937 if (face_is_owned[dcell->face(f)->index()] ==
938 FaceCategory::multigrid_refinement_edge)
940 refinement_edge_faces.push_back(
945 refinement_edge_faces.size(),
952 task_info.face_partition_data[
partition + 1] =
953 task_info.face_partition_data[
partition] + inner_counter;
954 task_info.boundary_partition_data[
partition + 1] =
955 task_info.boundary_partition_data[
partition] + boundary_counter;
957 task_info.ghost_face_partition_data.resize(2);
958 task_info.ghost_face_partition_data[0] = 0;
959 task_info.ghost_face_partition_data[1] = inner_ghost_faces.size();
960 task_info.refinement_edge_face_partition_data.resize(2);
961 task_info.refinement_edge_face_partition_data[0] = 0;
962 task_info.refinement_edge_face_partition_data[1] =
963 refinement_edge_faces.size();
969 FaceToCellTopology<1>
970 FaceSetup<dim>::create_face(
971 const unsigned int face_no,
972 const typename ::Triangulation<dim>::cell_iterator &cell,
973 const unsigned int number_cell_interior,
974 const typename ::Triangulation<dim>::cell_iterator &neighbor,
975 const unsigned int number_cell_exterior,
976 const bool is_mixed_mesh)
978 FaceToCellTopology<1> info;
979 info.cells_interior[0] = number_cell_interior;
980 info.cells_exterior[0] = number_cell_exterior;
981 info.interior_face_no = face_no;
982 if (cell->has_periodic_neighbor(face_no))
983 info.exterior_face_no = cell->periodic_neighbor_face_no(face_no);
985 info.exterior_face_no = cell->neighbor_face_no(face_no);
987 info.face_type = is_mixed_mesh ?
988 (cell->face(face_no)->reference_cell() !=
994 if (cell->level() > neighbor->level())
996 if (cell->has_periodic_neighbor(face_no))
998 cell->periodic_neighbor_of_coarser_periodic_neighbor(face_no)
1001 info.subface_index =
1002 cell->neighbor_of_coarser_neighbor(face_no).second;
1006 if (dim == 3 && cell->has_periodic_neighbor(face_no))
1008 const unsigned int exterior_face_orientation =
1009 !cell->get_triangulation()
1010 .get_periodic_face_map()
1011 .at({cell, face_no})
1013 2 * cell->get_triangulation()
1014 .get_periodic_face_map()
1015 .at({cell, face_no})
1017 4 * cell->get_triangulation()
1018 .get_periodic_face_map()
1019 .at({cell, face_no})
1022 info.face_orientation = exterior_face_orientation;
1027 info.face_orientation = 0;
1028 const unsigned int interior_face_orientation =
1029 !cell->face_orientation(face_no) + 2 * cell->face_flip(face_no) +
1030 4 * cell->face_rotation(face_no);
1031 const unsigned int exterior_face_orientation =
1032 !neighbor->face_orientation(info.exterior_face_no) +
1033 2 * neighbor->face_flip(info.exterior_face_no) +
1034 4 * neighbor->face_rotation(info.exterior_face_no);
1035 if (interior_face_orientation != 0)
1037 info.face_orientation = 8 + interior_face_orientation;
1038 Assert(exterior_face_orientation == 0,
1040 "Face seems to be wrongly oriented from both sides"));
1043 info.face_orientation = exterior_face_orientation;
1047 if (cell->level() > neighbor->level() && exterior_face_orientation > 0)
1050 ShapeInfo<double>::compute_orientation_table(2);
1051 const std::array<unsigned int, 8> inverted_orientations{
1052 {0, 1, 2, 3, 6, 5, 4, 7}};
1053 info.subface_index =
1054 orientation[inverted_orientations[exterior_face_orientation]]
1055 [info.subface_index];
1070 compare_faces_for_vectorization(
1071 const FaceToCellTopology<1> & face1,
1072 const FaceToCellTopology<1> & face2,
1073 const std::vector<unsigned int> &active_fe_indices,
1074 const unsigned int length)
1076 if (face1.interior_face_no != face2.interior_face_no)
1078 if (face1.exterior_face_no != face2.exterior_face_no)
1080 if (face1.subface_index != face2.subface_index)
1082 if (face1.face_orientation != face2.face_orientation)
1084 if (face1.face_type != face2.face_type)
1087 if (active_fe_indices.size() > 0)
1089 if (active_fe_indices[face1.cells_interior[0] / length] !=
1090 active_fe_indices[face2.cells_interior[0] / length])
1094 if (active_fe_indices[face1.cells_exterior[0] / length] !=
1095 active_fe_indices[face2.cells_exterior[0] / length])
1110 template <
int length>
1111 struct FaceComparator
1113 FaceComparator(
const std::vector<unsigned int> &active_fe_indices)
1114 : active_fe_indices(active_fe_indices)
1118 operator()(
const FaceToCellTopology<length> &face1,
1119 const FaceToCellTopology<length> &face2)
const
1122 if (face1.face_type < face2.face_type)
1124 else if (face1.face_type > face2.face_type)
1128 if (active_fe_indices.size() > 0)
1131 if (active_fe_indices[face1.cells_interior[0] / length] <
1132 active_fe_indices[face2.cells_interior[0] / length])
1134 else if (active_fe_indices[face1.cells_interior[0] / length] >
1135 active_fe_indices[face2.cells_interior[0] / length])
1141 if (active_fe_indices[face1.cells_exterior[0] / length] <
1142 active_fe_indices[face2.cells_exterior[0] / length])
1144 else if (active_fe_indices[face1.cells_exterior[0] / length] >
1145 active_fe_indices[face2.cells_exterior[0] / length])
1150 for (
unsigned int i = 0; i < length; ++i)
1151 if (face1.cells_interior[i] < face2.cells_interior[i])
1153 else if (face1.cells_interior[i] > face2.cells_interior[i])
1155 for (
unsigned int i = 0; i < length; ++i)
1156 if (face1.cells_exterior[i] < face2.cells_exterior[i])
1158 else if (face1.cells_exterior[i] > face2.cells_exterior[i])
1160 if (face1.interior_face_no < face2.interior_face_no)
1162 else if (face1.interior_face_no > face2.interior_face_no)
1164 if (face1.exterior_face_no < face2.exterior_face_no)
1166 else if (face1.exterior_face_no > face2.exterior_face_no)
1179 const std::vector<unsigned int> &active_fe_indices;
1184 template <
int vectorization_w
idth>
1187 const std::vector<FaceToCellTopology<1>> &faces_in,
1188 const std::vector<bool> & hard_vectorization_boundary,
1189 std::vector<unsigned int> & face_partition_data,
1190 std::vector<FaceToCellTopology<vectorization_width>> &faces_out,
1191 const std::vector<unsigned int> & active_fe_indices)
1193 FaceToCellTopology<vectorization_width> face_batch;
1194 std::vector<std::vector<unsigned int>> faces_type;
1196 unsigned int face_start = face_partition_data[0],
1197 face_end = face_partition_data[0];
1199 face_partition_data[0] = faces_out.size();
1200 for (
unsigned int partition = 0;
1201 partition < face_partition_data.size() - 1;
1204 std::vector<std::vector<unsigned int>> new_faces_type;
1207 face_start = face_end;
1208 face_end = face_partition_data[
partition + 1];
1215 for (
unsigned int face = face_start; face < face_end; ++face)
1217 for (
auto &face_type : faces_type)
1220 if (compare_faces_for_vectorization(faces_in[face],
1221 faces_in[face_type[0]],
1223 vectorization_width))
1225 face_type.push_back(face);
1229 faces_type.emplace_back(1, face);
1235 FaceComparator<vectorization_width> face_comparator(
1237 std::set<FaceToCellTopology<vectorization_width>,
1238 FaceComparator<vectorization_width>>
1239 new_faces(face_comparator);
1240 for (
const auto &face_type : faces_type)
1242 face_batch.face_type = faces_in[face_type[0]].face_type;
1243 face_batch.interior_face_no =
1244 faces_in[face_type[0]].interior_face_no;
1245 face_batch.exterior_face_no =
1246 faces_in[face_type[0]].exterior_face_no;
1247 face_batch.subface_index = faces_in[face_type[0]].subface_index;
1248 face_batch.face_orientation =
1249 faces_in[face_type[0]].face_orientation;
1250 unsigned int no_faces = face_type.size();
1251 std::vector<unsigned char> touched(no_faces, 0);
1257 unsigned int n_vectorized = 0;
1258 for (
unsigned int f = 0; f < no_faces; ++f)
1259 if (faces_in[face_type[f]].cells_interior[0] %
1260 vectorization_width ==
1263 bool is_contiguous =
true;
1264 if (f + vectorization_width > no_faces)
1265 is_contiguous =
false;
1267 for (
unsigned int v = 1; v < vectorization_width; ++v)
1268 if (faces_in[face_type[f + v]].cells_interior[0] !=
1269 faces_in[face_type[f]].cells_interior[0] + v)
1270 is_contiguous =
false;
1275 vectorization_width + 1);
1276 for (
unsigned int v = 0; v < vectorization_width; ++v)
1278 face_batch.cells_interior[v] =
1279 faces_in[face_type[f + v]].cells_interior[0];
1280 face_batch.cells_exterior[v] =
1281 faces_in[face_type[f + v]].cells_exterior[0];
1284 new_faces.insert(face_batch);
1285 f += vectorization_width - 1;
1286 n_vectorized += vectorization_width;
1290 std::vector<unsigned int> untouched;
1291 untouched.reserve(no_faces - n_vectorized);
1292 for (
unsigned int f = 0; f < no_faces; ++f)
1293 if (touched[f] == 0)
1294 untouched.push_back(f);
1296 for (
const auto f : untouched)
1298 face_batch.cells_interior[v] =
1299 faces_in[face_type[f]].cells_interior[0];
1300 face_batch.cells_exterior[v] =
1301 faces_in[face_type[f]].cells_exterior[0];
1303 if (v == vectorization_width)
1305 new_faces.insert(face_batch);
1309 if (v > 0 && v < vectorization_width)
1312 if (hard_vectorization_boundary[partition + 1] ||
1313 partition == face_partition_data.size() - 2)
1315 for (; v < vectorization_width; ++v)
1318 face_batch.cells_interior[v] =
1320 face_batch.cells_exterior[v] =
1323 new_faces.insert(face_batch);
1328 std::vector<unsigned int> untreated(v);
1329 for (
unsigned int f = 0; f < v; ++f)
1330 untreated[f] = face_type[*(untouched.end() - 1 - f)];
1331 new_faces_type.push_back(untreated);
1337 for (
auto it = new_faces.begin(); it != new_faces.end(); ++it)
1338 faces_out.push_back(*it);
1339 face_partition_data[
partition + 1] += new_faces.size();
1342 faces_type = std::move(new_faces_type);
1347 for (
const auto &face_type : faces_type)
1351 unsigned int nfaces = 0;
1352 for (
unsigned int i = face_partition_data[0];
1353 i < face_partition_data.back();
1355 for (
unsigned int v = 0; v < vectorization_width; ++v)
1360 std::vector<std::pair<unsigned int, unsigned int>> in_faces, out_faces;
1361 for (
const auto &face_in : faces_in)
1362 in_faces.emplace_back(face_in.cells_interior[0],
1363 face_in.cells_exterior[0]);
1364 for (
unsigned int i = face_partition_data[0];
1365 i < face_partition_data.back();
1367 for (
unsigned int v = 0;
1368 v < vectorization_width &&
1371 out_faces.emplace_back(faces_out[i].cells_interior[v],
1372 faces_out[i].cells_exterior[v]);
1373 std::sort(in_faces.begin(), in_faces.end());
1374 std::sort(out_faces.begin(), out_faces.end());
1376 for (
unsigned int i = 0; i < in_faces.size(); ++i)
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
#define AssertDimension(dim1, dim2)
#define AssertThrowMPI(error_code)
#define AssertIndexRange(index, range)
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
constexpr const ReferenceCell & get_hypercube()
void collect_faces_vectorization(const std::vector< FaceToCellTopology< 1 > > &faces_in, const std::vector< bool > &hard_vectorization_boundary, std::vector< unsigned int > &face_partition_data, std::vector< FaceToCellTopology< vectorization_width > > &faces_out)
const types::subdomain_id invalid_subdomain_id
static const unsigned int invalid_unsigned_int
const ::parallel::distributed::Triangulation< dim, spacedim > * triangulation
unsigned int n_hanging_faces_smaller_subdomain
unsigned int n_hanging_faces_larger_subdomain
std::vector< std::pair< CellId, CellId > > shared_faces
std::vector< FaceToCellTopology< 1 > > inner_faces
std::vector< bool > at_processor_boundary
std::vector< FaceToCellTopology< 1 > > boundary_faces
std::vector< FaceToCellTopology< 1 > > refinement_edge_faces
FaceToCellTopology< 1 > create_face(const unsigned int face_no, const typename ::Triangulation< dim >::cell_iterator &cell, const unsigned int number_cell_interior, const typename ::Triangulation< dim >::cell_iterator &neighbor, const unsigned int number_cell_exterior, const bool is_mixed_mesh)
std::vector< FaceCategory > face_is_owned
@ locally_active_done_here
@ multigrid_refinement_edge
@ locally_active_at_boundary
@ locally_active_done_elsewhere
void initialize(const ::Triangulation< dim > &triangulation, const unsigned int mg_level, const bool hold_all_faces_to_owned_cells, const bool build_inner_faces, std::vector< std::pair< unsigned int, unsigned int > > &cell_levels)
std::vector< FaceToCellTopology< 1 > > inner_ghost_faces
void generate_faces(const ::Triangulation< dim > &triangulation, const std::vector< std::pair< unsigned int, unsigned int > > &cell_levels, TaskInfo &task_info)