JSBSim Flight Dynamics Model 1.3.1 (17 May 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGFDMExec.h
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 Header: FGFDMExec.h
3 Author: Jon Berndt
4 Date started: 11/17/98
5 file The header file for the JSBSim executive.
6
7 ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
8
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU Lesser General Public License as published by the Free
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later version.
13
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
17 details.
18
19 You should have received a copy of the GNU Lesser General Public License along
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26HISTORY
27--------------------------------------------------------------------------------
2811/17/98 JSB Created
297/31/99 TP Added RunIC function that runs the sim so that every frame
30 begins with the IC values from the given FGInitialCondition
31 object and dt=0.
32
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34SENTRY
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
36
37#ifndef FGFDMEXEC_HEADER_H
38#define FGFDMEXEC_HEADER_H
39
40/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41INCLUDES
42%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
43
44#include <memory>
45
46#include "models/FGPropagate.h"
47#include "models/FGOutput.h"
48#include "models/FGInput.h"
49#include "math/FGTemplateFunc.h"
50
51/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52FORWARD DECLARATIONS
53%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54
55namespace JSBSim {
56
57class FGScript;
58class FGTrim;
59class FGAerodynamics;
60class FGAircraft;
61class FGAtmosphere;
62class FGAccelerations;
63class FGWinds;
64class FGAuxiliary;
65class FGBuoyantForces;
66class FGExternalReactions;
67class FGGroundReactions;
68class FGFCS;
69class FGInertial;
70class FGPropulsion;
71class FGMassBalance;
72class FGLogger;
73
75 public:
76 TrimFailureException(const std::string& msg) : BaseException(msg) {}
77};
78
79/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80CLASS DOCUMENTATION
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82
180/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181CLASS DECLARATION
182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
183
184class JSBSIM_API FGFDMExec : public FGJSBBase
185{
186 struct childData {
187 std::unique_ptr<FGFDMExec> exec;
188 std::string info;
189 FGColumnVector3 Loc;
190 FGColumnVector3 Orient;
191 bool mated;
192 bool internal;
193
194 childData(void) {
195 info = "";
196 Loc = FGColumnVector3(0,0,0);
197 Orient = FGColumnVector3(0,0,0);
198 mated = true;
199 internal = false;
200 }
201
202 void Run(void) {exec->Run();}
203 void AssignState(FGPropagate* source_prop) {
204 exec->GetPropagate()->SetVState(source_prop->GetVState());
205 }
206 };
207
208public:
209
211 FGFDMExec(FGPropertyManager* root = nullptr, std::shared_ptr<unsigned int> fdmctr = nullptr);
212
214 ~FGFDMExec();
215
216 // This list of enums is very important! The order in which models are listed
217 // here determines the order of execution of the models.
218 //
219 // There are some conditions that need to be met :
220 // 1. FCS can request mass geometry changes via the inertia/pointmass-*
221 // properties so it must be executed before MassBalance
222 // 2. MassBalance must be executed before Propulsion, Aerodynamics,
223 // GroundReactions, ExternalReactions and BuoyantForces to ensure that
224 // their moments are computed with the updated CG position.
225 enum eModels { ePropagate=0,
226 eInput,
227 eInertial,
228 eAtmosphere,
229 eWinds,
230 eSystems,
231 eMassBalance,
232 eAuxiliary,
233 ePropulsion,
234 eAerodynamics,
235 eGroundReactions,
236 eExternalReactions,
237 eBuoyantForces,
238 eAircraft,
239 eAccelerations,
240 eOutput,
241 eNumStandardModels };
242
244 void Unbind(void) {instance->Unbind();}
245
248 bool Run(void);
249
253 bool RunIC(void);
254
261 bool LoadPlanet(const SGPath& PlanetPath, bool useAircraftPath = true);
262
278 bool LoadModel(const SGPath& AircraftPath, const SGPath& EnginePath,
279 const SGPath& SystemsPath, const std::string& model,
280 bool addModelToPath = true);
281
292 bool LoadModel(const std::string& model, bool addModelToPath = true);
293
305 bool LoadScript(const SGPath& Script, double deltaT=0.0,
306 const SGPath& initfile=SGPath());
307
314 bool SetEnginePath(const SGPath& path) {
315 EnginePath = GetFullPath(path);
316 return true;
317 }
318
326 bool SetAircraftPath(const SGPath& path) {
327 AircraftPath = GetFullPath(path);
328 return true;
329 }
330
337 bool SetSystemsPath(const SGPath& path) {
338 SystemsPath = GetFullPath(path);
339 return true;
340 }
341
348 bool SetOutputPath(const SGPath& path) {
349 OutputPath = GetFullPath(path);
350 return true;
351 }
352
356 std::shared_ptr<FGAtmosphere> GetAtmosphere(void) const;
358 std::shared_ptr<FGAccelerations> GetAccelerations(void) const;
360 std::shared_ptr<FGWinds> GetWinds(void) const;
362 std::shared_ptr<FGFCS> GetFCS(void) const;
364 std::shared_ptr<FGPropulsion> GetPropulsion(void) const;
366 std::shared_ptr<FGMassBalance> GetMassBalance(void) const;
368 std::shared_ptr<FGAerodynamics> GetAerodynamics(void) const;
370 std::shared_ptr<FGInertial> GetInertial(void) const;
372 std::shared_ptr<FGGroundReactions> GetGroundReactions(void) const;
374 std::shared_ptr<FGExternalReactions> GetExternalReactions(void) const;
376 std::shared_ptr<FGBuoyantForces> GetBuoyantForces(void) const;
378 std::shared_ptr<FGAircraft> GetAircraft(void) const;
380 std::shared_ptr<FGPropagate> GetPropagate(void) const;
382 std::shared_ptr<FGAuxiliary> GetAuxiliary(void) const;
384 std::shared_ptr<FGInput> GetInput(void) const;
386 std::shared_ptr<FGOutput> GetOutput(void) const;
388 std::shared_ptr<FGScript> GetScript(void) const {return Script;}
390 std::shared_ptr<FGInitialCondition> GetIC(void) const {return IC;}
392 std::shared_ptr<FGTrim> GetTrim(void);
394
396 const SGPath& GetEnginePath(void) { return EnginePath; }
398 const SGPath& GetAircraftPath(void) { return AircraftPath; }
400 const SGPath& GetSystemsPath(void) { return SystemsPath; }
402 const SGPath& GetFullAircraftPath(void) { return FullAircraftPath; }
404 const SGPath& GetOutputPath(void) { return OutputPath; }
405
409 double GetPropertyValue(const std::string& property)
410 { return instance->GetNode()->getDoubleValue(property.c_str()); }
411
415 void SetPropertyValue(const std::string& property, double value)
416 { instance->GetNode()->setDoubleValue(property.c_str(), value); }
417
419 const std::string& GetModelName(void) const { return modelName; }
420
422 std::shared_ptr<FGPropertyManager> GetPropertyManager(void) const { return instance; }
424 std::vector <std::string> EnumerateFDMs(void);
426 size_t GetFDMCount(void) const {return ChildFDMList.size();}
428 auto GetChildFDM(int i) const {return ChildFDMList[i];}
430 void SetChild(bool ch) {IsChild = ch;}
431
447 bool SetOutputDirectives(const SGPath& fname)
448 { return Output->SetDirectivesFile(GetFullPath(fname)); }
449
451 void ForceOutput(int idx=0) { Output->ForceOutput(idx); }
452
454 void SetLoggingRate(double rate) { Output->SetRateHz(rate); }
455
460 bool SetOutputFileName(const int n, const std::string& fname) { return Output->SetOutputName(n, fname); }
461
466 std::string GetOutputFileName(int n) const { return Output->GetOutputName(n); }
467
477 void DoTrim(int mode);
478
482 void DoLinearization(int);
483
485 void DisableOutput(void) { Output->Disable(); }
487 void EnableOutput(void) { Output->Enable(); }
489 void DisableInput(void) { Input->Disable(); }
491 void EnableInput(void) { Input->Enable(); }
493 void Hold(void) {holding = true;}
495 void EnableIncrementThenHold(int Timesteps) {TimeStepsUntilHold = Timesteps; IncrementThenHolding = true;}
497 void CheckIncrementalHold(void);
499 void Resume(void) {holding = false;}
501 bool Holding(void) {return holding;}
503 static const int START_NEW_OUTPUT = 0x1;
504 static const int DONT_EXECUTE_RUN_IC = 0x2;
512 void ResetToInitialConditions(int mode);
514 void SetDebugLevel(int level) {debug_lvl = level;}
515
518 std::string base_string;
520 SGPropertyNode_ptr node;
521 };
522
527 void BuildPropertyCatalog(struct PropertyCatalogStructure* pcs);
528
536 std::string QueryPropertyCatalog(const std::string& check, const std::string& end_of_line="\n");
537
538 // Print the contents of the property catalog for the loaded aircraft.
539 void PrintPropertyCatalog(void);
540
541 // Print the simulation configuration
542 void PrintSimulationConfiguration(void) const;
543
544 std::vector<std::string>& GetPropertyCatalog(void) {return PropertyCatalog;}
545
546 void SetTrimStatus(bool status){ trim_status = status; }
547 bool GetTrimStatus(void) const { return trim_status; }
548 void SetTrimMode(int mode){ ta_mode = mode; }
549 int GetTrimMode(void) const { return ta_mode; }
550
551 std::string GetPropulsionTankReport() const;
552
554 double GetSimTime(void) const { return sim_time; }
555
557 double GetDeltaT(void) const {return dT;}
558
560 void SuspendIntegration(void) {saved_dT = dT; dT = 0.0;}
561
563 void ResumeIntegration(void) {dT = saved_dT;}
564
567 bool IntegrationSuspended(void) const {return dT == 0.0;}
568
572 double Setsim_time(double cur_time);
573
576 void Setdt(double delta_t) { dT = delta_t; }
577
590 void SetRootDir(const SGPath& rootDir) {RootDir = rootDir;}
591
595 const SGPath& GetRootDir(void) const {return RootDir;}
596
600 double IncrTime(void);
601
603 unsigned int GetFrame(void) const {return Frame;}
604
606 int GetDebugLevel(void) const {return debug_lvl;};
607
610 void Initialize(const FGInitialCondition* FGIC);
611
616 void SetHoldDown(bool hd);
617
621 bool GetHoldDown(void) const {return HoldDown;}
622
623 FGTemplateFunc_ptr GetTemplateFunc(const std::string& name) {
624 return TemplateFunctions.count(name) ? TemplateFunctions[name] : nullptr;
625 }
626
627 void AddTemplateFunc(const std::string& name, Element* el) {
628 TemplateFunctions[name] = std::make_shared<FGTemplateFunc>(this, el);
629 }
630
631 auto GetRandomGenerator(void) const { return RandomGenerator; }
632
633 int SRand(void) const { return RandomSeed; }
634
635private:
636 unsigned int Frame;
637 unsigned int IdFDM;
638 int disperse;
639 bool Terminate;
640 double dT;
641 double saved_dT;
642 double sim_time;
643 bool holding;
644 bool IncrementThenHolding;
645 int TimeStepsUntilHold;
646 bool Constructing;
647 bool modelLoaded;
648 bool IsChild;
649 std::string modelName;
650 SGPath AircraftPath;
651 SGPath FullAircraftPath;
652 SGPath EnginePath;
653 SGPath SystemsPath;
654 SGPath OutputPath;
655 std::string CFGVersion;
656 std::string Release;
657 SGPath RootDir;
658
659 // Standard Model pointers - shortcuts for internal executive use only.
660 // DO NOT TRY TO DELETE THEM !!!
661 FGPropagate* Propagate;
662 FGInertial* Inertial;
663 FGAtmosphere* Atmosphere;
664 FGWinds* Winds;
665 FGAuxiliary* Auxiliary;
666 FGFCS* FCS;
667 FGPropulsion* Propulsion;
668 FGAerodynamics* Aerodynamics;
669 FGGroundReactions* GroundReactions;
670 FGExternalReactions* ExternalReactions;
671 FGBuoyantForces* BuoyantForces;
672 FGMassBalance* MassBalance;
673 FGAircraft* Aircraft;
674 FGAccelerations* Accelerations;
675 FGOutput* Output;
676 FGInput* Input;
677
678 bool trim_status;
679 int ta_mode;
680 int trim_completed;
681
682 std::shared_ptr<FGInitialCondition> IC;
683 std::shared_ptr<FGScript> Script;
684 std::shared_ptr<FGTrim> Trim;
685
686 SGPropertyNode_ptr Root;
687 std::shared_ptr<FGPropertyManager> instance;
688
689 bool HoldDown;
690
691 unsigned int RandomSeed;
692 std::shared_ptr<RandomNumberGenerator> RandomGenerator;
693
694 // The FDM counter is used to give each child FDM an unique ID. The root FDM
695 // has the ID 0
696 std::shared_ptr<unsigned int> FDMctr;
697
698 std::vector <std::string> PropertyCatalog;
699 std::vector <std::shared_ptr<childData>> ChildFDMList;
700 std::vector <std::shared_ptr<FGModel>> Models;
701 std::map<std::string, FGTemplateFunc_ptr> TemplateFunctions;
702
703 bool ReadFileHeader(Element*);
704 bool ReadChild(Element*);
705 bool ReadPrologue(Element*);
706 void SRand(int sr);
707 void LoadInputs(unsigned int idx);
708 void LoadPlanetConstants(void);
709 bool LoadPlanet(Element* el);
710 void LoadModelConstants(void);
711 bool Allocate(void);
712 bool DeAllocate(void);
713 void InitializeModels(void);
714 int GetDisperse(void) const {return disperse;}
715 SGPath GetFullPath(const SGPath& name) {
716 if (name.isRelative())
717 return RootDir/name.utf8Str();
718 else
719 return name;
720 }
721
722 void Debug(int from);
723};
724}
725//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
726#endif
This class implements a 3 element column vector.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
const SGPath & GetOutputPath(void)
Retrieves the path to the output files.
Definition FGFDMExec.h:404
bool GetHoldDown(void) const
Gets the value of the property forces/hold-down.
Definition FGFDMExec.h:621
void EnableOutput(void)
Enables data logging to all outputs.
Definition FGFDMExec.h:487
void SetPropertyValue(const std::string &property, double value)
Sets a property value.
Definition FGFDMExec.h:415
const SGPath & GetEnginePath(void)
Retrieves the engine path.
Definition FGFDMExec.h:396
std::shared_ptr< FGInitialCondition > GetIC(void) const
Returns a pointer to the FGInitialCondition object.
Definition FGFDMExec.h:390
const SGPath & GetRootDir(void) const
Retrieve the Root Directory.
Definition FGFDMExec.h:595
void ForceOutput(int idx=0)
Forces the specified output object to print its items once.
Definition FGFDMExec.h:451
bool SetSystemsPath(const SGPath &path)
Set the path to the systems config file directories.
Definition FGFDMExec.h:337
bool SetOutputFileName(const int n, const std::string &fname)
Sets (or overrides) the output filename.
Definition FGFDMExec.h:460
void SetDebugLevel(int level)
Sets the debug level.
Definition FGFDMExec.h:514
const SGPath & GetAircraftPath(void)
Retrieves the aircraft path.
Definition FGFDMExec.h:398
double GetPropertyValue(const std::string &property)
Retrieves the value of a property.
Definition FGFDMExec.h:409
bool SetEnginePath(const SGPath &path)
Set the path to the engine config file directories.
Definition FGFDMExec.h:314
int GetDebugLevel(void) const
Retrieves the current debug level setting.
Definition FGFDMExec.h:606
void SetLoggingRate(double rate)
Sets the logging rate in Hz for all output objects (if any).
Definition FGFDMExec.h:454
std::shared_ptr< FGScript > GetScript(void) const
Retrieves the script object.
Definition FGFDMExec.h:388
bool SetOutputPath(const SGPath &path)
Set the directory where the output files will be written.
Definition FGFDMExec.h:348
const SGPath & GetFullAircraftPath(void)
Retrieves the full aircraft path name.
Definition FGFDMExec.h:402
void EnableIncrementThenHold(int Timesteps)
Turn on hold after increment.
Definition FGFDMExec.h:495
void SetRootDir(const SGPath &rootDir)
Set the root directory that is used to obtain absolute paths from relative paths.
Definition FGFDMExec.h:590
std::string GetOutputFileName(int n) const
Retrieves the current output filename.
Definition FGFDMExec.h:466
double GetDeltaT(void) const
Returns the simulation delta T.
Definition FGFDMExec.h:557
size_t GetFDMCount(void) const
Gets the number of child FDMs.
Definition FGFDMExec.h:426
void DisableInput(void)
Disables input from all inputs.
Definition FGFDMExec.h:489
const SGPath & GetSystemsPath(void)
Retrieves the systems path.
Definition FGFDMExec.h:400
unsigned int GetFrame(void) const
Retrieves the current frame count.
Definition FGFDMExec.h:603
void Resume(void)
Resumes execution from a "Hold".
Definition FGFDMExec.h:499
void DisableOutput(void)
Disables data logging to all outputs.
Definition FGFDMExec.h:485
bool IntegrationSuspended(void) const
Returns the simulation suspension state.
Definition FGFDMExec.h:567
bool SetOutputDirectives(const SGPath &fname)
Sets the output (logging) mechanism for this run.
Definition FGFDMExec.h:447
void EnableInput(void)
Enables input from all inputs.
Definition FGFDMExec.h:491
void Unbind(void)
Unbind all tied JSBSim properties.
Definition FGFDMExec.h:244
void SetChild(bool ch)
Marks this instance of the Exec object as a "child" object.
Definition FGFDMExec.h:430
double GetSimTime(void) const
Returns the cumulative simulation time in seconds.
Definition FGFDMExec.h:554
void Setdt(double delta_t)
Sets the integration time step for the simulation executive.
Definition FGFDMExec.h:576
void SuspendIntegration(void)
Suspends the simulation and sets the delta T to zero.
Definition FGFDMExec.h:560
std::shared_ptr< FGPropertyManager > GetPropertyManager(void) const
Returns a pointer to the property manager object.
Definition FGFDMExec.h:422
void Hold(void)
Pauses execution by preventing time from incrementing.
Definition FGFDMExec.h:493
bool SetAircraftPath(const SGPath &path)
Set the path to the aircraft config file directories.
Definition FGFDMExec.h:326
auto GetChildFDM(int i) const
Gets a particular child FDM.
Definition FGFDMExec.h:428
void ResumeIntegration(void)
Resumes the simulation by resetting delta T to the correct value.
Definition FGFDMExec.h:563
const std::string & GetModelName(void) const
Returns the model name.
Definition FGFDMExec.h:419
bool Holding(void)
Returns true if the simulation is Holding (i.e. simulation time is not moving).
Definition FGFDMExec.h:501
Initializes the simulation run.
JSBSim Base class.
Definition FGJSBBase.h:118
Models the EOM and integration/propagation of state.
Definition FGPropagate.h:95
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71
SGPropertyNode_ptr node
The node for the property.
Definition FGFDMExec.h:520
std::string base_string
Name of the property.
Definition FGFDMExec.h:518