JSBSim Flight Dynamics Model 1.3.3 (16 Oct 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGModel Class Reference

Detailed Description

Base class for all scheduled JSBSim models.

Each model binds simulation/models/<Name>/enabled (default true), where Name is the name passed to the constructor. Setting that property false skips the model's Run(): its last state and its property bindings are preserved, which is the property-tree mechanism by which an external system can replace a model, for example a host physics engine owning FGGroundReactions. The binding is made at construction, so a model that renames itself while loading does not move its enable property.

Author
Jon S. Berndt

Definition at line 78 of file FGModel.h.

#include <FGModel.h>

+ Inheritance diagram for FGModel:
+ Collaboration diagram for FGModel:

Public Member Functions

 FGModel (FGFDMExec *, const std::string &name)
 Constructor.
 
 ~FGModel () override
 Destructor.
 
virtual SGPath FindFullPathName (const SGPath &path) const
 
FGFDMExec * GetExec (void) const
 
const std::string & GetName (void) const
 
unsigned int GetRate (void) const
 Get the output rate for the model in frames.
 
bool InitModel (void) override
 
virtual bool Load (Element *el)
 
virtual bool Run (bool Holding)
 Runs the model; called by the Executive.
 
void SetPropertyManager (std::shared_ptr< FGPropertyManager > fgpm)
 
void SetRate (unsigned int tt)
 Set the ouput rate for the model in frames.
 
- Public Member Functions inherited from FGModelFunctions
std::string GetFunctionStrings (const std::string &delimeter) const
 Gets the strings for the current set of functions.
 
std::string GetFunctionValues (const std::string &delimeter) const
 Gets the function values.
 
std::shared_ptr< FGFunction > GetPreFunction (const std::string &name)
 Get one of the "pre" function.
 
bool Load (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void PostLoad (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void PreLoad (Element *el, FGFDMExec *fdmex, std::string prefix="")
 
void RunPostFunctions (void)
 
void RunPreFunctions (void)
 
- Public Member Functions inherited from FGJSBBase
 FGJSBBase ()
 Constructor for FGJSBBase.
 
virtual ~FGJSBBase ()
 Destructor for FGJSBBase.
 

Protected Member Functions

virtual void Debug (int from)
 
bool Upload (Element *el, bool preLoad)
 Uploads this model in memory.
 

Protected Attributes

bool enabled = true
 
unsigned int exe_ctr
 
FGFDMExec * FDMExec
 
std::string Name
 
std::shared_ptr< FGPropertyManager > PropertyManager
 
unsigned int rate
 
- Protected Attributes inherited from FGModelFunctions
FGPropertyReader LocalProperties
 
std::vector< std::shared_ptr< FGFunction > > PostFunctions
 
std::vector< std::shared_ptr< FGFunction > > PreFunctions
 

Additional Inherited Members

- Public Types inherited from FGJSBBase
enum  { eL = 1 , eM , eN }
 Moments L, M, N. More...
 
enum  { eP = 1 , eQ , eR }
 Rates P, Q, R. More...
 
enum  { eU = 1 , eV , eW }
 Velocities U, V, W. More...
 
enum  { eX = 1 , eY , eZ }
 Positions X, Y, Z. More...
 
enum  { ePhi = 1 , eTht , ePsi }
 Euler angles Phi, Theta, Psi. More...
 
enum  { eDrag = 1 , eSide , eLift }
 Stability axis forces, Drag, Side force, Lift. More...
 
enum  { eRoll = 1 , ePitch , eYaw }
 Local frame orientation Roll, Pitch, Yaw. More...
 
enum  { eNorth = 1 , eEast , eDown }
 Local frame position North, East, Down. More...
 
enum  { eLat = 1 , eLong , eRad }
 Locations Radius, Latitude, Longitude. More...
 
enum  {
  inNone = 0 , inDegrees , inRadians , inMeters ,
  inFeet
}
 Conversion specifiers. More...
 
- Static Public Member Functions inherited from FGJSBBase
static constexpr double CelsiusToFahrenheit (double celsius)
 Converts from degrees Celsius to degrees Fahrenheit.
 
static constexpr double CelsiusToKelvin (double celsius)
 Converts from degrees Celsius to degrees Kelvin.
 
static constexpr double CelsiusToRankine (double celsius)
 Converts from degrees Celsius to degrees Rankine.
 
static constexpr double Constrain (double min, double value, double max)
 Constrain a value between a minimum and a maximum value.
 
static bool EqualToRoundoff (double a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (double a, float b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, double b)
 Finite precision comparison.
 
static bool EqualToRoundoff (float a, float b)
 Finite precision comparison.
 
static constexpr double FahrenheitToCelsius (double fahrenheit)
 Converts from degrees Fahrenheit to degrees Celsius.
 
static constexpr double FeetToMeters (double measure)
 Converts from feet to meters.
 
static const std::string & GetVersion (void)
 Returns the version number of JSBSim.
 
static constexpr double KelvinToCelsius (double kelvin)
 Converts from degrees Kelvin to degrees Celsius.
 
static constexpr double KelvinToFahrenheit (double kelvin)
 Converts from degrees Kelvin to degrees Fahrenheit.
 
static constexpr double KelvinToRankine (double kelvin)
 Converts from degrees Kelvin to degrees Rankine.
 
static constexpr double RankineToCelsius (double rankine)
 Converts from degrees Rankine to degrees Celsius.
 
static constexpr double RankineToKelvin (double rankine)
 Converts from degrees Rankine to degrees Kelvin.
 
static constexpr double sign (double num)
 
- Static Public Attributes inherited from FGJSBBase
static short debug_lvl = 1
 
- Static Protected Member Functions inherited from FGJSBBase
static std::string CreateIndexedPropertyName (const std::string &Property, int index)
 
- Static Protected Attributes inherited from FGJSBBase
static constexpr double degtorad = M_PI / 180.
 
static constexpr double fpstokts = 1.0 / ktstofps
 
static constexpr double fttom = 0.3048
 
static constexpr double hptoftlbssec = 550.0
 
static constexpr double in3tom3 = inchtoft*inchtoft*inchtoft/m3toft3
 
static constexpr double inchtoft = 1.0/12.0
 
static constexpr double inhgtopa = 3386.38
 
static const std::string JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__
 
static constexpr double kgtolb = 2.20462
 
static constexpr double kgtoslug = 0.06852168
 
static constexpr double ktstofps = 1852./(3600*fttom)
 
static constexpr double lbtoslug = 1.0/slugtolb
 
static constexpr double m3toft3 = 1.0/(fttom*fttom*fttom)
 
static const std::string needed_cfg_version = "2.0"
 
static constexpr double psftoinhg = 0.014138
 
static constexpr double psftopa = 47.88
 
static constexpr double radtodeg = 180. / M_PI
 
static constexpr double slugtolb = 32.174049
 Note that definition of lbtoslug by the inverse of slugtolb and not to a different constant you can also get from some tables will make lbtoslug*slugtolb == 1 up to the magnitude of roundoff.
 

Constructor & Destructor Documentation

◆ FGModel()

FGModel ( FGFDMExec *  fdmex,
const std::string &  name 
)

Constructor.

Parameters
namethe name of this model. It populates the member Name and binds simulation/models/<name>/enabled.

Definition at line 59 of file FGModel.cpp.

60 : Name(name)
61{
62 FDMExec = fdmex;
63
64 //in order for FGModel derived classes to self-bind (that is, call
65 //their bind function in the constructor, the PropertyManager pointer
66 //must be brought up now.
67 PropertyManager = FDMExec->GetPropertyManager();
68
69 exe_ctr = 1;
70 rate = 1;
71
72 // A model that is scheduled by FGFDMExec is named and gets an enable property.
73 // The input and output types are not scheduled: they are instantiated one per
74 // <input> and <output> element, so a shared property path would be tied more
75 // than once. They pass an empty name and are enabled through the per-instance
76 // property that FGOutputType::SetIdx already binds, or through Enable() and
77 // Disable().
78 if (!Name.empty())
79 PropertyManager->Tie("simulation/models/" + Name + "/enabled", &enabled);
80
81 Debug(0);
82}
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
Definition FGFDMExec.h:422
+ Here is the call graph for this function:

◆ ~FGModel()

~FGModel ( )
override

Destructor.

Definition at line 86 of file FGModel.cpp.

87{
88 Debug(1);
89}

Member Function Documentation

◆ Debug()

void Debug ( int  from)
protectedvirtual

Definition at line 183 of file FGModel.cpp.

184{
185 if (debug_lvl <= 0) return;
186
187 if (debug_lvl & 1) { // Standard console startup message output
188 if (from == 0) { // Constructor
189
190 }
191 }
192 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
193 FGLogging log(LogLevel::DEBUG);
194 if (from == 0) log << "Instantiated: FGModel" << endl;
195 if (from == 1) log << "Destroyed: FGModel" << endl;
196 }
197 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
198 FGLogging log(LogLevel::DEBUG);
199 if (from ==2) log << "Entering Run() for model " << Name << endl;
200 }
201 if (debug_lvl & 8 ) { // Runtime state variables
202 }
203 if (debug_lvl & 16) { // Sanity checking
204 }
205 if (debug_lvl & 64) {
206 if (from == 0) { // Constructor
207 }
208 }
209}

◆ FindFullPathName()

SGPath FindFullPathName ( const SGPath &  path) const
virtual

Definition at line 116 of file FGModel.cpp.

117{
118 return CheckPathName(FDMExec->GetFullAircraftPath(), path);
119}
const SGPath & GetFullAircraftPath(void)
Retrieves the full aircraft path name.
Definition FGFDMExec.h:402

◆ GetExec()

FGFDMExec * GetExec ( void  ) const
inline

Definition at line 105 of file FGModel.h.

105{ return FDMExec; }

◆ GetName()

const std::string & GetName ( void  ) const
inline

Definition at line 109 of file FGModel.h.

109{ return Name; }

◆ GetRate()

unsigned int GetRate ( void  ) const
inline

Get the output rate for the model in frames.

Definition at line 104 of file FGModel.h.

104{ return rate; }

◆ InitModel()

bool InitModel ( void  )
overridevirtual

Reimplemented from FGModelFunctions.

Reimplemented in FGPropagate, FGOutputFile, FGOutputSocket, FGOutputType, FGMSIS, and FGOutput.

Definition at line 93 of file FGModel.cpp.

94{
95 exe_ctr = 1;
96 return FGModelFunctions::InitModel();
97}

◆ Load()

virtual bool Load ( Element *  el)
inlinevirtual

◆ Run()

bool Run ( bool  Holding)
virtual

Runs the model; called by the Executive.

Can pass in a value indicating if the executive is directing the simulation to Hold.

Parameters
Holdingif true, the executive has been directed to hold the sim from advancing time. Some models may ignore this flag, such as the Input model, which may need to be active to listen on a socket for the "Resume" command to be given. The Holding flag is not used in the base FGModel class.
See also
JSBSim.cpp documentation
Returns
false if no error

Reimplemented in FGPropagate, FGInputType, FGOutputType, FGWinds, FGAccelerations, FGAerodynamics, FGAircraft, FGAtmosphere, FGAuxiliary, FGBuoyantForces, FGExternalReactions, FGFCS, FGGroundReactions, FGInertial, FGInput, FGMassBalance, FGOutput, and FGPropulsion.

Definition at line 101 of file FGModel.cpp.

102{
103 FGModel::Debug(2);
104
105 if (rate == 1) return !enabled; // Fast exit if nothing to do
106
107 if (exe_ctr >= rate) exe_ctr = 0;
108
109 if (exe_ctr++ == 1) return !enabled;
110
111 return true;
112}
+ Here is the caller graph for this function:

◆ SetPropertyManager()

void SetPropertyManager ( std::shared_ptr< FGPropertyManager >  fgpm)
inline

Definition at line 107 of file FGModel.h.

107{ PropertyManager=fgpm;}

◆ SetRate()

void SetRate ( unsigned int  tt)
inline

Set the ouput rate for the model in frames.

Definition at line 102 of file FGModel.h.

102{rate = tt;}
+ Here is the caller graph for this function:

◆ Upload()

bool Upload ( Element *  el,
bool  preLoad 
)
protected

Uploads this model in memory.

Uploads the model in memory if its contents are contained in a separate file.

Parameters
ela pointer to the element
preLoadtrue if model functions and local properties must be preloaded.
Returns
true if model is successfully loaded

Definition at line 123 of file FGModel.cpp.

124{
125 FGModelLoader ModelLoader(this);
126 Element* document = ModelLoader.Open(el);
127
128 if (!document) return false;
129
130 if (document->GetName() != el->GetName()) {
131 FGXMLLogging log(el, LogLevel::ERROR);
132 log << " Read model '" << document->GetName()
133 << "' while expecting model '" << el->GetName() << "'" << endl;
134 return false;
135 }
136
137 bool result = true;
138
139 if (preLoad)
140 result = FGModelFunctions::Load(document, FDMExec);
141
142 if (document != el) {
143 el->MergeAttributes(document);
144
145 if (preLoad) {
146 // After reading interface properties in a file, read properties in the
147 // local model element. This allows general-purpose models to be defined
148 // in a file, with overrides or initial loaded constants supplied in the
149 // relevant element of the aircraft configuration file.
150 LocalProperties.Load(el, PropertyManager.get(), true);
151 }
152
153 Element* element = document->FindElement();
154 while (element) {
155 el->AddChildElement(element);
156 element->SetParent(el);
157 element = document->FindNextElement();
158 }
159 }
160
161 return result;
162}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ enabled

bool enabled = true
protected

Definition at line 115 of file FGModel.h.

◆ exe_ctr

unsigned int exe_ctr
protected

Definition at line 113 of file FGModel.h.

◆ FDMExec

FGFDMExec* FDMExec
protected

Definition at line 129 of file FGModel.h.

◆ Name

std::string Name
protected

Definition at line 116 of file FGModel.h.

◆ PropertyManager

std::shared_ptr<FGPropertyManager> PropertyManager
protected

Definition at line 130 of file FGModel.h.

◆ rate

unsigned int rate
protected

Definition at line 114 of file FGModel.h.


The documentation for this class was generated from the following files: