]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFactorGroup.cpp
Updates.
[flightgear.git] / src / FDM / JSBSim / FGFactorGroup.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Module:       FGFactorGroup.cpp
4  Author:       Tony Peden
5  Date started: 7/21/01
6  Purpose:      Encapsulates coefficients in the mathematical construct:
7                factor*(coeff1 + coeff2 + coeff3 + ... + coeffn)
8  Called by:    FGAerodynamics
9
10  ------------- Copyright (C) 2001 Tony Peden (apeden@earthlink.net) -----------
11
12  This program is free software; you can redistribute it and/or modify it under
13  the terms of the GNU General Public License as published by the Free Software
14  Foundation; either version 2 of the License, or (at your option) any later
15  version.
16
17  This program is distributed in the hope that it will be useful, but WITHOUT
18  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
20  details.
21
22  You should have received a copy of the GNU General Public License along with
23  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24  Place - Suite 330, Boston, MA  02111-1307, USA.
25
26  Further information about the GNU General Public License can also be found on
27  the world wide web at http://www.gnu.org.
28
29 FUNCTIONAL DESCRIPTION
30 --------------------------------------------------------------------------------
31 This class models the stability derivative coefficient lookup tables or
32 equations. Note that the coefficients need not be calculated each delta-t.
33
34 Note that the values in a row which index into the table must be the same value
35 for each column of data, so the first column of numbers for each altitude are
36 seen to be equal, and there are the same number of values for each altitude.
37
38 See the header file FGFactorGroup.h for the values of the identifiers.
39
40 HISTORY
41 --------------------------------------------------------------------------------
42 7/21/01   TP  Created
43
44 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45 INCLUDES
46 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47
48 #include "FGCoefficient.h"
49 #include "FGFactorGroup.h"
50 #include "FGState.h"
51 #include "FGFDMExec.h"
52
53 #ifndef FGFS
54 #  include <iomanip>
55 #else
56 #  include STL_IOMANIP
57 #endif
58
59 extern short debug_lvl;
60
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_FACTORGROUP;
63
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65 CLASS IMPLEMENTATION
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
67
68 FGFactorGroup::FGFactorGroup( FGFDMExec* fdmex ) : FGCoefficient( fdmex)
69 {
70   FDMExec=fdmex;
71   if (debug_lvl & 2) cout << "Instantiated: FGFactorGroup" << endl;
72 }  
73
74 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
75                           
76 FGFactorGroup::~FGFactorGroup()
77 {
78   int i;
79   for (i=0; i<sum.size(); i++) {
80     delete sum[i];
81   }
82   if (debug_lvl & 2) cout << "Destroyed:    FGFactorGroup" << endl;
83 }
84
85 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
86
87 bool FGFactorGroup::Load(FGConfigFile *AC_cfg) {
88   string token;
89   
90   if(AC_cfg) {
91     name = AC_cfg->GetValue("NAME");
92     AC_cfg->GetNextConfigLine();
93     *AC_cfg >> description;
94     token = AC_cfg->GetValue();
95     if( token == "FACTOR") {
96       FGCoefficient::Load(AC_cfg);
97       //if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
98     } 
99     token = AC_cfg->GetValue();  
100     while ( token != "/GROUP" ) {
101           sum.push_back( new FGCoefficient(FDMExec) );
102           sum.back()->Load(AC_cfg);
103           //if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
104           token = AC_cfg->GetValue(); 
105     }
106     AC_cfg->GetNextConfigLine();
107     return true;
108   } else {
109     return false;
110   }  
111 }  
112
113 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
114
115 float FGFactorGroup::TotalValue(void) {
116   int i;
117   float totalsum=0;
118   SDtotal=0.0;
119   for(i=0;i<sum.size();i++) {
120      totalsum+=sum[i]->TotalValue();
121      SDtotal += sum[i]->GetSD();
122   }
123   totalsum *= FGCoefficient::TotalValue();
124   SDtotal *= FGCoefficient::GetSD();
125   if (debug_lvl & 8) Debug();
126   return totalsum;
127 }        
128
129 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
130
131 string FGFactorGroup::GetCoefficientStrings(void) {
132   int i;
133   string CoeffStrings;
134   
135   CoeffStrings += name;
136   CoeffStrings += ", ";
137   CoeffStrings += FGCoefficient::Getname();
138   for(i=0;i<sum.size();i++) {
139     CoeffStrings += ", ";
140     CoeffStrings += sum[i]->Getname();
141   }
142   return CoeffStrings;    
143 }
144
145 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
146
147 string FGFactorGroup::GetCoefficientValues(void) {
148     int i;
149     char buffer[10];
150     string values;
151     
152     snprintf(buffer,10,"%9.6f",SDtotal);
153     values += string(buffer);
154     values += ", ";
155     snprintf(buffer,10,"%9.6f",FGCoefficient::GetSD() );
156     values += string(buffer);
157     values += ", ";
158     for(i=0;i<sum.size();i++) {
159        values += sum[i]->GetCoefficientValues();
160     }
161     return values;
162 }       
163
164 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
165
166 void FGFactorGroup::Debug(void)
167 {
168   cout << "FGCoefficient::GetSD(): " << FGCoefficient::GetSD() << endl;
169   cout << "FGFactorGroup::SDtotal: " << SDtotal << endl;
170 }
171