Skip to content

Rewrite docs/writing_a_material.md for the engine-2 API, with a compiled example #236

Open

Description

@petlenz

Part of #237.

Why

docs/writing_a_material.md (205 lines) predates partials, residual systems, history kinds and the error contract. A material author reading it today learns the declaration style but not:

  • how to make the material differentiable;
  • how to set up a local system;
  • which exception to throw.

The review of #222–#231 found pitfalls an author cannot guess from the API:

  • converges() keeps references to its tolerance and max-passes arguments, so they must be members or parameters;
  • independent_of() applies to every output of the callback;
  • residuals must be normalised scalars, because the tolerance is absolute;
  • checkpoints restore only history properties, never state a material keeps elsewhere;
  • step-size failures throw cutback_error, configuration errors throw logic_error/invalid_argument, and only fatal_error stops a host.

Design

Sections:

  1. Inputs, outputs and history (with kinds).
  2. Callbacks and reads.
  3. Partials and independent_of, and how check_partials verifies them.
  4. Local problems: converges() versus a system (Newton, newton_fd or picard), and what the implicit-function-theorem tangent gives you for free.
  5. Errors and cutbacks.
  6. Testing a material: the conformance list, the finite-difference check, report decks.
  7. Checklist before opening a PR.

The worked example is a small 1D-in-3D viscoelastic (Maxwell) material. It uses a history, a system for the internal variable, declared partials and the tangent from derivative(). It lives in examples/writing_a_material/ and is built and run as a test, and the guide includes it by line ranges, so the guide cannot drift from the code.

Tests

  • The example builds and runs in CI.
  • check_partials and the conformance test cover it.
  • Its tangent matches central finite differences.

Depends on

Can start after #229. It is final after #235, which removes the old paths the guide must no longer mention.

Out of scope

API reference generation (Doxygen); the guide is a tutorial.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions