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