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