]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/FGFactorGroup.cpp
I have attached revisions to the UIUC code. The revisions include the
[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   totalValue = 0;
74   Debug(0);
75 }  
76
77 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
78                           
79 FGFactorGroup::~FGFactorGroup()
80 {
81   for (unsigned int i=0; i<sum.size(); i++) delete sum[i];
82
83   Debug(1);
84 }
85
86 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
87
88 bool FGFactorGroup::Load(FGConfigFile *AC_cfg)
89 {
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     } 
100     token = AC_cfg->GetValue();  
101     while (token != string("/GROUP") ) {
102       sum.push_back( new FGCoefficient(FDMExec) );
103       sum.back()->Load(AC_cfg);
104       token = AC_cfg->GetValue(); 
105     }
106     AC_cfg->GetNextConfigLine();
107     return true;
108   } else {
109     return false;
110   }  
111 }  
112
113 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
114
115 double FGFactorGroup::TotalValue(void)
116 {
117   unsigned int i;
118   SDtotal = 0.0;
119   totalValue = 0.0;
120   for (i=0; i<sum.size(); i++) {
121      totalValue += sum[i]->TotalValue();
122      SDtotal += sum[i]->GetSD();
123   }
124   //cout << totalValue << "  " << FGCoefficient::TotalValue() << endl;
125   totalValue *= FGCoefficient::TotalValue();
126   SDtotal *= FGCoefficient::GetSD();
127   Debug(2);
128   return totalValue;
129 }
130
131 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
132
133 void FGFactorGroup::bind(FGPropertyManager* parent) {
134   
135   cout << "In FGFactorGroup::bind" << endl;
136   cout << parent->getName() << endl;
137   unsigned i;
138   node=parent->GetNode(name,true);
139   cout << node->getName() << endl;
140   node->SetString("description",description);
141   FGCoefficient::bind(node);
142   for (i=0; i < sum.size(); i++) { 
143     sum[i]->bind(node);
144   } 
145   node=(FGPropertyManager*)node->getParent();                                         
146
147 }
148
149 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
150   
151 void FGFactorGroup::unbind(void) {
152   unsigned i;
153   
154   FGCoefficient::unbind();
155   for (i=0; i < sum.size(); i++) { 
156     sum[i]->unbind();
157   } 
158 }
159
160 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
161 //    The bitmasked value choices are as follows:
162 //    unset: In this case (the default) JSBSim would only print
163 //       out the normally expected messages, essentially echoing
164 //       the config files as they are read. If the environment
165 //       variable is not set, debug_lvl is set to 1 internally
166 //    0: This requests JSBSim not to output any messages
167 //       whatsoever.
168 //    1: This value explicity requests the normal JSBSim
169 //       startup messages
170 //    2: This value asks for a message to be printed out when
171 //       a class is instantiated
172 //    4: When this value is set, a message is displayed when a
173 //       FGModel object executes its Run() method
174 //    8: When this value is set, various runtime state variables
175 //       are printed out periodically
176 //    16: When set various parameters are sanity checked and
177 //       a message is printed out when they go out of bounds
178
179 void FGFactorGroup::Debug(int from)
180 {
181   if (debug_lvl <= 0) return;
182
183   if (debug_lvl & 1) { // Standard console startup message output
184   }
185   if (debug_lvl & 2 ) { // Instantiation/Destruction notification
186     if (from == 0) cout << "Instantiated: FGFactorGroup" << endl;
187     if (from == 1) cout << "Destroyed:    FGFactorGroup" << endl;
188   }
189   if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
190   }
191   if (debug_lvl & 8 ) { // Runtime state variables
192     if (from == 2) {
193       cout << "FGCoefficient::GetSD(): " << FGCoefficient::GetSD() << endl;
194       cout << "FGFactorGroup::SDtotal: " << SDtotal << endl;
195     }
196   }
197   if (debug_lvl & 16) { // Sanity checking
198   }
199   if (debug_lvl & 64) {
200     if (from == 0) { // Constructor
201       cout << IdSrc << endl;
202       cout << IdHdr << endl;
203     }
204   }
205 }
206