|
NEML2 2.0.0
|
Let us start with the simplest example for solid mechanics. Consider a solid material whose elastic behavior (mapping from strain \( \boldsymbol{\varepsilon} \) to stress \( \boldsymbol{\sigma} \), or vice versa) can be described as
\[ \boldsymbol{\sigma} = 3 K \operatorname{vol} \boldsymbol{\varepsilon} + 2 G \operatorname{dev} \boldsymbol{\varepsilon}, \]
where \( K \) is the bulk modulus, and \( G \) is the shear modulus.
All available material models are listed in the syntax documentation. The documentation of each model provides a brief description, followed by a list of input file options. Each option has a short description right next to it, and can be expanded to show additional details.
There is an existing model that solves this exact problem: LinearIsotropicElasticity. The syntax documentation lists the input file options associated with this model.
As explained in the syntax documentation for LinearIsotropicElasticity, the option "strain" is used to specify the name of the variable for the elastic strain, and the option "stress" is used to specify the name of the variable for the stress. The options "coefficients" and "coefficient_types" are used to specify the values of the parameters, in this case \( K \) and \( G \).
Using these information, the input file for constructing this model can be composed as:
There are three common ways of interacting with NEML2 input files:
These methods are discussed in the getting started guide. In this set of tutorials, the C++ example code and the Python script example code are shown side-by-side with tabs, and in most cases the C++ APIs and the Python APIs have a nice one-to-one correspondance.
The following code parses the given input file named "input.i" and retrieves a Model named "my_model". Once retrieved, we can print out a summary of the model by streaming it to the console:
C++
Output:
Python
Output:
The summary includes information about the model's name, input variables, output variables, parameters, and buffers (if any). Note that the variables and parameters are additionally marked with tensor types surrounded by square brackets, i.e., [SR2] and [Scalar]. These are NEML2's primitive tensor types which will be extensively discussed in another set of tutorials (Tensors).
Before going over model evaluation, let us zoom out from this particular example and briefly discuss the structure of NEML2 models.
All NEML2 models, including this simple elasticity model under consideration, take the following general form
\[ y = f(x; p, b), \]
where \( x \) and \( y \) are respectively sets of input and output variables, \( p \) is the set of parameters, and \( b \) is the set of buffers. The utilities of parameters and buffers will be discussed in another tutorial. The forward operator \( f \) is responsible for mapping from input variables \( x \) to \( y \). NEML2 provides three forward operators for all models:
All three forward operators take a map/dictionary of variable values as input and return the requested output variables and/or their derivatives.
In addition to these standard forward operators, some models in NEML2 also support calculating second derivatives. Three additional forward operators are provided to request second derivatives:
Model evaluation consists of two simple steps:
In this example, the elasticity model can be evaluated using the following code:
set_default_dtype(kFloat64) is used to change the default precision to double precision.C++
Output:
Python
Output: