328 unsigned int last_node = (iblock + 1) *
_block_size;
329 unsigned int first_node = iblock *
_block_size + 1;
337 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
344 name(),
" : Calculation of negative Enthalpy h_out = : ", h_out,
" Axial Level= : ", 0);
352 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
355 auto dz = z_grid[iz] - z_grid[iz - 1];
357 Real edge_flux_ave = 0.0;
360 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
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;
372 edge_flux_ave = mdot_sum / si_sum;
374 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
378 auto mdot_in = (*_mdot_soln)(node_in);
379 auto h_in = (*_h_soln)(node_in);
380 auto volume = dz * (*_S_flow_soln)(node_in);
381 auto mdot_out = (*_mdot_soln)(node_out);
384 Real sumWijPrimeDhij = 0.0;
385 Real sweep_enthalpy = 0.0;
394 unsigned int counter = 0;
400 unsigned int ii_ch = chans.first;
401 unsigned int jj_ch = chans.second;
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);
421 (wire_lead_length != 0) && (wire_diameter != 0))
429 if ((ii_ch == sweep_donor) || (jj_ch == sweep_donor))
432 (*_h_soln)(node_sweep_donor);
446 _WijPrime(i_gap, iz) * (2 * h_in - (*_h_soln)(node_in_j) - (*
_h_soln)(node_in_i));
450 Real dist_ij = pitch;
463 dist_ij = pitch / std::sqrt(3);
469 0.66 * (pitch / pin_diameter) *
473 e_cond += 0.5 * (thcon_i + thcon_j) * Sij * shape_factor *
478 e_cond += -0.5 * (thcon_i + thcon_j) * Sij * shape_factor *
488 auto Si = (*_S_flow_soln)(node_in_i);
489 auto dist_ij = z_grid[iz] - z_grid[iz - 1];
491 e_cond += 0.5 * (thcon_i + thcon_j) * Si * ((*
_T_soln)(node_in_j) - (*
_T_soln)(node_in_i)) /
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 *
510 (mdot_in * h_in - sumWijh - sumWijPrimeDhij + added_enthalpy + e_cond + sweep_enthalpy +
516 " : Calculation of negative Enthalpy h_out = : ",
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)
550 const auto [it, inserted] = k_cache.try_emplace(node->id());
555 auto specificHeat = [&](
const Node * node)
557 const auto [it, inserted] = cp_cache.try_emplace(node->id());
566 for (
unsigned int iz = first_node; iz < last_node + 1; iz++)
571 auto iz_ind = iz - first_node;
576 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
582 mdot_sum += (*_mdot_soln)(node_in);
583 si_sum += (*_S_flow_soln)(node_in);
586 const Real edge_flux_ave = mdot_sum / si_sum;
588 for (
unsigned int i_ch = 0; i_ch <
_n_channels; i_ch++)
592 auto S_in = (*_S_flow_soln)(node_in);
593 auto S_out = (*_S_flow_soln)(node_out);
595 auto volume = dz * S_interp;
597 PetscScalar Pe = 0.5;
601 auto w_perim_in = (*_w_perim_soln)(node_in);
602 auto w_perim_out = (*_w_perim_soln)(node_out);
604 auto K_in = thermalConductivity(node_in);
605 auto K_out = thermalConductivity(node_out);
607 auto cp_in = specificHeat(node_in);
608 auto cp_out = specificHeat(node_out);
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));
623 PetscScalar value_tt =
_TR * (*_rho_soln)(node_out)*volume /
_dt;
624 LibmeshPetscCall(MatSetValues(
627 PetscScalar value_vec_tt =
635 if (iz == first_node)
638 PetscScalar value_at = (*_mdot_soln)(node_in) * (*
_h_soln)(node_in);
645 PetscInt col_at = i_ch +
_n_channels * (iz_ind - 1);
646 PetscScalar value_at = -1.0 * (*_mdot_soln)(node_in);
647 LibmeshPetscCall(MatSetValues(
653 PetscScalar value_at = (*_mdot_soln)(node_out);
654 LibmeshPetscCall(MatSetValues(
659 auto K_center = thermalConductivity(node_center);
660 auto cp_center = specificHeat(node_center);
661 auto diff_center = K_center / (cp_center + 1e-15);
663 if (iz == first_node)
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);
686 PetscScalar value_at = diff_up * S_up / dz_up + diff_down * S_down / dz_down;
687 LibmeshPetscCall(MatSetValues(
691 value_at = 1.0 * diff_down * S_down / dz_down * (*_h_soln)(node_bottom);
697 value_at = -diff_up * S_up / dz_up;
698 LibmeshPetscCall(MatSetValues(
701 else if (iz == last_node)
704 auto K_bottom = thermalConductivity(node_bottom);
705 auto cp_bottom = specificHeat(node_bottom);
706 auto diff_bottom = K_bottom / (cp_bottom + 1e-15);
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);
715 PetscScalar value_at = diff_down * S_down / dz_down;
716 LibmeshPetscCall(MatSetValues(
721 value_at = -diff_down * S_down / dz_down;
722 LibmeshPetscCall(MatSetValues(
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);
757 PetscScalar value_at = diff_up * S_up / dz_up + diff_down * S_down / dz_down;
758 LibmeshPetscCall(MatSetValues(
763 value_at = -diff_down * S_down / dz_down;
764 LibmeshPetscCall(MatSetValues(
769 value_at = -diff_up * S_up / dz_up;
770 LibmeshPetscCall(MatSetValues(
775 unsigned int counter = 0;
776 unsigned int cross_index = iz;
781 unsigned int ii_ch = chans.first;
782 unsigned int jj_ch = chans.second;
787 if (
_Wij(i_gap, cross_index) > 0.0)
789 if (iz == first_node)
791 h_star = (*_h_soln)(node_in_i);
792 PetscScalar value_vec_ct = -1.0 * alpha *
794 _Wij(i_gap, cross_index) * h_star;
796 LibmeshPetscCall(VecSetValues(
802 _Wij(i_gap, cross_index);
804 PetscInt col_ct = ii_ch +
_n_channels * (iz_ind - 1);
805 LibmeshPetscCall(MatSetValues(
808 PetscScalar value_ct = (1.0 - alpha) *
810 _Wij(i_gap, cross_index);
813 LibmeshPetscCall(MatSetValues(
816 else if (
_Wij(i_gap, cross_index) < 0.0)
818 if (iz == first_node)
820 h_star = (*_h_soln)(node_in_j);
821 PetscScalar value_vec_ct = -1.0 * alpha *
823 _Wij(i_gap, cross_index) * h_star;
825 LibmeshPetscCall(VecSetValues(
831 _Wij(i_gap, cross_index);
833 PetscInt col_ct = jj_ch +
_n_channels * (iz_ind - 1);
834 LibmeshPetscCall(MatSetValues(
837 PetscScalar value_ct = (1.0 - alpha) *
839 _Wij(i_gap, cross_index);
842 LibmeshPetscCall(MatSetValues(
847 if (iz == first_node)
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);
859 PetscScalar value_center_ct = 2.0 * alpha *
_WijPrime(i_gap, cross_index);
861 PetscInt col_ct = i_ch +
_n_channels * (iz_ind - 1);
862 LibmeshPetscCall(MatSetValues(
865 PetscScalar value_left_ct = -1.0 * alpha *
_WijPrime(i_gap, cross_index);
868 LibmeshPetscCall(MatSetValues(
871 PetscScalar value_right_ct = -1.0 * alpha *
_WijPrime(i_gap, cross_index);
874 LibmeshPetscCall(MatSetValues(
877 PetscScalar value_center_ct = 2.0 * (1.0 - alpha) *
_WijPrime(i_gap, cross_index);
880 LibmeshPetscCall(MatSetValues(
883 PetscScalar value_left_ct = -1.0 * (1.0 - alpha) *
_WijPrime(i_gap, cross_index);
886 LibmeshPetscCall(MatSetValues(
889 PetscScalar value_right_ct = -1.0 * (1.0 - alpha) *
_WijPrime(i_gap, cross_index);
892 LibmeshPetscCall(MatSetValues(
898 Real dist_ij = pitch;
911 dist_ij = pitch / std::sqrt(3);
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);
923 0.66 * (pitch / pin_diameter) *
926 auto base_value = harm_A * shape_factor * Sij / dist_ij;
927 auto neg_base_value = -1.0 * base_value;
931 const auto other_ch = (i_ch == ii_ch) ? jj_ch : ii_ch;
934 LibmeshPetscCall(MatSetValues(
938 LibmeshPetscCall(MatSetValues(
945 PetscScalar sweep_enthalpy = 0.0;
947 (wire_diameter != 0.0) && (wire_lead_length != 0.0))
949 auto beta_in = std::numeric_limits<double>::quiet_NaN();
950 auto beta_out = std::numeric_limits<double>::quiet_NaN();
958 unsigned int ii_ch = chans.first;
959 unsigned int jj_ch = chans.second;
965 if ((ii_ch == sweep_donor) || (jj_ch == sweep_donor))
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));
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);
993 if (iz == first_node)
995 PetscScalar value_hs = alpha * sweep_enthalpy;
1001 PetscInt col_sh = i_ch +
_n_channels * (iz_ind - 1);
1002 PetscScalar value_sh = alpha * wsweep_out;
1003 LibmeshPetscCall(MatSetValues(
1005 col_sh = sweep_donor +
_n_channels * (iz_ind - 1);
1006 value_sh = -alpha * wsweep_in;
1007 LibmeshPetscCall(MatSetValues(
1011 PetscScalar value_sh = (1.0 - alpha) * wsweep_out;
1015 value_sh = -(1.0 - alpha) * wsweep_in;
1023 PetscInt row_vec_ht = i_ch +
_n_channels * iz_ind;
1041 LibmeshPetscCall(MatAssemblyBegin(
_hc_sys_h_mat, MAT_FINAL_ASSEMBLY));
1042 LibmeshPetscCall(MatAssemblyEnd(
_hc_sys_h_mat, MAT_FINAL_ASSEMBLY));
1053 _console <<
"Block: " << iblock <<
" - Enthalpy conservation matrix assembled" << std::endl;