3211 if (dim == spacedim)
3212 for (
unsigned int cell_no = 0; cell_no < cells.size(); ++cell_no)
3235 tria.
faces = std::make_unique<
3244 const unsigned int n_cell = cells.size();
3249 auto &lines_0 = tria.
faces->lines;
3252 const auto &crs = connectivity.entity_to_entities(1, 0);
3253 const unsigned int n_lines = crs.ptr.size() - 1;
3259 for (
unsigned int line = 0; line < n_lines; ++line)
3260 for (
unsigned int i = crs.ptr[line], j = 0; i < crs.ptr[line + 1];
3269 auto &quads_0 = tria.
faces->quads;
3270 auto &faces = *tria.
faces;
3273 const auto &crs = connectivity.entity_to_entities(2, 1);
3274 const unsigned int n_quads = crs.ptr.size() - 1;
3281 for (
unsigned int q = 0, k = 0; q < n_quads; ++q)
3284 faces.set_quad_type(q, connectivity.entity_types(2)[q]);
3287 for (
unsigned int i = crs.ptr[q], j = 0; i < crs.ptr[q + 1];
3295 const unsigned char combined_orientation =
3296 connectivity.entity_orientations(1)
3297 .get_combined_orientation(k);
3301 combined_orientation ==
3303 combined_orientation ==
3306 faces.quads_line_orientations
3308 combined_orientation ==
3316 auto &cells_0 = tria.
levels[0]->cells;
3320 const auto &crs = connectivity.entity_to_entities(dim, dim - 1);
3321 const auto &nei = connectivity.entity_to_entities(dim, dim);
3325 bool orientation_needed =
false;
3327 orientation_needed =
true;
3330 const auto &orientations = connectivity.entity_orientations(1);
3331 for (
unsigned int i = 0; i < orientations.n_objects(); ++i)
3332 if (orientations.get_combined_orientation(i) !=
3335 orientation_needed =
true;
3345 for (
unsigned int cell = 0; cell < n_cell; ++cell)
3348 cells_0.boundary_or_material_id[cell].material_id =
3349 cells[cell].material_id;
3352 cells_0.manifold_id[cell] = cells[cell].manifold_id;
3355 level.reference_cell[cell] = connectivity.entity_types(dim)[cell];
3358 for (
unsigned int i = crs.ptr[cell], j = 0; i < crs.ptr[cell + 1];
3362 if (nei.col[i] !=
static_cast<unsigned int>(-1))
3364 j] = {0, nei.col[i]};
3371 if (orientation_needed)
3373 level.face_orientations.set_combined_orientation(
3375 connectivity.entity_orientations(dim - 1)
3376 .get_combined_orientation(i));
3385 auto &bids_face = dim == 3 ?
3386 tria.faces->quads.boundary_or_material_id :
3387 tria.faces->lines.boundary_or_material_id;
3390 std::vector<unsigned int> count(bids_face.size(), 0);
3393 const auto &crs = connectivity.entity_to_entities(dim, dim - 1);
3396 for (
unsigned int cell = 0; cell < cells.size(); ++cell)
3397 for (
unsigned int i = crs.ptr[cell]; i < crs.ptr[cell + 1]; ++i)
3398 count[crs.col[i]]++;
3401 for (
unsigned int face = 0; face < count.size(); ++face)
3403 if (count[face] != 1)
3407 bids_face[face].boundary_id = 0;
3413 const auto &crs = connectivity.entity_to_entities(2, 1);
3414 for (
unsigned int i = crs.ptr[face]; i < crs.ptr[face + 1]; ++i)
3415 tria.faces->lines.boundary_or_material_id[crs.col[i]]
3421 static const unsigned int t_tba =
static_cast<unsigned int>(-1);
3422 static const unsigned int t_inner =
static_cast<unsigned int>(-2);
3424 std::vector<unsigned int> type(
vertices.size(), t_tba);
3426 const auto &crs = connectivity.entity_to_entities(1, 0);
3428 for (
unsigned int cell = 0; cell < cells.size(); ++cell)
3429 for (
unsigned int i = crs.ptr[cell], j = 0; i < crs.ptr[cell + 1];
3431 if (type[crs.col[i]] != t_inner)
3432 type[crs.col[i]] = type[crs.col[i]] == t_tba ? j : t_inner;
3434 for (
unsigned int face = 0; face < type.size(); ++face)
3437 (*tria.vertex_to_manifold_id_map_1d)[face] =
3439 if (type[face] != t_inner && type[face] != t_tba)
3440 (*tria.vertex_to_boundary_id_map_1d)[face] = type[face];
3448 subcelldata.boundary_lines,
3455 subcelldata.boundary_quads,
3928 std::vector<unsigned int> &line_cell_count,
3929 std::vector<unsigned int> &quad_cell_count)
3931 const unsigned int dim = 3;
3943 std::vector<typename Triangulation<dim, spacedim>::line_iterator>
3945 std::vector<typename Triangulation<dim, spacedim>::quad_iterator>
3948 lines_to_delete.reserve(12 * 2 + 6 * 4 + 6);
3949 quads_to_delete.reserve(6 * 4 + 12);
3953 for (
unsigned int c = 0; c < cell->n_children(); ++c)
3957 const auto line_indices = TriaAccessorImplementation::
3958 Implementation::get_line_indices_of_cell(*child);
3959 for (
const unsigned int l : cell->line_indices())
3960 --line_cell_count[line_indices[l]];
3962 --quad_cell_count[child->quad_index(f)];
3976 quads_to_delete.push_back(cell->child(0)->face(1));
3979 quads_to_delete.push_back(cell->child(0)->face(3));
3982 quads_to_delete.push_back(cell->child(0)->face(5));
3985 quads_to_delete.push_back(cell->child(0)->face(1));
3986 quads_to_delete.push_back(cell->child(0)->face(3));
3987 quads_to_delete.push_back(cell->child(3)->face(0));
3988 quads_to_delete.push_back(cell->child(3)->face(2));
3990 lines_to_delete.push_back(cell->child(0)->line(11));
3993 quads_to_delete.push_back(cell->child(0)->face(1));
3994 quads_to_delete.push_back(cell->child(0)->face(5));
3995 quads_to_delete.push_back(cell->child(3)->face(0));
3996 quads_to_delete.push_back(cell->child(3)->face(4));
3998 lines_to_delete.push_back(cell->child(0)->line(5));
4001 quads_to_delete.push_back(cell->child(0)->face(3));
4002 quads_to_delete.push_back(cell->child(0)->face(5));
4003 quads_to_delete.push_back(cell->child(3)->face(2));
4004 quads_to_delete.push_back(cell->child(3)->face(4));
4006 lines_to_delete.push_back(cell->child(0)->line(7));
4009 quads_to_delete.push_back(cell->child(0)->face(1));
4010 quads_to_delete.push_back(cell->child(2)->face(1));
4011 quads_to_delete.push_back(cell->child(4)->face(1));
4012 quads_to_delete.push_back(cell->child(6)->face(1));
4014 quads_to_delete.push_back(cell->child(0)->face(3));
4015 quads_to_delete.push_back(cell->child(1)->face(3));
4016 quads_to_delete.push_back(cell->child(4)->face(3));
4017 quads_to_delete.push_back(cell->child(5)->face(3));
4019 quads_to_delete.push_back(cell->child(0)->face(5));
4020 quads_to_delete.push_back(cell->child(1)->face(5));
4021 quads_to_delete.push_back(cell->child(2)->face(5));
4022 quads_to_delete.push_back(cell->child(3)->face(5));
4024 lines_to_delete.push_back(cell->child(0)->line(5));
4025 lines_to_delete.push_back(cell->child(0)->line(7));
4026 lines_to_delete.push_back(cell->child(0)->line(11));
4027 lines_to_delete.push_back(cell->child(7)->line(0));
4028 lines_to_delete.push_back(cell->child(7)->line(2));
4029 lines_to_delete.push_back(cell->child(7)->line(8));
4047 for (
unsigned int child = 0; child < cell->n_children(); ++child)
4049 cell->child(child)->clear_user_data();
4050 cell->child(child)->clear_user_flag();
4055 cell->child(child)->set_combined_face_orientation(
4058 cell->child(child)->clear_used_flag();
4063 cell->clear_children();
4064 cell->clear_refinement_case();
4065 cell->clear_user_flag();
4078 cell->face(quad_no);
4082 quad->has_children()) ||
4087 switch (quad->refinement_case())
4099 Assert((quad_cell_count[quad->child_index(0)] == 0 &&
4100 quad_cell_count[quad->child_index(1)] == 0) ||
4101 (quad_cell_count[quad->child_index(0)] > 0 &&
4102 quad_cell_count[quad->child_index(1)] > 0),
4108 unsigned int deleted_grandchildren = 0;
4109 unsigned int number_of_child_refinements = 0;
4111 for (
unsigned int c = 0; c < 2; ++c)
4112 if (quad->child(c)->has_children())
4114 ++number_of_child_refinements;
4119 (quad_cell_count[quad->child(c)->child_index(0)] ==
4121 quad_cell_count[quad->child(c)->child_index(1)] ==
4123 (quad_cell_count[quad->child(c)->child_index(0)] >
4125 quad_cell_count[quad->child(c)->child_index(1)] >
4128 if (quad_cell_count[quad->child(c)->child_index(0)] ==
4135 Assert(quad->refinement_case() +
4136 quad->child(c)->refinement_case() ==
4144 quads_to_delete.push_back(
4145 quad->child(c)->child(0));
4146 quads_to_delete.push_back(
4147 quad->child(c)->child(1));
4148 if (quad->child(c)->refinement_case() ==
4150 lines_to_delete.push_back(
4151 quad->child(c)->child(0)->line(1));
4153 lines_to_delete.push_back(
4154 quad->child(c)->child(0)->line(3));
4155 quad->child(c)->clear_children();
4156 quad->child(c)->clear_refinement_case();
4157 ++deleted_grandchildren;
4165 if (number_of_child_refinements > 0 &&
4166 deleted_grandchildren == number_of_child_refinements)
4171 middle_line = quad->child(0)->line(1);
4173 middle_line = quad->child(0)->line(3);
4175 lines_to_delete.push_back(middle_line->child(0));
4176 lines_to_delete.push_back(middle_line->child(1));
4179 middle_line)] =
false;
4180 middle_line->clear_children();
4185 if (quad_cell_count[quad->child_index(0)] == 0)
4191 quads_to_delete.push_back(quad->child(0));
4192 quads_to_delete.push_back(quad->child(1));
4194 lines_to_delete.push_back(quad->child(0)->line(1));
4196 lines_to_delete.push_back(quad->child(0)->line(3));
4216 if (quad->child(0)->has_children())
4217 if (quad->refinement_case() ==
4251 quad_iterator switch_1 =
4252 quad->child(0)->child(1),
4254 quad->child(1)->child(0);
4256 Assert(!switch_1->has_children(),
4258 Assert(!switch_2->has_children(),
4261 const int switch_1_index = switch_1->index();
4262 const int switch_2_index = switch_2->index();
4263 for (
unsigned int l = 0;
4266 for (
unsigned int h = 0;
4270 for (
const unsigned int q :
4275 ->cells.get_bounding_object_indices(
4277 if (
index == switch_1_index)
4279 ->cells.get_bounding_object_indices(
4280 h)[q] = switch_2_index;
4281 else if (
index == switch_2_index)
4283 ->cells.get_bounding_object_indices(
4284 h)[q] = switch_1_index;
4289 const int switch_1_lines[4] = {
4290 static_cast<signed int>(
4291 switch_1->line_index(0)),
4292 static_cast<signed int>(
4293 switch_1->line_index(1)),
4294 static_cast<signed int>(
4295 switch_1->line_index(2)),
4296 static_cast<signed int>(
4297 switch_1->line_index(3))};
4298 const bool switch_1_line_orientations[4] = {
4299 switch_1->line_orientation(0),
4300 switch_1->line_orientation(1),
4301 switch_1->line_orientation(2),
4302 switch_1->line_orientation(3)};
4304 switch_1->boundary_id();
4305 const unsigned int switch_1_user_index =
4306 switch_1->user_index();
4307 const bool switch_1_user_flag =
4308 switch_1->user_flag_set();
4310 switch_1->set_bounding_object_indices(
4311 {switch_2->line_index(0),
4312 switch_2->line_index(1),
4313 switch_2->line_index(2),
4314 switch_2->line_index(3)});
4315 switch_1->set_line_orientation(
4316 0, switch_2->line_orientation(0));
4317 switch_1->set_line_orientation(
4318 1, switch_2->line_orientation(1));
4319 switch_1->set_line_orientation(
4320 2, switch_2->line_orientation(2));
4321 switch_1->set_line_orientation(
4322 3, switch_2->line_orientation(3));
4323 switch_1->set_boundary_id_internal(
4324 switch_2->boundary_id());
4325 switch_1->set_manifold_id(
4326 switch_2->manifold_id());
4327 switch_1->set_user_index(switch_2->user_index());
4328 if (switch_2->user_flag_set())
4329 switch_1->set_user_flag();
4331 switch_1->clear_user_flag();
4333 switch_2->set_bounding_object_indices(
4337 switch_1_lines[3]});
4338 switch_2->set_line_orientation(
4339 0, switch_1_line_orientations[0]);
4340 switch_2->set_line_orientation(
4341 1, switch_1_line_orientations[1]);
4342 switch_2->set_line_orientation(
4343 2, switch_1_line_orientations[2]);
4344 switch_2->set_line_orientation(
4345 3, switch_1_line_orientations[3]);
4346 switch_2->set_boundary_id_internal(
4347 switch_1_boundary_id);
4348 switch_2->set_manifold_id(
4349 switch_1->manifold_id());
4350 switch_2->set_user_index(switch_1_user_index);
4351 if (switch_1_user_flag)
4352 switch_2->set_user_flag();
4354 switch_2->clear_user_flag();
4356 const unsigned int child_0 =
4357 quad->child(0)->child_index(0);
4358 const unsigned int child_2 =
4359 quad->child(1)->child_index(0);
4360 quad->clear_children();
4361 quad->clear_refinement_case();
4362 quad->set_refinement_case(
4364 quad->set_children(0, child_0);
4365 quad->set_children(2, child_2);
4366 std::swap(quad_cell_count[child_0 + 1],
4367 quad_cell_count[child_2]);
4382 const unsigned int child_0 =
4383 quad->child(0)->child_index(0);
4384 const unsigned int child_2 =
4385 quad->child(1)->child_index(0);
4386 quad->clear_children();
4387 quad->clear_refinement_case();
4388 quad->set_refinement_case(
4390 quad->set_children(0, child_0);
4391 quad->set_children(2, child_2);
4395 quad->clear_children();
4396 quad->clear_refinement_case();
4407 Assert((quad_cell_count[quad->child_index(0)] == 0 &&
4408 quad_cell_count[quad->child_index(1)] == 0 &&
4409 quad_cell_count[quad->child_index(2)] == 0 &&
4410 quad_cell_count[quad->child_index(3)] == 0) ||
4411 (quad_cell_count[quad->child_index(0)] > 0 &&
4412 quad_cell_count[quad->child_index(1)] > 0 &&
4413 quad_cell_count[quad->child_index(2)] > 0 &&
4414 quad_cell_count[quad->child_index(3)] > 0),
4417 if (quad_cell_count[quad->child_index(0)] == 0)
4423 lines_to_delete.push_back(quad->child(0)->line(1));
4424 lines_to_delete.push_back(quad->child(3)->line(0));
4425 lines_to_delete.push_back(quad->child(0)->line(3));
4426 lines_to_delete.push_back(quad->child(3)->line(2));
4428 for (
unsigned int child = 0; child < quad->n_children();
4430 quads_to_delete.push_back(quad->child(child));
4436 quad->clear_children();
4437 quad->clear_refinement_case();
4456 for (
unsigned int line_no = 0;
4457 line_no < GeometryInfo<dim>::lines_per_cell;
4461 cell->line(line_no);
4465 line->has_children()) ||
4470 if (line->has_children())
4475 Assert((line_cell_count[line->child_index(0)] == 0 &&
4476 line_cell_count[line->child_index(1)] == 0) ||
4477 (line_cell_count[line->child_index(0)] > 0 &&
4478 line_cell_count[line->child_index(1)] > 0),
4481 if (line_cell_count[line->child_index(0)] == 0)
4483 for (
unsigned int c = 0; c < 2; ++c)
4484 Assert(!line->child(c)->has_children(),
4494 lines_to_delete.push_back(line->child(0));
4495 lines_to_delete.push_back(line->child(1));
4497 line->clear_children();
4509 typename std::vector<
4511 line = lines_to_delete.begin(),
4512 endline = lines_to_delete.end();
4513 for (; line != endline; ++line)
4515 (*line)->clear_user_data();
4516 (*line)->clear_user_flag();
4517 (*line)->clear_used_flag();
4520 typename std::vector<
4522 quad = quads_to_delete.begin(),
4523 endquad = quads_to_delete.end();
4524 for (; quad != endquad; ++quad)
4526 (*quad)->clear_user_data();
4527 (*quad)->clear_children();
4528 (*quad)->clear_refinement_case();
4529 (*quad)->clear_user_flag();
4530 (*quad)->clear_used_flag();
4556 unsigned int &next_unused_vertex,
4563 const unsigned int dim = 2;
4566 cell->clear_refine_flag();
4659 int new_vertices[9];
4660 for (
unsigned int vertex_no = 0; vertex_no < 4; ++vertex_no)
4661 new_vertices[vertex_no] = cell->vertex_index(vertex_no);
4662 for (
unsigned int line_no = 0; line_no < 4; ++line_no)
4663 if (cell->line(line_no)->has_children())
4664 new_vertices[4 + line_no] =
4665 cell->line(line_no)->child(0)->vertex_index(1);
4675 ++next_unused_vertex;
4678 "Internal error: During refinement, the triangulation "
4679 "wants to access an element of the 'vertices' array "
4680 "but it turns out that the array is not large enough."));
4683 new_vertices[8] = next_unused_vertex;
4689 cell->center(
true,
true);
4695 unsigned int lmin = 8;
4696 unsigned int lmax = 12;
4703 for (
unsigned int l = lmin; l < lmax; ++l)
4705 while (next_unused_line->used() ==
true)
4707 new_lines[l] = next_unused_line;
4725 for (
unsigned int c = 0; c < 2; ++c, ++l)
4726 new_lines[l] = cell->line(face_no)->child(c);
4729 new_lines[8]->set_bounding_object_indices(
4730 {new_vertices[6], new_vertices[8]});
4731 new_lines[9]->set_bounding_object_indices(
4732 {new_vertices[8], new_vertices[7]});
4733 new_lines[10]->set_bounding_object_indices(
4734 {new_vertices[4], new_vertices[8]});
4735 new_lines[11]->set_bounding_object_indices(
4736 {new_vertices[8], new_vertices[5]});
4745 new_lines[0] = cell->line(0);
4746 new_lines[1] = cell->line(1);
4747 new_lines[2] = cell->line(2)->child(0);
4748 new_lines[3] = cell->line(2)->child(1);
4749 new_lines[4] = cell->line(3)->child(0);
4750 new_lines[5] = cell->line(3)->child(1);
4751 new_lines[6]->set_bounding_object_indices(
4752 {new_vertices[6], new_vertices[7]});
4762 new_lines[0] = cell->line(0)->child(0);
4763 new_lines[1] = cell->line(0)->child(1);
4764 new_lines[2] = cell->line(1)->child(0);
4765 new_lines[3] = cell->line(1)->child(1);
4766 new_lines[4] = cell->line(2);
4767 new_lines[5] = cell->line(3);
4768 new_lines[6]->set_bounding_object_indices(
4769 {new_vertices[4], new_vertices[5]});
4772 for (
unsigned int l = lmin; l < lmax; ++l)
4774 new_lines[l]->set_used_flag();
4775 new_lines[l]->clear_user_flag();
4777 new_lines[l]->clear_children();
4779 new_lines[l]->set_boundary_id_internal(
4781 new_lines[l]->set_manifold_id(cell->manifold_id());
4788 while (next_unused_cell->used() ==
true)
4792 for (
unsigned int i = 0; i < n_children; ++i)
4795 subcells[i] = next_unused_cell;
4797 if (i % 2 == 1 && i < n_children - 1)
4798 while (next_unused_cell->used() ==
true)
4816 subcells[0]->set_bounding_object_indices({new_lines[0]->index(),
4817 new_lines[8]->
index(),
4818 new_lines[4]->
index(),
4819 new_lines[10]->
index()});
4820 subcells[1]->set_bounding_object_indices({new_lines[8]->index(),
4821 new_lines[2]->
index(),
4822 new_lines[5]->
index(),
4823 new_lines[11]->
index()});
4824 subcells[2]->set_bounding_object_indices({new_lines[1]->index(),
4825 new_lines[9]->
index(),
4826 new_lines[10]->
index(),
4827 new_lines[6]->
index()});
4828 subcells[3]->set_bounding_object_indices({new_lines[9]->index(),
4829 new_lines[3]->
index(),
4830 new_lines[11]->
index(),
4831 new_lines[7]->
index()});
4847 subcells[0]->set_bounding_object_indices({new_lines[0]->index(),
4848 new_lines[6]->
index(),
4849 new_lines[2]->
index(),
4850 new_lines[4]->
index()});
4851 subcells[1]->set_bounding_object_indices({new_lines[6]->index(),
4852 new_lines[1]->
index(),
4853 new_lines[3]->
index(),
4854 new_lines[5]->
index()});
4871 subcells[0]->set_bounding_object_indices({new_lines[0]->index(),
4872 new_lines[2]->
index(),
4873 new_lines[4]->
index(),
4874 new_lines[6]->
index()});
4875 subcells[1]->set_bounding_object_indices({new_lines[1]->index(),
4876 new_lines[3]->
index(),
4877 new_lines[6]->
index(),
4878 new_lines[5]->
index()});
4883 for (
unsigned int i = 0; i < n_children; ++i)
4885 subcells[i]->set_used_flag();
4886 subcells[i]->clear_refine_flag();
4887 subcells[i]->clear_user_flag();
4888 subcells[i]->clear_user_data();
4889 subcells[i]->clear_children();
4891 subcells[i]->set_material_id(cell->material_id());
4892 subcells[i]->set_manifold_id(cell->manifold_id());
4893 subcells[i]->set_subdomain_id(subdomainid);
4896 subcells[i]->set_parent(cell->index());
4902 for (
unsigned int i = 0; i < n_children / 2; ++i)
4903 cell->set_children(2 * i, subcells[2 * i]->index());
4905 cell->set_refinement_case(ref_case);
4912 if (dim == spacedim - 1)
4913 for (
unsigned int c = 0; c < n_children; ++c)
4914 cell->child(c)->set_direction_flag(cell->direction_flag());
4922 const bool check_for_distorted_cells)
4930 if (cell->refine_flag_set())
4943 line->clear_user_flag();
4947 unsigned int n_single_lines = 0;
4948 unsigned int n_lines_in_pairs = 0;
4949 unsigned int needed_vertices = 0;
4955 unsigned int needed_cells = 0;
4957 for (
const auto &cell :
4959 if (cell->refine_flag_set())
4964 needed_vertices += 0;
4965 n_single_lines += 3;
4967 else if (cell->reference_cell() ==
4971 needed_vertices += 1;
4972 n_single_lines += 4;
4979 for (
const auto line_no : cell->face_indices())
4981 auto line = cell->line(line_no);
4982 if (line->has_children() ==
false)
4983 line->set_user_flag();
4988 const unsigned int used_cells =
4995 used_cells + needed_cells,
5007 if (line->user_flag_set())
5010 n_lines_in_pairs += 2;
5011 needed_vertices += 1;
5026 unsigned int next_unused_vertex = 0;
5035 for (; line != endl; ++line)
5036 if (line->user_flag_set())
5041 ++next_unused_vertex;
5044 "Internal error: During refinement, the triangulation "
5045 "wants to access an element of the 'vertices' array "
5046 "but it turns out that the array is not large "
5052 bool pair_found =
false;
5054 for (; next_unused_line != endl; ++next_unused_line)
5055 if (!next_unused_line->used() &&
5056 !(++next_unused_line)->used())
5064 line->set_children(0, next_unused_line->index());
5067 children[2] = {next_unused_line, ++next_unused_line};
5072 children[0]->set_bounding_object_indices(
5073 {line->vertex_index(0), next_unused_vertex});
5074 children[1]->set_bounding_object_indices(
5075 {next_unused_vertex, line->vertex_index(1)});
5077 for (
auto &child : children)
5079 child->set_used_flag();
5080 child->clear_children();
5082 child->clear_user_flag();
5083 child->set_boundary_id_internal(line->boundary_id());
5084 child->set_manifold_id(line->manifold_id());
5089 line->clear_user_flag();
5096 cells_with_distorted_children;
5102 unsigned int &next_unused_vertex,
5103 auto &next_unused_line,
5104 auto &next_unused_cell,
5106 const auto ref_case = cell->refine_flag_set();
5107 cell->clear_refine_flag();
5109 unsigned int n_new_vertices = 0;
5118 std::vector<unsigned int> new_vertices(n_new_vertices,
5120 for (
unsigned int vertex_no = 0; vertex_no < cell->n_vertices();
5122 new_vertices[vertex_no] = cell->vertex_index(vertex_no);
5123 for (
unsigned int line_no = 0; line_no < cell->n_lines(); ++line_no)
5124 if (cell->line(line_no)->has_children())
5125 new_vertices[cell->n_vertices() + line_no] =
5126 cell->line(line_no)->child(0)->vertex_index(1);
5131 ++next_unused_vertex;
5135 "Internal error: During refinement, the triangulation wants "
5136 "to access an element of the 'vertices' array but it turns "
5137 "out that the array is not large enough."));
5140 new_vertices[8] = next_unused_vertex;
5143 cell->center(
true,
true);
5146 std::array<typename Triangulation<dim, spacedim>::raw_line_iterator,
5149 std::array<unsigned char, 12> inherited_orientations;
5150 inherited_orientations.fill(
5152 unsigned int lmin = 0;
5153 unsigned int lmax = 0;
5162 std::fill(inherited_orientations.begin() + lmin,
5163 inherited_orientations.begin() + lmax,
5176 for (
unsigned int l = lmin; l < lmax; ++l)
5178 while (next_unused_line->used() ==
true)
5180 new_lines[l] = next_unused_line;
5187 for (
const unsigned int face_no : cell->face_indices())
5194 const unsigned char combined_orientation =
5195 cell->combined_face_orientation(face_no);
5196 Assert(combined_orientation ==
5198 combined_orientation ==
5201 for (
unsigned int c = 0; c < 2; ++c)
5203 new_lines[2 * face_no + c] = cell->line(face_no)->child(c);
5204 inherited_orientations[2 * face_no + c] =
5205 cell->combined_face_orientation(face_no);
5207 if (combined_orientation ==
5209 std::swap(new_lines[2 * face_no], new_lines[2 * face_no + 1]);
5215 new_lines[6]->set_bounding_object_indices(
5216 {new_vertices[3], new_vertices[4]});
5217 new_lines[7]->set_bounding_object_indices(
5218 {new_vertices[4], new_vertices[5]});
5219 new_lines[8]->set_bounding_object_indices(
5220 {new_vertices[5], new_vertices[3]});
5224 new_lines[8]->set_bounding_object_indices(
5225 {new_vertices[6], new_vertices[8]});
5226 new_lines[9]->set_bounding_object_indices(
5227 {new_vertices[8], new_vertices[7]});
5228 new_lines[10]->set_bounding_object_indices(
5229 {new_vertices[4], new_vertices[8]});
5230 new_lines[11]->set_bounding_object_indices(
5231 {new_vertices[8], new_vertices[5]});
5238 for (
unsigned int l = lmin; l < lmax; ++l)
5240 new_lines[l]->set_used_flag();
5241 new_lines[l]->clear_user_flag();
5242 new_lines[l]->clear_user_data();
5243 new_lines[l]->clear_children();
5245 new_lines[l]->set_boundary_id_internal(
5247 new_lines[l]->set_manifold_id(cell->manifold_id());
5252 while (next_unused_cell->used() ==
true)
5255 unsigned int n_children = 0;
5263 for (
unsigned int i = 0; i < n_children; ++i)
5266 subcells[i] = next_unused_cell;
5268 if (i % 2 == 1 && i < n_children - 1)
5269 while (next_unused_cell->used() ==
true)
5275 static constexpr ::ndarray<unsigned int, 4, 4> tri_child_lines =
5276 {{{{0, 8, 5, X}}, {{1, 2, 6, X}}, {{7, 3, 4, X}}, {{6, 7, 8, X}}}};
5277 static constexpr ::ndarray<unsigned int, 4, 4>
5278 quad_child_lines = {{{{0, 8, 4, 10}},
5284 const auto &child_lines =
5288 for (
unsigned int i = 0; i < n_children; ++i)
5291 subcells[i]->set_bounding_object_indices(
5292 {new_lines[child_lines[i][0]]->index(),
5293 new_lines[child_lines[i][1]]->
index(),
5294 new_lines[child_lines[i][2]]->
index()});
5296 subcells[i]->set_bounding_object_indices(
5297 {new_lines[child_lines[i][0]]->index(),
5298 new_lines[child_lines[i][1]]->
index(),
5299 new_lines[child_lines[i][2]]->
index(),
5300 new_lines[child_lines[i][3]]->
index()});
5302 subcells[i]->set_used_flag();
5303 subcells[i]->clear_refine_flag();
5304 subcells[i]->clear_user_flag();
5305 subcells[i]->clear_user_data();
5306 subcells[i]->clear_children();
5308 subcells[i]->set_material_id(cell->material_id());
5309 subcells[i]->set_manifold_id(cell->manifold_id());
5310 subcells[i]->set_subdomain_id(cell->subdomain_id());
5313 ->reference_cell[subcells[i]->index()] = cell->reference_cell();
5317 for (
unsigned int face_no : cell->face_indices())
5318 subcells[i]->set_combined_face_orientation(
5319 face_no, inherited_orientations[child_lines[i][face_no]]);
5322 subcells[i]->set_parent(cell->index());
5328 for (
unsigned int face_no : cell->face_indices())
5329 subcells[3]->set_combined_face_orientation(
5332 for (
unsigned int i = 0; i < n_children / 2; ++i)
5333 cell->set_children(2 * i, subcells[2 * i]->index());
5335 cell->set_refinement_case(ref_case);
5337 if (dim == spacedim - 1)
5338 for (
unsigned int c = 0; c < n_children; ++c)
5339 cell->child(c)->set_direction_flag(cell->direction_flag());
5349 for (
const auto &cell :
5351 if (cell->refine_flag_set())
5360 check_for_distorted_cells &&
5361 has_distorted_children<dim, spacedim>(cell))
5369 return cells_with_distorted_children;
5383 const unsigned int dim = 1;
5389 if (cell->refine_flag_set())
5402 unsigned int needed_vertices = 0;
5407 unsigned int flagged_cells = 0;
5409 for (
const auto &acell :
5411 if (acell->refine_flag_set())
5416 const unsigned int used_cells =
5436 needed_vertices += flagged_cells;
5458 unsigned int next_unused_vertex = 0;
5465 for (
const auto &cell :
5467 if (cell->refine_flag_set())
5470 cell->clear_refine_flag();
5476 ++next_unused_vertex;
5480 "Internal error: During refinement, the triangulation "
5481 "wants to access an element of the 'vertices' array "
5482 "but it turns out that the array is not large enough."));
5497 while (next_unused_cell->used() ==
true)
5499 first_child = next_unused_cell;
5500 first_child->set_used_flag();
5501 first_child->clear_user_data();
5504 second_child = next_unused_cell;
5505 second_child->set_used_flag();
5506 second_child->clear_user_data();
5511 cell->set_children(0, first_child->index());
5512 first_child->clear_children();
5513 first_child->set_bounding_object_indices(
5514 {cell->vertex_index(0), next_unused_vertex});
5515 first_child->set_material_id(cell->material_id());
5516 first_child->set_manifold_id(cell->manifold_id());
5517 first_child->set_subdomain_id(subdomainid);
5518 if (dim == spacedim - 1)
5519 first_child->set_direction_flag(cell->direction_flag());
5521 first_child->set_parent(cell->index());
5525 first_child->face(1)->set_manifold_id(cell->manifold_id());
5530 first_child->set_neighbor(1, second_child);
5532 first_child->set_neighbor(0, cell->neighbor(0));
5533 else if (cell->neighbor(0)->is_active())
5539 Assert(cell->neighbor(0)->level() <= cell->level(),
5541 first_child->set_neighbor(0, cell->neighbor(0));
5547 const unsigned int nbnb = cell->neighbor_of_neighbor(0);
5548 first_child->set_neighbor(0,
5549 cell->neighbor(0)->child(nbnb));
5554 left_neighbor = cell->neighbor(0);
5555 while (left_neighbor->has_children())
5557 left_neighbor = left_neighbor->child(nbnb);
5558 left_neighbor->set_neighbor(nbnb, first_child);
5563 second_child->clear_children();
5564 second_child->set_bounding_object_indices(
5565 {next_unused_vertex, cell->vertex_index(1)});
5566 second_child->set_neighbor(0, first_child);
5567 second_child->set_material_id(cell->material_id());
5568 second_child->set_manifold_id(cell->manifold_id());
5569 second_child->set_subdomain_id(subdomainid);
5570 if (dim == spacedim - 1)
5571 second_child->set_direction_flag(cell->direction_flag());
5574 second_child->set_neighbor(1, cell->neighbor(1));
5575 else if (cell->neighbor(1)->is_active())
5577 Assert(cell->neighbor(1)->level() <= cell->level(),
5579 second_child->set_neighbor(1, cell->neighbor(1));
5584 const unsigned int nbnb = cell->neighbor_of_neighbor(1);
5585 second_child->set_neighbor(
5586 1, cell->neighbor(1)->child(nbnb));
5589 right_neighbor = cell->neighbor(1);
5590 while (right_neighbor->has_children())
5592 right_neighbor = right_neighbor->child(nbnb);
5593 right_neighbor->set_neighbor(nbnb, second_child);