Phase D PR1: recipe API for implicit residual equations (strain-coupled scalar state) - #99
Merged
Merged
Conversation
added 3 commits
June 16, 2026 12:02
…nt scope (t2s-only/dt/differentiability); robustness test for state-as-coefficient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First PR of the strain-coupled-state frontier (verified reachable by the Mode-B spike). Adds the recipe IR + API to declare a scalar state defined by an implicit residual
R(x, inputs) = 0(solved by a Newton solver), rather than a ratedx/dt = f(x).Why a new mechanism: a rate is
scalar_expression-typed, hence strain-independent by construction (the cas scalar node set has no bridge to a tensor leaf). A residual is expected to depend on the tensor strain — that's the coupling — so it'stensor_to_scalar-typed (a scalar built from the scalar state/params AND tensor inputs, e.g.x − c·trace(ε)). Confirmedx − c·trace(ε)auto-builds as t2s, no manual wrapping.This is purely the recipe API — no emission yet (PR2 = NumSimMaterialTarget Mode-B emission; PR3 = e2e golden).
API
struct ResidualEquation { state_variable_idx; expression_holder<tensor_to_scalar_expression> residual; doc; }add_scalar_residual_equation(ScalarStateVariableHandle const&, residual, doc="")residual_equations()accessor.Validation
Refactor
Extracted the shared handle-resolution (cross-recipe-hijack + bare-leaf defenses + index lookup) into
resolve_scalar_state_var_index_, now used by bothadd_scalar_evolution_equationandadd_scalar_residual_equation(caller-name parameterized; the one message-asserting test preserved). Plus a sharedassert_state_var_unbound_for the XOR guard.Tests
6 new (
RecipeTest): store-strain-coupled-residual, undeclared-leaf, state-must-appear, rate↔residual mutual exclusion (both orders), cross-recipe handle rejection. Full suite 280 pass.Scoped tight: no RecipeView (pass-view) forwarding — PR2's target reads ConstitutiveModel directly; will add when a pass needs it.
🤖 Generated with Claude Code