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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
47 static const char *IdSrc = "$Id$";
48 static const char *IdHdr = ID_TANK;
50 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
54 FGTank::FGTank(FGFDMExec* exec, Element* el, int tank_number)
55 : TankNumber(tank_number)
60 Temperature = -9999.0;
61 Auxiliary = exec->GetAuxiliary();
62 Radius = Capacity = Contents = Standpipe = 0.0;
63 PropertyManager = exec->GetPropertyManager();
65 vXYZ_drain.InitMatrix();
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 vXYZ_drain = vXYZ; // Set initial drain location to initial tank CG
78 element = el->FindElement("drain_location");
80 vXYZ_drain = element->FindElementTripletConvertTo("IN");
83 if (el->FindElement("radius"))
84 Radius = el->FindElementValueAsNumberConvertTo("radius", "IN");
85 if (el->FindElement("capacity"))
86 Capacity = el->FindElementValueAsNumberConvertTo("capacity", "LBS");
87 if (el->FindElement("contents"))
88 InitialContents = Contents = el->FindElementValueAsNumberConvertTo("contents", "LBS");
89 if (el->FindElement("temperature"))
90 InitialTemperature = Temperature = el->FindElementValueAsNumber("temperature");
91 if (el->FindElement("standpipe"))
92 InitialStandpipe = Standpipe = el->FindElementValueAsNumberConvertTo("standpipe", "LBS");
97 PctFull = 100.0*Contents/Capacity; // percent full; 0 to 100.0
103 char property_name[80];
104 snprintf(property_name, 80, "propulsion/tank[%d]/contents-lbs", TankNumber);
105 PropertyManager->Tie( property_name, (FGTank*)this, &FGTank::GetContents,
106 &FGTank::SetContents );
108 if (Temperature != -9999.0) InitialTemperature = Temperature = FahrenheitToCelsius(Temperature);
109 Area = 40.0 * pow(Capacity/1975, 0.666666667);
114 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123 void FGTank::ResetToIC(void)
125 Temperature = InitialTemperature;
126 Standpipe = InitialStandpipe;
127 Contents = InitialContents;
128 PctFull = 100.0*Contents/Capacity;
132 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 const FGColumnVector3 FGTank::GetXYZ(void)
136 return vXYZ_drain + (Contents/Capacity)*(vXYZ - vXYZ_drain);
139 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141 const double FGTank::GetXYZ(int idx)
143 return vXYZ_drain(idx) + (Contents/Capacity)*(vXYZ(idx)-vXYZ_drain(idx));
146 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148 double FGTank::Drain(double used)
150 double remaining = Contents - used;
152 if (remaining >= 0) { // Reduce contents by amount used.
155 PctFull = 100.0*Contents/Capacity;
157 } else { // This tank must be empty.
166 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168 double FGTank::Fill(double amount)
170 double overage = 0.0;
174 if (Contents > Capacity) {
175 overage = Contents - Capacity;
179 PctFull = Contents/Capacity*100.0;
184 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
186 void FGTank::SetContents(double amount)
189 if (Contents > Capacity) {
193 PctFull = Contents/Capacity*100.0;
197 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 double FGTank::Calculate(double dt)
201 if (Temperature == -9999.0) return 0.0;
202 double HeatCapacity = 900.0; // Joules/lbm/C
203 double TempFlowFactor = 1.115; // Watts/sqft/C
204 double TAT = Auxiliary->GetTAT_C();
205 double Tdiff = TAT - Temperature;
206 double dTemp = 0.0; // Temp change due to one surface
207 if (fabs(Tdiff) > 0.1) {
208 dTemp = (TempFlowFactor * Area * Tdiff * dt) / (Contents * HeatCapacity);
210 return Temperature += (dTemp + dTemp); // For now, assume upper/lower the same
213 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214 // The bitmasked value choices are as follows:
215 // unset: In this case (the default) JSBSim would only print
216 // out the normally expected messages, essentially echoing
217 // the config files as they are read. If the environment
218 // variable is not set, debug_lvl is set to 1 internally
219 // 0: This requests JSBSim not to output any messages
221 // 1: This value explicity requests the normal JSBSim
223 // 2: This value asks for a message to be printed out when
224 // a class is instantiated
225 // 4: When this value is set, a message is displayed when a
226 // FGModel object executes its Run() method
227 // 8: When this value is set, various runtime state variables
228 // are printed out periodically
229 // 16: When set various parameters are sanity checked and
230 // a message is printed out when they go out of bounds
232 void FGTank::Debug(int from)
234 if (debug_lvl <= 0) return;
236 if (debug_lvl & 1) { // Standard console startup message output
237 if (from == 0) { // Constructor
238 cout << " " << type << " tank holds " << Capacity << " lbs. " << type << endl;
239 cout << " currently at " << PctFull << "% of maximum capacity" << endl;
240 cout << " Tank location (X, Y, Z): " << vXYZ(eX) << ", " << vXYZ(eY) << ", " << vXYZ(eZ) << endl;
241 cout << " Effective radius: " << Radius << " inches" << endl;
242 cout << " Initial temperature: " << Temperature << " Fahrenheit" << endl;
245 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
246 if (from == 0) cout << "Instantiated: FGTank" << endl;
247 if (from == 1) cout << "Destroyed: FGTank" << endl;
249 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
251 if (debug_lvl & 8 ) { // Runtime state variables
253 if (debug_lvl & 16) { // Sanity checking
255 if (debug_lvl & 64) {
256 if (from == 0) { // Constructor
257 cout << IdSrc << endl;
258 cout << IdHdr << endl;