JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGModel.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGModel.cpp
4 Author: Jon Berndt
5 Date started: 11/11/98
6 Purpose: Base class for all models
7 Called by: FGSimExec, et. al.
8
9 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
10
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
13 Software Foundation; either version 2 of the License, or (at your option) any
14 later version.
15
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
19 details.
20
21 You should have received a copy of the GNU Lesser General Public License along
22 with this program; if not, write to the Free Software Foundation, Inc., 59
23 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25 Further information about the GNU Lesser General Public License can also be
26 found on the world wide web at http://www.gnu.org.
27
28FUNCTIONAL DESCRIPTION
29--------------------------------------------------------------------------------
30This base class for the FGAerodynamics, FGPropagate, etc. classes defines
31methods common to all models.
32
33HISTORY
34--------------------------------------------------------------------------------
3511/11/98 JSB Created
36
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38INCLUDES
39%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41#include "FGModel.h"
42#include "FGFDMExec.h"
43#include "input_output/FGModelLoader.h"
44#include "input_output/FGLog.h"
45
46using namespace std;
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51GLOBAL DECLARATIONS
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55CLASS IMPLEMENTATION
56%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57
59{
60 FDMExec = fdmex;
61
62 //in order for FGModel derived classes to self-bind (that is, call
63 //their bind function in the constructor, the PropertyManager pointer
64 //must be brought up now.
65 PropertyManager = FDMExec->GetPropertyManager();
66
67 exe_ctr = 1;
68 rate = 1;
69
70 Debug(0);
71}
72
73//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
74
76{
77 Debug(1);
78}
79
80//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81
82bool FGModel::InitModel(void)
83{
84 exe_ctr = 1;
85 return FGModelFunctions::InitModel();
86}
87
88//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
90bool FGModel::Run(bool Holding)
91{
92 FGModel::Debug(2);
93
94 if (rate == 1) return false; // Fast exit if nothing to do
95
96 if (exe_ctr >= rate) exe_ctr = 0;
97
98 if (exe_ctr++ == 1) return false;
99 else return true;
100}
101
102//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104SGPath FGModel::FindFullPathName(const SGPath& path) const
105{
106 return CheckPathName(FDMExec->GetFullAircraftPath(), path);
107}
108
109//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
111bool FGModel::Upload(Element* el, bool preLoad)
112{
113 FGModelLoader ModelLoader(this);
114 Element* document = ModelLoader.Open(el);
115
116 if (!document) return false;
117
118 if (document->GetName() != el->GetName()) {
119 FGXMLLogging log(el, LogLevel::ERROR);
120 log << " Read model '" << document->GetName()
121 << "' while expecting model '" << el->GetName() << "'" << endl;
122 return false;
123 }
124
125 bool result = true;
126
127 if (preLoad)
128 result = FGModelFunctions::Load(document, FDMExec);
129
130 if (document != el) {
131 el->MergeAttributes(document);
132
133 if (preLoad) {
134 // After reading interface properties in a file, read properties in the
135 // local model element. This allows general-purpose models to be defined
136 // in a file, with overrides or initial loaded constants supplied in the
137 // relevant element of the aircraft configuration file.
138 LocalProperties.Load(el, PropertyManager.get(), true);
139 }
140
141 Element* element = document->FindElement();
142 while (element) {
143 el->AddChildElement(element);
144 element->SetParent(el);
145 element = document->FindNextElement();
146 }
147 }
148
149 return result;
150}
151
152//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153// The bitmasked value choices are as follows:
154// unset: In this case (the default) JSBSim would only print
155// out the normally expected messages, essentially echoing
156// the config files as they are read. If the environment
157// variable is not set, debug_lvl is set to 1 internally
158// 0: This requests JSBSim not to output any messages
159// whatsoever.
160// 1: This value explicity requests the normal JSBSim
161// startup messages
162// 2: This value asks for a message to be printed out when
163// a class is instantiated
164// 4: When this value is set, a message is displayed when a
165// FGModel object executes its Run() method
166// 8: When this value is set, various runtime state variables
167// are printed out periodically
168// 16: When set various parameters are sanity checked and
169// a message is printed out when they go out of bounds
170
171void FGModel::Debug(int from)
172{
173 if (debug_lvl <= 0) return;
174
175 if (debug_lvl & 1) { // Standard console startup message output
176 if (from == 0) { // Constructor
177
178 }
179 }
180 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
181 FGLogging log(LogLevel::DEBUG);
182 if (from == 0) log << "Instantiated: FGModel" << endl;
183 if (from == 1) log << "Destroyed: FGModel" << endl;
184 }
185 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
186 FGLogging log(LogLevel::DEBUG);
187 if (from ==2) log << "Entering Run() for model " << Name << endl;
188 }
189 if (debug_lvl & 8 ) { // Runtime state variables
190 }
191 if (debug_lvl & 16) { // Sanity checking
192 }
193 if (debug_lvl & 64) {
194 if (from == 0) { // Constructor
195 }
196 }
197}
198}
Element * FindElement(const std::string &el="")
Searches for a specified element.
const std::string & GetName(void) const
Retrieves the element name.
void MergeAttributes(Element *el)
Merges the attributes of the current element with another element.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
void AddChildElement(Element *el)
Adds a child element to the list of children stored for this element.
void SetParent(Element *p)
This function sets the value of the parent class attribute to the supplied Element pointer.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
const SGPath & GetFullAircraftPath(void)
Retrieves the full aircraft path name.
Definition FGFDMExec.h:402
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
Definition FGFDMExec.h:422
~FGModel() override
Destructor.
Definition FGModel.cpp:75
FGModel(FGFDMExec *)
Constructor.
Definition FGModel.cpp:58
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:90
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:111
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71