14 #include "libmesh/elem.h" 15 #include "libmesh/boundary_info.h" 16 #include "libmesh/mesh_base.h" 17 #include "libmesh/parallel.h" 18 #include "libmesh/parallel_algebra.h" 19 #include "libmesh/face_tri3.h" 28 const std::vector<Real> & bdry_pars,
30 const std::set<subdomain_id_type> & subdomain_ids_set,
33 const std::vector<boundary_id_type> & other_boundaries_to_conform,
34 const bool assign_ext_to_new,
35 const bool side_to_remove)
41 std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> slc_bdry_side_list;
42 for (
unsigned int i = 0; i < bdry_side_list.size(); i++)
43 if (std::get<2>(bdry_side_list[i]) == external_boundary_id ||
44 std::find(other_boundaries_to_conform.begin(),
45 other_boundaries_to_conform.end(),
46 std::get<2>(bdry_side_list[i])) != other_boundaries_to_conform.end())
47 slc_bdry_side_list.push_back(bdry_side_list[i]);
51 std::vector<dof_id_type> crossed_elems_to_remove;
52 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
56 unsigned short removal_side_count = 0;
57 for (
unsigned int i = 0; i < (*elem_it)->n_vertices(); i++)
62 "MooseMeshXYCuttingUtils::lineRemoverMoveNode() only works for 2D meshes in XY plane.");
64 (*elem_it)->point(i)(1),
71 if (removal_side_count == (*elem_it)->n_vertices())
73 (*elem_it)->subdomain_id() = block_id_to_remove;
78 (*elem_it)->vertex_average()(1),
83 crossed_elems_to_remove.push_back((*elem_it)->id());
86 for (
const auto & elem_id : crossed_elems_to_remove)
88 bool remove_flag =
true;
93 std::find(crossed_elems_to_remove.begin(),
94 crossed_elems_to_remove.end(),
96 crossed_elems_to_remove.end())
113 std::vector<dof_id_type> node_list;
114 for (
auto elem_it =
mesh.active_subdomain_set_elements_begin(subdomain_ids_set);
115 elem_it !=
mesh.active_subdomain_set_elements_end(subdomain_ids_set);
118 for (
unsigned int i = 0; i < (*elem_it)->n_sides(); i++)
120 if ((*elem_it)->neighbor_ptr(i) !=
nullptr)
121 if ((*elem_it)->neighbor_ptr(i)->subdomain_id() == block_id_to_remove)
123 node_list.push_back((*elem_it)->side_ptr(i)->node_ptr(0)->id());
124 node_list.push_back((*elem_it)->side_ptr(i)->node_ptr(1)->id());
125 boundary_info.
add_side(*elem_it, i, trimming_section_boundary_id);
126 if (assign_ext_to_new && trimming_section_boundary_id != external_boundary_id)
127 boundary_info.
add_side(*elem_it, i, external_boundary_id);
132 const auto unique_it = std::unique(node_list.begin(), node_list.end());
133 node_list.resize(std::distance(node_list.begin(), unique_it));
136 std::vector<bool> node_list_flag(node_list.size(),
false);
137 std::vector<Point> node_list_point(node_list.size(),
Point(0.0, 0.0, 0.0));
139 for (
unsigned int i = 0; i < slc_bdry_side_list.size(); i++)
143 ->
side_ptr(std::get<1>(slc_bdry_side_list[i]))
147 ->
side_ptr(std::get<1>(slc_bdry_side_list[i]))
152 !(std::find(node_list.begin(), node_list.end(), side_id_0) == node_list.end());
154 !(std::find(node_list.begin(), node_list.end(), side_id_1) == node_list.end());
170 if (side_id_0_in && side_id_1_in)
174 std::get<1>(slc_bdry_side_list[i]),
175 std::get<2>(slc_bdry_side_list[i]));
177 else if (side_id_0_in && (side_node_0_remove != side_node_1_remove))
180 node_list_flag[std::distance(
181 node_list.begin(), std::find(node_list.begin(), node_list.end(), side_id_0))] =
true;
185 node_list_point[std::distance(node_list.begin(),
186 std::find(node_list.begin(), node_list.end(), side_id_0))] =
190 else if (side_id_1_in && (side_node_0_remove != side_node_1_remove))
193 node_list_flag[std::distance(
194 node_list.begin(), std::find(node_list.begin(), node_list.end(), side_id_1))] =
true;
198 node_list_point[std::distance(node_list.begin(),
199 std::find(node_list.begin(), node_list.end(), side_id_1))] =
205 for (
unsigned int i = 0; i < node_list.size(); i++)
210 if (node_list_flag[i])
219 (bdry_pars[1] * (bdry_pars[1] * x0 - bdry_pars[0] * y0) - bdry_pars[0] * bdry_pars[2]) /
220 (bdry_pars[0] * bdry_pars[0] + bdry_pars[1] * bdry_pars[1]);
222 (bdry_pars[0] * (-bdry_pars[1] * x0 + bdry_pars[0] * y0) - bdry_pars[1] * bdry_pars[2]) /
223 (bdry_pars[0] * bdry_pars[0] + bdry_pars[1] * bdry_pars[1]);
228 for (
auto elem_it =
mesh.active_subdomain_elements_begin(block_id_to_remove);
229 elem_it !=
mesh.active_subdomain_elements_end(block_id_to_remove);
235 std::vector<dof_id_type> zero_elems;
236 for (
auto elem_it =
mesh.elements_begin(); elem_it !=
mesh.elements_end(); elem_it++)
240 for (
unsigned int i = 0; i < (*elem_it)->n_sides(); i++)
242 if ((*elem_it)->neighbor_ptr(i) !=
nullptr)
244 boundary_info.
add_side((*elem_it)->neighbor_ptr(i),
245 ((*elem_it)->neighbor_ptr(i))->which_neighbor_am_i(*elem_it),
246 external_boundary_id);
247 boundary_info.
add_side((*elem_it)->neighbor_ptr(i),
248 ((*elem_it)->neighbor_ptr(i))->which_neighbor_am_i(*elem_it),
249 trimming_section_boundary_id);
252 zero_elems.push_back((*elem_it)->id());
255 for (
const auto & zero_elem : zero_elems)
269 const bool direction_param,
272 const Real tmp = px * param_1 + py * param_2 + param_3;
273 return direction_param ? tmp >= dis_tol : tmp <= dis_tol;
285 (param_12 * param_23 - param_22 * param_13) / (param_11 * param_22 - param_21 * param_12),
286 (param_13 * param_21 - param_23 * param_11) / (param_11 * param_22 - param_21 * param_12),
302 pt2(0) * pt1(1) - pt1(0) * pt2(1));
307 const std::set<subdomain_id_type> & subdomain_ids_set,
309 const SubdomainName tri_elem_subdomain_name_suffix)
316 : tri_elem_subdomain_shift;
318 tri_subdomain_id_shift,
319 "The TRI elements subdomain id to be assigned may exceed the numeric limit.");
321 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
322 std::vector<std::tuple<Elem *, unsigned int, bool, bool>> bad_elems_rec;
324 for (
auto & elem :
as_range(
mesh.active_elements_begin(),
mesh.active_elements_end()))
334 bad_elems_rec.push_back(std::make_tuple(elem, elem_angles.front().second,
false,
true));
340 bad_elems_rec.push_back(std::make_tuple(elem, elem_distances.front().second,
false,
false));
343 std::set<subdomain_id_type> new_subdomain_ids;
345 for (
const auto & bad_elem : bad_elems_rec)
347 std::vector<boundary_id_type> elem_bdry_container_0;
348 std::vector<boundary_id_type> elem_bdry_container_1;
349 std::vector<boundary_id_type> elem_bdry_container_2;
351 Elem * elem_0 = std::get<0>(bad_elem);
352 if (std::get<3>(bad_elem))
360 if ((elem_1 !=
nullptr || elem_2 !=
nullptr))
361 throw MooseException(
"The input mesh has degenerate quad element before trimming.");
365 elem_0, (std::get<1>(bad_elem) + 1) % elem_0->
n_vertices(), elem_bdry_container_1);
367 elem_0, (std::get<1>(bad_elem) + 2) % elem_0->
n_vertices(), elem_bdry_container_2);
369 elem_0, (std::get<1>(bad_elem) + 3) % elem_0->
n_vertices(), elem_bdry_container_0);
378 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
388 for (
auto bdry_id : elem_bdry_container_0)
389 boundary_info.
add_side(elem_Tri3, 2, bdry_id);
390 for (
auto bdry_id : elem_bdry_container_1)
391 boundary_info.
add_side(elem_Tri3, 0, bdry_id);
392 for (
auto bdry_id : elem_bdry_container_2)
393 boundary_info.
add_side(elem_Tri3, 1, bdry_id);
395 elem_Tri3->
subdomain_id() = elem_block_id + tri_subdomain_id_shift;
396 new_subdomain_ids.emplace(elem_block_id + tri_subdomain_id_shift);
398 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
402 for (
auto & nid : new_subdomain_ids)
406 (old_name.empty() ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
408 "_" + tri_elem_subdomain_name_suffix,
410 throw MooseException(
"The new subdomain name already exists in the mesh.");
412 (old_name.empty() ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
414 "_" + tri_elem_subdomain_name_suffix;
415 mooseWarning(
"Degenerate QUAD elements have been converted into TRI elements with a new " 419 return bad_elems_rec.size();
422 std::vector<std::pair<Real, unsigned int>>
425 std::vector<std::pair<Real, unsigned int>> angles;
426 const unsigned int n_vertices = elem.
n_vertices();
428 for (
unsigned int i = 0; i < n_vertices; i++)
437 angles.push_back(std::make_pair(acos(tmp), i));
439 std::sort(angles.begin(), angles.end(), std::greater<>());
443 std::vector<std::pair<Real, unsigned int>>
446 std::vector<std::pair<Real, unsigned int>> distances;
447 const unsigned int n_vertices = elem.
n_vertices();
449 for (
unsigned int i = 0; i < n_vertices; i++)
452 distances.push_back(std::make_pair(v1.
norm(), i));
454 std::sort(distances.begin(), distances.end());
461 const unsigned short node_shift,
469 const dof_id_type nid_1 = elem_old->node_ptr((1 + node_shift) % 3)->id();
470 const dof_id_type nid_2 = elem_old->node_ptr((2 + node_shift) % 3)->id();
472 const bool m1_side_flag =
477 const dof_id_type nid_m1 = m1_side_flag ? nid_3 : nid_4;
478 const dof_id_type nid_m2 = m1_side_flag ? nid_4 : nid_3;
483 std::vector<std::vector<boundary_id_type>> elem_side_list;
484 elem_side_list.resize(3);
485 for (
unsigned int i = 0; i < bdry_side_list.size(); i++)
487 if (std::get<0>(bdry_side_list[i]) == elem_id)
489 elem_side_list[(std::get<1>(bdry_side_list[i]) + 3 - node_shift) % 3].push_back(
490 std::get<2>(bdry_side_list[i]));
495 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
497 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
516 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
524 for (
const auto & side_info_0 : elem_side_list[0])
526 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
527 boundary_info.
add_side(elem_Tri3_1, 2, side_info_0);
529 for (
const auto & side_info_1 : elem_side_list[1])
530 boundary_info.
add_side(elem_Tri3_2, 2, side_info_1);
531 for (
const auto & side_info_2 : elem_side_list[2])
533 boundary_info.
add_side(elem_Tri3_0, 2, side_info_2);
534 boundary_info.
add_side(elem_Tri3_2, 0, side_info_2);
541 const unsigned short node_shift,
548 const dof_id_type nid_1 = elem_old->node_ptr((1 + node_shift) % 3)->id();
549 const dof_id_type nid_2 = elem_old->node_ptr((2 + node_shift) % 3)->id();
554 std::vector<std::vector<boundary_id_type>> elem_side_list;
555 elem_side_list.resize(3);
556 for (
unsigned int i = 0; i < bdry_side_list.size(); i++)
558 if (std::get<0>(bdry_side_list[i]) == elem_id)
560 elem_side_list[(std::get<1>(bdry_side_list[i]) + 3 - node_shift) % 3].push_back(
561 std::get<2>(bdry_side_list[i]));
566 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
568 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
582 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
589 for (
const auto & side_info_0 : elem_side_list[0])
590 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
591 for (
const auto & side_info_1 : elem_side_list[1])
593 boundary_info.
add_side(elem_Tri3_0, 1, side_info_1);
594 boundary_info.
add_side(elem_Tri3_1, 1, side_info_1);
596 for (
const auto & side_info_2 : elem_side_list[2])
597 boundary_info.
add_side(elem_Tri3_1, 2, side_info_2);
609 std::vector<std::vector<boundary_id_type>> elem_side_list;
610 elem_side_list.resize(4);
611 for (
unsigned int i = 0; i < bdry_side_list.size(); i++)
613 if (std::get<0>(bdry_side_list[i]) == elem_id)
615 elem_side_list[std::get<1>(bdry_side_list[i])].push_back(std::get<2>(bdry_side_list[i]));
625 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
627 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
632 if (
std::abs((*node_1 - *node_0).cross(*node_3 - *node_0).
norm() -
633 (*node_1 - *node_2).cross(*node_3 - *node_2).
norm()) >
634 std::abs((*node_0 - *node_1).cross(*node_2 - *node_1).
norm() -
635 (*node_0 - *node_3).cross(*node_2 - *node_3).
norm()))
648 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
655 for (
const auto & side_info_0 : elem_side_list[0])
656 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
657 for (
const auto & side_info_1 : elem_side_list[1])
658 boundary_info.
add_side(elem_Tri3_0, 1, side_info_1);
659 for (
const auto & side_info_2 : elem_side_list[2])
660 boundary_info.
add_side(elem_Tri3_1, 1, side_info_2);
661 for (
const auto & side_info_3 : elem_side_list[3])
662 boundary_info.
add_side(elem_Tri3_1, 2, side_info_3);
677 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
684 for (
const auto & side_info_0 : elem_side_list[0])
685 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
686 for (
const auto & side_info_1 : elem_side_list[1])
687 boundary_info.
add_side(elem_Tri3_1, 0, side_info_1);
688 for (
const auto & side_info_2 : elem_side_list[2])
689 boundary_info.
add_side(elem_Tri3_1, 1, side_info_2);
690 for (
const auto & side_info_3 : elem_side_list[3])
691 boundary_info.
add_side(elem_Tri3_0, 2, side_info_3);
697 const std::vector<Real> & cut_line_params,
699 const SubdomainName tri_elem_subdomain_name_suffix)
702 std::vector<dof_id_type> cross_elems_quad;
703 std::set<subdomain_id_type> new_subdomain_ids;
704 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
707 if ((*elem_it)->n_vertices() == 4)
709 std::vector<unsigned short> node_side_rec;
710 for (
unsigned int i = 0; i < 4; i++)
712 const Point v_point = (*elem_it)->point(i);
720 if (std::accumulate(node_side_rec.begin(), node_side_rec.end(), 0) != 4 &&
721 std::accumulate(node_side_rec.begin(), node_side_rec.end(), 0) > 0)
723 cross_elems_quad.push_back((*elem_it)->id());
724 new_subdomain_ids.emplace((*elem_it)->subdomain_id() + tri_subdomain_id_shift);
729 for (
const auto & cross_elem_quad : cross_elems_quad)
734 for (
auto & nid : new_subdomain_ids)
738 (old_name.empty() ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
740 "_" + tri_elem_subdomain_name_suffix,
742 throw MooseException(
"The new subdomain name already exists in the mesh.");
744 (old_name.empty() ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
746 "_" + tri_elem_subdomain_name_suffix;
747 mooseWarning(
"QUAD elements have been converted into TRI elements with a new " 756 const std::vector<Real> & cut_line_params,
761 std::vector<dof_id_type> cross_elems;
763 std::vector<std::vector<std::pair<dof_id_type, dof_id_type>>> node_pairs_vec;
765 std::vector<std::pair<dof_id_type, dof_id_type>> node_pairs_unique_vec;
766 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
769 std::vector<unsigned short> node_side_rec;
770 const auto n_vertices = (*elem_it)->n_vertices();
771 node_side_rec.resize(n_vertices);
772 for (
unsigned int i = 0; i < n_vertices; i++)
776 mooseError(
"MooseMeshXYCuttingUtils::lineRemoverCutElemTri() only works for 2D meshes in " 778 const Point v_point = (*elem_it)->point(i);
780 v_point(0), v_point(1), cut_line_params[0], cut_line_params[1], cut_line_params[2],
true);
782 if (std::accumulate(node_side_rec.begin(), node_side_rec.end(), 0) == (
int)node_side_rec.size())
784 (*elem_it)->subdomain_id() = block_id_to_remove;
786 else if (std::accumulate(node_side_rec.begin(), node_side_rec.end(), 0) > 0)
788 if ((*elem_it)->n_vertices() != 3 || (*elem_it)->n_nodes() != 3)
789 mooseError(
"The element across the cutting line is not TRI3, which is not supported.");
790 cross_elems.push_back((*elem_it)->id());
792 std::vector<std::pair<dof_id_type, dof_id_type>> node_pairs;
793 for (
unsigned int i = 0; i < node_side_rec.size(); i++)
796 if (node_side_rec[i] > 0 && node_side_rec[(i + 1) % node_side_rec.size()] == 0)
799 node_pairs.push_back(
800 std::make_pair((*elem_it)->node_ptr(i)->id(),
801 (*elem_it)->node_ptr((i + 1) % node_side_rec.size())->
id()));
802 node_pairs_unique_vec.push_back(node_pairs.back());
805 else if (node_side_rec[i] == 0 && node_side_rec[(i + 1) % node_side_rec.size()] > 0)
808 node_pairs.push_back(
809 std::make_pair((*elem_it)->node_ptr((i + 1) % node_side_rec.size())->
id(),
810 (*elem_it)->node_ptr(i)->id()));
811 node_pairs_unique_vec.push_back(node_pairs.back());
814 node_pairs_vec.push_back(node_pairs);
817 auto vec_ip = std::unique(node_pairs_unique_vec.begin(), node_pairs_unique_vec.end());
818 node_pairs_unique_vec.resize(std::distance(node_pairs_unique_vec.begin(), vec_ip));
821 std::vector<Node *> nodes_on_line;
823 std::vector<unsigned short> nodes_on_line_overlap;
824 for (
const auto & node_pair : node_pairs_unique_vec)
829 pt1, pt2, cut_line_params[0], cut_line_params[1], cut_line_params[2]);
832 nodes_on_line.push_back(
mesh.
node_ptr(node_pair.first));
833 nodes_on_line_overlap.push_back(1);
837 nodes_on_line.push_back(
mesh.
node_ptr(node_pair.second));
838 nodes_on_line_overlap.push_back(2);
843 nodes_on_line_overlap.push_back(0);
848 for (
unsigned int i = 0; i < cross_elems.size(); i++)
852 auto node_0 = cross_elem->
node_ptr(0);
853 auto node_1 = cross_elem->node_ptr(1);
854 auto node_2 = cross_elem->node_ptr(2);
855 const std::vector<dof_id_type> tri_nodes = {node_0->
id(), node_1->id(), node_2->id()};
857 const auto online_node_index_1 = std::distance(node_pairs_unique_vec.begin(),
858 std::find(node_pairs_unique_vec.begin(),
859 node_pairs_unique_vec.end(),
860 node_pairs_vec[i][0]));
861 const auto online_node_index_2 = std::distance(node_pairs_unique_vec.begin(),
862 std::find(node_pairs_unique_vec.begin(),
863 node_pairs_unique_vec.end(),
864 node_pairs_vec[i][1]));
865 auto node_3 = nodes_on_line[online_node_index_1];
866 auto node_4 = nodes_on_line[online_node_index_2];
867 const auto node_3_overlap_flag = nodes_on_line_overlap[online_node_index_1];
868 const auto node_4_overlap_flag = nodes_on_line_overlap[online_node_index_2];
870 if (node_3_overlap_flag == 0 && node_4_overlap_flag == 0)
873 const bool common_node_side = node_pairs_vec[i][0].first == node_pairs_vec[i][1].first;
875 common_node_side ? block_id_to_remove : cross_elem->subdomain_id();
877 common_node_side ? cross_elem->subdomain_id() : block_id_to_remove;
881 common_node_side ? node_pairs_vec[i][0].first : node_pairs_vec[i][0].second;
885 std::distance(tri_nodes.begin(),
886 std::find(tri_nodes.begin(), tri_nodes.end(), common_node_id)),
889 block_id_to_assign_1,
890 block_id_to_assign_2);
894 else if (node_3_overlap_flag > 0 && node_4_overlap_flag > 0)
899 cross_elem->vertex_average()(1),
905 : cross_elem->subdomain_id();
910 const auto node_3_finder = std::distance(
911 tri_nodes.begin(), std::find(tri_nodes.begin(), tri_nodes.end(), node_3->id()));
912 const auto node_4_finder = std::distance(
913 tri_nodes.begin(), std::find(tri_nodes.begin(), tri_nodes.end(), node_4->id()));
916 const dof_id_type node_id = node_3_finder < node_4_finder ? node_4->id() : node_3->id();
917 const auto node_finder =
std::min(node_3_finder, node_4_finder);
924 tri_nodes[(node_finder + 1) % 3] == node_pairs_vec[i][node_3_finder > node_4_finder].first
926 : cross_elem->subdomain_id(),
927 tri_nodes[(node_finder + 1) % 3] == node_pairs_vec[i][node_3_finder > node_4_finder].first
928 ? cross_elem->subdomain_id()
929 : block_id_to_remove);
939 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
942 if ((*elem_it)->subdomain_id() != block_id_to_remove)
944 for (
unsigned int j = 0; j < (*elem_it)->n_sides(); j++)
946 if ((*elem_it)->neighbor_ptr(j) !=
nullptr)
947 if ((*elem_it)->neighbor_ptr(j)->subdomain_id() == block_id_to_remove)
948 boundary_info.
add_side(*elem_it, j, new_boundary_id);
954 for (
auto elem_it =
mesh.active_subdomain_elements_begin(block_id_to_remove);
955 elem_it !=
mesh.active_subdomain_elements_end(block_id_to_remove);
963 const std::vector<Real> & cut_line_params,
965 const SubdomainName tri_elem_subdomain_name_suffix,
968 const bool improve_boundary_tri_elems)
971 quadToTriOnLine(
mesh, cut_line_params, tri_subdomain_id_shift, tri_elem_subdomain_name_suffix);
976 if (improve_boundary_tri_elems)
985 "MooseMeshXYCuttingUtils::boundaryTriElemImprover(): The boundary_to_improve provided " 986 "does not exist in the given mesh.");
995 std::map<dof_id_type, std::vector<std::tuple<dof_id_type, dof_id_type, dof_id_type>>>
997 for (
const auto & side : side_list)
999 if (std::get<2>(side) == boundary_to_improve)
1004 const auto key_node_id = elem->
node_id((std::get<1>(side) + 2) % 3);
1005 const auto value_elem_id = elem->
id();
1006 const auto value_node_id_1 = elem->
node_id(std::get<1>(side));
1007 const auto value_node_id_2 = elem->
node_id((std::get<1>(side) + 1) % 3);
1008 tri3_elem_info[key_node_id].push_back(
1009 std::make_tuple(value_elem_id, value_node_id_1, value_node_id_2));
1014 std::vector<dof_id_type> elems_to_remove;
1016 for (
const auto & tri_group : tri3_elem_info)
1020 std::vector<std::pair<dof_id_type, dof_id_type>> node_assm;
1021 std::vector<dof_id_type> elem_id_list;
1022 for (
const auto & tri : tri_group.second)
1024 node_assm.push_back(std::make_pair(std::get<1>(tri), std::get<2>(tri)));
1025 elem_id_list.push_back(std::get<0>(tri));
1027 std::vector<dof_id_type> ordered_node_list;
1028 std::vector<dof_id_type> ordered_elem_list;
1030 node_assm, elem_id_list, ordered_node_list, ordered_elem_list);
1037 std::vector<std::tuple<subdomain_id_type, std::vector<dof_id_type>,
unsigned int>> blocks_info;
1038 for (
const auto & elem_id : ordered_elem_list)
1040 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
1042 for (
unsigned int j = 0; j < n_elem_extra_ids; j++)
1044 if (!blocks_info.empty())
1047 exist_extra_ids == std::get<1>(blocks_info.back()))
1049 std::get<2>(blocks_info.back())++;
1053 blocks_info.push_back(
1057 unsigned int side_counter = 0;
1058 for (
const auto & block_info : blocks_info)
1060 const auto node_1 =
mesh.
node_ptr(ordered_node_list[side_counter]);
1062 const auto node_2 =
mesh.
node_ptr(ordered_node_list[side_counter + std::get<2>(block_info)]);
1064 const Point v1 = *node_1 - *node_0;
1065 const Point v2 = *node_2 - *node_0;
1066 const Real angle = std::acos(v1 * v2 / v1.
norm() / v2.
norm()) / M_PI * 180.0;
1067 const std::vector<dof_id_type> block_elems(ordered_elem_list.begin() + side_counter,
1068 ordered_elem_list.begin() + side_counter +
1069 std::get<2>(block_info));
1073 unsigned short side_id_0;
1074 unsigned short side_id_t;
1078 block_elems.front(),
1080 ordered_node_list[side_counter],
1085 ordered_node_list[side_counter + std::get<2>(block_info)],
1090 std::vector<boundary_id_type> side_0_boundary_ids;
1092 mesh.
elem_ptr(block_elems.front()), side_id_0, side_0_boundary_ids);
1093 std::vector<boundary_id_type> side_t_boundary_ids;
1103 if (std::get<2>(block_info) > 1)
1107 ordered_node_list[side_counter],
1108 ordered_node_list[side_counter + std::get<2>(block_info)],
1109 std::get<0>(block_info),
1110 std::get<1>(block_info),
1111 {boundary_to_improve},
1112 side_0_boundary_ids,
1113 side_t_boundary_ids);
1114 elems_to_remove.insert(elems_to_remove.end(), block_elems.begin(), block_elems.end());
1117 else if (angle < 135.0)
1120 const auto node_m =
mesh.
add_point((*node_1 + *node_2) / 2.0);
1123 ordered_node_list[side_counter],
1125 std::get<0>(block_info),
1126 std::get<1>(block_info),
1127 {boundary_to_improve},
1128 side_0_boundary_ids,
1129 std::vector<boundary_id_type>());
1133 ordered_node_list[side_counter + std::get<2>(block_info)],
1134 std::get<0>(block_info),
1135 std::get<1>(block_info),
1136 {boundary_to_improve},
1137 std::vector<boundary_id_type>(),
1138 side_t_boundary_ids);
1139 elems_to_remove.insert(elems_to_remove.end(), block_elems.begin(), block_elems.end());
1143 const auto node_m1 =
mesh.
add_point((*node_1 * 2.0 + *node_2) / 3.0);
1144 const auto node_m2 =
mesh.
add_point((*node_1 + *node_2 * 2.0) / 3.0);
1147 ordered_node_list[side_counter],
1149 std::get<0>(block_info),
1150 std::get<1>(block_info),
1151 {boundary_to_improve},
1152 side_0_boundary_ids,
1153 std::vector<boundary_id_type>());
1158 std::get<0>(block_info),
1159 std::get<1>(block_info),
1160 {boundary_to_improve},
1161 std::vector<boundary_id_type>(),
1162 std::vector<boundary_id_type>());
1166 ordered_node_list[side_counter + std::get<2>(block_info)],
1167 std::get<0>(block_info),
1168 std::get<1>(block_info),
1169 {boundary_to_improve},
1170 std::vector<boundary_id_type>(),
1171 side_t_boundary_ids);
1172 elems_to_remove.insert(elems_to_remove.end(), block_elems.begin(), block_elems.end());
1174 side_counter += std::get<2>(block_info);
1179 for (
const auto & elem_to_remove : elems_to_remove)
1190 const std::vector<dof_id_type> & extra_elem_ids,
1191 const std::vector<boundary_id_type> & boundary_ids_for_side_1,
1192 const std::vector<boundary_id_type> & boundary_ids_for_side_0,
1193 const std::vector<boundary_id_type> & boundary_ids_for_side_2)
1200 for (
const auto & boundary_id_for_side_0 : boundary_ids_for_side_0)
1201 boundary_info.
add_side(elem_Tri3_new, 0, boundary_id_for_side_0);
1202 for (
const auto & boundary_id_for_side_1 : boundary_ids_for_side_1)
1203 boundary_info.
add_side(elem_Tri3_new, 1, boundary_id_for_side_1);
1204 for (
const auto & boundary_id_for_side_2 : boundary_ids_for_side_2)
1205 boundary_info.
add_side(elem_Tri3_new, 2, boundary_id_for_side_2);
1208 for (
unsigned int j = 0; j < extra_elem_ids.size(); j++)
1219 unsigned short & side_id,
1223 for (
unsigned short i = 0; i < elem->
n_sides(); i++)
1225 if (elem->
side_ptr(i)->node_ptr(0)->id() == node_id_0 &&
1226 elem->
side_ptr(i)->node_ptr(1)->id() == node_id_1)
1232 else if (elem->
side_ptr(i)->node_ptr(0)->id() == node_id_1 &&
1233 elem->
side_ptr(i)->node_ptr(1)->id() == node_id_0)
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
void triElemSplitter(libMesh::ReplicatedMesh &mesh, const dof_id_type elem_id, const unsigned short node_shift, const dof_id_type nid_3, const dof_id_type nid_4, const subdomain_id_type single_elem_side_id, const subdomain_id_type double_elem_side_id)
Split a TRI3 element into three TRI3 elements based on two nodes on the two sides of the triangle...
void boundaryTriElemImprover(libMesh::ReplicatedMesh &mesh, const boundary_id_type boundary_to_improve)
Improve the element quality of the boundary TRI3 elements of the given boundary.
void lineRemoverCutElem(libMesh::ReplicatedMesh &mesh, const std::vector< Real > &cut_line_params, const dof_id_type tri_subdomain_id_shift, const SubdomainName tri_elem_subdomain_name_suffix, const subdomain_id_type block_id_to_remove, const boundary_id_type new_boundary_id, const bool improve_boundary_tri_elems=false)
Trim the 2D mesh by removing all the elements on one side of the given line.
std::vector< std::pair< Real, unsigned int > > vertex_angles(const Elem &elem)
void makeOrderedNodeList(std::vector< std::pair< dof_id_type, dof_id_type >> &node_assm, std::vector< dof_id_type > &elem_id_list, std::vector< dof_id_type > &midpoint_node_list, std::vector< dof_id_type > &ordered_node_list, std::vector< dof_id_type > &ordered_elem_id_list)
Convert a list of sides in the form of a vector of pairs of node ids into a list of ordered nodes bas...
virtual Node *& set_node(const unsigned int i)
auto norm() const -> decltype(std::norm(Real()))
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Point twoPointandLineIntersection(const Point &pt1, const Point &pt2, const Real param_1, const Real param_2, const Real param_3)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
static constexpr Real TOLERANCE
void makeImprovedTriElement(libMesh::ReplicatedMesh &mesh, const dof_id_type node_id_0, const dof_id_type node_id_1, const dof_id_type node_id_2, const subdomain_id_type subdomain_id, const std::vector< dof_id_type > &extra_elem_ids, const std::vector< boundary_id_type > &boundary_ids_for_side_1=std::vector< boundary_id_type >(), const std::vector< boundary_id_type > &boundary_ids_for_side_0=std::vector< boundary_id_type >(), const std::vector< boundary_id_type > &boundary_ids_for_side_2=std::vector< boundary_id_type >())
Make a TRI3 element with the given node ids and subdomain id with boundary information.
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
const boundary_id_type side_id
unsigned int n_elem_integers() const
void quadElemSplitter(libMesh::ReplicatedMesh &mesh, const dof_id_type elem_id, const subdomain_id_type tri_elem_subdomain_shift)
Split a QUAD4 element into two TRI3 elements.
void lineRemoverMoveNode(libMesh::ReplicatedMesh &mesh, const std::vector< Real > &bdry_pars, const subdomain_id_type block_id_to_remove, const std::set< subdomain_id_type > &subdomain_ids_set, const boundary_id_type trimming_section_boundary_id, const boundary_id_type external_boundary_id, const std::vector< boundary_id_type > &other_boundaries_to_conform=std::vector< boundary_id_type >(), const bool assign_ext_to_new=false, const bool side_to_remove=true)
Removes all the elements on one side of a given line and deforms the elements intercepted by the line...
bool hasBoundaryID(const MeshBase &input_mesh, const BoundaryID id)
Whether a particular boundary ID exists in the mesh.
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const BoundaryInfo & get_boundary_info() const
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
auto max(const L &left, const R &right)
void build_side_list(std::vector< dof_id_type > &element_id_list, std::vector< unsigned short int > &side_list, std::vector< boundary_id_type > &bc_id_list) const
const SubdomainID INVALID_BLOCK_ID
void clear_boundary_node_ids()
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true)=0
virtual void delete_elem(Elem *e)=0
std::vector< std::pair< Real, unsigned int > > vertex_distances(const Elem &elem)
virtual Elem * add_elem(Elem *e)=0
bool elemSideLocator(libMesh::ReplicatedMesh &mesh, const dof_id_type elem_id, const dof_id_type node_id_0, const dof_id_type node_id_1, unsigned short &side_id, bool &is_inverse)
Check if there is a side in an element that contains the given pair of nodes; if yes, also find the side id and the direction of the two nodes in the side.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
bool quasiTriElementsFixer(libMesh::ReplicatedMesh &mesh, const std::set< subdomain_id_type > &subdomain_ids_set, const subdomain_id_type tri_elem_subdomain_shift=Moose::INVALID_BLOCK_ID, const SubdomainName tri_elem_subdomain_name_suffix="tri")
Fixes degenerate QUAD elements created by the hexagonal mesh trimming by converting them into TRI ele...
std::string & subdomain_name(subdomain_id_type id)
virtual const Elem * elem_ptr(const dof_id_type i) const=0
virtual unsigned int n_sides() const=0
const Elem * neighbor_ptr(unsigned int i) const
void remove_side(const Elem *elem, const unsigned short int side)
Provides a way for users to bail out of the current solve.
virtual unsigned int n_vertices() const=0
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual bool contract()=0
virtual std::unique_ptr< Elem > side_ptr(unsigned int i)=0
subdomain_id_type subdomain_id() const
const Node * node_ptr(const unsigned int i) const
bool lineSideDeterminator(const Real px, const Real py, const Real param_1, const Real param_2, const Real param_3, const bool direction_param, const Real dis_tol=libMesh::TOLERANCE)
Determines whether a point on XY-plane is on the side of a given line that needs to be removed...
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
void quadToTriOnLine(libMesh::ReplicatedMesh &mesh, const std::vector< Real > &cut_line_params, const dof_id_type tri_subdomain_id_shift, const SubdomainName tri_elem_subdomain_name_suffix)
Convert all the QUAD4 elements in the mesh that are crossed by the given line into TRI3 elements...
virtual const Node * node_ptr(const dof_id_type i) const=0
auto min(const L &left, const R &right)
virtual ElemType type() const=0
dof_id_type node_id(const unsigned int i) const
void set_extra_integer(const unsigned int index, const dof_id_type value)
dof_id_type get_extra_integer(const unsigned int index) const
Point twoLineIntersection(const Real param_11, const Real param_12, const Real param_13, const Real param_21, const Real param_22, const Real param_23)
Calculates the intersection Point of two given straight lines.
void lineRemoverCutElemTri(libMesh::ReplicatedMesh &mesh, const std::vector< Real > &cut_line_params, const subdomain_id_type block_id_to_remove, const boundary_id_type new_boundary_id)
Trim the 2D mesh by removing all the elements on one side of the given line.