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 "RigidBodyMultiKernelAction.h" 11 : #include "Factory.h" 12 : #include "Parser.h" 13 : #include "Conversion.h" 14 : #include "FEProblem.h" 15 : 16 : registerMooseAction("PhaseFieldApp", RigidBodyMultiKernelAction, "add_kernel"); 17 : 18 : InputParameters 19 13 : RigidBodyMultiKernelAction::validParams() 20 : { 21 13 : InputParameters params = Action::validParams(); 22 13 : params.addClassDescription( 23 : "Action for applying Allen-Cahn equations and SingleGrainRigidBodyMotion to grains"); 24 26 : params.addRequiredParam<unsigned int>("op_num", "specifies the number of grains to create"); 25 26 : params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables"); 26 26 : params.addParam<VariableName>("c", "Name of coupled concentration variable"); 27 26 : params.addParam<MaterialPropertyName>("kappa_name", "kappa_op", "The kappa used with the kernel"); 28 26 : params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel"); 29 26 : params.addParam<MaterialPropertyName>( 30 : "f_name", "Base name of the free energy function F defined in a DerivativeParsedMaterial"); 31 26 : params.addParam<std::string>("base_name", 32 : "Optional parameter that allows the user to define " 33 : "type of force density under consideration"); 34 26 : params.addParam<Real>( 35 26 : "translation_constant", 500, "constant value characterizing grain translation"); 36 26 : params.addParam<Real>("rotation_constant", 1.0, "constant value characterizing grain rotation"); 37 26 : params.addRequiredParam<UserObjectName>( 38 : "grain_force", "userobject for getting force and torque acting on grains"); 39 26 : params.addRequiredParam<UserObjectName>("grain_tracker_object", 40 : "The FeatureFloodCount UserObject to get values from."); 41 26 : params.addRequiredParam<VectorPostprocessorName>("grain_volumes", 42 : "The feature volume VectorPostprocessorValue."); 43 26 : params.addParam<bool>("implicit", true, "Whether kernels are implicit or not"); 44 26 : params.addParam<bool>( 45 26 : "use_displaced_mesh", false, "Whether to use displaced mesh in the kernels"); 46 13 : return params; 47 0 : } 48 : 49 13 : RigidBodyMultiKernelAction::RigidBodyMultiKernelAction(const InputParameters & params) 50 : : Action(params), 51 13 : _op_num(getParam<unsigned int>("op_num")), 52 26 : _var_name_base(getParam<std::string>("var_name_base")), 53 39 : _implicit(getParam<bool>("implicit")) 54 : { 55 13 : } 56 : 57 : void 58 13 : RigidBodyMultiKernelAction::act() 59 : { 60 51 : for (unsigned int op = 0; op < _op_num; ++op) 61 : { 62 : // 63 : // Create variable names 64 : // 65 : 66 76 : std::string var_name = _var_name_base + Moose::stringify(op); 67 : 68 : // 69 : // Create vector of coupled variables 70 : // 71 : 72 : std::vector<VariableName> arg; 73 : unsigned int ind = 0; 74 : 75 76 : if (isParamValid("c")) 76 : { 77 38 : VariableName c = getParam<VariableName>("c"); 78 38 : arg.resize(_op_num); 79 : 80 162 : for (unsigned int j = 0; j < _op_num; ++j) 81 124 : if (j != op) 82 258 : arg[ind++] = _var_name_base + Moose::stringify(j); 83 : 84 38 : arg[ind++] = c; 85 : } 86 : else 87 : { 88 0 : arg.resize(_op_num - 1); 89 0 : for (unsigned int j = 0; j < _op_num; ++j) 90 0 : if (j != op) 91 0 : arg[ind++] = _var_name_base + Moose::stringify(j); 92 : } 93 : 94 : // 95 : // Create vector of order parameters 96 : // 97 : 98 38 : std::vector<VariableName> v(_op_num); 99 162 : for (unsigned int j = 0; j < _op_num; ++j) 100 372 : v[j] = _var_name_base + Moose::stringify(j); 101 : 102 : // 103 : // Set up ACInterface kernels 104 : // 105 : 106 : { 107 76 : InputParameters params = _factory.getValidParams("ACInterface"); 108 76 : params.set<NonlinearVariableName>("variable") = var_name; 109 76 : params.set<bool>("implicit") = getParam<bool>("implicit"); 110 76 : params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); 111 114 : params.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa_name"); 112 114 : params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mob_name"); 113 : 114 38 : std::string kernel_name = "ACInt_" + var_name; 115 76 : _problem->addKernel("ACInterface", kernel_name, params); 116 38 : } 117 : 118 : // 119 : // Set up the AllenCahn kernels 120 : // 121 : 122 : { 123 76 : InputParameters params = _factory.getValidParams("AllenCahn"); 124 76 : params.set<NonlinearVariableName>("variable") = var_name; 125 38 : params.set<std::vector<VariableName>>("coupled_variables") = arg; 126 114 : params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mob_name"); 127 114 : params.set<MaterialPropertyName>("f_name") = getParam<MaterialPropertyName>("f_name"); 128 38 : params.set<bool>("implicit") = _implicit; 129 76 : params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); 130 : 131 38 : std::string kernel_name = "AC_" + var_name; 132 76 : _problem->addKernel("AllenCahn", kernel_name, params); 133 38 : } 134 : 135 : // 136 : // Set up SingleGrainRigidBodyMotion kernels 137 : // 138 : 139 : { 140 76 : InputParameters params = _factory.getValidParams("SingleGrainRigidBodyMotion"); 141 76 : params.set<NonlinearVariableName>("variable") = var_name; 142 38 : params.set<std::vector<VariableName>>("v") = v; 143 38 : params.set<unsigned int>("op_index") = op; 144 114 : params.set<std::vector<VariableName>>("c") = {getParam<VariableName>("c")}; 145 38 : if (isParamValid("base_name")) 146 0 : params.set<std::string>("base_name") = getParam<std::string>("base_name"); 147 76 : params.set<Real>("translation_constant") = getParam<Real>("translation_constant"); 148 76 : params.set<Real>("rotation_constant") = getParam<Real>("rotation_constant"); 149 114 : params.set<UserObjectName>("grain_force") = getParam<UserObjectName>("grain_force"); 150 76 : params.set<UserObjectName>("grain_tracker_object") = 151 38 : getParam<UserObjectName>("grain_tracker_object"); 152 76 : params.set<VectorPostprocessorName>("grain_volumes") = 153 38 : getParam<VectorPostprocessorName>("grain_volumes"); 154 : 155 38 : params.set<bool>("implicit") = _implicit; 156 76 : params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); 157 : 158 38 : std::string kernel_name = "RigidBody_" + var_name; 159 76 : _problem->addKernel("SingleGrainRigidBodyMotion", kernel_name, params); 160 38 : } 161 : 162 : // 163 : // Set up TimeDerivative kernels 164 : // 165 : 166 : { 167 76 : InputParameters params = _factory.getValidParams("TimeDerivative"); 168 76 : params.set<NonlinearVariableName>("variable") = var_name; 169 38 : params.set<bool>("implicit") = true; 170 76 : params.set<bool>("use_displaced_mesh") = getParam<bool>("use_displaced_mesh"); 171 : 172 38 : std::string kernel_name = "IE_" + var_name; 173 76 : _problem->addKernel("TimeDerivative", kernel_name, params); 174 38 : } 175 38 : } 176 89 : }