Skip to content

Host-neutral errors.h and external_state_source.h out of umat/ (#212) - #222

Merged
petlenz merged 4 commits into
mainfrom
feature/host-neutral-headers
Oct 29, 2026
Merged

petlenz merged 4 commits into
mainfrom
feature/host-neutral-headers

Conversation

@petlenz

@petlenz petlenz commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Part of #212 (does not close it: driver/material_point.h still pulls umat/ in, see below). Part of #221: the engine will throw cutback_error itself for a fixed point that does not converge (#214), so the error types cannot live under umat/.

What

  • core/errors.h (new): fatal_error and cutback_error in numsim::materials. The header comment now describes any host; Abaqus is one example. It sits in core/, not driver/, because the property engine is its next user.
  • umat/errors.h: includes core/errors.h and keeps umat::fatal_error / umat::cutback_error as using-declarations, so every UMAT catch site and downstream user keeps compiling. The Abaqus fatal path (xit_, set_fatal_handler, invoke_fatal) stays here because it is UMAT-specific.
  • driver/external_state_source.h (moved from umat/): external_strain_source, external_deformation_gradient_source, external_scalar_source. umat/external_state_source.h remains as a forwarding header, because numsim-fft-homogenization includes it.
  • The strain source no longer reads raw 6-slot buffers. The buffer overload of external_strain_source::bind decoded the UMAT's canonical Voigt order and pulled umat/tensor_conversion.h into the source. The evaluator now converts with umat::strain_from_buffer and binds tensors. The 9-slot row-major overload of the deformation-gradient source involves no Voigt convention, so it stays.
  • driver/ throws fatal_error / cutback_error from numsim::materials and includes neither umat/errors.h nor umat/external_state_source.h.

Decided here

  • umat/json_model.h stays in umat/. It includes umat_interface.h and binds the deck's *USER MATERIAL constants to parameters. report/case_runner.h uses only its builder; separating that builder from the constants binding is a separate change, if it is ever needed.
  • Limit of this PR: driver/material_point.h still includes umat/statev_map.h, which includes umat/errors.h (and its weak xit_ declaration) and umat/tensor_conversion.h. So material_point.h is not yet free of umat/; core/errors.h and driver/external_state_source.h are. The remaining step is to move statev_map out of umat/ (noted on Move the host-neutral headers errors.h and external_state_source.h out of umat/ #212, which stays open).

Tests

test_host_neutral_headers, written first (red: core/errors.h missing):

  • umat::fatal_error / umat::cutback_error are the same types as the numsim::materials ones;
  • external_strain_source has no raw-buffer bind (a requires check);
  • both errors are std::runtime_errors;
  • the tensor bind(tensor2, tensor2) of the strain source stays callable (positive requires check);
  • the forwarder umat/external_state_source.h is compiled in this test.

test_host_neutral_includes includes only core/errors.h and driver/external_state_source.h and #errors if UMAT_ERRORS_H is defined or the guards are not NUMSIM_MATERIALS_CORE_ERRORS_H / NUMSIM_MATERIALS_DRIVER_EXTERNAL_STATE_SOURCE_H. test_umat_forwarder_includes includes only the forwarder and #errors unless umat/tensor_conversion.h came with it.

test_external_state_source's buffer case now converts through umat::strain_from_buffer and checks the same values.

Gate

GCC 14, reports on, -DNUMSIM_PREFER_SIBLINGS=OFF: -O1 build 0 warnings, 1446/1446 tests pass.

fatal_error and cutback_error move to core/errors.h in numsim::materials; umat/ keeps them as using-declarations next to the Abaqus fatal path. The external sources move to driver/, with a forwarding header at the old path. The strain source binds tensors only; the UMAT evaluator converts its Voigt buffers.
…he forwarder's transitive include

A TU that includes only core/errors.h and driver/external_state_source.h checks that umat/errors.h stays out and that the guards are NUMSIM_MATERIALS_*. The forwarder is compiled and again includes umat/tensor_conversion.h. The tensor bind of the strain source gets a positive requires check.
@petlenz

petlenz commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Review findings, addressed in b20e77d:

  1. The test TU included umat/errors.h itself, so it proved nothing. New test_host_neutral_includes includes only core/errors.h and driver/external_state_source.h and #errors if UMAT_ERRORS_H is defined. Red before the fix: the two guard checks below (the UMAT_ERRORS_H check holds already and is a regression guard).
  2. driver/material_point.h still includes umat/statev_map.h (-> umat/errors.h, the weak xit_). Not moved here. The PR body now states the limit and no longer says Closes #212; the remaining step is noted on Move the host-neutral headers errors.h and external_state_source.h out of umat/ #212, which stays open.
  3. The forwarder umat/external_state_source.h had no coverage and had lost its transitive include of umat/tensor_conversion.h. It includes it again, and test_umat_forwarder_includes (red: #error "umat/external_state_source.h must still include umat/tensor_conversion.h") plus the forwarder include in test_host_neutral_headers cover it.
  4. Guards are now NUMSIM_MATERIALS_CORE_ERRORS_H and NUMSIM_MATERIALS_DRIVER_EXTERNAL_STATE_SOURCE_H (red: #error "core/errors.h guard must be NUMSIM_MATERIALS_CORE_ERRORS_H", same for the driver header).
  5. A positive requires { s.bind(t, t); } for two tensor2 sits next to the negative raw-buffer check. It passes before and after (a regression guard, not red).

Gate: GCC 14 -O1, build 0 warnings, 1446/1446 tests pass.

…headers

# Conflicts:
#	tests/test_j2_kinematic_plasticity.cpp
The return-map and convergence failures from #231 included umat/errors.h and
threw umat::cutback_error; the same type now comes from core/errors.h, so no
material header pulls in umat/. test_host_neutral_includes covers the six headers.
@petlenz

petlenz commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

Merged main (#231) into this branch. The only conflict was the include block of tests/test_j2_kinematic_plasticity.cpp (driver/external_state_source.h from here, umat/errors.h from #231).

Follow-up commit bc4cac5: the six materials #231 changed (J2, J2-RK, J2 kinematic, Drucker-Prager, neo_hooke, mean-field kernels) now include core/errors.h and throw the core cutback_error (same type as umat::cutback_error), so no material header pulls in umat/. test_host_neutral_includes.cpp includes the six headers; with the previous headers it fails with #error "a header above includes umat/errors.h".

Gate: GCC 14 -O1, BUILD=0 TEST=0, 0 warnings, 1460 tests.

@petlenz
petlenz merged commit 5960fb8 into main Oct 29, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant