https://mooseframework.inl.gov
GeneralizedPlaneStrainAction.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 
11 
12 #include "Conversion.h"
13 #include "FEProblem.h"
14 #include "MooseMesh.h"
15 #include "NonlinearSystemBase.h"
16 
17 registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_scalar_kernel");
18 
19 registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_kernel");
20 
21 registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_user_object");
22 
25 {
27  params.addClassDescription("Set up the GeneralizedPlaneStrain environment");
28  params.addRequiredParam<std::vector<VariableName>>("displacements", "The displacement variables");
29  params.addRequiredParam<VariableName>("scalar_out_of_plane_strain",
30  "Scalar variable for the out-of-plane strain (in "
31  "y direction for 1D Axisymmetric or in z "
32  "direction for 2D Cartesian problems)");
33  params.addParam<std::vector<VariableName>>("temperature", "The temperature variable");
34  MooseEnum outOfPlaneDirection("x y z", "z");
35  params.addParam<MooseEnum>(
36  "out_of_plane_direction", outOfPlaneDirection, "The direction of the out-of-plane strain.");
37  params.addParam<FunctionName>(
38  "out_of_plane_pressure_function",
39  "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction "
40  "(y for 1D Axisymmetric or z for 2D Cartesian problems)");
41  params.addDeprecatedParam<FunctionName>(
42  "out_of_plane_pressure",
43  "Function used to prescribe pressure (applied toward the body) in the out-of-plane direction "
44  "(y for 1D Axisymmetric or z for 2D Cartesian problems)",
45  "This has been replaced by 'out_of_plane_pressure_function'");
46  params.addParam<MaterialPropertyName>("out_of_plane_pressure_material",
47  "0",
48  "Material used to prescribe pressure (applied toward the "
49  "body) in the out-of-plane direction");
50  params.addDeprecatedParam<Real>(
51  "factor",
52  "Scale factor applied to prescribed out-of-plane pressure (both material and function)",
53  "This has been replaced by 'pressure_factor'");
54  params.addParam<Real>(
55  "pressure_factor",
56  "Scale factor applied to prescribed out-of-plane pressure (both material and function)");
57  params.addParam<bool>("use_displaced_mesh", false, "Whether to use displaced mesh");
58  params.addParam<std::string>("base_name", "Material property base name");
59  params.addParam<std::vector<SubdomainName>>("block",
60  "The list of ids of the blocks (subdomain) "
61  "that the GeneralizedPlaneStrain kernels "
62  "will be applied to");
63  params.addParam<std::vector<TagName>>(
64  "extra_vector_tags",
65  "The tag names for extra vectors that residual data should be saved into");
66  params.addParam<std::vector<TagName>>("absolute_value_vector_tags",
67  "The tag names for extra vectors that the absolute value "
68  "of the residual should be accumulated into");
69 
70  return params;
71 }
72 
74  : Action(params),
75  _displacements(getParam<std::vector<VariableName>>("displacements")),
76  _ndisp(_displacements.size()),
77  _out_of_plane_direction(getParam<MooseEnum>("out_of_plane_direction"))
78 {
79 }
80 
81 void
83 {
84  // user object name
85  const std::string uo_name = _name + "_GeneralizedPlaneStrainUserObject";
86 
87  //
88  // Add off diagonal Jacobian kernels
89  //
90  if (_current_task == "add_kernel")
91  {
92  std::string k_type = "GeneralizedPlaneStrainOffDiag";
93  InputParameters params = _factory.getValidParams(k_type);
94 
95  params.applyParameters(parameters(), {"scalar_out_of_plane_strain"});
96  params.set<std::vector<VariableName>>("scalar_out_of_plane_strain") = {
97  getParam<VariableName>("scalar_out_of_plane_strain")};
98 
99  // add off-diagonal jacobian kernels for the displacements
100  for (unsigned int i = 0; i < _ndisp; ++i)
101  {
102  if (_out_of_plane_direction == i)
103  continue;
104 
105  std::string k_name = _name + "GeneralizedPlaneStrainOffDiag_disp" + Moose::stringify(i);
106  params.set<NonlinearVariableName>("variable") = _displacements[i];
107 
108  _problem->addKernel(k_type, k_name, params);
109  }
110 
111  // add temperature kernel only if temperature is a nonlinear variable (and not an auxvariable)
112  if (isParamValid("temperature"))
113  {
114  auto temp = getParam<std::vector<VariableName>>("temperature");
115  if (temp.size() > 1)
116  mooseError("Only one variable may be specified in 'temperature'");
117  if (_problem->getNonlinearSystemBase(/*nl_sys_num=*/0).hasVariable(temp[0]))
118  {
119  std::string k_name = _name + "_GeneralizedPlaneStrainOffDiag_temp";
120  params.set<NonlinearVariableName>("variable") = temp[0];
121 
122  _problem->addKernel(k_type, k_name, params);
123  }
124  }
125  }
126 
127  //
128  // Add user object
129  //
130  else if (_current_task == "add_user_object")
131  {
132  std::string uo_type = "GeneralizedPlaneStrainUserObject";
133  InputParameters params = _factory.getValidParams(uo_type);
134 
135  // Skipping selected parameters in applyParameters() and then manually setting them only if they
136  // are set by the user is just to prevent both the current and deprecated variants of these
137  // parameters from both getting passed to the UserObject. Once we get rid of the deprecated
138  // versions, we can just set them all with applyParameters().
139  params.applyParameters(
140  parameters(),
141  {"out_of_plane_pressure", "out_of_plane_pressure_function", "factor", "pressure_factor"});
142  if (parameters().isParamSetByUser("out_of_plane_pressure"))
143  params.set<FunctionName>("out_of_plane_pressure") =
144  getParam<FunctionName>("out_of_plane_pressure");
145  if (parameters().isParamSetByUser("out_of_plane_pressure_function"))
146  params.set<FunctionName>("out_of_plane_pressure_function") =
147  getParam<FunctionName>("out_of_plane_pressure_function");
148  if (parameters().isParamSetByUser("factor"))
149  params.set<Real>("factor") = getParam<Real>("factor");
150  if (parameters().isParamSetByUser("pressure_factor"))
151  params.set<Real>("pressure_factor") = getParam<Real>("pressure_factor");
152 
153  _problem->addUserObject(uo_type, uo_name, params);
154  }
155 
156  //
157  // Add scalar kernel
158  //
159  else if (_current_task == "add_scalar_kernel")
160  {
161  std::string sk_type = "GeneralizedPlaneStrain";
162  InputParameters params = _factory.getValidParams(sk_type);
163 
164  params.set<NonlinearVariableName>("variable") =
165  getParam<VariableName>("scalar_out_of_plane_strain");
166 
167  // set the UserObjectName from previously added UserObject
168  params.set<UserObjectName>("generalized_plane_strain") = uo_name;
169 
170  if (isParamValid("extra_vector_tags"))
171  params.set<std::vector<TagName>>("extra_vector_tags") =
172  getParam<std::vector<TagName>>("extra_vector_tags");
173  if (isParamValid("absolute_value_vector_tags"))
174  params.set<std::vector<TagName>>("absolute_value_vector_tags") =
175  getParam<std::vector<TagName>>("absolute_value_vector_tags");
176 
177  _problem->addScalarKernel(sk_type, _name + "_GeneralizedPlaneStrain", params);
178  }
179 }
void addDeprecatedParam(const std::string &name, const T &value, const std::string &doc_string, const std::string &deprecation_message)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int _ndisp
Number of displacement variables.
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
registerMooseAction("SolidMechanicsApp", GeneralizedPlaneStrainAction, "add_scalar_kernel")
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Factory & _factory
static InputParameters validParams()
const std::string & _current_task
std::string stringify(const T &t)
const std::string _name
bool isParamSetByUser(const std::string &nm) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const
GeneralizedPlaneStrainAction(const InputParameters &params)
std::vector< VariableName > _displacements