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 "StatRelErrorIndicator.h" 22 : 23 : #include "CardinalEnums.h" 24 : #include "TallyBase.h" 25 : 26 : registerMooseObject("CardinalApp", StatRelErrorIndicator); 27 : 28 : InputParameters 29 14 : StatRelErrorIndicator::validParams() 30 : { 31 14 : InputParameters params = OpenMCIndicator::validParams(); 32 14 : params.addClassDescription("An Indicator which reports the maximum relative error of all bins " 33 : "associated with a tally variable."); 34 28 : params.addRequiredParam<MooseEnum>( 35 28 : "score", getSingleTallyScoreEnum(), "The tally score used for the relative error."); 36 28 : params.addParam<unsigned int>("ext_filter_bin", 37 28 : 0, 38 : "The filter bin for the case where any filters are added to this " 39 : "tally with [Filters] (bin indices start at 0). This parameter " 40 : "should be specified if you wish to extract the relative error " 41 : "of a different non-spatial tally bin."); 42 : 43 14 : return params; 44 0 : } 45 : 46 10 : StatRelErrorIndicator::StatRelErrorIndicator(const InputParameters & parameters) 47 20 : : OpenMCIndicator(parameters), _bin_index(getParam<unsigned int>("ext_filter_bin")) 48 : { 49 20 : std::string score = getParam<MooseEnum>("score"); 50 : std::replace(score.begin(), score.end(), '_', '-'); 51 : 52 10 : if (!_openmc_problem->hasScore(score)) 53 2 : paramError("score", 54 2 : "The problem does not contain any score named " + 55 2 : std::string(getParam<MooseEnum>("score")) + 56 : "! Please " 57 : "ensure that one of your [Tallies] is scoring the requested reaction rate."); 58 : 59 16 : if (!_openmc_problem->hasOutput(score, "rel_error")) 60 2 : mooseError( 61 2 : "The problem does not contain any tallies that output the relative error for the score " + 62 2 : std::string(getParam<MooseEnum>("score")) + 63 : "! Please ensure that your problem " 64 : "includes 'output = unrelaxed_tally_rel_err'"); 65 : 66 : // Check to ensure the reaction rate / flux variables are CONSTANT MONOMIALS. 67 : bool const_mon = true; 68 18 : for (const auto v : _openmc_problem->getTallyScoreVariables(score, _tid, "_rel_error")) 69 : const_mon &= v->feType() == FEType(CONSTANT, MONOMIAL); 70 : 71 6 : if (!const_mon) 72 0 : paramError("score", 73 : "StatRelErrorIndicator only supports CONSTANT MONOMIAL field variables. " 74 : "Please ensure your [Tallies] are adding CONSTANT MONOMIAL field variables."); 75 : 76 : // Grab the relative error from the [Tallies]. 77 6 : const auto score_bins = _openmc_problem->getTallyScoreVariableValues(score, _tid, "_rel_error"); 78 6 : if (_bin_index >= score_bins.size()) 79 2 : paramError("ext_filter_bin", 80 : "The external filter bin provided is invalid for the number of " 81 2 : "external filter bins (" + 82 2 : std::to_string(score_bins.size()) + 83 : ") " 84 2 : "applied to " + 85 2 : std::string(getParam<MooseEnum>("score")) + "!"); 86 : 87 4 : _tally_rel_error = score_bins[_bin_index]; 88 4 : } 89 : 90 : void 91 1024 : StatRelErrorIndicator::computeIndicator() 92 : { 93 1024 : _field_var.setNodalValue((*_tally_rel_error)[0]); 94 1024 : } 95 : 96 : #endif