https://mooseframework.inl.gov
NEML2Action.C
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 #include "NEML2Action.h"
11 #include "NEML2ActionCommon.h"
12 #include "FEProblem.h"
13 #include "Factory.h"
14 #include "NEML2Utils.h"
16 
17 #ifdef NEML2_ENABLED
18 #include "neml2/neml2.h"
19 #include "neml2/base/Settings.h"
20 #include "neml2/models/VariableBase.h"
21 #endif
22 
23 registerMooseAction("MooseApp", NEML2Action, "parse_neml2");
24 registerMooseAction("MooseApp", NEML2Action, "add_material");
25 registerMooseAction("MooseApp", NEML2Action, "add_user_object");
26 
27 #ifdef NEML2_ENABLED
28 // NEML2 variable type --> MOOSE type
29 const std::map<neml2::TensorType, std::string> tensor_type_map = {
30  {neml2::TensorType::kScalar, "Real"},
31  {neml2::TensorType::kSR2, "SymmetricRankTwoTensor"},
32  {neml2::TensorType::kR2, "RankTwoTensor"},
33  {neml2::TensorType::kSSR4, "SymmetricRankFourTensor"},
34  {neml2::TensorType::kR4, "RankFourTensor"},
35  {neml2::TensorType::kRot, "RealVectorValue"}};
36 // NEML2 (output, input) type --> NEML2 derivative type
37 const std::map<std::pair<neml2::TensorType, neml2::TensorType>, neml2::TensorType> deriv_type_map =
38  {
39  {{neml2::TensorType::kScalar, neml2::TensorType::kScalar}, neml2::TensorType::kScalar},
40  {{neml2::TensorType::kSR2, neml2::TensorType::kSR2}, neml2::TensorType::kSSR4},
41  {{neml2::TensorType::kSR2, neml2::TensorType::kScalar}, neml2::TensorType::kSR2},
42  {{neml2::TensorType::kScalar, neml2::TensorType::kSR2}, neml2::TensorType::kSR2},
43  {{neml2::TensorType::kR2, neml2::TensorType::kR2}, neml2::TensorType::kR4},
44  {{neml2::TensorType::kR2, neml2::TensorType::kScalar}, neml2::TensorType::kR2},
45  {{neml2::TensorType::kScalar, neml2::TensorType::kR2}, neml2::TensorType::kR2},
46 };
47 #endif
48 
51 {
53  params.addClassDescription("Set up the NEML2 material model");
54  params.addParam<std::string>("executor_name",
55  "Name of the NEML2ModelExecutor user object. The default name is "
56  "'neml2_<model-name>_<block-name>' where <model-name> is the NEML2 "
57  "model's name, and <block-name> is this action sub-block's name.");
58  params.addParam<std::string>(
59  "batch_index_generator_name",
60  "Name of the NEML2BatchIndexGenerator user object. The default name is "
61  "'neml2_index_<model-name>_<block-name>' where <model-name> is the NEML2 model's name, and "
62  "<block-name> is this action sub-block's name.");
63  params.addParam<std::vector<SubdomainName>>(
64  "block", {}, "List of blocks (subdomains) where the material model is defined");
65  return params;
66 }
67 
69  : Action(params),
70  _executor_name(isParamValid("executor_name")
71  ? getParam<std::string>("executor_name")
72  : "neml2_" + getParam<std::string>("model") + "_" + name()),
73  _idx_generator_name(isParamValid("batch_index_generator_name")
74  ? getParam<std::string>("batch_index_generator_name")
75  : "neml2_index_" + getParam<std::string>("model") + "_" + name()),
76  _block(getParam<std::vector<SubdomainName>>("block")),
77  _skip_input_variables(getParam<std::vector<std::string>>("skip_input_variables"))
78 {
80 
81  // Apply parameters under the common area, i.e., under [NEML2]
82  const auto & all_params = _app.getInputParameterWarehouse().getInputParameters();
83  auto & sub_block_params = *(all_params.find(uniqueActionName())->second.get());
84  const auto & common_action = getCommonAction();
85  sub_block_params.applyParameters(common_action.parameters());
86 
87  // Set up optional output variable initialization
88  auto init_vars = getParam<std::vector<MaterialPropertyName>>("initialize_outputs");
89  auto init_vals = getParam<std::vector<MaterialPropertyName>>("initialize_output_values");
90  if (init_vars.size() != init_vals.size())
91  paramError("initialize_outputs",
92  "initialize_outputs should have the same length as initialize_output_values");
93  for (auto i : index_range(init_vars))
94  _initialize_output_values[init_vars[i]] = init_vals[i];
95 
96  // Set up additional outputs for each requested material property
97  auto outputs = getParam<std::vector<MaterialPropertyName>>("export_outputs");
98  auto output_targets = getParam<std::vector<std::vector<OutputName>>>("export_output_targets");
99  if (outputs.size() != output_targets.size())
100  paramError("export_outputs",
101  "export_outputs should have the same length as export_output_targets");
102  for (auto i : index_range(outputs))
103  _export_output_targets[outputs[i]] = output_targets[i];
104 
105 #ifdef NEML2_ENABLED
106  // File name and CLI args
107  _fname = getParam<DataFileName>("input");
108  _cli_args = getParam<std::vector<std::string>>("cli_args");
109 
110  // Load input file
111  auto factory = neml2::load_input(std::string(_fname), neml2::utils::join(_cli_args, " "));
112  _model = NEML2Utils::getModel(*factory, getParam<std::string>("model"));
113 #endif
114 }
115 
116 const NEML2ActionCommon &
118 {
119  auto common_block = _awh.getActions<NEML2ActionCommon>();
120  mooseAssert(common_block.size() == 1, "There must exist one and only one common NEML2 action.");
121  return *common_block[0];
122 }
123 
124 #ifndef NEML2_ENABLED
125 
126 void
128 {
129 }
130 
131 #else
132 
133 static std::string
134 obscureObjectName(const std::string & name,
135  const std::string & prefix,
136  const std::string & suffix,
137  const std::string & block)
138 {
139  return "__" + prefix + "_" + name + "_" + suffix + "_" + block + "__";
140 }
141 
142 void
144 {
145  if (_current_task == "parse_neml2")
146  {
147  if (_app.parameters().have_parameter<bool>("parse_neml2_only"))
148  if (!_app.parameters().get<bool>("parse_neml2_only"))
149  return;
150  printSummary();
151  }
152 
153  // Look up the MOOSE tensor type string for a NEML2 tensor type, or error
154  auto mooseType = [this](neml2::TensorType type) -> const std::string &
155  {
156  auto it = tensor_type_map.find(type);
157  if (it == tensor_type_map.end())
158  mooseError("NEML2 type ", type, " not yet mapped to MOOSE");
159  return it->second;
160  };
161 
162  if (_current_task == "add_user_object")
163  {
169 
170  printSummary();
171 
172  // Create and register a MOOSEToNEML2 gatherer user object, returning its name
173  auto addGatherer = [&](const std::string & moose_name,
174  const std::string & neml2_name,
175  NEML2Utils::MOOSEIOType moose_type,
176  neml2::TensorType neml2_type,
177  const std::string & suffix,
178  const std::string & type_prefix = "")
179  {
180  auto obj_name = obscureObjectName(moose_name, "moose_to_neml2", suffix, name());
181  auto obj_type = "MOOSE" + type_prefix + mooseType(neml2_type) + "ToNEML2";
182  auto obj_params = _factory.getValidParams(obj_type);
183  obj_params.set<std::string>("from_moose") = moose_name;
184  obj_params.set<std::string>("to_neml2") = neml2_name;
185  obj_params.set<MooseEnum>("quantity_type").assign(static_cast<int>(moose_type));
186  obj_params.set<std::vector<SubdomainName>>("block") = _block;
187  _problem->addUserObject(obj_type, obj_name, obj_params);
188  return obj_name;
189  };
190 
191  // MOOSEToNEML2 input gatherers
192  std::vector<UserObjectName> gatherers;
193  const auto sep = _model->settings().history_separator();
194  for (const auto & input : _inputs)
195  gatherers.push_back(addGatherer(input.name,
196  neml2::history_name(input.name, input.history_order, sep),
197  input.moose_type,
198  input.neml2_type,
199  std::to_string(input.history_order),
200  input.history_order == 1 ? "Old" : ""));
201 
202  // Additional NEML2Kernels that provide input data
203  for (const auto & kernel_name : getParam<std::vector<std::string>>("input_kernels"))
204  {
205  if (!_model->input_variables().count(kernel_name))
206  paramError("input_kernels",
207  "The NEML2 kernel ",
208  kernel_name,
209  " name does not match any NEML2 input variable.");
210  gatherers.push_back(kernel_name);
211  }
212 
213  // MOOSEToNEML2 parameter gatherers
214  std::vector<UserObjectName> param_gatherers;
215  for (const auto & param : _params)
216  param_gatherers.push_back(
217  addGatherer(param.name, param.name, param.moose_type, param.neml2_type, ""));
218 
219  // The index generator UO
220  {
221  auto type = "NEML2BatchIndexGenerator";
222  auto params = _factory.getValidParams(type);
223  params.applyParameters(parameters());
224  _problem->addUserObject(type, _idx_generator_name, params);
225  }
226 
227  // The Executor UO
228  {
229  auto type = "NEML2ModelExecutor";
230  auto params = _factory.getValidParams(type);
231  params.applyParameters(parameters());
232  params.set<UserObjectName>("batch_index_generator") = _idx_generator_name;
233  params.set<std::vector<UserObjectName>>("gatherers") = gatherers;
234  params.set<std::vector<UserObjectName>>("param_gatherers") = param_gatherers;
235  _problem->addUserObject(type, _executor_name, params);
236  }
237  }
238 
239  if (_current_task == "add_material")
240  {
241  // Look up the NEML2 derivative tensor type for (y, x) variables, or error
242  auto derivTensorType =
243  [this](neml2::TensorType y_type, neml2::TensorType x_type, const std::string & deriv_name)
244  {
245  auto it = deriv_type_map.find({y_type, x_type});
246  if (it == deriv_type_map.end())
247  mooseError("NEML2 derivative type for ", deriv_name, " not yet mapped to MOOSE");
248  return it->second;
249  };
250 
251  // Create and register a NEML2ToMOOSE material property retriever; `extra` lets
252  // each caller add the bits that are unique to outputs vs. (parameter) derivatives
253  auto addRetriever = [&](const std::string & moose_name,
254  const std::string & neml2_var,
255  neml2::TensorType tensor_type,
256  auto && extra)
257  {
258  auto obj_name = obscureObjectName(moose_name, "neml2_to_moose", "", name());
259  auto obj_type = "NEML2ToMOOSE" + mooseType(tensor_type) + "MaterialProperty";
260  auto obj_params = _factory.getValidParams(obj_type);
261  obj_params.set<UserObjectName>("neml2_executor") = _executor_name;
262  obj_params.set<MaterialPropertyName>("to_moose") = moose_name;
263  obj_params.set<std::string>("from_neml2") = neml2_var;
264  obj_params.set<std::vector<SubdomainName>>("block") = _block;
265  if (_export_output_targets.count(moose_name))
266  obj_params.set<std::vector<OutputName>>("outputs") = _export_output_targets[moose_name];
267  extra(obj_params);
268  _problem->addMaterial(obj_type, obj_name, obj_params);
269  };
270 
271  // NEML2ToMOOSE output retrievers
272  for (const auto & output : _outputs)
273  {
274  if (output.moose_type != NEML2Utils::MOOSEIOType::MATERIAL)
275  paramError("moose_output_types",
276  "Unsupported type corresponding to the moose output ",
277  output.name);
278  addRetriever(output.name,
279  output.name,
280  output.neml2_type,
281  [&](InputParameters & p)
282  {
283  if (_initialize_output_values.count(output.name))
284  p.set<MaterialPropertyName>("moose_material_property_init") =
285  _initialize_output_values[output.name];
286  });
287  }
288 
289  // NEML2ToMOOSE derivative retrievers
290  for (const auto & deriv : _derivs)
291  {
292  auto type = derivTensorType(_model->output_variable(deriv.y).type(),
293  _model->input_variable(deriv.x).type(),
294  deriv.name);
295  addRetriever(deriv.name,
296  deriv.y,
297  type,
298  [&](InputParameters & p)
299  { p.set<std::string>("neml2_input_derivative") = deriv.x; });
300  }
301 
302  // NEML2ToMOOSE parameter derivative retrievers
303  for (const auto & param_deriv : _param_derivs)
304  {
305  auto type = derivTensorType(_model->output_variable(param_deriv.y).type(),
306  _model->get_parameter(param_deriv.x).type(),
307  param_deriv.name);
308  addRetriever(param_deriv.name,
309  param_deriv.y,
310  type,
311  [&](InputParameters & p)
312  { p.set<std::string>("neml2_parameter_derivative") = param_deriv.x; });
313  }
314  }
315 }
316 
318 NEML2Action::inferMOOSEIOType(const neml2::VariableName & name,
319  const neml2::TensorType & type) const
320 {
321  // neml2::kScalar can only come from scalar variable, function, or variable
322  if (type == neml2::TensorType::kScalar)
323  {
324  bool is_time = _problem->isTransient() && (name == "t" || name == "time");
325  bool has_scalar = _problem->hasScalarVariable(name);
326  bool has_func = _problem->hasFunction(name);
327  bool has_var = _problem->hasVariable(name);
328  if (int(is_time) + int(has_scalar) + int(has_func) + int(has_var) > 1)
329  mooseError("Trying to infer MOOSE data type for NEML2 variable ",
330  name,
331  ". The name matches multiple types (",
332  (is_time ? "time " : ""),
333  (has_scalar ? "scalar variable " : ""),
334  (has_func ? "function " : ""),
335  (has_var ? "variable " : ""),
336  "). To avoid ambiguity, please explicitly specify the type in the NEML2 action.");
337  if (is_time)
339  if (has_scalar)
341  if (has_func)
343  if (has_var)
345  // if neither function nor variable exists, let's assume it's a material property
346  // note that we can't explicitly check if a material property with the given name exists,
347  // because materials are added _after_ user objects (see Moose.C)
348  if (!has_func && !has_var)
350  }
351 
352  // non-scalar can only come from material properties
354 }
355 
356 void
357 NEML2Action::setupInputMappings(const neml2::Model & model)
358 {
359  const auto & kernels = getParam<std::vector<std::string>>("input_kernels");
360 
361  // Default mapping
362  for (const auto & [vname, var] : model.input_variables())
363  {
364  // user requested to skip
365  if (std::find(_skip_input_variables.begin(), _skip_input_variables.end(), var->base_name()) !=
366  _skip_input_variables.end())
367  continue;
368 
369  // skip if the input is directly provided by a custom MOOSEToNEML2 object
370  bool gathered_by_kernel = false;
371  for (const auto & kernel_name : kernels)
372  if (vname == kernel_name)
373  {
374  gathered_by_kernel = true;
375  break;
376  }
377  if (gathered_by_kernel)
378  continue;
379 
380  // skip if manage_state_advance is true and the variable is stateful (history_order > 0),
381  // because in that case we will gather the variable on the compute device and do not need to set
382  // up a gatherer for it
383  if (getParam<bool>("manage_state_advance") && var->history_order() > 0)
384  continue;
385 
386  _inputs.push_back({var->base_name(),
387  inferMOOSEIOType(var->base_name(), var->type()),
388  var->type(),
389  var->history_order()});
390  }
391 
392  // User-specified mapping (overrides default mapping)
393  const auto [input_types, inputs] =
394  getInputParameterMapping<NEML2Utils::MOOSEIOType, std::string>("input_types", "inputs");
395 
396  for (auto i : index_range(inputs))
397  {
398  // Check if the input variable also appears in skip_input_variables
399  const auto itr =
400  std::find(_skip_input_variables.begin(), _skip_input_variables.end(), inputs[i]);
401  if (itr != _skip_input_variables.end())
402  paramError("skip_input_variables",
403  "The input variable ",
404  inputs[i],
405  " is listed in skip_input_variables, but it also appears in inputs. Please "
406  "remove it from either list.");
407  // Check if the input variable exists in the NEML2 model
408  if (model.input_variables().count(inputs[i]) == 0)
409  paramError("inputs", "The neml2 input variable ", inputs[i], " does not exist.");
410  // Check if the input variable is already gathered by a custom MOOSEToNEML2 object
411  bool gathered_by_kernel = false;
412  for (const auto & kernel_name : kernels)
413  if (inputs[i] == kernel_name)
414  {
415  gathered_by_kernel = true;
416  break;
417  }
418  if (gathered_by_kernel)
419  paramError("inputs",
420  "The input variable ",
421  inputs[i],
422  " is listed in inputs, but it also appears in input_kernels. Please "
423  "remove it from either list.");
424  // Check if the input variable is stateful and manage_state_advance is true
425  if (getParam<bool>("manage_state_advance"))
426  if (model.input_variable(inputs[i]).history_order() > 0)
427  paramError(
428  "inputs",
429  "The input variable ",
430  inputs[i],
431  " is listed in inputs, but it is stateful (history_order > 0) and manage_state_advance "
432  "is true. Please remove it from inputs, or set manage_state_advance to false.");
433 
434  // Get the existing mapping for this neml2 input variable and override it
435  for (auto & input : _inputs)
436  if (input.name == inputs[i])
437  {
438  input.moose_type = input_types[i];
439  break;
440  }
441  }
442 }
443 
444 void
445 NEML2Action::setupOutputMappings(const neml2::Model & model)
446 {
447  if (!getParam<bool>("auto_output"))
448  return;
449 
450  // Outputs
451  for (const auto & [name, var] : model.output_variables())
452  _outputs.push_back({name,
453  NEML2Utils::MOOSEIOType::MATERIAL,
454  var->type(),
455  /*history_order=*/0});
456 }
457 
458 void
459 NEML2Action::setupParameterMappings(const neml2::Model & model)
460 {
461  // User-specified mapping
462  const auto [param_types, params] = getInputParameterMapping<NEML2Utils::MOOSEIOType, std::string>(
463  "parameter_types", "parameters");
464 
465  for (auto i : index_range(params))
466  {
467  if (model.named_parameters().count(params[i]) == 0)
468  paramError("parameters", "The neml2 parameter ", params[i], " does not exist.");
469  const auto & param = model.get_parameter(params[i]);
470  _params.push_back({params[i], inferMOOSEIOType(params[i], param.type()), param.type()});
471  }
472 }
473 
474 void
475 NEML2Action::setupDerivativeMappings(const neml2::Model & model)
476 {
477  const auto derivs = getParam<std::vector<std::vector<std::string>>>("derivatives");
478 
479  for (auto i : index_range(derivs))
480  {
481  if (derivs[i].size() != 2)
482  paramError("derivatives", "The length of each pair in derivatives must be 2.");
483  if (model.output_variables().count(derivs[i][0]) == 0)
484  paramError("derivatives", "The NEML2 output variable ", derivs[i][0], " does not exist.");
485  if (model.input_variables().count(derivs[i][1]) == 0)
486  paramError("derivatives", "The NEML2 input variable ", derivs[i][1], " does not exist.");
487 
488  const auto & y = derivs[i][0];
489  const auto & x = derivs[i][1];
490  const auto deriv_name = derivativePropertyNameFirst(y, x);
491  _derivs.push_back({deriv_name, y, x});
492  }
493 }
494 
495 void
497 {
498  const auto derivs = getParam<std::vector<std::vector<std::string>>>("parameter_derivatives");
499 
500  for (auto i : index_range(derivs))
501  {
502  if (derivs[i].size() != 2)
503  paramError("parameter_derivatives",
504  "The length of each pair in parameter_derivatives must be 2.");
505  if (model.output_variables().count(derivs[i][0]) == 0)
506  paramError(
507  "parameter_derivatives", "The NEML2 output variable ", derivs[i][0], " does not exist.");
508  if (model.named_parameters().count(derivs[i][1]) == 0)
509  paramError("parameter_derivatives", "The NEML2 parameter ", derivs[i][1], " does not exist.");
510 
511  const auto & y = derivs[i][0];
512  const auto & x = derivs[i][1];
513  const auto deriv_name = derivativePropertyNameFirst(y, x);
514  _param_derivs.push_back({deriv_name, y, x});
515  }
516 }
517 
518 void
520 {
521  if (!_app.parameters().have_parameter<bool>("parse_neml2_only"))
522  return;
523 
524  // Save formatting of the output stream so that we can restore it later
525  const auto flags = _console.flags();
526 
527  // Default width for the summary
528  const int width = 79;
529 
530  _console << std::endl;
531  _console << COLOR_CYAN << std::setw(width) << std::setfill('*') << std::left
532  << "NEML2 MATERIAL MODEL SUMMARY BEGIN " << std::setfill(' ') << COLOR_DEFAULT
533  << std::endl;
534 
535  // Metadata
536  _console << "NEML2 input file location: " << fname() << std::endl;
537  _console << "NEML2 action path: " << parameters().blockFullpath() << std::endl;
538 
539  // List inputs, outputs, and parameters of the model
540  _console << COLOR_CYAN << std::setw(width) << std::setfill('-') << std::left
541  << "Material model structure " << std::setfill(' ') << COLOR_DEFAULT << std::endl;
542  _console << *_model;
543 
544  // List transfer between MOOSE and NEML2
545  if (!_app.parameters().get<bool>("parse_neml2_only"))
546  {
547  _console << COLOR_CYAN << std::setw(width) << std::setfill('-') << std::left
548  << "Transfer between MOOSE and NEML2 " << std::setfill(' ') << COLOR_DEFAULT
549  << std::endl;
550 
551  _console << "MOOSE --> NEML2" << std::endl;
552 
553  // List input transfer, MOOSE -> NEML2
554  for (const auto & input : _inputs)
555  _console << " - " << (input.history_order > 0 ? ("(old) " + input.name) : input.name) << " ("
556  << NEML2Utils::stringify(input.moose_type) << ")" << std::endl;
557 
558  // List parameter transfer, MOOSE -> NEML2
559  for (const auto & param : _params)
560  _console << " - " << param.name << " (" << NEML2Utils::stringify(param.moose_type) << " --> "
561  << param.neml2_type << ")" << std::endl;
562 
563  _console << "MOOSE <-- NEML2" << std::endl;
564 
565  // List output transfer, NEML2 -> MOOSE
566  for (const auto & output : _outputs)
567  _console << " - " << output.name << std::endl;
568 
569  // List derivative transfer, NEML2 -> MOOSE
570  for (const auto & deriv : _derivs)
571  _console << " - " << deriv.name << std::endl;
572 
573  // List parameter derivative transfer, NEML2 -> MOOSE
574  for (const auto & param_deriv : _param_derivs)
575  _console << " - " << param_deriv.name << std::endl;
576  }
577 
578  _console << COLOR_CYAN << std::setw(width) << std::setfill('*') << std::left
579  << "NEML2 MATERIAL MODEL SUMMARY END " << std::setfill(' ') << COLOR_DEFAULT << std::endl
580  << std::endl;
581 
582  // Restore the formatting of the output stream
583  _console.flags(flags);
584 }
585 
586 std::size_t
588 {
589  std::size_t max_moose_name_length = 0;
590  for (const auto & input : _inputs)
591  {
592  auto n = input.name.size();
593  if (input.history_order > 0)
594  n += 6; // 6 is the length of "(old) "
595  max_moose_name_length = std::max(max_moose_name_length, n);
596  }
597  for (const auto & param : _params)
598  max_moose_name_length = std::max(max_moose_name_length, param.name.size());
599  for (const auto & output : _outputs)
600  max_moose_name_length = std::max(max_moose_name_length, output.name.size());
601  for (const auto & deriv : _derivs)
602  max_moose_name_length = std::max(max_moose_name_length, deriv.name.size());
603  for (const auto & param_deriv : _param_derivs)
604  max_moose_name_length = std::max(max_moose_name_length, param_deriv.name.size());
605  return max_moose_name_length;
606 }
607 #endif // NEML2_ENABLED
std::string name(const ElemQuality q)
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
std::vector< DerivativeMapping > _param_derivs
MOOSE-NEML2 parameter derivative mappings.
Definition: NEML2Action.h:106
ActionWarehouse & _awh
Reference to ActionWarehouse where we store object build by actions.
Definition: Action.h:169
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 T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:416
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
Factory & _factory
The Factory associated with the MooseApp.
const FileName & fname() const
Definition: NEML2Action.h:41
InputParameterWarehouse & getInputParameterWarehouse()
Get the InputParameterWarehouse for MooseObjects.
Definition: MooseApp.C:2594
std::ios_base::fmtflags flags() const
Return the current flags.
Definition: ConsoleStream.C:56
std::vector< DerivativeMapping > _derivs
MOOSE-NEML2 derivative mappings.
Definition: NEML2Action.h:103
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
std::map< MaterialPropertyName, std::vector< OutputName > > _export_output_targets
Material property additional outputs.
Definition: NEML2Action.h:125
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:68
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...
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
Method for applying common parameters.
const MaterialPropertyName derivativePropertyNameFirst(const MaterialPropertyName &base, const SymbolName &c1) const
Helper functions to generate the material property names for the first derivatives.
Input parameters common to all block-restricted NEML2Actions.
const std::map< neml2::TensorType, std::string > tensor_type_map
Definition: NEML2Action.C:29
MooseObjectName uniqueActionName() const
The unique name for accessing input parameters of this action in the InputParameterWarehouse.
Definition: Action.h:108
void setupParameterDerivativeMappings(const neml2::Model &)
Set up MOOSE-NEML2 parameter derivative mappings.
Definition: NEML2Action.C:496
Base class for actions.
Definition: Action.h:34
std::string stringify(MOOSEIOType type)
Definition: NEML2Utils.C:18
auto max(const L &left, const R &right)
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
Real deriv(unsigned n, unsigned alpha, unsigned beta, Real x)
const std::multimap< MooseObjectName, std::shared_ptr< InputParameters > > & getInputParameters(THREAD_ID tid=0) const
Return const reference to the map containing the InputParameter objects.
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
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
const std::string & _current_task
The current action (even though we have separate instances for each action)
Definition: Action.h:172
std::map< MaterialPropertyName, MaterialPropertyName > _initialize_output_values
Material property initial conditions.
Definition: NEML2Action.h:122
const std::map< std::pair< neml2::TensorType, neml2::TensorType >, neml2::TensorType > deriv_type_map
Definition: NEML2Action.C:37
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:385
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
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
void assertNEML2Enabled()
Assert that NEML2 is enabled.
Definition: NEML2Utils.C:81
std::shared_ptr< neml2::Model > getModel(neml2::Factory &factory, const std::string &name, neml2::Dtype dtype=neml2::kFloat64)
Get the NEML2 Model.
Definition: NEML2Utils.C:38
void setupInputMappings(const neml2::Model &)
Set up MOOSE-NEML2 input variable mappings.
Definition: NEML2Action.C:357
std::string blockFullpath() const
void setupDerivativeMappings(const neml2::Model &)
Set up MOOSE-NEML2 derivative mappings.
Definition: NEML2Action.C:475
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
static InputParameters validParams()
Definition: NEML2Action.C:50
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:178
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
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
registerMooseAction("MooseApp", NEML2Action, "parse_neml2")
std::vector< const T * > getActions()
Retrieve all actions in a specific type ordered by their names.
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
auto index_range(const T &sizable)
std::vector< VariableMapping > _inputs
MOOSE-NEML2 input variable mappings.
Definition: NEML2Action.h:94
static InputParameters commonParams()
Parameters that can be specified EITHER under the common area OR under sub-blocks.
static std::string obscureObjectName(const std::string &name, const std::string &prefix, const std::string &suffix, const std::string &block)
Definition: NEML2Action.C:134