Skip to content

Add PYEXT: constitutive laws written in Python, driven by the C++ solver - #106

Open
chemiskyy wants to merge 2 commits into
masterfrom
feature/pyext
Open

Add PYEXT: constitutive laws written in Python, driven by the C++ solver#106
chemiskyy wants to merge 2 commits into
masterfrom
feature/pyext

Conversation

@chemiskyy

Copy link
Copy Markdown
Member

A law implementing simcoon.PythonUMAT is registered under the name PYEXT for the duration of a call and integrated by the C++ material-point solver exactly like a built-in kernel: same 24-argument convention, same start-of-increment rollback (so all history must live in statev), same step-cut protocol (raise StepCut).

Core, free of Python: umat_callback.{hpp,cpp} holds the callback slot and the free function umat_callback_M, dispatched from select_umat_M and select_umat_M_finite under id 300. PYEXT joins kirchhoff_box, so the finite-strain dispatcher does not apply a second J factor to a small-strain box.

Bindings: pyumat.{hpp,cpp} bridges numpy and armadillo, re-acquires the GIL that solver_run releases, validates shapes and finiteness before committing anything to the caller's buffers, and maps StepCut onto tnew_dt. launch_umat serves PYEXT through a serial loop, the parallel helper forbidding Python in its region.

Solver: step::compute_inc now returns a status instead of calling exit(0), which killed the interpreter; its callers propagate it through the existing abort path.

Also in this layer: python -m simcoon.doctor reports the OpenMP runtimes actually loaded in the process, and simcoon.identify gains the mape and wmape metrics.

A law implementing simcoon.PythonUMAT is registered under the name PYEXT for the
duration of a call and integrated by the C++ material-point solver exactly like a
built-in kernel: same 24-argument convention, same start-of-increment rollback (so
all history must live in statev), same step-cut protocol (raise StepCut).

Core, free of Python: umat_callback.{hpp,cpp} holds the callback slot and the free
function umat_callback_M, dispatched from select_umat_M and select_umat_M_finite
under id 300. PYEXT joins kirchhoff_box, so the finite-strain dispatcher does not
apply a second J factor to a small-strain box.

Bindings: pyumat.{hpp,cpp} bridges numpy and armadillo, re-acquires the GIL that
solver_run releases, validates shapes and finiteness before committing anything to
the caller's buffers, and maps StepCut onto tnew_dt. launch_umat serves PYEXT
through a serial loop, the parallel helper forbidding Python in its region.

Solver: step::compute_inc now returns a status instead of calling exit(0), which
killed the interpreter; its callers propagate it through the existing abort path.

Also in this layer: python -m simcoon.doctor reports the OpenMP runtimes actually
loaded in the process, and simcoon.identify gains the mape and wmape metrics.

Claude-Session: https://claude.ai/code/session_01Ni71E8DCPGa3NpbLZ3YboR
test_linear_elastic_matches_eliso[uniaxial] failed on ubuntu-latest: six of a
hundred and fifty stress entries differed by about 1e-9 while the field itself
reaches 1e7. Those are the transverse components that mixed control drives to zero;
they sit in the same array as values sixteen orders of magnitude larger, and the
Python law and ELISO reach them through a different order of floating-point
operations — a difference the platform's BLAS changes. A fixed atol of 1e-9 is
therefore below the resolution of the array it is applied to.

The absolute tolerance now follows the field, atol + rtol * max|reference|, which is
1e-3 on a 1e7 stress field and unchanged on a strain field of order 1e-2. The
comparison stays at 1e-10 of the field, so it still catches any real discrepancy in
the bridge.

Claude-Session: https://claude.ai/code/session_01Ni71E8DCPGa3NpbLZ3YboR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

1 participant