1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.org) --------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 #include <input_output/FGXMLElement.h>
42 #include "FGParameter.h"
43 #include <input_output/FGPropertyManager.h>
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51 #define ID_TABLE "$Id$"
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 using std::stringstream;
62 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
66 /** Lookup table class.
67 Models a one, two, or three dimensional lookup table for use in FGCoefficient,
68 FGPropeller, etc. A one-dimensional table is called a "VECTOR" in a coefficient
69 definition. For example:
71 \<COEFFICIENT NAME="{short name}" TYPE="VECTOR">
75 {non-dimensionalizing properties}
76 {row_1_key} {col_1_data}
82 A "real life" example is as shown here:
84 \<COEFFICIENT NAME="CLDf" TYPE="VECTOR">
85 Delta_lift_due_to_flap_deflection
88 aero/qbar-psf | metrics/Sw-sqft
95 The first column in the data table represents the lookup index (or "key"). In
96 this case, the lookup index is fcs/flap-pos-deg (flap extension in degrees).
97 If the flap position is 10 degrees, the value returned from the lookup table
98 would be 0.20. This value would be multiplied by qbar (aero/qbar-psf) and wing
99 area (metrics/Sw-sqft) to get the total lift force that is a result of flap
100 deflection (measured in pounds force). If the value of the flap-pos-deg property
101 was 15 (degrees), the value output by the table routine would be 0.25 - an
102 interpolation. If the flap position in degrees ever went below 0.0, or above
103 30 (degrees), the output from the table routine would be 0 and 0.35, respectively.
104 That is, there is no _extrapolation_ to values outside the range of the lookup
105 index. This is why it is important to chose the data for the table wisely.
107 The definition for a 2D table - referred to simply as a TABLE, is as follows:
109 \<COEFFICIENT NAME="{short name}" TYPE="TABLE">
113 {row lookup property}
114 {column lookup property}
115 {non-dimensionalizing}
116 {col_1_key col_2_key ... col_n_key }
117 {row_1_key} {col_1_data col_2_data ... col_n_data}
118 {row_2_key} {... ... ... ... }
119 { ... } {... ... ... ... }
120 {row_n_key} {... ... ... ... }
123 A "real life" example is as shown here:
125 \<COEFFICIENT NAME="CYb" TYPE="TABLE">
126 Side_force_due_to_beta
131 aero/qbar-psf | metrics/Sw-sqft
138 The definition for a 3D table in a coefficient would be (for example):
140 \<COEFFICIENT NAME="{short name}" TYPE="TABLE3D">
145 {row lookup property}
146 {column lookup property}
147 {table lookup property}
148 {non-dimensionalizing}
150 {col_1_key col_2_key ... col_n_key }
151 {row_1_key} {col_1_data col_2_data ... col_n_data}
152 {row_2_key} {... ... ... ... }
153 { ... } {... ... ... ... }
154 {row_n_key} {... ... ... ... }
157 {col_1_key col_2_key ... col_n_key }
158 {row_1_key} {col_1_data col_2_data ... col_n_data}
159 {row_2_key} {... ... ... ... }
160 { ... } {... ... ... ... }
161 {row_n_key} {... ... ... ... }
167 [At the present time, all rows and columns for each table must have the
170 In addition to using a Table for something like a coefficient, where all the
171 row and column elements are read in from a file, a Table could be created
172 and populated completely within program code:
174 // First column is thi, second is neta (combustion efficiency)
175 Lookup_Combustion_Efficiency = new FGTable(12);
176 *Lookup_Combustion_Efficiency << 0.00 << 0.980;
177 *Lookup_Combustion_Efficiency << 0.90 << 0.980;
178 *Lookup_Combustion_Efficiency << 1.00 << 0.970;
179 *Lookup_Combustion_Efficiency << 1.05 << 0.950;
180 *Lookup_Combustion_Efficiency << 1.10 << 0.900;
181 *Lookup_Combustion_Efficiency << 1.15 << 0.850;
182 *Lookup_Combustion_Efficiency << 1.20 << 0.790;
183 *Lookup_Combustion_Efficiency << 1.30 << 0.700;
184 *Lookup_Combustion_Efficiency << 1.40 << 0.630;
185 *Lookup_Combustion_Efficiency << 1.50 << 0.570;
186 *Lookup_Combustion_Efficiency << 1.60 << 0.525;
187 *Lookup_Combustion_Efficiency << 2.00 << 0.345;
189 The first column in the table, above, is thi (the lookup index, or key). The
190 second column is the output data - in this case, "neta" (the Greek letter
191 referring to combustion efficiency). Later on, the table is used like this:
193 combustion_efficiency = Lookup_Combustion_Efficiency->GetValue(equivalence_ratio);
195 @author Jon S. Berndt
201 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
205 class FGTable : public FGParameter
211 /** This is the very important copy constructor.
212 @param table a const reference to a table.*/
213 FGTable(const FGTable& table);
215 /// The constructor for a table
216 FGTable (FGPropertyManager* propMan, Element* el);
218 double GetValue(void) const;
219 double GetValue(double key) const;
220 double GetValue(double rowKey, double colKey) const;
221 double GetValue(double rowKey, double colKey, double TableKey) const;
222 /** Read the table in.
223 Data in the config file should be in matrix format with the row
224 independents as the first column and the column independents in
225 the first row. The implication of this layout is that there should
226 be no value in the upper left corner of the matrix e.g:
233 For multiple-table (i.e. 3D) data sets there is an additional number
234 key in the table definition. For example:
244 void operator<<(stringstream&);
245 FGTable& operator<<(const double n);
246 FGTable& operator<<(const int n);
248 inline double GetElement(int r, int c) {return Data[r][c];}
249 inline double GetElement(int r, int c, int t);
251 void SetRowIndexProperty(FGPropertyManager *node) {lookupProperty[eRow] = node;}
252 void SetColumnIndexProperty(FGPropertyManager *node) {lookupProperty[eColumn] = node;}
257 enum type {tt1D, tt2D, tt3D} Type;
258 enum axis {eRow=0, eColumn, eTable};
260 FGPropertyManager *lookupProperty[3];
262 vector <FGTable*> Tables;
263 int FindNumColumns(string);
264 int nRows, nCols, nTables, dimension;
265 int colCounter, rowCounter, tableCounter;
266 mutable int lastRowIndex, lastColumnIndex, lastTableIndex;
267 double** Allocate(void);
268 FGPropertyManager* const PropertyManager;
270 void Debug(int from);
273 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%