Skip to content

Commit

Permalink
comment on lock module
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedor Baart committed Feb 8, 2024
1 parent f0e92f9 commit 3df8a95
Showing 1 changed file with 23 additions and 40 deletions.
63 changes: 23 additions & 40 deletions opentnsim/lock.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""This is the lock module as part of the OpenTNSim package. See the locking examples in the book for detailed descriptions."""

# package(s) related to the simulation
import bisect
import datetime
Expand All @@ -9,6 +11,7 @@
import networkx as nx
import numpy as np
import pandas as pd

# spatial libraries
import pyproj
import pytz
Expand Down Expand Up @@ -127,12 +130,12 @@ def leave_lineup_area(self, origin, destination):

class IsLockWaitingArea(core.HasResource, core.Identifiable, core.Log, output.HasOutput):
"""Mixin class: Something has waiting area object properties as part of the lock complex [in SI-units]:
creates a waiting area with a waiting_area resource which is requested when a vessels wants to enter the area with limited capacity"""
creates a waiting area with a waiting_area resource which is requested when a vessels wants to enter the area with limited capacity
"""

def __init__(
self, node, distance_from_node, *args, **kwargs # a string which indicates the location of the start of the waiting area
):

self.node = node
self.distance_from_node = distance_from_node
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -206,7 +209,6 @@ def __init__(
*args,
**kwargs
):

self.start_node = start_node
self.end_node = end_node
self.lineup_length = self.effective_lineup_length = lineup_length
Expand Down Expand Up @@ -310,7 +312,6 @@ def __init__(
*args,
**kwargs
):

"""Initialization"""
# Properties
self.lock_length = lock_length
Expand Down Expand Up @@ -756,39 +757,28 @@ def determine_levelling_time(self, new_level, delay=0):
- environment: see init function"""

def calculate_discharge(lock, z, to_wlev, from_wlev, time_index, time_step):
two_gz = np.sqrt(2 * 9.81 * z)
if to_wlev[time_step] <= from_wlev[time_step]:
lock.water_level[time_index + time_step] = z + to_wlev[time_step]
if z != 0:
if lock.node_open == lock.node_doors2:
lock.discharge_res[time_step + time_index] += (
-1 * lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
)
lock.discharge_fresh[time_step + time_index] += (
-1 * lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
)
lock.discharge_res[time_step + time_index] += -1 * lock.disch_coeff * lock.opening_area * two_gz
lock.discharge_fresh[time_step + time_index] += -1 * lock.disch_coeff * lock.opening_area * two_gz
else:
lock.discharge_res[time_step + time_index] += lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
lock.discharge_saline[time_step + time_index] += (
lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
)
lock.discharge_res[time_step + time_index] += lock.disch_coeff * lock.opening_area * two_gz
lock.discharge_saline[time_step + time_index] += lock.disch_coeff * lock.opening_area * two_gz
else:
lock.discharge_res[time_step + time_index] = 0
lock.discharge_fresh[time_step + time_index] = 0
else:
lock.water_level[time_index + time_step] = to_wlev[time_step] - z
if z != 0:
if lock.node_open == lock.node_doors2:
lock.discharge_res[time_step + time_index] += lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
lock.discharge_saline[time_step + time_index] += (
lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
)
lock.discharge_res[time_step + time_index] += lock.disch_coeff * lock.opening_area * two_gz
lock.discharge_saline[time_step + time_index] += lock.disch_coeff * lock.opening_area * two_gz
else:
lock.discharge_res[time_step + time_index] += (
-1 * lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
)
lock.discharge_fresh[time_step + time_index] += (
-1 * lock.disch_coeff * lock.opening_area * np.sqrt(2 * 9.81 * z)
)
lock.discharge_res[time_step + time_index] += -1 * lock.disch_coeff * lock.opening_area * two_gz
lock.discharge_fresh[time_step + time_index] += -1 * lock.disch_coeff * lock.opening_area * two_gz
else:
lock.discharge_res[time_step + time_index] += 0
lock.discharge_fresh[time_step + time_index] += 0
Expand Down Expand Up @@ -833,6 +823,7 @@ def calculate_discharge(lock, z, to_wlev, from_wlev, time_index, time_step):
).argmin()
calculate_discharge(self, z, to_wlev, from_wlev, time_index, 0)
time_series = np.arange(0, 2 * 3600, self.time_step)

for t in enumerate(time_series):
if t[0] == 0:
continue
Expand Down Expand Up @@ -885,22 +876,15 @@ def convert_chamber(self, environment, new_level, number_of_vessels, vessel, tim

def door_open():
if len(self.log["Action"]) > 4:
if timeout_required:
T_door_open = self.env.now - time.mktime(pd.Timestamp(self.log["Time"][-4]).timetuple()) - 0.5 * self.doors_open
else:
T_door_open = (
self.env.now
+ self.doors_close
- time.mktime(pd.Timestamp(self.log["Time"][-4]).timetuple())
- 0.5 * self.doors_open
)
t_doors_open = time.mktime(pd.Timestamp(self.log["Time"][-4]).timetuple())
else:
if timeout_required:
T_door_open = self.env.now - time.mktime(self.env.simulation_start.timetuple()) - 0.5 * self.doors_open
else:
T_door_open = (
self.env.now + self.doors_close - time.mktime(self.env.simulation_start.timetuple()) - 0.5 * self.doors_open
)
t_doors_open = time.mktime(self.env.simulation_start.timetuple())

if timeout_required:
T_door_open = self.env.now - t_doors_open - 0.5 * self.doors_open
else:
T_door_open = self.env.now + self.doors_close - t_doors_open - 0.5 * self.doors_open

if "hydrodynamic_information" in dir(self.env.vessel_traffic_service):
time_index_start = np.absolute(
self.water_level.TIME.values - np.datetime64(datetime.datetime.fromtimestamp(self.env.now - T_door_open))
Expand Down Expand Up @@ -1370,7 +1354,6 @@ def change_lineup_dist(vessel, lock, lineup_area, lineup_dist, lineup_area_user)
# Checks the need to change the position of the vessel within the line-up area
for vessel_index, lineup_area_user in enumerate(lineup_area.line_up_area[start_node].users):
if lineup_area_user.obj.id == vessel.id:

# Imports information about the current lock cycle
lock_door_1_user_priority = 0
lock_door_2_user_priority = 0
Expand Down

0 comments on commit 3df8a95

Please sign in to comment.