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 "PFCRFFVariablesAction.h" 11 : #include "Factory.h" 12 : #include "FEProblem.h" 13 : #include "Conversion.h" 14 : #include "AddVariableAction.h" 15 : 16 : #include "libmesh/string_to_enum.h" 17 : 18 : registerMooseAction("PhaseFieldApp", PFCRFFVariablesAction, "add_variable"); 19 : 20 : InputParameters 21 33 : PFCRFFVariablesAction::validParams() 22 : { 23 33 : InputParameters params = Action::validParams(); 24 33 : MooseEnum familyEnum = AddVariableAction::getNonlinearVariableFamilies(); 25 33 : params.addClassDescription("Creates the L nonlinear variables for the Cahn-Hilliard equation for " 26 : "the RFF form of the phase field crystal model"); 27 66 : params.addParam<MooseEnum>( 28 : "family", 29 : familyEnum, 30 : "Specifies the family of FE shape functions to use for the L variables"); 31 33 : MooseEnum orderEnum = AddVariableAction::getNonlinearVariableOrders(); 32 66 : params.addParam<MooseEnum>( 33 : "order", 34 : orderEnum, 35 : "Specifies the order of the FE shape function to use for the L variables"); 36 66 : params.addParam<Real>("scaling", 1.0, "Specifies a scaling factor to apply to the L variables"); 37 66 : params.addRequiredParam<unsigned int>( 38 : "num_L", "specifies the number of complex L variables will be solved for"); 39 66 : params.addRequiredParam<std::string>("L_name_base", "Base name for the complex L variables"); 40 66 : params.addParam<std::vector<SubdomainName>>( 41 : "block", {}, "Block restriction for the variables and kernels"); 42 33 : return params; 43 33 : } 44 : 45 33 : PFCRFFVariablesAction::PFCRFFVariablesAction(const InputParameters & params) 46 : : Action(params), 47 33 : _num_L(getParam<unsigned int>("num_L")), 48 99 : _L_name_base(getParam<std::string>("L_name_base")) 49 : { 50 33 : } 51 : 52 : void 53 33 : PFCRFFVariablesAction::act() 54 : { 55 : #ifdef DEBUG 56 : Moose::err << "Inside the PFCRFFVariablesAction Object\n"; 57 : Moose::err << "VariableBase: " << _L_name_base << "\torder: " << getParam<MooseEnum>("order") 58 : << "\tfamily: " << getParam<MooseEnum>("family") << std::endl; 59 : #endif 60 : 61 33 : auto fe_type = AddVariableAction::feType(_pars); 62 33 : auto type = AddVariableAction::variableType(fe_type); 63 33 : auto var_params = _factory.getValidParams(type); 64 : 65 33 : var_params.applySpecificParameters(_pars, {"family", "order", "block"}); 66 99 : var_params.set<std::vector<Real>>("scaling") = {getParam<Real>("scaling")}; 67 : 68 : // Loop through the number of L variables 69 198 : for (unsigned int l = 0; l < _num_L; ++l) 70 : { 71 : // Create L base name 72 165 : std::string L_name = _L_name_base + Moose::stringify(l); 73 : 74 : // Create real L variable 75 165 : const std::string real_name = L_name + "_real"; 76 165 : _problem->addVariable(type, real_name, var_params); 77 : 78 165 : if (l > 0) 79 : { 80 : // Create imaginary L variable IF l > 0 81 132 : std::string imag_name = L_name + "_imag"; 82 132 : _problem->addVariable(type, imag_name, var_params); 83 : } 84 : } 85 66 : }