https://mooseframework.inl.gov
SCMPlanarMean.C
Go to the documentation of this file.
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 
25 {
27  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  params.addRequiredParam<AuxVariableName>("variable", "Variable you want the mean of");
30  params.addRequiredParam<Real>("height", "Axial location of plane [m]");
31  return params;
32 }
33 
35  : GeneralPostprocessor(parameters),
36  _mesh(SCM::getConstMesh<SubChannelMesh>(_fe_problem.mesh())),
37  _variable(getParam<AuxVariableName>("variable")),
38  _height(getParam<Real>("height")),
39  _mean_value(0)
40 {
41 }
42 
43 void
45 {
46  auto nz = _mesh.getNumOfAxialCells();
47  auto n_channels = _mesh.getNumOfChannels();
49  auto mdot_soln = SolutionHandle(_fe_problem.getVariable(0, "mdot"));
50  auto z_grid = _mesh.getZGrid();
51  auto total_length =
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  if (_height >= total_length)
59  {
60  for (unsigned int i_ch = 0; i_ch < n_channels; i_ch++)
61  {
62  auto * node_out = _mesh.getChannelNode(i_ch, nz);
63  mass_flow += mdot_soln(node_out);
64  sum_sol_mass_flow += Soln(node_out) * mdot_soln(node_out);
65  }
66  _mean_value = sum_sol_mass_flow / mass_flow;
67  }
68  else
69  {
70  // Locally average over each axial location in each channel
71  for (unsigned int iz = 0; iz < nz; iz++)
72  {
73  if (_height >= z_grid[iz] && _height < z_grid[iz + 1])
74  {
75  for (unsigned int i_ch = 0; i_ch < n_channels; i_ch++)
76  {
77  auto * node_out = _mesh.getChannelNode(i_ch, iz + 1);
78  auto * node_in = _mesh.getChannelNode(i_ch, iz);
79  auto average_solution = Soln(node_in) + (Soln(node_out) - Soln(node_in)) *
80  (_height - z_grid[iz]) /
81  (z_grid[iz + 1] - z_grid[iz]);
82  auto average_mass_flow = mdot_soln(node_in) + (mdot_soln(node_out) - mdot_soln(node_in)) *
83  (_height - z_grid[iz]) /
84  (z_grid[iz + 1] - z_grid[iz]);
85  mass_flow += average_mass_flow;
86  sum_sol_mass_flow += average_solution * average_mass_flow;
87  }
88  _mean_value = sum_sol_mass_flow / mass_flow;
89  break;
90  }
91  }
92  }
93 }
94 
95 Real
97 {
98  return _mean_value;
99 }
const SubChannelMesh & _mesh
geometric information
Definition: SCMPlanarMean.h:30
SCMPlanarMean(const InputParameters &params)
Definition: SCMPlanarMean.C:34
virtual const unsigned int & getNumOfChannels() const =0
Return the number of channels per layer.
virtual const std::vector< Real > & getZGrid() const
Get axial location of layers.
MeshBase & mesh
registerMooseObject("SubChannelApp", SCMPlanarMean)
Provide a simple RAII interface for linear lagrange solution variables.
virtual void execute() override
Definition: SCMPlanarMean.C:44
void addRequiredParam(const std::string &name, const std::string &doc_string)
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
virtual Node * getChannelNode(unsigned int i_chan, unsigned iz) const =0
Get the subchannel mesh node for a given channel index and elevation index.
static InputParameters validParams()
static InputParameters validParams()
Definition: SCMPlanarMean.C:24
virtual const Real & getHeatedLength() const
Return heated length.
const T & getConstMesh(const MooseMesh &mesh)
function to cast const mesh
Definition: SCM.h:21
virtual Real getValue() const override
Definition: SCMPlanarMean.C:96
const Real & _height
axial location [m]
Definition: SCMPlanarMean.h:34
virtual const unsigned int & getNumOfAxialCells() const
Return the number of axial cells.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
AuxVariableName const & _variable
name of variable
Definition: SCMPlanarMean.h:32
FEProblemBase & _fe_problem
Real _mean_value
average value we want to calculate
Definition: SCMPlanarMean.h:36
void addClassDescription(const std::string &doc_string)
Base class for subchannel meshes.
virtual const Real & getHeatedLengthExit() const
Return unheated length at exit.
registerMooseObjectRenamed("SubChannelApp", PlanarMean, "06/30/2025 24:00", SCMPlanarMean)
Definition: SCM.h:16
virtual const Real & getHeatedLengthEntry() const
Return unheated length at entry.
Calculates a mass flow averaged mean of a subchannel variable on a plane.
Definition: SCMPlanarMean.h:18