www.mooseframework.org
NonconservedAction.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 "NonconservedAction.h"
9 
10 // MOOSE includes
11 #include "Conversion.h"
12 #include "FEProblem.h"
13 #include "Factory.h"
14 #include "MooseObjectAction.h"
15 #include "MooseMesh.h"
16 
17 #include "libmesh/string_to_enum.h"
18 
19 template <>
20 InputParameters
22 {
23  InputParameters params = validParams<Action>();
24  params.addClassDescription(
25  "Set up the variable and the kernels needed for a nonconserved phase field variable");
26  // Get MooseEnums for the possible order/family options for this variable
27  MooseEnum families(AddVariableAction::getNonlinearVariableFamilies());
28  MooseEnum orders(AddVariableAction::getNonlinearVariableOrders());
29  params.addParam<MooseEnum>("family",
30  families,
31  "Specifies the family of FE "
32  "shape functions to use for this variable");
33  params.addParam<MooseEnum>("order",
34  orders,
35  "Specifies the order of the FE "
36  "shape function to use for this variable");
37  params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to this variable");
38  params.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
39  params.addParam<bool>(
40  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
41  params.addParamNamesToGroup("scaling implicit use_displaced_mesh", "Advanced");
42  params.addParam<MaterialPropertyName>("mobility", "L", "The mobility used with the kernel");
43  params.addParam<std::vector<VariableName>>("args",
44  "Vector of variable arguments this kernel depends on");
45  params.addRequiredParam<MaterialPropertyName>(
46  "free_energy", "Base name of the free energy function F defined in a free energy material");
47  params.addParam<MaterialPropertyName>("kappa", "kappa_op", "The kappa used with the kernel");
48  params.addParam<bool>("variable_mobility",
49  true,
50  "The mobility is a function of any MOOSE variable (if "
51  "this is set to false, L must be constant over the "
52  "entire domain!)");
53 
54  return params;
55 }
56 
57 NonconservedAction::NonconservedAction(const InputParameters & params)
58  : Action(params),
59  _var_name(name()),
60  _fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
61  Utility::string_to_enum<FEFamily>(getParam<MooseEnum>("family")))
62 {
63 }
64 
65 void
67 {
68  //
69  // Add variable
70  //
71  if (_current_task == "add_variable")
72  {
73  // Create nonconserved variable
74  _problem->addVariable(_var_name, _fe_type, getParam<Real>("scaling"));
75  }
76 
77  //
78  // Add Kernels
79  //
80  else if (_current_task == "add_kernel")
81  {
82  // Add time derivative kernel
83  std::string kernel_type = "TimeDerivative";
84 
85  std::string kernel_name = _var_name + "_" + kernel_type;
86  InputParameters params1 = _factory.getValidParams(kernel_type);
87  params1.set<NonlinearVariableName>("variable") = _var_name;
88  params1.applyParameters(parameters());
89 
90  _problem->addKernel(kernel_type, kernel_name, params1);
91 
92  // Add AllenCahn kernel
93  kernel_type = "AllenCahn";
94 
95  kernel_name = _var_name + "_" + kernel_type;
96  InputParameters params2 = _factory.getValidParams(kernel_type);
97  params2.set<NonlinearVariableName>("variable") = _var_name;
98  params2.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
99  params2.set<MaterialPropertyName>("f_name") = getParam<MaterialPropertyName>("free_energy");
100  params2.applyParameters(parameters());
101 
102  _problem->addKernel(kernel_type, kernel_name, params2);
103 
104  // Add ACInterface kernel
105  kernel_type = "ACInterface";
106 
107  kernel_name = _var_name + "_" + kernel_type;
108  InputParameters params3 = _factory.getValidParams(kernel_type);
109  params3.set<NonlinearVariableName>("variable") = _var_name;
110  params3.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
111  params3.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa");
112  params3.set<bool>("variable_L") = getParam<bool>("variable_mobility");
113  params3.applyParameters(parameters());
114 
115  _problem->addKernel(kernel_type, kernel_name, params3);
116  }
117 }
NonconservedAction(const InputParameters &params)
const FEType _fe_type
FEType for the variable being created.
InputParameters validParams< NonconservedAction >()
const NonlinearVariableName _var_name
Name of the variable being created.