LCOV - code coverage report
Current view: top level - src/postprocessors - LambdaEffective.C (source / functions) Hit Total Coverage
Test: neams-th-coe/cardinal: be601f Lines: 28 31 90.3 %
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 "LambdaEffective.h"
      22             : 
      23             : #include "OpenMCProblemBase.h"
      24             : 
      25             : #include "openmc/eigenvalue.h"
      26             : 
      27             : registerMooseObject("CardinalApp", LambdaEffective);
      28             : 
      29             : InputParameters
      30          96 : LambdaEffective::validParams()
      31             : {
      32          96 :   auto params = KEigenvalue::validParams();
      33          96 :   params.addClassDescription(
      34             :       "A post-processor which computes and returns the kinetics parameter $\\Lambda_{eff}$.");
      35         192 :   params.addParam<MooseEnum>(
      36             :       "output",
      37         192 :       getStatsOutputEnum(),
      38             :       "The value to output. Options are $\\Lambda_{eff}$ (mean), the standard deviation "
      39             :       "of $\\Lambda_{eff}$ (std_dev), or the relative error of $\\Lambda_{eff}$ (rel_err).");
      40             : 
      41          96 :   return params;
      42           0 : }
      43             : 
      44          26 : LambdaEffective::LambdaEffective(const InputParameters & parameters) : KEigenvalue(parameters)
      45             : {
      46          26 :   if (!_openmc_problem->computeKineticsParams())
      47           2 :     mooseError(
      48             :         "LambdaEffective can only be used if the OpenMC problem is computing kinetics parameters!");
      49          24 : }
      50             : 
      51             : Real
      52          24 : LambdaEffective::getValue() const
      53             : {
      54          24 :   const auto & ifp_tally = _openmc_problem->getKineticsParamTally();
      55          24 :   const auto n = ifp_tally.n_realizations_;
      56             : 
      57             :   const auto num_sum =
      58          24 :       xt::view(ifp_tally.results_, xt::all(), 0, static_cast<int>(openmc::TallyResult::SUM));
      59             :   const auto den_sum =
      60          24 :       xt::view(ifp_tally.results_, xt::all(), 2, static_cast<int>(openmc::TallyResult::SUM));
      61             : 
      62             :   const auto num_ss =
      63          24 :       xt::view(ifp_tally.results_, xt::all(), 0, static_cast<int>(openmc::TallyResult::SUM_SQ));
      64             :   const auto den_ss =
      65          24 :       xt::view(ifp_tally.results_, xt::all(), 2, static_cast<int>(openmc::TallyResult::SUM_SQ));
      66             : 
      67          24 :   const auto mean_k = kMean();
      68          24 :   const auto k_rel = kRelativeError();
      69             : 
      70          24 :   const Real lambda_eff = (num_sum[0] / n) / (den_sum[0] / n) / mean_k;
      71             : 
      72          24 :   const Real num_rel = _openmc_problem->relativeError(num_sum, num_ss, n)[0];
      73          24 :   const Real den_rel = _openmc_problem->relativeError(den_sum, den_ss, n)[0];
      74          24 :   const Real lambda_rel = std::sqrt(num_rel * num_rel + den_rel * den_rel + k_rel * k_rel);
      75             : 
      76          24 :   switch (_output)
      77             :   {
      78             :     case statistics::OutputEnum::Mean:
      79             :       return lambda_eff;
      80             : 
      81           8 :     case statistics::OutputEnum::StDev:
      82           8 :       return lambda_eff * lambda_rel;
      83             : 
      84           8 :     case statistics::OutputEnum::RelError:
      85           8 :       return lambda_rel;
      86             : 
      87           0 :     default:
      88           0 :       mooseError("Internal error: Unhandled statistics::OutputEnum enum in LambdaEffective.");
      89             :       break;
      90             :   }
      91             : 
      92             :   return lambda_eff;
      93             : }
      94             : 
      95             : #endif

Generated by: LCOV version 1.14