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