Skip to content

Commit 4813f74

Browse files
committed
Fix zero-shear NaN/Inf in f_compute_hb_viscosity
When shear_rate == 0, the naive formula produces 0/0 (yield term) and 0^(nn-1) which is Inf for nn<1 (power-law term). Both corrupt viscosity and propagate into Re, fluxes, and dt. Fix: - Yield term: use analytic L'Hopital limit (1-exp(-m*g))/g -> m at g=0, so yield_term = tau0*hb_m when shear_rate <= verysmall - Power-law term: use g_eff = max(shear_rate, verysmall) so nn<1 fluids get a large-but-finite viscosity at rest, bounded by mu_max Addresses reviewer comment from qodo-code-review.
1 parent 3c636c5 commit 4813f74

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/simulation/m_hb_function.fpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module m_hb_function
1010

1111
use m_derived_types !< Definitions of the derived types
1212
use m_global_parameters !< Definitions of the global parameters
13+
use m_constants !< verysmall
1314

1415
implicit none
1516

@@ -34,11 +35,18 @@ contains
3435
real(wp), intent(in) :: mu_min_val, mu_max_val
3536
real(wp), intent(in) :: shear_rate, hb_m_val
3637
real(wp) :: mu
37-
real(wp) :: yield_term, power_law_term, exp_term
38-
39-
exp_term = exp(-hb_m_val*shear_rate)
40-
yield_term = tau0*(1._wp - exp_term)/shear_rate
41-
power_law_term = K_val*(shear_rate**(nn_val - 1._wp))
38+
real(wp) :: yield_term, power_law_term, g_eff
39+
40+
! Guard shear_rate == 0: naive formula gives 0/0 (yield) and 0^(nn-1) (power-law). Analytic limits: (1-exp(-m*g))/g -> m as
41+
! g->0 (L'Hopital); for the power-law term use g_eff = max(g, verysmall) so nn<1 fluids get a large-but-finite viscosity at
42+
! rest, consistent with mu_max clamping.
43+
g_eff = max(shear_rate, verysmall)
44+
if (shear_rate <= verysmall) then
45+
yield_term = tau0*hb_m_val
46+
else
47+
yield_term = tau0*(1._wp - exp(-hb_m_val*shear_rate))/shear_rate
48+
end if
49+
power_law_term = K_val*(g_eff**(nn_val - 1._wp))
4250
4351
mu = yield_term + power_law_term
4452
mu = max(mu, mu_min_val)

0 commit comments

Comments
 (0)