Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating vehicle_import_demo #89

Merged
merged 5 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/fastsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import fastsimrust
from . import fastsimrust as fsr
from . import parameters as params
from . import utilities as utils
from . import utils
from . import simdrive, vehicle, cycle, calibration, tests
from . import calibration as cal
from .resample import resample
Expand Down
36 changes: 21 additions & 15 deletions python/fastsim/auxiliaries.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
"""Auxiliary functions that require fastsim and provide faster access FASTSim vehicle properties."""
import fastsim as fsim
from fastsim.vehicle import Vehicle
from fastsim import parameters as params
from scipy.optimize import minimize, curve_fit
import numpy as np
import matplotlib.pyplot as plt
from typing import Tuple, List

from fastsim.utilities import get_rho_air
# Local imports
import fastsim as fsim
from fastsim.vehicle import Vehicle
from fastsim import parameters as params
from fastsim.utils import get_rho_air

props = params.PhysicalProperties()
R_air = 287 # J/(kg*K)


def abc_to_drag_coeffs(veh: Vehicle,
a_lbf: float, b_lbf__mph: float, c_lbf__mph2: float,
custom_rho: bool = False,
custom_rho_temp_degC: float = 20.,
custom_rho_elevation_m: float = 180.,
simdrive_optimize: bool = True,
show_plots: bool = False,
use_rust=True) -> Tuple[float, float]:
def abc_to_drag_coeffs(
veh: Vehicle,
a_lbf: float, b_lbf__mph: float, c_lbf__mph2: float,
custom_rho: bool = False,
custom_rho_temp_degC: float = 20.,
custom_rho_elevation_m: float = 180.,
simdrive_optimize: bool = True,
show_plots: bool = False,
use_rust=True
) -> Tuple[float, float]:
"""For a given vehicle and target A, B, and C
coefficients; calculate and return drag and rolling resistance
coefficients.
Expand All @@ -41,13 +44,16 @@ def abc_to_drag_coeffs(veh: Vehicle,
"""

# TODO: allows air density read APIs for whole project; `get_rho_air()` not used for `SimDrive` yet
cur_ambient_air_density_kg__m3 = get_rho_air(
custom_rho_temp_degC, custom_rho_elevation_m) if custom_rho else props.air_density_kg_per_m3

if custom_rho:
cur_ambient_air_density_kg__m3 = get_rho_air(custom_rho_temp_degC, custom_rho_elevation_m)
else:
cur_ambient_air_density_kg__m3 = props.air_density_kg_per_m3

vmax_mph = 70.0

a_newton = a_lbf * params.N_PER_LBF
b_newton__mps = b_lbf__mph * params.N_PER_LBF * params.MPH_PER_MPS
_b_newton__mps = b_lbf__mph * params.N_PER_LBF * params.MPH_PER_MPS
c_newton__mps2 = c_lbf__mph2 * params.N_PER_LBF * \
params.MPH_PER_MPS * params.MPH_PER_MPS

Expand Down
2 changes: 1 addition & 1 deletion python/fastsim/demos/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# local modules
import fastsim as fsim
import fastsim.utilities as utils

# importlib.reload(simdrive) importlib.reload(cycle)

#for testing demo files, false when running automatic tests
Expand Down
1 change: 0 additions & 1 deletion python/fastsim/demos/demo_abc_drag_coef_conv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fastsim as fsim
from fastsim.auxiliaries import abc_to_drag_coeffs, drag_coeffs_to_abc
import fastsim.utilities as utils
v = fsim.vehicle.Vehicle.from_vehdb(1).to_rust()
v2 = fsim.vehicle.Vehicle.from_vehdb(1).to_rust()

Expand Down
2 changes: 1 addition & 1 deletion python/fastsim/demos/demo_eu_vehicle_wltp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import time
import fastsim as fsim
import fastsim.parameters as params
import fastsim.utilities as utils
import fastsim.utils as utils
import matplotlib.pyplot as plt


Expand Down
1 change: 0 additions & 1 deletion python/fastsim/demos/fusion_thermal_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from pathlib import Path
import os
import sys
import fastsim.utilities as utils

#for testing demo files, false when running automatic tests
SHOW_PLOTS = fsim.utils.show_plots()
Expand Down
1 change: 0 additions & 1 deletion python/fastsim/demos/stop_start_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import importlib
import seaborn as sns
import fastsim as fsim
import fastsim.utilities as utils

sns.set()

Expand Down
1 change: 0 additions & 1 deletion python/fastsim/demos/time_dilation_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from fastsim import parameters as params

import fastsim as fsim
import fastsim.utilities as utils

# importlib.reload(simdrive)

Expand Down
25 changes: 0 additions & 25 deletions python/fastsim/demos/utils.py

This file was deleted.

19 changes: 7 additions & 12 deletions python/fastsim/demos/vehicle_import_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import os, pathlib

import fastsim.fastsimrust as fsr
from fastsim.demos.utils import maybe_str_to_bool, DEMO_TEST_ENV_VAR
import fastsim.utils as utils

RAN_SUCCESSFULLY = False
IS_INTERACTIVE = maybe_str_to_bool(os.getenv(DEMO_TEST_ENV_VAR))
#for testing demo files, false when running automatic tests
SHOW_PLOTS = utils.show_plots()

# %%
# Setup some directories
Expand All @@ -33,14 +33,14 @@
# Python pathlib.Path object will be rejected.

options = fsr.get_options_for_year_make_model(year, make, model)
if IS_INTERACTIVE:
if SHOW_PLOTS:
for opt in options:
print(f"{opt.id}: {opt.transmission}")

# %%
# Get the data for the given option
data = options[1]
if IS_INTERACTIVE:
if SHOW_PLOTS:
print(
f"{data.year} {data.make} {data.model}: {data.comb_mpg_fuel1} mpg ({data.city_mpg_fuel1} CITY / {data.highway_mpg_fuel1} HWY)"
)
Expand Down Expand Up @@ -81,11 +81,6 @@
# Python pathlib.Path object will be rejected.

vehs = fsr.import_all_vehicles(int(year), make, model, other_inputs)
if IS_INTERACTIVE:
if SHOW_PLOTS:
for v in vehs:
print(f"Imported {v.scenario_name}")


# %%
# Used for automated testing
RAN_SUCCESSFULLY = True
print(f"Imported {v.scenario_name}")
28 changes: 20 additions & 8 deletions python/fastsim/tests/test_auxiliaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@ def test_abc_to_drag_coeffs(self):
a = 25.91
b = 0.1943
c = 0.01796
drag_coeff, wheel_rr_coef = auxiliaries.abc_to_drag_coeffs(veh=veh,
a_lbf=a,
b_lbf__mph=b,
c_lbf__mph2=c,
custom_rho=False,
simdrive_optimize=True,
show_plots=False,
use_rust=False)
drag_coeff, wheel_rr_coef = auxiliaries.abc_to_drag_coeffs(
veh=veh,
a_lbf=a,
b_lbf__mph=b,
c_lbf__mph2=c,
custom_rho=False,
simdrive_optimize=True,
show_plots=False,
use_rust=False
)
self.assertAlmostEqual(0.29396666380768194, drag_coeff, places=5)
self.assertAlmostEqual(0.00836074507871098, wheel_rr_coef, places=7)
drag_coeff, wheel_rr_coef = auxiliaries.abc_to_drag_coeffs(
veh=veh,
a_lbf=a,
b_lbf__mph=b,
c_lbf__mph2=c,
custom_rho=True,
simdrive_optimize=True,
show_plots=False,
use_rust=False
)

def test_drag_coeffs_to_abc(self):
veh = Vehicle.from_vehdb(1).to_rust()
Expand Down
16 changes: 0 additions & 16 deletions python/fastsim/tests/utils.py

This file was deleted.

1 change: 1 addition & 0 deletions python/fastsim/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .utilities import *
File renamed without changes.
Loading