LCOV - code coverage report
Current view: top level - src/userobjects - OpenMCNuclideDensities.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: 93e9c4 Lines: 28 31 90.3 %
Date: 2026-07-16 12:06:10 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 "OpenMCNuclideDensities.h"
      22             : #include "UserErrorChecking.h"
      23             : #include "openmc/material.h"
      24             : 
      25             : registerMooseObject("CardinalApp", OpenMCNuclideDensities);
      26             : 
      27             : InputParameters
      28          96 : OpenMCNuclideDensities::validParams()
      29             : {
      30          96 :   InputParameters params = GeneralUserObject::validParams();
      31          96 :   params += OpenMCBase::validParams();
      32         192 :   params.addRequiredParam<int32_t>("material_id", "ID of material to change nuclide densities");
      33         192 :   params.addRequiredParam<std::vector<std::string>>("names",
      34             :                                                     "Names of the nuclides to modify densities");
      35         192 :   params.addRequiredParam<std::vector<double>>("densities", "Nuclide densities (atom/b/cm) to set");
      36         192 :   params.declareControllable("names");
      37         192 :   params.declareControllable("densities");
      38          96 :   params.addClassDescription("Updates nuclide densities in an OpenMC material");
      39          96 :   return params;
      40           0 : }
      41             : 
      42          50 : OpenMCNuclideDensities::OpenMCNuclideDensities(const InputParameters & parameters)
      43             :   : GeneralUserObject(parameters),
      44             :     OpenMCBase(this, parameters),
      45          50 :     _material_id(getParam<int32_t>("material_id")),
      46         100 :     _names(getParam<std::vector<std::string>>("names")),
      47         150 :     _densities(getParam<std::vector<double>>("densities"))
      48             : {
      49          50 :   if (_openmc_problem->runRandomRay())
      50           2 :     mooseError("OpenMCNuclideDensities is not supported when running the random ray solver!");
      51             : 
      52          48 :   catchOpenMCError(openmc_get_material_index(_material_id, &_material_index),
      53          48 :                    "get the material index for material with ID " + std::to_string(_material_id));
      54          46 : }
      55             : 
      56             : void
      57          44 : OpenMCNuclideDensities::setValue()
      58             : {
      59          44 :   if (_names.size() == 0)
      60           0 :     paramError("names", "'names' cannot be of length zero!");
      61             : 
      62          44 :   if (_names.size() != _densities.size())
      63           2 :     mooseError("'names' and 'densities' must be the same length!");
      64             : 
      65             :   try
      66             :   {
      67          42 :     openmc::model::materials[_material_index]->set_densities(_names, _densities);
      68             :   }
      69           2 :   catch (const std::exception & e)
      70             :   {
      71           4 :     mooseError("In attempting to set nuclide densities in the '" + name() +
      72           2 :                "' UserObject, OpenMC reported:\n\n" + e.what());
      73           0 :   }
      74          40 : }
      75             : 
      76             : #endif

Generated by: LCOV version 1.14