2828#include "libmesh/enum_elem_type.h"
2929#include "libmesh/function_base.h"
3030#include "libmesh/hashing.h"
31+ #include "libmesh/mesh_serializer.h"
3132#include "libmesh/mesh_smoother_laplace.h"
3233#include "libmesh/mesh_triangle_holes.h"
3334#include "libmesh/unstructured_mesh.h"
@@ -151,7 +152,6 @@ namespace libMesh
151152Poly2TriTriangulator ::Poly2TriTriangulator (UnstructuredMesh & mesh ,
152153 dof_id_type n_boundary_nodes )
153154 : TriangulatorInterface (mesh ),
154- _serializer (_mesh ),
155155 _n_boundary_nodes (n_boundary_nodes ),
156156 _refine_bdy_allowed (true)
157157{
@@ -164,6 +164,11 @@ Poly2TriTriangulator::~Poly2TriTriangulator() = default;
164164// Primary function responsible for performing the triangulation
165165void Poly2TriTriangulator ::triangulate ()
166166{
167+ // We only operate on serialized meshes. And it's not safe to
168+ // serialize earlier, because it would then be possible for the user
169+ // to re-parallelize the mesh in between there and here.
170+ MeshSerializer serializer (_mesh );
171+
167172 // We don't yet support every set of Triangulator options in the
168173 // poly2tri implementation
169174
@@ -184,6 +189,14 @@ void Poly2TriTriangulator::triangulate()
184189 _elem_type != TRI7 )
185190 libmesh_not_implemented ();
186191
192+ // If we have no explicit segments defined, we may get them from
193+ // mesh elements
194+ this -> elems_to_segments ();
195+
196+ // If we *still* have no explicit segments defined, we get them from
197+ // the order of nodes.
198+ this -> nodes_to_segments (_n_boundary_nodes );
199+
187200 // Insert additional new points in between existing boundary points,
188201 // if that is requested and reasonable
189202 this -> insert_any_extra_boundary_points ();
@@ -199,6 +212,8 @@ void Poly2TriTriangulator::triangulate()
199212 if (_markers )
200213 libmesh_not_implemented ();
201214
215+ _mesh .set_mesh_dimension (2 );
216+
202217 // To the naked eye, a few smoothing iterations usually looks better,
203218 // so we do this by default unless the user says not to.
204219 if (this -> _smooth_after_generating )
@@ -273,9 +288,10 @@ void Poly2TriTriangulator::triangulate_current_points()
273288
274289 // Unless we're using an explicit segments list, we assume node ids
275290 // are contiguous here.
291+ dof_id_type nn = _mesh .max_node_id ();
276292 if (this -> segments .empty ())
277293 libmesh_error_msg_if
278- (_mesh .n_nodes () != _mesh . max_node_id () ,
294+ (_mesh .n_nodes () != nn ,
279295 "Poly2TriTriangulator needs contiguous node ids or explicit segments!" );
280296
281297 // And if we have more nodes than outer boundary points, the rest
@@ -301,10 +317,6 @@ void Poly2TriTriangulator::triangulate_current_points()
301317 // Prepare poly2tri points for our nodes, sorted into outer boundary
302318 // points and interior Steiner points.
303319
304- // If we have no explicit segments defined, we may get them from
305- // mesh elements
306- this -> elems_to_segments ();
307-
308320 if (this -> segments .empty ())
309321 {
310322 // If we have no segments even after taking elems into account,
@@ -455,7 +467,7 @@ void Poly2TriTriangulator::triangulate_current_points()
455467 }
456468 else
457469 {
458- Node * node = _mesh .add_point (p );
470+ Node * node = _mesh .add_point (p , nn ++ );
459471 point_node_map [pt ] = node ;
460472 }
461473 }
@@ -577,6 +589,11 @@ bool Poly2TriTriangulator::insert_refinement_points()
577589
578590 BoundaryInfo & boundary_info = _mesh .get_boundary_info ();
579591
592+ // In cases where we've been working with contiguous node id ranges;
593+ // let's keep it that way.
594+ dof_id_type nn = _mesh .max_node_id ();
595+ dof_id_type ne = _mesh .max_elem_id ();
596+
580597 for (auto & elem : mesh .element_ptr_range ())
581598 {
582599 // element_ptr_range skips deleted elements ... right?
@@ -663,13 +680,13 @@ bool Poly2TriTriangulator::insert_refinement_points()
663680 side ))
664681 {
665682 new_pt = ray_start ;
666- new_node = mesh .add_point (new_pt );
683+ new_node = mesh .add_point (new_pt , nn ++ );
667684 boundary_refine (side );
668685 }
669686 else
670687 {
671688 new_pt = cavity_elem -> vertex_average ();
672- new_node = mesh .add_point (new_pt );
689+ new_node = mesh .add_point (new_pt , nn ++ );
673690 // This was going to be a side refinement but it's
674691 // now an internal refinement
675692 side = invalid_uint ;
@@ -724,21 +741,21 @@ bool Poly2TriTriangulator::insert_refinement_points()
724741 // Let's just try bisecting for now
725742 new_pt = (cavity_elem -> point (side ) +
726743 cavity_elem -> point ((side + 1 )%3 )) / 2 ;
727- new_node = mesh .add_point (new_pt );
744+ new_node = mesh .add_point (new_pt , nn ++ );
728745 boundary_refine (side );
729746 }
730747 else // Do the best we can under these restrictions
731748 {
732749 new_pt = cavity_elem -> vertex_average ();
733- new_node = mesh .add_point (new_pt );
750+ new_node = mesh .add_point (new_pt , nn ++ );
734751
735752 // This was going to be a side refinement but it's
736753 // now an internal refinement
737754 side = invalid_uint ;
738755 }
739756 }
740757 else
741- new_node = mesh .add_point (new_pt );
758+ new_node = mesh .add_point (new_pt , nn ++ );
742759 }
743760 else
744761 libmesh_assert (new_node );
@@ -845,7 +862,7 @@ bool Poly2TriTriangulator::insert_refinement_points()
845862 continue ;
846863 }
847864
848- auto new_elem = Elem ::build (TRI3 );
865+ auto new_elem = Elem ::build_with_id (TRI3 , ne ++ );
849866 new_elem -> set_node (0 ) = new_node ;
850867 new_elem -> set_node (1 ) = node_CW ;
851868 new_elem -> set_node (2 ) = node_CCW ;
0 commit comments