https://mooseframework.inl.gov
SCMQuadPowerIC.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 "SCMQuadPowerIC.h"
11 #include "Function.h"
12 #include "QuadSubChannelMesh.h"
13 
14 using namespace std;
15 using namespace Eigen;
16 
17 registerMooseObject("SubChannelApp", SCMQuadPowerIC);
18 registerMooseObjectRenamed("SubChannelApp", QuadPowerIC, "06/30/2025 24:00", SCMQuadPowerIC);
19 
22 {
24  params.addClassDescription("Computes axial heat rate (W/m) that goes into the subchannel cells "
25  "or is assigned to the fuel pins, in a square lattice arrangement");
26  // params.addRequiredParam<Real>("power", "The total power of the subassembly [W]");
27  params.addRequiredParam<PostprocessorName>(
28  "power", "The postprocessor or Real to use for the total power of the subassembly [W]");
29  params.addRequiredParam<std::string>(
30  "filename", "name of radial power profile .txt file (should be a single column) [UnitLess].");
31  params.addParam<FunctionName>(
32  "axial_heat_rate",
33  "1.0",
34  "user provided normalized function of axial heat rate [Unitless]. "
35  "The integral over pin heated length should equal the heated length");
36  return params;
37 }
38 
40  : QuadSubChannelBaseIC(params),
41  _power(getPostprocessorValue("power")),
42  _numberoflines(0),
43  _filename(getParam<std::string>("filename")),
44  _axial_heat_rate(getFunction("axial_heat_rate"))
45 {
46  if (processor_id() > 0)
47  return;
48 
49  auto nx = _mesh.getNx();
50  auto ny = _mesh.getNy();
51  auto heated_length = _mesh.getHeatedLength();
52 
53  _power_dis.resize((ny - 1) * (nx - 1), 1);
54  _power_dis.setZero();
55  _pin_power_correction.resize((ny - 1) * (nx - 1), 1);
56  _pin_power_correction.setOnes();
57 
58  Real vin;
59  ifstream inFile;
60 
61  inFile.open(_filename);
62  if (!inFile)
63  mooseError(name(), "unable to open file : ", _filename);
64 
65  while (inFile >> vin)
66  _numberoflines += 1;
67 
68  if (inFile.fail() && !inFile.eof())
69  mooseError(name(), " non numerical input at line : ", _numberoflines);
70 
71  if (_numberoflines != (ny - 1) * (nx - 1))
72  mooseError(name(), " Radial profile file doesn't have correct size : ", (ny - 1) * (nx - 1));
73  inFile.close();
74 
75  inFile.open(_filename);
76  int i(0);
77  while (inFile >> vin)
78  {
79  _power_dis(i, 0) = vin;
80  i++;
81  }
82  inFile.close();
83  _console << " Power distribution matrix :\n" << _power_dis << " \n";
84 
85  auto sum = _power_dis.sum();
86  // full (100%) power of one pin [W]
87  auto fpin_power = _power / sum;
88  // actual pin power [W]
89  _ref_power = _power_dis * fpin_power;
90  // Convert the actual pin power to a linear heat rate [W/m]
91  _ref_qprime = _ref_power / heated_length;
92 }
93 
94 void
96 {
97  if (processor_id() > 0)
98  return;
99  auto nx = _mesh.getNx();
100  auto ny = _mesh.getNy();
101  auto n_pins = (nx - 1) * (ny - 1);
102  auto nz = _mesh.getNumOfAxialCells();
103  auto z_grid = _mesh.getZGrid();
104  auto heated_length = _mesh.getHeatedLength();
105  auto unheated_length_entry = _mesh.getHeatedLengthEntry();
106 
107  _estimate_power.resize(n_pins, 1);
108  _estimate_power.setZero();
109  for (unsigned int iz = 1; iz < nz + 1; iz++)
110  {
111  // Compute axial location of nodes.
112  auto z2 = z_grid[iz];
113  auto z1 = z_grid[iz - 1];
114  Point p1(0, 0, z1 - unheated_length_entry);
115  Point p2(0, 0, z2 - unheated_length_entry);
116  auto heat1 = _axial_heat_rate.value(_t, p1);
117  auto heat2 = _axial_heat_rate.value(_t, p2);
118  if (MooseUtils::absoluteFuzzyGreaterThan(z2, unheated_length_entry) &&
119  MooseUtils::absoluteFuzzyLessThan(z1, unheated_length_entry + heated_length))
120  {
121  // cycle through pins
122  for (unsigned int i_pin = 0; i_pin < n_pins; i_pin++)
123  {
124  // Compute the height of this element.
125  auto dz = z2 - z1;
126 
127  // calculation of power for the first heated segment if nodes don't align
128  if (MooseUtils::absoluteFuzzyGreaterThan(z2, unheated_length_entry) &&
129  MooseUtils::absoluteFuzzyLessThan(z1, unheated_length_entry))
130  {
131  heat1 = 0.0;
132  }
133 
134  // calculation of power for the last heated segment if nodes don't align
135  if (MooseUtils::absoluteFuzzyGreaterThan(z2, unheated_length_entry + heated_length) &&
136  MooseUtils::absoluteFuzzyLessThan(z1, unheated_length_entry + heated_length))
137  {
138  heat2 = 0.0;
139  }
140 
141  _estimate_power(i_pin) += _ref_qprime(i_pin) * (heat1 + heat2) * dz / 2.0;
142  }
143  }
144  }
145  // if a Pin has zero power (_ref_qprime(i_pin) = 0) then I need to avoid dividing by zero. I
146  // divide by a wrong non-zero number which is not correct but this error doesn't mess things cause
147  // _ref_qprime(i_pin) = 0.0
148  auto total_power = 0.0;
149  for (unsigned int i_pin = 0; i_pin < n_pins; i_pin++)
150  {
151  total_power += _estimate_power(i_pin);
152  if (_estimate_power(i_pin) == 0.0)
153  _estimate_power(i_pin) = 1.0;
154  }
155  // We need to correct the linear power assigned to the nodes of each pin
156  // so that the total power calculated by the trapezoidal rule agrees with the power assigned by
157  // the user.
159  _console << "###########################################" << std::endl;
160  _console << "Total power estimation by IC kernel before correction: " << total_power << " [W] "
161  << std::endl;
162  _console << "IC Power correction vector :\n" << _pin_power_correction << " \n";
163 }
164 
165 Real
166 SCMQuadPowerIC::value(const Point & p)
167 {
168  auto heated_length = _mesh.getHeatedLength();
169  auto unheated_length_entry = _mesh.getHeatedLengthEntry();
170  Point p1(0, 0, unheated_length_entry);
171  Point P = p - p1;
172  auto pin_mesh_exist = _mesh.pinMeshExist();
173 
175  if (MooseUtils::absoluteFuzzyGreaterEqual(p(2), unheated_length_entry) &&
176  MooseUtils::absoluteFuzzyLessEqual(p(2), unheated_length_entry + heated_length))
177  {
178  if (pin_mesh_exist)
179  {
180  // project axial heat rate on pins
181  auto i_pin = _mesh.getPinIndexFromPoint(p);
182  return _ref_qprime(i_pin) * _pin_power_correction(i_pin) * _axial_heat_rate.value(_t, P);
183  }
184  else
185  {
186  // project axial heat rate on subchannels
187  auto i_ch = _mesh.getSubchannelIndexFromPoint(p);
188  // if we are adjacent to the heated part of the fuel Pin
189  auto heat_rate = 0.0;
190  for (auto i_pin : _mesh.getChannelPins(i_ch))
191  {
192  heat_rate += 0.25 * _ref_qprime(i_pin) * _pin_power_correction(i_pin) *
194  }
195  return heat_rate;
196  }
197  }
198  else
199  return 0.0;
200 }
SCMQuadPowerIC(const InputParameters &params)
const PostprocessorValue & _power
The total power of the assembly.
registerMooseObject("SubChannelApp", SCMQuadPowerIC)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int _numberoflines
The number of lines associated with the radial power profile .txt file.
virtual const std::vector< Real > & getZGrid() const
Get axial location of layers.
static InputParameters validParams()
An abstract class for ICs for quadrilateral subchannels.
Eigen::MatrixXd _ref_qprime
Average linear heat rate over the whole pin [W/m].
void addRequiredParam(const std::string &name, const std::string &doc_string)
Real value(const Point &p) override
const QuadSubChannelMesh & _mesh
static InputParameters validParams()
const std::string & name() const
unsigned int getSubchannelIndexFromPoint(const Point &p) const override
Return a subchannel index for a given physical point p
virtual const Real & getHeatedLength() const
Return heated length.
Eigen::MatrixXd _estimate_power
Matrix which will hold the total estimated power of each pin [W].
virtual bool pinMeshExist() const override
Return if Pin Mesh exists or not.
Eigen::MatrixXd _pin_power_correction
The correction that will be applied to the estimated calculation [unitless].
Eigen::MatrixXd _power_dis
matrix that holds the values of the relative pin power
Eigen::MatrixXd _ref_power
Actual pin power [W].
virtual unsigned int getNumOfAxialCells() const
Return the number of axial cells.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual const unsigned int & getNy() const
Number of subchannels in the -y direction.
const Function & _axial_heat_rate
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
unsigned int getPinIndexFromPoint(const Point &p) const override
Return a pin index for a given physical point p
virtual const unsigned int & getNx() const
Number of subchannels in the -x direction.
const ConsoleStream _console
virtual Real value(Real t, const Point &p) const
virtual const std::vector< unsigned int > & getChannelPins(unsigned int i_chan) const override
Return a vector of pin indices for a given channel index.
processor_id_type processor_id() const
virtual const Real & getHeatedLengthEntry() const
Return unheated length at entry.
std::string _filename
The name of the radial power profile file.
virtual void initialSetup() override
registerMooseObjectRenamed("SubChannelApp", QuadPowerIC, "06/30/2025 24:00", SCMQuadPowerIC)
Sets the axial heat rate for each pin according to a radial power distribution and a user defined axi...