NEML2 2.0.0
|
The following input file defines a linear isotropic elasticity material model:
The input file defines two parameters: Young's modulus of 100 and Poisson's ratio of 0.3. While optional, the input file also sets the variable names of strain and stress to be "forces/E" and "state/S", respectively (refer to the documentation on tensor labeling for variable naming conventions).
Assuming the above input file is named "input_file.i", the C++ code snippet below parses the input file and loads the material model (into the heap).
Once the model is loaded, it can be streamed to provide a high-level summary of the model, i.e.,
The example model produces the following summary
Suppose we want to perform 3 material updates simultaneously, the input variables shall have a batch size of 3 (refer to the tensor system documentation for more detailed explanation on the term "batch"). The following code constructs the 3 input strains and performs 3 material updates simultaneously.
The forward operator is invoked using the neml2::Model::value method which takes a map of neml2::Tensor with keys being neml2::VariableName. Other forward operator APIs are available to additionally calculate the first and second derivatives of the output variables with respect to the input variables. There exist a total of 6 variants of the forward operator:
Method | Output variable values | 1st order derivatives | 2nd order derivatives |
---|---|---|---|
neml2::Model::value | \(\checkmark\) | ||
neml2::Model::dvalue | \(\checkmark\) | ||
neml2::Model::d2value | \(\checkmark\) | ||
neml2::Model::value_and_dvalue | \(\checkmark\) | \(\checkmark\) | |
neml2::Model::dvalue_and_d2value | \(\checkmark\) | \(\checkmark\) | |
neml2::Model::value_and_dvalue_and_d2value | \(\checkmark\) | \(\checkmark\) | \(\checkmark\) |
Each model contains zero or more parameters. The parameters are initialized with values specified in the input file. In the above example, the elasticity model contains two parameters: E
and nu
. Model parameters can be retrieved using the neml2::Model::get_parameter method, the parameter value can be updated using the assignment operator, and automatic differentiation can be used to track the derivatives w.r.t. a parameter:
Alternatively, the parameter value can be directly updated using the neml2::Model::set_parameter or neml2::Model::set_parameters method: