def calculateDensities(time): ########## all centers for road_index in range(len(networks[time].roads)): grid_=networks[time].roads[road_index].grid prev_grid=networks[time-1].roads[road_index].grid # updating central cells for i in range(1, grid_.cells.__len__() - 1, 1): cell = grid_.cells[i] prev_cell_before = prev_grid.cells[i - 1] prev_cell = prev_grid.cells[i] prev_cell_after = prev_grid.cells[i + 1] cell.p = 0.5 * prev_cell.p + 0.25 * prev_cell_after.p + 0.25 * prev_cell_before.p + FlowParams.d_t / FlowParams.d_x / 2 * ( q(prev_cell_before.p) - q(prev_cell_after.p)) # updating the first cell of road 3 cell = networks[time].roads[2].grid.cells[0] prev_cell = networks[time-1].roads[2].grid.cells[0] prev_cell_after=networks[time-1].roads[2].grid.cells[1] cell_after=networks[time].roads[2].grid.cells[1] prev_lastCell_1=networks[time-1].roads[1].grid.cells[-1] cell.p = prev_cell.p-(cell_after.p-prev_cell_after.p)+1/2*prev_lastCell_1.p #updating the last cells of road 1 lastCell = networks[time].roads[0].grid.cells[-1] prev_lastCell = networks[time-1].roads[0].grid.cells[-1] prev_lastCell_before=networks[time-1].roads[0].grid.cells[-1] lastCell_before=networks[time].roads[0].grid.cells[-1] lastCell.p=1/2*prev_lastCell.p+(prev_lastCell_before.p-lastCell_before.p) # updating the last cells of road 2 lastCell = networks[time].roads[1].grid.cells[-1] prev_lastCell = networks[time - 1].roads[1].grid.cells[-1] prev_lastCell_before = networks[time - 1].roads[1].grid.cells[-1] lastCell_before = networks[time].roads[1].grid.cells[-1] lastCell.p = prev_lastCell.p + (prev_lastCell_before.p - lastCell_before.p)
def calculateDensities(time): grid = grids[time] prev_grid = grids[time - 1] # updating the first cell firstCell = grid.cells[0] prev_firstCell = prev_grid.cells[0] prev_firstCell_after = prev_grid.cells[1] firstCell.p = 0.5 * prev_firstCell.p + 0.25 * prev_firstCell_after.p + 0.25 * FlowParams.p_source + FlowParams.d_t / FlowParams.d_x / 2 * ( q(FlowParams.p_source) - q(prev_firstCell_after.p)) # updating central cells for i in range(1, grid.cells.__len__() - 1, 1): cell = grid.cells[i] prev_cell_before = prev_grid.cells[i - 1] prev_cell = prev_grid.cells[i] prev_cell_after = prev_grid.cells[i + 1] cell.p = 0.5 * prev_cell.p + 0.25 * prev_cell_after.p + 0.25 * prev_cell_before.p + FlowParams.d_t / FlowParams.d_x / 2 * ( q(prev_cell_before.p) - q(prev_cell_after.p)) #updating the last cell lastCell = grid.cells[-1] prev_lastCell = prev_grid.cells[-1] prev_lastCell_before = prev_grid.cells[-2] p_out = 0 lastCell.p = 0.5 * prev_lastCell.p + 0.25 * p_out + 0.25 * prev_lastCell_before.p + FlowParams.d_t / FlowParams.d_x / 2 * ( q(prev_lastCell_before.p) - q(p_out))
def p(self, value): self._p = min([positive(value), FlowParams.p_max]) self.q = positive(q(self._p))
def __init__(self, number): self.number = number self._p = FlowParams.p_init self._q = FlowParams.q_init if FlowParams.q_init else q( FlowParams.p_init)