LCOV - code coverage report
Current view: top level - include/mesh - poly2tri_triangulator.h (source / functions) Hit Total Coverage
Test: libMesh/libmesh: #4229 (6a9aeb) with base 727f46 Lines: 3 5 60.0 %
Date: 2025-08-19 19:27:09 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : // The libMesh Finite Element Library.
       2             : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
       3             : 
       4             : // This library is free software; you can redistribute it and/or
       5             : // modify it under the terms of the GNU Lesser General Public
       6             : // License as published by the Free Software Foundation; either
       7             : // version 2.1 of the License, or (at your option) any later version.
       8             : 
       9             : // This library is distributed in the hope that it will be useful,
      10             : // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12             : // Lesser General Public License for more details.
      13             : 
      14             : // You should have received a copy of the GNU Lesser General Public
      15             : // License along with this library; if not, write to the Free Software
      16             : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
      17             : 
      18             : 
      19             : #ifndef LIBMESH_POLY2TRI_TRIANGULATOR_H
      20             : #define LIBMESH_POLY2TRI_TRIANGULATOR_H
      21             : 
      22             : #include <memory>
      23             : 
      24             : #include "libmesh/libmesh_config.h"
      25             : 
      26             : #ifdef LIBMESH_HAVE_POLY2TRI
      27             : 
      28             : // Local Includes
      29             : #include "libmesh/dof_object.h"
      30             : #include "libmesh/triangulator_interface.h"
      31             : 
      32             : namespace libMesh
      33             : {
      34             : 
      35             : // Forward Declarations
      36             : class BoundaryInfo;
      37             : class Elem;
      38             : 
      39             : /**
      40             :  * A C++ interface between LibMesh and the poly2tri library, with
      41             :  * custom code for Steiner point insertion.
      42             :  *
      43             :  * \author Roy H. Stogner
      44             :  * \date 2022
      45             :  */
      46         156 : class Poly2TriTriangulator : public TriangulatorInterface
      47             : {
      48             : public:
      49             :   /**
      50             :    * The constructor.  A reference to the mesh containing the points
      51             :    * which are to be triangulated must be provided.  The first
      52             :    * \p n_boundary_nodes are expected to form a closed loop around the
      53             :    * mesh domain; any subsequent nodes are expected to be interior
      54             :    * nodes or in the middle of (internal hole or external) boundary
      55             :    * segments.
      56             :    *
      57             :    * If \p n_boundary_nodes is not supplied or is \p invalid_id then
      58             :    * all mesh points are expected to be boundary polyline points.
      59             :    */
      60             :   explicit
      61             :   Poly2TriTriangulator(UnstructuredMesh & mesh,
      62             :                        dof_id_type n_boundary_nodes =
      63             :                          DofObject::invalid_id);
      64             : 
      65             :   /**
      66             :    * Empty destructor.  Defaulted in the .C so we can forward declare
      67             :    * unique_ptr contents.
      68             :    */
      69             :   virtual ~Poly2TriTriangulator();
      70             : 
      71             :   /**
      72             :    * Internally, this calls the poly2tri triangulation code in a loop,
      73             :    * inserting our owner Steiner points as necessary to promote mesh
      74             :    * quality.
      75             :    */
      76             :   virtual void triangulate() override;
      77             : 
      78             :   /**
      79             :    * Set a function giving desired triangle area as a function of
      80             :    * position.  Set this to nullptr to disable position-dependent area
      81             :    * constraint (falling back on desired_area()).
      82             :    */
      83             :   virtual void set_desired_area_function (FunctionBase<Real> * desired) override;
      84             : 
      85             :   /**
      86             :    * Get the function giving desired triangle area as a function of
      87             :    * position, or \p nullptr if no such function has been set.
      88             :    */
      89             :   virtual FunctionBase<Real> * get_desired_area_function () override;
      90             : 
      91             :   /**
      92             :    * Set whether or not the triangulation is allowed to refine the
      93             :    * mesh boundary when refining the interior.  This is true by
      94             :    * default, but may be set to false to make the mesh boundary more
      95             :    * predictable (and so easier to stitch to other meshes) later.
      96             :    */
      97           0 :   virtual void set_refine_boundary_allowed (bool refine_bdy_allowed) override
      98           0 :   { _refine_bdy_allowed = refine_bdy_allowed; }
      99             : 
     100             :   /**
     101             :    * Get whether or not the triangulation is allowed to refine the
     102             :    * mesh boundary when refining the interior.  True by default.
     103             :    */
     104       19525 :   virtual bool refine_boundary_allowed () const override
     105       19525 :   { return _refine_bdy_allowed; }
     106             : 
     107             : 
     108             : protected:
     109             :   /**
     110             :    * Is refining this element's boundary side allowed?
     111             :    */
     112             :   bool is_refine_boundary_allowed(const BoundaryInfo & boundary_info,
     113             :                                   const Elem & elem,
     114             :                                   unsigned int side);
     115             : 
     116             :   /**
     117             :    * Triangulate the current mesh and hole points.
     118             :    */
     119             :   void triangulate_current_points();
     120             : 
     121             :   /**
     122             :    * Add Steiner points as new mesh nodes, as necessary to refine an
     123             :    * existing trangulation.  Returns true iff new points were added.
     124             :    */
     125             :   bool insert_refinement_points();
     126             : 
     127             :   /**
     128             :    * Returns true if the given element ought to be refined according
     129             :    * to current criteria.
     130             :    */
     131             :   bool should_refine_elem(Elem & elem);
     132             : 
     133             : private:
     134             : 
     135             :   /**
     136             :    * We might have to replace the user-provided holes with refined
     137             :    * versions
     138             :    */
     139             :   std::map<const Hole *, std::unique_ptr<ArbitraryHole>> replaced_holes;
     140             : 
     141             :   /**
     142             :    * Keep track of how many mesh nodes are boundary nodes.
     143             :    */
     144             :   dof_id_type _n_boundary_nodes;
     145             : 
     146             :   /**
     147             :    * Location-dependent area requirements
     148             :    */
     149             :   std::unique_ptr<FunctionBase<Real>> _desired_area_func;
     150             : 
     151             :   /**
     152             :    * Whether to allow boundary refinement
     153             :    */
     154             :   bool _refine_bdy_allowed;
     155             : };
     156             : 
     157             : } // namespace libMesh
     158             : 
     159             : #endif // LIBMESH_HAVE_TRIANGLE
     160             : 
     161             : #endif // ifndef LIBMESH_POLY2TRI_TRIANGULATOR_H

Generated by: LCOV version 1.14