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