Skip to content
PyrucastPublic

About

Use MFront material behaviours from Rust, in pure Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

rustfront

CI crates.io docs.rs

Evaluate MFront material behaviours (constitutive laws) at a material point, in pure Rust. This repository holds two crates, released together under one version:

  • rustfront, the library: it loads the libraries generated with MFront's generic interface and integrates a behaviour at one material point, with no C or C++ build dependency. Its README presents the API through a minimal example.
  • mtest-rs, the command line tool: an unofficial, independent reimplementation of a subset of MTest built on rustfront, which reads the same .mtest files and writes the same .res files.

Development

The tests compile the behaviours of rustfront/tests/behaviours with mfront and fail without it; the comparison with MTest needs mtest. Both come with TFEL 5.1.0 or later:

./scripts/check.sh                            # every check of the CI
./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:

./scripts/try.sh

The script compiles the test behaviours of rustfront/tests/behaviours, runs the minimal example, then runs every case of mtest-rs/cases, and the one of the Cast3M acceleration algorithm with ten of MTest's others, with MTest and with mtest-rs, compares the two result files column by column with scripts/compare.py, and their JUnit reports, checks that both make the same number of Newton iterations at every step, and that both fail alike on a check of @Test made wrong on purpose. 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 runs TFEL's own MTest tests, read from a checkout of the TFEL sources (the version of the TFEL in the PATH), with MTest and with mtest-rs, with the options CMake gives MTest, and reports which ones agree, and why mtest-rs fails on the others. It compiles their behaviours and material properties with the generic interface. The tests written for the other interfaces of MFront (Cast3M, code_aster, Abaqus, Ansys, CalculiX, Cyrano, DIANA FEA, and those of MTest's acceleration algorithms, written for Cast3M) are ported to it: the behaviour is called by its generic name, the material properties the interface adds become evolutions, and the default stiffness MTest gives that interface is kept. MTest runs the same ports as mtest-rs: a port MTest fails is set aside. Everything it writes goes to target/tfel-suite.

With TFEL 5.1.0, rustfront loads the 187 behaviours and 54 material properties. The 2632 tests make 3611 cases, each finite strain test of the generic interface being run with the 12 combinations of a stress measure and a tangent operator. Wherever both run a test, mtest-rs and MTest write the same JUnit report; their results compare so:

Outcome generic Cast3M other interfaces accelerations
mtest-rs and MTest agree to 1e-12 1066 372 619 647
agree to 1e-9: round-off amplified (numerical Jacobian, accelerations) 43 23 26 142
agree to 1e-12, but for zeros of round-off: free stresses in MPa 1 0 0 0
both fail, as the test expects 10 11 34 0
differ: finite strain mistakes of MTest 5.1, round-off 89 14 21 74
mtest-rs fails a check of the test: finite strain, see below 0 1 0 9
a port MTest fails 0 23 22 137
not portable 0 57 0 170

No test fails for a feature of MTest that mtest-rs lacks.

A test is not portable when its behaviour uses one of the finite strain strategies of the Cast3M interface (175 cases), when the generic behaviour is not compiled for its hypothesis, plane stress that the Cast3M interface handles itself (49), or when it needs an environment variable of that interface (3). MTest fails 182 ports: in 113, the behaviour computes no stiffness operator at all, MTest computing the elastic stiffness from the material properties for the Cast3M interface only; 30 rest on the sub-stepping of the Cast3M interface, 12 on the kinematics of Abaqus/Explicit or Cyrano (strain components, small or finite strain keywords), 10 on the material property of thermal expansion the Cast3M interface adds to a finite strain behaviour; 4 do not converge, 11 fail a check of the test, and 2, tests of an interface's policy for out of bounds values, do not fail.

Of the 198 cases which differ, 159 are finite strain ones: the 88 cases of the generic interface and 71 ports, with loose criteria that MTest 5.1's residual makes stop elsewhere; with tight criteria, both agree to 1e-9. The others are round-off: GursonTvergaardNeedlemanPlasticFlow, which has a numerical Jacobian, and UnilateralMazars, a damage behaviour (7 cases, with the same iterations at every step), and 32 cases with tens of accelerated iterations per step. In 10 finite strain ports with a loose criterion, castem's mieheapellambrechtlogarithmicstrainnortoncreep-uniaxialloading-3-3D and 9 of the acceleration algorithms, mtest-rs misses a check of the test, as the MTest of TFEL's master branch does, whose residual is the same: MTest 5.1 passes them with its own.

MTest is compiled with -march=native, so its products may be fused: mtest-rs, which follows its algorithm, cannot follow its round-off bit for bit. Where a numerical Jacobian or tens of iterations of an acceleration algorithm amplify it, the results agree to 1e-9 only; in orthotropiccreep, the accelerated iterations of both agree to six digits for twenty iterations, then part, and stop after another number of iterations, as reversing the order of a single sum in mtest-rs does. The Anderson algorithms are the most sensitive: in a uniaxial test their residuals are aligned, and the round-off decides their weights, which MTest computes in long double (an MTest computing them in double agrees no better with mtest-rs). mtest-rs follows the two fixes of TFEL's master branch to these algorithms: with the MTest of that branch, the cases of uanderson agree with mtest-rs as well as those of fanderson. In ThermoElasticity, whose stresses are in MPa, the free stresses are zeros of round-off, 4.5e-13 in both, not on the same components.

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:

# 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

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.

About

Use MFront material behaviours from Rust, in pure Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages