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 "TestUtil.hpp"
24 #include "GlideSolvers/GlidePolar.hpp"
25 #include "Units/System.hpp"
45 GlidePolarTest::Init()
47 // Polar 1 from PolarStore (206 Hornet)
48 polar
.SetCoefficients(PolarCoefficients(fixed(0.0022032), fixed(-0.08784),
51 polar
.SetReferenceMass(fixed(318), false);
52 polar
.SetDryMass(fixed(318), false);
53 polar
.SetBallastRatio(fixed(100) / polar
.reference_mass
);
55 polar
.SetWingArea(fixed(9.8));
57 // No ballast and no bugs on the wings
58 polar
.ballast
= fixed(0);
59 polar
.bugs
= fixed(1);
64 polar
.SetVMax(Units::ToSysUnit(fixed(200), Unit::KILOMETER_PER_HOUR
), false);
68 GlidePolarTest::TestBasic()
72 ok1(equals(polar
.polar
.a
, polar
.ideal_polar
.a
));
73 ok1(equals(polar
.polar
.b
, polar
.ideal_polar
.b
));
74 ok1(equals(polar
.polar
.c
, polar
.ideal_polar
.c
));
76 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR
)), 0.606));
77 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR
)), 0.99));
78 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR
)), 1.918));
80 ok1(equals(polar
.GetSMax(), polar
.SinkRate(polar
.GetVMax())));
82 ok1(equals(polar
.GetVMin(), 19.934640523));
83 ok1(equals(polar
.GetSMin(), polar
.SinkRate(polar
.GetVMin())));
84 ok1(equals(polar
.GetVTakeoff(), polar
.GetVMin() / 2));
86 ok1(equals(polar
.GetVBestLD(), 25.830434162));
87 ok1(equals(polar
.GetSBestLD(), polar
.SinkRate(polar
.GetVBestLD())));
88 ok1(equals(polar
.GetBestLD(), polar
.GetVBestLD() / polar
.GetSBestLD()));
90 ok1(equals(polar
.GetTotalMass(), 318));
91 ok1(equals(polar
.GetWingLoading(), 32.448979592));
92 ok1(equals(polar
.GetBallast(), 0));
93 ok1(equals(polar
.GetBallastLitres(), 0));
94 ok1(polar
.IsBallastable());
95 ok1(!polar
.HasBallast());
99 GlidePolarTest::TestBallast()
101 polar
.SetBallast(fixed(0.25));
103 ok1(equals(polar
.GetBallastLitres(), 25));
104 ok1(equals(polar
.GetBallast(), 0.25));
106 polar
.SetBallastLitres(fixed(50));
108 ok1(equals(polar
.GetBallastLitres(), 50));
109 ok1(equals(polar
.GetBallast(), 0.5));
110 ok1(equals(polar
.GetTotalMass(), 368));
111 ok1(equals(polar
.GetWingLoading(), 37.551020408));
112 ok1(polar
.HasBallast());
114 fixed loading_factor
= sqrt(polar
.GetTotalMass() / polar
.reference_mass
);
115 ok1(equals(polar
.polar
.a
, polar
.ideal_polar
.a
/ loading_factor
));
116 ok1(equals(polar
.polar
.b
, polar
.ideal_polar
.b
));
117 ok1(equals(polar
.polar
.c
, polar
.ideal_polar
.c
* loading_factor
));
119 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR
)),
121 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR
)),
123 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR
)),
126 ok1(equals(polar
.GetVMin(), 21.44464));
127 ok1(equals(polar
.GetVBestLD(), 27.78703));
129 polar
.SetBallast(fixed(0));
130 ok1(!polar
.HasBallast());
134 GlidePolarTest::TestBugs()
136 polar
.SetBugs(fixed(0.75));
137 ok1(equals(polar
.GetBugs(), 0.75));
139 ok1(equals(polar
.polar
.a
, polar
.ideal_polar
.a
* 4 / 3));
140 ok1(equals(polar
.polar
.b
, polar
.ideal_polar
.b
* 4 / 3));
141 ok1(equals(polar
.polar
.c
, polar
.ideal_polar
.c
* 4 / 3));
143 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(80), Unit::KILOMETER_PER_HOUR
)),
145 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(120), Unit::KILOMETER_PER_HOUR
)),
147 ok1(equals(polar
.SinkRate(Units::ToSysUnit(fixed(160), Unit::KILOMETER_PER_HOUR
)),
150 ok1(equals(polar
.GetVMin(), 19.93464));
151 ok1(equals(polar
.GetVBestLD(), 25.83043));
153 polar
.SetBugs(fixed(1));
157 GlidePolarTest::TestMC()
159 polar
.SetMC(fixed(1));
160 ok1(equals(polar
.GetVBestLD(), 33.482780452));
162 polar
.SetMC(fixed(0));
163 ok1(equals(polar
.GetVBestLD(), 25.830434162));
167 GlidePolarTest::Run()
176 int main(int argc
, char **argv
)
183 return exit_status();