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