@@ -714,7 +714,7 @@ subroutine setup_bwr_geometry_realistic(sim)
714714
715715 end subroutine setup_bwr_geometry_realistic
716716
717- ! > Setup BWR simulation (from original)
717+ ! > Setup BWR simulation
718718 subroutine setup_bwr_simulation (sim )
719719 type (simulation_t), intent (out ) :: sim
720720
@@ -856,7 +856,6 @@ subroutine setup_bwr_simulation(sim)
856856 print * , " "
857857 end subroutine setup_bwr_simulation
858858
859- ! > Coupled physics time step (from original)
860859 subroutine coupled_time_step (sim , dt )
861860 type (simulation_t), intent (inout ) :: sim
862861 real (wp), intent (in ) :: dt
@@ -870,6 +869,48 @@ subroutine coupled_time_step(sim, dt)
870869 real (wp), parameter :: rho_vapor = 0.038_wp
871870 logical :: converged
872871
872+ real (wp) :: v_coolant
873+ integer :: i, j, k
874+ real (wp) :: Re, h_conv
875+ real (wp), parameter :: D_h = 0.01_wp ! hydraulic diameter
876+ real (wp), parameter :: mu = 0.0001_wp ! viscosity
877+ real (wp), parameter :: k_fluid = 0.6_wp ! thermal conductivity
878+ real (wp), parameter :: Pr = 0.9_wp ! Prandtl number for water
879+
880+ ! Set coolant velocity field for heat transfer
881+ ! Approximate axial flow velocity from mass flux
882+ ! v_z = G / rho where G is mass flux [kg/m^2.s]
883+
884+ v_coolant = sim% mass_flux_core / rho_liquid
885+
886+ ! Set velocity in heat transfer module
887+ if (allocated (sim% heat% vz)) then
888+ sim% heat% vz = v_coolant
889+ end if
890+
891+ ! Also update convective boundary conditions
892+ ! Higher flow = higher heat transfer coefficient
893+
894+ ! Reynolds number
895+ Re = rho_liquid * v_coolant * D_h / mu
896+
897+ ! Dittus-Boelter correlation for heat transfer coefficient
898+ h_conv = 0.023_wp * Re** 0.8_wp * Pr** 0.4_wp * k_fluid / D_h
899+
900+ ! Update boundary conditions in heat transfer
901+ do k = 1 , sim% nz
902+ do j = 1 , sim% ny
903+ do i = 1 , sim% nx
904+ ! Apply convective cooling in heat source term
905+
906+ end do
907+ end do
908+ end do
909+
910+ ! ========================================================================
911+ ! Continue with original coupling
912+ ! ========================================================================
913+
873914 ! Neutronics
874915 call mg_solve_eigenvalue(sim% neutronics, sim% k_eff, converged)
875916
@@ -920,7 +961,7 @@ subroutine coupled_time_step(sim, dt)
920961
921962 end subroutine coupled_time_step
922963
923- ! > Solve for initial steady state (from original)
964+ ! > Solve for initial steady state
924965 subroutine solve_steady_state (sim )
925966 type (simulation_t), intent (inout ) :: sim
926967
@@ -983,7 +1024,7 @@ subroutine solve_steady_state(sim)
9831024
9841025 end subroutine solve_steady_state
9851026
986- ! > Update cross sections with feedback (from original)
1027+ ! > Update cross sections with feedback
9871028 subroutine update_cross_sections_feedback (sim , T , rho )
9881029 type (simulation_t), intent (inout ) :: sim
9891030 real (wp), intent (in ) :: T(:, :, :)
@@ -999,23 +1040,26 @@ subroutine update_cross_sections_feedback(sim, T, rho)
9991040 T_fuel = T(i, j, k)
10001041 rho_mod = rho(i, j, k)
10011042
1043+ ! Get cross-sections with feedback
10021044 call xslib_get_xsec(sim% xslib, " UO2_35" , &
10031045 T_fuel, rho_mod, sim% burnup% burnup(i, j, k), xsec, &
10041046 Xe_conc= sim% burnup% Xe135(i, j, k), &
10051047 Sm_conc= sim% burnup% Sm149(i, j, k))
10061048
1049+ ! ================================================================
1050+ ! CRITICAL FIX: Apply control rod BEFORE setting cross-sections!
1051+ ! ================================================================
10071052 block
10081053 real (wp) :: node_bottom, node_top, rod_tip, inserted_fraction
10091054 real (wp) :: H_core
10101055
1011- ! Use sim%nz and sim%dz directly from simulation_t [cite: 136, 137]
10121056 H_core = real (sim% nz, wp) * sim% dz
10131057
1014- ! Calculate physical height of this node [cite: 137]
1058+ ! Calculate physical height of this node
10151059 node_bottom = real (k-1 , wp) * sim% dz
10161060 node_top = real (k, wp) * sim% dz
10171061
1018- ! BWR rods come from the BOTTOM.
1062+ ! BWR rods come from the BOTTOM
10191063 ! Position 0.0 = fully withdrawn (bottom)
10201064 ! Position 1.0 = fully inserted (top)
10211065 rod_tip = sim% rod_bank_position * H_core
@@ -1030,19 +1074,21 @@ subroutine update_cross_sections_feedback(sim, T, rho)
10301074 inserted_fraction = (rod_tip - node_bottom) / sim% dz
10311075 end if
10321076
1033- ! Access the xsec array directly within the neutronics state
1077+ ! Apply control rod to LOCAL xsec variable
1078+ ! BEFORE calling mg_set_cross_sections!
10341079 if (inserted_fraction > 0.0_wp ) then
1035- call xslib_apply_control_rod(sim % neutronics % xsec(i,j,k) , inserted_fraction)
1080+ call xslib_apply_control_rod(xsec, inserted_fraction)
10361081 end if
10371082 end block
10381083
1084+ ! Now set the modified cross-sections
10391085 call mg_set_cross_sections(sim% neutronics, xsec, i, i, j, j, k, k)
10401086 end do
10411087 end do
10421088 end do
10431089 end subroutine update_cross_sections_feedback
10441090
1045- ! > Apply reactivity insertion (from original)
1091+ ! > Apply reactivity insertion
10461092 subroutine apply_reactivity_insertion (sim , rho_pcm )
10471093 type (simulation_t), intent (inout ) :: sim
10481094 real (wp), intent (in ) :: rho_pcm
@@ -1064,7 +1110,7 @@ subroutine apply_reactivity_insertion(sim, rho_pcm)
10641110 end do
10651111 end subroutine apply_reactivity_insertion
10661112
1067- ! > Check safety limits (from original)
1113+ ! > Check safety limits
10681114 function check_safety_limits (sim ) result(approaching_limits)
10691115 type (simulation_t), intent (in ) :: sim
10701116 logical :: approaching_limits
@@ -1087,7 +1133,7 @@ function check_safety_limits(sim) result(approaching_limits)
10871133 end if
10881134 end function check_safety_limits
10891135
1090- ! > Print steady-state summary (from original)
1136+ ! > Print steady-state summary
10911137 subroutine print_steady_state_summary (sim )
10921138 type (simulation_t), intent (in ) :: sim
10931139
@@ -1104,7 +1150,7 @@ subroutine print_steady_state_summary(sim)
11041150 print * , " "
11051151 end subroutine print_steady_state_summary
11061152
1107- ! > Print transient summary (from original)
1153+ ! > Print transient summary
11081154 subroutine print_transient_summary (sim , step , t )
11091155 type (simulation_t), intent (in ) :: sim
11101156 integer , intent (in ) :: step
@@ -1120,7 +1166,7 @@ subroutine print_transient_summary(sim, step, t)
11201166 print * , " "
11211167 end subroutine print_transient_summary
11221168
1123- ! > Cleanup (from original)
1169+ ! > Cleanup
11241170 subroutine cleanup_simulation (sim )
11251171 type (simulation_t), intent (inout ) :: sim
11261172
0 commit comments