Skip to content

Commit 55ded73

Browse files
committed
Fix three bugs flagged in code review
1. check_non_newtonian() was never called from validate_simulation(), so all non-Newtonian parameter constraints were silently skipped. Also add required-field checks for K, nn, hb_m and an IGR prohibition. 2. Re_visc_nn was missing from private(...) in all four GPU_PARALLEL_LOOP calls in m_viscous.fpp, causing thread race conditions on GPU builds. 3. igr + non_newtonian is now prohibited at validation time: q_prim_vf sub-arrays are only allocated in the non-IGR path, so s_compute_dt would dereference unallocated storage with any_non_newtonian=.true.
1 parent 4813f74 commit 55ded73

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/simulation/m_viscous.fpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ contains
7474
#:if not MFC_CASE_OPTIMIZATION or num_dims > 1
7575
if (shear_stress) then ! Shear stresses
7676
$:GPU_PARALLEL_LOOP(collapse=3, private='[i, j, k, l, rho_visc, gamma_visc, pi_inf_visc, alpha_visc_sum , &
77-
& alpha_visc, alpha_rho_visc, Re_visc, tau_Re]')
77+
& alpha_visc, alpha_rho_visc, Re_visc, Re_visc_nn, tau_Re]')
7878
do l = is3_viscous%beg, is3_viscous%end
7979
do k = -1, 1
8080
do j = is1_viscous%beg, is1_viscous%end
@@ -168,7 +168,7 @@ contains
168168
#:if not MFC_CASE_OPTIMIZATION or num_dims > 1
169169
if (bulk_stress) then ! Bulk stresses
170170
$:GPU_PARALLEL_LOOP(collapse=3, private='[i, j, k, l, rho_visc, gamma_visc, pi_inf_visc, alpha_visc_sum , &
171-
& alpha_visc, alpha_rho_visc, Re_visc, tau_Re]')
171+
& alpha_visc, alpha_rho_visc, Re_visc, Re_visc_nn, tau_Re]')
172172
do l = is3_viscous%beg, is3_viscous%end
173173
do k = -1, 1
174174
do j = is1_viscous%beg, is1_viscous%end
@@ -255,7 +255,7 @@ contains
255255
if (p == 0) return
256256
#:if not MFC_CASE_OPTIMIZATION or num_dims > 2
257257
if (shear_stress) then ! Shear stresses
258-
$:GPU_PARALLEL_LOOP(collapse=3, private='[alpha_visc, alpha_rho_visc, Re_visc, tau_Re]')
258+
$:GPU_PARALLEL_LOOP(collapse=3, private='[alpha_visc, alpha_rho_visc, Re_visc, Re_visc_nn, tau_Re]')
259259
do l = is3_viscous%beg, is3_viscous%end
260260
do k = -1, 1
261261
do j = is1_viscous%beg, is1_viscous%end
@@ -345,7 +345,7 @@ contains
345345
end if
346346

347347
if (bulk_stress) then ! Bulk stresses
348-
$:GPU_PARALLEL_LOOP(collapse=3, private='[alpha_visc, alpha_rho_visc, Re_visc, tau_Re]')
348+
$:GPU_PARALLEL_LOOP(collapse=3, private='[alpha_visc, alpha_rho_visc, Re_visc, Re_visc_nn, tau_Re]')
349349
do l = is3_viscous%beg, is3_viscous%end
350350
do k = -1, 1
351351
do j = is1_viscous%beg, is1_viscous%end

toolchain/mfc/case_validator.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,12 @@ def check_viscosity(self):
883883
def check_non_newtonian(self):
884884
"""Checks constraints on non-Newtonian fluid parameters"""
885885
viscous = self.get("viscous", "F") == "T"
886+
igr = self.get("igr", "F") == "T"
886887
num_fluids = self.get("num_fluids", 1)
887888

889+
any_nn = any(self.get(f"fluid_pp({i})%non_newtonian", "F") == "T" for i in range(1, num_fluids + 1))
890+
self.prohibit(any_nn and igr, "non_newtonian is not supported with igr (primitive variable storage is not allocated in IGR mode)")
891+
888892
for i in range(1, num_fluids + 1):
889893
nn_flag = self.get(f"fluid_pp({i})%non_newtonian", "F") == "T"
890894
if not nn_flag:
@@ -899,6 +903,10 @@ def check_non_newtonian(self):
899903
mu_max = self.get(f"fluid_pp({i})%mu_max")
900904
hb_m = self.get(f"fluid_pp({i})%hb_m")
901905

906+
self.prohibit(K is None, f"fluid_pp({i})%K must be set when non_newtonian = T")
907+
self.prohibit(nn is None, f"fluid_pp({i})%nn must be set when non_newtonian = T")
908+
self.prohibit(hb_m is None, f"fluid_pp({i})%hb_m must be set when non_newtonian = T")
909+
902910
self.prohibit(K is not None and K <= 0, f"fluid_pp({i})%K (consistency index) must be > 0")
903911
self.prohibit(nn is not None and nn <= 0, f"fluid_pp({i})%nn (flow behavior index) must be > 0")
904912
self.prohibit(tau0 is not None and tau0 < 0, f"fluid_pp({i})%tau0 (yield stress) must be >= 0")
@@ -2111,6 +2119,7 @@ def validate_simulation(self):
21112119
self.check_bubbles_euler_simulation()
21122120
self.check_body_forces()
21132121
self.check_viscosity()
2122+
self.check_non_newtonian()
21142123
self.check_mhd_simulation()
21152124
self.check_igr_simulation()
21162125
self.check_acoustic_source()

0 commit comments

Comments
 (0)