From a87442c6f37d23b2e476fcdfa39d857002fd549b Mon Sep 17 00:00:00 2001 From: Henning Stahlke Date: Sat, 25 Feb 2017 14:01:02 +0100 Subject: [PATCH] YASim fix performance problem due to export to prop.tree. --- src/FDM/YASim/FGFDM.cpp | 38 ++++++++++++++++++++----------- src/FDM/YASim/FGFDM.hpp | 12 ++++++++++ src/FDM/YASim/Model.cpp | 43 +++++++++++++---------------------- src/FDM/YASim/Model.hpp | 2 +- src/FDM/YASim/Surface.cpp | 47 ++++++++++++++++++++++++++++----------- src/FDM/YASim/Surface.hpp | 16 +++++++++++-- 6 files changed, 102 insertions(+), 56 deletions(-) diff --git a/src/FDM/YASim/FGFDM.cpp b/src/FDM/YASim/FGFDM.cpp index fb4e5104d..4c69ff51c 100644 --- a/src/FDM/YASim/FGFDM.cpp +++ b/src/FDM/YASim/FGFDM.cpp @@ -133,7 +133,19 @@ void FGFDM::init() _cg_x = _yasimN->getNode("cg-x-m", true); _cg_y = _yasimN->getNode("cg-y-m", true); _cg_z = _yasimN->getNode("cg-z-m", true); - + _vxN = _yasimN->getNode("velocities/v-x", true); + _vyN = _yasimN->getNode("velocities/v-y", true); + _vzN = _yasimN->getNode("velocities/v-z", true); + _vrxN = _yasimN->getNode("velocities/vrot-x", true); + _vryN = _yasimN->getNode("velocities/vrot-y", true); + _vrzN = _yasimN->getNode("velocities/vrot-z", true); + _axN = _yasimN->getNode("accelerations/a-x", true); + _ayN = _yasimN->getNode("accelerations/a-y", true); + _azN = _yasimN->getNode("accelerations/a-z", true); + _arxN = _yasimN->getNode("accelerations/arot-x", true); + _aryN = _yasimN->getNode("accelerations/arot-y", true); + _arzN = _yasimN->getNode("accelerations/arot-z", true); + // Allows the user to start with something other than full fuel _airplane.setFuelFraction(fgGetFloat("/sim/fuel-fraction", 1)); @@ -626,18 +638,18 @@ void FGFDM::setOutputProperties(float dt) Math::vmul33(s->orient, s->rot, rot); Math::vmul33(s->orient, s->racc, racc); - _yasimN->getNode("velocities/v-x", true)->setFloatValue(v[0]); - _yasimN->getNode("velocities/v-y", true)->setFloatValue(v[1]); - _yasimN->getNode("velocities/v-z", true)->setFloatValue(v[2]); - _yasimN->getNode("velocities/vrot-x", true)->setFloatValue(rot[0]); - _yasimN->getNode("velocities/vrot-y", true)->setFloatValue(rot[1]); - _yasimN->getNode("velocities/vrot-z", true)->setFloatValue(rot[2]); - _yasimN->getNode("accelerations/a-x", true)->setFloatValue(acc[0]); - _yasimN->getNode("accelerations/a-y", true)->setFloatValue(acc[1]); - _yasimN->getNode("accelerations/a-z", true)->setFloatValue(acc[2]); - _yasimN->getNode("accelerations/arot-x", true)->setFloatValue(racc[0]); - _yasimN->getNode("accelerations/arot-y", true)->setFloatValue(racc[1]); - _yasimN->getNode("accelerations/arot-z", true)->setFloatValue(racc[2]); + _vxN->setFloatValue(v[0]); + _vyN->setFloatValue(v[1]); + _vzN->setFloatValue(v[2]); + _vrxN->setFloatValue(rot[0]); + _vryN->setFloatValue(rot[1]); + _vrzN->setFloatValue(rot[2]); + _axN->setFloatValue(acc[0]); + _ayN->setFloatValue(acc[1]); + _azN->setFloatValue(acc[2]); + _arxN->setFloatValue(racc[0]); + _aryN->setFloatValue(racc[1]); + _arzN->setFloatValue(racc[2]); ControlMap* cm = _airplane.getControlMap(); for(int i=0; i<_controlProps.size(); i++) { diff --git a/src/FDM/YASim/FGFDM.hpp b/src/FDM/YASim/FGFDM.hpp index 4461d26af..05daa9707 100644 --- a/src/FDM/YASim/FGFDM.hpp +++ b/src/FDM/YASim/FGFDM.hpp @@ -106,6 +106,18 @@ private: std::vector _tank_level_lbs; std::vector _thrust_props; std::vector _fuel_props; + SGPropertyNode* _vxN; + SGPropertyNode* _vyN; + SGPropertyNode* _vzN; + SGPropertyNode* _vrxN; + SGPropertyNode* _vryN; + SGPropertyNode* _vrzN; + SGPropertyNode* _axN; + SGPropertyNode* _ayN; + SGPropertyNode* _azN; + SGPropertyNode* _arxN; + SGPropertyNode* _aryN; + SGPropertyNode* _arzN; }; }; // namespace yasim diff --git a/src/FDM/YASim/Model.cpp b/src/FDM/YASim/Model.cpp index d1464e1ed..096b30336 100644 --- a/src/FDM/YASim/Model.cpp +++ b/src/FDM/YASim/Model.cpp @@ -391,11 +391,11 @@ void Model::calcForces(State* s) _body.addTorque(_torque); int i,j; for(i=0; i<_thrusters.size(); i++) { - Thruster* t = (Thruster*)_thrusters.get(i); - float thrust[3], pos[3]; - t->getThrust(thrust); - t->getPosition(pos); - _body.addForce(pos, thrust); + Thruster* t = (Thruster*)_thrusters.get(i); + float thrust[3], pos[3]; + t->getThrust(thrust); + t->getPosition(pos); + _body.addForce(pos, thrust); } // Get a ground plane in local coordinates. The first three @@ -417,34 +417,23 @@ void Model::calcForces(State* s) // point is different due to rotation. float faero[3]; faero[0] = faero[1] = faero[2] = 0; - int id = 0; - SGPropertyNode_ptr n = fgGetNode("/fdm/yasim/surfaces", true); - SGPropertyNode_ptr surfN; for(i=0; i<_surfaces.size(); i++) { - Surface* sf = (Surface*)_surfaces.get(i); + Surface* sf = (Surface*)_surfaces.get(i); - // Vsurf = wind - velocity + (rot cross (cg - pos)) - float vs[3], pos[3]; - sf->getPosition(pos); - localWind(pos, s, vs, alt); + // Vsurf = wind - velocity + (rot cross (cg - pos)) + float vs[3], pos[3]; + sf->getPosition(pos); + localWind(pos, s, vs, alt); - float force[3], torque[3]; - sf->calcForce(vs, _rho, force, torque); - id = sf->getID(); - if (n != 0) { - surfN = n->getChild("surface", id, true); - surfN->getNode("f-abs", true)->setFloatValue(Math::mag3(force)); - surfN->getNode("f-x", true)->setFloatValue(force[0]); - surfN->getNode("f-y", true)->setFloatValue(force[1]); - surfN->getNode("f-z", true)->setFloatValue(force[2]); - } - Math::add3(faero, force, faero); + float force[3], torque[3]; + sf->calcForce(vs, _rho, force, torque); + Math::add3(faero, force, faero); - _body.addForce(pos, force); - _body.addTorque(torque); + _body.addForce(pos, force); + _body.addTorque(torque); } float ld0 = faero[2]/faero[0]; - n = fgGetNode("/fdm/yasim/forces", true); + SGPropertyNode_ptr n = fgGetNode("/fdm/yasim/forces", true); if (n != 0) { n->getNode("f0-aero-x-drag", true)->setFloatValue(faero[0]); n->getNode("f0-aero-y-side", true)->setFloatValue(faero[1]); diff --git a/src/FDM/YASim/Model.hpp b/src/FDM/YASim/Model.hpp index 8f4d0bad8..f7f9a613c 100644 --- a/src/FDM/YASim/Model.hpp +++ b/src/FDM/YASim/Model.hpp @@ -81,7 +81,7 @@ private: void calcGearForce(Gear* g, float* v, float* rot, float* ground); float gearFriction(float wgt, float v, Gear* g); void localWind(float* pos, State* s, float* out, float alt, - bool is_rotor = false); + bool is_rotor = false); Integrator _integrator; RigidBody _body; diff --git a/src/FDM/YASim/Surface.cpp b/src/FDM/YASim/Surface.cpp index 1a9aa810d..6201fcf00 100644 --- a/src/FDM/YASim/Surface.cpp +++ b/src/FDM/YASim/Surface.cpp @@ -35,9 +35,21 @@ Surface::Surface( Version * version ) : _slatAlpha = 0; _spoilerLift = 1; _inducedDrag = 1; + _stallAlpha = 0; + _alpha = 0; _surfN = fgGetNode("/fdm/yasim/surfaces", true); - if (_surfN != 0) + if (_surfN != 0) { _surfN = _surfN->getChild("surface", _id, true); + _fxN = _surfN->getNode("f-x", true); + _fyN = _surfN->getNode("f-y", true); + _fzN = _surfN->getNode("f-z", true); + _fabsN = _surfN->getNode("f-abs", true); + _alphaN = _surfN->getNode("alpha", true); + _stallAlphaN = _surfN->getNode("stall-alpha", true); + _flapN = _surfN->getNode("flap-pos", true); + _slatN = _surfN->getNode("slat-pos", true); + _spoilerN = _surfN->getNode("spoiler-pos", true); + } } @@ -48,7 +60,7 @@ void Surface::setPosition(float* p) if (_surfN != 0) { _surfN->getNode("pos-x", true)->setFloatValue(p[0]); _surfN->getNode("pos-y", true)->setFloatValue(p[1]); - _surfN->getNode("pos-z", true)->setFloatValue(p[2]); + _surfN->getNode("pos-z", true)->setFloatValue(p[2]); } } @@ -150,10 +162,10 @@ void Surface::setSpoilerParams(float liftPenalty, float dragPenalty) void Surface::setFlapPos(float pos) { - if (_flapPos != pos) { - _flapPos = pos; - if (_surfN != 0) _surfN->getNode("flap-pos", true)->setFloatValue(pos); - } + if (_flapPos != pos) { + _flapPos = pos; + if (_surfN != 0) _flapN->setFloatValue(pos); + } } void Surface::setFlapEffectiveness(float effectiveness) @@ -169,24 +181,24 @@ double Surface::getFlapEffectiveness() void Surface::setSlatPos(float pos) { - if (_slatPos != pos) { + if (_slatPos != pos) { _slatPos = pos; - if (_surfN != 0) _surfN->getNode("slat-pos", true)->setFloatValue(pos); - } + if (_surfN != 0) _slatN->setFloatValue(pos); + } } void Surface::setSpoilerPos(float pos) { - if (_spoilerPos != pos) { + if (_spoilerPos != pos) { _spoilerPos = pos; - if (_surfN != 0) _surfN->getNode("spoiler-pos", true)->setFloatValue(pos); - } + if (_surfN != 0) _spoilerN->setFloatValue(pos); + } } // Calculate the aerodynamic force given a wind vector v (in the // aircraft's "local" coordinates) and an air density rho. Returns a // torque about the Y axis, too. -void Surface::calcForce(float* v, float rho, float* out, float* torque) +void Surface::calcForce(const float* v, const float rho, float* out, float* torque) { // Split v into magnitude and direction: float vel = Math::mag3(v); @@ -270,6 +282,15 @@ void Surface::calcForce(float* v, float rho, float* out, float* torque) float scale = 0.5f*rho*vel*vel*_c0; Math::mul3(scale, out, out); Math::mul3(scale, torque, torque); + // if we have a property tree, export info + if (_surfN != 0) { + _fabsN->setFloatValue(Math::mag3(out)); + _fxN->setFloatValue(out[0]); + _fyN->setFloatValue(out[1]); + _fzN->setFloatValue(out[2]); + _alphaN->setFloatValue(_alpha); + _stallAlphaN->setFloatValue(_stallAlpha); + } } #if 0 diff --git a/src/FDM/YASim/Surface.hpp b/src/FDM/YASim/Surface.hpp index 7b805c666..f3024ece9 100644 --- a/src/FDM/YASim/Surface.hpp +++ b/src/FDM/YASim/Surface.hpp @@ -45,7 +45,7 @@ public: // Modifier for flap lift coefficient, useful for simulating flap blowing etc. void setFlapEffectiveness(float effectiveness); - double getFlapEffectiveness(); + double getFlapEffectiveness(); // local -> Surface coords void setOrientation(float* o); @@ -79,8 +79,11 @@ public: // Induced drag multiplier void setInducedDrag(float mul) { _inducedDrag = mul; } - void calcForce(float* v, float rho, float* forceOut, float* torqueOut); + void calcForce(const float* v, const float rho, float* out, float* torque); + float getAlpha() { return _alpha; }; + float getStallAlpha() { return _stallAlpha; }; + private: SGPropertyNode_ptr _surfN; @@ -120,6 +123,15 @@ private: float _alpha; Version * _version; + SGPropertyNode* _fxN; + SGPropertyNode* _fyN; + SGPropertyNode* _fzN; + SGPropertyNode* _stallAlphaN; + SGPropertyNode* _alphaN; + SGPropertyNode* _flapN; + SGPropertyNode* _slatN; + SGPropertyNode* _spoilerN; + SGPropertyNode* _fabsN; }; }; // namespace yasim