Debian Codegraph @

src/FDM/JSBSim/models/FGExternalReactions.cpp

raw symbols SCIP
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 ([email protected]) ------------
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
28 FUNCTIONAL DESCRIPTION
29 --------------------------------------------------------------------------------
30
31 HISTORY
32 --------------------------------------------------------------------------------
33 17/11/06 DC Created
34
35 /%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 INCLUDES
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39 #include "FGExternalForce.h"
40 #include "FGExternalReactions.h"
41 #include "input_output/FGXMLElement.h"
42
43 using namespace std;
44
45 namespace JSBSim {
46
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 CLASS IMPLEMENTATION
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50
51 FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex)
52 {
53 Debug(0);
54 }
55
56 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57
58 bool FGExternalReactions::Load(Element* el)
59 {
60 // Call the base class Load() function to load interface properties.
61 if (!FGModel::Upload(el, true))
62 return false;
63
64 Debug(2);
65
66 // Parse force elements
67
68 Element* force_element = el->FindElement("force");
69 while (force_element) {
70 Forces.push_back(new FGExternalForce(FDMExec));
71 Forces.back()->setForce(force_element);
72 force_element = el->FindNextElement("force");
73 }
74
75 // Parse moment elements
76
77 Element* moment_element = el->FindElement("moment");
78 while (moment_element) {
79 Forces.push_back(new FGExternalForce(FDMExec));
80 Forces.back()->setMoment(moment_element);
81 moment_element = el->FindNextElement("moment");
82 }
83
84 PostLoad(el, FDMExec);
85
86 if (!Forces.empty()) bind();
87
88 return true;
89 }
90
91 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
93 FGExternalReactions::~FGExternalReactions()
94 {
95 for (unsigned int i=0; i<Forces.size(); i++) delete Forces[i];
96
97 Debug(1);
98 }
99
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101
102 bool FGExternalReactions::InitModel(void)
103 {
104 if (!FGModel::InitModel()) return false;
105
106 vTotalForces.InitMatrix();
107 vTotalMoments.InitMatrix();
108
109 return true;
110 }
111
112 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113
114 bool FGExternalReactions::Run(bool Holding)
115 {
116 if (FGModel::Run(Holding)) return true;
117 if (Holding) return false; // if paused don't execute
118 if (Forces.empty()) return true;
119
120 RunPreFunctions();
121
122 vTotalForces.InitMatrix();
123 vTotalMoments.InitMatrix();
124
125 for (unsigned int i=0; i<Forces.size(); i++) {
126 vTotalForces += Forces[i]->GetBodyForces();
127 vTotalMoments += Forces[i]->GetMoments();
128 }
129
130 RunPostFunctions();
131
132 return false;
133 }
134
135 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136
137 void FGExternalReactions::bind(void)
138 {
139 typedef double (FGExternalReactions::*PMF)(int) const;
140 PropertyManager->Tie("moments/l-external-lbsft", this, eL, (PMF)&FGExternalReactions::GetMoments);
141 PropertyManager->Tie("moments/m-external-lbsft", this, eM, (PMF)&FGExternalReactions::GetMoments);
142 PropertyManager->Tie("moments/n-external-lbsft", this, eN, (PMF)&FGExternalReactions::GetMoments);
143 PropertyManager->Tie("forces/fbx-external-lbs", this, eX, (PMF)&FGExternalReactions::GetForces);
144 PropertyManager->Tie("forces/fby-external-lbs", this, eY, (PMF)&FGExternalReactions::GetForces);
145 PropertyManager->Tie("forces/fbz-external-lbs", this, eZ, (PMF)&FGExternalReactions::GetForces);
146 }
147
148
149 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150 // The bitmasked value choices are as follows:
151 // unset: In this case (the default) JSBSim would only print
152 // out the normally expected messages, essentially echoing
153 // the config files as they are read. If the environment
154 // variable is not set, debug_lvl is set to 1 internally
155 // 0: This requests JSBSim not to output any messages
156 // whatsoever.
157 // 1: This value explicity requests the normal JSBSim
158 // startup messages
159 // 2: This value asks for a message to be printed out when
160 // a class is instantiated
161 // 4: When this value is set, a message is displayed when a
162 // FGModel object executes its Run() method
163 // 8: When this value is set, various runtime state variables
164 // are printed out periodically
165 // 16: When set various parameters are sanity checked and
166 // a message is printed out when they go out of bounds
167
168 void FGExternalReactions::Debug(int from)
169 {
170 if (debug_lvl <= 0) return;
171
172 if (debug_lvl & 1) { // Standard console startup message output
173 if (from == 0) { // Constructor - loading and initialization
174 }
175 if (from == 2) { // Loading
176 cout << endl << " External Reactions: " << endl;
177 }
178 }
179 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
180 if (from == 0) cout << "Instantiated: FGExternalReactions" << endl;
181 if (from == 1) cout << "Destroyed: FGExternalReactions" << endl;
182 }
183 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
184 }
185 if (debug_lvl & 8 ) { // Runtime state variables
186 }
187 if (debug_lvl & 16) { // Sanity checking
188 }
189 if (debug_lvl & 64) {
190 if (from == 0) { // Constructor
191 }
192 }
193 }
194
195 } // namespace JSBSim