LCOV - code coverage report
Current view: top level - src/meshgenerators - ConcentricCircleGeneratorBase.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #32971 (54bef8) with base c6cf66 Lines: 148 153 96.7 %
Date: 2026-05-29 20:39:24 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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             : #include "ConcentricCircleGeneratorBase.h"
      11             : 
      12             : InputParameters
      13        4894 : ConcentricCircleGeneratorBase::validParams()
      14             : {
      15        4894 :   InputParameters params = PolygonMeshGeneratorBase::validParams();
      16        9788 :   params.addRangeCheckedParam<std::vector<Real>>(
      17             :       "ring_radii", "ring_radii>0", "Radii of major concentric circles (rings).");
      18        9788 :   params.addRangeCheckedParam<std::vector<unsigned int>>(
      19             :       "ring_intervals",
      20             :       "ring_intervals>0",
      21             :       "Number of radial mesh intervals within each major concentric circle excluding their "
      22             :       "boundary layers.");
      23        9788 :   params.addRangeCheckedParam<std::vector<Real>>(
      24             :       "ring_radial_biases",
      25             :       "ring_radial_biases>0",
      26             :       "Values used to create biasing in radial meshing for ring regions.");
      27        9788 :   params.addRangeCheckedParam<std::vector<Real>>(
      28             :       "ring_inner_boundary_layer_widths",
      29             :       "ring_inner_boundary_layer_widths>=0",
      30             :       "Widths of each ring regions that are assigned to be each ring's inner boundary layers.");
      31        9788 :   params.addParam<std::vector<unsigned int>>(
      32             :       "ring_inner_boundary_layer_intervals",
      33             :       "Number of radial intervals of the rings' inner boundary layers");
      34        9788 :   params.addRangeCheckedParam<std::vector<Real>>(
      35             :       "ring_inner_boundary_layer_biases",
      36             :       "ring_inner_boundary_layer_biases>0",
      37             :       "Growth factors used for mesh biasing of the rings' inner boundary layers.");
      38        9788 :   params.addRangeCheckedParam<std::vector<Real>>(
      39             :       "ring_outer_boundary_layer_widths",
      40             :       "ring_outer_boundary_layer_widths>=0",
      41             :       "Widths of each ring regions that are assigned to be each ring's outer boundary layers.");
      42        9788 :   params.addParam<std::vector<unsigned int>>(
      43             :       "ring_outer_boundary_layer_intervals",
      44             :       "Number of radial intervals of the rings' outer boundary layers");
      45        9788 :   params.addRangeCheckedParam<std::vector<Real>>(
      46             :       "ring_outer_boundary_layer_biases",
      47             :       "ring_outer_boundary_layer_biases>0",
      48             :       "Growth factors used for mesh biasing of the rings' outer boundary layers.");
      49        9788 :   params.addParam<std::vector<subdomain_id_type>>(
      50             :       "ring_block_ids", "Optional customized block ids for each ring geometry block.");
      51        9788 :   params.addParam<std::vector<SubdomainName>>(
      52             :       "ring_block_names", "Optional customized block names for each ring geometry block.");
      53        9788 :   params.addParam<bool>("preserve_volumes",
      54        9788 :                         true,
      55             :                         "Volume of concentric circles can be preserved using this function.");
      56        9788 :   params.addParam<subdomain_id_type>("block_id_shift", 0, "Integer used to shift block IDs.");
      57        9788 :   params.addParam<bool>("create_inward_interface_boundaries",
      58        9788 :                         false,
      59             :                         "Whether the inward interface boundaries are created.");
      60        9788 :   params.addParam<bool>("create_outward_interface_boundaries",
      61        9788 :                         true,
      62             :                         "Whether the outward interface boundaries are created.");
      63        9788 :   params.addParam<boundary_id_type>(
      64        9788 :       "interface_boundary_id_shift", 0, "Integer used to shift interface boundary IDs.");
      65        9788 :   params.addParam<bool>("generate_side_specific_boundaries",
      66        9788 :                         false,
      67             :                         "whether the side-specific external boundaries are generated or not");
      68        9788 :   params.addRangeCheckedParam<boundary_id_type>("external_boundary_id",
      69             :                                                 "external_boundary_id>0",
      70             :                                                 "Optional customized external boundary id.");
      71        9788 :   params.addParam<BoundaryName>(
      72             :       "external_boundary_name", "", "Optional customized external boundary name.");
      73             : 
      74        9788 :   MooseEnum tri_elem_type("TRI3 TRI6 TRI7", "TRI3");
      75        9788 :   params.addParam<MooseEnum>(
      76             :       "tri_element_type", tri_elem_type, "Type of the triangular elements to be generated.");
      77        9788 :   MooseEnum quad_elem_type("QUAD4 QUAD8 QUAD9", "QUAD4");
      78        9788 :   params.addParam<MooseEnum>(
      79             :       "quad_element_type", quad_elem_type, "Type of the quadrilateral elements to be generated.");
      80             : 
      81        9788 :   params.addParam<std::vector<std::string>>(
      82             :       "inward_interface_boundary_names",
      83             :       "Optional customized boundary names for the internal inward interfaces between block.");
      84        9788 :   params.addParam<std::vector<std::string>>(
      85             :       "outward_interface_boundary_names",
      86             :       "Optional customized boundary names for the internal outward interfaces between block.");
      87             : 
      88        9788 :   params.addParamNamesToGroup(
      89             :       "ring_block_ids ring_block_names external_boundary_id external_boundary_name "
      90             :       "inward_interface_boundary_names outward_interface_boundary_names "
      91             :       "block_id_shift create_inward_interface_boundaries create_outward_interface_boundaries "
      92             :       "interface_boundary_id_shift generate_side_specific_boundaries",
      93             :       "Customized Subdomain/Boundary");
      94        9788 :   params.addParamNamesToGroup("ring_intervals", "General Mesh Density");
      95        9788 :   params.addParamNamesToGroup(
      96             :       "ring_radial_biases ring_inner_boundary_layer_biases ring_inner_boundary_layer_widths "
      97             :       "ring_inner_boundary_layer_intervals ring_outer_boundary_layer_biases "
      98             :       "ring_outer_boundary_layer_widths ring_outer_boundary_layer_intervals ",
      99             :       "Mesh Boundary Layers and Biasing Options");
     100             : 
     101        4894 :   params.addClassDescription("This ConcentricCircleGeneratorBase object is a base class to be "
     102             :                              "inherited for mesh generators that involve concentric circles.");
     103        4894 :   return params;
     104        4894 : }
     105             : 
     106        2503 : ConcentricCircleGeneratorBase::ConcentricCircleGeneratorBase(const InputParameters & parameters)
     107             :   : PolygonMeshGeneratorBase(parameters),
     108        6968 :     _ring_radii(isParamValid("ring_radii") ? getParam<std::vector<Real>>("ring_radii")
     109             :                                            : std::vector<Real>()),
     110        8930 :     _ring_intervals(isParamValid("ring_intervals")
     111        2503 :                         ? getParam<std::vector<unsigned int>>("ring_intervals")
     112             :                         : std::vector<unsigned int>()),
     113        5028 :     _ring_radial_biases(isParamValid("ring_radial_biases")
     114        2503 :                             ? getParam<std::vector<Real>>("ring_radial_biases")
     115        2503 :                             : std::vector<Real>(_ring_intervals.size(), 1.0)),
     116        7609 :     _ring_inner_boundary_layer_params(
     117        2503 :         {isParamValid("ring_inner_boundary_layer_widths")
     118        2503 :              ? getParam<std::vector<Real>>("ring_inner_boundary_layer_widths")
     119        2483 :              : std::vector<Real>(_ring_intervals.size(), 0.0),
     120             :          std::vector<Real>(),
     121        5006 :          isParamValid("ring_inner_boundary_layer_intervals")
     122        2503 :              ? getParam<std::vector<unsigned int>>("ring_inner_boundary_layer_intervals")
     123        2487 :              : std::vector<unsigned int>(_ring_intervals.size(), 0),
     124        5006 :          isParamValid("ring_inner_boundary_layer_biases")
     125        2503 :              ? getParam<std::vector<Real>>("ring_inner_boundary_layer_biases")
     126        2503 :              : std::vector<Real>(_ring_intervals.size(), 0.0)}),
     127        7613 :     _ring_outer_boundary_layer_params(
     128        2503 :         {isParamValid("ring_outer_boundary_layer_widths")
     129        2503 :              ? getParam<std::vector<Real>>("ring_outer_boundary_layer_widths")
     130        2483 :              : std::vector<Real>(_ring_intervals.size(), 0.0),
     131             :          std::vector<Real>(),
     132        5006 :          isParamValid("ring_outer_boundary_layer_intervals")
     133        2503 :              ? getParam<std::vector<unsigned int>>("ring_outer_boundary_layer_intervals")
     134        2485 :              : std::vector<unsigned int>(_ring_intervals.size(), 0),
     135        5006 :          isParamValid("ring_outer_boundary_layer_biases")
     136        2503 :              ? getParam<std::vector<Real>>("ring_outer_boundary_layer_biases")
     137        2503 :              : std::vector<Real>(_ring_intervals.size(), 0.0)}),
     138        8110 :     _ring_block_ids(isParamValid("ring_block_ids")
     139        2503 :                         ? getParam<std::vector<subdomain_id_type>>("ring_block_ids")
     140             :                         : std::vector<subdomain_id_type>()),
     141        8068 :     _ring_block_names(isParamValid("ring_block_names")
     142        2503 :                           ? getParam<std::vector<SubdomainName>>("ring_block_names")
     143             :                           : std::vector<SubdomainName>()),
     144        5006 :     _preserve_volumes(getParam<bool>("preserve_volumes")),
     145        5006 :     _block_id_shift(getParam<subdomain_id_type>("block_id_shift")),
     146        5006 :     _create_inward_interface_boundaries(getParam<bool>("create_inward_interface_boundaries")),
     147        5006 :     _create_outward_interface_boundaries(getParam<bool>("create_outward_interface_boundaries")),
     148        5006 :     _interface_boundary_id_shift(getParam<boundary_id_type>("interface_boundary_id_shift")),
     149        5006 :     _generate_side_specific_boundaries(getParam<bool>("generate_side_specific_boundaries")),
     150        6097 :     _external_boundary_id(isParamValid("external_boundary_id")
     151        4685 :                               ? getParam<boundary_id_type>("external_boundary_id")
     152             :                               : 0),
     153        2503 :     _external_boundary_name(getParam<BoundaryName>("external_boundary_name")),
     154        2515 :     _inward_interface_boundary_names(
     155        2503 :         isParamValid("inward_interface_boundary_names")
     156        2503 :             ? getParam<std::vector<std::string>>("inward_interface_boundary_names")
     157             :             : std::vector<std::string>()),
     158        2575 :     _outward_interface_boundary_names(
     159        2503 :         isParamValid("outward_interface_boundary_names")
     160        2503 :             ? getParam<std::vector<std::string>>("outward_interface_boundary_names")
     161             :             : std::vector<std::string>()),
     162        5006 :     _tri_elem_type(getParam<MooseEnum>("tri_element_type").template getEnum<TRI_ELEM_TYPE>()),
     163        7509 :     _quad_elem_type(getParam<MooseEnum>("quad_element_type").template getEnum<QUAD_ELEM_TYPE>())
     164             : {
     165             :   // Customized interface boundary id/name related error messages
     166        2503 :   if (!_create_inward_interface_boundaries && _inward_interface_boundary_names.size() > 0)
     167           4 :     paramError("create_inward_interface_boundaries",
     168             :                "If set false, 'inward_interface_boundary_names' "
     169             :                "should not be provided as they are not used.");
     170        2499 :   if (!_create_outward_interface_boundaries && _outward_interface_boundary_names.size() > 0)
     171           4 :     paramError("create_outward_interface_boundaries",
     172             :                "If set false, 'outward_interface_boundary_names' "
     173             :                "should not be provided as they are not used.");
     174        2495 :   if (!_create_outward_interface_boundaries && !_create_inward_interface_boundaries &&
     175         889 :       _interface_boundary_id_shift != 0)
     176           4 :     paramError("interface_boundary_id_shift",
     177             :                "this parameter should not be set if no interface boundaries are created.");
     178             : 
     179             :   // Rings related error messages
     180        2491 :   if (_ring_radii.size() != _ring_intervals.size())
     181           4 :     paramError("ring_radii", "This parameter and ring_intervals must have the same length.");
     182        2487 :   if (_ring_radii.size() != _ring_radial_biases.size())
     183           4 :     paramError("ring_radii", "This parameter and ring_radial_biases must have the same length.");
     184        3208 :   for (unsigned int i = 1; i < _ring_intervals.size(); i++)
     185         729 :     if (_ring_radii[i] <= _ring_radii[i - 1])
     186           4 :       paramError("ring_radii", "This parameter must be strictly ascending.");
     187        2477 :   if (_ring_radii.size() != _ring_inner_boundary_layer_params.widths.size() ||
     188        2477 :       _ring_radii.size() != _ring_inner_boundary_layer_params.intervals.size() ||
     189        2477 :       _ring_radii.size() != _ring_inner_boundary_layer_params.biases.size() ||
     190        2477 :       _ring_radii.size() != _ring_outer_boundary_layer_params.widths.size() ||
     191        4956 :       _ring_radii.size() != _ring_outer_boundary_layer_params.intervals.size() ||
     192             :       _ring_radii.size() != _ring_outer_boundary_layer_params.biases.size())
     193           2 :     paramError("ring_radii",
     194             :                "The inner and outer ring boundary layer parameters must have the same sizes as "
     195             :                "ring_radii.");
     196        2477 : }
     197             : 
     198             : void
     199        2173 : ConcentricCircleGeneratorBase::assignInterfaceBoundaryNames(ReplicatedMesh & mesh) const
     200             : {
     201        2173 :   if (!_inward_interface_boundary_names.empty())
     202             :   {
     203           0 :     for (unsigned int i = 0; i < _inward_interface_boundary_names.size(); i++)
     204             :     {
     205           0 :       mesh.get_boundary_info().sideset_name(i * 2 + 2 + _interface_boundary_id_shift) =
     206             :           _inward_interface_boundary_names[i];
     207           0 :       mesh.get_boundary_info().nodeset_name(i * 2 + 2 + _interface_boundary_id_shift) =
     208             :           _inward_interface_boundary_names[i];
     209             :     }
     210             :   }
     211        2173 :   if (!_outward_interface_boundary_names.empty())
     212             :   {
     213          84 :     for (unsigned int i = 0; i < _outward_interface_boundary_names.size(); i++)
     214             :     {
     215          56 :       mesh.get_boundary_info().sideset_name(i * 2 + 1 + _interface_boundary_id_shift) =
     216             :           _outward_interface_boundary_names[i];
     217          56 :       mesh.get_boundary_info().nodeset_name(i * 2 + 1 + _interface_boundary_id_shift) =
     218             :           _outward_interface_boundary_names[i];
     219             :     }
     220             :   }
     221        2173 : }
     222             : 
     223             : void
     224        2175 : ConcentricCircleGeneratorBase::assignBlockIdsNames(ReplicatedMesh & mesh,
     225             :                                                    std::vector<subdomain_id_type> & block_ids_old,
     226             :                                                    std::vector<subdomain_id_type> & block_ids_new,
     227             :                                                    std::vector<SubdomainName> & block_names,
     228             :                                                    const std::string & generator_name) const
     229             : {
     230        2175 :   if (block_ids_old.size() != block_ids_new.size() || block_ids_old.size() != block_names.size())
     231           0 :     mooseError("In ",
     232             :                generator_name,
     233             :                " ",
     234           0 :                _name,
     235             :                ": block_ids_old, block_ids_new and block_names must have the same size.");
     236             : 
     237        5461 :   for (auto it = block_names.begin(); it != block_names.end() - 1; it++)
     238             :   {
     239        3288 :     auto it_tmp = std::find(block_names.begin(), it + 1, *(it + 1));
     240        3288 :     if (it_tmp != it + 1 && block_ids_new[std::distance(block_names.begin(), it + 1)] !=
     241         179 :                                 block_ids_new[std::distance(block_names.begin(), it_tmp)])
     242           2 :       mooseError("In ",
     243             :                  generator_name,
     244             :                  " ",
     245           2 :                  _name,
     246             :                  ": blocks with different ids cannot have the same block name.");
     247             :   }
     248      352436 :   for (const auto & elem : mesh.element_ptr_range())
     249      386162 :     for (unsigned i = 0; i < block_ids_old.size(); ++i)
     250      386162 :       if (elem->subdomain_id() == block_ids_old[i])
     251             :       {
     252      174045 :         elem->subdomain_id() = block_ids_new[i];
     253      174045 :         break;
     254        2173 :       }
     255        7632 :   for (unsigned i = 0; i < block_ids_new.size(); ++i)
     256        5459 :     mesh.subdomain_name(block_ids_new[i]) = block_names[i];
     257        2173 : }
     258             : 
     259             : void
     260        1694 : ConcentricCircleGeneratorBase::ringBlockIdsNamesPreparer(
     261             :     unsigned int & block_counter,
     262             :     unsigned int & ring_block_num,
     263             :     std::vector<subdomain_id_type> & block_ids_old,
     264             :     std::vector<subdomain_id_type> & block_ids_new,
     265             :     std::vector<SubdomainName> & block_names) const
     266             : {
     267        1694 :   if (_ring_intervals.front() == 1)
     268        1042 :     ring_block_num = _ring_intervals.size();
     269             :   else
     270             :   {
     271         652 :     ring_block_num = _ring_intervals.size() + 1;
     272         652 :     block_ids_old.push_back(_block_id_shift + 1);
     273         680 :     block_ids_new.push_back(_ring_block_ids.empty() ? block_ids_old.back()
     274             :                                                     : _ring_block_ids.front());
     275         652 :     block_names.push_back(_ring_block_names.empty()
     276        1304 :                               ? (SubdomainName)std::to_string(block_ids_new.back())
     277             :                               : _ring_block_names.front());
     278         652 :     block_counter++;
     279             :   }
     280        4007 :   for (unsigned int i = ring_block_num - _ring_intervals.size(); i < ring_block_num; i++)
     281             :   {
     282        2313 :     block_ids_old.push_back(_block_id_shift + 1 + i);
     283        2923 :     block_ids_new.push_back(_ring_block_ids.empty() ? block_ids_old.back() : _ring_block_ids[i]);
     284        2313 :     block_names.push_back(_ring_block_names.empty()
     285        4626 :                               ? (SubdomainName)std::to_string(block_ids_new.back())
     286        1647 :                               : _ring_block_names[i]);
     287        2313 :     block_counter++;
     288             :   }
     289        1694 : }

Generated by: LCOV version 1.14