Skip to content

Commit

Permalink
removed code from topic branch
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Jun 27, 2024
1 parent 3305877 commit 6e0aa12
Showing 1 changed file with 0 additions and 151 deletions.
151 changes: 0 additions & 151 deletions python/altrios/demos/speed_limit_simple_corr_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,154 +159,3 @@
plt.tight_layout()
plt.show()

<<<<<<< HEAD
=======

#Downhill Simulation
#last recorded soc value
#singular BEL:
train_config = alt.TrainConfig(
cars_empty=Num_car_empty,
cars_loaded=Num_car_loaded,
rail_vehicle_type="Unit",
train_type=None,
train_length_meters=None,
train_mass_kilograms=None,
)
if num_BEL != 0:
uphill_soc = loco0.res.state.soc

# manually update soc value
alt.set_param_from_path(
#item, parameter to be changed, modified value
bel, "res.state.soc", uphill_soc
)
loco_vec = [bel.clone()] * num_BEL + [alt.Locomotive.default()] * num_diesel
# instantiate consist
loco_con = alt.Consist(
loco_vec
)

tsb = alt.TrainSimBuilder(
train_id="0",
origin_id="B",
destination_id="A",
train_config=train_config,
loco_con=loco_con,
)


network = alt.Network.from_file(
alt.resources_root() / network_file_name)
#Multiple BELs:
#for loco in range(len(loco_vec)):


location_map = alt.import_locations(alt.resources_root() / "networks/simple_corridor_locations_new_format.csv")
train_sim_down: alt.SetSpeedTrainSim = tsb.make_speed_limit_train_sim(
rail_vehicle=rail_vehicle,
location_map=location_map,
save_interval=1,
)
train_sim_down.set_save_interval(SAVE_INTERVAL)
est_time_net, _consist = alt.make_est_times(train_sim_down, network)

timed_link_path = alt.run_dispatch(
network,
alt.SpeedLimitTrainSimVec([train_sim_down]),
[est_time_net],
False,
False,
)[0]

t0 = time.perf_counter()
train_sim_down.walk_timed_path(
network=network,
timed_path=timed_link_path,
)
t1 = time.perf_counter()
print(f'Time to simulate: {t1 - t0:.5g}')
assert len(train_sim_down.history) > 1

# pull out solved locomotive for plotting convenience
if num_BEL != 0:
loco_down:alt.Locomotive = train_sim_down.loco_con.loco_vec.tolist()[0]
print("second leg battery usage: ",loco_down.res.state.energy_out_electrical_joules/(3.6*10**9) * num_BEL, " MWh")
print("second leg battery usage from `loco_vec`: ", np.sum([
0. if loco.res == None else loco.res.state.energy_out_electrical_joules for loco in train_sim_down.loco_con.loco_vec.tolist()
]) / (3.6*10**9), " MWh")

if num_diesel != 0:
diesel_loco_down:alt.Locomotive = train_sim_down.loco_con.loco_vec.tolist()[-1]
print("second leg diesel usage: ",train_sim_down.get_energy_fuel_joules(False)/(3.6*10**9), " MWh")
print("second leg diesel usage from `loco_vec`: ", np.sum([
0. if loco.fc == None else loco.fc.state.energy_fuel_joules for loco in train_sim_down.loco_con.loco_vec.tolist()
]) / (3.6*10**9), " MWh")

fig, ax = plt.subplots(4, 1, sharex=True)
ax[0].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(train_sim_down.history.pwr_whl_out_watts) / 1e6,
label="tract pwr",
)
ax[0].set_ylabel('Power [MW]')
ax[0].legend()

ax[1].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(train_sim_down.history.res_aero_newtons) / 1e3,
label='aero',
)
ax[1].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(train_sim_down.history.res_rolling_newtons) / 1e3,
label='rolling',
)
ax[1].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(train_sim_down.history.res_curve_newtons) / 1e3,
label='curve',
)
ax[1].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(train_sim_down.history.res_bearing_newtons) / 1e3,
label='bearing',
)
ax[1].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(train_sim_down.history.res_grade_newtons) / 1e3,
label='grade',
)
ax[1].set_ylabel('Force [MN]')
ax[1].legend()
if num_BEL != 0:
ax[2].plot(
np.array(train_sim_down.history.offset_back_meters),
np.array(loco_down.res.history.soc)
)

ax[2].set_ylabel('SOC')
ax[2].legend()

ax[-1].plot(
np.array(train_sim_down.history.offset_back_meters),
train_sim_down.history.speed_meters_per_second,
label='achieved'
)
ax[-1].plot(
np.array(train_sim_down.history.offset_back_meters),
train_sim_down.history.speed_limit_meters_per_second,
label='limit'
)
ax[-1].set_xlabel('Distance (m)')
ax[-1].set_ylabel('Speed [m/s]')
ax[-1].legend()
plt.suptitle(code_name + " Train Sim Demo")
if SHOW_PLOTS:
plt.tight_layout()
plt.show()


print(train_sim_down.state.mass_adj_kilograms/907.185)
>>>>>>> 426aec0f (energy calcs robust to loco_vec length)
# %%

0 comments on commit 6e0aa12

Please sign in to comment.