21#include "libmesh/string_to_enum.h"
35 "Set up the variable and the kernels needed for a grain growth simulation");
37 "specifies the number of order parameters to create");
38 params.
addRequiredParam<std::string>(
"var_name_base",
"specifies the base name of the variables");
40 "scaling", 1.0,
"Specifies a scaling factor to apply to the order parameters");
44 "Take the initial condition of all polycrystal variables from the mesh file");
51 "Specifies the family of FE "
52 "shape function to use for the order parameters");
55 "Specifies the order of the FE "
56 "shape function to use for the order parameters");
58 params.
addParam<MaterialPropertyName>(
59 "mobility",
"L",
"The isotropic mobility used with the kernels");
60 params.
addParam<MaterialPropertyName>(
"kappa",
"kappa_op",
"The kappa used with the kernels");
62 params.
addParam<VariableName>(
"c",
"Name of coupled concentration variable");
64 params.
addParam<Real>(
"en_ratio", 1.0,
"Ratio of surface to GB energy");
65 params.
addParam<
unsigned int>(
"ndef", 0,
"Specifies the number of deformed grains to create");
66 params.
addParam<
bool>(
"variable_mobility",
68 "The mobility is a function of any MOOSE variable (if "
69 "this is set to false, L must be constant over the "
72 "Vector of nonlinear variable arguments that L depends on");
74 params.
addParam<
bool>(
"implicit",
true,
"Whether kernels are implicit or not");
76 "use_displaced_mesh",
false,
"Whether to use displaced mesh in the kernels");
77 params.
addParam<
bool>(
"use_automatic_differentiation",
79 "Flag to use automatic differentiation (AD) objects when possible");
80 params.
addParam<std::vector<SubdomainName>>(
81 "block", {},
"Block restriction for the variables and kernels");
91 _op_num(getParam<unsigned
int>(
"op_num")),
92 _var_name_base(getParam<
std::string>(
"var_name_base")),
93 _fe_type(Utility::string_to_enum<Order>(getParam<
MooseEnum>(
"order")),
94 Utility::string_to_enum<FEFamily>(getParam<
MooseEnum>(
"family"))),
95 _initial_from_file(getParam<bool>(
"initial_from_file")),
96 _use_ad(getParam<bool>(
"use_automatic_differentiation"))
107 for (
unsigned int op = 0; op <
_op_num; op++)
120 std::string kernel_type =
_use_ad ?
"ADTimeDerivative" :
"TimeDerivative";
122 std::string kernel_name = var_name +
"_" + kernel_type;
124 params.
set<NonlinearVariableName>(
"variable") = var_name;
127 _problem->addKernel(kernel_type, kernel_name, params);
135 std::string kernel_type =
_use_ad ?
"ADGrainGrowth" :
"ACGrGrPoly";
138 std::vector<VariableName>
v;
141 unsigned int ind = 0;
142 for (
unsigned int j = 0; j <
_op_num; ++j)
146 std::string kernel_name = var_name +
"_" + kernel_type;
148 params.
set<NonlinearVariableName>(
"variable") = var_name;
149 params.
set<std::vector<VariableName>>(
"v") =
v;
150 params.
set<MaterialPropertyName>(
"mob_name") = getParam<MaterialPropertyName>(
"mobility");
153 _problem->addKernel(kernel_type, kernel_name, params);
161 std::string kernel_type =
_use_ad ?
"ADACInterface" :
"ACInterface";
163 std::string kernel_name = var_name +
"_" + kernel_type;
165 params.
set<NonlinearVariableName>(
"variable") = var_name;
166 params.
set<MaterialPropertyName>(
"mob_name") = getParam<MaterialPropertyName>(
"mobility");
167 params.
set<MaterialPropertyName>(
"kappa_name") = getParam<MaterialPropertyName>(
"kappa");
168 params.
set<
bool>(
"variable_L") = getParam<bool>(
"variable_mobility");
171 _problem->addKernel(kernel_type, kernel_name, params);
181 mooseError(
"AD version of ACGBPoly is not implemented");
183 std::string kernel_type =
"ACGBPoly";
185 std::string kernel_name = var_name +
"_" + kernel_type;
187 params.
set<NonlinearVariableName>(
"variable") = var_name;
188 params.
set<std::vector<VariableName>>(
"c") = {getParam<VariableName>(
"c")};
191 _problem->addKernel(kernel_type, kernel_name, params);
203 for (
unsigned int op = 0; op <
_op_num; op++)
216 auto * system = &
_problem->getNonlinearSystemBase(0);
217 system->addVariableToCopy(var_name, var_name,
"LATEST");
228 var_params.set<std::vector<Real>>(
"scaling") = {getParam<Real>(
"scaling")};
244 var_params.set<
MooseEnum>(
"order") =
"FIRST";
245 var_params.applySpecificParameters(
_pars, {
"block"});
246 _problem->addAuxVariable(
"MooseVariable",
"bnds", var_params);
252 std::vector<VariableName>
v;
255 for (
unsigned int j = 0; j <
_op_num; ++j)
258 std::string aux_kernel_type =
"BndsCalcAux";
260 std::string aux_kernel_name =
"bnds_" + aux_kernel_type;
262 params.
set<AuxVariableName>(
"variable") =
"bnds";
263 params.
set<std::vector<VariableName>>(
"v") =
v;
267 _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);
registerMooseAction("PhaseFieldApp", GrainGrowthAction, "add_aux_variable")
const ExecFlagType EXEC_TIMESTEP_END
const ExecFlagType EXEC_INITIAL
void ErrorVector unsigned int
static InputParameters validParams()
std::shared_ptr< FEProblemBase > & _problem
const std::string & _current_task
static MooseEnum getNonlinearVariableFamilies()
static MooseEnum getNonlinearVariableOrders()
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
InputParameters getValidParams(const std::string &name) const
const bool _initial_from_file
Take initial values from file?
const bool _use_ad
use AD objects where possible
GrainGrowthAction(const InputParameters ¶ms)
const std::string _var_name_base
static InputParameters validParams()
const unsigned int _op_num
number of variables and variable name base for variable creation
void addBnds(const std::string &name_base)
const libMesh::FEType _fe_type
FEType for the variable being created.
void setExodusFileRestart(bool flag)
const InputParameters & parameters() const
const std::string & type() const
void mooseError(Args &&... args) const
const InputParameters & _pars
bool isParamValid(const std::string &name) const
std::string stringify(const T &t)