Beispiel #1
0
def test_traffic_sequence_not_adjusted():
    c = opensees_default(bridge_705(0.5))
    max_time = 10
    traffic_scenario = normal_traffic(c=c, lam=5, min_d=2)
    traffic_sequence = traffic_scenario.traffic_sequence(bridge=c.bridge,
                                                         max_time=max_time)
    # Total time of the simulation should be greater than max_time.
    warmed_up_at = traffic_sequence[0][0].time_left_bridge(c.bridge)
    end_time = traffic_sequence[-1][1]
    assert end_time > warmed_up_at + max_time
    # The first vehicles should enter at x=0 at time t=0.
    assert traffic_sequence[0][0].init_x_frac == 0
    assert traffic_sequence[0][1] == 0
    assert traffic_sequence[0][2] == True
    # Time the simulation has warmed up at should be when the first vehicles has
    # left the bridge. Since all vehicles have the same speed, this should at
    # least be greater than the time any vehicles takes until it has begun to
    # leave the bridge (first axle leaving), but depending on vehicles length the
    # time to have entirely left will be a little different per vehicles.
    vehicle = next(traffic_scenario.mv_vehicles(bridge=c.bridge, lane=0))(0, 0)
    assert warmed_up_at > vehicle.time_leaving_bridge(c.bridge)
    first_vehicle, first_time, first_event = traffic_sequence[0]
    # Time of the first event should be 0, when the first vehicles enters.
    assert first_time == 0
    penul_vehicle, penul_time, penul_event = traffic_sequence[-2]
    final_vehicle, final_time, final_event = traffic_sequence[-1]
    # Time of the last event should be greater than the requested 'max_time' +
    # the time the simulation has 'warmed_up_at', and the second last event
    # should be less than.
    assert penul_time < max_time + warmed_up_at < final_time
Beispiel #2
0
def test_to_traffic_array():
    c = opensees_default(bridge_705(0.5))
    max_time = 10
    traffic_scenario = normal_traffic(c=c, lam=5, min_d=2)
    traffic_sequence = traffic_scenario.traffic_sequence(bridge=c.bridge,
                                                         max_time=max_time)

    # 'TrafficArray', traffic not allowed to warm up.
    traffic_array = to_traffic_array(c=c,
                                     traffic_sequence=traffic_sequence,
                                     max_time=max_time,
                                     warm_up=False)
    assert len(traffic_array) == max_time * (1 / c.sensor_hz) + 1
    for traffic_at_time in traffic_array:
        assert sum(traffic_at_time) > 0

    # 'TrafficArray', traffic warmed up.
    traffic_array_warm = to_traffic_array(c=c,
                                          traffic_sequence=traffic_sequence,
                                          max_time=max_time,
                                          warm_up=True)
    assert len(traffic_array_warm) == max_time * (1 / c.sensor_hz) + 1
    assert sum(traffic_array[0]) < sum(traffic_array_warm[0])
    for traffic_at_time in traffic_array_warm:
        assert sum(traffic_at_time) > 0
Beispiel #3
0
def cli(
    uls: int,
    msl: str,
    two_materials: bool,
    parallel: int,
    parallel_ulm: bool,
    save_to: bool,
    shorten_paths: bool,
    pdb: bool,
):
    global b_func
    global two_materials_
    global save_to_
    global parallel_
    global parallel_ulm_
    global shorten_paths_
    global il_num_loads_
    b_func = bridge_705(msl)
    two_materials_ = two_materials
    save_to_ = save_to
    parallel_ = parallel
    parallel_ulm_ = parallel_ulm
    shorten_paths_ = shorten_paths
    il_num_loads_ = uls

    click.echo(f"Bridge: {b_func().name}")
    click.echo(f"ULS: {il_num_loads_}")
    click.echo(f"MSL: {msl}")
    click.echo(f"Two materials: {two_materials_}")
    click.echo(f"Parallel: {parallel_}")
    click.echo(f"Parallel wheel tracks: {parallel_ulm_}")
    click.echo(f"Save to: {save_to_}")
    click.echo(f"Shorten paths: {shorten_paths_}")
Beispiel #4
0
def test_sample_vehicle():
    c = opensees_default(bridge_705(0.5))
    c.vehicle_density = [(11.5, 0.7), (12.2, 0.2), (43, 0.1)]

    # Test a vehicles is returned.
    vehicle = sample_vehicle(c)
    print_d(D, vehicle)
    assert isinstance(vehicle, Vehicle)

    # Test noise is added.
    _, vehicle = sample_vehicle(c=c, pd_row=True)
    true_vehicle = c.vehicle_data.loc[vehicle.index]
    for col_name in noise_col_names:
        # DataFrame is only of length 1, still need .all applied.
        assert (vehicle.loc[vehicle.index, col_name] !=
                c.vehicle_data.loc[vehicle.index, col_name]).all()

    # Test noise is not added.
    c.perturb_stddev = 0
    _, vehicle = sample_vehicle(c=c, pd_row=True)
    true_vehicle = c.vehicle_data.loc[vehicle.index]
    for col_name in noise_col_names:
        # DataFrame is only of length 1, still need .all applied.
        assert (vehicle.loc[vehicle.index,
                            col_name] == c.vehicle_data.loc[vehicle.index,
                                                            col_name]).all()
Beispiel #5
0
def test_to_traffic_array_methods():
    c = opensees_default(bridge_705(0.5))
    max_time = 1
    traffic_scenario = normal_traffic(c=c, lam=5, min_d=2)
    traffic_sequence = traffic_scenario.traffic_sequence(bridge=c.bridge,
                                                         max_time=max_time)
    traffic_array_new = to_traffic_array(c=c,
                                         traffic_sequence=traffic_sequence,
                                         max_time=max_time,
                                         new=True)
    traffic_array_old = to_traffic_array(c=c,
                                         traffic_sequence=traffic_sequence,
                                         max_time=max_time,
                                         new=False)
    assert traffic_array_new.shape == traffic_array_old.shape
    for time in range(len(traffic_array_new)):
        assert np.isclose(sum(traffic_array_new[time]),
                          sum(traffic_array_old[time]))
Beispiel #6
0
from copy import deepcopy
import numpy as np

from bridge_sim.bridges.bridge_705 import bridge_705
from bridge_sim.configs import opensees_default
from bridge_sim.vehicles import truck1
from bridge_sim.model import PointLoad
from bridge_sim.util import flatten

c = opensees_default(bridge_705(0.5))
entering_time = truck1.time_entering_bridge(bridge=c.bridge)
entered_time = truck1.time_entered_bridge(bridge=c.bridge)
leaving_time = truck1.time_leaving_bridge(bridge=c.bridge)
left_time = truck1.time_left_bridge(bridge=c.bridge)
wagen1_top_lane = deepcopy(truck1)
wagen1_top_lane.lane = 1
assert truck1.lane != wagen1_top_lane.lane
assert truck1.init_x_frac == 0


def test_mv_vehicle_time_leaving_bridge():
    # Bottom lane.
    assert c.bridge.length / truck1.mps == truck1.time_leaving_bridge(c.bridge)
    # Top lane.
    assert c.bridge.length / wagen1_top_lane.mps == wagen1_top_lane.time_leaving_bridge(
        c.bridge)


def test_mv_vehicle_time_left_bridge():
    # Bottom lane.
    time_to_leave = truck1.time_left_bridge(