@@ -1206,6 +1206,7 @@ contains
12061206 real(wp), dimension(num_fluids), intent(in) :: alpha_rho_K, alpha_K
12071207 #:endif
12081208 real(wp), intent(out) :: rho_K, gamma_K, pi_inf_K, qv_K
1209+ real(wp) :: gamma_i, pi_inf_i, dpi_i
12091210 integer :: i !< Loop iterator over fluids
12101211
12111212 ! The bubbly closure is written for one carrier liquid, which keeps its own coefficients
@@ -1227,8 +1228,14 @@ contains
12271228 $:GPU_LOOP(parallelism=' [seq]' )
12281229 do i = 1, num_fluids
12291230 rho_K = rho_K + alpha_rho_K(i)
1230- gamma_K = gamma_K + alpha_K(i)*gammas(i)
1231- pi_inf_K = pi_inf_K + alpha_K(i)*pi_infs(i)
1231+ if (any_state_dependent_eos) then
1232+ call s_eos_coefficients(alpha_rho_K(i)/max(alpha_K(i), sgm_eps), i, gamma_i, pi_inf_i, dpi_i)
1233+ else
1234+ gamma_i = gammas(i)
1235+ pi_inf_i = pi_infs(i)
1236+ end if
1237+ gamma_K = gamma_K + alpha_K(i)*gamma_i
1238+ pi_inf_K = pi_inf_K + alpha_K(i)*pi_inf_i
12321239 qv_K = qv_K + alpha_rho_K(i)*qvs(i)
12331240 end do
12341241 end if
@@ -1473,7 +1480,7 @@ contains
14731480
14741481 !> Speed of sound of a thermodynamic state. Enthalpy is not an argument: for a real state H, |u|^2 and qv all cancel out of c^2
14751482 !! = ((Gamma + 1)p + Pi)/(Gamma rho). Averaged states, whose enthalpy is a free input, use the _avg variant.
1476- subroutine s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c)
1483+ subroutine s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c, alpha_rho )
14771484
14781485 $:GPU_ROUTINE(parallelism=' [seq]' )
14791486
@@ -1484,8 +1491,14 @@ contains
14841491 real(wp), dimension(num_fluids), intent(in) :: adv
14851492 #:endif
14861493 real(wp), intent(out) :: c
1487- real(wp) :: alf !< Subgrid void fraction; dilute by construction
1488- integer :: q
1494+ #:if not MFC_CASE_OPTIMIZATION and USING_AMD
1495+ real(wp), dimension(3), intent(in), optional :: alpha_rho
1496+ #:else
1497+ real(wp), dimension(num_fluids), intent(in), optional :: alpha_rho
1498+ #:endif
1499+ real(wp) :: alf !< Subgrid void fraction; dilute by construction
1500+ real(wp) :: rho_q, gamma_q, pi_inf_q, dpi_q
1501+ integer :: q
14891502
14901503 if (chemistry) then ! Reacting mixture sound speed
14911504 c = sqrt((1.0_wp + 1.0_wp/gamma)*pres/rho)
@@ -1494,7 +1507,16 @@ contains
14941507 else
14951508 ! Every case below is a bulk modulus over a density. The equation of state enters
14961509 ! only through f_bulk_modulus; the cases differ in how the phases are mixed.
1497- if (alt_soundspeed) then ! Wood' s law: volume- weighted harmonic mean
1510+ if (any_state_dependent_eos .and. present(alpha_rho)) then ! frozen mixing: each phase' s modulus at its own density
1511+ c = 0._wp
1512+ $:GPU_LOOP(parallelism= ' [seq]' )
1513+ do q = 1 , num_fluids
1514+ rho_q = alpha_rho(q)/ max (adv(q), sgm_eps)
1515+ call s_eos_coefficients(rho_q, q, gamma_q, pi_inf_q, dpi_q)
1516+ c = c + adv(q)* (f_bulk_modulus(pres, gamma_q, pi_inf_q) - rho_q* dpi_q/ gamma_q)
1517+ end do
1518+ c = c/ rho
1519+ else if (alt_soundspeed) then ! Wood' s law: volume-weighted harmonic mean
14981520 c = 1._wp/(rho*(adv(1)/f_bulk_modulus(pres, gammas(1), pi_infs(1)) + adv(2)/f_bulk_modulus(pres, gammas(2), &
14991521 & pi_infs(2))))
15001522 else if (model_eqns == model_eqns_6eq) then ! volume-weighted arithmetic mean
@@ -1528,7 +1550,7 @@ contains
15281550 !> Speed of sound of an interface-averaged state. An average of two states is not a state - its enthalpy is not the one its
15291551 !! pressure and density imply - so the caller supplies H, |u|^2 and qv. Only the enthalpy-reading branches differ from
15301552 !! s_compute_speed_of_sound; keep the condition below in step with the branch list there.
1531- subroutine s_compute_speed_of_sound_avg (pres , rho , gamma , pi_inf , qv , vel_sum , H , c_c , adv , c )
1553+ subroutine s_compute_speed_of_sound_avg(pres, rho, gamma, pi_inf, qv, vel_sum, H, c_c, adv, c, alpha_rho )
15321554
15331555 $:GPU_ROUTINE(parallelism=' [seq]' )
15341556
@@ -1539,17 +1561,23 @@ contains
15391561 real(wp), dimension(num_fluids), intent(in) :: adv
15401562 #:endif
15411563 real(wp), intent(out) :: c
1564+ #:if not MFC_CASE_OPTIMIZATION and USING_AMD
1565+ real(wp), dimension(3), intent(in), optional :: alpha_rho
1566+ #:else
1567+ real(wp), dimension(num_fluids), intent(in), optional :: alpha_rho
1568+ #:endif
15421569
15431570 if (chemistry) then ! Reacting mixture sound speed
15441571 if (avg_state == avg_state_roe .and. abs(c_c) > verysmall) then
15451572 c = sqrt(c_c - (gamma - 1.0_wp)*(vel_sum - H))
15461573 else
1547- call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c)
1574+ call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c, alpha_rho )
15481575 end if
15491576 else if (relativity) then ! Relativistic sound speed
15501577 c = sqrt((1._wp + 1._wp/gamma)*pres/rho/H)
1551- else if (alt_soundspeed .or. model_eqns == model_eqns_6eq .or. (model_eqns == model_eqns_5eq .and. bubbles_euler)) then
1552- call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c)
1578+ else if (alt_soundspeed .or. model_eqns == model_eqns_6eq .or. (model_eqns == model_eqns_5eq .and. bubbles_euler) &
1579+ & .or. any_state_dependent_eos) then
1580+ call s_compute_speed_of_sound(pres, rho, gamma, pi_inf, adv, c, alpha_rho)
15531581 else ! Stiffened-gas mixture, the one branch where the averaged enthalpy survives
15541582 c = (H - 5.e-1*vel_sum - qv/rho)/gamma
15551583
0 commit comments