# rustfront
[](https://github.com/Pyrucast/rustfront/actions/workflows/ci.yml)
[](https://crates.io/crates/rustfront)
[](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 behaviours, for every
> modelling hypothesis, generated by TFEL 5.1.0 or later.
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.
## Try it
With `mfront` and `mtest` (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`.
## 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