https://mooseframework.inl.gov
Loading...
Searching...
No Matches
TriSubChannel1PhaseProblem.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
11#include "AuxiliarySystem.h"
12#include "TriSubChannelMesh.h"
15#include "SCM.h"
16#include <limits> // for std::numeric_limits
17#include <cmath> // for std::isnan
18#include <unordered_map>
20
22
25{
27 params.addClassDescription("Solver class for subchannels in a triangular lattice assembly and "
28 "bare/wire-wrapped fuel pins");
29 return params;
30}
31
47
49{
50 PetscErrorCode ierr = cleanUp();
51 if (ierr)
52 mooseError(name(), ": Error in memory cleanup");
53}
54
55PetscErrorCode
57{
59 // Clean up heat conduction system
60 LibmeshPetscCall(MatDestroy(&_hc_axial_heat_conduction_mat));
61 LibmeshPetscCall(VecDestroy(&_hc_axial_heat_conduction_rhs));
62 LibmeshPetscCall(MatDestroy(&_hc_radial_heat_conduction_mat));
63 LibmeshPetscCall(VecDestroy(&_hc_radial_heat_conduction_rhs));
64 LibmeshPetscCall(MatDestroy(&_hc_sweep_enthalpy_mat));
65 LibmeshPetscCall(VecDestroy(&_hc_sweep_enthalpy_rhs));
66 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
67}
68
69void
71{
73
74 if (_deformation)
75 {
76 // update surface area, wetted perimeter based on: Dpin, displacement
77 Real standard_area, wire_area, additional_area, wetted_perimeter, displaced_area;
78 auto flat_to_flat = _tri_sch_mesh.getFlatToFlat();
79 auto n_rings = _tri_sch_mesh.getNumOfRings();
80 auto pitch = _subchannel_mesh.getPitch();
81 auto pin_diameter = _subchannel_mesh.getPinDiameter();
82 auto wire_diameter = _tri_sch_mesh.getWireDiameter();
83 auto wire_lead_length = _tri_sch_mesh.getWireLeadLength();
84 auto gap = _tri_sch_mesh.getDuctToPinGap();
85 auto z_blockage = _subchannel_mesh.getZBlockage();
86 auto index_blockage = _subchannel_mesh.getIndexBlockage();
87 auto reduction_blockage = _subchannel_mesh.getReductionBlockage();
88 auto theta =
89 std::acos(wire_lead_length /
90 std::sqrt(Utility::pow<2>(wire_lead_length) +
91 Utility::pow<2>(libMesh::pi * (pin_diameter + wire_diameter))));
92 for (unsigned int iz = 0; iz < _n_cells + 1; iz++)
93 {
94 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
95 {
96 auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
97 auto * node = _subchannel_mesh.getChannelNode(i_ch, iz);
98 auto Z = _z_grid[iz];
99 Real rod_area = 0.0;
100 Real rod_perimeter = 0.0;
101 for (auto i_pin : _subchannel_mesh.getChannelPins(i_ch))
102 {
103 auto * pin_node = _subchannel_mesh.getPinNode(i_pin, iz);
104 if (subch_type == EChannelType::CENTER || subch_type == EChannelType::CORNER)
105 {
106 rod_area +=
107 (1.0 / 6.0) * 0.25 * M_PI * (*_Dpin_soln)(pin_node) * (*_Dpin_soln)(pin_node);
108 rod_perimeter += (1.0 / 6.0) * M_PI * (*_Dpin_soln)(pin_node);
109 }
110 else
111 {
112 rod_area +=
113 (1.0 / 4.0) * 0.25 * M_PI * (*_Dpin_soln)(pin_node) * (*_Dpin_soln)(pin_node);
114 rod_perimeter += (1.0 / 4.0) * M_PI * (*_Dpin_soln)(pin_node);
115 }
116 }
117
118 if (subch_type == EChannelType::CENTER)
119 {
120 standard_area = Utility::pow<2>(pitch) * std::sqrt(3.0) / 4.0;
121 additional_area = 0.0;
122 displaced_area = 0.0;
123 wire_area = libMesh::pi * Utility::pow<2>(wire_diameter) / 8.0 / std::cos(theta);
124 wetted_perimeter = rod_perimeter + 0.5 * libMesh::pi * wire_diameter / std::cos(theta);
125 }
126 else if (subch_type == EChannelType::EDGE)
127 {
128 standard_area = pitch * (pin_diameter / 2.0 + gap);
129 additional_area = 0.0;
130 displaced_area = (*_displacement_soln)(node)*pitch;
131 wire_area = libMesh::pi * Utility::pow<2>(wire_diameter) / 8.0 / std::cos(theta);
132 wetted_perimeter =
133 rod_perimeter + 0.5 * libMesh::pi * wire_diameter / std::cos(theta) + pitch;
134 }
135 else
136 {
137 standard_area = 1.0 / std::sqrt(3.0) * Utility::pow<2>(pin_diameter / 2.0 + gap);
138 additional_area = 0.0;
139 displaced_area = 1.0 / std::sqrt(3.0) *
140 (pin_diameter + 2.0 * gap + (*_displacement_soln)(node)) *
141 (*_displacement_soln)(node);
142 wire_area = libMesh::pi / 24.0 * Utility::pow<2>(wire_diameter) / std::cos(theta);
143 wetted_perimeter =
144 rod_perimeter + libMesh::pi * wire_diameter / std::cos(theta) / 6.0 +
145 2.0 / std::sqrt(3.0) * (pin_diameter / 2.0 + gap + (*_displacement_soln)(node));
146 }
147
148 // Calculate subchannel area
149 auto subchannel_area =
150 standard_area + additional_area + displaced_area - rod_area - wire_area;
151
152 // Correct subchannel area and wetted perimeter in case of overlapping pins
153 auto overlapping_pin_area = 0.0;
154 auto overlapping_wetted_perimeter = 0.0;
155 for (auto i_gap : _subchannel_mesh.getChannelGaps(i_ch))
156 {
157 auto gap_pins = _subchannel_mesh.getGapPins(i_gap);
158 auto pin_1 = gap_pins.first;
159 auto pin_2 = gap_pins.second;
160 auto * pin_node_1 = _subchannel_mesh.getPinNode(pin_1, iz);
161 auto * pin_node_2 = _subchannel_mesh.getPinNode(pin_2, iz);
162 auto Diameter1 = (*_Dpin_soln)(pin_node_1);
163 auto Radius1 = Diameter1 / 2.0;
164 auto Diameter2 = (*_Dpin_soln)(pin_node_2);
165 auto Radius2 = Diameter2 / 2.0;
166 auto pitch = _subchannel_mesh.getPitch();
167
168 if (pitch < (Radius1 + Radius2)) // overlapping pins
169 {
170 mooseWarning(" The gap of index : '", i_gap, " at axial cell ", iz, " ' is blocked.");
171 auto cos1 =
172 (pitch * pitch + Radius1 * Radius1 - Radius2 * Radius2) / (2 * pitch * Radius1);
173 auto cos2 =
174 (pitch * pitch + Radius2 * Radius2 - Radius1 * Radius1) / (2 * pitch * Radius2);
175 auto angle1 = 2.0 * acos(cos1);
176 auto angle2 = 2.0 * acos(cos2);
177 // half of the intersecting arc-length
178 overlapping_wetted_perimeter += 0.5 * angle1 * Radius1 + 0.5 * angle2 * Radius2;
179 // Half of the overlapping area
180 overlapping_pin_area +=
181 0.5 * Radius1 * Radius1 * acos(cos1) + 0.5 * Radius2 * Radius2 * acos(cos2) -
182 0.25 * sqrt((-pitch + Radius1 + Radius2) * (pitch + Radius1 - Radius2) *
183 (pitch - Radius1 + Radius2) * (pitch + Radius1 + Radius2));
184 }
185 }
186 subchannel_area += overlapping_pin_area; // correct surface area
187 wetted_perimeter += -overlapping_wetted_perimeter; // correct wetted perimeter
188
189 // Apply area reduction on subchannels affected by blockage
190 auto index = 0;
191 for (const auto & i_blockage : index_blockage)
192 {
193 if (i_ch == i_blockage && (Z >= z_blockage.front() && Z <= z_blockage.back()))
194 {
195 subchannel_area *= reduction_blockage[index];
196 }
197 index++;
198 }
199 _S_flow_soln->set(node, subchannel_area);
200 _w_perim_soln->set(node, wetted_perimeter);
201 }
202 }
203 // update map of gap between pins (gij) based on: Dpin, displacement
204 for (unsigned int iz = 0; iz < _n_cells + 1; iz++)
205 {
206 for (unsigned int i_gap = 0; i_gap < _n_gaps; i_gap++)
207 {
208 auto gap_pins = _subchannel_mesh.getGapPins(i_gap);
209 auto pin_1 = gap_pins.first;
210 auto pin_2 = gap_pins.second;
211 auto * pin_node_1 = _subchannel_mesh.getPinNode(pin_1, iz);
212 auto * pin_node_2 = _subchannel_mesh.getPinNode(pin_2, iz);
213
214 if (pin_1 == pin_2) // Corner or edge gap
215 {
216 auto displacement = 0.0;
217 auto counter = 0.0;
218 for (auto i_ch : _subchannel_mesh.getPinChannels(pin_1))
219 {
220 auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
221 auto * node = _subchannel_mesh.getChannelNode(i_ch, iz);
222 if (subch_type == EChannelType::EDGE || subch_type == EChannelType::CORNER)
223 {
224 displacement += (*_displacement_soln)(node);
225 counter += 1.0;
226 }
227 }
228 displacement = displacement / counter;
230 i_gap,
231 0.5 * (flat_to_flat - (n_rings - 1) * pitch * std::sqrt(3.0) -
232 (*_Dpin_soln)(pin_node_1)) +
233 displacement);
234 }
235 else // center gap
236 {
238 iz, i_gap, pitch - (*_Dpin_soln)(pin_node_1) / 2.0 - (*_Dpin_soln)(pin_node_2) / 2.0);
239 }
240 // if pins come in contact, the gap is zero
241 if (_tri_sch_mesh.getGapWidth(iz, i_gap) <= 0.0)
242 _tri_sch_mesh.setGapWidth(iz, i_gap, 0.0);
243 }
244 }
245 }
246
247 for (unsigned int iz = 1; iz < _n_cells + 1; iz++)
248 {
249 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
250 {
251 auto * node_out = _subchannel_mesh.getChannelNode(i_ch, iz);
252 auto * node_in = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
253 _mdot_soln->set(node_out, (*_mdot_soln)(node_in));
254 }
255 }
256
257 // We must do a global assembly to make sure data is parallel consistent before we do things
258 // like compute L2 norms
259 _aux->solution().close();
260}
261
262Real
263TriSubChannel1PhaseProblem::computeAddedHeatPin(unsigned int i_ch, unsigned int iz) const
264{
265 if (!_pin_mesh_exist)
266 return 0.0;
267
268 // Compute axial location of nodes.
269 auto z2 = _z_grid[iz];
270 auto z1 = _z_grid[iz - 1];
271 auto heated_length = _subchannel_mesh.getHeatedLength();
272 auto unheated_length_entry = _subchannel_mesh.getHeatedLengthEntry();
273 if (MooseUtils::absoluteFuzzyGreaterThan(z2, unheated_length_entry) &&
274 MooseUtils::absoluteFuzzyLessThan(z1, unheated_length_entry + heated_length))
275 {
276 // Compute the height of this element.
277 auto dz = z2 - z1;
278 Real factor;
279 auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
280 switch (subch_type)
281 {
283 factor = 1.0 / 6.0;
284 break;
286 factor = 1.0 / 4.0;
287 break;
289 factor = 1.0 / 6.0;
290 break;
291 default:
292 return 0.0; // handle invalid subch_type if needed
293 }
294 double heat_rate_in = 0.0;
295 double heat_rate_out = 0.0;
296 for (auto i_pin : _subchannel_mesh.getChannelPins(i_ch))
297 {
298 auto * node_in = _subchannel_mesh.getPinNode(i_pin, iz - 1);
299 auto * node_out = _subchannel_mesh.getPinNode(i_pin, iz);
300 heat_rate_out += factor * (*_q_prime_soln)(node_out);
301 heat_rate_in += factor * (*_q_prime_soln)(node_in);
302 }
303 return (heat_rate_in + heat_rate_out) * dz / 2.0;
304 }
305 else
306 return 0.0;
307}
308
309Real
311{
312 auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
313 if (subch_type == EChannelType::EDGE || subch_type == EChannelType::CORNER)
314 {
315 auto width = _subchannel_mesh.getPitch();
316 if (subch_type == EChannelType::CORNER)
317 width = 2.0 / std::sqrt(3.0) *
319 return width;
320 }
321 else
322 mooseError("Channel is not a perimetric subchannel ");
323}
324
325void
327{
328 unsigned int last_node = (iblock + 1) * _block_size;
329 unsigned int first_node = iblock * _block_size + 1;
330 const Real & wire_lead_length = _tri_sch_mesh.getWireLeadLength();
331 const Real & wire_diameter = _tri_sch_mesh.getWireDiameter();
332 const Real & pitch = _subchannel_mesh.getPitch();
333 const Real & pin_diameter = _subchannel_mesh.getPinDiameter();
334
335 if (iblock == 0)
336 {
337 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
338 {
339 auto * node = _subchannel_mesh.getChannelNode(i_ch, 0);
340 auto h_out = _fp->h_from_p_T((*_P_soln)(node) + _P_out, (*_T_soln)(node));
341 if (h_out < 0)
342 {
344 name(), " : Calculation of negative Enthalpy h_out = : ", h_out, " Axial Level= : ", 0);
345 }
346 _h_soln->set(node, h_out);
347 }
348 }
349
350 if (!_implicit_bool)
351 {
352 for (unsigned int iz = first_node; iz < last_node + 1; iz++)
353 {
354 auto z_grid = _subchannel_mesh.getZGrid();
355 auto dz = z_grid[iz] - z_grid[iz - 1];
356 // Calculation of average mass flux of all periphery subchannels
357 Real edge_flux_ave = 0.0;
358 Real mdot_sum = 0.0;
359 Real si_sum = 0.0;
360 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
361 {
362 auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
363 if (subch_type == EChannelType::EDGE || subch_type == EChannelType::CORNER)
364 {
365 auto * node_in = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
366 auto Si = (*_S_flow_soln)(node_in);
367 auto mdot_in = (*_mdot_soln)(node_in);
368 mdot_sum = mdot_sum + mdot_in;
369 si_sum = si_sum + Si;
370 }
371 }
372 edge_flux_ave = mdot_sum / si_sum;
373
374 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
375 {
376 auto * node_in = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
377 auto * node_out = _subchannel_mesh.getChannelNode(i_ch, iz);
378 auto mdot_in = (*_mdot_soln)(node_in);
379 auto h_in = (*_h_soln)(node_in); // J/kg
380 auto volume = dz * (*_S_flow_soln)(node_in);
381 auto mdot_out = (*_mdot_soln)(node_out);
382 auto h_out = 0.0;
383 Real sumWijh = 0.0;
384 Real sumWijPrimeDhij = 0.0;
385 Real sweep_enthalpy = 0.0;
386 Real e_cond = 0.0;
387
388 // Calculate added enthalpy from heatflux (Pin, Duct)
389 Real added_enthalpy = computeAddedHeatPin(i_ch, iz);
390 added_enthalpy += computeAddedHeatDuct(i_ch, iz);
391
392 // Calculate net sum of enthalpy into/out-of channel i from channels j around i
393 // (Turbulent diffusion, Diversion Crossflow, Sweep flow Enthalpy, Radial heat conduction)
394 unsigned int counter = 0;
395 for (auto i_gap : _subchannel_mesh.getChannelGaps(i_ch))
396 {
397 auto chans = _subchannel_mesh.getGapChannels(i_gap);
398 auto gap = _subchannel_mesh.getGapWidth(iz, i_gap);
399 auto Sij = dz * gap;
400 unsigned int ii_ch = chans.first; // the first subchannel next to gap i_gap
401 unsigned int jj_ch = chans.second; // the second subchannel next to gap i_gap
402 auto * node_in_i = _subchannel_mesh.getChannelNode(ii_ch, iz - 1);
403 auto * node_in_j = _subchannel_mesh.getChannelNode(jj_ch, iz - 1);
404 auto subch_type_i = _subchannel_mesh.getSubchannelType(ii_ch);
405 auto subch_type_j = _subchannel_mesh.getSubchannelType(jj_ch);
406 // Define donor enthalpy
407 auto h_star = 0.0;
408 if (_Wij(i_gap, iz) > 0.0)
409 h_star = (*_h_soln)(node_in_i);
410 else if (_Wij(i_gap, iz) < 0.0)
411 h_star = (*_h_soln)(node_in_j);
412 // Diversion crossflow
413 // take care of the sign by applying the map, use donor cell
414 sumWijh += _subchannel_mesh.getCrossflowSign(i_ch, counter) * _Wij(i_gap, iz) * h_star;
415 counter++;
416 // SWEEP FLOW is calculated if i_gap is located in the periphery
417 // and we have a wire-wrap (if i_gap is in the periphery then i_ch is in the periphery)
418 // There are two gaps per periphery subchannel that this is true.
419 if ((subch_type_i == EChannelType::CORNER || subch_type_i == EChannelType::EDGE) &&
420 (subch_type_j == EChannelType::CORNER || subch_type_j == EChannelType::EDGE) &&
421 (wire_lead_length != 0) && (wire_diameter != 0))
422 {
423 // donor subchannel and node of sweep flow. The donor subchannel is the subchannel next
424 // to i_ch that sweep flow, flows from and into i_ch
425 auto sweep_donor = _tri_sch_mesh.getSweepFlowChans(i_ch).first;
426 auto * node_sweep_donor = _subchannel_mesh.getChannelNode(sweep_donor, iz - 1);
427 // if one of the neighbor subchannels of the periphery gap is the donor subchannel
428 //(the other would be the i_ch) sweep enthalpy flows into i_ch
429 if ((ii_ch == sweep_donor) || (jj_ch == sweep_donor))
430 {
431 sweep_enthalpy += computeSweepFlowMixingParameter(i_gap, iz) * edge_flux_ave * Sij *
432 (*_h_soln)(node_sweep_donor);
433 }
434 // else sweep enthalpy flows out of i_ch
435 else
436 {
437 sweep_enthalpy -= computeSweepFlowMixingParameter(i_gap, iz) * edge_flux_ave * Sij *
438 (*_h_soln)(node_in);
439 }
440 }
441 // Inner gap
442 // Turbulent Diffusion
443 else
444 {
445 sumWijPrimeDhij +=
446 _WijPrime(i_gap, iz) * (2 * h_in - (*_h_soln)(node_in_j) - (*_h_soln)(node_in_i));
447 }
448
449 // compute the radial heat conduction through the gaps
450 Real dist_ij = pitch;
451
452 if (subch_type_i == EChannelType::EDGE && subch_type_j == EChannelType::EDGE)
453 {
454 dist_ij = pitch;
455 }
456 else if ((subch_type_i == EChannelType::CORNER && subch_type_j == EChannelType::EDGE) ||
457 (subch_type_i == EChannelType::EDGE && subch_type_j == EChannelType::CORNER))
458 {
459 dist_ij = pitch;
460 }
461 else
462 {
463 dist_ij = pitch / std::sqrt(3);
464 }
465
466 auto thcon_i = _fp->k_from_p_T((*_P_soln)(node_in_i) + _P_out, (*_T_soln)(node_in_i));
467 auto thcon_j = _fp->k_from_p_T((*_P_soln)(node_in_j) + _P_out, (*_T_soln)(node_in_j));
468 auto shape_factor =
469 0.66 * (pitch / pin_diameter) *
470 std::pow((_subchannel_mesh.getGapWidth(iz, i_gap) / pin_diameter), -0.3);
471 if (ii_ch == i_ch)
472 {
473 e_cond += 0.5 * (thcon_i + thcon_j) * Sij * shape_factor *
474 ((*_T_soln)(node_in_j) - (*_T_soln)(node_in_i)) / dist_ij;
475 }
476 else
477 {
478 e_cond += -0.5 * (thcon_i + thcon_j) * Sij * shape_factor *
479 ((*_T_soln)(node_in_j) - (*_T_soln)(node_in_i)) / dist_ij;
480 }
481 }
482
483 // compute the axial heat conduction between current and lower axial node
484 auto * node_in_i = _subchannel_mesh.getChannelNode(i_ch, iz);
485 auto * node_in_j = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
486 auto thcon_i = _fp->k_from_p_T((*_P_soln)(node_in_i) + _P_out, (*_T_soln)(node_in_i));
487 auto thcon_j = _fp->k_from_p_T((*_P_soln)(node_in_j) + _P_out, (*_T_soln)(node_in_j));
488 auto Si = (*_S_flow_soln)(node_in_i);
489 auto dist_ij = z_grid[iz] - z_grid[iz - 1];
490
491 e_cond += 0.5 * (thcon_i + thcon_j) * Si * ((*_T_soln)(node_in_j) - (*_T_soln)(node_in_i)) /
492 dist_ij;
493
494 unsigned int nz = _subchannel_mesh.getNumOfAxialCells();
495 // compute the axial heat conduction between current and upper axial node
496 if (iz < nz)
497 {
498 auto * node_in_i = _subchannel_mesh.getChannelNode(i_ch, iz);
499 auto * node_in_j = _subchannel_mesh.getChannelNode(i_ch, iz + 1);
500 auto thcon_i = _fp->k_from_p_T((*_P_soln)(node_in_i) + _P_out, (*_T_soln)(node_in_i));
501 auto thcon_j = _fp->k_from_p_T((*_P_soln)(node_in_j) + _P_out, (*_T_soln)(node_in_j));
502 auto Si = (*_S_flow_soln)(node_in_i);
503 auto dist_ij = z_grid[iz + 1] - z_grid[iz];
504 e_cond += 0.5 * (thcon_i + thcon_j) * Si *
505 ((*_T_soln)(node_in_j) - (*_T_soln)(node_in_i)) / dist_ij;
506 }
507
508 // end of radial heat conduction calc.
509 h_out =
510 (mdot_in * h_in - sumWijh - sumWijPrimeDhij + added_enthalpy + e_cond + sweep_enthalpy +
511 _TR * _rho_soln->old(node_out) * _h_soln->old(node_out) * volume / _dt) /
512 (mdot_out + _TR * (*_rho_soln)(node_out)*volume / _dt);
513 if (h_out < 0)
514 {
516 " : Calculation of negative Enthalpy h_out = : ",
517 h_out,
518 " Axial Level= : ",
519 iz);
520 }
521 _h_soln->set(node_out, h_out); // J/kg
522 }
523 }
524 }
525 else
526 {
527 LibmeshPetscCall(MatZeroEntries(_hc_time_derivative_mat));
528 LibmeshPetscCall(MatZeroEntries(_hc_advective_derivative_mat));
529 LibmeshPetscCall(MatZeroEntries(_hc_cross_derivative_mat));
530 LibmeshPetscCall(MatZeroEntries(_hc_axial_heat_conduction_mat));
531 LibmeshPetscCall(MatZeroEntries(_hc_radial_heat_conduction_mat));
532 LibmeshPetscCall(MatZeroEntries(_hc_sweep_enthalpy_mat));
533
534 LibmeshPetscCall(VecZeroEntries(_hc_time_derivative_rhs));
535 LibmeshPetscCall(VecZeroEntries(_hc_advective_derivative_rhs));
536 LibmeshPetscCall(VecZeroEntries(_hc_cross_derivative_rhs));
537 LibmeshPetscCall(VecZeroEntries(_hc_added_heat_rhs));
538 LibmeshPetscCall(VecZeroEntries(_hc_axial_heat_conduction_rhs));
539 LibmeshPetscCall(VecZeroEntries(_hc_radial_heat_conduction_rhs));
540 LibmeshPetscCall(VecZeroEntries(_hc_sweep_enthalpy_rhs));
541
542 // Thermal conductivity and specific heat are needed at every node many times during the
543 // assembly; evaluate each node once. Pressure and temperature do not change during assembly.
544 // The caches are keyed by node id, so they hold only the subchannel nodes of the block whatever
545 // the numbering of the mesh nodes.
546 std::unordered_map<dof_id_type, Real> k_cache;
547 std::unordered_map<dof_id_type, Real> cp_cache;
548 auto thermalConductivity = [&](const Node * node)
549 {
550 const auto [it, inserted] = k_cache.try_emplace(node->id());
551 if (inserted)
552 it->second = _fp->k_from_p_T((*_P_soln)(node) + _P_out, (*_T_soln)(node));
553 return it->second;
554 };
555 auto specificHeat = [&](const Node * node)
556 {
557 const auto [it, inserted] = cp_cache.try_emplace(node->id());
558 if (inserted)
559 it->second = _fp->cp_from_p_T((*_P_soln)(node) + _P_out, (*_T_soln)(node));
560 return it->second;
561 };
562
563 LibmeshPetscCall(MatZeroEntries(_hc_sys_h_mat));
564 LibmeshPetscCall(VecZeroEntries(_hc_sys_h_rhs));
565
566 for (unsigned int iz = first_node; iz < last_node + 1; iz++)
567 {
568 auto dz = _z_grid[iz] - _z_grid[iz - 1];
569 auto pitch = _subchannel_mesh.getPitch();
570 auto pin_diameter = _subchannel_mesh.getPinDiameter();
571 auto iz_ind = iz - first_node;
572
573 // Calculation of average mass flux of all periphery subchannels, used by the sweep flow
574 Real mdot_sum = 0.0;
575 Real si_sum = 0.0;
576 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
577 {
578 const auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
579 if (subch_type == EChannelType::EDGE || subch_type == EChannelType::CORNER)
580 {
581 const auto * node_in = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
582 mdot_sum += (*_mdot_soln)(node_in);
583 si_sum += (*_S_flow_soln)(node_in);
584 }
585 }
586 const Real edge_flux_ave = mdot_sum / si_sum;
587
588 for (unsigned int i_ch = 0; i_ch < _n_channels; i_ch++)
589 {
590 auto * node_in = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
591 auto * node_out = _subchannel_mesh.getChannelNode(i_ch, iz);
592 auto S_in = (*_S_flow_soln)(node_in);
593 auto S_out = (*_S_flow_soln)(node_out);
594 auto S_interp = computeInterpolatedValue(S_out, S_in, 0.5);
595 auto volume = dz * S_interp;
596
597 PetscScalar Pe = 0.5;
598 if (_interpolation_scheme == 3)
599 {
600 // Compute the cell Peclet number
601 auto w_perim_in = (*_w_perim_soln)(node_in);
602 auto w_perim_out = (*_w_perim_soln)(node_out);
603 auto w_perim_interp = this->computeInterpolatedValue(w_perim_out, w_perim_in, 0.5);
604 auto K_in = thermalConductivity(node_in);
605 auto K_out = thermalConductivity(node_out);
606 auto K = this->computeInterpolatedValue(K_out, K_in, 0.5);
607 auto cp_in = specificHeat(node_in);
608 auto cp_out = specificHeat(node_out);
609 auto cp = this->computeInterpolatedValue(cp_out, cp_in, 0.5);
610 auto mdot_loc =
611 this->computeInterpolatedValue((*_mdot_soln)(node_out), (*_mdot_soln)(node_in), 0.5);
612 // hydraulic diameter in the i direction
613 auto Dh_i = 4.0 * S_interp / w_perim_interp;
614 Pe = mdot_loc * Dh_i * cp / (K * S_interp) * (mdot_loc / std::abs(mdot_loc));
615 }
616 auto alpha = computeInterpolationCoefficients(Pe);
617
618 // Keep temporal storage independent of the spatial interpolation scheme. Applying the
619 // upwind coefficient to this term puts the storage on the upstream node and makes the
620 // small-timestep matrix singular in the upwind limit.
621 PetscInt row_tt = i_ch + _n_channels * iz_ind;
622 PetscInt col_tt = i_ch + _n_channels * iz_ind;
623 PetscScalar value_tt = _TR * (*_rho_soln)(node_out)*volume / _dt;
624 LibmeshPetscCall(MatSetValues(
625 _hc_time_derivative_mat, 1, &row_tt, 1, &col_tt, &value_tt, INSERT_VALUES));
626
627 PetscScalar value_vec_tt =
628 _TR * _rho_soln->old(node_out) * _h_soln->old(node_out) * volume / _dt;
629 PetscInt row_vec_tt = i_ch + _n_channels * iz_ind;
630 LibmeshPetscCall(
631 VecSetValues(_hc_time_derivative_rhs, 1, &row_vec_tt, &value_vec_tt, ADD_VALUES));
632
633 // Advective derivative term. mdot and h are face values, so the axial enthalpy flux
634 // through a face is mdot * h at that face and needs no interpolation
635 if (iz == first_node)
636 {
637 PetscInt row_at = i_ch + _n_channels * iz_ind;
638 PetscScalar value_at = (*_mdot_soln)(node_in) * (*_h_soln)(node_in);
639 LibmeshPetscCall(
640 VecSetValues(_hc_advective_derivative_rhs, 1, &row_at, &value_at, ADD_VALUES));
641 }
642 else
643 {
644 PetscInt row_at = i_ch + _n_channels * iz_ind;
645 PetscInt col_at = i_ch + _n_channels * (iz_ind - 1);
646 PetscScalar value_at = -1.0 * (*_mdot_soln)(node_in);
647 LibmeshPetscCall(MatSetValues(
648 _hc_advective_derivative_mat, 1, &row_at, 1, &col_at, &value_at, ADD_VALUES));
649 }
650
651 PetscInt row_at = i_ch + _n_channels * iz_ind;
652 PetscInt col_at = i_ch + _n_channels * iz_ind;
653 PetscScalar value_at = (*_mdot_soln)(node_out);
654 LibmeshPetscCall(MatSetValues(
655 _hc_advective_derivative_mat, 1, &row_at, 1, &col_at, &value_at, ADD_VALUES));
656
657 // Axial heat conduction
658 auto * node_center = _subchannel_mesh.getChannelNode(i_ch, iz);
659 auto K_center = thermalConductivity(node_center);
660 auto cp_center = specificHeat(node_center);
661 auto diff_center = K_center / (cp_center + 1e-15);
662
663 if (iz == first_node)
664 {
665 auto * node_top = _subchannel_mesh.getChannelNode(i_ch, iz + 1);
666 auto * node_bottom = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
667 auto K_bottom = thermalConductivity(node_bottom);
668 auto K_top = thermalConductivity(node_top);
669 auto cp_bottom = specificHeat(node_bottom);
670 auto cp_top = specificHeat(node_top);
671 auto diff_bottom = K_bottom / (cp_bottom + 1e-15);
672 auto diff_top = K_top / (cp_top + 1e-15);
673
674 auto dz_up = _z_grid[iz + 1] - _z_grid[iz];
675 auto dz_down = _z_grid[iz] - _z_grid[iz - 1];
676 auto S_up =
677 computeInterpolatedValue((*_S_flow_soln)(node_top), (*_S_flow_soln)(node_center));
678 auto S_down =
679 computeInterpolatedValue((*_S_flow_soln)(node_center), (*_S_flow_soln)(node_bottom));
680 auto diff_up = computeInterpolatedValue(diff_top, diff_center);
681 auto diff_down = computeInterpolatedValue(diff_center, diff_bottom);
682
683 // Diagonal value
684 PetscInt row_at = i_ch + _n_channels * iz_ind;
685 PetscInt col_at = i_ch + _n_channels * iz_ind;
686 PetscScalar value_at = diff_up * S_up / dz_up + diff_down * S_down / dz_down;
687 LibmeshPetscCall(MatSetValues(
688 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
689
690 // Bottom value
691 value_at = 1.0 * diff_down * S_down / dz_down * (*_h_soln)(node_bottom);
692 LibmeshPetscCall(
693 VecSetValues(_hc_axial_heat_conduction_rhs, 1, &row_at, &value_at, ADD_VALUES));
694
695 // Top value
696 col_at = i_ch + _n_channels * (iz_ind + 1);
697 value_at = -diff_up * S_up / dz_up;
698 LibmeshPetscCall(MatSetValues(
699 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
700 }
701 else if (iz == last_node)
702 {
703 auto * node_bottom = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
704 auto K_bottom = thermalConductivity(node_bottom);
705 auto cp_bottom = specificHeat(node_bottom);
706 auto diff_bottom = K_bottom / (cp_bottom + 1e-15);
707
708 auto dz_down = _z_grid[iz] - _z_grid[iz - 1];
709 auto S_down = 0.5 * ((*_S_flow_soln)(node_center) + (*_S_flow_soln)(node_bottom));
710 auto diff_down = 0.5 * (diff_center + diff_bottom);
711
712 // Diagonal value
713 PetscInt row_at = i_ch + _n_channels * iz_ind;
714 PetscInt col_at = i_ch + _n_channels * iz_ind;
715 PetscScalar value_at = diff_down * S_down / dz_down;
716 LibmeshPetscCall(MatSetValues(
717 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
718
719 // Bottom value
720 col_at = i_ch + _n_channels * (iz_ind - 1);
721 value_at = -diff_down * S_down / dz_down;
722 LibmeshPetscCall(MatSetValues(
723 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
724
725 // No conduction term for the outlet face: the two entries above are equal and opposite,
726 // so the row conducts only with the cell below and the outlet is modeled as adiabatic
727 // (zero enthalpy gradient). This neglects conduction into an outlet plenum, which is not
728 // part of the domain, and it is why the conduction of the block loses heat only through
729 // the inlet, where the enthalpy is prescribed (see
730 // SCMInletConductionHeatRatePostprocessor). The outflow enthalpy the flow itself carries
731 // is already in the advective term, whose diagonal holds mdot of this face for every cell
732 // including this one.
733 }
734 else
735 {
736 auto * node_top = _subchannel_mesh.getChannelNode(i_ch, iz + 1);
737 auto * node_bottom = _subchannel_mesh.getChannelNode(i_ch, iz - 1);
738 auto K_bottom = thermalConductivity(node_bottom);
739 auto K_top = thermalConductivity(node_top);
740 auto cp_bottom = specificHeat(node_bottom);
741 auto cp_top = specificHeat(node_top);
742 auto diff_bottom = K_bottom / (cp_bottom + 1e-15);
743 auto diff_top = K_top / (cp_top + 1e-15);
744
745 auto dz_up = _z_grid[iz + 1] - _z_grid[iz];
746 auto dz_down = _z_grid[iz] - _z_grid[iz - 1];
747 auto S_up =
748 computeInterpolatedValue((*_S_flow_soln)(node_top), (*_S_flow_soln)(node_center));
749 auto S_down =
750 computeInterpolatedValue((*_S_flow_soln)(node_center), (*_S_flow_soln)(node_bottom));
751 auto diff_up = computeInterpolatedValue(diff_top, diff_center);
752 auto diff_down = computeInterpolatedValue(diff_center, diff_bottom);
753
754 // Diagonal value
755 PetscInt row_at = i_ch + _n_channels * iz_ind;
756 PetscInt col_at = i_ch + _n_channels * iz_ind;
757 PetscScalar value_at = diff_up * S_up / dz_up + diff_down * S_down / dz_down;
758 LibmeshPetscCall(MatSetValues(
759 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
760
761 // Bottom value
762 col_at = i_ch + _n_channels * (iz_ind - 1);
763 value_at = -diff_down * S_down / dz_down;
764 LibmeshPetscCall(MatSetValues(
765 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
766
767 // Top value
768 col_at = i_ch + _n_channels * (iz_ind + 1);
769 value_at = -diff_up * S_up / dz_up;
770 LibmeshPetscCall(MatSetValues(
771 _hc_axial_heat_conduction_mat, 1, &row_at, 1, &col_at, &value_at, INSERT_VALUES));
772 }
773
774 // Radial Terms
775 unsigned int counter = 0;
776 unsigned int cross_index = iz;
777 // Real radial_heat_conduction(0.0);
778 for (auto i_gap : _subchannel_mesh.getChannelGaps(i_ch))
779 {
780 auto chans = _subchannel_mesh.getGapChannels(i_gap);
781 unsigned int ii_ch = chans.first;
782 unsigned int jj_ch = chans.second;
783 auto * node_in_i = _subchannel_mesh.getChannelNode(ii_ch, iz - 1);
784 auto * node_in_j = _subchannel_mesh.getChannelNode(jj_ch, iz - 1);
785 PetscScalar h_star;
786 // figure out donor axial velocity
787 if (_Wij(i_gap, cross_index) > 0.0)
788 {
789 if (iz == first_node)
790 {
791 h_star = (*_h_soln)(node_in_i);
792 PetscScalar value_vec_ct = -1.0 * alpha *
793 _subchannel_mesh.getCrossflowSign(i_ch, counter) *
794 _Wij(i_gap, cross_index) * h_star;
795 PetscInt row_vec_ct = i_ch + _n_channels * iz_ind;
796 LibmeshPetscCall(VecSetValues(
797 _hc_cross_derivative_rhs, 1, &row_vec_ct, &value_vec_ct, ADD_VALUES));
798 }
799 else
800 {
801 PetscScalar value_ct = alpha * _subchannel_mesh.getCrossflowSign(i_ch, counter) *
802 _Wij(i_gap, cross_index);
803 PetscInt row_ct = i_ch + _n_channels * iz_ind;
804 PetscInt col_ct = ii_ch + _n_channels * (iz_ind - 1);
805 LibmeshPetscCall(MatSetValues(
806 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_ct, ADD_VALUES));
807 }
808 PetscScalar value_ct = (1.0 - alpha) *
809 _subchannel_mesh.getCrossflowSign(i_ch, counter) *
810 _Wij(i_gap, cross_index);
811 PetscInt row_ct = i_ch + _n_channels * iz_ind;
812 PetscInt col_ct = ii_ch + _n_channels * iz_ind;
813 LibmeshPetscCall(MatSetValues(
814 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_ct, ADD_VALUES));
815 }
816 else if (_Wij(i_gap, cross_index) < 0.0) // _Wij=0 operations not necessary
817 {
818 if (iz == first_node)
819 {
820 h_star = (*_h_soln)(node_in_j);
821 PetscScalar value_vec_ct = -1.0 * alpha *
822 _subchannel_mesh.getCrossflowSign(i_ch, counter) *
823 _Wij(i_gap, cross_index) * h_star;
824 PetscInt row_vec_ct = i_ch + _n_channels * iz_ind;
825 LibmeshPetscCall(VecSetValues(
826 _hc_cross_derivative_rhs, 1, &row_vec_ct, &value_vec_ct, ADD_VALUES));
827 }
828 else
829 {
830 PetscScalar value_ct = alpha * _subchannel_mesh.getCrossflowSign(i_ch, counter) *
831 _Wij(i_gap, cross_index);
832 PetscInt row_ct = i_ch + _n_channels * iz_ind;
833 PetscInt col_ct = jj_ch + _n_channels * (iz_ind - 1);
834 LibmeshPetscCall(MatSetValues(
835 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_ct, ADD_VALUES));
836 }
837 PetscScalar value_ct = (1.0 - alpha) *
838 _subchannel_mesh.getCrossflowSign(i_ch, counter) *
839 _Wij(i_gap, cross_index);
840 PetscInt row_ct = i_ch + _n_channels * iz_ind;
841 PetscInt col_ct = jj_ch + _n_channels * iz_ind;
842 LibmeshPetscCall(MatSetValues(
843 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_ct, ADD_VALUES));
844 }
845
846 // Turbulent cross flows
847 if (iz == first_node)
848 {
849 PetscScalar value_vec_ct =
850 -2.0 * alpha * (*_h_soln)(node_in)*_WijPrime(i_gap, cross_index);
851 value_vec_ct += alpha * (*_h_soln)(node_in_j)*_WijPrime(i_gap, cross_index);
852 value_vec_ct += alpha * (*_h_soln)(node_in_i)*_WijPrime(i_gap, cross_index);
853 PetscInt row_vec_ct = i_ch + _n_channels * iz_ind;
854 LibmeshPetscCall(
855 VecSetValues(_hc_cross_derivative_rhs, 1, &row_vec_ct, &value_vec_ct, ADD_VALUES));
856 }
857 else
858 {
859 PetscScalar value_center_ct = 2.0 * alpha * _WijPrime(i_gap, cross_index);
860 PetscInt row_ct = i_ch + _n_channels * iz_ind;
861 PetscInt col_ct = i_ch + _n_channels * (iz_ind - 1);
862 LibmeshPetscCall(MatSetValues(
863 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_center_ct, ADD_VALUES));
864
865 PetscScalar value_left_ct = -1.0 * alpha * _WijPrime(i_gap, cross_index);
866 row_ct = i_ch + _n_channels * iz_ind;
867 col_ct = jj_ch + _n_channels * (iz_ind - 1);
868 LibmeshPetscCall(MatSetValues(
869 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_left_ct, ADD_VALUES));
870
871 PetscScalar value_right_ct = -1.0 * alpha * _WijPrime(i_gap, cross_index);
872 row_ct = i_ch + _n_channels * iz_ind;
873 col_ct = ii_ch + _n_channels * (iz_ind - 1);
874 LibmeshPetscCall(MatSetValues(
875 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_right_ct, ADD_VALUES));
876 }
877 PetscScalar value_center_ct = 2.0 * (1.0 - alpha) * _WijPrime(i_gap, cross_index);
878 PetscInt row_ct = i_ch + _n_channels * iz_ind;
879 PetscInt col_ct = i_ch + _n_channels * iz_ind;
880 LibmeshPetscCall(MatSetValues(
881 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_center_ct, ADD_VALUES));
882
883 PetscScalar value_left_ct = -1.0 * (1.0 - alpha) * _WijPrime(i_gap, cross_index);
884 row_ct = i_ch + _n_channels * iz_ind;
885 col_ct = jj_ch + _n_channels * iz_ind;
886 LibmeshPetscCall(MatSetValues(
887 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_left_ct, ADD_VALUES));
888
889 PetscScalar value_right_ct = -1.0 * (1.0 - alpha) * _WijPrime(i_gap, cross_index);
890 row_ct = i_ch + _n_channels * iz_ind;
891 col_ct = ii_ch + _n_channels * iz_ind;
892 LibmeshPetscCall(MatSetValues(
893 _hc_cross_derivative_mat, 1, &row_ct, 1, &col_ct, &value_right_ct, ADD_VALUES));
894
895 // Radial heat conduction
896 auto subch_type_i = _subchannel_mesh.getSubchannelType(ii_ch);
897 auto subch_type_j = _subchannel_mesh.getSubchannelType(jj_ch);
898 Real dist_ij = pitch;
899
900 if (subch_type_i == EChannelType::EDGE && subch_type_j == EChannelType::EDGE)
901 {
902 dist_ij = pitch;
903 }
904 else if ((subch_type_i == EChannelType::CORNER && subch_type_j == EChannelType::EDGE) ||
905 (subch_type_i == EChannelType::EDGE && subch_type_j == EChannelType::CORNER))
906 {
907 dist_ij = pitch;
908 }
909 else
910 {
911 dist_ij = pitch / std::sqrt(3);
912 }
913
914 auto Sij = dz * _subchannel_mesh.getGapWidth(iz, i_gap);
915 auto K_i = thermalConductivity(node_in_i);
916 auto K_j = thermalConductivity(node_in_j);
917 auto cp_i = specificHeat(node_in_i);
918 auto cp_j = specificHeat(node_in_j);
919 auto A_i = K_i / cp_i;
920 auto A_j = K_j / cp_j;
921 auto harm_A = 2.0 * A_i * A_j / (A_i + A_j);
922 auto shape_factor =
923 0.66 * (pitch / pin_diameter) *
924 std::pow((_subchannel_mesh.getGapWidth(iz, i_gap) / pin_diameter), -0.3);
925 // auto base_value = 0.5 * (A_i + A_j) * Sij * shape_factor / dist_ij;
926 auto base_value = harm_A * shape_factor * Sij / dist_ij;
927 auto neg_base_value = -1.0 * base_value;
928
929 // Each gap is visited once from each of its two channels, so only the row of the
930 // current channel is written here
931 const auto other_ch = (i_ch == ii_ch) ? jj_ch : ii_ch;
932 row_ct = i_ch + _n_channels * iz_ind;
933 col_ct = i_ch + _n_channels * iz_ind;
934 LibmeshPetscCall(MatSetValues(
935 _hc_radial_heat_conduction_mat, 1, &row_ct, 1, &col_ct, &base_value, ADD_VALUES));
936
937 col_ct = other_ch + _n_channels * iz_ind;
938 LibmeshPetscCall(MatSetValues(
939 _hc_radial_heat_conduction_mat, 1, &row_ct, 1, &col_ct, &neg_base_value, ADD_VALUES));
940 counter++;
941 }
942
943 // Compute the sweep flow enthalpy change
944 auto subch_type = _subchannel_mesh.getSubchannelType(i_ch);
945 PetscScalar sweep_enthalpy = 0.0;
946 if ((subch_type == EChannelType::EDGE || subch_type == EChannelType::CORNER) &&
947 (wire_diameter != 0.0) && (wire_lead_length != 0.0))
948 {
949 auto beta_in = std::numeric_limits<double>::quiet_NaN();
950 auto beta_out = std::numeric_limits<double>::quiet_NaN();
951 // donor sweep channel for i_ch
952 auto sweep_donor = _tri_sch_mesh.getSweepFlowChans(i_ch).first;
953 auto * node_sweep_donor = _subchannel_mesh.getChannelNode(sweep_donor, iz - 1);
954 // Calculation of turbulent mixing parameter
955 for (auto i_gap : _subchannel_mesh.getChannelGaps(i_ch))
956 {
957 auto chans = _subchannel_mesh.getGapChannels(i_gap);
958 unsigned int ii_ch = chans.first;
959 unsigned int jj_ch = chans.second;
960 auto subch_type_i = _subchannel_mesh.getSubchannelType(ii_ch);
961 auto subch_type_j = _subchannel_mesh.getSubchannelType(jj_ch);
962 if ((subch_type_i == EChannelType::CORNER || subch_type_i == EChannelType::EDGE) &&
963 (subch_type_j == EChannelType::CORNER || subch_type_j == EChannelType::EDGE))
964 {
965 if ((ii_ch == sweep_donor) || (jj_ch == sweep_donor))
966 {
967 beta_in = computeSweepFlowMixingParameter(i_gap, iz);
968 }
969 else
970 {
971 beta_out = computeSweepFlowMixingParameter(i_gap, iz);
972 }
973 }
974 }
975 // Abort execution if required values are unset
976 mooseAssert(!std::isnan(beta_in),
977 "beta_in was not set. Check gap logic for i_ch = " + std::to_string(i_ch) +
978 ", iz = " + std::to_string(iz));
979 mooseAssert(!std::isnan(beta_out),
980 "beta_out was not set. Check gap logic for i_ch = " + std::to_string(i_ch) +
981 ", iz = " + std::to_string(iz));
982
983 auto gap = _tri_sch_mesh.getDuctToPinGap();
984 auto Sij = dz * gap;
985 auto wsweep_in = edge_flux_ave * beta_in * Sij;
986 auto wsweep_out = edge_flux_ave * beta_out * Sij;
987 auto sweep_hin = (*_h_soln)(node_sweep_donor);
988 auto sweep_hout = (*_h_soln)(node_in);
989 sweep_enthalpy = (wsweep_in * sweep_hin - wsweep_out * sweep_hout);
990
991 // Sweep flow acts over the cell, so the enthalpies are interpolated to the cell center
992 PetscInt row_sh = i_ch + _n_channels * iz_ind;
993 if (iz == first_node)
994 {
995 PetscScalar value_hs = alpha * sweep_enthalpy;
996 LibmeshPetscCall(
997 VecSetValues(_hc_sweep_enthalpy_rhs, 1, &row_sh, &value_hs, ADD_VALUES));
998 }
999 else
1000 {
1001 PetscInt col_sh = i_ch + _n_channels * (iz_ind - 1);
1002 PetscScalar value_sh = alpha * wsweep_out;
1003 LibmeshPetscCall(MatSetValues(
1004 _hc_sweep_enthalpy_mat, 1, &row_sh, 1, &col_sh, &value_sh, ADD_VALUES));
1005 col_sh = sweep_donor + _n_channels * (iz_ind - 1);
1006 value_sh = -alpha * wsweep_in;
1007 LibmeshPetscCall(MatSetValues(
1008 _hc_sweep_enthalpy_mat, 1, &row_sh, 1, &col_sh, &value_sh, ADD_VALUES));
1009 }
1010 PetscInt col_sh = i_ch + _n_channels * iz_ind;
1011 PetscScalar value_sh = (1.0 - alpha) * wsweep_out;
1012 LibmeshPetscCall(
1013 MatSetValues(_hc_sweep_enthalpy_mat, 1, &row_sh, 1, &col_sh, &value_sh, ADD_VALUES));
1014 col_sh = sweep_donor + _n_channels * iz_ind;
1015 value_sh = -(1.0 - alpha) * wsweep_in;
1016 LibmeshPetscCall(
1017 MatSetValues(_hc_sweep_enthalpy_mat, 1, &row_sh, 1, &col_sh, &value_sh, ADD_VALUES));
1018 }
1019
1020 // Add heat enthalpy from pin and/or duct
1021 PetscScalar added_enthalpy = computeAddedHeatPin(i_ch, iz);
1022 added_enthalpy += computeAddedHeatDuct(i_ch, iz);
1023 PetscInt row_vec_ht = i_ch + _n_channels * iz_ind;
1024 LibmeshPetscCall(
1025 VecSetValues(_hc_added_heat_rhs, 1, &row_vec_ht, &added_enthalpy, ADD_VALUES));
1026 }
1027 }
1028 // Assembling system
1029 LibmeshPetscCall(MatAssemblyBegin(_hc_time_derivative_mat, MAT_FINAL_ASSEMBLY));
1030 LibmeshPetscCall(MatAssemblyEnd(_hc_time_derivative_mat, MAT_FINAL_ASSEMBLY));
1031 LibmeshPetscCall(MatAssemblyBegin(_hc_advective_derivative_mat, MAT_FINAL_ASSEMBLY));
1032 LibmeshPetscCall(MatAssemblyEnd(_hc_advective_derivative_mat, MAT_FINAL_ASSEMBLY));
1033 LibmeshPetscCall(MatAssemblyBegin(_hc_cross_derivative_mat, MAT_FINAL_ASSEMBLY));
1034 LibmeshPetscCall(MatAssemblyEnd(_hc_cross_derivative_mat, MAT_FINAL_ASSEMBLY));
1035 LibmeshPetscCall(MatAssemblyBegin(_hc_axial_heat_conduction_mat, MAT_FINAL_ASSEMBLY));
1036 LibmeshPetscCall(MatAssemblyEnd(_hc_axial_heat_conduction_mat, MAT_FINAL_ASSEMBLY));
1037 LibmeshPetscCall(MatAssemblyBegin(_hc_radial_heat_conduction_mat, MAT_FINAL_ASSEMBLY));
1038 LibmeshPetscCall(MatAssemblyEnd(_hc_radial_heat_conduction_mat, MAT_FINAL_ASSEMBLY));
1039 LibmeshPetscCall(MatAssemblyBegin(_hc_sweep_enthalpy_mat, MAT_FINAL_ASSEMBLY));
1040 LibmeshPetscCall(MatAssemblyEnd(_hc_sweep_enthalpy_mat, MAT_FINAL_ASSEMBLY));
1041 LibmeshPetscCall(MatAssemblyBegin(_hc_sys_h_mat, MAT_FINAL_ASSEMBLY));
1042 LibmeshPetscCall(MatAssemblyEnd(_hc_sys_h_mat, MAT_FINAL_ASSEMBLY));
1043 // Add all matrices together
1044 LibmeshPetscCall(addTermMatrices(_hc_sys_h_mat,
1053 _console << "Block: " << iblock << " - Enthalpy conservation matrix assembled" << std::endl;
1054 // RHS
1055 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_time_derivative_rhs));
1056 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_advective_derivative_rhs));
1057 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_cross_derivative_rhs));
1058 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_added_heat_rhs));
1059 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_axial_heat_conduction_rhs));
1060 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_radial_heat_conduction_rhs));
1061 LibmeshPetscCall(VecAXPY(_hc_sys_h_rhs, 1.0, _hc_sweep_enthalpy_rhs));
1062
1063 // Use system to solve for and populate enthalpy
1064 LibmeshPetscCall(this->solveAndPopulateEnthalpy(
1065 _hc_sys_h_mat, _hc_sys_h_rhs, first_node, last_node, "h_sys_"));
1066 }
1067}
PetscFunctionBegin
registerMooseObject("SubChannelApp", TriSubChannel1PhaseProblem)
const ConsoleStream _console
std::shared_ptr< AuxiliarySystem > _aux
void addClassDescription(const std::string &doc_string)
const std::string & name() const
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
Base class for the 1-phase steady-state/transient subchannel solver.
PetscErrorCode createPetscVector(Vec &v, PetscInt n)
Petsc Functions.
PetscScalar computeInterpolatedValue(PetscScalar topValue, PetscScalar botValue, PetscScalar Peclet=0.0)
Real computeSweepFlowMixingParameter(unsigned int i_gap, unsigned int iz) const
Computes and validates the sweep-flow mixing parameter.
std::unique_ptr< SolutionHandle > _w_perim_soln
PetscErrorCode createPetscMatrix(Mat &M, PetscInt n, PetscInt m)
Mat _hc_time_derivative_mat
Enthalpy Enthalpy conservation - time derivative.
static InputParameters validParams()
PetscErrorCode solveAndPopulateEnthalpy(Mat A, Vec rhs, unsigned int first_node, unsigned int last_node, const char *ksp_prefix)
Solve a linear system (A * x = rhs) with a simple PCJACOBI KSP and populate the enthalpy solution int...
const SinglePhaseFluidProperties * _fp
Non-owning pointer to fluid properties user object.
libMesh::DenseMatrix< Real > _WijPrime
const MooseEnum _interpolation_scheme
The interpolation method used in constructing the systems.
std::unique_ptr< SolutionHandle > _rho_soln
std::unique_ptr< SolutionHandle > _S_flow_soln
const PostprocessorValue & _P_out
Outlet pressure postprocessor value.
std::unique_ptr< SolutionHandle > _Dpin_soln
std::unique_ptr< SolutionHandle > _P_soln
void detectDeformation()
Detects whether pin diameter or duct displacement fields require geometry recalculation.
libMesh::DenseMatrix< Real > & _Wij
bool _deformation
Flag that activates the effect of deformation (pin/duct) based on the auxvalues for displacement,...
std::unique_ptr< SolutionHandle > _h_soln
std::unique_ptr< SolutionHandle > _T_soln
Real _TR
Flag that activates or deactivates the transient parts of the equations we solve by multiplication.
Vec _hc_added_heat_rhs
Enthalpy conservation - source and sink.
Mat _hc_advective_derivative_mat
Enthalpy conservation - advective (Eulerian) derivative;.
const bool _pin_mesh_exist
Flag that informs if there is a pin mesh or not.
const bool _implicit_bool
Flag to define the usage of a implicit or explicit solution.
std::vector< Real > _z_grid
axial location of nodes
std::unique_ptr< SolutionHandle > _mdot_soln
Solutions handles and link to TH tables properties.
PetscScalar computeInterpolationCoefficients(PetscScalar Peclet=0.0) const
Functions that computes the interpolation scheme given the Peclet number.
virtual Real computeAddedHeatDuct(unsigned int i_ch, unsigned int iz) const
Non-pure: implemented in the base (or override in a child if needed)
PetscErrorCode addTermMatrices(Mat system, const std::vector< Mat > &terms, bool &pattern_set)
Add the term matrices to a system matrix that was zeroed beforehand.
const bool _verbose_subchannel
Boolean to printout information related to subchannel solve.
Mat _hc_cross_derivative_mat
Enthalpy conservation - cross flux derivative.
virtual const Real & getHeatedLength() const
Return heated length.
virtual const std::vector< unsigned int > & getChannelPins(unsigned int i_chan) const =0
Return a vector of pin indices for a given channel index.
virtual const std::vector< Real > & getZBlockage() const
Get axial location of blockage (in,out) [m].
virtual const Real & getHeatedLengthEntry() const
Return unheated length at entry.
virtual const std::vector< Real > & getZGrid() const
Get axial location of layers.
virtual Real getGapWidth(unsigned int axial_index, unsigned int gap_index) const =0
Return gap width for a given gap index.
virtual const Real & getPitch() const
Return the undeformed pitch between 2 subchannels.
virtual const std::pair< unsigned int, unsigned int > & getGapChannels(unsigned int i_gap) const =0
Return a pair of subchannel indices for a given gap index.
virtual const std::vector< Real > & getReductionBlockage() const
Get area reduction of blocked subchannels.
virtual const std::pair< unsigned int, unsigned int > & getGapPins(unsigned int i_gap) const =0
Return a pair of pin indices for a given gap index.
virtual EChannelType getSubchannelType(unsigned int index) const =0
Return the type of the subchannel for given subchannel index.
virtual const Real & getCrossflowSign(unsigned int i_chan, unsigned int i_local) const =0
Return a sign for the crossflow given a subchannel index and local neighbor index.
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 const std::vector< unsigned int > & getIndexBlockage() const
Get index of blocked subchannels.
virtual const std::vector< unsigned int > & getChannelGaps(unsigned int i_chan) const =0
Return a vector of gap indices for a given channel index.
virtual unsigned int getNumOfAxialCells() const
Return the number of axial cells.
virtual const Real & getPinDiameter() const
Return undeformed Pin diameter.
virtual Node * getPinNode(unsigned int i_pin, unsigned int iz) const =0
Get the pin mesh node for a given pin index and elevation index.
virtual const std::vector< unsigned int > & getPinChannels(unsigned int i_pin) const =0
Return a vector of channel indices for a given Pin index.
Triangular subchannel solver.
static InputParameters validParams()
virtual Real computeAddedHeatPin(unsigned int i_ch, unsigned int iz) const override
Pure virtual: daughters provide different implementations.
virtual void computeh(int iblock) override
Computes Enthalpy per channel for block iblock.
virtual void initializeSolution() override
Function to initialize the solution & geometry fields.
virtual Real getSubChannelPeripheralDuctWidth(unsigned int i_ch) const override
Function that computes the width of the duct cell that the peripheral subchannel i_ch sees.
TriSubChannel1PhaseProblem(const InputParameters &params)
Mesh class for triangular, edge and corner subchannels for hexagonal lattice fuel assemblies.
const Real & getFlatToFlat() const
Return flat to flat [m].
const Real & getWireDiameter() const
Return wire diameter.
void setGapWidth(unsigned int axial_index, unsigned int gap_index, Real gap_width)
Set the gap width for a given axial cell and gap index.
Real getGapWidth(unsigned int axial_index, unsigned int gap_index) const override
Return gap width for a given gap index.
const Real & getDuctToPinGap() const
Return the the gap thickness between the duct and peripheral fuel pins.
const Real & getWireLeadLength() const
Return the wire lead length.
const std::pair< unsigned int, unsigned int > & getSweepFlowChans(unsigned int i_chan) const
const unsigned int & getNumOfRings() const
Return the number of fuel-pin rings, counting the center pin as the first ring.
Definition SCM.h:18
const Real pi