Skip to content

Refactor HLL, HLLC, HLLD Solvers #855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c4207e2
added s_compute_wave_speed
Jun 2, 2025
fcc7ed5
implemented s_compute_wave_speed on all solvers
Jun 2, 2025
62ffeee
cleaned up s_hlld_riemann_solver redundancy
Jun 2, 2025
4290728
cleaned up s_hllc_riemann_solver redundancy
Jun 2, 2025
947f203
cleaned up s_hll_riemann_solver redundancy
Jun 2, 2025
fede1c1
fixed s_compute_wave_speed subroutine
Jun 2, 2025
ee64da0
removed dir_idx indexing from the definition of wave speed subroutine
Jun 2, 2025
7313eba
dir_idx re-added
Jun 2, 2025
ea78231
fixed syntax errors
Jun 2, 2025
93a408e
dir_idx(_tau) not recognized yet albeit global variables thus just pa…
Jun 3, 2025
f5df480
Prettifying
Jun 3, 2025
82f4846
cleand up redundant loops in s_populate_riemann_states_variables_buffers
Jun 3, 2025
5dd2eed
corrected pointer implementation in s_populate_riemann_states_variabl…
Jun 3, 2025
035b345
refactored s_initialize_riemann_solver
Jun 3, 2025
11e05c0
refactored s_finalize_riemann_solver
Jun 4, 2025
e428b07
finished formatting
Jun 4, 2025
4050163
pushing to the test suite
Jun 4, 2025
8172c8a
Merge branch 'master' into master
mohdsaid497566 Jun 4, 2025
ca69b3c
implemented s_compute_wave_speed on all solvers
mohdsaid497566 Jun 5, 2025
fdbdcae
s_compute_wave_speed passed Hypoelasticity tests
mohdsaid497566 Jun 5, 2025
c60ff19
non-solver subroutines refactor
mohdsaid497566 Jun 5, 2025
5987122
s_hlld_riemann_solver passed Hypoelasticity tests
mohdsaid497566 Jun 5, 2025
062d51d
s_hllc_riemann_solver passed Hypoelasticity tests
mohdsaid497566 Jun 5, 2025
3fff3b1
s_hll_riemann_solver passed Hypoelasticity tests
mohdsaid497566 Jun 5, 2025
14270da
s_hll_riemann_solver passed Hypoelasticity tests
mohdsaid497566 Jun 5, 2025
44f8f5d
fixed minor error
mohdsaid497566 Jun 5, 2025
174902b
working refactor
Jun 6, 2025
60c7621
fixed some loops
mohdsaid497566 Jun 6, 2025
c11ed1e
HLLD further refactored
mohdsaid497566 Jun 6, 2025
5d4e6fa
HLLC refactored further
mohdsaid497566 Jun 6, 2025
19b84f2
removed s_compute_cylindrical_geometry_source_flux
mohdsaid497566 Jun 7, 2025
c3690db
small changes
mohdsaid497566 Jun 7, 2025
d8ff089
HLL small refactor
mohdsaid497566 Jun 7, 2025
e69c4ef
prettifying
mohdsaid497566 Jun 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions src/common/m_variables_conversion.fpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module m_variables_conversion
#ifndef MFC_PRE_PROCESS
s_compute_speed_of_sound, &
s_compute_fast_magnetosonic_speed, &
s_compute_wave_speed, &
#endif
s_finalize_variables_conversion_module

Expand Down Expand Up @@ -1719,4 +1720,118 @@ contains
end subroutine s_compute_fast_magnetosonic_speed
#endif

#ifndef MFC_PRE_PROCESS
subroutine s_compute_wave_speed(wave_speeds, vel_L, vel_R, pres_L, pres_R, rho_L, rho_R, rho_avg, &
c_L, c_R, c_avg, c_fast_L, c_fast_R, G_L, G_R, &
tau_e_L, tau_e_R, gamma_L, gamma_R, pi_inf_L, pi_inf_R, &
s_L, s_R, s_S, s_M, s_P, idx, idx_tau)

! Computes the wave speeds for the Riemann solver
#ifdef _CRAYFTN
!DIR$ INLINEALWAYS s_compute_wave_speed
#else
!$acc routine seq
#endif

! Input parameters
integer, intent(in) :: wave_speeds
integer, intent(in) :: idx, idx_tau
real(wp), intent(in) :: rho_L, rho_R
real(wp), dimension(:), intent(in) :: vel_L, vel_R, tau_e_L, tau_e_R
real(wp), intent(in) :: pres_L, pres_R, c_L, c_R
real(wp), intent(in) :: gamma_L, gamma_R, pi_inf_L, pi_inf_R
real(wp), intent(in) :: rho_avg, c_avg
real(wp), intent(in) :: c_fast_L, c_fast_R
real(wp), intent(in) :: G_L, G_R

! Local variables
real(wp) :: pres_SL, pres_SR, Ms_L, Ms_R

! Output parameters
real(wp), intent(out) :: s_L, s_R, s_S, s_M, s_P

if (wave_speeds == 1) then
if (elasticity) then
s_L = min(vel_L(idx) - sqrt(c_L*c_L + &
(((4_wp*G_L)/3_wp) + tau_e_L(idx_tau))/rho_L), vel_R(idx) - sqrt(c_R*c_R + &
(((4_wp*G_R)/3_wp) + tau_e_R(idx_tau))/rho_R))
s_R = max(vel_R(idx) + sqrt(c_R*c_R + &
(((4_wp*G_R)/3_wp) + tau_e_R(idx_tau))/rho_R), vel_L(idx) + sqrt(c_L*c_L + &
(((4_wp*G_L)/3_wp) + tau_e_L(idx_tau))/rho_L))
s_S = (pres_R - tau_e_R(idx_tau) - pres_L + &
tau_e_L(idx_tau) + rho_L*vel_L(idx)*(s_L - vel_L(idx)) - &
rho_R*vel_R(idx)*(s_R - vel_R(idx)))/(rho_L*(s_L - vel_L(idx)) - &
rho_R*(s_R - vel_R(idx)))
else if (mhd) then
s_L = min(vel_L(idx) - c_fast_L, vel_R(idx) - c_fast_R)
s_R = max(vel_R(idx) + c_fast_R, vel_L(idx) + c_fast_L)
s_S = (pres_R - pres_L + rho_L*vel_L(idx)* &
(s_L - vel_L(idx)) - rho_R*vel_R(idx)*(s_R - vel_R(idx))) &
/(rho_L*(s_L - vel_L(idx)) - rho_R*(s_R - vel_R(idx)))
else if (hypoelasticity) then
s_L = min(vel_L(idx) - sqrt(c_L*c_L + (((4._wp*G_L)/3._wp) + &
tau_e_L(idx_tau))/rho_L) &
, vel_R(idx) - sqrt(c_R*c_R + (((4._wp*G_R)/3._wp) + &
tau_e_R(idx_tau))/rho_R))
s_R = max(vel_R(idx) + sqrt(c_R*c_R + (((4._wp*G_R)/3._wp) + &
tau_e_R(idx_tau))/rho_R) &
, vel_L(idx) + sqrt(c_L*c_L + (((4._wp*G_L)/3._wp) + &
tau_e_L(idx_tau))/rho_L))
s_S = (pres_R - pres_L + rho_L*vel_L(idx)* &
(s_L - vel_L(idx)) - rho_R*vel_R(idx)*(s_R - vel_R(idx))) &
/(rho_L*(s_L - vel_L(idx)) - rho_R*(s_R - vel_R(idx)))
else if (hyperelasticity) then
s_L = min(vel_L(idx) - sqrt(c_L*c_L + (4._wp*G_L/3._wp)/rho_L) &
, vel_R(idx) - sqrt(c_R*c_R + (4._wp*G_R/3._wp)/rho_R))
s_R = max(vel_R(idx) + sqrt(c_R*c_R + (4._wp*G_R/3._wp)/rho_R) &
, vel_L(idx) + sqrt(c_L*c_L + (4._wp*G_L/3._wp)/rho_L))
s_S = (pres_R - pres_L + rho_L*vel_L(idx)* &
(s_L - vel_L(idx)) - rho_R*vel_R(idx)*(s_R - vel_R(idx))) &
/(rho_L*(s_L - vel_L(idx)) - rho_R*(s_R - vel_R(idx)))
else
s_L = min(vel_L(idx) - c_L, vel_R(idx) - c_R)
s_R = max(vel_R(idx) + c_R, vel_L(idx) + c_L)
s_S = (pres_R - pres_L + rho_L*vel_L(idx)* &
(s_L - vel_L(idx)) - rho_R*vel_R(idx)*(s_R - vel_R(idx))) &
/(rho_L*(s_L - vel_L(idx)) - rho_R*(s_R - vel_R(idx)))
end if
else if (wave_speeds == 2) then
pres_SL = 5e-1_wp*(pres_L + pres_R + rho_avg*c_avg*(vel_L(idx) - vel_R(idx)))
pres_SR = pres_SL
Ms_L = max(1._wp, sqrt(1._wp + ((5e-1_wp + gamma_L)/(1._wp + gamma_L))* &
(pres_SL/pres_L - 1._wp)*pres_L/ &
((pres_L + pi_inf_L/(1._wp + gamma_L)))))
Ms_R = max(1._wp, sqrt(1._wp + ((5e-1_wp + gamma_R)/(1._wp + gamma_R))* &
(pres_SR/pres_R - 1._wp)*pres_R/ &
((pres_R + pi_inf_R/(1._wp + gamma_R)))))
s_L = vel_L(idx) - c_L*Ms_L
s_R = vel_R(idx) + c_R*Ms_R
s_S = 5e-1_wp*((vel_L(idx) + vel_R(idx)) + (pres_L - pres_R)/(rho_avg*c_avg))
end if

! ! follows Einfeldt et al.
! s_M/P = min/max(0.,s_L/R)
s_M = min(0._wp, s_L)
s_P = max(0._wp, s_R)

#ifdef DEBUG
! Check for potential issues in wave speed calculation
if (s_R <= s_L) then
print *, 'WARNING: Wave speed issue detected in s_compute_wave_speed'
print *, 'Left wave speed >= Right wave speed:', s_L, s_R
print *, 'Input velocities :', vel_L(idx), vel_R(idx)
print *, 'Sound speeds:', c_L, c_R
print *, 'Densities:', rho_L, rho_R
print *, 'Pressures:', pres_L, pres_R
print *, 'Wave speeds method:', wave_speeds
if (elasticity .or. hypoelasticity .or. hyperelasticity) then
print *, 'Shear moduli:', G_L, G_R
end if
call s_mpi_abort('Error: Invalid wave speeds in s_compute_wave_speed')
end if
#endif

end subroutine s_compute_wave_speed
#endif

end module m_variables_conversion
Loading
Loading