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/replicated_mesh.h" 13 : 14 : #include "MooseTypes.h" 15 : 16 : namespace MooseMeshElementConversionUtils 17 : { 18 : // Define for comparing the key value of BCTuple 19 : struct BCTupleKeyComp 20 : { 21 299064 : bool operator()(const libMesh::BoundaryInfo::BCTuple & s, dof_id_type i) const 22 : { 23 299064 : return std::get<0>(s) < i; 24 : } 25 140376 : bool operator()(dof_id_type i, const libMesh::BoundaryInfo::BCTuple & s) const 26 : { 27 140376 : return i < std::get<0>(s); 28 : } 29 : }; 30 : 31 : /** 32 : * Split a HEX8 element into six TET4 elements. 33 : * @param mesh The mesh to be modified 34 : * @param bdry_side_list A list that contains the boundary information of the original mesh 35 : * @param elem_id The id of the element to be split 36 : * @param converted_elems_ids a vector to record the ids of the newly created TET4 elements 37 : */ 38 : void hexElemSplitter(ReplicatedMesh & mesh, 39 : const std::vector<libMesh::BoundaryInfo::BCTuple> & bdry_side_list, 40 : const dof_id_type elem_id, 41 : std::vector<dof_id_type> & converted_elems_ids); 42 : 43 : /** 44 : * Split a PYRAMID5 element into two TET4 elements. 45 : * @param mesh The mesh to be modified 46 : * @param bdry_side_list A list that contains the boundary information of the original mesh 47 : * @param elem_id The id of the element to be split 48 : * @param converted_elems_ids a vector to record the ids of the newly created TET4 elements 49 : */ 50 : void pyramidElemSplitter(ReplicatedMesh & mesh, 51 : const std::vector<libMesh::BoundaryInfo::BCTuple> & bdry_side_list, 52 : const dof_id_type elem_id, 53 : std::vector<dof_id_type> & converted_elems_ids); 54 : 55 : /** 56 : * Split a PRISM6 element into three TET4 elements. 57 : * @param mesh The mesh to be modified 58 : * @param bdry_side_list A list that contains the boundary information of the original mesh 59 : * @param elem_id The id of the element to be split 60 : * @param converted_elems_ids a vector to record the ids of the newly created TET4 elements 61 : */ 62 : void prismElemSplitter(ReplicatedMesh & mesh, 63 : const std::vector<libMesh::BoundaryInfo::BCTuple> & bdry_side_list, 64 : const dof_id_type elem_id, 65 : std::vector<dof_id_type> & converted_elems_ids); 66 : 67 : /** 68 : * Rotate a HEX8 element's nodes to ensure that the node with the minimum id is the first node; 69 : * and the node among its three neighboring nodes with the minimum id is the second node. 70 : * @param min_id_index The index of the node with the minimum id 71 : * @param sec_min_pos The index of the node among its three neighboring nodes with the minimum 72 : * id (see comments in the function for more details about how the index is defined) 73 : * @param face_rotation A vector to record the rotation of the faces of the HEX8 element 74 : * @param node_rotation a vector of node indices that can form a HEX8 element 75 : */ 76 : void nodeRotationHEX8(const unsigned int min_id_index, 77 : const unsigned int sec_min_pos, 78 : std::vector<unsigned int> & face_rotation, 79 : std::vector<unsigned int> & node_rotation); 80 : 81 : /** 82 : * Calculate the indices (within the element nodes) of the three neighboring nodes of a node in a 83 : * HEX8 element. 84 : * @param min_id_index The index of the node with the minimum id 85 : * @return a vector of the three neighboring nodes 86 : */ 87 : std::vector<unsigned int> neighborNodeIndicesHEX8(unsigned int min_id_index); 88 : 89 : /** 90 : * For a vector of rotated nodes that can form a HEX8 element, create a vector of four-node sets 91 : * that can form TET4 elements to replace the original HEX8 element. All the QUAD4 faces of the 92 : * HEX8 element will be split by the diagonal line that involves the node with the minimum id of 93 : * that face. 94 : * @param hex_nodes A vector of pointers to the nodes that can form a HEX8 element 95 : * @param rotated_tet_face_indices A vector of vectors of the original face indices of the HEX8 96 : * element corresponding to the faces of the newly created TET4 elements 97 : * @param tet_nodes_list a vector of vectors of pointers to the nodes that can form TET4 elements 98 : */ 99 : void hexNodesToTetNodesDeterminer(std::vector<const Node *> & hex_nodes, 100 : std::vector<std::vector<unsigned int>> & rotated_tet_face_indices, 101 : std::vector<std::vector<const Node *>> & tet_nodes_list); 102 : 103 : /** 104 : * For a HEX8 element, determine the direction of the diagonal line of each face that involves the 105 : * node with the minimum id of that face. 106 : * @param hex_nodes A vector of pointers to the nodes that can form a HEX8 element 107 : * @return a vector of boolean values indicating the direction of the diagonal line of each face 108 : */ 109 : std::vector<bool> quadFaceDiagonalDirectionsHex(const std::vector<const Node *> & hex_nodes); 110 : 111 : /** 112 : * For a QUAD4 element, determine the direction of the diagonal line that involves the node with 113 : * the minimum id of that element. 114 : * @param quad_nodes A vector of pointers to the nodes that can form a QUAD4 element 115 : * @return a boolean value indicating the direction of the diagonal line 116 : */ 117 : bool quadFaceDiagonalDirection(const std::vector<const Node *> & quad_nodes); 118 : 119 : /** 120 : * Creates sets of four nodes indices that can form TET4 elements to replace the original HEX8 121 : * element. 122 : * @param diagonal_directions A vector of boolean values indicating the direction of the diagonal 123 : * line of each face; true means the diagonal line is connecting node 0 and node 2, false means the 124 : * diagonal line is connecting node 1 and node 3 of that quad face 125 : * @param tet_face_indices A vector of vectors of the original face indices of the HEX8 element 126 : * corresponding to the faces of the newly created TET4 elements 127 : * @return a vector of vectors of node indices that can form TET4 elements 128 : */ 129 : std::vector<std::vector<unsigned int>> 130 : tetNodesForHex(const std::vector<bool> diagonal_directions, 131 : std::vector<std::vector<unsigned int>> & tet_face_indices); 132 : 133 : /** 134 : * Rotate a PRISM6 element nodes to ensure that the node with the minimum id is the first node. 135 : * @param min_id_index The index of the node, within the prism nodes, with the minimum id 136 : * @param face_rotation A vector to record the rotation of the faces of the PRISM6 element 137 : * @param node_rotation a vector of node indices that can form a PRISM6 element 138 : */ 139 : void nodeRotationPRISM6(unsigned int min_id_index, 140 : std::vector<unsigned int> & face_rotation, 141 : std::vector<unsigned int> & node_rotation); 142 : 143 : /** 144 : * For a rotated nodes that can form a PRISM6 element, create a series of four-node set that can 145 : * form TET4 elements to replace the original PRISM6 element. All the QUAD4 face of the PRISM6 146 : * element will be split by the diagonal line that involves the node with the minimum id of that 147 : * face. 148 : * @param prism_nodes A vector of pointers to the nodes that can form a PRISM6 element 149 : * @param rotated_tet_face_indices A vector of vectors of the original face indices of the PRISM6 150 : * element corresponding to the faces of the newly created TET4 elements 151 : * @param tet_nodes_list a vector of vectors of pointers to the nodes that can form TET4 elements 152 : */ 153 : void 154 : prismNodesToTetNodesDeterminer(std::vector<const Node *> & prism_nodes, 155 : std::vector<std::vector<unsigned int>> & rotated_tet_face_indices, 156 : std::vector<std::vector<const Node *>> & tet_nodes_list); 157 : 158 : /** 159 : * Creates sets of four nodes indices that can form TET4 elements to replace the original PRISM6 160 : * element. 161 : * @param diagonal_direction A boolean value indicating the direction of the diagonal line of Face 162 : * 2 163 : * @param tet_face_indices A vector of vectors of the original face indices of the PRISM6 element 164 : * corresponding to the faces of the newly created TET4 elements 165 : * @return a vector of vectors of node indices that can form TET4 elements 166 : */ 167 : std::vector<std::vector<unsigned int>> 168 : tetNodesForPrism(const bool diagonal_direction, 169 : std::vector<std::vector<unsigned int>> & tet_face_indices); 170 : 171 : /** 172 : * Rotate a PYRAMID5 element nodes to ensure that the node with the minimum id is the first node 173 : * for the bottom face. 174 : * @param min_id_index The index of the node, within the pyramid nodes, with the minimum id for the 175 : * bottom face 176 : * @param face_rotation A vector to record the rotation of the faces of the PYRAMID5 element 177 : * @param node_rotation a vector of node indices that can form a PYRAMID5 element 178 : */ 179 : void nodeRotationPYRAMID5(unsigned int min_id_index, 180 : std::vector<unsigned int> & face_rotation, 181 : std::vector<unsigned int> & node_rotation); 182 : 183 : /** 184 : * For a rotated nodes that can form a PYRAMID5 element, create a series of four-node set that can 185 : * form TET4 elements to replace the original PYRAMID5 element. The QUAD4 face of the 186 : * PYRAMID5 element will be split by the diagonal line that involves the node with the minimum id 187 : * of that face. 188 : * @param pyramid_nodes A vector of pointers to the nodes that can form a PYRAMID5 element 189 : * @param rotated_tet_face_indices A vector of vectors of the original face indices of the 190 : * PYRAMID5 element corresponding to the faces of the newly created TET4 elements 191 : * @param tet_nodes_list a vector of vectors of pointers to the nodes that can form TET4 elements 192 : */ 193 : void 194 : pyramidNodesToTetNodesDeterminer(std::vector<const Node *> & pyramid_nodes, 195 : std::vector<std::vector<unsigned int>> & rotated_tet_face_indices, 196 : std::vector<std::vector<const Node *>> & tet_nodes_list); 197 : 198 : /** 199 : * Convert all the elements in a 3D mesh, consisting of only linear elements, into TET4 elements. 200 : * @param mesh The mesh to be converted 201 : * @param elems_to_process A vector of pairs of element ids and a bool indicating whether the 202 : * element needs to be fully retained or will be further processed in the following procedures 203 : * @param converted_elems_ids_to_track A vector of element ids that need to be tracked for beig 204 : * further processed in the following procedures 205 : * @param block_id_to_remove The id of a new subdomain in the mesh containing all the elements to be 206 : * removed 207 : * @param delete_block_to_remove A bool indicating whether the block to be removed will be 208 : * deleted in this method 209 : */ 210 : void convert3DMeshToAllTet4(ReplicatedMesh & mesh, 211 : const std::vector<std::pair<dof_id_type, bool>> & elems_to_process, 212 : std::vector<dof_id_type> & converted_elems_ids_to_track, 213 : const subdomain_id_type block_id_to_remove, 214 : const bool delete_block_to_remove); 215 : 216 : /** 217 : * Convert all the elements in a 3D mesh consisting of only linear elements into TET4 elements. 218 : * @param mesh The mesh to be converted 219 : */ 220 : void convert3DMeshToAllTet4(ReplicatedMesh & mesh); 221 : 222 : /** 223 : * Collect the boundary information of the given element in a mesh. 224 : * @param bdry_side_list A list that contains the boundary information of the mesh 225 : * @param elem_id The id of the element to be processed 226 : * @param n_elem_sides The number of sides of the element 227 : * @param elem_side_list a vector of vectors to record the boundary information of the element 228 : */ 229 : void 230 : elementBoundaryInfoCollector(const std::vector<libMesh::BoundaryInfo::BCTuple> & bdry_side_list, 231 : const dof_id_type elem_id, 232 : const unsigned short n_elem_sides, 233 : std::vector<std::vector<boundary_id_type>> & elem_side_list); 234 : }