3205 if (dim == spacedim)
3206 for (
unsigned int cell_no = 0; cell_no < cells.size(); ++cell_no)
3214 const double cell_measure = GridTools::cell_measure<spacedim>(
3229 tria.
faces = std::make_unique<
3237 const auto connectivity = build_connectivity<unsigned int>(cells);
3238 const unsigned int n_cell = cells.size();
3243 auto &lines_0 = tria.
faces->lines;
3246 const auto &crs = connectivity.entity_to_entities(1, 0);
3247 const unsigned int n_lines = crs.ptr.size() - 1;
3253 for (
unsigned int line = 0; line < n_lines; ++line)
3254 for (
unsigned int i = crs.ptr[line], j = 0; i < crs.ptr[line + 1];
3263 auto &quads_0 = tria.
faces->quads;
3264 auto &faces = *tria.
faces;
3267 const auto &crs = connectivity.entity_to_entities(2, 1);
3268 const unsigned int n_quads = crs.ptr.size() - 1;
3275 for (
unsigned int q = 0, k = 0; q < n_quads; ++q)
3278 faces.set_quad_type(q, connectivity.entity_types(2)[q]);
3281 for (
unsigned int i = crs.ptr[q], j = 0; i < crs.ptr[q + 1];
3289 const unsigned char combined_orientation =
3290 connectivity.entity_orientations(1)
3291 .get_combined_orientation(k);
3295 combined_orientation ==
3297 combined_orientation ==
3300 faces.quads_line_orientations
3302 combined_orientation ==
3310 auto &cells_0 = tria.
levels[0]->cells;
3314 const auto &crs = connectivity.entity_to_entities(dim, dim - 1);
3315 const auto &nei = connectivity.entity_to_entities(dim, dim);
3319 bool orientation_needed =
false;
3321 orientation_needed =
true;
3324 const auto &orientations = connectivity.entity_orientations(1);
3325 for (
unsigned int i = 0; i < orientations.n_objects(); ++i)
3326 if (orientations.get_combined_orientation(i) !=
3329 orientation_needed =
true;
3339 for (
unsigned int cell = 0; cell < n_cell; ++cell)
3342 cells_0.boundary_or_material_id[cell].material_id =
3343 cells[cell].material_id;
3346 cells_0.manifold_id[cell] = cells[cell].manifold_id;
3349 level.reference_cell[cell] = connectivity.entity_types(dim)[cell];
3352 for (
unsigned int i = crs.ptr[cell], j = 0; i < crs.ptr[cell + 1];
3356 if (nei.col[i] !=
static_cast<unsigned int>(-1))
3358 j] = {0, nei.col[i]};
3365 if (orientation_needed)
3367 level.face_orientations.set_combined_orientation(
3369 connectivity.entity_orientations(dim - 1)
3370 .get_combined_orientation(i));
3379 auto &bids_face = dim == 3 ?
3380 tria.faces->quads.boundary_or_material_id :
3381 tria.faces->lines.boundary_or_material_id;
3384 std::vector<unsigned int> count(bids_face.size(), 0);
3387 const auto &crs = connectivity.entity_to_entities(dim, dim - 1);
3390 for (
unsigned int cell = 0; cell < cells.size(); ++cell)
3391 for (
unsigned int i = crs.ptr[cell]; i < crs.ptr[cell + 1]; ++i)
3392 count[crs.col[i]]++;
3395 for (
unsigned int face = 0; face < count.size(); ++face)
3397 if (count[face] != 1)
3401 bids_face[face].boundary_id = 0;
3407 const auto &crs = connectivity.entity_to_entities(2, 1);
3408 for (
unsigned int i = crs.ptr[face]; i < crs.ptr[face + 1]; ++i)
3409 tria.faces->lines.boundary_or_material_id[crs.col[i]]
3415 static const unsigned int t_tba =
static_cast<unsigned int>(-1);
3416 static const unsigned int t_inner =
static_cast<unsigned int>(-2);
3418 std::vector<unsigned int> type(
vertices.size(), t_tba);
3420 const auto &crs = connectivity.entity_to_entities(1, 0);
3422 for (
unsigned int cell = 0; cell < cells.size(); ++cell)
3423 for (
unsigned int i = crs.ptr[cell], j = 0; i < crs.ptr[cell + 1];
3425 if (type[crs.col[i]] != t_inner)
3426 type[crs.col[i]] = type[crs.col[i]] == t_tba ? j : t_inner;
3428 for (
unsigned int face = 0; face < type.size(); ++face)
3431 (*tria.vertex_to_manifold_id_map_1d)[face] =
3433 if (type[face] != t_inner && type[face] != t_tba)
3434 (*tria.vertex_to_boundary_id_map_1d)[face] = type[face];
3442 subcelldata.boundary_lines,
3449 subcelldata.boundary_quads,
3920 std::vector<unsigned int> &line_cell_count,
3921 std::vector<unsigned int> &quad_cell_count)
3923 const unsigned int dim = 3;
3935 std::vector<typename Triangulation<dim, spacedim>::line_iterator>
3937 std::vector<typename Triangulation<dim, spacedim>::quad_iterator>
3940 lines_to_delete.reserve(12 * 2 + 6 * 4 + 6);
3941 quads_to_delete.reserve(6 * 4 + 12);
3945 for (
unsigned int c = 0; c < cell->n_children(); ++c)
3949 const auto line_indices = TriaAccessorImplementation::
3950 Implementation::get_line_indices_of_cell(*child);
3951 for (
const unsigned int l : cell->line_indices())
3952 --line_cell_count[line_indices[l]];
3954 --quad_cell_count[child->quad_index(f)];
3968 quads_to_delete.push_back(cell->child(0)->face(1));
3971 quads_to_delete.push_back(cell->child(0)->face(3));
3974 quads_to_delete.push_back(cell->child(0)->face(5));
3977 quads_to_delete.push_back(cell->child(0)->face(1));
3978 quads_to_delete.push_back(cell->child(0)->face(3));
3979 quads_to_delete.push_back(cell->child(3)->face(0));
3980 quads_to_delete.push_back(cell->child(3)->face(2));
3982 lines_to_delete.push_back(cell->child(0)->line(11));
3985 quads_to_delete.push_back(cell->child(0)->face(1));
3986 quads_to_delete.push_back(cell->child(0)->face(5));
3987 quads_to_delete.push_back(cell->child(3)->face(0));
3988 quads_to_delete.push_back(cell->child(3)->face(4));
3990 lines_to_delete.push_back(cell->child(0)->line(5));
3993 quads_to_delete.push_back(cell->child(0)->face(3));
3994 quads_to_delete.push_back(cell->child(0)->face(5));
3995 quads_to_delete.push_back(cell->child(3)->face(2));
3996 quads_to_delete.push_back(cell->child(3)->face(4));
3998 lines_to_delete.push_back(cell->child(0)->line(7));
4001 quads_to_delete.push_back(cell->child(0)->face(1));
4002 quads_to_delete.push_back(cell->child(2)->face(1));
4003 quads_to_delete.push_back(cell->child(4)->face(1));
4004 quads_to_delete.push_back(cell->child(6)->face(1));
4006 quads_to_delete.push_back(cell->child(0)->face(3));
4007 quads_to_delete.push_back(cell->child(1)->face(3));
4008 quads_to_delete.push_back(cell->child(4)->face(3));
4009 quads_to_delete.push_back(cell->child(5)->face(3));
4011 quads_to_delete.push_back(cell->child(0)->face(5));
4012 quads_to_delete.push_back(cell->child(1)->face(5));
4013 quads_to_delete.push_back(cell->child(2)->face(5));
4014 quads_to_delete.push_back(cell->child(3)->face(5));
4016 lines_to_delete.push_back(cell->child(0)->line(5));
4017 lines_to_delete.push_back(cell->child(0)->line(7));
4018 lines_to_delete.push_back(cell->child(0)->line(11));
4019 lines_to_delete.push_back(cell->child(7)->line(0));
4020 lines_to_delete.push_back(cell->child(7)->line(2));
4021 lines_to_delete.push_back(cell->child(7)->line(8));
4027 triangulation.vertices_used[cell->child(0)->vertex_index(7)] =
4039 for (
unsigned int child = 0; child < cell->n_children(); ++child)
4041 cell->child(child)->clear_user_data();
4042 cell->child(child)->clear_user_flag();
4047 cell->child(child)->set_combined_face_orientation(
4050 cell->child(child)->clear_used_flag();
4055 cell->clear_children();
4056 cell->clear_refinement_case();
4057 cell->clear_user_flag();
4070 cell->face(quad_no);
4074 quad->has_children()) ||
4079 switch (quad->refinement_case())
4091 Assert((quad_cell_count[quad->child_index(0)] == 0 &&
4092 quad_cell_count[quad->child_index(1)] == 0) ||
4093 (quad_cell_count[quad->child_index(0)] > 0 &&
4094 quad_cell_count[quad->child_index(1)] > 0),
4100 unsigned int deleted_grandchildren = 0;
4101 unsigned int number_of_child_refinements = 0;
4103 for (
unsigned int c = 0; c < 2; ++c)
4104 if (quad->child(c)->has_children())
4106 ++number_of_child_refinements;
4111 (quad_cell_count[quad->child(c)->child_index(0)] ==
4113 quad_cell_count[quad->child(c)->child_index(1)] ==
4115 (quad_cell_count[quad->child(c)->child_index(0)] >
4117 quad_cell_count[quad->child(c)->child_index(1)] >
4120 if (quad_cell_count[quad->child(c)->child_index(0)] ==
4127 Assert(quad->refinement_case() +
4128 quad->child(c)->refinement_case() ==
4136 quads_to_delete.push_back(
4137 quad->child(c)->child(0));
4138 quads_to_delete.push_back(
4139 quad->child(c)->child(1));
4140 if (quad->child(c)->refinement_case() ==
4142 lines_to_delete.push_back(
4143 quad->child(c)->child(0)->line(1));
4145 lines_to_delete.push_back(
4146 quad->child(c)->child(0)->line(3));
4147 quad->child(c)->clear_children();
4148 quad->child(c)->clear_refinement_case();
4149 ++deleted_grandchildren;
4157 if (number_of_child_refinements > 0 &&
4158 deleted_grandchildren == number_of_child_refinements)
4163 middle_line = quad->child(0)->line(1);
4165 middle_line = quad->child(0)->line(3);
4167 lines_to_delete.push_back(middle_line->child(0));
4168 lines_to_delete.push_back(middle_line->child(1));
4171 middle_line)] =
false;
4172 middle_line->clear_children();
4177 if (quad_cell_count[quad->child_index(0)] == 0)
4183 quads_to_delete.push_back(quad->child(0));
4184 quads_to_delete.push_back(quad->child(1));
4186 lines_to_delete.push_back(quad->child(0)->line(1));
4188 lines_to_delete.push_back(quad->child(0)->line(3));
4208 if (quad->child(0)->has_children())
4209 if (quad->refinement_case() ==
4243 quad_iterator switch_1 =
4244 quad->child(0)->child(1),
4246 quad->child(1)->child(0);
4248 Assert(!switch_1->has_children(),
4250 Assert(!switch_2->has_children(),
4253 const int switch_1_index = switch_1->index();
4254 const int switch_2_index = switch_2->index();
4255 for (
unsigned int l = 0;
4258 for (
unsigned int h = 0;
4262 for (
const unsigned int q :
4267 ->cells.get_bounding_object_indices(
4269 if (
index == switch_1_index)
4271 ->cells.get_bounding_object_indices(
4272 h)[q] = switch_2_index;
4273 else if (
index == switch_2_index)
4275 ->cells.get_bounding_object_indices(
4276 h)[q] = switch_1_index;
4281 const int switch_1_lines[4] = {
4282 static_cast<signed int>(
4283 switch_1->line_index(0)),
4284 static_cast<signed int>(
4285 switch_1->line_index(1)),
4286 static_cast<signed int>(
4287 switch_1->line_index(2)),
4288 static_cast<signed int>(
4289 switch_1->line_index(3))};
4290 const bool switch_1_line_orientations[4] = {
4291 switch_1->line_orientation(0),
4292 switch_1->line_orientation(1),
4293 switch_1->line_orientation(2),
4294 switch_1->line_orientation(3)};
4296 switch_1->boundary_id();
4297 const unsigned int switch_1_user_index =
4298 switch_1->user_index();
4299 const bool switch_1_user_flag =
4300 switch_1->user_flag_set();
4302 switch_1->set_bounding_object_indices(
4303 {switch_2->line_index(0),
4304 switch_2->line_index(1),
4305 switch_2->line_index(2),
4306 switch_2->line_index(3)});
4307 switch_1->set_line_orientation(
4308 0, switch_2->line_orientation(0));
4309 switch_1->set_line_orientation(
4310 1, switch_2->line_orientation(1));
4311 switch_1->set_line_orientation(
4312 2, switch_2->line_orientation(2));
4313 switch_1->set_line_orientation(
4314 3, switch_2->line_orientation(3));
4315 switch_1->set_boundary_id_internal(
4316 switch_2->boundary_id());
4317 switch_1->set_manifold_id(
4318 switch_2->manifold_id());
4319 switch_1->set_user_index(switch_2->user_index());
4320 if (switch_2->user_flag_set())
4321 switch_1->set_user_flag();
4323 switch_1->clear_user_flag();
4325 switch_2->set_bounding_object_indices(
4329 switch_1_lines[3]});
4330 switch_2->set_line_orientation(
4331 0, switch_1_line_orientations[0]);
4332 switch_2->set_line_orientation(
4333 1, switch_1_line_orientations[1]);
4334 switch_2->set_line_orientation(
4335 2, switch_1_line_orientations[2]);
4336 switch_2->set_line_orientation(
4337 3, switch_1_line_orientations[3]);
4338 switch_2->set_boundary_id_internal(
4339 switch_1_boundary_id);
4340 switch_2->set_manifold_id(
4341 switch_1->manifold_id());
4342 switch_2->set_user_index(switch_1_user_index);
4343 if (switch_1_user_flag)
4344 switch_2->set_user_flag();
4346 switch_2->clear_user_flag();
4348 const unsigned int child_0 =
4349 quad->child(0)->child_index(0);
4350 const unsigned int child_2 =
4351 quad->child(1)->child_index(0);
4352 quad->clear_children();
4353 quad->clear_refinement_case();
4354 quad->set_refinement_case(
4356 quad->set_children(0, child_0);
4357 quad->set_children(2, child_2);
4358 std::swap(quad_cell_count[child_0 + 1],
4359 quad_cell_count[child_2]);
4374 const unsigned int child_0 =
4375 quad->child(0)->child_index(0);
4376 const unsigned int child_2 =
4377 quad->child(1)->child_index(0);
4378 quad->clear_children();
4379 quad->clear_refinement_case();
4380 quad->set_refinement_case(
4382 quad->set_children(0, child_0);
4383 quad->set_children(2, child_2);
4387 quad->clear_children();
4388 quad->clear_refinement_case();
4399 Assert((quad_cell_count[quad->child_index(0)] == 0 &&
4400 quad_cell_count[quad->child_index(1)] == 0 &&
4401 quad_cell_count[quad->child_index(2)] == 0 &&
4402 quad_cell_count[quad->child_index(3)] == 0) ||
4403 (quad_cell_count[quad->child_index(0)] > 0 &&
4404 quad_cell_count[quad->child_index(1)] > 0 &&
4405 quad_cell_count[quad->child_index(2)] > 0 &&
4406 quad_cell_count[quad->child_index(3)] > 0),
4409 if (quad_cell_count[quad->child_index(0)] == 0)
4415 lines_to_delete.push_back(quad->child(0)->line(1));
4416 lines_to_delete.push_back(quad->child(3)->line(0));
4417 lines_to_delete.push_back(quad->child(0)->line(3));
4418 lines_to_delete.push_back(quad->child(3)->line(2));
4420 for (
unsigned int child = 0; child < quad->n_children();
4422 quads_to_delete.push_back(quad->child(child));
4425 .vertices_used[quad->child(0)->vertex_index(3)] =
4428 quad->clear_children();
4429 quad->clear_refinement_case();
4448 for (
unsigned int line_no = 0;
4449 line_no < GeometryInfo<dim>::lines_per_cell;
4453 cell->line(line_no);
4457 line->has_children()) ||
4462 if (line->has_children())
4467 Assert((line_cell_count[line->child_index(0)] == 0 &&
4468 line_cell_count[line->child_index(1)] == 0) ||
4469 (line_cell_count[line->child_index(0)] > 0 &&
4470 line_cell_count[line->child_index(1)] > 0),
4473 if (line_cell_count[line->child_index(0)] == 0)
4475 for (
unsigned int c = 0; c < 2; ++c)
4476 Assert(!line->child(c)->has_children(),
4484 .vertices_used[line->child(0)->vertex_index(1)] =
false;
4486 lines_to_delete.push_back(line->child(0));
4487 lines_to_delete.push_back(line->child(1));
4489 line->clear_children();
4501 typename std::vector<
4503 line = lines_to_delete.
begin(),
4504 endline = lines_to_delete.end();
4505 for (; line != endline; ++line)
4507 (*line)->clear_user_data();
4508 (*line)->clear_user_flag();
4509 (*line)->clear_used_flag();
4512 typename std::vector<
4514 quad = quads_to_delete.
begin(),
4515 endquad = quads_to_delete.end();
4516 for (; quad != endquad; ++quad)
4518 (*quad)->clear_user_data();
4519 (*quad)->clear_children();
4520 (*quad)->clear_refinement_case();
4521 (*quad)->clear_user_flag();
4522 (*quad)->clear_used_flag();
4548 unsigned int &next_unused_vertex,
4555 const unsigned int dim = 2;
4558 cell->clear_refine_flag();
4651 int new_vertices[9];
4652 for (
unsigned int vertex_no = 0; vertex_no < 4; ++vertex_no)
4653 new_vertices[vertex_no] = cell->vertex_index(vertex_no);
4654 for (
unsigned int line_no = 0; line_no < 4; ++line_no)
4655 if (cell->line(line_no)->has_children())
4656 new_vertices[4 + line_no] =
4657 cell->line(line_no)->child(0)->vertex_index(1);
4666 while (
triangulation.vertices_used[next_unused_vertex] ==
true)
4667 ++next_unused_vertex;
4670 "Internal error: During refinement, the triangulation "
4671 "wants to access an element of the 'vertices' array "
4672 "but it turns out that the array is not large enough."));
4675 new_vertices[8] = next_unused_vertex;
4681 cell->center(
true,
true);
4687 unsigned int lmin = 8;
4688 unsigned int lmax = 12;
4695 for (
unsigned int l = lmin; l < lmax; ++l)
4697 while (next_unused_line->used() ==
true)
4699 new_lines[l] = next_unused_line;
4717 for (
unsigned int c = 0; c < 2; ++c, ++l)
4718 new_lines[l] = cell->line(face_no)->child(c);
4721 new_lines[8]->set_bounding_object_indices(
4722 {new_vertices[6], new_vertices[8]});
4723 new_lines[9]->set_bounding_object_indices(
4724 {new_vertices[8], new_vertices[7]});
4725 new_lines[10]->set_bounding_object_indices(
4726 {new_vertices[4], new_vertices[8]});
4727 new_lines[11]->set_bounding_object_indices(
4728 {new_vertices[8], new_vertices[5]});
4737 new_lines[0] = cell->line(0);
4738 new_lines[1] = cell->line(1);
4739 new_lines[2] = cell->line(2)->child(0);
4740 new_lines[3] = cell->line(2)->child(1);
4741 new_lines[4] = cell->line(3)->child(0);
4742 new_lines[5] = cell->line(3)->child(1);
4743 new_lines[6]->set_bounding_object_indices(
4744 {new_vertices[6], new_vertices[7]});
4754 new_lines[0] = cell->line(0)->child(0);
4755 new_lines[1] = cell->line(0)->child(1);
4756 new_lines[2] = cell->line(1)->child(0);
4757 new_lines[3] = cell->line(1)->child(1);
4758 new_lines[4] = cell->line(2);
4759 new_lines[5] = cell->line(3);
4760 new_lines[6]->set_bounding_object_indices(
4761 {new_vertices[4], new_vertices[5]});
4764 for (
unsigned int l = lmin; l < lmax; ++l)
4766 new_lines[l]->set_used_flag();
4767 new_lines[l]->clear_user_flag();
4769 new_lines[l]->clear_children();
4771 new_lines[l]->set_boundary_id_internal(
4773 new_lines[l]->set_manifold_id(cell->manifold_id());
4780 while (next_unused_cell->used() ==
true)
4784 for (
unsigned int i = 0; i < n_children; ++i)
4787 subcells[i] = next_unused_cell;
4789 if (i % 2 == 1 && i < n_children - 1)
4790 while (next_unused_cell->used() ==
true)
4808 subcells[0]->set_bounding_object_indices({new_lines[0]->index(),
4809 new_lines[8]->
index(),
4810 new_lines[4]->
index(),
4811 new_lines[10]->
index()});
4812 subcells[1]->set_bounding_object_indices({new_lines[8]->index(),
4813 new_lines[2]->
index(),
4814 new_lines[5]->
index(),
4815 new_lines[11]->
index()});
4816 subcells[2]->set_bounding_object_indices({new_lines[1]->index(),
4817 new_lines[9]->
index(),
4818 new_lines[10]->
index(),
4819 new_lines[6]->
index()});
4820 subcells[3]->set_bounding_object_indices({new_lines[9]->index(),
4821 new_lines[3]->
index(),
4822 new_lines[11]->
index(),
4823 new_lines[7]->
index()});
4839 subcells[0]->set_bounding_object_indices({new_lines[0]->index(),
4840 new_lines[6]->
index(),
4841 new_lines[2]->
index(),
4842 new_lines[4]->
index()});
4843 subcells[1]->set_bounding_object_indices({new_lines[6]->index(),
4844 new_lines[1]->
index(),
4845 new_lines[3]->
index(),
4846 new_lines[5]->
index()});
4863 subcells[0]->set_bounding_object_indices({new_lines[0]->index(),
4864 new_lines[2]->
index(),
4865 new_lines[4]->
index(),
4866 new_lines[6]->
index()});
4867 subcells[1]->set_bounding_object_indices({new_lines[1]->index(),
4868 new_lines[3]->
index(),
4869 new_lines[6]->
index(),
4870 new_lines[5]->
index()});
4875 for (
unsigned int i = 0; i < n_children; ++i)
4877 subcells[i]->set_used_flag();
4878 subcells[i]->clear_refine_flag();
4879 subcells[i]->clear_user_flag();
4880 subcells[i]->clear_user_data();
4881 subcells[i]->clear_children();
4883 subcells[i]->set_material_id(cell->material_id());
4884 subcells[i]->set_manifold_id(cell->manifold_id());
4885 subcells[i]->set_subdomain_id(subdomainid);
4888 subcells[i]->set_parent(cell->index());
4894 for (
unsigned int i = 0; i < n_children / 2; ++i)
4895 cell->set_children(2 * i, subcells[2 * i]->index());
4897 cell->set_refinement_case(ref_case);
4904 if (dim == spacedim - 1)
4905 for (
unsigned int c = 0; c < n_children; ++c)
4906 cell->child(c)->set_direction_flag(cell->direction_flag());
4914 const bool check_for_distorted_cells)
4920 for (
const auto &cell :
triangulation.active_cell_iterators_on_level(
4922 if (cell->refine_flag_set())
4935 line->clear_user_flag();
4939 unsigned int n_single_lines = 0;
4940 unsigned int n_lines_in_pairs = 0;
4941 unsigned int needed_vertices = 0;
4947 unsigned int needed_cells = 0;
4949 for (
const auto &cell :
4951 if (cell->refine_flag_set())
4956 needed_vertices += 0;
4957 n_single_lines += 3;
4959 else if (cell->reference_cell() ==
4963 needed_vertices += 1;
4964 n_single_lines += 4;
4971 for (
const auto line_no : cell->face_indices())
4973 auto line = cell->line(line_no);
4974 if (line->has_children() ==
false)
4975 line->set_user_flag();
4980 const unsigned int used_cells =
4987 used_cells + needed_cells,
4999 if (line->user_flag_set())
5002 n_lines_in_pairs += 2;
5003 needed_vertices += 1;
5008 needed_vertices += std::count(
triangulation.vertices_used.begin(),
5018 unsigned int next_unused_vertex = 0;
5027 for (; line != endl; ++line)
5028 if (line->user_flag_set())
5032 while (
triangulation.vertices_used[next_unused_vertex] ==
true)
5033 ++next_unused_vertex;
5036 "Internal error: During refinement, the triangulation "
5037 "wants to access an element of the 'vertices' array "
5038 "but it turns out that the array is not large "
5042 triangulation.vertices[next_unused_vertex] = line->center(
true);
5044 [[maybe_unused]]
bool pair_found =
false;
5045 for (; next_unused_line != endl; ++next_unused_line)
5046 if (!next_unused_line->used() &&
5047 !(++next_unused_line)->used())
5055 line->set_children(0, next_unused_line->index());
5058 children[2] = {next_unused_line, ++next_unused_line};
5063 children[0]->set_bounding_object_indices(
5064 {line->vertex_index(0), next_unused_vertex});
5065 children[1]->set_bounding_object_indices(
5066 {next_unused_vertex, line->vertex_index(1)});
5068 for (
auto &child : children)
5070 child->set_used_flag();
5071 child->clear_children();
5073 child->clear_user_flag();
5074 child->set_boundary_id_internal(line->boundary_id());
5075 child->set_manifold_id(line->manifold_id());
5080 line->clear_user_flag();
5087 cells_with_distorted_children;
5093 unsigned int &next_unused_vertex,
5094 auto &next_unused_line,
5095 auto &next_unused_cell,
5097 const auto ref_case = cell->refine_flag_set();
5098 cell->clear_refine_flag();
5100 unsigned int n_new_vertices = 0;
5109 std::vector<unsigned int> new_vertices(n_new_vertices,
5111 for (
unsigned int vertex_no = 0; vertex_no < cell->n_vertices();
5113 new_vertices[vertex_no] = cell->vertex_index(vertex_no);
5114 for (
unsigned int line_no = 0; line_no < cell->n_lines(); ++line_no)
5115 if (cell->line(line_no)->has_children())
5116 new_vertices[cell->n_vertices() + line_no] =
5117 cell->line(line_no)->child(0)->vertex_index(1);
5121 while (
triangulation.vertices_used[next_unused_vertex] ==
true)
5122 ++next_unused_vertex;
5126 "Internal error: During refinement, the triangulation wants "
5127 "to access an element of the 'vertices' array but it turns "
5128 "out that the array is not large enough."));
5131 new_vertices[8] = next_unused_vertex;
5134 cell->center(
true,
true);
5137 std::array<typename Triangulation<dim, spacedim>::raw_line_iterator,
5140 std::array<unsigned char, 12> inherited_orientations;
5141 inherited_orientations.fill(
5143 unsigned int lmin = 0;
5144 unsigned int lmax = 0;
5153 std::fill(inherited_orientations.begin() + lmin,
5154 inherited_orientations.begin() + lmax,
5167 for (
unsigned int l = lmin; l < lmax; ++l)
5169 while (next_unused_line->used() ==
true)
5171 new_lines[l] = next_unused_line;
5178 for (
const unsigned int face_no : cell->face_indices())
5185 const unsigned char combined_orientation =
5186 cell->combined_face_orientation(face_no);
5187 Assert(combined_orientation ==
5189 combined_orientation ==
5192 for (
unsigned int c = 0; c < 2; ++c)
5194 new_lines[2 * face_no + c] = cell->line(face_no)->child(c);
5195 inherited_orientations[2 * face_no + c] =
5196 cell->combined_face_orientation(face_no);
5198 if (combined_orientation ==
5200 std::swap(new_lines[2 * face_no], new_lines[2 * face_no + 1]);
5206 new_lines[6]->set_bounding_object_indices(
5207 {new_vertices[3], new_vertices[4]});
5208 new_lines[7]->set_bounding_object_indices(
5209 {new_vertices[4], new_vertices[5]});
5210 new_lines[8]->set_bounding_object_indices(
5211 {new_vertices[5], new_vertices[3]});
5215 new_lines[8]->set_bounding_object_indices(
5216 {new_vertices[6], new_vertices[8]});
5217 new_lines[9]->set_bounding_object_indices(
5218 {new_vertices[8], new_vertices[7]});
5219 new_lines[10]->set_bounding_object_indices(
5220 {new_vertices[4], new_vertices[8]});
5221 new_lines[11]->set_bounding_object_indices(
5222 {new_vertices[8], new_vertices[5]});
5229 for (
unsigned int l = lmin; l < lmax; ++l)
5231 new_lines[l]->set_used_flag();
5232 new_lines[l]->clear_user_flag();
5233 new_lines[l]->clear_user_data();
5234 new_lines[l]->clear_children();
5236 new_lines[l]->set_boundary_id_internal(
5238 new_lines[l]->set_manifold_id(cell->manifold_id());
5243 while (next_unused_cell->used() ==
true)
5246 unsigned int n_children = 0;
5254 for (
unsigned int i = 0; i < n_children; ++i)
5257 subcells[i] = next_unused_cell;
5259 if (i % 2 == 1 && i < n_children - 1)
5260 while (next_unused_cell->used() ==
true)
5266 static constexpr ::ndarray<unsigned int, 4, 4> tri_child_lines =
5267 {{{{0, 8, 5, X}}, {{1, 2, 6, X}}, {{7, 3, 4, X}}, {{6, 7, 8, X}}}};
5268 static constexpr ::ndarray<unsigned int, 4, 4>
5269 quad_child_lines = {{{{0, 8, 4, 10}},
5275 const auto &child_lines =
5279 for (
unsigned int i = 0; i < n_children; ++i)
5282 subcells[i]->set_bounding_object_indices(
5283 {new_lines[child_lines[i][0]]->index(),
5284 new_lines[child_lines[i][1]]->
index(),
5285 new_lines[child_lines[i][2]]->
index()});
5287 subcells[i]->set_bounding_object_indices(
5288 {new_lines[child_lines[i][0]]->index(),
5289 new_lines[child_lines[i][1]]->
index(),
5290 new_lines[child_lines[i][2]]->
index(),
5291 new_lines[child_lines[i][3]]->
index()});
5293 subcells[i]->set_used_flag();
5294 subcells[i]->clear_refine_flag();
5295 subcells[i]->clear_user_flag();
5296 subcells[i]->clear_user_data();
5297 subcells[i]->clear_children();
5299 subcells[i]->set_material_id(cell->material_id());
5300 subcells[i]->set_manifold_id(cell->manifold_id());
5301 subcells[i]->set_subdomain_id(cell->subdomain_id());
5304 ->reference_cell[subcells[i]->index()] = cell->reference_cell();
5308 for (
unsigned int face_no : cell->face_indices())
5309 subcells[i]->set_combined_face_orientation(
5310 face_no, inherited_orientations[child_lines[i][face_no]]);
5313 subcells[i]->set_parent(cell->index());
5319 for (
unsigned int face_no : cell->face_indices())
5320 subcells[3]->set_combined_face_orientation(
5323 for (
unsigned int i = 0; i < n_children / 2; ++i)
5324 cell->set_children(2 * i, subcells[2 * i]->index());
5326 cell->set_refinement_case(ref_case);
5328 if (dim == spacedim - 1)
5329 for (
unsigned int c = 0; c < n_children; ++c)
5330 cell->child(c)->set_direction_flag(cell->direction_flag());
5340 for (
const auto &cell :
5342 if (cell->refine_flag_set())
5351 check_for_distorted_cells &&
5352 has_distorted_children<dim, spacedim>(cell))
5360 return cells_with_distorted_children;
5374 const unsigned int dim = 1;
5378 for (
const auto &cell :
triangulation.active_cell_iterators_on_level(
5380 if (cell->refine_flag_set())
5393 unsigned int needed_vertices = 0;
5398 unsigned int flagged_cells = 0;
5400 for (
const auto &acell :
5402 if (acell->refine_flag_set())
5407 const unsigned int used_cells =
5427 needed_vertices += flagged_cells;
5432 needed_vertices += std::count(
triangulation.vertices_used.begin(),
5449 unsigned int next_unused_vertex = 0;
5456 for (
const auto &cell :
5458 if (cell->refine_flag_set())
5461 cell->clear_refine_flag();
5467 ++next_unused_vertex;
5471 "Internal error: During refinement, the triangulation "
5472 "wants to access an element of the 'vertices' array "
5473 "but it turns out that the array is not large enough."));
5488 while (next_unused_cell->used() ==
true)
5490 first_child = next_unused_cell;
5491 first_child->set_used_flag();
5492 first_child->clear_user_data();
5495 second_child = next_unused_cell;
5496 second_child->set_used_flag();
5497 second_child->clear_user_data();
5502 cell->set_children(0, first_child->index());
5503 first_child->clear_children();
5504 first_child->set_bounding_object_indices(
5505 {cell->vertex_index(0), next_unused_vertex});
5506 first_child->set_material_id(cell->material_id());
5507 first_child->set_manifold_id(cell->manifold_id());
5508 first_child->set_subdomain_id(subdomainid);
5509 if (dim == spacedim - 1)
5510 first_child->set_direction_flag(cell->direction_flag());
5512 first_child->set_parent(cell->index());
5516 first_child->face(1)->set_manifold_id(cell->manifold_id());
5521 first_child->set_neighbor(1, second_child);
5523 first_child->set_neighbor(0, cell->neighbor(0));
5524 else if (cell->neighbor(0)->is_active())
5530 Assert(cell->neighbor(0)->level() <= cell->level(),
5532 first_child->set_neighbor(0, cell->neighbor(0));
5538 const unsigned int nbnb = cell->neighbor_of_neighbor(0);
5539 first_child->set_neighbor(0,
5540 cell->neighbor(0)->child(nbnb));
5545 left_neighbor = cell->neighbor(0);
5546 while (left_neighbor->has_children())
5548 left_neighbor = left_neighbor->child(nbnb);
5549 left_neighbor->set_neighbor(nbnb, first_child);
5554 second_child->clear_children();
5555 second_child->set_bounding_object_indices(
5556 {next_unused_vertex, cell->vertex_index(1)});
5557 second_child->set_neighbor(0, first_child);
5558 second_child->set_material_id(cell->material_id());
5559 second_child->set_manifold_id(cell->manifold_id());
5560 second_child->set_subdomain_id(subdomainid);
5561 if (dim == spacedim - 1)
5562 second_child->set_direction_flag(cell->direction_flag());
5565 second_child->set_neighbor(1, cell->neighbor(1));
5566 else if (cell->neighbor(1)->is_active())
5568 Assert(cell->neighbor(1)->level() <= cell->level(),
5570 second_child->set_neighbor(1, cell->neighbor(1));
5575 const unsigned int nbnb = cell->neighbor_of_neighbor(1);
5576 second_child->set_neighbor(
5577 1, cell->neighbor(1)->child(nbnb));
5580 right_neighbor = cell->neighbor(1);
5581 while (right_neighbor->has_children())
5583 right_neighbor = right_neighbor->child(nbnb);
5584 right_neighbor->set_neighbor(nbnb, second_child);
5607 const bool check_for_distorted_cells)
5609 const unsigned int dim = 2;
5614 bool do_isotropic_refinement =
true;
5615 for (
const auto &cell :
triangulation.active_cell_iterators())
5619 do_isotropic_refinement =
false;
5623 if (do_isotropic_refinement)
5625 check_for_distorted_cells);
5632 for (
const auto &cell :
triangulation.active_cell_iterators_on_level(
5634 if (cell->refine_flag_set())
5649 line->clear_user_flag();
5655 unsigned int n_single_lines = 0;
5659 unsigned int n_lines_in_pairs = 0;
5665 unsigned int needed_vertices = 0;
5670 unsigned int needed_cells = 0;
5672 for (
const auto &cell :
5674 if (cell->refine_flag_set())
5685 n_single_lines += 4;
5697 n_single_lines += 1;
5705 for (
const unsigned int line_no :
5709 cell->refine_flag_set(), line_no) ==
5713 line = cell->line(line_no);
5714 if (line->has_children() ==
false)
5715 line->set_user_flag();
5722 const unsigned int used_cells =
5732 used_cells + needed_cells,
5748 if (line->user_flag_set())
5751 n_lines_in_pairs += 2;
5752 needed_vertices += 1;
5764 needed_vertices += std::count(
triangulation.vertices_used.begin(),
5781 unsigned int next_unused_vertex = 0;
5793 for (; line != endl; ++line)
5794 if (line->user_flag_set())
5800 while (
triangulation.vertices_used[next_unused_vertex] ==
true)
5801 ++next_unused_vertex;
5805 "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."));
5808 triangulation.vertices[next_unused_vertex] = line->center(
true);
5813 [[maybe_unused]]
bool pair_found =
false;
5814 for (; next_unused_line != endl; ++next_unused_line)
5815 if (!next_unused_line->used() &&
5816 !(++next_unused_line)->used())
5829 line->set_children(0, next_unused_line->index());
5833 children[2] = {next_unused_line, ++next_unused_line};
5839 children[0]->set_bounding_object_indices(
5840 {line->vertex_index(0), next_unused_vertex});
5841 children[1]->set_bounding_object_indices(
5842 {next_unused_vertex, line->vertex_index(1)});
5844 children[0]->set_used_flag();
5845 children[1]->set_used_flag();
5846 children[0]->clear_children();
5847 children[1]->clear_children();
5850 children[0]->clear_user_flag();
5851 children[1]->clear_user_flag();
5854 children[0]->set_boundary_id_internal(line->boundary_id());
5855 children[1]->set_boundary_id_internal(line->boundary_id());
5857 children[0]->set_manifold_id(line->manifold_id());
5858 children[1]->set_manifold_id(line->manifold_id());
5862 line->clear_user_flag();
5874 cells_with_distorted_children;
5888 for (
const auto &cell :
5890 if (cell->refine_flag_set())
5900 if (check_for_distorted_cells &&
5901 has_distorted_children<dim, spacedim>(cell))
5909 return cells_with_distorted_children;
5916 const bool check_for_distorted_cells)
5918 static const int dim = 3;
5920 using raw_line_iterator =
5922 using raw_quad_iterator =
5933 for (
const auto &cell :
triangulation.active_cell_iterators_on_level(
5935 if (cell->refine_flag_set())
5961 unsigned int needed_vertices = 0;
5962 unsigned int needed_lines_single = 0;
5963 unsigned int needed_quads_single = 0;
5964 unsigned int needed_lines_pair = 0;
5965 unsigned int needed_quads_pair = 0;
5968 unsigned int new_cells = 0;
5970 for (
const auto &cell :
5972 if (cell->refine_flag_set())
5975 Assert(cell->refine_flag_set() ==
5981 new_cells += cell->reference_cell().n_isotropic_children();
5986 needed_lines_single += 6;
5987 needed_quads_single += 12;
5989 else if (cell->reference_cell() ==
5992 needed_lines_single += 1;
5993 needed_quads_single += 8;
6004 for (
const auto face : cell->face_indices())
6005 if (cell->face(face)->n_children() == 0)
6006 cell->face(face)->set_user_flag();
6008 Assert(cell->face(face)->n_children() ==
6009 cell->reference_cell()
6010 .face_reference_cell(face)
6011 .n_isotropic_children(),
6014 for (
const auto line : cell->line_indices())
6015 if (cell->line(line)->has_children() ==
false)
6016 cell->line(line)->set_user_flag();
6018 Assert(cell->line(line)->n_children() == 2,
6022 const unsigned int used_cells =
6029 used_cells + new_cells,
6035 used_cells + new_cells,
6050 if (quad->user_flag_set() ==
false)
6055 needed_quads_pair += 4;
6056 needed_lines_pair += 4;
6057 needed_vertices += 1;
6061 needed_quads_pair += 4;
6062 needed_lines_single += 3;
6075 if (line->user_flag_set() ==
false)
6078 needed_lines_pair += 2;
6079 needed_vertices += 1;
6084 needed_lines_single);
6087 needed_quads_single);
6090 needed_quads_single);
6094 needed_vertices += std::count(
triangulation.vertices_used.begin(),
6115 for (
const auto &cell :
triangulation.active_cell_iterators())
6116 if (!cell->refine_flag_set())
6117 for (
unsigned int line_n = 0; line_n < cell->n_lines(); ++line_n)
6118 if (cell->line(line_n)->has_children())
6119 for (
unsigned int c = 0; c < 2; ++c)
6120 Assert(cell->line(line_n)->child(c)->user_flag_set() ==
false,
6124 unsigned int current_vertex = 0;
6128 auto get_next_unused_vertex = [](
const unsigned int current_vertex,
6129 std::vector<bool> &vertices_used) {
6130 unsigned int next_vertex = current_vertex;
6131 while (next_vertex < vertices_used.size() &&
6132 vertices_used[next_vertex] ==
true)
6135 vertices_used[next_vertex] =
true;
6145 raw_line_iterator next_unused_line =
triangulation.begin_raw_line();
6147 for (; line != endl; ++line)
6149 if (line->user_flag_set() ==
false)
6153 triangulation.faces->lines.template next_free_pair_object<1>(
6161 line->set_children(0, next_unused_line->index());
6163 const std::array<raw_line_iterator, 2> children{
6164 {next_unused_line, ++next_unused_line}};
6170 get_next_unused_vertex(current_vertex,
6172 triangulation.vertices[current_vertex] = line->center(
true);
6174 children[0]->set_bounding_object_indices(
6175 {line->vertex_index(0), current_vertex});
6176 children[1]->set_bounding_object_indices(
6177 {current_vertex, line->vertex_index(1)});
6179 const auto manifold_id = line->manifold_id();
6180 const auto boundary_id = line->boundary_id();
6181 for (
const auto &child : children)
6183 child->set_used_flag();
6184 child->clear_children();
6186 child->clear_user_flag();
6187 child->set_boundary_id_internal(boundary_id);
6188 child->set_manifold_id(manifold_id);
6191 line->clear_user_flag();
6201 for (; quad != endq; ++quad)
6203 if (quad->user_flag_set() ==
false)
6206 const auto reference_face_type = quad->reference_cell();
6210 std::array<raw_line_iterator, 4> new_lines;