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
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
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()
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]))
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(
# from bridge_sim import bridges, configs, model, plot, sim, vehicles # # config = configs.opensees_default(bridges.bridge_narrow, shorten_paths=True) # point_loads = vehicles.truck1.to_point_load_pw(time=3.5, bridge=config.bridge, list=True) # responses = sim.responses.load(config, model.RT.YTrans, point_loads) # plot.contour_responses(config, responses, point_loads) # plot.top_view_bridge(config, piers=True) # plt.tight_layout() # plt.show() # Example 3. import matplotlib.pyplot as plt from bridge_sim import bridges, configs, sim, model, plot config = configs.opensees_default(bridges.bridge_wide) responses = sim.responses.load( config, model.RT.YTrans, pier_settlement=[model.PierSettlement(0, 1.2), model.PierSettlement(1, 0.5)] ) plot.contour_responses(config, responses) plot.top_view_bridge(config, piers=True, lanes=True) plt.tight_layout() plt.show() # Example 4. # import matplotlib.pyplot as plt # from bridge_sim import bridges, configs, model, plot, sim #
from pathlib import Path import matplotlib.pyplot as plt from bridge_sim import bridges, configs, model, plot, sim config = configs.opensees_default(bridges.bridge_narrow) point_loads = [model.PointLoad(x=5, z=0, load=100)] responses = sim.responses.load(config, model.RT.YTrans, point_loads) plot.contour_responses(config, responses, point_loads) plot.top_view_bridge(config, piers=True) plt.tight_layout() plt.savefig(Path("~/docker.png").expanduser().as_posix())