1 /*flapdata.h
2 This is the interface definition file for the structure that
3 holds the flapping data.
4 Written by Theresa Robinson
5 robinst@ecf.toronto.edu
6 */
7 
8 #ifndef _FLAPDATA_H
9 #define _FLAPDATA_H
10 #include <simgear/compiler.h>
11 
12 #include <cstdio>
13 #include <fstream>
14 #include <sstream>
15 
16 #include "uiuc_warnings_errors.h"
17 //#include "uiuc_aircraft.h"
18 
19 using std::ifstream;
20 using std::istringstream;
21 
22 class flapStruct {
23 private:
24         double Lift,Thrust,Inertia,Moment;
25 public:
26         flapStruct();
27         flapStruct(const flapStruct &rhs);
28         flapStruct(double newLift, double newThrust, double newMoment, double newInertia);
29         double getLift() const;
30         double getThrust() const;
31         double getInertia() const;
32         double getMoment() const;
33 };
34 
35 
36 class FlapData {
37 
38         //class variables
39         private:
40 
41                 //the following are the arrays of increasing
42                 //data values that were used to generate the lift, thrust
43                 //pitch and inertial values
44                 double* alphaArray;        //angle of attack
45                 double* speedArray;                      //airspeed at the wing
46                 double* freqArray;         //flapping frequency
47                 double* phiArray;
48                 //the following four tables are generated (e.g. by FullWing)
49                 //using the data in the previous three arrays
50                 double**** liftTable;            //4D array: holds the lift data
51                 double**** thrustTable;          //4D array: holds the thrust data
52                 double**** momentTable;      //4D array: holds the pitching moment data
53                 double**** inertiaTable;    //4D array: holds the inertia data
54 
55                 //The values in the tables and arrays are directly related through
56                 //their indices, in the following way:
57                 //For alpha=alphaArray[i], speed=speedArray[j] and freq=freqArray[k]
58                 //phi=phiArray[l]
59                 //the lift is equal to liftTable[i][j][k][l]
60                 int alphaLength, speedLength, freqLength, phiLength;
61                 int lastAlphaIndex, lastSpeedIndex, lastFreqIndex, lastPhiIndex;
62                 //since we're assuming the angle of attack, velocity, and frequency
63                 //don't change much between calls to flap, we keep the last indices
64                 //as a good guess of where to start searching next time
65 
66         //public methods
67         public:
68                 //Constructors:
69                         //The default constructor:
70                         //Just sets the arrays to null and the guesses to zero
71                         FlapData();
72                         //A constructor that takes a file name:
73                         //Opens that file and fills all the arrays from it
74                         //sets the guesses to zero for the speed and halfway
75                         //along the array for the alpha and frequency
76                         FlapData(const char* filename);
77                 //The destructor:
78                 //Frees all memory associated with this object
79                 ~FlapData();
80                 //An initialization function that does the same thing
81                 //as the second constructor
82                 //returns zero if it was successful
83                 int init(const char* filename);
84                 //A function that returns the interpolated values
85                 //for all four associated numbers
86                 //given the angle of attack, speed, and flapping frequency
87                 flapStruct flapper(double alpha, double speed, double frequency, double phi);
88         //private methods
89         private:
90                 //A function that returns an index i such that
91                 // array[i] < value < array[i+1]
92                 //The function returns -1 if
93                 // (value < array[0]) OR (value > array[n-1])
94                 //(i.e. the value is not within the bounds of the array)
95                 //It performs a linear search starting at LastIndex
96                 int findIndex(double array[], double n, double value, int LastIndex);
97                 //A function that performs a linear interpolation based on the
98                 //eight points surrounding the value required
99                 double interpolate(double**** table, int alphaIndex, int speedIndex, int freqIndex, int phiIndex, double alpha, double speed, double freq, double phi2);
100                 //A function that performs a linear interpolation based on the two nearest points
101                 double interpolate(double x1, double y1, double x2, double y2, double x);
102                 //A function called by init that reads in the file
103                 //of the correct format and stores it in the arrays and tables
104                 int readIn(ifstream* f);
105 };
106 
107 #endif
108