Skip to content

Commit

Permalink
Aeromatic fix inputs (JSBSim-Team#860)
Browse files Browse the repository at this point in the history
* Fix a few expired links

* Fix the case where all input parameters are undefined. You will get a working configuration but it won't mean much. But at least it will not genereate NaN's in the output file under any circumstance. Auto fix a user mistake where emtpy weigth > max weight.

* Uncomment NaN signals for release builds

* Embed the input parameters into the output file.

* Introduce a warning system to display warning and alert messages after everything was finished.
  • Loading branch information
ermarch authored Mar 24, 2023
1 parent 398c07c commit e1af7ce
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 25 deletions.
6 changes: 5 additions & 1 deletion utils/aeromatic++/AeroBiplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ Biplane::Biplane(Aeromatic *p) : Aircraft(p)
_subclasses.push_back("Vintage Biplane");
_subclasses.push_back("Modern biplane");

_systems.push_back(new Propulsion(_aircraft));
if (aircraft->no_engines > 0) {
_systems.push_back(new Propulsion(_aircraft));
} else {
_warnings.push_back("No engine specified.");
}
_systems.push_back(new CableControls(_aircraft));
_systems.push_back(new LandingGear(_aircraft));
_systems.push_back(new Flaps(_aircraft));
Expand Down
6 changes: 5 additions & 1 deletion utils/aeromatic++/AeroFighterJet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ Fighter::Fighter(Aeromatic *p) : Aircraft(p)
{
_description = "Fighter Jet";

_systems.push_back(new Propulsion(_aircraft));
if (_aircraft->_no_engines > 0) {
_systems.push_back(new Propulsion(_aircraft));
} else {
_warnings.push_back("No engine specified.");
}
_systems.push_back(new Controls(_aircraft));
_systems.push_back(new LandingGear(_aircraft));
_systems.push_back(new Flaps(_aircraft));
Expand Down
6 changes: 5 additions & 1 deletion utils/aeromatic++/AeroHighPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ Performance::Performance(Aeromatic *p) : Aircraft(p)
_subclasses.push_back("Aerobatic");
_subclasses.push_back("Air Racer");

_systems.push_back(new Propulsion(_aircraft));
if (_aircraft->_no_engines > 0) {
_systems.push_back(new Propulsion(_aircraft));
} else {
_warnings.push_back("No engine specified.");
}
_systems.push_back(new CableControls(_aircraft));
_systems.push_back(new LandingGear(_aircraft));
_systems.push_back(new Flaps(_aircraft));
Expand Down
6 changes: 5 additions & 1 deletion utils/aeromatic++/AeroJetTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ JetTransport::JetTransport(Aeromatic *p) : Aircraft(p)
_subclasses.push_back("Passenger Jet Airliner");
_subclasses.push_back("Transonic Jet Transport");

_systems.push_back(new Propulsion(_aircraft));
if (_aircraft->_no_engines > 0) {
_systems.push_back(new Propulsion(_aircraft));
} else {
_warnings.push_back("No engine specified.");
}
_systems.push_back(new ThrustReverse(_aircraft));
_systems.push_back(new Controls(_aircraft));
_systems.push_back(new LandingGear(_aircraft));
Expand Down
4 changes: 3 additions & 1 deletion utils/aeromatic++/AeroLightGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ Light::Light(Aeromatic *p) : Aircraft(p)
_subclasses.push_back("Glider");
_subclasses.push_back("Small Commuter");

_systems.push_back(new Propulsion(_aircraft));
if (_aircraft->_no_engines > 0) {
_systems.push_back(new Propulsion(_aircraft));
}
_systems.push_back(new CableControls(_aircraft));
_systems.push_back(new LandingGear(_aircraft));
_systems.push_back(new Flaps(_aircraft));
Expand Down
6 changes: 5 additions & 1 deletion utils/aeromatic++/AeroPropTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ PropTransport::PropTransport(Aeromatic *p) : Aircraft(p)
_subclasses.push_back("Propeller Airliner");
_subclasses.push_back("Propeller Transport");

_systems.push_back(new Propulsion(_aircraft));
if (_aircraft->_no_engines > 0) {
_systems.push_back(new Propulsion(_aircraft));
} else {
_warnings.push_back("No engine specified.");
}
_systems.push_back(new Controls(_aircraft));
_systems.push_back(new LandingGear(_aircraft));
_systems.push_back(new Flaps(_aircraft));
Expand Down
75 changes: 67 additions & 8 deletions utils/aeromatic++/Aircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ bool Aeromatic::fdm()


//***** METRICS ***************************************
// empty weight > max weight? then assume a user mistake.
if (_empty_weight > _max_weight)
{
float tmp = _max_weight;
_max_weight = _empty_weight;
_empty_weight = tmp;
_warnings.push_back("Empty weight is set larger than maximum weigth, swapping.");
}

if (_max_weight == 0)
{
_alerts.push_back("Maximum weigth is set to zero. Guessing.");
_max_weight = 10000.0f;
}

_payload = _max_weight;
_stall_weight = _max_weight;

Expand All @@ -274,6 +289,10 @@ bool Aeromatic::fdm()
_user_wing_data++;
}

if (_wing.span == 0) {
_wing.span = sqrtf(_wing.aspect * _wing.area);
}

if (_wing.taper == 0) {
if (_wing.shape == DELTA) {
_wing.taper = 2.0f*_wing.span/_wing.area;
Expand Down Expand Up @@ -321,6 +340,24 @@ bool Aeromatic::fdm()
_wing.sweep_le += _wing.sweep;
}

if (_length == 0)
{
_warnings.push_back("Aircraft length is zero. Change it to match the span.");
_length = _wing.span;
}

if (_stall_speed == 0)
{
float rho = 0.0023769f;
aircraft->set_lift();
_stall_speed = sqrtf(2.0f*_stall_weight/(_CL0*rho*_wing.area));
}

// estimate empty weight, based on max weight
if (_empty_weight == 0) {
_empty_weight = _max_weight * aircraft->get_empty_weight();
}

if (_wing.thickness == 0)
{
// Hofman equation for t/c
Expand Down Expand Up @@ -421,13 +458,6 @@ bool Aeromatic::fdm()
_vtail.de_da = 4.0f/(_vtail.aspect+2.0f);
}

//***** EMPTY WEIGHT *********************************

// estimate empty weight, based on max weight
if (_empty_weight == 0) {
_empty_weight = _max_weight * aircraft->get_empty_weight();
}

//***** MOMENTS OF INERTIA ******************************

// use Roskam's formulae to estimate moments of inertia
Expand Down Expand Up @@ -479,6 +509,11 @@ bool Aeromatic::fdm()
payload_loc[Y] = _cg_loc[Y];
payload_loc[Z] = _cg_loc[Z];
_payload -= _empty_weight;
if (_payload < 0.0f)
{
_alerts.push_back("Payload would have become negative. Clip it.");
_payload = 0.0f;
}

//***** COEFFICIENTS **********************************
aircraft->set_lift();
Expand Down Expand Up @@ -577,7 +612,31 @@ Aeromatic::write_XML()
file << " </fileheader>" << std::endl;
file << std::endl;
file << "<!--\n File: " << _name << ".xml" << std::endl;
file << " Inputs:" << std::endl;
file << " Input parameters:" << std::endl;
for (auto it : _general_order) {
Param *param = _general[it];
file << " " << std::left << std::setw(35) << param->name() << ": " << param->get() << std::endl;
}
for (auto it : _weight_balance_order) {
Param *param = _weight_balance[it];
file << " " << std::left << std::setw(35) << param->name() << ": " << param->get() << std::endl;
}
for (auto it : _geometry_order) {
Param *param = _geometry[it];
file << " " << std::left << std::setw(35) << param->name() << ": " << param->get() << std::endl;
}
for (auto it : get_systems())
{
auto system = it;
Param* param;
system->param_reset();
while ((param = system->param_next()) != 0) {
file << " " << std::left << std::setw(35) << param->name() << ": " << param->get() << std::endl;
}
}
//
file << std::endl;
file << " Specifications:" << std::endl;
file << " name: " << _name << std::endl;
file << " type: ";
if (_no_engines == 0) file << "No engine ";
Expand Down
17 changes: 14 additions & 3 deletions utils/aeromatic++/Aircraft.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ class Aircraft

const char* get_verbose_description(int no_engines = -1);

const std::vector<std::string> get_subclasses() {
const std::vector<std::string>& get_warnings() {
return _warnings;
}

const std::vector<std::string>& get_alerts() {
return _alerts;
}

const std::vector<std::string>& get_subclasses() {
return _subclasses;
}

virtual const std::vector<System*> get_systems() {
virtual const std::vector<System*>& get_systems() {
return _systems;
}

Expand Down Expand Up @@ -106,6 +114,9 @@ class Aircraft
Aeromatic *_aircraft;
const char* _description;
std::vector<std::string> _subclasses;

std::vector<std::string> _warnings;
std::vector<std::string> _alerts;
};


Expand Down Expand Up @@ -529,7 +540,7 @@ class Aeromatic : public Aircraft
static std::string create_dir(std::string path, std::string subdir);
static bool overwrite(std::string path);

const std::vector<System*> get_systems() override {
const std::vector<System*>& get_systems() override {
return _aircraft[_atype]->get_systems();
}

Expand Down
8 changes: 4 additions & 4 deletions utils/aeromatic++/Systems/Controls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
* References:
*
* http://www.princeton.edu/~stengel/MAE331Lectures.html
* http://www.dept.aoe.vt.edu/~mason/Mason_f/ConfigAeroTransonics.pdf
* http://aerostudents.com/files/flightDynamics/lateralStabilityDerivatives.pdf
* http://aerostudents.com/files/flightDynamics/longitudinalStabilityDerivatives.pdf
* https://archive.aoe.vt.edu/mason/Mason_f/ConfigAeroTransonics.pdf
* http://www.aerostudents.com/courses/flight-dynamics/flightDynamicsFullVersion.pdf
* http://www.aerostudents.com/courses/flight-dynamics/flightDynamicsFullVersion.pdf
*
* Formula's for CLalpha wing for different configurations:
* http://aviation.stackexchange.com/questions/14508/calculating-a-finite-wings-lift-from-its-sectional-airfoil-shape
*
* See also:
* http://www.flightlevelengineering.com/downloads/stab.pdf
* https://web.archive.org/web/20180712182926/http://www.flightlevelengineering.com/downloads/stab.pdf
*/

#include <math.h>
Expand Down
24 changes: 21 additions & 3 deletions utils/aeromatic++/aeromatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Expand Down Expand Up @@ -167,6 +167,10 @@ int main(int argc, char *argv[])
in.basic_ios<char>::rdbuf(cin.rdbuf());
}

#if defined(__GNUC__) && !defined(sgi)
// feenableexcept(FE_INVALID);
#endif

cout << endl;
cout << "** AeromatiC++ version " << AEROMATIC_VERSION_STR << endl;
cout << "Aeromatic is a JSBSim configuration file generation utility." << endl;
Expand All @@ -182,7 +186,7 @@ int main(int argc, char *argv[])
cout << "** Weight and Balance **" << endl << endl;
for (auto it : aeromatic._weight_balance_order) {
ask(in, log, aeromatic._weight_balance[it]);
}
}
cout << endl;

cout << "** Geometry **" << endl << endl;
Expand Down Expand Up @@ -226,6 +230,20 @@ int main(int argc, char *argv[])
}
cout << endl << endl;

auto& warnings = aeromatic.get_warnings();
for (auto it : warnings) {
cout << "Warning: " << it << endl;
}

cout << endl;

auto& alerts = aeromatic.get_alerts();
for (auto it : alerts) {
cout << "Alert: " << it << endl;
}

cout << endl << endl;;

cout << "Press enter to continue." << endl;
string input;
getline(cin, input);
Expand Down
2 changes: 1 addition & 1 deletion utils/aeromatic++/config.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* versioning */
#define AEROMATIC_MAJOR_VERSION 3
#define AEROMATIC_MINOR_VERSION 3
#define AEROMATIC_MICRO_VERSION 20
#define AEROMATIC_MICRO_VERSION 21

0 comments on commit e1af7ce

Please sign in to comment.