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

Generated by: LCOV version 1.14