JSBSim Flight Dynamics Model 1.2.3 (07 Jun 2025)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
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
26HISTORY
27--------------------------------------------------------------------------------
285/2011 JSB Created
29
30%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31SENTRY
32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34#ifndef FGWINDS_H
35#define FGWINDS_H
36
37/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38INCLUDES
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41#include "models/FGModel.h"
42#include "math/FGMatrix33.h"
43#include <optional>
44
45/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46FORWARD DECLARATIONS
47%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
48
49namespace JSBSim {
50
51class FGTable;
52
53/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54CLASS DOCUMENTATION
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56
163/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164CLASS DECLARATION
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
166
167class FGWinds : public FGModel {
168public:
169
171 explicit FGWinds(FGFDMExec*);
173 ~FGWinds();
181 bool Run(bool Holding) override;
182 bool InitModel(void) override;
183 enum tType {ttNone, ttStandard, ttCulp, ttMilspec, ttTustin} turbType;
184
185 // TOTAL WIND access functions (wind + gust + turbulence)
186
188 virtual const FGColumnVector3& GetTotalWindNED(void) const { return vTotalWindNED; }
189
191 virtual double GetTotalWindNED(int idx) const {return vTotalWindNED(idx);}
192
193 // WIND access functions
194
196 virtual void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
197
199 virtual void SetWindNED(int idx, double wind) { vWindNED(idx)=wind;}
200
202 virtual void SetWindNED(const FGColumnVector3& wind) { vWindNED=wind; }
203
205 virtual const FGColumnVector3& GetWindNED(void) const { return vWindNED; }
206
208 virtual double GetWindNED(int idx) const {return vWindNED(idx);}
209
213 virtual double GetWindPsi(void) const { return psiw; }
214
222 virtual void SetWindPsi(double dir);
223
224 virtual void SetWindspeed(double speed);
225
226 virtual double GetWindspeed(void) const;
227
228 // GUST access functions
229
231 virtual void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
232
234 virtual void SetTurbNED(int idx, double turb) { vTurbulenceNED(idx)=turb;}
235
237 virtual void SetGustNED(double gN, double gE, double gD) { vGustNED(eNorth)=gN; vGustNED(eEast)=gE; vGustNED(eDown)=gD;}
238
240 virtual double GetGustNED(int idx) const {return vGustNED(idx);}
241
243 virtual double GetTurbNED(int idx) const {return vTurbulenceNED(idx);}
244
246 virtual const FGColumnVector3& GetGustNED(void) const {return vGustNED;}
247
250 virtual void SetTurbType(tType tt) {turbType = tt;}
251 virtual tType GetTurbType() const {return turbType;}
252
253 virtual void SetTurbGain(double tg) {TurbGain = tg;}
254 virtual double GetTurbGain() const {return TurbGain;}
255
256 virtual void SetTurbRate(double tr) {TurbRate = tr;}
257 virtual double GetTurbRate() const {return TurbRate;}
258
259 virtual void SetRhythmicity(double r) {Rhythmicity=r;}
260 virtual double GetRhythmicity() const {return Rhythmicity;}
261
262 virtual double GetTurbPQR(int idx) const {return vTurbPQR(idx);}
263 virtual double GetTurbMagnitude(void) const {return vTurbulenceNED.Magnitude();}
264 virtual double GetTurbDirection(void) const {return TurbDirection;}
265 virtual const FGColumnVector3& GetTurbPQR(void) const {return vTurbPQR;}
266
267 virtual void SetWindspeed20ft(double ws) { windspeed_at_20ft = ws;}
268 virtual double GetWindspeed20ft() const { return windspeed_at_20ft;}
269
271 virtual void SetProbabilityOfExceedence( int idx) {probability_of_exceedence_index = idx;}
272 virtual int GetProbabilityOfExceedence() const { return probability_of_exceedence_index;}
273
274 // Stores data defining a 1 - cosine gust profile that builds up, holds steady
275 // and fades out over specified durations.
277 bool Running;
278 double elapsedTime;
281 double endDuration;
283 {
284 elapsedTime = 0.0;
285 Running = false;
286 startupDuration = 2;
287 steadyDuration = 4;
288 endDuration = 2;
289 }
290 };
291
292 enum eGustFrame {gfNone=0, gfBody, gfWind, gfLocal};
293
298 double magnitude;
299 eGustFrame gustFrame;
302 {
303 vWind.InitMatrix(0.0);
304 gustFrame = gfLocal;
305 magnitude = 1.0;
306 };
307 };
308
310 struct UpDownBurst {
314 double ringRadius;
316 double circulation;
320 ringAltitude = 1000.0;
321 ringRadius = 2000.0;
322 ringCoreRadius = 100.0;
323 circulation = 100000.0;
324 }
325 };
326
327 // 1 - Cosine gust setters
329 virtual void StartGust(bool running) {oneMinusCosineGust.gustProfile.Running = running;}
331 virtual void StartupGustDuration(double dur) {oneMinusCosineGust.gustProfile.startupDuration = dur;}
333 virtual void SteadyGustDuration(double dur) {oneMinusCosineGust.gustProfile.steadyDuration = dur;}
335 virtual void EndGustDuration(double dur) {oneMinusCosineGust.gustProfile.endDuration = dur;}
337 virtual void GustMagnitude(double mag) {oneMinusCosineGust.magnitude = mag;}
345 virtual void GustFrame(eGustFrame gFrame) {oneMinusCosineGust.gustFrame = gFrame;}
347 virtual void GustXComponent(double x) {oneMinusCosineGust.vWind(eX) = x;}
349 virtual void GustYComponent(double y) {oneMinusCosineGust.vWind(eY) = y;}
351 virtual void GustZComponent(double z) {oneMinusCosineGust.vWind(eZ) = z;}
352
353 // Up- Down-burst functions
354 void NumberOfUpDownburstCells(int num);
355
356 struct Inputs {
357 double V;
358 double wingspan;
359 double DistanceAGL;
360 double AltitudeASL;
361 double longitude;
362 double latitude;
363 double planetRadius;
364 FGMatrix33 Tl2b;
365 FGMatrix33 Tw2b;
366 double totalDeltaT;
367 } in;
368
369private:
370
371 double MagnitudedAccelDt, MagnitudeAccel, Magnitude, TurbDirection;
372 //double h;
373 double TurbGain;
374 double TurbRate;
375 double Rhythmicity;
376 double wind_from_clockwise;
377 double spike, target_time, strength;
378 FGColumnVector3 vTurbulenceGrad;
379 FGColumnVector3 vBodyTurbGrad;
380 FGColumnVector3 vTurbPQR;
381
382 struct OneMinusCosineGust oneMinusCosineGust;
383 std::vector <struct UpDownBurst*> UpDownBurstCells;
384
385 // Dryden turbulence model
386 double windspeed_at_20ft;
387 int probability_of_exceedence_index;
388 FGTable *POE_Table;
389
390 // keep values from last timesteps
391 // TODO maybe use deque?
392 double xi_u_km1, nu_u_km1;
393 double xi_v_km1, xi_v_km2, nu_v_km1, nu_v_km2;
394 double xi_w_km1, xi_w_km2, nu_w_km1, nu_w_km2;
395 double xi_p_km1, nu_p_km1;
396 double xi_q_km1, xi_r_km1;
397
398 double psiw;
399 FGColumnVector3 vTotalWindNED;
400 FGColumnVector3 vWindNED;
401 FGColumnVector3 vGustNED;
402 FGColumnVector3 vCosineGust;
403 FGColumnVector3 vBurstGust;
404 FGColumnVector3 vTurbulenceNED;
405
406 std::optional<unsigned int> RandomSeed;
407 std::shared_ptr<RandomNumberGenerator> generator;
408
409 void SetRandomSeed(int sr);
410 int GetRandomSeed(void) const;
411
412 void Turbulence(double h);
413 void UpDownBurst();
414
415 void CosineGust();
416 double CosineGustProfile( double startDuration, double steadyDuration,
417 double endDuration, double elapsedTime);
418 double DistanceFromRingCenter(double lat, double lon);
419
420 virtual void bind(void);
421 void Debug(int from) override;
422};
423
424} // namespace JSBSim
425
426//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
427#endif
428
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:167
virtual const FGColumnVector3 & GetWindNED(void) const
Retrieves the wind components in NED frame.
Definition FGWinds.h:205
virtual void SetWindNED(const FGColumnVector3 &wind)
Sets the wind components in NED frame.
Definition FGWinds.h:202
virtual void GustMagnitude(double mag)
Specifies the magnitude of the gust in feet/second.
Definition FGWinds.h:337
virtual const FGColumnVector3 & GetTotalWindNED(void) const
Retrieves the total wind components in NED frame.
Definition FGWinds.h:188
virtual void GustXComponent(double x)
Specifies the X component of velocity in the specified gust frame (ft/sec).
Definition FGWinds.h:347
virtual void SetWindNED(int idx, double wind)
Sets a wind component in NED frame.
Definition FGWinds.h:199
virtual void SetTurbNED(int idx, double turb)
Sets a turbulence component in NED frame.
Definition FGWinds.h:234
virtual void SetWindPsi(double dir)
Sets the direction that the wind is coming from.
Definition FGWinds.cpp:194
virtual void StartupGustDuration(double dur)
Specifies the duration of the startup portion of the gust.
Definition FGWinds.h:331
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:146
virtual void SetTurbType(tType tt)
Turbulence models available: ttNone, ttStandard, ttBerndt, ttCulp, ttMilspec, ttTustin.
Definition FGWinds.h:250
virtual double GetTurbNED(int idx) const
Retrieves a turbulence component in NED frame.
Definition FGWinds.h:243
virtual void SteadyGustDuration(double dur)
Specifies the length of time that the gust is at a steady, full strength.
Definition FGWinds.h:333
~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:335
virtual double GetTotalWindNED(int idx) const
Retrieves a total wind component in NED frame.
Definition FGWinds.h:191
virtual void SetWindNED(double wN, double wE, double wD)
Sets the wind components in NED frame.
Definition FGWinds.h:196
virtual void GustZComponent(double z)
Specifies the Z component of velocity in the specified gust frame (ft/sec).
Definition FGWinds.h:351
virtual void SetProbabilityOfExceedence(int idx)
allowable range: 0-7, 3=light, 4=moderate, 6=severe turbulence
Definition FGWinds.h:271
virtual double GetWindNED(int idx) const
Retrieves a wind component in NED frame.
Definition FGWinds.h:208
virtual void GustFrame(eGustFrame gFrame)
Specifies the frame that the gust direction vector components are specified in.
Definition FGWinds.h:345
virtual double GetGustNED(int idx) const
Retrieves a gust component in NED frame.
Definition FGWinds.h:240
virtual void GustYComponent(double y)
Specifies the Y component of velocity in the specified gust frame (ft/sec).
Definition FGWinds.h:349
virtual void StartGust(bool running)
Initiates the execution of the gust.
Definition FGWinds.h:329
virtual const FGColumnVector3 & GetGustNED(void) const
Retrieves the gust components in NED frame.
Definition FGWinds.h:246
virtual double GetWindPsi(void) const
Retrieves the direction that the wind is coming from.
Definition FGWinds.h:213
virtual void SetGustNED(double gN, double gE, double gD)
Sets the gust components in NED frame.
Definition FGWinds.h:237
virtual void SetGustNED(int idx, double gust)
Sets a gust component in NED frame.
Definition FGWinds.h:231
Stores the information about a single one minus cosine gust instance.
Definition FGWinds.h:295
struct OneMinusCosineProfile gustProfile
Definition FGWinds.h:300
Stores information about a specified Up- or Down-burst.
Definition FGWinds.h:310
struct OneMinusCosineProfile oneMCosineProfile
Definition FGWinds.h:317