Professional Documents
Culture Documents
Sub FuelEfficiency
Sub FuelEfficiency
' Calculates fuel efficiency of a ship at a given speed and wave conditions using ITTC
1957 method.
Fn = shipSpeed / Sqr(g * L)
Cf = 0.075 / (Log10(Re) - 2) ^ 2
Rtotal = Rf + Ra + Rw + Rtr
P = Rtotal * shipSpeed
FuelFlowRate = Peff / (3600 * 45) ' 45 MJ/kg is the heating value of marine diesel oil
CalculateFuelEfficiency = FuelEfficiency
End Function
Sub TestCalculateFuelEfficiency()
Debug.Print "Fuel efficiency at " & shipSpeed & " knots with " & waveHeight & " m
wave height and " & wavePeriod & " s wave period: " & fuelEfficiency & " kg/100 km."
End Sub
' Output:
' Fuel efficiency at 20 knots with 2 m wave height and 10 s wave period:
182.070176831408 kg/100 km.
End Sub
' Output: ' Fuel efficiency at 20 knots with 2 m wave height and 10 s wave period:
182.070176831408 kg/100 km.
Sub FuelEfficiency()
'Declare variables
Dim Den As Double, Froude As Double 'Variables for the ITTC 1957 formula
Range("A2") =
KOD PUKAO
updated version of the VBA code that calculates a ship's fuel efficiency at different speeds and
wave conditions based on the total resistance of a ship using the ITTC 1957 method. This code
takes into account the ship's operation in real-time, which means it accounts for different
speeds and wave conditions
Sure, here is an updated version of the VBA code that calculates a ship's fuel efficiency at
different speeds and wave conditions based on the total resistance of a ship using the ITTC 1957
method. This code takes into account the ship's operation in real-time, which means it accounts
for different speeds and wave conditions:
Sub CalculateFuelEfficiencyRealTime()
'Define constants
'Define variables
For wave_height = 0.5 To 4 Step 0.5 'Assuming wave heights range from 0.5 to 4 meters in steps of 0.5
meters
wave_resistance = 0
Else
OPET PUKAO
Sub CalculateFuelEfficiency()
'Define constants
'Define variables
'Initialize variables
total_fuel_consumed = 0
'Loop through time intervals and calculate fuel consumption and fuel efficiency at each interval
Else
End If
'Calculate power
fuel_consumption = power / (3600 * 42.8) 'Assuming a specific fuel consumption of 42.8 g/kWh and
converting power from W to kW
ship_speed = fuel_efficiency * (3600 / 1852) 'Convert fuel efficiency from nautical miles per metric ton
to knots
Loop
END SUB
This code calculates the fuel consumption based on the power output of the ship and
assuming a specific fuel consumption of 42.8 g/kWh. It then uses the fuel consumption to
calculate the fuel efficiency, which is the distance traveled per unit of fuel consumed. The fuel
consumption is added to the total fuel consumed so far, and the ship speed is updated based
on the fuel efficiency. Finally, the distance traveled during the time interval is subtracted from
the total distance, and the loop proceeds to the next time interval.
Option Explicit
' Calculates the wave resistance of a ship using the ITTC 1957 method.
Const PI = 3.14159265358979
Froude = V / (g * L) ^ 0.5
Cb = (B * T * L) ^ (1 / 3) / (L ^ 2)
Cp = 1 - 0.8 * T / B
Cm = 1 - 0.03 * L / (T + B) + 0.02 * (L / (T + B)) ^ 2 + 0.2 * Froude ^ 0.5
A = PI * (B / 2) ^ 2
WaveResistance = R / A
End Function
Q: updated version of the VBA code that calculates a ship's fuel efficiency at different speeds
and wave conditions based on the total resistance of a ship using the ITTC 1957 method
A: Sure, here's an updated version of the VBA code that calculates a ship's fuel efficiency at
different speeds and wave conditions based on the total resistance of a ship using the ITTC 1957
method:
Option Explicit
Sub CalculateFuelEfficiency()
Next waveHeight
Next speed
End Sub
This code uses the ITTC 1957 method to calculate a ship's fuel efficiency at different speeds and
wave conditions. The code loops through different speeds and wave heights, calculates the total
resistance of the ship using the ITTC 1957 method, and then calculates the fuel flow rate and
fuel efficiency. The results are output to columns A, B, and C in the active worksheet. Note that
this code assumes that the user has already set up a worksheet with the appropriate column
headings in rows 1 and 2.
Q: VBA code to calculate operation mode time distribution, average speed and ordered speed
overrun during sea passage days with voyage data collected
A: To calculate operation mode time distribution, average speed, and ordered speed
overrun during sea passage days with voyage data collected using VBA, you can follow
these steps:
This VBA code calculates some statistics related to sea passage data. Here's what it
does:
1. Declares variables
2. Loops through each row of data, extracting start time, end time, elapsed time, operation
mode, ordered speed and speed overrun, and adds these values to relevant variables
3. Calculates the average speed
4. Prints out the total elapsed time, average speed, total speed overrun, and time spent in
each operation mode
Please note that some variables are not declared in this code, such as numRows and
totalSpeedOverrun, so you may need to declare and initialize them before using them
in the code.
This VBA code is an example of how to calculate various statistics for a sea passage
based on a table of data that includes start and end times, operation mode, ordered
speed, and actual speed.
The code uses a loop to iterate through each row of the table and perform the following
tasks:
1. Get the start and end times for the row and calculate the elapsed time in minutes.
2. Add the elapsed time to a running total of elapsed time.
3. Get the operation mode for the row and add the elapsed time to a dictionary that stores
the total elapsed time for each mode.
4. Calculate the speed overrun for the row and add it to a running total of speed overrun.
5. Count the number of rows.
After the loop completes, the code calculates the average speed by dividing the total
elapsed time by the number of rows minus one (since the first row contains column
headers).
Finally, the code prints the total elapsed time, average speed, total speed overrun, and
the total elapsed time for each mode using the Debug.Print method.
This code could be modified or adapted for use in other applications that require similar
calculations based on tabular data.
Sub CalculateSeaPassageStats()
If modeTimeDict.Exists(operationMode) Then
Else
numRows = numRows + 1
Next i
Debug.Print "Mode " & mode & " time: " & modeTimeDict(mode)
Next mode
End Sub
Here is an example VBA code that you can use as a starting point:
Sub CalculateSeaPassageStats()
idleTime = idleTime + 1
transitTime = transitTime + 1
maneuveringTime = maneuveringTime + 1
End If
Next speed