|
NEML2 2.1.0
|
Once the NEML2 library is built following the installation guide, the immediate question is
How do I evaluate a NEML2 material model?
NEML2 core capabilities are implemented as a library, not a program. As a library, it will be used by another C++ program to parse and evaluate a material model defined in an input file. Boilerplate for the C++ program can be found in the quick start guide below as well as in this set of tutorials, and external project integration is documented in the installation guide.
The other option to evaluate NEML2 material models is to use the NEML2 Python package. As mentioned in the installation guide, NEML2 also provides a Python package which provides bindings for the primitive tensors and parsers for deserializing and running material models. The following quick start guide as well as this set of tutorials describe the usage of the package.
The following is a quick summary of the most common model API usage patterns. Each topic is covered in full detail in the model tutorials.
Given an input file, a model is loaded with a single call:
load_model parses the file and returns the named model ready for evaluation. The running your first model tutorial walks through a complete example.
All NEML2 models expose three forward operators that accept a map of input variable values:
| Operator | Returns |
|---|---|
| value | output variable values \( y = f(x) \) |
| dvalue | first derivatives \( \partial y / \partial x \) |
| value_and_dvalue | both simultaneously |
The return value of neml2::Model::value is a dictionary keyed by output variable name. neml2::Model::dvalue returns a nested dictionary keyed by (output, input) variable names.
Model parameters can be updated at runtime — useful for optimization or training loops. Parameters are accessed by name and assigned new tensor values:
The model parameters tutorial covers parameters and buffers in detail, including how parameters can themselves be defined by other models.
We acknowledge the common need to use NEML2 as a standalone program and therefore provide utility binaries for common tasks.
As documented in build customization, the NEML2_TOOLS CMake option can be used to create these binaries.
When tools are enabled, NEML2 builds the following standalone executables:
When installed, these binaries are placed in the installed bin directory.
For the Python package, matching CLI wrappers are registered in pyproject.toml:
These commands dispatch to the shipped binaries bundled inside the Python package. See each tool's help message (for example, neml2-run --help) for further details.