rustfront 0.5.0

Evaluate MFront material behaviours (constitutive laws) at a material point, in pure Rust, without MGIS or any C++ build dependency
Documentation
# rustfront

[![CI](https://github.com/Pyrucast/rustfront/actions/workflows/ci.yml/badge.svg)](https://github.com/Pyrucast/rustfront/actions/workflows/ci.yml)
[![crates.io](https://img.shields.io/crates/v/rustfront.svg)](https://crates.io/crates/rustfront)
[![docs.rs](https://docs.rs/rustfront/badge.svg)](https://docs.rs/rustfront)

Evaluate [MFront] material behaviours (constitutive laws) at a material point,
in pure Rust.

MFront compiles material behaviours (elasticity, plasticity, creep, …) into
shared libraries. `rustfront` loads the libraries generated with MFront's
`generic` interface and integrates a behaviour at one material point, from
Rust code such as the [pyrucast] finite-element library.

It talks to the generated library directly: no [MGIS], no C or C++ build
dependency, nothing to compile but Rust.

> **Status:** early development. Small strain, finite strain and general
> behaviours, isotropic or orthotropic, point-wise models (`@DSL
> DefaultModel`, …) and material properties (`@DSL MaterialLaw`), for every
> modelling hypothesis, generated by TFEL 5.1.0 or later. Finite strain
> behaviours compute the Cauchy stress or either Piola-Kirchhoff stress, with
> any of their tangent operators; orthotropic behaviours come with the
> rotations between the global frame and their material frame.

The arrays of a material point (gradients, thermodynamic forces, material
properties, internal and external state variables) are borrowed from the
caller, who can keep the values of all its points in contiguous storage.
Only loading a library is `unsafe`; integrating is safe.

## Requirements

- Behaviours compiled by MFront (TFEL 5.1.0 or later) with the `generic`
  interface: `mfront --obuild --interface=generic Norton.mfront`.
- Rust 1.88 or later.
- To run the tests, `mfront` in the `PATH`: the tests compile the behaviours
  of `tests/behaviours` and fail without it. `./scripts/check.sh` runs every
  check of the CI, and `./scripts/install-tfel.sh <version> <prefix>` builds
  and installs a TFEL version.

## Try it

With `mfront`, `mtest` and `tfel-config` (TFEL 5.1.0 or later), `cargo` and
`python3` in the `PATH`:

```bash
./scripts/try.sh
```

The script compiles the test behaviours of `tests/behaviours`, runs the
minimal example, then runs every case of `mtest-rs/cases` with MTest and with
[mtest-rs](mtest-rs), compares the two result files column by column with
`scripts/compare.py`, and checks that both make the same number of Newton
iterations at every step. Everything it writes goes to `target/try`.

The MTest of TFEL 5.1 and before has two mistakes in finite strain, fixed in
TFEL's master branch, which mtest-rs follows (see `mtest-rs/README.md`): with
such an MTest, the finite strain cases agree in results, not in iterations,
and the two cases it gets wrong are compared with its results on the same
tests written otherwise.

`scripts/tfel-suite.py <TFEL sources>` goes further: it compiles the test
behaviours of TFEL's generic interface from a checkout of the TFEL sources
(the version of the TFEL in the `PATH`), runs each of their MTest tests with
MTest and with mtest-rs, and reports which ones agree, and why mtest-rs fails
on the others. Everything it writes goes to `target/tfel-suite`.

## Minimal example

[`examples/minimal.rs`](examples/minimal.rs) loads a behaviour, prints its
description, integrates it once at one material point and prints the stress
and the tangent operator:

```bash
mfront --obuild --interface=generic tests/behaviours/Elasticity.mfront
cargo run --example minimal -- src/libBehaviour.so
```

## mtest-rs

[mtest-rs](mtest-rs), in this repository, tests a behaviour at one material
point over a loading history: an unofficial, independent reimplementation of
a subset of MTest built on `rustfront`, reading the same `.mtest` files and
writing the same `.res` files.

## Relation to MGIS

[MGIS] is the official library for calling MFront behaviours from a solver,
with C, Fortran, Python and Julia bindings; Rust bindings are on its roadmap
([thelfer/MFrontGenericInterfaceSupport#376](https://github.com/thelfer/MFrontGenericInterfaceSupport/issues/376)).
`rustfront` takes another route: it reads the description each behaviour
exports and calls the behaviour itself, without going through MGIS.

## Releasing

`rustfront` and `mtest-rs` share one version, declared twice in the root
`Cargo.toml`: in `[workspace.package]`, and in the `rustfront` entry of
`[workspace.dependencies]`. To release:

```bash
# set the new version on both lines of Cargo.toml, then
git commit -am "Release X.Y.Z"
git tag -a vX.Y.Z -m "rustfront and mtest-rs X.Y.Z"
git push origin master vX.Y.Z
```

The tag starts `.github/workflows/release.yml`: it checks that the tag matches
`Cargo.toml`, runs the CI, publishes `rustfront` then `mtest-rs` on crates.io
through Trusted Publishing (no token stored in GitHub), and creates the GitHub
release. Each crate must have this workflow as its trusted publisher on
crates.io: owner `Pyrucast`, repository `rustfront`, workflow `release.yml`,
no environment.

## License

Licensed under either of

- Apache License, Version 2.0 ([LICENSE-APACHE]LICENSE-APACHE or
  <https://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT]LICENSE-MIT or
  <https://opensource.org/licenses/MIT>)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in this work by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.

[MFront]: https://thelfer.github.io/tfel/web/index.html
[MGIS]: https://github.com/thelfer/MFrontGenericInterfaceSupport
[pyrucast]: https://github.com/Pyrucast/pyrucast