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