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 "libmesh/point.h" 13 : #include "libmesh/int_range.h" 14 : 15 : #include <vector> 16 : 17 : using libMesh::Point; 18 : using libMesh::Real; 19 : 20 : /** 21 : * This class supports defining mortar segment mesh elements in 3D by projecting secondary and 22 : * primary elements onto a linearized plane, computing the overlapping polygon formed by their 23 : * projections, and triangulating the resulting nodes. 24 : */ 25 : 26 : class MortarSegmentHelper 27 : { 28 : public: 29 : MortarSegmentHelper(const std::vector<Point> secondary_nodes, 30 : const Point & center, 31 : const Point & normal); 32 : 33 : /** 34 : * Computes the intersection between line segments defined by point pairs (p1,p2) and (q1,q2) 35 : * Also computes s, the ratio of distance between (p1,p2) that the intersection falls, 36 : * quantity s is useful in avoiding adding nearly degenerate nodes 37 : */ 38 : Point getIntersection( 39 : const Point & p1, const Point & p2, const Point & q1, const Point & q2, Real & s) const; 40 : 41 : /** 42 : * Check that a point is inside the secondary polygon (for verification only) 43 : */ 44 : bool isInsideSecondary(const Point & pt) const; 45 : 46 : /** 47 : * Checks whether polygons are disjoint for an easy out 48 : */ 49 : bool isDisjoint(const std::vector<Point> & poly) const; 50 : 51 : /** 52 : * Clip secondary element (defined in instantiation) against given primary polygon 53 : * result is a set of 2D nodes defining clipped polygon 54 : */ 55 : std::vector<Point> clipPoly(const std::vector<Point> & primary_nodes) const; 56 : 57 : /** 58 : * Triangulate a polygon (currently uses center of polygon to define triangulation) 59 : * @param poly_nodes List of 2D nodes defining polygon 60 : * @param offset Current size of 3D nodes array (not poly_nodes) 61 : * @return tri_map List of integer arrays defining which nodes belong to each triangle 62 : */ 63 : void triangulatePoly(std::vector<Point> & poly_nodes, 64 : const unsigned int offset, 65 : std::vector<std::vector<unsigned int>> & tri_map) const; 66 : 67 : /** 68 : * Get mortar segments generated by a secondary and primary element pair 69 : * @param primary_nodes List of primary element 3D nodes 70 : * @return nodes List of 3D mortar segment nodes 71 : * @return tri_map List of integer arrays defining which nodes belong to each mortar segment 72 : */ 73 : void getMortarSegments(const std::vector<Point> & primary_nodes, 74 : std::vector<Point> & nodes, 75 : std::vector<std::vector<unsigned int>> & elem_to_nodes); 76 : 77 : /** 78 : * Compute area of polygon 79 : */ 80 : Real area(const std::vector<Point> & nodes) const; 81 : 82 : /** 83 : * Get center point of secondary element 84 : */ 85 2518 : const Point & center() const { return _center; } 86 : 87 : /** 88 : * Get area fraction remaining after clipping against primary elements 89 : */ 90 5446 : Real remainder() const { return _remaining_area_fraction; } 91 : 92 : /** 93 : * Get 3D position of node of linearized secondary element 94 : */ 95 : Point point(unsigned int i) const 96 : { 97 : return (_secondary_poly[i](0) * _u) + (_secondary_poly[i](1) * _v) + _center; 98 : } 99 : 100 : private: 101 : /** 102 : * Geometric center of secondary element 103 : */ 104 : Point _center; 105 : 106 : /** 107 : * Normal at geometric center of secondary element 108 : */ 109 : Point _normal; 110 : 111 : /** 112 : * Vectors orthogonal to normal that span the plane projection will be performed on. 113 : * These vectors are used to project the polygon clipping problem on a 2D plane, 114 : * they are defined so the nodes of the projected polygon are listed with positive orientation 115 : */ 116 : Point _u, _v; 117 : 118 : /** 119 : * Area of projected secondary element 120 : */ 121 : Real _secondary_area; 122 : 123 : /** 124 : * Fraction of area remaining after overlapping primary polygons clipped 125 : */ 126 : Real _remaining_area_fraction; 127 : 128 : bool _debug; 129 : 130 : /** 131 : * Tolerance for intersection and clipping 132 : */ 133 : Real _tolerance = 1e-8; 134 : 135 : /** 136 : * Tolerance times secondary area for dimensional consistency 137 : */ 138 : Real _area_tol; 139 : 140 : /** 141 : * Tolerance times secondary area for dimensional consistency 142 : */ 143 : Real _length_tol; 144 : 145 : /** 146 : * List of projected points on the linearized secondary element 147 : */ 148 : std::vector<Point> _secondary_poly; 149 : };