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 : 20 : #ifndef LIBMESH_ELEM_CUTTER_H 21 : #define LIBMESH_ELEM_CUTTER_H 22 : 23 : #include "libmesh/libmesh_config.h" 24 : 25 : #if defined(LIBMESH_HAVE_TRIANGLE) && defined(LIBMESH_HAVE_TETGEN) 26 : 27 : // libMesh includes 28 : #include "libmesh/libmesh_common.h" 29 : #include "libmesh/point.h" 30 : 31 : // TIMPI includes 32 : #include "timpi/communicator.h" 33 : 34 : // C++ includes 35 : #include <vector> 36 : #include <memory> 37 : 38 : namespace libMesh 39 : { 40 : 41 : // Forward declarations 42 : class Elem; 43 : class ReplicatedMesh; 44 : class TriangleInterface; 45 : class TetGenMeshInterface; 46 : 47 : // This is for backwards compatibility, but if your code relies on 48 : // forward declarations in our headers then fix it. 49 : class SerialMesh; 50 : 51 : /** 52 : * This class implements cutting a single element into a collection 53 : * of subelements. This class depends on libmesh's Triangle and Tetgen 54 : * interfaces, the former of which is only defined if libmesh is configured 55 : * with --disable-strict-lgpl. 56 : * 57 : * \author Benjamin S. Kirk 58 : * \date 2013 59 : * \brief Subdivides a single element using a mesh generator. 60 : */ 61 8 : class ElemCutter 62 : { 63 : public: 64 : 65 : /** 66 : * Constructor. Initializes pointer data 67 : * without requiring a full \p ReplicatedMesh in this header file. 68 : */ 69 : ElemCutter(); 70 : 71 : /** 72 : * Destructor. 73 : */ 74 : ~ElemCutter(); 75 : 76 : /** 77 : * \returns \p true if the element is completely inside the 78 : * interface defined implicitly by the vertex values of the signed 79 : * \p vertex_distance_func. 80 : */ 81 : bool is_inside (const Elem & elem, 82 : const std::vector<Real> & vertex_distance_func) const; 83 : 84 : /** 85 : * \returns \p true if the element is completely outside the 86 : * interface defined implicitly by the vertex values of the signed 87 : * \p vertex_distance_func. 88 : */ 89 : bool is_outside (const Elem & elem, 90 : const std::vector<Real> & vertex_distance_func) const; 91 : 92 : /** 93 : * \returns \p true if the element is cut by the interface defined 94 : * implicitly by the vertex values of the signed 95 : * \p vertex_distance_func. 96 : */ 97 : bool is_cut (const Elem & elem, 98 : const std::vector<Real> & vertex_distance_func) const; 99 : 100 : /** 101 : * This function implements cutting an element by a signed distance 102 : * function. The input array \p vertex_distance_func contains the 103 : * vertex values of a signed distance function, from which the cutting 104 : * interface is inferred from the 0 level set. If all vertex values 105 : * are positive, the element is outside the cutting surface and is not cut. 106 : * Likewise if all vertex values are negative, the element is inside the 107 : * cutting surface and is not cut. 108 : */ 109 : void operator()(const Elem & elem_in, 110 : const std::vector<Real> & vertex_distance_func); 111 : 112 : /** 113 : * \returns A list of general element pieces considered inside the 114 : * cutting surface. These are subelements whose geometric union 115 : * defines the spatial domain of the inside portion of the cut element. 116 : */ 117 385 : const std::vector<Elem const *> & inside_elements () const 118 770 : { return _inside_elem; } 119 : 120 : /** 121 : * \returns A list of general element pieces considered outside the 122 : * cutting surface. These are subelements whose geometric union 123 : * defines the spatial domain of the outside portion of the cut element. 124 : */ 125 385 : const std::vector<Elem const *> & outside_elements() const 126 770 : { return _outside_elem; } 127 : 128 : protected: 129 : 130 : /** 131 : * Finds the points where the cutting surface 132 : * intersects the element edges. 133 : */ 134 : void find_intersection_points(const Elem & elem, 135 : const std::vector<Real> & vertex_distance_func); 136 : 137 : /** 138 : * cutting algorithm in 1D. 139 : */ 140 : void cut_1D(const Elem & elem, 141 : const std::vector<Real> & vertex_distance_func); 142 : 143 : /** 144 : * cutting algorithm in 2D. 145 : */ 146 : void cut_2D(const Elem & elem, 147 : const std::vector<Real> & vertex_distance_func); 148 : 149 : /** 150 : * cutting algorithm in 3D. 151 : */ 152 : void cut_3D(const Elem & elem, 153 : const std::vector<Real> & vertex_distance_func); 154 : 155 : std::vector<Elem const *> _inside_elem; 156 : std::vector<Elem const *> _outside_elem; 157 : 158 : Parallel::Communicator _comm_self; // defaults to MPI_COMM_SELF 159 : 160 : std::unique_ptr<ReplicatedMesh> _inside_mesh_2D; 161 : std::unique_ptr<TriangleInterface> _triangle_inside; 162 : 163 : std::unique_ptr<ReplicatedMesh> _outside_mesh_2D; 164 : std::unique_ptr<TriangleInterface> _triangle_outside; 165 : 166 : std::unique_ptr<ReplicatedMesh> _inside_mesh_3D; 167 : std::unique_ptr<TetGenMeshInterface> _tetgen_inside; 168 : 169 : std::unique_ptr<ReplicatedMesh> _outside_mesh_3D; 170 : std::unique_ptr<TetGenMeshInterface> _tetgen_outside; 171 : 172 : std::vector<Point> _intersection_pts; 173 : }; 174 : 175 : 176 : } // namespace libMesh 177 : 178 : #endif // LIBMESH_HAVE_TRIANGLE && LIBMESH_HAVE_TETGEN 179 : #endif // LIBMESH_ELEM_CUTTER_H