From 072bad4f50c5750d37e9f0d974f7bfc21ec28695 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Thu, 27 Apr 2017 15:41:23 +0200 Subject: [PATCH] sync. with JSBSim and expose Oil_Press_Relief_Valve, Oil_Press_RPM_Max, Design_Oil_Temp, Oil_Viscosity_Index --- src/FDM/JSBSim/math/FGFunction.cpp | 18 ++++---- src/FDM/JSBSim/math/FGFunction.h | 4 +- src/FDM/JSBSim/math/FGTable.cpp | 43 ++++++++++++++++--- src/FDM/JSBSim/math/FGTable.h | 9 ++-- src/FDM/JSBSim/models/FGAccelerations.cpp | 9 +--- src/FDM/JSBSim/models/FGAccelerations.h | 2 - src/FDM/JSBSim/models/propulsion/FGPiston.cpp | 18 +++++--- src/FDM/JSBSim/models/propulsion/FGPiston.h | 5 +++ .../JSBSim/models/propulsion/FGPropeller.cpp | 4 +- .../JSBSim/models/propulsion/FGTurboProp.cpp | 11 ++++- 10 files changed, 85 insertions(+), 38 deletions(-) mode change 100644 => 100755 src/FDM/JSBSim/math/FGFunction.cpp mode change 100644 => 100755 src/FDM/JSBSim/math/FGFunction.h mode change 100644 => 100755 src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp diff --git a/src/FDM/JSBSim/math/FGFunction.cpp b/src/FDM/JSBSim/math/FGFunction.cpp old mode 100644 new mode 100755 index 853b81425..4272dc883 --- a/src/FDM/JSBSim/math/FGFunction.cpp +++ b/src/FDM/JSBSim/math/FGFunction.cpp @@ -43,7 +43,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGFunction.cpp,v 1.58 2015/07/12 19:34:08 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGFunction.cpp,v 1.59 2017/03/11 19:31:47 bcoconni Exp $"); IDENT(IdHdr,ID_FUNCTION); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -266,7 +266,7 @@ FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& pr } else if (operation == value_string || operation == v_string) { Parameters.push_back(new FGRealValue(element->GetDataAsNumber())); } else if (operation == table_string || operation == t_string) { - Parameters.push_back(new FGTable(PropertyManager, element)); + Parameters.push_back(new FGTable(PropertyManager, element, Prefix)); // operations } else if (operation == product_string || operation == difference_string || @@ -323,7 +323,7 @@ FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& pr element = el->GetNextElement(); } - bind(); // Allow any function to save its value + bind(el); // Allow any function to save its value Debug(0); } @@ -784,7 +784,7 @@ string FGFunction::GetValueAsString(void) const //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGFunction::bind(void) +void FGFunction::bind(Element* el) { if ( !Name.empty() ) { string tmp; @@ -796,9 +796,10 @@ void FGFunction::bind(void) Name = replace(Name,"#",Prefix); tmp = PropertyManager->mkPropertyName(Name, false); } else { - cerr << "Malformed function name with number: " << Prefix - << " and property name: " << Name - << " but no \"#\" sign for substitution." << endl; + cerr << el->ReadFrom() + << "Malformed function name with number: " << Prefix + << " and property name: " << Name + << " but no \"#\" sign for substitution." << endl; } } else { tmp = PropertyManager->mkPropertyName(Prefix + "/" + Name, false); @@ -808,7 +809,8 @@ void FGFunction::bind(void) if (PropertyManager->HasNode(tmp)) { FGPropertyNode* _property = PropertyManager->GetNode(tmp); if (_property->isTied()) { - cout << "Property " << tmp << " has already been successfully bound (late)." << endl; + cerr << el->ReadFrom() + << "Property " << tmp << " has already been successfully bound (late)." << endl; throw("Failed to bind the property to an existing already tied node."); } } diff --git a/src/FDM/JSBSim/math/FGFunction.h b/src/FDM/JSBSim/math/FGFunction.h old mode 100644 new mode 100755 index 25fa9b4c9..73bab38d2 --- a/src/FDM/JSBSim/math/FGFunction.h +++ b/src/FDM/JSBSim/math/FGFunction.h @@ -43,7 +43,7 @@ INCLUDES DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define ID_FUNCTION "$Id: FGFunction.h,v 1.32 2015/07/12 13:03:23 bcoconni Exp $" +#define ID_FUNCTION "$Id: FGFunction.h,v 1.33 2017/03/11 19:31:47 bcoconni Exp $" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS @@ -812,7 +812,7 @@ private: FGPropertyNode_ptr pCopyTo; // Property node for CopyTo property string unsigned int GetBinary(double) const; - void bind(void); + void bind(Element*); void Debug(int from); }; diff --git a/src/FDM/JSBSim/math/FGTable.cpp b/src/FDM/JSBSim/math/FGTable.cpp index 406d023a7..a60120221 100644 --- a/src/FDM/JSBSim/math/FGTable.cpp +++ b/src/FDM/JSBSim/math/FGTable.cpp @@ -47,7 +47,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGTable.cpp,v 1.32 2016/05/22 09:08:05 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGTable.cpp,v 1.33 2017/03/11 19:31:48 bcoconni Exp $"); IDENT(IdHdr,ID_TABLE); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -112,7 +112,9 @@ FGTable::FGTable(const FGTable& t) : PropertyManager(t.PropertyManager) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGTable::FGTable(FGPropertyManager* propMan, Element* el) : PropertyManager(propMan) +FGTable::FGTable(FGPropertyManager* propMan, Element* el, + const std::string& prefix) + : PropertyManager(propMan), Prefix(prefix) { unsigned int i; @@ -174,6 +176,11 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el) : PropertyManager(prop while (axisElement) { property_string = axisElement->GetDataLine(); + if (property_string.find("#") != string::npos) { + if (is_number(Prefix)) { + property_string = replace(property_string,"#",Prefix); + } + } // The property string passed into GetNode() must have no spaces or tabs. node = PropertyManager->GetNode(property_string); @@ -347,7 +354,7 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el) : PropertyManager(prop } } - bind(); + bind(el); if (debug_lvl & 1) Print(); } @@ -632,11 +639,37 @@ void FGTable::Print(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -void FGTable::bind(void) +void FGTable::bind(Element* el) { typedef double (FGTable::*PMF)(void) const; if ( !Name.empty() && !internal) { - string tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper + string tmp; + if (Prefix.empty()) + tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper + else { + if (is_number(Prefix)) { + if (Name.find("#") != string::npos) { // if "#" is found + Name = replace(Name,"#",Prefix); + tmp = PropertyManager->mkPropertyName(Name, false); // Allow upper + } else { + cerr << el->ReadFrom() + << "Malformed table name with number: " << Prefix + << " and property name: " << Name + << " but no \"#\" sign for substitution." << endl; + } + } else { + tmp = PropertyManager->mkPropertyName(Prefix + "/" + Name, false); + } + } + + if (PropertyManager->HasNode(tmp)) { + FGPropertyNode* _property = PropertyManager->GetNode(tmp); + if (_property->isTied()) { + cerr << el->ReadFrom() + << "Property " << tmp << " has already been successfully bound (late)." << endl; + throw("Failed to bind the property to an existing already tied node."); + } + } PropertyManager->Tie( tmp, this, (PMF)&FGTable::GetValue); } } diff --git a/src/FDM/JSBSim/math/FGTable.h b/src/FDM/JSBSim/math/FGTable.h index 377750b5a..d3f04bfae 100644 --- a/src/FDM/JSBSim/math/FGTable.h +++ b/src/FDM/JSBSim/math/FGTable.h @@ -48,7 +48,7 @@ INCLUDES DEFINITIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -#define ID_TABLE "$Id: FGTable.h,v 1.15 2013/01/26 17:06:49 bcoconni Exp $" +#define ID_TABLE "$Id: FGTable.h,v 1.16 2017/03/11 19:31:48 bcoconni Exp $" /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FORWARD DECLARATIONS @@ -233,7 +233,7 @@ combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio @endcode @author Jon S. Berndt -@version $Id: FGTable.h,v 1.15 2013/01/26 17:06:49 bcoconni Exp $ +@version $Id: FGTable.h,v 1.16 2017/03/11 19:31:48 bcoconni Exp $ */ /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -251,7 +251,7 @@ public: FGTable(const FGTable& table); /// The constructor for a table - FGTable (FGPropertyManager* propMan, Element* el); + FGTable (FGPropertyManager* propMan, Element* el, const std::string& prefix=""); FGTable (int ); FGTable (int, int); double GetValue(void) const; @@ -311,8 +311,9 @@ private: mutable int lastRowIndex, lastColumnIndex, lastTableIndex; double** Allocate(void); FGPropertyManager* const PropertyManager; + std::string Prefix; std::string Name; - void bind(void); + void bind(Element*); unsigned int FindNumColumns(const std::string&); void Debug(int from); diff --git a/src/FDM/JSBSim/models/FGAccelerations.cpp b/src/FDM/JSBSim/models/FGAccelerations.cpp index 048db3d9a..62fc0e977 100644 --- a/src/FDM/JSBSim/models/FGAccelerations.cpp +++ b/src/FDM/JSBSim/models/FGAccelerations.cpp @@ -104,8 +104,6 @@ bool FGAccelerations::InitModel(void) vGravAccel.InitMatrix(); vBodyAccel.InitMatrix(); - maxiter = 50; - matrixSize = iter = 0; return true; } @@ -257,7 +255,6 @@ void FGAccelerations::ResolveFrictionForces(double dt) FGColumnVector3 vdot, wdot; vector& multipliers = *in.MultipliersList; size_t n = multipliers.size(); - matrixSize = n; vFrictionForces.InitMatrix(); vFrictionMoments.InitMatrix(); @@ -306,7 +303,7 @@ void FGAccelerations::ResolveFrictionForces(double dt) } // Resolve the Lagrange multipliers with the projected Gauss-Seidel method - for (iter=0; iter < maxiter; iter = iter+1) { + for (int iter=0; iter < 50; iter++) { double norm = 0.; for (unsigned int i=0; i < n; i++) { @@ -387,10 +384,6 @@ void FGAccelerations::bind(void) PropertyManager->Tie("forces/fbx-gear-lbs", this, eX, (PMF)&FGAccelerations::GetGroundForces); PropertyManager->Tie("forces/fby-gear-lbs", this, eY, (PMF)&FGAccelerations::GetGroundForces); PropertyManager->Tie("forces/fbz-gear-lbs", this, eZ, (PMF)&FGAccelerations::GetGroundForces); - - iter = PropertyManager->CreatePropertyObject("numerical/friction-resolver/iterations"); - maxiter = PropertyManager->CreatePropertyObject("numerical/friction-resolver/max-iterations"); - matrixSize = PropertyManager->CreatePropertyObject("numerical/friction-resolver/matrix-size"); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/FDM/JSBSim/models/FGAccelerations.h b/src/FDM/JSBSim/models/FGAccelerations.h index b80456cd2..85dda88bb 100644 --- a/src/FDM/JSBSim/models/FGAccelerations.h +++ b/src/FDM/JSBSim/models/FGAccelerations.h @@ -40,7 +40,6 @@ INCLUDES #include -#include "simgear/props/propertyObject.hxx" #include "models/FGModel.h" #include "math/FGColumnVector3.h" #include "math/LagrangeMultiplier.h" @@ -392,7 +391,6 @@ private: FGColumnVector3 vGravAccel; FGColumnVector3 vFrictionForces; FGColumnVector3 vFrictionMoments; - simgear::PropertyObject iter, maxiter, matrixSize; int gravType; bool gravTorque; diff --git a/src/FDM/JSBSim/models/propulsion/FGPiston.cpp b/src/FDM/JSBSim/models/propulsion/FGPiston.cpp index e16e49c89..2ec5c29a0 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPiston.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGPiston.cpp @@ -234,6 +234,19 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Input RatedAltitude[2] = el->FindElementValueAsNumberConvertTo("ratedaltitude3", "FT"); } + Design_Oil_Temp = 358; // degK; + Oil_Viscosity_Index = 0.25; + Oil_Press_Relief_Valve = 60; // psi + Oil_Press_RPM_Max = MaxRPM*0.75; + if (el->FindElement("oil-pressure-relief-valve-psi")) + Oil_Press_Relief_Valve = el->FindElementValueAsNumberConvertTo("oil-pressure-relief-valve-psi", "PSI"); + if (el->FindElement("design-oil-temp-degK")) + Design_Oil_Temp = el->FindElementValueAsNumberConvertTo("design-oil-temp-degK", "DEGK"); + if (el->FindElement("oil-pressure-rpm-max")) + Oil_Press_RPM_Max = el->FindElementValueAsNumber("oil-pressure-rpm-max"); + if (el->FindElement("oil-viscosity-index")) + Oil_Viscosity_Index = el->FindElementValueAsNumber("oil-viscosity-index"); + while((table_element = el->FindNextElement("table")) != 0) { string name = table_element->GetAttributeValue("name"); try { @@ -920,11 +933,6 @@ void FGPiston::doOilTemperature(void) void FGPiston::doOilPressure(void) { - double Oil_Press_Relief_Valve = 60; // FIXME: may vary by engine - double Oil_Press_RPM_Max = MaxRPM * 0.75; // 75% of max rpm FIXME: may vary by engine - double Design_Oil_Temp = 358; // degK; FIXME: may vary by engine - double Oil_Viscosity_Index = 0.25; - OilPressure_psi = (Oil_Press_Relief_Valve / Oil_Press_RPM_Max) * RPM; if (OilPressure_psi >= Oil_Press_Relief_Valve) { diff --git a/src/FDM/JSBSim/models/propulsion/FGPiston.h b/src/FDM/JSBSim/models/propulsion/FGPiston.h index 1934f221e..97c6b7350 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPiston.h +++ b/src/FDM/JSBSim/models/propulsion/FGPiston.h @@ -361,6 +361,11 @@ private: bool Magneto_Right; int Magnetos; + double Oil_Press_Relief_Valve; + double Oil_Press_RPM_Max; + double Design_Oil_Temp; // degK + double Oil_Viscosity_Index; + // // Outputs (in addition to those in FGEngine). // diff --git a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp index e676431e6..50d9f8836 100644 --- a/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGPropeller.cpp @@ -45,7 +45,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGPropeller.cpp,v 1.60 2017/03/03 23:00:39 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGPropeller.cpp,v 1.61 2017/03/22 21:27:47 bcoconni Exp $"); IDENT(IdHdr,ID_PROPELLER); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -211,7 +211,7 @@ double FGPropeller::Calculate(double EnginePower) FGColumnVector3 localAeroVel = Transform().Transposed() * in.AeroUVW; double omega, PowerAvailable; - double Vel = localAeroVel(eU) + Vinduced; + double Vel = localAeroVel(eU); double rho = in.Density; double RPS = RPM/60.0; diff --git a/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp b/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp old mode 100644 new mode 100755 index d293bbaaf..dab3a4a4f --- a/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp +++ b/src/FDM/JSBSim/models/propulsion/FGTurboProp.cpp @@ -55,7 +55,7 @@ using namespace std; namespace JSBSim { -IDENT(IdSrc,"$Id: FGTurboProp.cpp,v 1.36 2017/02/26 11:41:28 bcoconni Exp $"); +IDENT(IdSrc,"$Id: FGTurboProp.cpp,v 1.37 2017/03/11 19:50:03 bcoconni Exp $"); IDENT(IdHdr,ID_TURBOPROP); /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -146,7 +146,14 @@ bool FGTurboProp::Load(FGFDMExec* exec, Element *el) while (table_element) { string name = table_element->GetAttributeValue("name"); if (!EnginePowerVC && name == "EnginePowerVC") { - EnginePowerVC = new FGTable(PropertyManager, table_element); + // Get a different name for each engines otherwise FGTable::bind() will + // complain that the property 'EnginePowerVC' is already bound. This is a + // ugly hack but the functionality is obsolete and will be removed some + // time in the future. + table_element->SetAttributeValue("name", string("propulsion/engine[#]/") + name); + EnginePowerVC = new FGTable(PropertyManager, table_element, + to_string((int)EngineNumber)); + table_element->SetAttributeValue("name", name); cerr << table_element->ReadFrom() <<"Note: Using the EnginePowerVC without enclosed tag is deprecated" << endl;