Line data Source code
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 : 10 : #include "MatVecRealGradAuxKernelAction.h" 11 : #include "Factory.h" 12 : #include "Conversion.h" 13 : #include "FEProblem.h" 14 : 15 : registerMooseAction("PhaseFieldApp", MatVecRealGradAuxKernelAction, "add_aux_kernel"); 16 : 17 : InputParameters 18 0 : MatVecRealGradAuxKernelAction::validParams() 19 : { 20 0 : InputParameters params = Action::validParams(); 21 0 : params.addClassDescription("Outputs all components of the gradient of the real standard " 22 : "vector-valued properties specified"); 23 0 : params.addRequiredParam<unsigned int>("op_num", 24 : "Value that specifies the number of grains to create"); 25 0 : params.addRequiredParam<std::vector<std::string>>( 26 : "var_name_base", "Vector specifies the base name of the variables"); 27 0 : params.addRequiredParam<std::vector<MaterialPropertyName>>("property", 28 : "the scalar material property names"); 29 0 : params.addParam<bool>( 30 0 : "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels"); 31 0 : params.addRequiredParam<unsigned int>("dim", "the dimensions of the mesh"); 32 0 : params.addParam<AuxVariableName>("divergence_variable", 33 : "Name of divergence variable to generate kernels for"); 34 0 : params.addParam<MaterialPropertyName>("divergence_property", 35 : "Scalar material property name for divergence variable"); 36 0 : return params; 37 0 : } 38 : 39 0 : MatVecRealGradAuxKernelAction::MatVecRealGradAuxKernelAction(const InputParameters & params) 40 : : Action(params), 41 0 : _div_var(getParam<AuxVariableName>("divergence_variable")), 42 0 : _prop(getParam<std::vector<MaterialPropertyName>>("property")), 43 0 : _div_prop(getParam<MaterialPropertyName>("divergence_property")) 44 : { 45 0 : mooseDeprecated("Use 'MaterialVectorAuxKernel' or 'MaterialVectorGradAuxKernel' action instead " 46 : "depending on data_type of MaterialProperty<std::vector<data_type> >"); 47 0 : } 48 : 49 : void 50 0 : MatVecRealGradAuxKernelAction::act() 51 : { 52 : const std::vector<std::string> var_name_base = 53 0 : getParam<std::vector<std::string>>("var_name_base"); 54 : 55 0 : const unsigned int op_num = getParam<unsigned int>("op_num"); 56 0 : const unsigned int dim = getParam<unsigned int>("dim"); 57 0 : const unsigned int size_v = var_name_base.size(); 58 0 : const unsigned int size_p = _prop.size(); 59 : 60 0 : if (size_p != size_v) 61 0 : paramError("property", "var_name_base and property must be vectors of the same dimension"); 62 : 63 0 : for (unsigned int op = 0; op < op_num; ++op) 64 : { 65 0 : for (unsigned int val = 0; val < size_v; ++val) 66 0 : for (unsigned int x = 0; x < dim; ++x) 67 : { 68 0 : std::string var_name = var_name_base[val] + Moose::stringify(x) + Moose::stringify(op); 69 : { 70 0 : InputParameters params = _factory.getValidParams("MaterialStdVectorRealGradientAux"); 71 0 : params.set<AuxVariableName>("variable") = var_name; 72 0 : params.set<MaterialPropertyName>("property") = _prop[val]; 73 0 : params.set<unsigned int>("component") = x; 74 0 : params.set<unsigned int>("index") = op; 75 0 : params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); 76 0 : _problem->addAuxKernel("MaterialStdVectorRealGradientAux", "grad_" + var_name, params); 77 0 : } 78 : } 79 : 80 0 : if (isParamValid("divergence_variable")) 81 : { 82 0 : if (isParamValid("divergence_property")) 83 : { 84 0 : InputParameters params = _factory.getValidParams("MaterialStdVectorAux"); 85 0 : params.set<AuxVariableName>("variable") = _div_var; 86 0 : params.set<MaterialPropertyName>("property") = _div_prop; 87 0 : params.set<unsigned int>("index") = op; 88 0 : params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); 89 0 : _problem->addAuxKernel("MaterialStdVectorAux", "div_" + Moose::stringify(op), params); 90 0 : } 91 : else 92 0 : mooseError("Must specify a divergence_property name along with divergence_variable name"); 93 : } 94 : } 95 0 : }