From 27b915d1cea1232063cef9ed65a40718d07fa300 Mon Sep 17 00:00:00 2001 From: Bo Zeng Date: Wed, 9 Aug 2023 18:05:36 -0600 Subject: [PATCH 1/4] allow AnnularMeshGenerator to apply offset in boundary ids and prefix on boundary names closes #25167 --- .../meshgenerators/AnnularMeshGenerator.h | 6 ++++ .../src/meshgenerators/AnnularMeshGenerator.C | 27 ++++++++++++++++-- .../boundary_prefix_offset.i | 16 +++++++++++ .../gold/boundary_prefix_offset_in.e | Bin 0 -> 6088 bytes .../annular_mesh_generator/tests | 11 +++++++ 5 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i create mode 100644 test/tests/meshgenerators/annular_mesh_generator/gold/boundary_prefix_offset_in.e diff --git a/framework/include/meshgenerators/AnnularMeshGenerator.h b/framework/include/meshgenerators/AnnularMeshGenerator.h index da054f057c98..095238096852 100644 --- a/framework/include/meshgenerators/AnnularMeshGenerator.h +++ b/framework/include/meshgenerators/AnnularMeshGenerator.h @@ -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 std::string _boundary_name_prefix; + + /// offset that is added to the boundary IDs + const boundary_id_type _boundary_id_offset; }; diff --git a/framework/src/meshgenerators/AnnularMeshGenerator.C b/framework/src/meshgenerators/AnnularMeshGenerator.C index bc70f9e34cde..0d508b74c265 100644 --- a/framework/src/meshgenerators/AnnularMeshGenerator.C +++ b/framework/src/meshgenerators/AnnularMeshGenerator.C @@ -71,6 +71,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("boundary_name_prefix", + "If provided, prefix the built in boundary names with this string"); + params.addParam( + "boundary_id_offset", 0, "This offset is added to the generated boundary IDs"); return params; } @@ -96,7 +100,11 @@ AnnularMeshGenerator::AnnularMeshGenerator(const InputParameters & parameters) _full_annulus(_dmin == 0.0 && _dmax == 360), _quad_subdomain_id(getParam("quad_subdomain_id")), _tri_subdomain_id(getParam("tri_subdomain_id")), - _equal_area(getParam("equal_area")) + _equal_area(getParam("equal_area")), + _boundary_name_prefix(isParamValid("boundary_name_prefix") + ? getParam("boundary_name_prefix") + "_" + : ""), + _boundary_id_offset(getParam("boundary_id_offset")) { if ((parameters.isParamSetByUser("tmin") || parameters.isParamSetByUser("tmax")) && (parameters.isParamSetByUser("dmin") || parameters.isParamSetByUser("dmax"))) @@ -292,7 +300,22 @@ AnnularMeshGenerator::generate() } } - mesh->prepare_for_use(); + // 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) + { + + const std::string old_sideset_name = boundary_info.sideset_name(*rit); + const std::string old_nodeset_name = boundary_info.nodeset_name(*rit); + + MeshTools::Modification::change_boundary_id(*mesh, *rit, *rit + _boundary_id_offset); + 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(mesh); } diff --git a/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i b/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i new file mode 100644 index 000000000000..7f75083e3b01 --- /dev/null +++ b/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i @@ -0,0 +1,16 @@ +[Mesh] + [amg] + type = AnnularMeshGenerator + nt = 12 + rmin = 1 + rmax = 5 + dmin = 45 + dmax = 135 + boundary_id_offset = 7 + boundary_name_prefix = bunga + [] +[] + +[Outputs] + exodus = true +[] diff --git a/test/tests/meshgenerators/annular_mesh_generator/gold/boundary_prefix_offset_in.e b/test/tests/meshgenerators/annular_mesh_generator/gold/boundary_prefix_offset_in.e new file mode 100644 index 0000000000000000000000000000000000000000..bfb8222dbc3b0eccee28d9b8531cfbbbd865d343 GIT binary patch literal 6088 zcmeHLU1%It6rPwinc3ZT+ibU6MbHN+K1j7`s1FuqN<&N`53NOwRTyTov&qn%nPq3z zBrByp_#lp6}i{>m+GR_Bngt z%)N8&x!*bWJ2!W8XW!t^EsB&BHGQON#r90ka&1NF!iW|+u5AXPUB#P}Ua#(&CC9}Z z=4*KO{E{8W@!P0TVY4eXoHC>-`EC{~M}!l=H}E_&u)}!nI<^N+iQ+D>Z;UY<4=_6g z4zRN^j#;&96jKZUCj-0031Eb8($;?y+b*&px1`@dY)f+-PrxY~$eyqPZm|t;f}?~V z;DinN^pd8ns$)KB*8<1)Ft(nwYj4-5C#mgS#=fmw@vYGD#?7klc%eDz*Gjb32Gvc$ z+OYi5Q!@%KFd= zD+ow}eQgGcG;OS{c@QqXgb~w;gyCDX-e#=$q7H6j9j2BJ=8(&B!zSI z(Cp%W3D7%y!4V5`f|95P9^_xG`Bl`MeZe*Q>*U@R`F8IgB#WHO^I_4vU`agW!~)+< z@!B&mIf0w*jP*YNQ-n!d3v`B!80p3_UW!e_?zk4^HUc zhmN9bJwOjt_y^(uM6USVU`hHuO-40w_WqymJMfKhafrefX9Y_V_aYe?cLm?VCiup< zt#h40sRb^Sq+rm4aaZykgl~+?zYX{;U`gT*laX;(@*RP%+z%~&H!>)-z>UjT5VeSX znTPB$zR!@Iad~avh6T9TM^cp zjlc94bMyMouf9?~_P`fLX81GZj#Sf7AAA2~WAw6qk!BEvf#}rg-yOYl=B?LD`i;|% zA2@vI6aB)>(X%h~%;U&gjS z_vl@-@p{h3>xqo)$Jck*J8UwfW( zD`|mr8|kg2_-=Z$IItlm$K%+1zv3Kl&q92B4?v&u;G8%g&W-cp963MEmGk7BIbY75 z^X4@ymp|vt`Es88&7vJ%!9}~;4nFGJj&i-Q7SxE}Q6tm^wE+L%96W Date: Thu, 10 Aug 2023 09:59:58 -0600 Subject: [PATCH 2/4] address Guillaume's review suggestions --- .../meshgenerators/AnnularMeshGenerator.h | 2 +- .../src/meshgenerators/AnnularMeshGenerator.C | 30 ++++++++++--------- .../annular_mesh_generator/tests | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/framework/include/meshgenerators/AnnularMeshGenerator.h b/framework/include/meshgenerators/AnnularMeshGenerator.h index 095238096852..8b8251170a95 100644 --- a/framework/include/meshgenerators/AnnularMeshGenerator.h +++ b/framework/include/meshgenerators/AnnularMeshGenerator.h @@ -68,7 +68,7 @@ class AnnularMeshGenerator : public MeshGenerator const bool & _equal_area; /// prefix string for the boundary names - const std::string _boundary_name_prefix; + const BoundaryName _boundary_name_prefix; /// offset that is added to the boundary IDs const boundary_id_type _boundary_id_offset; diff --git a/framework/src/meshgenerators/AnnularMeshGenerator.C b/framework/src/meshgenerators/AnnularMeshGenerator.C index 0d508b74c265..09e64a5e39b3 100644 --- a/framework/src/meshgenerators/AnnularMeshGenerator.C +++ b/framework/src/meshgenerators/AnnularMeshGenerator.C @@ -71,8 +71,8 @@ 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("boundary_name_prefix", - "If provided, prefix the built in boundary names with this string"); + params.addParam("boundary_name_prefix", + "If provided, prefix the built in boundary names with this string"); params.addParam( "boundary_id_offset", 0, "This offset is added to the generated boundary IDs"); @@ -102,7 +102,7 @@ AnnularMeshGenerator::AnnularMeshGenerator(const InputParameters & parameters) _tri_subdomain_id(getParam("tri_subdomain_id")), _equal_area(getParam("equal_area")), _boundary_name_prefix(isParamValid("boundary_name_prefix") - ? getParam("boundary_name_prefix") + "_" + ? getParam("boundary_name_prefix") + "_" : ""), _boundary_id_offset(getParam("boundary_id_offset")) { @@ -299,21 +299,23 @@ AnnularMeshGenerator::generate() boundary_info.nodeset_name(3) = "dmax"; } } - - // 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) + 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) + { - const std::string old_sideset_name = boundary_info.sideset_name(*rit); - const std::string old_nodeset_name = boundary_info.nodeset_name(*rit); + const std::string old_sideset_name = boundary_info.sideset_name(*rit); + const std::string old_nodeset_name = boundary_info.nodeset_name(*rit); - MeshTools::Modification::change_boundary_id(*mesh, *rit, *rit + _boundary_id_offset); + MeshTools::Modification::change_boundary_id(*mesh, *rit, *rit + _boundary_id_offset); - 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; + 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(); diff --git a/test/tests/meshgenerators/annular_mesh_generator/tests b/test/tests/meshgenerators/annular_mesh_generator/tests index db4efb921db5..08a995c1bf94 100644 --- a/test/tests/meshgenerators/annular_mesh_generator/tests +++ b/test/tests/meshgenerators/annular_mesh_generator/tests @@ -83,7 +83,7 @@ exodiff = boundary_prefix_offset_in.e mesh_mode = 'REPLICATED' recover = false - requirement = 'The system shall have the capability of generating an annular mesh with user defined prefix on boundary name and offset on boundary ids' + 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' [] From 9cc2b3424201684fa37d1408b2cbcab86507bab1 Mon Sep 17 00:00:00 2001 From: Bo Zeng Date: Thu, 10 Aug 2023 13:35:29 -0600 Subject: [PATCH 3/4] include libmesh/mesh_modification.h for Non Unity check. correct test --- framework/src/meshgenerators/AnnularMeshGenerator.C | 2 ++ .../annular_mesh_generator/boundary_prefix_offset.i | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/framework/src/meshgenerators/AnnularMeshGenerator.C b/framework/src/meshgenerators/AnnularMeshGenerator.C index 09e64a5e39b3..befa00298891 100644 --- a/framework/src/meshgenerators/AnnularMeshGenerator.C +++ b/framework/src/meshgenerators/AnnularMeshGenerator.C @@ -9,10 +9,12 @@ #include "AnnularMeshGenerator.h" #include "CastUniquePointer.h" +// #include "MooseEnum.h" #include "libmesh/replicated_mesh.h" #include "libmesh/face_quad4.h" #include "libmesh/face_tri3.h" +#include "libmesh/mesh_modification.h" registerMooseObject("MooseApp", AnnularMeshGenerator); diff --git a/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i b/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i index 7f75083e3b01..ad19e72f0cc3 100644 --- a/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i +++ b/test/tests/meshgenerators/annular_mesh_generator/boundary_prefix_offset.i @@ -9,6 +9,12 @@ boundary_id_offset = 7 boundary_name_prefix = bunga [] + [rename] + type = RenameBoundaryGenerator + input = amg + old_boundary = '7 bunga_rmax' + new_boundary = 'little_john khan' + [] [] [Outputs] From 771eb581fdb0c534b9639eb67d08bf8c8cd72394 Mon Sep 17 00:00:00 2001 From: Guillaume Giudicelli Date: Thu, 10 Aug 2023 23:43:15 -0600 Subject: [PATCH 4/4] Avoid unnecessary modifications --- .../src/meshgenerators/AnnularMeshGenerator.C | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/framework/src/meshgenerators/AnnularMeshGenerator.C b/framework/src/meshgenerators/AnnularMeshGenerator.C index befa00298891..923cffab1ccf 100644 --- a/framework/src/meshgenerators/AnnularMeshGenerator.C +++ b/framework/src/meshgenerators/AnnularMeshGenerator.C @@ -9,7 +9,6 @@ #include "AnnularMeshGenerator.h" #include "CastUniquePointer.h" -// #include "MooseEnum.h" #include "libmesh/replicated_mesh.h" #include "libmesh/face_quad4.h" @@ -311,12 +310,16 @@ AnnularMeshGenerator::generate() const std::string old_sideset_name = boundary_info.sideset_name(*rit); const std::string old_nodeset_name = boundary_info.nodeset_name(*rit); - MeshTools::Modification::change_boundary_id(*mesh, *rit, *rit + _boundary_id_offset); + if (_boundary_id_offset != 0) + MeshTools::Modification::change_boundary_id(*mesh, *rit, *rit + _boundary_id_offset); - 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; + 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; + } } }