Skip to content

Commit

Permalink
Merge branch 'patch' into SAM_1515
Browse files Browse the repository at this point in the history
  • Loading branch information
sjanzou committed Feb 28, 2024
2 parents eecfab6 + 8bf82bf commit e3e9b80
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 5 deletions.
5 changes: 4 additions & 1 deletion shared/lib_battery_powerflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "lib_power_electronics.h"
#include "lib_shared_inverter.h"

// 0.005 W when applied to power. Some inverters have a night time loss of 0.01 W
double powerflow_tolerance = 0.000005;

BatteryPower::BatteryPower(double dtHour) :
dtHour(dtHour),
powerSystem(0),
Expand Down Expand Up @@ -102,7 +105,7 @@ BatteryPower::BatteryPower(double dtHour) :
depthOfDischargeMax(1),
currentChargeMax(0),
currentDischargeMax(0),
tolerance(0.001){}
tolerance(powerflow_tolerance){}

BatteryPower::BatteryPower(const BatteryPower& orig) {
sharedInverter = orig.sharedInverter;
Expand Down
3 changes: 3 additions & 0 deletions shared/lib_battery_powerflow.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class SharedInverter;

struct BatteryPower;

// Allow for consistent power tolerances between the technology code and utility rate code
extern double powerflow_tolerance;

/**
* \class BatteryPowerFlow
*
Expand Down
1 change: 1 addition & 0 deletions shared/lib_pvshade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ void diffuse_reduce(

// sky diffuse reduction
Fskydiff = skydiffderates.lookup(stilt);
Fskydiff = fmin(Fskydiff, 1.0);
reduced_skydiff = Fskydiff * poa_sky;

double solalt = 90 - solzen;
Expand Down
2 changes: 1 addition & 1 deletion shared/lib_utility_rate_equations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,7 @@ void forecast_setup::setup(rate_data* rate, std::vector<double>& P_pv_ac, std::v
}

if (rate->dc_enabled) {
int dc_tou_period = rate->get_dc_tou_row(hour_of_year + step, curr_month - 1);
int dc_tou_period = rate->get_dc_tou_row(idx, curr_month - 1);
size_t month_idx = year * 12 + (curr_month - 1);
double peak = monthly_peaks.at(month_idx, dc_tou_period) - peak_offset; // Peak for dispatch calcs in battery: peak minus battery capacity
if (-1.0 * grid_power > peak) {
Expand Down
6 changes: 5 additions & 1 deletion ssc/cmod_utilityrate5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,10 @@ class cm_utilityrate5 : public compute_module
dc_tou_sched[ii] = (ssc_number_t)rate.m_dc_tou_sched[ii];
load[ii] = -e_load_cy[ii];
e_tofromgrid[ii] = e_grid_cy[ii];

if (fabs(e_tofromgrid[ii]) < powerflow_tolerance) { // powerflow_tolerance is defined globally in shared/lib_battery_powerflow.h, set to 0.000005 (Watts or Watt-hrs)
e_tofromgrid[ii] = 0.0;
}
if (e_tofromgrid[ii] > 0)
{
year1_hourly_e_togrid[ii] = e_tofromgrid[ii];
Expand All @@ -1430,7 +1434,7 @@ class cm_utilityrate5 : public compute_module
year1_hourly_e_togrid[ii] = 0.0;
year1_hourly_e_fromgrid[ii] = -e_tofromgrid[ii];
}
p_tofromgrid[ii] = p_grid_cy[ii];
p_tofromgrid[ii] = fabs(p_grid_cy[ii]) > powerflow_tolerance ? p_grid_cy[ii] : 0.0;
salespurchases[ii] = revenue_w_sys[ii];
}
assign("year1_hourly_ec_tou_schedule", var_data(&ec_tou_sched[0], (int)m_num_rec_yearly));
Expand Down
2 changes: 1 addition & 1 deletion ssc/common_financial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3338,7 +3338,7 @@ var_info vtab_lcos_inputs[] = {
{ SSC_INPUT, SSC_MATRIX, "net_billing_credits_ym", "Net billing credit", "$", "", "Charges by Month", "", "", "COL_LABEL=MONTHS,FORMAT_SPEC=CURRENCY,GROUP=UR_AM" },

// fix for running financial compute modules tests
{ SSC_INOUT, SSC_ARRAY, "gen_purchases", "Electricity from grid", "kW", "", "System Output", "", "", "" },
{ SSC_INOUT, SSC_ARRAY, "gen_purchases", "Electricity from grid to system", "kW", "", "System Output", "", "", "" },
{ SSC_INPUT, SSC_ARRAY, "rate_escalation", "Annual electricity rate escalation", "%/year", "", "Electricity Rates", "", "", "" },


Expand Down
139 changes: 139 additions & 0 deletions test/shared_test/lib_utility_rate_equations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -714,3 +714,142 @@ TEST(lib_utility_rate_equations_test, test_billing_demand_calcs_w_tou)

ASSERT_NEAR(16674.22, data.get_demand_charge(0, 0), 0.01);
}

TEST(lib_utility_rate_equations_test, test_demand_hourly_tou_charges)
{
ssc_number_t p_ur_ec_sched_weekday[288] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2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, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
ssc_number_t p_ur_ec_tou_mat[24] = { 1, 1, 9.9999999999999998e+37, 0, 0.050000000000000003, 0,
2, 1, 9.9999999999999998e+37, 0, 0.074999999999999997, 0,
3, 1, 9.9999999999999998e+37, 0, 0.059999999999999998, 0,
4, 1, 9.9999999999999998e+37, 0, 0.050000000000000003, 0 };
size_t tou_rows = 4;
bool sell_eq_buy = false;

// Schedyles don't have period 1 in March
ssc_number_t p_ur_dc_sched_weekday[288] = { 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 3, 3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, 4, 4 };
ssc_number_t p_ur_dc_tou_mat[20] = { 1, 1, 9.9999996802856925e+37, 3.3640100955963135,
2, 1, 9.9999996802856925e+37, 0.8336300253868103,
3, 1, 9.9999996802856925e+37, 0.1803400069475174,
4, 1, 9.9999996802856925e+37, 0.012780000455677509,
5, 1, 9.9999996802856925e+37, 0 };

size_t dc_tou_rows = 5;
// Also test incomplete flat mat
ssc_number_t p_ur_dc_flat_mat[8] = { 0, 1, 9.9999999999999998e+37, 0, 1, 1, 9.9999996802856925e+37, 0 };


/*
ssc_number_t p_ur_dc_flat_mat[48] = { 0, 1, 9.9999999999999998e+37, 0,
1, 1, 9.9999999999999998e+37, 0,
2, 1, 9.9999999999999998e+37, 0,
3, 1, 9.9999999999999998e+37, 0,
4, 1, 9.9999999999999998e+37, 0,
5, 1, 9.9999999999999998e+37, 0,
6, 1, 9.9999999999999998e+37, 0,
7, 1, 9.9999999999999998e+37, 0,
8, 1, 9.9999999999999998e+37, 0,
9, 1, 9.9999999999999998e+37, 0,
10, 1, 9.9999999999999998e+37, 0,
11, 1, 9.9999999999999998e+37, 0 };
*/
size_t dc_flat_rows = 2;

rate_data data;
data.m_num_rec_yearly = 8760;
data.rate_scale = { 1 };
data.init(8760);
data.setup_demand_charges(&p_ur_dc_sched_weekday[0], &p_ur_dc_sched_weekend[0], dc_tou_rows, &p_ur_dc_tou_mat[0], dc_flat_rows, &p_ur_dc_flat_mat[0]);
data.setup_energy_rates(&p_ur_ec_sched_weekday[0], &p_ur_ec_sched_weekend[0], tou_rows, &p_ur_ec_tou_mat[0], sell_eq_buy);
data.init_energy_rates_all_months(false);
data.init_dc_peak_vectors(2);

// Peak period 1: 5 kW, peak period 2: 10 kW
std::vector<double> day_one_power = { -1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, -1, -1, -1, -1 };

ASSERT_EQ(24, day_one_power.size());
int step = 1416; // 12 am March 1st
int month = 2;
for (int i = 0; i < day_one_power.size(); i++)
{
// Hourly, so power and energy are the same number
data.sort_energy_to_periods(month, day_one_power.at(i), step + i);
data.find_dc_tou_peak(month, day_one_power.at(i), step + i);
}

ASSERT_NEAR(9.482, data.get_demand_charge(2, 0), 0.01);

// Check whether or not it's safe to call this function twice on the same data
ASSERT_NEAR(9.482, data.get_demand_charge(2, 0), 0.01);
}

TEST(lib_utility_rate_equations_test, test_demand_subhourly_tou_charges)
{
ssc_number_t p_ur_ec_sched_weekday[288] = { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 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 0, 0.050000000000000003, 0,
2, 1, 9.9999999999999998e+37, 0, 0.074999999999999997, 0,
3, 1, 9.9999999999999998e+37, 0, 0.059999999999999998, 0,
4, 1, 9.9999999999999998e+37, 0, 0.050000000000000003, 0 };
size_t tou_rows = 4;
bool sell_eq_buy = false;

// Schedyles don't have period 1 in March
ssc_number_t p_ur_dc_sched_weekday[288] = { 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 2, 2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 3, 4, 4, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 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e+37, 0.1803400069475174,
4, 1, 9.9999996802856925e+37, 0.012780000455677509,
5, 1, 9.9999996802856925e+37, 0 };

size_t dc_tou_rows = 5;
// Also test incomplete flat mat
ssc_number_t p_ur_dc_flat_mat[8] = { 0, 1, 9.9999999999999998e+37, 0, 1, 1, 9.9999996802856925e+37, 0 };


/*
ssc_number_t p_ur_dc_flat_mat[48] = { 0, 1, 9.9999999999999998e+37, 0,
1, 1, 9.9999999999999998e+37, 0,
2, 1, 9.9999999999999998e+37, 0,
3, 1, 9.9999999999999998e+37, 0,
4, 1, 9.9999999999999998e+37, 0,
5, 1, 9.9999999999999998e+37, 0,
6, 1, 9.9999999999999998e+37, 0,
7, 1, 9.9999999999999998e+37, 0,
8, 1, 9.9999999999999998e+37, 0,
9, 1, 9.9999999999999998e+37, 0,
10, 1, 9.9999999999999998e+37, 0,
11, 1, 9.9999999999999998e+37, 0 };
*/
size_t dc_flat_rows = 2;

rate_data data;
data.m_num_rec_yearly = 8760*4;
data.rate_scale = { 1 };
data.init(8760*4);
data.setup_demand_charges(&p_ur_dc_sched_weekday[0], &p_ur_dc_sched_weekend[0], dc_tou_rows, &p_ur_dc_tou_mat[0], dc_flat_rows, &p_ur_dc_flat_mat[0]);
data.setup_energy_rates(&p_ur_ec_sched_weekday[0], &p_ur_ec_sched_weekend[0], tou_rows, &p_ur_ec_tou_mat[0], sell_eq_buy);
data.init_energy_rates_all_months(false);
data.init_dc_peak_vectors(2);

// Peak period 1: 5 kW, peak period 2: 10 kW
std::vector<double> day_one_power = { -1, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, -1, -1, -1, -1 };

ASSERT_EQ(24, day_one_power.size());
int step = 1416 * 4; // 12 am March 1st
int month = 2;
for (int i = 0; i < day_one_power.size(); i++)
{
// Hourly, so power and energy are the same number
data.sort_energy_to_periods(month, day_one_power.at(i), step + i);
data.find_dc_tou_peak(month, day_one_power.at(i), step + i);
}

// Only ran 6 hours of data, so expect different charges
ASSERT_NEAR(0.128, data.get_demand_charge(2, 0), 0.01);

// Check whether or not it's safe to call this function twice on the same data
ASSERT_NEAR(0.128, data.get_demand_charge(2, 0), 0.01);
}
2 changes: 1 addition & 1 deletion test/ssc_test/cmod_battery_pvsamv1_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ TEST_F(CMPvsamv1BatteryIntegration_cmod_pvsamv1, ResidentialACBatteryModelGridOu
ssc_number_t expectedEnergy = 8521.00;
ssc_number_t expectedBatteryChargeEnergy = 3290.77;
ssc_number_t expectedBatteryDischargeEnergy = 2974.91;
ssc_number_t expectedCritLoadUnmet = 485.18;
ssc_number_t expectedCritLoadUnmet = 488.14;

ssc_number_t peakKwCharge = -3.4;
ssc_number_t peakKwDischarge = 1.964;
Expand Down

0 comments on commit e3e9b80

Please sign in to comment.