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 #include "NEML2Utils.h"
21 
22 class NEML2ActionCommon;
23 
28 {
29 public:
31 
33 
34  virtual void act() override;
35 
36 protected:
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  neml2::TensorType neml2_type;
48  std::size_t history_order;
49  };
50 
52  {
53  std::string name;
55  neml2::TensorType neml2_type;
56  };
57 
59  {
60  std::string name;
61  std::string y;
62  std::string x;
63  };
64 
66  void setupInputMappings(const neml2::Model &);
67 
69  void setupOutputMappings(const neml2::Model &);
70 
72  void setupParameterMappings(const neml2::Model &);
73 
75  void setupDerivativeMappings(const neml2::Model &);
76 
78  void setupParameterDerivativeMappings(const neml2::Model &);
79 
81  NEML2Utils::MOOSEIOType inferMOOSEIOType(const neml2::VariableName & name,
82  const neml2::TensorType & type) const;
83 
85  FileName _fname;
86 
88  std::vector<std::string> _cli_args;
89 
91  std::shared_ptr<neml2::Model> _model;
92 
94  std::vector<VariableMapping> _inputs;
95 
97  std::vector<ParameterMapping> _params;
98 
100  std::vector<VariableMapping> _outputs;
101 
103  std::vector<DerivativeMapping> _derivs;
104 
106  std::vector<DerivativeMapping> _param_derivs;
107 
108 #endif
109  const UserObjectName _executor_name;
111 
113  const UserObjectName _idx_generator_name;
114 
116  const std::vector<SubdomainName> _block;
117 
119  std::vector<std::string> _skip_input_variables;
120 
122  std::map<MaterialPropertyName, MaterialPropertyName> _initialize_output_values;
123 
125  std::map<MaterialPropertyName, std::vector<OutputName>> _export_output_targets;
126 
127 private:
128 #ifdef NEML2_ENABLED
129  template <typename EnumType, typename T>
131  std::tuple<std::vector<EnumType>, std::vector<T>>
132  getInputParameterMapping(const std::string & source_opt, const std::string & name_opt) const
133  {
134  const auto moose_types = getParam<MultiMooseEnum>(source_opt).getSetValueIDs<EnumType>();
135  const auto neml2_names = getParam<std::vector<T>>(name_opt);
136 
137  if (moose_types.size() != neml2_names.size())
138  paramError(source_opt, source_opt, " must have the same length as ", name_opt);
139 
140  return {moose_types, neml2_names};
141  }
142 
144  void printSummary() const;
145 #endif
146 
148  std::size_t getLongestMOOSEName() const;
149 };
std::vector< DerivativeMapping > _param_derivs
MOOSE-NEML2 parameter derivative mappings.
Definition: NEML2Action.h:106
std::vector< std::string > _cli_args
List of cli-args.
Definition: NEML2Action.h:88
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:467
const FileName & fname() const
Definition: NEML2Action.h:41
std::vector< DerivativeMapping > _derivs
MOOSE-NEML2 derivative mappings.
Definition: NEML2Action.h:103
std::map< MaterialPropertyName, std::vector< OutputName > > _export_output_targets
Material property additional outputs.
Definition: NEML2Action.h:125
Action to set up NEML2 objects.
Definition: NEML2Action.h:27
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Input parameters common to all block-restricted NEML2Actions.
void setupParameterDerivativeMappings(const neml2::Model &)
Set up MOOSE-NEML2 parameter derivative mappings.
Definition: NEML2Action.C:496
Base class for actions.
Definition: Action.h:34
NEML2Utils::MOOSEIOType moose_type
Definition: NEML2Action.h:54
neml2::TensorType neml2_type
Definition: NEML2Action.h:47
const std::vector< SubdomainName > _block
Blocks this sub-block action applies to.
Definition: NEML2Action.h:116
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Definition: NEML2Action.C:127
const UserObjectName _executor_name
Name of the NEML2Executor user object.
Definition: NEML2Action.h:110
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:103
std::shared_ptr< neml2::Model > _model
The neml2 model.
Definition: NEML2Action.h:91
void printSummary() const
Print a summary of the NEML2 model.
Definition: NEML2Action.C:519
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:93
std::map< MaterialPropertyName, MaterialPropertyName > _initialize_output_values
Material property initial conditions.
Definition: NEML2Action.h:122
void setupParameterMappings(const neml2::Model &)
Set up MOOSE-NEML2 model parameter mappings.
Definition: NEML2Action.C:459
FileName _fname
Name of the NEML2 input file.
Definition: NEML2Action.h:85
const NEML2ActionCommon & getCommonAction() const
Definition: NEML2Action.C:117
NEML2Action(const InputParameters &)
Definition: NEML2Action.C:68
NEML2Utils::MOOSEIOType inferMOOSEIOType(const neml2::VariableName &name, const neml2::TensorType &type) const
Infer the MOOSE IO type from the variable name and type.
Definition: NEML2Action.C:318
NEML2Utils::MOOSEIOType moose_type
Definition: NEML2Action.h:46
void setupInputMappings(const neml2::Model &)
Set up MOOSE-NEML2 input variable mappings.
Definition: NEML2Action.C:357
neml2::TensorType neml2_type
Definition: NEML2Action.h:55
void setupDerivativeMappings(const neml2::Model &)
Set up MOOSE-NEML2 derivative mappings.
Definition: NEML2Action.C:475
static InputParameters validParams()
Definition: NEML2Action.C:50
std::vector< std::string > _skip_input_variables
Input variables to skip (i.e., not to set up mappings for)
Definition: NEML2Action.h:119
void setupOutputMappings(const neml2::Model &)
Set up MOOSE-NEML2 output variable mappings.
Definition: NEML2Action.C:445
const UserObjectName _idx_generator_name
Name of the NEML2BatchIndexGenerator user object.
Definition: NEML2Action.h:113
std::size_t getLongestMOOSEName() const
Get the maximum length of all MOOSE names (for printing purposes)
Definition: NEML2Action.C:587
std::vector< VariableMapping > _outputs
MOOSE-NEML2 output variable mappings.
Definition: NEML2Action.h:100
std::vector< ParameterMapping > _params
MOOSE-NEML2 model parameter mappings.
Definition: NEML2Action.h:97
std::vector< VariableMapping > _inputs
MOOSE-NEML2 input variable mappings.
Definition: NEML2Action.h:94
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.
Definition: NEML2Action.h:132