https://mooseframework.inl.gov
GrainGrowthLinearizedInterfaceAction.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 
11 
12 // MOOSE includes
13 #include "GrainGrowthAction.h"
14 #include "AddVariableAction.h"
15 #include "Conversion.h"
16 #include "FEProblem.h"
17 #include "Factory.h"
18 #include "MooseObjectAction.h"
19 #include "MooseMesh.h"
20 #include "NonlinearSystemBase.h"
21 
22 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_aux_variable");
23 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_aux_kernel");
24 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_variable");
25 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_kernel");
26 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_material");
27 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_bounds_vectors");
28 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "copy_nodal_vars");
29 registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "check_copy_nodal_vars");
30 
33 {
35  params.addClassDescription("Set up the variable and the kernels needed for a grain growth "
36  "simulation with a linearized interface");
37  params.addRequiredParam<std::string>("op_name_base",
38  "specifies the base name of the dependent order parameters");
39  params.addRequiredParam<Real>(
40  "bound_value",
41  "Bounds value used in the constrained solve, where limits are +/- bound_value");
42 
43  return params;
44 }
45 
47  const InputParameters & params)
48  : GrainGrowthAction(params), _op_name_base(getParam<std::string>("op_name_base"))
49 {
50 }
51 
52 void
54 {
55  // Create Variables
56  addVariables();
57 
58  // Loop over order parameters
59  for (unsigned int op = 0; op < _op_num; op++)
60  {
61  // Create transformed variable name
62  std::string var_name = _var_name_base + Moose::stringify(op);
63 
64  // Create dependent order parameter name
65  std::string op_name = _op_name_base + Moose::stringify(op);
66 
67  // Add aux-variables
68  if (_current_task == "add_aux_variable")
69  {
70  // Add aux-variable defining dependent order parameter
71  auto var_params = _factory.getValidParams("MooseVariable");
72  var_params.set<MooseEnum>("family") = "LAGRANGE";
73  var_params.set<MooseEnum>("order") = "FIRST";
74  _problem->addAuxVariable("MooseVariable", op_name, var_params);
75 
76  // Add bounds_dummy used for constrained solve
77  var_params = _factory.getValidParams("MooseVariable");
78  var_params.set<MooseEnum>("family") = "LAGRANGE";
79  var_params.set<MooseEnum>("order") = "FIRST";
80  _problem->addAuxVariable("MooseVariable", "bounds_dummy", var_params);
81  }
82  // Add the kernels for each grain growth variable
83  else if (_current_task == "add_kernel")
84  {
85  //
86  // Add time derivative kernel
87  //
88 
89  {
90  std::string kernel_type = "ChangedVariableTimeDerivative";
91 
92  std::string kernel_name = var_name + "_" + kernel_type;
93  InputParameters params = _factory.getValidParams(kernel_type);
94  params.set<NonlinearVariableName>("variable") = var_name;
95  params.set<MaterialPropertyName>("order_parameter") = op_name;
96  params.applyParameters(parameters());
97 
98  _problem->addKernel(kernel_type, kernel_name, params);
99  }
100 
101  //
102  // Add ACGrGrPolyLinearizedInterface kernel
103  //
104 
105  {
106  std::string kernel_type = "ACGrGrPolyLinearizedInterface";
107 
108  // Make vector of variable names and order parameter names, excluding this one
109  std::vector<VariableName> v;
110  v.resize(_op_num - 1);
111  std::vector<MaterialPropertyName> other_ops;
112  other_ops.resize(_op_num - 1);
113 
114  unsigned int ind = 0;
115  for (unsigned int j = 0; j < _op_num; ++j)
116  if (j != op)
117  {
119  other_ops[ind] = _op_name_base + Moose::stringify(j);
120  ind++;
121  }
122 
123  std::string kernel_name = var_name + "_" + kernel_type;
124  InputParameters params2 = _factory.getValidParams(kernel_type);
125  params2.set<NonlinearVariableName>("variable") = var_name;
126  params2.set<std::vector<VariableName>>("v") = v;
127  params2.set<MaterialPropertyName>("this_op") = op_name;
128  params2.set<std::vector<MaterialPropertyName>>("other_ops") = other_ops;
129  params2.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
130  params2.applyParameters(parameters());
131 
132  _problem->addKernel(kernel_type, kernel_name, params2);
133  }
134 
135  //
136  // Add ACInterface kernel
137  //
138 
139  {
140  std::string kernel_type = "ACInterfaceChangedVariable";
141 
142  std::string kernel_name = var_name + "_" + kernel_type;
143  InputParameters params = _factory.getValidParams(kernel_type);
144  params.set<NonlinearVariableName>("variable") = var_name;
145  params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility");
146  params.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa");
147  params.set<MaterialPropertyName>("order_parameter") = op_name;
148  params.set<bool>("variable_L") = getParam<bool>("variable_mobility");
149  params.applyParameters(parameters());
150 
151  _problem->addKernel(kernel_type, kernel_name, params);
152  }
153  }
154 
155  // Add derivative-parsed material defining order parameter expressions
156  if (_current_task == "add_material")
157  {
158  std::string material_name = "LinearizedInterfaceFunction";
159  auto params = _factory.getValidParams(material_name);
160  params.set<std::string>("property_name") = op_name;
161  params.set<std::vector<VariableName>>("phi") = {var_name};
162 
163  _problem->addMaterial(material_name, op_name, params);
164  }
165 
166  if (_current_task == "add_aux_kernel")
167  {
168  {
169  // Add auxkernel for the order parameter auxvariable
170  std::string aux_kernel_type = "LinearizedInterfaceAux";
171 
172  std::string aux_kernel_name = op_name + aux_kernel_type;
173  InputParameters params = _factory.getValidParams(aux_kernel_type);
174  params.set<AuxVariableName>("variable") = op_name;
175  params.set<std::vector<VariableName>>("nonlinear_variable") = {var_name};
176  params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END};
177  params.applyParameters(parameters());
178 
179  _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params);
180  }
181  // Add upper and lower bound for each variable
182  // Upper bound
183  {
184  std::string bound_type = "ConstantBounds";
185  std::string bound_name = var_name + "_upper_bound";
186  auto params = _factory.getValidParams(bound_type);
187  params.set<AuxVariableName>("variable") = "bounds_dummy";
188  params.set<NonlinearVariableName>("bounded_variable") = var_name;
189  params.set<MooseEnum>("bound_type") = "upper";
190  params.set<Real>("bound_value") = getParam<Real>("bound_value");
191  _problem->addAuxKernel(bound_type, bound_name, params);
192  }
193  // Lower bound
194  {
195  std::string bound_type = "ConstantBounds";
196  std::string bound_name = var_name + "_lower_bound";
197  auto params = _factory.getValidParams(bound_type);
198  params.set<AuxVariableName>("variable") = "bounds_dummy";
199  params.set<NonlinearVariableName>("bounded_variable") = var_name;
200  params.set<MooseEnum>("bound_type") = "lower";
201  params.set<Real>("bound_value") = -1.0 * getParam<Real>("bound_value");
202  _problem->addAuxKernel(bound_type, bound_name, params);
203  }
204  }
205  }
206 
207  if (_current_task == "add_bounds_vectors")
208  {
209  _problem->getNonlinearSystemBase(/*nl_sys_num=*/0)
210  .addVector("lower_bound", false, libMesh::GHOSTED);
211  _problem->getNonlinearSystemBase(/*nl_sys_num=*/0)
212  .addVector("upper_bound", false, libMesh::GHOSTED);
213  }
214 
215  // Add AuxVriable and AuxKernel for Bnds variable
217 }
void addBnds(const std::string &name_base)
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
void applyParameters(const InputParameters &common, const std::vector< std::string > &exclude={}, const bool allow_private=false)
const ExecFlagType EXEC_TIMESTEP_END
void addRequiredParam(const std::string &name, const std::string &doc_string)
const unsigned int _op_num
number of variables and variable name base for variable creation
Factory & _factory
const std::string _var_name_base
GrainGrowthLinearizedInterfaceAction(const InputParameters &params)
const std::string _op_name_base
number of variables and variable name base for variable creation
const std::string & _current_task
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:84
static InputParameters validParams()
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const InputParameters & parameters() const
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_aux_variable")
const ExecFlagType EXEC_INITIAL