17#include "libmesh/int_range.h"
18#include "libmesh/mesh_base.h"
19#include "libmesh/mesh_generation.h"
20#include "libmesh/mesh_serializer.h"
21#include "libmesh/point.h"
22#include "libmesh/elem.h"
23#include "libmesh/node.h"
24#include "libmesh/face_tri3.h"
25#include "libmesh/face_quad4.h"
31 const std::vector<Point> & boundary_points_vec_1,
32 const std::vector<Point> & boundary_points_vec_2,
33 const unsigned int num_layers,
34 const subdomain_id_type transition_layer_id,
35 const boundary_id_type input_boundary_1_id,
36 const boundary_id_type input_boundary_2_id,
37 const boundary_id_type begin_side_boundary_id,
38 const boundary_id_type end_side_boundary_id,
39 const std::string type,
40 const std::string name,
42 const Real bias_parameter,
46 boundary_points_vec_1, Point(0.0, 0.0, 1.0), Point(0.0, 0.0, 0.0)) ||
48 boundary_points_vec_2, Point(0.0, 0.0, 1.0), Point(0.0, 0.0, 0.0)))
53 ", the input vectors of points for "
54 "FillBetweenPointVectorsTools::fillBetweenPointVectorsGenerator "
55 "must be in XY plane.");
57 const unsigned int vec_1_node_num = boundary_points_vec_1.size();
58 const unsigned int vec_2_node_num = boundary_points_vec_2.size();
60 if (vec_1_node_num < 2 || vec_2_node_num < 2)
65 ", the two input vectors of points for "
66 "FillBetweenPointVectorsTools::fillBetweenPointVectorsGenerator "
67 "must respectively contain at least two elements.");
69 if (quad_elem && boundary_points_vec_1.size() != boundary_points_vec_2.size())
74 ", QUAD4 elements option can only be selected when the two input vectors of Points "
75 "have the same length. In the current instance, the first vector has ",
76 boundary_points_vec_1.size(),
77 " points and the second ",
78 boundary_points_vec_2.size(),
81 std::vector<Point> possibly_reoriented_boundary_points_vec_2;
82 const std::vector<Point> * oriented_boundary_points_vec_2 = &boundary_points_vec_2;
84 if (
needFlip(boundary_points_vec_1, boundary_points_vec_2))
86 possibly_reoriented_boundary_points_vec_2.assign(boundary_points_vec_2.rbegin(),
87 boundary_points_vec_2.rend());
88 oriented_boundary_points_vec_2 = &possibly_reoriented_boundary_points_vec_2;
100 std::vector<Real> vec_1_index;
101 std::vector<Real> vec_2_index;
103 std::vector<Real> wt_1;
104 std::vector<Real> index_1;
105 std::vector<Real> wt_2;
106 std::vector<Real> index_2;
109 std::unique_ptr<LinearInterpolation> linear_vec_1_x;
110 std::unique_ptr<LinearInterpolation> linear_vec_1_y;
111 std::unique_ptr<SplineInterpolation> spline_vec_1_l;
112 std::unique_ptr<LinearInterpolation> linear_vec_2_x;
113 std::unique_ptr<LinearInterpolation> linear_vec_2_y;
114 std::unique_ptr<SplineInterpolation> spline_vec_2_l;
117 boundary_points_vec_1,
126 *oriented_boundary_points_vec_2,
137 const Real increment = ((Real)vec_2_node_num - (Real)vec_1_node_num) / (Real)(num_layers);
139 std::vector<unsigned int> node_number_vec;
141 std::vector<std::vector<Node *>> nodes(num_layers + 1);
143 unsigned int node_counter = 0;
145 for (
const auto i : make_range(num_layers + 1))
148 node_number_vec.push_back(
149 (
unsigned int)(vec_1_node_num + (long)(increment * i + 0.5 - (increment < 0))));
151 nodes[i] = std::vector<Node *>(node_number_vec[i]);
154 std::vector<Real> weighted_surrogate_index_1;
155 std::vector<Real> unweighted_surrogate_index_1;
158 unweighted_surrogate_index_1,
166 std::vector<Real> weighted_surrogate_index_2;
167 std::vector<Real> unweighted_surrogate_index_2;
170 unweighted_surrogate_index_2,
177 for (
const auto j : make_range(node_number_vec[i]))
180 Point surrogate_pos_1 = Point(linear_vec_1_x->sample(weighted_surrogate_index_1[j]),
181 linear_vec_1_y->sample(weighted_surrogate_index_1[j]),
184 Point surrogate_pos_2 = Point(linear_vec_2_x->sample(weighted_surrogate_index_2[j]),
185 linear_vec_2_y->sample(weighted_surrogate_index_2[j]),
187 const Real l_ratio = bias_parameter <= 0.0
188 ?
std::pow(spline_vec_2_l->sample(weighted_surrogate_index_2[j]) /
189 spline_vec_1_l->sample(weighted_surrogate_index_1[j]),
190 1.0 / ((Real)num_layers - 1.0))
192 const Real index_factor =
193 MooseUtils::absoluteFuzzyEqual(l_ratio, 1.0)
194 ? (Real)i / (Real)num_layers
195 : (1.0 -
std::pow(l_ratio, (Real)i)) / (1.0 -
std::pow(l_ratio, (Real)num_layers));
196 Point tmp_point = surrogate_pos_2 * index_factor + surrogate_pos_1 * (1.0 - index_factor);
197 nodes[i][j] =
mesh.add_point(tmp_point, j + node_counter);
199 node_counter += node_number_vec[i];
210 begin_side_boundary_id,
211 end_side_boundary_id);
220 begin_side_boundary_id,
221 end_side_boundary_id);
226 const std::vector<Point> & boundary_points_vec_1,
227 const std::vector<Point> & boundary_points_vec_2,
228 const unsigned int num_layers,
229 const subdomain_id_type transition_layer_id,
230 const boundary_id_type external_boundary_id,
231 const std::string type,
232 const std::string name,
233 const bool quad_elem)
236 boundary_points_vec_1,
237 boundary_points_vec_2,
240 external_boundary_id,
241 external_boundary_id,
242 external_boundary_id,
243 external_boundary_id,
251 const std::vector<std::vector<Node *>> & nodes,
252 const unsigned int num_layers,
253 const std::vector<unsigned int> & node_number_vec,
254 const subdomain_id_type transition_layer_id,
255 const boundary_id_type input_boundary_1_id,
256 const boundary_id_type input_boundary_2_id,
257 const boundary_id_type begin_side_boundary_id,
258 const boundary_id_type end_side_boundary_id)
260 const unsigned int node_number = node_number_vec.front();
261 BoundaryInfo & boundary_info =
mesh.get_boundary_info();
263 for (
const auto i : make_range(num_layers))
264 for (
unsigned int j = 1; j < node_number; j++)
266 Elem * elem =
mesh.add_elem(
new Quad4);
272 transition_layer_id);
274 boundary_info.add_side(elem, is_elem_flip ? 0 : 3, input_boundary_1_id);
275 if (i == num_layers - 1)
276 boundary_info.add_side(elem, is_elem_flip ? 2 : 1, input_boundary_2_id);
278 boundary_info.add_side(elem, is_elem_flip ? 3 : 0, begin_side_boundary_id);
279 if (j == node_number - 1)
280 boundary_info.add_side(elem, is_elem_flip ? 1 : 2, end_side_boundary_id);
286 const std::vector<std::vector<Node *>> & nodes,
287 const unsigned int num_layers,
288 const std::vector<unsigned int> & node_number_vec,
289 const subdomain_id_type transition_layer_id,
290 const boundary_id_type input_boundary_1_id,
291 const boundary_id_type input_boundary_2_id,
292 const boundary_id_type begin_side_boundary_id,
293 const boundary_id_type end_side_boundary_id)
295 BoundaryInfo & boundary_info =
mesh.get_boundary_info();
297 for (
const auto i : make_range(num_layers))
299 unsigned int nodes_up_it = 0;
300 unsigned int nodes_down_it = 0;
301 const unsigned int node_number_up = node_number_vec[i + 1];
302 const unsigned int node_number_down = node_number_vec[i];
304 while (nodes_up_it < node_number_up - 1 && nodes_down_it < node_number_down - 1 &&
305 nodes_up_it + nodes_down_it < node_number_up + node_number_down - 3)
308 Real dis1 = (*nodes[i + 1][nodes_up_it] - *nodes[i][nodes_down_it + 1]).norm();
309 Real dis2 = (*nodes[i + 1][nodes_up_it + 1] - *nodes[i][nodes_down_it]).norm();
310 if (MooseUtils::absoluteFuzzyGreaterThan(dis1, dis2))
312 Elem * elem =
mesh.add_elem(
new Tri3);
314 nodes[i + 1][nodes_up_it],
315 nodes[i][nodes_down_it],
316 nodes[i + 1][nodes_up_it + 1],
317 transition_layer_id);
318 if (i == num_layers - 1)
319 boundary_info.add_side(elem, is_elem_flip ? 0 : 2, input_boundary_2_id);
320 if (nodes_up_it == 0 && nodes_down_it == 0)
321 boundary_info.add_side(elem, is_elem_flip ? 2 : 0, begin_side_boundary_id);
326 Elem * elem =
mesh.add_elem(
new Tri3);
328 nodes[i + 1][nodes_up_it],
329 nodes[i][nodes_down_it],
330 nodes[i][nodes_down_it + 1],
331 transition_layer_id);
333 boundary_info.add_side(elem, 1, input_boundary_1_id);
334 if (nodes_up_it == 0 && nodes_down_it == 0)
335 boundary_info.add_side(elem, is_elem_flip ? 2 : 0, begin_side_boundary_id);
340 while (nodes_up_it < node_number_up - 1)
342 Elem * elem =
mesh.add_elem(
new Tri3);
344 nodes[i + 1][nodes_up_it],
345 nodes[i][nodes_down_it],
346 nodes[i + 1][nodes_up_it + 1],
347 transition_layer_id);
349 if (i == num_layers - 1)
350 boundary_info.add_side(elem, is_elem_flip ? 0 : 2, input_boundary_2_id);
351 if (nodes_up_it == node_number_up - 1 && nodes_down_it == node_number_down - 1)
352 boundary_info.add_side(elem, 1, end_side_boundary_id);
354 while (nodes_down_it < node_number_down - 1)
356 Elem * elem =
mesh.add_elem(
new Tri3);
358 nodes[i + 1][nodes_up_it],
359 nodes[i][nodes_down_it],
360 nodes[i][nodes_down_it + 1],
361 transition_layer_id);
364 boundary_info.add_side(elem, 1, input_boundary_1_id);
365 if (nodes_up_it == node_number_up - 1 && nodes_down_it == node_number_down - 1)
366 boundary_info.add_side(elem, is_elem_flip ? 0 : 2, end_side_boundary_id);
373 const std::vector<Point> & boundary_points_vec,
374 std::vector<Real> & vec_index,
375 std::vector<Real> & wt,
376 std::vector<Real> & index,
378 std::unique_ptr<LinearInterpolation> & linear_vec_x,
379 std::unique_ptr<LinearInterpolation> & linear_vec_y,
380 std::unique_ptr<SplineInterpolation> & spline_vec_l)
382 std::vector<Real> pos_x;
383 std::vector<Real> pos_y;
384 std::vector<Real> dist_vec;
385 std::vector<Real> pos_l;
387 for (
const auto i : make_range(vec_node_num))
391 vec_index.push_back((Real)i / ((Real)vec_node_num - 1.0));
393 pos_x.push_back(boundary_points_vec[i](0));
394 pos_y.push_back(boundary_points_vec[i](1));
398 wt.push_back((boundary_points_vec[i] - boundary_points_vec[i - 1]).norm());
399 dist_vec.push_back(wt.back());
402 index.push_back(std::accumulate(wt.begin(), wt.end(), 0.0));
404 const Real dist_vec_total = index.back();
405 const Real wt_norm_factor = dist_vec_total / ((Real)vec_node_num - 1.0);
408 wt.begin(), wt.end(), wt.begin(), [wt_norm_factor](Real & c) { return c / wt_norm_factor; });
409 std::transform(index.begin(),
412 [dist_vec_total](Real & c) { return c / dist_vec_total; });
414 for (
const auto i : make_range(vec_node_num))
416 Real gaussian_factor(0.0);
419 for (
const auto j : make_range(vec_node_num - 1))
422 const Real tmp_factor =
423 exp(-((Real)(i - j) - 0.5) * ((Real)(i - j) - 0.5) / 2.0 / sigma / sigma);
424 gaussian_factor += tmp_factor;
425 sum_tmp += tmp_factor * dist_vec[j];
427 pos_l.push_back(sum_tmp / gaussian_factor);
430 linear_vec_x = std::make_unique<LinearInterpolation>(index, pos_x);
431 linear_vec_y = std::make_unique<LinearInterpolation>(index, pos_y);
432 spline_vec_l = std::make_unique<SplineInterpolation>(index, pos_l);
437 std::vector<Real> & unweighted_surrogate_index,
438 const std::vector<unsigned int> & node_number_vec,
439 const std::vector<Real> & wt,
440 const std::vector<Real> & index,
441 const unsigned int boundary_node_num,
442 const unsigned int i)
445 weighted_surrogate_index.push_back(0.0);
446 unweighted_surrogate_index.push_back(0.0);
447 for (
unsigned int j = 1; j < node_number_vec[i]; j++)
450 unweighted_surrogate_index.push_back((Real)j / ((Real)node_number_vec[i] - 1.0));
453 std::upper_bound(index.begin(), index.end(), unweighted_surrogate_index[j - 1]);
455 const auto it_1 = std::lower_bound(index.begin(), index.end(), unweighted_surrogate_index[j]);
457 const auto it_dist = std::distance(it_0, it_1);
459 const auto it_start = std::distance(index.begin(), it_0);
462 weighted_surrogate_index.push_back(weighted_surrogate_index[j - 1] +
463 wt[it_start - 1] / ((Real)node_number_vec[i] - 1.0));
466 weighted_surrogate_index.push_back(weighted_surrogate_index[j - 1]);
467 weighted_surrogate_index[j] += (*it_0 - unweighted_surrogate_index[j - 1]) * wt[it_start - 1];
468 weighted_surrogate_index[j] +=
469 (unweighted_surrogate_index[j] - *(it_1 - 1)) * wt[it_start + it_dist - 1];
470 for (
unsigned int k = 1; k < it_dist; k++)
471 weighted_surrogate_index[j] += wt[it_start + k - 1] / ((Real)boundary_node_num - 1.0);
477needFlip(
const std::vector<Point> & vec_pts_1,
const std::vector<Point> & vec_pts_2)
480 acos((vec_pts_1.back() - vec_pts_1.front()) * (vec_pts_2.front() - vec_pts_1.front()) /
481 (vec_pts_1.back() - vec_pts_1.front()).norm() /
482 (vec_pts_2.front() - vec_pts_1.front()).norm());
483 const Real th2 = acos(
484 (vec_pts_2.back() - vec_pts_1.back()) * (vec_pts_1.front() - vec_pts_1.back()) /
485 (vec_pts_2.back() - vec_pts_1.back()).norm() / (vec_pts_1.front() - vec_pts_1.back()).norm());
486 const Real th3 = acos(
487 (vec_pts_2.front() - vec_pts_2.back()) * (vec_pts_1.back() - vec_pts_2.back()) /
488 (vec_pts_2.front() - vec_pts_2.back()).norm() / (vec_pts_1.back() - vec_pts_2.back()).norm());
490 acos((vec_pts_1.front() - vec_pts_2.front()) * (vec_pts_2.back() - vec_pts_2.front()) /
491 (vec_pts_1.front() - vec_pts_2.front()).norm() /
492 (vec_pts_2.back() - vec_pts_2.front()).norm());
493 if (MooseUtils::absoluteFuzzyEqual(th1 + th2 + th3 + th4, 2 * M_PI))
500 Real & max_node_radius,
501 std::vector<dof_id_type> & boundary_ordered_node_list,
502 const Point origin_pt,
503 const boundary_id_type bid)
509 max_node_radius = 0.0;
510 BoundaryInfo & boundary_info =
mesh.get_boundary_info();
511 auto side_list_tmp = boundary_info.build_side_list();
512 std::vector<std::pair<dof_id_type, dof_id_type>> boundary_node_assm;
513 std::vector<dof_id_type> boundary_midpoint_node_list;
514 for (
const auto i : index_range(side_list_tmp))
516 if (std::get<2>(side_list_tmp[i]) == bid)
519 const auto elem =
mesh.elem_ptr(std::get<0>(side_list_tmp[i]));
520 const auto side = elem->side_ptr(std::get<1>(side_list_tmp[i]));
521 boundary_node_assm.push_back(std::make_pair(side->node_id(0), side->node_id(1)));
523 const auto & side_type = elem->side_type(std::get<1>(side_list_tmp[i]));
524 if (side_type == EDGE3)
525 boundary_midpoint_node_list.push_back(
526 elem->node_id(elem->n_vertices() + std::get<1>(side_list_tmp[i])));
528 boundary_midpoint_node_list.push_back(DofObject::invalid_id);
534 boundary_ordered_node_list,
536 boundary_midpoint_node_list,
540 return is_closed_loop;
545 Real & max_node_radius,
546 const Point origin_pt,
547 const boundary_id_type bid)
549 std::vector<dof_id_type> dummy_boundary_ordered_node_list;
551 mesh, max_node_radius, dummy_boundary_ordered_node_list, origin_pt, bid);
557 Real dummy_max_node_radius;
563 Real & max_node_radius,
564 std::vector<dof_id_type> & boundary_ordered_node_list,
565 const Point origin_pt,
566 const boundary_id_type bid)
574 if (((std::string)e.
what())
575 .compare(
"This mesh generator does not work for the provided external boundary as it "
576 "is not a closed loop.") != 0)
577 throw MooseException(
"The provided boundary is not an open single-segment boundary.");
582 throw MooseException(
"The provided boundary is closed loop, which is not supported.");
592 if (!
mesh.is_prepared())
593 mesh.find_neighbors();
594 BoundaryInfo & boundary_info =
mesh.get_boundary_info();
595 auto side_list = boundary_info.build_side_list();
596 for (
const auto i : index_range(side_list))
598 if (std::get<2>(side_list[i]) == bid)
599 if (
mesh.elem_ptr(std::get<0>(side_list[i]))->neighbor_ptr(std::get<1>(side_list[i])) !=
608 Real & max_node_radius,
609 std::vector<dof_id_type> & ordered_node_list,
610 const Point origin_pt)
616 max_node_radius = 0.0;
617 std::vector<std::pair<dof_id_type, dof_id_type>> node_assm;
618 for (
auto it =
mesh.active_elements_begin(); it !=
mesh.active_elements_end(); it++)
619 node_assm.push_back(std::make_pair((*it)->node_id(0), (*it)->node_id(1)));
622 mesh, max_node_radius, ordered_node_list, node_assm, origin_pt,
"curve", is_closed_loop);
623 return is_closed_loop;
629 std::vector<dof_id_type> dummy_ordered_node_list;
636 Real dummy_max_node_radius;
642 Real & max_node_radius,
643 std::vector<dof_id_type> & ordered_node_list,
644 const Point origin_pt)
652 if (((std::string)e.
what())
653 .compare(
"This mesh generator does not work for the provided curve as it is not a "
654 "closed loop.") != 0)
655 throw MooseException(
"The provided curve is not an open single-segment boundary.");
659 throw MooseException(
"The provided curve is closed loop, which is not supported.");
665 Real & max_node_radius,
666 std::vector<dof_id_type> & ordered_node_list,
667 std::vector<std::pair<dof_id_type, dof_id_type>> & node_assm,
668 std::vector<dof_id_type> & midpoint_node_list,
669 const Point origin_pt,
670 const std::string input_type,
671 bool & is_closed_loop,
672 const bool suppress_exception)
678 std::vector<dof_id_type> dummy_elem_list = std::vector<dof_id_type>(node_assm.size(), 0);
679 std::vector<dof_id_type> ordered_dummy_elem_list;
680 is_closed_loop =
false;
682 node_assm, dummy_elem_list, midpoint_node_list, ordered_node_list, ordered_dummy_elem_list);
686 if (ordered_node_list.front() != ordered_node_list.back())
689 if (!suppress_exception)
690 throw MooseException(
"This mesh generator does not work for the provided ",
692 " as it is not a closed loop.");
700 std::vector<Real> ordered_node_azi_list;
701 for (
const auto i : make_range(ordered_node_list.size() - 1))
703 ordered_node_azi_list.push_back(
704 (*
mesh.node_ptr(ordered_node_list[i]) - origin_pt)
705 .cross(*
mesh.node_ptr(ordered_node_list[i + 1]) - origin_pt)(2));
708 std::max((*
mesh.node_ptr(ordered_node_list[i]) - origin_pt).norm(), max_node_radius);
710 std::sort(ordered_node_azi_list.begin(), ordered_node_azi_list.end());
711 if (ordered_node_azi_list.front() * ordered_node_azi_list.back() < 0.0)
714 if (!suppress_exception)
716 "This mesh generator does not work for the provided ",
718 " as azimuthal angles of consecutive nodes do not change monotonically.");
721 is_closed_loop =
true;
727 Real & max_node_radius,
728 std::vector<dof_id_type> & ordered_node_list,
729 std::vector<std::pair<dof_id_type, dof_id_type>> & node_assm,
730 const Point origin_pt,
731 const std::string input_type,
732 bool & is_closed_loop,
733 const bool suppress_exception)
735 std::vector<dof_id_type> dummy_midpoint_node_list(node_assm.size(), DofObject::invalid_id);
740 dummy_midpoint_node_list,
753 const subdomain_id_type transition_layer_id)
757 elem->subdomain_id() = transition_layer_id;
758 if (((*nd_1 - *nd_0).cross((*nd_2 - *nd_0)).unit())(2) > 0)
760 elem->set_node(0, nd_0);
761 elem->set_node(1, nd_1);
762 elem->set_node(2, nd_2);
763 elem->set_node(3, nd_3);
768 elem->set_node(0, nd_0);
769 elem->set_node(3, nd_1);
770 elem->set_node(2, nd_2);
771 elem->set_node(1, nd_3);
778 Elem * elem, Node * nd_0, Node * nd_1, Node * nd_2,
const subdomain_id_type transition_layer_id)
782 elem->subdomain_id() = transition_layer_id;
783 if (((*nd_1 - *nd_0).cross((*nd_2 - *nd_0)).unit())(2) > 0)
785 elem->set_node(0, nd_0);
786 elem->set_node(1, nd_1);
787 elem->set_node(2, nd_2);
792 elem->set_node(0, nd_0);
793 elem->set_node(2, nd_1);
794 elem->set_node(1, nd_2);
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.
virtual const char * what() const
Get out the error message.
bool isCoPlanar(const std::vector< Point > &vec_pts, const Point plane_nvec, const Point fixed_pt)
Decides whether all the Points of a vector of Points are in a plane that is defined by a normal vecto...
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...
MooseUnits pow(const MooseUnits &, int)