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;
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 (
const auto i :
make_range((*elem_it)->n_vertices()))
60 if (!MooseUtils::absoluteFuzzyEqual((*elem_it)->point(i)(2), 0.0))
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 (
const auto i :
make_range((*elem_it)->n_sides()))
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 (
const auto i :
index_range(slc_bdry_side_list))
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))] =
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++)
238 if (MooseUtils::absoluteFuzzyEqual((*elem_it)->volume(), 0.0))
240 for (
const auto i :
make_range((*elem_it)->n_sides()))
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)
271 return std::abs(px * param_1 + py * param_2 + param_3) <= dis_tol;
280 const bool direction_param,
283 const Real tmp = px * param_1 + py * param_2 + param_3;
284 return direction_param ? tmp >= dis_tol : tmp <= dis_tol;
296 (param_12 * param_23 - param_22 * param_13) / (param_11 * param_22 - param_21 * param_12),
297 (param_13 * param_21 - param_23 * param_11) / (param_11 * param_22 - param_21 * param_12),
313 pt2(0) * pt1(1) - pt1(0) * pt2(1));
318 const std::set<subdomain_id_type> & subdomain_ids_set,
320 const SubdomainName tri_elem_subdomain_name_suffix)
327 : tri_elem_subdomain_shift;
328 mooseAssert(std::numeric_limits<subdomain_id_type>::max() - max_subdomain_id >
329 tri_subdomain_id_shift,
330 "The TRI elements subdomain id to be assigned may exceed the numeric limit.");
332 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
333 std::vector<std::tuple<Elem *, unsigned int, bool, bool>> bad_elems_rec;
335 for (
auto & elem :
as_range(
mesh.active_elements_begin(),
mesh.active_elements_end()))
343 if (MooseUtils::absoluteFuzzyEqual(elem_angles.front().first, M_PI, 0.001))
345 bad_elems_rec.push_back(std::make_tuple(elem, elem_angles.front().second,
false,
true));
349 if (MooseUtils::absoluteFuzzyEqual(elem_distances.front().first, 0.0))
351 bad_elems_rec.push_back(std::make_tuple(elem, elem_distances.front().second,
false,
false));
354 std::set<subdomain_id_type> new_subdomain_ids;
356 for (
const auto & bad_elem : bad_elems_rec)
358 std::vector<boundary_id_type> elem_bdry_container_0;
359 std::vector<boundary_id_type> elem_bdry_container_1;
360 std::vector<boundary_id_type> elem_bdry_container_2;
362 Elem * elem_0 = std::get<0>(bad_elem);
363 if (std::get<3>(bad_elem))
371 if ((elem_1 !=
nullptr || elem_2 !=
nullptr))
372 throw MooseException(
"The input mesh has degenerate quad element before trimming.");
376 elem_0, (std::get<1>(bad_elem) + 1) % elem_0->
n_vertices(), elem_bdry_container_1);
378 elem_0, (std::get<1>(bad_elem) + 2) % elem_0->
n_vertices(), elem_bdry_container_2);
380 elem_0, (std::get<1>(bad_elem) + 3) % elem_0->
n_vertices(), elem_bdry_container_0);
389 for (
const auto j :
make_range(n_elem_extra_ids))
399 for (
auto bdry_id : elem_bdry_container_0)
400 boundary_info.
add_side(elem_Tri3, 2, bdry_id);
401 for (
auto bdry_id : elem_bdry_container_1)
402 boundary_info.
add_side(elem_Tri3, 0, bdry_id);
403 for (
auto bdry_id : elem_bdry_container_2)
404 boundary_info.
add_side(elem_Tri3, 1, bdry_id);
406 elem_Tri3->
subdomain_id() = elem_block_id + tri_subdomain_id_shift;
407 new_subdomain_ids.emplace(elem_block_id + tri_subdomain_id_shift);
409 for (
const auto j :
make_range(n_elem_extra_ids))
413 for (
auto & nid : new_subdomain_ids)
417 (old_name.empty() ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
419 "_" + tri_elem_subdomain_name_suffix,
421 throw MooseException(
"The new subdomain name already exists in the mesh.");
424 ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
426 "_" + tri_elem_subdomain_name_suffix);
427 mooseWarning(
"Degenerate QUAD elements have been converted into TRI elements with a new "
431 return bad_elems_rec.size();
434std::vector<std::pair<Real, unsigned int>>
437 std::vector<std::pair<Real, unsigned int>> angles;
438 const unsigned int n_vertices = elem.
n_vertices();
449 angles.push_back(std::make_pair(acos(tmp), i));
451 std::sort(angles.begin(), angles.end(), std::greater<>());
455std::vector<std::pair<Real, unsigned int>>
458 std::vector<std::pair<Real, unsigned int>> distances;
459 const unsigned int n_vertices = elem.
n_vertices();
464 distances.push_back(std::make_pair(v1.
norm(), i));
466 std::sort(distances.begin(), distances.end());
473 const unsigned short node_shift,
481 const dof_id_type nid_1 = elem_old->node_ptr((1 + node_shift) % 3)->id();
482 const dof_id_type nid_2 = elem_old->node_ptr((2 + node_shift) % 3)->id();
484 const bool m1_side_flag =
489 const dof_id_type nid_m1 = m1_side_flag ? nid_3 : nid_4;
490 const dof_id_type nid_m2 = m1_side_flag ? nid_4 : nid_3;
495 std::vector<std::vector<boundary_id_type>> elem_side_list;
496 elem_side_list.resize(3);
499 if (std::get<0>(bdry_side_list[i]) == elem_id)
501 elem_side_list[(std::get<1>(bdry_side_list[i]) + 3 - node_shift) % 3].push_back(
502 std::get<2>(bdry_side_list[i]));
507 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
509 for (
const auto j :
make_range(n_elem_extra_ids))
528 for (
const auto j :
make_range(n_elem_extra_ids))
536 for (
const auto & side_info_0 : elem_side_list[0])
538 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
539 boundary_info.
add_side(elem_Tri3_1, 2, side_info_0);
541 for (
const auto & side_info_1 : elem_side_list[1])
542 boundary_info.
add_side(elem_Tri3_2, 2, side_info_1);
543 for (
const auto & side_info_2 : elem_side_list[2])
545 boundary_info.
add_side(elem_Tri3_0, 2, side_info_2);
546 boundary_info.
add_side(elem_Tri3_2, 0, side_info_2);
553 const unsigned short node_shift,
560 const dof_id_type nid_1 = elem_old->node_ptr((1 + node_shift) % 3)->id();
561 const dof_id_type nid_2 = elem_old->node_ptr((2 + node_shift) % 3)->id();
566 std::vector<std::vector<boundary_id_type>> elem_side_list;
567 elem_side_list.resize(3);
570 if (std::get<0>(bdry_side_list[i]) == elem_id)
572 elem_side_list[(std::get<1>(bdry_side_list[i]) + 3 - node_shift) % 3].push_back(
573 std::get<2>(bdry_side_list[i]));
578 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
580 for (
const auto j :
make_range(n_elem_extra_ids))
594 for (
const auto j :
make_range(n_elem_extra_ids))
601 for (
const auto & side_info_0 : elem_side_list[0])
602 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
603 for (
const auto & side_info_1 : elem_side_list[1])
605 boundary_info.
add_side(elem_Tri3_0, 1, side_info_1);
606 boundary_info.
add_side(elem_Tri3_1, 1, side_info_1);
608 for (
const auto & side_info_2 : elem_side_list[2])
609 boundary_info.
add_side(elem_Tri3_1, 2, side_info_2);
621 std::vector<std::vector<boundary_id_type>> elem_side_list;
622 elem_side_list.resize(4);
625 if (std::get<0>(bdry_side_list[i]) == elem_id)
627 elem_side_list[std::get<1>(bdry_side_list[i])].push_back(std::get<2>(bdry_side_list[i]));
637 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
639 for (
const auto j :
make_range(n_elem_extra_ids))
644 if (std::abs((*node_1 - *node_0).cross(*node_3 - *node_0).norm() -
645 (*node_1 - *node_2).cross(*node_3 - *node_2).norm()) >
646 std::abs((*node_0 - *node_1).cross(*node_2 - *node_1).norm() -
647 (*node_0 - *node_3).cross(*node_2 - *node_3).norm()))
660 for (
const auto j :
make_range(n_elem_extra_ids))
667 for (
const auto & side_info_0 : elem_side_list[0])
668 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
669 for (
const auto & side_info_1 : elem_side_list[1])
670 boundary_info.
add_side(elem_Tri3_0, 1, side_info_1);
671 for (
const auto & side_info_2 : elem_side_list[2])
672 boundary_info.
add_side(elem_Tri3_1, 1, side_info_2);
673 for (
const auto & side_info_3 : elem_side_list[3])
674 boundary_info.
add_side(elem_Tri3_1, 2, side_info_3);
689 for (
const auto j :
make_range(n_elem_extra_ids))
696 for (
const auto & side_info_0 : elem_side_list[0])
697 boundary_info.
add_side(elem_Tri3_0, 0, side_info_0);
698 for (
const auto & side_info_1 : elem_side_list[1])
699 boundary_info.
add_side(elem_Tri3_1, 0, side_info_1);
700 for (
const auto & side_info_2 : elem_side_list[2])
701 boundary_info.
add_side(elem_Tri3_1, 1, side_info_2);
702 for (
const auto & side_info_3 : elem_side_list[3])
703 boundary_info.
add_side(elem_Tri3_0, 2, side_info_3);
709 const std::vector<Real> & cut_line_params,
711 const SubdomainName tri_elem_subdomain_name_suffix)
714 std::vector<dof_id_type> cross_elems_quad;
715 std::set<subdomain_id_type> new_subdomain_ids;
716 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
719 if ((*elem_it)->n_vertices() == 4)
721 std::vector<unsigned short> node_side_rec;
724 const Point v_point = (*elem_it)->point(i);
726 v_point(0), v_point(1), cut_line_params[0], cut_line_params[1], cut_line_params[2]))
740 const auto num_nodes = std::accumulate(node_side_rec.begin(), node_side_rec.end(), 0);
741 if (num_nodes != (
int)node_side_rec.size() && num_nodes > 0)
743 cross_elems_quad.push_back((*elem_it)->id());
744 new_subdomain_ids.emplace((*elem_it)->subdomain_id() + tri_subdomain_id_shift);
749 for (
const auto & cross_elem_quad : cross_elems_quad)
754 for (
auto & nid : new_subdomain_ids)
758 (old_name.empty() ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
760 "_" + tri_elem_subdomain_name_suffix,
762 throw MooseException(
"The new subdomain name already exists in the mesh.");
765 ? (SubdomainName)(std::to_string(nid - tri_subdomain_id_shift))
767 "_" + tri_elem_subdomain_name_suffix);
768 mooseWarning(
"QUAD elements have been converted into TRI elements with a new "
777 const std::vector<Real> & cut_line_params,
782 std::vector<dof_id_type> cross_elems;
784 std::vector<std::vector<std::pair<dof_id_type, dof_id_type>>> node_pairs_vec;
786 std::vector<std::pair<dof_id_type, dof_id_type>> node_pairs_unique_vec;
787 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
790 const auto n_vertices = (*elem_it)->n_vertices();
791 unsigned int n_points_on_line = 0;
792 std::vector<unsigned short> node_side_rec(n_vertices, 0);
796 if (!MooseUtils::absoluteFuzzyEqual((*elem_it)->point(i)(2), 0.0))
797 mooseError(
"MooseMeshXYCuttingUtils::lineRemoverCutElemTri() only works for 2D meshes in "
799 const Point v_point = (*elem_it)->point(i);
801 v_point(0), v_point(1), cut_line_params[0], cut_line_params[1], cut_line_params[2]))
817 const unsigned int num_nodes = std::accumulate(node_side_rec.begin(), node_side_rec.end(), 0);
818 if (num_nodes == node_side_rec.size() - n_points_on_line)
820 (*elem_it)->subdomain_id() = block_id_to_remove;
822 else if (num_nodes > 0)
824 if ((*elem_it)->n_vertices() != 3 || (*elem_it)->n_nodes() != 3)
825 mooseError(
"The element across the cutting line is not TRI3, which is not supported.");
826 cross_elems.push_back((*elem_it)->id());
828 std::vector<std::pair<dof_id_type, dof_id_type>> node_pairs;
832 if (node_side_rec[i] > 0 && node_side_rec[(i + 1) % node_side_rec.size()] == 0)
835 node_pairs.push_back(
836 std::make_pair((*elem_it)->node_ptr(i)->id(),
837 (*elem_it)->node_ptr((i + 1) % node_side_rec.size())->id()));
838 node_pairs_unique_vec.push_back(node_pairs.back());
841 else if (node_side_rec[i] == 0 && node_side_rec[(i + 1) % node_side_rec.size()] > 0)
844 node_pairs.push_back(
845 std::make_pair((*elem_it)->node_ptr((i + 1) % node_side_rec.size())->id(),
846 (*elem_it)->node_ptr(i)->id()));
847 node_pairs_unique_vec.push_back(node_pairs.back());
850 node_pairs_vec.push_back(node_pairs);
853 auto vec_ip = std::unique(node_pairs_unique_vec.begin(), node_pairs_unique_vec.end());
854 node_pairs_unique_vec.resize(std::distance(node_pairs_unique_vec.begin(), vec_ip));
857 std::vector<Node *> nodes_on_line;
859 std::vector<unsigned short> nodes_on_line_overlap;
860 for (
const auto & node_pair : node_pairs_unique_vec)
865 pt1, pt2, cut_line_params[0], cut_line_params[1], cut_line_params[2]);
868 nodes_on_line.push_back(
mesh.
node_ptr(node_pair.first));
869 nodes_on_line_overlap.push_back(1);
873 nodes_on_line.push_back(
mesh.
node_ptr(node_pair.second));
874 nodes_on_line_overlap.push_back(2);
879 nodes_on_line_overlap.push_back(0);
888 auto node_0 = cross_elem->
node_ptr(0);
889 auto node_1 = cross_elem->node_ptr(1);
890 auto node_2 = cross_elem->node_ptr(2);
891 const std::vector<dof_id_type> tri_nodes = {node_0->
id(), node_1->id(), node_2->id()};
893 const auto online_node_index_1 = std::distance(node_pairs_unique_vec.begin(),
894 std::find(node_pairs_unique_vec.begin(),
895 node_pairs_unique_vec.end(),
896 node_pairs_vec[i][0]));
897 const auto online_node_index_2 = std::distance(node_pairs_unique_vec.begin(),
898 std::find(node_pairs_unique_vec.begin(),
899 node_pairs_unique_vec.end(),
900 node_pairs_vec[i][1]));
901 auto node_3 = nodes_on_line[online_node_index_1];
902 auto node_4 = nodes_on_line[online_node_index_2];
903 const auto node_3_overlap_flag = nodes_on_line_overlap[online_node_index_1];
904 const auto node_4_overlap_flag = nodes_on_line_overlap[online_node_index_2];
906 if (node_3_overlap_flag == 0 && node_4_overlap_flag == 0)
909 const bool common_node_side = node_pairs_vec[i][0].first == node_pairs_vec[i][1].first;
911 common_node_side ? block_id_to_remove : cross_elem->subdomain_id();
913 common_node_side ? cross_elem->subdomain_id() : block_id_to_remove;
917 common_node_side ? node_pairs_vec[i][0].first : node_pairs_vec[i][0].second;
921 std::distance(tri_nodes.begin(),
922 std::find(tri_nodes.begin(), tri_nodes.end(), common_node_id)),
925 block_id_to_assign_1,
926 block_id_to_assign_2);
930 else if (node_3_overlap_flag > 0 && node_4_overlap_flag > 0)
935 cross_elem->vertex_average()(1),
941 : cross_elem->subdomain_id();
946 const auto node_3_finder = std::distance(
947 tri_nodes.begin(), std::find(tri_nodes.begin(), tri_nodes.end(), node_3->id()));
948 const auto node_4_finder = std::distance(
949 tri_nodes.begin(), std::find(tri_nodes.begin(), tri_nodes.end(), node_4->id()));
952 const dof_id_type node_id = node_3_finder < node_4_finder ? node_4->id() : node_3->id();
953 const auto node_finder = std::min(node_3_finder, node_4_finder);
960 tri_nodes[(node_finder + 1) % 3] == node_pairs_vec[i][node_3_finder > node_4_finder].first
962 : cross_elem->subdomain_id(),
963 tri_nodes[(node_finder + 1) % 3] == node_pairs_vec[i][node_3_finder > node_4_finder].first
964 ? cross_elem->subdomain_id()
965 : block_id_to_remove);
975 for (
auto elem_it =
mesh.active_elements_begin(); elem_it !=
mesh.active_elements_end();
978 if ((*elem_it)->subdomain_id() != block_id_to_remove)
980 for (
const auto j :
make_range((*elem_it)->n_sides()))
982 if ((*elem_it)->neighbor_ptr(j) !=
nullptr)
983 if ((*elem_it)->neighbor_ptr(j)->subdomain_id() == block_id_to_remove)
984 boundary_info.
add_side(*elem_it, j, new_boundary_id);
990 for (
auto elem_it =
mesh.active_subdomain_elements_begin(block_id_to_remove);
991 elem_it !=
mesh.active_subdomain_elements_end(block_id_to_remove);
999 const std::vector<Real> & cut_line_params,
1001 const SubdomainName tri_elem_subdomain_name_suffix,
1004 const bool improve_boundary_tri_elems)
1007 quadToTriOnLine(
mesh, cut_line_params, tri_subdomain_id_shift, tri_elem_subdomain_name_suffix);
1012 if (improve_boundary_tri_elems)
1021 "MooseMeshXYCuttingUtils::boundaryTriElemImprover(): The boundary_to_improve provided "
1022 "does not exist in the given mesh.");
1031 std::map<dof_id_type, std::vector<std::tuple<dof_id_type, dof_id_type, dof_id_type>>>
1033 for (
const auto & side : side_list)
1035 if (std::get<2>(side) == boundary_to_improve)
1040 const auto key_node_id = elem->
node_id((std::get<1>(side) + 2) % 3);
1041 const auto value_elem_id = elem->
id();
1042 const auto value_node_id_1 = elem->
node_id(std::get<1>(side));
1043 const auto value_node_id_2 = elem->
node_id((std::get<1>(side) + 1) % 3);
1044 tri3_elem_info[key_node_id].push_back(
1045 std::make_tuple(value_elem_id, value_node_id_1, value_node_id_2));
1050 std::vector<dof_id_type> elems_to_remove;
1052 for (
const auto & tri_group : tri3_elem_info)
1056 std::vector<std::pair<dof_id_type, dof_id_type>> node_assm;
1057 std::vector<dof_id_type> elem_id_list;
1058 for (
const auto & tri : tri_group.second)
1060 node_assm.push_back(std::make_pair(std::get<1>(tri), std::get<2>(tri)));
1061 elem_id_list.push_back(std::get<0>(tri));
1063 std::vector<dof_id_type> ordered_node_list;
1064 std::vector<dof_id_type> ordered_elem_list;
1066 node_assm, elem_id_list, ordered_node_list, ordered_elem_list);
1073 std::vector<std::tuple<subdomain_id_type, std::vector<dof_id_type>,
unsigned int>> blocks_info;
1074 for (
const auto & elem_id : ordered_elem_list)
1076 std::vector<dof_id_type> exist_extra_ids(n_elem_extra_ids);
1078 for (
const auto j :
make_range(n_elem_extra_ids))
1080 if (!blocks_info.empty())
1083 exist_extra_ids == std::get<1>(blocks_info.back()))
1085 std::get<2>(blocks_info.back())++;
1089 blocks_info.push_back(
1093 unsigned int side_counter = 0;
1094 for (
const auto & block_info : blocks_info)
1096 const auto node_1 =
mesh.
node_ptr(ordered_node_list[side_counter]);
1098 const auto node_2 =
mesh.
node_ptr(ordered_node_list[side_counter + std::get<2>(block_info)]);
1100 const Point v1 = *node_1 - *node_0;
1101 const Point v2 = *node_2 - *node_0;
1102 const Real angle = std::acos(v1 * v2 / v1.
norm() / v2.
norm()) / M_PI * 180.0;
1103 const std::vector<dof_id_type> block_elems(ordered_elem_list.begin() + side_counter,
1104 ordered_elem_list.begin() + side_counter +
1105 std::get<2>(block_info));
1109 unsigned short side_id_0;
1110 unsigned short side_id_t;
1114 block_elems.front(),
1116 ordered_node_list[side_counter],
1121 ordered_node_list[side_counter + std::get<2>(block_info)],
1126 std::vector<boundary_id_type> side_0_boundary_ids;
1128 mesh.
elem_ptr(block_elems.front()), side_id_0, side_0_boundary_ids);
1129 std::vector<boundary_id_type> side_t_boundary_ids;
1139 if (std::get<2>(block_info) > 1)
1143 ordered_node_list[side_counter],
1144 ordered_node_list[side_counter + std::get<2>(block_info)],
1145 std::get<0>(block_info),
1146 std::get<1>(block_info),
1147 {boundary_to_improve},
1148 side_0_boundary_ids,
1149 side_t_boundary_ids);
1150 elems_to_remove.insert(elems_to_remove.end(), block_elems.begin(), block_elems.end());
1153 else if (angle < 135.0)
1156 const auto node_m =
mesh.
add_point((*node_1 + *node_2) / 2.0);
1159 ordered_node_list[side_counter],
1161 std::get<0>(block_info),
1162 std::get<1>(block_info),
1163 {boundary_to_improve},
1164 side_0_boundary_ids,
1165 std::vector<boundary_id_type>());
1169 ordered_node_list[side_counter + std::get<2>(block_info)],
1170 std::get<0>(block_info),
1171 std::get<1>(block_info),
1172 {boundary_to_improve},
1173 std::vector<boundary_id_type>(),
1174 side_t_boundary_ids);
1175 elems_to_remove.insert(elems_to_remove.end(), block_elems.begin(), block_elems.end());
1179 const auto node_m1 =
mesh.
add_point((*node_1 * 2.0 + *node_2) / 3.0);
1180 const auto node_m2 =
mesh.
add_point((*node_1 + *node_2 * 2.0) / 3.0);
1183 ordered_node_list[side_counter],
1185 std::get<0>(block_info),
1186 std::get<1>(block_info),
1187 {boundary_to_improve},
1188 side_0_boundary_ids,
1189 std::vector<boundary_id_type>());
1194 std::get<0>(block_info),
1195 std::get<1>(block_info),
1196 {boundary_to_improve},
1197 std::vector<boundary_id_type>(),
1198 std::vector<boundary_id_type>());
1202 ordered_node_list[side_counter + std::get<2>(block_info)],
1203 std::get<0>(block_info),
1204 std::get<1>(block_info),
1205 {boundary_to_improve},
1206 std::vector<boundary_id_type>(),
1207 side_t_boundary_ids);
1208 elems_to_remove.insert(elems_to_remove.end(), block_elems.begin(), block_elems.end());
1210 side_counter += std::get<2>(block_info);
1215 for (
const auto & elem_to_remove : elems_to_remove)
1226 const std::vector<dof_id_type> & extra_elem_ids,
1227 const std::vector<boundary_id_type> & boundary_ids_for_side_1,
1228 const std::vector<boundary_id_type> & boundary_ids_for_side_0,
1229 const std::vector<boundary_id_type> & boundary_ids_for_side_2)
1236 for (
const auto & boundary_id_for_side_0 : boundary_ids_for_side_0)
1237 boundary_info.
add_side(elem_Tri3_new, 0, boundary_id_for_side_0);
1238 for (
const auto & boundary_id_for_side_1 : boundary_ids_for_side_1)
1239 boundary_info.
add_side(elem_Tri3_new, 1, boundary_id_for_side_1);
1240 for (
const auto & boundary_id_for_side_2 : boundary_ids_for_side_2)
1241 boundary_info.
add_side(elem_Tri3_new, 2, boundary_id_for_side_2);
1255 unsigned short & side_id,
1259 for (
unsigned short i = 0; i < elem->
n_sides(); i++)
1261 if (elem->
side_ptr(i)->node_ptr(0)->id() == node_id_0 &&
1262 elem->
side_ptr(i)->node_ptr(1)->id() == node_id_1)
1268 else if (elem->
side_ptr(i)->node_ptr(0)->id() == node_id_1 &&
1269 elem->
side_ptr(i)->node_ptr(1)->id() == node_id_0)
void mooseWarning(Args &&... args)
Emit a warning message with the given stringified, concatenated args.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Provides a way for users to bail out of the current solve.
std::vector< BCTuple > build_side_list(BCTupleSortBy sort_by=BCTupleSortBy::ELEM_ID) const
void boundary_ids(const Node *node, std::vector< boundary_id_type > &vec_to_fill) const
void clear_boundary_node_ids()
void add_side(const dof_id_type elem, const unsigned short int side, const boundary_id_type id)
void remove_side(const Elem *elem, const unsigned short int side)
dof_id_type get_extra_integer(const unsigned int index) const
void set_extra_integer(const unsigned int index, const dof_id_type value)
virtual Node *& set_node(const unsigned int i)
virtual unsigned int n_vertices() const=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
virtual ElemType type() const=0
virtual unsigned int n_sides() const=0
dof_id_type node_id(const unsigned int i) const
const Elem * neighbor_ptr(unsigned int i) const
void set_subdomain_name(subdomain_id_type id, const std::string &name, bool synchronous=false)
virtual bool contract()=0
unsigned int n_elem_integers() const
const BoundaryInfo & get_boundary_info() const
virtual const Node * node_ptr(const dof_id_type i) const=0
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
virtual void delete_elem(Elem *e)=0
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
virtual const Elem * elem_ptr(const dof_id_type i) const=0
virtual Elem * add_elem(Elem *e)=0
std::string & subdomain_name(subdomain_id_type id)
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true, const bool assert_valid=true)=0
bool hasBoundaryID(const MeshBase &input_mesh, const BoundaryID id)
Whether a particular boundary ID exists in the mesh.
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...
SubdomainID getSubdomainID(const SubdomainName &subdomain_name, const MeshBase &mesh)
Gets the subdomain ID associated with the given SubdomainName.
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.
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.
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 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,...
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.
Point twoPointandLineIntersection(const Point &pt1, const Point &pt2, const Real param_1, const Real param_2, const Real param_3)
Calculates the intersection Point of a straight line defined by two given points and another straight...
bool pointOnLine(const Real px, const Real py, const Real param_1, const Real param_2, const Real param_3, const Real dis_tol=libMesh::TOLERANCE)
Determines whether a point on XY-plane is on a given line, to within a tolerance.
std::vector< std::pair< Real, unsigned int > > vertex_distances(const Elem &elem)
Calculates the distances between the vertices of a given 2D element.
std::vector< std::pair< Real, unsigned int > > vertex_angles(const Elem &elem)
Calculates the internal angles of a given 2D element.
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 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.
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 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 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.
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...
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.
const SubdomainID INVALID_BLOCK_ID
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
auto index_range(const T &sizable)
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)
const boundary_id_type side_id