Debian Codegraph @

src/FDM/JSBSim/models/atmosphere/FGWinds.h

raw symbols SCIP
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 ([email protected]) -------------
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
56 /** Models atmospheric disturbances: winds, gusts, turbulence, downbursts, etc.
57
58 <h2>Turbulence</h2>
59 Various turbulence models are available. They are specified
60 via the property <tt>atmosphere/turb-type</tt>. The following models are
61 available:
62 - 0: ttNone (turbulence disabled)
63 - 1: ttStandard
64 - 2: ttCulp
65 - 3: ttMilspec (Dryden spectrum)
66 - 4: ttTustin (Dryden spectrum)
67
68 The Milspec and Tustin models are described in the Yeager report cited
69 below. They both use a Dryden spectrum model whose parameters (scale
70 lengths and intensities) are modelled according to MIL-F-8785C. Parameters
71 are modelled differently for altitudes below 1000ft and above 2000ft, for
72 altitudes in between they are interpolated linearly.
73
74 The two models differ in the implementation of the transfer functions
75 described in the milspec.
76
77 To use one of these two models, set <tt>atmosphere/turb-type</tt> to 4
78 resp. 5, and specify values for
79 <tt>atmosphere/turbulence/milspec/windspeed_at_20ft_AGL-fps</tt> and
80 <tt>atmosphere/turbulence/milspec/severity</tt> (the latter corresponds to
81 the probability of exceedence curves from Fig.&nbsp;7 of the milspec,
82 allowable range is 0 (disabled) to 7). <tt>atmosphere/psiw-rad</tt> is
83 respected as well; note that you have to specify a positive wind magnitude
84 to prevent psiw from being reset to zero.
85
86 Reference values (cf. figures 7 and 9 from the milspec):
87 <table>
88 <tr><td><b>Intensity</b></td>
89 <td><b><tt>windspeed_at_20ft_AGL-fps</tt></b></td>
90 <td><b><tt>severity</tt></b></td></tr>
91 <tr><td>light</td>
92 <td>25 (15 knots)</td>
93 <td>3</td></tr>
94 <tr><td>moderate</td>
95 <td>50 (30 knots)</td>
96 <td>4</td></tr>
97 <tr><td>severe</td>
98 <td>75 (45 knots)</td>
99 <td>6</td></tr>
100 </table>
101
102 <h2>Cosine Gust</h2>
103 A one minus cosine gust model is available. This permits a configurable,
104 predictable gust to be input to JSBSim for testing handling and
105 dynamics. Here is how a gust can be entered in a script:
106
107 ~~~{.xml}
108 <event name="Introduce gust">
109 <condition> simulation/sim-time-sec ge 10 </condition>
110 <set name="atmosphere/cosine-gust/startup-duration-sec" value="5"/>
111 <set name="atmosphere/cosine-gust/steady-duration-sec" value="1"/>
112 <set name="atmosphere/cosine-gust/end-duration-sec" value="5"/>
113 <set name="atmosphere/cosine-gust/magnitude-ft_sec" value="30"/>
114 <set name="atmosphere/cosine-gust/frame" value="2"/>
115 <set name="atmosphere/cosine-gust/X-velocity-ft_sec" value="-1"/>
116 <set name="atmosphere/cosine-gust/Y-velocity-ft_sec" value="0"/>
117 <set name="atmosphere/cosine-gust/Z-velocity-ft_sec" value="0"/>
118 <set name="atmosphere/cosine-gust/start" value="1"/>
119 <notify/>
120 </event>
121 ~~~
122
123 The x, y, z velocity components are meant to define the direction vector.
124 The vector will be normalized by the routine, so it does not need to be a
125 unit vector.
126
127 The startup duration is the time it takes to build up to full strength
128 (magnitude-ft_sec) from zero. Steady duration is the time the gust stays at
129 the specified magnitude. End duration is the time it takes to dwindle to
130 zero from the specified magnitude. The start and end transients are in a
131 smooth cosine shape.
132
133 The frame is specified from the following enum:
134
135 enum eGustFrame {gfNone=0, gfBody, gfWind, gfLocal};
136
137 That is, if you specify the X, Y, Z gust direction vector in the body frame,
138 frame will be "1". If the X, Y, and Z gust direction vector is in the Wind
139 frame, use frame = 2. If you specify the gust direction vector in the local
140 frame (N-E-D) use frame = 3. Note that an internal local frame direction
141 vector is created based on the X, Y, Z direction vector you specify and the
142 frame *at the time the gust is begun*. The direction vector is not updated
143 after the initial creation. This is to keep the gust at the same direction
144 independent of aircraft dynamics.
145
146 The gust is triggered when the property atmosphere/cosine-gust/start is set
147 to 1. It can be used repeatedly - the gust resets itself after it has
148 completed.
149
150 The cosine gust is global: it affects the whole world not just the vicinity
151 of the aircraft.
152
153 @see Yeager, Jessie C.: "Implementation and Testing of Turbulence Models for
154 the F18-HARV" (<a
155 href="http://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980028448_1998081596.pdf">
156 pdf</a>), NASA CR-1998-206937, 1998
157
158 @see MIL-F-8785C: Military Specification: Flying Qualities of Piloted Aircraft
159
160 */
161
162 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163 CLASS DECLARATION
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
165
166 class FGWinds : public FGModel {
167 public:
168
169 /// Constructor
170 explicit FGWinds(FGFDMExec*);
171 /// Destructor
172 ~FGWinds();
173 /** Runs the winds model; called by the Executive
174 Can pass in a value indicating if the executive is directing the simulation to Hold.
175 @param Holding if true, the executive has been directed to hold the sim
176 from advancing time. Some models may ignore this flag, such
177 as the Input model, which may need to be active to listen
178 on a socket for the "Resume" command to be given.
179 @return false if no error */
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
186 /// Retrieves the total wind components in NED frame.
187 virtual const FGColumnVector3& GetTotalWindNED(void) const { return vTotalWindNED; }
188
189 /// Retrieves a total wind component in NED frame.
190 virtual double GetTotalWindNED(int idx) const {return vTotalWindNED(idx);}
191
192 // WIND access functions
193
194 /// Sets the wind components in NED frame.
195 virtual void SetWindNED(double wN, double wE, double wD) { vWindNED(1)=wN; vWindNED(2)=wE; vWindNED(3)=wD;}
196
197 /// Sets a wind component in NED frame.
198 virtual void SetWindNED(int idx, double wind) { vWindNED(idx)=wind;}
199
200 /// Sets the wind components in NED frame.
201 virtual void SetWindNED(const FGColumnVector3& wind) { vWindNED=wind; }
202
203 /// Retrieves the wind components in NED frame.
204 virtual const FGColumnVector3& GetWindNED(void) const { return vWindNED; }
205
206 /// Retrieves a wind component in NED frame.
207 virtual double GetWindNED(int idx) const {return vWindNED(idx);}
208
209 /** Retrieves the direction that the wind is coming from.
210 The direction is defined as north=0 and increases counterclockwise.
211 The wind heading is returned in radians.*/
212 virtual double GetWindPsi(void) const { return psiw; }
213
214 /** Sets the direction that the wind is coming from.
215 The direction is defined as north=0 and increases counterclockwise to 2*pi
216 (radians). The vertical component of wind is assumed to be zero - and is
217 forcibly set to zero. This function sets the vWindNED vector components
218 based on the supplied direction. The magnitude of the wind set in the
219 vector is preserved (assuming the vertical component is non-zero).
220 @param dir wind direction in the horizontal plane, in radians.*/
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
229 /// Sets a gust component in NED frame.
230 virtual void SetGustNED(int idx, double gust) { vGustNED(idx)=gust;}
231
232 /// Sets a turbulence component in NED frame.
233 virtual void SetTurbNED(int idx, double turb) { vTurbulenceNED(idx)=turb;}
234
235 /// Sets the gust components in NED frame.
236 virtual void SetGustNED(double gN, double gE, double gD) { vGustNED(eNorth)=gN; vGustNED(eEast)=gE; vGustNED(eDown)=gD;}
237
238 /// Retrieves a gust component in NED frame.
239 virtual double GetGustNED(int idx) const {return vGustNED(idx);}
240
241 /// Retrieves a turbulence component in NED frame.
242 virtual double GetTurbNED(int idx) const {return vTurbulenceNED(idx);}
243
244 /// Retrieves the gust components in NED frame.
245 virtual const FGColumnVector3& GetGustNED(void) const {return vGustNED;}
246
247 /** Turbulence models available: ttNone, ttStandard, ttBerndt, ttCulp,
248 ttMilspec, ttTustin */
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
269 /// allowable range: 0-7, 3=light, 4=moderate, 6=severe turbulence
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.
275 struct OneMinusCosineProfile {
276 bool Running; ///<- This flag is set true through FGWinds::StartGust().
277 double elapsedTime; ///<- Stores the elapsed time for the ongoing gust.
278 double startupDuration; ///<- Specifies the time it takes for the gust startup transient.
279 double steadyDuration; ///<- Specifies the duration of the steady gust.
280 double endDuration; ///<- Specifies the time it takes for the gust to subsude.
281 OneMinusCosineProfile() ///<- The constructor.
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
293 /// Stores the information about a single one minus cosine gust instance.
294 struct OneMinusCosineGust {
295 FGColumnVector3 vWind; ///<- The input normalized wind vector.
296 FGColumnVector3 vWindTransformed; ///<- The transformed normal vector at the time the gust is started.
297 double magnitude; ///<- The magnitude of the wind vector.
298 eGustFrame gustFrame; ///<- The frame that the wind vector is specified in.
299 struct OneMinusCosineProfile gustProfile; ///<- The gust shape (profile) data for this gust.
300 OneMinusCosineGust() ///<- Constructor.
301 {
302 vWind.InitMatrix(0.0);
303 gustFrame = gfLocal;
304 magnitude = 1.0;
305 };
306 };
307
308 /// Stores information about a specified Up- or Down-burst.
309 struct UpDownBurst {
310 double ringLatitude; ///<- The latitude of the downburst run (radians)
311 double ringLongitude; ///<- The longitude of the downburst run (radians)
312 double ringAltitude; ///<- The altitude of the ring (feet).
313 double ringRadius; ///<- The radius of the ring (feet).
314 double ringCoreRadius; ///<- The cross-section "core" radius of the ring (feet).
315 double circulation; ///<- The circulation (gamma) (feet-squared per second).
316 struct OneMinusCosineProfile oneMCosineProfile;///<- A gust profile structure.
317 UpDownBurst() { ///<- Constructor
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
327 /// Initiates the execution of the gust.
328 virtual void StartGust(bool running) {oneMinusCosineGust.gustProfile.Running = running;}
329 ///Specifies the duration of the startup portion of the gust.
330 virtual void StartupGustDuration(double dur) {oneMinusCosineGust.gustProfile.startupDuration = dur;}
331 ///Specifies the length of time that the gust is at a steady, full strength.
332 virtual void SteadyGustDuration(double dur) {oneMinusCosineGust.gustProfile.steadyDuration = dur;}
333 /// Specifies the length of time it takes for the gust to return to zero velocity.
334 virtual void EndGustDuration(double dur) {oneMinusCosineGust.gustProfile.endDuration = dur;}
335 /// Specifies the magnitude of the gust in feet/second.
336 virtual void GustMagnitude(double mag) {oneMinusCosineGust.magnitude = mag;}
337 /** Specifies the frame that the gust direction vector components are specified in. The
338 body frame is defined with the X direction forward, and the Y direction positive out
339 the right wing. The wind frame is defined with the X axis pointing into the velocity
340 vector, the Z axis perpendicular to the X axis, in the aircraft XZ plane, and the Y
341 axis completing the system. The local axis is a navigational frame with X pointing north,
342 Y pointing east, and Z pointing down. This is a locally vertical, locally horizontal
343 frame, with the XY plane tangent to the geocentric surface. */
344 virtual void GustFrame(eGustFrame gFrame) {oneMinusCosineGust.gustFrame = gFrame;}
345 /// Specifies the X component of velocity in the specified gust frame (ft/sec).
346 virtual void GustXComponent(double x) {oneMinusCosineGust.vWind(eX) = x;}
347 /// Specifies the Y component of velocity in the specified gust frame (ft/sec).
348 virtual void GustYComponent(double y) {oneMinusCosineGust.vWind(eY) = y;}
349 /// Specifies the Z component of velocity in the specified gust frame (ft/sec).
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; ///< in ft/s
386 int probability_of_exceedence_index; ///< this is bound as the severity property
387 FGTable *POE_Table; ///< probability of exceedence 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