Branch data Line data Source code
1 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 : :
3 : : Module: FGTank.cpp
4 : : Author: Jon Berndt
5 : : Date started: 01/21/99
6 : : Called by: FGAircraft
7 : :
8 : : ------------- Copyright (C) 1999 Jon S. Berndt (jon@jsbsim.org) -------------
9 : :
10 : : This program is free software; you can redistribute it and/or modify it under
11 : : the terms of the GNU Lesser General Public License as published by the Free Software
12 : : Foundation; either version 2 of the License, or (at your option) any later
13 : : version.
14 : :
15 : : This program is distributed in the hope that it will be useful, but WITHOUT
16 : : ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 : : FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18 : : details.
19 : :
20 : : You should have received a copy of the GNU Lesser General Public License along with
21 : : this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 : : Place - Suite 330, Boston, MA 02111-1307, USA.
23 : :
24 : : Further information about the GNU Lesser General Public License can also be found on
25 : : the world wide web at http://www.gnu.org.
26 : :
27 : : FUNCTIONAL DESCRIPTION
28 : : --------------------------------------------------------------------------------
29 : : See header file.
30 : :
31 : : HISTORY
32 : : --------------------------------------------------------------------------------
33 : : 01/21/99 JSB Created
34 : :
35 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 : : INCLUDES
37 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38 : :
39 : : #include "FGTank.h"
40 : : #include "FGFDMExec.h"
41 : : #include "models/FGAuxiliary.h"
42 : : #include "input_output/FGXMLElement.h"
43 : : #include "input_output/FGPropertyManager.h"
44 : : #include <iostream>
45 : : #include <cstdlib>
46 : :
47 : : using namespace std;
48 : :
49 : : namespace JSBSim {
50 : :
51 : : static const char *IdSrc = "$Id: FGTank.cpp,v 1.28 2010/01/24 19:26:04 jberndt Exp $";
52 : : static const char *IdHdr = ID_TANK;
53 : :
54 : : /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 : : CLASS IMPLEMENTATION
56 : : %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 : :
58 : 6 : FGTank::FGTank(FGFDMExec* exec, Element* el, int tank_number)
59 : 6 : : TankNumber(tank_number), Exec(exec)
60 : : {
61 : 6 : string token, strFuelName;
62 : : Element* element;
63 : : Element* element_Grain;
64 : 6 : Area = 1.0;
65 : 6 : Density = 6.6;
66 : 6 : InitialTemperature = Temperature = -9999.0;
67 : 6 : Ixx = Iyy = Izz = 0.0;
68 : 6 : Radius = Contents = Standpipe = Length = InnerRadius = 0.0;
69 : 6 : InitialStandpipe = 0.0;
70 : 6 : Capacity = 0.00001;
71 : 6 : Priority = InitialPriority = 1;
72 : 6 : PropertyManager = Exec->GetPropertyManager();
73 : 6 : vXYZ.InitMatrix();
74 : 6 : vXYZ_drain.InitMatrix();
75 : :
76 : 12 : type = el->GetAttributeValue("type");
77 [ + + ][ # # ]: 6 : if (type == "FUEL") Type = ttFUEL;
78 [ + - ][ # # ]: 2 : else if (type == "OXIDIZER") Type = ttOXIDIZER;
79 : 0 : else Type = ttUNKNOWN;
80 : :
81 : 6 : element = el->FindElement("location");
82 [ + - ][ # # ]: 6 : if (element) vXYZ = element->FindElementTripletConvertTo("IN");
83 : 0 : else cerr << "No location found for this tank." << endl;
84 : :
85 : 6 : vXYZ_drain = vXYZ; // Set initial drain location to initial tank CG
86 : :
87 : 6 : element = el->FindElement("drain_location");
88 [ + + # # ]: 6 : if (element) {
89 : 4 : vXYZ_drain = element->FindElementTripletConvertTo("IN");
90 : : }
91 : :
92 [ + + ][ # # ]: 6 : if (el->FindElement("radius"))
93 : 2 : Radius = el->FindElementValueAsNumberConvertTo("radius", "IN");
94 [ + - ][ # # ]: 6 : if (el->FindElement("capacity"))
95 : 6 : Capacity = el->FindElementValueAsNumberConvertTo("capacity", "LBS");
96 [ + - ][ # # ]: 6 : if (el->FindElement("contents"))
97 : 6 : InitialContents = Contents = el->FindElementValueAsNumberConvertTo("contents", "LBS");
98 [ - + # # ]: 6 : if (el->FindElement("temperature"))
99 : 0 : InitialTemperature = Temperature = el->FindElementValueAsNumber("temperature");
100 [ - + ][ # # ]: 6 : if (el->FindElement("standpipe"))
101 : 0 : InitialStandpipe = Standpipe = el->FindElementValueAsNumberConvertTo("standpipe", "LBS");
102 [ - + ][ # # ]: 6 : if (el->FindElement("priority"))
103 : 0 : InitialPriority = Priority = el->FindElementValueAsNumber("priority");
104 [ - + ][ # # ]: 6 : if (el->FindElement("density"))
105 : 0 : Density = el->FindElementValueAsNumberConvertTo("density", "LBS/GAL");
106 [ - + ][ # # ]: 6 : if (el->FindElement("type"))
107 : 0 : strFuelName = el->FindElementValue("type");
108 : :
109 : :
110 : 6 : SetPriority( InitialPriority ); // this will also set the Selected flag
111 : :
112 [ - + ][ # # ]: 6 : if (Capacity == 0) {
113 : 0 : cerr << "Tank capacity must not be zero. Reset to 0.00001 lbs!" << endl;
114 : 0 : Capacity = 0.00001;
115 : 0 : Contents = 0.0;
116 : : }
117 : 6 : PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0
118 : :
119 : : // Check whether this is a solid propellant "tank". Initialize it if true.
120 : :
121 : 6 : grainType = gtUNKNOWN; // This is the default
122 : :
123 : 6 : element_Grain = el->FindElement("grain_config");
124 [ + + # # ]: 6 : if (element_Grain) {
125 : :
126 : 4 : strGType = element_Grain->GetAttributeValue("type");
127 [ + - ][ # # ]: 2 : if (strGType == "CYLINDRICAL") grainType = gtCYLINDRICAL;
128 [ # # ][ # # ]: 0 : else if (strGType == "ENDBURNING") grainType = gtENDBURNING;
129 : 0 : else cerr << "Unknown propellant grain type specified" << endl;
130 : :
131 [ + - ][ # # ]: 2 : if (element_Grain->FindElement("length"))
132 : 2 : Length = element_Grain->FindElementValueAsNumberConvertTo("length", "IN");
133 [ + - ][ # # ]: 2 : if (element_Grain->FindElement("bore_diameter"))
134 : 2 : InnerRadius = element_Grain->FindElementValueAsNumberConvertTo("bore_diameter", "IN")/2.0;
135 : :
136 : : // Initialize solid propellant values for debug and runtime use.
137 : :
138 [ + - - - ]: 2 : switch (grainType) {
[ # # # # ]
139 : : case gtCYLINDRICAL:
140 [ - + ][ # # ]: 2 : if (Radius <= InnerRadius) {
141 : 0 : cerr << "The bore diameter should be smaller than the total grain diameter!" << endl;
142 : 0 : exit(-1);
143 : : }
144 : 2 : Volume = M_PI * Length * (Radius*Radius - InnerRadius*InnerRadius); // cubic inches
145 : 2 : break;
146 : : case gtENDBURNING:
147 : 0 : Volume = M_PI * Length * Radius * Radius; // cubic inches
148 : 0 : break;
149 : : case gtUNKNOWN:
150 : 0 : cerr << "Unknown grain type found in this rocket engine definition." << endl;
151 : 0 : exit(-1);
152 : : }
153 : 2 : Density = (Contents*lbtoslug)/Volume; // slugs/in^3
154 : 2 : CalculateInertias();
155 : : }
156 : :
157 : 6 : string property_name, base_property_name;
158 : 12 : base_property_name = CreateIndexedPropertyName("propulsion/tank", TankNumber);
159 : 12 : property_name = base_property_name + "/contents-lbs";
160 : : PropertyManager->Tie( property_name.c_str(), (FGTank*)this, &FGTank::GetContents,
161 : 6 : &FGTank::SetContents );
162 : 12 : property_name = base_property_name + "/priority";
163 : : PropertyManager->Tie( property_name.c_str(), (FGTank*)this, &FGTank::GetPriority,
164 : 6 : &FGTank::SetPriority );
165 : :
166 [ - + ][ # # ]: 6 : if (Temperature != -9999.0) InitialTemperature = Temperature = FahrenheitToCelsius(Temperature);
167 : 6 : Area = 40.0 * pow(Capacity/1975, 0.666666667);
168 : :
169 : : // A named fuel type will override a previous density value
170 [ - + ][ # # ]: 6 : if (!strFuelName.empty()) Density = ProcessFuelName(strFuelName);
171 : :
172 : 6 : Debug(0);
173 : 6 : }
174 : :
175 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176 : :
177 : 6 : FGTank::~FGTank()
178 : : {
179 : 6 : Debug(1);
180 : 6 : }
181 : :
182 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 : :
184 : 0 : void FGTank::ResetToIC(void)
185 : : {
186 : 0 : SetTemperature( InitialTemperature );
187 : 0 : SetStandpipe ( InitialStandpipe );
188 : 0 : SetContents ( InitialContents );
189 : 0 : PctFull = 100.0*Contents/Capacity;
190 : 0 : SetPriority( InitialPriority );
191 : 0 : }
192 : :
193 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 : :
195 : 324042 : const FGColumnVector3 FGTank::GetXYZ(void)
196 : : {
197 : 972126 : return vXYZ_drain + (Contents/Capacity)*(vXYZ - vXYZ_drain);
198 : : }
199 : :
200 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201 : :
202 : 972126 : const double FGTank::GetXYZ(int idx)
203 : : {
204 : 972126 : return vXYZ_drain(idx) + (Contents/Capacity)*(vXYZ(idx)-vXYZ_drain(idx));
205 : : }
206 : :
207 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208 : :
209 : 1061720 : double FGTank::Drain(double used)
210 : : {
211 : 1061720 : double remaining = Contents - used;
212 : :
213 [ + + ]: 1061720 : if (remaining >= 0) { // Reduce contents by amount used.
214 : :
215 : 1061714 : Contents -= used;
216 : 1061714 : PctFull = 100.0*Contents/Capacity;
217 : :
218 : : } else { // This tank must be empty.
219 : :
220 : 6 : Contents = 0.0;
221 : 6 : PctFull = 0.0;
222 : : }
223 : :
224 [ + + ]: 1061720 : if (grainType != gtUNKNOWN) CalculateInertias();
225 : :
226 : 1061720 : return remaining;
227 : : }
228 : :
229 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230 : :
231 : 0 : double FGTank::Fill(double amount)
232 : : {
233 : 0 : double overage = 0.0;
234 : :
235 : 0 : Contents += amount;
236 : :
237 [ # # ]: 0 : if (Contents > Capacity) {
238 : 0 : overage = Contents - Capacity;
239 : 0 : Contents = Capacity;
240 : 0 : PctFull = 100.0;
241 : : } else {
242 : 0 : PctFull = Contents/Capacity*100.0;
243 : : }
244 : 0 : return overage;
245 : : }
246 : :
247 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 : :
249 : 0 : void FGTank::SetContents(double amount)
250 : : {
251 : 0 : Contents = amount;
252 [ # # ]: 0 : if (Contents > Capacity) {
253 : 0 : Contents = Capacity;
254 : 0 : PctFull = 100.0;
255 : : } else {
256 : 0 : PctFull = Contents/Capacity*100.0;
257 : : }
258 : 0 : }
259 : :
260 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 : :
262 : 0 : void FGTank::SetContentsGallons(double gallons)
263 : : {
264 : 0 : SetContents(gallons * Density);
265 : 0 : }
266 : :
267 : :
268 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 : :
270 : 324030 : double FGTank::Calculate(double dt)
271 : : {
272 [ + - ]: 324030 : if (Temperature == -9999.0) return 0.0;
273 : 0 : double HeatCapacity = 900.0; // Joules/lbm/C
274 : 0 : double TempFlowFactor = 1.115; // Watts/sqft/C
275 : 0 : double TAT = Exec->GetAuxiliary()->GetTAT_C();
276 : 0 : double Tdiff = TAT - Temperature;
277 : 0 : double dTemp = 0.0; // Temp change due to one surface
278 [ # # ]: 0 : if (fabs(Tdiff) > 0.1) {
279 : 0 : dTemp = (TempFlowFactor * Area * Tdiff * dt) / (Contents * HeatCapacity);
280 : : }
281 : 324030 : return Temperature += (dTemp + dTemp); // For now, assume upper/lower the same
282 : : }
283 : :
284 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
285 : : // This function calculates the moments of inertia for a solid propellant
286 : : // grain - either an end burning cylindrical grain or a bored cylindrical
287 : : // grain.
288 : :
289 : 32830 : void FGTank::CalculateInertias(void)
290 : : {
291 : 32830 : double Mass = Contents*lbtoslug;
292 : : double RadSumSqr;
293 : 32830 : double Rad2 = Radius*Radius;
294 : :
295 [ + - ]: 32830 : if (Density > 0.0) {
296 : 32830 : Volume = (Contents*lbtoslug)/Density; // in^3
297 : : } else {
298 : 0 : cerr << endl << " Solid propellant grain density is zero!" << endl << endl;
299 : 0 : exit(-1);
300 : : }
301 : :
302 [ + - - - ]: 32830 : switch (grainType) {
303 : : case gtCYLINDRICAL:
304 : 32830 : InnerRadius = sqrt(Rad2 - Volume/(M_PI * Length));
305 : 32830 : RadSumSqr = (Rad2 + InnerRadius*InnerRadius)/144.0;
306 : 32830 : Ixx = 0.5*Mass*RadSumSqr;
307 : 32830 : Iyy = Mass*(3.0*RadSumSqr + Length*Length/144.0)/12.0;
308 : 32830 : break;
309 : : case gtENDBURNING:
310 : 0 : Length = Volume/(M_PI*Rad2);
311 : 0 : Ixx = 0.5*Mass*Rad2/144.0;
312 : 0 : Iyy = Mass*(3.0*Rad2 + Length*Length)/(144.0*12.0);
313 : 0 : break;
314 : : case gtUNKNOWN:
315 : 0 : cerr << "Unknown grain type found." << endl;
316 : 0 : exit(-1);
317 : : break;
318 : : }
319 : 32830 : Izz = Iyy;
320 : :
321 : 32830 : }
322 : :
323 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324 : :
325 : 0 : double FGTank::ProcessFuelName(std::string const& name)
326 : : {
327 [ # # ]: 0 : if (name == "AVGAS") return 6.02;
328 [ # # ]: 0 : else if (name == "JET-A") return 6.74;
329 [ # # ]: 0 : else if (name == "JET-A1") return 6.74;
330 [ # # ]: 0 : else if (name == "JET-B") return 6.48;
331 [ # # ]: 0 : else if (name == "JP-1") return 6.76;
332 [ # # ]: 0 : else if (name == "JP-2") return 6.38;
333 [ # # ]: 0 : else if (name == "JP-3") return 6.34;
334 [ # # ]: 0 : else if (name == "JP-4") return 6.48;
335 [ # # ]: 0 : else if (name == "JP-5") return 6.81;
336 [ # # ]: 0 : else if (name == "JP-6") return 6.55;
337 [ # # ]: 0 : else if (name == "JP-7") return 6.61;
338 [ # # ]: 0 : else if (name == "JP-8") return 6.66;
339 [ # # ]: 0 : else if (name == "JP-8+100") return 6.66;
340 : : //else if (name == "JP-9") return 6.74;
341 : : //else if (name == "JPTS") return 6.74;
342 [ # # ]: 0 : else if (name == "RP-1") return 6.73;
343 [ # # ]: 0 : else if (name == "T-1") return 6.88;
344 [ # # ]: 0 : else if (name == "ETHANOL") return 6.58;
345 [ # # ]: 0 : else if (name == "HYDRAZINE")return 8.61;
346 [ # # ]: 0 : else if (name == "F-34") return 6.66;
347 [ # # ]: 0 : else if (name == "F-35") return 6.74;
348 [ # # ]: 0 : else if (name == "F-40") return 6.48;
349 [ # # ]: 0 : else if (name == "F-44") return 6.81;
350 [ # # ]: 0 : else if (name == "AVTAG") return 6.48;
351 [ # # ]: 0 : else if (name == "AVCAT") return 6.81;
352 : : else {
353 : 0 : cerr << "Unknown fuel type specified: "<< name << endl;
354 : : }
355 : :
356 : 0 : return 6.6;
357 : : }
358 : :
359 : :
360 : : //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
361 : : // The bitmasked value choices are as follows:
362 : : // unset: In this case (the default) JSBSim would only print
363 : : // out the normally expected messages, essentially echoing
364 : : // the config files as they are read. If the environment
365 : : // variable is not set, debug_lvl is set to 1 internally
366 : : // 0: This requests JSBSim not to output any messages
367 : : // whatsoever.
368 : : // 1: This value explicity requests the normal JSBSim
369 : : // startup messages
370 : : // 2: This value asks for a message to be printed out when
371 : : // a class is instantiated
372 : : // 4: When this value is set, a message is displayed when a
373 : : // FGModel object executes its Run() method
374 : : // 8: When this value is set, various runtime state variables
375 : : // are printed out periodically
376 : : // 16: When set various parameters are sanity checked and
377 : : // a message is printed out when they go out of bounds
378 : :
379 : 12 : void FGTank::Debug(int from)
380 : : {
381 [ + - ]: 12 : if (debug_lvl <= 0) return;
382 : :
383 [ + - ]: 12 : if (debug_lvl & 1) { // Standard console startup message output
384 [ + + ]: 12 : if (from == 0) { // Constructor
385 : 12 : cout << " " << type << " tank holds " << Capacity << " lbs. " << type << endl;
386 : 12 : cout << " currently at " << PctFull << "% of maximum capacity" << endl;
387 : 18 : cout << " Tank location (X, Y, Z): " << vXYZ(eX) << ", " << vXYZ(eY) << ", " << vXYZ(eZ) << endl;
388 : 12 : cout << " Effective radius: " << Radius << " inches" << endl;
389 : 12 : cout << " Initial temperature: " << Temperature << " Fahrenheit" << endl;
390 : 6 : cout << " Priority: " << Priority << endl;
391 : : }
392 : : }
393 [ - + ]: 12 : if (debug_lvl & 2 ) { // Instantiation/Destruction notification
394 [ # # ]: 0 : if (from == 0) cout << "Instantiated: FGTank" << endl;
395 [ # # ]: 0 : if (from == 1) cout << "Destroyed: FGTank" << endl;
396 : : }
397 : 12 : if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
398 : : }
399 : 12 : if (debug_lvl & 8 ) { // Runtime state variables
400 : : }
401 : 12 : if (debug_lvl & 16) { // Sanity checking
402 : : }
403 [ - + ]: 12 : if (debug_lvl & 64) {
404 [ # # ]: 0 : if (from == 0) { // Constructor
405 : 0 : cout << IdSrc << endl;
406 : 0 : cout << IdHdr << endl;
407 : : }
408 : : }
409 : : }
410 [ + + ][ + - ]: 12 : }
|