https://mooseframework.inl.gov
Loading...
Searching...
No Matches
NEML2Action.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 <memory>
13
14#ifdef NEML2_ENABLED
15#include "NEML2ModelHandle.h"
16#endif
17
18#include "Action.h"
19#include "NEML2Utils.h"
21
23
28{
29public:
31
33
34 virtual void act() override;
35
36protected:
37 const NEML2ActionCommon & getCommonAction() const;
38
39#ifdef NEML2_ENABLED
40
41 const FileName & fname() const { return _fname; }
42
44 {
45 std::string name;
47 std::string moose_tensor_type;
48 std::size_t history_order;
49 };
50
52 {
53 std::string name;
54 std::string y;
55 std::string x;
56 std::string moose_tensor_type;
57 };
58
66
69
72
75
78
81
89
93 std::string
94 resolveParameterName(const std::string & user_name,
95 const std::map<std::string, std::vector<int64_t>> & param_shapes) const;
96
99 NEML2Utils::MOOSEIOType inferMOOSEIOType(const std::string & name, bool is_scalar) const;
100
102 FileName _fname;
103
105 std::vector<std::string> _cli_args;
106
109 std::unique_ptr<NEML2ModelHandle> _model;
110
112 std::vector<VariableMapping> _inputs;
113
115 std::vector<VariableMapping> _outputs;
116
118 std::vector<DerivativeMapping> _derivs;
119
121 std::vector<ParameterMapping> _params;
122
124 std::vector<DerivativeMapping> _param_derivs;
125
126#endif
128 const UserObjectName _executor_name;
129
131 const UserObjectName _idx_generator_name;
132
134 const std::vector<SubdomainName> _block;
135
137 std::vector<std::string> _skip_input_variables;
138
140 std::map<MaterialPropertyName, MaterialPropertyName> _initialize_output_values;
141
143 std::map<MaterialPropertyName, std::vector<OutputName>> _export_output_targets;
144
145private:
146#ifdef NEML2_ENABLED
148 template <typename EnumType, typename T>
149 std::tuple<std::vector<EnumType>, std::vector<T>>
150 getInputParameterMapping(const std::string & source_opt, const std::string & name_opt) const
151 {
152 const auto moose_types = getParam<MultiMooseEnum>(source_opt).getSetValueIDs<EnumType>();
153 const auto neml2_names = getParam<std::vector<T>>(name_opt);
154
155 if (moose_types.size() != neml2_names.size())
156 paramError(source_opt, source_opt, " must have the same length as ", name_opt);
157
158 return {moose_types, neml2_names};
159 }
160
162 void printSummary() const;
163#endif
164
166 std::size_t getLongestMOOSEName() const;
167};
Base class for actions.
Definition Action.h:38
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
Input parameters common to all block-restricted NEML2Actions.
Action to set up NEML2 objects.
Definition NEML2Action.h:28
std::vector< ParameterMapping > _params
MOOSE-NEML2 model parameter (value) mappings.
void setupParameterDerivativeMappings(const NEML2ModelHandle &)
Set up MOOSE-NEML2 output-parameter-derivative mappings.
void setupInputMappings(const NEML2ModelHandle &)
Set up MOOSE-NEML2 input variable mappings.
std::vector< VariableMapping > _inputs
MOOSE-NEML2 input variable mappings.
const FileName & fname() const
Definition NEML2Action.h:41
void setupOutputMappings(const NEML2ModelHandle &)
Set up MOOSE-NEML2 output variable mappings.
const NEML2ActionCommon & getCommonAction() const
std::vector< std::string > _skip_input_variables
Input variables to skip (i.e., not to set up mappings for)
std::vector< std::string > _cli_args
List of cli-args.
void setupParameterMappings(const NEML2ModelHandle &)
Set up MOOSE-NEML2 model parameter (value) mappings.
std::vector< DerivativeMapping > _param_derivs
MOOSE-NEML2 output-parameter-derivative mappings.
static InputParameters validParams()
Definition NEML2Action.C:66
std::unique_ptr< NEML2ModelHandle > _model
The neml2 model handle, used here only for introspection during setup.
const UserObjectName _idx_generator_name
Name of the NEML2BatchIndexGenerator user object.
void printSummary() const
Print a summary of the NEML2 model.
void setupDerivativeMappings(const NEML2ModelHandle &)
Set up MOOSE-NEML2 derivative mappings.
std::map< MaterialPropertyName, std::vector< OutputName > > _export_output_targets
Material property additional outputs.
std::vector< VariableMapping > _outputs
MOOSE-NEML2 output variable mappings.
void checkStatefulConsistency(const NEML2ModelHandle &) const
Validate consistency between the action configuration and the model's I/O before MOOSE wires up (stat...
const std::vector< SubdomainName > _block
Blocks this sub-block action applies to.
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
const UserObjectName _executor_name
Name of the NEML2Executor user object.
NEML2Utils::MOOSEIOType inferMOOSEIOType(const std::string &name, bool is_scalar) const
Infer the MOOSE IO type from the variable name (only scalar-typed variables can map to time/scalar/fu...
std::vector< DerivativeMapping > _derivs
MOOSE-NEML2 derivative mappings.
std::map< MaterialPropertyName, MaterialPropertyName > _initialize_output_values
Material property initial conditions.
FileName _fname
Name of the NEML2 input file.
std::string resolveParameterName(const std::string &user_name, const std::map< std::string, std::vector< int64_t > > &param_shapes) const
Resolve a user-written parameter name to a fully-qualified NEML2 parameter name.
std::tuple< std::vector< EnumType >, std::vector< T > > getInputParameterMapping(const std::string &source_opt, const std::string &name_opt) const
Get parameter lists for mapping between MOOSE and NEML2 quantities.
std::size_t getLongestMOOSEName() const
Get the maximum length of all MOOSE names (for printing purposes)
Runtime-agnostic handle over a NEML2 v3 model.
std::string moose_tensor_type
MOOSE C++ tensor type string of the derivative block.
Definition NEML2Action.h:56
std::string moose_tensor_type
MOOSE C++ tensor type string.
Definition NEML2Action.h:64
std::string neml2_name
fully-qualified NEML2 parameter name (set target)
Definition NEML2Action.h:62
std::string moose_name
MOOSE quantity name (from_moose source)
Definition NEML2Action.h:61
NEML2Utils::MOOSEIOType moose_type
Definition NEML2Action.h:63
std::string name
MOOSE quantity name (base name, no ~N lag suffix)
Definition NEML2Action.h:45
std::string moose_tensor_type
MOOSE C++ tensor type string (e.g. SymmetricRankTwoTensor)
Definition NEML2Action.h:47
NEML2Utils::MOOSEIOType moose_type
Definition NEML2Action.h:46