00001 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00002 00003 Module: FGModel.cpp 00004 Author: Jon Berndt 00005 Date started: 11/11/98 00006 Purpose: Base class for all models 00007 Called by: FGSimExec, et. al. 00008 00009 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) ------------- 00010 00011 This program is free software; you can redistribute it and/or modify it under 00012 the terms of the GNU Lesser General Public License as published by the Free Software 00013 Foundation; either version 2 of the License, or (at your option) any later 00014 version. 00015 00016 This program is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00018 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00019 details. 00020 00021 You should have received a copy of the GNU Lesser General Public License along with 00022 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00023 Place - Suite 330, Boston, MA 02111-1307, USA. 00024 00025 Further information about the GNU Lesser General Public License can also be found on 00026 the world wide web at http://www.gnu.org. 00027 00028 FUNCTIONAL DESCRIPTION 00029 -------------------------------------------------------------------------------- 00030 This base class for the FGAerodynamics, FGPropagate, etc. classes defines methods 00031 common to all models. 00032 00033 HISTORY 00034 -------------------------------------------------------------------------------- 00035 11/11/98 JSB Created 00036 00037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00038 INCLUDES 00039 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00040 00041 #include "FGModel.h" 00042 #include "FGState.h" 00043 #include "FGFDMExec.h" 00044 #include "FGAtmosphere.h" 00045 #include "FGFCS.h" 00046 #include "FGPropulsion.h" 00047 #include "FGMassBalance.h" 00048 #include "FGAerodynamics.h" 00049 #include "FGInertial.h" 00050 #include "FGGroundReactions.h" 00051 #include "FGExternalReactions.h" 00052 #include "FGAircraft.h" 00053 #include "FGPropagate.h" 00054 #include "FGAuxiliary.h" 00055 00056 namespace JSBSim { 00057 00058 static const char *IdSrc = "$Id: FGModel.cpp,v 1.7 2008/01/23 23:54:47 jberndt Exp $"; 00059 static const char *IdHdr = ID_MODEL; 00060 00061 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00062 GLOBAL DECLARATIONS 00063 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00064 00065 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00066 CLASS IMPLEMENTATION 00067 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ 00068 00069 FGModel::FGModel(FGFDMExec* fdmex) 00070 { 00071 FDMExec = fdmex; 00072 NextModel = 0L; 00073 00074 State = 0; 00075 Atmosphere = 0; 00076 FCS = 0; 00077 Propulsion = 0; 00078 MassBalance = 0; 00079 Aerodynamics = 0; 00080 Inertial = 0; 00081 GroundReactions = 0; 00082 ExternalReactions = 0; 00083 Aircraft = 0; 00084 Propagate = 0; 00085 Auxiliary = 0; 00086 00087 //in order for FGModel derived classes to self-bind (that is, call 00088 //their bind function in the constructor, the PropertyManager pointer 00089 //must be brought up now. 00090 PropertyManager = FDMExec->GetPropertyManager(); 00091 00092 exe_ctr = 1; 00093 rate = 1; 00094 00095 if (debug_lvl & 2) cout << " FGModel Base Class" << endl; 00096 } 00097 00098 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00099 00100 FGModel::~FGModel() 00101 { 00102 if (debug_lvl & 2) cout << "Destroyed: FGModel" << endl; 00103 } 00104 00105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00106 00107 bool FGModel::InitModel(void) 00108 { 00109 State = FDMExec->GetState(); 00110 Atmosphere = FDMExec->GetAtmosphere(); 00111 FCS = FDMExec->GetFCS(); 00112 Propulsion = FDMExec->GetPropulsion(); 00113 MassBalance = FDMExec->GetMassBalance(); 00114 Aerodynamics = FDMExec->GetAerodynamics(); 00115 Inertial = FDMExec->GetInertial(); 00116 GroundReactions = FDMExec->GetGroundReactions(); 00117 ExternalReactions = FDMExec->GetExternalReactions(); 00118 BuoyantForces = FDMExec->GetBuoyantForces(); 00119 Aircraft = FDMExec->GetAircraft(); 00120 Propagate = FDMExec->GetPropagate(); 00121 Auxiliary = FDMExec->GetAuxiliary(); 00122 00123 if (!State || 00124 !Atmosphere || 00125 !FCS || 00126 !Propulsion || 00127 !MassBalance || 00128 !Aerodynamics || 00129 !Inertial || 00130 !GroundReactions || 00131 !ExternalReactions || 00132 !Aircraft || 00133 !Propagate || 00134 !Auxiliary) return(false); 00135 else return(true); 00136 } 00137 00138 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00139 00140 bool FGModel::Run() 00141 { 00142 if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl; 00143 00144 if (exe_ctr++ >= rate) exe_ctr = 1; 00145 00146 if (exe_ctr == 1) return false; 00147 else return true; 00148 } 00149 00150 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 00151 // The bitmasked value choices are as follows: 00152 // unset: In this case (the default) JSBSim would only print 00153 // out the normally expected messages, essentially echoing 00154 // the config files as they are read. If the environment 00155 // variable is not set, debug_lvl is set to 1 internally 00156 // 0: This requests JSBSim not to output any messages 00157 // whatsoever. 00158 // 1: This value explicity requests the normal JSBSim 00159 // startup messages 00160 // 2: This value asks for a message to be printed out when 00161 // a class is instantiated 00162 // 4: When this value is set, a message is displayed when a 00163 // FGModel object executes its Run() method 00164 // 8: When this value is set, various runtime state variables 00165 // are printed out periodically 00166 // 16: When set various parameters are sanity checked and 00167 // a message is printed out when they go out of bounds 00168 00169 void FGModel::Debug(int from) 00170 { 00171 if (debug_lvl <= 0) return; 00172 00173 if (debug_lvl & 1) { // Standard console startup message output 00174 if (from == 0) { // Constructor 00175 00176 } 00177 } 00178 if (debug_lvl & 2 ) { // Instantiation/Destruction notification 00179 if (from == 0) cout << "Instantiated: FGModel" << endl; 00180 if (from == 1) cout << "Destroyed: FGModel" << endl; 00181 } 00182 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects 00183 } 00184 if (debug_lvl & 8 ) { // Runtime state variables 00185 } 00186 if (debug_lvl & 16) { // Sanity checking 00187 } 00188 if (debug_lvl & 64) { 00189 if (from == 0) { // Constructor 00190 cout << IdSrc << endl; 00191 cout << IdHdr << endl; 00192 } 00193 } 00194 } 00195 }
1.5.5