1
0
Fork 0

Maintenance: AIThermal

initialize class members.
SPDX tags.
const variables were appropriate.
eliminate variable shadowing.
spelling.
This commit is contained in:
scttgs0 2023-05-21 21:58:50 -05:00
parent c9d08571c3
commit bb917594d8
2 changed files with 294 additions and 310 deletions

View file

@ -1,24 +1,10 @@
// FGAIThermal - FGAIBase-derived class creates an AI thermal
//
// Copyright (C) 2004  David P. Culp - davidculp2@comcast.net
//
// An attempt to refine the thermal shape and behaviour by WooT 2009
//
// Copyright (C) 2009 Patrice Poly ( WooT )
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version.
//
// This program 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
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/*
* SPDX-FileName: AIThermal.cxx
* SPDX-FileComment: AIBase-derived class creates an AI thermal. An attempt to refine the thermal shape and behaviour by WooT 2009
* SPDX-FileCopyrightText: Copyright (C) 2004  David P. Culp - davidculp2@comcast.net
* SPDX-FileContributor: Copyright (C) 2009 Patrice Poly ( WooT )
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include <cmath>
#include <string>
@ -43,7 +29,8 @@ FGAIThermal::FGAIThermal() : FGAIBase(object_type::otThermal, false)
}
void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) {
void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode)
{
if (!scFileNode)
return;
@ -54,7 +41,8 @@ void FGAIThermal::readFromScenario(SGPropertyNode* scFileNode) {
setHeight(scFileNode->getDoubleValue("height-msl", 5000.0));
}
bool FGAIThermal::init(ModelSearchOrder searchOrder) {
bool FGAIThermal::init(ModelSearchOrder searchOrder)
{
factor = 8.0 * max_strength / (diameter * diameter * diameter);
setAltitude(height);
_surface_wind_from_deg_node =
@ -69,7 +57,8 @@ bool FGAIThermal::init(ModelSearchOrder searchOrder) {
return FGAIBase::init(searchOrder);
}
void FGAIThermal::bind() {
void FGAIThermal::bind()
{
FGAIBase::bind();
tie("position/altitude-agl-ft", SGRawValuePointer<double>(&altitude_agl_ft));
tie("alt-rel", SGRawValuePointer<double>(&alt_rel));
@ -81,7 +70,8 @@ void FGAIThermal::bind() {
tie("is-dead", SGRawValuePointer<bool>(&is_dead));
}
void FGAIThermal::update(double dt) {
void FGAIThermal::update(double dt)
{
FGAIBase::update(dt);
Run(dt);
Transform();
@ -90,7 +80,8 @@ void FGAIThermal::update(double dt) {
//the formula to get the available portion of VUpMax depending on altitude
//returns a double between 0 and 1
double FGAIThermal::get_strength_fac(double alt_frac) {
double FGAIThermal::get_strength_fac(double alt_frac)
{
double PI = 4.0 * atan(1.0);
double fac = 0.0;
@ -110,8 +101,8 @@ double FGAIThermal::get_strength_fac(double alt_frac) {
}
void FGAIThermal::Run(double dt) {
void FGAIThermal::Run(double dt)
{
// *****************************************
// the thermal characteristics and variables
// *****************************************
@ -121,19 +112,19 @@ cycle_timer += dt ;
// time
// the time needed for the thermal to be completely formed
double tmin1 = 5.0 ;
const double tmin1 = 5.0;
// the time when the thermal begins to die
double tmin2 = 20.0 ;
const double tmin2 = 20.0;
// the time when the thermal is completely dead
double tmin3 = 25.0;
double alive_cycle_time = tmin3*60.0;
const double tmin3 = 25.0;
const double alive_cycle_time = tmin3 * 60.0;
//the time of the complete cycle, including a period of inactivity
double tmin4 = 30.0;
const double tmin4 = 30.0;
// some times expressed in a fraction of tmin3;
double t1 = tmin1/tmin3 ;
double t2 = tmin2/tmin3 ;
double t3 = 1.0 ;
double t4 = tmin4/tmin3;
const double t1 = tmin1 / tmin3;
const double t2 = tmin2 / tmin3;
const double t3 = 1.0;
const double t4 = tmin4 / tmin3;
// the time elapsed since the thermal was born, in a 0-1 fraction of tmin3
time = cycle_timer / alive_cycle_time;
@ -154,21 +145,15 @@ double MaxUpdraft=max_strength;
double MinUpdraft = -max_strength * 0.25;
//the fraction of MaxUpdraft one can expect at our height and time
double maxstrengthavail;
//max updraft at the user altitude and time
double v_up_max;
//min updraft at the user altitude and time, this is a negative number
double v_up_min;
double wind_speed;
//max radius of the the thermal, including the sink area
double Rmax = diameter/2.0;
const double Rmax = diameter / 2.0;
// 'shaping' of the thermal, the higher, the more conical the thermal- between 0 and 1
double shaping=0.8;
const double shaping = 0.8;
//the radius of the thermal at our altitude in FT, including sink
double Rsink;
//the relative radius of the thermal where we have updraft, between 0 an 1
double r_up_frac=0.9;
//radius of the thermal where we have updraft, in FT
double Rup;
//how far are we from the thermal center at our altitude in FEET
@ -225,7 +210,7 @@ double PI = 4.0 * atan(1.0);
// thermal main cycle
// ******************
//we get the max strenght proportion we can expect at the time and altitude, formuled between 0 and 1
//we get the max strength proportion we can expect at the time and altitude, clamped between 0 and 1
//double xx;
if (time <= t1) {
xx = (time / t1);
@ -284,11 +269,11 @@ v_up_min = maxstrengthavail * MinUpdraft;
// We still need to know how far we are from the thermal center
// To determine the thermal inclinaison in the wind, we use a ugly approximation,
// To determine the thermal inclination in the wind, we use a ugly approximation,
// in which we say the thermal bends 20° (0.34906 rad ) for 10 kts wind.
// We move the thermal foot upwind, to keep the cloud model over the "center" at ceiling level.
// the displacement distance of the center of the thermal slice, at user altitude,
// and relative to a hipothetical vertical thermal, would be:
// and relative to a hypothetical vertical thermal, would be:
// get surface and 9000 ft wind
@ -355,5 +340,4 @@ if ( alt_rel >= 1.1 ) {
strength = Vup;
range = dist_center;
}

View file

@ -48,21 +48,21 @@ private:
void Run(double dt);
double get_strength_fac(double alt_frac);
double max_strength;
double strength;
double diameter;
double height = 0.0;
double factor;
double alt_rel = 0.0;
double alt;
double v_up_max = 0.0;
double v_up_min = 0.0;
double r_up_frac = 0.0;
double cycle_timer;
double dt_count;
double time = 0.0;
double xx = 0.0;
double ground_elev_ft; // ground level in ft
double max_strength{0.0};
double strength{0.0};
double diameter{0.0};
double height{0.0};
double factor{0.0};
double alt_rel{0.0};
double alt{0.0};
double v_up_max{0.0}; //max updraft at the user altitude and time
double v_up_min{0.0}; //min updraft at the user altitude and time, this is a negative number
double r_up_frac{0.9}; //the relative radius of the thermal where we have updraft, between 0 an 1
double cycle_timer{0.0};
double dt_count{0.0};
double time{0.0};
double xx{0.0};
double ground_elev_ft{0.0}; // ground level in ft
bool do_agl_calc = false;
bool is_forming = false;