LCOV - code coverage report
Current view: top level - src/auxkernels - CellDensityAux.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: f3518d Lines: 14 17 82.4 %
Date: 2025-10-01 10:06:53 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 "CellDensityAux.h"
      22             : #include "CardinalEnums.h"
      23             : 
      24             : registerMooseObject("CardinalApp", CellDensityAux);
      25             : 
      26             : InputParameters
      27         380 : CellDensityAux::validParams()
      28             : {
      29         380 :   InputParameters params = OpenMCAuxKernel::validParams();
      30         380 :   params.addClassDescription("OpenMC fluid density (kg/m$^3$), mapped to each MOOSE element");
      31         380 :   return params;
      32           0 : }
      33             : 
      34         189 : CellDensityAux::CellDensityAux(const InputParameters & parameters) : OpenMCAuxKernel(parameters) {}
      35             : 
      36             : Real
      37     4384384 : CellDensityAux::computeValue()
      38             : {
      39             :   // if the element doesn't map to an OpenMC cell, return a density of -1; otherwise, we would
      40             :   // get an error in the call to cellCouplingFields, since it relies on the
      41             :   // OpenMCCellAverageProblem::_cell_to_elem std::map that wouldn't have an entry that corresponds
      42             :   // to an unmapped cell
      43     4384384 :   if (!mappedElement())
      44             :     return OpenMCCellAverageProblem::UNMAPPED;
      45             : 
      46             :   OpenMCCellAverageProblem::cellInfo cell_info =
      47     4040256 :       _openmc_problem->elemToCellInfo(_current_elem->id());
      48             : 
      49             :   // we only extract the material information for density feedback cells, because otherwise we don't
      50             :   // need to know the material info. So, set a value of -1 for non-density feedback cells.
      51     4040256 :   if (!_openmc_problem->hasDensityFeedback(cell_info))
      52             :     return OpenMCCellAverageProblem::UNMAPPED;
      53             : 
      54     1510400 :   int32_t index = _openmc_problem->cellToMaterialIndex(cell_info);
      55             : 
      56             :   // if the material is void, return -1
      57     1510400 :   if (_openmc_problem->materialID(index) == -1)
      58             :     return OpenMCCellAverageProblem::UNMAPPED;
      59             : 
      60             :   // Fetch the density.
      61             :   double density;
      62     1510368 :   int err = openmc_cell_get_density(cell_info.first, &cell_info.second, &density);
      63             : 
      64     1510368 :   if (err)
      65           0 :     mooseError("In attempting to get the density for " + _openmc_problem->printCell(cell_info) +
      66           0 :                ", OpenMC reported:\n\n" + std::string(openmc_err_msg));
      67             : 
      68     1510368 :   return density / _openmc_problem->densityConversionFactor();
      69             : }
      70             : 
      71             : #endif

Generated by: LCOV version 1.14