Debian Codegraph @

src/FDM/YASim/Surface.hpp

raw symbols SCIP
1 #ifndef _SURFACE_HPP
2 #define _SURFACE_HPP
3
4 #include <simgear/props/props.hxx>
5 #include "Version.hpp"
6 #include "Math.hpp"
7 #include "Wing.hpp"
8
9 namespace yasim {
10
11 // FIXME: need a "chord" member for calculating moments. Generic
12 // forces act at the center, but "pre-stall" lift acts towards the
13 // front, and flaps act (in both lift and drag) toward the back.
14 class Surface
15 {
16 static int s_idGenerator;
17 int _id; //index for property tree
18
19 public:
20 Surface(Version * version, const float* pos, float c0);
21
22 int getID() const { return _id; };
23 static void resetIDgen() { s_idGenerator = 0; };
24
25 // Position of this surface in local coords
26 void setPosition(const float* p);
27 void getPosition(float* out) const { Math::set3(_pos, out); }
28
29 // Distance scale along the X axis used for torque (pitch) calculation
30 void setChord(float chord);
31
32 // Slats act to move the stall peak by the specified angle, and
33 // increase drag by the multiplier specified.
34 void setSlatParams(float stallDelta, float dragPenalty);
35
36 // Flaps add to lift coefficient, and multiply drag.
37 void setFlapParams(float liftAdd, float dragPenalty);
38
39 // Spoilers reduce the pre-stall lift, and multiply drag.
40 void setSpoilerParams(float liftPenalty, float dragPenalty);
41
42 // Positions for the controls, in the range [0:1]. [-1:1] for
43 // flaps, with positive meaning "force goes towards positive Z"
44 void setFlapPos(float pos);
45 void setSlatPos(float pos);
46 void setSpoilerPos(float pos);
47
48 // Modifier for flap lift coefficient, useful for simulating flap blowing etc.
49 void setFlapEffectiveness(float effectiveness) { _flapEffectiveness = effectiveness; }
50 double getFlapEffectiveness() const { return _flapEffectiveness; }
51
52 // local -> Surface coords
53 void setOrientation(const float* o);
54
55 // For variable-incidence control surfaces. The angle is a
56 // negative rotation about the surface's Y axis, in radians, so
57 // positive is "up" (i.e. "positive AoA")
58 void setIncidence(float angle);
59
60 // The offset from base incidence for this surface.
61 void setTwist(float angle);
62
63 void setTotalForceCoefficient(float c0) { _c0 = c0; }
64 void mulTotalForceCoefficient(float factor) { _c0 *= factor; }
65 float getTotalForceCoefficient() const { return _c0; }
66
67 void setDragCoefficient(float cx) { _cx = cx; }
68 void mulDragCoefficient(float factor) { _cx *= factor; }
69 float getDragCoefficient() const { return _cx; }
70 void setYDrag(float cy) { _cy = cy; }
71 void setLiftCoefficient(float cz) { _cz = cz; }
72 float getLiftCoefficient() const { return _cz; }
73
74 // zero-alpha Z drag ("camber") specified as a fraction of cz
75 void setZeroAlphaLift(float cz0) { _cz0 = cz0; }
76
77 // i: 0 == forward, 1 == backwards
78 void setStallPeak(int i, float peak) { _peaks[i] = peak; }
79
80 // i: 0 == fwd/+z, 1 == fwd/-z, 2 == rev/+z, 3 == rev/-z
81 void setStall(int i, float alpha) { _stalls[i] = alpha; }
82 void setStallWidth(int i, float width) { _widths[i] = width; }
83
84 // Induced drag multiplier
85 void setInducedDrag(float mul) { _inducedDrag = mul; }
86
87 void calcForce(const float* v, const float rho, float mach, float* out, float* torque);
88
89 float getAlpha() const { return _alpha; };
90 float getStallAlpha() const { return _stallAlpha; };
91
92 void setFlowRegime(FlowRegime flow) { _flow = flow; };
93 FlowRegime getFlowRegime() { return _flow; };
94
95 void setCriticalMachNumber(float mach) { _Mcrit = mach; };
96 float getCriticalMachNumber() const { return _Mcrit; };
97
98 private:
99 SGPropertyNode_ptr _surfN;
100 Version * _version;
101
102 float stallFunc(float* v);
103 float flapLift(float alpha);
104 float controlDrag(float lift, float drag);
105
106 float _chord {0}; // X-axis size
107 float _c0 {1}; // total force coefficient
108 float _cx {1}; // X-axis force coefficient
109 float _cy {1}; // Y-axis force coefficient
110 float _cz {1}; // Z-axis force coefficient
111 float _cz0 {0}; // Z-axis force offset
112 float _peaks[2] {1, 1}; // Stall peak coefficients (fwd, back)
113 float _stalls[4] {0, 0, 0, 0}; // Stall angles (fwd/back, pos/neg)
114 float _widths[4] {0.01f, 0.01f, 0.01f, 0.01f}; // Stall widths
115 float _pos[3]; // position in local coords
116 float _orient[9]; // local->surface orthonormal matrix
117
118 float _slatAlpha {0};
119 float _slatDrag {1};
120 float _flapLift {0};
121 float _flapDrag {1};
122 float _flapEffectiveness {1};
123 float _spoilerLift {1};
124 float _spoilerDrag {1};
125
126 float _slatPos {0};
127 float _flapPos {0};
128 float _spoilerPos {0};
129 float _incidence {0};
130 float _twist {0};
131 float _inducedDrag {1};
132
133 // used during calculations
134 float _stallAlpha {0};
135 float _alpha {0};
136
137 FlowRegime _flow{FLOW_SUBSONIC};
138 float _Mcrit {0.6f};
139
140 std::vector<float> pg_coefficients {-1.7671f, 0.4495f, 10.3423f, -6.9237f};
141
142 SGPropertyNode* _fxN;
143 SGPropertyNode* _fyN;
144 SGPropertyNode* _fzN;
145 SGPropertyNode* _stallAlphaN;
146 SGPropertyNode* _alphaN;
147 SGPropertyNode* _flapN;
148 SGPropertyNode* _slatN;
149 SGPropertyNode* _spoilerN;
150 SGPropertyNode* _fabsN;
151 SGPropertyNode* _incidenceN;
152 SGPropertyNode* _twistN;
153 SGPropertyNode* _pgCorrectionN;
154 SGPropertyNode* _dcdwaveN;
155 };
156
157 }; // namespace yasim
158 #endif // _SURFACE_HPP