www.mooseframework.org
MatVecRealGradAuxKernelAction.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "Factory.h"
12 #include "Conversion.h"
13 #include "FEProblem.h"
14 
15 registerMooseAction("PhaseFieldApp", MatVecRealGradAuxKernelAction, "add_aux_kernel");
16 
19 {
21  params.addRequiredParam<unsigned int>("op_num",
22  "Value that specifies the number of grains to create");
23  params.addRequiredParam<std::vector<std::string>>(
24  "var_name_base", "Vector specifies the base name of the variables");
25  params.addRequiredParam<std::vector<MaterialPropertyName>>("property",
26  "the scalar material property names");
27  params.addParam<bool>(
28  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels");
29  params.addRequiredParam<unsigned int>("dim", "the dimensions of the mesh");
30  params.addParam<AuxVariableName>("divergence_variable",
31  "Name of divergence variable to generate kernels for");
32  params.addParam<MaterialPropertyName>("divergence_property",
33  "Scalar material property name for divergence variable");
34  return params;
35 }
36 
38  : Action(params),
39  _div_var(getParam<AuxVariableName>("divergence_variable")),
40  _prop(getParam<std::vector<MaterialPropertyName>>("property")),
41  _div_prop(getParam<MaterialPropertyName>("divergence_property"))
42 {
43  mooseDeprecated("Use 'MaterialVectorAuxKernel' or 'MaterialVectorGradAuxKernel' action instead "
44  "depending on data_type of MaterialProperty<std::vector<data_type> >");
45 }
46 
47 void
49 {
50  const std::vector<std::string> var_name_base =
51  getParam<std::vector<std::string>>("var_name_base");
52 
53  const unsigned int op_num = getParam<unsigned int>("op_num");
54  const unsigned int dim = getParam<unsigned int>("dim");
55  const unsigned int size_v = var_name_base.size();
56  const unsigned int size_p = _prop.size();
57 
58  if (size_p != size_v)
59  paramError("property", "var_name_base and property must be vectors of the same dimension");
60 
61  for (unsigned int op = 0; op < op_num; ++op)
62  {
63  for (unsigned int val = 0; val < size_v; ++val)
64  for (unsigned int x = 0; x < dim; ++x)
65  {
66  std::string var_name = var_name_base[val] + Moose::stringify(x) + Moose::stringify(op);
67  {
68  InputParameters params = _factory.getValidParams("MaterialStdVectorRealGradientAux");
69  params.set<AuxVariableName>("variable") = var_name;
70  params.set<MaterialPropertyName>("property") = _prop[val];
71  params.set<unsigned int>("component") = x;
72  params.set<unsigned int>("index") = op;
73  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
74  _problem->addAuxKernel("MaterialStdVectorRealGradientAux", "grad_" + var_name, params);
75  }
76  }
77 
78  if (isParamValid("divergence_variable"))
79  {
80  if (isParamValid("divergence_property"))
81  {
82  InputParameters params = _factory.getValidParams("MaterialStdVectorAux");
83  params.set<AuxVariableName>("variable") = _div_var;
84  params.set<MaterialPropertyName>("property") = _div_prop;
85  params.set<unsigned int>("index") = op;
86  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
87  _problem->addAuxKernel("MaterialStdVectorAux", "div_" + Moose::stringify(op), params);
88  }
89  else
90  mooseError("Must specify a divergence_property name along with divergence_variable name");
91  }
92  }
93 }
registerMooseAction("PhaseFieldApp", MatVecRealGradAuxKernelAction, "add_aux_kernel")
void mooseDeprecated(Args &&... args) const
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
unsigned int dim
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
void addRequiredParam(const std::string &name, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Factory & _factory
static InputParameters validParams()
const std::vector< double > x
const std::vector< MaterialPropertyName > _prop
MatVecRealGradAuxKernelAction(const InputParameters &params)
void paramError(const std::string &param, Args... args) const
std::string stringify(const T &t)
void mooseError(Args &&... args) const
std::shared_ptr< FEProblemBase > & _problem