www.mooseframework.org
RigidBodyMultiKernelAction.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
3 /* */
4 /* All contents are licensed under LGPL V2.1 */
5 /* See LICENSE for full restrictions */
6 /****************************************************************/
8 #include "Factory.h"
9 #include "Parser.h"
10 #include "Conversion.h"
11 #include "FEProblem.h"
12 
13 template <>
14 InputParameters
16 {
17  InputParameters params = validParams<Action>();
18  params.addClassDescription(
19  "Action for applying AllenCahn equations and SingleGrainRigidBodyMotion to grains");
20  params.addRequiredParam<unsigned int>("op_num", "specifies the number of grains to create");
21  params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables");
22  params.addParam<VariableName>("c", "Name of coupled concentration variable");
23  params.addParam<MaterialPropertyName>("kappa_name", "kappa_op", "The kappa used with the kernel");
24  params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel");
25  params.addParam<MaterialPropertyName>(
26  "f_name", "Base name of the free energy function F defined in a DerivativeParsedMaterial");
27  params.addParam<std::string>("base_name",
28  "Optional parameter that allows the user to define "
29  "type of force density under consideration");
30  params.addParam<Real>(
31  "translation_constant", 500, "constant value characterizing grain translation");
32  params.addParam<Real>("rotation_constant", 1.0, "constant value characterizing grain rotation");
33  params.addRequiredParam<UserObjectName>(
34  "grain_force", "userobject for getting force and torque acting on grains");
35  params.addRequiredParam<UserObjectName>("grain_tracker_object",
36  "The FeatureFloodCount UserObject to get values from.");
37  params.addRequiredParam<VectorPostprocessorName>("grain_volumes",
38  "The feature volume VectorPostprocessorValue.");
39  params.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
40  params.addParam<bool>(
41  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
42  return params;
43 }
44 
46  : Action(params),
47  _op_num(getParam<unsigned int>("op_num")),
48  _var_name_base(getParam<std::string>("var_name_base")),
49  _implicit(getParam<bool>("implicit"))
50 {
51 }
52 
53 void
55 {
56  for (unsigned int op = 0; op < _op_num; ++op)
57  {
58  //
59  // Create variable names
60  //
61 
62  std::string var_name = _var_name_base + Moose::stringify(op);
63 
64  //
65  // Create vector of coupled variables
66  //
67 
68  std::vector<VariableName> arg;
69  unsigned int ind = 0;
70 
71  if (isParamValid("c"))
72  {
73  VariableName c = getParam<VariableName>("c");
74  arg.resize(_op_num);
75 
76  for (unsigned int j = 0; j < _op_num; ++j)
77  if (j != op)
78  arg[ind++] = _var_name_base + Moose::stringify(j);
79 
80  arg[ind++] = c;
81  }
82  else
83  {
84  arg.resize(_op_num - 1);
85  for (unsigned int j = 0; j < _op_num; ++j)
86  if (j != op)
87  arg[ind++] = _var_name_base + Moose::stringify(j);
88  }
89 
90  //
91  // Create vector of order parameters
92  //
93 
94  std::vector<VariableName> v(_op_num);
95  for (unsigned int j = 0; j < _op_num; ++j)
96  v[j] = _var_name_base + Moose::stringify(j);
97 
98  //
99  // Set up ACInterface kernels
100  //
101 
102  {
103  InputParameters params = _factory.getValidParams("ACInterface");
104  params.set<NonlinearVariableName>("variable") = var_name;
105  params.set<bool>("implicit") = getParam<bool>("implicit");
106  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
107  params.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa_name");
108  params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mob_name");
109 
110  std::string kernel_name = "ACInt_" + var_name;
111  _problem->addKernel("ACInterface", kernel_name, params);
112  }
113 
114  //
115  // Set up the AllenCahn kernels
116  //
117 
118  {
119  InputParameters params = _factory.getValidParams("AllenCahn");
120  params.set<NonlinearVariableName>("variable") = var_name;
121  params.set<std::vector<VariableName>>("args") = arg;
122  params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mob_name");
123  params.set<MaterialPropertyName>("f_name") = getParam<MaterialPropertyName>("f_name");
124  params.set<bool>("implicit") = _implicit;
125  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
126 
127  std::string kernel_name = "AC_" + var_name;
128  _problem->addKernel("AllenCahn", kernel_name, params);
129  }
130 
131  //
132  // Set up SingleGrainRigidBodyMotion kernels
133  //
134 
135  {
136  InputParameters params = _factory.getValidParams("SingleGrainRigidBodyMotion");
137  params.set<NonlinearVariableName>("variable") = var_name;
138  params.set<std::vector<VariableName>>("v") = v;
139  params.set<unsigned int>("op_index") = op;
140  params.set<std::vector<VariableName>>("c") = {getParam<VariableName>("c")};
141  if (isParamValid("base_name"))
142  params.set<std::string>("base_name") = getParam<std::string>("base_name");
143  params.set<Real>("translation_constant") = getParam<Real>("translation_constant");
144  params.set<Real>("rotation_constant") = getParam<Real>("rotation_constant");
145  params.set<UserObjectName>("grain_force") = getParam<UserObjectName>("grain_force");
146  params.set<UserObjectName>("grain_tracker_object") =
147  getParam<UserObjectName>("grain_tracker_object");
148  params.set<VectorPostprocessorName>("grain_volumes") =
149  getParam<VectorPostprocessorName>("grain_volumes");
150 
151  params.set<bool>("implicit") = _implicit;
152  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
153 
154  std::string kernel_name = "RigidBody_" + var_name;
155  _problem->addKernel("SingleGrainRigidBodyMotion", kernel_name, params);
156  }
157 
158  //
159  // Set up TimeDerivative kernels
160  //
161 
162  {
163  InputParameters params = _factory.getValidParams("TimeDerivative");
164  params.set<NonlinearVariableName>("variable") = var_name;
165  params.set<bool>("implicit") = true;
166  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
167 
168  std::string kernel_name = "IE_" + var_name;
169  _problem->addKernel("TimeDerivative", kernel_name, params);
170  }
171  }
172 }
InputParameters validParams< RigidBodyMultiKernelAction >()
RigidBodyMultiKernelAction(const InputParameters &params)