Add Herschel-Bulkley non-Newtonian viscosity model#1298
Add Herschel-Bulkley non-Newtonian viscosity model#1298jasontruong2707 wants to merge 5 commits intoMFlowCode:masterfrom
Conversation
Review Summary by QodoAdd Herschel-Bulkley non-Newtonian viscosity model with dynamic Reynolds number computation
WalkthroughsDescription• Implements Herschel-Bulkley non-Newtonian viscosity model with Papanastasiou regularization for power-law, Bingham, and HB fluids • Replaces static viscous Reynolds arrays (Res_viscous, Res_gs, Res_pr) with dynamic computation via new m_re_visc module • Adds per-fluid non-Newtonian parameters: yield stress (tau0), consistency index (K), flow behavior index (nn), viscosity bounds (mu_max, mu_min, mu_bulk), and regularization parameter (hb_m) • Integrates non-Newtonian viscosity computation into time-stepping CFL calculations, Riemann solvers, and data output stability criteria • Adds validation for non-Newtonian fluid parameters in input checker • Extends MPI communication across pre-processing, simulation, and post-processing modules to broadcast non-Newtonian properties • Supports non-Newtonian viscosity in immersed boundary method calculations • Includes two validation cases: 2D Poiseuille flow and 2D lid-driven cavity with non-Newtonian fluids • Adds non-Newtonian parameter definitions to toolchain configuration • Maintains backward compatibility with Newtonian flows (non-Newtonian disabled by default) Diagramflowchart LR
A["Input Parameters<br/>non_newtonian, tau0, K, nn"] --> B["m_hb_function<br/>Herschel-Bulkley<br/>Viscosity Model"]
B --> C["m_re_visc<br/>Dynamic Re Computation"]
C --> D["Time Stepping<br/>CFL Calculation"]
C --> E["Riemann Solvers<br/>Viscous Fluxes"]
C --> F["Data Output<br/>Stability Criteria"]
G["Velocity Gradients"] --> C
H["Strain Rate Tensor"] --> B
File Changes1. src/simulation/m_time_steppers.fpp
|
Code Review by Qodo
1. non_newtonian lacks case validation
|
| _r(f"{px}non_newtonian", LOG, {"viscosity"}) | ||
| for a in ["tau0", "K", "nn", "mu_max", "mu_min", "mu_bulk", "hb_m"]: | ||
| _r(f"{px}{a}", REAL, {"viscosity"}) |
There was a problem hiding this comment.
1. non_newtonian lacks case validation 📘 Rule violation ⛯ Reliability
New HB parameters (fluid_pp(*)%non_newtonian, tau0, K, nn, mu_*, hb_m) are defined but not validated in toolchain/mfc/case_validator.py, allowing invalid configurations to pass toolchain checks. This should be validated in the toolchain since physics constraints are explicitly enforced in the Fortran input checker.
Agent Prompt
## Issue description
The PR introduces new non-Newtonian viscosity inputs (`fluid_pp(*)%non_newtonian`, `tau0`, `K`, `nn`, `mu_min`, `mu_max`, `mu_bulk`, `hb_m`) but the toolchain validator does not validate them, so invalid cases can pass toolchain checks and only fail later at runtime.
## Issue Context
Fortran-side validation was added in `src/simulation/m_checker.fpp`, indicating physics constraints apply and should also be enforced in `toolchain/mfc/case_validator.py` per the compliance checklist.
## Fix Focus Areas
- toolchain/mfc/case_validator.py[993-1024]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
| if (any_non_newtonian) then | ||
| if (igr) then | ||
| call s_compute_re_visc(q_cons_ts(1)%vf, alpha, j, k, l, Re_visc_per_phase) | ||
| else | ||
| call s_compute_re_visc(q_prim_vf, alpha, j, k, l, Re_visc_per_phase) | ||
| end if | ||
| call s_compute_mixture_re(alpha, Re_visc_per_phase, Re) |
There was a problem hiding this comment.
2. Igr uses conservative gradients 🐞 Bug ✓ Correctness
In s_compute_dt, the IGR branch calls s_compute_re_visc with q_cons_ts(1)%vf, but s_compute_re_visc differentiates q_prim_vf(momxb:), so it treats momenta as velocities and computes an incorrect shear rate and viscosity. This can yield an incorrect (potentially unstable) time step whenever any_non_newtonian and igr are enabled.
Agent Prompt
### Issue description
When `igr` is enabled, `s_compute_dt` calls `s_compute_re_visc` with `q_cons_ts(1)%vf` (conservative state). `s_compute_re_visc` assumes its first argument is primitive variables and differentiates `q_prim_vf(momxb:...)` as velocities, so the IGR path computes wrong shear rate/viscosity and thus wrong dt.
### Issue Context
`m_re_visc` computes velocity gradients directly from the provided field, without converting momenta to velocities.
### Fix Focus Areas
- src/simulation/m_time_steppers.fpp[748-754]
- src/simulation/m_re_visc.fpp[26-90]
### Suggested fix
- Option A (simplest): In `s_compute_dt`, ensure `q_prim_vf` is valid even when `igr` is true (perform conservative→primitive conversion when `any_non_newtonian` is true, or always for dt computation).
- Option B: Add a conservative-aware path in `s_compute_re_visc` (or a new routine) that computes velocities `u=mom/rho` at neighbor cells before differencing, and use that path from the IGR branch.
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughAdds Herschel–Bulkley non‑Newtonian support: eight new fields to the derived type physical_parameters (non_newtonian, tau0, K, nn, mu_min, mu_max, mu_bulk, hb_m); new modules m_hb_function and m_re_visc for HB viscosity and viscous/Re computations; input validation via s_check_inputs_non_newtonian; MPI broadcasts and GPU updates extended to the new fields; time‑stepper dt computation updated to use per‑phase viscous terms; pressure‑relaxation internals simplified; two example case scripts added; and CI workflow scripts reference shared frontier scripts. 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
New files
Test plan