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 : // MOOSE includes 13 : #include "CrackFrontPointsProvider.h" 14 : #include "XFEMAppTypes.h" 15 : #include "SolidMechanicsAppTypes.h" 16 : 17 : #include "libmesh/libmesh_common.h" 18 : #include "libmesh/libmesh.h" // libMesh::invalid_uint 19 : #include "libmesh/elem.h" 20 : 21 : using namespace libMesh; 22 : 23 : class XFEM; 24 : 25 : namespace Xfem 26 : { 27 : /// Data structure defining a cut on an element edge 28 : struct CutEdge 29 : { 30 : /// ID of the first node on the edge 31 : unsigned int _id1; 32 : /// ID of the second node on the edge 33 : unsigned int _id2; 34 : /// Fractional distance along the edge (from node 1 to 2) where the cut is located 35 : Real _distance; 36 : /// Local ID of this side in the host element 37 : unsigned int _host_side_id; 38 : }; 39 : 40 : /** 41 : * Operator < for two CutEdge Objects 42 : * Needed to allow the use of std::set<CutEdge> 43 : * @param lhs CutEdge object on the left side of the comparison 44 : * @param rhs CutEdge object on the right side of the comparison 45 : * @return bool true if lhs < rhs 46 : */ 47 : inline bool 48 : operator<(const CutEdge & lhs, const CutEdge & rhs) 49 : { 50 640 : if (lhs._id1 != rhs._id1) 51 560 : return lhs._id1 < rhs._id1; 52 : else 53 80 : return lhs._id2 < rhs._id2; 54 : } 55 : 56 : /// Data structure defining a cut through a node 57 : struct CutNode 58 : { 59 : /// ID of the cut node 60 : unsigned int _id; 61 : /// Local ID of this node in the host element 62 : unsigned int _host_id; 63 : }; 64 : 65 : /// Data structure defining a cut through a face 66 110752 : struct CutFace 67 : { 68 : /// ID of the cut face 69 : unsigned int _face_id; 70 : /// IDs of all cut faces 71 : std::vector<unsigned int> _face_edge; 72 : /// Fractional distance along the cut edges where the cut is located 73 : std::vector<Real> _position; 74 : }; 75 : 76 : /// Data structure describing geometrically described cut through 2D element 77 : struct GeomMarkedElemInfo2D 78 : { 79 : /// Container for data about all cut edges in this element 80 : std::vector<CutEdge> _elem_cut_edges; 81 : /// Container for data about all cut nodes in this element 82 : std::vector<CutNode> _elem_cut_nodes; 83 : /// Container for data about all cut fragments in this element 84 : std::vector<CutEdge> _frag_cut_edges; 85 : /// Container for data about all cut edges in cut fragments in this element 86 : std::vector<std::vector<Point>> _frag_edges; 87 : }; 88 : 89 : /// Data structure describing geometrically described cut through 3D element 90 : struct GeomMarkedElemInfo3D 91 : { 92 : /// Container for data about all cut faces in this element 93 : std::vector<CutFace> _elem_cut_faces; 94 : /// Container for data about all faces this element's fragment 95 : std::vector<CutFace> _frag_cut_faces; 96 : /// Container for data about all cut faces in cut fragments in this element 97 : std::vector<std::vector<Point>> _frag_faces; 98 : }; 99 : 100 : } // namespace Xfem 101 : 102 : class GeometricCutUserObject : public CrackFrontPointsProvider 103 : { 104 : public: 105 : /** 106 : * Factory constructor, takes parameters so that all derived classes can be built using the same 107 : * constructor. 108 : */ 109 : static InputParameters validParams(); 110 : 111 : GeometricCutUserObject(const InputParameters & parameters, const bool uses_mesh = false); 112 : 113 : virtual void initialize() override; 114 : virtual void execute() override; 115 : virtual void threadJoin(const UserObject & y) override; 116 : virtual void finalize() override; 117 : 118 : /** 119 : * Check to see whether a specified 2D element should be cut based on geometric 120 : * conditions 121 : * @param elem Pointer to the libMesh element to be considered for cutting 122 : * @param cut_edges Data structure filled with information about edges to be cut 123 : * @param cut_nodes Data structure filled with information about nodes to be cut 124 : * @return bool true if element is to be cut 125 : */ 126 : virtual bool cutElementByGeometry(const Elem * elem, 127 : std::vector<Xfem::CutEdge> & cut_edges, 128 : std::vector<Xfem::CutNode> & cut_nodes) const = 0; 129 : 130 : /** 131 : * Check to see whether a specified 3D element should be cut based on geometric 132 : * conditions 133 : * @param elem Pointer to the libMesh element to be considered for cutting 134 : * @param cut_faces Data structure filled with information about edges to be cut 135 : * @return bool true if element is to be cut 136 : */ 137 : virtual bool cutElementByGeometry(const Elem * elem, 138 : std::vector<Xfem::CutFace> & cut_faces) const = 0; 139 : 140 : /** 141 : * Check to see whether a fragment of a 2D element should be cut based on geometric conditions 142 : * @param frag_edges Data structure defining the current fragment to be considered 143 : * @param cut_edges Data structure filled with information about fragment edges to be cut 144 : * @return bool true if fragment is to be cut 145 : */ 146 : virtual bool cutFragmentByGeometry(std::vector<std::vector<Point>> & frag_edges, 147 : std::vector<Xfem::CutEdge> & cut_edges) const = 0; 148 : 149 : /** 150 : * Check to see whether a fragment of a 3D element should be cut based on geometric conditions 151 : * @param frag_faces Data structure defining the current fragment to be considered 152 : * @param cut_faces Data structure filled with information about fragment faces to be cut 153 : * @return bool true if fragment is to be cut 154 : */ 155 : virtual bool cutFragmentByGeometry(std::vector<std::vector<Point>> & frag_faces, 156 : std::vector<Xfem::CutFace> & cut_faces) const = 0; 157 : 158 : /** 159 : * Get the interface ID for this cutting object. 160 : * @return the interface ID 161 : */ 162 48758 : unsigned int getInterfaceID() const { return _interface_id; }; 163 : 164 : /** 165 : * Set the interface ID for this cutting object. 166 : * @param the interface ID 167 : */ 168 493 : void setInterfaceID(unsigned int interface_id) { _interface_id = interface_id; }; 169 : 170 : /** 171 : * Should the elements cut by this cutting object be healed in the current 172 : * time step? 173 : * @return true if the cut element should be healed 174 : */ 175 16330 : bool shouldHealMesh() const { return _heal_always; }; 176 : 177 : /** 178 : * Get CutSubdomainID telling which side the node belongs to relative to the cut. 179 : * The returned ID contains no physical meaning, but should be consistent throughout the 180 : * simulation. 181 : * @param node Pointer to the node 182 : * @return An unsigned int indicating the side 183 : */ 184 0 : virtual CutSubdomainID getCutSubdomainID(const Node * /*node*/) const 185 : { 186 0 : mooseError("Objects that inherit from GeometricCutUserObject should override the " 187 : "getCutSubdomainID method"); 188 : return 0; 189 : } 190 : 191 : /** 192 : * Get the CutSubdomainID for the given element. 193 : * @param node Pointer to the element 194 : * @return The CutSubdomainID 195 : */ 196 : CutSubdomainID getCutSubdomainID(const Elem * elem) const; 197 : 198 : protected: 199 : /// Pointer to the XFEM controller object 200 : std::shared_ptr<XFEM> _xfem; 201 : 202 : /// Associated interface id 203 : unsigned int _interface_id; 204 : 205 : /// Heal the mesh 206 : bool _heal_always; 207 : 208 : /// Time step information needed to advance a 3D crack only at the real beginning of a time step 209 : int _last_step_initialized; 210 : 211 : ///@{Containers with information about all 2D and 3D elements marked for cutting by this object 212 : std::map<unsigned int, std::vector<Xfem::GeomMarkedElemInfo2D>> _marked_elems_2d; 213 : std::map<unsigned int, std::vector<Xfem::GeomMarkedElemInfo3D>> _marked_elems_3d; 214 : ///@} 215 : 216 : ///@{ Methods to pack/unpack the _marked_elems_2d and _marked_elems_3d data into a structure suitable for parallel communication 217 : void serialize(std::string & serialized_buffer); 218 : void deserialize(std::vector<std::string> & serialized_buffers); 219 : ///@} 220 : };