GRINS-0.6.0
averaged_turbine_base.C
Go to the documentation of this file.
1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // GRINS - General Reacting Incompressible Navier-Stokes
5 //
6 // Copyright (C) 2014-2015 Paul T. Bauman, Roy H. Stogner
7 // Copyright (C) 2010-2013 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA 02110-1301 USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 
26 // This class
28 
29 // GRINS
31 
32 // libMesh
33 #include "libmesh/parsed_function.h"
34 #include "libmesh/zero_function.h"
35 
36 namespace GRINS
37 {
38 
39  template<class Mu>
40  AveragedTurbineBase<Mu>::AveragedTurbineBase( const std::string& physics_name, const GetPot& input )
41  : IncompressibleNavierStokesBase<Mu>(physics_name,
42  incompressible_navier_stokes, /* "core" Physics name */
43  input)
44  {
45  this->read_input_options(input);
46 
47  return;
48  }
49 
50  template<class Mu>
52  {
53  return;
54  }
55 
56  template<class Mu>
57  void AveragedTurbineBase<Mu>::init_variables( libMesh::FEMSystem* system )
58  {
59  this->_fan_speed_var = system->add_variable(_fan_speed_var_name,
60  libMesh::FIRST,
61  libMesh::SCALAR);
62 
64  }
65 
66  template<class Mu>
67  void AveragedTurbineBase<Mu>::set_time_evolving_vars( libMesh::FEMSystem* system )
68  {
69  system->time_evolving(this->fan_speed_var());
70 
72  }
73 
74 
75  template<class Mu>
76  void AveragedTurbineBase<Mu>::read_input_options( const GetPot& input )
77  {
78  std::string base_function =
79  input("Physics/"+averaged_turbine+"/base_velocity",
80  std::string("0"));
81 
82  if (base_function == "0")
83  libmesh_error_msg("Error! Zero AveragedTurbine specified!" <<
84  std::endl);
85 
86  if (base_function == "0")
87  this->base_velocity_function.reset
88  (new libMesh::ZeroFunction<libMesh::Number>());
89  else
90  this->base_velocity_function.reset
91  (new libMesh::ParsedFunction<libMesh::Number>(base_function));
92 
93  std::string vertical_function =
94  input("Physics/"+averaged_turbine+"/local_vertical",
95  std::string("0"));
96 
97  if (vertical_function == "0")
98  libmesh_error_msg("Warning! Zero LocalVertical specified!" <<
99  std::endl);
100 
101  this->local_vertical_function.reset
102  (new libMesh::ParsedFunction<libMesh::Number>(vertical_function));
103 
104  std::string lift_function_string =
105  input("Physics/"+averaged_turbine+"/lift",
106  std::string("0"));
107 
108  if (lift_function_string == "0")
109  std::cout << "Warning! Zero lift function specified!" << std::endl;
110 
111  this->lift_function.reset
112  (new libMesh::ParsedFunction<libMesh::Number>(lift_function_string));
113 
114  std::string drag_function_string =
115  input("Physics/"+averaged_turbine+"/drag",
116  std::string("0"));
117 
118  if (drag_function_string == "0")
119  std::cout << "Warning! Zero drag function specified!" << std::endl;
120 
121  this->drag_function.reset
122  (new libMesh::ParsedFunction<libMesh::Number>(drag_function_string));
123 
124  std::string chord_function_string =
125  input("Physics/"+averaged_turbine+"/chord_length",
126  std::string("0"));
127 
128  if (chord_function_string == "0")
129  libmesh_error_msg("Warning! Zero chord function specified!" <<
130  std::endl);
131 
132  this->chord_function.reset
133  (new libMesh::ParsedFunction<libMesh::Number>(chord_function_string));
134 
135  std::string area_function_string =
136  input("Physics/"+averaged_turbine+"/area_swept",
137  std::string("0"));
138 
139  if (area_function_string == "0")
140  libmesh_error_msg("Warning! Zero area_swept_function specified!" <<
141  std::endl);
142 
143  this->area_swept_function.reset
144  (new libMesh::ParsedFunction<libMesh::Number>(area_function_string));
145 
146  std::string aoa_function_string =
147  input("Physics/"+averaged_turbine+"/angle_of_attack",
148  std::string("00000"));
149 
150  if (aoa_function_string == "00000")
151  libmesh_error_msg("Warning! No angle-of-attack specified!" <<
152  std::endl);
153 
154  this->aoa_function.reset
155  (new libMesh::ParsedFunction<libMesh::Number>(aoa_function_string));
156 
157  std::string torque_function_string =
158  input("Physics/"+averaged_turbine+"/torque",
159  std::string("0"));
160 
161  if (torque_function_string == "0")
162  std::cout << "Warning! Zero torque function specified!" << std::endl;
163 
164  this->torque_function.reset
165  (new libMesh::ParsedFunction<libMesh::Number>(torque_function_string));
166 
167  this->set_parameter
168  (this->moment_of_inertia, input,
169  "Physics/"+averaged_turbine+"/moment_of_inertia",
170  libMesh::Number(0));
171 
172  if (!moment_of_inertia)
173  libmesh_error_msg(
174  "Error! Zero AveragedTurbine moment of inertia specified!" <<
175  std::endl);
176 
177  this->set_parameter
178  (this->initial_speed, input,
179  "Physics/"+averaged_turbine+"/initial_speed",
180  libMesh::Number(0));
181 
182  this->_fan_speed_var_name = input("Physics/VariableNames/fan_speed",
184 
185  }
186 
187  template<class Mu>
189  ( const libMesh::Point& point,
190  const libMesh::Real time,
191  const libMesh::NumberVectorValue& U,
192  libMesh::Number s,
193  libMesh::NumberVectorValue& U_B_1,
194  libMesh::NumberVectorValue& F,
195  libMesh::NumberTensorValue *dFdU,
196  libMesh::NumberVectorValue *dFds)
197  {
198  // Find base velocity of moving fan at this point
199  libmesh_assert(base_velocity_function.get());
200 
201  libMesh::DenseVector<libMesh::Number> output_vec(3);
202 
203  (*base_velocity_function)(point, time,
204  output_vec);
205 
206  U_B_1(0) = output_vec(0);
207  U_B_1(1) = output_vec(1);
208  U_B_1(2) = output_vec(2);
209 
210  const libMesh::NumberVectorValue U_B = U_B_1 * s;
211 
212  const libMesh::Number U_B_size = U_B.size();
213 
214  // If there's no base velocity there's no fan
215  if (!U_B_size)
216  return false;
217 
218  // Normal in fan velocity direction
219  const libMesh::NumberVectorValue N_B =
220  libMesh::NumberVectorValue(U_B/U_B_size);
221 
222  (*local_vertical_function)(point, time,
223  output_vec);
224 
225  // Normal in fan vertical direction
226  const libMesh::NumberVectorValue N_V(output_vec(0),
227  output_vec(1),
228  output_vec(2));
229 
230  // Normal in radial direction (or opposite radial direction,
231  // for fans turning clockwise!)
232  const libMesh::NumberVectorValue N_R = N_B.cross(N_V);
233 
234  // Fan-wing-plane component of local relative velocity
235  const libMesh::NumberVectorValue U_P = U - (U*N_R)*N_R - U_B;
236 
237  const libMesh::Number U_P_size = U_P.size();
238 
239  // If there's no flow in the fan's frame of reference, there's no
240  // lift or drag. FIXME - should we account for drag in the
241  // out-of-plane direction?
242  if (!U_P_size)
243  return false;
244 
245  // Direction opposing drag
246  const libMesh::NumberVectorValue N_drag =
247  libMesh::NumberVectorValue(-U_P/U_P_size);
248 
249  // Direction opposing lift
250  const libMesh::NumberVectorValue N_lift = N_drag.cross(N_R);
251 
252  // "Forward" velocity
253  const libMesh::Number u_fwd = -(U_P * N_B);
254 
255  // "Upward" velocity
256  const libMesh::Number u_up = U_P * N_V;
257 
258  // If there's no forward or upward velocity we should have already
259  // returned false
260  libmesh_assert (u_up || u_fwd);
261 
262  // Angle WRT fan velocity direction
263  const libMesh::Number part_angle = std::atan2(u_up, u_fwd);
264 
265  // Angle WRT fan chord
266  const libMesh::Number angle = part_angle +
267  (*aoa_function)(point, time);
268 
269  const libMesh::Number C_lift = (*lift_function)(point, angle);
270  const libMesh::Number C_drag = (*drag_function)(point, angle);
271 
272  const libMesh::Number chord = (*chord_function)(point, time);
273  const libMesh::Number area = (*area_swept_function)(point, time);
274 
275  const libMesh::Number v_sq = U_P*U_P;
276 
277  const libMesh::Number LDfactor = 0.5 * this->_rho * v_sq * chord / area;
278  const libMesh::Number lift = C_lift * LDfactor;
279  const libMesh::Number drag = C_drag * LDfactor;
280 
281  // Force
282  F = lift * N_lift + drag * N_drag;
283 
284  if (dFdU)
285  {
286  const libMesh::NumberVectorValue LDderivfactor =
287  (N_lift*C_lift+N_drag*C_drag) *
288  this->_rho * chord / area;
289 
290  const libMesh::Number sfactor = -(U_P*U_B_1);
291 
292  (*dFds) = LDderivfactor * sfactor;
293 
294  for (unsigned int i=0; i != 3; ++i)
295  for (unsigned int j=0; j != 3; ++j)
296  (*dFdU)(i,j) = LDderivfactor(i) * U_P(j);
297  }
298 
299  return true;
300  }
301 
302 } // namespace GRINS
303 
304 // Instantiate
305 INSTANTIATE_INC_NS_SUBCLASS(AveragedTurbineBase);
virtual void set_time_evolving_vars(libMesh::FEMSystem *system)
Sets turbine_speed and velocity variables to be time-evolving.
virtual void init_variables(libMesh::FEMSystem *system)
Initialization of variables.
const PhysicsName incompressible_navier_stokes
Physics class for Incompressible Navier-Stokes.
const std::string fan_speed_var_name_default
fan speed
const PhysicsName averaged_turbine
INSTANTIATE_INC_NS_SUBCLASS(AveragedTurbineBase)
virtual void init_variables(libMesh::FEMSystem *system)
Initialization of Navier-Stokes variables.
GRINS namespace.
virtual void set_time_evolving_vars(libMesh::FEMSystem *system)
Sets velocity variables to be time-evolving.
bool compute_force(const libMesh::Point &point, const libMesh::Real time, const libMesh::NumberVectorValue &U, libMesh::Number s, libMesh::NumberVectorValue &U_B_1, libMesh::NumberVectorValue &F, libMesh::NumberTensorValue *dFdU=NULL, libMesh::NumberVectorValue *dFds=NULL)
virtual void read_input_options(const GetPot &input)
Read options from GetPot input file.

Generated on Mon Jun 22 2015 21:32:20 for GRINS-0.6.0 by  doxygen 1.8.9.1