LCOV - code coverage report
Current view: top level - include/constraints - MortarSegmentHelper.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 39a256 Lines: 2 2 100.0 %
Date: 2026-07-14 14:36:17 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #pragma once
      11             : 
      12             : #include "MortarSegmentInfo.h"
      13             : 
      14             : #include "libmesh/point.h"
      15             : #include "libmesh/int_range.h"
      16             : 
      17             : #include <vector>
      18             : 
      19             : using libMesh::Point;
      20             : using libMesh::Real;
      21             : 
      22             : /**
      23             :  * This class supports defining mortar segment mesh elements in 3D by projecting secondary and
      24             :  * primary elements onto a linearized plane, computing the overlapping polygon formed by their
      25             :  * projections, and triangulating the resulting nodes.
      26             :  */
      27             : 
      28             : class MortarSegmentHelper
      29             : {
      30             : public:
      31             :   MortarSegmentHelper(const std::vector<Point> secondary_nodes,
      32             :                       const Point & center,
      33             :                       const Point & normal,
      34             :                       const MortarSegmentTriangulationMode triangulation_mode,
      35             :                       const bool triangulate_triangles);
      36             : 
      37             :   /**
      38             :    * Computes the intersection between line segments defined by point pairs (p1,p2) and (q1,q2)
      39             :    * Also computes s, the ratio of distance between (p1,p2) that the intersection falls,
      40             :    * quantity s is useful in avoiding adding nearly degenerate nodes
      41             :    */
      42             :   Point getIntersection(
      43             :       const Point & p1, const Point & p2, const Point & q1, const Point & q2, Real & s) const;
      44             : 
      45             :   /**
      46             :    * Check that a point is inside the secondary polygon (for verification only)
      47             :    */
      48             :   bool isInsideSecondary(const Point & pt) const;
      49             : 
      50             :   /**
      51             :    * Checks whether polygons are disjoint for an easy out
      52             :    */
      53             :   bool isDisjoint(const std::vector<Point> & poly) const;
      54             : 
      55             :   /**
      56             :    * Project a primary polygon into the helper plane while preserving the clipping orientation.
      57             :    */
      58             :   std::vector<Point> projectPrimaryPoly(const std::vector<Point> & primary_nodes) const;
      59             : 
      60             :   /**
      61             :    * Clip secondary element (defined in instantiation) against given primary polygon
      62             :    * result is a set of 2D nodes defining clipped polygon
      63             :    */
      64             :   std::vector<Point> clipPoly(const std::vector<Point> & primary_nodes) const;
      65             : 
      66             :   /**
      67             :    * Triangulate a polygon according to the configured mortar-segment triangulation mode.
      68             :    * @param poly_nodes List of 2D nodes defining polygon. May be augmented with extra interior
      69             :    *                   nodes (e.g. centroid) by triangulation modes that require them; callers
      70             :    *                   should append the result to their nodes list before applying the offset
      71             :    *                   to \p tri_map.
      72             :    * @param tri_map Output triangle list expressed in indices local to \p poly_nodes (i.e. starting
      73             :    *                at 0). Callers are responsible for shifting these indices into the global node
      74             :    *                numbering.
      75             :    */
      76             :   void triangulatePoly(std::vector<Point> & poly_nodes,
      77             :                        std::vector<std::vector<unsigned int>> & tri_map) const;
      78             : 
      79             :   /**
      80             :    * Get mortar segments generated by a secondary and primary element pair
      81             :    * @param primary_nodes List of primary element 3D nodes
      82             :    * @return nodes List of 3D mortar segment nodes
      83             :    * @return tri_map List of integer arrays defining which nodes belong to each mortar segment
      84             :    */
      85             :   void getMortarSegments(const std::vector<Point> & primary_nodes,
      86             :                          std::vector<Point> & nodes,
      87             :                          std::vector<std::vector<unsigned int>> & elem_to_nodes);
      88             : 
      89             :   /**
      90             :    * Compute area of polygon
      91             :    */
      92             :   Real area(const std::vector<Point> & nodes) const;
      93             : 
      94             :   /**
      95             :    * Get center point of secondary element
      96             :    */
      97        4950 :   const Point & center() const { return _center; }
      98             : 
      99             :   /**
     100             :    * Get area fraction remaining after clipping against primary elements
     101             :    */
     102       10134 :   Real remainder() const { return _remaining_area_fraction; }
     103             : 
     104             :   /**
     105             :    * Get 3D position of node of linearized secondary element
     106             :    */
     107             :   Point point(unsigned int i) const
     108             :   {
     109             :     return (_secondary_poly[i](0) * _u) + (_secondary_poly[i](1) * _v) + _center;
     110             :   }
     111             : 
     112             : private:
     113             :   /**
     114             :    * Geometric center of secondary element
     115             :    */
     116             :   Point _center;
     117             : 
     118             :   /**
     119             :    * Normal at geometric center of secondary element
     120             :    */
     121             :   Point _normal;
     122             : 
     123             :   /**
     124             :    * Vectors orthogonal to normal that span the plane projection will be performed on.
     125             :    * These vectors are used to project the polygon clipping problem on a 2D plane,
     126             :    * they are defined so the nodes of the projected polygon are listed with positive orientation
     127             :    */
     128             :   Point _u, _v;
     129             : 
     130             :   /**
     131             :    * Area of projected secondary element
     132             :    */
     133             :   Real _secondary_area;
     134             : 
     135             :   /**
     136             :    * Fraction of area remaining after overlapping primary polygons clipped
     137             :    */
     138             :   Real _remaining_area_fraction;
     139             : 
     140             :   bool _debug;
     141             : 
     142             :   /**
     143             :    * Tolerance for intersection and clipping
     144             :    */
     145             :   Real _tolerance = 1e-8;
     146             : 
     147             :   /**
     148             :    * Triangulation mode used for clipped polygons.
     149             :    */
     150             :   const MortarSegmentTriangulationMode _triangulation_mode;
     151             : 
     152             :   /**
     153             :    * Whether already-triangular polygons should still be centroid-subdivided.
     154             :    */
     155             :   const bool _triangulate_triangles;
     156             : 
     157             :   /**
     158             :    * Tolerance times secondary area for dimensional consistency
     159             :    */
     160             :   Real _area_tol;
     161             : 
     162             :   /**
     163             :    * Tolerance times secondary area for dimensional consistency
     164             :    */
     165             :   Real _length_tol;
     166             : 
     167             :   /**
     168             :    * List of projected points on the linearized secondary element
     169             :    */
     170             :   std::vector<Point> _secondary_poly;
     171             : };

Generated by: LCOV version 1.14