https://mooseframework.inl.gov
MultiAuxVariablesAction.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 #include "FEProblem.h"
12 #include "Conversion.h"
13 #include "MooseMesh.h"
14 
15 registerMooseAction("PhaseFieldApp", MultiAuxVariablesAction, "add_aux_variable");
16 
19 {
21  params.addClassDescription("Set up auxvariables for components of "
22  "MaterialProperty<std::vector<data_type> > for polycrystal sample.");
23  params.addRequiredParam<unsigned int>(
24  "grain_num", "Specifies the number of grains to create the aux variables for.");
25  params.addRequiredParam<std::vector<std::string>>(
26  "variable_base", "Vector that specifies the base name of the variables.");
27  MultiMooseEnum data_type("Real RealGradient", "Real");
29  "data_type",
30  data_type,
31  "Specifying data type of the materials property, variables are created accordingly");
32  return params;
33 }
34 
36  : AddAuxVariableAction(params),
37  _grain_num(getParam<unsigned int>("grain_num")),
38  _var_name_base(getParam<std::vector<std::string>>("variable_base")),
39  _num_var(_var_name_base.size()),
40  _data_type(getParam<MultiMooseEnum>("data_type")),
41  _data_size(_data_type.size())
42 {
43 }
44 
45 void
47 {
48  init();
49 
50  if (_num_var != _data_size)
51  mooseError("Data type not provided for all the AuxVariables in MultiAuxVariablesAction");
52 
53  // mesh dimension & components required for gradient variables
54  const unsigned int dim = _mesh->dimension();
55  const std::vector<char> suffix = {'x', 'y', 'z'};
56 
57  // Loop through the number of order parameters
58  for (unsigned int val = 0; val < _num_var; ++val)
59  for (unsigned int gr = 0; gr < _grain_num; ++gr)
60  {
62  if (_data_type[val] == "Real")
63  {
64  // Create variable names with variable name base followed by the order parameter it applies
65  // to.
66  std::string var_name = _var_name_base[val] + Moose::stringify(gr);
67 
68  _problem->addAuxVariable(_type, var_name, _moose_object_pars);
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  _problem->addAuxVariable(_type, var_name, _moose_object_pars);
81  }
82  }
83 }
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
MPI_Datatype data_type
unsigned int dim
void init() override
static InputParameters validParams()
registerMooseAction("PhaseFieldApp", MultiAuxVariablesAction, "add_aux_variable")
void addRequiredParam(const std::string &name, const std::string &doc_string)
const std::vector< double > x
std::string stringify(const T &t)
std::shared_ptr< MooseMesh > & _mesh
InputParameters _moose_object_pars
void mooseError(Args &&... args) const
void addClassDescription(const std::string &doc_string)
std::shared_ptr< FEProblemBase > & _problem
const unsigned int _grain_num
number of grains to create
Automatically generates all auxvariables given vectors telling it the names and how many to create...
const unsigned int _data_size
number of properties
MultiAuxVariablesAction(const InputParameters &params)
void ErrorVector unsigned int
static InputParameters validParams()