Skip to content

Commit

Permalink
Add battery charge from grid % metric to outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjprilliman committed Feb 8, 2024
1 parent 120ec1d commit 9a28e68
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/lib_battery_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@ battery_metrics_t::battery_metrics_t(double dt_hour)
_average_efficiency = 100.;
_average_roundtrip_efficiency = 100.;
_pv_charge_percent = 0.;
_grid_charge_percent = 0.;

// annual metrics
_e_charge_from_pv_annual = 0.;
Expand All @@ -938,6 +939,7 @@ battery_metrics_t::battery_metrics_t(double dt_hour)
double battery_metrics_t::average_battery_conversion_efficiency() { return _average_efficiency; }
double battery_metrics_t::average_battery_roundtrip_efficiency() { return _average_roundtrip_efficiency; }
double battery_metrics_t::pv_charge_percent() { return _pv_charge_percent; }
double battery_metrics_t::grid_charge_percent() { return _grid_charge_percent; }
double battery_metrics_t::energy_pv_charge_annual() { return _e_charge_from_pv_annual; }
double battery_metrics_t::energy_grid_charge_annual() { return _e_charge_from_grid_annual; }
double battery_metrics_t::energy_charge_annual() { return _e_charge_annual; }
Expand Down Expand Up @@ -996,6 +998,7 @@ void battery_metrics_t::accumulate_battery_charge_components(double P_tofrom_bat
_average_efficiency = 100. * (_e_discharge_accumulated / _e_charge_accumulated);
_average_roundtrip_efficiency = 100. * (_e_discharge_accumulated / (_e_charge_accumulated + _e_loss_system));
_pv_charge_percent = 100. * (_e_charge_from_pv / _e_charge_accumulated);
_grid_charge_percent = 100. * (_e_charge_from_grid / _e_charge_accumulated);
}
void battery_metrics_t::accumulate_grid_annual(double P_tofrom_grid)
{
Expand Down
2 changes: 2 additions & 0 deletions shared/lib_battery_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ class battery_metrics_t
double average_battery_conversion_efficiency();
double average_battery_roundtrip_efficiency();
double pv_charge_percent();
double grid_charge_percent();

protected:

Expand All @@ -492,6 +493,7 @@ class battery_metrics_t

/*! This is the percentage of energy charge from the PV system [%] */
double _pv_charge_percent;
double _grid_charge_percent;

// annual metrics
double _e_charge_from_pv_annual; // [Kwh]
Expand Down
12 changes: 12 additions & 0 deletions ssc/cmod_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ var_info vtab_battery_outputs[] = {
{ SSC_OUTPUT, SSC_NUMBER, "average_battery_conversion_efficiency", "Battery average cycle conversion efficiency", "%", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "average_battery_roundtrip_efficiency", "Battery average roundtrip efficiency", "%", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "batt_system_charge_percent", "Battery charge energy charged from system", "%", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "batt_grid_charge_percent", "Battery charge energy charged from grid", "%", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "batt_bank_installed_capacity", "Battery bank installed capacity", "kWh", "", "Annual", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "annual_crit_load", "Critical load energy (year 1)", "kWh", "", "Battery", "", "", "" },
{ SSC_OUTPUT, SSC_NUMBER, "annual_crit_load_unmet", "Critical load energy unmet (year 1)", "kWh", "", "Battery", "", "", "" },
Expand Down Expand Up @@ -924,6 +925,7 @@ battstor::battstor(var_table& vt, bool setup_model, size_t nrec, double dt_hr, c
outUnmetLosses = 0;
outAverageCycleEfficiency = 0;
outSystemChargePercent = 0;
outGridChargePercent = 0;
outAnnualSystemChargeEnergy = 0;
outAnnualGridChargeEnergy = 0;
outAnnualChargeEnergy = 0;
Expand Down Expand Up @@ -1729,6 +1731,7 @@ battstor::battstor(const battstor& orig) {
outAverageCycleEfficiency = orig.outAverageCycleEfficiency;
outAverageRoundtripEfficiency = orig.outAverageRoundtripEfficiency;
outSystemChargePercent = orig.outSystemChargePercent;
outGridChargePercent = orig.outGridChargePercent;

// copy models
if (orig.batt_vars) batt_vars = orig.batt_vars;
Expand Down Expand Up @@ -1995,6 +1998,14 @@ void battstor::metrics()
outSystemChargePercent = 100;
else if (outSystemChargePercent < 0)
outSystemChargePercent = 0;

// Grid charge ratio
outGridChargePercent = (ssc_number_t)battery_metrics->grid_charge_percent();
if (outGridChargePercent > 100)
outGridChargePercent = 100;
else if (outGridChargePercent < 0)
outGridChargePercent = 0;

}

// function needed to correctly calculate P_grid due to additional losses in P_gen post battery like wiring, curtailment, availablity
Expand Down Expand Up @@ -2068,6 +2079,7 @@ void battstor::calculate_monthly_and_annual_outputs(compute_module& cm)
cm.assign("average_battery_conversion_efficiency", var_data((ssc_number_t)outAverageCycleEfficiency));
cm.assign("average_battery_roundtrip_efficiency", var_data((ssc_number_t)outAverageRoundtripEfficiency));
cm.assign("batt_system_charge_percent", var_data((ssc_number_t)outSystemChargePercent));
cm.assign("batt_grid_charge_percent", var_data((ssc_number_t)outGridChargePercent));
cm.assign("batt_bank_installed_capacity", (ssc_number_t)batt_vars->batt_kwh);

// monthly outputs
Expand Down
1 change: 1 addition & 0 deletions ssc/cmod_battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ struct battstor
double outAverageCycleEfficiency;
double outAverageRoundtripEfficiency;
double outSystemChargePercent;
double outGridChargePercent;

//output variables for self-consumption dispatch
double outTimestepsLoadMetBySystemYear1;
Expand Down

0 comments on commit 9a28e68

Please sign in to comment.