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 "PolycrystalVariablesAction.h" 11 : #include "AddVariableAction.h" 12 : #include "Conversion.h" 13 : #include "Factory.h" 14 : #include "FEProblem.h" 15 : #include "NonlinearSystemBase.h" 16 : 17 : #include "libmesh/string_to_enum.h" 18 : 19 : registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "add_variable"); 20 : registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "copy_nodal_vars"); 21 : registerMooseAction("PhaseFieldApp", PolycrystalVariablesAction, "check_copy_nodal_vars"); 22 : 23 : InputParameters 24 1240 : PolycrystalVariablesAction::validParams() 25 : { 26 1240 : InputParameters params = Action::validParams(); 27 1240 : params.addClassDescription("Set up order parameter variables for a polycrystal simulation"); 28 : // Get MooseEnums for the possible order/family options for this variable 29 1240 : MooseEnum families(AddVariableAction::getNonlinearVariableFamilies()); 30 1240 : MooseEnum orders(AddVariableAction::getNonlinearVariableOrders()); 31 2480 : params.addParam<MooseEnum>("family", 32 : families, 33 : "Specifies the family of FE " 34 : "shape function to use for the order parameters"); 35 2480 : params.addParam<MooseEnum>("order", 36 : orders, 37 : "Specifies the order of the FE " 38 : "shape function to use for the order parameters"); 39 2480 : params.addParam<bool>( 40 : "initial_from_file", 41 2480 : false, 42 : "Take the initial condition of all polycrystal variables from the mesh file"); 43 2480 : params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to this variable"); 44 2480 : params.addRequiredParam<unsigned int>("op_num", 45 : "specifies the number of order parameters to create"); 46 2480 : params.addRequiredParam<std::string>("var_name_base", "specifies the base name of the variables"); 47 2480 : params.addParam<std::vector<SubdomainName>>( 48 : "block", {}, "Block restriction for the variables and kernels"); 49 1240 : return params; 50 1240 : } 51 : 52 957 : PolycrystalVariablesAction::PolycrystalVariablesAction(const InputParameters & params) 53 : : Action(params), 54 957 : _op_num(getParam<unsigned int>("op_num")), 55 2871 : _var_name_base(getParam<std::string>("var_name_base")) 56 : { 57 957 : } 58 : 59 : void 60 2871 : PolycrystalVariablesAction::act() 61 : { 62 : // take initial values from file? 63 5742 : bool initial_from_file = getParam<bool>("initial_from_file"); 64 : 65 : // Loop through the number of order parameters 66 19206 : for (unsigned int op = 0; op < _op_num; op++) 67 : { 68 : // Create variable names 69 16335 : std::string var_name = _var_name_base + Moose::stringify(op); 70 : 71 : // Add the variable 72 16335 : if (_current_task == "add_variable") 73 : { 74 5445 : auto fe_type = AddVariableAction::feType(_pars); 75 5445 : auto type = AddVariableAction::variableType(fe_type); 76 5445 : auto var_params = _factory.getValidParams(type); 77 : 78 5445 : var_params.applySpecificParameters(_pars, {"order", "family", "block"}); 79 5445 : var_params.set<std::vector<Real>>("scaling") = {_pars.get<Real>("scaling")}; 80 5445 : _problem->addVariable(type, var_name, var_params); 81 5445 : } 82 : 83 : // Setup initial from file if requested 84 16335 : if (initial_from_file) 85 : { 86 132 : if (_current_task == "check_copy_nodal_vars") 87 44 : _app.setExodusFileRestart(true); 88 : 89 132 : if (_current_task == "copy_nodal_vars") 90 : { 91 44 : auto * system = &_problem->getNonlinearSystemBase(/*nl_sys_num=*/0); 92 88 : system->addVariableToCopy(var_name, var_name, "LATEST"); 93 : } 94 : } 95 : } 96 2871 : }