Skip to content

Commit

Permalink
Merge pull request #25169 from BoZeng1997/annularmeshgen_boundary
Browse files Browse the repository at this point in the history
AnnularMeshGenerator apply offset in boundary ids and prefix on boundary names
  • Loading branch information
GiudGiud authored Aug 11, 2023
2 parents 5490ab9 + 771eb58 commit 3c86f3d
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 2 deletions.
6 changes: 6 additions & 0 deletions framework/include/meshgenerators/AnnularMeshGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ class AnnularMeshGenerator : public MeshGenerator

/// Whether to construct rings to have equal areas
const bool & _equal_area;

/// prefix string for the boundary names
const BoundaryName _boundary_name_prefix;

/// offset that is added to the boundary IDs
const boundary_id_type _boundary_id_offset;
};
34 changes: 32 additions & 2 deletions framework/src/meshgenerators/AnnularMeshGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "libmesh/replicated_mesh.h"
#include "libmesh/face_quad4.h"
#include "libmesh/face_tri3.h"
#include "libmesh/mesh_modification.h"

registerMooseObject("MooseApp", AnnularMeshGenerator);

Expand Down Expand Up @@ -71,6 +72,10 @@ AnnularMeshGenerator::validParams()
"dmax!=360, a sector of an annulus or disc is created. In this case "
"boundary sidesets are also created at dmin and dmax, and "
"given these names");
params.addParam<BoundaryName>("boundary_name_prefix",
"If provided, prefix the built in boundary names with this string");
params.addParam<boundary_id_type>(
"boundary_id_offset", 0, "This offset is added to the generated boundary IDs");

return params;
}
Expand All @@ -96,7 +101,11 @@ AnnularMeshGenerator::AnnularMeshGenerator(const InputParameters & parameters)
_full_annulus(_dmin == 0.0 && _dmax == 360),
_quad_subdomain_id(getParam<SubdomainID>("quad_subdomain_id")),
_tri_subdomain_id(getParam<SubdomainID>("tri_subdomain_id")),
_equal_area(getParam<bool>("equal_area"))
_equal_area(getParam<bool>("equal_area")),
_boundary_name_prefix(isParamValid("boundary_name_prefix")
? getParam<BoundaryName>("boundary_name_prefix") + "_"
: ""),
_boundary_id_offset(getParam<boundary_id_type>("boundary_id_offset"))
{
if ((parameters.isParamSetByUser("tmin") || parameters.isParamSetByUser("tmax")) &&
(parameters.isParamSetByUser("dmin") || parameters.isParamSetByUser("dmax")))
Expand Down Expand Up @@ -291,8 +300,29 @@ AnnularMeshGenerator::generate()
boundary_info.nodeset_name(3) = "dmax";
}
}
if (_boundary_id_offset != 0 || !_boundary_name_prefix.empty())
{
// apply boundary id offset and name prefix
const auto mesh_boundary_ids = boundary_info.get_boundary_ids();
for (auto rit = mesh_boundary_ids.rbegin(); rit != mesh_boundary_ids.rend(); ++rit)
{

mesh->prepare_for_use();
const std::string old_sideset_name = boundary_info.sideset_name(*rit);
const std::string old_nodeset_name = boundary_info.nodeset_name(*rit);

if (_boundary_id_offset != 0)
MeshTools::Modification::change_boundary_id(*mesh, *rit, *rit + _boundary_id_offset);

if (!_boundary_name_prefix.empty())
{
boundary_info.sideset_name(*rit + _boundary_id_offset) =
_boundary_name_prefix + old_sideset_name;
boundary_info.nodeset_name(*rit + _boundary_id_offset) =
_boundary_name_prefix + old_nodeset_name;
}
}
}

mesh->prepare_for_use();
return dynamic_pointer_cast<MeshBase>(mesh);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[Mesh]
[amg]
type = AnnularMeshGenerator
nt = 12
rmin = 1
rmax = 5
dmin = 45
dmax = 135
boundary_id_offset = 7
boundary_name_prefix = bunga
[]
[rename]
type = RenameBoundaryGenerator
input = amg
old_boundary = '7 bunga_rmax'
new_boundary = 'little_john khan'
[]
[]

[Outputs]
exodus = true
[]
Binary file not shown.
11 changes: 11 additions & 0 deletions test/tests/meshgenerators/annular_mesh_generator/tests
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,15 @@
design = 'meshgenerators/AnnularMeshGenerator.md'
issues = '#20422'
[]
[boundary_prefix_offset]
type = Exodiff
input = boundary_prefix_offset.i
cli_args = '--mesh-only'
exodiff = boundary_prefix_offset_in.e
mesh_mode = 'REPLICATED'
recover = false
requirement = 'The system shall have the capability of generating an annular mesh with a user-defined prefix on boundary names and/or an offset on the boundary ids'
design = 'meshgenerators/AnnularMeshGenerator.md'
issues = '#25167'
[]
[]

0 comments on commit 3c86f3d

Please sign in to comment.