14 #include "libmesh/mesh_modification.h" 26 MooseEnum cutting_type(
"CUT_ELEM_TRI MOV_NODE",
"CUT_ELEM_TRI");
30 "Which method is to be used to cut the input mesh. 'CUT_ELEM_TRI' is the recommended method " 31 "but it may cause fine elements near the cutting line, while 'MOV_NODE' deforms subdomain " 32 "boundaries if they are not perpendicular to the cutting line.");
34 params.
addRequiredParam<MeshGeneratorName>(
"input",
"The input mesh that needs to be trimmed.");
37 "Cutting line parameters, which are a, b, and c in line equation a*x+b*y+c=0. Note that " 38 "a*x+b*y+c>0 part is being removed.");
40 "new_boundary_id",
"Boundary id to be assigned to the boundary formed by the cutting.");
42 "Boundary id of the external boundary of the input mesh.");
43 params.
addParam<std::vector<boundary_id_type>>(
44 "other_boundaries_to_conform",
45 "IDs of the other boundaries that need to be conformed to during nodes moving.");
48 "tri_elem_subdomain_name_suffix",
50 "Suffix to the block name used for quad elements that are trimmed/converted into " 51 "triangular elements to avert degenerate quad elements");
53 "tri_elem_subdomain_shift",
54 "Customized id shift to define subdomain ids of the converted triangular elements.");
56 "improve_tri_elements",
false,
"Whether to improve TRI3 elements after CUT_ELEM_TRI method.");
59 "This XYMeshLineCutter object is designed to trim the input mesh by removing all the " 60 "elements on one side of a given straight line with special processing on the elements " 61 "crossed by the cutting line to ensure a smooth cross-section.");
68 _cutting_type(getParam<
MooseEnum>(
"cutting_type").template getEnum<
CutType>()),
69 _input_name(getParam<MeshGeneratorName>(
"input")),
70 _cut_line_params(getParam<
std::vector<
Real>>(
"cut_line_params")),
72 _input_mesh_external_boundary_id(
73 isParamValid(
"input_mesh_external_boundary_id")
76 _other_boundaries_to_conform(
77 isParamValid(
"other_boundaries_to_conform")
80 _tri_elem_subdomain_name_suffix(getParam<SubdomainName>(
"tri_elem_subdomain_name_suffix")),
81 _tri_elem_subdomain_shift(isParamValid(
"tri_elem_subdomain_shift")
84 _improve_tri_elements(getParam<bool>(
"improve_tri_elements")),
85 _input(getMeshByName(_input_name))
88 paramError(
"cut_line_params",
"this parameter must have three elements.");
91 paramError(
"cut_line_params",
"At lease one of the first two elements must be non-zero.");
94 "This parameter is not supported when 'MOV_NODE' method is selected as " 99 "input_mesh_external_boundary_id",
100 "This parameter must be provided if 'MOV_NODE' method is selected as 'cutting_type'.");
103 std::unique_ptr<MeshBase>
106 auto replicated_mesh_ptr =
dynamic_cast<ReplicatedMesh *
>(
_input.get());
107 if (!replicated_mesh_ptr)
108 paramError(
"input",
"Input is not a replicated mesh, which is required");
109 if (*(replicated_mesh_ptr->elem_dimensions().begin()) != 2 ||
110 *(replicated_mesh_ptr->elem_dimensions().rbegin()) != 2)
111 paramError(
"input",
"Only 2D meshes are supported.");
116 paramError(
"input_mesh_external_boundary_id",
"Boundary must exist in input mesh");
123 "Boundary '" + std::to_string(bid) +
"' must exist in input mesh");
125 ReplicatedMesh &
mesh = *replicated_mesh_ptr;
127 std::set<subdomain_id_type> subdomain_ids_set;
128 mesh.subdomain_ids(subdomain_ids_set);
145 tri_subdomain_id_shift,
153 if (((std::string)e.
what()).compare(
"The new subdomain name already exists in the mesh.") ==
157 mooseError(
"In XYMeshLineCutter with 'CUT_ELEM_TRI' mode, " + (std::string)e.
what());
174 if (((std::string)e.
what())
175 .compare(
"The input mesh has degenerate quad element before trimming.") == 0)
177 else if (((std::string)e.
what())
178 .compare(
"The new subdomain name already exists in the mesh.") == 0)
181 mooseError(
"In XYMeshLineCutter with 'MOV_NODE' mode, " + (std::string)e.
what());
190 mesh.prepare_for_use();
void lineRemoverCutElem(libMesh::ReplicatedMesh &mesh, const std::vector< Real > &cut_line_params, const dof_id_type tri_subdomain_id_shift, const SubdomainName tri_elem_subdomain_name_suffix, const subdomain_id_type block_id_to_remove, const boundary_id_type new_boundary_id, const bool improve_boundary_tri_elems=false)
Trim the 2D mesh by removing all the elements on one side of the given line.
registerMooseObject("MooseApp", XYMeshLineCutter)
virtual const char * what() const
Get out the error message.
const bool _improve_tri_elements
Whether to improve TRI3 elements after CUT_ELEM_TRI method.
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
const boundary_id_type _new_boundary_id
Boundary id to be assigned to the boundary formed by the cutting.
const BoundaryID INVALID_BOUNDARY_ID
void lineRemoverMoveNode(libMesh::ReplicatedMesh &mesh, const std::vector< Real > &bdry_pars, const subdomain_id_type block_id_to_remove, const std::set< subdomain_id_type > &subdomain_ids_set, const boundary_id_type trimming_section_boundary_id, const boundary_id_type external_boundary_id, const std::vector< boundary_id_type > &other_boundaries_to_conform=std::vector< boundary_id_type >(), const bool assign_ext_to_new=false, const bool side_to_remove=true)
Removes all the elements on one side of a given line and deforms the elements intercepted by the line...
enum XYMeshLineCutter::CutType _cutting_type
bool hasBoundaryID(const MeshBase &input_mesh, const BoundaryID id)
Whether a particular boundary ID exists in the mesh.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
const SubdomainID INVALID_BLOCK_ID
XYMeshLineCutter(const InputParameters ¶meters)
std::unique_ptr< MeshBase > & _input
Reference to input mesh pointer.
static InputParameters validParams()
const boundary_id_type _input_mesh_external_boundary_id
Boundary id of the external boundary of the input mesh (only needed for MOV_NODE method) ...
bool quasiTriElementsFixer(libMesh::ReplicatedMesh &mesh, const std::set< subdomain_id_type > &subdomain_ids_set, const subdomain_id_type tri_elem_subdomain_shift=Moose::INVALID_BLOCK_ID, const SubdomainName tri_elem_subdomain_name_suffix="tri")
Fixes degenerate QUAD elements created by the hexagonal mesh trimming by converting them into TRI ele...
CutType
Method to cut the input mesh.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
const std::vector< boundary_id_type > _other_boundaries_to_conform
IDs of the other boundaries that need to be conformed to during nodes moving (only needed for MOV_NOD...
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
static InputParameters validParams()
const SubdomainName _tri_elem_subdomain_name_suffix
SubdomainName suffix used to rename the converted triangular elements.
Provides a way for users to bail out of the current solve.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const subdomain_id_type _tri_elem_subdomain_shift
Customized id shift to define subdomain ids of the converted triangular elements. ...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
This XYMeshLineCutter object is designed to trim the input mesh by removing all the elements on one s...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const std::vector< Real > _cut_line_params
Cutting line parameters, which are a, b, and c in line equation a*x+b*y+c=0. Note that a*x+b*y+c>0 pa...
BoundaryID getNextFreeBoundaryID(MeshBase &input_mesh)
Checks input mesh and returns the largest boundary ID in the mesh plus one, which is a boundary ID in...
MeshGenerators are objects that can modify or add to an existing mesh.