| 1 | // AeroElement.cxx -- Mesh element for the computation of a wing wake. |
| 2 | // |
| 3 | // Written by Bertrand Coconnier, started March 2017. |
| 4 | // |
| 5 | // Copyright (C) 2017 Bertrand Coconnier - [email protected] |
| 6 | // |
| 7 | // This program is free software; you can redistribute it and/or modify it under |
| 8 | // the terms of the GNU General Public License as published by the Free Software |
| 9 | // Foundation; either version 2 of the License, or (at your option) any later |
| 10 | // version. |
| 11 | // |
| 12 | // This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 14 | // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 15 | // details. |
| 16 | // |
| 17 | // You should have received a copy of the GNU General Public License along with |
| 18 | // this program; if not, write to the Free Software Foundation, Inc., 51 |
| 19 | // Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | // |
| 21 | // $Id$ |
| 22 | |
| 23 | #include <cmath> |
| 24 | |
| 25 | #include <simgear/structure/SGSharedPtr.hxx> |
| 26 | #include <simgear/math/SGVec3.hxx> |
| 27 | #include "AeroElement.hxx" |
| 28 | |
| 29 | AeroElement::AeroElement(const SGVec3d& n1, const SGVec3d& n2, |
| 30 | const SGVec3d& n3, const SGVec3d& n4) |
| 31 | { |
| 32 | p1 = 0.75*n2 + 0.25*n1; |
| 33 | p2 = 0.75*n3 + 0.25*n4; |
| 34 | normal = normalize(cross(n3 - n1, n2 - n4)); |
| 35 | collocationPt = 0.375*(n1 + n4) + 0.125*(n2 + n3); |
| 36 | } |
| 37 | |
| 38 | SGVec3d AeroElement::vortexInducedVel(const SGVec3d& p, const SGVec3d& n1, |
| 39 | const SGVec3d& n2) const |
| 40 | { |
| 41 | SGVec3d r0 = n2-n1, r1 = p-n1, r2 = p-n2; |
| 42 | SGVec3d v = cross(r1, r2); |
| 43 | double vSqrNorm = dot(v, v); |
| 44 | double r1SqrNorm = dot(r1, r1); |
| 45 | double r2SqrNorm = dot(r2, r2); |
| 46 | |
| 47 | if ((vSqrNorm < 1E-6) || (r1SqrNorm < 1E-6) || (r2SqrNorm < 1E-6)) |
| 48 | return SGVec3d::zeros(); |
| 49 | |
| 50 | r1 /= sqrt(r1SqrNorm); |
| 51 | r2 /= sqrt(r2SqrNorm); |
| 52 | v *= dot(r0, r1-r2) / (4.0*M_PI*vSqrNorm); |
| 53 | |
| 54 | return v; |
| 55 | } |
| 56 | |
| 57 | SGVec3d AeroElement::semiInfVortexInducedVel(const SGVec3d& point, |
| 58 | const SGVec3d& vEnd, |
| 59 | const SGVec3d& vDir) const |
| 60 | { |
| 61 | SGVec3d r = point-vEnd; |
| 62 | double rSqrNorm = dot(r, r); |
| 63 | double denom = rSqrNorm - dot(r, vDir)*sqrt(rSqrNorm); |
| 64 | |
| 65 | if (fabs(denom) < 1E-6) |
| 66 | return SGVec3d::zeros(); |
| 67 | |
| 68 | SGVec3d v = cross(r, vDir); |
| 69 | v /= 4*M_PI*denom; |
| 70 | |
| 71 | return v; |
| 72 | } |
| 73 | |
| 74 | SGVec3d AeroElement::getInducedVelocity(const SGVec3d& p) const |
| 75 | { |
| 76 | const SGVec3d w(-1.,0.,0.); |
| 77 | SGVec3d v = semiInfVortexInducedVel(p, p1, w); |
| 78 | v -= semiInfVortexInducedVel(p, p2, w); |
| 79 | v += vortexInducedVel(p, p1, p2); |
| 80 | |
| 81 | return v; |
| 82 | } |