1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8 ------------- Copyright (C) 1999 Jon S. Berndt (jsb@hal-pc.org) -------------
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
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
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.
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.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
32 --------------------------------------------------------------------------------
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 #include <FGFDMExec.h>
40 #include <models/FGAuxiliary.h>
43 #if !defined ( sgi ) || defined( __GNUC__ ) && (_COMPILER_VERSION < 740)
51 static const char *IdSrc = "$Id$";
52 static const char *IdHdr = ID_TANK;
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
58 FGTank::FGTank(FGFDMExec* exec, Element* el)
63 Temperature = -9999.0;
64 Auxiliary = exec->GetAuxiliary();
65 Radius = Capacity = Contents = 0.0;
67 type = el->GetAttributeValue("type");
68 if (type == "FUEL") Type = ttFUEL;
69 else if (type == "OXIDIZER") Type = ttOXIDIZER;
70 else Type = ttUNKNOWN;
72 element = el->FindElement("location");
73 if (element) vXYZ = element->FindElementTripletConvertTo("IN");
74 else cerr << "No location found for this tank." << endl;
76 if (el->FindElement("radius"))
77 Radius = el->FindElementValueAsNumberConvertTo("radius", "IN");
78 if (el->FindElement("capacity"))
79 Capacity = el->FindElementValueAsNumberConvertTo("capacity", "LBS");
80 if (el->FindElement("contents"))
81 Contents = el->FindElementValueAsNumberConvertTo("contents", "LBS");
82 if (el->FindElement("temperature"))
83 Temperature = el->FindElementValueAsNumber("temperature");
88 PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0
94 if (Temperature != -9999.0) Temperature = FahrenheitToCelsius(Temperature);
95 Area = 40.0 * pow(Capacity/1975, 0.666666667);
100 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 double FGTank::Drain(double used)
111 double shortage = Contents - used;
115 PctFull = 100.0*Contents/Capacity;
124 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126 double FGTank::Fill(double amount)
128 double overage = 0.0;
132 if (Contents > Capacity) {
133 overage = Contents - Capacity;
137 PctFull = Contents/Capacity*100.0;
142 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144 void FGTank::SetContents(double amount)
147 if (Contents > Capacity) {
151 PctFull = Contents/Capacity*100.0;
155 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157 double FGTank::Calculate(double dt)
159 if (Temperature == -9999.0) return 0.0;
160 double HeatCapacity = 900.0; // Joules/lbm/C
161 double TempFlowFactor = 1.115; // Watts/sqft/C
162 double TAT = Auxiliary->GetTAT_C();
163 double Tdiff = TAT - Temperature;
164 double dT = 0.0; // Temp change due to one surface
165 if (fabs(Tdiff) > 0.1) {
166 dT = (TempFlowFactor * Area * Tdiff * dt) / (Contents * HeatCapacity);
168 return Temperature += (dT + dT); // For now, assume upper/lower the same
171 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
172 // The bitmasked value choices are as follows:
173 // unset: In this case (the default) JSBSim would only print
174 // out the normally expected messages, essentially echoing
175 // the config files as they are read. If the environment
176 // variable is not set, debug_lvl is set to 1 internally
177 // 0: This requests JSBSim not to output any messages
179 // 1: This value explicity requests the normal JSBSim
181 // 2: This value asks for a message to be printed out when
182 // a class is instantiated
183 // 4: When this value is set, a message is displayed when a
184 // FGModel object executes its Run() method
185 // 8: When this value is set, various runtime state variables
186 // are printed out periodically
187 // 16: When set various parameters are sanity checked and
188 // a message is printed out when they go out of bounds
190 void FGTank::Debug(int from)
192 if (debug_lvl <= 0) return;
194 if (debug_lvl & 1) { // Standard console startup message output
195 if (from == 0) { // Constructor
196 cout << " " << type << " tank holds " << Capacity << " lbs. " << type << endl;
197 cout << " currently at " << PctFull << "% of maximum capacity" << endl;
198 cout << " Tank location (X, Y, Z): " << vXYZ(eX) << ", " << vXYZ(eY) << ", " << vXYZ(eZ) << endl;
199 cout << " Effective radius: " << Radius << " inches" << endl;
200 cout << " Initial temperature: " << Temperature << " Fahrenheit" << endl;
203 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
204 if (from == 0) cout << "Instantiated: FGTank" << endl;
205 if (from == 1) cout << "Destroyed: FGTank" << endl;
207 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
209 if (debug_lvl & 8 ) { // Runtime state variables
211 if (debug_lvl & 16) { // Sanity checking
213 if (debug_lvl & 64) {
214 if (from == 0) { // Constructor
215 cout << IdSrc << endl;
216 cout << IdHdr << endl;