JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGWinds.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGWinds.cpp
4  Author: Jon Berndt, Tony Peden, Andreas Gaeb
5  Date started: Extracted from FGAtmosphere, which originated in 1998
6  5/2011
7  Purpose: Models winds, gusts, turbulence, and other atmospheric disturbances
8  Called by: FGFDMExec
9 
10  ------------- Copyright (C) 2011 Jon S. Berndt (jon@jsbsim.org) -------------
11 
12  This program is free software; you can redistribute it and/or modify it under
13  the terms of the GNU Lesser General Public License as published by the Free Software
14  Foundation; either version 2 of the License, or (at your option) any later
15  version.
16 
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
20  details.
21 
22  You should have received a copy of the GNU Lesser General Public License along with
23  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24  Place - Suite 330, Boston, MA 02111-1307, USA.
25 
26  Further information about the GNU Lesser General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28 
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31 
32 HISTORY
33 --------------------------------------------------------------------------------
34 
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 COMMENTS, REFERENCES, and NOTES
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 [1] Anderson, John D. "Introduction to Flight, Third Edition", McGraw-Hill,
39  1989, ISBN 0-07-001641-0
40 
41 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 INCLUDES
43 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 
45 #include <iostream>
46 #include <cstdlib>
47 #include "FGWinds.h"
48 #include "FGFDMExec.h"
49 
50 using namespace std;
51 
52 namespace JSBSim {
53 
54 IDENT(IdSrc,"$Id: FGWinds.cpp,v 1.15 2015/02/27 20:49:36 bcoconni Exp $");
55 IDENT(IdHdr,ID_WINDS);
56 
57 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58 CLASS IMPLEMENTATION
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
60 
61 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62 // square a value, but preserve the original sign
63 
64 /*
65 static inline double square_signed (double value)
66 {
67  if (value < 0)
68  return value * value * -1;
69  else
70  return value * value;
71 }
72 */
73 
75 static inline double sqr(double x) { return x*x; }
76 
77 FGWinds::FGWinds(FGFDMExec* fdmex) : FGModel(fdmex)
78 {
79  Name = "FGWinds";
80 
81  MagnitudedAccelDt = MagnitudeAccel = Magnitude = TurbDirection = 0.0;
82  SetTurbType( ttMilspec );
83  TurbGain = 1.0;
84  TurbRate = 10.0;
85  Rhythmicity = 0.1;
86  spike = target_time = strength = 0.0;
87  wind_from_clockwise = 0.0;
88  psiw = 0.0;
89 
90  vGustNED.InitMatrix();
91  vTurbulenceNED.InitMatrix();
92  vCosineGust.InitMatrix();
93 
94  // Milspec turbulence model
95  windspeed_at_20ft = 0.;
96  probability_of_exceedence_index = 0;
97  POE_Table = new FGTable(7,12);
98  // this is Figure 7 from p. 49 of MIL-F-8785C
99  // rows: probability of exceedance curve index, cols: altitude in ft
100  *POE_Table
101  << 500.0 << 1750.0 << 3750.0 << 7500.0 << 15000.0 << 25000.0 << 35000.0 << 45000.0 << 55000.0 << 65000.0 << 75000.0 << 80000.0
102  << 1 << 3.2 << 2.2 << 1.5 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0
103  << 2 << 4.2 << 3.6 << 3.3 << 1.6 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0
104  << 3 << 6.6 << 6.9 << 7.4 << 6.7 << 4.6 << 2.7 << 0.4 << 0.0 << 0.0 << 0.0 << 0.0 << 0.0
105  << 4 << 8.6 << 9.6 << 10.6 << 10.1 << 8.0 << 6.6 << 5.0 << 4.2 << 2.7 << 0.0 << 0.0 << 0.0
106  << 5 << 11.8 << 13.0 << 16.0 << 15.1 << 11.6 << 9.7 << 8.1 << 8.2 << 7.9 << 4.9 << 3.2 << 2.1
107  << 6 << 15.6 << 17.6 << 23.0 << 23.6 << 22.1 << 20.0 << 16.0 << 15.1 << 12.1 << 7.9 << 6.2 << 5.1
108  << 7 << 18.7 << 21.5 << 28.4 << 30.2 << 30.7 << 31.0 << 25.2 << 23.1 << 17.5 << 10.7 << 8.4 << 7.2;
109 
110  bind();
111  Debug(0);
112 }
113 
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 
117 {
118  delete(POE_Table);
119  Debug(1);
120 }
121 
122 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 
124 bool FGWinds::InitModel(void)
125 {
126  if (!FGModel::InitModel()) return false;
127 
128  psiw = 0.0;
129 
130  vGustNED.InitMatrix();
131  vTurbulenceNED.InitMatrix();
132  vCosineGust.InitMatrix();
133 
134  oneMinusCosineGust.gustProfile.Running = false;
135  oneMinusCosineGust.gustProfile.elapsedTime = 0.0;
136 
137  return true;
138 }
139 
140 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 
142 bool FGWinds::Run(bool Holding)
143 {
144  if (FGModel::Run(Holding)) return true;
145  if (Holding) return false;
146 
147  if (turbType != ttNone) Turbulence(in.AltitudeASL);
148  if (oneMinusCosineGust.gustProfile.Running) CosineGust();
149 
150  vTotalWindNED = vWindNED + vGustNED + vCosineGust + vTurbulenceNED;
151 
152  // psiw (Wind heading) is the direction the wind is blowing towards
153  if (vWindNED(eX) != 0.0) psiw = atan2( vWindNED(eY), vWindNED(eX) );
154  if (psiw < 0) psiw += 2*M_PI;
155 
156  Debug(2);
157  return false;
158 }
159 
160 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
161 //
162 // psi is the angle that the wind is blowing *towards*
163 
164 void FGWinds::SetWindspeed(double speed)
165 {
166  if (vWindNED.Magnitude() == 0.0) {
167  psiw = 0.0;
168  vWindNED(eNorth) = speed;
169  } else {
170  vWindNED(eNorth) = speed * cos(psiw);
171  vWindNED(eEast) = speed * sin(psiw);
172  vWindNED(eDown) = 0.0;
173  }
174 }
175 
176 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 
178 double FGWinds::GetWindspeed(void) const
179 {
180  return vWindNED.Magnitude();
181 }
182 
183 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184 //
185 // psi is the angle that the wind is blowing *towards*
186 
187 void FGWinds::SetWindPsi(double dir)
188 {
189  double mag = GetWindspeed();
190  psiw = dir;
191  SetWindspeed(mag);
192 }
193 
194 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
195 
196 void FGWinds::Turbulence(double h)
197 {
198  switch (turbType) {
199 
200  case ttCulp: {
201 
202  vTurbPQR(eP) = wind_from_clockwise;
203  if (TurbGain == 0.0) return;
204 
205  // keep the inputs within allowable limts for this model
206  if (TurbGain < 0.0) TurbGain = 0.0;
207  if (TurbGain > 1.0) TurbGain = 1.0;
208  if (TurbRate < 0.0) TurbRate = 0.0;
209  if (TurbRate > 30.0) TurbRate = 30.0;
210  if (Rhythmicity < 0.0) Rhythmicity = 0.0;
211  if (Rhythmicity > 1.0) Rhythmicity = 1.0;
212 
213  // generate a sine wave corresponding to turbulence rate in hertz
214  double time = FDMExec->GetSimTime();
215  double sinewave = sin( time * TurbRate * 6.283185307 );
216 
217  double random = 0.0;
218  if (target_time == 0.0) {
219  strength = random = 1 - 2.0*(double(rand())/double(RAND_MAX));
220  target_time = time + 0.71 + (random * 0.5);
221  }
222  if (time > target_time) {
223  spike = 1.0;
224  target_time = 0.0;
225  }
226 
227  // max vertical wind speed in fps, corresponds to TurbGain = 1.0
228  double max_vs = 40;
229 
230  vTurbulenceNED.InitMatrix();
231  double delta = strength * max_vs * TurbGain * (1-Rhythmicity) * spike;
232 
233  // Vertical component of turbulence.
234  vTurbulenceNED(eDown) = sinewave * max_vs * TurbGain * Rhythmicity;
235  vTurbulenceNED(eDown)+= delta;
236  if (in.DistanceAGL/in.wingspan < 3.0)
237  vTurbulenceNED(eDown) *= in.DistanceAGL/in.wingspan * 0.3333;
238 
239  // Yaw component of turbulence.
240  vTurbulenceNED(eNorth) = sin( delta * 3.0 );
241  vTurbulenceNED(eEast) = cos( delta * 3.0 );
242 
243  // Roll component of turbulence. Clockwise vortex causes left roll.
244  vTurbPQR(eP) += delta * 0.04;
245 
246  spike = spike * 0.9;
247  break;
248  }
249  case ttMilspec:
250  case ttTustin: {
251 
252  // an index of zero means turbulence is disabled
253  // airspeed occurs as divisor in the code below
254  if (probability_of_exceedence_index == 0 || in.V == 0) {
255  vTurbulenceNED(eNorth) = vTurbulenceNED(eEast) = vTurbulenceNED(eDown) = 0.0;
256  vTurbPQR(eP) = vTurbPQR(eQ) = vTurbPQR(eR) = 0.0;
257  return;
258  }
259 
260  // Turbulence model according to MIL-F-8785C (Flying Qualities of Piloted Aircraft)
261  double b_w = in.wingspan, L_u, L_w, sig_u, sig_w;
262 
263  if (b_w == 0.) b_w = 30.;
264 
265  // clip height functions at 10 ft
266  if (h <= 10.) h = 10;
267 
268  // Scale lengths L and amplitudes sigma as function of height
269  if (h <= 1000) {
270  L_u = h/pow(0.177 + 0.000823*h, 1.2); // MIL-F-8785c, Fig. 10, p. 55
271  L_w = h;
272  sig_w = 0.1*windspeed_at_20ft;
273  sig_u = sig_w/pow(0.177 + 0.000823*h, 0.4); // MIL-F-8785c, Fig. 11, p. 56
274  } else if (h <= 2000) {
275  // linear interpolation between low altitude and high altitude models
276  L_u = L_w = 1000 + (h-1000.)/1000.*750.;
277  sig_u = sig_w = 0.1*windspeed_at_20ft
278  + (h-1000.)/1000.*(POE_Table->GetValue(probability_of_exceedence_index, h) - 0.1*windspeed_at_20ft);
279  } else {
280  L_u = L_w = 1750.; // MIL-F-8785c, Sec. 3.7.2.1, p. 48
281  sig_u = sig_w = POE_Table->GetValue(probability_of_exceedence_index, h);
282  }
283 
284  // keep values from last timesteps
285  // TODO maybe use deque?
286  static double
287  xi_u_km1 = 0, nu_u_km1 = 0,
288  xi_v_km1 = 0, xi_v_km2 = 0, nu_v_km1 = 0, nu_v_km2 = 0,
289  xi_w_km1 = 0, xi_w_km2 = 0, nu_w_km1 = 0, nu_w_km2 = 0,
290  xi_p_km1 = 0, nu_p_km1 = 0,
291  xi_q_km1 = 0, xi_r_km1 = 0;
292 
293 
294  double
295  T_V = in.totalDeltaT, // for compatibility of nomenclature
296  sig_p = 1.9/sqrt(L_w*b_w)*sig_w, // Yeager1998, eq. (8)
297  //sig_q = sqrt(M_PI/2/L_w/b_w), // eq. (14)
298  //sig_r = sqrt(2*M_PI/3/L_w/b_w), // eq. (17)
299  L_p = sqrt(L_w*b_w)/2.6, // eq. (10)
300  tau_u = L_u/in.V, // eq. (6)
301  tau_w = L_w/in.V, // eq. (3)
302  tau_p = L_p/in.V, // eq. (9)
303  tau_q = 4*b_w/M_PI/in.V, // eq. (13)
304  tau_r =3*b_w/M_PI/in.V, // eq. (17)
305  nu_u = GaussianRandomNumber(),
306  nu_v = GaussianRandomNumber(),
307  nu_w = GaussianRandomNumber(),
308  nu_p = GaussianRandomNumber(),
309  xi_u=0, xi_v=0, xi_w=0, xi_p=0, xi_q=0, xi_r=0;
310 
311  // values of turbulence NED velocities
312 
313  if (turbType == ttTustin) {
314  // the following is the Tustin formulation of Yeager's report
315  double
316  omega_w = in.V/L_w, // hidden in nomenclature p. 3
317  omega_v = in.V/L_u, // this is defined nowhere
318  C_BL = 1/tau_u/tan(T_V/2/tau_u), // eq. (19)
319  C_BLp = 1/tau_p/tan(T_V/2/tau_p), // eq. (22)
320  C_BLq = 1/tau_q/tan(T_V/2/tau_q), // eq. (24)
321  C_BLr = 1/tau_r/tan(T_V/2/tau_r); // eq. (26)
322 
323  // all values calculated so far are strictly positive, except for
324  // the random numbers nu_*. This means that in the code below, all
325  // divisors are strictly positive, too, and no floating point
326  // exception should occur.
327  xi_u = -(1 - C_BL*tau_u)/(1 + C_BL*tau_u)*xi_u_km1
328  + sig_u*sqrt(2*tau_u/T_V)/(1 + C_BL*tau_u)*(nu_u + nu_u_km1); // eq. (18)
329  xi_v = -2*(sqr(omega_v) - sqr(C_BL))/sqr(omega_v + C_BL)*xi_v_km1
330  - sqr(omega_v - C_BL)/sqr(omega_v + C_BL) * xi_v_km2
331  + sig_u*sqrt(3*omega_v/T_V)/sqr(omega_v + C_BL)*(
332  (C_BL + omega_v/sqrt(3.))*nu_v
333  + 2/sqrt(3.)*omega_v*nu_v_km1
334  + (omega_v/sqrt(3.) - C_BL)*nu_v_km2); // eq. (20) for v
335  xi_w = -2*(sqr(omega_w) - sqr(C_BL))/sqr(omega_w + C_BL)*xi_w_km1
336  - sqr(omega_w - C_BL)/sqr(omega_w + C_BL) * xi_w_km2
337  + sig_w*sqrt(3*omega_w/T_V)/sqr(omega_w + C_BL)*(
338  (C_BL + omega_w/sqrt(3.))*nu_w
339  + 2/sqrt(3.)*omega_w*nu_w_km1
340  + (omega_w/sqrt(3.) - C_BL)*nu_w_km2); // eq. (20) for w
341  xi_p = -(1 - C_BLp*tau_p)/(1 + C_BLp*tau_p)*xi_p_km1
342  + sig_p*sqrt(2*tau_p/T_V)/(1 + C_BLp*tau_p) * (nu_p + nu_p_km1); // eq. (21)
343  xi_q = -(1 - 4*b_w*C_BLq/M_PI/in.V)/(1 + 4*b_w*C_BLq/M_PI/in.V) * xi_q_km1
344  + C_BLq/in.V/(1 + 4*b_w*C_BLq/M_PI/in.V) * (xi_w - xi_w_km1); // eq. (23)
345  xi_r = - (1 - 3*b_w*C_BLr/M_PI/in.V)/(1 + 3*b_w*C_BLr/M_PI/in.V) * xi_r_km1
346  + C_BLr/in.V/(1 + 3*b_w*C_BLr/M_PI/in.V) * (xi_v - xi_v_km1); // eq. (25)
347 
348  } else if (turbType == ttMilspec) {
349  // the following is the MIL-STD-1797A formulation
350  // as cited in Yeager's report
351  xi_u = (1 - T_V/tau_u) *xi_u_km1 + sig_u*sqrt(2*T_V/tau_u)*nu_u; // eq. (30)
352  xi_v = (1 - 2*T_V/tau_u)*xi_v_km1 + sig_u*sqrt(4*T_V/tau_u)*nu_v; // eq. (31)
353  xi_w = (1 - 2*T_V/tau_w)*xi_w_km1 + sig_w*sqrt(4*T_V/tau_w)*nu_w; // eq. (32)
354  xi_p = (1 - T_V/tau_p) *xi_p_km1 + sig_p*sqrt(2*T_V/tau_p)*nu_p; // eq. (33)
355  xi_q = (1 - T_V/tau_q) *xi_q_km1 + M_PI/4/b_w*(xi_w - xi_w_km1); // eq. (34)
356  xi_r = (1 - T_V/tau_r) *xi_r_km1 + M_PI/3/b_w*(xi_v - xi_v_km1); // eq. (35)
357  }
358 
359  // rotate by wind azimuth and assign the velocities
360  double cospsi = cos(psiw), sinpsi = sin(psiw);
361  vTurbulenceNED(eNorth) = cospsi*xi_u + sinpsi*xi_v;
362  vTurbulenceNED(eEast) = -sinpsi*xi_u + cospsi*xi_v;
363  vTurbulenceNED(eDown) = xi_w;
364 
365  vTurbPQR(eP) = cospsi*xi_p + sinpsi*xi_q;
366  vTurbPQR(eQ) = -sinpsi*xi_p + cospsi*xi_q;
367  vTurbPQR(eR) = xi_r;
368 
369  // vTurbPQR is in the body fixed frame, not NED
370  vTurbPQR = in.Tl2b*vTurbPQR;
371 
372  // hand on the values for the next timestep
373  xi_u_km1 = xi_u; nu_u_km1 = nu_u;
374  xi_v_km2 = xi_v_km1; xi_v_km1 = xi_v; nu_v_km2 = nu_v_km1; nu_v_km1 = nu_v;
375  xi_w_km2 = xi_w_km1; xi_w_km1 = xi_w; nu_w_km2 = nu_w_km1; nu_w_km1 = nu_w;
376  xi_p_km1 = xi_p; nu_p_km1 = nu_p;
377  xi_q_km1 = xi_q;
378  xi_r_km1 = xi_r;
379 
380  }
381  default:
382  break;
383  }
384 
385  TurbDirection = atan2( vTurbulenceNED(eEast), vTurbulenceNED(eNorth))*radtodeg;
386 
387 }
388 
389 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
390 
391 double FGWinds::CosineGustProfile(double startDuration, double steadyDuration, double endDuration, double elapsedTime)
392 {
393  double factor = 0.0;
394  if (elapsedTime >= 0 && elapsedTime <= startDuration) {
395  factor = (1.0 - cos(M_PI*elapsedTime/startDuration))/2.0;
396  } else if (elapsedTime > startDuration && (elapsedTime <= (startDuration + steadyDuration))) {
397  factor = 1.0;
398  } else if (elapsedTime > (startDuration + steadyDuration) && elapsedTime <= (startDuration + steadyDuration + endDuration)) {
399  factor = (1-cos(M_PI*(1-(elapsedTime-(startDuration + steadyDuration))/endDuration)))/2.0;
400  } else {
401  factor = 0.0;
402  }
403 
404  return factor;
405 }
406 
407 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
408 
409 void FGWinds::CosineGust()
410 {
411  struct OneMinusCosineProfile& profile = oneMinusCosineGust.gustProfile;
412 
413  double factor = CosineGustProfile( profile.startupDuration,
414  profile.steadyDuration,
415  profile.endDuration,
416  profile.elapsedTime);
417  // Normalize the gust wind vector
418  oneMinusCosineGust.vWind.Normalize();
419 
420  if (oneMinusCosineGust.vWindTransformed.Magnitude() == 0.0) {
421  switch (oneMinusCosineGust.gustFrame) {
422  case gfBody:
423  oneMinusCosineGust.vWindTransformed = in.Tl2b.Inverse() * oneMinusCosineGust.vWind;
424  break;
425  case gfWind:
426  oneMinusCosineGust.vWindTransformed = in.Tl2b.Inverse() * in.Tw2b * oneMinusCosineGust.vWind;
427  break;
428  case gfLocal:
429  // this is the native frame - and the default.
430  oneMinusCosineGust.vWindTransformed = oneMinusCosineGust.vWind;
431  break;
432  default:
433  break;
434  }
435  }
436 
437  vCosineGust = factor * oneMinusCosineGust.vWindTransformed * oneMinusCosineGust.magnitude;
438 
439  profile.elapsedTime += in.totalDeltaT;
440 
441  if (profile.elapsedTime > (profile.startupDuration + profile.steadyDuration + profile.endDuration)) {
442  profile.Running = false;
443  profile.elapsedTime = 0.0;
444  oneMinusCosineGust.vWindTransformed.InitMatrix(0.0);
445  vCosineGust.InitMatrix(0);
446  }
447 }
448 
449 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450 
451 void FGWinds::NumberOfUpDownburstCells(int num)
452 {
453  for (unsigned int i=0; i<UpDownBurstCells.size();i++) delete UpDownBurstCells[i];
454  UpDownBurstCells.clear();
455  if (num >= 0) {
456  for (int i=0; i<num; i++) UpDownBurstCells.push_back(new struct UpDownBurst);
457  }
458 }
459 
460 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
461 // Calculates the distance between a specified point (where presumably the
462 // Up/Downburst is centered) and the current vehicle location. The distance
463 // here is calculated from the Haversine formula.
464 
465 double FGWinds::DistanceFromRingCenter(double lat, double lon)
466 {
467  double deltaLat = in.latitude - lat;
468  double deltaLong = in.longitude - lon;
469  double dLat2 = deltaLat/2.0;
470  double dLong2 = deltaLong/2.0;
471  double a = sin(dLat2)*sin(dLat2)
472  + cos(lat)*cos(in.latitude)*sin(dLong2)*sin(dLong2);
473  double c = 2.0*atan2(sqrt(a), sqrt(1.0 - a));
474  double d = in.planetRadius*c;
475  return d;
476 }
477 
478 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
479 
481 {
482 
483  for (unsigned int i=0; i<UpDownBurstCells.size(); i++) {
484  /*double d =*/ DistanceFromRingCenter(UpDownBurstCells[i]->ringLatitude, UpDownBurstCells[i]->ringLongitude);
485 
486  }
487 }
488 
489 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490 
491 void FGWinds::bind(void)
492 {
493  typedef double (FGWinds::*PMF)(int) const;
494  typedef int (FGWinds::*PMFt)(void) const;
495  typedef void (FGWinds::*PMFd)(int,double);
496  typedef void (FGWinds::*PMFi)(int);
497  typedef double (FGWinds::*Ptr)(void) const;
498 
499  // User-specified steady, constant, wind properties (local navigational/geographic frame: N-E-D)
500  PropertyManager->Tie("atmosphere/psiw-rad", this, &FGWinds::GetWindPsi, &FGWinds::SetWindPsi);
501  PropertyManager->Tie("atmosphere/wind-north-fps", this, eNorth, (PMF)&FGWinds::GetWindNED,
502  (PMFd)&FGWinds::SetWindNED);
503  PropertyManager->Tie("atmosphere/wind-east-fps", this, eEast, (PMF)&FGWinds::GetWindNED,
504  (PMFd)&FGWinds::SetWindNED);
505  PropertyManager->Tie("atmosphere/wind-down-fps", this, eDown, (PMF)&FGWinds::GetWindNED,
506  (PMFd)&FGWinds::SetWindNED);
507  PropertyManager->Tie("atmosphere/wind-mag-fps", this, &FGWinds::GetWindspeed,
508  &FGWinds::SetWindspeed);
509 
510  // User-specifieded gust (local navigational/geographic frame: N-E-D)
511  PropertyManager->Tie("atmosphere/gust-north-fps", this, eNorth, (PMF)&FGWinds::GetGustNED,
512  (PMFd)&FGWinds::SetGustNED);
513  PropertyManager->Tie("atmosphere/gust-east-fps", this, eEast, (PMF)&FGWinds::GetGustNED,
514  (PMFd)&FGWinds::SetGustNED);
515  PropertyManager->Tie("atmosphere/gust-down-fps", this, eDown, (PMF)&FGWinds::GetGustNED,
516  (PMFd)&FGWinds::SetGustNED);
517 
518  // User-specified 1 - cosine gust parameters (in specified frame)
519  PropertyManager->Tie("atmosphere/cosine-gust/startup-duration-sec", this, (Ptr)0L, &FGWinds::StartupGustDuration);
520  PropertyManager->Tie("atmosphere/cosine-gust/steady-duration-sec", this, (Ptr)0L, &FGWinds::SteadyGustDuration);
521  PropertyManager->Tie("atmosphere/cosine-gust/end-duration-sec", this, (Ptr)0L, &FGWinds::EndGustDuration);
522  PropertyManager->Tie("atmosphere/cosine-gust/magnitude-ft_sec", this, (Ptr)0L, &FGWinds::GustMagnitude);
523  PropertyManager->Tie("atmosphere/cosine-gust/frame", this, (PMFt)0L, (PMFi)&FGWinds::GustFrame);
524  PropertyManager->Tie("atmosphere/cosine-gust/X-velocity-ft_sec", this, (Ptr)0L, &FGWinds::GustXComponent);
525  PropertyManager->Tie("atmosphere/cosine-gust/Y-velocity-ft_sec", this, (Ptr)0L, &FGWinds::GustYComponent);
526  PropertyManager->Tie("atmosphere/cosine-gust/Z-velocity-ft_sec", this, (Ptr)0L, &FGWinds::GustZComponent);
527  PropertyManager->Tie("atmosphere/cosine-gust/start", this, (PMFt)0L, (PMFi)&FGWinds::StartGust);
528 
529  // User-specified Up- Down-burst parameters
530  PropertyManager->Tie("atmosphere/updownburst/number-of-cells", this, (PMFt)0L, &FGWinds::NumberOfUpDownburstCells);
531 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
532 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
533 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
534 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
535 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
536 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
537 // PropertyManager->Tie("atmosphere/updownburst/", this, (Ptr)0L, &FGWinds::);
538 
539  // User-specified turbulence (local navigational/geographic frame: N-E-D)
540  PropertyManager->Tie("atmosphere/turb-north-fps", this, eNorth, (PMF)&FGWinds::GetTurbNED,
541  (PMFd)&FGWinds::SetTurbNED);
542  PropertyManager->Tie("atmosphere/turb-east-fps", this, eEast, (PMF)&FGWinds::GetTurbNED,
543  (PMFd)&FGWinds::SetTurbNED);
544  PropertyManager->Tie("atmosphere/turb-down-fps", this, eDown, (PMF)&FGWinds::GetTurbNED,
545  (PMFd)&FGWinds::SetTurbNED);
546  // Experimental turbulence parameters
547  PropertyManager->Tie("atmosphere/p-turb-rad_sec", this,1, (PMF)&FGWinds::GetTurbPQR);
548  PropertyManager->Tie("atmosphere/q-turb-rad_sec", this,2, (PMF)&FGWinds::GetTurbPQR);
549  PropertyManager->Tie("atmosphere/r-turb-rad_sec", this,3, (PMF)&FGWinds::GetTurbPQR);
550  PropertyManager->Tie("atmosphere/turb-type", this, (PMFt)&FGWinds::GetTurbType, (PMFi)&FGWinds::SetTurbType);
551  PropertyManager->Tie("atmosphere/turb-rate", this, &FGWinds::GetTurbRate, &FGWinds::SetTurbRate);
552  PropertyManager->Tie("atmosphere/turb-gain", this, &FGWinds::GetTurbGain, &FGWinds::SetTurbGain);
553  PropertyManager->Tie("atmosphere/turb-rhythmicity", this, &FGWinds::GetRhythmicity,
554  &FGWinds::SetRhythmicity);
555 
556  // Parameters for milspec turbulence
557  PropertyManager->Tie("atmosphere/turbulence/milspec/windspeed_at_20ft_AGL-fps",
558  this, &FGWinds::GetWindspeed20ft,
559  &FGWinds::SetWindspeed20ft);
560  PropertyManager->Tie("atmosphere/turbulence/milspec/severity",
561  this, &FGWinds::GetProbabilityOfExceedence,
563 
564  // Total, calculated winds (local navigational/geographic frame: N-E-D). Read only.
565  PropertyManager->Tie("atmosphere/total-wind-north-fps", this, eNorth, (PMF)&FGWinds::GetTotalWindNED);
566  PropertyManager->Tie("atmosphere/total-wind-east-fps", this, eEast, (PMF)&FGWinds::GetTotalWindNED);
567  PropertyManager->Tie("atmosphere/total-wind-down-fps", this, eDown, (PMF)&FGWinds::GetTotalWindNED);
568 
569 }
570 
571 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
572 // The bitmasked value choices are as follows:
573 // unset: In this case (the default) JSBSim would only print
574 // out the normally expected messages, essentially echoing
575 // the config files as they are read. If the environment
576 // variable is not set, debug_lvl is set to 1 internally
577 // 0: This requests JSBSim not to output any messages
578 // whatsoever.
579 // 1: This value explicity requests the normal JSBSim
580 // startup messages
581 // 2: This value asks for a message to be printed out when
582 // a class is instantiated
583 // 4: When this value is set, a message is displayed when a
584 // FGModel object executes its Run() method
585 // 8: When this value is set, various runtime state variables
586 // are printed out periodically
587 // 16: When set various parameters are sanity checked and
588 // a message is printed out when they go out of bounds
589 
590 void FGWinds::Debug(int from)
591 {
592  if (debug_lvl <= 0) return;
593 
594  if (debug_lvl & 1) { // Standard console startup message output
595  if (from == 0) { // Constructor
596  }
597  }
598  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
599  if (from == 0) cout << "Instantiated: FGWinds" << endl;
600  if (from == 1) cout << "Destroyed: FGWinds" << endl;
601  }
602  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
603  }
604  if (debug_lvl & 8 ) { // Runtime state variables
605  }
606  if (debug_lvl & 16) { // Sanity checking
607  }
608  if (debug_lvl & 128) { //
609  }
610  if (debug_lvl & 64) {
611  if (from == 0) { // Constructor
612  cout << IdSrc << endl;
613  cout << IdHdr << endl;
614  }
615  }
616 }
617 
618 } // namespace JSBSim
virtual void SteadyGustDuration(double dur)
Specifies the length of time that the gust is at a steady, full strength.
Definition: FGWinds.h:283
virtual void SetWindPsi(double dir)
Sets the direction that the wind is coming from.
Definition: FGWinds.cpp:187
virtual void StartGust(bool running)
Initiates the execution of the gust.
Definition: FGWinds.h:279
virtual void SetGustNED(int idx, double gust)
Sets a gust component in NED frame.
Definition: FGWinds.h:182
virtual void StartupGustDuration(double dur)
Specifies the duration of the startup portion of the gust.
Definition: FGWinds.h:281
virtual const FGColumnVector3 & GetTotalWindNED(void) const
Retrieves the total wind components in NED frame.
Definition: FGWinds.h:140
FGMatrix33 Inverse(void) const
Return the inverse of the matrix.
Definition: FGMatrix33.cpp:227
virtual void SetWindNED(double wN, double wE, double wD)
Sets the wind components in NED frame.
Definition: FGWinds.h:148
virtual void SetTurbNED(int idx, double turb)
Sets a turbulence component in NED frame.
Definition: FGWinds.h:185
STL namespace.
virtual void EndGustDuration(double dur)
Specifies the length of time it takes for the gust to return to zero velocity.
Definition: FGWinds.h:285
FGColumnVector3 & Normalize(void)
Normalize.
virtual void GustYComponent(double y)
Specifies the Y component of velocity in the specified gust frame (ft/sec).
Definition: FGWinds.h:299
FGColumnVector3 vWindTransformed
Definition: FGWinds.h:247
Models atmospheric disturbances: winds, gusts, turbulence, downbursts, etc.
Definition: FGWinds.h:119
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:92
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
virtual const FGColumnVector3 & GetGustNED(void) const
Retrieves the gust components in NED frame.
Definition: FGWinds.h:197
Stores information about a specified Up- or Down-burst.
Definition: FGWinds.h:260
struct OneMinusCosineProfile gustProfile
Definition: FGWinds.h:250
virtual double GetTurbNED(int idx) const
Retrieves a turbulence component in NED frame.
Definition: FGWinds.h:194
virtual double GetWindPsi(void) const
Retrieves the direction that the wind is coming from.
Definition: FGWinds.h:165
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
virtual void GustMagnitude(double mag)
Specifies the magnitude of the gust in feet/second.
Definition: FGWinds.h:287
virtual void SetTurbType(tType tt)
Turbulence models available: ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin.
Definition: FGWinds.h:200
virtual const FGColumnVector3 & GetWindNED(void) const
Retrieves the wind components in NED frame.
Definition: FGWinds.h:157
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
Definition: FGFDMExec.h:533
virtual void GustFrame(eGustFrame gFrame)
Specifies the frame that the gust direction vector components are specified in.
Definition: FGWinds.h:295
virtual void GustXComponent(double x)
Specifies the X component of velocity in the specified gust frame (ft/sec).
Definition: FGWinds.h:297
virtual void GustZComponent(double z)
Specifies the Z component of velocity in the specified gust frame (ft/sec).
Definition: FGWinds.h:301
virtual void SetProbabilityOfExceedence(int idx)
allowable range: 0-7, 3=light, 4=moderate, 6=severe turbulence
Definition: FGWinds.h:221
double Magnitude(void) const
Length of the vector.
~FGWinds()
Destructor.
Definition: FGWinds.cpp:116
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
Lookup table class.
Definition: FGTable.h:243
bool Run(bool Holding)
Runs the winds model; called by the Executive Can pass in a value indicating if the executive is dire...
Definition: FGWinds.cpp:142