diff --git a/docs/changes.md b/docs/changes.md index bff31e8..3a862cd 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -7,6 +7,20 @@ rediscover why a thing is the way it is. Open gaps are in ## 2026-11 +- **2026-11-18: 0.3.1, a stabilization without a method (C42 round 6).** ymf 0.3.0 required `method` in every + `stabilization:` block, so proteus's RDLS block (`stabilization: {shock_capturing: {factor: 0.9, lag: false}}`, read + as a free map by ymf 0.2) no longer loaded, and `test/dispatch` broke on every proteus PR. Now `method: none` is a + word (no residual-based method; it reads only `shock_capturing`), the bare `stabilization: none` says a sub-problem is + not stabilized at all (MCorr, PresInc), and a block that states only `shock_capturing` loads and means exactly + that, `method: none` plus that shock capturing; ymf picks no method for it and fills in no key. `tau` or `lagged` + without a method are refused (they belong to one). `ymf.stabilization.missing(block)` still lists what a reader that + must not guess needs: under `none` an unstated `shock_capturing` is not missing (the word says there is none), a + stated block must be complete (`beta`, `reference` for RDLS's). A spec written before 2026-11-17 loads unchanged: + proteus's own `test/dispatch/dambreak.ymf` and `two_phase_level_set.ymf` (`cekees/main` b9d98f5d) are fixtures + (`tests/fixtures/proteus_dispatch_0_2/`), loaded, resolved and round-tripped through an archive with the same key. + Suite 1032 -> 1048. What proteus's RDLS actually applies (SUPG with `tau: metric`, not lagged, and a classical + `beta` 1 shock capturing) is in `HANDOFF_2026-11-18_ymf-r6.md`: the old block was incomplete, not wrong to load. + - **2026-11-17: C42 round 5, the formulation a generator and a dispatcher read (C19 spike report, C5 step 4 part 2).** The generator spike could not generate what the spec did not say (stabilization, shock capturing, lagging, boundary kind, porosity) and C5 could not state a dispersive model or a mesh of a box that is not square. Now the spec states diff --git a/docs/problem-specification.md b/docs/problem-specification.md index 36fab6c..5104732 100644 --- a/docs/problem-specification.md +++ b/docs/problem-specification.md @@ -896,7 +896,7 @@ checked on load, so that a second solver reads the same ones: | model family (`physical_model.family`) | `two_phase_level_set`, `shallow_water`, `dispersive_shallow_water` | | sub-problem role (`role`) | two-phase: `velocity_pressure`, `velocity`, `pressure_increment`, `pressure`, `pressure_spin_up`, `volume_fraction`, `level_set`, `level_set_redistanced`, `redistancing`, `mass_correction`; shallow water: `shallow_water` | | `time_integration` | `backward_euler`, `bdf2`, `ssp_rk3`, `none` | -| `stabilization.method` | `ASGS`, `SUPG`, `residual_shock_capturing`, `entropy_viscosity`, `graph_viscosity_smoothness`, `graph_viscosity_entropy_residual` | +| `stabilization.method` | `ASGS`, `SUPG`, `residual_shock_capturing`, `entropy_viscosity`, `graph_viscosity_smoothness`, `graph_viscosity_entropy_residual`, `none` | | `discretization.scheme` and its options | `graph_viscosity_convex_limiting`: `entropy_viscosity_coefficient`, `lumped_mass`, `bounds_relaxation` (and `time_integration`, `outputs`, `dt` for every scheme) | | `step_control.type` | `min_cfl`, `fixed` | | `regularize.*.by` | `smoothed_heaviside`, `smoothed_sign`, `wet_dry_cutoff` | @@ -967,6 +967,28 @@ the entropy and graph viscosities read none (their parameters are the scheme's o `reference` positive, `factor` non-negative. `lag`, `sc_beta`, `sc_uref` (the keys proteus's dispatcher read first) are accepted and resolve to `lagged`, `beta`, `reference`. +*No method, and shock capturing alone* (0.3.1). `method: none` says the sub-problem has no residual-based method; it reads +only `shock_capturing`. Three statements, three meanings: + +```yaml +stabilization: none # not stabilized at all, shock capturing included (MCorr, PresInc, a projection) +stabilization: {method: none, shock_capturing: {factor: 0.9, lagged: false}} # shock capturing and no method +stabilization: {shock_capturing: {factor: 0.9, lagged: false}} # the same: a block without `method` +``` + +A block with `shock_capturing` and no `method` is the second one, exactly: ymf never picks a method for a block that +does not name one (it is neither `SUPG` nor `residual_shock_capturing`, which also takes `tau`), and `tau` or `lagged` +without a method are refused, because they belong to a method. `resolve` returns `{"method": "none", ...}` for all +three and adds no other key. + +*What a reader that must not guess still needs: `ymf.stabilization.missing(block)`.* It returns the dotted keys the +kernel generator reads that the block does not state, and nothing is filled in: `missing("SUPG")` is `["tau", "lagged", +"shock_capturing"]`; with `shock_capturing: {factor: 0.9, lagged: false}` stated it also asks for `shock_capturing.beta` and +`.reference` (stating `shock_capturing: none` answers the block as a whole); the entropy and graph viscosities need +nothing. For `none`, an unstated `shock_capturing` is not missing (the word says there is none); a `shock_capturing` +block it does state must be complete, so `missing({"shock_capturing": {"factor": 0.9, "lag": False}})` is +`["shock_capturing.beta", "shock_capturing.reference"]` and `missing("none")` is `[]`. + **Lagging** (`lagged_coefficients`): `{μ: previous_iterate, ρ: previous_step}` says which of the model's coefficients a sub-problem freezes, in the Newton iteration (a Picard step: the Jacobian drops the dependence) or in time (a constant of the step). A field read from another sub-problem is `lags`; a stabilization's lag is its `lagged`. diff --git a/src/ymf/schema.py b/src/ymf/schema.py index 5754ebf..f7c18ee 100644 --- a/src/ymf/schema.py +++ b/src/ymf/schema.py @@ -112,9 +112,10 @@ } ) +# A block without ``method`` states shock capturing alone (``method: none``), ymf.stabilization.resolve. StabilizationDef = Str() | Map( { - "method": Str(), + Optional("method"): Str(), Optional("tau"): Str(), Optional("lagged"): Bool(), Optional("lag"): Bool(), diff --git a/src/ymf/stabilization.py b/src/ymf/stabilization.py index 8caab2c..1e88904 100644 --- a/src/ymf/stabilization.py +++ b/src/ymf/stabilization.py @@ -14,6 +14,8 @@ reference: 1.0 # the reference value of the unknown (sc_uref) lagged: true # the viscosity taken from the previous step (ShockCapturing lag) stabilization: {method: SUPG, shock_capturing: none} # none, stated: the solver adds no shock capturing + stabilization: none # nothing: no method, no shock capturing (MCorr, a projection) + stabilization: {shock_capturing: {factor: 0.9}} # shock capturing with no method (proteus's RDLS block of 0.2) What it is for. The generator (C19) turned VOF and NCLS into a functor each, but the SUPG tau, the shock capturing and their lag are the engine template's, and the template took them from the model's name (``dambreak.ymf`` stated none: the @@ -28,6 +30,11 @@ Which keys a method takes: +* ``none``: no residual-based method. It takes only ``shock_capturing``: ``stabilization: none`` (or ``method: none``) + says that the sub-problem is not stabilized at all, shock capturing included; ``{method: none, shock_capturing: + {factor: 0.9}}`` says shock capturing and nothing else. A block that states ``shock_capturing`` and no ``method`` is + exactly that second one (ymf 0.2 read such a block, proteus's RDLS stated one; 0.3.0 refused it; resolve gives it + ``method: none``). This is a meaning, not a default: ymf never picks a method for a block that does not name one. * ``SUPG``, ``ASGS``: ``tau``, ``lagged``, ``shock_capturing`` (the residual-based viscosity added to the method). * ``residual_shock_capturing``: the shock-capturing viscosity alone: ``tau``, ``shock_capturing`` (its block says how much; unstated, the solver's own coefficient applies). @@ -53,6 +60,7 @@ class StabilizationError(ValueError): #: method -> the keys of the block it reads (beside ``method``) TAKES: Dict[str, tuple] = { + "none": ("shock_capturing",), "SUPG": ("tau", "lagged", "shock_capturing"), "ASGS": ("tau", "lagged", "shock_capturing"), "residual_shock_capturing": ("tau", "shock_capturing"), @@ -139,13 +147,28 @@ def _shock_capturing(block: Any, where: str) -> Optional[Dict[str, Any]]: def resolve(block: Any, where: str = "stabilization") -> Dict[str, Any]: """The stabilization as a block with ymf's words and every stated key kept: ``{method, tau?, lagged?, - shock_capturing?}``, ``shock_capturing`` a dict, or ``None`` when the spec says ``none``. Nothing is added. - Raises :class:`StabilizationError`.""" + shock_capturing?}``, ``shock_capturing`` a dict, or ``None`` when the spec says ``none``. Nothing is added, with one + reading of what is stated: a block that gives ``shock_capturing`` and no ``method`` has ``method: none`` (shock + capturing and no residual-based method), and the bare word ``none`` is ``{"method": "none"}``, which under + :data:`TAKES` ``none`` states no shock capturing either. Raises :class:`StabilizationError`.""" if isinstance(block, str): block = {"method": block} - if not isinstance(block, dict) or "method" not in block: - raise StabilizationError("%s: say the method (stabilization: SUPG), or give a block with method:" % (where,)) + if not isinstance(block, dict): + raise StabilizationError("%s: say the method (stabilization: SUPG, or none), or give a block with method:" + % (where,)) block = _keys(block, "stabilization_key", where) + if "method" not in block: + if "shock_capturing" not in block: + raise StabilizationError( + "%s: say the method (stabilization: SUPG, or none), or give a block with method: (a block with only " + "shock_capturing has no method: none)" % (where,)) + others = sorted(set(block) - {"shock_capturing"}) + if others: + raise StabilizationError( + "%s: no method is stated, so the block is shock capturing and nothing else (method: none), and " + "%s %s read by a method: say which (method: SUPG, ASGS or residual_shock_capturing)" + % (where, ", ".join(others), "is" if len(others) == 1 else "are")) + block = dict(block, method="none") method = _method(block["method"], where + ".method") takes = TAKES[method] unread = sorted(set(block) - {"method"} - set(takes)) @@ -194,12 +217,14 @@ def missing(block: Any) -> List[str]: def generator_needs(method: str, resolved: Optional[Dict[str, Any]] = None) -> List[str]: """What the kernel generator reads of a stabilization of ``method``: ``tau`` (and ``lagged`` for SUPG and ASGS), - and the shock-capturing block's four keys (or its explicit ``none``).""" + and the shock-capturing block's four keys (or its explicit ``none``). Method ``none`` needs no statement that there + is no shock capturing (it says so); only a shock-capturing block it does state must be complete.""" takes = TAKES[method] needs = [k for k in ("tau", "lagged") if k in takes] if "shock_capturing" in takes: sc = (resolved or {}).get("shock_capturing", "unstated") - needs.append("shock_capturing") + if method != "none": + needs.append("shock_capturing") if isinstance(sc, dict): needs += ["shock_capturing." + k for k in SHOCK_CAPTURING_KEYS] return needs diff --git a/src/ymf/vocabulary.py b/src/ymf/vocabulary.py index dfaab0b..457f41f 100644 --- a/src/ymf/vocabulary.py +++ b/src/ymf/vocabulary.py @@ -253,6 +253,7 @@ def roles_of(doc: Dict[str, Any], entry: Dict[str, Any]) -> Dict[str, Optional[s } STABILIZATION: Dict[str, str] = { + "none": "no residual-based method (and no shock capturing unless the block states it): a projection, a correction", "ASGS": "algebraic subgrid scale stabilization (variational multiscale)", "SUPG": "streamline-upwind Petrov-Galerkin", "residual_shock_capturing": "residual-based shock-capturing viscosity alone", diff --git a/tests/fixtures/proteus_dispatch_0_2/README.md b/tests/fixtures/proteus_dispatch_0_2/README.md new file mode 100644 index 0000000..3e9efe6 --- /dev/null +++ b/tests/fixtures/proteus_dispatch_0_2/README.md @@ -0,0 +1,10 @@ +Specs written against ymf 0.2 / main before 2026-11-17, kept as they were, so that every ymf release still loads them +(tests/test_stabilization_compat.py). Copied byte for byte from proteus `cekees/main` b9d98f5d, `test/dispatch/`: + +| file | git blob | +|---|---| +| `two_phase_level_set.ymf` | 59cb5110b87d3557718f98014f2cf6f44b54e4eb | +| `dambreak.ymf` | 88aa84631839ec89bbdbda6bd190240da22bec80 | + +Do not edit them or bring them up to date: their old spellings (`lag`, `sc_beta`, `sc_uref`) and RDLS's `stabilization` +block, which states `shock_capturing` and no `method`, are what they test. diff --git a/tests/fixtures/proteus_dispatch_0_2/dambreak.ymf b/tests/fixtures/proteus_dispatch_0_2/dambreak.ymf new file mode 100644 index 0000000..88aa846 --- /dev/null +++ b/tests/fixtures/proteus_dispatch_0_2/dambreak.ymf @@ -0,0 +1,168 @@ +# The 2-D dam break of test/TwoPhaseFlow, three ways, as discretizations of one +# model (YMF_MODEL_FAMILIES_C42 section 2.5, with ymf's tests/fixtures/two_phase +# for the case). test_dispatch.py checks that proteus.Dispatch maps each one +# onto exactly the modules and flags TwoPhaseFlow builds for its deck: +# +# level_set_five damBreakLevelSet.py RANS2P, VOF, NCLS, RDLS, MCorr +# level_set_clsvof damBreakLevelSet.py interface=1 RANS2P, CLSVOF +# clsvof_projection damBreak.py CLSVOF, RANS3PF, PresInc, Pres, PresInit +# +# All three solve the non-conservative inertia form: RANS2P's default +# (NONCONSERVATIVE_FORM = 1.0) and the only one RANS3PF has. +# The proteus: blocks are interim hints (D8): model names are checked against +# the dispatch, and eb_penalty_constant (the decks' 1e6, the table's default +# 100) is an option ymf does not type yet. +extends: two_phase_level_set.ymf + +model: + name: "Dam break, 3.22 m × 1.8 m tank, 1.2 m × 0.6 m column (2-D)" + physical_model: {provenance: human_specified} + strong_form: + domain: "Ω = [0, 3.22] × [0, 1.8], t ∈ (0, 3]" + boundary_regions: + - {name: walls, where: "x = 0 or x = 3.22 or y = 0"} + - {name: top, where: "y = 1.8"} + boundary_sets: + - {region: walls, set: free_slip} + - {region: top, set: atmosphere} + initial_conditions: + - {field: v, type: constant, value: 0.0} + - {field: p, type: constant, value: 0.0} + - field: φ + type: function + formula: "sqrt(max(x − 1.2, 0)² + max(y − 0.6, 0)²) + min(max(x − 1.2, y − 0.6), 0)" + units: m + coefficients: + ρw: {value: 998.2} + νw: {value: 1.004e-6} + ρa: {value: 1.205} + νa: {value: 1.5e-5} + g: {formula: "(0, -9.8)"} + +solution_paths: + analytical: [] + discretizations: + - name: level_set_five + provenance: proteus_derived + from_weak_form: nonconservative_inertia + mesh: {h: 0.0322} + binds: + h: {meaning: element_size} + ε: {formula: "1.5 h"} + regularize: + heaviside: {by: smoothed_heaviside, width: ε} + step_control: {type: min_cfl, cfl: 0.25, step_exact: true} + solver: {type: nonlinear, nonlinear_solver: newton, linear_solver: iterative, max_iterations: 50} + subproblems: + - name: flow + solves: [momentum, continuity] + lags: {φ: previous_step, χ: {via: vof, at: previous_step}} + finite_element: {velocity: {family: CG, order: 1}, pressure: {family: CG, order: 1}} + time_integration: backward_euler + stabilization: {method: ASGS, lag: true, shock_capturing: {factor: 0.5, lag: true}} + solver: {max_iterations: 100} + proteus: {model: RANS2P, useVF: 1.0, eb_penalty_constant: 1.0e6} + - name: vof + introduces: {name: χh, approximates: χ, units: "1"} + equation: "∂χh/∂t + ∇·(v χh) = 0" + initial_condition: "heaviside(φ)" + lags: {v: {via: flow, at: current_step}} + finite_element: {fields: {family: CG, order: 1}} + time_integration: backward_euler + stabilization: {method: SUPG, shock_capturing: {factor: 0.5, lag: true, sc_uref: 1.0, sc_beta: 1.5}} + proteus: {model: VOF} + - name: ncls + solves: [interface] + lags: {v: {via: flow, at: current_step}} + finite_element: {fields: {family: CG, order: 1}} + time_integration: backward_euler + stabilization: {method: SUPG, shock_capturing: {factor: 0.5, lag: true, sc_uref: 1.0, sc_beta: 1.5}} + proteus: {model: NCLS} + - name: rdls + enforces: "norm(∇φ) = 1" + for: φ + equation: "sign(φs) (norm(∇φ) − 1) = 0" + lags: {φs: {of: φ, via: ncls, at: current_step}} + regularize: {sign: {by: smoothed_sign, width: εr}} + binds: {εr: {formula: "0.75 h"}} + pseudo_time: steady + writes_back: {φ: replace} + finite_element: {fields: {family: CG, order: 1}} + stabilization: {shock_capturing: {factor: 0.9, lag: false}} + proteus: {model: RDLS, epsFact: 0.75} + - name: mcorr + enforces: "heaviside(φ) = χh" + introduces: {name: φc, correction_of: φ, units: m} + equation: "heaviside(φ + φc) − χh − ∇·(εd ∇φc) = 0" + binds: {εd: {formula: "10 h"}} + lags: {φ: {via: rdls, at: current_step}, χh: {via: vof, at: current_step}} + writes_back: {φ: add} + finite_element: {fields: {family: CG, order: 1}} + time_integration: none + proteus: {model: MCorr} + + # RANS2P with CLSVOF in place of the four interface solves + - name: level_set_clsvof + provenance: proteus_derived + from_weak_form: nonconservative_inertia + mesh: {h: 0.0322} + binds: + h: {meaning: element_size} + ε: {formula: "1.5 h"} + regularize: + heaviside: {by: smoothed_heaviside, width: ε} + step_control: {type: min_cfl, cfl: 0.25, step_exact: true} + solver: {type: nonlinear, nonlinear_solver: newton, linear_solver: iterative, max_iterations: 50} + subproblems: + - name: flow + solves: [momentum, continuity] + lags: {φ: previous_step, χ: {via: clsvof, at: previous_step}} + finite_element: {velocity: {family: CG, order: 1}, pressure: {family: CG, order: 1}} + time_integration: backward_euler + solver: {max_iterations: 100} + proteus: {model: RANS2P, eb_penalty_constant: 1.0e6} + - name: clsvof + solves: [interface] + enforces: "norm(∇φ) = 1" + lags: {v: {via: flow, at: current_step}} + finite_element: {fields: {family: CG, order: 1}} + time_integration: backward_euler + + # damBreak.py: CLSVOF first, then the projection scheme's velocity step + # (P2), the pressure increment and update, and a pressure spin-up + - name: clsvof_projection + provenance: proteus_derived + from_weak_form: nonconservative_inertia + mesh: {h: 0.0322} + binds: + h: {meaning: element_size} + ε: {formula: "1.5 h"} + regularize: + heaviside: {by: smoothed_heaviside, width: ε} + step_control: {type: min_cfl, cfl: 0.25, step_exact: true} + solver: {type: nonlinear, nonlinear_solver: newton, linear_solver: iterative} + subproblems: + - name: clsvof + solves: [interface] + enforces: "norm(∇φ) = 1" + lags: {v: {via: flow, at: previous_step}} + solver: {max_iterations: 50} + proteus: {model: CLSVOF, disc_ICs: true} + - name: flow + solves: [momentum] + lags: {φ: {via: clsvof, at: current_step}, χ: {via: clsvof, at: current_step}, p: {via: pressure, at: previous_step}} + finite_element: {velocity: {family: CG, order: 2}} + time_integration: bdf2 + solver: {max_iterations: 1} + proteus: {model: RANS3PF, eb_penalty_constant: 1.0e6} + - name: pressureInc + enforces: "∇·v = 0" + solver: {max_iterations: 50} + proteus: {model: PresInc} + - name: pressure + solves: [continuity] + lags: {v: {via: flow, at: current_step}} + proteus: {model: Pres} + - name: pressureInit + spin_up: true + proteus: {model: PresInit} diff --git a/tests/fixtures/proteus_dispatch_0_2/two_phase_level_set.ymf b/tests/fixtures/proteus_dispatch_0_2/two_phase_level_set.ymf new file mode 100644 index 0000000..59cb511 --- /dev/null +++ b/tests/fixtures/proteus_dispatch_0_2/two_phase_level_set.ymf @@ -0,0 +1,66 @@ +# The two-phase level-set family of ymf's tests/fixtures/two_phase (C42), with +# the two inertia forms as weak forms (D1: a formulation is a weak_forms +# entry). proteus.Dispatch picks RANS2P's NONCONSERVATIVE_FORM from the +# discretization's from_weak_form, never from a module name in the spec. +# Incompressible two-phase flow with a sharp interface carried by a level +# set (C42): the model only. Phase 0 is water (φ < 0), phase 1 air (φ > 0). +# The density and viscosity are coefficients of the state, through +# χ = heaviside(φ). The whole model is not one ADR system (v·∇φ is a +# Hamiltonian in another unknown); a split discretization classifies each +# sub-problem with the others' fields lagged. +ymf_state: abstract + +model: + physical_model: + provenance: human_specified + processes: [incompressible_flow, two_phase_flow, interface_transport, gravity] + assumptions: [newtonian, immiscible, isothermal, no_phase_change, no_surface_tension] + strong_form: + provenance: human_specified + unknowns: + - {name: v, units: m/s, rank: 1} + - {name: p, units: Pa} + - {name: φ, units: m} + equation_formulation: "variable-density incompressible Navier-Stokes, interface by a level set" + equations: + - name: momentum + for: v + equation: "∂(ρ v)/∂t + ∇·(ρ v⊗v) − ∇·(2μ sym(∇v)) + ∇p = ρ g in Ω" + - name: continuity + for: p + equation: "∇·v = 0 in Ω" + - name: interface + for: φ + equation: "∂φ/∂t + v·∇φ = 0 in Ω" + coefficients: + χ: {formula: "heaviside(φ)", units: "1", role: phase_indicator} + ρ: {formula: "ρw (1 − χ) + ρa χ", units: kg/m3, role: density} + μ: {formula: "ρw νw (1 − χ) + ρa νa χ", units: Pa*s, role: dynamic_viscosity} + ρw: {units: kg/m3} + νw: {units: m2/s} + ρa: {units: kg/m3} + νa: {units: m2/s} + g: {units: m/s2, role: gravity} + # what the cases' walls and tops mean, written once (Proteus's + # BC_RANS.setFreeSlip and setAtmosphere, for this model's unknowns) + condition_sets: + free_slip: + - {variable: v, type: slip} + atmosphere: + - {variable: p, type: dirichlet, value: 0.0} + - {variable: v, type: open} + - {variable: χ, type: inflow, value: 1.0} # what enters is air + + weak_forms: + - label: conservative_inertia + provenance: human_specified + derivation: "momentum as written; viscous and pressure terms integrated by parts" + solution_spaces: {trial: "H1(Ω)^d × L2(Ω) × H1(Ω)", test: "H1(Ω)^d × L2(Ω) × H1(Ω)"} + bilinear: "free text until weak forms are parsed" + linear: "free text" + - label: nonconservative_inertia + provenance: human_specified + derivation: "ρ(∂v/∂t + v·∇v) in place of ∂(ρv)/∂t + ∇·(ρ v⊗v), using ∇·v = 0 and the interface equation" + solution_spaces: {trial: "H1(Ω)^d × L2(Ω) × H1(Ω)", test: "H1(Ω)^d × L2(Ω) × H1(Ω)"} + bilinear: "free text until weak forms are parsed" + linear: "free text" diff --git a/tests/test_stabilization.py b/tests/test_stabilization.py index 9ba86dd..3bd5695 100644 --- a/tests/test_stabilization.py +++ b/tests/test_stabilization.py @@ -41,6 +41,14 @@ def test_shock_capturing_none_is_stated_and_is_not_absent(): @pytest.mark.parametrize("block, message", [ ({"tau": "metric"}, "say the method"), + ({}, "say the method"), + ({"tau": "metric", "shock_capturing": {"factor": 0.9}}, + "no method is stated.*tau is read by a method: say which"), + ({"tau": "metric", "lagged": True, "shock_capturing": {"factor": 0.9}}, + "lagged, tau are read by a method"), + ({"method": "none", "tau": "metric"}, "none does not read tau; its keys are method, shock_capturing"), + ({"method": "none", "lagged": True}, "none does not read lagged"), + ({"shock_capturing": {"beta": 1.5}}, "factor is required"), ({"method": "GLS"}, "stabilization GLS: ymf knows"), ({"method": "SUPG", "tau": "h"}, "tau: h is not one of metric, element_size"), ({"method": "SUPG", "lagged": "maybe"}, "'maybe' is not true or false"), @@ -65,6 +73,62 @@ def test_a_stabilization_that_does_not_make_sense_is_refused(block, message): resolve(block) +# --- no method: none, and shock capturing alone (0.3.1) ------------------------------------------------------------ + +def test_none_says_there_is_no_stabilization_and_adds_nothing(): + assert resolve("none") == {"method": "none"} == resolve({"method": "none"}) + assert canonical("stabilization", "none") == "none" + # none with shock capturing stated none is the same statement, spelled out + assert resolve({"method": "none", "shock_capturing": "none"}) == {"method": "none", "shock_capturing": None} + + +def test_a_block_that_states_only_shock_capturing_is_shock_capturing_with_no_method(): + # proteus's RDLS block in test/dispatch at cekees/main b9d98f5d (ymf 0.2: a free map; 0.3.0: refused for want of method) + old = {"shock_capturing": {"factor": 0.9, "lag": False}} + assert resolve(old) == {"method": "none", "shock_capturing": {"factor": 0.9, "lagged": False}} + assert resolve(old) == resolve({"method": "none", "shock_capturing": {"factor": 0.9, "lagged": False}}) + # not a method ymf picks: it is not residual_shock_capturing (a method that also takes tau), nor SUPG + assert resolve(old)["method"] not in ("SUPG", "residual_shock_capturing") + assert resolve({"shock_capturing": "none"}) == {"method": "none", "shock_capturing": None} + + +def test_missing_asks_none_only_for_a_shock_capturing_block_it_states(): + assert missing("none") == [] and missing({"method": "none", "shock_capturing": "none"}) == [] + assert missing({"shock_capturing": {"factor": 0.9, "lag": False}}) == [ + "shock_capturing.beta", "shock_capturing.reference"] + assert missing({"shock_capturing": {"factor": 0.9, "beta": 1.0, "reference": 1.0, "lagged": False}}) == [] + # nothing was filled in on the way: the same two keys are still unstated + assert "beta" not in resolve({"shock_capturing": {"factor": 0.9}})["shock_capturing"] + # SUPG still asks for everything it reads, shock capturing stated or not + assert missing("SUPG") == ["tau", "lagged", "shock_capturing"] + + +def test_a_spec_states_none_and_shock_capturing_alone_and_split_problem_carries_them(): + doc = load_ymf(FORMULATION) + _state(doc, "mcorr", "none") + _state(doc, "rdls", {"shock_capturing": {"factor": 0.9, "lag": False}}) + check(doc) + split = {s["name"]: s for s in split_problem(doc, "level_set_five")["subproblems"]} + assert split["mcorr"]["stabilization"] == {"method": "none"} + assert split["rdls"]["stabilization"] == {"method": "none", "shock_capturing": {"factor": 0.9, "lagged": False}} + # an entry's none is the default of the sub-problems that state nothing; a sub-problem that states one replaces it + entry = doc["solution_paths"]["discretizations"][0] + entry["stabilization"] = {"method": "none"} + del subproblem(doc, "level_set_five", "vof")["stabilization"] + split = {s["name"]: s for s in split_problem(doc, "level_set_five")["subproblems"]} + assert split["vof"]["stabilization"] == {"method": "none"} + assert split["flow"]["stabilization"]["method"] == "ASGS" + + +def test_a_block_that_states_shock_capturing_with_a_key_only_a_method_reads_is_refused_on_load(): + doc = _state(load_ymf(FORMULATION), "rdls", {"tau": "metric", "shock_capturing": {"factor": 0.9}}) + with pytest.raises(VocabularyError, match=r"subproblems\[rdls\]\.stabilization: no method is stated"): + check(doc) + doc = _state(load_ymf(FORMULATION), "rdls", {"tau": "metric"}) + with pytest.raises(VocabularyError, match="say the method"): + check(doc) + + # --- what a generator still needs stated ------------------------------------------------------------------------ def test_missing_says_what_the_generator_cannot_guess(): diff --git a/tests/test_stabilization_compat.py b/tests/test_stabilization_compat.py new file mode 100644 index 0000000..8b34000 --- /dev/null +++ b/tests/test_stabilization_compat.py @@ -0,0 +1,81 @@ +"""ymf 0.3.1: a spec written against ymf 0.2 (or main before 2026-11-17) loads unchanged. + +The fixtures are proteus's own ``test/dispatch/dambreak.ymf`` and ``two_phase_level_set.ymf`` from ``cekees/main`` +b9d98f5d, untouched (tests/fixtures/proteus_dispatch_0_2/README.md). ymf 0.3.0 refused them: RDLS's block states +``shock_capturing`` and no ``method``. They must load, mean what they said, and survive an archive. +""" + +import pytest + +pytest.importorskip("strictyaml") +pytest.importorskip("sympy") + +from _formulation import FIXTURES, roundtrip, subproblem # noqa: E402 +from ymf import closure # noqa: E402 +from ymf.schema import load_ymf # noqa: E402 +from ymf.stabilization import missing # noqa: E402 +from ymf.symbolic import split_problem # noqa: E402 +from ymf.vocabulary import check # noqa: E402 + +OLD = FIXTURES / "proteus_dispatch_0_2" +DAMBREAK = OLD / "dambreak.ymf" +SHOCK_ONLY = {"method": "none", "shock_capturing": {"factor": 0.9, "lagged": False}} + + +@pytest.fixture(scope="module") +def doc(): + return load_ymf(DAMBREAK) + + +def test_the_old_spec_loads_and_passes_the_checks(doc): + check(doc) + names = [e["name"] for e in doc["solution_paths"]["discretizations"]] + assert names == ["level_set_five", "level_set_clsvof", "clsvof_projection"] + + +def test_the_old_blocks_mean_what_they_said(doc): + split = {s["name"]: s for s in split_problem(doc, "level_set_five")["subproblems"]} + # written `{method: ASGS, lag: true, shock_capturing: {factor: 0.5, lag: true}}` + assert split["flow"]["stabilization"] == {"method": "ASGS", "lagged": True, + "shock_capturing": {"factor": 0.5, "lagged": True}} + # written `{method: SUPG, shock_capturing: {factor: 0.5, lag: true, sc_uref: 1.0, sc_beta: 1.5}}` + for name in ("vof", "ncls"): + assert split[name]["stabilization"] == { + "method": "SUPG", "shock_capturing": {"factor": 0.5, "beta": 1.5, "reference": 1.0, "lagged": True}} + # written `{shock_capturing: {factor: 0.9, lag: false}}`: shock capturing and no method; nothing was added + assert split["rdls"]["stabilization"] == SHOCK_ONLY + assert "stabilization" not in split["mcorr"] + # the other two discretizations state none + for name in ("level_set_clsvof", "clsvof_projection"): + assert all("stabilization" not in s for s in split_problem(doc, name)["subproblems"]) + + +def test_what_the_old_spec_leaves_unstated_is_still_reported_not_filled_in(doc): + split = {s["name"]: s for s in split_problem(doc, "level_set_five")["subproblems"]} + assert missing(split["rdls"]["stabilization"]) == ["shock_capturing.beta", "shock_capturing.reference"] + assert missing(split["vof"]["stabilization"]) == ["tau", "lagged"] + assert missing(split["flow"]["stabilization"]) == ["tau", "shock_capturing.beta", "shock_capturing.reference"] + + +def test_the_old_spec_round_trips_through_an_archive(tmp_path): + realization = {"h": 0.0322} + spec, again, digest = roundtrip(tmp_path, DAMBREAK, "level_set_five", realization) + # the key is the old spec's: reading it again from its archive gives the same one, and the archived blocks resolve + # to what the fixture's did + for name in ("flow", "vof", "ncls", "rdls", "mcorr"): + assert subproblem(again, "level_set_five", name).get("stabilization") == subproblem( + spec, "level_set_five", name).get("stabilization") + split = {s["name"]: s for s in split_problem(again, "level_set_five")["subproblems"]} + assert split["rdls"]["stabilization"] == SHOCK_ONLY + # and the statement is part of the key: the same spec with RDLS's shock capturing changed has another one + other = load_ymf(DAMBREAK) + subproblem(other, "level_set_five", "rdls")["stabilization"] = {"shock_capturing": {"factor": 0.8, "lag": False}} + assert closure.input_digest(other, "level_set_five", realization) != digest + + +def test_the_old_block_and_the_same_in_ymfs_new_words_resolve_alike(doc): + new = load_ymf(DAMBREAK) + subproblem(new, "level_set_five", "rdls")["stabilization"] = { + "method": "none", "shock_capturing": {"factor": 0.9, "lagged": False}} + rdls = lambda d: {s["name"]: s for s in split_problem(d, "level_set_five")["subproblems"]}["rdls"] # noqa: E731 + assert rdls(doc)["stabilization"] == rdls(new)["stabilization"] == SHOCK_ONLY