https://mooseframework.inl.gov
Shaft.C
Go to the documentation of this file.
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 
18 {
20  params.addParam<Real>("scaling_factor_omega", 1.0, "Scaling factor for omega [-]");
21  params.addParam<Real>("initial_speed", "Initial shaft speed");
22  params.addParam<bool>("ad", true, "Use AD version or not");
23  params.addRequiredParam<std::vector<std::string>>("connected_components",
24  "Names of the connected components");
25  params.addClassDescription("Component that connects torque of turbomachinery components");
26  return params;
27 }
28 
29 Shaft::Shaft(const InputParameters & parameters)
30  : Component(parameters),
31  _scaling_factor_omega(getParam<Real>("scaling_factor_omega")),
32  _omega_var_name(genName(name(), "omega")),
33  _connected_components(getParam<std::vector<std::string>>("connected_components"))
34 {
35  for (auto & comp_name : _connected_components)
36  addDependency(comp_name);
37 }
38 
39 void
41 {
43 
44  for (const auto & comp_name : _connected_components)
45  {
46  if (hasComponentByName<Component>(comp_name))
47  {
48  const Component & c = getComponentByName<Component>(comp_name);
49  const ShaftConnectable & scc = dynamic_cast<const ShaftConnectable &>(c);
50  scc.setShaftName(name());
51  }
52  }
53 }
54 
55 void
56 Shaft::check() const
57 {
58  if (_connected_components.size() == 0)
59  logError("No components are connected to the shaft.");
60 
61  bool ics_set = getTHMProblem().hasInitialConditionsFromFile() || isParamValid("initial_speed");
62  if (!ics_set && !_app.isRestarting())
63  logError("The `initial_speed` parameter is missing.");
64 }
65 
66 void
68 {
71 
72  if (isParamValid("initial_speed"))
73  getTHMProblem().addConstantScalarIC(_omega_var_name, getParam<Real>("initial_speed"));
74 }
75 
76 void
78 {
79  std::vector<UserObjectName> uo_names;
80 
81  for (const auto & comp_name : _connected_components)
82  {
83  const Component & c = getComponentByName<Component>(comp_name);
84  const ShaftConnectable & scc = dynamic_cast<const ShaftConnectable &>(c);
85  uo_names.push_back(scc.getShaftConnectedUserObjectName());
86  }
87 
88  if (getParam<bool>("ad"))
89  {
90  {
91  std::string class_name = "ADShaftTimeDerivativeScalarKernel";
92  InputParameters params = _factory.getValidParams(class_name);
93  params.set<NonlinearVariableName>("variable") = _omega_var_name;
94  params.set<std::vector<UserObjectName>>("uo_names") = {uo_names};
95  getTHMProblem().addScalarKernel(class_name, genName(name(), "td"), params);
96  }
97 
98  for (std::size_t i = 0; i < uo_names.size(); i++)
99  {
100  std::string class_name = "ADShaftComponentTorqueScalarKernel";
101  InputParameters params = _factory.getValidParams(class_name);
102  params.set<NonlinearVariableName>("variable") = _omega_var_name;
103  params.set<UserObjectName>("shaft_connected_component_uo") = uo_names[i];
104  getTHMProblem().addScalarKernel(class_name, genName(name(), i, "shaft_speed"), params);
105  }
106  }
107  else
108  {
109  {
110  std::string class_name = "ShaftTimeDerivativeScalarKernel";
111  InputParameters params = _factory.getValidParams(class_name);
112  params.set<NonlinearVariableName>("variable") = _omega_var_name;
113  params.set<std::vector<UserObjectName>>("uo_names") = {uo_names};
114  getTHMProblem().addScalarKernel(class_name, genName(name(), "td"), params);
115  }
116 
117  for (std::size_t i = 0; i < uo_names.size(); i++)
118  {
119  std::string class_name = "ShaftComponentTorqueScalarKernel";
120  InputParameters params = _factory.getValidParams(class_name);
121  params.set<NonlinearVariableName>("variable") = _omega_var_name;
122  params.set<UserObjectName>("shaft_connected_component_uo") = uo_names[i];
123  getTHMProblem().addScalarKernel(class_name, genName(name(), i, "shaft_speed"), params);
124  }
125  }
126 }
127 
128 VariableName
130 {
131  return _omega_var_name;
132 }
virtual void addVariables() override
Definition: Shaft.C:67
std::string genName(const std::string &prefix, unsigned int id, const std::string &suffix="") const
Build a name from a prefix, number and possible suffix.
SCALAR
const VariableName _omega_var_name
Name of the omega variable.
Definition: Shaft.h:33
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
THMProblem & getTHMProblem() const
Gets the THM problem.
Definition: Component.C:135
void addDependency(const std::string &dependency)
Adds a component name to the list of dependencies.
Definition: Component.C:129
FIRST
const Real & _scaling_factor_omega
scaling factor for scalar variable omega
Definition: Shaft.h:31
T & set(const std::string &name, bool quiet_mode=false)
InputParameters getValidParams(const std::string &name) const
registerMooseObject("ThermalHydraulicsApp", Shaft)
bool isRestarting() const
static InputParameters validParams()
Definition: Component.C:18
virtual const std::string & name() const
void addRequiredParam(const std::string &name, const std::string &doc_string)
void logError(Args &&... args) const
Logs an error.
Definition: Component.h:215
bool isParamValid(const std::string &name) const
static InputParameters validParams()
Definition: Shaft.C:17
Component that connects torque of turbomachinery components.
Definition: Shaft.h:17
void addSimVariable(bool nl, const VariableName &name, libMesh::FEType fe_type, Real scaling_factor=1.0)
Queues a variable of type MooseVariableScalar to be added to the nonlinear or aux system...
Definition: Simulation.C:271
virtual void check() const override
Check the component integrity.
Definition: Shaft.C:56
const std::string name
Definition: Setup.h:20
virtual void init()
Initializes the component.
Definition: Component.h:290
const std::vector< std::string > & _connected_components
Components connected to this shaft.
Definition: Shaft.h:35
Base class for THM components.
Definition: Component.h:27
void addConstantScalarIC(const VariableName &var_name, Real value)
Definition: Simulation.C:552
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Shaft(const InputParameters &params)
Definition: Shaft.C:29
MooseApp & _app
virtual VariableName getOmegaVariableName() const
Definition: Shaft.C:129
Factory & _factory
The Factory associated with the MooseApp.
Definition: Component.h:446
Interface class for components that connect to a shaft.
virtual void setShaftName(const std::string &name) const
void addClassDescription(const std::string &doc_string)
virtual void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
virtual void addMooseObjects() override
Definition: Shaft.C:77
virtual void init() override
Initializes the component.
Definition: Shaft.C:40
bool hasInitialConditionsFromFile() const
Are initial conditions specified from a file.
Definition: Simulation.C:1070