www.mooseframework.org
GrainGrowthAction.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 /****************************************************************/
7 
8 #include "GrainGrowthAction.h"
9 
10 // MOOSE includes
11 #include "AddVariableAction.h"
12 #include "Conversion.h"
13 #include "FEProblem.h"
14 #include "Factory.h"
15 #include "MooseObjectAction.h"
16 #include "MooseMesh.h"
17 
18 #include "libmesh/string_to_enum.h"
19 
20 template <>
21 InputParameters
23 {
24  InputParameters params = validParams<Action>();
25  params.addClassDescription(
26  "Set up the variable and the kernels needed for a grain growth simulation");
27  params.addRequiredParam<unsigned int>("op_num",
28  "specifies the number of order parameters to create");
29  params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables");
30  // Get MooseEnums for the possible order/family options for this variable
31  MooseEnum families(AddVariableAction::getNonlinearVariableFamilies());
32  MooseEnum orders(AddVariableAction::getNonlinearVariableOrders());
33  params.addParam<MooseEnum>("family",
34  families,
35  "Specifies the family of FE "
36  "shape function to use for the order parameters");
37  params.addParam<MooseEnum>("order",
38  orders,
39  "Specifies the order of the FE "
40  "shape function to use for the order parameters");
41  params.addParam<MaterialPropertyName>(
42  "mobility", "L", "The isotropic mobility used with the kernels");
43  params.addParam<MaterialPropertyName>("kappa", "kappa_op", "The kappa used with the kernels");
44  params.addParam<Real>(
45  "scaling", 1.0, "Specifies a scaling factor to apply to the order parameters");
46  params.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
47  params.addParam<bool>(
48  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
49  params.addParam<VariableName>("c", "Name of coupled concentration variable");
50  params.addParam<Real>("en_ratio", 1.0, "Ratio of surface to GB energy");
51  params.addParam<unsigned int>("ndef", 0, "Specifies the number of deformed grains to create");
52  params.addParam<bool>("variable_mobility",
53  true,
54  "The mobility is a function of any MOOSE variable (if "
55  "this is set to false, L must be constant over the "
56  "entire domain!)");
57  params.addCoupledVar("args", "Vector of nonlinear variable arguments that L depends on");
58  params.addParamNamesToGroup("scaling implicit use_displaced_mesh", "Advanced");
59  params.addParamNamesToGroup("c en_ratio ndef", "Multiphysics");
60 
61  return params;
62 }
63 
64 GrainGrowthAction::GrainGrowthAction(const InputParameters & params)
65  : Action(params),
66  _op_num(getParam<unsigned int>("op_num")),
67  _var_name_base(getParam<std::string>("var_name_base")),
68  _fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
69  Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")))
70 {
71 }
72 
73 void
75 {
76  // Loop over order parameters
77  for (unsigned int op = 0; op < _op_num; op++)
78  {
79  // Create variable name
80  std::string var_name = _var_name_base + Moose::stringify(op);
81 
82  // Add variable
83  if (_current_task == "add_variable")
84  _problem->addVariable(var_name, _fe_type, getParam<Real>("scaling"));
85 
86  // Add Kernels
87  else if (_current_task == "add_kernel")
88  {
89  //
90  // Add time derivative kernel
91  //
92 
93  {
94  std::string kernel_type = "TimeDerivative";
95 
96  std::string kernel_name = var_name + "_" + kernel_type;
97  InputParameters params = _factory.getValidParams(kernel_type);
98  params.set<NonlinearVariableName>("variable") = var_name;
99  params.applyParameters(parameters());
100 
101  _problem->addKernel(kernel_type, kernel_name, params);
102  }
103 
104  //
105  // Add ACGrGrPoly kernel
106  //
107 
108  {
109  std::string kernel_type = "ACGrGrPoly";
110 
111  // Make vector of order parameter names, excluding this one
112  std::vector<VariableName> v;
113  v.resize(_op_num - 1);
114 
115  unsigned int ind = 0;
116  for (unsigned int j = 0; j < _op_num; ++j)
117  if (j != op)
118  v[ind++] = _var_name_base + Moose::stringify(j);
119 
120  std::string kernel_name = var_name + "_" + kernel_type;
121  InputParameters params = _factory.getValidParams(kernel_type);
122  params.set<NonlinearVariableName>("variable") = var_name;
123  params.set<std::vector<VariableName>>("v") = v;
124  params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
125  params.applyParameters(parameters());
126 
127  _problem->addKernel(kernel_type, kernel_name, params);
128  }
129 
130  //
131  // Add ACInterface kernel
132  //
133 
134  {
135  std::string kernel_type = "ACInterface";
136 
137  std::string kernel_name = var_name + "_" + kernel_type;
138  InputParameters params = _factory.getValidParams(kernel_type);
139  params.set<NonlinearVariableName>("variable") = var_name;
140  params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
141  params.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa");
142  params.set<bool>("variable_L") = getParam<bool>("variable_mobility");
143  params.applyParameters(parameters());
144 
145  _problem->addKernel(kernel_type, kernel_name, params);
146  }
147 
148  //
149  // Set up optional ACGBPoly bubble interaction kernels
150  //
151 
152  if (isParamValid("c"))
153  {
154  std::string kernel_type = "ACGBPoly";
155 
156  std::string kernel_name = var_name + "_" + kernel_type;
157  InputParameters params = _factory.getValidParams(kernel_type);
158  params.set<NonlinearVariableName>("variable") = var_name;
159  params.set<std::vector<VariableName>>("c") = {getParam<VariableName>("c")};
160  params.applyParameters(parameters());
161 
162  _problem->addKernel(kernel_type, kernel_name, params);
163  }
164  }
165  }
166  // Create auxvariable
167  if (_current_task == "add_aux_variable")
168  _problem->addAuxVariable("bnds",
169  FEType(Utility::string_to_enum<Order>("FIRST"),
170  Utility::string_to_enum<FEFamily>("LAGRANGE")));
171  // Create BndsCalcAux auxkernel
172  else if (_current_task == "add_aux_kernel")
173  {
174  // Make vector of order parameter names, excluding this one std::vector<VariableName> v;
175  std::vector<VariableName> v;
176  v.resize(_op_num);
177 
178  for (unsigned int j = 0; j < _op_num; ++j)
179  v[j] = _var_name_base + Moose::stringify(j);
180 
181  std::string aux_kernel_type = "BndsCalcAux";
182 
183  std::string aux_kernel_name = "bnds_" + aux_kernel_type;
184  InputParameters params = _factory.getValidParams(aux_kernel_type);
185  params.set<AuxVariableName>("variable") = "bnds";
186  params.set<std::vector<VariableName>>("v") = v;
187  params.applyParameters(parameters());
188 
189  _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);
190  }
191 }
const unsigned int _op_num
number of variables and variable name base for variable creation
virtual void act()
const std::string _var_name_base
InputParameters validParams< GrainGrowthAction >()
const FEType _fe_type
FEType for the variable being created.
GrainGrowthAction(const InputParameters &params)