17#ifndef dealii_face_setup_internal_h
18#define dealii_face_setup_internal_h
42 namespace MatrixFreeFunctions
84 const unsigned int mg_level,
85 const bool hold_all_faces_to_owned_cells,
86 const bool build_inner_faces,
87 std::vector<std::pair<unsigned int, unsigned int>> &cell_levels);
98 const std::vector<std::pair<unsigned int, unsigned int>> &cell_levels,
109 const unsigned int face_no,
110 const typename ::Triangulation<dim>::cell_iterator &cell,
111 const unsigned int number_cell_interior,
112 const typename ::Triangulation<dim>::cell_iterator &neighbor,
113 const unsigned int number_cell_exterior,
114 const bool is_mixed_mesh);
144 template <
int vectorization_w
idth>
148 const std::vector<bool> & hard_vectorization_boundary,
149 std::vector<unsigned int> & face_partition_data,
160 : use_active_cells(true)
167 FaceSetup<dim>::initialize(
169 const unsigned int mg_level,
170 const bool hold_all_faces_to_owned_cells,
171 const bool build_inner_faces,
172 std::vector<std::pair<unsigned int, unsigned int>> &cell_levels)
178 if (use_active_cells)
179 for (
const auto &cell_level : cell_levels)
181 typename ::Triangulation<dim>::cell_iterator dcell(
190 at_processor_boundary.resize(cell_levels.size(),
false);
193 FaceCategory::locally_active_done_elsewhere);
197 std::map<types::subdomain_id, FaceIdentifier>
198 inner_faces_at_proc_boundary;
204 for (
unsigned int i = 0; i < cell_levels.size(); ++i)
206 if (i > 0 && cell_levels[i] == cell_levels[i - 1])
208 typename ::Triangulation<dim>::cell_iterator dcell(
210 for (
const unsigned int f : dcell->face_indices())
212 if (dcell->at_boundary(f) && !dcell->has_periodic_neighbor(f))
214 typename ::Triangulation<dim>::cell_iterator neighbor =
215 dcell->neighbor_or_periodic_neighbor(f);
221 const CellId id_mine = dcell->id();
222 if (use_active_cells && neighbor->has_children())
223 for (
unsigned int c = 0;
224 c < (dcell->has_periodic_neighbor(f) ?
225 dcell->periodic_neighbor(f)
226 ->face(dcell->periodic_neighbor_face_no(f))
228 dcell->face(f)->n_children());
231 typename ::Triangulation<dim>::cell_iterator
233 dcell->at_boundary(f) ?
234 dcell->periodic_neighbor_child_on_subface(f, c) :
235 dcell->neighbor_child_on_subface(f, c);
237 neighbor_c->subdomain_id();
238 if (my_domain < neigh_domain)
239 inner_faces_at_proc_boundary[neigh_domain]
240 .n_hanging_faces_larger_subdomain++;
241 else if (my_domain > neigh_domain)
242 inner_faces_at_proc_boundary[neigh_domain]
243 .n_hanging_faces_smaller_subdomain++;
248 use_active_cells ? neighbor->subdomain_id() :
249 neighbor->level_subdomain_id();
250 if (neighbor->level() < dcell->level() &&
253 if (my_domain < neigh_domain)
254 inner_faces_at_proc_boundary[neigh_domain]
255 .n_hanging_faces_smaller_subdomain++;
256 else if (my_domain > neigh_domain)
257 inner_faces_at_proc_boundary[neigh_domain]
258 .n_hanging_faces_larger_subdomain++;
260 else if (neighbor->level() == dcell->level() &&
261 my_domain != neigh_domain)
267 const CellId id_neigh = neighbor->id();
268 if (my_domain < neigh_domain)
269 inner_faces_at_proc_boundary[neigh_domain]
270 .shared_faces.emplace_back(id_mine, id_neigh);
272 inner_faces_at_proc_boundary[neigh_domain]
273 .shared_faces.emplace_back(id_neigh, id_mine);
282 for (
auto &inner_face : inner_faces_at_proc_boundary)
284 Assert(inner_face.first != my_domain,
286 std::sort(inner_face.second.shared_faces.begin(),
287 inner_face.second.shared_faces.end());
288 inner_face.second.shared_faces.erase(
289 std::unique(inner_face.second.shared_faces.begin(),
290 inner_face.second.shared_faces.end()),
291 inner_face.second.shared_faces.end());
296# if defined(DEAL_II_WITH_MPI) && defined(DEBUG)
298 if (const ::parallel::TriangulationBase<dim> *ptria =
299 dynamic_cast<const ::parallel::TriangulationBase<dim>
301 comm = ptria->get_communicator();
304 unsigned int mysize = inner_face.second.shared_faces.size();
307 int ierr = MPI_Sendrecv(&mysize,
316 600 + inner_face.first,
321 mysize = inner_face.second.n_hanging_faces_smaller_subdomain;
322 ierr = MPI_Sendrecv(&mysize,
331 700 + inner_face.first,
336 mysize = inner_face.second.n_hanging_faces_larger_subdomain;
337 ierr = MPI_Sendrecv(&mysize,
346 800 + inner_face.first,
368 std::vector<std::tuple<CellId, CellId, unsigned int>> other_range(
369 inner_face.second.shared_faces.size());
370 for (
unsigned int i = 0; i < other_range.size(); ++i)
372 std::make_tuple(inner_face.second.shared_faces[i].second,
373 inner_face.second.shared_faces[i].first,
375 std::sort(other_range.begin(), other_range.end());
383 unsigned int n_faces_lower_proc = 0, n_faces_higher_proc = 0;
384 std::vector<char> assignment(other_range.size(), 0);
385 if (inner_face.second.shared_faces.size() > 0)
389 unsigned int count = 0;
390 for (
unsigned int i = 1;
391 i < inner_face.second.shared_faces.size();
393 if (inner_face.second.shared_faces[i].first ==
394 inner_face.second.shared_faces[i - 1 - count].first)
401 for (
unsigned int k = 0; k <= count; ++k)
402 assignment[i - 1 - k] = 1;
403 n_faces_higher_proc += count + 1;
413 for (
unsigned int i = 1; i < other_range.size(); ++i)
414 if (std::get<0>(other_range[i]) ==
415 std::get<0>(other_range[i - 1 - count]))
422 for (
unsigned int k = 0; k <= count; ++k)
425 .shared_faces[std::get<2>(
429 .shared_faces[std::get<2>(
430 other_range[i - 1 - k])]
435 if (assignment[std::get<2>(
436 other_range[i - 1 - k])] == 0)
438 assignment[std::get<2>(
439 other_range[i - 1 - k])] = -1;
440 ++n_faces_lower_proc;
454 n_faces_lower_proc +=
455 inner_face.second.n_hanging_faces_smaller_subdomain;
456 n_faces_higher_proc +=
457 inner_face.second.n_hanging_faces_larger_subdomain;
458 const unsigned int n_total_faces_at_proc_boundary =
459 (inner_face.second.shared_faces.size() +
460 inner_face.second.n_hanging_faces_smaller_subdomain +
461 inner_face.second.n_hanging_faces_larger_subdomain);
462 unsigned int split_index = n_total_faces_at_proc_boundary / 2;
463 if (split_index < n_faces_lower_proc)
465 else if (split_index <
466 n_total_faces_at_proc_boundary - n_faces_higher_proc)
467 split_index -= n_faces_lower_proc;
469 split_index = n_total_faces_at_proc_boundary -
470 n_faces_higher_proc - n_faces_lower_proc;
473# if defined(DEAL_II_WITH_MPI) && defined(DEBUG)
474 ierr = MPI_Sendrecv(&split_index,
483 900 + inner_face.first,
488 ierr = MPI_Sendrecv(&n_faces_lower_proc,
497 1000 + inner_face.first,
502 ierr = MPI_Sendrecv(&n_faces_higher_proc,
511 1100 + inner_face.first,
519 std::vector<std::pair<CellId, CellId>> owned_faces_lower,
521 for (
unsigned int i = 0; i < assignment.size(); ++i)
522 if (assignment[i] < 0)
523 owned_faces_lower.push_back(
524 inner_face.second.shared_faces[i]);
525 else if (assignment[i] > 0)
526 owned_faces_higher.push_back(
527 inner_face.second.shared_faces[i]);
529 inner_face.second.shared_faces.size() + 1 -
530 owned_faces_lower.size() -
531 owned_faces_higher.size());
533 unsigned int i = 0, c = 0;
534 for (; i < assignment.size() && c < split_index; ++i)
535 if (assignment[i] == 0)
537 owned_faces_lower.push_back(
538 inner_face.second.shared_faces[i]);
541 for (; i < assignment.size(); ++i)
542 if (assignment[i] == 0)
544 owned_faces_higher.push_back(
545 inner_face.second.shared_faces[i]);
550 std::vector<std::pair<CellId, CellId>> check_faces;
551 check_faces.insert(check_faces.end(),
552 owned_faces_lower.begin(),
553 owned_faces_lower.end());
554 check_faces.insert(check_faces.end(),
555 owned_faces_higher.begin(),
556 owned_faces_higher.end());
557 std::sort(check_faces.begin(), check_faces.end());
559 inner_face.second.shared_faces.size());
560 for (
unsigned int i = 0; i < check_faces.size(); ++i)
561 Assert(check_faces[i] == inner_face.second.shared_faces[i],
566 if (my_domain < inner_face.first)
567 inner_face.second.shared_faces.swap(owned_faces_lower);
569 inner_face.second.shared_faces.swap(owned_faces_higher);
571 std::sort(inner_face.second.shared_faces.begin(),
572 inner_face.second.shared_faces.end());
578 std::set<std::pair<unsigned int, unsigned int>> ghost_cells;
579 for (
unsigned int i = 0; i < cell_levels.size(); ++i)
581 typename ::Triangulation<dim>::cell_iterator dcell(
583 if (use_active_cells)
585 for (
const auto f : dcell->face_indices())
587 if (dcell->at_boundary(f) && !dcell->has_periodic_neighbor(f))
588 face_is_owned[dcell->face(f)->index()] =
589 FaceCategory::locally_active_at_boundary;
590 else if (!build_inner_faces)
595 else if ((dcell->at_boundary(f) ==
false ||
596 dcell->has_periodic_neighbor(f)) &&
598 dcell->neighbor_or_periodic_neighbor(f)->level() <
601 face_is_owned[dcell->face(f)->index()] =
602 FaceCategory::multigrid_refinement_edge;
606 typename ::Triangulation<dim>::cell_iterator neighbor =
607 dcell->neighbor_or_periodic_neighbor(f);
610 if (use_active_cells && neighbor->has_children() &&
611 hold_all_faces_to_owned_cells ==
false)
614 bool add_to_ghost =
false;
616 id1 = use_active_cells ? dcell->subdomain_id() :
617 dcell->level_subdomain_id(),
618 id2 = use_active_cells ?
619 (neighbor->has_children() ?
620 dcell->neighbor_child_on_subface(f, 0)
622 neighbor->subdomain_id()) :
623 neighbor->level_subdomain_id();
631 (use_active_cells ==
false || neighbor->is_active())) ||
632 dcell->level() > neighbor->level() ||
634 inner_faces_at_proc_boundary[id2].shared_faces.begin(),
635 inner_faces_at_proc_boundary[id2].shared_faces.end(),
636 std::make_pair(id1 < id2 ? dcell->
id() : neighbor->id(),
637 id1 < id2 ? neighbor->
id() :
640 face_is_owned[dcell->face(f)->index()] =
641 FaceCategory::locally_active_done_here;
642 if (dcell->level() == neighbor->level())
645 ->face(dcell->has_periodic_neighbor(f) ?
646 dcell->periodic_neighbor_face_no(f) :
647 dcell->neighbor_face_no(f))
649 FaceCategory::locally_active_done_here;
655 if (use_active_cells)
657 (dcell->subdomain_id() != neighbor->subdomain_id());
659 add_to_ghost = (dcell->level_subdomain_id() !=
660 neighbor->level_subdomain_id());
662 else if (hold_all_faces_to_owned_cells ==
true)
665 face_is_owned[dcell->face(f)->index()] =
666 FaceCategory::ghosted;
667 if (use_active_cells)
669 if (neighbor->has_children())
670 for (
unsigned int s = 0;
671 s < dcell->face(f)->n_children();
673 if (dcell->at_boundary(f))
676 ->periodic_neighbor_child_on_subface(f,
679 dcell->subdomain_id())
684 if (dcell->neighbor_child_on_subface(f, s)
686 dcell->subdomain_id())
690 add_to_ghost = (dcell->subdomain_id() !=
691 neighbor->subdomain_id());
694 add_to_ghost = (dcell->level_subdomain_id() !=
695 neighbor->level_subdomain_id());
700 if (use_active_cells && neighbor->has_children())
701 for (
unsigned int s = 0;
702 s < dcell->face(f)->n_children();
705 typename ::Triangulation<dim>::cell_iterator
707 dcell->at_boundary(f) ?
708 dcell->periodic_neighbor_child_on_subface(f,
710 dcell->neighbor_child_on_subface(f, s);
711 if (neighbor_child->subdomain_id() !=
712 dcell->subdomain_id())
714 std::pair<unsigned int, unsigned int>(
715 neighbor_child->level(),
716 neighbor_child->index()));
720 std::pair<unsigned int, unsigned int>(
721 neighbor->level(), neighbor->index()));
722 at_processor_boundary[i] =
true;
730 for (
const auto &ghost_cell : ghost_cells)
731 cell_levels.push_back(ghost_cell);
738 FaceSetup<dim>::generate_faces(
740 const std::vector<std::pair<unsigned int, unsigned int>> &cell_levels,
741 TaskInfo & task_info)
747 std::map<std::pair<unsigned int, unsigned int>,
unsigned int>
749 for (
unsigned int cell = 0; cell < cell_levels.size(); ++cell)
750 if (cell == 0 || cell_levels[cell] != cell_levels[cell - 1])
752 typename ::Triangulation<dim>::cell_iterator dcell(
754 cell_levels[cell].
first,
755 cell_levels[cell].
second);
756 std::pair<unsigned int, unsigned int> level_index(dcell->level(),
758 map_to_vectorized[level_index] = cell;
762 const unsigned int vectorization_length = task_info.vectorization_length;
763 task_info.face_partition_data.resize(
764 task_info.cell_partition_data.size() - 1, 0);
765 task_info.boundary_partition_data.resize(
766 task_info.cell_partition_data.size() - 1, 0);
767 std::vector<unsigned char> face_visited(face_is_owned.size(), 0);
768 for (
unsigned int partition = 0;
769 partition < task_info.cell_partition_data.size() - 2;
772 unsigned int boundary_counter = 0;
773 unsigned int inner_counter = 0;
774 for (
unsigned int cell = task_info.cell_partition_data[partition] *
775 vectorization_length;
776 cell < task_info.cell_partition_data[partition + 1] *
777 vectorization_length;
779 if (cell == 0 || cell_levels[cell] != cell_levels[cell - 1])
781 typename ::Triangulation<dim>::cell_iterator dcell(
783 cell_levels[cell].
first,
784 cell_levels[cell].
second);
785 for (
const auto f : dcell->face_indices())
788 if (face_is_owned[dcell->face(f)->index()] ==
789 FaceCategory::locally_active_at_boundary)
793 FaceToCellTopology<1> info;
794 info.cells_interior[0] = cell;
796 info.interior_face_no = f;
797 info.exterior_face_no = dcell->face(f)->boundary_id();
800 (dcell->face(f)->reference_cell() !=
805 info.face_orientation = 0;
806 boundary_faces.push_back(info);
808 face_visited[dcell->face(f)->index()]++;
813 typename ::Triangulation<dim>::cell_iterator
814 neighbor = dcell->neighbor_or_periodic_neighbor(f);
815 if (use_active_cells && neighbor->has_children())
817 for (
unsigned int c = 0;
818 c < dcell->face(f)->n_children();
821 typename ::Triangulation<
822 dim>::cell_iterator neighbor_c =
823 dcell->at_boundary(f) ?
824 dcell->periodic_neighbor_child_on_subface(
826 dcell->neighbor_child_on_subface(f, c);
828 neighbor_c->subdomain_id();
829 const unsigned int neighbor_face_no =
830 dcell->has_periodic_neighbor(f) ?
831 dcell->periodic_neighbor_face_no(f) :
832 dcell->neighbor_face_no(f);
833 if (neigh_domain != dcell->subdomain_id() ||
835 [dcell->face(f)->child(c)->index()] ==
838 std::pair<unsigned int, unsigned int>
839 level_index(neighbor_c->level(),
840 neighbor_c->index());
842 [dcell->face(f)->child(c)->index()] ==
843 FaceCategory::locally_active_done_here)
846 inner_faces.push_back(create_face(
849 map_to_vectorized[level_index],
854 else if (face_is_owned[dcell->face(f)
857 FaceCategory::ghosted)
859 inner_ghost_faces.push_back(create_face(
862 map_to_vectorized[level_index],
869 face_is_owned[dcell->face(f)
872 locally_active_done_elsewhere ||
873 face_is_owned[dcell->face(f)
875 FaceCategory::ghosted,
881 [dcell->face(f)->child(c)->index()] = 1;
888 use_active_cells ? dcell->subdomain_id() :
889 dcell->level_subdomain_id();
891 use_active_cells ? neighbor->subdomain_id() :
892 neighbor->level_subdomain_id();
893 if (neigh_domain != my_domain ||
894 face_visited[dcell->face(f)->index()] == 1)
896 std::pair<unsigned int, unsigned int>
897 level_index(neighbor->level(),
899 if (face_is_owned[dcell->face(f)->index()] ==
900 FaceCategory::locally_active_done_here)
902 Assert(use_active_cells ||
907 inner_faces.push_back(create_face(
912 map_to_vectorized[level_index],
915 else if (face_is_owned[dcell->face(f)
917 FaceCategory::ghosted)
919 inner_ghost_faces.push_back(create_face(
924 map_to_vectorized[level_index],
930 face_visited[dcell->face(f)->index()] = 1;
931 if (dcell->has_periodic_neighbor(f))
935 dcell->periodic_neighbor_face_no(f))
938 if (face_is_owned[dcell->face(f)->index()] ==
939 FaceCategory::multigrid_refinement_edge)
941 refinement_edge_faces.push_back(
946 refinement_edge_faces.size(),
953 task_info.face_partition_data[
partition + 1] =
954 task_info.face_partition_data[
partition] + inner_counter;
955 task_info.boundary_partition_data[
partition + 1] =
956 task_info.boundary_partition_data[
partition] + boundary_counter;
958 task_info.ghost_face_partition_data.resize(2);
959 task_info.ghost_face_partition_data[0] = 0;
960 task_info.ghost_face_partition_data[1] = inner_ghost_faces.size();
961 task_info.refinement_edge_face_partition_data.resize(2);
962 task_info.refinement_edge_face_partition_data[0] = 0;
963 task_info.refinement_edge_face_partition_data[1] =
964 refinement_edge_faces.size();
970 FaceToCellTopology<1>
971 FaceSetup<dim>::create_face(
972 const unsigned int face_no,
973 const typename ::Triangulation<dim>::cell_iterator &cell,
974 const unsigned int number_cell_interior,
975 const typename ::Triangulation<dim>::cell_iterator &neighbor,
976 const unsigned int number_cell_exterior,
977 const bool is_mixed_mesh)
979 FaceToCellTopology<1> info;
980 info.cells_interior[0] = number_cell_interior;
981 info.cells_exterior[0] = number_cell_exterior;
982 info.interior_face_no = face_no;
983 if (cell->has_periodic_neighbor(face_no))
984 info.exterior_face_no = cell->periodic_neighbor_face_no(face_no);
986 info.exterior_face_no = cell->neighbor_face_no(face_no);
988 info.face_type = is_mixed_mesh ?
989 (cell->face(face_no)->reference_cell() !=
995 if (cell->level() > neighbor->level())
997 if (cell->has_periodic_neighbor(face_no))
999 cell->periodic_neighbor_of_coarser_periodic_neighbor(face_no)
1002 info.subface_index =
1003 cell->neighbor_of_coarser_neighbor(face_no).second;
1007 if (dim == 3 && cell->has_periodic_neighbor(face_no))
1009 const unsigned int exterior_face_orientation =
1010 !cell->get_triangulation()
1011 .get_periodic_face_map()
1012 .at({cell, face_no})
1014 2 * cell->get_triangulation()
1015 .get_periodic_face_map()
1016 .at({cell, face_no})
1018 4 * cell->get_triangulation()
1019 .get_periodic_face_map()
1020 .at({cell, face_no})
1023 info.face_orientation = exterior_face_orientation;
1028 info.face_orientation = 0;
1029 const unsigned int interior_face_orientation =
1030 !cell->face_orientation(face_no) + 2 * cell->face_flip(face_no) +
1031 4 * cell->face_rotation(face_no);
1032 const unsigned int exterior_face_orientation =
1033 !neighbor->face_orientation(info.exterior_face_no) +
1034 2 * neighbor->face_flip(info.exterior_face_no) +
1035 4 * neighbor->face_rotation(info.exterior_face_no);
1036 if (interior_face_orientation != 0)
1038 info.face_orientation = 8 + interior_face_orientation;
1039 Assert(exterior_face_orientation == 0,
1041 "Face seems to be wrongly oriented from both sides"));
1044 info.face_orientation = exterior_face_orientation;
1048 if (cell->level() > neighbor->level() && exterior_face_orientation > 0)
1051 ShapeInfo<double>::compute_orientation_table(2);
1052 const std::array<unsigned int, 8> inverted_orientations{
1053 {0, 1, 2, 3, 6, 5, 4, 7}};
1054 info.subface_index =
1055 orientation[inverted_orientations[exterior_face_orientation]]
1056 [info.subface_index];
1071 compare_faces_for_vectorization(
1072 const FaceToCellTopology<1> & face1,
1073 const FaceToCellTopology<1> & face2,
1074 const std::vector<unsigned int> &active_fe_indices,
1075 const unsigned int length)
1077 if (face1.interior_face_no != face2.interior_face_no)
1079 if (face1.exterior_face_no != face2.exterior_face_no)
1081 if (face1.subface_index != face2.subface_index)
1083 if (face1.face_orientation != face2.face_orientation)
1085 if (face1.face_type != face2.face_type)
1088 if (active_fe_indices.size() > 0)
1090 if (active_fe_indices[face1.cells_interior[0] / length] !=
1091 active_fe_indices[face2.cells_interior[0] / length])
1095 if (active_fe_indices[face1.cells_exterior[0] / length] !=
1096 active_fe_indices[face2.cells_exterior[0] / length])
1111 template <
int length>
1112 struct FaceComparator
1114 FaceComparator(
const std::vector<unsigned int> &active_fe_indices)
1115 : active_fe_indices(active_fe_indices)
1119 operator()(
const FaceToCellTopology<length> &face1,
1120 const FaceToCellTopology<length> &face2)
const
1123 if (face1.face_type < face2.face_type)
1125 else if (face1.face_type > face2.face_type)
1129 if (active_fe_indices.size() > 0)
1132 if (active_fe_indices[face1.cells_interior[0] / length] <
1133 active_fe_indices[face2.cells_interior[0] / length])
1135 else if (active_fe_indices[face1.cells_interior[0] / length] >
1136 active_fe_indices[face2.cells_interior[0] / length])
1142 if (active_fe_indices[face1.cells_exterior[0] / length] <
1143 active_fe_indices[face2.cells_exterior[0] / length])
1145 else if (active_fe_indices[face1.cells_exterior[0] / length] >
1146 active_fe_indices[face2.cells_exterior[0] / length])
1151 for (
unsigned int i = 0; i < length; ++i)
1152 if (face1.cells_interior[i] < face2.cells_interior[i])
1154 else if (face1.cells_interior[i] > face2.cells_interior[i])
1156 for (
unsigned int i = 0; i < length; ++i)
1157 if (face1.cells_exterior[i] < face2.cells_exterior[i])
1159 else if (face1.cells_exterior[i] > face2.cells_exterior[i])
1161 if (face1.interior_face_no < face2.interior_face_no)
1163 else if (face1.interior_face_no > face2.interior_face_no)
1165 if (face1.exterior_face_no < face2.exterior_face_no)
1167 else if (face1.exterior_face_no > face2.exterior_face_no)
1180 const std::vector<unsigned int> &active_fe_indices;
1185 template <
int vectorization_w
idth>
1188 const std::vector<FaceToCellTopology<1>> &faces_in,
1189 const std::vector<bool> & hard_vectorization_boundary,
1190 std::vector<unsigned int> & face_partition_data,
1191 std::vector<FaceToCellTopology<vectorization_width>> &faces_out,
1192 const std::vector<unsigned int> & active_fe_indices)
1194 FaceToCellTopology<vectorization_width> face_batch;
1195 std::vector<std::vector<unsigned int>> faces_type;
1197 unsigned int face_start = face_partition_data[0],
1198 face_end = face_partition_data[0];
1200 face_partition_data[0] = faces_out.size();
1201 for (
unsigned int partition = 0;
1202 partition < face_partition_data.size() - 1;
1205 std::vector<std::vector<unsigned int>> new_faces_type;
1208 face_start = face_end;
1209 face_end = face_partition_data[
partition + 1];
1216 for (
unsigned int face = face_start; face < face_end; ++face)
1218 for (
auto &face_type : faces_type)
1221 if (compare_faces_for_vectorization(faces_in[face],
1222 faces_in[face_type[0]],
1224 vectorization_width))
1226 face_type.push_back(face);
1230 faces_type.emplace_back(1, face);
1236 FaceComparator<vectorization_width> face_comparator(
1238 std::set<FaceToCellTopology<vectorization_width>,
1239 FaceComparator<vectorization_width>>
1240 new_faces(face_comparator);
1241 for (
const auto &face_type : faces_type)
1243 face_batch.face_type = faces_in[face_type[0]].face_type;
1244 face_batch.interior_face_no =
1245 faces_in[face_type[0]].interior_face_no;
1246 face_batch.exterior_face_no =
1247 faces_in[face_type[0]].exterior_face_no;
1248 face_batch.subface_index = faces_in[face_type[0]].subface_index;
1249 face_batch.face_orientation =
1250 faces_in[face_type[0]].face_orientation;
1251 unsigned int no_faces = face_type.size();
1252 std::vector<unsigned char> touched(no_faces, 0);
1258 unsigned int n_vectorized = 0;
1259 for (
unsigned int f = 0; f < no_faces; ++f)
1260 if (faces_in[face_type[f]].cells_interior[0] %
1261 vectorization_width ==
1264 bool is_contiguous =
true;
1265 if (f + vectorization_width > no_faces)
1266 is_contiguous =
false;
1268 for (
unsigned int v = 1; v < vectorization_width; ++v)
1269 if (faces_in[face_type[f + v]].cells_interior[0] !=
1270 faces_in[face_type[f]].cells_interior[0] + v)
1271 is_contiguous =
false;
1276 vectorization_width + 1);
1277 for (
unsigned int v = 0; v < vectorization_width; ++v)
1279 face_batch.cells_interior[v] =
1280 faces_in[face_type[f + v]].cells_interior[0];
1281 face_batch.cells_exterior[v] =
1282 faces_in[face_type[f + v]].cells_exterior[0];
1285 new_faces.insert(face_batch);
1286 f += vectorization_width - 1;
1287 n_vectorized += vectorization_width;
1291 std::vector<unsigned int> untouched;
1292 untouched.reserve(no_faces - n_vectorized);
1293 for (
unsigned int f = 0; f < no_faces; ++f)
1294 if (touched[f] == 0)
1295 untouched.push_back(f);
1297 for (
const auto f : untouched)
1299 face_batch.cells_interior[v] =
1300 faces_in[face_type[f]].cells_interior[0];
1301 face_batch.cells_exterior[v] =
1302 faces_in[face_type[f]].cells_exterior[0];
1304 if (v == vectorization_width)
1306 new_faces.insert(face_batch);
1310 if (v > 0 && v < vectorization_width)
1313 if (hard_vectorization_boundary[partition + 1] ||
1314 partition == face_partition_data.size() - 2)
1316 for (; v < vectorization_width; ++v)
1319 face_batch.cells_interior[v] =
1321 face_batch.cells_exterior[v] =
1324 new_faces.insert(face_batch);
1329 std::vector<unsigned int> untreated(v);
1330 for (
unsigned int f = 0; f < v; ++f)
1331 untreated[f] = face_type[*(untouched.end() - 1 - f)];
1332 new_faces_type.push_back(untreated);
1338 for (
auto it = new_faces.begin(); it != new_faces.end(); ++it)
1339 faces_out.push_back(*it);
1340 face_partition_data[
partition + 1] += new_faces.size();
1343 faces_type = std::move(new_faces_type);
1348 for (
const auto &face_type : faces_type)
1352 unsigned int nfaces = 0;
1353 for (
unsigned int i = face_partition_data[0];
1354 i < face_partition_data.back();
1356 for (
unsigned int v = 0; v < vectorization_width; ++v)
1361 std::vector<std::pair<unsigned int, unsigned int>> in_faces, out_faces;
1362 for (
const auto &face_in : faces_in)
1363 in_faces.emplace_back(face_in.cells_interior[0],
1364 face_in.cells_exterior[0]);
1365 for (
unsigned int i = face_partition_data[0];
1366 i < face_partition_data.back();
1368 for (
unsigned int v = 0;
1369 v < vectorization_width &&
1372 out_faces.emplace_back(faces_out[i].cells_interior[v],
1373 faces_out[i].cells_exterior[v]);
1374 std::sort(in_faces.begin(), in_faces.end());
1375 std::sort(out_faces.begin(), out_faces.end());
1377 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)