10 #ifdef LIBTORCH_ENABLED 21 "Material object which relies on the evaluation of a TorchScript module.");
23 "prop_names",
"The names of the properties this material will generate.");
25 "input_names",
"The input parameters for the neural network.");
27 "torch_script_userobject",
28 "The name of the user object which contains the torch script module.");
35 _prop_names(getParam<
std::vector<
std::string>>(
"prop_names")),
36 _num_props(_prop_names.size()),
37 _input_names(getParam<
std::vector<PostprocessorName>>(
"input_names")),
38 _num_inputs(_input_names.size()),
40 _input_tensor(torch::zeros(
42 torch::TensorOptions().dtype(torch::kFloat64).device(_app.getLibtorchDevice())))
45 paramError(
"prop_names",
"Must declare at least one property!");
48 paramError(
"input_names",
"Must declare at least one input to the neural net!");
50 for (
const auto & input_name : _input_names)
51 _module_inputs.push_back(&getPostprocessorValueByName(input_name));
53 for (
const auto & prop_name : _prop_names)
54 _properties.push_back(&declareGenericProperty<Real, false>(prop_name));
73 for (
unsigned int input_i = 0; input_i <
_num_inputs; ++input_i)
78 mooseError(
"The tensor needs to be the same length (right now ",
80 ") as the number of properties (right now ",
84 const auto output_accessor = output.accessor<
Real, 2>();
85 for (
unsigned int prop_i = 0; prop_i <
_num_props; ++prop_i)
std::vector< GenericMaterialProperty< Real, false > * > _properties
Vector of all the properties, for now we don't support AD.
static InputParameters validParams()
registerMooseObject("MooseApp", TorchScriptMaterial)
std::vector< const PostprocessorValue * > _module_inputs
The module input parameters stored as postprocessor values.
const unsigned int _num_inputs
Number of inputs to the neural net.
torch::Tensor _input_tensor
Place holder for the inputs to the neural network.
A user object the loads a torch module using the torch script format and just-in-time compilation...
This material declares properties which are evaluated as based on a torch script neural network...
const TorchScriptUserObject & _torch_script_userobject
The user object that holds the torch module.
static InputParameters validParams()
TorchScriptMaterial(const InputParameters ¶meters)
Materials compute MaterialProperties.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int _num_props
Number of properties that will be defined.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
virtual void initQpStatefulProperties() override
Initialize stateful properties at quadrature points.
void computeQpValues()
A helper method for evaluating the torch script module and populating the material properties...
torch::Tensor evaluate(const torch::Tensor &input) const
Function to evaluate the torch script module at certain input.
virtual void computeQpProperties() override
Users must override this method.