https://mooseframework.inl.gov
NonconservedAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 
10 #include "NonconservedAction.h"
11 
12 // MOOSE includes
13 #include "Conversion.h"
14 #include "FEProblem.h"
15 #include "Factory.h"
16 #include "MooseObjectAction.h"
17 #include "MooseMesh.h"
18 
19 #include "libmesh/string_to_enum.h"
20 
21 using namespace libMesh;
22 
23 registerMooseAction("PhaseFieldApp", NonconservedAction, "add_variable");
24 
25 registerMooseAction("PhaseFieldApp", NonconservedAction, "add_kernel");
26 
29 {
31  params.addClassDescription(
32  "Set up the variable and the kernels needed for a non-conserved phase field variable");
33  // Get MooseEnums for the possible order/family options for this variable
36  params.addParam<MooseEnum>("family",
37  families,
38  "Specifies the family of FE "
39  "shape functions to use for this variable");
40  params.addParam<MooseEnum>("order",
41  orders,
42  "Specifies the order of the FE "
43  "shape function to use for this variable");
44  params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to this variable");
45  params.addParam<bool>("implicit", true, "Whether kernels are implicit or not");
46  params.addParam<bool>(
47  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
48  params.addParamNamesToGroup("scaling implicit use_displaced_mesh", "Advanced");
49  params.addParam<MaterialPropertyName>("mobility", "L", "The mobility used with the kernel");
50  params.addCoupledVar("args", "Vector of nonlinear variable arguments this kernel depends on");
51  params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
52  params.addRequiredParam<MaterialPropertyName>(
53  "free_energy", "Base name of the free energy function F defined in a free energy material");
54  params.addParam<MaterialPropertyName>("kappa", "kappa_op", "The kappa used with the kernel");
55  params.addParam<bool>("variable_mobility",
56  true,
57  "The mobility is a function of any MOOSE variable (if "
58  "this is set to false, L must be constant over the "
59  "entire domain!)");
60  params.addParam<std::vector<SubdomainName>>(
61  "block", {}, "Block restriction for the variables and kernels");
62  return params;
63 }
64 
66  : Action(params),
67  _var_name(name()),
68  _fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
69  Utility::string_to_enum<libMesh::FEFamily>(getParam<MooseEnum>("family")))
70 {
71 }
72 
73 void
75 {
76  //
77  // Add variable
78  //
79  if (_current_task == "add_variable")
80  {
82  auto var_params = _factory.getValidParams(type);
83 
84  var_params.applySpecificParameters(_pars, {"family", "order", "block"});
85  var_params.set<std::vector<Real>>("scaling") = {getParam<Real>("scaling")};
86 
87  // Create nonconserved variable
88  _problem->addVariable(type, _var_name, var_params);
89  }
90 
91  //
92  // Add Kernels
93  //
94  else if (_current_task == "add_kernel")
95  {
96  // Add time derivative kernel
97  std::string kernel_type = "TimeDerivative";
98 
99  std::string kernel_name = _var_name + "_" + kernel_type;
100  InputParameters params1 = _factory.getValidParams(kernel_type);
101  params1.set<NonlinearVariableName>("variable") = _var_name;
102  params1.applyParameters(parameters());
103 
104  _problem->addKernel(kernel_type, kernel_name, params1);
105 
106  // Add AllenCahn kernel
107  kernel_type = "AllenCahn";
108 
109  kernel_name = _var_name + "_" + kernel_type;
110  InputParameters params2 = _factory.getValidParams(kernel_type);
111  params2.set<NonlinearVariableName>("variable") = _var_name;
112  params2.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
113  params2.set<MaterialPropertyName>("f_name") = getParam<MaterialPropertyName>("free_energy");
114  params2.applyParameters(parameters());
115 
116  _problem->addKernel(kernel_type, kernel_name, params2);
117 
118  // Add ACInterface kernel
119  kernel_type = "ACInterface";
120 
121  kernel_name = _var_name + "_" + kernel_type;
122  InputParameters params3 = _factory.getValidParams(kernel_type);
123  params3.set<NonlinearVariableName>("variable") = _var_name;
124  params3.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
125  params3.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa");
126  params3.set<bool>("variable_L") = getParam<bool>("variable_mobility");
127  params3.applyParameters(parameters());
128 
129  _problem->addKernel(kernel_type, kernel_name, params3);
130  }
131 }
Order
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)
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
NonconservedAction(const InputParameters &params)
void addRequiredParam(const std::string &name, const std::string &doc_string)
static MooseEnum getNonlinearVariableFamilies()
Factory & _factory
static InputParameters validParams()
static MooseEnum getNonlinearVariableOrders()
static InputParameters validParams()
const std::string name
Definition: Setup.h:20
T string_to_enum(const std::string &s)
const std::string & type() const
const std::string & _current_task
void deprecateCoupledVar(const std::string &old_name, const std::string &new_name, const std::string &removal_date)
static std::string variableType(const libMesh::FEType &fe_type, const bool is_fv=false, const bool is_array=false)
void addCoupledVar(const std::string &name, const std::string &doc_string)
const libMesh::FEType _fe_type
FEType for the variable being created.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const InputParameters & _pars
registerMooseAction("PhaseFieldApp", NonconservedAction, "add_variable")
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const
const NonlinearVariableName _var_name
Name of the variable being created.
FEFamily
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)