https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
21registerMooseAction("PhaseFieldApp", NonconservedAction, "add_variable");
22
23registerMooseAction("PhaseFieldApp", NonconservedAction, "add_kernel");
24
27{
30 "Set up the variable and the kernels needed for a non-conserved phase field variable");
31 // Get MooseEnums for the possible order/family options for this variable
34 params.addParam<MooseEnum>("family",
35 families,
36 "Specifies the family of FE "
37 "shape functions to use for this variable");
38 params.addParam<MooseEnum>("order",
39 orders,
40 "Specifies the order of the FE "
41 "shape function to use for this variable");
42 params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to this variable");
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 params.addParamNamesToGroup("scaling implicit use_displaced_mesh", "Advanced");
47 params.addParam<MaterialPropertyName>("mobility", "L", "The mobility used with the kernel");
48 params.addCoupledVar("coupled_variables",
49 "Vector of nonlinear variable arguments this kernel depends on");
50 params.addRequiredParam<MaterialPropertyName>(
51 "free_energy", "Base name of the free energy function F defined in a free energy material");
52 params.addParam<MaterialPropertyName>("kappa", "kappa_op", "The kappa used with the kernel");
53 params.addParam<bool>("variable_mobility",
54 true,
55 "The mobility is a function of any MOOSE variable (if "
56 "this is set to false, L must be constant over the "
57 "entire domain!)");
58 params.addParam<std::vector<SubdomainName>>(
59 "block", {}, "Block restriction for the variables and kernels");
60 return params;
61}
62
64 : Action(params),
65 _var_name(name()),
66 _fe_type(Utility::string_to_enum<Order>(getParam<MooseEnum>("order")),
67 Utility::string_to_enum<libMesh::FEFamily>(getParam<MooseEnum>("family")))
68{
69}
70
71void
73{
74 //
75 // Add variable
76 //
77 if (_current_task == "add_variable")
78 {
80 auto var_params = _factory.getValidParams(type);
81
82 var_params.applySpecificParameters(_pars, {"family", "order", "block"});
83 var_params.set<std::vector<Real>>("scaling") = {getParam<Real>("scaling")};
84
85 // Create nonconserved variable
86 _problem->addVariable(type, _var_name, var_params);
87 }
88
89 //
90 // Add Kernels
91 //
92 else if (_current_task == "add_kernel")
93 {
94 // Add time derivative kernel
95 std::string kernel_type = "TimeDerivative";
96
97 std::string kernel_name = _var_name + "_" + kernel_type;
98 InputParameters params1 = _factory.getValidParams(kernel_type);
99 params1.set<NonlinearVariableName>("variable") = _var_name;
100 params1.applyParameters(parameters());
101
102 _problem->addKernel(kernel_type, kernel_name, params1);
103
104 // Add AllenCahn kernel
105 kernel_type = "AllenCahn";
106
107 kernel_name = _var_name + "_" + kernel_type;
108 InputParameters params2 = _factory.getValidParams(kernel_type);
109 params2.set<NonlinearVariableName>("variable") = _var_name;
110 params2.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
111 params2.set<MaterialPropertyName>("f_name") = getParam<MaterialPropertyName>("free_energy");
112 params2.applyParameters(parameters());
113
114 _problem->addKernel(kernel_type, kernel_name, params2);
115
116 // Add ACInterface kernel
117 kernel_type = "ACInterface";
118
119 kernel_name = _var_name + "_" + kernel_type;
120 InputParameters params3 = _factory.getValidParams(kernel_type);
121 params3.set<NonlinearVariableName>("variable") = _var_name;
122 params3.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
123 params3.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa");
124 params3.set<bool>("variable_L") = getParam<bool>("variable_mobility");
125 params3.applyParameters(parameters());
126
127 _problem->addKernel(kernel_type, kernel_name, params3);
128 }
129}
registerMooseAction("PhaseFieldApp", NonconservedAction, "add_variable")
const std::string name
Definition Setup.h:21
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
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
T & set(const std::string &name, bool quiet_mode=false)
void addCoupledVar(const std::string &name, const std::string &doc_string)
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
const InputParameters & parameters() const
const std::string & type() const
const InputParameters & _pars
const NonlinearVariableName _var_name
Name of the variable being created.
const libMesh::FEType _fe_type
FEType for the variable being created.
NonconservedAction(const InputParameters &params)
static InputParameters validParams()
Factory & _factory
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...