489 auto cell_rel_it = cell_relations.begin();
491 for (; cell_rel_it != cell_relations.end();
494 cell_rel_it->second =
496 dest_fixed_it + size,
503 template <
int dim,
int spacedim>
509 const
unsigned int handle,
513 const
boost::iterator_range<
std::vector<
char>::const_iterator> &)>
514 &unpack_callback)
const
520 const bool callback_variable_transfer = (handle % 2 == 0);
521 const unsigned int callback_index = handle / 2;
529 if (cell_relations.size() > 0)
535 std::vector<char>::const_iterator dest_data_it;
536 std::vector<char>::const_iterator dest_sizes_cell_it;
546 if (callback_variable_transfer)
559 const unsigned int offset_variable_data_sizes =
568 offset_variable_data_sizes +
569 callback_index *
sizeof(
unsigned int);
587 if (cell_relations.begin() != cell_relations.end())
592 auto cell_rel_it = cell_relations.begin();
594 for (; cell_rel_it != cell_relations.end(); ++cell_rel_it)
596 const auto &dealii_cell = cell_rel_it->first;
597 const auto &cell_status = cell_rel_it->second;
599 if (callback_variable_transfer)
603 data_increment = *dest_sizes_it;
610 if (callback_index == 0)
614 &(*(dest_sizes_cell_it -
sizeof(
unsigned int))),
615 sizeof(
unsigned int));
618 &(*dest_sizes_cell_it),
619 sizeof(
unsigned int));
626 dest_data_it += offset;
627 data_increment -= offset;
632 if (cell_rel_it != cell_relations.end() - 1)
641 unpack_callback(dealii_cell,
643 boost::make_iterator_range(dest_data_it,
644 dest_data_it + size));
648 unpack_callback(dealii_cell->parent(),
650 boost::make_iterator_range(dest_data_it,
651 dest_data_it + size));
663 if (cell_rel_it != cell_relations.end() - 1)
664 dest_data_it += data_increment;
670 template <
int dim,
int spacedim>
673 const
unsigned int global_first_cell,
674 const
unsigned int global_num_cells,
675 const
std::
string &file_basename,
676 const
MPI_Comm &mpi_communicator)
const
681#ifdef DEAL_II_WITH_MPI
686 const unsigned int myrank =
688 const unsigned int mpisize =
699 const std::string fname_fixed =
700 std::string(file_basename) +
"_fixed.data";
703 int ierr = MPI_Info_create(&info);
707 ierr = MPI_File_open(mpi_communicator,
709 MPI_MODE_CREATE | MPI_MODE_WRONLY,
714 ierr = MPI_File_set_size(fh, 0);
718 ierr = MPI_Barrier(mpi_communicator);
720 ierr = MPI_Info_free(&info);
741 const MPI_Offset size_header =
746 const MPI_Offset my_global_file_position =
748 static_cast<MPI_Offset
>(global_first_cell) * bytes_per_cell;
752 my_global_file_position,
759 ierr = MPI_File_close(&fh);
770 const std::string fname_variable =
771 std::string(file_basename) +
"_variable.data";
774 int ierr = MPI_Info_create(&info);
778 ierr = MPI_File_open(mpi_communicator,
779 fname_variable.c_str(),
780 MPI_MODE_CREATE | MPI_MODE_WRONLY,
785 ierr = MPI_File_set_size(fh, 0);
789 ierr = MPI_Barrier(mpi_communicator);
791 ierr = MPI_Info_free(&info);
796 const MPI_Offset my_global_file_position =
797 static_cast<MPI_Offset
>(global_first_cell) *
798 sizeof(
unsigned int);
803 static_cast<std::size_t
>(
804 std::numeric_limits<int>::max()),
809 my_global_file_position,
821 std::uint64_t prefix_sum = 0;
822 ierr = MPI_Exscan(&size_on_proc,
830 const MPI_Offset my_global_file_position =
831 static_cast<MPI_Offset
>(global_num_cells) *
sizeof(
unsigned int) +
837 my_global_file_position,
845 ierr = MPI_File_close(&fh);
852 (void)global_first_cell;
853 (void)global_num_cells;
854 (void)mpi_communicator;
860 const std::string fname_fixed =
861 std::string(file_basename) +
"_fixed.data";
863 std::ofstream file(fname_fixed, std::ios::binary | std::ios::out);
867 file.write(
reinterpret_cast<const char *
>(
881 const std::string fname_variable =
882 std::string(file_basename) +
"_variable.data";
884 std::ofstream file(fname_variable,
885 std::ios::binary | std::ios::out);
889 file.write(
reinterpret_cast<const char *
>(
901 template <
int dim,
int spacedim>
904 const
unsigned int global_first_cell,
905 const
unsigned int global_num_cells,
906 const
unsigned int local_num_cells,
907 const
std::
string &file_basename,
908 const
unsigned int n_attached_deserialize_fixed,
909 const
unsigned int n_attached_deserialize_variable,
913 ExcMessage(
"Previously loaded data has not been released yet!"));
917#ifdef DEAL_II_WITH_MPI
922 const unsigned int mpisize =
931 const std::string fname_fixed =
932 std::string(file_basename) +
"_fixed.data";
935 int ierr = MPI_Info_create(&info);
939 ierr = MPI_File_open(
940 mpi_communicator, fname_fixed.c_str(), MPI_MODE_RDONLY, info, &fh);
943 ierr = MPI_Info_free(&info);
967 const MPI_Offset size_header =
972 const MPI_Offset my_global_file_position =
974 static_cast<MPI_Offset
>(global_first_cell) * bytes_per_cell;
978 my_global_file_position,
986 ierr = MPI_File_close(&fh);
995 const std::string fname_variable =
996 std::string(file_basename) +
"_variable.data";
999 int ierr = MPI_Info_create(&info);
1003 ierr = MPI_File_open(mpi_communicator,
1004 fname_variable.c_str(),
1010 ierr = MPI_Info_free(&info);
1016 const MPI_Offset my_global_file_position_sizes =
1017 static_cast<MPI_Offset
>(global_first_cell) *
sizeof(
unsigned int);
1021 my_global_file_position_sizes,
1031 const std::uint64_t size_on_proc =
1036 std::uint64_t prefix_sum = 0;
1037 ierr = MPI_Exscan(&size_on_proc,
1045 const MPI_Offset my_global_file_position =
1046 static_cast<MPI_Offset
>(global_num_cells) *
sizeof(
unsigned int) +
1053 my_global_file_position,
1060 ierr = MPI_File_close(&fh);
1067 (void)mpi_communicator;
1068 (void)global_first_cell;
1069 (void)global_num_cells;
1075 const std::string fname_fixed =
1076 std::string(file_basename) +
"_fixed.data";
1078 std::ifstream file(fname_fixed, std::ios::binary | std::ios::in);
1101 const std::string fname_variable =
1102 std::string(file_basename) +
"_variable.data";
1104 std::ifstream file(fname_variable, std::ios::binary | std::ios::in);
1113 const std::uint64_t size =
1125 template <
int dim,
int spacedim>
1167 template <
int dim,
int spacedim>
1169 cell_is_patch_level_1(
1174 unsigned int n_active_children = 0;
1175 for (
unsigned int i = 0; i < cell->n_children(); ++i)
1176 if (cell->child(i)->is_active())
1177 ++n_active_children;
1179 return (n_active_children == 0) ||
1180 (n_active_children == cell->n_children());
1190 template <
int dim,
int spacedim>
1192 cell_will_be_coarsened(
1198 if (cell->has_children())
1200 unsigned int children_to_coarsen = 0;
1201 const unsigned int n_children = cell->n_children();
1203 for (
unsigned int c = 0; c < n_children; ++c)
1204 if (cell->child(c)->is_active() && cell->child(c)->coarsen_flag_set())
1205 ++children_to_coarsen;
1206 if (children_to_coarsen == n_children)
1209 for (
unsigned int c = 0; c < n_children; ++c)
1210 if (cell->child(c)->is_active())
1211 cell->child(c)->clear_coarsen_flag();
1247 template <
int dim,
int spacedim>
1249 face_will_be_refined_by_neighbor_internal(
1251 const unsigned int face_no,
1260 cell->neighbor(face_no);
1272 if (cell_will_be_coarsened(neighbor))
1281 expected_face_ref_case = cell->face(face_no)->refinement_case();
1293 const unsigned int neighbor_neighbor = cell->neighbor_face_no(face_no);
1307 neighbor_face = neighbor->
face(neighbor_neighbor);
1308 const int this_face_index = cell->face_index(face_no);
1314 if (neighbor_face->index() == this_face_index)
1320 expected_face_ref_case = face_ref_case;
1338 for (
unsigned int c = 0; c < neighbor_face->n_children(); ++c)
1339 if (neighbor_face->child_index(c) == this_face_index)
1348 if ((neighbor_face->refinement_case() | face_ref_case) ==
1349 neighbor_face->refinement_case())
1368 expected_face_ref_case =
1369 ~neighbor_face->refinement_case();
1396 template <
int dim,
int spacedim>
1398 face_will_be_refined_by_neighbor(
1400 const unsigned int face_no)
1403 return face_will_be_refined_by_neighbor_internal(cell, face_no, dummy);
1410 template <
int dim,
int spacedim>
1412 face_will_be_refined_by_neighbor(
1414 const unsigned int face_no,
1417 return face_will_be_refined_by_neighbor_internal(cell,
1419 expected_face_ref_case);
1424 template <
int dim,
int spacedim>
1426 satisfies_level1_at_vertex_rule(
1429 std::vector<unsigned int> min_adjacent_cell_level(
1431 std::vector<unsigned int> max_adjacent_cell_level(
1435 for (
const unsigned int v : cell->vertex_indices())
1437 min_adjacent_cell_level[cell->vertex_index(v)] =
1439 min_adjacent_cell_level[cell->vertex_index(v)], cell->level());
1440 max_adjacent_cell_level[cell->vertex_index(v)] =
1442 min_adjacent_cell_level[cell->vertex_index(v)], cell->level());
1445 for (
unsigned int k = 0; k < triangulation.
n_vertices(); ++k)
1447 if (max_adjacent_cell_level[k] - min_adjacent_cell_level[k] > 1)
1471 template <
int dim,
int spacedim>
1473 middle_vertex_index(
1476 if (line->has_children())
1477 return line->child(0)->vertex_index(1);
1482 template <
int dim,
int spacedim>
1484 middle_vertex_index(
1487 switch (
static_cast<unsigned char>(quad->refinement_case()))
1490 return middle_vertex_index<dim, spacedim>(quad->child(0)->line(1));
1493 return middle_vertex_index<dim, spacedim>(quad->child(0)->line(3));
1496 return quad->child(0)->vertex_index(3);
1505 template <
int dim,
int spacedim>
1507 middle_vertex_index(
1510 switch (
static_cast<unsigned char>(hex->refinement_case()))
1513 return middle_vertex_index<dim, spacedim>(hex->child(0)->quad(1));
1516 return middle_vertex_index<dim, spacedim>(hex->child(0)->quad(3));
1519 return middle_vertex_index<dim, spacedim>(hex->child(0)->quad(5));
1522 return middle_vertex_index<dim, spacedim>(hex->child(0)->line(11));
1525 return middle_vertex_index<dim, spacedim>(hex->child(0)->line(5));
1528 return middle_vertex_index<dim, spacedim>(hex->child(0)->line(7));
1531 return hex->child(0)->vertex_index(7);
1552 template <
class TRIANGULATION>
1553 inline typename TRIANGULATION::DistortedCellList
1554 collect_distorted_coarse_cells(
const TRIANGULATION &)
1556 return typename TRIANGULATION::DistortedCellList();
1578 vertices[i] = cell->vertex(i);
1584 if (determinants[i] <=
1592 return distorted_cells;
1604 has_distorted_children(
1609 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
1619 if (determinants[i] <=
1635 template <
int dim,
int spacedim>
1637 has_distorted_children(
1644 template <
int dim,
int spacedim>
1646 update_periodic_face_map_recursively(
1649 unsigned int n_face_1,
1650 unsigned int n_face_2,
1660 const FaceIterator face_1 = cell_1->
face(n_face_1);
1661 const FaceIterator face_2 = cell_2->
face(n_face_2);
1663 const auto inverse_orientation =
1664 face_1->reference_cell().get_inverse_combined_orientation(orientation);
1668 const auto [face_orientation, face_rotation, face_flip] =
1671 Assert((dim != 1) || (face_orientation ==
true && face_flip ==
false &&
1672 face_rotation ==
false),
1674 "(face_orientation, face_flip, face_rotation) "
1675 "is invalid for 1d"));
1677 Assert((dim != 2) || (face_flip ==
false && face_rotation ==
false),
1679 "(face_orientation, face_flip, face_rotation) "
1680 "is invalid for 2d"));
1685 Assert(face_1->at_boundary() && face_2->at_boundary(),
1686 ExcMessage(
"Periodic faces must be on the boundary"));
1697 std::pair<typename Triangulation<dim, spacedim>::cell_iterator,
1699 const CellFace cell_face_1(cell_1, n_face_1);
1700 const CellFace cell_face_2(cell_2, n_face_2);
1701 const std::pair<CellFace, types::geometric_orientation>
1702 cell_face_orientation_2(cell_face_2, orientation);
1704 const std::pair<CellFace, std::pair<CellFace, types::geometric_orientation>>
1705 periodic_faces(cell_face_1, cell_face_orientation_2);
1709 periodic_face_map.insert(periodic_faces);
1717 update_periodic_face_map_recursively<dim, spacedim>(
1718 cell_1->
child(n_face_1),
1719 cell_2->
child(n_face_2),
1727 update_periodic_face_map_recursively<dim, spacedim>(
1728 cell_1->
child(n_face_1),
1747 Assert(face_1->n_children() ==
1749 face_2->n_children() ==
1755 for (
unsigned int i = 0;
1756 i < GeometryInfo<dim>::max_children_per_face;
1760 const unsigned int j =
1762 i, n_face_1, inverse_orientation);
1765 unsigned int child_cell_1 =
1773 face_1->refinement_case());
1774 unsigned int child_cell_2 =
1782 face_2->refinement_case());
1793 update_periodic_face_map_recursively<dim, spacedim>(
1794 cell_1->
child(child_cell_1),
1795 cell_2->
child(child_cell_2),
1804 for (
unsigned int i = 0;
1805 i < GeometryInfo<dim>::max_children_per_face;
1809 unsigned int child_cell_1 =
1817 face_1->refinement_case());
1820 update_periodic_face_map_recursively<dim, spacedim>(
1821 cell_1->
child(child_cell_1),
1836 child_line_index(
const unsigned int child_no,
1845 return line_orientation == D ? 0 : 1;
1847 return line_orientation == D ? 1 : 0;
1892 <<
"Something went wrong upon construction of cell "
1906 <<
" has negative measure. This typically "
1907 <<
"indicates some distortion in the cell, or a mistakenly "
1908 <<
"swapped pair of vertices in the input to "
1909 <<
"Triangulation::create_triangulation().");
1921 <<
"Error while creating cell " << arg1
1922 <<
": the vertex index " << arg2 <<
" must be between 0 and "
1933 <<
"The input data for creating a triangulation contained "
1934 <<
"information about a line with indices " << arg1 <<
" and " << arg2
1935 <<
" that is described to have boundary indicator "
1936 <<
static_cast<int>(arg3)
1937 <<
". However, this is an internal line not located on the "
1938 <<
"boundary. You cannot assign a boundary indicator to it." << std::endl
1940 <<
"If this happened at a place where you call "
1941 <<
"Triangulation::create_triangulation() yourself, you need "
1942 <<
"to check the SubCellData object you pass to this function."
1945 <<
"If this happened in a place where you are reading a mesh "
1946 <<
"from a file, then you need to investigate why such a line "
1947 <<
"ended up in the input file. A typical case is a geometry "
1948 <<
"that consisted of multiple parts and for which the mesh "
1949 <<
"generator program assumes that the interface between "
1950 <<
"two parts is a boundary when that isn't supposed to be "
1951 <<
"the case, or where the mesh generator simply assigns "
1952 <<
"'geometry indicators' to lines at the perimeter of "
1953 <<
"a part that are not supposed to be interpreted as "
1954 <<
"'boundary indicators'.");
1966 <<
"The input data for creating a triangulation contained "
1967 <<
"information about a quad with indices " << arg1 <<
", " << arg2
1968 <<
", " << arg3 <<
", and " << arg4
1969 <<
" that is described to have boundary indicator "
1970 <<
static_cast<int>(arg5)
1971 <<
". However, this is an internal quad not located on the "
1972 <<
"boundary. You cannot assign a boundary indicator to it." << std::endl
1974 <<
"If this happened at a place where you call "
1975 <<
"Triangulation::create_triangulation() yourself, you need "
1976 <<
"to check the SubCellData object you pass to this function."
1979 <<
"If this happened in a place where you are reading a mesh "
1980 <<
"from a file, then you need to investigate why such a quad "
1981 <<
"ended up in the input file. A typical case is a geometry "
1982 <<
"that consisted of multiple parts and for which the mesh "
1983 <<
"generator program assumes that the interface between "
1984 <<
"two parts is a boundary when that isn't supposed to be "
1985 <<
"the case, or where the mesh generator simply assigns "
1986 <<
"'geometry indicators' to quads at the surface of "
1987 <<
"a part that are not supposed to be interpreted as "
1988 <<
"'boundary indicators'.");
1997 <<
"In SubCellData the line info of the line with vertex indices " << arg1
1998 <<
" and " << arg2 <<
" appears more than once. "
1999 <<
"This is not allowed.");
2009 <<
"In SubCellData the line info of the line with vertex indices " << arg1
2010 <<
" and " << arg2 <<
" appears multiple times with different (valid) "
2011 << arg3 <<
". This is not allowed.");
2023 <<
"In SubCellData the quad info of the quad with line indices " << arg1
2024 <<
", " << arg2 <<
", " << arg3 <<
" and " << arg4
2025 <<
" appears multiple times with different (valid) " << arg5
2026 <<
". This is not allowed.");
2037 const unsigned int new_quads_in_pairs,
2038 const unsigned int new_quads_single)
2044 unsigned int next_free_single = 0;
2045 unsigned int next_free_pair = 0;
2049 [[maybe_unused]]
unsigned int n_quads = 0;
2050 unsigned int n_unused_pairs = 0;
2051 unsigned int n_unused_singles = 0;
2052 for (
unsigned int i = 0; i < tria_faces.
quads.
used.size(); ++i)
2056 else if (i + 1 < tria_faces.
quads.
used.size())
2061 if (next_free_single == 0)
2062 next_free_single = i;
2067 if (next_free_pair == 0)
2075 Assert(n_quads + 2 * n_unused_pairs + n_unused_singles ==
2080 const int additional_single_quads = new_quads_single - n_unused_singles;
2082 unsigned int new_size =
2083 tria_faces.
quads.
used.size() + new_quads_in_pairs - 2 * n_unused_pairs;
2084 if (additional_single_quads > 0)
2085 new_size += additional_single_quads;
2095 q_is_q.reserve(new_size);
2096 q_is_q.insert(q_is_q.end(), new_size - q_is_q.size(),
true);
2114 const unsigned int total_cells,
2116 const bool tetraheder_in_mesh =
false)
2118 const unsigned int dim = tria_level.
dim;
2134 if (tetraheder_in_mesh)
2191 tria_level.
parents.reserve((total_cells + 1) / 2);
2193 (total_cells + 1) / 2 -
2197 tria_level.
neighbors.reserve(total_cells * max_n_faces(dim));
2199 total_cells * max_n_faces(dim) -
2201 std::make_pair(-1, -1));
2203 if (dim == 2 || dim == 3)
2226 <<
"The containers have sizes " << arg1 <<
" and " << arg2
2227 <<
", which is not as expected.");
2236 const unsigned int true_dimension)
2264 const unsigned int new_objects_in_pairs,
2265 const unsigned int new_objects_single = 0)
2277 [[maybe_unused]]
unsigned int n_objects = 0;
2278 unsigned int n_unused_pairs = 0;
2279 unsigned int n_unused_singles = 0;
2280 for (
unsigned int i = 0; i < tria_objects.
used.size(); ++i)
2282 if (tria_objects.
used[i])
2284 else if (i + 1 < tria_objects.
used.size())
2286 if (tria_objects.
used[i + 1])
2303 Assert(n_objects + 2 * n_unused_pairs + n_unused_singles ==
2304 tria_objects.
used.size(),
2309 const int additional_single_objects =
2310 new_objects_single - n_unused_singles;
2312 unsigned int new_size = tria_objects.
used.size() +
2313 new_objects_in_pairs - 2 * n_unused_pairs;
2314 if (additional_single_objects > 0)
2315 new_size += additional_single_objects;
2318 if (new_size > tria_objects.
n_objects())
2323 tria_objects.
cells.reserve(new_size *
2325 tria_objects.
cells.insert(tria_objects.
cells.end(),
2330 tria_objects.
used.reserve(new_size);
2331 tria_objects.
used.insert(tria_objects.
used.end(),
2332 new_size - tria_objects.
used.size(),
2342 tria_objects.
children.reserve(factor * new_size);
2362 tria_objects.
user_data.reserve(new_size);
2363 tria_objects.
user_data.resize(new_size);
2372 if (n_unused_singles == 0)
2380 const unsigned int new_hexes = new_objects_in_pairs;
2382 const unsigned int new_size =
2383 new_hexes + std::count(tria_objects.
used.begin(),
2384 tria_objects.
used.end(),
2388 if (new_size > tria_objects.
n_objects())
2390 tria_objects.
cells.reserve(new_size *
2392 tria_objects.
cells.insert(tria_objects.
cells.end(),
2397 tria_objects.
used.reserve(new_size);
2398 tria_objects.
used.insert(tria_objects.
used.end(),
2399 new_size - tria_objects.
used.size(),
2408 tria_objects.
children.reserve(4 * new_size);
2427 tria_objects.
user_data.reserve(new_size);
2428 tria_objects.
user_data.resize(new_size);
2452 tria_object.
used.size()));
2493 template <
int dim,
int spacedim>
2515 std::vector<unsigned int> &line_cell_count,
2516 std::vector<unsigned int> &quad_cell_count) = 0;
2523 const bool check_for_distorted_cells) = 0;
2552 virtual std::unique_ptr<Policy<dim, spacedim>>
2563 template <
int dim,
int spacedim,
typename T>
2570 T::update_neighbors(tria);
2577 std::vector<unsigned int> &line_cell_count,
2578 std::vector<unsigned int> &quad_cell_count)
override
2580 T::delete_children(tria, cell, line_cell_count, quad_cell_count);
2585 const bool check_for_distorted_cells)
override
2587 return T::execute_refinement(triangulation, check_for_distorted_cells);
2594 T::prevent_distorted_boundary_cells(triangulation);
2601 T::prepare_refinement_dim_dependent(triangulation);
2612 std::unique_ptr<Policy<dim, spacedim>>
2615 return std::make_unique<PolicyWrapper<dim, spacedim, T>>();
2729 template <
int dim,
int spacedim>
2733 const unsigned int level_objects,
2736 using line_iterator =
2739 number_cache.n_levels = 0;
2740 if (level_objects > 0)
2742 for (
unsigned int level = 0; level < level_objects; ++level)
2743 if (triangulation.
begin(level) != triangulation.
end(level))
2744 number_cache.n_levels = level + 1;
2752 number_cache.n_lines = 0;
2753 number_cache.n_active_lines = 0;
2759 number_cache.n_lines_level.resize(number_cache.n_levels);
2760 number_cache.n_active_lines_level.resize(number_cache.n_levels);
2762 for (
unsigned int level = 0; level < number_cache.n_levels; ++level)
2765 number_cache.n_lines_level[level] = 0;
2766 number_cache.n_active_lines_level[level] = 0;
2768 line_iterator line = triangulation.
begin_line(level),
2770 (level == number_cache.n_levels - 1 ?
2771 line_iterator(triangulation.
end_line()) :
2773 for (; line != endc; ++line)
2775 ++number_cache.n_lines_level[level];
2776 if (line->has_children() ==
false)
2777 ++number_cache.n_active_lines_level[level];
2781 number_cache.n_lines += number_cache.n_lines_level[level];
2782 number_cache.n_active_lines +=
2783 number_cache.n_active_lines_level[level];
2789 number_cache.n_lines_level.clear();
2790 number_cache.n_active_lines_level.clear();
2792 line_iterator line = triangulation.
begin_line(),
2794 for (; line != endc; ++line)
2796 ++number_cache.n_lines;
2797 if (line->has_children() ==
false)
2798 ++number_cache.n_active_lines;
2817 template <
int dim,
int spacedim>
2821 const unsigned int level_objects,
2838 using quad_iterator =
2844 number_cache.n_quads = 0;
2845 number_cache.n_active_quads = 0;
2855 unsigned int n_levels = 0;
2856 if (level_objects > 0)
2858 for (
unsigned int level = 0; level < level_objects; ++level)
2859 if (triangulation.
begin(level) != triangulation.
end(level))
2860 n_levels = level + 1;
2862 number_cache.n_quads_level.resize(n_levels);
2863 number_cache.n_active_quads_level.resize(n_levels);
2865 for (
unsigned int level = 0; level < n_levels; ++level)
2868 number_cache.n_quads_level[level] = 0;
2869 number_cache.n_active_quads_level[level] = 0;
2871 quad_iterator quad = triangulation.
begin_quad(level),
2873 (level == n_levels - 1 ?
2874 quad_iterator(triangulation.
end_quad()) :
2876 for (; quad != endc; ++quad)
2878 ++number_cache.n_quads_level[level];
2879 if (quad->has_children() ==
false)
2880 ++number_cache.n_active_quads_level[level];
2884 number_cache.n_quads += number_cache.n_quads_level[level];
2885 number_cache.n_active_quads +=
2886 number_cache.n_active_quads_level[level];
2892 number_cache.n_quads_level.clear();
2893 number_cache.n_active_quads_level.clear();
2895 quad_iterator quad = triangulation.
begin_quad(),
2897 for (; quad != endc; ++quad)
2899 ++number_cache.n_quads;
2900 if (quad->has_children() ==
false)
2901 ++number_cache.n_active_quads;
2906 update_lines.
join();
2924 template <
int dim,
int spacedim>
2928 const unsigned int level_objects,
2945 using hex_iterator =
2951 number_cache.n_hexes = 0;
2952 number_cache.n_active_hexes = 0;
2963 unsigned int n_levels = 0;
2964 if (level_objects > 0)
2966 for (
unsigned int level = 0; level < level_objects; ++level)
2967 if (triangulation.
begin(level) != triangulation.
end(level))
2968 n_levels = level + 1;
2970 number_cache.n_hexes_level.resize(n_levels);
2971 number_cache.n_active_hexes_level.resize(n_levels);
2973 for (
unsigned int level = 0; level < n_levels; ++level)
2976 number_cache.n_hexes_level[level] = 0;
2977 number_cache.n_active_hexes_level[level] = 0;
2979 hex_iterator hex = triangulation.
begin_hex(level),
2980 endc = (level == n_levels - 1 ?
2981 hex_iterator(triangulation.
end_hex()) :
2983 for (; hex != endc; ++hex)
2985 ++number_cache.n_hexes_level[level];
2986 if (hex->has_children() ==
false)
2987 ++number_cache.n_active_hexes_level[level];
2991 number_cache.n_hexes += number_cache.n_hexes_level[level];
2992 number_cache.n_active_hexes +=
2993 number_cache.n_active_hexes_level[level];
2999 number_cache.n_hexes_level.clear();
3000 number_cache.n_active_hexes_level.clear();
3002 hex_iterator hex = triangulation.
begin_hex(),
3003 endc = triangulation.
end_hex();
3004 for (; hex != endc; ++hex)
3006 ++number_cache.n_hexes;
3007 if (hex->has_children() ==
false)
3008 ++number_cache.n_active_hexes;
3013 update_quads_and_lines.
join();
3017 template <
int dim,
int spacedim>
3021 const unsigned int level_objects,
3026 number_cache.active_cell_index_partitioner =
3027 std::make_shared<const Utilities::MPI::Partitioner>(
3030 number_cache.level_cell_index_partitioners.resize(
3032 for (
unsigned int level = 0; level < triangulation.
n_levels(); ++level)
3033 number_cache.level_cell_index_partitioners[level] =
3034 std::make_shared<const Utilities::MPI::Partitioner>(
3035 triangulation.
n_cells(level));
3039 template <
int spacedim>
3045 template <
int dim,
int spacedim>
3100 static const unsigned int left_right_offset[2][6][2] = {
3109 {{0, 1}, {1, 0}, {0, 1}, {1, 0}, {0, 1}, {1, 0}}};
3120 std::vector<typename Triangulation<dim, spacedim>::cell_iterator>
3121 adjacent_cells(2 * triangulation.
n_raw_faces(), dummy);
3129 const unsigned int offset =
3135 adjacent_cells[2 * face->index() + offset] = cell;
3145 if (cell->
is_active() && face->has_children())
3147 adjacent_cells[2 * face->child(0)->index() + offset] =
3149 adjacent_cells[2 * face->child(1)->index() + offset] =
3175 if (face->has_children() &&
3181 for (
unsigned int c = 0; c < face->n_children(); ++c)
3182 adjacent_cells[2 * face->child(c)->index() + offset] =
3184 if (face->child(0)->has_children())
3186 adjacent_cells[2 * face->child(0)->child(0)->index() +
3188 adjacent_cells[2 * face->child(0)->child(1)->index() +
3191 if (face->child(1)->has_children())
3193 adjacent_cells[2 * face->child(1)->child(0)->index() +
3195 adjacent_cells[2 * face->child(1)->child(1)->index() +
3210 const unsigned int offset =
3216 f, adjacent_cells[2 * cell->
face(f)->index() + 1 - offset]);
3224 template <
int dim,
int spacedim>
3238 if (dim == spacedim)
3239 for (
unsigned int cell_no = 0; cell_no < cells.size(); ++cell_no)
3262 tria.
faces = std::make_unique<
3271 const unsigned int n_cell = cells.size();
3276 auto &lines_0 = tria.
faces->lines;
3279 const auto &crs = connectivity.entity_to_entities(1, 0);
3280 const unsigned int n_lines = crs.ptr.size() - 1;
3286 for (
unsigned int line = 0; line < n_lines; ++line)
3287 for (
unsigned int i = crs.ptr[line], j = 0; i < crs.ptr[line + 1];
3296 auto &quads_0 = tria.
faces->quads;
3297 auto &faces = *tria.
faces;
3300 const auto &crs = connectivity.entity_to_entities(2, 1);
3301 const unsigned int n_quads = crs.ptr.size() - 1;
3308 for (
unsigned int q = 0, k = 0; q < n_quads; ++q)
3311 const auto reference_cell = connectivity.entity_types(2)[q];
3312 faces.set_quad_type(q, reference_cell);
3315 for (
unsigned int i = crs.ptr[q], j = 0; i < crs.ptr[q + 1];
3324 const auto combined_orientation =
3325 connectivity.entity_orientations(1)
3326 .get_combined_orientation(k);
3329 Assert(combined_orientation ==
3331 combined_orientation ==
3337 faces.quads_line_orientations
3339 combined_orientation ==
3347 auto &cells_0 = tria.
levels[0]->cells;
3348 auto &level = *tria.
levels[0];
3351 const auto &crs = connectivity.entity_to_entities(dim, dim - 1);
3352 const auto &nei = connectivity.entity_to_entities(dim, dim);
3356 bool orientation_needed =
false;
3358 orientation_needed =
true;
3361 const auto &orientations = connectivity.entity_orientations(1);
3362 for (
unsigned int i = 0; i < orientations.n_objects(); ++i)
3363 if (orientations.get_combined_orientation(i) !=
3366 orientation_needed =
true;
3376 for (
unsigned int cell = 0; cell < n_cell; ++cell)
3379 cells_0.boundary_or_material_id[cell].material_id =
3380 cells[cell].material_id;
3383 cells_0.manifold_id[cell] = cells[cell].manifold_id;
3386 level.reference_cell[cell] = connectivity.entity_types(dim)[cell];
3389 for (
unsigned int i = crs.ptr[cell], j = 0; i < crs.ptr[cell + 1];
3393 if (nei.col[i] !=
static_cast<unsigned int>(-1))
3395 j] = {0, nei.col[i]};
3402 if (orientation_needed)
3404 level.face_orientations.set_combined_orientation(
3406 connectivity.entity_orientations(dim - 1)
3407 .get_combined_orientation(i));
3416 auto &bids_face = dim == 3 ?
3417 tria.
faces->quads.boundary_or_material_id :
3418 tria.
faces->lines.boundary_or_material_id;
3421 std::vector<unsigned int> count(bids_face.size(), 0);
3424 const auto &crs = connectivity.entity_to_entities(dim, dim - 1);
3427 for (
unsigned int cell = 0; cell < cells.size(); ++cell)
3428 for (
unsigned int i = crs.ptr[cell]; i < crs.ptr[cell + 1]; ++i)
3429 count[crs.col[i]]++;
3432 for (
unsigned int face = 0; face < count.size(); ++face)
3434 if (count[face] != 1)
3438 bids_face[face].boundary_id = 0;
3444 const auto &crs = connectivity.entity_to_entities(2, 1);
3445 for (
unsigned int i = crs.ptr[face]; i < crs.ptr[face + 1]; ++i)
3446 tria.
faces->lines.boundary_or_material_id[crs.col[i]]
3452 static const unsigned int t_tba =
static_cast<unsigned int>(-1);
3453 static const unsigned int t_inner =
static_cast<unsigned int>(-2);
3455 std::vector<unsigned int> type(vertices.size(), t_tba);
3457 const auto &crs = connectivity.entity_to_entities(1, 0);
3459 for (
unsigned int cell = 0; cell < cells.size(); ++cell)
3460 for (
unsigned int i = crs.ptr[cell], j = 0; i < crs.ptr[cell + 1];
3462 if (type[crs.col[i]] != t_inner)
3463 type[crs.col[i]] = type[crs.col[i]] == t_tba ? j : t_inner;
3465 for (
unsigned int face = 0; face < type.size(); ++face)
3470 if (type[face] != t_inner && type[face] != t_tba)
3491 template <
int structdim,
int spacedim,
typename T>
3501 if (boundary_objects_in.empty())
3505 auto boundary_objects = boundary_objects_in;
3508 for (
auto &boundary_object : boundary_objects)
3509 std::sort(boundary_object.vertices.begin(),
3510 boundary_object.vertices.end());
3513 std::sort(boundary_objects.begin(),
3514 boundary_objects.end(),
3515 [](
const auto &a,
const auto &b) {
3516 return a.vertices < b.vertices;
3519 [[maybe_unused]]
unsigned int counter = 0;
3521 std::vector<unsigned int> key;
3524 for (
unsigned int o = 0; o < obj.
n_objects(); ++o)
3538 key.assign(crs.
col.data() + crs.
ptr[o],
3539 crs.
col.data() + crs.
ptr[o + 1]);
3540 std::sort(key.begin(), key.end());
3543 const auto subcell_object =
3544 std::lower_bound(boundary_objects.begin(),
3545 boundary_objects.end(),
3547 [&](
const auto &cell,
const auto &key) {
3548 return cell.vertices < key;
3552 if (subcell_object == boundary_objects.end() ||
3553 subcell_object->vertices != key)
3559 manifold_id = subcell_object->manifold_id;
3562 if (subcell_object->boundary_id !=
3568 "The input arguments for creating a triangulation "
3569 "specified a boundary id for an internal face. This "
3572 "The object in question has vertex indices " +
3573 [subcell_object]() {
3575 for (
const auto v : subcell_object->vertices)
3576 s += std::to_string(v) +
',';
3579 " which are located at coordinates " +
3580 [vertex_locations, subcell_object]() {
3581 std::ostringstream s;
3582 for (
unsigned int i = 0;
3583 i < subcell_object->vertices.size();
3586 << vertex_locations[subcell_object->vertices[i]]
3587 << (i != subcell_object->vertices.size() - 1 ?
"), " :
3592 boundary_id = subcell_object->boundary_id;
3605 const unsigned structdim,
3606 const unsigned int size)
3608 const unsigned int dim = faces.
dim;
3610 if (dim == 3 && structdim == 2)
3625 const unsigned int spacedim,
3626 const unsigned int size,
3627 const bool orientation_needed)
3629 const unsigned int dim = level.
dim;
3639 level.
parents.assign((size + 1) / 2, -1);
3641 if (dim == spacedim - 1)
3644 level.
neighbors.assign(size * max_n_faces(dim), {-1, -1});
3648 if (orientation_needed)
3663 const unsigned int structdim = obj.
structdim;
3667 obj.
used.assign(size,
true);
3671 BoundaryOrMaterialId());
3681 obj.
cells.assign(size * max_n_faces(structdim), -1);
3711 template <
int spacedim>
3715 std::vector<unsigned int> &,
3716 std::vector<unsigned int> &)
3718 const unsigned int dim = 1;
3744 neighbor = neighbor->
child(1);
3756 neighbor = neighbor->
child(1);
3772 neighbor = neighbor->
child(0);
3784 neighbor = neighbor->
child(0);
3800 for (
unsigned int child = 0; child < cell->
n_children(); ++child)
3815 template <
int spacedim>
3819 std::vector<unsigned int> &line_cell_count,
3820 std::vector<unsigned int> &)
3822 const unsigned int dim = 2;
3830 std::vector<typename Triangulation<dim, spacedim>::line_iterator>
3833 lines_to_delete.reserve(4 * 2 + 4);
3838 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
3842 for (
unsigned int l = 0; l < GeometryInfo<dim>::lines_per_cell; ++l)
3860 lines_to_delete.push_back(cell->
child(0)->
line(1));
3861 lines_to_delete.push_back(cell->
child(0)->
line(3));
3862 lines_to_delete.push_back(cell->
child(3)->
line(0));
3863 lines_to_delete.push_back(cell->
child(3)->
line(2));
3867 unsigned int inner_face_no =
3872 lines_to_delete.push_back(cell->
child(0)->
line(inner_face_no));
3876 for (
unsigned int child = 0; child < cell->
n_children(); ++child)
3893 for (
unsigned int line_no = 0;
3894 line_no < GeometryInfo<dim>::lines_per_cell;
3898 cell->
line(line_no);
3900 if (line->has_children())
3905 Assert((line_cell_count[line->child_index(0)] == 0 &&
3906 line_cell_count[line->child_index(1)] == 0) ||
3907 (line_cell_count[line->child_index(0)] > 0 &&
3908 line_cell_count[line->child_index(1)] > 0),
3911 if (line_cell_count[line->child_index(0)] == 0)
3913 for (
unsigned int c = 0; c < 2; ++c)
3914 Assert(!line->child(c)->has_children(),
3924 lines_to_delete.push_back(line->child(0));
3925 lines_to_delete.push_back(line->child(1));
3927 line->clear_children();
3939 typename std::vector<
3941 line = lines_to_delete.begin(),
3942 endline = lines_to_delete.end();
3943 for (; line != endline; ++line)
3945 (*line)->clear_user_data();
3946 (*line)->clear_user_flag();
3947 (*line)->clear_used_flag();
3953 template <
int spacedim>
3957 std::vector<unsigned int> &line_cell_count,
3958 std::vector<unsigned int> &quad_cell_count)
3960 const unsigned int dim = 3;
3972 std::vector<typename Triangulation<dim, spacedim>::line_iterator>
3974 std::vector<typename Triangulation<dim, spacedim>::quad_iterator>
3977 lines_to_delete.reserve(12 * 2 + 6 * 4 + 6);
3978 quads_to_delete.reserve(6 * 4 + 12);
3982 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
3986 const auto line_indices = TriaAccessorImplementation::
3987 Implementation::get_line_indices_of_cell(*child);
3989 --line_cell_count[line_indices[l]];
4005 quads_to_delete.push_back(cell->
child(0)->
face(1));
4008 quads_to_delete.push_back(cell->
child(0)->
face(3));
4011 quads_to_delete.push_back(cell->
child(0)->
face(5));
4014 quads_to_delete.push_back(cell->
child(0)->
face(1));
4015 quads_to_delete.push_back(cell->
child(0)->
face(3));
4016 quads_to_delete.push_back(cell->
child(3)->
face(0));
4017 quads_to_delete.push_back(cell->
child(3)->
face(2));
4019 lines_to_delete.push_back(cell->
child(0)->
line(11));
4022 quads_to_delete.push_back(cell->
child(0)->
face(1));
4023 quads_to_delete.push_back(cell->
child(0)->
face(5));
4024 quads_to_delete.push_back(cell->
child(3)->
face(0));
4025 quads_to_delete.push_back(cell->
child(3)->
face(4));
4027 lines_to_delete.push_back(cell->
child(0)->
line(5));
4030 quads_to_delete.push_back(cell->
child(0)->
face(3));
4031 quads_to_delete.push_back(cell->
child(0)->
face(5));
4032 quads_to_delete.push_back(cell->
child(3)->
face(2));
4033 quads_to_delete.push_back(cell->
child(3)->
face(4));
4035 lines_to_delete.push_back(cell->
child(0)->
line(7));
4038 quads_to_delete.push_back(cell->
child(0)->
face(1));
4039 quads_to_delete.push_back(cell->
child(2)->
face(1));
4040 quads_to_delete.push_back(cell->
child(4)->
face(1));
4041 quads_to_delete.push_back(cell->
child(6)->
face(1));
4043 quads_to_delete.push_back(cell->
child(0)->
face(3));
4044 quads_to_delete.push_back(cell->
child(1)->
face(3));
4045 quads_to_delete.push_back(cell->
child(4)->
face(3));
4046 quads_to_delete.push_back(cell->
child(5)->
face(3));
4048 quads_to_delete.push_back(cell->
child(0)->
face(5));
4049 quads_to_delete.push_back(cell->
child(1)->
face(5));
4050 quads_to_delete.push_back(cell->
child(2)->
face(5));
4051 quads_to_delete.push_back(cell->
child(3)->
face(5));
4053 lines_to_delete.push_back(cell->
child(0)->
line(5));
4054 lines_to_delete.push_back(cell->
child(0)->
line(7));
4055 lines_to_delete.push_back(cell->
child(0)->
line(11));
4056 lines_to_delete.push_back(cell->
child(7)->
line(0));
4057 lines_to_delete.push_back(cell->
child(7)->
line(2));
4058 lines_to_delete.push_back(cell->
child(7)->
line(8));
4076 for (
unsigned int child = 0; child < cell->
n_children(); ++child)
4107 cell->
face(quad_no);
4111 quad->has_children()) ||
4116 switch (quad->refinement_case())
4128 Assert((quad_cell_count[quad->child_index(0)] == 0 &&
4129 quad_cell_count[quad->child_index(1)] == 0) ||
4130 (quad_cell_count[quad->child_index(0)] > 0 &&
4131 quad_cell_count[quad->child_index(1)] > 0),
4137 unsigned int deleted_grandchildren = 0;
4138 unsigned int number_of_child_refinements = 0;
4140 for (
unsigned int c = 0; c < 2; ++c)
4141 if (quad->child(c)->has_children())
4143 ++number_of_child_refinements;
4148 (quad_cell_count[quad->child(c)->child_index(0)] ==
4150 quad_cell_count[quad->child(c)->child_index(1)] ==
4152 (quad_cell_count[quad->child(c)->child_index(0)] >
4154 quad_cell_count[quad->child(c)->child_index(1)] >
4157 if (quad_cell_count[quad->child(c)->child_index(0)] ==
4164 Assert(quad->refinement_case() +
4165 quad->child(c)->refinement_case() ==
4173 quads_to_delete.push_back(
4174 quad->child(c)->child(0));
4175 quads_to_delete.push_back(
4176 quad->child(c)->child(1));
4177 if (quad->child(c)->refinement_case() ==
4179 lines_to_delete.push_back(
4180 quad->child(c)->child(0)->line(1));
4182 lines_to_delete.push_back(
4183 quad->child(c)->child(0)->line(3));
4184 quad->child(c)->clear_children();
4185 quad->child(c)->clear_refinement_case();
4186 ++deleted_grandchildren;
4194 if (number_of_child_refinements > 0 &&
4195 deleted_grandchildren == number_of_child_refinements)
4200 middle_line = quad->child(0)->line(1);
4202 middle_line = quad->child(0)->line(3);
4204 lines_to_delete.push_back(middle_line->child(0));
4205 lines_to_delete.push_back(middle_line->child(1));
4208 middle_line)] =
false;
4209 middle_line->clear_children();
4214 if (quad_cell_count[quad->child_index(0)] == 0)
4220 quads_to_delete.push_back(quad->child(0));
4221 quads_to_delete.push_back(quad->child(1));
4223 lines_to_delete.push_back(quad->child(0)->line(1));
4225 lines_to_delete.push_back(quad->child(0)->line(3));
4245 if (quad->child(0)->has_children())
4246 if (quad->refinement_case() ==
4280 quad_iterator switch_1 =
4281 quad->child(0)->child(1),
4283 quad->child(1)->child(0);
4285 Assert(!switch_1->has_children(),
4287 Assert(!switch_2->has_children(),
4290 const int switch_1_index = switch_1->index();
4291 const int switch_2_index = switch_2->index();
4292 for (
unsigned int l = 0;
4293 l < triangulation.
levels.size();
4295 for (
unsigned int h = 0;
4297 triangulation.
levels[l]->cells.n_objects();
4299 for (
const unsigned int q :
4304 ->cells.get_bounding_object_indices(
4306 if (
index == switch_1_index)
4308 ->cells.get_bounding_object_indices(
4309 h)[q] = switch_2_index;
4310 else if (
index == switch_2_index)
4312 ->cells.get_bounding_object_indices(
4313 h)[q] = switch_1_index;
4318 const int switch_1_lines[4] = {
4319 static_cast<signed int>(
4320 switch_1->line_index(0)),
4321 static_cast<signed int>(
4322 switch_1->line_index(1)),
4323 static_cast<signed int>(
4324 switch_1->line_index(2)),
4325 static_cast<signed int>(
4326 switch_1->line_index(3))};
4328 switch_1_line_orientations[4] = {
4329 switch_1->line_orientation(0),
4330 switch_1->line_orientation(1),
4331 switch_1->line_orientation(2),
4332 switch_1->line_orientation(3)};
4334 switch_1->boundary_id();
4335 const unsigned int switch_1_user_index =
4336 switch_1->user_index();
4337 const bool switch_1_user_flag =
4338 switch_1->user_flag_set();
4340 switch_1->set_bounding_object_indices(
4341 {switch_2->line_index(0),
4342 switch_2->line_index(1),
4343 switch_2->line_index(2),
4344 switch_2->line_index(3)});
4345 switch_1->set_line_orientation(
4346 0, switch_2->line_orientation(0));
4347 switch_1->set_line_orientation(
4348 1, switch_2->line_orientation(1));
4349 switch_1->set_line_orientation(
4350 2, switch_2->line_orientation(2));
4351 switch_1->set_line_orientation(
4352 3, switch_2->line_orientation(3));
4353 switch_1->set_boundary_id_internal(
4354 switch_2->boundary_id());
4355 switch_1->set_manifold_id(
4356 switch_2->manifold_id());
4357 switch_1->set_user_index(switch_2->user_index());
4358 if (switch_2->user_flag_set())
4359 switch_1->set_user_flag();
4361 switch_1->clear_user_flag();
4363 switch_2->set_bounding_object_indices(
4367 switch_1_lines[3]});
4368 switch_2->set_line_orientation(
4369 0, switch_1_line_orientations[0]);
4370 switch_2->set_line_orientation(
4371 1, switch_1_line_orientations[1]);
4372 switch_2->set_line_orientation(
4373 2, switch_1_line_orientations[2]);
4374 switch_2->set_line_orientation(
4375 3, switch_1_line_orientations[3]);
4376 switch_2->set_boundary_id_internal(
4377 switch_1_boundary_id);
4378 switch_2->set_manifold_id(
4379 switch_1->manifold_id());
4380 switch_2->set_user_index(switch_1_user_index);
4381 if (switch_1_user_flag)
4382 switch_2->set_user_flag();
4384 switch_2->clear_user_flag();
4386 const unsigned int child_0 =
4387 quad->child(0)->child_index(0);
4388 const unsigned int child_2 =
4389 quad->child(1)->child_index(0);
4390 quad->clear_children();
4391 quad->clear_refinement_case();
4392 quad->set_refinement_case(
4394 quad->set_children(0, child_0);
4395 quad->set_children(2, child_2);
4396 std::swap(quad_cell_count[child_0 + 1],
4397 quad_cell_count[child_2]);
4412 const unsigned int child_0 =
4413 quad->child(0)->child_index(0);
4414 const unsigned int child_2 =
4415 quad->child(1)->child_index(0);
4416 quad->clear_children();
4417 quad->clear_refinement_case();
4418 quad->set_refinement_case(
4420 quad->set_children(0, child_0);
4421 quad->set_children(2, child_2);
4425 quad->clear_children();
4426 quad->clear_refinement_case();
4437 Assert((quad_cell_count[quad->child_index(0)] == 0 &&
4438 quad_cell_count[quad->child_index(1)] == 0 &&
4439 quad_cell_count[quad->child_index(2)] == 0 &&
4440 quad_cell_count[quad->child_index(3)] == 0) ||
4441 (quad_cell_count[quad->child_index(0)] > 0 &&
4442 quad_cell_count[quad->child_index(1)] > 0 &&
4443 quad_cell_count[quad->child_index(2)] > 0 &&
4444 quad_cell_count[quad->child_index(3)] > 0),
4447 if (quad_cell_count[quad->child_index(0)] == 0)
4453 lines_to_delete.push_back(quad->child(0)->line(1));
4454 lines_to_delete.push_back(quad->child(3)->line(0));
4455 lines_to_delete.push_back(quad->child(0)->line(3));
4456 lines_to_delete.push_back(quad->child(3)->line(2));
4458 for (
unsigned int child = 0; child < quad->n_children();
4460 quads_to_delete.push_back(quad->child(child));
4466 quad->clear_children();
4467 quad->clear_refinement_case();
4486 for (
unsigned int line_no = 0;
4487 line_no < GeometryInfo<dim>::lines_per_cell;
4491 cell->
line(line_no);
4495 line->has_children()) ||
4500 if (line->has_children())
4505 Assert((line_cell_count[line->child_index(0)] == 0 &&
4506 line_cell_count[line->child_index(1)] == 0) ||
4507 (line_cell_count[line->child_index(0)] > 0 &&
4508 line_cell_count[line->child_index(1)] > 0),
4511 if (line_cell_count[line->child_index(0)] == 0)
4513 for (
unsigned int c = 0; c < 2; ++c)
4514 Assert(!line->child(c)->has_children(),
4524 lines_to_delete.push_back(line->child(0));
4525 lines_to_delete.push_back(line->child(1));
4527 line->clear_children();
4539 typename std::vector<
4541 line = lines_to_delete.begin(),
4542 endline = lines_to_delete.end();
4543 for (; line != endline; ++line)
4545 (*line)->clear_user_data();
4546 (*line)->clear_user_flag();
4547 (*line)->clear_used_flag();
4550 typename std::vector<
4552 quad = quads_to_delete.begin(),
4553 endquad = quads_to_delete.end();
4554 for (; quad != endquad; ++quad)
4556 (*quad)->clear_user_data();
4557 (*quad)->clear_children();
4558 (*quad)->clear_refinement_case();
4559 (*quad)->clear_user_flag();
4560 (*quad)->clear_used_flag();
4582 template <
int spacedim>
4586 unsigned int &next_unused_vertex,
4593 const unsigned int dim = 2;
4689 int new_vertices[9];
4690 for (
unsigned int vertex_no = 0; vertex_no < 4; ++vertex_no)
4691 new_vertices[vertex_no] = cell->
vertex_index(vertex_no);
4692 for (
unsigned int line_no = 0; line_no < 4; ++line_no)
4693 if (cell->
line(line_no)->has_children())
4694 new_vertices[4 + line_no] =
4695 cell->
line(line_no)->child(0)->vertex_index(1);
4704 while (triangulation.
vertices_used[next_unused_vertex] ==
true)
4705 ++next_unused_vertex;
4708 "Internal error: During refinement, the triangulation "
4709 "wants to access an element of the 'vertices' array "
4710 "but it turns out that the array is not large enough."));
4713 new_vertices[8] = next_unused_vertex;
4718 triangulation.
vertices[next_unused_vertex] =
4719 cell->
center(
true,
true);
4725 unsigned int lmin = 8;
4726 unsigned int lmax = 12;
4733 for (
unsigned int l = lmin; l < lmax; ++l)
4735 while (next_unused_line->used() ==
true)
4737 new_lines[l] = next_unused_line;
4755 for (
unsigned int c = 0; c < 2; ++c, ++l)
4756 new_lines[l] = cell->
line(face_no)->child(c);
4759 new_lines[8]->set_bounding_object_indices(
4760 {new_vertices[6], new_vertices[8]});
4761 new_lines[9]->set_bounding_object_indices(
4762 {new_vertices[8], new_vertices[7]});
4763 new_lines[10]->set_bounding_object_indices(
4764 {new_vertices[4], new_vertices[8]});
4765 new_lines[11]->set_bounding_object_indices(
4766 {new_vertices[8], new_vertices[5]});
4775 new_lines[0] = cell->
line(0);
4776 new_lines[1] = cell->
line(1);
4777 new_lines[2] = cell->
line(2)->child(0);
4778 new_lines[3] = cell->
line(2)->child(1);
4779 new_lines[4] = cell->
line(3)->child(0);
4780 new_lines[5] = cell->
line(3)->child(1);
4781 new_lines[6]->set_bounding_object_indices(
4782 {new_vertices[6], new_vertices[7]});
4792 new_lines[0] = cell->
line(0)->child(0);
4793 new_lines[1] = cell->
line(0)->child(1);
4794 new_lines[2] = cell->
line(1)->child(0);
4795 new_lines[3] = cell->
line(1)->child(1);
4796 new_lines[4] = cell->
line(2);
4797 new_lines[5] = cell->
line(3);
4798 new_lines[6]->set_bounding_object_indices(
4799 {new_vertices[4], new_vertices[5]});
4802 for (
unsigned int l = lmin; l < lmax; ++l)
4804 new_lines[l]->set_used_flag();
4805 new_lines[l]->clear_user_flag();
4807 new_lines[l]->clear_children();
4809 new_lines[l]->set_boundary_id_internal(
4811 new_lines[l]->set_manifold_id(cell->
manifold_id());
4818 while (next_unused_cell->
used() ==
true)
4822 for (
unsigned int i = 0; i < n_children; ++i)
4825 subcells[i] = next_unused_cell;
4827 if (i % 2 == 1 && i < n_children - 1)
4828 while (next_unused_cell->
used() ==
true)
4847 new_lines[8]->index(),
4848 new_lines[4]->index(),
4849 new_lines[10]->index()});
4851 new_lines[2]->index(),
4852 new_lines[5]->index(),
4853 new_lines[11]->index()});
4855 new_lines[9]->index(),
4856 new_lines[10]->index(),
4857 new_lines[6]->index()});
4859 new_lines[3]->index(),
4860 new_lines[11]->index(),
4861 new_lines[7]->index()});
4878 new_lines[6]->index(),
4879 new_lines[2]->index(),
4880 new_lines[4]->index()});
4882 new_lines[1]->index(),
4883 new_lines[3]->index(),
4884 new_lines[5]->index()});
4902 new_lines[2]->index(),
4903 new_lines[4]->index(),
4904 new_lines[6]->index()});
4906 new_lines[3]->index(),
4907 new_lines[6]->index(),
4908 new_lines[5]->index()});
4913 for (
unsigned int i = 0; i < n_children; ++i)
4932 for (
unsigned int i = 0; i < n_children / 2; ++i)
4942 if (dim == spacedim - 1)
4943 for (
unsigned int c = 0; c < n_children; ++c)
4949 template <
int dim,
int spacedim>
4952 const bool check_for_distorted_cells)
4959 triangulation.
levels.size() - 1))
4962 triangulation.
levels.push_back(
4973 line->clear_user_flag();
4977 unsigned int n_single_lines = 0;
4978 unsigned int n_lines_in_pairs = 0;
4979 unsigned int needed_vertices = 0;
4981 for (
int level = triangulation.
levels.size() - 2; level >= 0; --level)
4985 unsigned int needed_cells = 0;
4987 for (
const auto &cell :
4994 needed_vertices += 0;
4995 n_single_lines += 3;
5001 needed_vertices += 1;
5002 n_single_lines += 4;
5011 auto line = cell->
line(line_no);
5012 if (line->has_children() ==
false)
5013 line->set_user_flag();
5018 const unsigned int used_cells =
5019 std::count(triangulation.
levels[level + 1]->cells.used.begin(),
5020 triangulation.
levels[level + 1]->cells.used.end(),
5025 used_cells + needed_cells,
5036 if (line->user_flag_set())
5039 n_lines_in_pairs += 2;
5040 needed_vertices += 1;
5045 needed_vertices += std::count(triangulation.
vertices_used.begin(),
5049 if (needed_vertices > triangulation.
vertices.size())
5055 unsigned int next_unused_vertex = 0;
5064 for (; line != endl; ++line)
5065 if (line->user_flag_set())
5069 while (triangulation.
vertices_used[next_unused_vertex] ==
true)
5070 ++next_unused_vertex;
5073 "Internal error: During refinement, the triangulation "
5074 "wants to access an element of the 'vertices' array "
5075 "but it turns out that the array is not large "
5079 triangulation.
vertices[next_unused_vertex] = line->center(
true);
5081 [[maybe_unused]]
bool pair_found =
false;
5082 for (; next_unused_line != endl; ++next_unused_line)
5083 if (!next_unused_line->used() &&
5084 !(++next_unused_line)->used())
5092 line->set_children(0, next_unused_line->index());
5095 children[2] = {next_unused_line, ++next_unused_line};
5100 children[0]->set_bounding_object_indices(
5101 {line->vertex_index(0), next_unused_vertex});
5102 children[1]->set_bounding_object_indices(
5103 {next_unused_vertex, line->vertex_index(1)});
5105 for (
auto &child : children)
5107 child->set_used_flag();
5108 child->clear_children();
5109 child->clear_user_data();
5110 child->clear_user_flag();
5111 child->set_boundary_id_internal(line->boundary_id());
5112 child->set_manifold_id(line->manifold_id());
5117 line->clear_user_flag();
5124 cells_with_distorted_children;
5130 unsigned int &next_unused_vertex,
5131 auto &next_unused_line,
5132 auto &next_unused_cell,
5137 unsigned int n_new_vertices = 0;
5146 std::vector<unsigned int> new_vertices(n_new_vertices,
5148 for (
unsigned int vertex_no = 0; vertex_no < cell->
n_vertices();
5150 new_vertices[vertex_no] = cell->
vertex_index(vertex_no);
5151 for (
unsigned int line_no = 0; line_no < cell->
n_lines(); ++line_no)
5152 if (cell->
line(line_no)->has_children())
5154 cell->
line(line_no)->child(0)->vertex_index(1);
5158 while (triangulation.
vertices_used[next_unused_vertex] ==
true)
5159 ++next_unused_vertex;
5161 next_unused_vertex < triangulation.
vertices.size(),
5163 "Internal error: During refinement, the triangulation wants "
5164 "to access an element of the 'vertices' array but it turns "
5165 "out that the array is not large enough."));
5168 new_vertices[8] = next_unused_vertex;
5170 triangulation.
vertices[next_unused_vertex] =
5171 cell->
center(
true,
true);
5174 std::array<typename Triangulation<dim, spacedim>::raw_line_iterator,
5177 std::array<types::geometric_orientation, 12> inherited_orientations;
5179 unsigned int lmin = 0;
5180 unsigned int lmax = 0;
5189 std::fill(inherited_orientations.begin() + lmin,
5190 inherited_orientations.begin() + lmax,
5203 for (
unsigned int l = lmin; l < lmax; ++l)
5205 while (next_unused_line->used() ==
true)
5207 new_lines[l] = next_unused_line;
5214 for (
const unsigned int face_no : cell->
face_indices())
5221 const auto combined_orientation =
5223 Assert(combined_orientation ==
5225 combined_orientation ==
5228 for (
unsigned int c = 0; c < 2; ++c)
5230 new_lines[2 * face_no + c] = cell->
line(face_no)->child(c);
5231 inherited_orientations[2 * face_no + c] =
5235 std::swap(new_lines[2 * face_no], new_lines[2 * face_no + 1]);
5241 new_lines[6]->set_bounding_object_indices(
5242 {new_vertices[3], new_vertices[4]});
5243 new_lines[7]->set_bounding_object_indices(
5244 {new_vertices[4], new_vertices[5]});
5245 new_lines[8]->set_bounding_object_indices(
5246 {new_vertices[5], new_vertices[3]});
5250 new_lines[8]->set_bounding_object_indices(
5251 {new_vertices[6], new_vertices[8]});
5252 new_lines[9]->set_bounding_object_indices(
5253 {new_vertices[8], new_vertices[7]});
5254 new_lines[10]->set_bounding_object_indices(
5255 {new_vertices[4], new_vertices[8]});
5256 new_lines[11]->set_bounding_object_indices(
5257 {new_vertices[8], new_vertices[5]});
5264 for (
unsigned int l = lmin; l < lmax; ++l)
5266 new_lines[l]->set_used_flag();
5267 new_lines[l]->clear_user_flag();
5268 new_lines[l]->clear_user_data();
5269 new_lines[l]->clear_children();
5271 new_lines[l]->set_boundary_id_internal(
5273 new_lines[l]->set_manifold_id(cell->
manifold_id());
5278 while (next_unused_cell->used() ==
true)
5281 unsigned int n_children = 0;
5289 for (
unsigned int i = 0; i < n_children; ++i)
5292 subcells[i] = next_unused_cell;
5294 if (i % 2 == 1 && i < n_children - 1)
5295 while (next_unused_cell->used() ==
true)
5301 static constexpr ::ndarray<unsigned int, 4, 4> tri_child_lines =
5302 {{{{0, 8, 5, X}}, {{1, 2, 6, X}}, {{7, 3, 4, X}}, {{6, 7, 8, X}}}};
5303 static constexpr ::ndarray<unsigned int, 4, 4>
5304 quad_child_lines = {{{{0, 8, 4, 10}},
5310 const auto &child_lines =
5314 for (
unsigned int i = 0; i < n_children; ++i)
5318 {new_lines[child_lines[i][0]]->index(),
5319 new_lines[child_lines[i][1]]->index(),
5320 new_lines[child_lines[i][2]]->index()});
5323 {new_lines[child_lines[i][0]]->index(),
5324 new_lines[child_lines[i][1]]->index(),
5325 new_lines[child_lines[i][2]]->index(),
5326 new_lines[child_lines[i][3]]->index()});
5345 face_no, inherited_orientations[child_lines[i][face_no]]);
5358 for (
unsigned int i = 0; i < n_children / 2; ++i)
5363 if (dim == spacedim - 1)
5364 for (
unsigned int c = 0; c < n_children; ++c)
5369 level < static_cast<int>(triangulation.
levels.size()) - 1;
5373 next_unused_cell = triangulation.
begin_raw(level + 1);
5375 for (
const auto &cell :
5386 check_for_distorted_cells &&
5387 has_distorted_children<dim, spacedim>(cell))
5395 return cells_with_distorted_children;
5404 template <
int spacedim>
5409 const unsigned int dim = 1;
5414 triangulation.
levels.size() - 1))
5417 triangulation.
levels.push_back(
5428 unsigned int needed_vertices = 0;
5429 for (
int level = triangulation.
levels.size() - 2; level >= 0; --level)
5433 unsigned int flagged_cells = 0;
5435 for (
const auto &acell :
5437 if (acell->refine_flag_set())
5442 const unsigned int used_cells =
5443 std::count(triangulation.
levels[level + 1]->cells.used.begin(),
5444 triangulation.
levels[level + 1]->cells.used.end(),
5461 needed_vertices += flagged_cells;
5466 needed_vertices += std::count(triangulation.
vertices_used.begin(),
5472 if (needed_vertices > triangulation.
vertices.size())
5483 unsigned int next_unused_vertex = 0;
5485 for (
int level = triangulation.
levels.size() - 2; level >= 0; --level)
5488 next_unused_cell = triangulation.
begin_raw(level + 1);
5490 for (
const auto &cell :
5501 ++next_unused_vertex;
5503 next_unused_vertex < triangulation.
vertices.size(),
5505 "Internal error: During refinement, the triangulation "
5506 "wants to access an element of the 'vertices' array "
5507 "but it turns out that the array is not large enough."));
5512 triangulation.
vertices[next_unused_vertex] =
5522 while (next_unused_cell->
used() ==
true)
5524 first_child = next_unused_cell;
5529 second_child = next_unused_cell;
5543 if (dim == spacedim - 1)
5582 left_neighbor = left_neighbor->
child(nbnb);
5595 if (dim == spacedim - 1)
5614 right_neighbor = cell->
neighbor(1);
5617 right_neighbor = right_neighbor->
child(nbnb);
5638 template <
int spacedim>
5641 const bool check_for_distorted_cells)
5643 const unsigned int dim = 2;
5648 bool do_isotropic_refinement =
true;
5653 do_isotropic_refinement =
false;
5657 if (do_isotropic_refinement)
5659 check_for_distorted_cells);
5667 triangulation.
levels.size() - 1))
5670 triangulation.
levels.push_back(
5683 line->clear_user_flag();
5689 unsigned int n_single_lines = 0;
5693 unsigned int n_lines_in_pairs = 0;
5699 unsigned int needed_vertices = 0;
5700 for (
int level = triangulation.
levels.size() - 2; level >= 0; --level)
5704 unsigned int needed_cells = 0;
5706 for (
const auto &cell :
5719 n_single_lines += 4;
5731 n_single_lines += 1;
5739 for (
const unsigned int line_no :
5747 line = cell->
line(line_no);
5748 if (line->has_children() ==
false)
5749 line->set_user_flag();
5756 const unsigned int used_cells =
5757 std::count(triangulation.
levels[level + 1]->cells.used.begin(),
5758 triangulation.
levels[level + 1]->cells.used.end(),
5766 used_cells + needed_cells,
5781 if (line->user_flag_set())
5784 n_lines_in_pairs += 2;
5785 needed_vertices += 1;
5797 needed_vertices += std::count(triangulation.
vertices_used.begin(),
5803 if (needed_vertices > triangulation.
vertices.size())
5814 unsigned int next_unused_vertex = 0;
5826 for (; line != endl; ++line)
5827 if (line->user_flag_set())
5833 while (triangulation.
vertices_used[next_unused_vertex] ==
true)
5834 ++next_unused_vertex;
5836 next_unused_vertex < triangulation.
vertices.size(),
5838 "Internal error: During refinement, the triangulation wants to access an element of the 'vertices' array but it turns out that the array is not large enough."));
5841 triangulation.
vertices[next_unused_vertex] = line->center(
true);
5846 [[maybe_unused]]
bool pair_found =
false;
5847 for (; next_unused_line != endl; ++next_unused_line)
5848 if (!next_unused_line->used() &&
5849 !(++next_unused_line)->used())
5862 line->set_children(0, next_unused_line->index());
5866 children[2] = {next_unused_line, ++next_unused_line};
5872 children[0]->set_bounding_object_indices(
5873 {line->vertex_index(0), next_unused_vertex});
5874 children[1]->set_bounding_object_indices(
5875 {next_unused_vertex, line->vertex_index(1)});
5877 children[0]->set_used_flag();
5878 children[1]->set_used_flag();
5879 children[0]->clear_children();
5880 children[1]->clear_children();
5883 children[0]->clear_user_flag();
5884 children[1]->clear_user_flag();
5887 children[0]->set_boundary_id_internal(line->boundary_id());
5888 children[1]->set_boundary_id_internal(line->boundary_id());
5890 children[0]->set_manifold_id(line->manifold_id());
5891 children[1]->set_manifold_id(line->manifold_id());
5895 line->clear_user_flag();
5907 cells_with_distorted_children;
5915 level < static_cast<int>(triangulation.
levels.size()) - 1;
5919 next_unused_cell = triangulation.
begin_raw(level + 1);
5921 for (
const auto &cell :
5933 if (check_for_distorted_cells &&
5934 has_distorted_children<dim, spacedim>(cell))
5942 return cells_with_distorted_children;
5946 template <
int spacedim>
5949 const bool check_for_distorted_cells)
5951 static const int dim = 3;
5953 using raw_line_iterator =
5955 using raw_quad_iterator =
5967 triangulation.
levels.size() - 1))
5970 triangulation.
levels.push_back(
5978 triangulation.
faces->quads.clear_user_data();
5979 triangulation.
faces->lines.clear_user_flags();
5980 triangulation.
faces->quads.clear_user_flags();
5995 unsigned int needed_vertices = 0;
5996 unsigned int needed_lines_single = 0;
5997 unsigned int needed_faces_single = 0;
5998 unsigned int needed_lines_pair = 0;
5999 unsigned int needed_faces_pair = 0;
6000 for (
int level = triangulation.
levels.size() - 2; level >= 0; --level)
6002 unsigned int new_cells = 0;
6004 for (
const auto &cell :
6020 needed_lines_single += 6;
6021 needed_faces_single += 12;
6026 needed_lines_single += 1;
6027 needed_faces_single += 8;
6039 if (cell->
face(face)->n_children() == 0)
6040 cell->
face(face)->set_user_flag();
6049 if (cell->
line(line)->has_children() ==
false)
6050 cell->
line(line)->set_user_flag();
6056 const unsigned int used_cells =
6057 std::count(triangulation.
levels[level + 1]->cells.used.begin(),
6058 triangulation.
levels[level + 1]->cells.used.end(),
6063 used_cells + new_cells,
6068 used_cells + new_cells,
6082 if (quad->user_flag_set() ==
false)
6087 needed_faces_pair += 4;
6088 needed_lines_pair += 4;
6089 needed_vertices += 1;
6093 needed_faces_pair += 4;
6094 needed_lines_single += 3;
6107 if (line->user_flag_set() ==
false)
6110 needed_lines_pair += 2;
6111 needed_vertices += 1;
6116 needed_lines_single);
6119 needed_faces_single);
6122 needed_faces_single);
6126 needed_vertices += std::count(triangulation.
vertices_used.begin(),
6130 if (needed_vertices > triangulation.
vertices.size())
6151 for (
unsigned int line_n = 0; line_n < cell->
n_lines();
6153 if (cell->
line(line_n)->has_children())
6154 for (
unsigned int c = 0; c < 2; ++c)
6155 Assert(cell->
line(line_n)->child(c)->user_flag_set() ==
6160 unsigned int current_vertex = 0;
6164 auto get_next_unused_vertex = [](
const unsigned int current_vertex,
6165 std::vector<bool> &vertices_used) {
6166 unsigned int next_vertex = current_vertex;
6167 while (next_vertex < vertices_used.size() &&
6168 vertices_used[next_vertex] ==
true)
6171 vertices_used[next_vertex] =
true;
6181 raw_line_iterator next_unused_line = triangulation.
begin_raw_line();
6183 for (; line != endl; ++line)
6185 if (line->user_flag_set() ==
false)
6189 triangulation.
faces->lines.template next_free_pair_object<1>(
6197 line->set_children(0, next_unused_line->index());
6199 const std::array<raw_line_iterator, 2> children{
6200 {next_unused_line, ++next_unused_line}};
6206 get_next_unused_vertex(current_vertex,
6208 triangulation.
vertices[current_vertex] = line->center(
true);
6210 children[0]->set_bounding_object_indices(
6211 {line->vertex_index(0), current_vertex});
6212 children[1]->set_bounding_object_indices(
6213 {current_vertex, line->vertex_index(1)});
6215 const auto manifold_id = line->manifold_id();
6216 const auto boundary_id = line->boundary_id();
6217 for (
const auto &child : children)
6219 child->set_used_flag();
6220 child->clear_children();
6221 child->clear_user_data();
6222 child->clear_user_flag();
6223 child->set_boundary_id_internal(boundary_id);
6224 child->set_manifold_id(manifold_id);
6227 line->clear_user_flag();
6237 for (; face != endf; ++face)
6239 if (face->user_flag_set() ==
false)
6242 const auto reference_face_type = face->reference_cell();
6246 std::array<raw_line_iterator, 4> new_lines;
6249 for (
unsigned int l = 0; l < 2; ++l)
6251 auto next_unused_line =
6252 triangulation.
faces->lines
6253 .template next_free_pair_object<1>(triangulation);
6254 new_lines[2 * l] = next_unused_line;
6255 new_lines[2 * l + 1] = ++next_unused_line;
6260 for (
unsigned int l = 0; l < 3; ++l)
6262 triangulation.
faces->lines
6263 .template next_free_single_object<1>(triangulation);
6272 for (
const unsigned int line : face->line_indices())
6280 std::array<raw_quad_iterator, 4> new_faces;
6281 for (
unsigned int f = 0; f < 2; ++f)
6283 auto next_unused_quad =
6284 triangulation.
faces->quads
6285 .template next_free_pair_object<2>(triangulation);
6287 new_faces[2 * f] = next_unused_quad;
6288 new_faces[2 * f + 1] = ++next_unused_quad;
6290 face->set_children(2 * f, new_faces[2 * f]->
index());
6296 for (
const auto &quad : new_faces)
6304 std::array<unsigned int, 9> vertex_indices = {};
6306 for (
const auto i : face->vertex_indices())
6307 vertex_indices[k++] = face->vertex_index(i);
6309 for (
const auto i : face->line_indices())
6310 vertex_indices[k++] = face->line(i)->child(0)->vertex_index(1);
6315 get_next_unused_vertex(current_vertex,
6317 vertex_indices[k++] = current_vertex;
6319 triangulation.
vertices[current_vertex] =
6320 face->center(
true,
true);
6324 std::array<raw_line_iterator, 12> lines;
6325 unsigned int n_lines = 0;
6326 for (
unsigned int l = 0; l < face->n_lines(); ++l)
6327 for (
unsigned int c = 0; c < 2; ++c)
6328 lines[n_lines++] = face->line(l)->child(
6329 child_line_index(c, face->line_orientation(l)));
6331 for (
unsigned int l = 0; l < face->n_lines(); ++l)
6332 lines[n_lines++] = new_lines[l];
6334 std::array<int, 12> line_indices;
6335 for (
unsigned int i = 0; i < n_lines; ++i)
6336 line_indices[i] = lines[i]->
index();
6338 static constexpr ::ndarray<unsigned int, 12, 2>
6339 line_vertices_quad{{{{0, 4}},
6352 static constexpr ::ndarray<unsigned int, 4, 4>
6353 quad_lines_quad{{{{0, 8, 4, 10}},
6358 static constexpr ::ndarray<unsigned int, 12, 2>
6359 line_vertices_tri{{{{0, 3}},
6372 static constexpr ::ndarray<unsigned int, 4, 4>
6373 tri_lines_tri{{{{0, 8, 5, X}},
6378 static constexpr ::ndarray<unsigned int, 4, 4, 2>
6379 tri_line_vertices_tri{
6380 {{{{{0, 3}}, {{3, 5}}, {{5, 0}}, {{X, X}}}},
6381 {{{{3, 1}}, {{1, 4}}, {{4, 3}}, {{X, X}}}},
6382 {{{{5, 4}}, {{4, 2}}, {{2, 5}}, {{X, X}}}},
6383 {{{{3, 4}}, {{4, 5}}, {{5, 3}}, {{X, X}}}}}};
6385 const auto &line_vertices =
6387 line_vertices_quad :
6389 const auto &face_lines =
6394 for (
unsigned int i = 0, j = 2 * face->n_lines();
6395 i < face->n_lines();
6398 auto &new_line = new_lines[i];
6399 new_line->set_bounding_object_indices(
6400 {vertex_indices[line_vertices[j][0]],
6401 vertex_indices[line_vertices[j][1]]});
6402 new_line->set_used_flag();
6403 new_line->clear_user_flag();
6404 new_line->clear_user_data();
6405 new_line->clear_children();
6406 new_line->set_boundary_id_internal(face->boundary_id());
6407 new_line->set_manifold_id(face->manifold_id());
6411 for (
unsigned int i = 0; i < new_faces.size(); ++i)
6413 auto &new_face = new_faces[i];
6417 triangulation.
faces->set_quad_type(new_face->index(),
6418 reference_face_type);
6421 new_face->set_bounding_object_indices(
6422 {line_indices[face_lines[i][0]],
6423 line_indices[face_lines[i][1]],
6424 line_indices[face_lines[i][2]]});
6426 new_face->set_bounding_object_indices(
6427 {line_indices[face_lines[i][0]],
6428 line_indices[face_lines[i][1]],
6429 line_indices[face_lines[i][2]],
6430 line_indices[face_lines[i][3]]});
6434 new_face->set_used_flag();
6435 new_face->clear_user_flag();
6436 new_face->clear_user_data();
6437 new_face->clear_children();
6438 new_face->set_boundary_id_internal(face->boundary_id());
6439 new_face->set_manifold_id(face->manifold_id());
6441 [[maybe_unused]] std::set<unsigned int> s;
6448 for (
const auto f : new_face->line_indices())
6450 const std::array<unsigned int, 2> vertices_0 = {
6451 {lines[face_lines[i][f]]->vertex_index(0),
6452 lines[face_lines[i][f]]->vertex_index(1)}};
6454 const std::array<unsigned int, 2> vertices_1 = {
6455 {vertex_indices[tri_line_vertices_tri[i][f][0]],
6456 vertex_indices[tri_line_vertices_tri[i][f][1]]}};
6458 const auto orientation =
6466 for (
const auto i : vertices_0)
6468 for (
const auto i : vertices_1)
6472 new_face->set_line_orientation(f, orientation);
6486 static constexpr ::ndarray<unsigned int, 4, 2>
6487 quad_child_boundary_lines{
6488 {{{0, 2}}, {{1, 3}}, {{0, 1}}, {{2, 3}}}};
6490 for (
unsigned int i = 0; i < 4; ++i)
6491 for (
unsigned int j = 0; j < 2; ++j)
6492 new_faces[quad_child_boundary_lines[i][j]]
6493 ->set_line_orientation(i, face->line_orientation(i));
6496 face->clear_user_flag();
6501 cells_with_distorted_children;
6505 for (
unsigned int level = 0; level != triangulation.
levels.size() - 1;
6509 next_unused_cell = triangulation.
begin_raw(level + 1);
6511 cell->
level() >=
static_cast<int>(level),
6514 for (; cell != triangulation.
end() &&
6515 cell->
level() ==
static_cast<int>(level);
6526 unsigned int n_new_lines = 0;
6527 unsigned int n_new_faces = 0;
6528 unsigned int n_new_cells = 0;
6546 std::array<raw_line_iterator, 6> new_lines;
6547 for (
unsigned int i = 0; i < n_new_lines; ++i)
6550 triangulation.
faces->lines
6551 .template next_free_single_object<1>(triangulation);
6554 new_lines[i]->set_used_flag();
6555 new_lines[i]->clear_user_flag();
6556 new_lines[i]->clear_user_data();
6557 new_lines[i]->clear_children();
6558 new_lines[i]->set_boundary_id_internal(
6560 new_lines[i]->set_manifold_id(cell->
manifold_id());
6563 std::array<raw_quad_iterator, 12> new_faces;
6564 for (
unsigned int i = 0; i < n_new_faces; ++i)
6567 triangulation.
faces->quads
6568 .template next_free_single_object<2>(triangulation);
6570 auto &new_face = new_faces[i];
6574 triangulation.
faces->set_quad_type(
6576 reference_cell_type.face_reference_cell(0));
6579 new_face->set_used_flag();
6580 new_face->clear_user_flag();
6581 new_face->clear_user_data();
6582 new_face->clear_children();
6583 new_face->set_boundary_id_internal(
6586 for (
const auto j : new_faces[i]->line_indices())
6587 new_face->set_line_orientation(
6598 for (
unsigned int i = 0; i < n_new_cells; ++i)
6602 triangulation.
levels[level + 1]->cells.next_free_hex(
6603 triangulation, level + 1);
6607 new_cells[i] = next_unused_cell;
6609 auto &new_cell = new_cells[i];
6612 triangulation.
levels[new_cell->level()]
6613 ->reference_cell[new_cell->index()] =
6614 reference_cell_type;
6617 new_cell->set_used_flag();
6618 new_cell->clear_user_flag();
6619 new_cell->clear_user_data();
6620 new_cell->clear_children();
6626 new_cell->set_parent(cell->
index());
6631 for (
const auto f : new_cell->face_indices())
6632 new_cell->set_combined_face_orientation(
6635 for (
unsigned int i = 0; i < n_new_cells / 2; ++i)
6641 std::array<unsigned int, 27> vertex_indices = {};
6648 const unsigned int n_vertices =
6650 for (
unsigned int i = 0; i < n_vertices; ++i)
6653 const std::array<unsigned int, 12> line_indices =
6654 TriaAccessorImplementation::Implementation::
6655 get_line_indices_of_cell(*cell);
6667 for (
unsigned int l = 0; l < n_lines; ++l)
6669 raw_line_iterator line(&triangulation,
6672 vertex_indices[k++] = line->child(0)->vertex_index(1);
6678 vertex_indices[k++] =
6679 cell->
face(i)->child(0)->vertex_index(3);
6683 get_next_unused_vertex(current_vertex,
6685 vertex_indices[k++] = current_vertex;
6687 triangulation.
vertices[current_vertex] =
6688 cell->
center(
true,
true);
6692 unsigned int chosen_line_tetrahedron = 0;
6696 static constexpr ::ndarray<unsigned int, 6, 2>
6697 new_line_vertices = {{{{22, 26}},
6703 for (
unsigned int i = 0; i < n_new_lines; ++i)
6704 new_lines[i]->set_bounding_object_indices(
6705 {vertex_indices[new_line_vertices[i][0]],
6706 vertex_indices[new_line_vertices[i][1]]});
6714 static constexpr ::ndarray<unsigned int, 3, 2>
6715 new_line_vertices = {{{{6, 8}}, {{5, 7}}, {{4, 9}}}};
6720 if (refinement_choice ==
6725 double min_distance =
6726 std::numeric_limits<double>::infinity();
6727 for (
unsigned int i = 0; i < new_line_vertices.size();
6730 const double current_distance =
6732 [vertex_indices[new_line_vertices[i][0]]]
6734 vertices[vertex_indices
6735 [new_line_vertices[i][1]]]);
6736 if (current_distance < min_distance)
6738 chosen_line_tetrahedron = i;
6739 min_distance = current_distance;
6743 else if (refinement_choice ==
6746 chosen_line_tetrahedron = 0;
6747 else if (refinement_choice ==
6750 chosen_line_tetrahedron = 1;
6751 else if (refinement_choice ==
6754 chosen_line_tetrahedron = 2;
6761 new_lines[0]->set_bounding_object_indices(
6763 [new_line_vertices[chosen_line_tetrahedron][0]],
6765 [new_line_vertices[chosen_line_tetrahedron][1]]});
6770 boost::container::small_vector<raw_line_iterator, 30>
6775 relevant_lines.resize(30);
6776 for (
unsigned int f = 0, k = 0; f < 6; ++f)
6777 for (
unsigned int c = 0; c < 4; ++c, ++k)
6780 ndarray<unsigned int, 4, 2>
6782 {{{0, 1}}, {{3, 0}}, {{0, 3}}, {{3, 2}}}};
6788 standard_to_real_face_vertex(
6794 standard_to_real_face_line(
6801 for (
unsigned int i = 0, k = 24; i < 6; ++i, ++k)
6802 relevant_lines[k] = new_lines[i];
6817 relevant_lines.resize(13);
6820 for (
unsigned int f = 0; f < 4; ++f)
6821 for (
unsigned int l = 0; l < 3; ++l, ++k)
6825 array<std::array<unsigned int, 3>, 6>
6826 table = {{{{0, 1, 2}},
6833 const auto combined_orientation =
6838 ->line(table[combined_orientation][l]);
6841 relevant_lines[k++] = new_lines[0];
6847 boost::container::small_vector<unsigned int, 30>
6848 relevant_line_indices(relevant_lines.size());
6849 for (
unsigned int i = 0; i < relevant_line_indices.size();
6851 relevant_line_indices[i] = relevant_lines[i]->
index();
6860 const auto &new_face_lines =
6862 chosen_line_tetrahedron);
6877 chosen_line_tetrahedron);
6879 static constexpr ::ndarray<unsigned int, 4, 2>
6880 representative_lines{
6881 {{{0, 2}}, {{2, 0}}, {{3, 3}}, {{1, 1}}}};
6883 for (
unsigned int q = 0; q < n_new_faces; ++q)
6885 auto &new_face = new_faces[q];
6887 if (new_face->n_lines() == 3)
6888 new_face->set_bounding_object_indices(
6889 {relevant_line_indices[new_face_lines[q][0]],
6890 relevant_line_indices[new_face_lines[q][1]],
6891 relevant_line_indices[new_face_lines[q][2]]});
6892 else if (new_face->n_lines() == 4)
6893 new_face->set_bounding_object_indices(
6894 {relevant_line_indices[new_face_lines[q][0]],
6895 relevant_line_indices[new_face_lines[q][1]],
6896 relevant_line_indices[new_face_lines[q][2]],
6897 relevant_line_indices[new_face_lines[q][3]]});
6905 const unsigned int n_compute_lines =
6908 new_face->n_lines();
6909 for (
unsigned int line = 0; line < n_compute_lines;
6912 const unsigned int l =
6913 (reference_cell_type ==
6915 representative_lines[q % 4][0] :
6918 const std::array<unsigned int, 2> vertices_0 = {
6919 {relevant_lines[new_face_lines[q][l]]
6921 relevant_lines[new_face_lines[q][l]]
6922 ->vertex_index(1)}};
6924 const std::array<unsigned int, 2> vertices_1 = {
6925 {vertex_indices[table[q][l][0]],
6926 vertex_indices[table[q][l][1]]}};
6928 const auto orientation =
6933 new_face->set_line_orientation(l, orientation);
6938 if (reference_cell_type ==
6940 new_faces[representative_lines[q % 4][1] + q -
6942 ->set_line_orientation(l, orientation);
6949 std::array<int, 36> face_indices;
6953 for (
unsigned int i = 0; i < n_new_faces; ++i)
6954 face_indices[i] = new_faces[i]->
index();
6956 for (
unsigned int f = 0, k = n_new_faces; f < 6; ++f)
6957 for (
unsigned int c = 0; c < 4; ++c, ++k)
6959 cell->
face(f)->isotropic_child_index(
6974 for (
unsigned int i = 0; i < n_new_faces; ++i)
6975 face_indices[i] = new_faces[i]->
index();
6977 for (
unsigned int f = 0, k = n_new_faces; f < 4; ++f)
6978 for (
unsigned int c = 0; c < 4; ++c, ++k)
6980 const auto combined_orientation =
6982 face_indices[k] = cell->
face(f)->child_index(
6985 .standard_to_real_face_vertex(
6986 c, f, combined_orientation));
7002 const auto cell_faces =
7004 chosen_line_tetrahedron);
7006 for (
unsigned int c = 0;
7007 c < GeometryInfo<dim>::max_children_per_cell;
7010 auto &new_cell = new_cells[c];
7011 const auto reference_cell = new_cell->reference_cell();
7015 new_cell->set_bounding_object_indices(
7016 {face_indices[cell_faces[c][0]],
7017 face_indices[cell_faces[c][1]],
7018 face_indices[cell_faces[c][2]],
7019 face_indices[cell_faces[c][3]]});
7024 for (
const auto f : new_cell->face_indices())
7026 const auto &face = new_cell->face(f);
7028 Assert(face->n_vertices() == 3,
7031 const std::array<unsigned int, 3> vertices_0 = {
7032 {face->vertex_index(0),
7033 face->vertex_index(1),
7034 face->vertex_index(2)}};
7043 const auto new_cell_vertices =
7046 chosen_line_tetrahedron)[c];
7050 std::array<unsigned int, 3> vertices_1;
7051 for (
unsigned int face_vertex_no :
7052 face->vertex_indices())
7054 const auto cell_vertex_no =
7055 reference_cell.face_to_cell_vertices(
7059 vertices_1[face_vertex_no] = vertex_indices
7060 [new_cell_vertices[cell_vertex_no]];
7063 new_cell->set_combined_face_orientation(
7065 face->reference_cell()
7066 .get_combined_orientation(
7071 else if (new_cell->n_faces() == 6)
7072 new_cell->set_bounding_object_indices(
7073 {face_indices[cell_faces[c][0]],
7074 face_indices[cell_faces[c][1]],
7075 face_indices[cell_faces[c][2]],
7076 face_indices[cell_faces[c][3]],
7077 face_indices[cell_faces[c][4]],
7078 face_indices[cell_faces[c][5]]});
7087 static constexpr ::ndarray<unsigned int, 6, 4>
7088 face_to_child_indices_hex{{{{0, 2, 4, 6}},
7097 const auto combined_orientation =
7099 for (
unsigned int c = 0; c < 4; ++c)
7100 new_cells[face_to_child_indices_hex[f][c]]
7101 ->set_combined_face_orientation(
7102 f, combined_orientation);
7107 if (check_for_distorted_cells &&
7108 has_distorted_children<dim, spacedim>(cell))
7115 triangulation.
faces->quads.clear_user_data();
7117 return cells_with_distorted_children;
7124 template <
int spacedim>
7127 const bool check_for_distorted_cells)
7129 const unsigned int dim = 3;
7132 bool flag_isotropic_mesh =
true;
7134 cell = triangulation.
begin(),
7135 endc = triangulation.
end();
7136 for (; cell != endc; ++cell)
7146 flag_isotropic_mesh =
false;
7150 if (flag_isotropic_mesh)
7152 check_for_distorted_cells);
7164 triangulation.
levels.size() - 1))
7167 triangulation.
levels.push_back(
7176 triangulation.
faces->quads.clear_user_data();
7182 line->clear_user_flag();
7187 quad->clear_user_flag();
7210 unsigned int needed_vertices = 0;
7211 unsigned int needed_lines_single = 0;
7212 unsigned int needed_quads_single = 0;
7213 unsigned int needed_lines_pair = 0;
7214 unsigned int needed_quads_pair = 0;
7215 for (
int level = triangulation.
levels.size() - 2; level >= 0; --level)
7219 unsigned int new_cells = 0;
7221 for (
const auto &acell :
7223 if (acell->refine_flag_set())
7233 ++needed_quads_single;
7241 ++needed_lines_single;
7242 needed_quads_single += 4;
7249 needed_lines_single += 6;
7250 needed_quads_single += 12;
7264 for (
const unsigned int face :
7268 aface = acell->face(face);
7275 acell->face_orientation(face),
7276 acell->face_flip(face),
7277 acell->face_rotation(face));
7282 if (face_ref_case ==
7285 if (aface->n_active_descendants() < 4)
7288 aface->set_user_flag();
7290 else if (aface->refinement_case() != face_ref_case)
7301 Assert(aface->refinement_case() ==
7304 aface->refinement_case() ==
7307 aface->set_user_index(face_ref_case);
7313 for (
unsigned int line = 0;
7314 line < GeometryInfo<dim>::lines_per_cell;
7318 !acell->line(line)->has_children())
7319 acell->line(line)->set_user_flag();
7325 const unsigned int used_cells =
7326 std::count(triangulation.
levels[level + 1]->cells.used.begin(),
7327 triangulation.
levels[level + 1]->cells.used.end(),
7335 used_cells + new_cells,
7348 if (quad->user_flag_set())
7354 needed_quads_pair += 4;
7355 needed_lines_pair += 4;
7356 needed_vertices += 1;
7358 if (quad->user_index())
7362 needed_quads_pair += 2;
7363 needed_lines_single += 1;
7376 if (quad->has_children())
7378 Assert(quad->refinement_case() ==
7381 if ((face_refinement_cases[quad->user_index()] ==
7383 (quad->child(0)->line_index(1) + 1 !=
7384 quad->child(2)->line_index(1))) ||
7385 (face_refinement_cases[quad->user_index()] ==
7387 (quad->child(0)->line_index(3) + 1 !=
7388 quad->child(1)->line_index(3))))
7389 needed_lines_pair += 2;
7398 if (line->user_flag_set())
7400 needed_lines_pair += 2;
7401 needed_vertices += 1;
7407 needed_lines_single);
7411 needed_quads_single);
7414 needed_quads_single);
7418 needed_vertices += std::count(triangulation.
vertices_used.begin(),
7424 if (needed_vertices > triangulation.
vertices.size())
7445 for (
unsigned int line = 0;
7446 line < GeometryInfo<dim>::lines_per_cell;
7448 if (cell->
line(line)->has_children())
7449 for (
unsigned int c = 0; c < 2; ++c)
7450 Assert(cell->
line(line)->child(c)->user_flag_set() ==
7463 unsigned int next_unused_vertex = 0;
7474 for (; line != endl; ++line)
7475 if (line->user_flag_set())
7481 while (triangulation.
vertices_used[next_unused_vertex] ==
true)
7482 ++next_unused_vertex;
7484 next_unused_vertex < triangulation.
vertices.size(),
7486 "Internal error: During refinement, the triangulation wants to access an element of the 'vertices' array but it turns out that the array is not large enough."));
7489 triangulation.
vertices[next_unused_vertex] = line->center(
true);
7495 triangulation.
faces->lines.template next_free_pair_object<1>(
7503 line->set_children(0, next_unused_line->index());
7507 children[2] = {next_unused_line, ++next_unused_line};
7514 children[0]->set_bounding_object_indices(
7515 {line->vertex_index(0), next_unused_vertex});
7516 children[1]->set_bounding_object_indices(
7517 {next_unused_vertex, line->vertex_index(1)});
7519 children[0]->set_used_flag();
7520 children[1]->set_used_flag();
7521 children[0]->clear_children();
7522 children[1]->clear_children();
7525 children[0]->clear_user_flag();
7526 children[1]->clear_user_flag();
7528 children[0]->set_boundary_id_internal(line->boundary_id());
7529 children[1]->set_boundary_id_internal(line->boundary_id());
7531 children[0]->set_manifold_id(line->manifold_id());
7532 children[1]->set_manifold_id(line->manifold_id());
7537 line->clear_user_flag();
7567 for (
unsigned int loop = 0; loop < 2; ++loop)
7580 for (; quad != endq; ++quad)
7582 if (quad->user_index())
7585 face_refinement_cases[quad->user_index()];
7594 if (aniso_quad_ref_case == quad->refinement_case())
7597 Assert(quad->refinement_case() ==
7599 quad->refinement_case() ==
7604 Assert(quad->user_index() ==
7606 quad->user_index() ==
7615 triangulation.
faces->lines
7616 .template next_free_single_object<1>(triangulation);
7632 unsigned int vertex_indices[2];
7636 quad->line(2)->child(0)->vertex_index(1);
7638 quad->line(3)->child(0)->vertex_index(1);
7643 quad->line(0)->child(0)->vertex_index(1);
7645 quad->line(1)->child(0)->vertex_index(1);
7648 new_line->set_bounding_object_indices(
7649 {vertex_indices[0], vertex_indices[1]});
7650 new_line->set_used_flag();
7651 new_line->clear_user_flag();
7653 new_line->clear_children();
7654 new_line->set_boundary_id_internal(quad->boundary_id());
7655 new_line->set_manifold_id(quad->manifold_id());
7663 triangulation.
faces->quads
7664 .template next_free_pair_object<2>(triangulation);
7665 new_quads[0] = next_unused_quad;
7669 new_quads[1] = next_unused_quad;
7674 new_quads[0]->set_bounding_object_indices(
7675 {
static_cast<int>(quad->line_index(0)),
7679 child_line_index(0, quad->line_orientation(2)))
7683 child_line_index(0, quad->line_orientation(3)))
7685 new_quads[1]->set_bounding_object_indices(
7687 static_cast<int>(quad->line_index(1)),
7690 child_line_index(1, quad->line_orientation(2)))
7694 child_line_index(1, quad->line_orientation(3)))
7699 new_quads[0]->set_bounding_object_indices(
7702 child_line_index(0, quad->line_orientation(0)))
7706 child_line_index(0, quad->line_orientation(1)))
7708 static_cast<int>(quad->line_index(2)),
7709 new_line->index()});
7710 new_quads[1]->set_bounding_object_indices(
7713 child_line_index(1, quad->line_orientation(0)))
7717 child_line_index(1, quad->line_orientation(1)))
7720 static_cast<int>(quad->line_index(3))});
7723 for (
const auto &new_quad : new_quads)
7725 new_quad->set_used_flag();
7726 new_quad->clear_user_flag();
7727 new_quad->clear_user_data();
7728 new_quad->clear_children();
7729 new_quad->set_boundary_id_internal(quad->boundary_id());
7730 new_quad->set_manifold_id(quad->manifold_id());
7734 for (
unsigned int j = 0;
7735 j < GeometryInfo<dim>::lines_per_face;
7737 new_quad->set_line_orientation(
7744 new_quads[0]->set_line_orientation(
7745 0, quad->line_orientation(0));
7746 new_quads[0]->set_line_orientation(
7747 2, quad->line_orientation(2));
7748 new_quads[1]->set_line_orientation(
7749 1, quad->line_orientation(1));
7750 new_quads[1]->set_line_orientation(
7751 3, quad->line_orientation(3));
7754 new_quads[0]->set_line_orientation(
7755 3, quad->line_orientation(3));
7756 new_quads[1]->set_line_orientation(
7757 2, quad->line_orientation(2));
7761 new_quads[0]->set_line_orientation(
7762 1, quad->line_orientation(1));
7763 new_quads[1]->set_line_orientation(
7764 0, quad->line_orientation(0));
7770 if (quad->refinement_case() ==
7793 if (aniso_quad_ref_case ==
7796 old_child[0] = quad->child(0)->line(1);
7797 old_child[1] = quad->child(2)->line(1);
7801 Assert(aniso_quad_ref_case ==
7805 old_child[0] = quad->child(0)->line(3);
7806 old_child[1] = quad->child(1)->line(3);
7809 if (old_child[0]->
index() + 1 != old_child[1]->
index())
7815 spacedim>::raw_line_iterator
7818 new_child[0] = new_child[1] =
7819 triangulation.
faces->lines
7820 .template next_free_pair_object<1>(
7824 new_child[0]->set_used_flag();
7825 new_child[1]->set_used_flag();
7827 const int old_index_0 = old_child[0]->index(),
7828 old_index_1 = old_child[1]->index(),
7829 new_index_0 = new_child[0]->index(),
7830 new_index_1 = new_child[1]->index();
7834 for (
unsigned int q = 0;
7835 q < triangulation.
faces->quads.n_objects();
7837 for (
unsigned int l = 0;
7838 l < GeometryInfo<dim>::lines_per_face;
7841 const int this_index =
7842 triangulation.
faces->quads
7843 .get_bounding_object_indices(q)[l];
7844 if (this_index == old_index_0)
7845 triangulation.
faces->quads
7846 .get_bounding_object_indices(q)[l] =
7848 else if (this_index == old_index_1)
7849 triangulation.
faces->quads
7850 .get_bounding_object_indices(q)[l] =
7855 for (
unsigned int i = 0; i < 2; ++i)
7857 Assert(!old_child[i]->has_children(),
7860 new_child[i]->set_bounding_object_indices(
7861 {old_child[i]->vertex_index(0),
7862 old_child[i]->vertex_index(1)});
7863 new_child[i]->set_boundary_id_internal(
7864 old_child[i]->boundary_id());
7865 new_child[i]->set_manifold_id(
7866 old_child[i]->manifold_id());
7867 new_child[i]->set_user_index(
7868 old_child[i]->user_index());
7869 if (old_child[i]->user_flag_set())
7870 new_child[i]->set_user_flag();
7872 new_child[i]->clear_user_flag();
7874 new_child[i]->clear_children();
7876 old_child[i]->clear_user_flag();
7877 old_child[i]->clear_user_index();
7878 old_child[i]->clear_used_flag();
7884 if (aniso_quad_ref_case ==
7887 new_line->set_children(
7888 0, quad->child(0)->line_index(1));
7889 Assert(new_line->child(1) ==
7890 quad->child(2)->line(1),
7927 quad_iterator switch_1 = quad->child(1),
7928 switch_2 = quad->child(2);
7929 const int switch_1_index = switch_1->index();
7930 const int switch_2_index = switch_2->index();
7931 for (
unsigned int l = 0;
7932 l < triangulation.
levels.size();
7934 for (
unsigned int h = 0;
7936 triangulation.
levels[l]->cells.n_objects();
7938 for (
const unsigned int q :
7941 const int face_index =
7943 ->cells.get_bounding_object_indices(
7945 if (face_index == switch_1_index)
7947 ->cells.get_bounding_object_indices(
7948 h)[q] = switch_2_index;
7949 else if (face_index == switch_2_index)
7951 ->cells.get_bounding_object_indices(
7952 h)[q] = switch_1_index;
7956 const unsigned int switch_1_lines[4] = {
7957 switch_1->line_index(0),
7958 switch_1->line_index(1),
7959 switch_1->line_index(2),
7960 switch_1->line_index(3)};
7962 switch_1_line_orientations[4] = {
7963 switch_1->line_orientation(0),
7964 switch_1->line_orientation(1),
7965 switch_1->line_orientation(2),
7966 switch_1->line_orientation(3)};
7968 switch_1->boundary_id();
7969 const unsigned int switch_1_user_index =
7970 switch_1->user_index();
7971 const bool switch_1_user_flag =
7972 switch_1->user_flag_set();
7974 switch_1_refinement_case =
7975 switch_1->refinement_case();
7976 const int switch_1_first_child_pair =
7977 (switch_1_refinement_case ?
7978 switch_1->child_index(0) :
7980 const int switch_1_second_child_pair =
7981 (switch_1_refinement_case ==
7983 switch_1->child_index(2) :
7986 switch_1->set_bounding_object_indices(
7987 {switch_2->line_index(0),
7988 switch_2->line_index(1),
7989 switch_2->line_index(2),
7990 switch_2->line_index(3)});
7991 switch_1->set_line_orientation(
7992 0, switch_2->line_orientation(0));
7993 switch_1->set_line_orientation(
7994 1, switch_2->line_orientation(1));
7995 switch_1->set_line_orientation(
7996 2, switch_2->line_orientation(2));
7997 switch_1->set_line_orientation(
7998 3, switch_2->line_orientation(3));
7999 switch_1->set_boundary_id_internal(
8000 switch_2->boundary_id());
8001 switch_1->set_manifold_id(switch_2->manifold_id());
8002 switch_1->set_user_index(switch_2->user_index());
8003 if (switch_2->user_flag_set())
8004 switch_1->set_user_flag();
8006 switch_1->clear_user_flag();
8007 switch_1->clear_refinement_case();
8008 switch_1->set_refinement_case(
8009 switch_2->refinement_case());
8010 switch_1->clear_children();
8011 if (switch_2->refinement_case())
8012 switch_1->set_children(0,
8013 switch_2->child_index(0));
8014 if (switch_2->refinement_case() ==
8016 switch_1->set_children(2,
8017 switch_2->child_index(2));
8019 switch_2->set_bounding_object_indices(
8023 switch_1_lines[3]});
8024 switch_2->set_line_orientation(
8025 0, switch_1_line_orientations[0]);
8026 switch_2->set_line_orientation(
8027 1, switch_1_line_orientations[1]);
8028 switch_2->set_line_orientation(
8029 2, switch_1_line_orientations[2]);
8030 switch_2->set_line_orientation(
8031 3, switch_1_line_orientations[3]);
8032 switch_2->set_boundary_id_internal(
8033 switch_1_boundary_id);
8034 switch_2->set_manifold_id(switch_1->manifold_id());
8035 switch_2->set_user_index(switch_1_user_index);
8036 if (switch_1_user_flag)
8037 switch_2->set_user_flag();
8039 switch_2->clear_user_flag();
8040 switch_2->clear_refinement_case();
8041 switch_2->set_refinement_case(
8042 switch_1_refinement_case);
8043 switch_2->clear_children();
8044 switch_2->set_children(0,
8045 switch_1_first_child_pair);
8046 switch_2->set_children(2,
8047 switch_1_second_child_pair);
8049 new_quads[0]->set_refinement_case(
8051 new_quads[0]->set_children(0, quad->child_index(0));
8052 new_quads[1]->set_refinement_case(
8054 new_quads[1]->set_children(0, quad->child_index(2));
8058 new_quads[0]->set_refinement_case(
8060 new_quads[0]->set_children(0, quad->child_index(0));
8061 new_quads[1]->set_refinement_case(
8063 new_quads[1]->set_children(0, quad->child_index(2));
8064 new_line->set_children(
8065 0, quad->child(0)->line_index(3));
8066 Assert(new_line->child(1) ==
8067 quad->child(1)->line(3),
8070 quad->clear_children();
8074 quad->set_children(0, new_quads[0]->
index());
8076 quad->set_refinement_case(aniso_quad_ref_case);
8083 if (quad->user_flag_set())
8095 ++next_unused_vertex;
8097 next_unused_vertex < triangulation.
vertices.size(),
8099 "Internal error: During refinement, the triangulation wants to access an element of the 'vertices' array but it turns out that the array is not large enough."));
8107 quad->refinement_case();
8113 quad->child(0)->set_user_index(
8115 quad->child(1)->set_user_index(
8121 middle_line = quad->child(0)->line(1);
8123 middle_line = quad->child(0)->line(3);
8130 if (!middle_line->has_children())
8137 triangulation.
vertices[next_unused_vertex] =
8138 middle_line->center(
true);
8145 triangulation.
faces->lines
8146 .template next_free_pair_object<1>(
8151 middle_line->set_children(
8152 0, next_unused_line->index());
8156 raw_line_iterator children[2] = {
8157 next_unused_line, ++next_unused_line};
8165 children[0]->set_bounding_object_indices(
8166 {middle_line->vertex_index(0),
8167 next_unused_vertex});
8168 children[1]->set_bounding_object_indices(
8169 {next_unused_vertex,
8170 middle_line->vertex_index(1)});
8172 children[0]->set_used_flag();
8173 children[1]->set_used_flag();
8174 children[0]->clear_children();
8175 children[1]->clear_children();
8178 children[0]->clear_user_flag();
8179 children[1]->clear_user_flag();
8181 children[0]->set_boundary_id_internal(
8182 middle_line->boundary_id());
8183 children[1]->set_boundary_id_internal(
8184 middle_line->boundary_id());
8186 children[0]->set_manifold_id(
8187 middle_line->manifold_id());
8188 children[1]->set_manifold_id(
8189 middle_line->manifold_id());
8195 quad->clear_user_flag();
8224 triangulation.
vertices[next_unused_vertex] =
8225 quad->center(
true,
true);
8234 for (
unsigned int i = 0; i < 4; ++i)
8244 triangulation.
faces->lines
8245 .template next_free_pair_object<1>(triangulation);
8247 new_lines[i] = next_unused_line;
8270 const unsigned int vertex_indices[5] = {
8271 quad->line(0)->child(0)->vertex_index(1),
8272 quad->line(1)->child(0)->vertex_index(1),
8273 quad->line(2)->child(0)->vertex_index(1),
8274 quad->line(3)->child(0)->vertex_index(1),
8275 next_unused_vertex};
8277 new_lines[0]->set_bounding_object_indices(
8278 {vertex_indices[2], vertex_indices[4]});
8279 new_lines[1]->set_bounding_object_indices(
8280 {vertex_indices[4], vertex_indices[3]});
8281 new_lines[2]->set_bounding_object_indices(
8282 {vertex_indices[0], vertex_indices[4]});
8283 new_lines[3]->set_bounding_object_indices(
8284 {vertex_indices[4], vertex_indices[1]});
8286 for (
const auto &new_line : new_lines)
8288 new_line->set_used_flag();
8289 new_line->clear_user_flag();
8290 new_line->clear_user_data();
8291 new_line->clear_children();
8292 new_line->set_boundary_id_internal(quad->boundary_id());
8293 new_line->set_manifold_id(quad->manifold_id());
8306 const int line_indices[12] = {
8308 ->child(child_line_index(0, quad->line_orientation(0)))
8311 ->child(child_line_index(1, quad->line_orientation(0)))
8314 ->child(child_line_index(0, quad->line_orientation(1)))
8317 ->child(child_line_index(1, quad->line_orientation(1)))
8320 ->child(child_line_index(0, quad->line_orientation(2)))
8323 ->child(child_line_index(1, quad->line_orientation(2)))
8326 ->child(child_line_index(0, quad->line_orientation(3)))
8329 ->child(child_line_index(1, quad->line_orientation(3)))
8331 new_lines[0]->index(),
8332 new_lines[1]->index(),
8333 new_lines[2]->index(),
8334 new_lines[3]->index()};
8343 triangulation.
faces->quads
8344 .template next_free_pair_object<2>(triangulation);
8346 new_quads[0] = next_unused_quad;
8350 new_quads[1] = next_unused_quad;
8354 triangulation.
faces->quads
8355 .template next_free_pair_object<2>(triangulation);
8356 new_quads[2] = next_unused_quad;
8360 new_quads[3] = next_unused_quad;
8364 quad->set_children(0, new_quads[0]->
index());
8365 quad->set_children(2, new_quads[2]->
index());
8368 new_quads[0]->set_bounding_object_indices(
8373 new_quads[1]->set_bounding_object_indices(
8378 new_quads[2]->set_bounding_object_indices(
8383 new_quads[3]->set_bounding_object_indices(
8388 for (
const auto &new_quad : new_quads)
8390 new_quad->set_used_flag();
8391 new_quad->clear_user_flag();
8392 new_quad->clear_user_data();
8393 new_quad->clear_children();
8394 new_quad->set_boundary_id_internal(quad->boundary_id());
8395 new_quad->set_manifold_id(quad->manifold_id());
8399 for (
unsigned int j = 0;
8400 j < GeometryInfo<dim>::lines_per_face;
8402 new_quad->set_line_orientation(
8409 new_quads[0]->set_line_orientation(
8410 0, quad->line_orientation(0));
8411 new_quads[0]->set_line_orientation(
8412 2, quad->line_orientation(2));
8413 new_quads[1]->set_line_orientation(
8414 1, quad->line_orientation(1));
8415 new_quads[1]->set_line_orientation(
8416 2, quad->line_orientation(2));
8417 new_quads[2]->set_line_orientation(
8418 0, quad->line_orientation(0));
8419 new_quads[2]->set_line_orientation(
8420 3, quad->line_orientation(3));
8421 new_quads[3]->set_line_orientation(
8422 1, quad->line_orientation(1));
8423 new_quads[3]->set_line_orientation(
8424 3, quad->line_orientation(3));
8428 quad->clear_user_flag();
8439 cells_with_distorted_children;
8441 for (
unsigned int level = 0; level != triangulation.
levels.size() - 1;
8453 for (; hex != endh; ++hex)
8454 if (hex->refine_flag_set())
8462 hex->clear_refine_flag();
8463 hex->set_refinement_case(ref_case);
8474 unsigned int n_new_lines = 0;
8475 unsigned int n_new_quads = 0;
8476 unsigned int n_new_hexes = 0;
8507 new_lines(n_new_lines);
8508 for (
unsigned int i = 0; i < n_new_lines; ++i)
8511 triangulation.
faces->lines
8512 .template next_free_single_object<1>(triangulation);
8515 new_lines[i]->set_used_flag();
8516 new_lines[i]->clear_user_flag();
8517 new_lines[i]->clear_user_data();
8518 new_lines[i]->clear_children();
8520 new_lines[i]->set_boundary_id_internal(
8524 new_lines[i]->set_manifold_id(hex->manifold_id());
8531 new_quads(n_new_quads);
8532 for (
unsigned int i = 0; i < n_new_quads; ++i)
8535 triangulation.
faces->quads
8536 .template next_free_single_object<2>(triangulation);
8539 new_quads[i]->set_used_flag();
8540 new_quads[i]->clear_user_flag();
8541 new_quads[i]->clear_user_data();
8542 new_quads[i]->clear_children();
8544 new_quads[i]->set_boundary_id_internal(
8548 new_quads[i]->set_manifold_id(hex->manifold_id());
8551 for (
unsigned int j = 0;
8552 j < GeometryInfo<dim>::lines_per_face;
8554 new_quads[i]->set_line_orientation(
8564 new_hexes(n_new_hexes);
8565 for (
unsigned int i = 0; i < n_new_hexes; ++i)
8569 triangulation.
levels[level + 1]->cells.next_free_hex(
8570 triangulation, level + 1);
8574 new_hexes[i] = next_unused_hex;
8577 new_hexes[i]->set_used_flag();
8578 new_hexes[i]->clear_user_flag();
8579 new_hexes[i]->clear_user_data();
8580 new_hexes[i]->clear_children();
8583 new_hexes[i]->set_material_id(hex->material_id());
8584 new_hexes[i]->set_manifold_id(hex->manifold_id());
8585 new_hexes[i]->set_subdomain_id(subdomainid);
8588 new_hexes[i]->set_parent(hex->index());
8600 for (
const unsigned int f :
8602 new_hexes[i]->set_combined_face_orientation(
8606 for (
unsigned int i = 0; i < n_new_hexes / 2; ++i)
8607 hex->set_children(2 * i, new_hexes[2 * i]->index());
8614 const bool f_or[6] = {hex->face_orientation(0),
8615 hex->face_orientation(1),
8616 hex->face_orientation(2),
8617 hex->face_orientation(3),
8618 hex->face_orientation(4),
8619 hex->face_orientation(5)};
8622 const bool f_fl[6] = {hex->face_flip(0),
8630 const bool f_ro[6] = {hex->face_rotation(0),
8631 hex->face_rotation(1),
8632 hex->face_rotation(2),
8633 hex->face_rotation(3),
8634 hex->face_rotation(4),
8635 hex->face_rotation(5)};
8639 hex->combined_face_orientation(0),
8640 hex->combined_face_orientation(1),
8641 hex->combined_face_orientation(2),
8642 hex->combined_face_orientation(3),
8643 hex->combined_face_orientation(4),
8644 hex->combined_face_orientation(5)};
8654 const unsigned int child_at_origin[2][2][2] = {
8741 raw_line_iterator lines[4] = {
8742 hex->face(2)->child(0)->line(
8743 (hex->face(2)->refinement_case() ==
8747 hex->face(3)->child(0)->line(
8748 (hex->face(3)->refinement_case() ==
8752 hex->face(4)->child(0)->line(
8753 (hex->face(4)->refinement_case() ==
8757 hex->face(5)->child(0)->line(
8758 (hex->face(5)->refinement_case() ==
8764 unsigned int line_indices[4];
8765 for (
unsigned int i = 0; i < 4; ++i)
8766 line_indices[i] = lines[i]->
index();
8779 const unsigned int middle_vertices[2] = {
8780 hex->line(2)->child(0)->vertex_index(1),
8781 hex->line(7)->child(0)->vertex_index(1)};
8783 for (
unsigned int i = 0; i < 4; ++i)
8784 if (lines[i]->vertex_index(i % 2) ==
8785 middle_vertices[i % 2])
8786 line_orientation[i] =
8791 Assert(lines[i]->vertex_index((i + 1) % 2) ==
8792 middle_vertices[i % 2],
8794 line_orientation[i] =
8800 new_quads[0]->set_bounding_object_indices(
8806 new_quads[0]->set_line_orientation(
8807 0, line_orientation[0]);
8808 new_quads[0]->set_line_orientation(
8809 1, line_orientation[1]);
8810 new_quads[0]->set_line_orientation(
8811 2, line_orientation[2]);
8812 new_quads[0]->set_line_orientation(
8813 3, line_orientation[3]);
8846 const int quad_indices[11] = {
8847 new_quads[0]->index(),
8849 hex->face(0)->index(),
8851 hex->face(1)->index(),
8853 hex->face(2)->child_index(
8854 child_at_origin[hex->face(2)->refinement_case() -
8855 1][f_fl[2]][f_ro[2]]),
8856 hex->face(2)->child_index(
8858 child_at_origin[hex->face(2)->refinement_case() -
8859 1][f_fl[2]][f_ro[2]]),
8861 hex->face(3)->child_index(
8862 child_at_origin[hex->face(3)->refinement_case() -
8863 1][f_fl[3]][f_ro[3]]),
8864 hex->face(3)->child_index(
8866 child_at_origin[hex->face(3)->refinement_case() -
8867 1][f_fl[3]][f_ro[3]]),
8869 hex->face(4)->child_index(
8870 child_at_origin[hex->face(4)->refinement_case() -
8871 1][f_fl[4]][f_ro[4]]),
8872 hex->face(4)->child_index(
8874 child_at_origin[hex->face(4)->refinement_case() -
8875 1][f_fl[4]][f_ro[4]]),
8877 hex->face(5)->child_index(
8878 child_at_origin[hex->face(5)->refinement_case() -
8879 1][f_fl[5]][f_ro[5]]),
8880 hex->face(5)->child_index(
8882 child_at_origin[hex->face(5)->refinement_case() -
8883 1][f_fl[5]][f_ro[5]])
8887 new_hexes[0]->set_bounding_object_indices(
8894 new_hexes[1]->set_bounding_object_indices(
8969 raw_line_iterator lines[4] = {
8970 hex->face(0)->child(0)->line(
8971 (hex->face(0)->refinement_case() ==
8975 hex->face(1)->child(0)->line(
8976 (hex->face(1)->refinement_case() ==
8980 hex->face(4)->child(0)->line(
8981 (hex->face(4)->refinement_case() ==
8985 hex->face(5)->child(0)->line(
8986 (hex->face(5)->refinement_case() ==
8992 unsigned int line_indices[4];
8993 for (
unsigned int i = 0; i < 4; ++i)
8994 line_indices[i] = lines[i]->
index();
9007 const unsigned int middle_vertices[2] = {
9008 hex->line(0)->child(0)->vertex_index(1),
9009 hex->line(5)->child(0)->vertex_index(1)};
9011 for (
unsigned int i = 0; i < 4; ++i)
9012 if (lines[i]->vertex_index(i % 2) ==
9013 middle_vertices[i % 2])
9014 line_orientation[i] =
9019 Assert(lines[i]->vertex_index((i + 1) % 2) ==
9020 middle_vertices[i % 2],
9022 line_orientation[i] =
9028 new_quads[0]->set_bounding_object_indices(
9034 new_quads[0]->set_line_orientation(
9035 0, line_orientation[2]);
9036 new_quads[0]->set_line_orientation(
9037 1, line_orientation[3]);
9038 new_quads[0]->set_line_orientation(
9039 2, line_orientation[0]);
9040 new_quads[0]->set_line_orientation(
9041 3, line_orientation[1]);
9074 const int quad_indices[11] = {
9075 new_quads[0]->index(),
9077 hex->face(0)->child_index(
9078 child_at_origin[hex->face(0)->refinement_case() -
9079 1][f_fl[0]][f_ro[0]]),
9080 hex->face(0)->child_index(
9082 child_at_origin[hex->face(0)->refinement_case() -
9083 1][f_fl[0]][f_ro[0]]),
9085 hex->face(1)->child_index(
9086 child_at_origin[hex->face(1)->refinement_case() -
9087 1][f_fl[1]][f_ro[1]]),
9088 hex->face(1)->child_index(
9090 child_at_origin[hex->face(1)->refinement_case() -
9091 1][f_fl[1]][f_ro[1]]),
9093 hex->face(2)->index(),
9095 hex->face(3)->index(),
9097 hex->face(4)->child_index(
9098 child_at_origin[hex->face(4)->refinement_case() -
9099 1][f_fl[4]][f_ro[4]]),
9100 hex->face(4)->child_index(
9102 child_at_origin[hex->face(4)->refinement_case() -
9103 1][f_fl[4]][f_ro[4]]),
9105 hex->face(5)->child_index(
9106 child_at_origin[hex->face(5)->refinement_case() -
9107 1][f_fl[5]][f_ro[5]]),
9108 hex->face(5)->child_index(
9110 child_at_origin[hex->face(5)->refinement_case() -
9111 1][f_fl[5]][f_ro[5]])
9115 new_hexes[0]->set_bounding_object_indices(
9122 new_hexes[1]->set_bounding_object_indices(
9199 raw_line_iterator lines[4] = {
9200 hex->face(0)->child(0)->line(
9201 (hex->face(0)->refinement_case() ==
9205 hex->face(1)->child(0)->line(
9206 (hex->face(1)->refinement_case() ==
9210 hex->face(2)->child(0)->line(
9211 (hex->face(2)->refinement_case() ==
9215 hex->face(3)->child(0)->line(
9216 (hex->face(3)->refinement_case() ==
9222 unsigned int line_indices[4];
9223 for (
unsigned int i = 0; i < 4; ++i)
9224 line_indices[i] = lines[i]->
index();
9237 const unsigned int middle_vertices[2] = {
9238 middle_vertex_index<dim, spacedim>(hex->line(8)),
9239 middle_vertex_index<dim, spacedim>(hex->line(11))};
9241 for (
unsigned int i = 0; i < 4; ++i)
9242 if (lines[i]->vertex_index(i % 2) ==
9243 middle_vertices[i % 2])
9244 line_orientation[i] =
9249 Assert(lines[i]->vertex_index((i + 1) % 2) ==
9250 middle_vertices[i % 2],
9252 line_orientation[i] =
9258 new_quads[0]->set_bounding_object_indices(
9264 new_quads[0]->set_line_orientation(
9265 0, line_orientation[0]);
9266 new_quads[0]->set_line_orientation(
9267 1, line_orientation[1]);
9268 new_quads[0]->set_line_orientation(
9269 2, line_orientation[2]);
9270 new_quads[0]->set_line_orientation(
9271 3, line_orientation[3]);
9305 const int quad_indices[11] = {
9306 new_quads[0]->index(),
9308 hex->face(0)->child_index(
9309 child_at_origin[hex->face(0)->refinement_case() -
9310 1][f_fl[0]][f_ro[0]]),
9311 hex->face(0)->child_index(
9313 child_at_origin[hex->face(0)->refinement_case() -
9314 1][f_fl[0]][f_ro[0]]),
9316 hex->face(1)->child_index(
9317 child_at_origin[hex->face(1)->refinement_case() -
9318 1][f_fl[1]][f_ro[1]]),
9319 hex->face(1)->child_index(
9321 child_at_origin[hex->face(1)->refinement_case() -
9322 1][f_fl[1]][f_ro[1]]),
9324 hex->face(2)->child_index(
9325 child_at_origin[hex->face(2)->refinement_case() -
9326 1][f_fl[2]][f_ro[2]]),
9327 hex->face(2)->child_index(
9329 child_at_origin[hex->face(2)->refinement_case() -
9330 1][f_fl[2]][f_ro[2]]),
9332 hex->face(3)->child_index(
9333 child_at_origin[hex->face(3)->refinement_case() -
9334 1][f_fl[3]][f_ro[3]]),
9335 hex->face(3)->child_index(
9337 child_at_origin[hex->face(3)->refinement_case() -
9338 1][f_fl[3]][f_ro[3]]),
9340 hex->face(4)->index(),
9342 hex->face(5)->index()
9345 new_hexes[0]->set_bounding_object_indices(
9352 new_hexes[1]->set_bounding_object_indices(
9384 new_lines[0]->set_bounding_object_indices(
9385 {middle_vertex_index<dim, spacedim>(hex->face(4)),
9386 middle_vertex_index<dim, spacedim>(hex->face(5))});
9454 spacedim>::raw_line_iterator lines[13] = {
9455 hex->face(0)->child(0)->line(
9456 (hex->face(0)->refinement_case() ==
9460 hex->face(1)->child(0)->line(
9461 (hex->face(1)->refinement_case() ==
9465 hex->face(2)->child(0)->line(
9466 (hex->face(2)->refinement_case() ==
9470 hex->face(3)->child(0)->line(
9471 (hex->face(3)->refinement_case() ==
9479 0, f_or[4], f_fl[4], f_ro[4]))
9482 1, f_or[4], f_fl[4], f_ro[4])),
9486 3, f_or[4], f_fl[4], f_ro[4]))
9489 0, f_or[4], f_fl[4], f_ro[4])),
9493 0, f_or[4], f_fl[4], f_ro[4]))
9496 3, f_or[4], f_fl[4], f_ro[4])),
9500 3, f_or[4], f_fl[4], f_ro[4]))
9503 2, f_or[4], f_fl[4], f_ro[4])),
9508 0, f_or[5], f_fl[5], f_ro[5]))
9511 1, f_or[5], f_fl[5], f_ro[5])),
9515 3, f_or[5], f_fl[5], f_ro[5]))
9518 0, f_or[5], f_fl[5], f_ro[5])),
9522 0, f_or[5], f_fl[5], f_ro[5]))
9525 3, f_or[5], f_fl[5], f_ro[5])),
9529 3, f_or[5], f_fl[5], f_ro[5]))
9532 2, f_or[5], f_fl[5], f_ro[5])),
9537 unsigned int line_indices[13];
9538 for (
unsigned int i = 0; i < 13; ++i)
9539 line_indices[i] = lines[i]->
index();
9550 const unsigned int middle_vertices[4] = {
9551 hex->line(0)->child(0)->vertex_index(1),
9552 hex->line(1)->child(0)->vertex_index(1),
9553 hex->line(2)->child(0)->vertex_index(1),
9554 hex->line(3)->child(0)->vertex_index(1),
9560 for (
unsigned int i = 0; i < 4; ++i)
9561 if (lines[i]->vertex_index(0) == middle_vertices[i])
9562 line_orientation[i] =
9567 Assert(lines[i]->vertex_index(1) ==
9570 line_orientation[i] =
9580 for (
unsigned int i = 4; i < 12; ++i)
9581 if (lines[i]->vertex_index((i + 1) % 2) ==
9582 middle_vertex_index<dim, spacedim>(
9583 hex->face(3 + i / 4)))
9584 line_orientation[i] =
9589 Assert(lines[i]->vertex_index(i % 2) ==
9590 (middle_vertex_index<dim, spacedim>(
9591 hex->face(3 + i / 4))),
9593 line_orientation[i] =
9599 line_orientation[12] =
9625 new_quads[0]->set_bounding_object_indices(
9630 new_quads[1]->set_bounding_object_indices(
9635 new_quads[2]->set_bounding_object_indices(
9640 new_quads[3]->set_bounding_object_indices(
9646 new_quads[0]->set_line_orientation(
9647 0, line_orientation[2]);
9648 new_quads[0]->set_line_orientation(
9649 2, line_orientation[4]);
9650 new_quads[0]->set_line_orientation(
9651 3, line_orientation[8]);
9653 new_quads[1]->set_line_orientation(
9654 1, line_orientation[3]);
9655 new_quads[1]->set_line_orientation(
9656 2, line_orientation[5]);
9657 new_quads[1]->set_line_orientation(
9658 3, line_orientation[9]);
9660 new_quads[2]->set_line_orientation(
9661 0, line_orientation[6]);
9662 new_quads[2]->set_line_orientation(
9663 1, line_orientation[10]);
9664 new_quads[2]->set_line_orientation(
9665 2, line_orientation[0]);
9667 new_quads[3]->set_line_orientation(
9668 0, line_orientation[7]);
9669 new_quads[3]->set_line_orientation(
9670 1, line_orientation[11]);
9671 new_quads[3]->set_line_orientation(
9672 3, line_orientation[1]);
9705 const int quad_indices[20] = {
9706 new_quads[0]->index(),
9707 new_quads[1]->index(),
9708 new_quads[2]->index(),
9709 new_quads[3]->index(),
9711 hex->face(0)->child_index(
9712 child_at_origin[hex->face(0)->refinement_case() -
9713 1][f_fl[0]][f_ro[0]]),
9714 hex->face(0)->child_index(
9716 child_at_origin[hex->face(0)->refinement_case() -
9717 1][f_fl[0]][f_ro[0]]),
9719 hex->face(1)->child_index(
9720 child_at_origin[hex->face(1)->refinement_case() -
9721 1][f_fl[1]][f_ro[1]]),
9722 hex->face(1)->child_index(
9724 child_at_origin[hex->face(1)->refinement_case() -
9725 1][f_fl[1]][f_ro[1]]),
9727 hex->face(2)->child_index(
9728 child_at_origin[hex->face(2)->refinement_case() -
9729 1][f_fl[2]][f_ro[2]]),
9730 hex->face(2)->child_index(
9732 child_at_origin[hex->face(2)->refinement_case() -
9733 1][f_fl[2]][f_ro[2]]),
9735 hex->face(3)->child_index(
9736 child_at_origin[hex->face(3)->refinement_case() -
9737 1][f_fl[3]][f_ro[3]]),
9738 hex->face(3)->child_index(
9740 child_at_origin[hex->face(3)->refinement_case() -
9741 1][f_fl[3]][f_ro[3]]),
9743 hex->face(4)->isotropic_child_index(
9745 0, f_or[4], f_fl[4], f_ro[4])),
9746 hex->face(4)->isotropic_child_index(
9748 1, f_or[4], f_fl[4], f_ro[4])),
9749 hex->face(4)->isotropic_child_index(
9751 2, f_or[4], f_fl[4], f_ro[4])),
9752 hex->face(4)->isotropic_child_index(
9754 3, f_or[4], f_fl[4], f_ro[4])),
9756 hex->face(5)->isotropic_child_index(
9758 0, f_or[5], f_fl[5], f_ro[5])),
9759 hex->face(5)->isotropic_child_index(
9761 1, f_or[5], f_fl[5], f_ro[5])),
9762 hex->face(5)->isotropic_child_index(
9764 2, f_or[5], f_fl[5], f_ro[5])),
9765 hex->face(5)->isotropic_child_index(
9767 3, f_or[5], f_fl[5], f_ro[5]))};
9769 new_hexes[0]->set_bounding_object_indices(
9776 new_hexes[1]->set_bounding_object_indices(
9783 new_hexes[2]->set_bounding_object_indices(
9790 new_hexes[3]->set_bounding_object_indices(
9822 new_lines[0]->set_bounding_object_indices(
9823 {middle_vertex_index<dim, spacedim>(hex->face(2)),
9824 middle_vertex_index<dim, spacedim>(hex->face(3))});
9892 spacedim>::raw_line_iterator lines[13] = {
9893 hex->face(0)->child(0)->line(
9894 (hex->face(0)->refinement_case() ==
9898 hex->face(1)->child(0)->line(
9899 (hex->face(1)->refinement_case() ==
9903 hex->face(4)->child(0)->line(
9904 (hex->face(4)->refinement_case() ==
9908 hex->face(5)->child(0)->line(
9909 (hex->face(5)->refinement_case() ==
9917 0, f_or[2], f_fl[2], f_ro[2]))
9920 3, f_or[2], f_fl[2], f_ro[2])),
9924 3, f_or[2], f_fl[2], f_ro[2]))
9927 2, f_or[2], f_fl[2], f_ro[2])),
9931 0, f_or[2], f_fl[2], f_ro[2]))
9934 1, f_or[2], f_fl[2], f_ro[2])),
9938 3, f_or[2], f_fl[2], f_ro[2]))
9941 0, f_or[2], f_fl[2], f_ro[2])),
9946 0, f_or[3], f_fl[3], f_ro[3]))
9949 3, f_or[3], f_fl[3], f_ro[3])),
9953 3, f_or[3], f_fl[3], f_ro[3]))
9956 2, f_or[3], f_fl[3], f_ro[3])),
9960 0, f_or[3], f_fl[3], f_ro[3]))
9963 1, f_or[3], f_fl[3], f_ro[3])),
9967 3, f_or[3], f_fl[3], f_ro[3]))
9970 0, f_or[3], f_fl[3], f_ro[3])),
9975 unsigned int line_indices[13];
9976 for (
unsigned int i = 0; i < 13; ++i)
9977 line_indices[i] = lines[i]->
index();
9988 const unsigned int middle_vertices[4] = {
9989 hex->line(8)->child(0)->vertex_index(1),
9990 hex->line(9)->child(0)->vertex_index(1),
9991 hex->line(2)->child(0)->vertex_index(1),
9992 hex->line(6)->child(0)->vertex_index(1),
9997 for (
unsigned int i = 0; i < 4; ++i)
9998 if (lines[i]->vertex_index(0) == middle_vertices[i])
9999 line_orientation[i] =
10004 Assert(lines[i]->vertex_index(1) ==
10005 middle_vertices[i],
10007 line_orientation[i] =
10017 for (
unsigned int i = 4; i < 12; ++i)
10018 if (lines[i]->vertex_index((i + 1) % 2) ==
10019 middle_vertex_index<dim, spacedim>(
10020 hex->face(1 + i / 4)))
10021 line_orientation[i] =
10027 Assert(lines[i]->vertex_index(i % 2) ==
10028 (middle_vertex_index<dim, spacedim>(
10029 hex->face(1 + i / 4))),
10031 line_orientation[i] =
10037 line_orientation[12] =
10064 new_quads[0]->set_bounding_object_indices(
10068 line_indices[10]});
10069 new_quads[1]->set_bounding_object_indices(
10073 line_indices[11]});
10074 new_quads[2]->set_bounding_object_indices(
10078 line_indices[12]});
10079 new_quads[3]->set_bounding_object_indices(
10085 new_quads[0]->set_line_orientation(
10086 0, line_orientation[0]);
10087 new_quads[0]->set_line_orientation(
10088 2, line_orientation[6]);
10089 new_quads[0]->set_line_orientation(
10090 3, line_orientation[10]);
10092 new_quads[1]->set_line_orientation(
10093 1, line_orientation[1]);
10094 new_quads[1]->set_line_orientation(
10095 2, line_orientation[7]);
10096 new_quads[1]->set_line_orientation(
10097 3, line_orientation[11]);
10099 new_quads[2]->set_line_orientation(
10100 0, line_orientation[4]);
10101 new_quads[2]->set_line_orientation(
10102 1, line_orientation[8]);
10103 new_quads[2]->set_line_orientation(
10104 2, line_orientation[2]);
10106 new_quads[3]->set_line_orientation(
10107 0, line_orientation[5]);
10108 new_quads[3]->set_line_orientation(
10109 1, line_orientation[9]);
10110 new_quads[3]->set_line_orientation(
10111 3, line_orientation[3]);
10145 const int quad_indices[20] = {
10146 new_quads[0]->index(),
10147 new_quads[1]->index(),
10148 new_quads[2]->index(),
10149 new_quads[3]->index(),
10151 hex->face(0)->child_index(
10152 child_at_origin[hex->face(0)->refinement_case() -
10153 1][f_fl[0]][f_ro[0]]),
10154 hex->face(0)->child_index(
10156 child_at_origin[hex->face(0)->refinement_case() -
10157 1][f_fl[0]][f_ro[0]]),
10159 hex->face(1)->child_index(
10160 child_at_origin[hex->face(1)->refinement_case() -
10161 1][f_fl[1]][f_ro[1]]),
10162 hex->face(1)->child_index(
10164 child_at_origin[hex->face(1)->refinement_case() -
10165 1][f_fl[1]][f_ro[1]]),
10167 hex->face(2)->isotropic_child_index(
10169 0, f_or[2], f_fl[2], f_ro[2])),
10170 hex->face(2)->isotropic_child_index(
10172 1, f_or[2], f_fl[2], f_ro[2])),
10173 hex->face(2)->isotropic_child_index(
10175 2, f_or[2], f_fl[2], f_ro[2])),
10176 hex->face(2)->isotropic_child_index(
10178 3, f_or[2], f_fl[2], f_ro[2])),
10180 hex->face(3)->isotropic_child_index(
10182 0, f_or[3], f_fl[3], f_ro[3])),
10183 hex->face(3)->isotropic_child_index(
10185 1, f_or[3], f_fl[3], f_ro[3])),
10186 hex->face(3)->isotropic_child_index(
10188 2, f_or[3], f_fl[3], f_ro[3])),
10189 hex->face(3)->isotropic_child_index(
10191 3, f_or[3], f_fl[3], f_ro[3])),
10193 hex->face(4)->child_index(
10194 child_at_origin[hex->face(4)->refinement_case() -
10195 1][f_fl[4]][f_ro[4]]),
10196 hex->face(4)->child_index(
10198 child_at_origin[hex->face(4)->refinement_case() -
10199 1][f_fl[4]][f_ro[4]]),
10201 hex->face(5)->child_index(
10202 child_at_origin[hex->face(5)->refinement_case() -
10203 1][f_fl[5]][f_ro[5]]),
10204 hex->face(5)->child_index(
10206 child_at_origin[hex->face(5)->refinement_case() -
10207 1][f_fl[5]][f_ro[5]])};
10218 new_hexes[0]->set_bounding_object_indices(
10225 new_hexes[1]->set_bounding_object_indices(
10231 quad_indices[18]});
10232 new_hexes[2]->set_bounding_object_indices(
10239 new_hexes[3]->set_bounding_object_indices(
10245 quad_indices[19]});
10272 new_lines[0]->set_bounding_object_indices(
10274 {middle_vertex_index<dim, spacedim>(hex->face(0)),
10275 middle_vertex_index<dim, spacedim>(hex->face(1))});
10344 spacedim>::raw_line_iterator lines[13] = {
10345 hex->face(2)->child(0)->line(
10346 (hex->face(2)->refinement_case() ==
10350 hex->face(3)->child(0)->line(
10351 (hex->face(3)->refinement_case() ==
10355 hex->face(4)->child(0)->line(
10356 (hex->face(4)->refinement_case() ==
10360 hex->face(5)->child(0)->line(
10361 (hex->face(5)->refinement_case() ==
10369 0, f_or[0], f_fl[0], f_ro[0]))
10372 1, f_or[0], f_fl[0], f_ro[0])),
10376 3, f_or[0], f_fl[0], f_ro[0]))
10379 0, f_or[0], f_fl[0], f_ro[0])),
10383 0, f_or[0], f_fl[0], f_ro[0]))
10386 3, f_or[0], f_fl[0], f_ro[0])),
10390 3, f_or[0], f_fl[0], f_ro[0]))
10393 2, f_or[0], f_fl[0], f_ro[0])),
10398 0, f_or[1], f_fl[1], f_ro[1]))
10401 1, f_or[1], f_fl[1], f_ro[1])),
10405 3, f_or[1], f_fl[1], f_ro[1]))
10408 0, f_or[1], f_fl[1], f_ro[1])),
10412 0, f_or[1], f_fl[1], f_ro[1]))
10415 3, f_or[1], f_fl[1], f_ro[1])),
10419 3, f_or[1], f_fl[1], f_ro[1]))
10422 2, f_or[1], f_fl[1], f_ro[1])),
10427 unsigned int line_indices[13];
10429 for (
unsigned int i = 0; i < 13; ++i)
10430 line_indices[i] = lines[i]->
index();
10441 const unsigned int middle_vertices[4] = {
10442 hex->line(8)->child(0)->vertex_index(1),
10443 hex->line(10)->child(0)->vertex_index(1),
10444 hex->line(0)->child(0)->vertex_index(1),
10445 hex->line(4)->child(0)->vertex_index(1),
10450 for (
unsigned int i = 0; i < 4; ++i)
10451 if (lines[i]->vertex_index(0) == middle_vertices[i])
10452 line_orientation[i] =
10457 Assert(lines[i]->vertex_index(1) ==
10458 middle_vertices[i],
10460 line_orientation[i] =
10470 for (
unsigned int i = 4; i < 12; ++i)
10471 if (lines[i]->vertex_index((i + 1) % 2) ==
10472 middle_vertex_index<dim, spacedim>(
10473 hex->face(i / 4 - 1)))
10474 line_orientation[i] =
10479 Assert(lines[i]->vertex_index(i % 2) ==
10480 (middle_vertex_index<dim, spacedim>(
10481 hex->face(i / 4 - 1))),
10483 line_orientation[i] =
10488 line_orientation[12] =
10509 new_quads[0]->set_bounding_object_indices(
10513 line_indices[12]});
10514 new_quads[1]->set_bounding_object_indices(
10519 new_quads[2]->set_bounding_object_indices(
10524 new_quads[3]->set_bounding_object_indices(
10530 new_quads[0]->set_line_orientation(
10531 0, line_orientation[6]);
10532 new_quads[0]->set_line_orientation(
10533 1, line_orientation[10]);
10534 new_quads[0]->set_line_orientation(
10535 2, line_orientation[0]);
10537 new_quads[1]->set_line_orientation(
10538 0, line_orientation[7]);
10539 new_quads[1]->set_line_orientation(
10540 1, line_orientation[11]);
10541 new_quads[1]->set_line_orientation(
10542 3, line_orientation[1]);
10544 new_quads[2]->set_line_orientation(
10545 0, line_orientation[2]);
10546 new_quads[2]->set_line_orientation(
10547 2, line_orientation[4]);
10548 new_quads[2]->set_line_orientation(
10549 3, line_orientation[8]);
10551 new_quads[3]->set_line_orientation(
10552 1, line_orientation[3]);
10553 new_quads[3]->set_line_orientation(
10554 2, line_orientation[5]);
10555 new_quads[3]->set_line_orientation(
10556 3, line_orientation[9]);
10590 const int quad_indices[20] = {
10591 new_quads[0]->index(),
10592 new_quads[1]->index(),
10593 new_quads[2]->index(),
10594 new_quads[3]->index(),
10596 hex->face(0)->isotropic_child_index(
10598 0, f_or[0], f_fl[0], f_ro[0])),
10599 hex->face(0)->isotropic_child_index(
10601 1, f_or[0], f_fl[0], f_ro[0])),
10602 hex->face(0)->isotropic_child_index(
10604 2, f_or[0], f_fl[0], f_ro[0])),
10605 hex->face(0)->isotropic_child_index(
10607 3, f_or[0], f_fl[0], f_ro[0])),
10609 hex->face(1)->isotropic_child_index(
10611 0, f_or[1], f_fl[1], f_ro[1])),
10612 hex->face(1)->isotropic_child_index(
10614 1, f_or[1], f_fl[1], f_ro[1])),
10615 hex->face(1)->isotropic_child_index(
10617 2, f_or[1], f_fl[1], f_ro[1])),
10618 hex->face(1)->isotropic_child_index(
10620 3, f_or[1], f_fl[1], f_ro[1])),
10622 hex->face(2)->child_index(
10623 child_at_origin[hex->face(2)->refinement_case() -
10624 1][f_fl[2]][f_ro[2]]),
10625 hex->face(2)->child_index(
10627 child_at_origin[hex->face(2)->refinement_case() -
10628 1][f_fl[2]][f_ro[2]]),
10630 hex->face(3)->child_index(
10631 child_at_origin[hex->face(3)->refinement_case() -
10632 1][f_fl[3]][f_ro[3]]),
10633 hex->face(3)->child_index(
10635 child_at_origin[hex->face(3)->refinement_case() -
10636 1][f_fl[3]][f_ro[3]]),
10638 hex->face(4)->child_index(
10639 child_at_origin[hex->face(4)->refinement_case() -
10640 1][f_fl[4]][f_ro[4]]),
10641 hex->face(4)->child_index(
10643 child_at_origin[hex->face(4)->refinement_case() -
10644 1][f_fl[4]][f_ro[4]]),
10646 hex->face(5)->child_index(
10647 child_at_origin[hex->face(5)->refinement_case() -
10648 1][f_fl[5]][f_ro[5]]),
10649 hex->face(5)->child_index(
10651 child_at_origin[hex->face(5)->refinement_case() -
10652 1][f_fl[5]][f_ro[5]])};
10654 new_hexes[0]->set_bounding_object_indices(
10661 new_hexes[1]->set_bounding_object_indices(
10668 new_hexes[2]->set_bounding_object_indices(
10674 quad_indices[18]});
10675 new_hexes[3]->set_bounding_object_indices(
10681 quad_indices[19]});
10713 ++next_unused_vertex;
10715 next_unused_vertex < triangulation.
vertices.size(),
10717 "Internal error: During refinement, the triangulation wants to access an element of the 'vertices' array but it turns out that the array is not large enough."));
10727 triangulation.
vertices[next_unused_vertex] =
10728 hex->center(
true,
true);
10749 const unsigned int vertex_indices[7] = {
10750 middle_vertex_index<dim, spacedim>(hex->face(0)),
10751 middle_vertex_index<dim, spacedim>(hex->face(1)),
10752 middle_vertex_index<dim, spacedim>(hex->face(2)),
10753 middle_vertex_index<dim, spacedim>(hex->face(3)),
10754 middle_vertex_index<dim, spacedim>(hex->face(4)),
10755 middle_vertex_index<dim, spacedim>(hex->face(5)),
10756 next_unused_vertex};
10758 new_lines[0]->set_bounding_object_indices(
10759 {vertex_indices[2], vertex_indices[6]});
10760 new_lines[1]->set_bounding_object_indices(
10761 {vertex_indices[6], vertex_indices[3]});
10762 new_lines[2]->set_bounding_object_indices(
10763 {vertex_indices[0], vertex_indices[6]});
10764 new_lines[3]->set_bounding_object_indices(
10765 {vertex_indices[6], vertex_indices[1]});
10766 new_lines[4]->set_bounding_object_indices(
10767 {vertex_indices[4], vertex_indices[6]});
10768 new_lines[5]->set_bounding_object_indices(
10769 {vertex_indices[6], vertex_indices[5]});
10838 spacedim>::raw_line_iterator lines[30] = {
10842 0, f_or[0], f_fl[0], f_ro[0]))
10845 1, f_or[0], f_fl[0], f_ro[0])),
10849 3, f_or[0], f_fl[0], f_ro[0]))
10852 0, f_or[0], f_fl[0], f_ro[0])),
10856 0, f_or[0], f_fl[0], f_ro[0]))
10859 3, f_or[0], f_fl[0], f_ro[0])),
10863 3, f_or[0], f_fl[0], f_ro[0]))
10866 2, f_or[0], f_fl[0], f_ro[0])),
10871 0, f_or[1], f_fl[1], f_ro[1]))
10874 1, f_or[1], f_fl[1], f_ro[1])),
10878 3, f_or[1], f_fl[1], f_ro[1]))
10881 0, f_or[1], f_fl[1], f_ro[1])),
10885 0, f_or[1], f_fl[1], f_ro[1]))
10888 3, f_or[1], f_fl[1], f_ro[1])),
10892 3, f_or[1], f_fl[1], f_ro[1]))
10895 2, f_or[1], f_fl[1], f_ro[1])),
10900 0, f_or[2], f_fl[2], f_ro[2]))
10903 1, f_or[2], f_fl[2], f_ro[2])),
10907 3, f_or[2], f_fl[2], f_ro[2]))
10910 0, f_or[2], f_fl[2], f_ro[2])),
10914 0, f_or[2], f_fl[2], f_ro[2]))
10917 3, f_or[2], f_fl[2], f_ro[2])),
10921 3, f_or[2], f_fl[2], f_ro[2]))
10924 2, f_or[2], f_fl[2], f_ro[2])),
10929 0, f_or[3], f_fl[3], f_ro[3]))
10932 1, f_or[3], f_fl[3], f_ro[3])),
10936 3, f_or[3], f_fl[3], f_ro[3]))
10939 0, f_or[3], f_fl[3], f_ro[3])),
10943 0, f_or[3], f_fl[3], f_ro[3]))
10946 3, f_or[3], f_fl[3], f_ro[3])),
10950 3, f_or[3], f_fl[3], f_ro[3]))
10953 2, f_or[3], f_fl[3], f_ro[3])),
10958 0, f_or[4], f_fl[4], f_ro[4]))
10961 1, f_or[4], f_fl[4], f_ro[4])),
10965 3, f_or[4], f_fl[4], f_ro[4]))
10968 0, f_or[4], f_fl[4], f_ro[4])),
10972 0, f_or[4], f_fl[4], f_ro[4]))
10975 3, f_or[4], f_fl[4], f_ro[4])),
10979 3, f_or[4], f_fl[4], f_ro[4]))
10982 2, f_or[4], f_fl[4], f_ro[4])),
10987 0, f_or[5], f_fl[5], f_ro[5]))
10990 1, f_or[5], f_fl[5], f_ro[5])),
10994 3, f_or[5], f_fl[5], f_ro[5]))
10997 0, f_or[5], f_fl[5], f_ro[5])),
11001 0, f_or[5], f_fl[5], f_ro[5]))
11004 3, f_or[5], f_fl[5], f_ro[5])),
11008 3, f_or[5], f_fl[5], f_ro[5]))
11011 2, f_or[5], f_fl[5], f_ro[5])),
11021 unsigned int line_indices[30];
11022 for (
unsigned int i = 0; i < 30; ++i)
11023 line_indices[i] = lines[i]->
index();
11038 for (
unsigned int i = 0; i < 24; ++i)
11039 if (lines[i]->vertex_index((i + 1) % 2) ==
11040 vertex_indices[i / 4])
11041 line_orientation[i] =
11047 Assert(lines[i]->vertex_index(i % 2) ==
11048 vertex_indices[i / 4],
11050 line_orientation[i] =
11056 for (
unsigned int i = 24; i < 30; ++i)
11057 line_orientation[i] =
11090 new_quads[0]->set_bounding_object_indices(
11094 line_indices[24]});
11095 new_quads[1]->set_bounding_object_indices(
11099 line_indices[25]});
11100 new_quads[2]->set_bounding_object_indices(
11104 line_indices[20]});
11105 new_quads[3]->set_bounding_object_indices(
11109 line_indices[21]});
11110 new_quads[4]->set_bounding_object_indices(
11114 line_indices[28]});
11115 new_quads[5]->set_bounding_object_indices(
11119 line_indices[29]});
11120 new_quads[6]->set_bounding_object_indices(
11125 new_quads[7]->set_bounding_object_indices(
11130 new_quads[8]->set_bounding_object_indices(
11134 line_indices[26]});
11135 new_quads[9]->set_bounding_object_indices(
11139 line_indices[27]});
11140 new_quads[10]->set_bounding_object_indices(
11144 line_indices[12]});
11145 new_quads[11]->set_bounding_object_indices(
11149 line_indices[13]});
11154 new_quads[0]->set_line_orientation(
11155 0, line_orientation[10]);
11156 new_quads[0]->set_line_orientation(
11157 2, line_orientation[16]);
11159 new_quads[1]->set_line_orientation(
11160 1, line_orientation[14]);
11161 new_quads[1]->set_line_orientation(
11162 2, line_orientation[17]);
11164 new_quads[2]->set_line_orientation(
11165 0, line_orientation[11]);
11166 new_quads[2]->set_line_orientation(
11167 3, line_orientation[20]);
11169 new_quads[3]->set_line_orientation(
11170 1, line_orientation[15]);
11171 new_quads[3]->set_line_orientation(
11172 3, line_orientation[21]);
11174 new_quads[4]->set_line_orientation(
11175 0, line_orientation[18]);
11176 new_quads[4]->set_line_orientation(
11177 2, line_orientation[0]);
11179 new_quads[5]->set_line_orientation(
11180 1, line_orientation[22]);
11181 new_quads[5]->set_line_orientation(
11182 2, line_orientation[1]);
11184 new_quads[6]->set_line_orientation(
11185 0, line_orientation[19]);
11186 new_quads[6]->set_line_orientation(
11187 3, line_orientation[4]);
11189 new_quads[7]->set_line_orientation(
11190 1, line_orientation[23]);
11191 new_quads[7]->set_line_orientation(
11192 3, line_orientation[5]);
11194 new_quads[8]->set_line_orientation(
11195 0, line_orientation[2]);
11196 new_quads[8]->set_line_orientation(
11197 2, line_orientation[8]);
11199 new_quads[9]->set_line_orientation(
11200 1, line_orientation[6]);
11201 new_quads[9]->set_line_orientation(
11202 2, line_orientation[9]);
11204 new_quads[10]->set_line_orientation(
11205 0, line_orientation[3]);
11206 new_quads[10]->set_line_orientation(
11207 3, line_orientation[12]);
11209 new_quads[11]->set_line_orientation(
11210 1, line_orientation[7]);
11211 new_quads[11]->set_line_orientation(
11212 3, line_orientation[13]);
11253 const int quad_indices[36] = {
11254 new_quads[0]->index(),
11255 new_quads[1]->index(),
11256 new_quads[2]->index(),
11257 new_quads[3]->index(),
11258 new_quads[4]->index(),
11259 new_quads[5]->index(),
11260 new_quads[6]->index(),
11261 new_quads[7]->index(),
11262 new_quads[8]->index(),
11263 new_quads[9]->index(),
11264 new_quads[10]->index(),
11265 new_quads[11]->index(),
11267 hex->face(0)->isotropic_child_index(
11269 0, f_or[0], f_fl[0], f_ro[0])),
11270 hex->face(0)->isotropic_child_index(
11272 1, f_or[0], f_fl[0], f_ro[0])),
11273 hex->face(0)->isotropic_child_index(
11275 2, f_or[0], f_fl[0], f_ro[0])),
11276 hex->face(0)->isotropic_child_index(
11278 3, f_or[0], f_fl[0], f_ro[0])),
11280 hex->face(1)->isotropic_child_index(
11282 0, f_or[1], f_fl[1], f_ro[1])),
11283 hex->face(1)->isotropic_child_index(
11285 1, f_or[1], f_fl[1], f_ro[1])),
11286 hex->face(1)->isotropic_child_index(
11288 2, f_or[1], f_fl[1], f_ro[1])),
11289 hex->face(1)->isotropic_child_index(
11291 3, f_or[1], f_fl[1], f_ro[1])),
11293 hex->face(2)->isotropic_child_index(
11295 0, f_or[2], f_fl[2], f_ro[2])),
11296 hex->face(2)->isotropic_child_index(
11298 1, f_or[2], f_fl[2], f_ro[2])),
11299 hex->face(2)->isotropic_child_index(
11301 2, f_or[2], f_fl[2], f_ro[2])),
11302 hex->face(2)->isotropic_child_index(
11304 3, f_or[2], f_fl[2], f_ro[2])),
11306 hex->face(3)->isotropic_child_index(
11308 0, f_or[3], f_fl[3], f_ro[3])),
11309 hex->face(3)->isotropic_child_index(
11311 1, f_or[3], f_fl[3], f_ro[3])),
11312 hex->face(3)->isotropic_child_index(
11314 2, f_or[3], f_fl[3], f_ro[3])),
11315 hex->face(3)->isotropic_child_index(
11317 3, f_or[3], f_fl[3], f_ro[3])),
11319 hex->face(4)->isotropic_child_index(
11321 0, f_or[4], f_fl[4], f_ro[4])),
11322 hex->face(4)->isotropic_child_index(
11324 1, f_or[4], f_fl[4], f_ro[4])),
11325 hex->face(4)->isotropic_child_index(
11327 2, f_or[4], f_fl[4], f_ro[4])),
11328 hex->face(4)->isotropic_child_index(
11330 3, f_or[4], f_fl[4], f_ro[4])),
11332 hex->face(5)->isotropic_child_index(
11334 0, f_or[5], f_fl[5], f_ro[5])),
11335 hex->face(5)->isotropic_child_index(
11337 1, f_or[5], f_fl[5], f_ro[5])),
11338 hex->face(5)->isotropic_child_index(
11340 2, f_or[5], f_fl[5], f_ro[5])),
11341 hex->face(5)->isotropic_child_index(
11343 3, f_or[5], f_fl[5], f_ro[5]))};
11346 new_hexes[0]->set_bounding_object_indices(
11353 new_hexes[1]->set_bounding_object_indices(
11360 new_hexes[2]->set_bounding_object_indices(
11366 quad_indices[10]});
11367 new_hexes[3]->set_bounding_object_indices(
11373 quad_indices[11]});
11376 new_hexes[4]->set_bounding_object_indices(
11382 quad_indices[32]});
11383 new_hexes[5]->set_bounding_object_indices(
11389 quad_indices[33]});
11390 new_hexes[6]->set_bounding_object_indices(
11396 quad_indices[34]});
11397 new_hexes[7]->set_bounding_object_indices(
11403 quad_indices[35]});
11437 for (
unsigned int s = 0;
11444 const unsigned int current_child =
11453 ref_case, f, f_or[f], f_fl[f], f_ro[f]));
11454 new_hexes[current_child]->set_combined_face_orientation(
11460 if (check_for_distorted_cells &&
11461 has_distorted_children<dim, spacedim>(hex))
11478 triangulation.
faces->quads.clear_user_data();
11481 return cells_with_distorted_children;
11497 template <
int spacedim>
11504 template <
int dim,
int spacedim>
11511 if (spacedim > dim)
11523 for (
const unsigned int face_no :
11525 if (cell->
face(face_no)->at_boundary())
11536 spacedim>::face_iterator
11537 face = cell->
face(face_no);
11547 .transform_real_to_unit_cell(cell, new_bound);
11557 const double dist =
11558 std::fabs(new_unit[face_no / 2] - face_no % 2);
11563 const double allowed = 0.25;
11565 if (dist > allowed)
11585 template <
int dim,
int spacedim>
11590 ExcMessage(
"Wrong function called -- there should "
11591 "be a specialization."));
11595 template <
int spacedim>
11600 const unsigned int dim = 3;
11601 using raw_line_iterator =
11606 bool mesh_changed =
false;
11610 mesh_changed =
false;
11626 const std::array<unsigned int, 12> line_indices =
11627 TriaAccessorImplementation::Implementation::
11628 get_line_indices_of_cell(*cell);
11629 for (
unsigned int l = 0; l < cell->
n_lines(); ++l)
11634 raw_line_iterator line(&triangulation,
11638 line->set_user_flag();
11644 const std::array<unsigned int, 12> line_indices =
11645 TriaAccessorImplementation::Implementation::
11646 get_line_indices_of_cell(*cell);
11647 for (
unsigned int l = 0; l < cell->
n_lines(); ++l)
11652 raw_line_iterator line(&triangulation,
11656 line->set_user_flag();
11670 cell != triangulation.
end();
11673 const std::array<unsigned int, 12> line_indices =
11674 TriaAccessorImplementation::Implementation::
11675 get_line_indices_of_cell(*cell);
11676 for (
unsigned int l = 0; l < cell->
n_lines(); ++l)
11678 raw_line_iterator line(&triangulation, 0, line_indices[l]);
11679 if (line->has_children())
11688 bool offending_line_found =
false;
11690 for (
unsigned int c = 0; c < 2; ++c)
11692 Assert(line->child(c)->has_children() ==
false,
11695 if (line->child(c)->user_flag_set() &&
11708 allow_anisotropic_smoothing)
11713 for (
unsigned int k = 0; k < cell->
n_lines();
11719 raw_line_iterator(&triangulation,
11725 offending_line_found =
true;
11731 for (
unsigned int k = 0; k < cell->
n_lines();
11735 raw_line_iterator(&triangulation,
11738 if (!line->has_children() &&
11740 line_refinement_case(
11743 line->set_user_flag();
11750 if (offending_line_found)
11752 mesh_changed =
true;
11771 triangulation.
last();
11772 cell != triangulation.
end();
11776 const std::array<unsigned int, 12> line_indices =
11777 TriaAccessorImplementation::Implementation::
11778 get_line_indices_of_cell(*cell);
11779 for (
unsigned int l = 0; l < cell->
n_lines(); ++l)
11781 raw_line_iterator line(&triangulation,
11784 if (line->has_children() &&
11785 (line->child(0)->user_flag_set() ||
11786 line->child(1)->user_flag_set()))
11788 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
11791 for (
unsigned int k = 0; k < cell->
n_lines(); ++k)
11797 raw_line_iterator(&triangulation,
11801 mesh_changed =
true;
11807 while (mesh_changed ==
true);
11818 template <
int dim,
int spacedim>
11838 const unsigned int n_subfaces =
11843 for (
unsigned int c = 0; c < n_subfaces; ++c)
11846 child = cell->
child(
11850 child_neighbor = child->
neighbor(n);
11890 template <
int spacedim>
11895 template <
int dim,
int spacedim>
11898 std::vector<std::pair<unsigned int, unsigned int>> adjacent_cells(
11900 {numbers::invalid_unsigned_int, numbers::invalid_unsigned_int});
11902 const auto set_entry = [&](
const auto &face_index,
const auto &cell) {
11903 const std::pair<unsigned int, unsigned int> cell_pair = {
11905 unsigned int index;
11907 if (adjacent_cells[2 * face_index].first ==
11909 adjacent_cells[2 * face_index].second ==
11912 index = 2 * face_index + 0;
11916 Assert(((adjacent_cells[2 * face_index + 1].first ==
11918 (adjacent_cells[2 * face_index + 1].second ==
11921 index = 2 * face_index + 1;
11924 adjacent_cells[
index] = cell_pair;
11927 const auto get_entry =
11928 [&](
const auto &face_index,
11930 auto test = adjacent_cells[2 * face_index];
11932 if (test == std::pair<unsigned int, unsigned int>(cell->
level(),
11934 test = adjacent_cells[2 * face_index + 1];
11948 set_entry(face->index(), cell);
11950 if (cell->
is_active() && face->has_children())
11951 for (
unsigned int c = 0; c < face->n_children(); ++c)
11952 set_entry(face->child(c)->index(), cell);
11960 template <
int dim,
int spacedim>
11965 std::vector<unsigned int> & ,
11966 std::vector<unsigned int> & )
11971 template <
int dim,
int spacedim>
11974 const bool check_for_distorted_cells)
11977 triangulation, check_for_distorted_cells);
11980 template <
int dim,
int spacedim>
11988 template <
int dim,
int spacedim>
11996 template <
int dim,
int spacedim>
12008 template <
int dim,
int spacedim>
12013 return flat_manifold;
12020template <
int dim,
int spacedim>
12026template <
int dim,
int spacedim>
12029 const MeshSmoothing smooth_grid,
12030 const bool check_for_distorted_cells)
12031 : cell_attached_data({0, 0, {}, {}})
12032 , smooth_grid(smooth_grid)
12033 , anisotropic_refinement(
false)
12034 , check_for_distorted_cells(check_for_distorted_cells)
12038 vertex_to_boundary_id_map_1d =
12039 std::make_unique<std::map<unsigned int, types::boundary_id>>();
12040 vertex_to_manifold_id_map_1d =
12041 std::make_unique<std::map<unsigned int, types::manifold_id>>();
12045 signals.create.connect(signals.any_change);
12046 signals.post_refinement.connect(signals.any_change);
12047 signals.clear.connect(signals.any_change);
12048 signals.mesh_movement.connect(signals.any_change);
12053template <
int dim,
int spacedim>
12056 Triangulation<dim, spacedim> &&tria) noexcept
12057 : EnableObserverPointer(std::move(tria))
12058 , smooth_grid(tria.smooth_grid)
12059 , reference_cells(std::move(tria.reference_cells))
12060 , periodic_face_pairs_level_0(std::move(tria.periodic_face_pairs_level_0))
12061 , periodic_face_map(std::move(tria.periodic_face_map))
12062 , levels(std::move(tria.levels))
12063 , faces(std::move(tria.faces))
12064 , vertices(std::move(tria.vertices))
12065 , vertices_used(std::move(tria.vertices_used))
12066 , manifolds(std::move(tria.manifolds))
12067 , anisotropic_refinement(tria.anisotropic_refinement)
12068 , check_for_distorted_cells(tria.check_for_distorted_cells)
12069 , number_cache(std::move(tria.number_cache))
12070 , vertex_to_boundary_id_map_1d(std::move(tria.vertex_to_boundary_id_map_1d))
12071 , vertex_to_manifold_id_map_1d(std::move(tria.vertex_to_manifold_id_map_1d))
12073 tria.number_cache = internal::TriangulationImplementation::NumberCache<dim>();
12076 this->policy = tria.policy->clone();
12080template <
int dim,
int spacedim>
12083 Triangulation<dim, spacedim> &&tria)
noexcept
12087 smooth_grid = tria.smooth_grid;
12088 reference_cells = std::move(tria.reference_cells);
12089 periodic_face_pairs_level_0 = std::move(tria.periodic_face_pairs_level_0);
12090 periodic_face_map = std::move(tria.periodic_face_map);
12091 levels = std::move(tria.levels);
12092 faces = std::move(tria.faces);
12093 vertices = std::move(tria.vertices);
12094 vertices_used = std::move(tria.vertices_used);
12095 manifolds = std::move(tria.manifolds);
12096 anisotropic_refinement = tria.anisotropic_refinement;
12097 number_cache = tria.number_cache;
12098 vertex_to_boundary_id_map_1d = std::move(tria.vertex_to_boundary_id_map_1d);
12099 vertex_to_manifold_id_map_1d = std::move(tria.vertex_to_manifold_id_map_1d);
12101 tria.number_cache = internal::TriangulationImplementation::NumberCache<dim>();
12104 this->policy = tria.policy->clone();
12111template <
int dim,
int spacedim>
12129 AssertNothrow((dim == 1) || (vertex_to_boundary_id_map_1d ==
nullptr),
12134 AssertNothrow((dim == 1) || (vertex_to_manifold_id_map_1d ==
nullptr),
12140template <
int dim,
int spacedim>
12148 clear_despite_subscriptions();
12149 periodic_face_pairs_level_0.clear();
12150 periodic_face_map.clear();
12151 reference_cells.clear();
12153 cell_attached_data = {0, 0, {}, {}};
12154 data_serializer.clear();
12157template <
int dim,
int spacedim>
12161 return MPI_COMM_SELF;
12166template <
int dim,
int spacedim>
12170 return get_mpi_communicator();
12175template <
int dim,
int spacedim>
12180 return number_cache.active_cell_index_partitioner;
12185template <
int dim,
int spacedim>
12192 return number_cache.level_cell_index_partitioners[level];
12197template <
int dim,
int spacedim>
12200 const MeshSmoothing mesh_smoothing)
12202 smooth_grid = mesh_smoothing;
12207template <
int dim,
int spacedim>
12212 return smooth_grid;
12217template <
int dim,
int spacedim>
12221 const Manifold<dim, spacedim> &manifold_object)
12225 manifolds[m_number] = manifold_object.
clone();
12230template <
int dim,
int spacedim>
12238 manifolds[m_number] =
12245template <
int dim,
int spacedim>
12249 for (
auto &m : manifolds)
12256template <
int dim,
int spacedim>
12264 "Error: set_all_manifold_ids() can not be called on an empty Triangulation."));
12266 for (
const auto &cell : this->active_cell_iterators())
12271template <
int dim,
int spacedim>
12279 "Error: set_all_manifold_ids_on_boundary() can not be called on an empty Triangulation."));
12281 for (
const auto &cell : this->active_cell_iterators())
12283 if (cell->
face(f)->at_boundary())
12284 cell->
face(f)->set_all_manifold_ids(m_number);
12288template <
int dim,
int spacedim>
12297 "Error: set_all_manifold_ids_on_boundary() can not be called on an empty Triangulation."));
12299 [[maybe_unused]]
bool boundary_found =
false;
12301 for (
const auto &cell : this->active_cell_iterators())
12305 if (cell->
face(f)->at_boundary() &&
12306 cell->
face(f)->boundary_id() == b_id)
12308 boundary_found =
true;
12309 cell->
face(f)->set_manifold_id(m_number);
12314 for (
unsigned int e = 0; e < GeometryInfo<dim>::lines_per_cell; ++
e)
12315 if (cell->
line(e)->at_boundary() &&
12316 cell->
line(e)->boundary_id() == b_id)
12318 boundary_found =
true;
12319 cell->
line(e)->set_manifold_id(m_number);
12323 Assert(boundary_found, ExcBoundaryIdNotFound(b_id));
12328template <
int dim,
int spacedim>
12340 const auto it = manifolds.find(m_number);
12342 if (it != manifolds.end())
12345 return *(it->second);
12351 "No manifold of the manifold id " + std::to_string(m_number) +
12352 " has been attached to the triangulation. "
12353 "Please attach the right manifold with Triangulation::set_manifold()."));
12361template <
int dim,
int spacedim>
12366 std::set<types::boundary_id> boundary_ids;
12367 for (
const auto &cell : active_cell_iterators())
12371 boundary_ids.insert(cell->
face(face)->boundary_id());
12373 return {boundary_ids.begin(), boundary_ids.end()};
12378template <
int dim,
int spacedim>
12383 std::set<types::manifold_id> m_ids;
12384 for (
const auto &cell : active_cell_iterators())
12389 m_ids.insert(face->manifold_id());
12392 const auto line_indices = internal::TriaAccessorImplementation::
12393 Implementation::get_line_indices_of_cell(*cell);
12394 for (
unsigned int l = 0;
l < cell->
n_lines(); ++
l)
12396 raw_line_iterator line(
this, 0, line_indices[l]);
12397 m_ids.insert(line->manifold_id());
12401 return {m_ids.begin(), m_ids.end()};
12409template <
int dim,
int spacedim>
12412 const Triangulation<dim, spacedim> &other_tria)
12414 Assert((vertices.empty()) && (levels.empty()) && (faces ==
nullptr),
12415 ExcTriangulationNotEmpty(vertices.size(), levels.size()));
12417 (dim == 1 || other_tria.
faces !=
nullptr),
12419 "When calling Triangulation::copy_triangulation(), "
12420 "the target triangulation must be empty but the source "
12421 "triangulation (the argument to this function) must contain "
12422 "something. Here, it seems like the source does not "
12423 "contain anything at all."));
12434 faces = std::make_unique<internal::TriangulationImplementation::TriaFaces>(
12435 *other_tria.
faces);
12437 for (
const auto &p : other_tria.
manifolds)
12438 set_manifold(p.first, *p.second);
12441 levels.reserve(other_tria.
levels.size());
12442 for (
const auto &level : other_tria.
levels)
12444 std::make_unique<internal::TriangulationImplementation::TriaLevel>(
12451 vertex_to_boundary_id_map_1d =
12452 std::make_unique<std::map<unsigned int, types::boundary_id>>(
12455 vertex_to_manifold_id_map_1d =
12456 std::make_unique<std::map<unsigned int, types::manifold_id>>(
12461 this->policy = other_tria.
policy->clone();
12464 this->periodic_face_pairs_level_0.reserve(
12469 auto entry = other_entry;
12471 cell_iterator(
this, entry.cell[0]->level(), entry.cell[0]->index());
12473 cell_iterator(
this, entry.cell[1]->level(), entry.cell[1]->index());
12474 periodic_face_pairs_level_0.emplace_back(entry);
12477 for (
auto [first_cell_, second_cell_and_orientation] :
12480 auto first_cell = first_cell_;
12481 first_cell.first = cell_iterator(
this,
12482 first_cell.first->level(),
12483 first_cell.first->index());
12484 second_cell_and_orientation.first.first =
12485 cell_iterator(
this,
12486 second_cell_and_orientation.first.first->level(),
12487 second_cell_and_orientation.first.first->index());
12489 this->periodic_face_map[first_cell] = second_cell_and_orientation;
12504template <
int dim,
int spacedim>
12508 this->update_reference_cells();
12510 if (this->all_reference_cells_are_hyper_cube())
12513 std::make_unique<internal::TriangulationImplementation::PolicyWrapper<
12516 internal::TriangulationImplementation::Implementation>>();
12521 std::make_unique<internal::TriangulationImplementation::PolicyWrapper<
12524 internal::TriangulationImplementation::ImplementationMixedMesh>>();
12530template <
int dim,
int spacedim>
12533 const std::vector<Point<spacedim>> &v,
12534 const std::vector<CellData<dim>> &cells,
12535 const SubCellData &subcelldata)
12537 Assert((vertices.empty()) && (levels.empty()) && (faces ==
nullptr),
12538 ExcTriangulationNotEmpty(vertices.size(), levels.size()));
12553 clear_despite_subscriptions();
12561 reset_cell_vertex_indices_cache();
12563 *
this, levels.size(), number_cache);
12564 reset_active_cell_indices();
12565 reset_global_cell_indices();
12570 if (check_for_distorted_cells)
12572 DistortedCellList distorted_cells = collect_distorted_coarse_cells(*
this);
12576 AssertThrow(distorted_cells.distorted_cells.empty(), distorted_cells);
12609 if ((dim == spacedim - 1) && all_reference_cells_are_hyper_cube())
12617 const bool values[][2] = {{
false,
true}, {
true,
false}};
12620 correct(i, j) =
values[i][j];
12625 const bool values[][4] = {{
false,
true,
true,
false},
12626 {
true,
false,
false,
true},
12627 {
true,
false,
false,
true},
12628 {
false,
true,
true,
false}};
12631 correct(i, j) = (
values[i][j]);
12639 std::list<active_cell_iterator> this_round, next_round;
12640 active_cell_iterator neighbor;
12644 this_round.push_back(begin_active());
12645 begin_active()->set_direction_flag(
true);
12646 begin_active()->set_user_flag();
12648 while (this_round.size() > 0)
12650 for (
const auto &cell : this_round)
12654 if (cell->
face(i)->at_boundary() ==
false)
12660 const unsigned int nb_of_nb =
12665 if (neighbor->user_flag_set())
12668 !(correct(i, nb_of_nb) ^
12669 (neighbor->direction_flag() ==
12672 "The triangulation you are trying to create is not orientable."));
12681 if (correct(i, nb_of_nb) ^
12682 (neighbor->direction_flag() ==
12684 neighbor->set_direction_flag(
12685 !neighbor->direction_flag());
12686 neighbor->set_user_flag();
12687 next_round.push_back(neighbor);
12698 if (next_round.empty())
12699 for (
const auto &cell : this->active_cell_iterators())
12702 next_round.push_back(cell);
12709 next_round.swap(this_round);
12710 next_round.clear();
12712 clear_user_flags();
12715 this->update_cell_relations();
12723template <
int dim,
int spacedim>
12726 const TriangulationDescription::Description<dim, spacedim> &construction_data)
12734 auto cell_infos = construction_data.
cell_infos;
12737 for (
auto &cell_info : cell_infos)
12741 [&](
const TriangulationDescription::CellData<dim> &a,
12742 const TriangulationDescription::CellData<dim> &b) {
12743 const CellId a_id(a.id);
12744 const CellId b_id(b.id);
12746 const auto a_coarse_cell_index =
12747 this->coarse_cell_id_to_coarse_cell_index(a_id.get_coarse_cell_id());
12748 const auto b_coarse_cell_index =
12749 this->coarse_cell_id_to_coarse_cell_index(b_id.get_coarse_cell_id());
12756 if (a_coarse_cell_index != b_coarse_cell_index)
12757 return a_coarse_cell_index < b_coarse_cell_index;
12759 return a_id < b_id;
12765 for (
unsigned int level = 0;
12766 level < cell_infos.size() && !cell_infos[level].empty();
12772 auto cell = this->
begin(level);
12773 auto cell_info = cell_infos[level].begin();
12774 for (; cell_info != cell_infos[level].end(); ++cell_info)
12776 while (cell_info->id != cell->
id().template to_binary<dim>())
12780 cell->
face(face)->set_manifold_id(
12781 cell_info->manifold_line_ids[face]);
12785 cell->
face(face)->set_manifold_id(
12786 cell_info->manifold_quad_ids[face]);
12788 const auto line_indices = internal::TriaAccessorImplementation::
12789 Implementation::get_line_indices_of_cell(*cell);
12790 for (
unsigned int l = 0;
l < cell->
n_lines(); ++
l)
12792 raw_line_iterator line(
this, 0, line_indices[l]);
12793 line->set_manifold_id(cell_info->manifold_line_ids[l]);
12802 if (level + 1 != cell_infos.size())
12806 auto coarse_cell = this->
begin(level);
12807 auto fine_cell_info = cell_infos[level + 1].begin();
12810 for (; fine_cell_info != cell_infos[level + 1].end();
12815 !coarse_cell->id().is_parent_of(CellId(fine_cell_info->id)))
12819 coarse_cell->set_refine_flag();
12823 ::Triangulation<dim,
12824 spacedim>::execute_coarsening_and_refinement();
12829 for (
unsigned int level = 0;
12830 level < cell_infos.size() && !cell_infos[level].empty();
12833 auto cell = this->
begin(level);
12834 auto cell_info = cell_infos[level].begin();
12835 for (; cell_info != cell_infos[level].end(); ++cell_info)
12838 while (cell_info->id != cell->
id().template to_binary<dim>())
12842 for (
auto pair : cell_info->boundary_ids)
12843 if (cell->
face(pair.first)->at_boundary())
12844 cell->
face(pair.first)->set_boundary_id(pair.second);
12853template <
int dim,
int spacedim>
12859 "This function can only be called if dim == spacedim-1."));
12860 for (
const auto &cell : this->active_cell_iterators())
12866template <
int dim,
int spacedim>
12871 ExcMessage(
"Error: An empty Triangulation can not be refined."));
12873 for (
const auto &cell : this->active_cell_iterators())
12883template <
int dim,
int spacedim>
12888 ExcMessage(
"Error: An empty Triangulation can not be refined."));
12890 for (
unsigned int i = 0; i < times; ++i)
12892 set_all_refine_flags();
12893 execute_coarsening_and_refinement();
12899template <
int dim,
int spacedim>
12903 for (
unsigned int i = 0; i < times; ++i)
12905 for (
const auto &cell : this->active_cell_iterators())
12910 execute_coarsening_and_refinement();
12920template <
int dim,
int spacedim>
12925 std::vector<bool>::iterator i = v.begin();
12927 for (
const auto &cell : this->active_cell_iterators())
12928 for (
unsigned int j = 0; j < dim; ++j, ++i)
12937template <
int dim,
int spacedim>
12941 std::vector<bool> v;
12942 save_refine_flags(v);
12951template <
int dim,
int spacedim>
12955 std::vector<bool> v;
12957 load_refine_flags(v);
12962template <
int dim,
int spacedim>
12968 std::vector<bool>::const_iterator i = v.begin();
12969 for (
const auto &cell : this->active_cell_iterators())
12971 unsigned int ref_case = 0;
12973 for (
unsigned int j = 0; j < dim; ++j, ++i)
12975 ref_case += 1 << j;
12977 ExcGridReadError());
12989template <
int dim,
int spacedim>
12992 std::vector<bool> &v)
const
12995 std::vector<bool>::iterator i = v.begin();
12996 for (
const auto &cell : this->active_cell_iterators())
13007template <
int dim,
int spacedim>
13011 std::vector<bool> v;
13012 save_coarsen_flags(v);
13021template <
int dim,
int spacedim>
13025 std::vector<bool> v;
13030 load_coarsen_flags(v);
13035template <
int dim,
int spacedim>
13038 const std::vector<bool> &v)
13042 std::vector<bool>::const_iterator i = v.begin();
13043 for (
const auto &cell : this->active_cell_iterators())
13056template <
int dim,
int spacedim>
13060 return anisotropic_refinement;
13070 std::vector<std::vector<bool>>
13071 extract_raw_coarsen_flags(
13072 const std::vector<std::unique_ptr<
13073 ::internal::TriangulationImplementation::TriaLevel>> &levels)
13075 std::vector<std::vector<bool>> coarsen_flags(levels.size());
13076 for (
unsigned int level = 0; level < levels.size(); ++level)
13077 coarsen_flags[level] = levels[level]->coarsen_flags;
13078 return coarsen_flags;
13081 std::vector<std::vector<std::uint8_t>>
13082 extract_raw_refine_flags(
13083 const std::vector<std::unique_ptr<
13084 ::internal::TriangulationImplementation::TriaLevel>> &levels)
13086 std::vector<std::vector<std::uint8_t>> refine_flags(levels.size());
13087 for (
unsigned int level = 0; level < levels.size(); ++level)
13088 refine_flags[level] = levels[level]->refine_flags;
13089 return refine_flags;
13102 clear_user_data(std::vector<std::unique_ptr<
13103 internal::TriangulationImplementation::TriaLevel>> &levels)
13105 for (
auto &level : levels)
13106 level->cells.clear_user_data();
13112 clear_user_data(internal::TriangulationImplementation::TriaFaces *faces)
13114 if (faces->
dim == 2)
13120 if (faces->
dim == 3)
13130template <
int dim,
int spacedim>
13135 ::clear_user_data(levels);
13137 ::clear_user_data(faces.get());
13145 clear_user_flags_line(
13148 std::unique_ptr<internal::TriangulationImplementation::TriaLevel>>
13150 internal::TriangulationImplementation::TriaFaces *faces)
13154 for (
const auto &level : levels)
13155 level->cells.clear_user_flags();
13157 else if (dim == 2 || dim == 3)
13169template <
int dim,
int spacedim>
13173 ::clear_user_flags_line(dim, levels, faces.get());
13181 clear_user_flags_quad(
13184 std::unique_ptr<internal::TriangulationImplementation::TriaLevel>>
13186 internal::TriangulationImplementation::TriaFaces *faces)
13194 for (
const auto &level : levels)
13195 level->cells.clear_user_flags();
13209template <
int dim,
int spacedim>
13213 ::clear_user_flags_quad(dim, levels, faces.get());
13221 clear_user_flags_hex(
13224 std::unique_ptr<internal::TriangulationImplementation::TriaLevel>>
13226 internal::TriangulationImplementation::TriaFaces *)
13238 for (
const auto &level : levels)
13239 level->cells.clear_user_flags();
13249template <
int dim,
int spacedim>
13253 ::clear_user_flags_hex(dim, levels, faces.get());
13258template <
int dim,
int spacedim>
13262 clear_user_flags_line();
13263 clear_user_flags_quad();
13264 clear_user_flags_hex();
13269template <
int dim,
int spacedim>
13273 save_user_flags_line(out);
13276 save_user_flags_quad(out);
13279 save_user_flags_hex(out);
13287template <
int dim,
int spacedim>
13295 std::vector<bool> tmp;
13297 save_user_flags_line(tmp);
13298 v.insert(v.end(), tmp.begin(), tmp.end());
13302 save_user_flags_quad(tmp);
13303 v.insert(v.end(), tmp.begin(), tmp.end());
13308 save_user_flags_hex(tmp);
13309 v.insert(v.end(), tmp.begin(), tmp.end());
13318template <
int dim,
int spacedim>
13322 load_user_flags_line(in);
13325 load_user_flags_quad(in);
13328 load_user_flags_hex(in);
13336template <
int dim,
int spacedim>
13341 std::vector<bool> tmp;
13345 tmp.insert(tmp.end(), v.begin(), v.begin() + n_lines());
13347 load_user_flags_line(tmp);
13352 tmp.insert(tmp.end(),
13353 v.begin() + n_lines(),
13354 v.begin() + n_lines() + n_quads());
13355 load_user_flags_quad(tmp);
13361 tmp.insert(tmp.end(),
13362 v.begin() + n_lines() + n_quads(),
13363 v.begin() + n_lines() + n_quads() + n_hexs());
13364 load_user_flags_hex(tmp);
13373template <
int dim,
int spacedim>
13376 std::vector<bool> &v)
const
13378 v.resize(n_lines(),
false);
13379 std::vector<bool>::iterator i = v.begin();
13380 line_iterator line = begin_line(), endl = end_line();
13381 for (; line != endl; ++line, ++i)
13382 *i = line->user_flag_set();
13389template <
int dim,
int spacedim>
13393 std::vector<bool> v;
13394 save_user_flags_line(v);
13403template <
int dim,
int spacedim>
13407 std::vector<bool> v;
13412 load_user_flags_line(v);
13417template <
int dim,
int spacedim>
13420 const std::vector<bool> &v)
13422 Assert(v.size() == n_lines(), ExcGridReadError());
13424 line_iterator line = begin_line(), endl = end_line();
13425 std::vector<bool>::const_iterator i = v.begin();
13426 for (; line != endl; ++line, ++i)
13428 line->set_user_flag();
13430 line->clear_user_flag();
13439 template <
typename Iterator>
13441 get_user_flag(
const Iterator &i)
13443 return i->user_flag_set();
13448 template <
int structdim,
int dim,
int spacedim>
13450 get_user_flag(
const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &)
13458 template <
typename Iterator>
13460 set_user_flag(
const Iterator &i)
13462 i->set_user_flag();
13467 template <
int structdim,
int dim,
int spacedim>
13469 set_user_flag(
const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &)
13476 template <
typename Iterator>
13478 clear_user_flag(
const Iterator &i)
13480 i->clear_user_flag();
13485 template <
int structdim,
int dim,
int spacedim>
13488 const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &)
13496template <
int dim,
int spacedim>
13499 std::vector<bool> &v)
const
13501 v.resize(n_quads(),
false);
13505 std::vector<bool>::iterator i = v.begin();
13506 quad_iterator quad = begin_quad(), endq = end_quad();
13507 for (; quad != endq; ++quad, ++i)
13508 *i = get_user_flag(quad);
13516template <
int dim,
int spacedim>
13520 std::vector<bool> v;
13521 save_user_flags_quad(v);
13530template <
int dim,
int spacedim>
13534 std::vector<bool> v;
13539 load_user_flags_quad(v);
13544template <
int dim,
int spacedim>
13547 const std::vector<bool> &v)
13549 Assert(v.size() == n_quads(), ExcGridReadError());
13553 quad_iterator quad = begin_quad(), endq = end_quad();
13554 std::vector<bool>::const_iterator i = v.begin();
13555 for (; quad != endq; ++quad, ++i)
13557 set_user_flag(quad);
13559 clear_user_flag(quad);
13567template <
int dim,
int spacedim>
13570 std::vector<bool> &v)
const
13572 v.resize(n_hexs(),
false);
13576 std::vector<bool>::iterator i = v.begin();
13577 hex_iterator hex = begin_hex(), endh = end_hex();
13578 for (; hex != endh; ++hex, ++i)
13579 *i = get_user_flag(hex);
13587template <
int dim,
int spacedim>
13591 std::vector<bool> v;
13592 save_user_flags_hex(v);
13601template <
int dim,
int spacedim>
13605 std::vector<bool> v;
13610 load_user_flags_hex(v);
13615template <
int dim,
int spacedim>
13618 const std::vector<bool> &v)
13620 Assert(v.size() == n_hexs(), ExcGridReadError());
13624 hex_iterator hex = begin_hex(), endh = end_hex();
13625 std::vector<bool>::const_iterator i = v.begin();
13626 for (; hex != endh; ++hex, ++i)
13628 set_user_flag(hex);
13630 clear_user_flag(hex);
13638template <
int dim,
int spacedim>
13641 std::vector<unsigned int> &v)
const
13647 std::vector<unsigned int> tmp;
13649 save_user_indices_line(tmp);
13650 v.insert(v.end(), tmp.begin(), tmp.end());
13654 save_user_indices_quad(tmp);
13655 v.insert(v.end(), tmp.begin(), tmp.end());
13660 save_user_indices_hex(tmp);
13661 v.insert(v.end(), tmp.begin(), tmp.end());
13670template <
int dim,
int spacedim>
13673 const std::vector<unsigned int> &v)
13676 std::vector<unsigned int> tmp;
13680 tmp.insert(tmp.end(), v.begin(), v.begin() + n_lines());
13682 load_user_indices_line(tmp);
13687 tmp.insert(tmp.end(),
13688 v.begin() + n_lines(),
13689 v.begin() + n_lines() + n_quads());
13690 load_user_indices_quad(tmp);
13696 tmp.insert(tmp.end(),
13697 v.begin() + n_lines() + n_quads(),
13698 v.begin() + n_lines() + n_quads() + n_hexs());
13699 load_user_indices_hex(tmp);
13708template <
int dim,
int spacedim>
13714 std::ofstream ofs_tria(file_basename +
"_triangulation.data");
13717 boost::archive::text_oarchive oa(ofs_tria, boost::archive::no_header);
13719 internal::CellAttachedDataSerializer<dim, spacedim>::version_number);
13724 std::ofstream ofs_info(file_basename +
".info");
13726 <<
"version nproc n_attached_fixed_size_objs n_attached_variable_size_objs n_active_cells"
13728 << internal::CellAttachedDataSerializer<dim, spacedim>::version_number
13729 <<
" " << 1 <<
" " << this->cell_attached_data.pack_callbacks_fixed.size()
13730 <<
" " << this->cell_attached_data.pack_callbacks_variable.size() <<
" "
13731 << this->n_global_active_cells() << std::endl;
13734 this->save_attached_data(0, this->n_global_active_cells(), file_basename);
13739template <
int dim,
int spacedim>
13750 std::ifstream ifs_tria(file_basename +
"_triangulation.data");
13753 boost::archive::text_iarchive ia(ifs_tria, boost::archive::no_header);
13755 internal::CellAttachedDataSerializer<dim, spacedim>::version_number);
13759 unsigned int version, numcpus, attached_count_fixed, attached_count_variable,
13760 n_global_active_cells;
13762 std::ifstream ifs_info(std::string(file_basename) +
".info");
13764 std::string firstline;
13765 std::getline(ifs_info, firstline);
13766 ifs_info >> version >> numcpus >> attached_count_fixed >>
13767 attached_count_variable >> n_global_active_cells;
13771 ExcMessage(
"Incompatible number of CPUs found in .info file."));
13773 const auto expected_version =
13774 ::internal::CellAttachedDataSerializer<dim,
13775 spacedim>::version_number;
13778 "The information saved in the file you are trying "
13779 "to read the triangulation from was written with an "
13780 "incompatible file format version and cannot be read."));
13781 Assert(this->n_global_active_cells() == n_global_active_cells,
13782 ExcMessage(
"The number of cells of the triangulation differs "
13783 "from the number of cells written into the .info file."));
13787 this->cell_attached_data.n_attached_data_sets = 0;
13788 this->cell_attached_data.n_attached_deserialize =
13789 attached_count_fixed + attached_count_variable;
13791 this->load_attached_data(0,
13792 this->n_global_active_cells(),
13795 attached_count_fixed,
13796 attached_count_variable);
13798 this->update_cell_relations();
13804 template <
typename Iterator>
13806 get_user_index(
const Iterator &i)
13808 return i->user_index();
13813 template <
int structdim,
int dim,
int spacedim>
13816 const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &)
13824 template <
typename Iterator>
13826 set_user_index(
const Iterator &i,
const unsigned int x)
13828 i->set_user_index(x);
13833 template <
int structdim,
int dim,
int spacedim>
13836 const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &,
13837 const unsigned int)
13845template <
int dim,
int spacedim>
13848 std::vector<unsigned int> &v)
const
13850 v.resize(n_lines(), 0);
13851 std::vector<unsigned int>::iterator i = v.begin();
13852 line_iterator line = begin_line(), endl = end_line();
13853 for (; line != endl; ++line, ++i)
13854 *i = line->user_index();
13859template <
int dim,
int spacedim>
13862 const std::vector<unsigned int> &v)
13864 Assert(v.size() == n_lines(), ExcGridReadError());
13866 line_iterator line = begin_line(), endl = end_line();
13867 std::vector<unsigned int>::const_iterator i = v.begin();
13868 for (; line != endl; ++line, ++i)
13869 line->set_user_index(*i);
13873template <
int dim,
int spacedim>
13876 std::vector<unsigned int> &v)
const
13878 v.resize(n_quads(), 0);
13882 std::vector<unsigned int>::iterator i = v.begin();
13883 quad_iterator quad = begin_quad(), endq = end_quad();
13884 for (; quad != endq; ++quad, ++i)
13885 *i = get_user_index(quad);
13891template <
int dim,
int spacedim>
13894 const std::vector<unsigned int> &v)
13896 Assert(v.size() == n_quads(), ExcGridReadError());
13900 quad_iterator quad = begin_quad(), endq = end_quad();
13901 std::vector<unsigned int>::const_iterator i = v.begin();
13902 for (; quad != endq; ++quad, ++i)
13903 set_user_index(quad, *i);
13908template <
int dim,
int spacedim>
13911 std::vector<unsigned int> &v)
const
13913 v.resize(n_hexs(), 0);
13917 std::vector<unsigned int>::iterator i = v.begin();
13918 hex_iterator hex = begin_hex(), endh = end_hex();
13919 for (; hex != endh; ++hex, ++i)
13920 *i = get_user_index(hex);
13926template <
int dim,
int spacedim>
13929 const std::vector<unsigned int> &v)
13931 Assert(v.size() == n_hexs(), ExcGridReadError());
13935 hex_iterator hex = begin_hex(), endh = end_hex();
13936 std::vector<unsigned int>::const_iterator i = v.begin();
13937 for (; hex != endh; ++hex, ++i)
13938 set_user_index(hex, *i);
13950 template <
typename Iterator>
13952 get_user_pointer(
const Iterator &i)
13954 return i->user_pointer();
13959 template <
int structdim,
int dim,
int spacedim>
13962 const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &)
13970 template <
typename Iterator>
13972 set_user_pointer(
const Iterator &i,
void *x)
13974 i->set_user_pointer(x);
13979 template <
int structdim,
int dim,
int spacedim>
13982 const TriaIterator<InvalidAccessor<structdim, dim, spacedim>> &,
13991template <
int dim,
int spacedim>
13994 std::vector<void *> &v)
const
14000 std::vector<void *> tmp;
14002 save_user_pointers_line(tmp);
14003 v.insert(v.end(), tmp.begin(), tmp.end());
14007 save_user_pointers_quad(tmp);
14008 v.insert(v.end(), tmp.begin(), tmp.end());
14013 save_user_pointers_hex(tmp);
14014 v.insert(v.end(), tmp.begin(), tmp.end());
14023template <
int dim,
int spacedim>
14026 const std::vector<void *> &v)
14029 std::vector<void *> tmp;
14033 tmp.insert(tmp.end(), v.begin(), v.begin() + n_lines());
14035 load_user_pointers_line(tmp);
14040 tmp.insert(tmp.end(),
14041 v.begin() + n_lines(),
14042 v.begin() + n_lines() + n_quads());
14043 load_user_pointers_quad(tmp);
14049 tmp.insert(tmp.end(),
14050 v.begin() + n_lines() + n_quads(),
14051 v.begin() + n_lines() + n_quads() + n_hexs());
14052 load_user_pointers_hex(tmp);
14061template <
int dim,
int spacedim>
14064 std::vector<void *> &v)
const
14066 v.resize(n_lines(),
nullptr);
14067 std::vector<void *>::iterator i = v.begin();
14068 line_iterator line = begin_line(), endl = end_line();
14069 for (; line != endl; ++line, ++i)
14070 *i = line->user_pointer();
14075template <
int dim,
int spacedim>
14078 const std::vector<void *> &v)
14080 Assert(v.size() == n_lines(), ExcGridReadError());
14082 line_iterator line = begin_line(), endl = end_line();
14083 std::vector<void *>::const_iterator i = v.begin();
14084 for (; line != endl; ++line, ++i)
14085 line->set_user_pointer(*i);
14090template <
int dim,
int spacedim>
14093 std::vector<void *> &v)
const
14095 v.resize(n_quads(),
nullptr);
14099 std::vector<void *>::iterator i = v.begin();
14100 quad_iterator quad = begin_quad(), endq = end_quad();
14101 for (; quad != endq; ++quad, ++i)
14102 *i = get_user_pointer(quad);
14108template <
int dim,
int spacedim>
14111 const std::vector<void *> &v)
14113 Assert(v.size() == n_quads(), ExcGridReadError());
14117 quad_iterator quad = begin_quad(), endq = end_quad();
14118 std::vector<void *>::const_iterator i = v.begin();
14119 for (; quad != endq; ++quad, ++i)
14120 set_user_pointer(quad, *i);
14125template <
int dim,
int spacedim>
14128 std::vector<void *> &v)
const
14130 v.resize(n_hexs(),
nullptr);
14134 std::vector<void *>::iterator i = v.begin();
14135 hex_iterator hex = begin_hex(), endh = end_hex();
14136 for (; hex != endh; ++hex, ++i)
14137 *i = get_user_pointer(hex);
14143template <
int dim,
int spacedim>
14146 const std::vector<void *> &v)
14148 Assert(v.size() == n_hexs(), ExcGridReadError());
14152 hex_iterator hex = begin_hex(), endh = end_hex();
14153 std::vector<void *>::const_iterator i = v.begin();
14154 for (; hex != endh; ++hex, ++i)
14155 set_user_pointer(hex, *i);
14165template <
int dim,
int spacedim>
14173 return begin_raw_line(level);
14175 return begin_raw_quad(level);
14177 return begin_raw_hex(level);
14180 return raw_cell_iterator();
14186template <
int dim,
int spacedim>
14194 return begin_line(level);
14196 return begin_quad(level);
14198 return begin_hex(level);
14201 return cell_iterator();
14207template <
int dim,
int spacedim>
14215 return begin_active_line(level);
14217 return begin_active_quad(level);
14219 return begin_active_hex(level);
14222 return active_cell_iterator();
14228template <
int dim,
int spacedim>
14233 const unsigned int level = levels.size() - 1;
14234 if (levels[level]->cells.n_objects() == 0)
14239 raw_cell_iterator ri(
const_cast<Triangulation<dim, spacedim> *
>(
this),
14241 levels[level]->cells.n_objects() - 1);
14244 if (ri->used() ==
true)
14247 if (ri->used() ==
true)
14254template <
int dim,
int spacedim>
14260 cell_iterator cell = last();
14265 if (cell->is_active() ==
true)
14268 if (cell->is_active() ==
true)
14276template <
int dim,
int spacedim>
14280 const CellId &cell_id)
const
14283 this->contains_cell(cell_id),
14285 "CellId is invalid for this triangulation.\n"
14286 "Either the provided CellId does not correspond to a cell in this "
14287 "triangulation object, or, in case you are using a parallel "
14288 "triangulation, may correspond to an artificial cell that is less "
14289 "refined on this processor. In the case of "
14290 "parallel::fullydistributed::Triangulation, the corresponding coarse "
14291 "cell might not be accessible by the current process."));
14293 cell_iterator cell(
14297 cell = cell->child(
static_cast<unsigned int>(child_index));
14304template <
int dim,
int spacedim>
14308 const auto coarse_cell_index =
14314 cell_iterator cell(
this, 0, coarse_cell_index);
14318 if (cell->has_children() ==
false)
14320 cell = cell->child(
static_cast<unsigned int>(child_index));
14328template <
int dim,
int spacedim>
14333 return cell_iterator(
const_cast<Triangulation<dim, spacedim> *
>(
this),
14340template <
int dim,
int spacedim>
14353 if (level >= levels.size())
14355 Assert(level < n_global_levels(),
14356 ExcInvalidLevel(level, n_global_levels()));
14362 Assert(level < levels.size(), ExcInvalidLevel(level, levels.size()));
14363 if (level < levels.size() - 1)
14364 return begin_raw(level + 1);
14370template <
int dim,
int spacedim>
14383 if (level >= levels.size())
14385 Assert(level < n_global_levels(),
14386 ExcInvalidLevel(level, n_global_levels()));
14392 Assert(level < levels.size(), ExcInvalidLevel(level, levels.size()));
14393 if (level < levels.size() - 1)
14394 return begin(level + 1);
14400template <
int dim,
int spacedim>
14413 if (level >= levels.size())
14415 Assert(level < n_global_levels(),
14416 ExcInvalidLevel(level, n_global_levels()));
14422 Assert(level < levels.size(), ExcInvalidLevel(level, levels.size()));
14423 return (level >= levels.size() - 1 ? active_cell_iterator(
end()) :
14424 begin_active(level + 1));
14429template <
int dim,
int spacedim>
14431IteratorRange<typename Triangulation<dim, spacedim>::
14435 return IteratorRange<typename Triangulation<dim, spacedim>::cell_iterator>(
14440template <
int dim,
int spacedim>
14442IteratorRange<typename Triangulation<dim, spacedim>::
14446 return IteratorRange<
14453template <
int dim,
int spacedim>
14455IteratorRange<typename Triangulation<dim, spacedim>::
14459 return IteratorRange<typename Triangulation<dim, spacedim>::cell_iterator>(
14465template <
int dim,
int spacedim>
14467IteratorRange<typename Triangulation<dim, spacedim>::
14471 return IteratorRange<
14473 begin_active(level), end_active(level));
14481template <
int dim,
int spacedim>
14490 return raw_face_iterator();
14492 return begin_line();
14494 return begin_quad();
14497 return face_iterator();
14503template <
int dim,
int spacedim>
14512 return raw_face_iterator();
14514 return begin_active_line();
14516 return begin_active_quad();
14519 return active_face_iterator();
14525template <
int dim,
int spacedim>
14534 return raw_face_iterator();
14541 return raw_face_iterator();
14547template <
int dim,
int spacedim>
14549IteratorRange<typename Triangulation<dim, spacedim>::
14553 return IteratorRange<
14555 begin_active_face(), end_face());
14561template <
int dim,
int spacedim>
14566 vertex_iterator i =
14567 raw_vertex_iterator(
const_cast<Triangulation<dim, spacedim> *
>(
this), 0, 0);
14571 while (i->used() ==
false)
14579template <
int dim,
int spacedim>
14585 return begin_vertex();
14590template <
int dim,
int spacedim>
14595 return raw_vertex_iterator(
const_cast<Triangulation<dim, spacedim> *
>(
this),
14607template <
int dim,
int spacedim>
14620 if (level >= levels.size())
14622 Assert(level < n_global_levels(),
14623 ExcInvalidLevel(level, n_global_levels()));
14632 Assert(level < levels.size(), ExcInvalidLevel(level, levels.size()));
14634 if (level >= levels.size() || levels[level]->cells.n_objects() == 0)
14637 return raw_line_iterator(
14638 const_cast<Triangulation<dim, spacedim> *
>(
this), level, 0);
14641 Assert(level == 0, ExcFacesHaveNoLevel());
14642 return raw_line_iterator(
14643 const_cast<Triangulation<dim, spacedim> *
>(
this), 0, 0);
14648template <
int dim,
int spacedim>
14654 raw_line_iterator ri = begin_raw_line(level);
14657 while (ri->used() ==
false)
14665template <
int dim,
int spacedim>
14669 const unsigned int level)
const
14672 line_iterator i = begin_line(level);
14675 while (i->has_children())
14683template <
int dim,
int spacedim>
14688 return raw_line_iterator(
const_cast<Triangulation<dim, spacedim> *
>(
this),
14699template <
int dim,
int spacedim>
14712 if (level >= levels.size())
14714 Assert(level < n_global_levels(),
14715 ExcInvalidLevel(level, n_global_levels()));
14723 return raw_hex_iterator();
14728 Assert(level < levels.size(), ExcInvalidLevel(level, levels.size()));
14730 if (level >= levels.size() || levels[level]->cells.n_objects() == 0)
14733 return raw_quad_iterator(
14734 const_cast<Triangulation<dim, spacedim> *
>(
this), level, 0);
14739 Assert(level == 0, ExcFacesHaveNoLevel());
14741 return raw_quad_iterator(
14742 const_cast<Triangulation<dim, spacedim> *
>(
this), 0, 0);
14748 return raw_hex_iterator();
14754template <
int dim,
int spacedim>
14760 raw_quad_iterator ri = begin_raw_quad(level);
14763 while (ri->used() ==
false)
14771template <
int dim,
int spacedim>
14775 const unsigned int level)
const
14778 quad_iterator i = begin_quad(level);
14781 while (i->has_children())
14789template <
int dim,
int spacedim>
14794 return raw_quad_iterator(
const_cast<Triangulation<dim, spacedim> *
>(
this),
14805template <
int dim,
int spacedim>
14818 if (level >= levels.size())
14820 Assert(level < n_global_levels(),
14821 ExcInvalidLevel(level, n_global_levels()));
14830 return raw_hex_iterator();
14835 Assert(level < levels.size(), ExcInvalidLevel(level, levels.size()));
14837 if (level >= levels.size() || levels[level]->cells.n_objects() == 0)
14840 return raw_hex_iterator(
14841 const_cast<Triangulation<dim, spacedim> *
>(
this), level, 0);
14846 return raw_hex_iterator();
14852template <
int dim,
int spacedim>
14858 raw_hex_iterator ri = begin_raw_hex(level);
14861 while (ri->used() ==
false)
14869template <
int dim,
int spacedim>
14875 hex_iterator i = begin_hex(level);
14878 while (i->has_children())
14886template <
int dim,
int spacedim>
14891 return raw_hex_iterator(
const_cast<Triangulation<dim, spacedim> *
>(
this),
14905 inline unsigned int
14912 inline unsigned int
14916 return c.n_active_lines;
14920 inline unsigned int
14927 inline unsigned int
14931 return c.n_active_quads;
14935 inline unsigned int
14942 inline unsigned int
14946 return c.n_active_hexes;
14953template <
int dim,
int spacedim>
14961template <
int dim,
int spacedim>
14968template <
int dim,
int spacedim>
14976template <
int dim,
int spacedim>
14984template <
int dim,
int spacedim>
14991 return n_used_vertices();
15003template <
int dim,
int spacedim>
15010 return n_vertices();
15012 return n_raw_lines();
15014 return n_raw_quads();
15022template <
int dim,
int spacedim>
15029 return n_used_vertices();
15031 return n_active_lines();
15033 return n_active_quads();
15041template <
int dim,
int spacedim>
15044 const unsigned int level)
const
15049 return n_raw_lines(level);
15051 return n_raw_quads(level);
15053 return n_raw_hexs(level);
15062template <
int dim,
int spacedim>
15065 const unsigned int level)
const
15070 return n_lines(level);
15072 return n_quads(level);
15074 return n_hexs(level);
15083template <
int dim,
int spacedim>
15086 const unsigned int level)
const
15091 return n_active_lines(level);
15093 return n_active_quads(level);
15095 return n_active_hexs(level);
15103template <
int dim,
int spacedim>
15107 if (anisotropic_refinement ==
false)
15109 for (
unsigned int lvl = 0; lvl < n_global_levels() - 1; ++lvl)
15115 for (
const auto &cell : active_cell_iterators())
15116 for (
const auto &i : cell->face_indices())
15117 if (cell->face(i)->has_children())
15124template <
int dim,
int spacedim>
15128 return number_cache.n_lines;
15133template <
int dim,
int spacedim>
15136 const unsigned int level)
const
15141 return levels[level]->cells.n_objects();
15144 Assert(
false, ExcFacesHaveNoLevel());
15149template <
int dim,
int spacedim>
15163template <
int dim,
int spacedim>
15166 const unsigned int level)
const
15169 Assert(dim == 1, ExcFacesHaveNoLevel());
15170 return number_cache.n_lines_level[level];
15174template <
int dim,
int spacedim>
15178 return number_cache.n_active_lines;
15182template <
int dim,
int spacedim>
15185 const unsigned int level)
const
15188 Assert(dim == 1, ExcFacesHaveNoLevel());
15190 return number_cache.n_active_lines_level[level];
15340template <
int dim,
int spacedim>
15344 return number_cache.n_quads;
15348template <
int dim,
int spacedim>
15351 const unsigned int level)
const
15353 Assert(dim == 2, ExcFacesHaveNoLevel());
15355 return number_cache.n_quads_level[level];
15365 return levels[level]->cells.n_objects();
15375 return levels[level]->cells.n_objects();
15389template <
int dim,
int spacedim>
15403 return faces->quads.n_objects();
15408template <
int dim,
int spacedim>
15412 return number_cache.n_active_quads;
15416template <
int dim,
int spacedim>
15419 const unsigned int level)
const
15422 Assert(dim == 2, ExcFacesHaveNoLevel());
15424 return number_cache.n_active_quads_level[level];
15428template <
int dim,
int spacedim>
15437template <
int dim,
int spacedim>
15446template <
int dim,
int spacedim>
15454template <
int dim,
int spacedim>
15463template <
int dim,
int spacedim>
15466 const unsigned int)
const
15498 return levels[level]->cells.n_objects();
15522template <
int dim,
int spacedim>
15526 return std::count(vertices_used.begin(), vertices_used.end(),
true);
15531template <
int dim,
int spacedim>
15535 return vertices_used;
15566template <
int dim,
int spacedim>
15570 cell_iterator cell = begin(0),
15571 endc = (n_levels() > 1 ? begin(1) : cell_iterator(end()));
15574 unsigned int max_vertex_index = 0;
15575 for (; cell != endc; ++cell)
15577 if (cell->vertex_index(vertex) > max_vertex_index)
15578 max_vertex_index = cell->vertex_index(vertex);
15584 std::vector<unsigned short int> usage_count(max_vertex_index + 1, 0);
15588 for (cell = begin(); cell != endc; ++cell)
15590 ++usage_count[cell->vertex_index(vertex)];
15593 static_cast<unsigned int>(
15594 *std::max_element(usage_count.begin(), usage_count.end())));
15599template <
int dim,
int spacedim>
15609template <
int dim,
int spacedim>
15618template <
int dim,
int spacedim>
15620const Triangulation<dim, spacedim>
15628template <
int dim,
int spacedim>
15631 const std::vector<GridTools::PeriodicFacePair<cell_iterator>>
15632 &periodicity_vector)
15634 periodic_face_pairs_level_0.insert(periodic_face_pairs_level_0.end(),
15635 periodicity_vector.begin(),
15636 periodicity_vector.end());
15639 update_periodic_face_map();
15644template <
int dim,
int spacedim>
15646const typename std::map<
15647 std::pair<typename Triangulation<dim, spacedim>::cell_iterator,
unsigned int>,
15648 std::pair<std::pair<typename Triangulation<dim, spacedim>::cell_iterator,
15653 return periodic_face_map;
15657template <
int dim,
int spacedim>
15664 if (
dynamic_cast<parallel::DistributedTriangulationBase<dim, spacedim> *
>(
15668 this->local_cell_relations.clear();
15671 for (
const auto &cell : this->active_cell_iterators())
15672 this->local_cell_relations.emplace_back(
15678template <
int dim,
int spacedim>
15682 if (
dynamic_cast<parallel::DistributedTriangulationBase<dim, spacedim> *
>(
15686 std::vector<CellId> active_cell_old;
15689 if (this->cell_attached_data.n_attached_data_sets > 0)
15695 for (
const auto &cell : this->active_cell_iterators())
15698 (cell->level() > 0) && (cell->coarsen_flag_set());
15701 active_cell_old.emplace_back(cell->id());
15704 if (cell->parent()->child(0) == cell)
15705 active_cell_old.emplace_back(cell->parent()->id());
15710 this->local_cell_relations.clear();
15711 this->local_cell_relations.reserve(this->n_global_active_cells());
15714 std::pair<
unsigned int,
15715 typename internal::CellAttachedDataSerializer<dim, spacedim>::
15717 local_cell_relations_tmp;
15719 for (
const auto &cell : this->active_cell_iterators())
15721 if (std::find(active_cell_old.begin(),
15722 active_cell_old.end(),
15723 cell->id()) != active_cell_old.end())
15725 const unsigned int index =
15726 std::distance(active_cell_old.begin(),
15727 std::find(active_cell_old.begin(),
15728 active_cell_old.end(),
15732 cell->refine_flag_set() ?
15736 local_cell_relations_tmp.emplace_back(
15738 typename internal::CellAttachedDataSerializer<dim, spacedim>::
15739 cell_relation_t{cell, status});
15741 else if (cell->level() > 0 &&
15742 std::find(active_cell_old.begin(),
15743 active_cell_old.end(),
15744 cell->parent()->id()) != active_cell_old.end())
15746 const unsigned int index =
15747 std::distance(active_cell_old.begin(),
15748 std::find(active_cell_old.begin(),
15749 active_cell_old.end(),
15750 cell->parent()->id()));
15754 if (cell->parent()->child_iterator_to_index(cell) == 0)
15759 local_cell_relations_tmp.emplace_back(
15761 typename internal::CellAttachedDataSerializer<dim, spacedim>::
15762 cell_relation_t{cell->parent(), status});
15770 std::stable_sort(local_cell_relations_tmp.begin(),
15771 local_cell_relations_tmp.end(),
15772 [](
const auto &a,
const auto &b) {
15773 return a.first < b.first;
15776 for (
const auto &tmp : local_cell_relations_tmp)
15777 this->local_cell_relations.emplace_back(tmp.second);
15780 this->data_serializer.pack_data(
15781 this->local_cell_relations,
15782 this->cell_attached_data.pack_callbacks_fixed,
15783 this->cell_attached_data.pack_callbacks_variable,
15784 this->get_mpi_communicator());
15787 this->data_serializer.dest_data_fixed =
15788 this->data_serializer.src_data_fixed;
15789 this->data_serializer.dest_data_variable =
15790 this->data_serializer.src_data_variable;
15791 this->data_serializer.dest_sizes_variable =
15792 this->data_serializer.src_sizes_variable;
15798template <
int dim,
int spacedim>
15802 if (
dynamic_cast<parallel::DistributedTriangulationBase<dim, spacedim> *
>(
15807 if (this->cell_attached_data.n_attached_data_sets > 0)
15809 std::vector<typename internal::CellAttachedDataSerializer<dim, spacedim>::
15813 for (
const auto &cell : local_cell_relations)
15815 if (cell.first->has_children())
15820 temp.emplace_back(cell.first->child(0),
15824 temp.push_back(cell);
15827 this->local_cell_relations = temp;
15833template <
int dim,
int spacedim>
15847 if (smooth_grid & limit_level_difference_at_vertices)
15851 signals.pre_refinement();
15853 this->pack_data_serial();
15855 execute_coarsening();
15857 const DistortedCellList cells_with_distorted_children = execute_refinement();
15862 this->unpack_data_serial();
15864 reset_cell_vertex_indices_cache();
15869 if (smooth_grid & limit_level_difference_at_vertices)
15874 this->policy->update_neighbors(*
this);
15875 reset_active_cell_indices();
15877 reset_global_cell_indices();
15880 signals.post_refinement();
15882 AssertThrow(cells_with_distorted_children.distorted_cells.empty(),
15883 cells_with_distorted_children);
15885 update_periodic_face_map();
15887 if (this->cell_attached_data.n_attached_data_sets == 0)
15888 this->update_cell_relations();
15914 for (
const auto &cell : cell_iterators())
15916 if (cell->has_children() && cell->reference_cell().is_hyper_cube())
15917 for (
const unsigned int f : cell->face_indices())
15918 if (cell->at_boundary(f) ==
false)
15920 for (
const auto &child : cell->child_iterators())
15923 child->at_boundary(f) ==
false,
15925 "We ended up with a triangulation whose child cells "
15926 "are not connected to their neighbors as expected. "
15927 "When you created the triangulation, did you forget "
15928 "to call GridTools::consistently_order_cells() "
15929 "before calling Triangulation::create_triangulation()?"));
15938template <
int dim,
int spacedim>
15942 unsigned int active_cell_index = 0;
15943 for (raw_cell_iterator cell = begin_raw(); cell !=
end(); ++cell)
15944 if ((cell->used() ==
false) || cell->has_children())
15948 cell->set_active_cell_index(active_cell_index);
15949 ++active_cell_index;
15957template <
int dim,
int spacedim>
15963 for (
const auto &cell : active_cell_iterators())
15964 cell->set_global_active_cell_index(cell_index++);
15967 for (
unsigned int l = 0;
l < levels.size(); ++
l)
15970 for (
const auto &cell : cell_iterators_on_level(l))
15971 cell->set_global_level_cell_index(cell_index++);
15977template <
int dim,
int spacedim>
15981 for (
unsigned int l = 0;
l < levels.size(); ++
l)
15983 std::vector<unsigned int> &cache = levels[
l]->cell_vertex_indices_cache;
15985 cache.resize(levels[l]->refine_flags.size() *
15988 for (
const auto &cell : cell_iterators_on_level(l))
15990 const unsigned int my_index =
15996 const ReferenceCell ref_cell = cell->reference_cell();
15998 for (
unsigned int face = 4; face < 6; ++face)
16000 const auto face_iter = cell->face(face);
16001 const std::array<types::geometric_orientation, 2>
16002 line_orientations{{face_iter->line_orientation(0),
16003 face_iter->line_orientation(1)}};
16004 const std::array<unsigned int, 2> line_vertex_indices{
16005 {line_orientations[0] ==
16007 line_orientations[1] ==
16009 const std::array<unsigned int, 4> raw_vertex_indices{
16010 {face_iter->line(0)->vertex_index(1 - line_vertex_indices[0]),
16011 face_iter->line(1)->vertex_index(1 - line_vertex_indices[1]),
16012 face_iter->line(0)->vertex_index(line_vertex_indices[0]),
16013 face_iter->line(1)->vertex_index(line_vertex_indices[1])}};
16015 const auto combined_orientation =
16016 levels[
l]->face_orientations.get_combined_orientation(
16018 const std::array<unsigned int, 4> vertex_order{
16021 combined_orientation),
16024 combined_orientation),
16027 combined_orientation),
16029 3, face, combined_orientation)}};
16031 const unsigned int index = my_index + 4 * (face - 4);
16032 for (
unsigned int i = 0; i < 4; ++i)
16033 cache[
index + i] = raw_vertex_indices[vertex_order[i]];
16037 const std::array<types::geometric_orientation, 2>
16039 {cell->line_orientation(0), cell->line_orientation(1)}};
16040 const std::array<unsigned int, 2> line_vertex_indices{
16042 line_orientations[1] ==
16044 const std::array<unsigned int, 4> raw_vertex_indices{
16045 {cell->line(0)->vertex_index(1 - line_vertex_indices[0]),
16046 cell->line(1)->vertex_index(1 - line_vertex_indices[1]),
16047 cell->line(0)->vertex_index(line_vertex_indices[0]),
16048 cell->line(1)->vertex_index(line_vertex_indices[1])}};
16049 for (
unsigned int i = 0; i < 4; ++i)
16050 cache[my_index + i] = raw_vertex_indices[i];
16054 cache[my_index + 0] = cell->vertex_index(0);
16055 cache[my_index + 1] = cell->vertex_index(1);
16060 for (
const unsigned int i : cell->vertex_indices())
16062 const auto [face_index, vertex_index] =
16064 const auto vertex_within_face_index =
16068 cell->combined_face_orientation(face_index));
16069 cache[my_index + i] =
16070 cell->face(face_index)
16071 ->vertex_index(vertex_within_face_index);
16080template <
int dim,
int spacedim>
16085 periodic_face_map.clear();
16087 typename std::vector<
16088 GridTools::PeriodicFacePair<cell_iterator>>::const_iterator it;
16089 for (it = periodic_face_pairs_level_0.begin();
16090 it != periodic_face_pairs_level_0.end();
16093 update_periodic_face_map_recursively<dim, spacedim>(it->cell[0],
16098 periodic_face_map);
16100 const auto face_reference_cell =
16101 it->cell[0]->reference_cell().face_reference_cell(it->face_idx[0]);
16103 update_periodic_face_map_recursively<dim, spacedim>(
16108 face_reference_cell.get_inverse_combined_orientation(it->orientation),
16109 periodic_face_map);
16113 typename std::map<std::pair<cell_iterator, unsigned int>,
16114 std::pair<std::pair<cell_iterator, unsigned int>,
16117 for (it_test = periodic_face_map.begin(); it_test != periodic_face_map.end();
16121 it_test->first.first;
16123 it_test->second.first.first;
16128 Assert(periodic_face_map[it_test->second.first].first ==
16137template <
int dim,
int spacedim>
16141 std::set<ReferenceCell> reference_cells_set;
16142 for (
auto cell : active_cell_iterators())
16143 if (cell->is_locally_owned())
16144 reference_cells_set.insert(cell->reference_cell());
16146 this->reference_cells =
16147 std::vector<ReferenceCell>(reference_cells_set.begin(),
16148 reference_cells_set.end());
16153template <
int dim,
int spacedim>
16155const std::vector<ReferenceCell>
16158 return this->reference_cells;
16163template <
int dim,
int spacedim>
16167 Assert(this->reference_cells.size() > 0,
16168 ExcMessage(
"You can't ask about the kinds of reference "
16169 "cells used by this triangulation if the "
16170 "triangulation doesn't yet have any cells in it."));
16171 return (this->reference_cells.size() == 1 &&
16172 this->reference_cells[0].is_hyper_cube());
16177template <
int dim,
int spacedim>
16181 Assert(this->reference_cells.size() > 0,
16182 ExcMessage(
"You can't ask about the kinds of reference "
16183 "cells used by this triangulation if the "
16184 "triangulation doesn't yet have any cells in it."));
16185 return (this->reference_cells.size() == 1 &&
16186 this->reference_cells[0].is_simplex());
16191template <
int dim,
int spacedim>
16195 Assert(this->reference_cells.size() > 0,
16196 ExcMessage(
"You can't ask about the kinds of reference "
16197 "cells used by this triangulation if the "
16198 "triangulation doesn't yet have any cells in it."));
16199 return reference_cells.size() > 1 ||
16200 ((reference_cells[0].is_hyper_cube() ==
false) &&
16201 (reference_cells[0].is_simplex() ==
false));
16206template <
int dim,
int spacedim>
16209 const std::function<std::vector<char>(
const cell_iterator &,
16210 const ::CellStatus)>
16212 const bool returns_variable_size_data)
16218 if (returns_variable_size_data)
16220 handle = 2 * this->cell_attached_data.pack_callbacks_variable.size();
16221 this->cell_attached_data.pack_callbacks_variable.push_back(pack_callback);
16225 handle = 2 * this->cell_attached_data.pack_callbacks_fixed.size() + 1;
16226 this->cell_attached_data.pack_callbacks_fixed.push_back(pack_callback);
16230 ++this->cell_attached_data.n_attached_data_sets;
16237template <
int dim,
int spacedim>
16240 const unsigned int handle,
16241 const std::function<
16242 void(
const cell_iterator &,
16243 const ::CellStatus,
16244 const boost::iterator_range<std::vector<char>::const_iterator> &)>
16248 this->data_serializer.unpack_data(this->local_cell_relations,
16253 --this->cell_attached_data.n_attached_data_sets;
16254 if (this->cell_attached_data.n_attached_deserialize > 0)
16255 --this->cell_attached_data.n_attached_deserialize;
16264 if (this->cell_attached_data.n_attached_data_sets == 0 &&
16265 this->cell_attached_data.n_attached_deserialize == 0)
16268 this->cell_attached_data.pack_callbacks_fixed.clear();
16269 this->cell_attached_data.pack_callbacks_variable.clear();
16270 this->data_serializer.clear();
16273 for (
auto &cell_rel : this->local_cell_relations)
16280template <
int dim,
int spacedim>
16283 const unsigned int global_first_cell,
16284 const unsigned int global_num_cells,
16285 const std::string &file_basename)
const
16288 auto tria =
const_cast<Triangulation<dim, spacedim> *
>(
this);
16291 for (
const auto &cell_rel : this->local_cell_relations)
16294 Assert((cell_rel.second ==
16299 if (this->cell_attached_data.n_attached_data_sets > 0)
16302 tria->data_serializer.pack_data(
16303 tria->local_cell_relations,
16304 tria->cell_attached_data.pack_callbacks_fixed,
16305 tria->cell_attached_data.pack_callbacks_variable,
16306 this->get_mpi_communicator());
16309 tria->data_serializer.save(global_first_cell,
16312 this->get_mpi_communicator());
16315 tria->data_serializer.clear();
16321 tria->cell_attached_data.n_attached_data_sets = 0;
16322 tria->cell_attached_data.pack_callbacks_fixed.clear();
16323 tria->cell_attached_data.pack_callbacks_variable.clear();
16328template <
int dim,
int spacedim>
16331 const unsigned int global_first_cell,
16332 const unsigned int global_num_cells,
16333 const unsigned int local_num_cells,
16334 const std::string &file_basename,
16335 const unsigned int n_attached_deserialize_fixed,
16336 const unsigned int n_attached_deserialize_variable)
16339 if (this->cell_attached_data.n_attached_deserialize > 0)
16341 this->data_serializer.load(global_first_cell,
16345 n_attached_deserialize_fixed,
16346 n_attached_deserialize_variable,
16347 this->get_mpi_communicator());
16349 this->data_serializer.unpack_cell_status(this->local_cell_relations);
16355 for (
const auto &cell_rel : this->local_cell_relations)
16357 Assert((cell_rel.second ==
16366template <
int dim,
int spacedim>
16374 vertices_used.clear();
16382 vertex_to_boundary_id_map_1d->clear();
16385 vertex_to_manifold_id_map_1d->clear();
16395 number_cache = internal::TriangulationImplementation::NumberCache<dim>();
16400template <
int dim,
int spacedim>
16402typename Triangulation<dim, spacedim>::DistortedCellList
16405 const DistortedCellList cells_with_distorted_children =
16406 this->policy->execute_refinement(*
this, check_for_distorted_cells);
16412 *
this, levels.size(), number_cache);
16416 for (
const auto &level : levels)
16423 for (
const auto &cell : this->cell_iterators())
16427 return cells_with_distorted_children;
16432template <
int dim,
int spacedim>
16438 const cell_iterator endc =
end();
16439 bool do_coarsen =
false;
16440 if (levels.size() >= 2)
16441 for (cell_iterator cell =
begin(n_levels() - 1); cell != endc; --cell)
16442 if (!cell->is_active() && cell->child(0)->coarsen_flag_set())
16454 std::vector<unsigned int> line_cell_count(dim > 1 ? this->n_raw_lines() : 0);
16455 std::vector<unsigned int> quad_cell_count(dim > 2 ? this->n_raw_quads() : 0);
16457 for (
const auto &cell : this->cell_iterators())
16461 const auto line_indices = internal::TriaAccessorImplementation::
16462 Implementation::get_line_indices_of_cell(*cell);
16465 const unsigned int n_lines =
std::min(cell->n_lines(), 12u);
16466 for (
unsigned int l = 0;
l < n_lines; ++
l)
16467 ++line_cell_count[line_indices[l]];
16468 for (
const unsigned int q : cell->face_indices())
16469 ++quad_cell_count[cell->face_index(q)];
16472 for (
unsigned int l = 0;
l < cell->n_lines(); ++
l)
16473 ++line_cell_count[cell->line(l)->index()];
16490 if (levels.size() >= 2)
16491 for (cell_iterator cell =
begin(n_levels() - 1); cell != endc; --cell)
16492 if (!cell->is_active() && cell->child(0)->coarsen_flag_set())
16494 for (
unsigned int child = 0; child < cell->n_children(); ++child)
16496 Assert(cell->child(child)->coarsen_flag_set(),
16498 cell->child(child)->clear_coarsen_flag();
16501 signals.pre_coarsening_on_cell(cell);
16503 this->policy->delete_children(*
this,
16511 *
this, levels.size(), number_cache);
16516template <
int dim,
int spacedim>
16533 auto previous_coarsen_flags = internal::extract_raw_coarsen_flags(levels);
16535 bool continue_iterating =
true;
16539 if (smooth_grid & limit_level_difference_at_vertices)
16541 Assert(!anisotropic_refinement,
16542 ExcMessage(
"In case of anisotropic refinement the "
16543 "limit_level_difference_at_vertices flag for "
16544 "mesh smoothing must not be set!"));
16548 std::vector<int> vertex_level(vertices.size(), 0);
16549 for (
const auto &cell : this->active_cell_iterators())
16551 if (cell->refine_flag_set())
16552 for (
const unsigned int vertex : cell->vertex_indices())
16553 vertex_level[cell->vertex_index(vertex)] =
16554 std::max(vertex_level[cell->vertex_index(vertex)],
16555 cell->level() + 1);
16556 else if (!cell->coarsen_flag_set())
16557 for (
const unsigned int vertex : cell->vertex_indices())
16558 vertex_level[cell->vertex_index(vertex)] =
16559 std::max(vertex_level[cell->vertex_index(vertex)],
16570 for (
const unsigned int vertex : cell->vertex_indices())
16571 vertex_level[cell->vertex_index(vertex)] =
16572 std::max(vertex_level[cell->vertex_index(vertex)],
16573 cell->level() - 1);
16587 active_cell_iterator endc =
end();
16588 for (active_cell_iterator cell = last_active(); cell != endc; --cell)
16589 if (cell->refine_flag_set() ==
false)
16591 for (
const unsigned int vertex : cell->vertex_indices())
16592 if (vertex_level[cell->vertex_index(vertex)] >=
16596 cell->clear_coarsen_flag();
16601 if (vertex_level[cell->vertex_index(vertex)] >
16604 cell->set_refine_flag();
16606 for (
const unsigned int v : cell->vertex_indices())
16607 vertex_level[cell->vertex_index(v)] =
16608 std::max(vertex_level[cell->vertex_index(v)],
16609 cell->level() + 1);
16625 for (
const auto &acell : this->active_cell_iterators_on_level(0))
16626 acell->clear_coarsen_flag();
16628 const cell_iterator endc =
end();
16629 for (cell_iterator cell =
begin(n_levels() - 1); cell != endc; --cell)
16632 if (cell->is_active())
16635 const unsigned int n_children = cell->n_children();
16636 unsigned int flagged_children = 0;
16637 for (
unsigned int child = 0; child < n_children; ++child)
16639 const auto child_cell = cell->child(child);
16640 if (child_cell->is_active() && child_cell->coarsen_flag_set())
16642 ++flagged_children;
16644 child_cell->clear_coarsen_flag();
16650 if (flagged_children == n_children &&
16651 this->policy->coarsening_allowed(cell))
16652 for (
unsigned int c = 0; c < n_children; ++c)
16654 Assert(cell->child(c)->refine_flag_set() ==
false,
16657 cell->child(c)->set_coarsen_flag();
16663 auto current_coarsen_flags = internal::extract_raw_coarsen_flags(levels);
16665 continue_iterating = (current_coarsen_flags != previous_coarsen_flags);
16666 previous_coarsen_flags.swap(current_coarsen_flags);
16668 while (continue_iterating ==
true);
16680 const auto flags_before = internal::extract_raw_coarsen_flags(
levels);
16685 const auto flags_after = internal::extract_raw_coarsen_flags(
levels);
16687 return (flags_before != flags_after);
16698 const auto flags_before = internal::extract_raw_coarsen_flags(
levels);
16703 const auto flags_after = internal::extract_raw_coarsen_flags(
levels);
16705 return (flags_before != flags_after);
16716 const auto flags_before = internal::extract_raw_coarsen_flags(
levels);
16721 const auto flags_after = internal::extract_raw_coarsen_flags(
levels);
16723 return (flags_before != flags_after);
16734 template <
int dim,
int spacedim>
16736 possibly_do_not_produce_unrefined_islands(
16741 unsigned int n_neighbors = 0;
16744 unsigned int count = 0;
16752 if (face_will_be_refined_by_neighbor(cell, n))
16759 if (count == n_neighbors ||
16760 (count >= n_neighbors - 1 &&
16763 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
16769 (cell_will_be_coarsened(cell->
neighbor(face))))
16770 possibly_do_not_produce_unrefined_islands<dim, spacedim>(
16786 template <
int dim,
int spacedim>
16788 possibly_refine_unrefined_island(
16790 const bool allow_anisotropic_smoothing)
16799 const parallel::distributed::Triangulation<dim, spacedim> *
>(
16811 "The triangulation is trying to avoid unrefined islands "
16812 "during mesh refinement/coarsening, as you had requested "
16813 " by passing the appropriate 'smoothing flags' to the "
16814 "constructor of the triangulation. However, for objects "
16815 "of type parallel::distributed::Triangulation, control "
16816 "over which cells get refined rests with p4est, not the "
16817 "deal.II triangulation, and consequently it is not "
16818 "always possible to avoid unrefined islands in the mesh. "
16819 "Please remove the constructor argument to the triangulation "
16820 "object that requests mesh smoothing."));
16832 if (allow_anisotropic_smoothing ==
false)
16835 unsigned int refined_neighbors = 0, unrefined_neighbors = 0;
16839 if (face_will_be_refined_by_neighbor(cell, face))
16840 ++refined_neighbors;
16842 ++unrefined_neighbors;
16845 if (unrefined_neighbors < refined_neighbors)
16853 if (unrefined_neighbors > 0)
16856 (face_will_be_refined_by_neighbor(cell, face) ==
false) &&
16859 possibly_refine_unrefined_island<dim, spacedim>(
16860 cell->
neighbor(face), allow_anisotropic_smoothing);
16867 RefinementCase<dim> smoothing_cell_refinement_case =
16872 for (
unsigned int face_pair = 0;
16873 face_pair < GeometryInfo<dim>::faces_per_cell / 2;
16879 RefinementCase<dim> directional_cell_refinement_case =
16882 for (
unsigned int face_index = 0; face_index < 2; ++face_index)
16884 unsigned int face = 2 * face_pair + face_index;
16887 RefinementCase<dim - 1> expected_face_ref_case =
16888 RefinementCase<dim - 1>::no_refinement;
16891 face_will_be_refined_by_neighbor<dim, spacedim>(
16892 cell, face, expected_face_ref_case);
16906 directional_cell_refinement_case =
16907 (directional_cell_refinement_case &
16910 expected_face_ref_case,
16920 Assert(directional_cell_refinement_case <
16923 smoothing_cell_refinement_case =
16924 smoothing_cell_refinement_case | directional_cell_refinement_case;
16929 if (smoothing_cell_refinement_case)
16933 smoothing_cell_refinement_case);
16940template <
int dim,
int spacedim>
16946 const auto coarsen_flags_before = internal::extract_raw_coarsen_flags(levels);
16947 const auto refine_flags_before = internal::extract_raw_refine_flags(levels);
16965 auto coarsen_flags_before_loop = coarsen_flags_before;
16966 auto refine_flags_before_loop = refine_flags_before;
17043 if (((smooth_grid & coarsest_level_1) || (smooth_grid & patch_level_1)) &&
17046 for (
const auto &cell : active_cell_iterators_on_level(1))
17050 bool mesh_changed_in_this_loop =
false;
17059 if (smooth_grid & do_not_produce_unrefined_islands &&
17060 !(smooth_grid & patch_level_1))
17062 for (
const auto &cell : cell_iterators())
17066 if (!cell->
is_active() && cell_will_be_coarsened(cell))
17067 possibly_do_not_produce_unrefined_islands<dim, spacedim>(cell);
17091 if (smooth_grid & (eliminate_refined_inner_islands |
17092 eliminate_refined_boundary_islands) &&
17093 !(smooth_grid & patch_level_1))
17095 for (
const auto &cell : cell_iterators())
17105 bool all_children_active =
true;
17107 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
17112 all_children_active =
false;
17116 if (all_children_active)
17123 unsigned int unrefined_neighbors = 0, total_neighbors = 0;
17134 bool at_periodic_boundary =
false;
17138 const cell_iterator neighbor = cell->
neighbor(n);
17143 if (!face_will_be_refined_by_neighbor(cell, n))
17144 ++unrefined_neighbors;
17149 at_periodic_boundary =
true;
17164 if ((unrefined_neighbors == total_neighbors) &&
17166 (smooth_grid & eliminate_refined_inner_islands)) ||
17169 eliminate_refined_boundary_islands))) &&
17170 (total_neighbors != 0))
17173 for (
unsigned int c = 0; c < cell->
n_children(); ++c)
17194 if (smooth_grid & limit_level_difference_at_vertices)
17196 Assert(!anisotropic_refinement,
17197 ExcMessage(
"In case of anisotropic refinement the "
17198 "limit_level_difference_at_vertices flag for "
17199 "mesh smoothing must not be set!"));
17203 std::vector<int> vertex_level(vertices.size(), 0);
17204 for (
const auto &cell : active_cell_iterators())
17210 cell->
level() + 1);
17226 cell->
level() - 1);
17240 for (active_cell_iterator cell = last_active(); cell !=
end(); --cell)
17261 cell->
level() + 1);
17282 if (smooth_grid & eliminate_unrefined_islands)
17284 for (active_cell_iterator cell = last_active(); cell !=
end(); --cell)
17289 possibly_refine_unrefined_island<dim, spacedim>(
17290 cell, (smooth_grid & allow_anisotropic_smoothing) != 0);
17318 if (smooth_grid & patch_level_1)
17328 for (
const auto &cell : cell_iterators())
17340 RefinementCase<dim> combined_ref_case =
17342 for (
unsigned int i = 0; i < cell->
n_children(); ++i)
17343 combined_ref_case =
17346 for (
unsigned int i = 0; i < cell->
n_children(); ++i)
17348 cell_iterator child = cell->
child(i);
17350 child->clear_coarsen_flag();
17351 child->set_refine_flag(combined_ref_case);
17364 for (
const auto &cell : cell_iterators())
17377 const unsigned int n_children = cell->
n_children();
17378 bool has_active_grandchildren =
false;
17380 for (
unsigned int i = 0; i < n_children; ++i)
17383 has_active_grandchildren =
true;
17387 if (has_active_grandchildren ==
false)
17393 unsigned int n_grandchildren = 0;
17396 unsigned int n_coarsen_flags = 0;
17401 for (
unsigned int c = 0; c < n_children; ++c)
17406 cell_iterator child = cell->
child(c);
17408 const unsigned int nn_children = child->n_children();
17409 n_grandchildren += nn_children;
17414 if (child->child(0)->is_active())
17415 for (
unsigned int cc = 0; cc < nn_children; ++cc)
17416 if (child->child(cc)->coarsen_flag_set())
17431 if ((n_coarsen_flags != n_grandchildren) && (n_coarsen_flags > 0))
17432 for (
unsigned int c = 0; c < n_children; ++c)
17434 const cell_iterator child = cell->
child(c);
17435 if (child->child(0)->is_active())
17436 for (
unsigned int cc = 0; cc < child->n_children(); ++cc)
17437 child->child(cc)->clear_coarsen_flag();
17448 this->policy->prevent_distorted_boundary_cells(*
this);
17464 bool changed =
true;
17468 active_cell_iterator cell = last_active(), endc =
end();
17470 for (; cell != endc; --cell)
17471 if (cell->refine_flag_set())
17474 for (
const auto i : cell->face_indices())
17479 const bool has_periodic_neighbor =
17480 cell->has_periodic_neighbor(i);
17481 const bool has_neighbor_or_periodic_neighbor =
17482 !cell->at_boundary(i) || has_periodic_neighbor;
17483 if (has_neighbor_or_periodic_neighbor &&
17485 cell->refine_flag_set(), i) !=
17498 if (cell->neighbor_or_periodic_neighbor(i)->is_active())
17500 if ((!has_periodic_neighbor &&
17501 cell->neighbor_is_coarser(i)) ||
17502 (has_periodic_neighbor &&
17503 cell->periodic_neighbor_is_coarser(i)))
17505 if (cell->neighbor_or_periodic_neighbor(i)
17506 ->coarsen_flag_set())
17507 cell->neighbor_or_periodic_neighbor(i)
17508 ->clear_coarsen_flag();
17525 allow_anisotropic_smoothing)
17527 has_periodic_neighbor ?
17528 cell->periodic_neighbor(i)
17529 ->flag_for_face_refinement(
17531 ->periodic_neighbor_of_coarser_periodic_neighbor(
17534 RefinementCase<dim - 1>::cut_x) :
17536 ->flag_for_face_refinement(
17538 ->neighbor_of_coarser_neighbor(
17541 RefinementCase<dim - 1>::cut_x);
17545 ->neighbor_or_periodic_neighbor(
17547 ->refine_flag_set())
17549 cell->neighbor_or_periodic_neighbor(i)
17550 ->set_refine_flag();
17682 std::pair<unsigned int, unsigned int>
17684 has_periodic_neighbor ?
17686 ->periodic_neighbor_of_coarser_periodic_neighbor(
17688 cell->neighbor_of_coarser_neighbor(i);
17689 unsigned int refined_along_x = 0,
17690 refined_along_y = 0,
17691 to_be_refined_along_x = 0,
17692 to_be_refined_along_y = 0;
17694 const int this_face_index =
17695 cell->face_index(i);
17704 const auto parent_face = [&]() {
17705 if (has_periodic_neighbor)
17707 const auto neighbor =
17708 cell->periodic_neighbor(i);
17709 const auto parent_face_no =
17711 ->periodic_neighbor_of_periodic_neighbor(
17714 neighbor->periodic_neighbor(
17716 return parent->face(parent_face_no);
17719 return cell->neighbor(i)->face(
17723 if ((this_face_index ==
17724 parent_face->child_index(0)) ||
17725 (this_face_index ==
17726 parent_face->child_index(1)))
17734 RefinementCase<dim - 1> frc =
17735 parent_face->refinement_case();
17736 if (frc & RefinementCase<dim>::cut_x)
17738 if (frc & RefinementCase<dim>::cut_y)
17751 RefinementCase<dim - 1> flagged_frc =
17753 cell->refine_flag_set(),
17755 cell->face_orientation(i),
17756 cell->face_flip(i),
17757 cell->face_rotation(i));
17759 RefinementCase<dim>::cut_x)
17760 ++to_be_refined_along_x;
17762 RefinementCase<dim>::cut_y)
17763 ++to_be_refined_along_y;
17768 allow_anisotropic_smoothing) ||
17769 cell->neighbor_or_periodic_neighbor(i)
17770 ->refine_flag_set())
17772 if (refined_along_x +
17773 to_be_refined_along_x >
17777 ->neighbor_or_periodic_neighbor(i)
17778 ->flag_for_face_refinement(
17780 RefinementCase<dim -
17782 if (refined_along_y +
17783 to_be_refined_along_y >
17787 ->neighbor_or_periodic_neighbor(i)
17788 ->flag_for_face_refinement(
17790 RefinementCase<dim -
17796 ->neighbor_or_periodic_neighbor(i)
17797 ->refine_flag_set() !=
17801 cell->neighbor_or_periodic_neighbor(i)
17802 ->set_refine_flag();
17808 cell->neighbor_or_periodic_neighbor(i);
17809 RefinementCase<dim - 1> nb_frc =
17811 nb->refine_flag_set(),
17813 nb->face_orientation(nb_indices.first),
17814 nb->face_flip(nb_indices.first),
17815 nb->face_rotation(nb_indices.first));
17816 if ((nb_frc & RefinementCase<dim>::cut_x) &&
17817 !((refined_along_x != 0u) ||
17818 (to_be_refined_along_x != 0u)))
17819 changed |= cell->flag_for_face_refinement(
17822 if ((nb_frc & RefinementCase<dim>::cut_y) &&
17823 !((refined_along_y != 0u) ||
17824 (to_be_refined_along_y != 0u)))
17825 changed |= cell->flag_for_face_refinement(
17832 cell->neighbor_or_periodic_neighbor(i)
17833 ->clear_coarsen_flag();
17834 const unsigned int nb_nb =
17835 has_periodic_neighbor ?
17837 ->periodic_neighbor_of_periodic_neighbor(
17839 cell->neighbor_of_neighbor(i);
17840 const cell_iterator neighbor =
17841 cell->neighbor_or_periodic_neighbor(i);
17842 RefinementCase<dim - 1> face_ref_case =
17844 neighbor->refine_flag_set(),
17846 neighbor->face_orientation(nb_nb),
17847 neighbor->face_flip(nb_nb),
17848 neighbor->face_rotation(nb_nb));
17849 RefinementCase<dim - 1> needed_face_ref_case =
17851 cell->refine_flag_set(),
17853 cell->face_orientation(i),
17854 cell->face_flip(i),
17855 cell->face_rotation(i));
17860 if ((face_ref_case ==
17861 RefinementCase<dim>::cut_x &&
17862 needed_face_ref_case ==
17863 RefinementCase<dim>::cut_y) ||
17865 RefinementCase<dim>::cut_y &&
17866 needed_face_ref_case ==
17867 RefinementCase<dim>::cut_x))
17869 changed = cell->flag_for_face_refinement(
17871 neighbor->flag_for_face_refinement(
17872 nb_nb, needed_face_ref_case);
17878 RefinementCase<dim - 1>
17879 face_ref_case = cell->face(i)->refinement_case(),
17880 needed_face_ref_case =
17882 cell->refine_flag_set(),
17884 cell->face_orientation(i),
17885 cell->face_flip(i),
17886 cell->face_rotation(i));
17890 if ((face_ref_case == RefinementCase<dim>::cut_x &&
17891 needed_face_ref_case ==
17892 RefinementCase<dim>::cut_y) ||
17893 (face_ref_case == RefinementCase<dim>::cut_y &&
17894 needed_face_ref_case ==
17895 RefinementCase<dim>::cut_x))
17897 cell->flag_for_face_refinement(i,
17909 this->policy->prepare_refinement_dim_dependent(*
this);
17915 fix_coarsen_flags();
17918 auto coarsen_flags_after_loop =
17919 internal::extract_raw_coarsen_flags(levels);
17920 auto refine_flags_after_loop = internal::extract_raw_refine_flags(levels);
17923 mesh_changed_in_this_loop =
17924 ((coarsen_flags_before_loop != coarsen_flags_after_loop) ||
17925 (refine_flags_before_loop != refine_flags_after_loop));
17928 coarsen_flags_before_loop.swap(coarsen_flags_after_loop);
17929 refine_flags_before_loop.swap(refine_flags_after_loop);
17931 while (mesh_changed_in_this_loop);
17937 return ((coarsen_flags_before != coarsen_flags_before_loop) ||
17938 (refine_flags_before != refine_flags_before_loop));
17943template <
int dim,
int spacedim>
17946 const unsigned int magic_number1,
17947 const std::vector<bool> &v,
17948 const unsigned int magic_number2,
17951 const unsigned int N = v.size();
17952 unsigned char *flags =
new unsigned char[
N / 8 + 1];
17953 for (
unsigned int i = 0; i <
N / 8 + 1; ++i)
17956 for (
unsigned int position = 0; position <
N; ++position)
17957 flags[position / 8] |= (v[position] ? (1 << (position % 8)) : 0);
17966 out << magic_number1 <<
' ' <<
N << std::endl;
17967 for (
unsigned int i = 0; i <
N / 8 + 1; ++i)
17968 out <<
static_cast<unsigned int>(flags[i]) <<
' ';
17970 out << std::endl << magic_number2 << std::endl;
17978template <
int dim,
int spacedim>
17981 const unsigned int magic_number1,
17982 std::vector<bool> &v,
17983 const unsigned int magic_number2,
17988 unsigned int magic_number;
17989 in >> magic_number;
17990 AssertThrow(magic_number == magic_number1, ExcGridReadError());
17996 unsigned char *flags =
new unsigned char[
N / 8 + 1];
17997 unsigned short int tmp;
17998 for (
unsigned int i = 0; i <
N / 8 + 1; ++i)
18004 for (
unsigned int position = 0; position !=
N; ++position)
18005 v[position] = ((flags[position / 8] & (1 << (position % 8))) != 0);
18007 in >> magic_number;
18008 AssertThrow(magic_number == magic_number2, ExcGridReadError());
18017template <
int dim,
int spacedim>
18021 std::size_t mem = 0;
18022 mem +=
sizeof(MeshSmoothing);
18026 for (
const auto &level : levels)
18030 mem +=
sizeof(manifolds);
18031 mem +=
sizeof(smooth_grid);
18033 mem +=
sizeof(faces);
18042template <
int dim,
int spacedim>
18050#include "grid/tria.inst"