Skip to content

Commit 227baa4

Browse files
sbryngelsonclaude
andcommitted
Fix physics docs rendering: \implies → \Rightarrow, backtick code params
- Replace \implies with \Rightarrow (Doxygen MathJax compatible) - Add _format_message() to wrap code parameter references in backticks in auto-generated check messages (Fortran accessors, snake_case params, known short params like nb/dt/m/n/p) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8d781a0 commit 227baa4

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

toolchain/mfc/case_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"check_alpha_rho_consistency": {
7373
"title": "Alpha-Rho Consistency",
7474
"category": "Mixture Constraints",
75-
"math": r"\alpha_j = 0 \implies \alpha_j \rho_j = 0, \quad \alpha_j > 0 \implies \alpha_j \rho_j > 0",
75+
"math": r"\alpha_j = 0 \Rightarrow \alpha_j \rho_j = 0, \quad \alpha_j > 0 \Rightarrow \alpha_j \rho_j > 0",
7676
"explanation": (
7777
"Warns about physically inconsistent combinations: "
7878
"density assigned to an absent phase, or a present phase with zero density."
@@ -106,7 +106,7 @@
106106
"check_velocity_components": {
107107
"title": "Velocity Components in Inactive Dimensions",
108108
"category": "Velocity and Dimensional Consistency",
109-
"math": r"n = 0 \implies v_2 = 0, \quad p = 0 \implies v_3 = 0",
109+
"math": r"n = 0 \Rightarrow v_2 = 0, \quad p = 0 \Rightarrow v_3 = 0",
110110
"explanation": "Setting velocity components in dimensions that do not exist is almost certainly a mistake.",
111111
"exceptions": ["MHD simulations (transverse velocity couples to magnetic field in 1D)"],
112112
},

toolchain/mfc/gen_physics_docs.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from __future__ import annotations
1010

11+
import re
1112
import sys
1213
from collections import defaultdict
1314
from pathlib import Path
@@ -47,6 +48,26 @@
4748
"warning": "- \\f$\\triangle\\f$ ",
4849
}
4950

51+
# Regex to detect code-like tokens in validation messages.
52+
# Matches (in order of priority):
53+
# 1. Fortran-style accessors: fluid_pp(i)%gamma, bc_y%beg
54+
# 2. Known short param names with optional array index: alpha(j), vel(2), Re(1), nb, dt
55+
# 3. Snake_case identifiers with optional array index: model_eqns, weno_order, alpha_rho(j)
56+
# 4. Single-letter grid dimension params: m, n, p
57+
_CODE_RE = re.compile(
58+
r"(?<!`)\b("
59+
r"\w+(?:\([^)]*\))?%\w+(?:\([^)]*\))?"
60+
r"|(?:alpha|vel|Re|dt|nb|sigma|mhd|igr|Bx0|viscous|thermal|polytropic|relativity|rhoref|pref|var)(?:\([^)]*\))?"
61+
r"|[a-z]\w*_\w+(?:\([^)]*\))?"
62+
r"|[mnp]"
63+
r")(?!\w)"
64+
)
65+
66+
67+
def _format_message(msg: str) -> str:
68+
"""Wrap code-like parameter references in backticks."""
69+
return _CODE_RE.sub(r"`\1`", msg)
70+
5071

5172
def _stages_str(stages: Set[str]) -> str:
5273
order = ["common", "pre_process", "simulation", "post_process"]
@@ -88,7 +109,7 @@ def _render_method(doc: dict, method_rules: List[Rule], lines: List[str]) -> Non
88109
if msgs:
89110
lines.append("**Enforced checks:**\n")
90111
for m in msgs[:8]:
91-
lines.append(f"{_SEVERITY_ICON.get(m.severity, '- ')}{m.message}")
112+
lines.append(f"{_SEVERITY_ICON.get(m.severity, '- ')}{_format_message(m.message)}")
92113
if len(msgs) > 8:
93114
lines.append(f"- *(+{len(msgs) - 8} more)*")
94115
lines.append("")

0 commit comments

Comments
 (0)