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
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 "math/FGTemplateFunc.h"
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51FORWARD DECLARATIONS
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
54namespace JSBSim {
55
56class FGScript;
57class FGTrim;
58class FGAerodynamics;
59class FGAircraft;
60class FGAtmosphere;
61class FGAccelerations;
62class FGWinds;
63class FGAuxiliary;
64class FGBuoyantForces;
65class FGExternalReactions;
66class FGGroundReactions;
67class FGFCS;
68class FGInertial;
69class FGInput;
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 Hold(void) {holding = true;}
491 void EnableIncrementThenHold(int Timesteps) {TimeStepsUntilHold = Timesteps; IncrementThenHolding = true;}
493 void CheckIncrementalHold(void);
495 void Resume(void) {holding = false;}
497 bool Holding(void) {return holding;}
499 static const int START_NEW_OUTPUT = 0x1;
500 static const int DONT_EXECUTE_RUN_IC = 0x2;
508 void ResetToInitialConditions(int mode);
510 void SetDebugLevel(int level) {debug_lvl = level;}
511
514 std::string base_string;
516 SGPropertyNode_ptr node;
517 };
518
523 void BuildPropertyCatalog(struct PropertyCatalogStructure* pcs);
524
532 std::string QueryPropertyCatalog(const std::string& check, const std::string& end_of_line="\n");
533
534 // Print the contents of the property catalog for the loaded aircraft.
535 void PrintPropertyCatalog(void);
536
537 // Print the simulation configuration
538 void PrintSimulationConfiguration(void) const;
539
540 std::vector<std::string>& GetPropertyCatalog(void) {return PropertyCatalog;}
541
542 void SetTrimStatus(bool status){ trim_status = status; }
543 bool GetTrimStatus(void) const { return trim_status; }
544 void SetTrimMode(int mode){ ta_mode = mode; }
545 int GetTrimMode(void) const { return ta_mode; }
546
547 std::string GetPropulsionTankReport() const;
548
550 double GetSimTime(void) const { return sim_time; }
551
553 double GetDeltaT(void) const {return dT;}
554
556 void SuspendIntegration(void) {saved_dT = dT; dT = 0.0;}
557
559 void ResumeIntegration(void) {dT = saved_dT;}
560
563 bool IntegrationSuspended(void) const {return dT == 0.0;}
564
568 double Setsim_time(double cur_time);
569
572 void Setdt(double delta_t) { dT = delta_t; }
573
586 void SetRootDir(const SGPath& rootDir) {RootDir = rootDir;}
587
591 const SGPath& GetRootDir(void) const {return RootDir;}
592
596 double IncrTime(void);
597
599 unsigned int GetFrame(void) const {return Frame;}
600
602 int GetDebugLevel(void) const {return debug_lvl;};
603
606 void Initialize(const FGInitialCondition* FGIC);
607
612 void SetHoldDown(bool hd);
613
617 bool GetHoldDown(void) const {return HoldDown;}
618
619 FGTemplateFunc_ptr GetTemplateFunc(const std::string& name) {
620 return TemplateFunctions.count(name) ? TemplateFunctions[name] : nullptr;
621 }
622
623 void AddTemplateFunc(const std::string& name, Element* el) {
624 TemplateFunctions[name] = std::make_shared<FGTemplateFunc>(this, el);
625 }
626
627 auto GetRandomGenerator(void) const { return RandomGenerator; }
628
629 int SRand(void) const { return RandomSeed; }
630
631private:
632 unsigned int Frame;
633 unsigned int IdFDM;
634 int disperse;
635 bool Terminate;
636 double dT;
637 double saved_dT;
638 double sim_time;
639 bool holding;
640 bool IncrementThenHolding;
641 int TimeStepsUntilHold;
642 bool Constructing;
643 bool modelLoaded;
644 bool IsChild;
645 std::string modelName;
646 SGPath AircraftPath;
647 SGPath FullAircraftPath;
648 SGPath EnginePath;
649 SGPath SystemsPath;
650 SGPath OutputPath;
651 std::string CFGVersion;
652 std::string Release;
653 SGPath RootDir;
654
655 // Standard Model pointers - shortcuts for internal executive use only.
656 // DO NOT TRY TO DELETE THEM !!!
657 FGPropagate* Propagate;
658 FGInertial* Inertial;
659 FGAtmosphere* Atmosphere;
660 FGWinds* Winds;
661 FGAuxiliary* Auxiliary;
662 FGFCS* FCS;
663 FGPropulsion* Propulsion;
664 FGAerodynamics* Aerodynamics;
665 FGGroundReactions* GroundReactions;
666 FGExternalReactions* ExternalReactions;
667 FGBuoyantForces* BuoyantForces;
668 FGMassBalance* MassBalance;
669 FGAircraft* Aircraft;
670 FGAccelerations* Accelerations;
671 FGOutput* Output;
672 FGInput* Input;
673
674 bool trim_status;
675 int ta_mode;
676 int trim_completed;
677
678 std::shared_ptr<FGInitialCondition> IC;
679 std::shared_ptr<FGScript> Script;
680 std::shared_ptr<FGTrim> Trim;
681
682 SGPropertyNode_ptr Root;
683 std::shared_ptr<FGPropertyManager> instance;
684
685 bool HoldDown;
686
687 unsigned int RandomSeed;
688 std::shared_ptr<RandomNumberGenerator> RandomGenerator;
689
690 // The FDM counter is used to give each child FDM an unique ID. The root FDM
691 // has the ID 0
692 std::shared_ptr<unsigned int> FDMctr;
693
694 std::vector <std::string> PropertyCatalog;
695 std::vector <std::shared_ptr<childData>> ChildFDMList;
696 std::vector <std::shared_ptr<FGModel>> Models;
697 std::map<std::string, FGTemplateFunc_ptr> TemplateFunctions;
698
699 bool ReadFileHeader(Element*);
700 bool ReadChild(Element*);
701 bool ReadPrologue(Element*);
702 void SRand(int sr);
703 void LoadInputs(unsigned int idx);
704 void LoadPlanetConstants(void);
705 bool LoadPlanet(Element* el);
706 void LoadModelConstants(void);
707 bool Allocate(void);
708 bool DeAllocate(void);
709 void InitializeModels(void);
710 int GetDisperse(void) const {return disperse;}
711 SGPath GetFullPath(const SGPath& name) {
712 if (name.isRelative())
713 return RootDir/name.utf8Str();
714 else
715 return name;
716 }
717
718 void Debug(int from);
719};
720}
721//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
722#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:617
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:591
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:510
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:602
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:491
void SetRootDir(const SGPath &rootDir)
Set the root directory that is used to obtain absolute paths from relative paths.
Definition FGFDMExec.h:586
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:553
size_t GetFDMCount(void) const
Gets the number of child FDMs.
Definition FGFDMExec.h:426
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:599
void Resume(void)
Resumes execution from a "Hold".
Definition FGFDMExec.h:495
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:563
bool SetOutputDirectives(const SGPath &fname)
Sets the output (logging) mechanism for this run.
Definition FGFDMExec.h:447
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:550
void Setdt(double delta_t)
Sets the integration time step for the simulation executive.
Definition FGFDMExec.h:572
void SuspendIntegration(void)
Suspends the simulation and sets the delta T to zero.
Definition FGFDMExec.h:556
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:489
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:559
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:497
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:516
std::string base_string
Name of the property.
Definition FGFDMExec.h:514