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