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