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

Generated by: LCOV version 1.14