Skip to content

Commit

Permalink
Some migration to the new logging system.
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoconni committed Oct 27, 2024
1 parent a9e425d commit 218252e
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 108 deletions.
12 changes: 7 additions & 5 deletions src/models/propulsion/FGForce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ moments due to the difference between the point of application and the cg.
#include "FGForce.h"
#include "FGFDMExec.h"
#include "models/FGAuxiliary.h"
#include "input_output/FGLog.h"

using namespace std;

Expand Down Expand Up @@ -108,9 +109,9 @@ const FGMatrix33& FGForce::Transform(void) const
return mT;
default:
{
const string s("Unrecognized tranform requested from FGForce::Transform()");
cout << s << endl;
throw BaseException(s);
FGLogging log(fdmex->GetLogger(), LogLevel::FATAL);
log << "Unrecognized tranform requested from FGForce::Transform()\n";
throw BaseException(log.str());
}
}
}
Expand Down Expand Up @@ -185,8 +186,9 @@ void FGForce::Debug(int from)
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGForce" << endl;
if (from == 1) cout << "Destroyed: FGForce" << endl;
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
if (from == 0) log << "Instantiated: FGForce\n";
if (from == 1) log << "Destroyed: FGForce\n";
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
Expand Down
20 changes: 12 additions & 8 deletions src/models/propulsion/FGNozzle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ INCLUDES
#include <cstdlib>

#include "FGNozzle.h"
#include "FGFDMExec.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGLog.h"

using namespace std;

Expand All @@ -52,14 +54,14 @@ CLASS IMPLEMENTATION


FGNozzle::FGNozzle(FGFDMExec* FDMExec, Element* nozzle_element, int num)
: FGThruster(FDMExec, nozzle_element, num)
: FGThruster(FDMExec, nozzle_element, num)
{
if (nozzle_element->FindElement("area"))
Area = nozzle_element->FindElementValueAsNumberConvertTo("area", "FT2");
else {
const string s("Fatal Error: Nozzle exit area must be given in nozzle config file.");
cerr << s << endl;
throw BaseException(s);
FGXMLLogging log(fdmex->GetLogger(), nozzle_element, LogLevel::FATAL);
log << "Fatal Error: Nozzle exit area must be given in nozzle config file.\n";
throw BaseException(log.str());
}

Thrust = 0;
Expand Down Expand Up @@ -133,13 +135,15 @@ void FGNozzle::Debug(int from)

if (debug_lvl & 1) { // Standard console startup message output
if (from == 0) { // Constructor
cout << " Nozzle Name: " << Name << endl;
cout << " Nozzle Exit Area = " << Area << endl;
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
log << " Nozzle Name: " << Name << "\n";
log << " Nozzle Exit Area = " << Area << "\n";
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGNozzle" << endl;
if (from == 1) cout << "Destroyed: FGNozzle" << endl;
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
if (from == 0) log << "Instantiated: FGNozzle\n";
if (from == 1) log << "Destroyed: FGNozzle\n";
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
Expand Down
65 changes: 28 additions & 37 deletions src/models/propulsion/FGPropeller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ INCLUDES
#include "FGFDMExec.h"
#include "FGPropeller.h"
#include "input_output/FGXMLElement.h"
#include "input_output/FGLog.h"

using namespace std;

Expand Down Expand Up @@ -109,14 +110,19 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
} else if (name == "CP_MACH") {
CpMach = new FGTable(PropertyManager, table_element);
} else {
cerr << "Unknown table type: " << name << " in propeller definition." << endl;
FGXMLLogging log(fdmex->GetLogger(), table_element, LogLevel::ERROR);
log << "Unknown table type: " << name << " in propeller definition.\n";
}
} catch (std::string& str) {
throw("Error loading propeller table:" + name + ". " + str);
FGXMLLogging log(fdmex->GetLogger(), table_element, LogLevel::ERROR);
log << "Error loading propeller table:" << name << ". " << str << "\n";
throw BaseException(log.str());
}
}
if( (cPower == 0) || (cThrust == 0)){
cerr << "Propeller configuration must contain C_THRUST and C_POWER tables!" << endl;
FGXMLLogging log(fdmex->GetLogger(), prop_element, LogLevel::ERROR);
log << "Propeller configuration must contain C_THRUST and C_POWER tables!\n";
throw BaseException(log.str());
}

local_element = prop_element->GetParent()->FindElement("sense");
Expand All @@ -129,7 +135,9 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num)
P_Factor = local_element->GetDataAsNumber();
}
if (P_Factor < 0) {
cerr << "P-Factor value in propeller configuration file must be greater than zero" << endl;
FGXMLLogging log(fdmex->GetLogger(), local_element, LogLevel::ERROR);
log << "P-Factor value in propeller configuration file must be greater than zero\n";
throw BaseException(log.str());
}
if (prop_element->FindElement("ct_factor"))
SetCtFactor( prop_element->FindElementValueAsNumber("ct_factor") );
Expand Down Expand Up @@ -249,12 +257,12 @@ double FGPropeller::Calculate(double EnginePower)
// Since Thrust and Vel can both be negative we need to adjust this formula
// To handle sign (direction) separately from magnitude.
double Vel2sum = Vel*abs(Vel) + 2.0*Thrust/(rho*Area);

if( Vel2sum > 0.0)
Vinduced = 0.5 * (-Vel + sqrt(Vel2sum));
else
Vinduced = 0.5 * (-Vel - sqrt(-Vel2sum));

// P-factor is simulated by a shift of the acting location of the thrust.
// The shift is a multiple of the angle between the propeller shaft axis
// and the relative wind that goes through the propeller disk.
Expand Down Expand Up @@ -359,7 +367,7 @@ double FGPropeller::GetPowerRequired(void)
if (CpMach) cPReq *= CpMach->GetValue(HelicalTipMach);

double RPS = RPM / 60.0;
double local_RPS = RPS < 0.01 ? 0.01 : RPS;
double local_RPS = RPS < 0.01 ? 0.01 : RPS;

PowerRequired = cPReq*local_RPS*local_RPS*local_RPS*D5*in.Density;

Expand Down Expand Up @@ -439,39 +447,22 @@ void FGPropeller::Debug(int from)

if (debug_lvl & 1) { // Standard console startup message output
if (from == 0) { // Constructor
cout << "\n Propeller Name: " << Name << endl;
cout << " IXX = " << Ixx << endl;
cout << " Diameter = " << Diameter << " ft." << endl;
cout << " Number of Blades = " << numBlades << endl;
cout << " Gear Ratio = " << GearRatio << endl;
cout << " Minimum Pitch = " << MinPitch << endl;
cout << " Maximum Pitch = " << MaxPitch << endl;
cout << " Minimum RPM = " << MinRPM << endl;
cout << " Maximum RPM = " << MaxRPM << endl;
// Tables are being printed elsewhere...
// cout << " Thrust Coefficient: " << endl;
// cThrust->Print();
// cout << " Power Coefficient: " << endl;
// cPower->Print();
// cout << " Mach Thrust Coefficient: " << endl;
// if(CtMach)
// {
// CtMach->Print();
// } else {
// cout << " NONE" << endl;
// }
// cout << " Mach Power Coefficient: " << endl;
// if(CpMach)
// {
// CpMach->Print();
// } else {
// cout << " NONE" << endl;
// }
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
log << "\n Propeller Name: " << Name << "\n";
log << " IXX = " << Ixx << "\n";
log << " Diameter = " << Diameter << " ft." << "\n";
log << " Number of Blades = " << numBlades << "\n";
log << " Gear Ratio = " << GearRatio << "\n";
log << " Minimum Pitch = " << MinPitch << "\n";
log << " Maximum Pitch = " << MaxPitch << "\n";
log << " Minimum RPM = " << MinRPM << "\n";
log << " Maximum RPM = " << MaxRPM << "\n";
}
}
if (debug_lvl & 2 ) { // Instantiation/Destruction notification
if (from == 0) cout << "Instantiated: FGPropeller" << endl;
if (from == 1) cout << "Destroyed: FGPropeller" << endl;
FGLogging log(fdmex->GetLogger(), LogLevel::DEBUG);
if (from == 0) log << "Instantiated: FGPropeller\n";
if (from == 1) log << "Destroyed: FGPropeller\n";
}
if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
}
Expand Down
Loading

0 comments on commit 218252e

Please sign in to comment.