Skip to content

Phase 2.6 — MOOSE backend state-variable wiring (declareProperty / getMaterialPropertyOld / _dt) #77

Description

@petlenz

Phase 2.6 — wire state variables through the MOOSE backend so an evolution recipe (state variable + evolution equation, with enable_local_newton()) emits a compilable, correct MOOSE Material. Today the MOOSE target is provably wrong for such recipes — pinned by the MooseBackendDoesNotYetWireStateVariables_KNOWN_GAP guard test in tests/IntegrationTest.cpp. This issue flips that guard to a positive check.

The problem (confirmed)

src/targets/moose_material.cpp iterates parameters() / inputs() / outputs() and never handles Category::StateVariableCurrent / StateVariableOld. Two concrete failures for an evolution recipe:

  1. No member / binding for the state variable. <sv> and <sv>_old are never declared, so the generated .C references undeclared members.
  2. Arity-mismatched compute call. emit_compute_qp_body rebuilds the argument list as parameters() → inputs() → outputs(), independently of render_compute_function's actual order (symbols() registration order → outputs → newton-owned <sv>_out). It omits the state-variable arguments entirely (observed: a 3-arg call into a 7-parameter function).

Deliverables

  1. Member declarations (MOOSE Material class):
    • StateVariableCurrentMaterialProperty<Real> & _<sv>; (writable, declareProperty)
    • StateVariableOldconst MaterialProperty<Real> & _<sv>_old; (getMaterialPropertyOld)
  2. Constructor init list:
    • _<sv>(declareProperty<Real>("<Model>_<sv>"))
    • _<sv>_old(getMaterialPropertyOld<Real>("<Model>_<sv>")) — note MOOSE's getMaterialPropertyOld takes the SAME declared property name; "old" is automatic state versioning.
  3. dt mapping. The auto-registered dt scalar parameter must map to MOOSE's built-in _dt (the framework timestep), NOT getParam<Real>("dt"). Special-case the state_time_step_name symbol in both validParams (skip — it's not an input-file param) and the compute call (pass _dt).
  4. computeQpProperties call-site in the GENERATED order. The call must reproduce render_compute_function's argument order exactly:
    • symbols in registration order, with: parameters → _<name>, scalar inputs → _<name>[_qp], tensor inputs → adaptor, StateVariableOld_<sv>_old[_qp], dt_dt, and StateVariableCurrent SKIPPED (it's an out-param in the Newton path);
    • then outputs (_<name>[_qp] / adaptor);
    • then newton-owned <sv>_out_<sv>[_qp] (the writable declareProperty).
  5. State initialisation. initQpStatefulProperties() (or equivalent) sets _<sv>[_qp] to the StateVariable's initial_value at simulation start. (Scalar initial values; expression-valued initials can reuse the scalar emit.)
  6. Flip the guard test. MooseBackendDoesNotYetWireStateVariables_KNOWN_GAP → positive assertions: getMaterialPropertyOld<Real>("...<sv>") declared, declareProperty for the current, compute call has matching arity, _dt used. Closes Phase 2.2: render_compute_function Category-aware branch for StateVariable symbols #60's MOOSE half.

Architectural decision (resolve in implementation)

Argument-order coupling. The MOOSE call-site and render_compute_function independently reconstruct the argument order — a latent drift hazard (they already diverge today). Recommend extracting a single canonical_argument_order(model, newton_owned) → vector<ArgSpec> helper that BOTH the function signature and every backend's call-site iterate, so the order has one source of truth. This is the robust fix and prevents the next backend (Abaqus/ANSYS) from re-introducing the same bug.

Out of scope

Acceptance

  • A linear-hardening + an autocatalytic-cure recipe each emit a MOOSE .h/.C pair that is self-consistent: every referenced member is declared, the compute call arity matches the generated function, dt_dt, state var initialised.
  • MooseBackendDoesNotYetWireStateVariables_KNOWN_GAP rewritten to positive checks and passing.
  • All existing tests stay green.

Refs

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions