Skip to content

Cylindrical viscous operator: 1/r of the theta divergence and hoop terms, 2D axisymmetric stress, GPU face bounds (fixes #1910) - #2515

Merged
sbryngelson merged 9 commits into
MFlowCode:masterfrom
sbryngelson:cyl-viscous-1910
Nov 26, 2026
Merged

sbryngelson merged 9 commits into
MFlowCode:masterfrom
sbryngelson:cyl-viscous-1910

Conversation

@sbryngelson

@sbryngelson sbryngelson commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Closes #1910

Summary

The cylindrical viscous operator was missing metric terms. In 3D cylindrical coordinates (z = theta, dz in radians), the theta divergence of the viscous, conduction, species and surface-tension fluxes lacked a 1/r, and so did both hoop terms. The 2D axisymmetric path used the Cartesian (x, r) stress, so div u had no u_r/r term and the radial momentum had no -tau_thth/r hoop term. Cylindrical species diffusion also skipped its radial geometric term. This PR fixes all of these.

It also fixes a GPU-only defect found while testing: s_compute_cylindrical_viscous_source_flux looped over bounds that were never updated to the device, so on GPUs it skipped the first face of every sweep.

Term-by-term map

MFC: x = axial, y = r, z = theta. tau = mu (grad u + grad u^T) + (mu_b - 2 mu/3)(div u) I.

Term Where before
theta-face stresses (gradient-side 1/r) s_compute_cylindrical_viscous_source_flux, norm_dir = 3 correct
theta divergence (1/r) dF/dtheta: momentum, viscous work, conduction, species, surface tension s_compute_additional_physics_rhs, idir = 3 (m_rhs.fpp) missing 1/r; now 1/(dz*y_cc), as in the advection path
hoop -tau_thth/r on rho u_r, +tau_rth/r on rho u_theta (3D) same, grid_geometry == 3 block missing 1/r
r divergence (1/r) d(r F_r)/dr idir = 2 + geometric source correct for momentum and energy
conduction theta face gradient m_conduction.fpp had r^2 folded in; now carries one r (the divergence supplies the other), unchanged to round-off
species diffusion theta face gradient m_chemistry.fpp missing 1/r
species diffusion radial geometric term F/r, and radial species divergence on the axis-BC branch m_rhs.fpp idir = 2 missing / skipped
2D axisymmetric stress s_compute_viscous_source_flux now takes the cylindrical path for any cyl_coord Cartesian stress (no u_r/r in div u)
2D axisymmetric hoop -tau_thth/r on rho u_r new s_compute_axisym_viscous_hoop (cell-centred gradients) missing

GPU defect (found and fixed here)

s_compute_cylindrical_viscous_source_flux looped over its dummy bounds ix/iy/iz. These are m_rhs's irx/iry/irz, which are GPU_DECLARE(create) and set on the host only, so the device kernel ran with stale bounds and skipped face -1 in the sweep direction. s_compute_cartesian_viscous_source_flux already loops over isx/isy/isz, which s_populate_riemann_states_variables_buffers copies from the same bounds and updates to the device. The cylindrical routine now does the same, and the unused bounds arguments are removed from s_compute_viscous_source_flux and its four callers.

The defect was already in master's 3D cylindrical viscous path. There it skipped the x-face at j = -1 and the theta seam face at l = -1. Routing 2D axisymmetric through the same routine is what exposed it: on the GPU, FB822062 and 27A13E25 grew an axial momentum of 2.5e-11 in the first x column, where it should be exactly 0. A debug print of the x-face axial-momentum viscous flux in FB822062 (third call, k = 3, faces j = -1, 0, 1, 2):

F(-1) F(0) F(1) F(2)
CPU (GNU 12.3) -1.9197520475615920e-05 -1.9197520475615920e-05 -1.9197520475615920e-05 -1.9197520475615920e-05
GPU (Quadro RTX 6000, NVHPC 25.11), before 0 -1.9197520475615792e-05 -1.9197520475616178e-05 -1.9197520475615792e-05

All inputs at face -1 (u_r, its derivatives, Re) agree between CPU and GPU; that face was simply not computed. No tolerance was changed. With the fix, the GPU reproduces the CPU results.

Verification: manufactured solutions

examples/3D_cyl_viscous_mms runs one RK3 step of a manufactured velocity field on r in [0, 2] with the axis BC and mu = mu_b = 1. The viscous rate, (q with viscosity - q without)/dt, is compared with exact sympy rates at the cell centres. Errors are max norms over the interior rings, relative to the largest exact rate. Cases: (a) u_x = A (r/R)^2 cos th; (b) Taylor-Couette u_th = A (r + 0.5/r), exact force 0; (c) all three components with shear and bulk viscosity; (d) 2D axisymmetric u_x = A (r/R)^2, u_r = A (r/R)^3.

Case, component N = 32 64 128 256 order before the fix (N = 128)
(a) rho u_x 1.07e-3 2.68e-4 6.70e-5 2.0 0.289
(a) rho E 1.20e-3 2.95e-4 7.41e-5 2.0 0.124
(b) rho u_th 1.50e-2 3.81e-3 9.63e-4 2.0 1.00
(c) rho u_x 8.84e-4 3.27e-4 8.63e-5 1.9 0.075
(c) rho u_r 1.32e-3 3.23e-4 8.05e-5 2.0 0.107
(c) rho u_th 2.79e-3 7.94e-4 2.03e-4 2.0 0.257
(c) rho E 1.24e-3 2.93e-4 7.30e-5 2.0 0.078
(d) rho u_r 1.49e-3 5.30e-4 1.31e-4 3.27e-5 2.0 0.125
(d) rho E 8.19e-4 1.86e-4 4.60e-5 1.18e-5 2.0 0.038

Before the fix, the errors stay O(1) and match the rates of the defective operator. For example, case (a) gives (4 - r) mu A cos th / R^2 instead of 3 mu A cos th / R^2. Species diffusion (--case S2, S3: h2o2 at rest, uniform T and p, unity Lewis, Y_H2 = Y0 + 1e-3 (r/R)^2, times cos th in 3D). The script compares the rate of rho Y_H2 with its exact value. That value uses rho D = k/cp from Cantera; in 2D it includes the 2 r d(rho D)/dr term, because rho D follows the local composition. The errors are max norms relative to the exact mean:

case N = 32 64 128
S2 (2D axisymmetric) 6.7e-6 1.7e-6 5.4e-7
S3 (3D cylindrical) 1.07e-3 2.67e-4

The N = 32 and 64 runs were repeated on this exact branch, on Phoenix:

case, component N GNU 12.3 CPU Quadro RTX 6000, NVHPC 25.11
(a) rho u_x 32 / 64 1.070e-3 / 2.676e-4 1.070e-3 / 2.677e-4
(b) rho u_th 32 / 64 1.497e-2 / 3.806e-3 1.497e-2 / 3.806e-3
(c) rho u_th 32 / 64 2.790e-3 / 7.941e-4 2.790e-3 / 7.941e-4
(d) rho u_r 32 / 64 1.488e-3 / 5.297e-4 1.488e-3 / 5.297e-4

Tests and goldens

New tests. Goldens were generated on Phoenix with GNU 12.3 + OpenMPI 4.1.5 (double, CPU), from the committed branch. Master's source, run against these goldens, fails every one of them (tolerance mismatch):

UUID Test Covers
872A4241 3D -> Cylindrical -> Viscous -> Azimuthal swirl plus an off-centre theta wedge with radial velocity: the theta divergence and both 3D hoop terms
F1BD319C 2D -> Axisymmetric -> Viscous -> Radial O(0.1) axial and radial velocity: u_r/r in div u and the 2D hoop term -tau_thth/r (the existing 2D tests start at rest and cannot detect it)
D432D8B0 Cylindrical Species Diffusion -> 2D Axisymmetric radial geometric term and the axis cell of species diffusion
02772BF1 Cylindrical Species Diffusion -> 3D Cylindrical theta face gradient and divergence (mixture-averaged transport)
AF351991 Cylindrical Species Diffusion -> 3D Cylindrical -> Unity Lewis the same, unity-Lewis transport
  • No existing golden changed. All 59 tests whose names match Cylindrical, Axisymmetric or cyl pass on the CPU and on the GPU.
  • examples/3D_cyl_viscous_mms is excluded from the example-case test, because run_mms.py writes its initial state between pre_process and simulation. The tests above cover its code paths.

Floating-point traps at the axis face (#2510)

The radial sweep evaluated /r_eff at the axis face, where r_eff = y_cb(-1) = 0. That face's flux is never used, so ordinary builds were unaffected, but a trapping build stopped there. The kernel now uses a unit radius on that face. Two tests, built with GNU 12.3 on Phoenix with traps for invalid, divide-by-zero and overflow turned on after MPI_Init (an LD_PRELOAD feenableexcept):

07C33719 3D -> Cylindrical -> Viscous 09623DE3 ... -> weno_Re_flux -> weno_avg
master 73816da SIGFPE SIGFPE
this branch pass pass

This covers the axis-face part of #2510 for these two tests; the AMD flang checked build is being handled in #2510 itself.

Review fixes

  • Under not MFC_CASE_OPTIMIZATION and USING_AMD, vel_src_int has dimension 3. It is now assigned as vel_src_int(1:num_dims), which keeps the size-2 slice in 2D conforming.
  • The derive_rates.py output path is now relative to the script.

Not covered

This PR was made with Claude Code (AI).

@sbryngelson
sbryngelson requested a review from a team as a code owner November 26, 2026 06:54
@sbryngelson
sbryngelson requested review from danieljvickers and removed request for a team November 26, 2026 06:54
@sbryngelson

Copy link
Copy Markdown
Member Author

Hand test of 61627e6 on Phoenix (GT). Cylindrical/axisymmetric set: the 55 tests whose names match Cylindrical, Axisymmetric or cyl, including FB822062, 27A13E25 and the new 872A4241.

Machine Compiler Device Tests MMS (a)-(d), N = 32, 64
Phoenix cpu-small GNU 12.3 + OpenMPI 4.1.5, double CPU 55 passed / 0 failed second-order errors, table in the PR body
Phoenix gpu-rtx6000 NVHPC 25.11 (CUDA 12.9), OpenACC, double Quadro RTX 6000 (driver 580.178.04) 55 passed / 0 failed match the CPU to 3-4 digits in every ring

The 872A4241 golden was generated on the CPU lane above. Before the bounds fix (50fefd1), the same GPU lane failed FB822062, 27A13E25 and 872A4241. ./mfc.sh precheck passes.

AI-assisted (Claude Code).

@github-actions

Copy link
Copy Markdown

Claude Code Review

Head SHA: 61627e6

Files changed:

  • 18 in changed_files.txt (the PR also adds tests/872A4241/golden.txt and golden-metadata.txt)
  • src/simulation/m_riemann_state.fpp
  • src/simulation/m_rhs.fpp
  • src/simulation/m_viscous.fpp
  • src/common/m_chemistry.fpp
  • src/simulation/m_conduction.fpp
  • src/simulation/m_riemann_solver_hll.fpp
  • src/simulation/m_riemann_solver_hllc.fpp
  • toolchain/mfc/test/cases.py
  • docs/documentation/validation_coordinates.md
  • examples/3D_cyl_viscous_mms/run_mms.py

Summary: The PR makes four changes:

  • adds the missing 1/r to the 3D cylindrical theta divergence and to both hoop terms (Does the viscous azimuthal term have the divergence-side 1/r in 3D cylindrical? #1910);
  • sends 2D axisymmetric viscous flux through the cylindrical stress, with a new cell-centred -tau_thth/r term;
  • fixes cylindrical species diffusion: the theta-face 1/r, the radial F/r term and the axis branch;
  • makes s_compute_cylindrical_viscous_source_flux loop over the device-updated isx/isy/isz.

I checked each metric term, the axis-cell flux cancellation on both grid types, the GPU-bounds diagnosis and the MMS exact rates (cases A3, B3 and E2 re-derived by hand). All are consistent with the code. The one code defect is a shape mismatch in the newly reached 2D path, in AMD flang builds without case optimization. The rest are test-coverage gaps and limits that are not documented.

Findings:

  • medium src/simulation/m_riemann_state.fpp:899 (likely): Shape mismatch in the 2D path, in AMD flang builds without case optimization.
    • Cause: line 285 changes the dispatch from grid_geometry == 3 to cyl_coord. That sends 2D axisymmetric runs into s_compute_cylindrical_viscous_source_flux, which only 3D reached before.
    • The mismatch: under #:if not MFC_CASE_OPTIMIZATION and USING_AMD (line 793), vel_src_int is dimension(3) (line 798). Lines 899, 909 and 919 assign it vel_src_rsx_vf(j, k, l,1:num_dims). With num_dims = 2 this assigns a size-2 section to a size-3 non-allocatable array, which the standard does not allow.
    • Possible consequences: vel_src_rsx_vf is allocated 1:num_vels (m_riemann_solvers.fpp:103), which is 2 in 2D without MHD. If the assignment is lowered as a loop over the left-hand side, it reads one slab past the end of the allocation. If it goes through flang's runtime Assign, that call aborts on mismatched element counts. I can't tell which happens without the compiler.
    • Why 2D was safe before: the Cartesian routine fills the same buffer with an explicit do i_dim = 1, num_dims loop (lines 1113-1137).
    • Exposure: the Frontier AMD lane (amdflang, OpenMP, no --case-optimization) runs FB822062 and 27A13E25. The PR's hand tests used only GNU on CPU and NVHPC.
    • Fix: in all three branches, use vel_src_int(1:num_dims) = vel_src_rsx_vf(j, k, l, 1:num_dims), or the Cartesian routine's loop.
  • medium toolchain/mfc/test/cases.py:1198 (confident): No regression test is sensitive to the 2D axisymmetric viscous change.
    • Untested code: s_compute_axisym_viscous_hoop and the u_r/r term that now enters the 2D stress through the cylindrical routine.
    • Evidence: the PR says FB822062 and 27A13E25 still pass against their old goldens. In those tests the fluid starts at rest (all patch vel = 0) and runs 50 steps of dt = 1e-11, so the momenta are tiny. The comparator passes any value within 1e-11 absolute for Axisymmetric traces (Tolerance(tol, tol) in test.py:914, is_close in packer/tol.py:60). Removing the new hoop term, or flipping its sign, would therefore fail no test.
    • The new test doesn't help here: 872A4241 is 3D and never calls the 2D routine.
    • Fix: add a 2D analogue in alter_2d: the Viscous stack with a nonzero patch_icpp(i)%vel(2) that is large enough for u_r/r and tau_thth/r to exceed 1e-11. Confirm that master fails it, as was done for 872A4241.
  • medium src/simulation/m_rhs.fpp:2062 (confident): The species-diffusion fixes have no test and no reproduction script.
    • Affected code: the theta-face 1/r in both transport models (m_chemistry.fpp:434, 604), the radial species divergence on the axis branch (m_rhs.fpp:2062-2082), and the new radial geometric term (m_rhs.fpp:2166-2180). These change results for every 2D axisymmetric and 3D cylindrical run with chem_params%diffusion.
    • No test: no test in cases.py and no example combines cyl_coord = T with chem_params%diffusion = T.
    • No script: validation_coordinates.md:55 reports an h2o2 result (rate flat in r to 4e-4 and 5e-4, 3D/2D ratio 0.7503). But run_mms.py and case.py have no chemistry case, and the Reproduce block lists only A3, B3, C3 and E2.
    • Fix: add the species case to examples/3D_cyl_viscous_mms, plus a small chemistry-diffusion test in 2D axisymmetric and 3D cylindrical.
  • low src/simulation/m_rhs.fpp:2072 (confident): With viscosity and chemistry diffusion both on, the axis cell's energy row misses the diffusive enthalpy flux that its species now get.
    • What happens: at k = 0 the species now diffuse radially through face 0. The energy row still takes only the viscous part (tau_Re_vf), so lambda*grad T + sum h_k J_k through that face is missing. Cell 1 does receive it through the same face. Species therefore move in and out of the axis cell at fixed energy, and its temperature shifts with composition.
    • What changed: before the PR the axis rank had no radial species diffusion at all, so the k = 0 row was missing both terms, which is at least consistent.
    • Who it affects: viscous reacting axisymmetric runs, such as jets and flames.
    • Documentation: the PR body lists this under "Not covered". The code comment ("Without viscosity the axis cell's energy row takes the same form") and the Limits paragraph (validation_coordinates.md:57) don't say what happens with viscosity.
    • Fix: state the consequence in both places, or add only the chemistry part of F_E(0) to the k = 0 row. The face -1 term cancels on these grids, so it isn't needed.
  • low src/simulation/m_rhs.fpp:2237 (confident): For surface tension, the theta-face hoop terms changed too, not only the theta divergence the PR mentions.
    • Why: the hoop block is not gated on viscous, and m_surface_tension writes the capillary stresses into the same flux_src_rsx_vf(mom) theta-face slots. So 3D cylindrical surface tension now also gets -sigma_thth/r and +sigma_rth/r.
    • Mismatch: the PR description says "only its theta divergence now carries the 1/r".
    • Exposure: surface_tension with p > 0 and cyl_coord passes the validator, and no test covers it.
    • Fix: correct the description and validation_coordinates.md:57 so users know both terms changed.
  • low examples/3D_cyl_viscous_mms/derive_rates.py:67 (confident): open("exact_rates.py", "w") writes to the current working directory.
    • Effect: run_mms.py imports exact_rates from its own directory (sys.path.insert(0, HERE)), and the documented commands run from the repository root. Regenerating the rates from there leaves a stray ./exact_rates.py and the example's copy stale.
    • Fix: write to os.path.join(os.path.dirname(os.path.abspath(__file__)), "exact_rates.py").

Coverage:

  • Read in the post-change context:
    • m_conduction.fpp: in full.
    • m_chemistry.fpp: s_compute_chemistry_diffusion_flux and its helpers (lines 330-738).
    • m_rhs.fpp: s_compute_additional_physics_rhs in full, s_compute_directional_rhs, and the RHS driver around the call.
    • m_riemann_state.fpp: lines 1-1173, which cover the dispatcher, s_populate_riemann_states_variables_buffers, s_initialize_riemann_solver, and both viscous source-flux routines.
    • m_viscous.fpp: lines 1-430, which cover s_compute_axis_inv_re, s_compute_viscous_stress_cylindrical_boundary and the new hoop routine.
    • HLL and HLLC: both viscous call sites.
    • cases.py: alter_2d, alter_3d and the example skip list.
    • Docs: validation_coordinates.md and the cylindrical section of equations.md.
    • From the diff, in full: all of the new example files.
    • Not reviewed: the PNG (binary) and the golden values, which I could only check through their metadata.
  • Traced in the base checkout:
    • Where grid_geometry is set and updated to the device.
    • The validator's cylindrical BC rules (2D needs -2, 3D needs -14, no 1D cyl_coord), LF + cylindrical viscous rejection, conduction + chemistry rejection, and AMR/IGR being Cartesian only.
    • The 2D axisymmetric half-cell grid (m_grid.f90) and the ghost y_cc(-1) mirror (m_boundary_common.fpp). Together they confirm the face -1 species flux is finite and cancels in the axis cell.
    • Every reader of flux_src_rsx_vf (m_ibm, m_cbc, m_amr_registers, m_rhs). None of them uses the 0/0 that 2D now writes at the axis face k = -1.
    • irx/iry/irz are never device-updated, and isx/isy/isz are updated in s_populate_riemann_states_variables_buffers. No other kernel still loops over the ix/iy/iz dummies.
    • VCFL already uses the Fourier-filtered r*dtheta (m_sim_helpers.fpp), which matches the corrected operator's stiffness.
    • USING_AMD is defined as LLVMFlang, and the CI matrix shows the Frontier AMD lane runs without --case-optimization.
    • The test tolerance path (compute_tolerance, packer/tol.py), and the test hash: 872A4241 matches its trace.
    • The golden metadata: generated at 50fefd1, and the last commit adds only the golden and a doc line.
  • Linked issue and PR discussion: read issue Does the viscous azimuthal term have the divergence-side 1/r in 3D cylindrical? #1910 and the PR comments; the PR fixes what the issue reports.
  • Pre-existing, not counted as a finding: in chemistry-only cylindrical runs, s_initialize_riemann_solver never zeroes the momentum slots of flux_src_rsx_vf. Yet three loops read them: the axis branch's k = 1..n loop over mom..E, the geometric loop, and the 3D hoop block. That is worth checking on GPU, where newly allocated memory is not guaranteed to be zero.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Claude Code Review

Head SHA: 6acc8a9

Files changed:

  • 18 in changed_files.txt (the PR also adds tests/872A4241/golden.txt and golden-metadata.txt)
  • src/simulation/m_rhs.fpp
  • src/simulation/m_viscous.fpp
  • src/simulation/m_riemann_state.fpp
  • src/simulation/m_riemann_solver_hll.fpp
  • src/simulation/m_riemann_solver_hllc.fpp
  • src/simulation/m_conduction.fpp
  • src/common/m_chemistry.fpp
  • toolchain/mfc/test/cases.py
  • docs/documentation/validation_coordinates.md
  • examples/3D_cyl_viscous_mms/run_mms.py

Summary: The PR makes four changes to the cylindrical operator:

  • adds the missing 1/r to the 3D theta divergence and to both hoop terms;
  • sends 2D axisymmetric viscosity through the cylindrical face stress, with a new cell-centred -tau_thth/r routine;
  • adds the cylindrical metric terms to species diffusion;
  • makes the cylindrical viscous kernel loop over the device-updated isx/isy/isz bounds.

I checked every term against the cylindrical Navier-Stokes operator, plus the r = 0 face cancellation on both axis grids, the conduction refactor (unchanged to round-off) and the GPU-bounds diagnosis. All are correct. What remains:

  • a non-conforming array assignment on the newly reached 2D path in amdflang builds;
  • no regression test that can detect the 2D or species changes;
  • a 0/0 at the 2D axis face, which matters only under FPE traps;
  • several places where the docs and comments disagree with the code.

Findings:

  • medium src/simulation/m_riemann_state.fpp:899 (likely): The 2D re-route reaches a non-conforming array assignment in amdflang builds without case optimization.
    • Cause: line 285 now sends every cyl_coord run into s_compute_cylindrical_viscous_source_flux, which only 3D reached before.
    • The mismatch: under #:if not MFC_CASE_OPTIMIZATION and USING_AMD (line 793), vel_src_int is dimension(3) (line 798). Lines 899, 909 and 919 assign it vel_src_rsx_vf(j, k, l,1:num_dims), which is a size-2 section in 2D. vel_src_rsx_vf is allocated 1:num_vels (m_riemann_solvers.fpp:103).
    • Possible consequences:
      • If flang lowers the assignment as a loop over the left-hand side's constant extent, each thread reads vel_src_rsx_vf(j,k,l,3), up to one full component slab past the end of the device allocation.
      • If it lowers it through flang's runtime Assign, that call aborts on mismatched element counts.
    • What CI shows: the value is unused in 2D, and FB822062 and 27A13E25 passed on both Frontier AMD shards at test grid size. The realistic risk is a GPU memory-access fault on production-size 2D grids.
    • Why 2D was safe before: 2D used the Cartesian routine, whose explicit do i_dim = 1, num_dims loops (lines 1113-1137) are safe.
    • Fix: in all three branches, use vel_src_int(1:num_dims) = vel_src_rsx_vf(j, k, l, 1:num_dims), or the Cartesian loop.
  • medium toolchain/mfc/test/cases.py:1063 (confident): No regression test can detect the 2D axisymmetric fix.
    • Untested code: s_compute_axisym_viscous_hoop and the u_r/r term that the cyl_coord dispatch now puts into the 2D stress.
    • Evidence:
      • The only 2D axisymmetric viscous tests, FB822062 and 27A13E25, start at rest and run 50 steps of dt = 1e-11.
      • The author's measurement in Does the viscous azimuthal term have the divergence-side 1/r in 3D cylindrical? #1910 shows max |ρu_r| moving from 6.19996e-9 to 6.19368e-9, a change of 6.3e-12.
      • The comparator passes anything within 1e-11 absolute for "Axisymmetric" traces (toolchain/mfc/test/case.py:474-475, Tolerance(tol, tol) at test.py:914, is_close in packer/tol.py:60).
      • So reverting the new hoop routine or the dispatch change would still pass every test.
    • The new test doesn't help here: 872A4241 is 3D (grid_geometry == 3) and never calls the 2D routine.
    • Overstated coverage: the skip-list comment at line 4046 ("covered by 3D -> Cylindrical -> Viscous -> Azimuthal") and the PR text "872A4241 covers the same code paths" both overstate it. The excluded example also holds the 2D case E2.
    • Fix: add a 2D variant to the alter_2d Viscous stack with O(0.1) radial velocity (patch_icpp(i)%vel(2)) and moderate Re. Confirm that master fails it, as was done for 872A4241.
  • medium src/simulation/m_rhs.fpp:2062 (confident): The cylindrical species-diffusion changes have no test and no reproducer.
    • Affected code:
      • the radial species divergence on the axis rank (lines 2062-2082);
      • the new radial geometric term F/r (lines 2166-2180);
      • the theta-face 1/r in both transport models (m_chemistry.fpp:434, 604).
    • Who it affects: results change for every 2D axisymmetric and 3D cylindrical run with chem_params%diffusion.
    • No test: no test in cases.py and no example combines cyl_coord = T with chemistry diffusion; every chemistry example sets cyl_coord = F. Codecov reports 0% patch coverage for the m_chemistry.fpp lines and 25% for m_rhs.fpp.
    • No reproducer: the h2o2 results in validation_coordinates.md:55 (rate flat in r to 4e-4 and 5e-4, 3D/2D ratio 0.7503) can't be rerun. run_mms.py and case.py accept only A3, B3, C3 and E2, and have no chemistry.
    • Fix: add the species case to examples/3D_cyl_viscous_mms, plus a small 2D axisymmetric and 3D cylindrical chemistry-diffusion test.
  • low src/simulation/m_riemann_state.fpp:925 (likely): 2D axisymmetric viscous runs now compute 0/0 at the axis face.
    • What happens: for norm_dir = 2, isy%beg = -1 and r_eff = y_cb(-1) = 0 (line 910; m_grid.f90:80). The reflective ghost makes avg_v_int(2) exactly 0, so divergence_cyl and flux_src_rsx_vf(j,-1,l,mom..E) are NaN.
    • Nothing reads these values:
      • the axis branch differences mom..E from k = 1 and uses tau_Re_vf at k = 0;
      • the IB face booking needs a body on exactly one side of a face, and an axisymmetric body is mirror-symmetric about r = 0.
    • Where it matters: normal builds are unaffected. Cray Debug and RelDebug builds compile with -K trap=fp (cmake/GPU.cmake:97,104), so a Cray CPU debug run of any 2D axisymmetric viscous case would now stop on the first y-sweep. No CI lane runs that configuration.
    • Note: 3D already had the same latent division at this face.
    • Fix: skip the /r_eff terms when r_eff == 0; that face's flux is unused.
  • low src/simulation/m_rhs.fpp:2072 (confident): With viscosity and chemistry diffusion both on, the axis cell's species now diffuse through face 0, but its energy row does not get the matching flux.
    • What happens:
      • The k = 0 energy row still takes only the viscous part (tau_Re_vf, lines 2032-2044 and 2138-2149).
      • It misses λ∂T/∂r + Σh_kJ_k through face 0, which cell 1 does receive (lines 2046-2058).
      • So energy is not conserved across face 0, and the axis cell's temperature drifts with its composition.
    • Who it affects: viscous reacting axisymmetric runs, such as jets and flames.
    • Documentation: the PR body lists this under "Not covered". The code comment (lines 2060-2061) says only "Without viscosity the axis cell's energy row takes the same form", and the Limits paragraph (validation_coordinates.md:57) doesn't mention it.
    • Fix: state the limitation in both places, or keep the chemistry energy flux in its own slot so the k = 0 row can add it.
  • low docs/documentation/validation_coordinates.md:57 (confident): For surface tension in 3D cylindrical coordinates, which the validator accepts, the docs and the PR description don't match the code.
    • What the code now does:
      • The color-function term and the theta divergence of the capillary fluxes carry 1/r (m_rhs.fpp:2189-2192, 2204-2211).
      • So do the hoop terms (lines 2232-2248). That block is not gated on viscous, and m_surface_tension.fpp:227 writes the capillary theta-face momentum fluxes into the same slots.
      • The capillary theta gradient c_divs(3) (m_surface_tension.fpp:282) still has no 1/r.
    • What the text says:
      • line 57: surface tension "has no cylindrical metric terms";
      • equations.md:428: every θ derivative carries 1/r, in both the face gradient and the divergence;
      • the PR body: "only its theta divergence now carries the 1/r".
    • Fix: describe the actual split in both docs. Alternatively, add the gradient 1/r, or prohibit the combination in case_validator.py.
  • low examples/3D_cyl_azimuthal_conduction_convergence/compare_analytic.py:14 (confident): The edited docstring is now wrong.
    • The text: it attributes the θ term to "the two 1/r factors (the face gradient in m_conduction, the divergence in m_rhs)", but keeps "Dropping either metric factor multiplies that half by r**2".
    • The error: with the two factors in separate places, dropping either one multiplies that half by r. Only dropping both gives r**2.
    • Fix: correct the sentence.
  • low examples/3D_cyl_viscous_mms/derive_rates.py:67 (confident): open("exact_rates.py", "w") writes to the current working directory.
    • Effect: run_mms.py imports exact_rates from the example directory (sys.path.insert(0, HERE)), and the documented commands run from the repository root. Regenerating the rates from there leaves a stray ./exact_rates.py and the example's copy stale.
    • Fix: write to os.path.join(os.path.dirname(os.path.abspath(__file__)), "exact_rates.py").

Coverage:

  • Read in the post-change context:
    • m_conduction.fpp: in full.
    • m_rhs.fpp: s_compute_additional_physics_rhs in full, plus s_compute_directional_rhs, the RHS driver (lines 640-920) and the gradient and tau_Re_vf allocations.
    • m_riemann_state.fpp: the dispatcher, s_populate_riemann_states_variables_buffers, s_initialize_riemann_solver, and both viscous source-flux routines.
    • m_viscous.fpp: lines 1-1180, covering s_compute_axis_inv_re, the axis stress, the new hoop routine, s_get_viscous, the divergence theorem and s_compute_fd_gradient.
    • m_chemistry.fpp: s_compute_chemistry_diffusion_flux, both transport models.
    • HLL and HLLC: both viscous call sites, and the buffer-population call that comes before them.
    • cases.py: get_dimensions, alter_2d, alter_3d and the example skip list.
    • Docs: validation_coordinates.md in full, and the edited sections of equations.md and validation.md.
    • From the diff, in full: every new example file, and the compare_analytic.py docstring.
    • Not reviewed: the PNG (binary). The 872A4241 golden was checked only for presence.
  • Traced in the base checkout:
    • The axisymmetric half-cell grid (m_grid.f90): y_cc(0) = dy(0)/2 on both axis grids, so the r = 0 species face cancels exactly.
    • Validator constraints:
      • bc_y%beg must be -2 in 2D and -14 in 3D;
      • heat conduction with chemistry is prohibited;
      • surface tension is allowed with cyl_coord;
      • IB thermal options, AMR and IGR are Cartesian only.
    • flux_src_rsx_vf: its allocation and per-sweep zeroing, and every reader (m_ibm face booking, m_amr_registers, m_cbc).
    • GPU state:
      • irx/iry/irz are never device-updated;
      • isx/isy/isz are assigned only in the buffer-population routine;
      • no other kernel still loops over the dummy bounds.
    • The diffusive CFL already uses the Fourier-filtered r*dθ (m_sim_helpers.fpp), which matches the stiffer corrected operator.
    • grid_geometry is declared in all three targets and is GPU_DECLAREd and updated in simulation.
    • The MFC_OMP_PRESENT_ALLOCATABLE opt-in in m_rhs and the GPU private/scalar-argument traps: the new kernels comply.
    • Debug flags in cmake/GPU.cmake: only Cray enables FP traps.
    • The test tolerance path, and the trace-to-UUID mapping for FB822062, 27A13E25 and 872A4241.
  • History, issue and CI:
    • Issue Does the viscous azimuthal term have the divergence-side 1/r in 3D cylindrical? #1910 and its comments, including the FB822062 measurement; the PR fixes what the issue asks.
    • The PR thread, including two earlier automated reviews of 61627e6. The compare 67a8bc3...6acc8a9 shows that only run_mms.py changed since then, so the AMD assignment, test-coverage, surface-tension and derive_rates.py points raised there are still open. I re-derived each one here.
    • I disagree with one earlier claim: that no build enables FPE traps. Cray Debug and RelDebug do.
    • CI:
      • The NVHPC 25.5 cpu/gpu-omp and 26.9 cpu failures are apt mirror-sync errors, not code.
      • The Frontier AMD and CCE test shards passed, including FB822062, 27A13E25 and 872A4241.
      • The Phoenix lanes were still pending.

@sbryngelson

Copy link
Copy Markdown
Member Author

Rebased onto master 10e1299 (after #2491); head is now 67a8bc3.

AI-assisted (Claude Code).

@sbryngelson

Copy link
Copy Markdown
Member Author

GPU rerun on the exact head 67a8bc3, i.e. on master 10e1299 after #2491's device-side time-stepping change. Phoenix gpu-rtx6000, Quadro RTX 6000 (driver 580.178.04), NVHPC 25.11 (CUDA 12.9), OpenACC, double, built fresh. Result on the same 55 cylindrical/axisymmetric tests as the CPU run: 55 passed / 0 failed. This includes 872A4241, FB822062 and 27A13E25, and the three goldens #2491 regenerated (9C9B2CBC, B85C5AB6, C0127FD0).

AI-assisted (Claude Code).

@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.21311% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.59%. Comparing base (c158eee) to head (34fd9b7).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/simulation/m_viscous.fpp 57.14% 6 Missing and 3 partials ⚠️
src/simulation/m_rhs.fpp 75.00% 1 Missing and 5 partials ⚠️
src/common/m_chemistry.fpp 0.00% 2 Missing ⚠️
src/simulation/m_riemann_state.fpp 77.77% 0 Missing and 2 partials ⚠️
src/simulation/m_conduction.fpp 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2515      +/-   ##
==========================================
- Coverage   66.59%   66.59%   -0.01%     
==========================================
  Files         112      112              
  Lines       31558    31602      +44     
  Branches     4856     4869      +13     
==========================================
+ Hits        21015    21044      +29     
- Misses       6561     6566       +5     
- Partials     3982     3992      +10     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…rms, 2D axisymmetric stress (fixes MFlowCode#1910)

3D cylindrical (theta = z, dz in radians):
- m_rhs: the theta divergence of the viscous, conduction, species and
  surface-tension fluxes is (1/r) dF/dtheta (was dF/dtheta), as in the
  advection path; the hoop sources -tau_thth/r and +tau_rth/r carry their 1/r.
- m_conduction: the theta face gradient carries one 1/r (was r^2 folded in),
  the divergence the other; unchanged to round-off.
- m_chemistry: the theta face gradient of the species diffusion carries 1/r.

Cylindrical species diffusion (2D and 3D): the radial geometric term F/r for
the species rows, and the radial species divergence on the axis-BC branch,
which skipped it.

2D axisymmetric viscous: the face fluxes use the cylindrical stress (div u
with u_r/r), and s_compute_axisym_viscous_hoop adds -tau_thth/r.

Verified against manufactured solutions (examples/3D_cyl_viscous_mms): every
component converges at second order; before, the errors stay O(1) and match
the defective operator. New test 3D -> Cylindrical -> Viscous -> Azimuthal.
…/isz bounds

The kernel looped over its dummy bounds (m_rhs irx/iry/irz, GPU_DECLARE create,
never updated to the device), so on GPUs the first face (j/k/l = -1) was skipped.
The Cartesian routine already uses isx/isy/isz; the unused bounds arguments are
dropped.
…e radius, 2D axisymmetric radial-flow and cylindrical species-diffusion tests, species MMS cases (S2, S3), MFlowCode#2513 noted
…eal-gas fix; goldens for the four new cylindrical tests; validation page species results
@sbryngelson

Copy link
Copy Markdown
Member Author

Review addressed at a82b66d, rebased onto master c158eee (#2505, #2514, #2508). The rebase had two trivial conflicts: master's E-row condition in the theta divergence, and master's new alpha_sum private variable.

Finding Change
(medium) vel_src_int shape under not MFC_CASE_OPTIMIZATION and USING_AMD all three branches now assign vel_src_int(1:num_dims) = vel_src_rsx_vf(j, k, l, 1:num_dims)
(medium) no 2D axisymmetric viscous test detects the fix new F1BD319C 2D -> Axisymmetric -> Viscous -> Radial (O(0.1) axial and radial velocity); master fails it; the skip-list comment and the PR text no longer credit 872A4241 with 2D coverage
(medium) species diffusion has no test or reproducer new D432D8B0 (2D axisymmetric), 02772BF1 (3D cylindrical) and AF351991 (3D, unity Lewis); master fails all three. examples/3D_cyl_viscous_mms gains --case S2 and S3 (h2o2 at rest, set with Cantera, exact rate with rho D = k/cp, including the 2D 2 r d(rho D)/dr term); second order, table in the PR body
(low) 0/0 at the axis face r_eff is set to 1 on the r = 0 face, whose flux is unused. 07C33719 and 09623DE3, built with GNU 12.3 and FP traps for invalid, divide-by-zero and overflow turned on after MPI_Init, raise SIGFPE on master 73816da and pass on this branch (#2510)
(low) axis-cell energy with viscosity and chemistry the code comment and the validation page now point to #2513
(low) surface-tension hoop terms the validation page and the PR body now state that the 3D theta-face hoop terms carry the 1/r too
(low) derive_rates.py output path now written next to the script

Evidence, on the pre-rebase head 1112d3b6 (same Fortran except the rebase resolutions):

Check Phoenix CPU, GNU 12.3 + OpenMPI 4.1.5 Phoenix GPU, Tesla V100-PCIE-16GB, NVHPC 25.11, OpenACC
59 cylindrical/axisymmetric tests, incl. the 5 new ones 59 passed (new goldens generated here) 59 passed
S2 max error, N = 32 / 64 6.75e-6 / 1.66e-6 (N = 128: 5.36e-7) 6.75e-6 / 1.57e-6
S3 max error, N = 32 / 64 1.069e-3 / 2.671e-4 1.069e-3 / 2.671e-4
E2 rho u_r error, N = 32 / 64 1.488e-3 / 5.297e-4 1.488e-3 / 5.297e-4

The CPU rerun of the 59 tests on a82b66d is still running; I will post its result here when it finishes. This push touches Fortran in src/: m_riemann_state.fpp (the slice and the axis-face radius) and m_rhs.fpp (a comment, plus the axis-cell species energy row condition, which now matches master's other branches and changes no result).

AI-assisted (Claude Code).

@github-actions

Copy link
Copy Markdown

Lines of Code

File Lines Diff
src/simulation/m_viscous.fpp 1102 +45
src/simulation/m_rhs.fpp 2181 +44
src/common/m_chemistry.fpp 541 +2
src/simulation/m_riemann_solver_hll.fpp 621 -2
src/simulation/m_riemann_solver_hllc.fpp 1382 -2
src/simulation/m_riemann_state.fpp 1199 -1
Directory Lines Diff
common 12509 +2
simulation 42784 +84
total 62841 +86

@sbryngelson

Copy link
Copy Markdown
Member Author

CPU rerun on the pushed head a82b66d: Phoenix cpu-small, GNU 12.3 + OpenMPI 4.1.5, double, clean build. All 59 cylindrical/axisymmetric tests (including the 5 new ones) pass against the committed goldens: 59 passed / 0 failed. ./mfc.sh precheck passes.

AI-assisted (Claude Code).

@sbryngelson
sbryngelson merged commit 61ef81d into MFlowCode:master Nov 26, 2026
50 checks passed
sbryngelson added a commit to sbryngelson/MFC that referenced this pull request Nov 26, 2026
…C central tangential velocity); their MFlowCode#2515 goldens predate it
sbryngelson added a commit that referenced this pull request Nov 27, 2026
…, TSC image points and ib_visc_compact by default (#2486)

* Tests: generic configurations for degenerate tests; tolerances from measured spreads

* IBM: ib_wall_order = 2 by default (1 with ib_second_order_vel)

* IBM: ib_ip_interp = 2 (TSC) by default (1 with ib_second_order_vel)

* Docs: TSC image points and the quadratic no-slip ghost are the defaults

* Viscous IB: ib_visc_compact by default with weno_Re_flux, so the viscous flux no longer reads unfilled solid cells (#2041)

* Tests: tolerances measured with the new defaults on more lanes

* Tests: cold-wall twin and flux-wall tolerances from the measured GNU/GPU spread

* Tests: override_tol_single for the single-precision lane; tolerances from the measured CI spread

* Review: explicit IB options in the validation examples, ib_visc_compact = F tests, wording of the old defaults

* Tests: regenerate the changed goldens (Phoenix, GNU 12.3, OpenMPI 4.1.5)

* Format the wall_fill comment

* Tests: goldens that move on the new base (09FDDC81, and the overlap-cell seam test from #2514)

* Tests: C1F0BCB1 tolerance 1e-7 (GitHub ubuntu GNU differs from the Phoenix GNU golden by 4e-9 relative)

* Tests: goldens that move on the new base (master 946d1e5; Tuolumne, GNU 13.3.1 CPU)

* Tests: regenerate 872A4241 and F1BD319C on top of #2517 (HLLC central tangential velocity); their #2515 goldens predate it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

claude-full-review Trigger Claude Code review

Development

Successfully merging this pull request may close these issues.

Does the viscous azimuthal term have the divergence-side 1/r in 3D cylindrical?

1 participant