Okay, it may be a very simple error, but this one's been driving me nuts for the last hour or so. This is for an assisngment that's due tonight (in 4hours). So if any one can check this out, it would awesome.
It's a little long cos i'm not sure where the problem is, the value 'startingWeight' that is passed into the methods is being passed into them as the initial value, not the value as the result of all the previous code, as is evident in say: "startingWeight -= 554*9.81;" It will subtract the value, but the value passed back into the method "calculateFuelUsage()" is the original 151315*9.81.
Thanks in advance!
startingWeight is basically a variable that stores the current weight of the aircraft.
The Output. You'll see here that the "End Weight" should go down as the flight progresses, but it simply subtracts the "Total Fuel Used" from the original value of startingWeight.
It's a little long cos i'm not sure where the problem is, the value 'startingWeight' that is passed into the methods is being passed into them as the initial value, not the value as the result of all the previous code, as is evident in say: "startingWeight -= 554*9.81;" It will subtract the value, but the value passed back into the method "calculateFuelUsage()" is the original 151315*9.81.
Thanks in advance!
startingWeight is basically a variable that stores the current weight of the aircraft.
Code:
double timeStep = 0.01; //seconds
double counter = 0;
double totalTime = 0;
double distanceStep = 0;
double distanceCovered = 0;
double desiredDistance; //metres; 18042.9m to first turn, to first buoy 610165.433m, to next two buoys 400km,
double startingWeight = (151315-291.76)*9.81; //after first climb to 1500m 291.76,
double cruiseVelocity ; //SL v = 155, 1500m = 170, 8400m v = 214, intermediate = 170, TURNS = 132.2 @ SL, 140.47 @ 1500m
double fuelWeightUsed = 0;
double curFuelWeightUsed = 0;
double curThrust;
double cruiseHeight; //dropping buoys 33m, intermediate = 1524m, cruise = 8400m, final turn in to approach is 272.72m
public fuelUsage()
{
calcTotalFuelUsage();
}
private void calcTotalFuelUsage()
{
//calculateFuelUsage(h, dD, startingWeight, cV, n, "");
//calculateFuelUsage(8400, 10000000, startingWeight, 214 , 1 , "Cruise to First Turn");
calculateFuelUsage(1524, 18042.9, startingWeight, 170 , 1 , "Cruise to First Turn");
calculateFuelUsage(1524, 2159.52, startingWeight, 140.47, 1.3, "Turn 1");
startingWeight -= 554*9.81;
calculateFuelUsage(8400, 610224.012, startingWeight, 214, 1, "Departing Cruise"); //Cruise
calculateFuelUsageDescent(4216.5, (8400-33)*11, startingWeight, 184.5, 1, "First Descent"); //Cruise
startingWeight -= 200*9.81; //Drop Buoy 1
calculateFuelUsage(33, 141421.3, startingWeight, 155, 1, "Buoy 1-2 Cruise"); //Cruise 200km @ Sea Level
startingWeight -= 200*9.81; //Drop Buoy 2
calculateFuelUsage(33, 141421.3, startingWeight, 155, 1, "Buoy 2-3 Cruise"); //Cruise 200km @ Sea Level
startingWeight -= 200*9.81; //Drop Buoy 3
calculateFuelUsage(33, 5944.1588, startingWeight, 1132.2, 1.3, "Turn 2"); //Turn 2
calculateFuelUsage(33, 196402.241, startingWeight, 155, 1, "Buoy 3-4 Cruise"); //Cruise km @ Sea Level
calculateFuelUsage(33, 5944.1588, startingWeight, 1132.2, 1.3, "Turn 3"); //Turn 3
startingWeight -= 200*9.81; //Drop Buoy 4
calculateFuelUsage(33, 400000, startingWeight, 155, 1, "Buoy 4-5 Cruise"); //Cruise 400km @ Sea Level
startingWeight -= 200*9.81; //Drop Buoy 5
calculateFuelUsage(33, 1763.682, startingWeight, 155, 1.3, "Turn 4"); //Turn 4
startingWeight -= (544.006+291.76)*9.81; //climb to 8400m
calculateFuelUsage(8400, 977869.77, startingWeight, 214, 1, "Final Cruise"); //Final Cruise
calculateFuelUsageDescent(4275, (8400-150)*11, startingWeight, 160, 1, "Final Descent"); //Final Descent
calculateFuelUsage(8400, 2492.386, startingWeight, 132.2, 1.3, "Turn 5"); //turn 5
calculateFuelUsageDescent(80, 1760, startingWeight, 96.51, 1, "Approach Descent"); //Final Descent
}
private void calculateFuelUsage(double cruiseHeight, double desiredDistance, double startingWeight, double cruiseVelocity, double n_1, String title)
{
double fuelWeightUsed = 0;
double distanceCovered = 0;
double totalTime = 0;
while (distanceCovered < desiredDistance)
{
totalTime += timeStep;
distanceStep = cruiseVelocity*timeStep;
curThrust = calcCoeffDrag(cruiseHeight, cruiseVelocity, (startingWeight-fuelWeightUsed), n_1)*0.5*rho(cruiseHeight)*Math.pow(cruiseVelocity, 2)*wingArea;
curFuelWeightUsed = ((tsfc*curThrust)/cruiseVelocity)*(distanceStep/g); //this gives the fuel used per timeStep in kilograms
fuelWeightUsed += (curFuelWeightUsed*9.81/1.4);
distanceCovered += distanceStep;
}
startingWeight -= fuelWeightUsed;
System.out.println("\n---"+title+"----");
System.out.println("Total Fuel Used: "+fuelWeightUsed/9.81+" kg");
System.out.println("End Weight: "+startingWeight/9.81+" kg");
System.out.println("Distance Covered: "+distanceCovered+" m");
System.out.println("Total time taken: "+totalTime+" s");
}
The Output. You'll see here that the "End Weight" should go down as the flight progresses, but it simply subtracts the "Total Fuel Used" from the original value of startingWeight.
Code:
---Cruise to First Turn----
Total Fuel Used: 145.7385063647447 kg
End Weight: 150877.50149363524 kg
Distance Covered: 18043.800000003597 m
Total time taken: 106.1400000000174 s
---Turn 1----
Total Fuel Used: 22.769672350170147 kg
End Weight: 151000.47032764982 kg
Distance Covered: 2160.428600000054 m
Total time taken: 15.379999999999717 s
---Departing Cruise----
Total Fuel Used: 3965.0585781985224 kg
End Weight: 146504.18142180145 kg
Distance Covered: 610225.2800030949 m
Total time taken: 2851.5200000158216 s
---First Descent----
Total Fuel Used: 33.612201426565 kg
Distance Covered: 92037.8250000452 m
Total time taken: 498.8499999996913 s
---Buoy 1-2 Cruise----
Total Fuel Used: 1190.1855930666181 kg
End Weight: 149079.05440693337 kg
Distance Covered: 141422.00000009598 m
Total time taken: 912.3999999993152 s
---Buoy 2-3 Cruise----
Total Fuel Used: 1189.3788325053533 kg
End Weight: 148879.86116749464 kg
Distance Covered: 141422.00000009598 m
Total time taken: 912.3999999993152 s
---Turn 2----
Total Fuel Used: 482.30331477859977 kg
End Weight: 149386.9366852214 kg
Distance Covered: 5955.37200000003 m
Total time taken: 5.259999999999932 s
---Buoy 3-4 Cruise----
Total Fuel Used: 1649.3731141955334 kg
End Weight: 148219.86688580445 kg
Distance Covered: 196403.59999968304 m
Total time taken: 1267.1199999989926 s
---Turn 3----
Total Fuel Used: 482.30331477859977 kg
End Weight: 149386.9366852214 kg
Distance Covered: 5955.37200000003 m
Total time taken: 5.259999999999932 s
---Buoy 4-5 Cruise----
Total Fuel Used: 3347.2495083701515 kg
End Weight: 146321.99049162984 kg
Distance Covered: 400000.7499981539 m
Total time taken: 2580.650000009909 s
---Turn 4----
Total Fuel Used: 17.431497595335166 kg
End Weight: 149451.80850240466 kg
Distance Covered: 1763.899999999966 m
Total time taken: 11.379999999999802 s
---Final Cruise----
Total Fuel Used: 6277.745320605392 kg
End Weight: 142355.72867939458 kg
Distance Covered: 977870.8600054949 m
Total time taken: 4569.490000053321 s
---Final Descent----
Total Fuel Used: 33.03168774364626 kg
Distance Covered: 90750.40000004965 m
Total time taken: 567.1899999996292 s
---Turn 5----
Total Fuel Used: 40.345675293154684 kg
End Weight: 148593.1283247068 kg
Distance Covered: 2493.2919999999554 m
Total time taken: 18.86000000000015 s
---Approach Descent----
Total Fuel Used: 1.08927779957211 kg
Distance Covered: 1760.342399999925 m
Total time taken: 18.24000000000005 s