LCOV - code coverage report
Current view: top level - src/filters - FromXMLFilter.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: 93e9c4 Lines: 28 29 96.6 %
Date: 2026-07-16 12:06:10 Functions: 2 2 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 "FromXMLFilter.h"
      22             : 
      23             : #include "OpenMCCellAverageProblem.h"
      24             : 
      25             : registerMooseObject("CardinalApp", FromXMLFilter);
      26             : 
      27             : InputParameters
      28          42 : FromXMLFilter::validParams()
      29             : {
      30          42 :   auto params = FilterBase::validParams();
      31          42 :   params.addClassDescription(
      32             :       "A class which provides a thin wrapper around an arbitrary OpenMC filter.");
      33          84 :   params.addRequiredParam<unsigned int>(
      34             :       "filter_id",
      35             :       "The id of the OpenMC filter that this class should provide to Cardinal tallies.");
      36          84 :   params.addRequiredParam<std::string>("bin_label",
      37             :                                        "The label that is used for this filter's bins.");
      38          84 :   params.addParam<bool>("allow_expansion_filters",
      39          84 :                         false,
      40             :                         "Whether functional expansion filters are allowed or not. Tallies with "
      41             :                         "these filters are likely to fail "
      42             :                         "automatic normalization as a sum over all bins may not make sense for a "
      43             :                         "certain functional expansion.");
      44             : 
      45          42 :   return params;
      46           0 : }
      47             : 
      48          26 : FromXMLFilter::FromXMLFilter(const InputParameters & parameters)
      49             :   : FilterBase(parameters),
      50          26 :     _filter_id(getParam<unsigned int>("filter_id")),
      51          78 :     _bin_label(getParam<std::string>("bin_label"))
      52             : {
      53          26 :   if (_openmc_problem.runRandomRay())
      54           2 :     mooseError("FromXMLFilter is presently not supported when running the random ray solver!");
      55             : 
      56             :   // Check to make sure the filter exists.
      57          24 :   if (openmc::model::filter_map.count(_filter_id) == 0)
      58           2 :     paramError("filter_id",
      59           2 :                "A filter with the id " + Moose::stringify(_filter_id) +
      60             :                    " does not exist in the OpenMC model! Please make sure the filter has been "
      61             :                    "added in the OpenMC model and you've supplied the correct filter id.");
      62             : 
      63          22 :   _filter_index = openmc::model::filter_map.at(_filter_id);
      64          22 :   _filter = openmc::model::tally_filters[_filter_index].get();
      65             : 
      66             :   // Check to see if the filter is a spatial filter.
      67          22 :   switch (_filter->type())
      68             :   {
      69           2 :     case openmc::FilterType::CELLBORN:
      70             :     case openmc::FilterType::CELLFROM:
      71             :     case openmc::FilterType::CELL:
      72             :     case openmc::FilterType::CELL_INSTANCE:
      73             :     case openmc::FilterType::DISTRIBCELL:
      74             :     case openmc::FilterType::MATERIAL:
      75             :     case openmc::FilterType::MATERIALFROM:
      76             :     case openmc::FilterType::MESH:
      77             :     case openmc::FilterType::MESHBORN:
      78             :     case openmc::FilterType::MESH_SURFACE:
      79             :     case openmc::FilterType::SPATIAL_LEGENDRE:
      80             :     case openmc::FilterType::SURFACE:
      81             :     case openmc::FilterType::UNIVERSE:
      82             :     case openmc::FilterType::ZERNIKE:
      83             :     case openmc::FilterType::ZERNIKE_RADIAL:
      84           2 :       paramError(
      85             :           "filter_id",
      86           2 :           "The filter with the id " + Moose::stringify(_filter_id) +
      87             :               " is a spatial filter. "
      88             :               "FromXMLFilter currently does not support the addition of spatial filters from the "
      89             :               "OpenMC XML files because they would clash with the OpenMC -> MOOSE mapping "
      90             :               "performed by Cardinal's tally objects.");
      91             :       break;
      92             :     default:
      93             :       break;
      94             :   }
      95             : 
      96             :   // Check to see if the filter is a non-spatial expansion filter.
      97             :   bool is_exp;
      98          20 :   switch (_filter->type())
      99             :   {
     100             :     case openmc::FilterType::LEGENDRE:
     101             :     case openmc::FilterType::SPHERICAL_HARMONICS:
     102             :     case openmc::FilterType::ENERGY_FUNCTION:
     103             :       is_exp = true;
     104             :       break;
     105             :     default:
     106             :       is_exp = false;
     107             :       break;
     108             :   }
     109             : 
     110          60 :   if (is_exp && getParam<bool>("allow_expansion_filters"))
     111          18 :     mooseWarning("You have selected a functional expansion filter. Tallies which use this filter "
     112             :                  "may fail normalization as the sum over all tally bins may not be well posed "
     113             :                  "if any bins contain functional expansion coefficients.");
     114           6 :   else if (is_exp && !getParam<bool>("allow_expansion_filters"))
     115           2 :     paramError("filter_id",
     116             :                "You have selected a functional expansion filter. Tallies which use this filter "
     117             :                "may fail normalization as the sum over all tally bins may not be well posed "
     118             :                "if any bins contain functional expansion coefficients. If you still wish to "
     119             :                "use this filter, set 'allow_expansion_filters' to true.");
     120          16 : }
     121             : #endif

Generated by: LCOV version 1.14