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 "GrainGrowthLinearizedInterfaceAction.h" 11 : 12 : // MOOSE includes 13 : #include "GrainGrowthAction.h" 14 : #include "AddVariableAction.h" 15 : #include "Conversion.h" 16 : #include "FEProblem.h" 17 : #include "Factory.h" 18 : #include "MooseObjectAction.h" 19 : #include "MooseMesh.h" 20 : #include "NonlinearSystemBase.h" 21 : 22 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_aux_variable"); 23 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_aux_kernel"); 24 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_variable"); 25 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_kernel"); 26 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_material"); 27 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "add_bounds_vectors"); 28 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "copy_nodal_vars"); 29 : registerMooseAction("PhaseFieldApp", GrainGrowthLinearizedInterfaceAction, "check_copy_nodal_vars"); 30 : 31 : InputParameters 32 221 : GrainGrowthLinearizedInterfaceAction::validParams() 33 : { 34 221 : InputParameters params = GrainGrowthAction::validParams(); 35 221 : params.addClassDescription("Set up the variable and the kernels needed for a grain growth " 36 : "simulation with a linearized interface"); 37 442 : params.addRequiredParam<std::string>("op_name_base", 38 : "specifies the base name of the dependent order parameters"); 39 442 : params.addRequiredParam<Real>( 40 : "bound_value", 41 : "Bounds value used in the constrained solve, where limits are +/- bound_value"); 42 : 43 221 : return params; 44 0 : } 45 : 46 21 : GrainGrowthLinearizedInterfaceAction::GrainGrowthLinearizedInterfaceAction( 47 21 : const InputParameters & params) 48 42 : : GrainGrowthAction(params), _op_name_base(getParam<std::string>("op_name_base")) 49 : { 50 21 : } 51 : 52 : void 53 168 : GrainGrowthLinearizedInterfaceAction::act() 54 : { 55 : // Create Variables 56 168 : addVariables(); 57 : 58 : // Loop over order parameters 59 1008 : for (unsigned int op = 0; op < _op_num; op++) 60 : { 61 : // Create transformed variable name 62 1680 : std::string var_name = _var_name_base + Moose::stringify(op); 63 : 64 : // Create dependent order parameter name 65 840 : std::string op_name = _op_name_base + Moose::stringify(op); 66 : 67 : // Add aux-variables 68 840 : if (_current_task == "add_aux_variable") 69 : { 70 : // Add aux-variable defining dependent order parameter 71 105 : auto var_params = _factory.getValidParams("MooseVariable"); 72 210 : var_params.set<MooseEnum>("family") = "LAGRANGE"; 73 210 : var_params.set<MooseEnum>("order") = "FIRST"; 74 105 : _problem->addAuxVariable("MooseVariable", op_name, var_params); 75 : 76 : // Add bounds_dummy used for constrained solve 77 105 : var_params = _factory.getValidParams("MooseVariable"); 78 210 : var_params.set<MooseEnum>("family") = "LAGRANGE"; 79 210 : var_params.set<MooseEnum>("order") = "FIRST"; 80 210 : _problem->addAuxVariable("MooseVariable", "bounds_dummy", var_params); 81 105 : } 82 : // Add the kernels for each grain growth variable 83 735 : else if (_current_task == "add_kernel") 84 : { 85 : // 86 : // Add time derivative kernel 87 : // 88 : 89 : { 90 105 : std::string kernel_type = "ChangedVariableTimeDerivative"; 91 : 92 105 : std::string kernel_name = var_name + "_" + kernel_type; 93 105 : InputParameters params = _factory.getValidParams(kernel_type); 94 210 : params.set<NonlinearVariableName>("variable") = var_name; 95 210 : params.set<MaterialPropertyName>("order_parameter") = op_name; 96 105 : params.applyParameters(parameters()); 97 : 98 105 : _problem->addKernel(kernel_type, kernel_name, params); 99 105 : } 100 : 101 : // 102 : // Add ACGrGrPolyLinearizedInterface kernel 103 : // 104 : 105 : { 106 105 : std::string kernel_type = "ACGrGrPolyLinearizedInterface"; 107 : 108 : // Make vector of variable names and order parameter names, excluding this one 109 : std::vector<VariableName> v; 110 105 : v.resize(_op_num - 1); 111 : std::vector<MaterialPropertyName> other_ops; 112 105 : other_ops.resize(_op_num - 1); 113 : 114 : unsigned int ind = 0; 115 756 : for (unsigned int j = 0; j < _op_num; ++j) 116 651 : if (j != op) 117 : { 118 1638 : v[ind] = _var_name_base + Moose::stringify(j); 119 546 : other_ops[ind] = _op_name_base + Moose::stringify(j); 120 546 : ind++; 121 : } 122 : 123 105 : std::string kernel_name = var_name + "_" + kernel_type; 124 105 : InputParameters params2 = _factory.getValidParams(kernel_type); 125 210 : params2.set<NonlinearVariableName>("variable") = var_name; 126 210 : params2.set<std::vector<VariableName>>("v") = v; 127 210 : params2.set<MaterialPropertyName>("this_op") = op_name; 128 105 : params2.set<std::vector<MaterialPropertyName>>("other_ops") = other_ops; 129 315 : params2.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility"); 130 105 : params2.applyParameters(parameters()); 131 : 132 105 : _problem->addKernel(kernel_type, kernel_name, params2); 133 210 : } 134 : 135 : // 136 : // Add ACInterface kernel 137 : // 138 : 139 : { 140 105 : std::string kernel_type = "ACInterfaceChangedVariable"; 141 : 142 105 : std::string kernel_name = var_name + "_" + kernel_type; 143 105 : InputParameters params = _factory.getValidParams(kernel_type); 144 210 : params.set<NonlinearVariableName>("variable") = var_name; 145 315 : params.set<MaterialPropertyName>("mob_name") = getParam<MaterialPropertyName>("mobility"); 146 315 : params.set<MaterialPropertyName>("kappa_name") = getParam<MaterialPropertyName>("kappa"); 147 210 : params.set<MaterialPropertyName>("order_parameter") = op_name; 148 210 : params.set<bool>("variable_L") = getParam<bool>("variable_mobility"); 149 105 : params.applyParameters(parameters()); 150 : 151 105 : _problem->addKernel(kernel_type, kernel_name, params); 152 105 : } 153 : } 154 : 155 : // Add derivative-parsed material defining order parameter expressions 156 840 : if (_current_task == "add_material") 157 : { 158 105 : std::string material_name = "LinearizedInterfaceFunction"; 159 105 : auto params = _factory.getValidParams(material_name); 160 210 : params.set<std::string>("property_name") = op_name; 161 315 : params.set<std::vector<VariableName>>("phi") = {var_name}; 162 : 163 105 : _problem->addMaterial(material_name, op_name, params); 164 105 : } 165 : 166 840 : if (_current_task == "add_aux_kernel") 167 : { 168 : { 169 : // Add auxkernel for the order parameter auxvariable 170 105 : std::string aux_kernel_type = "LinearizedInterfaceAux"; 171 : 172 105 : std::string aux_kernel_name = op_name + aux_kernel_type; 173 105 : InputParameters params = _factory.getValidParams(aux_kernel_type); 174 210 : params.set<AuxVariableName>("variable") = op_name; 175 315 : params.set<std::vector<VariableName>>("nonlinear_variable") = {var_name}; 176 420 : params.set<ExecFlagEnum>("execute_on") = {EXEC_INITIAL, EXEC_TIMESTEP_END}; 177 105 : params.applyParameters(parameters()); 178 : 179 105 : _problem->addAuxKernel(aux_kernel_type, aux_kernel_name, params); 180 105 : } 181 : // Add upper and lower bound for each variable 182 : // Upper bound 183 : { 184 105 : std::string bound_type = "ConstantBounds"; 185 105 : std::string bound_name = var_name + "_upper_bound"; 186 105 : auto params = _factory.getValidParams(bound_type); 187 210 : params.set<AuxVariableName>("variable") = "bounds_dummy"; 188 210 : params.set<NonlinearVariableName>("bounded_variable") = var_name; 189 210 : params.set<MooseEnum>("bound_type") = "upper"; 190 210 : params.set<Real>("bound_value") = getParam<Real>("bound_value"); 191 105 : _problem->addAuxKernel(bound_type, bound_name, params); 192 105 : } 193 : // Lower bound 194 : { 195 105 : std::string bound_type = "ConstantBounds"; 196 105 : std::string bound_name = var_name + "_lower_bound"; 197 105 : auto params = _factory.getValidParams(bound_type); 198 210 : params.set<AuxVariableName>("variable") = "bounds_dummy"; 199 210 : params.set<NonlinearVariableName>("bounded_variable") = var_name; 200 210 : params.set<MooseEnum>("bound_type") = "lower"; 201 210 : params.set<Real>("bound_value") = -1.0 * getParam<Real>("bound_value"); 202 105 : _problem->addAuxKernel(bound_type, bound_name, params); 203 105 : } 204 : } 205 : } 206 : 207 168 : if (_current_task == "add_bounds_vectors") 208 : { 209 21 : _problem->getNonlinearSystemBase(/*nl_sys_num=*/0) 210 21 : .addVector("lower_bound", false, libMesh::GHOSTED); 211 21 : _problem->getNonlinearSystemBase(/*nl_sys_num=*/0) 212 42 : .addVector("upper_bound", false, libMesh::GHOSTED); 213 : } 214 : 215 : // Add AuxVriable and AuxKernel for Bnds variable 216 168 : addBnds(_op_name_base); 217 273 : }