NEML2 2.0.0
|
Let us start with the simplest example for solid mechanics. Consider a solid material whose elastic behavior (mapping from strain
where
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
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:
Output:
Output:
The summary includes information about the model's name, primary floating point numeric type (denoted as "Dtype"), current device, 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.
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
where
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.
Output:
Output:
Previous | Next |
---|---|
Input file | Model parameters |