Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
romainsacchi committed Apr 24, 2023
2 parents 0780f68 + 0c10eea commit 3175da9
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 40 deletions.
7 changes: 4 additions & 3 deletions carculator_bus/__init__.py
Expand Up @@ -15,7 +15,7 @@
"BusModel",
"InventoryBus",
"get_driving_cycle",
"get_road_gradient"
"get_road_gradient",
)

# library version
Expand All @@ -25,8 +25,9 @@

DATA_DIR = Path(__file__).resolve().parent / "data"

from carculator_utils.array import fill_xarray_from_input_parameters

from .bus_input_parameters import BusInputParameters
from .driving_cycles import get_driving_cycle, get_road_gradient
from .inventory import InventoryBus
from .model import BusModel
from .driving_cycles import get_driving_cycle, get_road_gradient
from carculator_utils.array import fill_xarray_from_input_parameters
4 changes: 2 additions & 2 deletions carculator_bus/driving_cycles.py
@@ -1,5 +1,5 @@
from carculator_utils import get_standard_driving_cycle_and_gradient
import numpy as np
from carculator_utils import get_standard_driving_cycle_and_gradient


def get_driving_cycle(size: list) -> np.ndarray:
Expand All @@ -15,4 +15,4 @@ def get_road_gradient(size: list) -> np.ndarray:
vehicle_type="bus",
vehicle_sizes=size,
name="bus",
)[1]
)[1]
28 changes: 18 additions & 10 deletions carculator_bus/inventory.py
Expand Up @@ -350,7 +350,6 @@ def fill_in_A_matrix(self):
["BEV-depot", "PHEV-d"],
)


self.A[
np.ix_(
np.arange(self.iterations),
Expand All @@ -359,9 +358,12 @@ def fill_in_A_matrix(self):
contains=("Bus, ", "battery"), excludes=("motion", "opp")
),
)
] = -1 / (
self.array[self.array_inputs["kilometers per year"], :, index] * 2 * 24
).values[:, None]
] = (
-1
/ (
self.array[self.array_inputs["kilometers per year"], :, index] * 2 * 24
).values[:, None]
)

# Opportunity charging BEV buses
# The charging station has a lifetime of 24 years
Expand All @@ -380,9 +382,12 @@ def fill_in_A_matrix(self):
),
self.find_input_indices(contains=("Bus, ", "BEV-opp")),
)
] = -1 / (
self.array[self.array_inputs["kilometers per year"], :, index] * 10 * 24
).values[:, None]
] = (
-1
/ (
self.array[self.array_inputs["kilometers per year"], :, index] * 10 * 24
).values[:, None]
)

# In-motion charging BEV buses
# The overhead lines have a lifetime of 40 years
Expand All @@ -399,8 +404,11 @@ def fill_in_A_matrix(self):
self.find_input_indices(("Overhead lines",)),
self.find_input_indices(contains=("Bus, ", "BEV-motion")),
)
] = -1 / (
self.array[self.array_inputs["lifetime kilometers"], :, index] * 60 * 40
).values[:, None]
] = (
-1
/ (
self.array[self.array_inputs["lifetime kilometers"], :, index] * 60 * 40
).values[:, None]
)

print("*********************************************************************")
97 changes: 75 additions & 22 deletions carculator_bus/model.py
Expand Up @@ -394,7 +394,11 @@ def check_compliance_of_buses(self):

if len(l_size) > 0:
self.array.loc[
dict(powertrain="BEV-motion", parameter="is_available", size=l_size,)
dict(
powertrain="BEV-motion",
parameter="is_available",
size=l_size,
)
] = 0

def adjust_cost(self):
Expand Down Expand Up @@ -448,7 +452,13 @@ def adjust_cost(self):
]

if len(l_pwt) > 0:
self.array.loc[:, l_pwt, "energy battery cost per kWh", :, :,] = np.reshape(
self.array.loc[
:,
l_pwt,
"energy battery cost per kWh",
:,
:,
] = np.reshape(
(2.75e86 * np.exp(-9.61e-2 * self.array.year.values) + 5.059e1)
* cost_factor,
(1, 1, n_year, n_iterations),
Expand All @@ -462,7 +472,13 @@ def adjust_cost(self):
]

if len(l_pwt) > 0:
self.array.loc[:, l_pwt, "power battery cost per kW", :, :,] = np.reshape(
self.array.loc[
:,
l_pwt,
"power battery cost per kW",
:,
:,
] = np.reshape(
(8.337e40 * np.exp(-4.49e-2 * self.array.year.values) + 11.17)
* cost_factor,
(1, 1, n_year, n_iterations),
Expand All @@ -471,7 +487,11 @@ def adjust_cost(self):
# Correction of combustion powertrain cost for ICEV-g
if "ICEV-g" in self.array.powertrain.values:
self.array.loc[
:, ["ICEV-g"], "combustion powertrain cost per kW", :, :,
:,
["ICEV-g"],
"combustion powertrain cost per kW",
:,
:,
] = np.reshape(
(5.92e160 * np.exp(-0.1819 * self.array.year.values) + 26.76)
* cost_factor,
Expand Down Expand Up @@ -541,7 +561,9 @@ def calculate_ttw_energy(self):
"battery heating energy",
"recuperated energy",
]
).sum(dim=["second", "parameter"]).values
)
.sum(dim=["second", "parameter"])
.values
/ distance.values
).T

Expand Down Expand Up @@ -579,7 +601,9 @@ def calculate_ttw_energy(self):
"battery cooling energy",
"battery heating energy",
]
).sum(dim=["parameter", "second"]).values
)
.sum(dim=["parameter", "second"])
.values
/ distance.values
).T

Expand Down Expand Up @@ -734,7 +758,10 @@ def set_trips_properties(self):
# (we omitted the stops in the average)
speed = self.ecm.velocity / 1000 * 3600
speed[speed == 0] = np.nan
self["average speed"] = np.nanmean(speed, axis=0,).T
self["average speed"] = np.nanmean(
speed,
axis=0,
).T
self["daily distance"] = self["operation time"] * self["average speed"]

# the number of trips is simply the daily driven distance
Expand Down Expand Up @@ -799,7 +826,15 @@ def set_energy_stored_properties(self):
)

self.array.loc[dict(powertrain="FCEV", parameter="fuel tank mass")] = (
(-0.1916 * np.power(14.4, 2,)) + (14.586 * 14.4) + 10.805
(
-0.1916
* np.power(
14.4,
2,
)
)
+ (14.586 * 14.4)
+ 10.805
) * nb_cylinder

# for older trolley BEV buses,
Expand Down Expand Up @@ -994,14 +1029,11 @@ def set_energy_stored_properties(self):

self.array.loc[
dict(powertrain="FCEV", parameter="electric energy stored")
] = (
20
+ (
self.array.loc[dict(powertrain="FCEV", parameter="fuel mass")]
* 120
/ 3.6
* 0.06
)
] = 20 + (
self.array.loc[dict(powertrain="FCEV", parameter="fuel mass")]
* 120
/ 3.6
* 0.06
)

self["battery cell mass"] = self["electric energy stored"] / _(
Expand Down Expand Up @@ -1391,7 +1423,13 @@ def calculate_cost_impacts(self, sensitivity=False, scope=None):
dims=["size", "powertrain", "cost_type", "year", "value"],
)

response.loc[:, :, list_cost_cat, :, :,] = self.array.sel(
response.loc[
:,
:,
list_cost_cat,
:,
:,
] = self.array.sel(
powertrain=scope["powertrain"],
size=scope["size"],
year=scope["year"],
Expand Down Expand Up @@ -1420,28 +1458,43 @@ def remove_energy_consumption_from_unavailable_vehicles(self):

pwts = [
pt
for pt in ["BEV-depot", "BEV-opp", "BEV-motion",]
for pt in [
"BEV-depot",
"BEV-opp",
"BEV-motion",
]
if pt in self.array.coords["powertrain"].values
]

years = [y for y in self.array.year.values if y < 2020]

if years:
self.array.loc[
dict(parameter="TtW energy", powertrain=pwts, year=years,)
dict(
parameter="TtW energy",
powertrain=pwts,
year=years,
)
] = 0

# and also coach buses with BEV-opp or BEV-motion powertrain
pwts = [
pt
for pt in ["BEV-opp", "BEV-motion",]
for pt in [
"BEV-opp",
"BEV-motion",
]
if pt in self.array.coords["powertrain"].values
]
sizes = [s for s in self.array.coords["size"].values if "coach" in s.lower()]

if pwts and sizes:
self.array.loc[
dict(parameter="TtW energy", powertrain=pwts, size=sizes,)
dict(
parameter="TtW energy",
powertrain=pwts,
size=sizes,
)
] = 0

# remove double-deck BEV-motion buses
Expand All @@ -1466,4 +1519,4 @@ def remove_energy_consumption_from_unavailable_vehicles(self):
< self["average passengers"] * 1.5,
0,
self["TtW energy"],
)
)
8 changes: 5 additions & 3 deletions dev/mc_time.py
@@ -1,11 +1,13 @@
import pandas as pd

from carculator_bus import *

bip = BusInputParameters()
#bip.stochastic(5)
# bip.stochastic(5)
bip.static()
dcts, array = fill_xarray_from_input_parameters(
bip,
scope={"year":[2020], "size":["9m","18m"], "powertrain":["BEV-motion"]},
scope={"year": [2020], "size": ["9m", "18m"], "powertrain": ["BEV-motion"]},
)
bm = BusModel(array, country="CH")
bm.set_all()
bm.set_all()

0 comments on commit 3175da9

Please sign in to comment.