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 "Shaft.h" 11 : #include "ShaftConnectable.h" 12 : #include "Component1DConnection.h" 13 : 14 : registerMooseObject("ThermalHydraulicsApp", Shaft); 15 : 16 : InputParameters 17 510 : Shaft::validParams() 18 : { 19 510 : InputParameters params = Component::validParams(); 20 1020 : params.addParam<Real>("scaling_factor_omega", 1.0, "Scaling factor for omega [-]"); 21 1020 : params.addParam<Real>("initial_speed", "Initial shaft speed"); 22 1020 : params.addParam<bool>("ad", true, "Use AD version or not"); 23 1020 : params.addRequiredParam<std::vector<std::string>>("connected_components", 24 : "Names of the connected components"); 25 510 : params.addClassDescription("Component that connects torque of turbomachinery components"); 26 510 : return params; 27 0 : } 28 : 29 255 : Shaft::Shaft(const InputParameters & parameters) 30 : : Component(parameters), 31 255 : _scaling_factor_omega(getParam<Real>("scaling_factor_omega")), 32 510 : _omega_var_name(genName(name(), "omega")), 33 765 : _connected_components(getParam<std::vector<std::string>>("connected_components")) 34 : { 35 707 : for (auto & comp_name : _connected_components) 36 452 : addDependency(comp_name); 37 255 : } 38 : 39 : void 40 255 : Shaft::init() 41 : { 42 : Component::init(); 43 : 44 707 : for (const auto & comp_name : _connected_components) 45 : { 46 : if (hasComponentByName<Component>(comp_name)) 47 : { 48 : const Component & c = getComponentByName<Component>(comp_name); 49 452 : const ShaftConnectable & scc = dynamic_cast<const ShaftConnectable &>(c); 50 452 : scc.setShaftName(name()); 51 : } 52 : } 53 255 : } 54 : 55 : void 56 240 : Shaft::check() const 57 : { 58 240 : if (_connected_components.size() == 0) 59 10 : logError("No components are connected to the shaft."); 60 : 61 472 : bool ics_set = getTHMProblem().hasInitialConditionsFromFile() || isParamValid("initial_speed"); 62 240 : if (!ics_set && !_app.isRestarting()) 63 4 : logError("The `initial_speed` parameter is missing."); 64 240 : } 65 : 66 : void 67 243 : Shaft::addVariables() 68 : { 69 243 : getTHMProblem().addSimVariable( 70 243 : true, _omega_var_name, libMesh::FEType(FIRST, SCALAR), _scaling_factor_omega); 71 : 72 486 : if (isParamValid("initial_speed")) 73 681 : getTHMProblem().addConstantScalarIC(_omega_var_name, getParam<Real>("initial_speed")); 74 243 : } 75 : 76 : void 77 243 : Shaft::addMooseObjects() 78 : { 79 : std::vector<UserObjectName> uo_names; 80 : 81 693 : for (const auto & comp_name : _connected_components) 82 : { 83 : const Component & c = getComponentByName<Component>(comp_name); 84 450 : const ShaftConnectable & scc = dynamic_cast<const ShaftConnectable &>(c); 85 900 : uo_names.push_back(scc.getShaftConnectedUserObjectName()); 86 : } 87 : 88 486 : if (getParam<bool>("ad")) 89 : { 90 : { 91 243 : std::string class_name = "ADShaftTimeDerivativeScalarKernel"; 92 243 : InputParameters params = _factory.getValidParams(class_name); 93 486 : params.set<NonlinearVariableName>("variable") = _omega_var_name; 94 243 : params.set<std::vector<UserObjectName>>("uo_names") = {uo_names}; 95 486 : getTHMProblem().addScalarKernel(class_name, genName(name(), "td"), params); 96 243 : } 97 : 98 693 : for (std::size_t i = 0; i < uo_names.size(); i++) 99 : { 100 450 : std::string class_name = "ADShaftComponentTorqueScalarKernel"; 101 450 : InputParameters params = _factory.getValidParams(class_name); 102 900 : params.set<NonlinearVariableName>("variable") = _omega_var_name; 103 450 : params.set<UserObjectName>("shaft_connected_component_uo") = uo_names[i]; 104 450 : getTHMProblem().addScalarKernel(class_name, genName(name(), i, "shaft_speed"), params); 105 450 : } 106 : } 107 : else 108 : { 109 : { 110 0 : std::string class_name = "ShaftTimeDerivativeScalarKernel"; 111 0 : InputParameters params = _factory.getValidParams(class_name); 112 0 : params.set<NonlinearVariableName>("variable") = _omega_var_name; 113 0 : params.set<std::vector<UserObjectName>>("uo_names") = {uo_names}; 114 0 : getTHMProblem().addScalarKernel(class_name, genName(name(), "td"), params); 115 0 : } 116 : 117 0 : for (std::size_t i = 0; i < uo_names.size(); i++) 118 : { 119 0 : std::string class_name = "ShaftComponentTorqueScalarKernel"; 120 0 : InputParameters params = _factory.getValidParams(class_name); 121 0 : params.set<NonlinearVariableName>("variable") = _omega_var_name; 122 0 : params.set<UserObjectName>("shaft_connected_component_uo") = uo_names[i]; 123 0 : getTHMProblem().addScalarKernel(class_name, genName(name(), i, "shaft_speed"), params); 124 0 : } 125 : } 126 243 : } 127 : 128 : VariableName 129 450 : Shaft::getOmegaVariableName() const 130 : { 131 450 : return _omega_var_name; 132 : }