www.mooseframework.org
MultiAuxVariablesAction.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 /****************************************************************/
8 #include "FEProblem.h"
9 #include "Conversion.h"
10 #include "MooseMesh.h"
11 
12 template <>
13 InputParameters
15 {
16  InputParameters params = validParams<AddAuxVariableAction>();
17  params.addClassDescription("Set up auxvariables for components of "
18  "MaterialProperty<std::vector<data_type> > for polycrystal sample.");
19  params.addRequiredParam<unsigned int>(
20  "grain_num", "Specifies the number of grains to create the aux varaivles for.");
21  params.addRequiredParam<std::vector<std::string>>(
22  "variable_base", "Vector that specifies the base name of the variables.");
23  MultiMooseEnum data_type("Real RealGradient", "Real");
24  params.addRequiredParam<MultiMooseEnum>(
25  "data_type",
26  data_type,
27  "Specifying data type of the materials property, variables are created accordingly");
28  return params;
29 }
30 
32  : AddAuxVariableAction(params),
33  _grain_num(getParam<unsigned int>("grain_num")),
34  _var_name_base(getParam<std::vector<std::string>>("variable_base")),
35  _num_var(_var_name_base.size()),
36  _data_type(getParam<MultiMooseEnum>("data_type")),
37  _data_size(_data_type.size())
38 {
39 }
40 
41 void
43 {
44  if (_num_var != _data_size)
45  mooseError("Data type not provided for all the AuxVariables in MultiAuxVariablesAction");
46 
47  // Blocks from the input
48  std::set<SubdomainID> blocks = getSubdomainIDs();
49 
50  // mesh dimension & components required for gradient variables
51  const unsigned int dim = _mesh->dimension();
52  const std::vector<char> suffix = {'x', 'y', 'z'};
53 
54  // Loop through the number of order parameters
55  for (unsigned int val = 0; val < _num_var; ++val)
56  for (unsigned int gr = 0; gr < _grain_num; ++gr)
57  {
59  if (_data_type[val] == "Real")
60  {
61  // Create variable names with variable name base followed by the order parameter it applies
62  // to.
63  std::string var_name = _var_name_base[val] + Moose::stringify(gr);
64 
65  if (blocks.empty())
66  _problem->addAuxVariable(var_name, _fe_type);
67  else
68  _problem->addAuxVariable(var_name, _fe_type, &blocks);
69  }
71  if (_data_type[val] == "RealGradient")
72  for (unsigned int x = 0; x < dim; ++x)
73  {
78  std::string var_name = _var_name_base[val] + Moose::stringify(gr) + "_" + suffix[x];
79 
80  if (blocks.empty())
81  _problem->addAuxVariable(var_name, _fe_type);
82  else
83  _problem->addAuxVariable(var_name, _fe_type, &blocks);
84  }
85  }
86 }
const MultiMooseEnum & _data_type
list of material properties to be used
const std::vector< std::string > & _var_name_base
base name for the auxvariables
const unsigned int _num_var
number of auxvariables
MultiAuxVariablesAction(InputParameters params)
InputParameters validParams< MultiAuxVariablesAction >()
const unsigned int _grain_num
number of grains to create
const unsigned int _data_size
number of properties