LCOV - code coverage report
Current view: top level - src/auxkernels - CellMaterialIDAux.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: faa471 Lines: 19 20 95.0 %
Date: 2026-08-05 13:00:46 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 "CellMaterialIDAux.h"
      22             : #include "CardinalEnums.h"
      23             : 
      24             : registerMooseObject("CardinalApp", CellMaterialIDAux);
      25             : 
      26             : InputParameters
      27         336 : CellMaterialIDAux::validParams()
      28             : {
      29         336 :   InputParameters params = OpenMCAuxKernel::validParams();
      30         336 :   params.addClassDescription("OpenMC material ID, mapped to each MOOSE element");
      31         336 :   return params;
      32           0 : }
      33             : 
      34         167 : CellMaterialIDAux::CellMaterialIDAux(const InputParameters & parameters)
      35         167 :   : OpenMCAuxKernel(parameters)
      36             : {
      37         167 : }
      38             : 
      39             : Real
      40     2975426 : CellMaterialIDAux::computeValue()
      41             : {
      42             :   // if the element doesn't map to an OpenMC cell, return a cell ID of -1; otherwise, we would
      43             :   // get an error in the call to cellCouplingFields, since these
      44             :   // rely on a valid cell instance, index pair being passed to OpenMC's C-API
      45     2975426 :   if (!mappedElement())
      46             :     return OpenMCCellAverageProblem::UNMAPPED;
      47             : 
      48             :   OpenMCCellAverageProblem::cellInfo cell_info =
      49     2631298 :       _openmc_problem->elemToCellInfo(_current_elem->id());
      50             : 
      51     2631298 :   if (!_openmc_problem->hasDensityFeedback(cell_info))
      52             :     return -1;
      53             : 
      54             :   // if the cell which maps to this element contains more than one cell within it (e.g. if filled
      55             :   // by a universe or lattice), then we cannot return a single value from this function. We check
      56             :   // if there are multiple cell IDs; if this does not fail, then we still need to check the number
      57             :   // of instances of the single-ID fill.
      58             : 
      59             :   // we could technically have a situation where you build a lattice of single-material universes,
      60             :   // which would trigger this error message. I opted for an error here because it's likely not worth
      61             :   // the expense to form a list of all the materials filling the given cell to see if we're actually
      62             :   // in a situation where we have multiple MATERIALs in those cells, vs. multiple cells all filled
      63             :   // by the same material.
      64     1299842 :   int nc = _openmc_problem->numContainedMaterialCells(cell_info);
      65     1299842 :   if (nc > 1)
      66           2 :     mooseError(
      67             :         "Element ",
      68           2 :         this->_current_elem->id(),
      69             :         " maps to OpenMC cell ",
      70           2 :         _openmc_problem->printCell(cell_info),
      71             :         " which contains ",
      72             :         nc,
      73             :         " material-filled cells (for instance, by being filled by a universe or lattice). "
      74             :         "Therefore, we cannot easily return a single material ID at this position in space.");
      75             : 
      76             :   // we screen to be sure there's just one material fill, so "first" here is same as "only"
      77     1299840 :   auto first_material_cell = _openmc_problem->firstContainedMaterialCell(cell_info);
      78             : 
      79             :   int32_t index;
      80     1299840 :   _openmc_problem->materialFill(first_material_cell, index);
      81             : 
      82     1299840 :   return _openmc_problem->materialID(index);
      83             : }
      84             : 
      85             : #endif

Generated by: LCOV version 1.14