def test_liion_dc_connected_dc_sizing(): model = batt.default("GenericBatteryCommercial") model.BatteryCell.batt_chem = 1 model.Inverter.inverter_model = 0 model.Inverter.inv_snl_eff_cec = 50 model.BatterySystem.batt_ac_or_dc = 0 BatteryTools.battery_model_sizing(model, 100, 400, 500) assert (model.BatterySystem.batt_computed_bank_capacity == pytest.approx( 400, 1)) assert (model.BatterySystem.batt_power_discharge_max_kwdc == pytest.approx( 100, 1)) assert (model.BatterySystem.batt_power_charge_max_kwdc == pytest.approx( 100, 1)) assert (model.BatterySystem.batt_power_discharge_max_kwac == pytest.approx( 49, 1)) assert (model.BatterySystem.batt_power_charge_max_kwac == pytest.approx( 204, 1)) assert (model.BatterySystem.batt_current_discharge_max == pytest.approx( 200, 1)) assert (model.BatterySystem.batt_current_charge_max == pytest.approx( 200, 1)) model.Inverter.inv_snl_eff_cec = 100 model.BatterySystem.batt_ac_or_dc = 0 BatteryTools.battery_model_sizing(model, 100, 400, 500) assert (model.BatterySystem.batt_computed_bank_capacity == pytest.approx( 400, 1)) assert (model.BatterySystem.batt_power_discharge_max_kwdc == pytest.approx( 100, 1)) assert (model.BatterySystem.batt_power_charge_max_kwdc == pytest.approx( 100, 1)) assert (model.BatterySystem.batt_power_discharge_max_kwac == pytest.approx( 98, 1)) assert (model.BatterySystem.batt_power_charge_max_kwac == pytest.approx( 102, 1))
def test_reopt_sizing_pvsam(solar_resource): import PySAM.Utilityrate5 as ur sys = pvsam.default("FlatPlatePVCommercial") fin = ur.from_existing(sys, "FlatPlatePVCommercial") bt = stbt.from_existing(sys, "GenericBatteryCommercial") sys.SolarResource.solar_resource_file = solar_resource bt.Load.crit_load = [0] * 8760 post = sys.Reopt_size_battery_post() assert('Scenario' in post['reopt_post']) assert(post['reopt_post']['Scenario']['Site']['latitude'] == pytest.approx(33.6, 0.1))
def test_leadacid(): model = batt.default("GenericBatteryCommercial") model.BatteryCell.batt_chem = 0 assert (model.BatterySystem.batt_computed_bank_capacity != pytest.approx( 100, .5)) assert (model.BatterySystem.batt_power_charge_max_kwdc != pytest.approx( 50, 0.5)) BatteryTools.battery_model_sizing(model, 100, 400, 500) assert (model.BatterySystem.batt_computed_strings == 261) assert (model.BatterySystem.batt_computed_series == 139) assert (model.BatterySystem.batt_computed_bank_capacity == pytest.approx( 417, 1)) assert (model.BatterySystem.batt_power_charge_max_kwdc == pytest.approx( 96.29, 1))
def test_liion_ac_connected_ac_sizing(): model = batt.default("GenericBatteryCommercial") model.BatteryCell.batt_chem = 1 model.BatterySystem.batt_ac_or_dc = 1 # ac BatteryTools.battery_model_sizing(model, 100, 400, 500) assert (model.BatterySystem.batt_computed_bank_capacity == pytest.approx( 417, 1)) assert (model.BatterySystem.batt_power_discharge_max_kwdc == pytest.approx( 104, 1)) assert (model.BatterySystem.batt_power_charge_max_kwdc == pytest.approx( 96, 1)) assert (model.BatterySystem.batt_power_discharge_max_kwac == pytest.approx( 100, 1)) assert (model.BatterySystem.batt_power_charge_max_kwac == pytest.approx( 100, 1)) assert (model.BatterySystem.batt_current_discharge_max == pytest.approx( 208, 1)) assert (model.BatterySystem.batt_current_charge_max == pytest.approx( 192, 1))
def test_battery_model_change_chemistry(): model = batt.default("GenericBatterySingleOwner") original_capacity = model.value('batt_computed_bank_capacity') original_power = model.BatterySystem.batt_power_discharge_max_kwac BatteryTools.battery_model_change_chemistry(model, 'leadacid') params_new = battstfl.default('leadacid').export() cell_params = params_new['ParamsCell'] pack_params = params_new['ParamsPack'] assert (model.value('batt_computed_bank_capacity') == pytest.approx( original_capacity, 0.1)) assert (model.value('batt_power_discharge_max_kwac') == pytest.approx( original_power, 0.1)) assert (model.BatteryCell.batt_chem == cell_params['chem']) assert (model.BatteryCell.batt_calendar_choice == cell_params['calendar_choice']) assert (model.BatteryCell.batt_Vnom_default == cell_params['Vnom_default']) assert ( model.BatteryCell.LeadAcid_q10_computed == cell_params['leadacid_q10']) assert (model.BatteryCell.batt_Cp == pack_params['Cp']) BatteryTools.battery_model_change_chemistry(model, 'nmcgraphite') params_new = battstfl.default('nmcgraphite').export() cell_params = params_new['ParamsCell'] pack_params = params_new['ParamsPack'] assert (model.value('batt_computed_bank_capacity') == pytest.approx( original_capacity, 0.1)) assert (model.value('batt_power_discharge_max_kwac') == pytest.approx( original_power, 0.1)) assert (model.BatteryCell.batt_C_rate == cell_params['C_rate']) assert (model.BatteryCell.batt_calendar_choice == cell_params['calendar_choice']) assert (model.BatteryCell.batt_Vexp == cell_params['Vexp']) assert (model.BatteryCell.batt_Cp == pack_params['Cp'])
@author: brtietz """ import PySAM.Battery as battery_model import PySAM.Pvsamv1 as pvsam from PySAM.PySSC import * weather_file = sys.argv[1] # .csv weather file with tmy format analysis_period = 1 # years days_in_year = 365 # Create the detailed residential pv model using PySAM's defaults system_model = pvsam.default("FlatPlatePVResidential") # Create the battery model based on the PV defaults battery = battery_model.from_existing(system_model, "GenericBatteryResidential") # Default model does not include a weather file, so set that based on the command line path system_model.SolarResource.solar_resource_file = weather_file # 24 hours of dispatch data, duplicated for each day. Would need to extend daily_dispatch for subhourly lifetime_dispatch = [] daily_dispatch = [ 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, -2, -1, 0, 0, 0, 0, 2, 4, 2, 2, 0, 0, 0 ] # kW, negative is charging # Extend daily lists for entire analysis period for i in range(0, days_in_year * analysis_period): lifetime_dispatch.extend(daily_dispatch) # Change from default dispatch to custom dispatch
Additional financial models, inputs, and outputs can be found at https://nrel-pysam.readthedocs.io/en/master/modules/Battery.html Most recently tested against PySAM 2.2.3 @author: brtietz """ import PySAM.Battery as battery_model analysis_period = 1 # years steps_in_year = 8760 # currently hours in year, multiply this for subhourly tests (example * 12 for 5 minute tests) days_in_year = 365 # Create the model using PySAM's defaults battery = battery_model.default("GenericBatterySingleOwner") # Set up inputs needed by the model. battery.BatteryCell.batt_room_temperature_celsius = [20] * (steps_in_year * analysis_period) # degrees C, room temperature. Would normally come from weather file # 24 hours of data to duplicate for the test. Would need to add data here for subhourly lifetime_generation = [] lifetime_dispatch = [] daily_generation = [0, 0, 0, 0, 0, 0, 0, 200, 400, 600, 800, 1000, 1000, 1000, 1000, 800, 600, 400, 200, 0, 0, 0, 0, 0] # kW daily_dispatch = [0, 0, 0, 0, 0, 0, 0, -200, -400, -600, -800, -1000, -1000, 0, 0, 200, 400, 600, 800, 1000, 1000, 0, 0, 0] # kW, negative is charging # Extend daily lists for entire analysis period for i in range(0, days_in_year * analysis_period): lifetime_generation.extend(daily_generation) lifetime_dispatch.extend(daily_dispatch)