LCOV - code coverage report
Current view: top level - src/meshgenerators - PeripheralTriangleMeshGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose reactor: #31405 (292dce) with base fef103 Lines: 75 82 91.5 %
Date: 2025-09-04 07:56:24 Functions: 3 3 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 "PeripheralTriangleMeshGenerator.h"
      11             : 
      12             : // Moose headers
      13             : #include "MooseApp.h"
      14             : #include "MooseMeshUtils.h"
      15             : #include "Factory.h"
      16             : #include "libmesh/elem.h"
      17             : 
      18             : registerMooseObject("ReactorApp", PeripheralTriangleMeshGenerator);
      19             : 
      20             : InputParameters
      21          54 : PeripheralTriangleMeshGenerator::validParams()
      22             : {
      23          54 :   InputParameters params = MeshGenerator::validParams();
      24         108 :   params.addRequiredParam<MeshGeneratorName>("input", "The input mesh to be modified.");
      25         108 :   params.addRequiredRangeCheckedParam<Real>("peripheral_ring_radius",
      26             :                                             "peripheral_ring_radius>0",
      27             :                                             "Radius of the peripheral ring to be added.");
      28         108 :   params.addRequiredRangeCheckedParam<unsigned int>("peripheral_ring_num_segments",
      29             :                                                     "peripheral_ring_num_segments>0",
      30             :                                                     "Number of segments of the peripheral ring.");
      31         108 :   params.addRangeCheckedParam<Real>(
      32             :       "desired_area",
      33             :       0,
      34             :       "desired_area>=0",
      35             :       "Desired (maximum) triangle area, or 0 to skip uniform refinement");
      36         108 :   params.addParam<std::string>(
      37             :       "desired_area_func",
      38          54 :       std::string(),
      39             :       "Desired area as a function of x,y; omit to skip non-uniform refinement");
      40             : 
      41         108 :   params.addParam<bool>(
      42         108 :       "use_auto_area_func", false, "Use the automatic area function in the peripheral region.");
      43         108 :   params.addParam<Real>(
      44             :       "auto_area_func_default_size",
      45         108 :       0,
      46             :       "Background size for automatic area function, or 0 to use non background size");
      47         108 :   params.addParam<Real>("auto_area_func_default_size_dist",
      48         108 :                         -1.0,
      49             :                         "Effective distance of background size for automatic area "
      50             :                         "function, or negative to use non background size");
      51         108 :   params.addParam<unsigned int>("auto_area_function_num_points",
      52         108 :                                 10,
      53             :                                 "Maximum number of nearest points used for the inverse distance "
      54             :                                 "interpolation algorithm for automatic area function calculation.");
      55         162 :   params.addRangeCheckedParam<Real>(
      56             :       "auto_area_function_power",
      57         108 :       1.0,
      58             :       "auto_area_function_power>0",
      59             :       "Polynomial power of the inverse distance interpolation algorithm for automatic area "
      60             :       "function calculation.");
      61             : 
      62         108 :   params.addParam<SubdomainName>(
      63             :       "peripheral_ring_block_name", "", "The block name assigned to the created peripheral layer.");
      64         108 :   params.addParam<BoundaryName>("external_boundary_name",
      65             :                                 "Optional customized external boundary name.");
      66         108 :   MooseEnum tri_elem_type("TRI3 TRI6 TRI7 DEFAULT", "DEFAULT");
      67         108 :   params.addParam<MooseEnum>(
      68             :       "tri_element_type", tri_elem_type, "Type of the triangular elements to be generated.");
      69          54 :   params.addClassDescription("This PeripheralTriangleMeshGenerator object is designed to generate "
      70             :                              "a triangulated mesh between a generated outer circle boundary "
      71             :                              "and a provided inner mesh.");
      72         108 :   params.addParamNamesToGroup("desired_area desired_area_func use_auto_area_func "
      73             :                               "auto_area_func_default_size auto_area_func_default_size_dist "
      74             :                               "auto_area_function_num_points auto_area_function_power",
      75             :                               "Peripheral Area Delaunay");
      76          54 :   return params;
      77          54 : }
      78             : 
      79          27 : PeripheralTriangleMeshGenerator::PeripheralTriangleMeshGenerator(const InputParameters & parameters)
      80             :   : MeshGenerator(parameters),
      81          54 :     _input_name(getParam<MeshGeneratorName>("input")),
      82          54 :     _peripheral_ring_radius(getParam<Real>("peripheral_ring_radius")),
      83          54 :     _peripheral_ring_num_segments(getParam<unsigned int>("peripheral_ring_num_segments")),
      84          54 :     _desired_area(getParam<Real>("desired_area")),
      85         108 :     _desired_area_func(getParam<std::string>("desired_area_func"))
      86             : {
      87             :   // Calculate outer boundary points
      88             : 
      89             :   std::vector<libMesh::Point> outer_polyline;
      90             :   // radial spacing
      91          27 :   Real d_theta = 2.0 * M_PI / _peripheral_ring_num_segments;
      92        1827 :   for (unsigned int i = 0; i < _peripheral_ring_num_segments; i++)
      93             :   {
      94             :     // rotation angle
      95        1800 :     Real theta = i * d_theta;
      96             :     // calculate (x, y) coords
      97        1800 :     Real x = _peripheral_ring_radius * std::cos(theta);
      98        1800 :     Real y = _peripheral_ring_radius * std::sin(theta);
      99             : 
     100             :     // add to outer boundary list
     101        1800 :     outer_polyline.emplace_back(x, y, 0);
     102             :   }
     103             : 
     104             :   // Generate outer boundary polyline
     105             :   {
     106          27 :     auto params = _app.getFactory().getValidParams("PolyLineMeshGenerator");
     107          27 :     params.set<std::vector<Point>>("points") = outer_polyline;
     108          27 :     params.set<unsigned int>("num_edges_between_points") = 1;
     109          27 :     params.set<bool>("loop") = true;
     110          54 :     addMeshSubgenerator("PolyLineMeshGenerator", _input_name + "_periphery_polyline", params);
     111          27 :   }
     112             : 
     113             :   // Generate periphery region
     114             :   {
     115          27 :     declareMeshForSub("input");
     116          54 :     auto params = _app.getFactory().getValidParams("XYDelaunayGenerator");
     117          54 :     params.set<MeshGeneratorName>("boundary") =
     118          27 :         (MeshGeneratorName)_input_name + "_periphery_polyline";
     119          27 :     params.set<std::vector<MeshGeneratorName>>("holes") =
     120          81 :         std::vector<MeshGeneratorName>{_input_name};
     121          27 :     params.set<unsigned int>("add_nodes_per_boundary_segment") = 0;
     122          27 :     params.set<Real>("desired_area") = _desired_area;
     123          27 :     params.set<std::string>("desired_area_func") = _desired_area_func;
     124          54 :     params.set<bool>("use_auto_area_func") = getParam<bool>("use_auto_area_func");
     125          54 :     if (isParamSetByUser("auto_area_func_default_size"))
     126           0 :       params.set<Real>("auto_area_func_default_size") =
     127           0 :           getParam<Real>("auto_area_func_default_size");
     128          54 :     if (isParamSetByUser("auto_area_func_default_size_dist"))
     129           0 :       params.set<Real>("auto_area_func_default_size_dist") =
     130           0 :           getParam<Real>("auto_area_func_default_size_dist");
     131          54 :     if (isParamSetByUser("auto_area_function_num_points"))
     132           0 :       params.set<unsigned int>("auto_area_function_num_points") =
     133           0 :           getParam<unsigned int>("auto_area_function_num_points");
     134          54 :     if (isParamSetByUser("auto_area_function_power"))
     135           0 :       params.set<Real>("auto_area_function_power") = getParam<Real>("auto_area_function_power");
     136          27 :     params.set<bool>("refine_boundary") = false;
     137          54 :     params.set<std::vector<bool>>("refine_holes") = std::vector<bool>{false};
     138          54 :     params.set<std::vector<bool>>("stitch_holes") = std::vector<bool>{true};
     139          54 :     if (isParamValid("external_boundary_name"))
     140          18 :       params.set<BoundaryName>("output_boundary") =
     141          18 :           getParam<BoundaryName>("external_boundary_name");
     142          54 :     params.set<SubdomainName>("output_subdomain_name") =
     143          27 :         getParam<SubdomainName>("peripheral_ring_block_name");
     144          81 :     params.set<MooseEnum>("tri_element_type") = getParam<MooseEnum>("tri_element_type");
     145          27 :     params.set<bool>("verbose_stitching") = false;
     146          54 :     addMeshSubgenerator("XYDelaunayGenerator", _input_name + "_periphery", params);
     147          54 :     _build_mesh = &getMeshByName(_input_name + "_periphery");
     148          27 :   }
     149          27 : }
     150             : 
     151             : std::unique_ptr<MeshBase>
     152          27 : PeripheralTriangleMeshGenerator::generate()
     153             : {
     154          27 :   (*_build_mesh)->find_neighbors();
     155          27 :   return std::move(*_build_mesh);
     156             : }

Generated by: LCOV version 1.14