LCOV - code coverage report
Current view: top level - src/mesh - UniformTensorMesh.C (source / functions) Hit Total Coverage
Test: idaholab/swift: #92 (25e020) with base b3cd84 Lines: 0 83 0.0 %
Date: 2025-09-10 17:10:32 Functions: 0 8 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /**********************************************************************/
       2             : /*                    DO NOT MODIFY THIS HEADER                       */
       3             : /*             Swift, a Fourier spectral solver for MOOSE             */
       4             : /*                                                                    */
       5             : /*            Copyright 2024 Battelle Energy Alliance, LLC            */
       6             : /*                        ALL RIGHTS RESERVED                         */
       7             : /**********************************************************************/
       8             : 
       9             : #include "UniformTensorMesh.h"
      10             : 
      11             : #include "MooseApp.h"
      12             : 
      13             : #include "libmesh/mesh_generation.h"
      14             : #include "libmesh/string_to_enum.h"
      15             : #include "libmesh/unstructured_mesh.h"
      16             : 
      17             : registerMooseObject("SwiftApp", UniformTensorMesh);
      18             : 
      19             : InputParameters
      20           0 : UniformTensorMesh::validParams()
      21             : {
      22           0 :   InputParameters params = MooseMesh::validParams();
      23             : 
      24           0 :   MooseEnum dims("1=1 2 3");
      25           0 :   params.addRequiredParam<MooseEnum>("dim", dims, "The dimension of the mesh to be generated");
      26             : 
      27           0 :   params.addParam<unsigned int>("nx", 1, "Number of elements in the X direction");
      28           0 :   params.addParam<unsigned int>("ny", 1, "Number of elements in the Y direction");
      29           0 :   params.addParam<unsigned int>("nz", 1, "Number of elements in the Z direction");
      30           0 :   params.addParam<Real>("xmax", 1.0, "Upper X Coordinate of the generated mesh");
      31           0 :   params.addParam<Real>("ymax", 1.0, "Upper Y Coordinate of the generated mesh");
      32           0 :   params.addParam<Real>("zmax", 1.0, "Upper Z Coordinate of the generated mesh");
      33             : 
      34           0 :   params.set<bool>("allow_renumbering") = false;
      35           0 :   params.set<bool>("dummy_mesh") = false;
      36           0 :   params.suppressParameter<bool>("allow_renumbering");
      37           0 :   params.addClassDescription("Create a line, square, or cube mesh with uniformly spaced elements.");
      38           0 :   return params;
      39           0 : }
      40             : 
      41           0 : UniformTensorMesh::UniformTensorMesh(const InputParameters & parameters)
      42             :   : MooseMesh(parameters),
      43           0 :     _dim(getParam<MooseEnum>("dim")),
      44           0 :     _nx(getParam<unsigned int>("nx")),
      45           0 :     _ny(getParam<unsigned int>("ny")),
      46           0 :     _nz(getParam<unsigned int>("nz")),
      47           0 :     _xmax(getParam<Real>("xmax")),
      48           0 :     _ymax(getParam<Real>("ymax")),
      49           0 :     _zmax(getParam<Real>("zmax"))
      50             : {
      51             :   // All generated meshes are regular orthogonal meshes - until they get modified ;)
      52           0 :   _regular_orthogonal_mesh = true;
      53             : 
      54             :   // set unused dimensions to 1
      55           0 :   if (_dim <= 2)
      56           0 :     _nz = 1;
      57           0 :   if (_dim <= 1)
      58           0 :     _ny = 1;
      59           0 :   if (_dim == 0)
      60           0 :     _nx = 1;
      61             : 
      62             :   // Error check
      63           0 :   if (_nx == 0)
      64           0 :     paramError("nx", "Number of grid points in any direction must be greater than zero");
      65           0 :   if (_ny == 0)
      66           0 :     paramError("ny", "Number of grid points in any direction must be greater than zero");
      67           0 :   if (_nz == 0)
      68           0 :     paramError("nz", "Number of grid points in any direction must be greater than zero");
      69           0 : }
      70             : 
      71             : void
      72           0 : UniformTensorMesh::prepared(bool state)
      73             : {
      74           0 :   MooseMesh::prepared(state);
      75             : 
      76             :   // Fall back on scanning the mesh for coordinates instead of using input parameters for queries
      77           0 :   if (!state)
      78           0 :     mooseError("UniformTensorMesh must not be modified");
      79           0 : }
      80             : 
      81             : unsigned int
      82           0 : UniformTensorMesh::getElementsInDimension(unsigned int component) const
      83             : {
      84           0 :   switch (component)
      85             :   {
      86           0 :     case 0:
      87           0 :       return _nx;
      88           0 :     case 1:
      89           0 :       return _ny;
      90           0 :     case 2:
      91           0 :       return _nz;
      92           0 :     default:
      93           0 :       mooseError("Invalid component");
      94             :   }
      95             : }
      96             : 
      97             : Real
      98           0 : UniformTensorMesh::getMinInDimension(unsigned int) const
      99             : {
     100           0 :   return 0.0;
     101             : }
     102             : 
     103             : Real
     104           0 : UniformTensorMesh::getMaxInDimension(unsigned int component) const
     105             : {
     106           0 :   switch (component)
     107             :   {
     108           0 :     case 0:
     109           0 :       return _xmax;
     110           0 :     case 1:
     111           0 :       return _dim > 1 ? _ymax : 0.0;
     112           0 :     case 2:
     113           0 :       return _dim > 2 ? _zmax : 0.0;
     114           0 :     default:
     115           0 :       mooseError("Invalid component");
     116             :   }
     117             : }
     118             : 
     119             : std::unique_ptr<MooseMesh>
     120           0 : UniformTensorMesh::safeClone() const
     121             : {
     122           0 :   return _app.getFactory().copyConstruct(*this);
     123             : }
     124             : 
     125             : void
     126           0 : UniformTensorMesh::buildMesh()
     127             : {
     128           0 :   auto dummy = getParam<bool>("dummy_mesh");
     129             : 
     130             :   // Switching on MooseEnum
     131           0 :   switch (_dim)
     132             :   {
     133             :     // The build_XYZ mesh generation functions take an
     134             :     // UnstructuredMesh& as the first argument, hence the dynamic_cast.
     135           0 :     case 1:
     136             :     {
     137             : 
     138           0 :       auto elem_type = Utility::string_to_enum<ElemType>("EDGE2");
     139           0 :       MeshTools::Generation::build_line(dynamic_cast<UnstructuredMesh &>(getMesh()),
     140             :                                         dummy ? 1 : _nx,
     141             :                                         0.0,
     142             :                                         _xmax,
     143             :                                         elem_type,
     144             :                                         false);
     145           0 :       break;
     146             :     }
     147             : 
     148           0 :     case 2:
     149             :     {
     150           0 :       auto elem_type = Utility::string_to_enum<ElemType>("QUAD4");
     151           0 :       MeshTools::Generation::build_square(dynamic_cast<UnstructuredMesh &>(getMesh()),
     152             :                                           dummy ? 1 : _nx,
     153             :                                           dummy ? 1 : _ny,
     154             :                                           0.0,
     155             :                                           _xmax,
     156             :                                           0.0,
     157             :                                           _ymax,
     158             :                                           elem_type,
     159             :                                           false);
     160           0 :       break;
     161             :     }
     162             : 
     163           0 :     case 3:
     164             :     {
     165           0 :       auto elem_type = Utility::string_to_enum<ElemType>("HEX8");
     166           0 :       MeshTools::Generation::build_cube(dynamic_cast<UnstructuredMesh &>(getMesh()),
     167             :                                         dummy ? 1 : _nx,
     168             :                                         dummy ? 1 : _ny,
     169             :                                         dummy ? 1 : _nz,
     170             :                                         0.0,
     171             :                                         _xmax,
     172             :                                         0.0,
     173             :                                         _ymax,
     174             :                                         0.0,
     175             :                                         _zmax,
     176             :                                         elem_type,
     177             :                                         false);
     178           0 :       break;
     179             :     }
     180             :   }
     181           0 : }

Generated by: LCOV version 1.14