Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

FUNKCIJA ZA FUEL EFFICIENCY

Public Function CalculateFuelEfficiency(shipSpeed As Double, waveHeight As Double,


wavePeriod As Double) As Double

' Calculates fuel efficiency of a ship at a given speed and wave conditions using ITTC
1957 method.

' Define constants.

Const g As Double = 9.81 ' Acceleration due to gravity [m/s^2]

Const rho As Double = 1025 ' Density of seawater [kg/m^3]

Const L As Double = 223 ' Ship length [m]

Const B As Double = 32.2 ' Ship beam [m]

Const T As Double = 13.4 ' Ship draft [m]

Const S As Double = L * B ' Wetted surface area [m^2]

Const Cb As Double = 0.77 ' Block coefficient [-]

Const Cm As Double = 0.98 ' Midship section coefficient [-]

Const Cw As Double = 1 ' Waterplane area coefficient [-]

Const Rtr As Double = 0 ' Shafting and propeller resistance [N]

' Define variables.

Dim Fn As Double ' Froude number [-]

Dim Re As Double ' Reynolds number [-]

Dim Cf As Double ' Frictional resistance coefficient [-]


Dim Ca As Double ' Added resistance coefficient [-]

Dim Cwv As Double ' Wave-making resistance coefficient [-]

Dim Rf As Double ' Frictional resistance [N]

Dim Ra As Double ' Added resistance [N]

Dim Rw As Double ' Wave-making resistance [N]

Dim Rtotal As Double ' Total resistance [N]

Dim P As Double ' Power required [W]

Dim Peff As Double ' Effective power [W]

Dim FuelFlowRate As Double ' Fuel flow rate [kg/s]

Dim FuelEfficiency As Double ' Fuel efficiency [kg/kWh]

' Calculate Froude number.

Fn = shipSpeed / Sqr(g * L)

' Calculate Reynolds number.

Re = (rho * shipSpeed * L) / 1.139E-6

' Calculate frictional resistance coefficient.

Cf = 0.075 / (Log10(Re) - 2) ^ 2

' Calculate added resistance coefficient.


Ca = 0.006 * (1 + 0.035 * Fn ^ 1.3) * (T / B) ^ 0.2

' Calculate wave-making resistance coefficient.

Cwv = (0.0011 + 0.022 * (L / T) + 0.9 * (waveHeight / T) ^ 3) * (1.56 / (Fn ^ 0.75)) * (1 -


0.0225 * Abs(Cb - 0.8)) * (1 - 0.1 * Exp(-1.5 * (wavePeriod / L) ^ 2))

' Calculate frictional resistance.

Rf = Cf * 0.5 * rho * S * shipSpeed ^ 2

' Calculate added resistance.

Ra = Ca * 0.5 * rho * S * shipSpeed ^ 2

' Calculate wave-making resistance.

Rw = Cwv * rho * g * (T / L) ^ 0.5 * (L ^ 3) * (1.0 / (2.0 * shipSpeed)) ^ 2

' Calculate total resistance.

Rtotal = Rf + Ra + Rw + Rtr

' Calculate power required.

P = Rtotal * shipSpeed

' Calculate effective power.


Peff = P * 0.7 ' Assume 30% power loss

' Calculate fuel flow rate.

FuelFlowRate = Peff / (3600 * 45) ' 45 MJ/kg is the heating value of marine diesel oil

' Calculate fuel efficiency.

FuelEfficiency = 1000 / (FuelFlowRate * shipSpeed) ' g/kWh to kg/100 km

CalculateFuelEfficiency = FuelEfficiency

End Function

' Test the function.

Sub TestCalculateFuelEfficiency()

Dim shipSpeed As Double

Dim waveHeight As Double

Dim wavePeriod As Double

Dim fuelEfficiency As Double

shipSpeed = 20 ' knots

waveHeight = 2 ' meters

wavePeriod = 10 ' seconds


fuelEfficiency = CalculateFuelEfficiency(shipSpeed * 0.5144, waveHeight, wavePeriod)

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 Speed As Double 'Speed of the ship in knots

Dim Wave As Double 'Wave height in meters

Dim Resistance As Double 'Total resistance of the ship

Dim Efficiency As Double 'Fuel efficiency of the ship

Dim Den As Double, Froude As Double 'Variables for the ITTC 1957 formula

'Prompt user for ship speed and wave height

Speed = InputBox("Enter the ship speed (in knots):")

Wave = InputBox("Enter the wave height (in meters):")

'Calculate Froude number


Froude = Speed / ((9.81 * Wave) ^ 0.5)

'Calculate the ITTC 1957 formula denominator

Den = 0.075 / ((Log10((Wave / 0.36) + 1.74 * Froude ^ 0.75) - 0.127) ^ 2)

'Calculate total resistance

Resistance = Den * (Speed ^ 2)

'Calculate fuel efficiency

Efficiency = Speed / (Resistance ^ 0.5)

'Output the results

Range("A1") = "Ship Speed (knots)"

Range("B1") = "Wave Height (m)"

Range("C1") = "Resistance (N)"

Range("D1") = "Fuel Efficiency (knots/N)"

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

Const rho_sea As Double = 1025 'Density of seawater in kg/m^3

Const g As Double = 9.81 'Gravity constant in m/s^2

'Define variables

Dim ship_speed As Double

Dim wave_height As Double

Dim ship_length As Double

Dim ship_displacement As Double

Dim froude_number As Double

Dim friction_resistance As Double

Dim wave_resistance As Double

Dim total_resistance As Double

Dim power As Double

Dim fuel_consumption As Double

Dim fuel_efficiency As Double

'Get user input

ship_speed = InputBox("Enter ship speed in knots")

ship_length = InputBox("Enter ship length in meters")

ship_displacement = InputBox("Enter ship displacement in metric tons")

'Loop through wave heights

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

'Calculate Froude number

froude_number = ship_speed / (g * ship_length) ^ 0.5


'Calculate frictional resistance

friction_resistance = 0.075 * (ship_displacement * g) ^ 0.67 / (1 + froude_number ^ 2) ^ 0.5

'Calculate wave resistance

If wave_height / ship_length < 0.04 Then

wave_resistance = 0

ElseIf wave_height / ship_length > 0.4 Then

wave_resistance = 0.125 * rho_sea * g * ship_length ^ 3

Else

wave_resistance = 0.125 * rho_sea * g * ship_length ^ 3 * (1.446 * wave_height / ship_length -


0.125 * (wave_height /

OPET PUKAO

Sub CalculateFuelEfficiency()

'Define constants

Const rho_sea As Double = 1025 'Density of seawater in kg/m^3

Const g As Double = 9.81 'Gravity constant in m/s^2

'Define variables

Dim ship_speed As Double

Dim wave_height As Double

Dim ship_length As Double

Dim ship_displacement As Double

Dim froude_number As Double

Dim friction_resistance As Double

Dim wave_resistance As Double

Dim total_resistance As Double


Dim power As Double

Dim fuel_consumption As Double

Dim fuel_efficiency As Double

Dim time_interval As Double

Dim distance As Double

Dim total_fuel_consumed As Double

'Get user input

ship_speed = InputBox("Enter initial ship speed in knots")

wave_height = InputBox("Enter initial significant wave height in meters")

ship_length = InputBox("Enter ship length in meters")

ship_displacement = InputBox("Enter ship displacement in metric tons")

time_interval = InputBox("Enter time interval in hours")

distance = InputBox("Enter distance traveled in nautical miles")

'Initialize variables

total_fuel_consumed = 0

'Loop through time intervals and calculate fuel consumption and fuel efficiency at each interval

Do While distance > 0

'Calculate Froude number

froude_number = ship_speed / (g * ship_length) ^ 0.5

'Calculate frictional resistance

friction_resistance = 0.075 * (ship_displacement * g) ^ 0.67 / (1 + froude_number ^ 2) ^ 0.5

'Calculate wave resistance

If wave_height / ship_length < 0.04 Then


wave_resistance = 0

ElseIf wave_height / ship_length > 0.4 Then

wave_resistance = 0.125 * rho_sea * g * ship_length ^ 3

Else

wave_resistance = 0.125 * rho_sea * g * ship_length ^ 3 * (1.446 * wave_height / ship_length -


0.125 * (wave_height / ship_length) ^ 3)

End If

'Calculate total resistance

total_resistance = friction_resistance + wave_resistance

'Calculate power

power = total_resistance * ship_speed

'Calculate fuel consumption

'Calculate fuel consumption

fuel_consumption = power / (3600 * 42.8) 'Assuming a specific fuel consumption of 42.8 g/kWh and
converting power from W to kW

'Calculate fuel efficiency

fuel_efficiency = distance / fuel_consumption

'Add fuel consumption to total fuel consumed

total_fuel_consumed = total_fuel_consumed + fuel_consumption

'Update ship speed based on fuel efficiency

ship_speed = fuel_efficiency * (3600 / 1852) 'Convert fuel efficiency from nautical miles per metric ton
to knots

'Decrement distance by distance traveled during time interval


distance = distance - (ship_speed * time_interval)

'Loop to next time interval

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.

FUELCONSUMPTION WAVE RESISTANCE FUNKCIJA:

Option Explicit

Function WaveResistance(B, L, T, V, g, rho, nu, Fn) As Double

' Calculates the wave resistance of a ship using the ITTC 1957 method.

' B: Beam (m)

' L: Length (m)

' T: Draft (m)

' V: Speed (m/s)

' g: Acceleration due to gravity (m/s^2)

' rho: Density of water (kg/m^3)

' nu: Kinematic viscosity of water (m^2/s)

' Fn: Froude number

Const PI = 3.14159265358979

Dim Froude, Cb, Cp, Cm, R, k, A As Double

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

R = 0.5 * rho * V ^ 2 * L * (Cp + Cm) / (g * (1 + k * Fn ^ 2))

A = PI * (B / 2) ^ 2

WaveResistance = R / A

End Function

Here's a breakdown of what each line does:

 Cp = 1 - 0.8 * T / B: Calculates the prismatic coefficient of the ship, which is a


measure of the distribution of volume along the length of the ship. The prismatic
coefficient is a dimensionless quantity between 0 and 1, and a higher value indicates
that the ship is more "full-bodied" and less "streamlined".
 Cm = 1 - 0.03 * L / (T + B) + 0.02 * (L / (T + B)) ^ 2 + 0.2 * Froude ^
0.5: Calculates the midship section coefficient of the ship, which is a measure of the
cross-sectional area of the ship at its widest point. The midship section coefficient is also
a dimensionless quantity between 0 and 1, and a higher value indicates that the ship has
a larger cross-sectional area.
 `R = 0.

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()

Dim speed As Double, resistance As Double, displacement As Double

Dim waveHeight As Double, waveLength As Double, viscosity As Double

Dim fricResistance As Double, waveResistance As Double, totalResistance As Double

Dim fuelFlowRate As Double, fuelEfficiency As Double


' Define ship parameters

displacement = 10000 ' in metric tons

viscosity = 1.15E-6 ' in m^2/s

' Loop through different speeds

For speed = 10 To 20 Step 1

' Loop through different wave conditions

For waveHeight = 0.5 To 2 Step 0.5

waveLength = 1.56 * waveHeight ^ 1.67

' Calculate resistance components

fricResistance = 0.075 * viscosity * speed * displacement / (log10(waveLength / (2.5 *


viscosity)) ^ 2)

waveResistance = 0.5 * displacement * waveHeight ^ 2 / waveLength

totalResistance = fricResistance + waveResistance

' Calculate fuel flow rate and fuel efficiency

fuelFlowRate = 0.1 * totalResistance * speed ^ 3

fuelEfficiency = speed / fuelFlowRate

' Output results

Range("A1").Offset(speed - 10, 0) = speed

Range("B1").Offset(speed - 10, 0) = waveHeight

Range("C1").Offset(speed - 10, 0) = fuelEfficiency

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()

' Declare variables

Dim startTime As Date

Dim endTime As Date

Dim elapsedTime As Long

Dim totalElapsedTime As Long

Dim averageSpeed As Double


Dim orderedSpeed As Double

Dim speedOverrun As Double

Dim operationMode As String

Dim modeTimeDict As Object

Set modeTimeDict = CreateObject("Scripting.Dictionary")

' Loop through all rows of voyage data

For i = 2 To Range("A" & Rows.Count).End(xlUp).Row

' Get start and end times

startTime = Range("A" & i).Value

endTime = Range("B" & i).Value

' Calculate elapsed time in minutes

elapsedTime = DateDiff("n", startTime, endTime)

' Add elapsed time to total elapsed time

totalElapsedTime = totalElapsedTime + elapsedTime

' Get operation mode

operationMode = Range("C" & i).Value

' Add elapsed time to dictionary for operation mode

If modeTimeDict.Exists(operationMode) Then

modeTimeDict(operationMode) = modeTimeDict(operationMode) + elapsedTime

Else

modeTimeDict.Add operationMode, elapsedTime


End If

' Calculate ordered speed and speed overrun

orderedSpeed = Range("D" & i).Value

speedOverrun = Range("E" & i).Value - orderedSpeed

' Add speed overrun to total speed overrun

totalSpeedOverrun = totalSpeedOverrun + speedOverrun

' Add to counter for number of rows

numRows = numRows + 1

Next i

' Calculate average speed

averageSpeed = totalElapsedTime / (numRows - 1)

' Print results

Debug.Print "Total elapsed time: " & totalElapsedTime

Debug.Print "Average speed: " & averageSpeed

Debug.Print "Total speed overrun: " & totalSpeedOverrun

' Print dictionary of mode times

For Each mode In modeTimeDict.Keys

Debug.Print "Mode " & mode & " time: " & modeTimeDict(mode)

Next mode
End Sub

1. Open Microsoft Excel and create a new workbook.


2. Click on the "Developer" tab and select "Visual Basic" to open the VBA editor.
3. In the VBA editor, create a new module by clicking "Insert" and selecting "Module."
4. Define the necessary variables that will be used in the code. For example, you may need
to define variables for start time, end time, and speed data.
5. Create a loop that will iterate through the data collected during the sea passage days.
This can be done using a "For Each" loop or a "Do While" loop, depending on how the
data is organized.
6. Within the loop, calculate the operation mode time distribution by determining the
percentage of time spent in each mode. This can be done by dividing the total time
spent in each mode by the total time of the sea passage.
7. Calculate the average speed by summing all the speeds recorded during the sea
passage and dividing by the number of data points.
8. Calculate the ordered speed overrun by subtracting the average speed from the ordered
speed.
9. Output the results to a separate sheet within the Excel workbook.

Here is an example VBA code that you can use as a starting point:

Sub CalculateSeaPassageStats()

' Define variables

Dim startTime As Date

Dim endTime As Date

Dim speedData As Range

' Set the range for the speed data

Set speedData = Range("A2:A100")

' Initialize counters

Dim totalTime As Long


Dim idleTime As Long

Dim transitTime As Long

Dim maneuveringTime As Long

' Get start and end times

startTime = speedData.Cells(1, 1).Value

endTime = speedData.Cells(speedData.Cells.Count, 1).Value

' Calculate elapsed time in minutes

totalTime = DateDiff("n", startTime, endTime)

' Loop through the speed data

For Each speed In speedData

If speed.Value = "Idle" Then

idleTime = idleTime + 1

ElseIf speed.Value = "Transit" Then

transitTime = transitTime + 1

ElseIf speed.Value = "Maneuvering" Then

maneuveringTime = maneuveringTime + 1

End If

Next speed

' Print results

Debug.Print "Total time (minutes): " & totalTime

Debug.Print "Idle time: " & idleTime

Debug.Print "Transit time: " & transitTime

Debug.Print "Maneuvering time: " & maneuveringTime


End Sub

You might also like