Debian Codegraph @

src/FDM/AIWake/AircraftMesh.cxx

raw symbols SCIP
1 // AircraftMesh.cxx -- Mesh for the computation of the wake induced force and
2 // moment on an aircraft.
3
4 // Written by Bertrand Coconnier, started March 2017.
5 //
6 // Copyright (C) 2017 Bertrand Coconnier - [email protected]
7 //
8 // This program is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License as published by the Free Software
10 // Foundation; either version 2 of the License, or (at your option) any later
11 // version.
12 //
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 // details.
17 //
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc., 51
20 // Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 //
22 // $Id$
23
24 #include <vector>
25 #include <cmath>
26
27 #include <simgear/structure/SGSharedPtr.hxx>
28 #include <simgear/math/SGVec3.hxx>
29 #include <simgear/math/SGGeoc.hxx>
30 #include <simgear/math/SGGeod.hxx>
31 #include <simgear/math/SGQuat.hxx>
32 #include "AircraftMesh.hxx"
33 #include <FDM/flight.hxx>
34 #include "AIWakeGroup.hxx"
35 #include "AIModel/AIAircraft.hxx"
36 extern "C" {
37 #include "../LaRCsim/ls_matrix.h"
38 }
39
40 AircraftMesh::AircraftMesh(double _span, double _chord, const std::string& name)
41 : WakeMesh(_span, _chord, name)
42 {
43 collPt.resize(nelm, SGVec3d::zeros());
44 midPt.resize(nelm, SGVec3d::zeros());
45 }
46
47 void AircraftMesh::setPosition(const SGVec3d& _pos, const SGQuatd& orient)
48 {
49 SGVec3d pos = _pos * SG_METER_TO_FEET;
50 SGGeoc geoc = SGGeoc::fromCart(pos);
51 SGQuatd Te2l = SGQuatd::fromLonLatRad(geoc.getLongitudeRad(),
52 geoc.getLatitudeRad());
53 Te2b = Te2l * orient;
54
55 for (int i=0; i<nelm; ++i) {
56 SGVec3d pt = elements[i]->getCollocationPoint();
57 collPt[i] = pos + Te2b.backTransform(pt);
58 pt = elements[i]->getBoundVortexMidPoint();
59 midPt[i] = pos + Te2b.backTransform(pt);
60 }
61 }
62
63 SGVec3d AircraftMesh::GetForce(const AIWakeGroup& wg, const SGVec3d& vel,
64 double rho)
65 {
66 std::vector<double> rhs;
67 rhs.resize(nelm, 0.0);
68
69 for (int i=0; i<nelm; ++i)
70 rhs[i] = dot(elements[i]->getNormal(),
71 Te2b.transform(wg.getInducedVelocityAt(collPt[i])));
72
73 for (int i=1; i<=nelm; ++i) {
74 Gamma[i][1] = 0.0;
75 for (int k=1; k<=nelm; ++k)
76 Gamma[i][1] += influenceMtx[i][k]*rhs[k-1];
77 }
78
79 SGVec3d f(0.,0.,0.);
80 moment = SGVec3d::zeros();
81
82 for (int i=0; i<nelm; ++i) {
83 SGVec3d mp = elements[i]->getBoundVortexMidPoint();
84 SGVec3d v = Te2b.transform(wg.getInducedVelocityAt(midPt[i]));
85 v += getInducedVelocityAt(mp);
86
87 // The minus sign before vel to transform the aircraft velocity from the
88 // body frame to wind frame.
89 SGVec3d Fi = rho*Gamma[i+1][1]*cross(v-vel,
90 elements[i]->getBoundVortex());
91 f += Fi;
92 moment += cross(mp, Fi);
93 }
94
95 return f;
96 }