Skip to content

Commit

Permalink
#1788 add experiment drive cycles example
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Nov 9, 2021
1 parent c8630d8 commit 855b972
Showing 1 changed file with 45 additions and 40 deletions.
85 changes: 45 additions & 40 deletions examples/scripts/experiment_drive_cycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Constant-current constant-voltage charge with US06 Drive Cycle using Experiment Class.
#
import pybamm
import numpy as np
import pandas as pd
import os

Expand All @@ -10,15 +11,16 @@
pybamm.set_logging_level("INFO")

# import drive cycle from file
drive_cycle_current = pd.read_csv("pybamm/input/drive_cycles/US06.csv",
comment="#",
header=None).to_numpy()
drive_cycle_current = pd.read_csv(
"pybamm/input/drive_cycles/US06.csv", comment="#", header=None
).to_numpy()


# Map Drive Cycle
def Map_Drive_Cycle(x, min_ip_value, max_ip_value, min_op_value, max_op_value):
return (x - min_ip_value) * (max_op_value - min_op_value) / (
max_ip_value - min_ip_value) + min_op_value
max_ip_value - min_ip_value
) + min_op_value


# Map Current to Voltage
Expand All @@ -30,12 +32,13 @@ def Map_Drive_Cycle(x, min_ip_value, max_ip_value, min_op_value, max_op_value):
for I in drive_cycle_current[:, 1]:
temp_volts = np.append(
temp_volts,
Map_Drive_Cycle(I, min_ip_value, max_ip_value, min_Voltage,
max_Voltage))
Map_Drive_Cycle(I, min_ip_value, max_ip_value, min_Voltage, max_Voltage),
)

drive_cycle_voltage = drive_cycle_current
drive_cycle_voltage = np.column_stack((np.delete(drive_cycle_voltage, 1,
1), np.array(temp_volts)))
drive_cycle_voltage = np.column_stack(
(np.delete(drive_cycle_voltage, 1, 1), np.array(temp_volts))
)

# Map Current to Power
temp_volts = np.array([])
Expand All @@ -45,42 +48,44 @@ def Map_Drive_Cycle(x, min_ip_value, max_ip_value, min_op_value, max_op_value):
max_Power = 5.5
for I in drive_cycle_current[:, 1]:
temp_volts = np.append(
temp_volts,
Map_Drive_Cycle(I, min_ip_value, max_ip_value, min_Power, max_Power))
temp_volts, Map_Drive_Cycle(I, min_ip_value, max_ip_value, min_Power, max_Power)
)

drive_cycle_power = drive_cycle_current
drive_cycle_power = np.column_stack((np.delete(drive_cycle_power, 1,
1), np.array(temp_volts)))
experiment = pybamm.Experiment([
# "Charge at 1 A until 4.1 V",
# "Hold at 4.1 V until 50 mA",
# "Rest for 1 hour",
"Run US06_A (A),
# "Rest for 1 hour",
]
# + [
# "Charge at 1 A until 4.1 V",
# "Hold at 4.1 V until 50 mA",
# "Rest for 1 hour",
# "Run US06_V (V)",
# "Rest for 1 hour",
# ] + [
# "Charge at 1 A until 4.1 V",
# "Hold at 4.1 V until 50 mA",
# "Rest for 1 hour",
# "Run US06_W (W)",
# "Rest for 1 hour",
# ]
,drive_cycles={
"US06_A": drive_cycle_current,
"US06_V": drive_cycle_voltage,
"US06_W": drive_cycle_power,
})
drive_cycle_power = np.column_stack(
(np.delete(drive_cycle_power, 1, 1), np.array(temp_volts))
)
experiment = pybamm.Experiment(
[
"Charge at 1 A until 4.1 V",
"Hold at 4.1 V until 50 mA",
"Rest for 1 hour",
"Run US06_A (A)",
"Rest for 1 hour",
]
# + [
# "Charge at 1 A until 4.1 V",
# "Hold at 4.1 V until 50 mA",
# "Rest for 1 hour",
# "Run US06_V (V)",
# "Rest for 1 hour",
# ]
+ [
# "Charge at 1 A until 4.1 V",
# "Hold at 4.1 V until 50 mA",
# "Rest for 1 hour",
"Run US06_W (W)",
"Rest for 1 hour",
],
drive_cycles={
"US06_A": drive_cycle_current,
"US06_V": drive_cycle_voltage,
"US06_W": drive_cycle_power,
},
)

model = pybamm.lithium_ion.DFN()
sim = pybamm.Simulation(model,
experiment=experiment,
solver=pybamm.CasadiSolver())
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.CasadiSolver())
sim.solve()

# Show all plots
Expand Down

0 comments on commit 855b972

Please sign in to comment.