https://mooseframework.inl.gov
MOOSEToNEML2.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 "MOOSEToNEML2.h"
11 
14 {
15  auto params = emptyInputParameters();
16  params.addRequiredParam<std::string>(
17  "to_neml2", NEML2Utils::docstring("Name of the NEML2 variable or parameter to write to"));
18  return params;
19 }
20 
21 #ifndef NEML2_ENABLED
22 
24 
25 #else
26 
28  : _mode(Mode::UNDEFINED), _raw_name(params.get<std::string>("to_neml2"))
29 {
31 }
32 
33 void
35 {
36  _mode = m;
37 
40  else if (_mode == Mode::PARAMETER)
42  else
43  mooseError("Encountered invalid Mode in MOOSEToNEML2::setMode");
44 
45  checkMode();
46 }
47 
48 void
50 {
51  if (_mode == Mode::VARIABLE)
55 }
56 
57 const neml2::VariableName &
59 {
60  mooseAssert(_mode == Mode::VARIABLE || _mode == Mode::OLD_VARIABLE,
61  "Mode must be VARIABLE or OLD_VARIABLE when calling NEML2Variable");
62  return _neml2_variable;
63 }
64 
65 const std::string &
67 {
68  mooseAssert(_mode == Mode::PARAMETER, "Mode must be PARAMETER when calling NEML2Parameter");
69  return _neml2_parameter;
70 }
71 
72 void
73 MOOSEToNEML2::insertInto(neml2::ValueMap & input,
74  std::map<std::string, neml2::Tensor> & params) const
75 {
77  input[_neml2_variable] = gatheredData();
78  else if (_mode == Mode::PARAMETER)
79  params[_neml2_parameter] = gatheredData();
80  else
81  mooseError("Encountered invalid Mode in MOOSEToNEML2::insertInto");
82 }
83 #endif
neml2::VariableName _neml2_variable
NEML2 input variable to transfer data to.
Definition: MOOSEToNEML2.h:79
void insertInto(neml2::ValueMap &, std::map< std::string, neml2::Tensor > &) const
Insert the gathered data into the NEML2 material model.
Definition: MOOSEToNEML2.C:73
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
T * get(const std::unique_ptr< T > &u)
The MooseUtils::get() specializations are used to support making forwards-compatible code changes fro...
Definition: MooseUtils.h:1155
void assertOldVariable(const neml2::VariableName &)
Assert that the NEML2 variable name sits on either the old_forces or the old_state subaxis...
Definition: NEML2Utils.C:39
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Mode _mode
Whether we should insert into NEML2 input variable or NEML2 model parameter.
Definition: MOOSEToNEML2.h:76
InputParameters emptyInputParameters()
void setMode(Mode) const
Change the mode of operation.
Definition: MOOSEToNEML2.C:34
MOOSEToNEML2(const InputParameters &params)
Definition: MOOSEToNEML2.C:23
std::string docstring(const std::string &desc)
Augment docstring if NEML2 is not enabled.
Definition: NEML2Utils.C:77
const neml2::VariableName & NEML2VariableName() const
Name of the NEML2 input variable (only meaningful when _mode == VARIABLE)
Definition: MOOSEToNEML2.C:58
virtual neml2::Tensor gatheredData() const =0
Convert data gathered from MOOSE into neml2::Tensor.
void assertNEML2Enabled()
Assert that NEML2 is enabled.
Definition: NEML2Utils.C:87
void assertVariable(const neml2::VariableName &)
Assert that the NEML2 variable name sits on either the forces or the state subaxis.
Definition: NEML2Utils.C:29
static InputParameters validParams()
Definition: MOOSEToNEML2.C:13
const std::string & NEML2ParameterName() const
Name of the NEML2 parameter (only meaningful when _mode == PARAMETER)
Definition: MOOSEToNEML2.C:66
virtual void checkMode() const
Perform error checking after _mode has been set.
Definition: MOOSEToNEML2.C:49
std::string _neml2_parameter
NEML2 parameter to transfer data to.
Definition: MOOSEToNEML2.h:82
neml2::VariableName parseVariableName(const std::string &)
Parse a raw string into NEML2 variable name.
Definition: NEML2Utils.C:49
const std::string _raw_name
Raw name of the input variable or model parameter.
Definition: MOOSEToNEML2.h:86