JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
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 Software
13  Foundation; either version 2 of the License, or (at your option) any later
14  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 with
22  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
23  Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25  Further information about the GNU Lesser General Public License can also be found on
26  the world wide web at http://www.gnu.org.
27 
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30 
31 HISTORY
32 --------------------------------------------------------------------------------
33 17/11/06 DC Created
34 
35 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 INCLUDES
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 
39 #include <iostream>
40 #include <string>
41 
42 #include "FGExternalReactions.h"
43 #include "input_output/FGXMLElement.h"
44 
45 using namespace std;
46 
47 namespace JSBSim {
48 
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 DEFINITIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 GLOBAL DATA
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 IDENT(IdSrc,"$Id: FGExternalReactions.cpp,v 1.21 2015/01/31 14:56:21 bcoconni Exp $");
58 IDENT(IdHdr,ID_EXTERNALREACTIONS);
59 
60 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 CLASS IMPLEMENTATION
62 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
63 
64 FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex)
65 {
66  NoneDefined = true;
67 
68  Debug(0);
69 }
70 
71 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 
74 {
75  // Call the base class Load() function to load interface properties.
76  if (!FGModel::Load(el))
77  return false;
78 
79  Debug(2);
80 
81  // Parse force elements
82 
83  int index=0;
84  Element* force_element = el->FindElement("force");
85  while (force_element) {
86  Forces.push_back( new FGExternalForce(FDMExec, force_element, index) );
87  NoneDefined = false;
88  index++;
89  force_element = el->FindNextElement("force");
90  }
91 
92  PostLoad(el, PropertyManager);
93 
94  if (!NoneDefined) bind();
95 
96  return true;
97 }
98 
99 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 
102 {
103  for (unsigned int i=0; i<Forces.size(); i++) delete Forces[i];
104  Forces.clear();
105 
106  Debug(1);
107 }
108 
109 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110 
111 bool FGExternalReactions::InitModel(void)
112 {
113  if (!FGModel::InitModel()) return false;
114 
115  vTotalForces.InitMatrix();
116  vTotalMoments.InitMatrix();
117 
118  return true;
119 }
120 
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 
123 bool FGExternalReactions::Run(bool Holding)
124 {
125  if (FGModel::Run(Holding)) return true;
126  if (Holding) return false; // if paused don't execute
127  if (NoneDefined) return true;
128 
129  RunPreFunctions();
130 
131  vTotalForces.InitMatrix();
132  vTotalMoments.InitMatrix();
133 
134  for (unsigned int i=0; i<Forces.size(); i++) {
135  vTotalForces += Forces[i]->GetBodyForces();
136  vTotalMoments += Forces[i]->GetMoments();
137  }
138 
139  RunPostFunctions();
140 
141  return false;
142 }
143 
144 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145 
146 void FGExternalReactions::bind(void)
147 {
148  typedef double (FGExternalReactions::*PMF)(int) const;
149  PropertyManager->Tie("moments/l-external-lbsft", this, eL, (PMF)&FGExternalReactions::GetMoments);
150  PropertyManager->Tie("moments/m-external-lbsft", this, eM, (PMF)&FGExternalReactions::GetMoments);
151  PropertyManager->Tie("moments/n-external-lbsft", this, eN, (PMF)&FGExternalReactions::GetMoments);
152  PropertyManager->Tie("forces/fbx-external-lbs", this, eX, (PMF)&FGExternalReactions::GetForces);
153  PropertyManager->Tie("forces/fby-external-lbs", this, eY, (PMF)&FGExternalReactions::GetForces);
154  PropertyManager->Tie("forces/fbz-external-lbs", this, eZ, (PMF)&FGExternalReactions::GetForces);
155 }
156 
157 
158 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159 // The bitmasked value choices are as follows:
160 // unset: In this case (the default) JSBSim would only print
161 // out the normally expected messages, essentially echoing
162 // the config files as they are read. If the environment
163 // variable is not set, debug_lvl is set to 1 internally
164 // 0: This requests JSBSim not to output any messages
165 // whatsoever.
166 // 1: This value explicity requests the normal JSBSim
167 // startup messages
168 // 2: This value asks for a message to be printed out when
169 // a class is instantiated
170 // 4: When this value is set, a message is displayed when a
171 // FGModel object executes its Run() method
172 // 8: When this value is set, various runtime state variables
173 // are printed out periodically
174 // 16: When set various parameters are sanity checked and
175 // a message is printed out when they go out of bounds
176 
177 void FGExternalReactions::Debug(int from)
178 {
179  if (debug_lvl <= 0) return;
180 
181  if (debug_lvl & 1) { // Standard console startup message output
182  if (from == 0) { // Constructor - loading and initialization
183  }
184  if (from == 2) { // Loading
185  cout << endl << " External Reactions: " << endl;
186  }
187  }
188  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
189  if (from == 0) cout << "Instantiated: FGExternalReactions" << endl;
190  if (from == 1) cout << "Destroyed: FGExternalReactions" << endl;
191  }
192  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
193  }
194  if (debug_lvl & 8 ) { // Runtime state variables
195  }
196  if (debug_lvl & 16) { // Sanity checking
197  }
198  if (debug_lvl & 64) {
199  if (from == 0) { // Constructor
200  cout << IdSrc << endl;
201  cout << IdHdr << endl;
202  }
203  }
204 }
205 
206 } // namespace JSBSim
207 
bool Load(Element *el)
Loads the external forces from the XML configuration file.
Encapsulates code that models an individual arbitrary force.
STL namespace.
Element * FindElement(const std::string &el="")
Searches for a specified element.
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:92
void Tie(const std::string &name, bool *pointer, bool useDefault=true)
Tie a property to an external bool variable.
const FGColumnVector3 & GetMoments(void) const
Retrieves the total moment resulting from the forces defined in the external reactions.
const FGColumnVector3 & GetForces(void) const
Retrieves the total forces defined in the external reactions.
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
bool Run(bool Holding)
Sum all the constituent forces for this cycle.
virtual bool Load(Element *el)
Loads this model.
Definition: FGModel.cpp:113
Manages the external and/or arbitrary forces.