12#include "libmesh/petsc_vector.h"
13#include "libmesh/dense_matrix.h"
14#include "libmesh/dense_vector.h"
36 const PetscScalar * xx;
41 Ctx * cc =
static_cast<Ctx *
>(ctx);
42 LibmeshPetscCallQ(VecGetSize(
x, &size));
45 LibmeshPetscCallQ(VecGetArrayRead(
x, &xx));
46 for (PetscInt i = 0; i < size; i++)
47 solution_seed(i) = xx[i];
49 LibmeshPetscCallQ(VecRestoreArrayRead(
x, &xx));
54 LibmeshPetscCallQ(VecGetArray(
f, &ff));
55 for (
int i = 0; i < size; i++)
56 ff[i] = Wij_residual_vector(i);
58 LibmeshPetscCallQ(VecRestoreArray(
f, &ff));
59 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
66 MooseEnum schemes(
"upwind downwind central_difference exponential",
"central_difference");
67 MooseEnum gravity_direction(
"counter_flow co_flow none",
"counter_flow");
68 MooseEnum monolithic_preconditioners(
"lu fieldsplit_lu fieldsplit_ilu",
"fieldsplit_ilu");
74 params.
addParam<
unsigned int>(
"n_blocks", 1,
"The number of blocks in the axial direction");
75 params.
addParam<Real>(
"P_tol", 1e-6,
"Pressure tolerance");
80 "Maximum number of pressure iterations; zero selects the solver's automatic limit");
81 params.
addParam<Real>(
"T_tol", 1e-6,
"Temperature tolerance");
82 params.
addParam<
int>(
"T_maxit", 100,
"Maximum number of iterations for inner temperature loop");
86 "T_relaxation > 0 & T_relaxation <= 1",
87 "Relaxation factor for temperature updates in the inner thermal-hydraulic iteration");
91 "enthalpy_subcycles > 0",
92 "Number of enthalpy, temperature, and property updates performed per flow solve");
94 "mass_flow_equation_relaxation",
96 "mass_flow_equation_relaxation > 0 & mass_flow_equation_relaxation <= 1",
97 "Equation relaxation factor for mass flow rate in the implicit non-segregated solve");
99 "pressure_equation_relaxation",
101 "pressure_equation_relaxation > 0 & pressure_equation_relaxation <= 1",
102 "Equation relaxation factor for pressure in the implicit non-segregated solve");
104 "crossflow_equation_relaxation",
106 "crossflow_equation_relaxation > 0 & crossflow_equation_relaxation <= 1",
107 "Equation relaxation factor for crossflow in the implicit non-segregated solve");
109 "mass_flow_relaxation",
111 "mass_flow_relaxation > 0 & mass_flow_relaxation <= 1",
112 "Post-solve relaxation factor for mass flow rate updates in the implicit non-segregated "
115 "pressure_relaxation",
117 "pressure_relaxation > 0 & pressure_relaxation <= 1",
118 "Post-solve relaxation factor for pressure updates in the implicit non-segregated solve");
120 "crossflow_relaxation",
122 "crossflow_relaxation > 0 & crossflow_relaxation <= 1",
123 "Post-solve relaxation factor for crossflow updates in the implicit non-segregated solve");
124 params.
addParam<PetscReal>(
"rtol", 1e-6,
"Relative tolerance for ksp solver");
125 params.
addParam<PetscReal>(
"atol", 1e-6,
"Absolute tolerance for ksp solver");
126 params.
addParam<PetscReal>(
"dtol", 1e5,
"Divergence tolerance or ksp solver");
129 params.
addParam<
unsigned int>(
"maxit", 1e4,
"Maximum number of iterations for ksp solver");
131 "monolithic_gmres_restart",
133 "monolithic_gmres_restart > 0",
134 "Restart length of the FGMRES solver of the monolithic flow system. Values of 100 to "
135 "300 speed up solves with tight P_tol and T_tol, where the default stagnates once the "
136 "crossflow damping is small, but can destabilize the outer iteration of flow blockage cases");
138 "monolithic_retry_maxit",
140 "monolithic_retry_maxit > 0",
141 "Largest number of FGMRES iterations of a monolithic linear solve before it is retried "
142 "with a smaller crossflow pseudo-time step. The last retry uses maxit. Only used with "
143 "crossflow_pseudo_time_damping.");
145 "crossflow_pseudo_time_step",
147 "crossflow_pseudo_time_step > 0",
148 "Initial pseudo-time step of the crossflow damping of the monolithic flow system "
149 "[s]. Each gap is damped by its crossflow inertia over a pseudo-time step that grows from "
150 "this value as the cross-momentum residual decreases. Smaller values damp more strongly "
151 "and need more outer iterations; the converged solution does not depend on it.");
153 "crossflow_pseudo_time_damping",
155 "Whether to damp the crossflow of the monolithic flow system with a pseudo-time "
156 "derivative. The damping vanishes at convergence and does not change the converged "
157 "solution. Without it the monolithic system is solved undamped, and a monolithic linear "
158 "solve that does not converge is an error.");
160 "monolithic_preconditioner",
161 monolithic_preconditioners,
162 "Preconditioner of the monolithic flow system: 'lu' factors the monolithic matrix "
163 "exactly with MUMPS; 'fieldsplit_lu' and 'fieldsplit_ilu' use a multiplicative field split "
164 "with one split per field, factored exactly or with ILU(0). 'fieldsplit_ilu' is the "
165 "cheapest per iteration and scales best to large assemblies.");
167 "interpolation_scheme",
169 "Interpolation scheme used to evaluate values at the cell center. Default is "
170 "central_difference");
172 "gravity", gravity_direction,
"Direction of gravity. Default is counter_flow");
174 "implicit",
false,
"Boolean to define the use of explicit or implicit solution.");
176 "staggered_pressure",
178 "Boolean to define the use of staggered or collocated pressure.",
179 "Pressure is a face value and the pressure drop is a cell value, so the collocated "
180 "formulation is always used. This parameter is ignored.");
182 "segregated",
true,
"Boolean to define whether to use a segregated solution.");
184 "verbose_subchannel",
false,
"Boolean to print out information related to subchannel solve.");
185 params.
addRequiredParam<
bool>(
"compute_density",
"Flag that enables the calculation of density");
187 "Flag that enables the calculation of viscosity");
190 "Flag that informs whether we solve the Enthalpy/Temperature equations or not");
193 "The postprocessor (or scalar) that provides the absolute outlet pressure [Pa]. The solved "
194 "pressure variable P is relative to this value.");
195 params.
addRequiredParam<UserObjectName>(
"fp",
"Fluid properties user object name");
197 "Closure computing the friction factor");
200 "Closure computing the turbulent mixing, wire-induced "
201 "mixing and sweep flow mixing parameter where applicable");
203 "pin_HTC_closure",
"Closure computing HTC on fuel pin (required if pin mesh exists).");
204 params.
addParam<UserObjectName>(
"duct_HTC_closure",
205 "Closure computing HTC on duct (required if duct mesh exists).");
207 "full_output",
false,
"Flag that enables the output of the maximum number of variables.");
209 "Thermal diffusion coefficient used in turbulent crossflow.",
210 "Use closure system instead.");
214 "Boolean to define the use of a constant beta or beta correlation (Kim and Chung, 2001)",
215 "Use closure system instead.");
218 "rtol atol dtol maxit",
219 "Solver tolerances and iterations");
221 "mass_flow_equation_relaxation pressure_equation_relaxation crossflow_equation_relaxation "
222 "mass_flow_relaxation pressure_relaxation crossflow_relaxation monolithic_gmres_restart "
223 "monolithic_retry_maxit crossflow_pseudo_time_step crossflow_pseudo_time_damping "
224 "monolithic_preconditioner",
225 "Monolithic solver");
227 params.
addParamNamesToGroup(
"fp friction_closure mixing_closure pin_HTC_closure duct_HTC_closure",
239 _friction_args(0, 1.0, 0.0, 0.0),
241 1.0, 1.0,
std::numeric_limits<unsigned
int>::max(), 0, 0),
242 _P_out(getPostprocessorValue(
"P_out")),
245 _n_blocks(getParam<unsigned
int>(
"n_blocks")),
246 _Wij(declareRestartableData<
libMesh::DenseMatrix<Real>>(
"Wij")),
247 _Wij_old(declareRestartableData<
libMesh::DenseMatrix<Real>>(
"Wij_old")),
249 _kij(_subchannel_mesh.getKij()),
251 _compute_density(getParam<bool>(
"compute_density")),
252 _compute_viscosity(getParam<bool>(
"compute_viscosity")),
253 _compute_power(getParam<bool>(
"compute_power")),
254 _pin_mesh_exist(_subchannel_mesh.pinMeshExist()),
255 _duct_mesh_exist(_subchannel_mesh.ductMeshExist()),
258 _P_tol(getParam<Real>(
"P_tol")),
259 _P_maxit(getParam<
int>(
"P_maxit")),
260 _T_tol(getParam<Real>(
"T_tol")),
261 _T_maxit(getParam<
int>(
"T_maxit")),
262 _T_relaxation(getParam<Real>(
"T_relaxation")),
263 _enthalpy_subcycles(getParam<unsigned
int>(
"enthalpy_subcycles")),
264 _mass_flow_equation_relaxation(getParam<Real>(
"mass_flow_equation_relaxation")),
265 _pressure_equation_relaxation(getParam<Real>(
"pressure_equation_relaxation")),
266 _crossflow_equation_relaxation(getParam<Real>(
"crossflow_equation_relaxation")),
267 _mass_flow_relaxation(getParam<Real>(
"mass_flow_relaxation")),
268 _pressure_relaxation(getParam<Real>(
"pressure_relaxation")),
269 _crossflow_relaxation(getParam<Real>(
"crossflow_relaxation")),
270 _rtol(getParam<PetscReal>(
"rtol")),
271 _atol(getParam<PetscReal>(
"atol")),
272 _dtol(getParam<PetscReal>(
"dtol")),
273 _maxit(getParam<unsigned
int>(
"maxit")),
274 _monolithic_gmres_restart(getParam<unsigned
int>(
"monolithic_gmres_restart")),
275 _monolithic_retry_maxit(getParam<unsigned
int>(
"monolithic_retry_maxit")),
276 _crossflow_pseudo_time_step(getParam<Real>(
"crossflow_pseudo_time_step")),
277 _crossflow_pseudo_time_damping(getParam<bool>(
"crossflow_pseudo_time_damping")),
278 _monolithic_preconditioner(getParam<
MooseEnum>(
"monolithic_preconditioner")),
279 _interpolation_scheme(getParam<
MooseEnum>(
"interpolation_scheme")),
280 _gravity_direction(getParam<
MooseEnum>(
"gravity")),
281 _dir_grav(computeGravityDir(_gravity_direction)),
282 _implicit_bool(getParam<bool>(
"implicit")),
283 _segregated_bool(getParam<bool>(
"segregated")),
284 _verbose_subchannel(getParam<bool>(
"verbose_subchannel")),
285 _friction_closure(nullptr),
286 _mixing_closure(nullptr),
287 _pin_HTC_closure(nullptr),
288 _duct_HTC_closure(nullptr),
290 _duct_heat_flux_soln(nullptr),
291 _Tduct_soln(nullptr),
296 "You are using a deprecated parameter. Please use the mixing_closure system.");
298 paramError(
"pin_HTC_closure",
"required when a pin mesh exists.");
300 paramError(
"duct_HTC_closure",
"required when a duct mesh exists.");
302 paramError(
"segregated",
"A non-segregated solve requires 'implicit = true'.");
304 for (
const auto * relaxation_param : {
"mass_flow_equation_relaxation",
305 "pressure_equation_relaxation",
306 "crossflow_equation_relaxation",
307 "mass_flow_relaxation",
308 "pressure_relaxation",
309 "crossflow_relaxation",
310 "crossflow_pseudo_time_step",
311 "crossflow_pseudo_time_damping",
312 "monolithic_retry_maxit",
313 "monolithic_preconditioner"})
318 "' parameter is only used by the implicit non-segregated solve. Set "
319 "'implicit = true' and 'segregated = false' to use it.");
321 for (
const auto * damping_param : {
"crossflow_pseudo_time_step",
"monolithic_retry_maxit"})
326 "' parameter is only used with 'crossflow_pseudo_time_damping = true'.");
425 ": When implicit number of blocks can't be equal to number of cells. This will "
426 "cause problems with the subchannel interpolation scheme.");
438 if (getParam<bool>(
"full_output"))
468 _fp = &getUserObject<SinglePhaseFluidProperties>(getParam<UserObjectName>(
"fp"));
470 &getUserObject<SCMFrictionClosureBase>(getParam<UserObjectName>(
"friction_closure"));
472 &getUserObject<SCMMixingClosureBase>(getParam<UserObjectName>(
"mixing_closure"));
479 &getUserObject<SCMHTCClosureBase>(getParam<UserObjectName>(
"pin_HTC_closure"));
482 &getUserObject<SCMHTCClosureBase>(getParam<UserObjectName>(
"duct_HTC_closure"));
490 Real viscosity_in = 0.0;
491 Real volumetric_flow_in = 0.0;
492 Real mass_flow_in = 0.0;
496 const Real mdot_in = (*_mdot_soln)(node_in);
497 const Real rho_in = (*_rho_soln)(node_in);
498 viscosity_in += mdot_in * (*_mu_soln)(node_in);
499 volumetric_flow_in += mdot_in / rho_in;
500 mass_flow_in += mdot_in;
504 const Real inlet_mu = viscosity_in / mass_flow_in;
505 _bulk_Re = mass_flow_in * bulk_Dh / (inlet_mu * flow_area);
506 _bulk_V = volumetric_flow_in / flow_area;
512 if (MooseUtils::absoluteFuzzyEqual(
_bulk_Re, 0.0))
513 mooseError(
"The computed bulk Reynolds number is zero.");
515 if (MooseUtils::absoluteFuzzyEqual(
_bulk_V, 0.0))
516 mooseError(
"The computed bulk velocity is zero.");
529 for (
unsigned int iz = 0; iz <
_n_cells + 1; iz++)
530 for (
unsigned int i_pin = 0; i_pin <
_n_pins; i_pin++)
533 const Real Dpin = (*_Dpin_soln)(node);
534 if (std::abs(Dpin) <=
tol)
537 ". You must initialize Dpin to a non-zero value.");
538 if (std::abs(Dpin - pin_diameter) >
tol)
557 PetscErrorCode ierr =
cleanUp();
564 const std::vector<Mat> & terms,
568#if !PETSC_VERSION_LESS_THAN(3, 15, 0)
569 const MatStructure first_pattern = UNKNOWN_NONZERO_PATTERN;
571 const MatStructure first_pattern = DIFFERENT_NONZERO_PATTERN;
573 for (
const auto term : terms)
575 MatAXPY(system, 1.0, term, pattern_set ? SUBSET_NONZERO_PATTERN : first_pattern));
579 LibmeshPetscCall(MatSetOption(system, MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
582 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
592 LibmeshPetscCall(VecDestroy(&
_Wij_vec));
593 LibmeshPetscCall(VecDestroy(&
_prod));
594 LibmeshPetscCall(VecDestroy(&
_prodp));
640 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
666 const auto Pe = Peclet;
667 if (std::abs(Pe) < 1e-6)
668 return 0.5 + Pe / 12.0;
669 const auto e = std::exp(-std::abs(Pe));
670 const auto alpha_pos = 1.0 - 1.0 / std::abs(Pe) + e / (1.0 - e);
671 return Pe > 0 ? alpha_pos : 1.0 - alpha_pos;
675 ": Interpolation scheme should be a string: upwind, downwind, central_difference, "
682 PetscScalar botValue,
686 return alpha * botValue + (1.0 - alpha) * topValue;
692 const unsigned int last_node = (iblock + 1) *
_block_size;
693 const unsigned int first_node = iblock *
_block_size + 1;
696 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
698 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
700 int i =
_n_gaps * (iz - first_node) + i_gap;
701 solution_seed(i) =
_Wij(i_gap, iz);
712 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
714 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
716 _Wij(i_gap, iz) = root(i);
725 const unsigned int last_node = (iblock + 1) *
_block_size;
726 const unsigned int first_node = iblock *
_block_size + 1;
730 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
732 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
737 unsigned int counter = 0;
752 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
754 unsigned int iz_ind = iz - first_node;
755 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
758 unsigned int counter = 0;
762 PetscInt col = i_gap +
_n_gaps * iz_ind;
764 LibmeshPetscCall(MatSetValues(
_mc_sumWij_mat, 1, &row, 1, &col, &value, INSERT_VALUES));
769 LibmeshPetscCall(MatAssemblyBegin(
_mc_sumWij_mat, MAT_FINAL_ASSEMBLY));
770 LibmeshPetscCall(MatAssemblyEnd(
_mc_sumWij_mat, MAT_FINAL_ASSEMBLY));
776 LibmeshPetscCall(VecDuplicate(
_Wij_vec, &loc_Wij));
780 LibmeshPetscCall(populateSolutionChan<SolutionHandle>(
782 LibmeshPetscCall(VecDestroy(&loc_prod));
783 LibmeshPetscCall(VecDestroy(&loc_Wij));
791 const unsigned int last_node = (iblock + 1) *
_block_size;
792 const unsigned int first_node = iblock *
_block_size + 1;
795 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
798 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
802 auto volume = dz * (*_S_flow_soln)(node_in);
803 auto time_term =
_TR * ((*_rho_soln)(node_out)-
_rho_soln->old(node_out)) * volume /
_dt;
805 auto mdot_out = (*_mdot_soln)(node_in) - (*
_SumWij_soln)(node_out)-time_term;
810 " : Calculation of negative mass flow mdot_out = : ",
814 " - Implicit solves are required for recirculating flow.");
822 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
825 auto iz_ind = iz - first_node;
826 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
830 auto volume = dz * (*_S_flow_soln)(node_in);
833 auto time_term =
_TR * ((*_rho_soln)(node_out)-
_rho_soln->old(node_out)) * volume /
_dt;
835 PetscScalar value_vec = -1.0 * time_term;
850 Real
rho, drho_dp_T, drho_dT;
853 Real h, dh_dp_T, dh_dT;
855 const Real drho_dp_h = drho_dp_T - drho_dT * dh_dp_T / dh_dT;
856 const PetscScalar pressure_coefficient = volume /
_dt * drho_dp_h;
857 const PetscInt pressure_col = i_ch +
_n_channels * (iz_ind + 1);
863 &pressure_coefficient,
865 const PetscScalar linearization_rhs = pressure_coefficient * (*_P_soln)(node_out);
871 if (iz == first_node)
873 PetscScalar value_vec = (*_mdot_soln)(node_in);
882 PetscScalar value = -1.0;
890 PetscScalar value = 1.0;
897 PetscScalar value_vec_2 = -1.0 * (*_SumWij_soln)(node_out);
915 LibmeshPetscCall(KSPCreate(PETSC_COMM_SELF, &ksploc));
917 LibmeshPetscCall(KSPGetPC(ksploc, &pc));
918 LibmeshPetscCall(PCSetType(pc, PCJACOBI));
920 LibmeshPetscCall(KSPSetFromOptions(ksploc));
922 LibmeshPetscCall(populateSolutionChan<SolutionHandle>(
925 LibmeshPetscCall(KSPDestroy(&ksploc));
926 LibmeshPetscCall(VecDestroy(&sol));
934 const unsigned int last_node = (iblock + 1) *
_block_size;
935 const unsigned int first_node = iblock *
_block_size + 1;
938 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
942 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
946 auto rho_in = (*_rho_soln)(node_in);
947 auto rho_out = (*_rho_soln)(node_out);
948 auto mu_in = (*_mu_soln)(node_in);
949 auto S = (*_S_flow_soln)(node_in);
950 auto w_perim = (*_w_perim_soln)(node_in);
951 auto time_term =
_TR * ((*_mdot_soln)(node_out)-
_mdot_soln->old(node_out)) * dz /
_dt -
955 Utility::pow<2>((*
_mdot_soln)(node_out)) * (1.0 / S / rho_out - 1.0 / S / rho_in);
956 auto mass_term2 = -2.0 * (*_mdot_soln)(node_out) * (*
_SumWij_soln)(node_out) / S / rho_in;
957 auto crossflow_term = 0.0;
958 auto turbulent_term = 0.0;
959 unsigned int counter = 0;
963 unsigned int ii_ch = chans.first;
964 unsigned int jj_ch = chans.second;
969 auto rho_i = (*_rho_soln)(node_in_i);
970 auto rho_j = (*_rho_soln)(node_in_j);
971 auto Si = (*_S_flow_soln)(node_in_i);
972 auto Sj = (*_S_flow_soln)(node_in_j);
975 if (
_Wij(i_gap, iz) > 0.0)
976 u_star = (*
_mdot_soln)(node_out_i) / Si / rho_i;
978 u_star = (*_mdot_soln)(node_out_j) / Sj / rho_j;
983 turbulent_term +=
_WijPrime(i_gap, iz) * (2 * (*_mdot_soln)(node_out) / rho_in / S -
988 turbulent_term *=
_CT;
992 ki = k_grid[i_ch][iz - 1];
994 ki = k_grid[i_ch][iz];
997 PetscScalar Pe = 0.5;
1001 const auto w_perim_mid =
1003 const auto mdot_mid =
1006 const auto Dh_mid = 4.0 * S_mid / w_perim_mid;
1008 i_ch, std::abs(mdot_mid) / S_mid * Dh_mid / mu_mid, S_mid, w_perim_mid);
1010 Pe = 1.0 / ((ff_mid * dz / Dh_mid + ki) * 0.5) * mdot_mid / std::abs(mdot_mid);
1019 const auto Dh_c = 4.0 * S_c / w_perim_c;
1020 auto Re = std::abs(mdot_c) / S_c * Dh_c / mu_c;
1025 auto friction_term =
1026 (ff * dz / Dh_c + ki) * 0.5 * mdot_c * std::abs(mdot_c) / (S_c * rho_c);
1028 auto DP = (1 / S) * (time_term + mass_term1 + mass_term2 + crossflow_term + turbulent_term +
1029 friction_term + gravity_term);
1049 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1053 auto iz_ind = iz - first_node;
1054 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1061 PetscScalar Pe = 0.5;
1065 auto S_in = (*_S_flow_soln)(node_in);
1066 auto S_out = (*_S_flow_soln)(node_out);
1068 auto w_perim_in = (*_w_perim_soln)(node_in);
1069 auto w_perim_out = (*_w_perim_soln)(node_out);
1073 auto mu_in = (*_mu_soln)(node_in);
1074 auto mu_out = (*_mu_soln)(node_out);
1076 auto Dh_c = 4.0 * S_interp / w_perim_interp;
1078 auto Re = ((std::abs(mdot_loc) / S_interp) * Dh_c / mu_interp);
1086 ki = k_grid[i_ch][iz - 1];
1088 ki = k_grid[i_ch][iz];
1089 Pe = 1.0 / ((ff * dz / Dh_c + ki) * 0.5) * mdot_loc / std::abs(mdot_loc);
1094 auto rho_in = (*_rho_soln)(node_in);
1095 auto rho_out = (*_rho_soln)(node_out);
1099 auto mu_in = (*_mu_soln)(node_in);
1100 auto mu_out = (*_mu_soln)(node_out);
1104 auto S_in = (*_S_flow_soln)(node_in);
1105 auto S_out = (*_S_flow_soln)(node_out);
1109 auto w_perim_in = (*_w_perim_soln)(node_in);
1110 auto w_perim_out = (*_w_perim_soln)(node_out);
1114 auto Dh_c = 4.0 * S_interp / w_perim_interp;
1121 PetscScalar value_tt =
_TR * dz /
_dt;
1122 LibmeshPetscCall(MatSetValues(
1126 PetscInt row_vec_tt = i_ch +
_n_channels * iz_ind;
1132 if (iz == first_node)
1134 PetscScalar value_vec_at = Utility::pow<2>((*
_mdot_soln)(node_in)) / (S_in * rho_in);
1135 PetscInt row_vec_at = i_ch +
_n_channels * iz_ind;
1136 LibmeshPetscCall(VecSetValues(
1142 PetscInt col_at = i_ch +
_n_channels * (iz_ind - 1);
1143 PetscScalar value_at = -1.0 * (*_mdot_soln)(node_in) / (S_in * rho_in);
1144 LibmeshPetscCall(MatSetValues(
1151 PetscScalar value_at = (*_mdot_soln)(node_out) / (S_out * rho_out);
1152 LibmeshPetscCall(MatSetValues(
1156 unsigned int counter = 0;
1157 unsigned int cross_index = iz;
1161 unsigned int ii_ch = chans.first;
1162 unsigned int jj_ch = chans.second;
1177 if (
_Wij(i_gap, cross_index) > 0.0)
1179 if (iz == first_node)
1181 u_star = (*_mdot_soln)(node_in_i) / S_i / rho_i;
1182 PetscScalar value_vec_ct = -1.0 * alpha *
1184 _Wij(i_gap, cross_index) * u_star;
1185 PetscInt row_vec_ct = i_ch +
_n_channels * iz_ind;
1186 LibmeshPetscCall(VecSetValues(
1192 _Wij(i_gap, cross_index) / S_i / rho_i;
1194 PetscInt col_ct = ii_ch +
_n_channels * (iz_ind - 1);
1195 LibmeshPetscCall(MatSetValues(
1198 PetscScalar value_ct = (1.0 - alpha) *
1200 _Wij(i_gap, cross_index) / S_i / rho_i;
1203 LibmeshPetscCall(MatSetValues(
1206 else if (
_Wij(i_gap, cross_index) < 0.0)
1208 if (iz == first_node)
1210 u_star = (*_mdot_soln)(node_in_j) / S_j / rho_j;
1211 PetscScalar value_vec_ct = -1.0 * alpha *
1213 _Wij(i_gap, cross_index) * u_star;
1214 PetscInt row_vec_ct = i_ch +
_n_channels * iz_ind;
1215 LibmeshPetscCall(VecSetValues(
1221 _Wij(i_gap, cross_index) / S_j / rho_j;
1223 PetscInt col_ct = jj_ch +
_n_channels * (iz_ind - 1);
1224 LibmeshPetscCall(MatSetValues(
1227 PetscScalar value_ct = (1.0 - alpha) *
1229 _Wij(i_gap, cross_index) / S_j / rho_j;
1232 LibmeshPetscCall(MatSetValues(
1236 if (iz == first_node)
1238 PetscScalar value_vec_ct = -2.0 * alpha * (*_mdot_soln)(node_in)*
_CT *
1239 _WijPrime(i_gap, cross_index) / (rho_interp * S_interp);
1240 value_vec_ct += alpha * (*_mdot_soln)(node_in_j)*
_CT *
_WijPrime(i_gap, cross_index) /
1242 value_vec_ct += alpha * (*_mdot_soln)(node_in_i)*
_CT *
_WijPrime(i_gap, cross_index) /
1244 PetscInt row_vec_ct = i_ch +
_n_channels * iz_ind;
1250 PetscScalar value_center_ct =
1251 2.0 * alpha *
_CT *
_WijPrime(i_gap, cross_index) / (rho_interp * S_interp);
1253 PetscInt col_ct = i_ch +
_n_channels * (iz_ind - 1);
1254 LibmeshPetscCall(MatSetValues(
1257 PetscScalar value_left_ct =
1258 -1.0 * alpha *
_CT *
_WijPrime(i_gap, cross_index) / (rho_j * S_j);
1261 LibmeshPetscCall(MatSetValues(
1264 PetscScalar value_right_ct =
1265 -1.0 * alpha *
_CT *
_WijPrime(i_gap, cross_index) / (rho_i * S_i);
1268 LibmeshPetscCall(MatSetValues(
1272 PetscScalar value_center_ct =
1273 2.0 * (1.0 - alpha) *
_CT *
_WijPrime(i_gap, cross_index) / (rho_interp * S_interp);
1276 LibmeshPetscCall(MatSetValues(
1279 PetscScalar value_left_ct =
1280 -1.0 * (1.0 - alpha) *
_CT *
_WijPrime(i_gap, cross_index) / (rho_j * S_j);
1283 LibmeshPetscCall(MatSetValues(
1286 PetscScalar value_right_ct =
1287 -1.0 * (1.0 - alpha) *
_CT *
_WijPrime(i_gap, cross_index) / (rho_i * S_i);
1290 LibmeshPetscCall(MatSetValues(
1296 PetscScalar mdot_interp =
1298 auto Re = ((std::abs(mdot_interp) / S_interp) * Dh_c / mu_interp);
1306 ki = k_grid[i_ch][iz - 1];
1308 ki = k_grid[i_ch][iz];
1309 auto coef = (ff * dz / Dh_c + ki) * 0.5 * std::abs(mdot_interp) / (S_interp * rho_interp);
1310 if (iz == first_node)
1312 PetscScalar value_vec = -1.0 * alpha * coef * (*_mdot_soln)(node_in);
1321 PetscScalar value = alpha * coef;
1329 PetscScalar value = (1.0 - alpha) * coef;
1334 PetscScalar value_vec =
_dir_grav * -1.0 *
_g_grav * rho_interp * dz * S_interp;
1336 LibmeshPetscCall(VecSetValues(
_amc_gravity_rhs, 1, &row_vec, &value_vec, ADD_VALUES));
1368 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
1375 LibmeshPetscCall(VecGetArray(ls, &xx));
1376 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1378 auto iz_ind = iz - first_node;
1379 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1386 auto S_in = (*_S_flow_soln)(node_in);
1387 auto S_out = (*_S_flow_soln)(node_out);
1393 auto DP = (1 / S_interp) * xx[iz_ind *
_n_channels + i_ch];
1407 LibmeshPetscCall(VecRestoreArray(ls, &xx));
1408 LibmeshPetscCall(VecDestroy(&ls));
1416 const unsigned int last_node = (iblock + 1) *
_block_size;
1417 const unsigned int first_node = iblock *
_block_size + 1;
1420 for (
unsigned int iz = last_node; iz > first_node - 1; iz--)
1423 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1435 for (
unsigned int iz = last_node; iz > first_node - 1; iz--)
1437 auto iz_ind = iz - first_node;
1439 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1445 auto S_in = (*_S_flow_soln)(node_in);
1446 auto S_out = (*_S_flow_soln)(node_out);
1452 PetscScalar value = -1.0 * S_interp;
1460 if (iz == last_node)
1462 PetscScalar value = -1.0 * (*_P_soln)(node_out)*S_interp;
1470 PetscScalar value = 1.0 * S_interp;
1481 auto dp_out =
_DP(i_ch, iz);
1482 PetscScalar value_v = -1.0 * dp_out * S_interp;
1497 LibmeshPetscCall(KSPCreate(PETSC_COMM_SELF, &ksploc));
1499 LibmeshPetscCall(KSPGetPC(ksploc, &pc));
1500 LibmeshPetscCall(PCSetType(pc, PCJACOBI));
1502 LibmeshPetscCall(KSPSetFromOptions(ksploc));
1505 LibmeshPetscCall(VecGetArray(sol, &xx));
1507 for (
unsigned int iz = last_node; iz > first_node - 1; iz--)
1509 auto iz_ind = iz - first_node;
1510 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1513 PetscScalar value = xx[iz_ind *
_n_channels + i_ch];
1517 LibmeshPetscCall(VecRestoreArray(sol, &xx));
1519 LibmeshPetscCall(KSPDestroy(&ksploc));
1520 LibmeshPetscCall(VecDestroy(&sol));
1528 const unsigned int last_node = (iblock + 1) *
_block_size;
1529 const unsigned int first_node = iblock *
_block_size + 1;
1530 std::vector<Real> residual;
1532 Real residual_norm_sq = 0.0;
1533 Real temperature_norm_sq = 0.0;
1534 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1536 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1539 const Real
T = (*_T_soln)(node);
1541 residual.push_back(T_from_ph -
T);
1542 residual_norm_sq += Utility::pow<2>(residual.back());
1543 temperature_norm_sq += Utility::pow<2>(
T);
1549 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1550 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1557 return std::sqrt(residual_norm_sq) / (std::sqrt(temperature_norm_sq) + 1e-14);
1563 const unsigned int last_node = (iblock + 1) *
_block_size;
1564 const unsigned int first_node = iblock *
_block_size + 1;
1567 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1573 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1575 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1586 const unsigned int last_node = (iblock + 1) *
_block_size;
1587 const unsigned int first_node = iblock *
_block_size + 1;
1590 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1596 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1598 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
1609 const unsigned int last_node = (iblock + 1) *
_block_size;
1610 const unsigned int first_node = iblock *
_block_size + 1;
1615 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1618 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
1621 unsigned int i_ch = chans.first;
1622 unsigned int j_ch = chans.second;
1627 auto rho_i = (*_rho_soln)(node_in_i);
1628 auto rho_j = (*_rho_soln)(node_in_j);
1629 auto Si = (*_S_flow_soln)(node_in_i);
1630 auto Sj = (*_S_flow_soln)(node_in_j);
1634 auto friction_term =
_kij *
_Wij(i_gap, iz) * std::abs(
_Wij(i_gap, iz));
1635 auto DPij = (*_P_soln)(node_in_i) - (*
_P_soln)(node_in_j);
1637 auto rho_star = 0.0;
1638 if (
_Wij(i_gap, iz) > 0.0)
1640 else if (
_Wij(i_gap, iz) < 0.0)
1643 rho_star = (rho_i + rho_j) / 2.0;
1644 auto mass_term_out =
1648 (*_mdot_soln)(node_in_i) / Si / rho_i + (*
_mdot_soln)(node_in_j) / Sj / rho_j;
1649 auto term_out = Sij * rho_star * (Lij / dz) * mass_term_out *
_Wij(i_gap, iz);
1650 auto term_in = Sij * rho_star * (Lij / dz) * mass_term_in *
_Wij(i_gap, iz - 1);
1651 auto inertia_term = term_out - term_in;
1652 auto pressure_term = 2 * Utility::pow<2>(Sij) * DPij * rho_star;
1657 time_term + friction_term + inertia_term - pressure_term;
1675 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1678 auto iz_ind = iz - first_node;
1679 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
1682 unsigned int i_ch = chans.first;
1683 unsigned int j_ch = chans.second;
1690 auto rho_i_in = (*_rho_soln)(node_in_i);
1691 auto rho_i_out = (*_rho_soln)(node_out_i);
1693 auto rho_j_in = (*_rho_soln)(node_in_j);
1694 auto rho_j_out = (*_rho_soln)(node_out_j);
1698 auto S_i_in = (*_S_flow_soln)(node_in_i);
1699 auto S_i_out = (*_S_flow_soln)(node_out_i);
1700 auto S_j_in = (*_S_flow_soln)(node_in_j);
1701 auto S_j_out = (*_S_flow_soln)(node_out_j);
1708 auto rho_star = 0.0;
1709 if (
_Wij(i_gap, iz) > 0.0)
1710 rho_star = rho_i_interp;
1711 else if (
_Wij(i_gap, iz) < 0.0)
1712 rho_star = rho_j_interp;
1714 rho_star = (rho_i_interp + rho_j_interp) / 2.0;
1717 PetscScalar time_factor =
_TR * Lij * Sij * rho_star /
_dt;
1718 PetscInt row_td = i_gap +
_n_gaps * iz_ind;
1719 PetscInt col_td = i_gap +
_n_gaps * iz_ind;
1720 PetscScalar value_td = time_factor;
1721 PetscScalar value_td_rhs = time_factor *
_Wij_old(i_gap, iz);
1731 LibmeshPetscCall(MatSetValues(
1735 const PetscScalar inertia = Lij * Sij * rho_star;
1740 PetscScalar Pe = 0.5;
1742 auto mass_term_out = (*_mdot_soln)(node_out_i) / S_i_out / rho_i_out +
1743 (*
_mdot_soln)(node_out_j) / S_j_out / rho_j_out;
1744 auto mass_term_in = (*_mdot_soln)(node_in_i) / S_i_in / rho_i_in +
1745 (*
_mdot_soln)(node_in_j) / S_j_in / rho_j_in;
1746 auto term_out = Sij * rho_star * (Lij / dz) * mass_term_out / 2.0;
1747 auto term_in = Sij * rho_star * (Lij / dz) * mass_term_in / 2.0;
1748 if (iz == first_node)
1750 PetscInt row_ad = i_gap +
_n_gaps * iz_ind;
1751 PetscScalar value_ad = term_in * alpha *
_Wij(i_gap, iz - 1);
1755 PetscInt col_ad = i_gap +
_n_gaps * iz_ind;
1756 value_ad = -1.0 * term_in * (1.0 - alpha) + term_out * alpha;
1757 LibmeshPetscCall(MatSetValues(
1760 col_ad = i_gap +
_n_gaps * (iz_ind + 1);
1761 value_ad = term_out * (1.0 - alpha);
1762 LibmeshPetscCall(MatSetValues(
1765 else if (iz == last_node)
1767 PetscInt row_ad = i_gap +
_n_gaps * iz_ind;
1768 PetscInt col_ad = i_gap +
_n_gaps * (iz_ind - 1);
1769 PetscScalar value_ad = -1.0 * term_in * alpha;
1770 LibmeshPetscCall(MatSetValues(
1773 col_ad = i_gap +
_n_gaps * iz_ind;
1774 value_ad = -1.0 * term_in * (1.0 - alpha) + term_out * alpha;
1775 LibmeshPetscCall(MatSetValues(
1778 value_ad = -1.0 * term_out * (1.0 - alpha) *
_Wij(i_gap, iz);
1784 PetscInt row_ad = i_gap +
_n_gaps * iz_ind;
1785 PetscInt col_ad = i_gap +
_n_gaps * (iz_ind - 1);
1786 PetscScalar value_ad = -1.0 * term_in * alpha;
1787 LibmeshPetscCall(MatSetValues(
1790 col_ad = i_gap +
_n_gaps * iz_ind;
1791 value_ad = -1.0 * term_in * (1.0 - alpha) + term_out * alpha;
1792 LibmeshPetscCall(MatSetValues(
1795 col_ad = i_gap +
_n_gaps * (iz_ind + 1);
1796 value_ad = term_out * (1.0 - alpha);
1797 LibmeshPetscCall(MatSetValues(
1801 PetscInt row_ff = i_gap +
_n_gaps * iz_ind;
1802 PetscInt col_ff = i_gap +
_n_gaps * iz_ind;
1803 PetscScalar value_ff =
_kij * std::abs(
_Wij(i_gap, iz)) / 2.0;
1804 LibmeshPetscCall(MatSetValues(
1810 PetscScalar pressure_factor = Utility::pow<2>(Sij) * rho_star;
1811 PetscInt row_pf = i_gap +
_n_gaps * iz_ind;
1813 PetscScalar value_pf = -1.0 * alpha * pressure_factor;
1817 value_pf = alpha * pressure_factor;
1821 if (iz == last_node)
1823 PetscInt row_pf = i_gap +
_n_gaps * iz_ind;
1824 PetscScalar value_pf = (1.0 - alpha) * pressure_factor * (*
_P_soln)(node_out_i);
1827 value_pf = -1.0 * (1.0 - alpha) * pressure_factor * (*
_P_soln)(node_out_j);
1833 row_pf = i_gap +
_n_gaps * iz_ind;
1835 value_pf = -1.0 * (1.0 - alpha) * pressure_factor;
1839 value_pf = (1.0 - alpha) * pressure_factor;
1877 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
1885 LibmeshPetscCall(VecAXPY(sol_holder_W, 1.0, sol_holder_P));
1887 LibmeshPetscCall(VecGetArray(sol_holder_W, &xx));
1888 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1890 auto iz_ind = iz - first_node;
1891 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
1896 LibmeshPetscCall(VecRestoreArray(sol_holder_W, &xx));
1897 LibmeshPetscCall(VecDestroy(&sol_holder_P));
1898 LibmeshPetscCall(VecDestroy(&sol_holder_W));
1906 const unsigned int last_node = (iblock + 1) *
_block_size;
1907 const unsigned int first_node = iblock *
_block_size + 1;
1909 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
1912 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
1915 unsigned int i_ch = chans.first;
1916 unsigned int j_ch = chans.second;
1921 auto Si_in = (*_S_flow_soln)(node_in_i);
1922 auto Sj_in = (*_S_flow_soln)(node_in_j);
1923 auto Si_out = (*_S_flow_soln)(node_out_i);
1924 auto Sj_out = (*_S_flow_soln)(node_out_j);
1926 auto Sij = dz * gap;
1932 0.5 * (((*_mdot_soln)(node_in_i) + (*
_mdot_soln)(node_in_j)) / (Si_in + Sj_in) +
1938 _WijPrime(i_gap, iz) = beta * avg_massflux * Sij;
1942 auto iz_ind = iz - first_node;
1943 PetscScalar base_value = beta * 0.5 * Sij;
1946 if (iz == first_node)
1948 PetscScalar value_tl = -1.0 * base_value / (Si_in + Sj_in) *
1950 PetscInt row = i_gap +
_n_gaps * iz_ind;
1956 PetscScalar value_tl = base_value / (Si_in + Sj_in);
1957 PetscInt row = i_gap +
_n_gaps * iz_ind;
1959 PetscInt col_ich = i_ch +
_n_channels * (iz_ind - 1);
1960 LibmeshPetscCall(MatSetValues(
1963 PetscInt col_jch = j_ch +
_n_channels * (iz_ind - 1);
1964 LibmeshPetscCall(MatSetValues(
1969 PetscScalar value_bl = base_value / (Si_out + Sj_out);
1970 PetscInt row = i_gap +
_n_gaps * iz_ind;
1973 LibmeshPetscCall(MatSetValues(
1977 LibmeshPetscCall(MatSetValues(
1992 LibmeshPetscCall(VecDuplicate(
_Wij_vec, &loc_Wij));
1993 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
1999 LibmeshPetscCall(VecDestroy(&loc_prod));
2000 LibmeshPetscCall(VecDestroy(&loc_Wij));
2008 if (!std::isfinite(beta) || beta < 0.0)
2010 ": Mixing closure returned invalid beta = ",
2016 ". Beta must be finite and non-negative.");
2025 if (!std::isfinite(beta) || beta < 0.0)
2027 ": Mixing closure returned invalid sweep-flow coefficient = ",
2033 ". sweep-flow coefficient must be finite and non-negative.");
2041 const unsigned int last_node = (iblock + 1) *
_block_size;
2042 const unsigned int first_node = iblock *
_block_size + 1;
2046 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
2048 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
2050 _Wij(i_gap, iz) = solution(i);
2071 for (
unsigned int i_gap = 0; i_gap <
_n_gaps; i_gap++)
2077 return Wij_residual_vector;
2092 LibmeshPetscCall(SNESCreate(PETSC_COMM_SELF, &snes));
2093 LibmeshPetscCall(VecCreate(PETSC_COMM_SELF, &
x));
2095 LibmeshPetscCall(VecSetFromOptions(
x));
2096 LibmeshPetscCall(VecDuplicate(
x, &r));
2098#if PETSC_VERSION_LESS_THAN(3, 13, 0)
2099 LibmeshPetscCall(PetscOptionsSetValue(PETSC_NULL,
"-snes_mf", PETSC_NULL));
2101 LibmeshPetscCall(SNESSetUseMatrixFree(snes, PETSC_FALSE, PETSC_TRUE));
2104 ctx.iblock = iblock;
2106 LibmeshPetscCall(SNESSetFunction(snes, r,
formFunction, &ctx));
2107 LibmeshPetscCall(SNESGetKSP(snes, &ksp));
2108 LibmeshPetscCall(KSPGetPC(ksp, &pc));
2109 LibmeshPetscCall(PCSetType(pc, PCNONE));
2111 LibmeshPetscCall(SNESSetFromOptions(snes));
2112 LibmeshPetscCall(VecGetArray(
x, &xx));
2115 xx[i] = solution(i);
2117 LibmeshPetscCall(VecRestoreArray(
x, &xx));
2119 LibmeshPetscCall(SNESSolve(snes, NULL,
x));
2123 SNESConvergedReason reason;
2124 LibmeshPetscCall(SNESGetConvergedReason(snes, &reason));
2127 PetscInt iterations;
2128 PetscReal residual_norm;
2129 LibmeshPetscCall(SNESGetIterationNumber(snes, &iterations));
2130 LibmeshPetscCall(SNESGetFunctionNorm(snes, &residual_norm));
2131 mooseWarning(
"Crossflow nonlinear solve did not converge: ",
2132 SNESConvergedReasons[reason],
2134 static_cast<int>(reason),
2137 " iterations; residual norm = ",
2139 ". The crossflow of this iteration is not updated.");
2141 LibmeshPetscCall(VecGetArray(
x, &xx));
2145 LibmeshPetscCall(VecRestoreArray(
x, &xx));
2146 LibmeshPetscCall(VecDestroy(&
x));
2147 LibmeshPetscCall(VecDestroy(&r));
2148 LibmeshPetscCall(SNESDestroy(&snes));
2149 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
2154 Mat
A, Vec rhs,
unsigned int first_node,
unsigned int last_node,
const char * ksp_prefix)
2160 LibmeshPetscCall(VecDuplicate(rhs, &
x));
2165 LibmeshPetscCall(KSPCreate(PETSC_COMM_SELF, &ksp));
2166 LibmeshPetscCall(KSPSetOperators(ksp,
A,
A));
2167 LibmeshPetscCall(KSPGetPC(ksp, &pc));
2168 LibmeshPetscCall(PCSetType(pc, PCJACOBI));
2170 if (ksp_prefix && *ksp_prefix)
2171 LibmeshPetscCall(KSPSetOptionsPrefix(ksp, ksp_prefix));
2172 LibmeshPetscCall(KSPSetFromOptions(ksp));
2176 LibmeshPetscCall(KSPGMRESSetPreAllocateVectors(ksp));
2179 LibmeshPetscCall(KSPSolve(ksp, rhs,
x));
2180 KSPConvergedReason reason;
2181 LibmeshPetscCall(KSPGetConvergedReason(ksp, &reason));
2184 PetscInt iterations;
2185 PetscReal residual_norm;
2186 LibmeshPetscCall(KSPGetIterationNumber(ksp, &iterations));
2187 LibmeshPetscCall(KSPGetResidualNorm(ksp, &residual_norm));
2189 ": enthalpy linear solve failed: ",
2190 KSPConvergedReasons[reason],
2192 static_cast<int>(reason),
2195 " iterations; residual norm = ",
2201 PetscScalar * xx =
nullptr;
2202 LibmeshPetscCall(VecGetArray(
x, &xx));
2203 for (
unsigned int iz = first_node; iz <= last_node; ++iz)
2205 const unsigned int iz_ind = iz - first_node;
2206 for (
unsigned int i_ch = 0; i_ch <
_n_channels; ++i_ch)
2209 const PetscScalar h_out = xx[iz_ind *
_n_channels + i_ch];
2212 name(),
" : Calculation of negative Enthalpy h_out = ", h_out,
" Axial Level = ", iz);
2213 _h_soln->set(node_out, h_out);
2216 LibmeshPetscCall(VecRestoreArray(
x, &xx));
2219 LibmeshPetscCall(KSPDestroy(&ksp));
2220 LibmeshPetscCall(VecDestroy(&
x));
2222 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
2228 mooseAssert(iz > 0,
"Trapezoidal rule requires starting at index 1 at least");
2239 auto heat_rate_in = (*_duct_heat_flux_soln)(node_in_duct);
2240 auto heat_rate_out = (*_duct_heat_flux_soln)(node_out_duct);
2242 return 0.5 * (heat_rate_in + heat_rate_out) * dz * width;
2259 PetscScalar inv_dtau)
2267 LibmeshPetscCall(VecScale(damping, inv_dtau));
2269 LibmeshPetscCall(MatDiagonalSet(M_ww, damping, ADD_VALUES));
2272 LibmeshPetscCall(VecPointwiseMult(damping, damping, Wij_iter));
2273 LibmeshPetscCall(VecAXPY(b_w, 1.0, damping));
2274 LibmeshPetscCall(VecDestroy(&damping));
2275 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
2280 Mat M_ww, Mat M_wp, Vec b_w, Vec Wij_iter,
int iblock, PetscScalar & inv_dtau)
2283 const unsigned int first_node = iblock *
_block_size + 1;
2284 const unsigned int last_node = (iblock + 1) *
_block_size;
2287 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
2291 LibmeshPetscCall(MatMult(M_ww, Wij_iter, residual));
2292 LibmeshPetscCall(MatMultAdd(M_wp,
_prodp, residual, residual));
2293 LibmeshPetscCall(VecAXPY(residual, -1.0, b_w));
2294 PetscReal residual_norm;
2295 LibmeshPetscCall(VecNorm(residual, NORM_2, &residual_norm));
2302 residual_ref = std::max(residual_ref, residual_norm);
2303 const Real residual_ratio = residual_ref > 0.0 ? residual_norm / residual_ref : 1.0;
2311 inv_dtau = std::min(
2315 _console <<
"Crossflow residual ratio: " + std::to_string(residual_ratio) << std::endl;
2316 _console <<
"Crossflow pseudo-time step: " + std::to_string(1.0 / inv_dtau) << std::endl;
2321 LibmeshPetscCall(VecDestroy(&residual));
2322 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
2330 auto V = [&](
const std::string & s)
2336 auto DupMatAssembled = [&](Mat src, Mat * dst)
2340 LibmeshPetscCall(MatDuplicate(src, MAT_COPY_VALUES, dst));
2341 LibmeshPetscCall(MatAssemblyBegin(*dst, MAT_FINAL_ASSEMBLY));
2342 LibmeshPetscCall(MatAssemblyEnd(*dst, MAT_FINAL_ASSEMBLY));
2348 auto DupVecCopy = [&](Vec src, Vec * dst)
2350 LibmeshPetscCall(VecDuplicate(src, dst));
2351 LibmeshPetscCall(VecCopy(src, *dst));
2354 const PetscInt Q = 3;
2357 auto Idx = [&](PetscInt r, PetscInt
c) {
return Q * r +
c; };
2360 std::vector<Mat> mat_array(Q * Q, NULL);
2361 std::vector<Vec> vec_array(Q, NULL);
2364 auto AssembleEquation = [&](PetscInt
f,
2372 DupMatAssembled(
A0, &mat_array[Idx(
f, 0)]);
2373 DupMatAssembled(
A1, &mat_array[Idx(
f, 1)]);
2374 DupMatAssembled(
A2, &mat_array[Idx(
f, 2)]);
2375 DupVecCopy(rhs, &vec_array[
f]);
2377 LibmeshPetscCall(VecAXPY(vec_array[
f], 1.0, rhs_add));
2378 V(std::string(label) +
" system assembled");
2397 auto relaxEquation =
2398 [&](Mat diagonal_block, Vec rhs, Vec work,
const Real relaxation,
auto && populate)
2400 if (relaxation == 1.0)
2403 Vec diagonal =
nullptr;
2404 LibmeshPetscCall(VecDuplicate(rhs, &diagonal));
2407 LibmeshPetscCall(MatGetDiagonal(diagonal_block, diagonal));
2408 LibmeshPetscCall(VecScale(diagonal, 1.0 / relaxation));
2409 LibmeshPetscCall(MatDiagonalSet(diagonal_block, diagonal, INSERT_VALUES));
2412 LibmeshPetscCall(populate(work));
2415 LibmeshPetscCall(VecScale(diagonal, 1.0 - relaxation));
2416 LibmeshPetscCall(VecPointwiseMult(work, work, diagonal));
2417 LibmeshPetscCall(VecAXPY(rhs, 1.0, work));
2419 LibmeshPetscCall(VecDestroy(&diagonal));
2423 const unsigned int first_node = iblock *
_block_size + 1;
2424 const unsigned int last_node = (iblock + 1) *
_block_size;
2434 V(
"Starting nested system.");
2465 PetscScalar inv_dtau = 0.0;
2472 mat_array[Idx(2, 2)], mat_array[Idx(2, 1)], vec_array[2], Wij_iter, iblock, inv_dtau));
2478 relaxEquation(mat_array[Idx(0, 0)],
2484 return populateVectorFromHandle<SolutionHandle>(
2489 relaxEquation(mat_array[Idx(1, 1)],
2497 return populateVectorFromHandle<SolutionHandle>(
2502 relaxEquation(mat_array[Idx(2, 2)],
2508 return populateVectorFromDense<libMesh::DenseMatrix<Real>>(
2512 V(
"Linear solver relaxed");
2520 std::vector<IS> field_is(Q);
2521 PetscInt n_total = 0;
2522 for (
const auto f : make_range(Q))
2525 LibmeshPetscCall(VecGetSize(vec_array[
f], &n));
2526 LibmeshPetscCall(ISCreateStride(PETSC_COMM_SELF, n, n_total, 1, &field_is[
f]));
2527 LibmeshPetscCall(ISToGeneral(field_is[
f]));
2531 LibmeshPetscCall(MatCreateNest(
2532 PETSC_COMM_SELF, Q, field_is.data(), Q, field_is.data(), mat_array.data(), &A_nest));
2533 V(
"Nested system created");
2537 LibmeshPetscCall(KSPCreate(PETSC_COMM_SELF, &ksp));
2538 LibmeshPetscCall(KSPSetOptionsPrefix(ksp,
"scm_monolithic_"));
2539 LibmeshPetscCall(KSPSetType(ksp, KSPFGMRES));
2541 LibmeshPetscCall(KSPSetOperators(ksp, A_nest, A_nest));
2542 LibmeshPetscCall(KSPGetPC(ksp, &pc));
2549 LibmeshPetscCall(PCSetType(pc, PCLU));
2550 LibmeshPetscCall(PCFactorSetMatSolverType(pc, MATSOLVERMUMPS));
2555 LibmeshPetscCall(PCSetType(pc, PCFIELDSPLIT));
2556 for (
const auto f : make_range(Q))
2557 LibmeshPetscCall(PCFieldSplitSetIS(pc, NULL, field_is[
f]));
2559 LibmeshPetscCall(KSPSetFromOptions(ksp));
2563 LibmeshPetscCall(KSPSetUp(ksp));
2566 LibmeshPetscCall(PCFieldSplitGetSubKSP(pc, &n_splits, &sub_ksp));
2567 for (
const auto f : make_range(n_splits))
2570 LibmeshPetscCall(KSPGetPC(sub_ksp[
f], &sub_pc));
2571 LibmeshPetscCall(PCSetType(sub_pc, PCLU));
2573 LibmeshPetscCall(PetscFree(sub_ksp));
2575 V(
"Linear solver assembled");
2582 LibmeshPetscCall(VecDuplicate(b_vec, &x_vec));
2583 for (
const auto f : make_range(Q))
2584 LibmeshPetscCall(VecISCopy(b_vec, field_is[
f], SCATTER_FORWARD, vec_array[
f]));
2588 LibmeshPetscCall(KSPSetInitialGuessNonzero(ksp, PETSC_TRUE));
2589 LibmeshPetscCall(KSPConvergedDefaultSetUIRNorm(ksp));
2590 PetscReal rtol, atol, dtol;
2592 LibmeshPetscCall(KSPGetTolerances(ksp, &rtol, &atol, &dtol, &maxit));
2609 auto setInitialGuess = [&]()
2611 std::vector<Vec> x_sub(Q);
2612 for (
const auto f : make_range(Q))
2613 LibmeshPetscCall(VecGetSubVector(x_vec, field_is[
f], &x_sub[
f]));
2614 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
2616 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
2618 LibmeshPetscCall(VecCopy(Wij_iter, x_sub[2]));
2619 for (
const auto f : make_range(Q))
2620 LibmeshPetscCall(VecRestoreSubVector(x_vec, field_is[
f], &x_sub[
f]));
2622 KSPConvergedReason reason;
2625 for (
const auto attempt : make_range(max_retries + 1))
2627 const bool last_attempt = attempt == max_retries;
2628 LibmeshPetscCall(KSPSetTolerances(
2629 ksp, rtol, atol, dtol, last_attempt ? maxit : std::min(maxit, retry_maxit)));
2631 LibmeshPetscCall(KSPSolve(ksp, b_vec, x_vec));
2632 LibmeshPetscCall(KSPGetConvergedReason(ksp, &reason));
2633 if (reason >= 0 || last_attempt)
2640 inv_dtau += delta_inv_dtau;
2643 V(
"Monolithic linear solve did not converge; retrying with nominal crossflow pseudo-time step "
2644 "(before crossflow equation relaxation): " +
2645 std::to_string(1.0 / inv_dtau));
2648 LibmeshPetscCall(VecGetSubVector(b_vec, field_is[2], &b_w));
2650 LibmeshPetscCall(VecRestoreSubVector(b_vec, field_is[2], &b_w));
2655 LibmeshPetscCall(KSPSetOperators(ksp, A_nest, A_nest));
2657 LibmeshPetscCall(VecDestroy(&Wij_iter));
2660 PetscInt iterations;
2661 PetscReal residual_norm;
2662 LibmeshPetscCall(KSPGetIterationNumber(ksp, &iterations));
2663 LibmeshPetscCall(KSPGetResidualNorm(ksp, &residual_norm));
2665 ": monolithic linear solve failed: ",
2666 KSPConvergedReasons[reason],
2668 static_cast<int>(reason),
2671 " iterations; residual norm = ",
2677 LibmeshPetscCall(VecDestroy(&b_vec));
2678 LibmeshPetscCall(MatDestroy(&A_nest));
2679 LibmeshPetscCall(KSPDestroy(&ksp));
2680 for (PetscInt i = 0; i < Q * Q; i++)
2681 LibmeshPetscCall(MatDestroy(&mat_array[i]));
2682 for (PetscInt i = 0; i < Q; i++)
2683 LibmeshPetscCall(VecDestroy(&vec_array[i]));
2684 V(
"Solver elements destroyed");
2687 Vec sol_mdot, sol_p, sol_Wij;
2688 V(
"Vectors to hold solution created");
2690 LibmeshPetscCall(VecISCopy(x_vec, field_is[0], SCATTER_REVERSE, sol_mdot));
2692 LibmeshPetscCall(VecISCopy(x_vec, field_is[1], SCATTER_REVERSE, sol_p));
2694 LibmeshPetscCall(VecISCopy(x_vec, field_is[2], SCATTER_REVERSE, sol_Wij));
2695 V(
"Solution from monolithic solver copied to solution vectors");
2698 auto relaxSolution = [&](Vec solution, Vec old_solution,
const Real relaxation)
2700 LibmeshPetscCall(VecScale(solution, relaxation));
2701 LibmeshPetscCall(VecAXPY(solution, 1.0 - relaxation, old_solution));
2703 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
2705 LibmeshPetscCall(populateVectorFromHandle<SolutionHandle>(
2710 Vec pressure_residual;
2711 LibmeshPetscCall(VecDuplicate(sol_p, &pressure_residual));
2712 LibmeshPetscCall(VecCopy(sol_p, pressure_residual));
2713 LibmeshPetscCall(VecAXPY(pressure_residual, -1.0,
_prodp));
2715 const PetscScalar * residual_array;
2716 const PetscScalar * old_pressure_array;
2717 PetscInt pressure_size;
2718 LibmeshPetscCall(VecGetSize(pressure_residual, &pressure_size));
2719 LibmeshPetscCall(VecGetArrayRead(pressure_residual, &residual_array));
2720 LibmeshPetscCall(VecGetArrayRead(
_prodp, &old_pressure_array));
2721 Real residual_norm_sq = 0.0;
2722 Real pressure_norm_sq = 0.0;
2723 for (PetscInt i = 0; i < pressure_size; ++i)
2725 residual_norm_sq += Utility::pow<2>(residual_array[i]);
2726 pressure_norm_sq += Utility::pow<2>(old_pressure_array[i] +
_P_out);
2728 LibmeshPetscCall(VecRestoreArrayRead(pressure_residual, &residual_array));
2729 LibmeshPetscCall(VecRestoreArrayRead(
_prodp, &old_pressure_array));
2730 LibmeshPetscCall(VecDestroy(&pressure_residual));
2733 std::sqrt(residual_norm_sq) / (std::sqrt(pressure_norm_sq) + 1e-14));
2742 LibmeshPetscCall(populateSolutionChan<SolutionHandle>(
2747 PetscScalar * sol_p_array;
2748 LibmeshPetscCall(VecGetArray(sol_p, &sol_p_array));
2749 for (
unsigned int iz = last_node; iz > first_node - 1; iz--)
2751 const auto iz_ind = iz - first_node;
2752 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
2755 PetscScalar value = sol_p_array[iz_ind *
_n_channels + i_ch];
2759 LibmeshPetscCall(VecRestoreArray(sol_p, &sol_p_array));
2767 LibmeshPetscCall(populateSolutionChan<SolutionHandle>(
2770 V(
"Solutions assigned to MOOSE variables.");
2773 LibmeshPetscCall(VecDestroy(&x_vec));
2774 for (
auto & is : field_is)
2775 LibmeshPetscCall(ISDestroy(&is));
2776 LibmeshPetscCall(VecDestroy(&sol_mdot));
2777 LibmeshPetscCall(VecDestroy(&sol_p));
2778 LibmeshPetscCall(VecDestroy(&sol_Wij));
2779 V(
"Solutions destroyed.");
2781 PetscFunctionReturn(LIBMESH_PETSC_SUCCESS);
2787 _console <<
"Executing subchannel solver\n";
2798 for (
const auto * ti :
transient->getTimeIntegrators())
2800 mooseWarning(
"The subchannel solver always uses implicit (backward) Euler time "
2801 "integration; the requested '",
2803 "' time integrator is ignored.");
2812 auto V = [&](
const std::string & s)
2818 const unsigned int first_node,
2819 const unsigned int last_node)
2821 std::vector<Real>
values;
2823 for (
unsigned int iz = first_node; iz <= last_node; ++iz)
2824 for (
unsigned int i_ch = 0; i_ch <
_n_channels; ++i_ch)
2829 const std::vector<Real> & old_values,
2830 const unsigned int first_node,
2831 const unsigned int last_node,
2832 const Real reference_offset)
2834 Real difference_norm_sq = 0.0;
2835 Real reference_norm_sq = 0.0;
2837 for (
unsigned int iz = first_node; iz <= last_node; ++iz)
2838 for (
unsigned int i_ch = 0; i_ch <
_n_channels; ++i_ch)
2841 difference_norm_sq += Utility::pow<2>(value - old_values[i]);
2842 reference_norm_sq += Utility::pow<2>(old_values[i] + reference_offset);
2845 return std::sqrt(difference_norm_sq) / (std::sqrt(reference_norm_sq) + 1e-14);
2847 V(
"Solution initialized");
2849 unsigned int P_it = 0;
2850 unsigned int P_it_max;
2851 bool temperature_converged =
true;
2864 while ((P_error >
_P_tol && P_it < P_it_max))
2867 temperature_converged =
true;
2869 _console <<
"Solving Outer Iteration : " << P_it << std::endl;
2871 for (
unsigned int iblock = 0; iblock <
_n_blocks; iblock++)
2875 Real T_block_error = 1.0;
2877 _console <<
"Solving Block: " << iblock <<
" From first level: " << first_level
2878 <<
" to last level: " << last_level << std::endl;
2890 V(
"Done with main solve.");
2898 if (T_block_error <= _T_tol || T_it >=
_T_maxit)
2901 V(
"Enthalpy subcycle: " + std::to_string(enthalpy_subcycle + 1));
2903 const auto T_old = saveValues(*
_T_soln, first_level, last_level);
2908 T_block_error = 0.0;
2916 V(
"Done with thermal solve.");
2919 V(
"Start updating thermophysical properties.");
2924 V(
"Done updating thermophysical properties.");
2929 _aux->solution().close();
2933 relativeChange(*
_T_soln, T_old, first_level, last_level, 0.0);
2934 _console <<
"T_block_error: " << T_block_error << std::endl;
2940 const bool block_converged = T_block_error <=
_T_tol;
2941 temperature_converged &= block_converged;
2942 if (!block_converged)
2944 _console <<
"Reached maximum number of temperature iterations for block: " << iblock
2951 _console <<
"P_error :" << P_error << std::endl;
2952 V(
"Iteration: " + std::to_string(P_it));
2953 V(
"Maximum iterations: " + std::to_string(P_it_max));
2957 const bool pressure_converged = P_error <=
_P_tol;
2958 if (!pressure_converged)
2960 _console <<
"Reached maximum number of axial pressure iterations" << std::endl;
2962 _converged = pressure_converged && temperature_converged;
2965 _console <<
"Finished executing subchannel solver\n";
2968 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
2978 for (
unsigned int iz = 0; iz <
_n_cells + 1; ++iz)
2980 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
2983 auto mu = (*_mu_soln)(node);
2984 auto S = (*_S_flow_soln)(node);
2985 auto w_perim = (*_w_perim_soln)(node);
2986 auto Dh_i = 4.0 * S / w_perim;
2990 auto Pr = (*_mu_soln)(node)*cp / k;
3010 _console <<
"Commencing calculation of Pin surface temperature \n";
3011 for (
unsigned int i_pin = 0; i_pin <
_n_pins; i_pin++)
3013 for (
unsigned int iz = 0; iz <
_n_cells + 1; ++iz)
3021 auto mu = (*_mu_soln)(node);
3022 auto S = (*_S_flow_soln)(node);
3023 auto w_perim = (*_w_perim_soln)(node);
3024 auto Dh_i = 4.0 * S / w_perim;
3028 auto Pr = (*_mu_soln)(node)*cp / k;
3037 (*_q_prime_soln)(pin_node) / ((*
_Dpin_soln)(pin_node)*M_PI * hw) + (*_T_soln)(node);
3042 mooseError(
"Pin was not found for pin index: " + std::to_string(i_pin));
3050 _console <<
"Commencing calculation of duct surface temperature " << std::endl;
3052 for (Node * dn : duct_nodes)
3055 auto mu = (*_mu_soln)(node_chan);
3056 auto S = (*_S_flow_soln)(node_chan);
3057 auto w_perim = (*_w_perim_soln)(node_chan);
3058 auto Dh_i = 4.0 * S / w_perim;
3059 auto Re = ((std::abs((*
_mdot_soln)(node_chan)) / S) * Dh_i /
mu);
3062 auto Pr = (*_mu_soln)(node_chan)*cp / k;
3079 auto T_chan = (*_duct_heat_flux_soln)(dn) / hw + (*
_T_soln)(node_chan);
3083 _aux->solution().close();
3091 Real power_in = 0.0;
3092 Real power_out = 0.0;
3093 Real mass_flow_in = 0.0;
3094 Real mass_flow_out = 0.0;
3095 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
3099 const Real mdot_in = (*_mdot_soln)(node_in);
3100 power_in += mdot_in * (*_h_soln)(node_in);
3101 power_out += (*_mdot_soln)(node_out) * (*
_h_soln)(node_out);
3102 mass_flow_in += mdot_in;
3103 mass_flow_out += (*_mdot_soln)(node_out);
3105 auto h_bulk_out = power_out / mass_flow_out;
3106 auto T_bulk_out =
_fp->T_from_p_h(
_P_out, h_bulk_out);
3111 _console <<
" ======================================= " << std::endl;
3112 _console <<
" ======== Subchannel Print Outs ======== " << std::endl;
3113 _console <<
" ======================================= " << std::endl;
3116 _console <<
"Assembly hydraulic diameter :" << bulk_Dh <<
" m" << std::endl;
3118 _console <<
"Bulk coolant temperature at outlet :" << T_bulk_out <<
" K" << std::endl;
3119 _console <<
"Power added to coolant is : " << power_out - power_in <<
" Watt" << std::endl;
3120 _console <<
"Mass flow rate in is : " << mass_flow_in <<
" kg/sec" << std::endl;
3121 _console <<
"Mass balance is : " << mass_flow_out - mass_flow_in <<
" kg/sec" << std::endl;
3122 _console <<
"User defined outlet pressure is : " <<
_P_out <<
" Pa" << std::endl;
3123 _console <<
" ======================================= " << std::endl;
3126 if (MooseUtils::absoluteFuzzyLessEqual((power_out - power_in), -1.0))
3128 "Energy conservation equation might not be solved correctly, Power added to coolant: " +
3129 std::to_string(power_out - power_in) +
" Watt ");
Real f(Real x)
Test function for Brents method.
const std::vector< double > x
std::array< Real, 2 > values
PetscErrorCode formFunction(SNES, Vec x, Vec f, void *ctx)
void ErrorVector unsigned int
const ConsoleStream _console
static InputParameters validParams()
std::shared_ptr< AuxiliarySystem > _aux
virtual Real & dt() const
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 void transient(bool trans)
virtual bool isTransient() const override
void initialSetup() override
bool isRestarting() const
Executioner * getExecutioner() const
bool isRecovering() const
const std::string & name() const
void paramError(const std::string ¶m, Args... args) const
void mooseError(Args &&... args) const
void mooseWarning(Args &&... args) const
bool isParamValid(const std::string &name) const
static InputParameters validParams()
virtual Real computeFrictionFactor(const FrictionStruct &friction_info) const =0
Computes the friction factor for the local conditions.
Real computeHTC(const FrictionStruct &friction_info, const NusseltStruct &nusselt_info, const Real conduction_k) const
Computes the convective heat transfer coefficient for the local conditions.
virtual void computeBulkMixingParameters() const
Precomputes the mixing coefficients that depend only on the bulk flow.
virtual Real computeSweepFlowMixingParameter(const unsigned int i_gap, const unsigned int iz) const
Computes the wire-wrap sweep-flow coefficient for peripheral gaps.
virtual void computeBlockMixingParameters(const unsigned int, const unsigned int) const
Precomputes the mixing coefficients that depend on the flow solution of the axial levels first_node t...
virtual Real getCT() const
Return the Turbulent modeling parameter.
virtual Real computeMixingParameter(const unsigned int i_gap, const unsigned int iz) const =0
Computes the turbulent mixing coefficient for the local conditions around gap(i_gap) and axial level(...
Provide a simple RAII interface for linear lagrange solution variables.
Base class for the 1-phase steady-state/transient subchannel solver.
libMesh::DenseMatrix< Real > _DP
void computeP(int iblock)
Computes Pressure per channel for block iblock.
Mat _hc_sys_h_mat
System matrices.
const Real & _mass_flow_equation_relaxation
Equation relaxation factor for mass flow rate in the monolithic solve.
Vec _mc_axial_convection_rhs
const Real & _pressure_equation_relaxation
Equation relaxation factor for pressure in the monolithic solve.
PetscErrorCode createPetscVector(Vec &v, PetscInt n)
Petsc Functions.
const PetscInt _monolithic_retry_maxit
Largest number of FGMRES iterations of a monolithic solve before it is retried with more damping.
virtual void syncSolutions(Direction direction) override
const bool _segregated_bool
Segregated solve.
PetscScalar computeInterpolatedValue(PetscScalar topValue, PetscScalar botValue, PetscScalar Peclet=0.0)
const SCMMixingClosureBase * _mixing_closure
Turbulent Mixing closure object.
PetscErrorCode shiftCrossflowDamping(Mat M_ww, Vec b_w, Vec Wij_iter, PetscScalar inv_dtau)
Add the damping of the inverse pseudo-time step inv_dtau to the cross-momentum equation: inv_dtau L_i...
Real computeSweepFlowMixingParameter(unsigned int i_gap, unsigned int iz) const
Computes and validates the sweep-flow mixing parameter.
virtual ~SubChannel1PhaseProblem()
const SCMHTCClosureBase * _pin_HTC_closure
HTC closure objects.
const SCMHTCClosureBase * _duct_HTC_closure
SubChannel1PhaseProblem(const InputParameters ¶ms)
static constexpr Real _max_crossflow_pseudo_time_step_reduction
Cap on the pseudo-time step reduction: the reduction one fully retried monolithic solve provides.
Mat _cmc_friction_force_mat
Cross momentum conservation - friction force.
std::unique_ptr< SolutionHandle > _w_perim_soln
PetscErrorCode petscSnesSolver(int iblock, const libMesh::DenseVector< Real > &solution, libMesh::DenseVector< Real > &root)
Computes solution of nonlinear equation using snes and provided a residual in a formFunction.
PetscErrorCode addCrossflowDamping(Mat M_ww, Mat M_wp, Vec b_w, Vec Wij_iter, int iblock, PetscScalar &inv_dtau)
Add the pseudo-time damping added_K_ij (Wij - Wij_iter) to the cross-momentum equation of the monolit...
const PetscReal & _dtol
The divergence tolerance for the ksp linear solver.
PetscErrorCode createPetscMatrix(Mat &M, PetscInt n, PetscInt m)
virtual void initializeSolution()=0
Function to initialize the solution & geometry fields.
std::unique_ptr< SolutionHandle > _displacement_soln
Mat _hc_time_derivative_mat
Enthalpy Enthalpy conservation - time derivative.
Mat _cmc_time_derivative_mat
Cross momentum Cross momentum conservation - time derivative.
const SCMFrictionClosureBase * _friction_closure
Friction closure object.
Mat _amc_turbulent_cross_flows_mat
Axial momentum Axial momentum conservation - compute turbulent cross fluxes.
bool _cmc_sys_Wij_pattern_set
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.
Mat _amc_sys_mdot_mat
Axial momentum system matrix.
Mat _cmc_sys_Wij_mat
Lateral momentum system matrix.
static constexpr unsigned int _max_crossflow_retries
Number of monolithic linear-solve retries, each halving the crossflow pseudo-time step.
libMesh::DenseMatrix< Real > _WijPrime
Vec _hc_cross_derivative_rhs
void computeRho(int iblock)
Computes Density per channel for block iblock.
virtual Real getSubChannelPeripheralDuctWidth(unsigned int i_ch) const =0
Function that computes the width of the duct cell that the peripheral subchannel i_ch sees.
std::unique_ptr< SolutionHandle > _DP_soln
const MooseEnum _interpolation_scheme
The interpolation method used in constructing the systems.
std::unique_ptr< SolutionHandle > _rho_soln
Mat _mc_sumWij_mat
Matrices and vectors to be used in implicit assembly Mass conservation Mass conservation - sum of cro...
std::unique_ptr< SolutionHandle > _duct_heat_flux_soln
struct SubChannel1PhaseProblem::FrictionStruct _friction_args
bool _amc_sys_mdot_pattern_set
Whether the nonzero patterns of the assembled system matrices have been established.
void computeDP(int iblock)
Computes Pressure Drop per channel for block iblock.
const Real & _T_tol
Convergence tolerance for the temperature loop in internal solve.
const bool _duct_mesh_exist
Flag that informs if there is a duct mesh or not.
std::unique_ptr< SolutionHandle > _S_flow_soln
void computeWijResidual(int iblock)
Computes Residual Matrix based on the lateral momentum conservation equation for block iblock.
const bool _compute_power
Flag that informs if we need to solve the Enthalpy/Temperature equations or not.
const PostprocessorValue & _P_out
Outlet pressure postprocessor value.
virtual void initialSetup() override
std::unique_ptr< SolutionHandle > _Dpin_soln
Mat _cmc_pressure_force_mat
Cross momentum conservation - pressure force.
std::unique_ptr< SolutionHandle > _P_soln
Real _bulk_Re
Assembly bulk Reynolds number.
Vec _hc_advective_derivative_rhs
Vec _amc_pressure_force_rhs
unsigned int _n_blocks
number of axial blocks
void detectDeformation()
Detects whether pin diameter or duct displacement fields require geometry recalculation.
Mat _amc_time_derivative_mat
Axial momentum conservation - time derivative.
libMesh::DenseMatrix< Real > & _Wij
std::unique_ptr< SolutionHandle > _Tduct_soln
bool _deformation
Flag that activates the effect of deformation (pin/duct) based on the auxvalues for displacement,...
libMesh::DenseMatrix< Real > _Wij_residual_matrix
friend PetscErrorCode formFunction(SNES snes, Vec x, Vec f, void *ctx)
This is the residual Vector function in a form compatible with the SNES PETC solvers.
std::unique_ptr< SolutionHandle > _h_soln
std::unique_ptr< SolutionHandle > _T_soln
virtual void computeh(int iblock)=0
Computes Enthalpy per channel for block iblock.
std::unique_ptr< SolutionHandle > _mu_soln
Real _TR
Flag that activates or deactivates the transient parts of the equations we solve by multiplication.
Vec _hc_time_derivative_rhs
virtual void externalSolve() override
Mat _cmc_advective_derivative_mat
Cross momentum conservation - advective (Eulerian) derivative.
const PetscInt _maxit
The maximum number of iterations to use for the ksp linear solver.
bool _time_integrator_checked
Whether the time integrator has been checked for consistency with the implementation.
Vec _hc_added_heat_rhs
Enthalpy conservation - source and sink.
const Real & _P_tol
Convergence tolerance for the pressure loop in external solve.
Mat _amc_friction_force_mat
Axial momentum conservation - friction force.
Real _CT
Turbulent modeling parameter used in axial momentum equation.
PetscErrorCode populateDenseFromVector(const Vec &x, T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
Real _pressure_fixed_point_error
Maximum pressure fixed-point update before solution relaxation over the blocks.
Mat _mc_density_pressure_mat
Mass conservation - pressure derivative of transient density.
const bool _compute_viscosity
Flag that activates or deactivates the calculation of viscosity.
Mat _hc_advective_derivative_mat
Enthalpy conservation - advective (Eulerian) derivative;.
Vec _cmc_time_derivative_rhs
Vec _cmc_advective_derivative_rhs
PetscErrorCode implicitPetscSolve(int iblock)
Computes implicit solve using PetSc.
const bool _compute_density
Flag that activates or deactivates the calculation of density.
libMesh::DenseVector< Real > residualFunction(int iblock, libMesh::DenseVector< Real > solution)
Computes Residual Vector based on the lateral momentum conservation equation for block iblock & updat...
bool _converged
Variable that informs whether we exited external solve with a converged solution or not.
const Real & _crossflow_pseudo_time_step
Initial pseudo-time step of the crossflow damping.
void computeSumWij(int iblock)
Computes net diversion crossflow per channel for block iblock.
const int & _T_maxit
Maximum iterations for the inner temperature loop.
const Real & _T_relaxation
Relaxation factor for temperature updates in the inner thermal-hydraulic iteration.
const Real & _crossflow_relaxation
Relaxation factor for crossflow updates in the monolithic solve.
std::unique_ptr< SolutionHandle > _Tpin_soln
const bool _pin_mesh_exist
Flag that informs if there is a pin mesh or not.
Vec _amc_time_derivative_rhs
Mat _amc_pressure_force_mat
Axial momentum conservation - pressure force.
const bool _crossflow_pseudo_time_damping
Whether the crossflow of the monolithic solve is damped with a pseudo-time derivative.
void computeMdot(int iblock)
Computes mass flow per channel for block iblock.
Real _bulk_V
Assembly bulk velocity.
Vec _cmc_pseudo_time_inertia
Crossflow inertia L_ij S_ij rho* of each gap of the block, the coefficient of the pseudo-time derivat...
std::unique_ptr< SolutionHandle > _SumWij_soln
const bool _implicit_bool
Flag to define the usage of a implicit or explicit solution.
const int & _P_maxit
Maximum number of pressure iterations; zero selects the solver's existing automatic limit.
std::vector< Real > _z_grid
axial location of nodes
virtual bool solverSystemConverged(const unsigned int) override
Vec _cmc_pressure_force_rhs
const Real & _mass_flow_relaxation
Relaxation factor for mass flow rate updates in the monolithic solve.
Vec _amc_cross_derivative_rhs
Mat _amc_cross_derivative_mat
Axial momentum conservation - cross flux derivative.
std::vector< Real > _crossflow_residual_ref
Per-block largest cross-momentum residual norm of the solve, which scales the crossflow damping in th...
void computeWijFromSolve(int iblock)
Computes diversion crossflow per gap for block iblock.
const unsigned int & _enthalpy_subcycles
Number of enthalpy, temperature, and property updates performed per flow solve.
void computeMu(int iblock)
Computes Viscosity per channel for block iblock.
Vec _amc_friction_force_rhs
Vec _amc_turbulent_cross_flows_rhs
PetscErrorCode populateVectorFromDense(Vec &x, const T &solution, const unsigned int first_axial_level, const unsigned int last_axial_level, const unsigned int cross_dimension)
libMesh::DenseMatrix< Real > & _Wij_old
SubChannelMesh & _subchannel_mesh
struct SubChannel1PhaseProblem::NusseltStruct _nusselt_args
std::unique_ptr< SolutionHandle > _mdot_soln
Solutions handles and link to TH tables properties.
std::unique_ptr< SolutionHandle > _q_prime_soln
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)
const PetscReal & _rtol
The relative convergence tolerance, (relative decrease) for the ksp linear solver.
const Real & _crossflow_equation_relaxation
Equation relaxation factor for crossflow in the monolithic solve.
Vec _amc_gravity_rhs
Axial momentum conservation - buoyancy force No implicit matrix.
Mat _mc_axial_convection_mat
Mass conservation - axial convection.
Vec _amc_advective_derivative_rhs
Mat _amc_advective_derivative_mat
Axial momentum conservation - advective (Eulerian) derivative.
void computeBulkReynoldsNumber()
Computes the assembly bulk Reynolds number from inlet flow conditions.
Real computeT(int iblock)
Computes and relaxes Temperature per channel for block iblock.
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 MooseEnum _monolithic_preconditioner
Preconditioner of the monolithic flow system.
void computeWijPrime(int iblock)
Computes turbulent crossflow per gap for block iblock.
Real computeMixingParameter(unsigned int i_gap, unsigned int iz) const
Computes and validates the turbulent mixing parameter.
std::unique_ptr< SolutionHandle > _ff_soln
std::vector< Real > _crossflow_pseudo_time_step_reduction
Per-block factor, raised after monolithic linear-solve failures, that divides the crossflow pseudo-ti...
Vec _cmc_friction_force_rhs
const bool _verbose_subchannel
Boolean to printout information related to subchannel solve.
Mat _hc_cross_derivative_mat
Enthalpy conservation - cross flux derivative.
const PetscReal & _atol
The absolute convergence tolerance for the ksp linear solver.
const Real & _pressure_relaxation
Relaxation factor for pressure updates in the monolithic solve.
const PetscInt _monolithic_gmres_restart
Restart length of the FGMRES solver of the monolithic flow system.
std::unique_ptr< SolutionHandle > _HTC_soln
static const std::string ENTHALPY
static const std::string DISPLACEMENT
static const std::string PRESSURE_DROP
static const std::string WETTED_PERIMETER
static const std::string PRESSURE
static const std::string DUCT_TEMPERATURE
static const std::string FRICTION_FACTOR
static const std::string MASS_FLOW_RATE
static const std::string SURFACE_AREA
static const std::string VISCOSITY
static const std::string DENSITY
static const std::string PIN_DIAMETER
static const std::string HEAT_TRANSFER_COEFFICIENT
static const std::string LINEAR_HEAT_RATE
static const std::string DUCT_HEAT_FLUX
static const std::string SUM_CROSSFLOW
static const std::string PIN_TEMPERATURE
static const std::string TEMPERATURE
Base class for subchannel meshes.
virtual unsigned int getNumOfChannels() const =0
Return the number of channels per layer.
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 unsigned int channelIndex(const Point &point) const =0
Real getAssemblyFlowArea() const
Return undeformed bundle inlet flow area.
Real getAssemblyHydraulicDiameter() const
Return undeformed bundle-average hydraulic diameter.
virtual const std::vector< Real > & getZGrid() const
Get axial location of layers.
Node * getChannelNodeFromDuct(Node *duct_node) const
Function that gets the channel node from the duct node.
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.
const std::vector< Node * > & getDuctNodes() const
Function that returns the vector with the duct nodes.
Node * getDuctNodeFromChannel(Node *channel_node) const
Function that gets the duct node from the channel node.
virtual unsigned int getNumOfPins() const =0
Return the number of pins.
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 const std::vector< std::vector< Real > > & getKGrid() const
Get axial cell location and value of loss coefficient.
virtual unsigned int getZIndex(const Point &point) const
Get axial index of point.
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 getNumOfGapsPerLayer() const =0
Return the number of gaps per layer.
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.
void max(const T &r, T &o, Request &req) const
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
void resize(const unsigned int new_m, const unsigned int new_n)
virtual void zero() override final
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
static constexpr Real TOLERANCE
SubChannel1PhaseProblem * schp
structure with the needed information to compute the friction factor at a specific subchannel cell
structure with the needed information to compute the Nusselt number at a specific subchannel cell and...