LCOV - code coverage report
Current view: top level - src/meshgenerators - OpenMCMeshGenerator.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: 9f356e Lines: 39 40 97.5 %
Date: 2026-08-19 15:42:22 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /********************************************************************/
       2             : /*                  SOFTWARE COPYRIGHT NOTIFICATION                 */
       3             : /*                             Cardinal                             */
       4             : /*                                                                  */
       5             : /*                  (c) 2021 UChicago Argonne, LLC                  */
       6             : /*                        ALL RIGHTS RESERVED                       */
       7             : /*                                                                  */
       8             : /*                 Prepared by UChicago Argonne, LLC                */
       9             : /*               Under Contract No. DE-AC02-06CH11357               */
      10             : /*                With the U. S. Department of Energy               */
      11             : /*                                                                  */
      12             : /*             Prepared by Battelle Energy Alliance, LLC            */
      13             : /*               Under Contract No. DE-AC07-05ID14517               */
      14             : /*                With the U. S. Department of Energy               */
      15             : /*                                                                  */
      16             : /*                 See LICENSE for full restrictions                */
      17             : /********************************************************************/
      18             : 
      19             : #ifdef ENABLE_OPENMC_COUPLING
      20             : 
      21             : #include "OpenMCMeshGenerator.h"
      22             : #include "GeneratedMeshGenerator.h"
      23             : 
      24             : registerMooseObject("CardinalApp", OpenMCMeshGenerator);
      25             : 
      26             : InputParameters
      27          88 : OpenMCMeshGenerator::validParams()
      28             : {
      29          88 :   InputParameters params = MeshGenerator::validParams();
      30             : 
      31          88 :   params.addClassDescription(
      32             :       "A class that generates a mesh from an available OpenMC regular mesh.");
      33         176 :   params.addRequiredParam<unsigned int>(
      34             :       "mesh_id", "The id of the OpenMC mesh that this class should provide to Cardinal.");
      35         264 :   params.addRangeCheckedParam<Real>(
      36             :       "scaling",
      37         176 :       1.0,
      38             :       "scaling > 0.0",
      39             :       "Scaling factor used to scale the OpenMC mesh dimensions for the creation of the mesh; "
      40             :       "OpenMC always uses units of centimeters. Setting 'scaling = 100' means that the [Mesh] "
      41             :       "created will have units of meters, for example.");
      42         176 :   params.addParam<FileName>(
      43             :       "xml_directory", "./", "The directory in which to look for OpenMC XML files.");
      44          88 :   return params;
      45           0 : }
      46             : 
      47          42 : OpenMCMeshGenerator::OpenMCMeshGenerator(const InputParameters & params)
      48             :   : MeshGenerator(params),
      49          42 :     _scaling(getParam<Real>("scaling")),
      50         126 :     _xml_directory(getParam<FileName>("xml_directory"))
      51             : {
      52             :   // Check to make sure the mesh exists.
      53          84 :   auto _mesh_id = getParam<unsigned int>("mesh_id");
      54          42 :   if (openmc::model::mesh_map.count(_mesh_id) == 0)
      55           4 :     paramError("mesh_id",
      56           2 :                "A mesh with the id " + Moose::stringify(_mesh_id) +
      57             :                    " does not exist in the OpenMC model! Please make sure the mesh has been "
      58             :                    "added in the OpenMC model and you've supplied the correct mesh id.");
      59             : 
      60          40 :   _openmc_mesh_index = openmc::model::mesh_map.at(_mesh_id);
      61          40 :   _openmc_mesh = openmc::model::meshes[_openmc_mesh_index].get();
      62             : 
      63          40 :   if (_openmc_mesh->n_dimension_ != 3)
      64           4 :     mooseError("At this time, this object only supports 3D meshes. Please contact the Cardinal "
      65             :                "developer team if you need 2D or 1D meshes!");
      66             : 
      67             :   // Construct mesh using a subgenerator
      68          36 :   if (_openmc_mesh->get_mesh_type() == openmc::RegularMesh::mesh_type)
      69             :   {
      70          34 :     openmc::RegularMesh * regular_mesh = dynamic_cast<openmc::RegularMesh *>(_openmc_mesh);
      71             : 
      72          34 :     InputParameters params = GeneratedMeshGenerator::validParams();
      73          34 :     params.set<MooseEnum>("dim") = regular_mesh->n_dimension_;
      74          34 :     params.set<unsigned int>("nx") = regular_mesh->shape_[0];
      75          34 :     params.set<unsigned int>("ny") = regular_mesh->shape_[1];
      76          34 :     params.set<unsigned int>("nz") = regular_mesh->shape_[2];
      77          34 :     params.set<Real>("xmin") = regular_mesh->lower_left()[0] / _scaling;
      78          34 :     params.set<Real>("xmax") = regular_mesh->upper_right()[0] / _scaling;
      79          34 :     params.set<Real>("ymin") = regular_mesh->lower_left()[1] / _scaling;
      80          34 :     params.set<Real>("ymax") = regular_mesh->upper_right()[1] / _scaling;
      81          34 :     params.set<Real>("zmin") = regular_mesh->lower_left()[2] / _scaling;
      82          34 :     params.set<Real>("zmax") = regular_mesh->upper_right()[2] / _scaling;
      83          68 :     addMeshSubgenerator("GeneratedMeshGenerator", name() + "_openmc_sub_mesh", params);
      84             : 
      85          68 :     _build_mesh = &getMeshByName(name() + "_openmc_sub_mesh");
      86          34 :   }
      87             :   else
      88           2 :     mooseError(
      89             :         "This object is currently only implemented for regular meshes (RegularMesh) in OpenMC! "
      90             :         "Please contact the Cardinal developer team if you require another structured mesh type.");
      91          34 : }
      92             : 
      93             : std::unique_ptr<MeshBase>
      94          34 : OpenMCMeshGenerator::generate()
      95             : {
      96          34 :   return std::move(*_build_mesh);
      97             : }
      98             : 
      99             : #endif

Generated by: LCOV version 1.14