LCOV - code coverage report
Current view: top level - src/filters - PolarAngleFilter.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: 920dc5 Lines: 27 29 93.1 %
Date: 2025-08-10 20:41:39 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 "PolarAngleFilter.h"
      22             : 
      23             : #include "openmc/tallies/filter_polar.h"
      24             : 
      25             : registerMooseObject("CardinalApp", PolarAngleFilter);
      26             : 
      27             : InputParameters
      28         102 : PolarAngleFilter::validParams()
      29             : {
      30         102 :   auto params = FilterBase::validParams();
      31         102 :   params.addClassDescription("A class which provides a thin wrapper around an OpenMC PolarFilter. "
      32             :                              "Bins can either be equally spaced by setting 'num_equal_divisions', "
      33             :                              "or a set of polar angles can "
      34             :                              "be provided by setting 'polar_angle_boundaries'.");
      35         204 :   params.addRangeCheckedParam<unsigned int>(
      36             :       "num_equal_divisions",
      37             :       "num_equal_divisions > 0",
      38             :       "The number of equally spaces subdivisions of "
      39             :       "$[0, \\pi]$ to use if equal subdivisions are desired.");
      40         204 :   params.addParam<std::vector<Real>>("polar_angle_boundaries",
      41             :                                      "The polar angle boundaries in $[0, \\pi]$ which must be "
      42             :                                      "provided in increasing order. If 0 and "
      43             :                                      "$\\pi$ are not included this filter may result in some "
      44             :                                      "missed particles during normalization.");
      45             : 
      46         102 :   return params;
      47           0 : }
      48             : 
      49          54 : PolarAngleFilter::PolarAngleFilter(const InputParameters & parameters) : FilterBase(parameters)
      50             : {
      51         162 :   if (isParamValid("num_equal_divisions") == isParamValid("polar_angle_boundaries"))
      52           4 :     mooseError("You have either set 'num_equal_divisions' and 'polar_angle_boundaries' or have not "
      53             :                "specified a bin option! Please specify either 'num_equal_divisions' or "
      54             :                "'polar_angle_boundaries'.");
      55             : 
      56         100 :   if (isParamValid("num_equal_divisions"))
      57             :   {
      58          64 :     auto num_angles = getParam<unsigned int>("num_equal_divisions");
      59         128 :     for (unsigned int i = 0; i < num_angles + 1; ++i)
      60          96 :       _polar_angle_bnds.push_back((libMesh::pi / num_angles) * i);
      61             :   }
      62             : 
      63         100 :   if (isParamValid("polar_angle_boundaries"))
      64             :   {
      65          54 :     _polar_angle_bnds = getParam<std::vector<Real>>("polar_angle_boundaries");
      66             : 
      67             :     // Make sure we have at least two boundaries to form bins.
      68          18 :     if (_polar_angle_bnds.size() < 2)
      69           2 :       paramError("polar_angle_boundaries",
      70             :                  "At least two polar angles are required to create bins!");
      71             : 
      72             :     // Sort the boundaries so they're monotonically decreasing.
      73          16 :     std::sort(_polar_angle_bnds.begin(),
      74             :               _polar_angle_bnds.end(),
      75          48 :               [](const Real & a, const Real & b) { return a < b; });
      76             : 
      77             :     // Warn the user if there is the possibility of missed particles.
      78          16 :     if (_polar_angle_bnds.front() > 0.0 || _polar_angle_bnds.back() < libMesh::pi)
      79           0 :       mooseWarning(
      80             :           "The bin boundaries don't contain one of the following: 0 or pi. Some particles may be "
      81             :           "missed during normalization.");
      82             :   }
      83             : 
      84             :   // Initialize the OpenMC PolarFilter.
      85          48 :   _filter_index = openmc::model::tally_filters.size();
      86             : 
      87          96 :   auto polar_filter = dynamic_cast<openmc::PolarFilter *>(openmc::Filter::create("polar"));
      88          48 :   polar_filter->set_bins(_polar_angle_bnds);
      89          48 :   _filter = polar_filter;
      90          48 : }
      91             : 
      92             : std::string
      93         176 : PolarAngleFilter::binName(unsigned int bin_index) const
      94             : {
      95         352 :   return "theta" + Moose::stringify(bin_index + 1);
      96             : }
      97             : #endif

Generated by: LCOV version 1.14