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
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
54{
55 Debug(0);
56}
57
58//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
61{
62 // Call the base class Load() function to load interface properties.
63 if (!FGModel::Upload(el, true))
64 return false;
65
66 Debug(2);
67
68 // Parse force elements
69
70 Element* force_element = el->FindElement("force");
71 while (force_element) {
72 Forces.push_back(new FGExternalForce(FDMExec));
73 Forces.back()->setForce(force_element);
74 force_element = el->FindNextElement("force");
75 }
76
77 // Parse moment elements
78
79 Element* moment_element = el->FindElement("moment");
80 while (moment_element) {
81 Forces.push_back(new FGExternalForce(FDMExec));
82 Forces.back()->setMoment(moment_element);
83 moment_element = el->FindNextElement("moment");
84 }
85
86 PostLoad(el, FDMExec);
87
88 if (!Forces.empty()) bind();
89
90 return true;
91}
92
93//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94
96{
97 for (unsigned int i=0; i<Forces.size(); i++) delete Forces[i];
98
99 Debug(1);
100}
101
102//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
104bool FGExternalReactions::InitModel(void)
105{
106 if (!FGModel::InitModel()) return false;
107
108 vTotalForces.InitMatrix();
109 vTotalMoments.InitMatrix();
110
111 return true;
112}
113
114//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115
116bool FGExternalReactions::Run(bool Holding)
117{
118 if (FGModel::Run(Holding)) return true;
119 if (Holding) return false; // if paused don't execute
120 if (Forces.empty()) return true;
121
122 RunPreFunctions();
123
124 vTotalForces.InitMatrix();
125 vTotalMoments.InitMatrix();
126
127 for (unsigned int i=0; i<Forces.size(); i++) {
128 vTotalForces += Forces[i]->GetBodyForces();
129 vTotalMoments += Forces[i]->GetMoments();
130 }
131
132 RunPostFunctions();
133
134 return false;
135}
136
137//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
139void FGExternalReactions::bind(void)
140{
141 PropertyManager->Tie("moments/l-external-lbsft", this, eL, &FGExternalReactions::GetMoments);
142 PropertyManager->Tie("moments/m-external-lbsft", this, eM, &FGExternalReactions::GetMoments);
143 PropertyManager->Tie("moments/n-external-lbsft", this, eN, &FGExternalReactions::GetMoments);
144 PropertyManager->Tie("forces/fbx-external-lbs", this, eX, &FGExternalReactions::GetForces);
145 PropertyManager->Tie("forces/fby-external-lbs", this, eY, &FGExternalReactions::GetForces);
146 PropertyManager->Tie("forces/fbz-external-lbs", this, eZ, &FGExternalReactions::GetForces);
147}
148
149
150//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151// The bitmasked value choices are as follows:
152// unset: In this case (the default) JSBSim would only print
153// out the normally expected messages, essentially echoing
154// the config files as they are read. If the environment
155// variable is not set, debug_lvl is set to 1 internally
156// 0: This requests JSBSim not to output any messages
157// whatsoever.
158// 1: This value explicity requests the normal JSBSim
159// startup messages
160// 2: This value asks for a message to be printed out when
161// a class is instantiated
162// 4: When this value is set, a message is displayed when a
163// FGModel object executes its Run() method
164// 8: When this value is set, various runtime state variables
165// are printed out periodically
166// 16: When set various parameters are sanity checked and
167// a message is printed out when they go out of bounds
168
169void FGExternalReactions::Debug(int from)
170{
171 if (debug_lvl <= 0) return;
172
173 if (debug_lvl & 1) { // Standard console startup message output
174 if (from == 0) { // Constructor - loading and initialization
175 }
176 if (from == 2) { // Loading
177 FGLogging log(LogLevel::DEBUG);
178 log << "\n External Reactions: \n";
179 }
180 }
181 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
182 FGLogging log(LogLevel::DEBUG);
183 if (from == 0) log << "Instantiated: FGExternalReactions\n";
184 if (from == 1) log << "Destroyed: FGExternalReactions\n";
185 }
186 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
187 }
188 if (debug_lvl & 8 ) { // Runtime state variables
189 }
190 if (debug_lvl & 16) { // Sanity checking
191 }
192 if (debug_lvl & 64) {
193 if (from == 0) { // Constructor
194 }
195 }
196}
197
198} // 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.
Encapsulates code that models an individual arbitrary force, moment or a combination thereof.
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.
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:70
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition FGModel.cpp:90
bool Upload(Element *el, bool preLoad)
Uploads this model in memory.
Definition FGModel.cpp:111
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71