@@ -2850,7 +2850,6 @@ contains
28502850
28512851 real(wp), dimension(7) :: U_L, U_R, U_starL, U_starR, U_doubleL, U_doubleR
28522852 real(wp), dimension(7) :: F_L, F_R, F_starL, F_starR, F_hlld
2853-
28542853 ! Indices for U and F: (rho, rho*vel(1), rho*vel(2), rho*vel(3), By, Bz, E)
28552854 ! Note: vel and B are permutated, so vel(1) is the normal velocity, and x is the normal direction
28562855 ! Note: Bx is omitted as the magnetic flux is always zero in the normal direction
@@ -2970,74 +2969,15 @@ contains
29702969 E_starL = ((s_L - vel%L(1))*E%L - pTot_L*vel%L(1) + p_star*s_M)/(s_L - s_M)
29712970 E_starR = ((s_R - vel%R(1))*E%R - pTot_R*vel%R(1) + p_star*s_M)/(s_R - s_M)
29722971
2973- ! (5) Compute the left/right conserved state vectors
2974- U_L(1) = rho%L
2975- U_L(2) = rho%L*vel%L(1)
2976- U_L(3) = rho%L*vel%L(2)
2977- U_L(4) = rho%L*vel%L(3)
2978- U_L(5) = B%L(2)
2979- U_L(6) = B%L(3)
2980- U_L(7) = E%L
2981-
2982- U_R(1) = rho%R
2983- U_R(2) = rho%R*vel%R(1)
2984- U_R(3) = rho%R*vel%R(2)
2985- U_R(4) = rho%R*vel%R(3)
2986- U_R(5) = B%R(2)
2987- U_R(6) = B%R(3)
2988- U_R(7) = E%R
2989-
2990- ! (6) Compute the left/right star state vectors
2991- U_starL(1) = rhoL_star
2992- U_starL(2) = rhoL_star*s_M
2993- U_starL(3) = rhoL_star*vel%L(2)
2994- U_starL(4) = rhoL_star*vel%L(3)
2995- U_starL(5) = B%L(2)
2996- U_starL(6) = B%L(3)
2997- U_starL(7) = E_starL
2998-
2999- U_starR(1) = rhoR_star
3000- U_starR(2) = rhoR_star*s_M
3001- U_starR(3) = rhoR_star*vel%R(2)
3002- U_starR(4) = rhoR_star*vel%R(3)
3003- U_starR(5) = B%R(2)
3004- U_starR(6) = B%R(3)
3005- U_starR(7) = E_starR
3006-
3007- ! (7) Compute the left/right fluxes
3008- F_L(1) = rho%L*vel%L(1)
3009- F_L(2) = rho%L*vel%L(1)*vel%L(1) - B%L(1)*B%L(1) + pTot_L
3010- F_L(3) = rho%L*vel%L(1)*vel%L(2) - B%L(1)*B%L(2)
3011- F_L(4) = rho%L*vel%L(1)*vel%L(3) - B%L(1)*B%L(3)
3012- F_L(5) = vel%L(1)*B%L(2) - vel%L(2)*B%L(1)
3013- F_L(6) = vel%L(1)*B%L(3) - vel%L(3)*B%L(1)
3014- F_L(7) = (E%L + pTot_L)*vel%L(1) - B%L(1)*(vel%L(1)*B%L(1) + vel%L(2)*B%L(2) + vel%L(3)*B%L(3))
3015-
3016- F_R(1) = rho%R*vel%R(1)
3017- F_R(2) = rho%R*vel%R(1)*vel%R(1) - B%R(1)*B%R(1) + pTot_R
3018- F_R(3) = rho%R*vel%R(1)*vel%R(2) - B%R(1)*B%R(2)
3019- F_R(4) = rho%R*vel%R(1)*vel%R(3) - B%R(1)*B%R(3)
3020- F_R(5) = vel%R(1)*B%R(2) - vel%R(2)*B%R(1)
3021- F_R(6) = vel%R(1)*B%R(3) - vel%R(3)*B%R(1)
3022- F_R(7) = (E%R + pTot_R)*vel%R(1) - B%R(1)*(vel%R(1)*B%R(1) + vel%R(2)*B%R(2) + vel%R(3)*B%R(3))
3023-
3024- ! (8) Compute the left/right star fluxes (note array operations)
3025- F_starL = F_L + s_L*(U_starL - U_L)
3026- F_starR = F_R + s_R*(U_starR - U_R)
3027-
3028- ! (9) Compute the rotational (Alfvén) speeds
3029- s_starL = s_M - abs(B%L(1))/sqrt(rhoL_star)
3030- s_starR = s_M + abs(B%L(1))/sqrt(rhoR_star)
2972+ ! (5) Compute left/right state vectors and fluxes
2973+ call s_compute_hlld_state_variables(' L' , rho%L, vel%L, B%L, E%L, pTot_L, rhoL_star, s_M, E_starL, s_L, &
2974+ U_L, F_L, U_starL, F_starL, sqrt_rhoL_star, vL_star, wL_star)
2975+ call s_compute_hlld_state_variables(' R' , rho%R, vel%R, B%R, E%R, pTot_R, rhoR_star, s_M, E_starR, s_R, &
2976+ U_R, F_R, U_starR, F_starR, sqrt_rhoR_star, vR_star, wR_star)
30312977
3032- ! (10) Compute the double–star states [Miyoshi Eqns. (59)-(62)]
3033- sqrt_rhoL_star = sqrt(rhoL_star)
3034- sqrt_rhoR_star = sqrt(rhoR_star)
2978+ ! (6) Compute the double–star states [Miyoshi Eqns. (59)-(62)]
30352979 denom_ds = sqrt_rhoL_star + sqrt_rhoR_star
30362980 sign_Bx = sign(1._wp, B%L(1))
3037- vL_star = vel%L(2)
3038- wL_star = vel%L(3)
3039- vR_star = vel%R(2)
3040- wR_star = vel%R(3)
30412981 v_double = (sqrt_rhoL_star*vL_star + sqrt_rhoR_star*vR_star + (B%R(2) - B%L(2))*sign_Bx)/denom_ds
30422982 w_double = (sqrt_rhoL_star*wL_star + sqrt_rhoR_star*wR_star + (B%R(3) - B%L(3))*sign_Bx)/denom_ds
30432983 By_double = (sqrt_rhoL_star*B%R(2) + sqrt_rhoR_star*B%L(2) + sqrt_rhoL_star*sqrt_rhoR_star*(vR_star - vL_star)*sign_Bx)/denom_ds
@@ -3047,23 +2987,14 @@ contains
30472987 E_doubleR = E_starR + sqrt_rhoR_star*((vR_star*B%R(2) + wR_star*B%R(3)) - (v_double*By_double + w_double*Bz_double))*sign_Bx
30482988 E_double = 0.5_wp*(E_doubleL + E_doubleR)
30492989
3050- U_doubleL(1) = rhoL_star
3051- U_doubleL(2) = rhoL_star*s_M
3052- U_doubleL(3) = rhoL_star*v_double
3053- U_doubleL(4) = rhoL_star*w_double
3054- U_doubleL(5) = By_double
3055- U_doubleL(6) = Bz_double
3056- U_doubleL(7) = E_double
3057-
3058- U_doubleR(1) = rhoR_star
3059- U_doubleR(2) = rhoR_star*s_M
3060- U_doubleR(3) = rhoR_star*v_double
3061- U_doubleR(4) = rhoR_star*w_double
3062- U_doubleR(5) = By_double
3063- U_doubleR(6) = Bz_double
3064- U_doubleR(7) = E_double
3065-
3066- ! (11) Choose HLLD flux based on wave-speed regions
2990+ U_doubleL = s_compute_U_double(rhoL_star, s_M, v_double, w_double, By_double, Bz_double, E_double)
2991+ U_doubleR = s_compute_U_double(rhoR_star, s_M, v_double, w_double, By_double, Bz_double, E_double)
2992+
2993+ ! (7) Compute the rotational (Alfvén) speeds
2994+ s_starL = s_M - abs(B%L(1))/sqrt(rhoL_star)
2995+ s_starR = s_M + abs(B%L(1))/sqrt(rhoR_star)
2996+
2997+ ! (8) Choose HLLD flux based on wave-speed regions
30672998 if (0.0_wp <= s_L) then
30682999 F_hlld = F_L
30693000 else if (0.0_wp <= s_starL) then
@@ -3078,7 +3009,7 @@ contains
30783009 F_hlld = F_R
30793010 end if
30803011
3081- ! (12 ) Reorder and write temporary variables to the flux array
3012+ ! (9 ) Reorder and write temporary variables to the flux array
30823013 ! Mass
30833014 flux_rs${XYZ}$_vf(j, k, l, 1) = F_hlld(1) ! TODO multi-component
30843015 ! Momentum
@@ -3111,6 +3042,65 @@ contains
31113042
31123043 call s_finalize_riemann_solver(flux_vf, flux_src_vf, flux_gsrc_vf, &
31133044 norm_dir, ix, iy, iz)
3045+
3046+ contains
3047+ function s_compute_U_double(rho_star, s_M, v_double, w_double, By_double, Bz_double, E_double) result(U_double)
3048+ implicit none
3049+ real(wp), intent(in) :: rho_star, s_M, v_double, w_double, By_double, Bz_double, E_double
3050+ real(wp) :: U_double(7)
3051+
3052+ U_double(1) = rho_star
3053+ U_double(2) = rho_star*s_M
3054+ U_double(3) = rho_star*v_double
3055+ U_double(4) = rho_star*w_double
3056+ U_double(5) = By_double
3057+ U_double(6) = Bz_double
3058+ U_double(7) = E_double
3059+ end function s_compute_U_double
3060+
3061+ subroutine s_compute_hlld_state_variables(side, rho, vel, B, E, pTot, rho_star, s_M, E_star, s_wave, &
3062+ U, F, U_star, F_star, sqrt_rho_star, v_star, w_star)
3063+ implicit none
3064+ ! Input parameters
3065+ character(len=1), intent(in) :: side ! dummy ' L' for left or ' R' for right
3066+ real(wp), intent(in) :: rho, pTot, rho_star, s_M, E_star, s_wave, E
3067+ real(wp), dimension(:), intent(in) :: vel, B
3068+ ! Output parameters
3069+ real(wp), dimension(7), intent(out) :: U, F, U_star
3070+ real(wp), intent(out) :: sqrt_rho_star, v_star, w_star
3071+ real(wp), dimension(7), intent(out) :: F_star
3072+ ! Compute the base state vector
3073+ U(1) = rho
3074+ U(2) = rho*vel(1)
3075+ U(3) = rho*vel(2)
3076+ U(4) = rho*vel(3)
3077+ U(5) = B(2)
3078+ U(6) = B(3)
3079+ U(7) = E
3080+ ! Compute the flux vector
3081+ F(1) = U(2)
3082+ F(2) = U(2)*vel(1) - B(1)*B(1) + pTot
3083+ F(3) = U(2)*vel(2) - B(1)*B(2)
3084+ F(4) = U(2)*vel(3) - B(1)*B(3)
3085+ F(5) = vel(1)*B(2) - vel(2)*B(1)
3086+ F(6) = vel(1)*B(3) - vel(3)*B(1)
3087+ F(7) = (E + pTot)*vel(1) - B(1)*(vel(1)*B(1) + vel(2)*B(2) + vel(3)*B(3))
3088+ ! Compute the star state
3089+ U_star(1) = rho_star
3090+ U_star(2) = rho_star*s_M
3091+ U_star(3) = rho_star*vel(2)
3092+ U_star(4) = rho_star*vel(3)
3093+ U_star(5) = B(2)
3094+ U_star(6) = B(3)
3095+ U_star(7) = E_star
3096+ ! Compute the star flux using HLL relation
3097+ F_star = F + s_wave*(U_star - U)
3098+ ! Compute additional parameters needed for double-star states
3099+ sqrt_rho_star = sqrt(rho_star)
3100+ v_star = vel(2)
3101+ w_star = vel(3)
3102+ end subroutine s_compute_hlld_state_variables
3103+ ! end contains
31143104 end subroutine s_hlld_riemann_solver
31153105
31163106 !> The computation of parameters, the allocation of memory,
0 commit comments