Simulation with traffic generation.#

This demo is for the case of generating new traffic and load effect data under a recorded regional traffic flow.

The bridge:

  • Has four 3.5m-width lanes.

  • Has a length of 20m.

  • Has a width of 16m.

  • Has one load effect being considered.

The traffic flow:

  • Vehicles are generated from Garage model.

  • Headways are in freeflow condition (Poisson arrival model).


The part that has already been introduced in the single_vehicle demo.

But this time we change to define a 4-lane bridge.

[4]:
import pybtls as pb
from pathlib import Path


# set the load effect by using a 2D influence surface
lanes_position = [(0.5, 4.0), (4.0, 7.5), (8.5, 12.0), (12.0, 15.5)]
IS_matrix = [
    [0.0, 0.0, 4.0, 8.0, 12.0, 16.0],
    [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
    [10.0, 0.0, 2.5, 5.0, 2.5, 0.0],
    [20.0, 0.0, 0.0, 0.0, 0.0, 0.0],
]
load_effect = pb.InfluenceSurface()
load_effect.set_IS(IS_matrix, lanes_position)

# set the bridge
bridge = pb.Bridge(length=20.0, no_lane=4)
bridge.add_load_effect(inf_line_surf=load_effect, threshold=0.0)
bridge.add_load_effect(
    inf_line_surf=load_effect, threshold=1000.0
)  # We add the same load effect again, but this time with a threshold of 1000.0 for the later POT analysis

Set lane flow compositions (here we just use the same flow for all lanes).

For the lane_dir, 1 means from left to right and 2 means from right to left, based on the same coordinate system as the influence surface.

[5]:
lfc_lane1 = pb.LaneFlowComposition(lane_index=1, lane_dir=1)
lfc_lane1.assign_lane_data(
    hourly_truck_flow=[100] * 24,
    hourly_car_flow=[0] * 24,
    hourly_speed_mean=[80 / 3.6 * 10] * 24,
    hourly_speed_std=[10.0] * 24,
)

lfc_lane2 = pb.LaneFlowComposition(lane_index=2, lane_dir=1)
lfc_lane2.assign_lane_data(
    hourly_truck_flow=[100] * 24,
    hourly_car_flow=[0] * 24,
    hourly_speed_mean=[80 / 3.6 * 10] * 24,
    hourly_speed_std=[10.0] * 24,
)

lfc_lane3 = pb.LaneFlowComposition(lane_index=3, lane_dir=2)
lfc_lane3.assign_lane_data(
    hourly_truck_flow=[100] * 24,
    hourly_car_flow=[0] * 24,
    hourly_speed_mean=[80 / 3.6 * 10] * 24,
    hourly_speed_std=[10.0] * 24,
)

lfc_lane4 = pb.LaneFlowComposition(lane_index=4, lane_dir=2)
lfc_lane4.assign_lane_data(
    hourly_truck_flow=[100] * 24,
    hourly_car_flow=[0] * 24,
    hourly_speed_mean=[80 / 3.6 * 10] * 24,
    hourly_speed_std=[10.0] * 24,
)

Set vehicle generator. Here we use the garage one.

[6]:
# The kernel is to ensure variation between the generated vehicles and garages.
kernel = [[1.0, 0.08], [1.0, 0.05], [1.0, 0.02]]

vehicle_gen = pb.VehicleGenGarage(
    garage=Path(".") / "garage.txt", kernel=kernel, garage_format=4
)

Choose headway generator with the freeflow one.

[7]:
# set headway generator
headway_gen = pb.HeadwayGenFreeflow()

Assemble the vehicle generator and the headway generator with the lfc information to get a traffic generator.

[8]:
traffic_gen = pb.TrafficGenerator(no_lane=4)
traffic_gen.add_lane(vehicle_gen=vehicle_gen, headway_gen=headway_gen, lfc=lfc_lane1)
traffic_gen.add_lane(vehicle_gen=vehicle_gen, headway_gen=headway_gen, lfc=lfc_lane2)
traffic_gen.add_lane(vehicle_gen=vehicle_gen, headway_gen=headway_gen, lfc=lfc_lane3)
traffic_gen.add_lane(vehicle_gen=vehicle_gen, headway_gen=headway_gen, lfc=lfc_lane4)
# traffic_gen.set_start_time(0.0)  # optional, the default start_time is 0.0 unless you want to change it.

Set output, which will be written to HDD.

We request for the time-history, all-event, block-max, peak-over-threshold, and fatigue rainflow output.

[9]:
output_config = pb.OutputConfig()
output_config.set_event_output(write_time_history=True, write_each_event=True)
output_config.set_BM_output(write_vehicle=True, write_summary=True, write_mixed=True)
output_config.set_POT_output(write_vehicle=True, write_summary=True, write_counter=True)
output_config.set_fatigue_output(write_rainflow_output=True, rainflow_decimal=0, rainflow_cut_off=100.0)

Set the simulation and run.

[10]:
sim_task = pb.Simulation(Path(".") / "temp")
sim_task.add_sim(
    bridge=bridge,
    traffic=traffic_gen,
    no_day=250,  # 1-year working days
    output_config=output_config,
    time_step=0.1,
    min_gvw=35,  # Ignore vehicles with GVW less than 35 kN.
    # active_lane=[1,2,3,4],  # optional, if not set, all lanes will be active.
    # track_progress=False,  # optional, if True, the progress print will show up.
    tag="Case2",
)

# run simulation
sim_task.run(no_core=1)

Bridge 20 m: Flushing AllEvents buffer: 10000 events at 7/1/0 14:41:1
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 14/1/0 6:31:42
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 20/1/0 19:51:25
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 2/2/0 7:15:8
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 9/2/0 0:49:30
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 15/2/0 14:22:48
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 22/2/0 5:52:39
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 3/3/0 20:29:16
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 10/3/0 12:29:11
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 17/3/0 4:51:51
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 23/3/0 21:47:27
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 5/4/0 12:33:57
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 12/4/0 4:45:23
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 18/4/0 18:38:38
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 25/4/0 13:37:11
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 7/5/0 6:1:33
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 13/5/0 23:35:35
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 20/5/0 15:41:9
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 2/6/0 5:45:32
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 9/6/0 0:10:57
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 15/6/0 17:16:2
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 22/6/0 12:34:0
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 4/7/0 3:24:59
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 10/7/0 17:42:5
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 17/7/0 10:22:32
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 23/7/0 23:11:30
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 5/8/0 14:23:45
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 12/8/0 5:22:5
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 18/8/0 18:45:30
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 25/8/0 10:48:53
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 7/9/0 4:51:36
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 13/9/0 22:0:55
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 20/9/0 14:47:57
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 2/10/0 7:10:53
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 9/10/0 0:30:58
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 15/10/0 15:44:40
Bridge 20 m: Flushing AllEvents buffer: 10000 events at 22/10/0 7:52:52
Bridge 20 m: Flushing AllEvents buffer: 5532 events at 25/10/0 23:59:6

Check what are the outputs.

[8]:
sim_output = sim_task.get_output()
print(sim_output.keys())
dict_keys(['Case2'])

Use two simple loops to display all the read-in outputs.

The data are stored as pandas.DataFrame.

[9]:
from IPython.display import display

case2_output = sim_output["Case2"]

for i in case2_output.get_summary():
    print(i)

    for j in case2_output.read_data(i):
        print(j)
        display(case2_output.read_data(i)[j])
time_history
TH_20
Time (s) No. Trucks Effect 1 Effect 2
0 4.258400e+01 1 0.000 0.000
1 4.268400e+01 1 12.384 12.384
2 4.278400e+01 1 30.136 30.136
3 4.288400e+01 1 58.898 58.898
4 4.298400e+01 1 87.660 87.660
... ... ... ... ...
4702994 2.159993e+07 1 66.352 66.352
4702995 2.159993e+07 1 45.311 45.311
4702996 2.159993e+07 1 29.782 29.782
4702997 2.159993e+07 1 14.254 14.254
4702998 2.159993e+07 1 2.109 2.109

4702999 rows × 4 columns

all_events
BL_20_AllEvents
Time (s) No. Trucks Effect 1 Effect 2
0 4.258360e+01 1 110.7130 110.7130
1 1.583170e+02 1 138.2720 138.2720
2 3.166630e+02 1 44.7878 44.7878
3 3.459510e+02 1 318.2000 318.2000
4 3.474340e+02 1 33.4742 33.4742
... ... ... ... ...
375141 2.159990e+07 1 813.5680 813.5680
375142 2.159990e+07 1 847.5070 847.5070
375143 2.159990e+07 1 137.7530 137.7530
375144 2.159990e+07 1 18.6105 18.6105
375145 2.159990e+07 1 134.1990 134.1990

375146 rows × 4 columns

BM_by_no_trucks
BM_V_20_3
Index Effect Value Time Position on Bridge No. Trucks Trucks
0 5 1 1011.6 403996.0 8.93 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
1 5 2 1011.6 403996.0 8.93 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
2 10 1 294.8 793455.0 9.27 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
3 10 2 294.8 793455.0 9.27 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4 13 1 549.8 1082703.2 -5.42 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
... ... ... ... ... ... ... ...
79 238 2 835.8 20557689.2 14.31 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
80 239 1 476.0 20621893.3 21.99 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
81 239 2 476.0 20621893.3 21.99 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
82 245 1 151.5 21126323.3 -0.25 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
83 245 2 151.5 21126323.3 -0.25 3 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...

84 rows × 7 columns

BM_V_20_2
Index Effect Value Time Position on Bridge No. Trucks Trucks
0 1 1 705.5 79389.2 26.99 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
1 1 2 705.5 79389.2 26.99 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
2 2 1 577.9 96299.8 6.90 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
3 2 2 577.9 96299.8 6.90 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4 3 1 1077.4 217474.4 -2.49 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
... ... ... ... ... ... ... ...
495 248 2 798.4 21364852.9 14.78 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
496 249 1 769.1 21506786.0 22.62 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
497 249 2 769.1 21506786.0 22.62 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
498 250 1 496.1 21590791.3 -5.00 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
499 250 2 496.1 21590791.3 -5.00 2 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...

500 rows × 7 columns

BM_V_20_1
Index Effect Value Time Position on Bridge No. Trucks Trucks
0 1 1 1086.1 73798.3 -1.64 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
1 1 2 1086.1 73798.3 -1.64 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
2 2 1 1156.8 96013.5 -2.21 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
3 2 2 1156.8 96013.5 -2.21 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4 3 1 1135.9 191177.8 21.77 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
... ... ... ... ... ... ... ...
495 248 2 1153.8 21380814.0 22.31 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
496 249 1 1104.8 21483678.1 19.44 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
497 249 2 1104.8 21483678.1 19.44 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
498 250 1 1149.9 21553543.3 21.75 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
499 250 2 1149.9 21553543.3 21.75 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...

500 rows × 7 columns

BM_by_mixed
BM_V_20_All
Index Effect Value Time Position on Bridge No. Trucks Trucks
0 1 1 1086.1 73798.3 -1.64 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
1 1 2 1086.1 73798.3 -1.64 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
2 2 1 1156.8 96013.5 -2.21 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
3 2 2 1156.8 96013.5 -2.21 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4 3 1 1135.9 191177.8 21.77 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
... ... ... ... ... ... ... ...
495 248 2 1153.8 21380814.0 22.31 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
496 249 1 1104.8 21483678.1 19.44 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
497 249 2 1104.8 21483678.1 19.44 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
498 250 1 1149.9 21553543.3 21.75 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
499 250 2 1149.9 21553543.3 21.75 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...

500 rows × 7 columns

BM_summary
BM_S_20_Eff_1
Block Index 1-Truck Event 2-Truck Event 3-Truck Event
0 1 1086.1 705.5 NaN
1 2 1156.8 577.9 NaN
2 3 1135.9 1077.4 NaN
3 4 1147.4 753.9 NaN
4 5 1184.0 726.4 1011.6
... ... ... ... ...
245 246 1137.6 936.1 NaN
246 247 1172.3 683.6 NaN
247 248 1153.8 798.4 NaN
248 249 1104.8 769.1 NaN
249 250 1149.9 496.1 NaN

250 rows × 4 columns

BM_S_20_Eff_2
Block Index 1-Truck Event 2-Truck Event 3-Truck Event
0 1 1086.1 705.5 NaN
1 2 1156.8 577.9 NaN
2 3 1135.9 1077.4 NaN
3 4 1147.4 753.9 NaN
4 5 1184.0 726.4 1011.6
... ... ... ... ...
245 246 1137.6 936.1 NaN
246 247 1172.3 683.6 NaN
247 248 1153.8 798.4 NaN
248 249 1104.8 769.1 NaN
249 250 1149.9 496.1 NaN

250 rows × 4 columns

POT_vehicle
PT_V_20_1
Index Effect Value Time Position on Bridge No. Trucks Trucks
0 1 1 110.7 43.2 6.98 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
1 1 2 110.7 43.2 6.98 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
2 2 1 138.3 159.0 15.15 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
3 2 2 138.3 159.0 15.15 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4 3 1 44.8 317.3 6.95 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
... ... ... ... ... ... ... ...
746233 3117 2 137.8 21599915.0 13.79 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff2...
746234 3118 1 18.6 21599915.7 30.66 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff2...
746235 3118 2 18.6 21599915.7 30.66 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff2...
746236 3119 1 134.2 21599929.9 14.15 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff2...
746237 3119 2 134.2 21599929.9 14.15 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff2...

746238 rows × 7 columns

PT_V_20_2
Index Effect Value Time Position on Bridge No. Trucks Trucks
0 1 1 1080.3 20293.1 19.04 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
1 1 2 1080.3 20293.1 19.04 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
2 2 1 1041.5 65173.9 21.38 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
3 2 2 1041.5 65173.9 21.38 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
4 3 1 1086.1 73798.3 -1.64 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bfef...
... ... ... ... ... ... ... ...
4103 15 2 1106.4 21552703.8 22.88 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4104 16 1 1149.9 21553543.3 21.75 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4105 16 2 1149.9 21553543.3 21.75 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4106 17 1 1055.9 21553904.3 0.80 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...
4107 17 2 1055.9 21553904.3 0.80 1 [<pybtls.lib.libbtls.Vehicle object at 0x7bff5...

4108 rows × 7 columns

POT_summary
PT_S_20_Eff_2
Peak Index Time No. Trucks Peak Value
0 1 20293.1 1 1080.3
1 2 65173.9 1 1041.5
2 3 73798.3 1 1086.1
3 4 78477.0 1 1011.3
4 5 91504.3 1 1042.8
... ... ... ... ...
2049 13 21542593.7 1 1114.8
2050 14 21552315.9 1 1000.9
2051 15 21552703.8 1 1106.4
2052 16 21553543.3 1 1149.9
2053 17 21553904.3 1 1055.9

2054 rows × 4 columns

PT_S_20_Eff_1
Peak Index Time No. Trucks Peak Value
0 1 43.2 1 110.7
1 2 159.0 1 138.3
2 3 317.3 1 44.8
3 4 346.7 1 318.2
4 5 347.4 1 33.5
... ... ... ... ...
373114 3115 21599857.3 1 813.6
373115 3116 21599877.1 1 847.5
373116 3117 21599915.0 1 137.8
373117 3118 21599915.7 1 18.6
373118 3119 21599929.9 1 134.2

373119 rows × 4 columns

POT_counter
PT_C_20
Block Effect 1 Effect 2
0 1 1453 4
1 2 1498 12
2 3 1455 12
3 4 1570 11
4 5 1424 8
... ... ... ...
282 247 1541 4
283 248 1313 6
284 248 198 0
285 249 1497 10
286 250 1424 7

287 rows × 3 columns

fatigue_rainflow
RC_20_1
Amplitude No. Cycles
0 100 1169.5
1 101 1229.5
2 102 1306.0
3 103 1416.0
4 104 1474.5
... ... ...
1101 1357 0.5
1102 1385 0.5
1103 1423 0.5
1104 1471 0.5
1105 1515 0.5

1106 rows × 2 columns

RC_20_2
Amplitude No. Cycles
0 100 1169.5
1 101 1229.5
2 102 1306.0
3 103 1416.0
4 104 1474.5
... ... ...
1101 1357 0.5
1102 1385 0.5
1103 1423 0.5
1104 1471 0.5
1105 1515 0.5

1106 rows × 2 columns

The simulation output can be saved and loaded for further analysis.

[ ]:
pb.save_output(sim_output, Path("./temp") / "output.pkl")
sim_output = pb.load_output(Path("./temp") / "output.pkl")
Outputs have been successfully loaded from temp/output.pkl!