JSBSim Flight Dynamics Model  1.2.0 (05 Nov 2023)
An Open Source Flight Dynamics and Control Software Library in C++
FGWinds.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGWinds.h
4  Author: Jon Berndt, Andreas Gaeb, David Culp
5  Date started: 5/2011
6 
7  ------------- Copyright (C) 2011 Jon S. Berndt (jon@jsbsim.org) -------------
8 
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free
11  Software Foundation; either version 2 of the License, or (at your option) any
12  later version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17  details.
18 
19  You should have received a copy of the GNU Lesser General Public License along
20  with this program; if not, write to the Free Software Foundation, Inc., 59
21  Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 
23  Further information about the GNU Lesser General Public License can also be
24  found on the world wide web at http://www.gnu.org.
25 
26 HISTORY
27 --------------------------------------------------------------------------------
28 5/2011 JSB Created
29 
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33 
34 #ifndef FGWINDS_H
35 #define FGWINDS_H
36 
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40 
41 #include "models/FGModel.h"
42 #include "math/FGMatrix33.h"
43 
44 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 FORWARD DECLARATIONS
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 
48 namespace JSBSim {
49 
50 class FGTable;
51 
52 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 CLASS DOCUMENTATION
54 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 
162 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 CLASS DECLARATION
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
165 
166 class FGWinds : public FGModel {
167 public:
168 
170  explicit FGWinds(FGFDMExec*);
172  ~FGWinds();
180  bool Run(bool Holding) override;
181  bool InitModel(void) override;
182  enum tType {ttNone, ttStandard, ttCulp, ttMilspec, ttTustin} turbType;
183 
184  // TOTAL WIND access functions (wind + gust + turbulence)
185 
187  virtual const FGColumnVector3& GetTotalWindNED(void) const { return vTotalWindNED; }
188 
190  virtual double GetTotalWindNED(int idx) const {return vTotalWindNED(idx);}
191 
192  // WIND access functions
193 
195  virtual void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
196 
198  virtual void SetWindNED(int idx, double wind) { vWindNED(idx)=wind;}
199 
201  virtual void SetWindNED(const FGColumnVector3& wind) { vWindNED=wind; }
202 
204  virtual const FGColumnVector3& GetWindNED(void) const { return vWindNED; }
205 
207  virtual double GetWindNED(int idx) const {return vWindNED(idx);}
208 
212  virtual double GetWindPsi(void) const { return psiw; }
213 
221  virtual void SetWindPsi(double dir);
222 
223  virtual void SetWindspeed(double speed);
224 
225  virtual double GetWindspeed(void) const;
226 
227  // GUST access functions
228 
230  virtual void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
231 
233  virtual void SetTurbNED(int idx, double turb) { vTurbulenceNED(idx)=turb;}
234 
236  virtual void SetGustNED(double gN, double gE, double gD) { vGustNED(eNorth)=gN; vGustNED(eEast)=gE; vGustNED(eDown)=gD;}
237 
239  virtual double GetGustNED(int idx) const {return vGustNED(idx);}
240 
242  virtual double GetTurbNED(int idx) const {return vTurbulenceNED(idx);}
243 
245  virtual const FGColumnVector3& GetGustNED(void) const {return vGustNED;}
246 
249  virtual void SetTurbType(tType tt) {turbType = tt;}
250  virtual tType GetTurbType() const {return turbType;}
251 
252  virtual void SetTurbGain(double tg) {TurbGain = tg;}
253  virtual double GetTurbGain() const {return TurbGain;}
254 
255  virtual void SetTurbRate(double tr) {TurbRate = tr;}
256  virtual double GetTurbRate() const {return TurbRate;}
257 
258  virtual void SetRhythmicity(double r) {Rhythmicity=r;}
259  virtual double GetRhythmicity() const {return Rhythmicity;}
260 
261  virtual double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
262  virtual double GetTurbMagnitude(void) const {return vTurbulenceNED.Magnitude();}
263  virtual double GetTurbDirection(void) const {return TurbDirection;}
264  virtual const FGColumnVector3& GetTurbPQR(void) const {return vTurbPQR;}
265 
266  virtual void SetWindspeed20ft(double ws) { windspeed_at_20ft = ws;}
267  virtual double GetWindspeed20ft() const { return windspeed_at_20ft;}
268 
270  virtual void SetProbabilityOfExceedence( int idx) {probability_of_exceedence_index = idx;}
271  virtual int GetProbabilityOfExceedence() const { return probability_of_exceedence_index;}
272 
273  // Stores data defining a 1 - cosine gust profile that builds up, holds steady
274  // and fades out over specified durations.
276  bool Running;
277  double elapsedTime;
279  double steadyDuration;
280  double endDuration;
282  {
283  elapsedTime = 0.0;
284  Running = false;
285  startupDuration = 2;
286  steadyDuration = 4;
287  endDuration = 2;
288  }
289  };
290 
291  enum eGustFrame {gfNone=0, gfBody, gfWind, gfLocal};
292 
297  double magnitude;
298  eGustFrame gustFrame;
301  {
302  vWind.InitMatrix(0.0);
303  gustFrame = gfLocal;
304  magnitude = 1.0;
305  };
306  };
307 
309  struct UpDownBurst {
310  double ringLatitude;
311  double ringLongitude;
312  double ringAltitude;
313  double ringRadius;
314  double ringCoreRadius;
315  double circulation;
318  ringLatitude = ringLongitude = 0.0;
319  ringAltitude = 1000.0;
320  ringRadius = 2000.0;
321  ringCoreRadius = 100.0;
322  circulation = 100000.0;
323  }
324  };
325 
326  // 1 - Cosine gust setters
328  virtual void StartGust(bool running) {oneMinusCosineGust.gustProfile.Running = running;}
330  virtual void StartupGustDuration(double dur) {oneMinusCosineGust.gustProfile.startupDuration = dur;}
332  virtual void SteadyGustDuration(double dur) {oneMinusCosineGust.gustProfile.steadyDuration = dur;}
334  virtual void EndGustDuration(double dur) {oneMinusCosineGust.gustProfile.endDuration = dur;}
336  virtual void GustMagnitude(double mag) {oneMinusCosineGust.magnitude = mag;}
344  virtual void GustFrame(eGustFrame gFrame) {oneMinusCosineGust.gustFrame = gFrame;}
346  virtual void GustXComponent(double x) {oneMinusCosineGust.vWind(eX) = x;}
348  virtual void GustYComponent(double y) {oneMinusCosineGust.vWind(eY) = y;}
350  virtual void GustZComponent(double z) {oneMinusCosineGust.vWind(eZ) = z;}
351 
352  // Up- Down-burst functions
353  void NumberOfUpDownburstCells(int num);
354 
355  struct Inputs {
356  double V;
357  double wingspan;
358  double DistanceAGL;
359  double AltitudeASL;
360  double longitude;
361  double latitude;
362  double planetRadius;
363  FGMatrix33 Tl2b;
364  FGMatrix33 Tw2b;
365  double totalDeltaT;
366  } in;
367 
368 private:
369 
370  double MagnitudedAccelDt, MagnitudeAccel, Magnitude, TurbDirection;
371  //double h;
372  double TurbGain;
373  double TurbRate;
374  double Rhythmicity;
375  double wind_from_clockwise;
376  double spike, target_time, strength;
377  FGColumnVector3 vTurbulenceGrad;
378  FGColumnVector3 vBodyTurbGrad;
379  FGColumnVector3 vTurbPQR;
380 
381  struct OneMinusCosineGust oneMinusCosineGust;
382  std::vector <struct UpDownBurst*> UpDownBurstCells;
383 
384  // Dryden turbulence model
385  double windspeed_at_20ft;
386  int probability_of_exceedence_index;
387  FGTable *POE_Table;
388 
389  double psiw;
390  FGColumnVector3 vTotalWindNED;
391  FGColumnVector3 vWindNED;
392  FGColumnVector3 vGustNED;
393  FGColumnVector3 vCosineGust;
394  FGColumnVector3 vBurstGust;
395  FGColumnVector3 vTurbulenceNED;
396 
397  std::shared_ptr<RandomNumberGenerator> generator;
398 
399  void Turbulence(double h);
400  void UpDownBurst();
401 
402  void CosineGust();
403  double CosineGustProfile( double startDuration, double steadyDuration,
404  double endDuration, double elapsedTime);
405  double DistanceFromRingCenter(double lat, double lon);
406 
407  virtual void bind(void);
408  void Debug(int from) override;
409 };
410 
411 } // namespace JSBSim
412 
413 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414 #endif
415 
This class implements a 3 element column vector.
double Magnitude(void) const
Length of the vector.
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:184
Handles matrix math operations.
Definition: FGMatrix33.h:70
Base class for all scheduled JSBSim models.
Definition: FGModel.h:70
Lookup table class.
Definition: FGTable.h:234
Models atmospheric disturbances: winds, gusts, turbulence, downbursts, etc.
Definition: FGWinds.h:166
virtual const FGColumnVector3 & GetTotalWindNED(void) const
Retrieves the total wind components in NED frame.
Definition: FGWinds.h:187
virtual void SetWindNED(const FGColumnVector3 &wind)
Sets the wind components in NED frame.
Definition: FGWinds.h:201
virtual void GustMagnitude(double mag)
Specifies the magnitude of the gust in feet/second.
Definition: FGWinds.h:336
virtual void GustXComponent(double x)
Specifies the X component of velocity in the specified gust frame (ft/sec).
Definition: FGWinds.h:346
virtual void SetWindNED(int idx, double wind)
Sets a wind component in NED frame.
Definition: FGWinds.h:198
virtual void SetTurbNED(int idx, double turb)
Sets a turbulence component in NED frame.
Definition: FGWinds.h:233
virtual void SetWindPsi(double dir)
Sets the direction that the wind is coming from.
Definition: FGWinds.cpp:185
virtual void StartupGustDuration(double dur)
Specifies the duration of the startup portion of the gust.
Definition: FGWinds.h:330
bool Run(bool Holding) override
Runs the winds model; called by the Executive Can pass in a value indicating if the executive is dire...
Definition: FGWinds.cpp:140
virtual void SetTurbType(tType tt)
Turbulence models available: ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin.
Definition: FGWinds.h:249
virtual const FGColumnVector3 & GetWindNED(void) const
Retrieves the wind components in NED frame.
Definition: FGWinds.h:204
virtual double GetTurbNED(int idx) const
Retrieves a turbulence component in NED frame.
Definition: FGWinds.h:242
virtual void SteadyGustDuration(double dur)
Specifies the length of time that the gust is at a steady, full strength.
Definition: FGWinds.h:332
~FGWinds()
Destructor.
Definition: FGWinds.cpp:114
virtual void EndGustDuration(double dur)
Specifies the length of time it takes for the gust to return to zero velocity.
Definition: FGWinds.h:334
virtual double GetTotalWindNED(int idx) const
Retrieves a total wind component in NED frame.
Definition: FGWinds.h:190
virtual void SetWindNED(double wN, double wE, double wD)
Sets the wind components in NED frame.
Definition: FGWinds.h:195
virtual void GustZComponent(double z)
Specifies the Z component of velocity in the specified gust frame (ft/sec).
Definition: FGWinds.h:350
virtual void SetProbabilityOfExceedence(int idx)
allowable range: 0-7, 3=light, 4=moderate, 6=severe turbulence
Definition: FGWinds.h:270
virtual double GetWindNED(int idx) const
Retrieves a wind component in NED frame.
Definition: FGWinds.h:207
virtual void GustFrame(eGustFrame gFrame)
Specifies the frame that the gust direction vector components are specified in.
Definition: FGWinds.h:344
FGWinds(FGFDMExec *)
Constructor.
Definition: FGWinds.cpp:74
virtual double GetGustNED(int idx) const
Retrieves a gust component in NED frame.
Definition: FGWinds.h:239
virtual void GustYComponent(double y)
Specifies the Y component of velocity in the specified gust frame (ft/sec).
Definition: FGWinds.h:348
virtual void StartGust(bool running)
Initiates the execution of the gust.
Definition: FGWinds.h:328
virtual double GetWindPsi(void) const
Retrieves the direction that the wind is coming from.
Definition: FGWinds.h:212
virtual const FGColumnVector3 & GetGustNED(void) const
Retrieves the gust components in NED frame.
Definition: FGWinds.h:245
virtual void SetGustNED(double gN, double gE, double gD)
Sets the gust components in NED frame.
Definition: FGWinds.h:236
virtual void SetGustNED(int idx, double gust)
Sets a gust component in NED frame.
Definition: FGWinds.h:230
Stores the information about a single one minus cosine gust instance.
Definition: FGWinds.h:294
FGColumnVector3 vWindTransformed
Definition: FGWinds.h:296
struct OneMinusCosineProfile gustProfile
Definition: FGWinds.h:299
Stores information about a specified Up- or Down-burst.
Definition: FGWinds.h:309
struct OneMinusCosineProfile oneMCosineProfile
Definition: FGWinds.h:316