Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/input_output/FGInputType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGInputType::FGInputType(FGFDMExec* fdmex, bool isEnabled) :
FGModel(fdmex), enabled(isEnabled)
FGModel(fdmex, "")
{
enabled = isEnabled;
Debug(0);
}

Expand Down Expand Up @@ -100,7 +101,6 @@ bool FGInputType::InitModel(void)
bool FGInputType::Run(bool Holding)
{
if (FGModel::Run(Holding)) return true;
if (!enabled) return true;

RunPreFunctions();
Read(Holding);
Expand Down
1 change: 0 additions & 1 deletion src/input_output/FGInputType.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class FGInputType : public FGModel

protected:
unsigned int InputIdx;
bool enabled;

void Debug(int from) override;
};
Expand Down
6 changes: 2 additions & 4 deletions src/input_output/FGOutputType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGOutputType::FGOutputType(FGFDMExec* fdmex) :
FGModel(fdmex),
SubSystems(0),
enabled(true)
FGModel(fdmex, ""),
SubSystems(0)
{
Aerodynamics = FDMExec->GetAerodynamics();
Auxiliary = FDMExec->GetAuxiliary();
Expand Down Expand Up @@ -186,7 +185,6 @@ bool FGOutputType::InitModel(void)
bool FGOutputType::Run(bool Holding)
{
if (FGModel::Run(Holding)) return true;
if (!enabled) return true;

RunPreFunctions();
Print();
Expand Down
1 change: 0 additions & 1 deletion src/input_output/FGOutputType.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ class FGOutputType : public FGModel
int SubSystems;
std::vector <FGPropertyValue*> OutputParameters;
std::vector <std::string> OutputCaptions;
bool enabled;

std::shared_ptr<FGAerodynamics> Aerodynamics;
std::shared_ptr<FGAuxiliary> Auxiliary;
Expand Down
3 changes: 1 addition & 2 deletions src/models/FGAccelerations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGAccelerations::FGAccelerations(FGFDMExec* fdmex)
: FGModel(fdmex)
: FGModel(fdmex, "FGAccelerations")
{
Debug(0);
Name = "FGAccelerations";
gravTorque = false;

vPQRidot.InitMatrix();
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGAerodynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec)
FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec, "FGAerodynamics")
{
Name = "FGAerodynamics";

AxisIdx["DRAG"] = 0;
AxisIdx["SIDE"] = 1;
AxisIdx["LIFT"] = 2;
Expand Down
3 changes: 1 addition & 2 deletions src/models/FGAircraft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex)
FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex, "FGAircraft")
{
Name = "FGAircraft";
WingSpan = 0.0;
WingArea = 0.0;
cbar = 0.0;
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGAtmosphere.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,9 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex)
: FGModel(fdmex),
: FGModel(fdmex, "FGAtmosphere"),
StdDaySLsoundspeed(sqrt(SHRatio*Reng0*StdDaySLtemperature))
{
Name = "FGAtmosphere";

bind();
SGPropertyNode* root = PropertyManager->GetNode();
atmosphere_node = root->getNode("atmosphere");
Expand Down
3 changes: 1 addition & 2 deletions src/models/FGAuxiliary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex)
FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex, "FGAuxiliary")
{
Name = "FGAuxiliary";
pt = FGAtmosphere::StdDaySLpressure; // ISA SL pressure
tat = FGAtmosphere::StdDaySLtemperature; // ISA SL temperature
tatc = RankineToCelsius(tat);
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGBuoyantForces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,8 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec)
FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec, "FGBuoyantForces")
{
Name = "FGBuoyantForces";

NoneDefined = true;

vTotalForces.InitMatrix();
Expand Down
2 changes: 1 addition & 1 deletion src/models/FGExternalReactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex)
FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex, "FGExternalReactions")
{
Debug(0);
}
Expand Down
3 changes: 1 addition & 2 deletions src/models/FGFCS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGFCS::FGFCS(FGFDMExec* fdm) : FGModel(fdm), ChannelRate(1)
FGFCS::FGFCS(FGFDMExec* fdm) : FGModel(fdm, "FGFCS"), ChannelRate(1)
{
int i;
Name = "FGFCS";
systype = stFCS;

DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGGroundReactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,10 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) :
FGModel(fgex),
FGModel(fgex, "FGGroundReactions"),
FGSurface(fgex),
DsCmd(0.0)
{
Name = "FGGroundReactions";

bind();

Debug(0);
Expand Down
2 changes: 1 addition & 1 deletion src/models/FGInertial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CLASS IMPLEMENTATION


FGInertial::FGInertial(FGFDMExec* fgex)
: FGModel(fgex)
: FGModel(fgex, "FGInertial")
{
Name = "Earth";

Expand Down
4 changes: 1 addition & 3 deletions src/models/FGInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGInput::FGInput(FGFDMExec* fdmex) : FGModel(fdmex)
FGInput::FGInput(FGFDMExec* fdmex) : FGModel(fdmex, "FGInput")
{
Name = "FGInput";
enabled = true;

Debug(0);
Expand Down Expand Up @@ -142,7 +141,6 @@ bool FGInput::Run(bool Holding)
{
if (FDMExec->GetTrimStatus()) return true;
if (FGModel::Run(Holding)) return true;
if (!enabled) return true;

vector<FGInputType*>::iterator it;
for (it = InputTypes.begin(); it != InputTypes.end(); ++it)
Expand Down
1 change: 0 additions & 1 deletion src/models/FGInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class FGInput : public FGModel

private:
std::vector<FGInputType*> InputTypes;
bool enabled;

void Debug(int from) override;
};
Expand Down
3 changes: 1 addition & 2 deletions src/models/FGMassBalance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ CLASS IMPLEMENTATION


FGMassBalance::FGMassBalance(FGFDMExec* fdmex)
: FGModel(fdmex)
: FGModel(fdmex, "FGMassBalance")
{
Name = "FGMassBalance";
Weight = EmptyWeight = Mass = 0.0;

vbaseXYZcg.InitMatrix();
Expand Down
20 changes: 16 additions & 4 deletions src/models/FGModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ INCLUDES
#include "FGFDMExec.h"
#include "input_output/FGModelLoader.h"
#include "input_output/FGLog.h"
#include "input_output/FGPropertyManager.h"

using namespace std;

Expand All @@ -55,7 +56,8 @@ GLOBAL DECLARATIONS
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGModel::FGModel(FGFDMExec* fdmex)
FGModel::FGModel(FGFDMExec* fdmex, const std::string& name)
: Name(name)
{
FDMExec = fdmex;

Expand All @@ -67,6 +69,15 @@ FGModel::FGModel(FGFDMExec* fdmex)
exe_ctr = 1;
rate = 1;

// A model that is scheduled by FGFDMExec is named and gets an enable property.
// The input and output types are not scheduled: they are instantiated one per
// <input> and <output> element, so a shared property path would be tied more
// than once. They pass an empty name and are enabled through the per-instance
// property that FGOutputType::SetIdx already binds, or through Enable() and
// Disable().
if (!Name.empty())
PropertyManager->Tie("simulation/models/" + Name + "/enabled", &enabled);

Debug(0);
}

Expand All @@ -91,12 +102,13 @@ bool FGModel::Run(bool Holding)
{
FGModel::Debug(2);

if (rate == 1) return false; // Fast exit if nothing to do
if (rate == 1) return !enabled; // Fast exit if nothing to do

if (exe_ctr >= rate) exe_ctr = 0;

if (exe_ctr++ == 1) return false;
else return true;
if (exe_ctr++ == 1) return !enabled;

return true;
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Expand Down
18 changes: 15 additions & 3 deletions src/models/FGModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ CLASS DOCUMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

/** 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
*/

Expand All @@ -70,14 +79,16 @@ class JSBSIM_API FGModel : public FGModelFunctions
{
public:

/// Constructor
explicit FGModel(FGFDMExec*);
/** Constructor.
@param name the name of this model. It populates the member Name and binds
simulation/models/<name>/enabled. */
FGModel(FGFDMExec*, const std::string& name);
/// Destructor
~FGModel() override;

/** Runs the model; called by the Executive.
Can pass in a value indicating if the executive is directing the simulation to Hold.
@param Holding if true, the executive has been directed to hold the sim from
@param Holding if 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
Expand All @@ -101,6 +112,7 @@ class JSBSIM_API FGModel : public FGModelFunctions
protected:
unsigned int exe_ctr;
unsigned int rate;
bool enabled = true;
std::string Name;

/** Uploads this model in memory.
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ namespace JSBSim {
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex)
FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex, "FGOutput")
{
Name = "FGOutput";
enabled = true;

PropertyManager->Tie<FGOutput, int>("simulation/force-output", this, nullptr,
Expand Down Expand Up @@ -97,7 +96,6 @@ bool FGOutput::Run(bool Holding)
if (FDMExec->GetTrimStatus()) return true;
if (FGModel::Run(Holding)) return true;
if (Holding) return false;
if (!enabled) return true;

for (auto output: OutputTypes)
output->Run(Holding);
Expand Down
1 change: 0 additions & 1 deletion src/models/FGOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ class JSBSIM_API FGOutput : public FGModel

private:
std::vector<FGOutputType*> OutputTypes;
bool enabled;
SGPath includePath;

void Debug(int from) override;
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGPropagate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGPropagate::FGPropagate(FGFDMExec* fdmex)
: FGModel(fdmex)
: FGModel(fdmex, "FGPropagate")
{
Name = "FGPropagate";

Inertial = FDMExec->GetInertial();

/// These define the indices use to select the various integrators.
Expand Down
4 changes: 1 addition & 3 deletions src/models/FGPropulsion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ extern short debug_lvl;
CLASS IMPLEMENTATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec)
FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec, "FGPropulsion")
{
Name = "FGPropulsion";

ActiveEngine = -1; // -1: ALL, 0: Engine 1, 1: Engine 2 ...
tankJ.InitMatrix();
DumpRate = 0.0;
Expand Down
4 changes: 1 addition & 3 deletions src/models/atmosphere/FGWinds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ static inline double square_signed (double value)
constexpr double sqr(double x) { return x*x; }

FGWinds::FGWinds(FGFDMExec* fdmex)
: FGModel(fdmex), generator(fdmex->GetRandomGenerator())
: FGModel(fdmex, "FGWinds"), generator(fdmex->GetRandomGenerator())
{
Name = "FGWinds";

MagnitudedAccelDt = MagnitudeAccel = Magnitude = TurbDirection = 0.0;
SetTurbType( ttMilspec );
TurbGain = 1.0;
Expand Down
Loading