1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 Purpose: Base class for all models
7 Called by: FGSimExec, et. al.
9 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
11 This program is free software; you can redistribute it and/or modify it under
12 the terms of the GNU Lesser General Public License as published by the Free Software
13 Foundation; either version 2 of the License, or (at your option) any later
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
21 You should have received a copy of the GNU Lesser General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23 Place - Suite 330, Boston, MA 02111-1307, USA.
25 Further information about the GNU Lesser General Public License can also be found on
26 the world wide web at http://www.gnu.org.
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 This base class for the FGAerodynamics, FGPropagate, etc. classes defines methods
34 --------------------------------------------------------------------------------
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43 #include "FGFDMExec.h"
44 #include "FGAtmosphere.h"
46 #include "FGPropulsion.h"
47 #include "FGMassBalance.h"
48 #include "FGAerodynamics.h"
49 #include "FGInertial.h"
50 #include "FGGroundReactions.h"
51 #include "FGExternalReactions.h"
52 #include "FGAircraft.h"
53 #include "FGPropagate.h"
54 #include "FGAuxiliary.h"
61 static const char *IdSrc = "$Id$";
62 static const char *IdHdr = ID_MODEL;
64 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
68 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
72 FGModel::FGModel(FGFDMExec* fdmex)
85 ExternalReactions = 0;
90 //in order for FGModel derived classes to self-bind (that is, call
91 //their bind function in the constructor, the PropertyManager pointer
92 //must be brought up now.
93 PropertyManager = FDMExec->GetPropertyManager();
98 if (debug_lvl & 2) cout << " FGModel Base Class" << endl;
101 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105 for (unsigned int i=0; i<interface_properties.size(); i++) delete interface_properties[i];
106 interface_properties.clear();
108 if (debug_lvl & 2) cout << "Destroyed: FGModel" << endl;
111 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 bool FGModel::InitModel(void)
115 State = FDMExec->GetState();
116 Atmosphere = FDMExec->GetAtmosphere();
117 FCS = FDMExec->GetFCS();
118 Propulsion = FDMExec->GetPropulsion();
119 MassBalance = FDMExec->GetMassBalance();
120 Aerodynamics = FDMExec->GetAerodynamics();
121 Inertial = FDMExec->GetInertial();
122 GroundReactions = FDMExec->GetGroundReactions();
123 ExternalReactions = FDMExec->GetExternalReactions();
124 BuoyantForces = FDMExec->GetBuoyantForces();
125 Aircraft = FDMExec->GetAircraft();
126 Propagate = FDMExec->GetPropagate();
127 Auxiliary = FDMExec->GetAuxiliary();
137 !ExternalReactions ||
140 !Auxiliary) return(false);
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146 bool FGModel::Load(Element* el)
148 // Interface properties are all stored in the interface properties array.
150 string interface_property_string = "";
152 Element *property_element = el->FindElement("property");
153 if (property_element && debug_lvl > 0) cout << endl << " Declared properties" << endl << endl;
154 while (property_element) {
155 interface_property_string = property_element->GetDataLine();
156 if (PropertyManager->HasNode(interface_property_string)) {
157 cerr << " Property " << interface_property_string << " is already defined." << endl;
160 if ( ! property_element->GetAttributeValue("value").empty())
161 value = property_element->GetAttributeValueAsNumber("value");
162 interface_properties.push_back(new double(value));
163 PropertyManager->Tie(interface_property_string, interface_properties.back());
165 cout << " " << interface_property_string << " (initial value: " << value << ")" << endl;
167 property_element = el->FindNextElement("property");
173 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177 if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl;
179 if (exe_ctr++ >= rate) exe_ctr = 1;
181 if (exe_ctr == 1) return false;
185 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 // The bitmasked value choices are as follows:
187 // unset: In this case (the default) JSBSim would only print
188 // out the normally expected messages, essentially echoing
189 // the config files as they are read. If the environment
190 // variable is not set, debug_lvl is set to 1 internally
191 // 0: This requests JSBSim not to output any messages
193 // 1: This value explicity requests the normal JSBSim
195 // 2: This value asks for a message to be printed out when
196 // a class is instantiated
197 // 4: When this value is set, a message is displayed when a
198 // FGModel object executes its Run() method
199 // 8: When this value is set, various runtime state variables
200 // are printed out periodically
201 // 16: When set various parameters are sanity checked and
202 // a message is printed out when they go out of bounds
204 void FGModel::Debug(int from)
206 if (debug_lvl <= 0) return;
208 if (debug_lvl & 1) { // Standard console startup message output
209 if (from == 0) { // Constructor
213 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
214 if (from == 0) cout << "Instantiated: FGModel" << endl;
215 if (from == 1) cout << "Destroyed: FGModel" << endl;
217 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
219 if (debug_lvl & 8 ) { // Runtime state variables
221 if (debug_lvl & 16) { // Sanity checking
223 if (debug_lvl & 64) {
224 if (from == 0) { // Constructor
225 cout << IdSrc << endl;
226 cout << IdHdr << endl;