3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "test_debug.hpp"
24 #include "GlideSolvers/GlideSettings.hpp"
25 #include "GlideSolvers/GlidePolar.hpp"
26 #include "GlideSolvers/GlideState.hpp"
27 #include "GlideSolvers/GlideResult.hpp"
28 #include "GlideSolvers/MacCready.hpp"
29 #include "Navigation/Aircraft.hpp"
30 #include "OS/FileUtil.hpp"
37 const fixed
Vmin(5.0);
40 polar_mc(std::ofstream
&ofile
, const fixed mc
)
43 ofile
<< (double)mc
<< " "
44 << (double)polar
.GetVBestLD() << " "
45 << (double)polar
.GetBestLD() << " "
46 << (double)polar
.GetVMin() << " "
47 << (double)polar
.GetSMin() << " "
48 << (double)polar
.GetVMax() << " "
49 << (double)polar
.GetSMax() << "\n";
53 basic_polar(const fixed mc
)
56 sprintf(bname
,"output/results/res-polar-%02d-best.txt",(int)(mc
*10));
57 std::ofstream
pfile("output/results/res-polar.txt");
58 std::ofstream
mfile(bname
);
61 for (fixed V
= Vmin
; V
<= polar
.GetVMax(); V
+= fixed(0.25)) {
62 pfile
<< (double)mc
<< " "
64 << -(double)polar
.SinkRate(V
) << " "
65 << (double)(V
/polar
.SinkRate(V
))
72 << " " << (double)polar
.GetBestLD()
75 << " " << (double)polar
.GetVBestLD()
76 << " " << -(double)polar
.GetSBestLD()
77 << " " << (double)polar
.GetBestLD()
83 test_glide_alt(const fixed h
, const fixed W
, const fixed Wangle
,
86 GlideSettings settings
;
87 settings
.SetDefaults();
89 GlidePolar
polar(fixed(0));
90 polar
.SetMC(fixed(1));
93 ac
.wind
.norm
= fabs(W
);
95 ac
.wind
.bearing
= Angle::Degrees(fixed(180)+Wangle
);
97 ac
.wind
.bearing
= Angle::Degrees(Wangle
);
101 GeoVector
vect(fixed(400.0), Angle::Zero());
102 GlideState
gs(vect
, fixed(0), ac
.altitude
, ac
.wind
);
103 GlideResult gr
= MacCready::Solve(settings
, polar
, gs
);
104 hfile
<< (double)h
<< " "
105 << (double)gr
.altitude_difference
<< " "
106 << (double)gr
.time_elapsed
<< " "
107 << (double)gr
.v_opt
<< " "
109 << (double)Wangle
<< " "
114 test_glide_stf(const fixed h
, const fixed W
, const fixed Wangle
, const fixed S
,
117 GlideSettings settings
;
118 settings
.SetDefaults();
120 GlidePolar
polar(fixed(0));
121 polar
.SetMC(fixed(1));
124 ac
.wind
.norm
= fabs(W
);
126 ac
.wind
.bearing
= Angle::Degrees(fixed(180)+Wangle
);
128 ac
.wind
.bearing
= Angle::Degrees(Wangle
);
133 GeoVector
vect(fixed(400.0), Angle::Zero());
134 GlideState
gs(vect
, fixed(0), ac
.altitude
, ac
.wind
);
135 GlideResult gr
= MacCready::Solve(settings
, polar
, gs
);
137 fixed Vstf
= polar
.SpeedToFly(ac
, gr
, false);
139 hfile
<< (double)h
<< " "
140 << (double)gr
.altitude_difference
<< " "
141 << (double)gr
.v_opt
<< " "
142 << (double)Vstf
<< " "
144 << (double)Wangle
<< " "
145 << (double)ac
.netto_vario
<< " "
152 { // variation with height
153 std::ofstream
hfile("output/results/res-polar-s0.txt");
154 for (fixed h
=fixed(0); h
<fixed(40.0); h
+= fixed(0.1)) {
155 test_glide_stf(h
,fixed(0),fixed(0),fixed(0),hfile
);
158 { // variation with S, below FG
159 std::ofstream
hfile("output/results/res-polar-s1.txt");
160 for (fixed S
=fixed(-4.0); S
<fixed(4.0); S
+= fixed(0.1)) {
161 test_glide_stf(fixed(0), fixed(0),fixed(0),S
, hfile
);
164 { // variation with S, above FG
165 std::ofstream
hfile("output/results/res-polar-s2.txt");
166 for (fixed S
=fixed(-4.0); S
<fixed(4.0); S
+= fixed(0.1)) {
167 test_glide_stf(fixed(40), fixed(0),fixed(0),S
, hfile
);
170 { // variation with S, below FG, wind
171 std::ofstream
hfile("output/results/res-polar-s3.txt");
172 for (fixed S
=fixed(-4.0); S
<fixed(4.0); S
+= fixed(0.1)) {
173 test_glide_stf(fixed(0), fixed(10.0), fixed(0),S
, hfile
);
176 { // variation with S, above FG, wind
177 std::ofstream
hfile("output/results/res-polar-s4.txt");
178 for (fixed S
=fixed(-4.0); S
<fixed(4.0); S
+= fixed(0.1)) {
179 test_glide_stf(fixed(40), fixed(10.0), fixed(0), S
, hfile
);
189 std::ofstream
ofile("output/results/res-polar-m.txt");
190 for (fixed mc
=fixed(0); mc
<fixed(5.0); mc
+= fixed(0.1)) {
197 std::ofstream
hfile("output/results/res-polar-h-00.txt");
198 for (fixed h
=fixed(0); h
<fixed(40.0); h
+= fixed(0.1)) {
199 test_glide_alt(h
, fixed(0), fixed(0), hfile
);
204 std::ofstream
hfile("output/results/res-polar-h-50.txt");
205 for (fixed h
=fixed(0); h
<fixed(40.0); h
+= fixed(0.1)) {
206 test_glide_alt(h
, fixed(5.0), fixed(0), hfile
);
211 std::ofstream
hfile("output/results/res-polar-w.txt");
212 for (fixed w
=fixed(-10.0); w
<=fixed(10.0); w
+= fixed(0.1)) {
213 test_glide_alt(fixed(50.0), w
, fixed(0), hfile
);
218 std::ofstream
hfile("output/results/res-polar-a.txt");
219 for (fixed a
=fixed(0); a
<=fixed(360.0); a
+= fixed(10)) {
220 test_glide_alt(fixed(50.0), fixed(10.0), a
, hfile
);
227 test_glide_cb(const fixed h
, const fixed W
, const fixed Wangle
,
230 GlideSettings settings
;
231 settings
.SetDefaults();
233 GlidePolar
polar(fixed(1));
236 ac
.wind
.norm
= fabs(W
);
238 ac
.wind
.bearing
= Angle::Degrees(fixed(180)+Wangle
);
240 ac
.wind
.bearing
= Angle::Degrees(Wangle
);
244 GeoVector
vect(fixed(400.0), Angle::Zero());
245 GlideState
gs (vect
, fixed(0), ac
.altitude
, ac
.wind
);
246 GlideResult gr
= MacCready::Solve(settings
, polar
, gs
);
250 hfile
<< (double)W
<< " "
251 << (double)Wangle
<< " "
252 << (double)gr
.vector
.bearing
.Degrees() << " "
253 << (double)gr
.cruise_track_bearing
.Degrees() << " "
261 std::ofstream
hfile("output/results/res-polar-cb.txt");
262 for (fixed a
= fixed(0); a
<= fixed(360.0); a
+= fixed(10)) {
263 test_glide_cb(fixed(0), fixed(10.0), a
, hfile
);
273 Directory::Create(_T("output/results"));
275 ok(test_mc(),"mc output",0);
276 ok(test_stf(),"mc stf",0);
277 ok(test_cb(),"cruise bearing",0);
279 return exit_status();