Thread: [Gcblue-commits] gcb_wx/src/database tcAirDBObject.cpp,1.13,1.14
Status: Alpha
Brought to you by:
ddcforge
|
From: Dewitt C. <ddc...@us...> - 2005-05-27 00:28:31
|
Update of /cvsroot/gcblue/gcb_wx/src/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5463/src/database Modified Files: tcAirDBObject.cpp Log Message: Modified air model to use thrust factor vs. altitude and fuel efficiency vs. alt tables Index: tcAirDBObject.cpp =================================================================== RCS file: /cvsroot/gcblue/gcb_wx/src/database/tcAirDBObject.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** tcAirDBObject.cpp 26 May 2005 11:54:11 -0000 1.13 --- tcAirDBObject.cpp 27 May 2005 00:28:21 -0000 1.14 *************** *** 1,6 **** /* ! ** tcAirDBObject.cpp ! ** ! ** Copyright (C) 2003 Dewitt Colclough (de...@tw...) ** All rights reserved. --- 1,6 ---- /* ! ** @file tcAirDBObject.cpp ! */ ! /* Copyright (C) 2003-2005 Dewitt Colclough (de...@tw...) ** All rights reserved. *************** *** 34,38 **** namespace Database { ! #define THRUST_DECAY_ALT 5000.0f /** * Calculate private parameters. Should be called after --- 34,60 ---- namespace Database { ! std::vector<float> tcAirDBObject::tableAltitudes; ! ! /** ! * Static function to initialize common table of altitude points (in meters) ! * Must be called once before starting simulation ! */ ! void tcAirDBObject::InitializeTableAltitudes() ! { ! wxASSERT(tableAltitudes.size() == 0); ! tableAltitudes.clear(); ! ! tableAltitudes.push_back(2000.0f); ! tableAltitudes.push_back(4000.0f); ! tableAltitudes.push_back(6000.0f); ! tableAltitudes.push_back(8000.0f); ! tableAltitudes.push_back(10000.0f); ! tableAltitudes.push_back(12000.0f); ! tableAltitudes.push_back(16000.0f); ! tableAltitudes.push_back(20000.0f); ! tableAltitudes.push_back(25000.0f); ! tableAltitudes.push_back(30000.0f); ! } ! /** * Calculate private parameters. Should be called after *************** *** 51,70 **** { invMachRange = 0; ! } ! ! ! // thrustDecayFactor ! const float decay_alt = THRUST_DECAY_ALT; // altitude that decay begins at ! wxASSERT(zeroThrustAltitude_m > decay_alt); ! ! if (zeroThrustAltitude_m > decay_alt) ! { ! thrustDecayFactor = 1.0f / (zeroThrustAltitude_m - 5000.0f); ! } ! else ! { ! thrustDecayFactor = 0; ! } } /** --- 73,80 ---- { invMachRange = 0; ! } } + + /** *************** *** 103,124 **** * Placed here to allow better thrust decay model to be incorporated into * database without affecting air model - * @return thrust decay factor */ ! float tcAirDBObject::GetThrustFactor(float alt_m) const { ! const float decay_alt = THRUST_DECAY_ALT; // altitude that decay begins at ! ! float d_alt = alt_m - decay_alt; ! if (d_alt <= 0) return 1.0f; ! ! float thrustFactor = 1.0f - thrustDecayFactor * d_alt; ! if (thrustFactor > 0) ! { ! return thrustFactor * thrustFactor; ! } ! else ! { ! return 0; ! } } --- 113,149 ---- * Placed here to allow better thrust decay model to be incorporated into * database without affecting air model */ ! void tcAirDBObject::GetThrustAndEfficiencyFactors(float alt_m, float& thrustFactor, float& fuelEfficienyFactor) const { ! thrustFactor = 1.0f; ! fuelEfficienyFactor = 1.0f; ! ! size_t nAlt = tableAltitudes.size(); ! ! if (alt_m < tableAltitudes[0]) return; ! if (alt_m >= tableAltitudes[nAlt-1]) ! { ! thrustFactor = thrustTable[nAlt-1]; ! fuelEfficienyFactor = fuelEfficiencyTable[nAlt-1]; ! return; ! } ! ! // search for position in table and linearly interpolate factors ! for (size_t idx=2; idx<nAlt; idx++) ! { ! float alt_low = tableAltitudes[idx-1]; ! float alt_high = tableAltitudes[idx]; ! if (alt_m <= alt_high) ! { ! float low_weight = (alt_high - alt_m) / (alt_high - alt_low); ! float high_weight = 1.0f - low_weight; ! thrustFactor = low_weight * thrustTable[idx-1] + high_weight * thrustTable[idx]; ! fuelEfficienyFactor = low_weight * fuelEfficiencyTable[idx-1] + ! high_weight * fuelEfficiencyTable[idx]; ! return; ! } ! } ! ! wxASSERT(false); // error, corrupt table } *************** *** 141,149 **** if (mbLoad) { - *csv >> zeroThrustAltitude_m; *csv >> mfAfterburnFuelRate_kgps; ! *csv >> mfAfterburnThrust_N; ! *csv >> mfDragArea_sm; ! *csv >> mfWingArea_sm; *csv >> mfCdpsub; *csv >> mfCdptran; --- 166,171 ---- if (mbLoad) { *csv >> mfAfterburnFuelRate_kgps; ! *csv >> mfAfterburnThrust_N; *csv >> mfCdpsub; *csv >> mfCdptran; *************** *** 157,165 **** else { - *csv << zeroThrustAltitude_m; *csv << mfAfterburnFuelRate_kgps; ! *csv << mfAfterburnThrust_N; ! *csv << mfDragArea_sm; ! *csv << mfWingArea_sm; *csv << mfCdpsub; *csv << mfCdptran; --- 179,184 ---- else { *csv << mfAfterburnFuelRate_kgps; ! *csv << mfAfterburnThrust_N; *csv << mfCdpsub; *csv << mfCdptran; *************** *** 190,198 **** TiXmlElement* localNode = node->InsertEndChild(TiXmlElement("air"))->ToElement(); - localNode->SetAttribute("ZeroThrustAltitude_m", zeroThrustAltitude_m); localNode->SetAttribute("afterburnFuelRate_kgps", mfAfterburnFuelRate_kgps); ! localNode->SetAttribute("afterburnThrust_N", mfAfterburnThrust_N); ! localNode->SetAttribute("dragArea_sm", mfDragArea_sm); ! localNode->SetAttribute("wingArea_sm", mfWingArea_sm); localNode->SetAttribute("cdpsub", mfCdpsub); localNode->SetAttribute("cdptran", mfCdptran); --- 209,214 ---- TiXmlElement* localNode = node->InsertEndChild(TiXmlElement("air"))->ToElement(); localNode->SetAttribute("afterburnFuelRate_kgps", mfAfterburnFuelRate_kgps); ! localNode->SetAttribute("afterburnThrust_N", mfAfterburnThrust_N); localNode->SetAttribute("cdpsub", mfCdpsub); localNode->SetAttribute("cdptran", mfCdptran); *************** *** 213,221 **** csv->SetWriteLineBlock(false); - *csv << "ZeroThrustAltitude_m"; *csv << "AfterburnFuelRate_kgps"; *csv << "AfterburnThrust_N"; - *csv << "DragArea_sm"; - *csv << "WingArea_sm"; *csv << "Cdpsub"; *csv << "Cdptran"; --- 229,234 ---- *************** *** 240,248 **** columnString += ","; - columnString += "ZeroThrustAltitude_m number(5),"; columnString += "ABFuelRate_kgps number(8),"; columnString += "ABThrust_N number(8),"; - columnString += "DragArea_sm number(8),"; - columnString += "WingArea_sm number(8),"; columnString += "Cdpsub number(8),"; columnString += "Cdptran number(8),"; --- 253,258 ---- *************** *** 254,257 **** --- 264,286 ---- columnString += "Gmax number(8)"; + if (tableAltitudes.size() == 0) + { + InitializeTableAltitudes(); + } + + for (size_t idx=0; idx<tableAltitudes.size(); idx++) + { + wxString s; + s.Printf(",T%d number(5)", int(0.001f*tableAltitudes[idx])); + columnString += s.c_str(); + } + + for (size_t idx=0; idx<tableAltitudes.size(); idx++) + { + wxString s; + s.Printf(",FE%d number(5)", int(0.001f*tableAltitudes[idx])); + columnString += s.c_str(); + } + } *************** *** 260,268 **** tcGenericDBObject::ReadSql(entry); - zeroThrustAltitude_m = entry.GetDouble("ZeroThrustAltitude_m"); mfAfterburnFuelRate_kgps = entry.GetDouble("ABFuelRate_kgps"); ! mfAfterburnThrust_N = entry.GetDouble("ABThrust_N"); ! mfDragArea_sm = entry.GetDouble("DragArea_sm"); ! mfWingArea_sm = entry.GetDouble("WingArea_sm"); mfCdpsub = entry.GetDouble("Cdpsub"); mfCdptran = entry.GetDouble("Cdptran"); --- 289,294 ---- tcGenericDBObject::ReadSql(entry); mfAfterburnFuelRate_kgps = entry.GetDouble("ABFuelRate_kgps"); ! mfAfterburnThrust_N = entry.GetDouble("ABThrust_N"); mfCdpsub = entry.GetDouble("Cdpsub"); mfCdptran = entry.GetDouble("Cdptran"); *************** *** 274,277 **** --- 300,322 ---- mfGmax = entry.GetDouble("Gmax"); + thrustTable.clear(); + for (size_t idx=0; idx<tableAltitudes.size(); idx++) + { + wxString s; + s.Printf("T%d", int(0.001f*tableAltitudes[idx])); + float thrustFactor = entry.GetDouble(s.c_str()); + thrustTable.push_back(thrustFactor); + } + + fuelEfficiencyTable.clear(); + for (size_t idx=0; idx<tableAltitudes.size(); idx++) + { + wxString s; + s.Printf("FE%d", int(0.001f*tableAltitudes[idx])); + float fuelEfficiency = entry.GetDouble(s.c_str()); + fuelEfficiencyTable.push_back(fuelEfficiency); + } + + CalculateParams(); } *************** *** 284,292 **** s << ","; - s << zeroThrustAltitude_m << ","; s << mfAfterburnFuelRate_kgps << ","; ! s << mfAfterburnThrust_N << ","; ! s << mfDragArea_sm << ","; ! s << mfWingArea_sm << ","; s << mfCdpsub << ","; s << mfCdptran << ","; --- 329,334 ---- s << ","; s << mfAfterburnFuelRate_kgps << ","; ! s << mfAfterburnThrust_N << ","; s << mfCdpsub << ","; s << mfCdptran << ","; *************** *** 298,301 **** --- 340,355 ---- s << mfGmax; + for (size_t idx=0; idx<tableAltitudes.size(); idx++) + { + s << ","; + s << thrustTable[idx]; + } + + for (size_t idx=0; idx<tableAltitudes.size(); idx++) + { + s << ","; + s << fuelEfficiencyTable[idx]; + } + valueString += s.str(); *************** *** 304,326 **** tcAirDBObject::tcAirDBObject() ! : thrustDecayFactor(0), ! invMachRange(0) { mnClassID = DTYPE_AIR; mnModelType = MTYPE_FIXEDWINGX; mnType = PTYPE_FIXEDWING; // functional classification } tcAirDBObject::tcAirDBObject(tcAirDBObject& obj) : tcGenericDBObject(obj), - thrustDecayFactor(obj.thrustDecayFactor), invMachRange(obj.invMachRange) { mnClassID = DTYPE_AIR; ! zeroThrustAltitude_m = obj.zeroThrustAltitude_m; mfAfterburnFuelRate_kgps = obj.mfAfterburnFuelRate_kgps; ! mfAfterburnThrust_N = obj.mfAfterburnThrust_N; ! mfDragArea_sm = obj.mfDragArea_sm; ! mfWingArea_sm = obj.mfWingArea_sm; mfCdpsub = obj.mfCdpsub; mfCdptran = obj.mfCdptran; --- 358,381 ---- tcAirDBObject::tcAirDBObject() ! : invMachRange(0) { mnClassID = DTYPE_AIR; mnModelType = MTYPE_FIXEDWINGX; mnType = PTYPE_FIXEDWING; // functional classification + + if (tableAltitudes.size() == 0) + { + InitializeTableAltitudes(); + } } tcAirDBObject::tcAirDBObject(tcAirDBObject& obj) : tcGenericDBObject(obj), invMachRange(obj.invMachRange) { mnClassID = DTYPE_AIR; ! mfAfterburnFuelRate_kgps = obj.mfAfterburnFuelRate_kgps; ! mfAfterburnThrust_N = obj.mfAfterburnThrust_N; mfCdpsub = obj.mfCdpsub; mfCdptran = obj.mfCdptran; *************** *** 331,334 **** --- 386,394 ---- stallSpeed_mps = obj.stallSpeed_mps; mfGmax = obj.mfGmax; + + if (tableAltitudes.size() == 0) + { + InitializeTableAltitudes(); + } } |