]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFactorGroup.cpp
Synced with latest JSBSim cvs.
[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 #  if defined(sgi) && !defined(__GNUC__)
55 #    include <iomanip.h>
56 #  else
57 #    include <iomanip>
58 #  endif
59 #else
60 #  include STL_IOMANIP
61 #endif
62
63 static const char *IdSrc = "$Id$";
64 static const char *IdHdr = ID_FACTORGROUP;
65
66 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 CLASS IMPLEMENTATION
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
69
70 FGFactorGroup::FGFactorGroup( FGFDMExec* fdmex ) : FGCoefficient( fdmex)
71 {
72   FDMExec=fdmex;
73   if (debug_lvl & 2) cout << "Instantiated: FGFactorGroup" << endl;
74 }  
75
76 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
77                           
78 FGFactorGroup::~FGFactorGroup()
79 {
80   int i;
81   for (i=0; i<sum.size(); i++) {
82     delete sum[i];
83   }
84   if (debug_lvl & 2) cout << "Destroyed:    FGFactorGroup" << endl;
85 }
86
87 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
88
89 bool FGFactorGroup::Load(FGConfigFile *AC_cfg) {
90   string token;
91   
92   if(AC_cfg) {
93     name = AC_cfg->GetValue("NAME");
94     AC_cfg->GetNextConfigLine();
95     *AC_cfg >> description;
96     token = AC_cfg->GetValue();
97     if( token == "FACTOR") {
98       FGCoefficient::Load(AC_cfg);
99       //if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
100     } 
101     token = AC_cfg->GetValue();  
102     while ( token != string("/GROUP") ) {
103           sum.push_back( new FGCoefficient(FDMExec) );
104           sum.back()->Load(AC_cfg);
105           //if (debug_lvl > 0) DisplayCoeffFactors(ca.back()->Getmultipliers());
106           token = AC_cfg->GetValue(); 
107     }
108     AC_cfg->GetNextConfigLine();
109     return true;
110   } else {
111     return false;
112   }  
113 }  
114
115 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
116
117 double FGFactorGroup::TotalValue(void) {
118   int i;
119   double totalsum=0;
120   SDtotal=0.0;
121   for(i=0;i<sum.size();i++) {
122      totalsum+=sum[i]->TotalValue();
123      SDtotal += sum[i]->GetSD();
124   }
125   totalsum *= FGCoefficient::TotalValue();
126   SDtotal *= FGCoefficient::GetSD();
127   if (debug_lvl & 8) Debug();
128   return totalsum;
129 }        
130
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
132
133 void FGFactorGroup::Debug(void)
134 {
135   cout << "FGCoefficient::GetSD(): " << FGCoefficient::GetSD() << endl;
136   cout << "FGFactorGroup::SDtotal: " << SDtotal << endl;
137 }
138