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