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 "FoMAux.h" 22 : 23 : registerMooseObject("CardinalApp", FoMAux); 24 : 25 : InputParameters 26 42 : FoMAux::validParams() 27 : { 28 42 : auto params = OpenMCAuxKernel::validParams(); 29 42 : params.addClassDescription("An auxkernel which computes a figure of merit for a tally."); 30 84 : params.addCoupledVar("tally_value", 31 : "The variable containing the value of the tally. FoMAux " 32 : "assumes this has units of the tally score divided by " 33 : "volume. This is required for the AMR figure of merit."); 34 84 : params.addCoupledVar( 35 : "tally_value_init", 36 : "The variable containing the tally value on the initial adaptivity step. FoMAux " 37 : "assumes this has units of the tally score divided by volume. This is required " 38 : "for the AMR figure of merit."); 39 84 : params.addRequiredCoupledVar( 40 : "tally_rel_error", "The variable containing the statistical relative error of the tally."); 41 : 42 84 : params.addRequiredParam<PostprocessorName>("sim_time", "The cumulative simulation time."); 43 : 44 84 : params.addRequiredParam<MooseEnum>( 45 : "fom_type", 46 126 : MooseEnum("VR AMR"), 47 : "The type of Figure of Merit (FoM) to compute. Options are the standard " 48 : "variance reduction FoM (VR) or the adaptive mesh refinement FoM (AMR)."); 49 : 50 42 : return params; 51 0 : } 52 : 53 26 : FoMAux::FoMAux(const InputParameters & parameters) 54 : : OpenMCAuxKernel(parameters), 55 42 : _tally_val(isCoupled("tally_value") ? &coupledValue("tally_value") : nullptr), 56 42 : _tally_val_init(isCoupled("tally_value_init") ? &coupledValue("tally_value_init") : nullptr), 57 26 : _tally_val_rel_err(coupledValue("tally_rel_error")), 58 26 : _sim_time(getPostprocessorValue("sim_time")), 59 78 : _fom_type(getParam<MooseEnum>("fom_type").getEnum<FoMType>()) 60 : { 61 26 : if (_var.feType() != FEType(libMesh::CONSTANT, libMesh::MONOMIAL)) 62 0 : paramError("variable", 63 : "FoMAux only supports CONSTANT MONOMIAL shape functions. Please " 64 : "ensure that 'variable' is of type MONOMIAL and order CONSTANT."); 65 : 66 26 : errorCoupledConstMonomial("tally_rel_error"); 67 : 68 : // Error-check the different FoM options. 69 24 : if (_fom_type == FoMType::AMR) 70 : { 71 16 : errorCoupledConstMonomial("tally_value"); 72 20 : errorCoupledConstMonomial("tally_value_init"); 73 : } 74 16 : } 75 : 76 : Real 77 16384 : FoMAux::computeValue() 78 : { 79 16384 : switch (_fom_type) 80 : { 81 8192 : case FoMType::VR: 82 8192 : return 1.0 / _sim_time / _tally_val_rel_err[0] / _tally_val_rel_err[0]; 83 8192 : case FoMType::AMR: 84 8192 : return std::abs((*_tally_val)[0] - (*_tally_val_init)[0]) / _sim_time / 85 8192 : _tally_val_rel_err[0] / (*_tally_val_init)[0]; 86 0 : default: 87 : { 88 0 : mooseError("Unhandled FoMType enum in FoMAux!"); 89 : return 0.0; 90 : } 91 : } 92 : } 93 : 94 : #endif