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
FGExternalReactions.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGExternalReactions.cpp
4 Author: David P. Culp
5 Date started: 17/11/06
6 Purpose: Manages the External Forces
7 Called by: FGAircraft
8
9 ------------- Copyright (C) 2006 David P. Culp (daveculp@cox.net) ------------
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--------------------------------------------------------------------------------
30
31HISTORY
32--------------------------------------------------------------------------------
3317/11/06 DC Created
34
35/%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36INCLUDES
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39#include "FGFDMExec.h"
40#include "FGExternalForce.h"
41#include "FGExternalReactions.h"
42#include "input_output/FGXMLElement.h"
43#include "input_output/FGLog.h"
44
45using namespace std;
46
47namespace JSBSim {
48
49/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50CLASS IMPLEMENTATION
51%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex, "FGExternalReactions")
54{
55 bind();
56 Debug(0);
57}
58
59//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
62{
63 // Call the base class Load() function to load interface properties.
64 if (!FGModel::Upload(el, true))
65 return false;
66
67 Debug(2);
68
69 Element* force_element = el->FindElement("force");
70 while (force_element) {
71 auto force = std::make_unique<FGExternalForce>(FDMExec);
72 force->setForce(force_element);
73 Add(std::move(force));
74 force_element = el->FindNextElement("force");
75 }
76
77 Element* moment_element = el->FindElement("moment");
78 while (moment_element) {
79 auto moment = std::make_unique<FGExternalForce>(FDMExec);
80 moment->setMoment(moment_element);
81 Add(std::move(moment));
82 moment_element = el->FindNextElement("moment");
83 }
84
85 PostLoad(el, FDMExec);
86
87 return true;
88}
89
90//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
92void FGExternalReactions::Add(std::unique_ptr<FGExternalForce> force)
93{
94 if (!force) return;
95 Forces.push_back(std::move(force));
96}
97
98//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
104
105//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106
107bool FGExternalReactions::InitModel(void)
108{
109 if (!FGModel::InitModel()) return false;
110
111 vTotalForces.InitMatrix();
112 vTotalMoments.InitMatrix();
113
114 return true;
115}
116
117//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118
119bool FGExternalReactions::Run(bool Holding)
120{
121 if (FGModel::Run(Holding)) return true;
122 if (Holding) return false; // if paused don't execute
123 if (Forces.empty()) return true;
124
125 RunPreFunctions();
126
127 vTotalForces.InitMatrix();
128 vTotalMoments.InitMatrix();
129
130 for (unsigned int i=0; i<Forces.size(); i++) {
131 vTotalForces += Forces[i]->GetBodyForces();
132 vTotalMoments += Forces[i]->GetMoments();
133 }
134
135 RunPostFunctions();
136
137 return false;
138}
139
140//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141
142void FGExternalReactions::bind(void)
143{
144 PropertyManager->Tie("moments/l-external-lbsft", this, eL, &FGExternalReactions::GetMoments);
145 PropertyManager->Tie("moments/m-external-lbsft", this, eM, &FGExternalReactions::GetMoments);
146 PropertyManager->Tie("moments/n-external-lbsft", this, eN, &FGExternalReactions::GetMoments);
147 PropertyManager->Tie("forces/fbx-external-lbs", this, eX, &FGExternalReactions::GetForces);
148 PropertyManager->Tie("forces/fby-external-lbs", this, eY, &FGExternalReactions::GetForces);
149 PropertyManager->Tie("forces/fbz-external-lbs", this, eZ, &FGExternalReactions::GetForces);
150}
151
152
153//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154// The bitmasked value choices are as follows:
155// unset: In this case (the default) JSBSim would only print
156// out the normally expected messages, essentially echoing
157// the config files as they are read. If the environment
158// variable is not set, debug_lvl is set to 1 internally
159// 0: This requests JSBSim not to output any messages
160// whatsoever.
161// 1: This value explicity requests the normal JSBSim
162// startup messages
163// 2: This value asks for a message to be printed out when
164// a class is instantiated
165// 4: When this value is set, a message is displayed when a
166// FGModel object executes its Run() method
167// 8: When this value is set, various runtime state variables
168// are printed out periodically
169// 16: When set various parameters are sanity checked and
170// a message is printed out when they go out of bounds
171
172void FGExternalReactions::Debug(int from)
173{
174 if (debug_lvl <= 0) return;
175
176 if (debug_lvl & 1) { // Standard console startup message output
177 if (from == 0) { // Constructor - loading and initialization
178 }
179 if (from == 2) { // Loading
180 FGLogging log(LogLevel::DEBUG);
181 log << "\n External Reactions: \n";
182 }
183 }
184 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
185 FGLogging log(LogLevel::DEBUG);
186 if (from == 0) log << "Instantiated: FGExternalReactions\n";
187 if (from == 1) log << "Destroyed: FGExternalReactions\n";
188 }
189 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
190 }
191 if (debug_lvl & 8 ) { // Runtime state variables
192 }
193 if (debug_lvl & 16) { // Sanity checking
194 }
195 if (debug_lvl & 64) {
196 if (from == 0) { // Constructor
197 }
198 }
199}
200
201} // namespace JSBSim
Element * FindElement(const std::string &el="")
Searches for a specified element.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
const FGColumnVector3 & GetMoments(void) const
Retrieves the total moment resulting from the forces defined in the external reactions.
bool Load(Element *el) override
Loads the external forces from the XML configuration file.
~FGExternalReactions(void) override
Destructor.
void Add(std::unique_ptr< FGExternalForce > force)
Adds a force or moment created in code to the external reactions.
bool Run(bool Holding) override
Sum all the constituent forces for this cycle.
FGExternalReactions(FGFDMExec *fdmex)
Constructor.
const FGColumnVector3 & GetForces(void) const
Retrieves the total forces defined in the external reactions.
Encapsulates the JSBSim simulation executive.
Definition FGFDMExec.h:185
Base class for all scheduled JSBSim models.
Definition FGModel.h:79
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:101
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:123
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:73