LCOV - code coverage report
Current view: top level - src/postprocessors - SCMPlanarMean.C (source / functions) Hit Total Coverage
Test: idaholab/moose subchannel: #31405 (292dce) with base fef103 Lines: 43 44 97.7 %
Date: 2025-09-04 07:58:06 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "SCMPlanarMean.h"
      11             : #include "SolutionHandle.h"
      12             : #include "FEProblemBase.h"
      13             : #include "Function.h"
      14             : #include "MooseMesh.h"
      15             : #include "MooseVariable.h"
      16             : #include "SubProblem.h"
      17             : #include "libmesh/system.h"
      18             : #include "SCM.h"
      19             : 
      20             : registerMooseObject("SubChannelApp", SCMPlanarMean);
      21             : registerMooseObjectRenamed("SubChannelApp", PlanarMean, "06/30/2025 24:00", SCMPlanarMean);
      22             : 
      23             : InputParameters
      24         120 : SCMPlanarMean::validParams()
      25             : {
      26         120 :   InputParameters params = GeneralPostprocessor::validParams();
      27         120 :   params.addClassDescription("Calculates an mass-flow-rate averaged mean of the chosen "
      28             :                              "variable on a z-plane at a user defined height over all subchannels");
      29         240 :   params.addRequiredParam<AuxVariableName>("variable", "Variable you want the mean of");
      30         240 :   params.addRequiredParam<Real>("height", "Axial location of plane [m]");
      31         120 :   return params;
      32           0 : }
      33             : 
      34          60 : SCMPlanarMean::SCMPlanarMean(const InputParameters & parameters)
      35             :   : GeneralPostprocessor(parameters),
      36          60 :     _mesh(SCM::getConstMesh<SubChannelMesh>(_fe_problem.mesh())),
      37         120 :     _variable(getParam<AuxVariableName>("variable")),
      38         120 :     _height(getParam<Real>("height")),
      39          60 :     _mean_value(0)
      40             : {
      41          60 : }
      42             : 
      43             : void
      44          60 : SCMPlanarMean::execute()
      45             : {
      46          60 :   auto nz = _mesh.getNumOfAxialCells();
      47          60 :   auto n_channels = _mesh.getNumOfChannels();
      48          60 :   auto Soln = SolutionHandle(_fe_problem.getVariable(0, _variable));
      49          60 :   auto mdot_soln = SolutionHandle(_fe_problem.getVariable(0, "mdot"));
      50          60 :   auto z_grid = _mesh.getZGrid();
      51             :   auto total_length =
      52          60 :       _mesh.getHeatedLength() + _mesh.getHeatedLengthEntry() + _mesh.getHeatedLengthExit();
      53             : 
      54             :   auto mass_flow = 0.0;
      55             :   auto sum_sol_mass_flow = 0.0;
      56             : 
      57             :   // Use outlet mass flow rate for weighting. Print value at the exit of the assembly.
      58          60 :   if (_height >= total_length)
      59             :   {
      60        3042 :     for (unsigned int i_ch = 0; i_ch < n_channels; i_ch++)
      61             :     {
      62        2988 :       auto * node_out = _mesh.getChannelNode(i_ch, nz);
      63        2988 :       mass_flow += mdot_soln(node_out);
      64        2988 :       sum_sol_mass_flow += Soln(node_out) * mdot_soln(node_out);
      65             :     }
      66          54 :     _mean_value = sum_sol_mass_flow / mass_flow;
      67             :   }
      68             :   else
      69             :   {
      70             :     // Locally average over each axial location in each channel
      71           6 :     for (unsigned int iz = 0; iz < nz; iz++)
      72             :     {
      73           6 :       if (_height >= z_grid[iz] && _height < z_grid[iz + 1])
      74             :       {
      75         258 :         for (unsigned int i_ch = 0; i_ch < n_channels; i_ch++)
      76             :         {
      77         252 :           auto * node_out = _mesh.getChannelNode(i_ch, iz + 1);
      78         252 :           auto * node_in = _mesh.getChannelNode(i_ch, iz);
      79         252 :           auto average_solution = Soln(node_in) + (Soln(node_out) - Soln(node_in)) *
      80         252 :                                                       (_height - z_grid[iz]) /
      81         252 :                                                       (z_grid[iz + 1] - z_grid[iz]);
      82         252 :           auto average_mass_flow = mdot_soln(node_in) + (mdot_soln(node_out) - mdot_soln(node_in)) *
      83         252 :                                                             (_height - z_grid[iz]) /
      84         252 :                                                             (z_grid[iz + 1] - z_grid[iz]);
      85         252 :           mass_flow += average_mass_flow;
      86         252 :           sum_sol_mass_flow += average_solution * average_mass_flow;
      87             :         }
      88           6 :         _mean_value = sum_sol_mass_flow / mass_flow;
      89           6 :         break;
      90             :       }
      91             :     }
      92             :   }
      93          60 : }
      94             : 
      95             : Real
      96          60 : SCMPlanarMean::getValue() const
      97             : {
      98          60 :   return _mean_value;
      99             : }

Generated by: LCOV version 1.14