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 
24 {
26  params.addClassDescription("Calculates an mass-flow-rate averaged mean of the chosen "
27  "variable on a z-plane at a user defined height over all subchannels");
28  params.addRequiredParam<AuxVariableName>("variable", "Variable you want the mean of");
29  params.addRequiredParam<Real>("height", "Axial location of plane [m]");
30  return params;
31 }
32 
34  : GeneralPostprocessor(parameters),
35  _mesh(SCM::getConstMesh<SubChannelMesh>(_fe_problem.mesh())),
36  _variable(getParam<AuxVariableName>("variable")),
37  _height(getParam<Real>("height")),
38  _mean_value(0)
39 {
40 }
41 
42 void
44 {
45  auto nz = _mesh.getNumOfAxialCells();
46  auto n_channels = _mesh.getNumOfChannels();
48  auto mdot_soln = SolutionHandle(_fe_problem.getVariable(0, "mdot"));
49  auto z_grid = _mesh.getZGrid();
50  auto total_length =
52 
53  auto mass_flow = 0.0;
54  auto sum_sol_mass_flow = 0.0;
55 
56  // Use outlet mass flow rate for weighting. Print value at the exit of the assembly.
57  if (_height >= total_length)
58  {
59  for (unsigned int i_ch = 0; i_ch < n_channels; i_ch++)
60  {
61  auto * node_out = _mesh.getChannelNode(i_ch, nz);
62  mass_flow += mdot_soln(node_out);
63  sum_sol_mass_flow += Soln(node_out) * mdot_soln(node_out);
64  }
65  _mean_value = sum_sol_mass_flow / mass_flow;
66  }
67  else
68  {
69  // Locally average over each axial location in each channel
70  for (unsigned int iz = 0; iz < nz; iz++)
71  {
72  if (_height >= z_grid[iz] && _height < z_grid[iz + 1])
73  {
74  for (unsigned int i_ch = 0; i_ch < n_channels; i_ch++)
75  {
76  auto * node_out = _mesh.getChannelNode(i_ch, iz + 1);
77  auto * node_in = _mesh.getChannelNode(i_ch, iz);
78  auto average_solution = Soln(node_in) + (Soln(node_out) - Soln(node_in)) *
79  (_height - z_grid[iz]) /
80  (z_grid[iz + 1] - z_grid[iz]);
81  auto average_mass_flow = mdot_soln(node_in) + (mdot_soln(node_out) - mdot_soln(node_in)) *
82  (_height - z_grid[iz]) /
83  (z_grid[iz + 1] - z_grid[iz]);
84  mass_flow += average_mass_flow;
85  sum_sol_mass_flow += average_solution * average_mass_flow;
86  }
87  _mean_value = sum_sol_mass_flow / mass_flow;
88  break;
89  }
90  }
91  }
92 }
93 
94 Real
96 {
97  return _mean_value;
98 }
const SubChannelMesh & _mesh
geometric information
Definition: SCMPlanarMean.h:30
SCMPlanarMean(const InputParameters &params)
Definition: SCMPlanarMean.C:33
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:43
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
static InputParameters validParams()
FEProblemBase & _fe_problem
static InputParameters validParams()
Definition: SCMPlanarMean.C:23
virtual const Real & getHeatedLength() const
Return heated length.
virtual unsigned int getNumOfChannels() const =0
Return the number of channels per layer.
const T & getConstMesh(const MooseMesh &mesh)
function to cast const mesh
Definition: SCM.h:21
virtual Real getValue() const override
Definition: SCMPlanarMean.C:95
virtual Node * getChannelNode(unsigned int i_chan, unsigned int iz) const =0
Get the subchannel mesh node for a given channel index and elevation index.
virtual unsigned int getNumOfAxialCells() const
Return the number of axial cells.
const Real & _height
axial location [m]
Definition: SCMPlanarMean.h:34
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
AuxVariableName const & _variable
name of variable
Definition: SCMPlanarMean.h:32
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.
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