https://mooseframework.inl.gov
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 "neml2/models/Model.h"
16 #endif
17 
18 #include "Action.h"
19 
20 class NEML2ActionCommon;
21 
25 class NEML2Action : public Action
26 {
27 public:
29 
31 
32  virtual void act() override;
33 
34 protected:
35  const NEML2ActionCommon & getCommonAction() const;
36 
37 #ifdef NEML2_ENABLED
38 
39  const FileName & fname() const { return _fname; }
40 
41  enum class MOOSEIOType
42  {
43  MATERIAL,
44  VARIABLE,
46  };
47 
48  struct MOOSEIO
49  {
50  const std::string name;
52  };
53 
54  struct NEML2IO
55  {
56  const neml2::VariableName name;
57  const neml2::TensorType type;
58  };
59 
60  struct NEML2Param
61  {
62  const std::string name;
63  const neml2::TensorType type;
64  };
65 
67  {
68  const MOOSEIO moose;
69  const NEML2IO neml2;
70  };
71 
73  {
74  const MOOSEIO moose;
76  };
77 
79  {
80  const MOOSEIO moose;
81  const struct NEML2Derivative
82  {
83  const NEML2IO y;
84  const NEML2IO x;
85  } neml2;
86  };
87 
89  {
90  const MOOSEIO moose;
91  const struct NEML2Derivative
92  {
93  const NEML2IO y;
94  const NEML2Param x;
95  } neml2;
96  };
97 
99  void setupInputMappings(const neml2::Model &);
100 
102  void setupParameterMappings(const neml2::Model &);
103 
105  void setupOutputMappings(const neml2::Model &);
106 
108  void setupDerivativeMappings(const neml2::Model &);
109 
111  void setupParameterDerivativeMappings(const neml2::Model &);
112 
114  FileName _fname;
115 
117  std::vector<std::string> _cli_args;
118 
120  std::shared_ptr<neml2::Model> _model;
121 
123  std::vector<VariableMapping> _inputs;
124 
126  std::vector<ParameterMapping> _params;
127 
129  std::vector<VariableMapping> _outputs;
130 
132  std::vector<DerivativeMapping> _derivs;
133 
135  std::vector<ParameterDerivativeMapping> _param_derivs;
136 
137 #endif
138  const UserObjectName _executor_name;
140 
142  const UserObjectName _idx_generator_name;
143 
145  const std::vector<SubdomainName> _block;
146 
148  std::map<MaterialPropertyName, MaterialPropertyName> _initialize_output_values;
149 
151  std::map<MaterialPropertyName, std::vector<OutputName>> _export_output_targets;
152 
153 private:
154 #ifdef NEML2_ENABLED
155  template <typename EnumType, typename T1, typename T2>
157  std::tuple<std::vector<EnumType>, std::vector<T1>, std::vector<T2>>
158  getInputParameterMapping(const std::string & moose_type_opt,
159  const std::string & moose_name_opt,
160  const std::string & neml2_name_opt) const
161  {
162  const auto moose_types = getParam<MultiMooseEnum>(moose_type_opt).getSetValueIDs<EnumType>();
163  const auto moose_names = getParam<std::vector<T1>>(moose_name_opt);
164  const auto neml2_names = getParam<std::vector<T2>>(neml2_name_opt);
165 
166  if (moose_types.size() != moose_names.size())
167  paramError(moose_name_opt, moose_name_opt, " must have the same length as ", moose_type_opt);
168  if (moose_names.size() != neml2_names.size())
169  paramError(moose_name_opt, moose_name_opt, " must have the same length as ", neml2_name_opt);
170 
171  return {moose_types, moose_names, neml2_names};
172  }
173 
175  void printSummary() const;
176 #endif
177 
179  std::size_t getLongestMOOSEName() const;
180 };
std::vector< std::string > _cli_args
List of cli-args.
Definition: NEML2Action.h:117
const FileName & fname() const
Definition: NEML2Action.h:39
std::vector< DerivativeMapping > _derivs
MOOSE-NEML2 derivative mappings.
Definition: NEML2Action.h:132
std::map< MaterialPropertyName, std::vector< OutputName > > _export_output_targets
Material property additional outputs.
Definition: NEML2Action.h:151
Action to set up NEML2 objects.
Definition: NEML2Action.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const neml2::VariableName name
Definition: NEML2Action.h:56
Input parameters common to all block-restricted NEML2Actions.
const neml2::TensorType type
Definition: NEML2Action.h:63
const struct NEML2Action::DerivativeMapping::NEML2Derivative neml2
void setupParameterDerivativeMappings(const neml2::Model &)
Set up MOOSE-NEML2 parameter derivative mappings.
Definition: NEML2Action.C:454
Base class for actions.
Definition: Action.h:33
std::tuple< std::vector< EnumType >, std::vector< T1 >, std::vector< T2 > > getInputParameterMapping(const std::string &moose_type_opt, const std::string &moose_name_opt, const std::string &neml2_name_opt) const
Get parameter lists for mapping between MOOSE and NEML2 quantities.
Definition: NEML2Action.h:158
const std::vector< SubdomainName > _block
Blocks this sub-block action applies to.
Definition: NEML2Action.h:145
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Definition: NEML2Action.C:128
const UserObjectName _executor_name
Name of the NEML2Executor user object.
Definition: NEML2Action.h:139
std::shared_ptr< neml2::Model > _model
The neml2 model.
Definition: NEML2Action.h:120
void printSummary() const
Print a summary of the NEML2 model.
Definition: NEML2Action.C:479
const std::string name
Definition: NEML2Action.h:62
std::map< MaterialPropertyName, MaterialPropertyName > _initialize_output_values
Material property initial conditions.
Definition: NEML2Action.h:148
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 ...
std::vector< ParameterDerivativeMapping > _param_derivs
MOOSE-NEML2 parameter derivative mappings.
Definition: NEML2Action.h:135
void setupParameterMappings(const neml2::Model &)
Set up MOOSE-NEML2 model parameter mappings.
Definition: NEML2Action.C:403
FileName _fname
Name of the NEML2 input file.
Definition: NEML2Action.h:114
const NEML2ActionCommon & getCommonAction() const
Definition: NEML2Action.C:118
NEML2Action(const InputParameters &)
Definition: NEML2Action.C:70
const neml2::TensorType type
Definition: NEML2Action.h:57
const struct NEML2Action::ParameterDerivativeMapping::NEML2Derivative neml2
void setupInputMappings(const neml2::Model &)
Set up MOOSE-NEML2 input variable mappings.
Definition: NEML2Action.C:386
void setupDerivativeMappings(const neml2::Model &)
Set up MOOSE-NEML2 derivative mappings.
Definition: NEML2Action.C:432
static InputParameters validParams()
Definition: NEML2Action.C:48
const std::string name
Definition: NEML2Action.h:50
void setupOutputMappings(const neml2::Model &)
Set up MOOSE-NEML2 output variable mappings.
Definition: NEML2Action.C:415
const UserObjectName _idx_generator_name
Name of the NEML2BatchIndexGenerator user object.
Definition: NEML2Action.h:142
std::size_t getLongestMOOSEName() const
Get the maximum length of all MOOSE names (for printing purposes)
Definition: NEML2Action.C:555
std::vector< VariableMapping > _outputs
MOOSE-NEML2 output variable mappings.
Definition: NEML2Action.h:129
const MOOSEIOType type
Definition: NEML2Action.h:51
std::vector< ParameterMapping > _params
MOOSE-NEML2 model parameter mappings.
Definition: NEML2Action.h:126
std::vector< VariableMapping > _inputs
MOOSE-NEML2 input variable mappings.
Definition: NEML2Action.h:123