Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ if (MFC_DOCUMENTATION)
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/case_constraints.md"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/gen_case_constraints_docs.py"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/case_validator.py"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/params/definitions.py"
"${examples_DOCs}"
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_constraints.sh"
"${CMAKE_CURRENT_SOURCE_DIR}"
Expand All @@ -684,10 +685,12 @@ if (MFC_DOCUMENTATION)
)

# Generate parameters.md from parameter registry
# docs_gen.py now AST-parses case_validator.py, so it must be a dependency
file(GLOB_RECURSE params_SRCs CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/params/*.py")
add_custom_command(
OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/docs/documentation/parameters.md"
DEPENDS "${params_SRCs}"
"${CMAKE_CURRENT_SOURCE_DIR}/toolchain/mfc/case_validator.py"
COMMAND "bash" "${CMAKE_CURRENT_SOURCE_DIR}/docs/gen_parameters.sh"
"${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Generating parameters.md"
Expand Down
49 changes: 41 additions & 8 deletions toolchain/mfc/case_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
# pylint: disable=too-many-lines
# Justification: Comprehensive validator covering all MFC parameter constraints

import re
from typing import Dict, Any, List, Set
from functools import lru_cache
from .common import MFCException
from .params.definitions import CONSTRAINTS


@lru_cache(maxsize=1)
Expand Down Expand Up @@ -144,6 +146,10 @@ def check_model_eqns_and_num_fluids(self):
def check_igr(self):
"""Checks constraints regarding IGR order"""
igr = self.get('igr', 'F') == 'T'
igr_pres_lim = self.get('igr_pres_lim', 'F') == 'T'

self.prohibit(igr_pres_lim and not igr,
"igr_pres_lim requires igr to be enabled")

if not igr:
return
Expand All @@ -152,7 +158,6 @@ def check_igr(self):
m = self.get('m', 0)
n = self.get('n', 0)
p = self.get('p', 0)

self.prohibit(igr_order not in [None, 3, 5],
"igr_order must be 3 or 5")
if igr_order:
Expand Down Expand Up @@ -191,6 +196,10 @@ def check_weno(self):
def check_muscl(self):
"""Check constraints regarding MUSCL order"""
recon_type = self.get('recon_type', 1)
int_comp = self.get('int_comp', 'F') == 'T'

self.prohibit(int_comp and recon_type != 2,
"int_comp (THINC interface compression) requires recon_type = 2 (MUSCL)")

# MUSCL_TYPE = 2
if recon_type != 2:
Expand Down Expand Up @@ -381,6 +390,13 @@ def check_qbmm_and_polydisperse(self):
self.prohibit(qbmm and nnode is not None and nnode != 4,
"QBMM requires nnode = 4")

sigR = self.get('sigR')
sigV = self.get('sigV')
self.prohibit(sigR is not None and sigR != 0 and not qbmm,
"sigR requires qbmm to be enabled")
self.prohibit(sigV is not None and sigV != 0 and not qbmm,
"sigV requires qbmm to be enabled")

def check_adv_n(self):
"""Checks constraints on adv_n flag"""
adv_n = self.get('adv_n', 'F') == 'T'
Expand Down Expand Up @@ -1201,6 +1217,10 @@ def check_probe_integral_output(self):
def check_hyperelasticity(self):
"""Checks hyperelasticity constraints"""
hyperelasticity = self.get('hyperelasticity', 'F') == 'T'
pre_stress = self.get('pre_stress', 'F') == 'T'

self.prohibit(pre_stress and not hyperelasticity,
"pre_stress requires hyperelasticity to be enabled")

if not hyperelasticity:
return
Expand Down Expand Up @@ -1911,14 +1931,27 @@ def _format_errors(self) -> str:
err_lower = err.lower()
if "must be positive" in err_lower or "must be set" in err_lower:
lines.append(" [dim]Check that this required parameter is defined in your case file[/dim]")
elif "weno_order" in err_lower:
lines.append(" [dim]Valid values: 1, 3, 5, or 7[/dim]")
elif "riemann_solver" in err_lower:
lines.append(" [dim]Valid values: 1 (HLL), 2 (HLLC), 3 (Exact), etc.[/dim]")
elif "model_eqns" in err_lower:
lines.append(" [dim]Valid values: 1, 2 (5-eq), 3 (6-eq), or 4[/dim]")
elif "boundary" in err_lower or "bc_" in err_lower:
continue
if "boundary" in err_lower or "bc_" in err_lower:
lines.append(" [dim]Common BC values: -1 (periodic), -2 (reflective), -3 (extrapolation)[/dim]")
continue

# Auto-generate hints from CONSTRAINTS with value_labels
for param_name, constraint in CONSTRAINTS.items():
if not re.search(r'\b' + re.escape(param_name) + r'\b', err_lower):
Comment thread
sbryngelson marked this conversation as resolved.
Outdated
continue
choices = constraint.get("choices")
if not choices:
continue
labels = constraint.get("value_labels", {})
if labels:
items = [f"{v} ({labels[v]})" if v in labels else str(v)
for v in choices]
hint = f"Valid values: {', '.join(items)}"
else:
hint = f"Valid values: {choices}"
lines.append(f" [dim]{hint}[/dim]")
break
Comment thread
coderabbitai[bot] marked this conversation as resolved.

lines.append("")
lines.append("[dim]Tip: Run './mfc.sh validate case.py' for detailed validation[/dim]")
Expand Down
Loading
Loading