www.mooseframework.org
MaterialVectorAuxKernelAction.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", MaterialVectorAuxKernelAction, "add_aux_kernel");
16 
19 {
21  params.addRequiredParam<unsigned int>(
22  "grain_num", "Value that specifies the number of grains to create aux kernels for.");
23  params.addRequiredParam<std::vector<std::string>>(
24  "variable_base", "Vector specifies the base name of the variables.");
25  params.addRequiredParam<std::vector<MaterialPropertyName>>("property",
26  "The material property names.");
27  params.addParam<bool>(
28  "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels.");
29  return params;
30 }
31 
33  : Action(params),
34  _grain_num(getParam<unsigned int>("grain_num")),
35  _var_name_base(getParam<std::vector<std::string>>("variable_base")),
36  _num_var(_var_name_base.size()),
37  _prop(getParam<std::vector<MaterialPropertyName>>("property")),
38  _num_prop(_prop.size())
39 {
40 }
41 
42 void
44 {
45  if (_num_prop != _num_var)
46  paramError("property", "variable_base and property must be vectors of the same size");
47 
48  for (unsigned int gr = 0; gr < _grain_num; ++gr)
49  for (unsigned int val = 0; val < _num_var; ++val)
50  {
51  std::string var_name = _var_name_base[val] + Moose::stringify(gr);
52 
53  InputParameters params = _factory.getValidParams("MaterialStdVectorAux");
54  params.set<AuxVariableName>("variable") = var_name;
55  params.set<MaterialPropertyName>("property") = _prop[val];
56  params.set<unsigned int>("index") = gr;
57  params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh");
58 
59  std::string aux_kernel_name = var_name;
60  _problem->addAuxKernel("MaterialStdVectorAux", aux_kernel_name, params);
61  }
62 }
const unsigned int _grain_num
number of grains to create
MaterialVectorAuxKernelAction(const InputParameters &params)
const std::vector< MaterialPropertyName > & _prop
list of material properties to be used
const unsigned int _num_prop
number of properties
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
const unsigned int _num_var
number of auxvariables
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)
const std::vector< std::string > & _var_name_base
base name for the auxvariables
Factory & _factory
static InputParameters validParams()
void paramError(const std::string &param, Args... args) const
std::string stringify(const T &t)
std::shared_ptr< FEProblemBase > & _problem
void ErrorVector unsigned int
registerMooseAction("PhaseFieldApp", MaterialVectorAuxKernelAction, "add_aux_kernel")