- inputPath to the NEML2 input file containing the NEML2 model(s)
C++ Type:DataFileName
Unit:(no unit assumed)
Controllable:No
Description:Path to the NEML2 input file containing the NEML2 model(s)
- modelName of the NEML2 model, i.e., the string inside the brackets [] in the NEML2 input file that corresponds to the model you want to use.
C++ Type:std::string
Unit:(no unit assumed)
Controllable:No
Description:Name of the NEML2 model, i.e., the string inside the brackets [] in the NEML2 input file that corresponds to the model you want to use.
NEML2 syntax
The NEML2
block is used to construct a set of material and user objects so that MOOSE can "outsource" the material update to NEML2. Different objects get created depending on the operation mode (explained below). They are summarized in the following table for convenience:
Object | Type | Operation mode | Description |
---|---|---|---|
CauchyStressFromNEML2 | Material | ELEMENT | Perform element-wise batched material update |
CauchyStressFromNEML2UO | UserObject | ALL | Perform mesh-wise batched material update |
CauchyStressFromNEML2Receiver | Material | ALL | Assign the outputs of the batched material update into the corresponding material properties |
Example Input Syntax
[NEML2]
input = 'models/${neml2_input}.i'
model = 'model'
temperature = 'T'
verbose = true
mode = ELEMENT
device = 'cpu'
[]
(moose/modules/solid_mechanics/test/tests/neml2/fem.i)The field "input" specifies the relative path to the NEML2 input file. The field "model" tells MOOSE which material model to import from the NEML2 input file. The field "device" specifies where to evaluate the NEML2 model, e.g., CPU or CUDA. The parameter "mode" determines the mode of operation for NEML2, and it is important to understand the differences between the modes in order to use NEML2 most efficiently. Each mode is discussed below in detail.
Operation Mode: PARSE_ONLY
In this mode, the NEML2 input file is parsed, and all the objects specified in the NEML2 input file are created. No MOOSE objects are being created in this mode of operation. This mode offers the highest level of flexibility, and requires the most amount of effort to set up the necessary MOOSE objects.
Operation Mode: ELEMENT
In this mode, a regular MOOSE material object CauchyStressFromNEML2
is constructed to perform the constitutive update. On each element, the material
loops through all the quadrature points and gathers all the necessary input variables into a batched input vector with batch size equal to the number of quadrature points;
calls the NEML2 material model to compute the batched output given the batched input;
loops through each quadrature point and assigns the output variables to the corresponding MOOSE material properties.
Operation Mode: ALL
In this mode, a user object CauchyStressFromNEML2UO
and a regular MOOSE material object CauchyStressFromNEML2Receiver
are created. During each residual evaluation,
The user object gathers all input variables from all quadrature points into a batched input vector with batch size equal to the total number of quadrature points on the mesh.
The user object calls the NEML2 material model to compute the batched output given the batched input.
The material object retrieves the batched output from the user object and assigns the output variables to the corresponding MOOSE material properties.
Efficiency Considerations
As discussed earlier, the ELEMENT mode and the ALL mode produce input vectors with different batch sizes. NEML2 handles the threading and vectorization of the batched evaluation. When the batch size is large (i.e. in the ALL mode), it allows for a potentially more aggressive use of the available computing resource, and GPUs can make the evaluation a lot faster relying on massive vectorization.
Verbosity
Only two verbosity levels are currently implemented, e.g., verbose = true
and verbose = false
. In the verbose mode, additional information about the NEML2 material model is printed to the console. An example output is listed below
*** BEGIN NEML2 INFO ***
Input:
----------------------------------------
| Variable | Storage size |
----------------------------------------
| forces/E | 6 |
| forces/t | 1 |
| old_forces/E | 6 |
| old_forces/t | 1 |
| old_state/S | 6 |
| old_state/internal/Kp | 6 |
| old_state/internal/ep | 1 |
| state/S | 6 |
| state/internal/Kp | 6 |
| state/internal/ep | 1 |
----------------------------------------
Output:
------------------------------------
| Variable | Storage size |
------------------------------------
| state/S | 6 |
| state/internal/Kp | 6 |
| state/internal/ep | 1 |
------------------------------------
Parameters:
---------------------------------------------------------
| Parameter | Requires grad |
---------------------------------------------------------
| implicit_rate.kinharden.H | False |
| implicit_rate.isoharden.K | False |
| implicit_rate.normality.flow.yield.sy | False |
| implicit_rate.yield.sy | False |
| implicit_rate.flow_rate.eta | False |
| implicit_rate.flow_rate.n | False |
| implicit_rate.elasticity.E | False |
| implicit_rate.elasticity.nu | False |
---------------------------------------------------------
*** END NEML2 INFO ***
Inspect NEML2 information
The MOOSE solid-mechanics module also provides a command-line option to inspect the NEML2 material model _without_ running the entire simulation. This is achieved using the --parse-neml2-only
command-line argument, i.e.
solid_mechanics-opt -i input.i --parse-neml2-only
Input Parameters
- active__all__ If specified only the blocks named will be visited and made active
Default:__all__
C++ Type:std::vector<std::string>
Unit:(no unit assumed)
Controllable:No
Description:If specified only the blocks named will be visited and made active
- devicecpuDevice on which to evaluate the NEML2 model. The string supplied must follow the following schema: (cpu|cuda)[:
] where cpu or cuda specifies the device type, and : optionally specifies a device index. Default:cpu
C++ Type:std::string
Unit:(no unit assumed)
Controllable:No
Description:Device on which to evaluate the NEML2 model. The string supplied must follow the following schema: (cpu|cuda)[:
] where cpu or cuda specifies the device type, and : optionally specifies a device index. - enable_ADFalseSet to true to enable PyTorch AD. When set to false (default), no function graph or gradient is computed, which speeds up model evaluation.
Default:False
C++ Type:bool
Unit:(no unit assumed)
Controllable:No
Description:Set to true to enable PyTorch AD. When set to false (default), no function graph or gradient is computed, which speeds up model evaluation.
- inactiveIf specified blocks matching these identifiers will be skipped.
C++ Type:std::vector<std::string>
Unit:(no unit assumed)
Controllable:No
Description:If specified blocks matching these identifiers will be skipped.
- modeELEMENTMode of operation for the NEML2 material model.
Default:ELEMENT
C++ Type:MooseEnum
Unit:(no unit assumed)
Controllable:No
Description:Mode of operation for the NEML2 material model.
- temperature0 Coupled temperature
Default:0
C++ Type:std::vector<VariableName>
Unit:(no unit assumed)
Controllable:No
Description:Coupled temperature
- verboseTrueWhether to print additional information about the NEML2 model at the beginning of the simulation
Default:True
C++ Type:bool
Unit:(no unit assumed)
Controllable:No
Description:Whether to print additional information about the NEML2 model at the beginning of the simulation
Optional Parameters
- control_tagsAdds user-defined labels for accessing object parameters via control logic.
C++ Type:std::vector<std::string>
Unit:(no unit assumed)
Controllable:No
Description:Adds user-defined labels for accessing object parameters via control logic.