https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NEML2ModelExecutor.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#pragma once
11
12#include "NEML2ModelInterface.h"
13#include "GeneralUserObject.h"
15
16class MOOSEToNEML2;
17
23class NEML2ModelExecutor : public NEML2ModelInterface<GeneralUserObject>
24{
25public:
28
30
31 NEML2ModelExecutor(const InputParameters & params);
32
33#ifndef NEML2_ENABLED
34 void initialize() override {}
35 void execute() override {}
36 void finalize() override {}
37#else
38 void initialize() override;
39 void meshChanged() override;
40 void execute() override;
41 void finalize() override;
42
43 void initialSetup() override;
44
46 std::size_t getBatchIndex(dof_id_type elem_id) const;
47
49 const neml2::Tensor & getOutput(const neml2::VariableName & output_name) const;
50
52 const neml2::Tensor & getOutputDerivative(const neml2::VariableName & output_name,
53 const neml2::VariableName & input_name) const;
54
56 const neml2::Tensor & getOutputParameterDerivative(const neml2::VariableName & output_name,
57 const std::string & parameter_name) const;
58
60 bool outputReady() const { return _output_ready; }
61
62protected:
64 virtual void addGatheredVariable(const UserObjectName &, const neml2::VariableName &);
65
67 virtual void addGatheredParameter(const UserObjectName &, const std::string &);
68
70 virtual void checkExecutionStage() const final;
71
73 virtual void fillInputs();
74
76 virtual bool solve();
77
79 virtual void extractOutputs();
80
82 virtual void expandInputs();
83
85 void advanceState();
86
89
92
95
98
100 std::map<std::string, neml2::Tensor> _model_params;
101
103 neml2::ValueMap _in;
104
106 neml2::ValueMap _out;
107
110
112 neml2::DerivMap _dout_din;
113
114 // set of gathered NEML2 input variables
115 std::set<neml2::VariableName> _gathered_variable_names;
116
117 // set of gathered NEML2 model parameters
119
121 std::vector<const MOOSEToNEML2 *> _gatherers;
123
125 mutable neml2::ValueMap _retrieved_outputs;
126
128 mutable neml2::DerivMap _retrieved_derivatives;
129
131 mutable std::map<neml2::VariableName, std::map<std::string, neml2::Tensor>>
133
134private:
136 bool _error;
139#endif
140};
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
Common interface for inserting gathered MOOSE data into the NEML2 material model.
NEML2BatchIndexGenerator iterates over the mesh and generates a map from element ID to batch index wh...
NEML2ModelExecutor executes a NEML2 model.
std::map< neml2::VariableName, std::map< std::string, neml2::Tensor > > _retrieved_parameter_derivatives
set of parameter derivatives that were retrieved (by other objects)
neml2::DerivMap _retrieved_derivatives
set of derivatives that were retrieved (by other objects)
void initialSetup() override
Gets called at the beginning of the simulation before this object is asked to do its job.
const bool _debug_inputs_on_failure
Dump input tensor info on failure to aid debugging.
neml2::ValueMap _out
The output variables of the material model.
bool _error
Whether an error was encountered.
void execute() override
Execute method.
const neml2::Tensor & getOutputDerivative(const neml2::VariableName &output_name, const neml2::VariableName &input_name) const
Get a reference(!) to the requested output derivative view.
std::string _error_message
Error message.
static InputParameters actionParams()
Parameters that can be specified under the NEML2Action common area.
virtual bool solve()
Perform the material update.
std::set< std::string > _gathered_parameter_names
neml2::ValueMap _retrieved_outputs
set of output variables that were retrieved (by other objects)
neml2::ValueMap _in
The input variables of the material model.
bool outputReady() const
check if the output is fully computed and ready to be fetched
std::vector< const MOOSEToNEML2 * > _param_gatherers
virtual void checkExecutionStage() const final
Prevent output and derivative retrieval after construction.
static InputParameters validParams()
const bool _manage_state_advance
Advance state on device (rather than via MOSOE material properties)
bool _output_ready
flag that indicates if output data has been fully computed
const neml2::Tensor & getOutputParameterDerivative(const neml2::VariableName &output_name, const std::string &parameter_name) const
Get a reference(!) to the requested output parameter derivative view.
virtual void addGatheredVariable(const UserObjectName &, const neml2::VariableName &)
Register a NEML2 input variable gathered by a gatherer.
std::size_t getBatchIndex(dof_id_type elem_id) const
Get the batch index for the given element ID.
void advanceState()
Save stateful variables for on-device state advance.
void finalize() override
Finalize.
std::map< std::string, neml2::Tensor > _model_params
The model parameters to update (gathered from MOOSE)
const NEML2BatchIndexGenerator & _batch_index_generator
The NEML2BatchIndexGenerator used to generate the element-to-batch-index map.
neml2::DerivMap _dout_din
The derivative of the output variables w.r.t. the input variables.
virtual void extractOutputs()
Extract output derivatives with respect to input variables and model parameters.
void initialize() override
Called before execute() is ever called so that data can be cleared.
neml2::ValueMap _state_vars
Cached variables from the last successful step (for on-device advance)
virtual void fillInputs()
Fill input variables and model parameters using the gatherers.
const neml2::Tensor & getOutput(const neml2::VariableName &output_name) const
Get a reference(!) to the requested output view.
virtual void expandInputs()
Expand tensor shapes if necessary to conformal sizes.
std::vector< const MOOSEToNEML2 * > _gatherers
MOOSE data gathering user objects.
virtual void addGatheredParameter(const UserObjectName &, const std::string &)
Register a NEML2 model parameter gathered by a gatherer.
void meshChanged() override
Called on this object when the mesh changes.
std::set< neml2::VariableName > _gathered_variable_names
Interface class to provide common input parameters, members, and methods for MOOSEObjects that use NE...