|
NEML2 2.0.0
|
In this tutorial, we will revisit the problem defined in the previous tutorial and demonstrate how to work with model parameters.
Recall that the linear elasticity material model can be mathematically written as
\[ \boldsymbol{\sigma} = 3 K \operatorname{vol} \boldsymbol{\varepsilon} + 2 G \operatorname{dev} \boldsymbol{\varepsilon}. \]
Also recall that all NEML2 models can be written in the following general form
\[ y = f(x; p, b). \]
Pattern matching suggests the following set definitions:
\[ x = \left\{ \boldsymbol{\varepsilon} \right\}, \quad y = \left\{ \boldsymbol{\sigma} \right\}, \quad p = \left\{ K, G \right\}, \quad b = \varnothing. \]
Both \( K \) and \( G \) are here categorized as model parameters. The major differences between parameters and buffers are
In summary, parameter is a more powerful superset of buffer. However, there is overhead cost associated with maintaining a parameter that buffers avoid.
All model parameters are associated with a unique name, either predefined by the model itself or chosen by the user. The following code iterates through all parameters in the model and print out their values:
C++
Output: @list-output:ex1
Python
Output: @list-output:ex2
neml2::Model::get_parameter can be used to retrieve a specific parameter given its name. In other words, the above code is equivalent to
C++
Output: @list-output:ex3
Python In Python, model parameters can be more conveniently retrieved as attributes, i.e.
Output: @list-output:ex4
Model parameters can always be changed by changing the input file. However, in certain cases (e.g., training and optimization), the parameter values should preferrably be updated at runtime (e.g., after each epoch or optimization iteration).
The neml2::Model::set_parameter and neml2::Model::set_parameters methods can be used for that purpose:
C++
Output: @list-output:ex5
Python
Output: @list-output:ex6