Debian Codegraph @

test_suite/system_tests/FDM/testAeroMesh.cxx

raw symbols SCIP
1 #include "testAeroMesh.hxx"
2
3 #include "test_suite/FGTestApi/testGlobals.hxx"
4 #include "test_suite/FGTestApi/PrivateAccessorFDM.hxx"
5 #include "test_suite/FGTestApi/scene_graph.hxx"
6
7 #include <vector>
8 #include <map>
9 #include <iostream>
10
11 #include <simgear/constants.h>
12 #include <simgear/misc/test_macros.hxx>
13 #include <simgear/math/SGVec3.hxx>
14 #include <simgear/math/SGGeod.hxx>
15 #include <simgear/math/SGQuat.hxx>
16 #include <simgear/math/SGGeoc.hxx>
17 #include <simgear/props/props.hxx>
18
19 #include <AIModel/AIAircraft.hxx>
20 #include <AIModel/AIManager.hxx>
21 #include <AIModel/performancedata.hxx>
22 #include <AIModel/performancedb.hxx>
23 #include "FDM/AIWake/AircraftMesh.hxx"
24 #include "FDM/AIWake/AIWakeGroup.hxx"
25 extern "C" {
26 #include "src/FDM/LaRCsim/ls_matrix.h"
27 }
28
29 #include "FDM/JSBSim/math/FGLocation.h"
30 #include "FDM/JSBSim/math/FGQuaternion.h"
31
32 #include <Main/globals.hxx>
33
34
35 using namespace std;
36 using namespace JSBSim;
37
38 double rho = 2.0E-3;
39
40
41 // Set up function for each test.
42 void AeroMeshTests::setUp()
43 {
44 FGTestApi::setUp::initTestGlobals("aeromesh");
45 FGTestApi::setUp::initScenery();
46 globals->get_props()->getNode("environment/density-slugft3", true)
47 ->setDoubleValue(rho);
48 }
49
50
51 // Clean up after each test.
52 void AeroMeshTests::tearDown()
53 {
54 FGTestApi::tearDown::shutdownTestGlobals();
55 }
56
57
58 void AeroMeshTests::testLiftComputation()
59 {
60 double b = 10.0;
61 double c = 2.0;
62 AircraftMesh_ptr mesh = new AircraftMesh(b, c, "test");
63 SGGeod geodPos = SGGeod::fromDeg(0.0, 0.0);
64 SGVec3d pos;
65 double vel = 100.;
66 double weight = 50.;
67
68 SGGeodesy::SGGeodToCart(geodPos, pos);
69 mesh->setPosition(pos, SGQuatd::unit());
70
71 SGPropertyNode* props = globals->get_props()->getNode("ai/models", true);
72 props->setDoubleValue("acceleration-kts-hour", 0.0);
73 props->setDoubleValue("deceleration-kts-hour", 0.0);
74 props->setDoubleValue("climbrate-fpm", 0.0);
75 props->setDoubleValue("decentrate-fpm", 0.0);
76 props->setDoubleValue("rotate-speed-kts", 0.0);
77 props->setDoubleValue("takeoff-speed-kts", 0.0);
78 props->setDoubleValue("climb-speed-kts", 0.0);
79 props->setDoubleValue("cruise-speed-kts", 0.0);
80 props->setDoubleValue("decent-speed-kts", 0.0);
81 props->setDoubleValue("approach-speed-kts", 0.0);
82 props->setDoubleValue("touchdown-speed-kts", 0.0);
83 props->setDoubleValue("taxi-speed-kts", 0.0);
84 props->setDoubleValue("geometry/wing/span-ft", b);
85 props->setDoubleValue("geometry/wing/chord-ft", c);
86 props->setDoubleValue("geometry/weight-lbs", weight);
87
88 auto subsystem_mgr = globals->get_subsystem_mgr();
89 subsystem_mgr->add<PerformanceDB>();
90 subsystem_mgr->get_subsystem<PerformanceDB>()->bind();
91 subsystem_mgr->get_subsystem<PerformanceDB>()->init();
92
93 FGAIManager *aiManager = new FGAIManager;
94 FGAIAircraft *ai = new FGAIAircraft;
95 ai->setGeodPos(geodPos);
96 ai->setSpeed(vel * SG_FPS_TO_KT);
97 ai->setPerformance("", "jet_transport");
98 ai->getPerformance()->initFromProps(props);
99 aiManager->attach(ai);
100
101 AIWakeGroup wg;
102 wg.AddAI(ai);
103
104 SGVec3d force = mesh->GetForce(wg, SGVec3d(vel, 0., 0.), rho);
105
106 CPPUNIT_ASSERT_DOUBLES_EQUAL(force[1], 0.0, 1e-9);
107 CPPUNIT_ASSERT_DOUBLES_EQUAL(force[2], -weight, 1e-9);
108
109 SGVec3d moment = mesh->GetMoment();
110 CPPUNIT_ASSERT_DOUBLES_EQUAL(moment[0], 0.0, 1e-9);
111 CPPUNIT_ASSERT_DOUBLES_EQUAL(moment[1], -0.5*weight, 1e-9);
112 CPPUNIT_ASSERT_DOUBLES_EQUAL(moment[2], 0.0, 1e-9);
113
114 auto accessor = FGTestApi::PrivateAccessor::FDM::Accessor();
115
116 for (int i=1; i<= accessor.read_FDM_AIWake_WakeMesh_nelm(mesh); ++i)
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_WakeMesh_Gamma(accessor.read_FDM_AIWake_AIWakeGroup_aiWakeData(&wg, 1))[i][1],
118 accessor.read_FDM_AIWake_WakeMesh_Gamma(mesh)[i][1], 1e-9);
119 }
120
121
122 void AeroMeshTests::testFourierLiftingLine()
123 {
124 double b = 10.0;
125 double c = 2.0;
126 double vel = 100.;
127 double weight = 50.;
128
129 auto accessor = FGTestApi::PrivateAccessor::FDM::Accessor();
130
131 WakeMesh_ptr mesh = new WakeMesh(b, c, "testMesh");
132 int N = accessor.read_FDM_AIWake_WakeMesh_nelm(mesh);
133 double **mtx = nr_matrix(1, N, 1, N);
134 double **coef = nr_matrix(1, N, 1, 1);
135
136 mesh->computeAoA(vel, rho, weight);
137
138 for (int m=1; m<=N; ++m) {
139 double vm = M_PI*m/(N+1);
140 double sm = sin(vm);
141 coef[m][1] = c*M_PI/(2*b);
142 for (int n=1; n<=N; ++n)
143 mtx[m][n] = sin(n*vm)*(1.0+coef[m][1]*n/sm);
144 }
145
146 nr_gaussj(mtx, N, coef, 1);
147
148 double S = b*c;
149 double AR = b*b/S;
150 double lift = 0.5*rho*S*vel*vel*coef[1][1]*M_PI*AR;
151 double sinAlpha = weight / lift;
152 lift *= sinAlpha;
153
154 cout << "y, Lift (Fourier), Lift (VLM), Corrected lift (VLM)" << endl;
155
156 for (int i=1; i<=N; ++i) {
157 double y = accessor.read_FDM_AIWake_WakeMesh_elements(mesh)[i-1]->getBoundVortexMidPoint()[1];
158 double theta = acos(2.0*y/b);
159 double gamma = 0.0;
160 for (int n=1; n<=N; ++n)
161 gamma += coef[n][1]*sin(n*theta);
162
163 gamma *= 2.0*b*vel*sinAlpha;
164
165 cout << y << ", " << gamma << ", " << accessor.read_FDM_AIWake_WakeMesh_Gamma(mesh)[i][1] << ", "
166 << accessor.read_FDM_AIWake_WakeMesh_Gamma(mesh)[i][1] / gamma - 1.0 << endl;
167 }
168
169 nr_free_matrix(mtx, 1, N, 1, N);
170 nr_free_matrix(coef, 1, N, 1, 1);
171 }
172
173
174 void AeroMeshTests::testFrameTransformations()
175 {
176 double b = 10.0;
177 double c = 2.0;
178 double yaw = 80. * SGD_DEGREES_TO_RADIANS;
179 double pitch = 5. * SGD_DEGREES_TO_RADIANS;
180 double roll = -10. * SGD_DEGREES_TO_RADIANS;
181 SGQuatd orient = SGQuatd::fromYawPitchRoll(yaw, pitch, roll);
182 SGGeod geodPos = SGGeod::fromDeg(45.0, 10.0);
183 SGVec3d pos;
184
185 SGGeodesy::SGGeodToCart(geodPos, pos);
186 SGGeoc geoc = SGGeoc::fromCart(pos);
187
188 FGLocation loc(geoc.getLongitudeRad(),
189 geoc.getLatitudeRad(),
190 geoc.getRadiusFt());
191
192 CPPUNIT_ASSERT_DOUBLES_EQUAL(pos[0] * SG_METER_TO_FEET, loc(1), 1e-7);
193 CPPUNIT_ASSERT_DOUBLES_EQUAL(pos[1] * SG_METER_TO_FEET, loc(2), 1e-7);
194 CPPUNIT_ASSERT_DOUBLES_EQUAL(pos[2] * SG_METER_TO_FEET, loc(3), 1e-7);
195
196 AircraftMesh_ptr mesh = new AircraftMesh(b, c, "test");
197 mesh->setPosition(pos, orient);
198
199 FGQuaternion qJ(roll, pitch, yaw);
200 FGMatrix33 Tb2l = qJ.GetTInv();
201 FGColumnVector3 refPos = loc.GetTec2l() * loc;
202
203 for (int i=0; i < 4; ++i)
204 CPPUNIT_ASSERT_DOUBLES_EQUAL(orient(i), qJ((i+1) % 4 + 1), 1e-9);
205
206 auto accessor = FGTestApi::PrivateAccessor::FDM::Accessor();
207
208 for (int i=0; i < accessor.read_FDM_AIWake_WakeMesh_nelm(mesh); ++i) {
209 SGVec3d pt = accessor.read_FDM_AIWake_WakeMesh_elements(mesh)[i]->getBoundVortexMidPoint();
210 FGColumnVector3 ptJ(pt[0], pt[1], pt[2]);
211 FGColumnVector3 p = loc.GetTl2ec() * (refPos + Tb2l * ptJ);
212 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_AircraftMesh_midPt(mesh)[i][0], p(1), 1e-7);
213 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_AircraftMesh_midPt(mesh)[i][1], p(2), 1e-7);
214 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_AircraftMesh_midPt(mesh)[i][2], p(3), 1e-7);
215
216 pt = accessor.read_FDM_AIWake_WakeMesh_elements(mesh)[i]->getCollocationPoint();
217 ptJ.InitMatrix(pt[0], pt[1], pt[2]);
218 p = loc.GetTl2ec() * (refPos + Tb2l * ptJ);
219 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_AircraftMesh_collPt(mesh)[i][0], p(1), 1e-7);
220 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_AircraftMesh_collPt(mesh)[i][1], p(2), 1e-7);
221 CPPUNIT_ASSERT_DOUBLES_EQUAL(accessor.read_FDM_AIWake_AircraftMesh_collPt(mesh)[i][2], p(3), 1e-7);
222 }
223 }