LibtorchModel

commentnote

This is a NEML2 model. See the NEML2 syntax documentation for guidance on using NEML2 models in a MOOSE simulation.

This model is a wrapper for evaluating PyTorch modules in .pt format, mapping an arbitrary number of inputs to an arbitrary number of outputs. See the Torch Script documentation for instructions on exporting PyTorch modules as torch scripts.

Example Input File

An example NEML2 input file is shown below. In this example, a single input inputs = 'forces/T' is mapped to a single output outputs = 'state/k_T'.

[Models]
  [kappa]
    type = LibtorchModel
    inputs = 'forces/T'
    outputs = 'state/k_T'
    file_path = 'libtorch/test/thermal_conductivity_model.pt'
  []
[]
(moose/test/tests/neml2/torchscript/thermal_conductivity.i)

The evaluated NEML2 variable value state/k_T can then be mapped back to a MOOSE material property as shown in the following input file.

[NEML2<<<{"href": "../../../syntax/NEML2/index.html"}>>>]
  input<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: Path to the NEML2 input file containing the NEML2 model(s).)"}>>> = 'thermal_conductivity.i'
  [thermal_conductivity_model]
    model<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original 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.)"}>>> = 'kappa'

    moose_input_types<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: Type of each MOOSE data to be used as NEML2 input variable)"}>>> = 'VARIABLE'
    moose_inputs<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: List of MOOSE data to be used as inputs of the material model.)"}>>> = 'T'
    neml2_inputs<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: List of NEML2 input variables corresponding to each MOOSE data.)"}>>> = 'forces/T'

    moose_output_types<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: MOOSE types used to hold the NEML2 output variables)"}>>> = 'MATERIAL'
    neml2_outputs<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: List of NEML2 output variables corresponding to each MOOSE data.)"}>>> = 'state/k_T'
    moose_outputs<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: List of MOOSE data used to hold the output of the material model.)"}>>> = 'k_T'

    moose_derivative_types<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: MOOSE types used to hold the NEML2 variable derivatives)"}>>> = 'MATERIAL'
    neml2_derivatives<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: List of pairs of NEML2 variables to take derivatives (i.e., first in the pair w.r.t. the second in the pair).)"}>>> = 'state/k_T forces/T'
    moose_derivatives<<<{"description": "The `NEML2` library is required but not enabled. Refer to the documentation for guidance on how to enable it. (Original description: List of MOOSE data used to hold the derivative of the material model.)"}>>> = 'dk_T/dT'

    export_outputs<<<{"description": "List of MOOSE material properties to export which correspond to NEML2 output variables or output derivatives. Each material property's export targets can be specified by export_output_targets. The default export target is 'none'."}>>> = 'k_T dK_T/dT'
    export_output_targets<<<{"description": "The export targets corresponding to each MOOSE material property specified in export_outputs."}>>> = 'exodus; exodus'
  []
[]
(moose/test/tests/neml2/torchscript/heat_conduction.i)

The NEML2 input file is specified inside the NEML2 block. We specify which NEML2 model to use (model = 'rom'), and specify that we want to map the non-linear T variable in MOOSE to the forces/T NEML2 variable, and the state/k_T NEML2 variable is mapped back to the k_T MOOSE material property (which is automatically generated by the action).

NEML2 also uses automatic differenciation on the libtorch model to provide arbitrary derivatives of the outputs in relation to the inputs. Here we specify that we want to calculate to populate the Jacobian in a heat conduction example problem.

References

No citations exist within this document.