Beispiel #1
0
def test_batterystateful_model_change_chemistry():
    model = battstfl.default("leadacid")
    original_capacity = model.ParamsPack.nominal_energy

    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('nominal_energy') == pytest.approx(
        original_capacity, 0.1))
    assert (model.ParamsCell.Vnom_default == cell_params['Vnom_default'])
    assert (model.ParamsPack.Cp == pack_params['Cp'])
Beispiel #2
0
def chem_batterystateful(model: BattStfl.BatteryStateful, chem):
    """
    Helper function for battery_model_change_chemistry
    """
    if type(model) != BattStfl.BatteryStateful:
        raise TypeError

    chem = chem.lower()

    if chem != 'LeadAcid' and chem != 'lfpgraphite' and chem != 'nmcgraphite':
        raise NotImplementedError

    if chem == 'leadacid':
        model.ParamsCell.chem = 0
    else:
        model.ParamsCell.chem = 1

    original_capacity = model.ParamsPack.nominal_energy
    original_voltage = model.ParamsPack.nominal_voltage

    params_dict = BattStfl.default(chem).export()

    for group in ('ParamsCell', 'ParamsPack'):
        for k, v in params_dict[group].items():
            model.value(k, v)

    battery_model_sizing(model, -1, original_capacity, original_voltage)
Beispiel #3
0
def test_stateful_from_data():
    b = bt.new()
    d = {'Controls': {'control_mode': 1.0, 'dt_hr': 0.016666666666666666, 'input_power': 0.0},
         'ParamsCell': {'C_rate': 0.2, 'Qexp': 2.584, 'Qfull': 3.2, 'Qnom': 3.126, 'Vexp': 3.53, 'Vfull': 4.2,
                        'Vnom': 3.342, 'Vcut': 0, 'Vnom_default': 3.6, 'life_model': 1, 'chem': 1.0,
                        'cycling_matrix': ((10.0, 0.0, 100.85333333333334), (10.0, 1250.0, 94.88402967051991),
                                           (10.0, 2500.0, 88.91472600735459), (10.0, 3750.0, 82.94542234383735),
                                           (10.0, 5000.0, 76.97611867996821), (20.0, 0.0, 100.85333333333334),
                                           (20.0, 1250.0, 94.87983534903533), (20.0, 2500.0, 88.90633717426442),
                                           (20.0, 3750.0, 82.93283880899575), (20.0, 5000.0, 76.95934025320447),
                                           (40.0, 0.0, 100.85333333333334), (40.0, 1250.0, 94.78221121806645),
                                           (40.0, 2500.0, 88.71098572007159), (40.0, 3750.0, 82.63965652437861),
                                           (40.0, 5000.0, 76.56822331441485), (80.0, 0.0, 100.85333333333334),
                                           (80.0, 1250.0, 92.48380979037378), (80.0, 2500.0, 84.0542799046757),
                                           (80.0, 3750.0, 75.5600050138485), (80.0, 5000.0, 66.99558786034476),
                                           (100.0, 0.0, 100.85333333333334), (100.0, 1250.0, 88.12558851005116),
                                           (100.0, 2500.0, 74.87324171194942), (100.0, 3750.0, 60.95107257220129),
                                           (100.0, 5000.0, 46.13117125424217)), 'initial_SOC': 50.0,
                        'maximum_SOC': 90.0, 'minimum_SOC': 10.0, 'resistance': 0.001155, 'voltage_choice': 0.0},
         'ParamsPack': {'Cp': 1500.0, 'T_room_init': 12.717792686395654,
                        'cap_vs_temp': ((0.0, 80.2), (23.0, 100.0), (30.0, 103.1), (45.0, 105.4)), 'h': 7.5,
                        'mass': 6470.406178696914, 'nominal_energy': 653.5763816865569, 'nominal_voltage': 500.0,
                        'surface_area': 33.602970087562625}, 'StatePack': {}, 'StateCell': {}}
    dd = dict()
    for gr, vr in d.items():
        for k, v in vr.items():
            dd[k] = v
    b.assign(d)
    b.setup()
    assert b.Controls.control_mode == 1
Beispiel #4
0
    def __init__(self,
                 site: SiteInfo,
                 battery_config: dict,
                 chemistry: str = 'lfpgraphite',
                 system_voltage_volts: float = 500):
        """
        Battery Storage class based on PySAM's BatteryStateful Model

        :param site: Power source site information (SiteInfo object)
        :param battery_config: Battery configuration with the following keys:

            #. ``system_capacity_kwh``: float, Battery energy capacity [kWh]
            #. ``system_capacity_kw``: float, Battery rated power capacity [kW]

        :param chemistry: Battery storage chemistry, options include:

            #. ``LFPGraphite``: Lithium Iron Phosphate (Lithium Ion)
            #. ``LMOLTO``: LMO/Lithium Titanate (Lithium Ion)
            #. ``LeadAcid``: Lead Acid
            #. ``NMCGraphite``: Nickel Manganese Cobalt Oxide (Lithium Ion)

        :param system_voltage_volts: Battery system voltage [VDC]
        """
        for key in ('system_capacity_kwh', 'system_capacity_kw'):
            if key not in battery_config.keys():
                raise ValueError

        system_model = BatteryModel.default(chemistry)
        financial_model = Singleowner.from_existing(system_model, "StandaloneBatterySingleOwner")
        super().__init__("Battery", site, system_model, financial_model)

        self.Outputs = BatteryOutputs(n_timesteps=site.n_timesteps)
        self.system_capacity_kw: float = battery_config['system_capacity_kw']
        self.chemistry = chemistry
        BatteryTools.battery_model_sizing(self._system_model,
                                          battery_config['system_capacity_kw'],
                                          battery_config['system_capacity_kwh'],
                                          system_voltage_volts,
                                          module_specs=Battery.module_specs)
        self._system_model.ParamsPack.h = 20
        self._system_model.ParamsPack.Cp = 900
        self._system_model.ParamsCell.resistance = 0.001
        self._system_model.ParamsCell.C_rate = battery_config['system_capacity_kw'] / battery_config['system_capacity_kwh']

        # Minimum set of parameters to set to get statefulBattery to work
        self._system_model.value("control_mode", 0.0)
        self._system_model.value("input_current", 0.0)
        self._system_model.value("dt_hr", 1.0)
        self._system_model.value("minimum_SOC", 10.0)
        self._system_model.value("maximum_SOC", 90.0)
        self._system_model.value("initial_SOC", 10.0)

        self._dispatch = None

        logger.info("Initialized battery with parameters and state {}".format(self._system_model.export()))
Beispiel #5
0
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'])
Beispiel #6
0
def test_stateful():
    b = bt.default("NMCGraphite")
    b.Controls.control_mode = 1
    b.Controls.dt_hr = 1
    b.ParamsCell.minimum_SOC = 10
    b.ParamsCell.maximum_SOC = 90
    b.ParamsCell.initial_SOC = 50
    b.Controls.input_power = 0
    b.setup()
    assert (b.StatePack.SOC == approx(50))

    b.Controls.input_power = 0.5
    b.execute(0)
    assert (b.StatePack.SOC == approx(44.811, 1e-2))
Beispiel #7
0
def test_stateful_lmolto():
    b = bt.default("LMOLTO")
    b.Controls.control_mode = 1
    b.Controls.dt_hr = 1
    b.ParamsCell.minimum_SOC = 10
    b.ParamsCell.maximum_SOC = 90
    b.ParamsCell.initial_SOC = 50
    b.Controls.input_power = 0
    b.setup()
    assert (b.StatePack.SOC == approx(50))

    b.Controls.input_power = 0.5
    b.execute(0)
    assert (b.StatePack.SOC == approx(45.216, 1e-2))
Beispiel #8
0
def chem_battery(model: Batt.Battery, chem):
    """
    Helper function for battery_model_change_chemistry
    """
    if type(model) != Batt.Battery:
        raise TypeError

    chem = chem.lower()

    if chem != 'leadacid' and chem != 'lfpgraphite' and chem != 'nmcgraphite':
        raise NotImplementedError

    if chem == 'leadacid':
        model.BatteryCell.batt_chem = 0
    else:
        model.BatteryCell.batt_chem = 1

    original_capacity = model.value('batt_computed_bank_capacity')
    original_voltage = model.BatteryCell.batt_Vnom_default * model.BatterySystem.batt_computed_series
    if model.BatterySystem.batt_ac_or_dc:
        original_power = model.BatterySystem.batt_power_discharge_max_kwac
    else:
        original_power = model.BatterySystem.batt_power_discharge_max_kwdc

    params_dict = BattStfl.default(chem).export()

    for group in ('ParamsCell', 'ParamsPack'):
        for k, v in params_dict[group].items():
            if k == 'nominal_voltage' or k == "T_room_init":
                continue
            elif k == 'cycling_matrix':
                k = 'batt_lifetime_matrix'
            elif 'leadacid' in k:
                k = 'LeadAcid' + k[8:]
                if 'tn' not in k:
                    k += '_computed'
            elif k == 'h':
                k = 'batt_h_to_ambient'
            elif k == 'nominal_energy':
                k = 'batt_computed_bank_capacity'
            elif k == 'cap_vs_temp':
                pass
            else:
                k = 'batt_' + k

            model.value(k, v)

    battery_model_sizing(model, original_power, original_capacity,
                         original_voltage)
Beispiel #9
0
def test_stateful():
    import PySAM.BatteryStateful as bt
    import PySAM.BatteryTools as BatteryTools

    b = bt.new()

    params = {"control_mode": 1, "input_current": 1, "input_power": 1, 
                "chem": 1, "nominal_energy": 10, "nominal_voltage": 500,
              "initial_SOC": 50.000, "maximum_SOC": 95.000, "minimum_SOC": 5.000, "dt_hr": 1.000, "leadacid_tn": 0.000,
              "leadacid_qn": 0.000, "leadacid_q10": 0.000, "leadacid_q20": 0.000, "voltage_choice": 0,
              "Vnom_default": 3.600, "resistance": 0.0001, "Vfull": 4.100, "Vexp": 4.050, "Vnom": 3.400, "Qfull": 2.250,
              "Qexp": 0.040, "Qnom": 2.000, "C_rate": 0.200, "mass": 507.000, "surface_area": 2.018, "Cp": 1004.000,
              "h": 5.000, "cap_vs_temp": [[-10, 60], [0, 80], [25, 1E+2], [40, 1E+2]], "T_room_init": 20,
              "cycling_matrix": [[20, 0, 1E+2], [20, 5E+3, 80], [20, 1E+4, 60], [80, 0, 1E+2], [80, 1E+3, 80],
                                 [80, 2E+3, 60]], "calendar_choice": 1, "calendar_q0": 1.020, "calendar_a": 0.003,
              "calendar_b": -7280.000, "calendar_c": 930.000, "calendar_matrix": [[-3.1E+231]], "loss_choice": 0,
              "monthly_charge_loss": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
              "monthly_discharge_loss": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
              "monthly_idle_loss": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], "schedule_loss": [], "replacement_option": 0,
              "replacement_capacity": 0.000, "replacement_schedule": [], "replacement_schedule_percent": []}

    for k, v in params.items():
        b.value(k, v)

    b.setup()
    b.execute()
    if params['control_mode'] == 0.0:
        b.value("input_current", -4.0)
    else:
        b.value("input_power", -4.0)
    b.execute()
    b.execute()
    if params['control_mode'] == 0.0:
        b.value("input_current", 4.0)
    else:
        b.value("input_power", 4.0)
    b.execute()
    b.execute()

    b.setup()
    b.execute()
    print(b.StatePack.export())
    b.execute()
    print(b.StatePack.export())