LCOV - code coverage report
Current view: top level - src/meshgenerators - SphereMeshGenerator.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 39a256 Lines: 24 25 96.0 %
Date: 2026-07-14 14:36:17 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 "SphereMeshGenerator.h"
      11             : #include "CastUniquePointer.h"
      12             : 
      13             : #include "libmesh/mesh_generation.h"
      14             : #include "libmesh/string_to_enum.h"
      15             : 
      16             : registerMooseObject("MooseApp", SphereMeshGenerator);
      17             : 
      18             : InputParameters
      19        3393 : SphereMeshGenerator::validParams()
      20             : {
      21        3393 :   InputParameters params = MeshGenerator::validParams();
      22        6786 :   params.addClassDescription("Generate a sphere (ball) mesh centered on the origin");
      23       20358 :   params.addRequiredRangeCheckedParam<Real>("radius", "radius > 0.0", "Sphere (ball) radius");
      24       20358 :   params.addRequiredRangeCheckedParam<unsigned int>("nr", "nr >= 0", "Number of refinements");
      25             : 
      26       10179 :   params.addParam<MooseEnum>(
      27        6786 :       "elem_type", MooseMesh::elemTypes(), "The type of element to generate");
      28       10179 :   params.addParam<unsigned int>("n_smooth", 0, "Number of smoothing operations");
      29        3393 :   return params;
      30           0 : }
      31             : 
      32         166 : SphereMeshGenerator::SphereMeshGenerator(const InputParameters & parameters)
      33             :   : MeshGenerator(parameters),
      34         166 :     _radius(getParam<Real>("radius")),
      35         332 :     _nr(getParam<unsigned int>("nr")),
      36         332 :     _elem_type(getParam<MooseEnum>("elem_type")),
      37         498 :     _n_smooth(getParam<unsigned int>("n_smooth"))
      38             : {
      39         166 : }
      40             : 
      41             : std::unique_ptr<MeshBase>
      42         165 : SphereMeshGenerator::generate()
      43             : {
      44         165 :   auto mesh = buildMeshBaseObject();
      45             : 
      46         495 :   if (!isParamValid("elem_type"))
      47         228 :     _elem_type = "HEX8";
      48             : 
      49             :   // libMesh will determine sphere dimension based on ElemType, and
      50             :   // will throw an error with error message if the ElemType is not yet
      51             :   // implemented (prisms and pyramids, currently)
      52         165 :   ElemType et = Utility::string_to_enum<ElemType>(_elem_type);
      53             : 
      54         165 :   MeshTools::Generation::build_sphere(
      55         165 :       cast_ref<UnstructuredMesh &>(*mesh), _radius, _nr, et, _n_smooth);
      56             : 
      57         330 :   return dynamic_pointer_cast<MeshBase>(mesh);
      58         165 : }

Generated by: LCOV version 1.14