Skip to content

Commit

Permalink
correct final tests by forcing charging for battwatts resilience tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brtietz committed Oct 19, 2023
1 parent c0ef401 commit b4a069e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
13 changes: 8 additions & 5 deletions ssc/cmod_battwatts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,15 @@ cm_battwatts::cm_battwatts()
add_var_info(vtab_grid_curtailment);
}

std::shared_ptr<batt_variables> cm_battwatts::setup_variables(size_t n_recs)
std::shared_ptr<batt_variables> cm_battwatts::setup_variables(size_t n_recs_lifetime)
{
size_t nyears = 1;
size_t n_recs = n_recs_lifetime;
bool system_use_lifetime_output = as_boolean("system_use_lifetime_output");
if (system_use_lifetime_output)
if (system_use_lifetime_output) {
nyears = (size_t)as_double("analysis_period");
n_recs = n_recs_lifetime / nyears;
}
int chem = as_integer("batt_simple_chemistry");
int pos = as_integer("batt_simple_meter_position");
double kwh = as_number("batt_simple_kwh");
Expand All @@ -313,7 +316,7 @@ std::shared_ptr<batt_variables> cm_battwatts::setup_variables(size_t n_recs)
std::vector<double> dispatch_custom;
if (dispatch == 2){
dispatch_custom = as_vector_double("batt_custom_dispatch");
if (dispatch_custom.size()!=n_recs) throw exec_error("battwatts",
if (dispatch_custom.size()!=n_recs_lifetime / nyears) throw exec_error("battwatts",
"'batt_custom_dispatch' length must be equal to length of 'ac'.");
}
// Interconnection and curtailment
Expand All @@ -328,7 +331,7 @@ std::shared_ptr<batt_variables> cm_battwatts::setup_variables(size_t n_recs)
single_year_to_lifetime_interpolated<double>(
system_use_lifetime_output,
(size_t)nyears,
n_recs * nyears,
n_recs_lifetime,
curtailment_year_one,
scaleFactors,
interpolation_factor,
Expand All @@ -346,7 +349,7 @@ std::shared_ptr<batt_variables> cm_battwatts::setup_variables(size_t n_recs)
}
}

return battwatts_create(n_recs, nyears, chem, pos, kwh, kw, inv_eff, dispatch, dispatch_custom, interconnection_limit, curtailment_lifetime);
return battwatts_create(n_recs_lifetime, nyears, chem, pos, kwh, kw, inv_eff, dispatch, dispatch_custom, interconnection_limit, curtailment_lifetime);
}


Expand Down
12 changes: 6 additions & 6 deletions test/ssc_test/cmod_battery_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TEST_F(CMBattery_cmod_battery, ResilienceMetricsFullLoad){

EXPECT_EQ(resilience_hours[0], 0); // Max current restrictions prevent this battery from meeting the outage until day 2 (hr 46)
EXPECT_EQ(resilience_hours[46], 5);
EXPECT_NEAR(avg_critical_load, 702.8, 0.1);
EXPECT_NEAR(avg_critical_load, 701.8, 0.1);
EXPECT_NEAR(resilience_hrs_avg, 1.17, 0.01);
EXPECT_EQ(resilience_hrs_min, 0);
EXPECT_EQ(outage_durations[0], 0);
Expand All @@ -117,8 +117,8 @@ TEST_F(CMBattery_cmod_battery, ResilienceMetricsFullLoad){
if (power_max - batt_power[i] < 0.1)
max_indices.push_back(i);
}
EXPECT_EQ(max_indices.size(), 3);
EXPECT_EQ(max_indices[0], 3631);
EXPECT_EQ(max_indices.size(), 26);
EXPECT_EQ(max_indices[0], 2743);

auto batt_q0 = data_vtab->as_vector_ssc_number_t("batt_q0");
auto cap_max = *std::max_element(batt_q0.begin(), batt_q0.end());
Expand Down Expand Up @@ -155,8 +155,8 @@ TEST_F(CMBattery_cmod_battery, ResilienceMetricsFullLoadLifetime){

EXPECT_EQ(resilience_hours[0], 0); // Max current restrictions prevent this battery from meeting the outage until day 2 (hr 46)
EXPECT_EQ(resilience_hours[46], 5);
EXPECT_NEAR(avg_critical_load, 700.2, 0.1);
EXPECT_NEAR(resilience_hrs_avg, 1.17, 0.01);
EXPECT_NEAR(avg_critical_load, 698.3, 0.1);
EXPECT_NEAR(resilience_hrs_avg, 1.16, 0.01);
EXPECT_EQ(resilience_hrs_min, 0);
EXPECT_EQ(outage_durations[0], 0);
EXPECT_EQ(resilience_hrs_max, 24);
Expand All @@ -173,7 +173,7 @@ TEST_F(CMBattery_cmod_battery, ResilienceMetricsFullLoadLifetime){
if (power_max - batt_power[i] < 0.1)
max_indices.push_back(i);
}
EXPECT_EQ(max_indices[0], 3631);
EXPECT_EQ(max_indices[0], 2743);

auto batt_q0 = data_vtab->as_vector_ssc_number_t("batt_q0");
auto cap_max = *std::max_element(batt_q0.begin(), batt_q0.end());
Expand Down
28 changes: 14 additions & 14 deletions test/ssc_test/cmod_battwatts_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ TEST_F(CMBattwatts_cmod_battwatts, ResilienceMetricsHalfLoad){
double avg_critical_load = data.as_double("avg_critical_load"); // Load met

EXPECT_EQ(resilience_hours[0], 14);
EXPECT_EQ(resilience_hours[1], 14);
EXPECT_EQ(resilience_hours[1], 15);
EXPECT_NEAR(avg_critical_load, 7.98, 0.1);
EXPECT_NEAR(resilience_hrs_avg, 31.66, 0.01);
EXPECT_NEAR(resilience_hrs_avg, 31.95, 0.01);
EXPECT_EQ(resilience_hrs_min, 14);
EXPECT_EQ(outage_durations[0], 14);
EXPECT_EQ(resilience_hrs_max, 32);
EXPECT_EQ(outage_durations[16], 30);
EXPECT_NEAR(pdf_of_surviving[0], 0.00068, 1e-3);
EXPECT_NEAR(pdf_of_surviving[1], 0.00217, 1e-3);
EXPECT_NEAR(pdf_of_surviving[1], 0.00034, 1e-3);

}

Expand All @@ -84,15 +84,15 @@ TEST_F(CMBattwatts_cmod_battwatts, ResilienceMetricsHalfLoadLifetime){
double avg_critical_load = data.as_double("avg_critical_load");

EXPECT_EQ(resilience_hours[0], 14);
EXPECT_EQ(resilience_hours[1], 14);
EXPECT_EQ(resilience_hours[1], 15);
EXPECT_NEAR(avg_critical_load, 8.026, 0.1);
EXPECT_NEAR(resilience_hrs_avg, 31.83, 0.01);
EXPECT_NEAR(resilience_hrs_avg, 31.975, 0.01);
EXPECT_EQ(resilience_hrs_min, 14);
EXPECT_EQ(resilience_hrs_max, 32);
EXPECT_EQ(outage_durations[0], 14);
EXPECT_EQ(outage_durations[16], 30);
EXPECT_NEAR(pdf_of_surviving[0], 0.00034, 1e-5);
EXPECT_NEAR(pdf_of_surviving[1], 0.00103, 1e-5);
EXPECT_NEAR(pdf_of_surviving[0], 5.707e-05, 1e-5);
EXPECT_NEAR(pdf_of_surviving[1], 0.000171, 1e-5);

}

Expand All @@ -105,7 +105,7 @@ TEST_F(CMBattwatts_cmod_battwatts, ResidentialDefaults) {
EXPECT_FALSE(errors);

double charge_percent = data.as_number("batt_system_charge_percent");
EXPECT_NEAR(charge_percent, 95.63, 0.1);
EXPECT_NEAR(charge_percent, 96.52, 0.1);

auto batt_power_data = data.as_vector_ssc_number_t("batt_power");
ssc_number_t peakKwDischarge = *std::max_element(batt_power_data.begin(), batt_power_data.end());
Expand All @@ -116,11 +116,11 @@ TEST_F(CMBattwatts_cmod_battwatts, ResidentialDefaults) {

auto batt_voltage = data.as_vector_ssc_number_t("batt_voltage");
ssc_number_t peakVoltage = *std::max_element(batt_voltage.begin(), batt_voltage.end());
EXPECT_NEAR(peakVoltage, 578.9, 0.1);
EXPECT_NEAR(peakVoltage, 579.3, 0.1);

auto cycles = data.as_vector_ssc_number_t("batt_cycles");
ssc_number_t maxCycles = *std::max_element(cycles.begin(), cycles.end());
EXPECT_NEAR(maxCycles, 613, 0.1);
EXPECT_NEAR(maxCycles, 477, 0.1);
}

TEST_F(CMBattwatts_cmod_battwatts, ResidentialDefaultsLeadAcid) {
Expand All @@ -135,7 +135,7 @@ TEST_F(CMBattwatts_cmod_battwatts, ResidentialDefaultsLeadAcid) {
EXPECT_FALSE(errors);

double charge_percent = data.as_number("batt_system_charge_percent");
EXPECT_NEAR(charge_percent, 96.13, 0.1);
EXPECT_NEAR(charge_percent, 96.94, 0.1);

auto batt_power_data = data.as_vector_ssc_number_t("batt_power");
ssc_number_t peakKwDischarge = *std::max_element(batt_power_data.begin(), batt_power_data.end());
Expand All @@ -150,7 +150,7 @@ TEST_F(CMBattwatts_cmod_battwatts, ResidentialDefaultsLeadAcid) {

auto cycles = data.as_vector_ssc_number_t("batt_cycles");
ssc_number_t maxCycles = *std::max_element(cycles.begin(), cycles.end());
EXPECT_NEAR(maxCycles, 613, 0.1);
EXPECT_NEAR(maxCycles, 477, 0.1);
}

TEST_F(CMBattwatts_cmod_battwatts, NoPV) {
Expand All @@ -171,7 +171,7 @@ TEST_F(CMBattwatts_cmod_battwatts, NoPV) {
ssc_number_t peakKwDischarge = *std::max_element(batt_power_data.begin(), batt_power_data.end());
ssc_number_t peakKwCharge = *std::min_element(batt_power_data.begin(), batt_power_data.end());

EXPECT_NEAR(peakKwDischarge, 0.9, 0.1);
EXPECT_NEAR(peakKwDischarge, 1.035, 0.1);
EXPECT_NEAR(peakKwCharge, -0.7, 0.1);

auto batt_voltage = data.as_vector_ssc_number_t("batt_voltage");
Expand All @@ -180,5 +180,5 @@ TEST_F(CMBattwatts_cmod_battwatts, NoPV) {

auto cycles = data.as_vector_ssc_number_t("batt_cycles");
ssc_number_t maxCycles = *std::max_element(cycles.begin(), cycles.end());
EXPECT_NEAR(maxCycles, 520, 0.1);
EXPECT_NEAR(maxCycles, 522, 0.1);
}
13 changes: 9 additions & 4 deletions test/ssc_test/cmod_battwatts_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CMBattwatts_cmod_battwatts : public ::testing::Test {
std::vector<double> ac;
std::vector<double> load;
std::vector<double> crit_load;
std::vector<double> dispatch;

double m_error_tolerance_hi = 1.0;
double m_error_tolerance_lo = 0.1;
Expand All @@ -57,11 +58,14 @@ class CMBattwatts_cmod_battwatts : public ::testing::Test {
for (size_t i = 0; i < 8760 * nyears; i++){
size_t hr = i % 24;
if (hr > 7 && hr < 18 )
ac.push_back(1.);
ac.push_back(1.); // Watts
else
ac.push_back(0.);
load.push_back(0.5);
crit_load.push_back(0.25);
load.push_back(0.5); // kW
crit_load.push_back(0.25); // kW
if (i < 8760) {
dispatch.push_back(-0.1); // kW - keep the battery fully charged
}
}


Expand All @@ -71,7 +75,8 @@ class CMBattwatts_cmod_battwatts : public ::testing::Test {
data.assign("batt_simple_kwh", 10);
data.assign("batt_simple_kw", 5);
data.assign("batt_simple_chemistry", 1);
data.assign("batt_simple_dispatch", 0);
data.assign("batt_simple_dispatch", 2);
data.assign("batt_custom_dispatch", dispatch);
data.assign("batt_simple_meter_position", 0);
data.assign("ac", ac);
data.assign("load", load);
Expand Down

0 comments on commit b4a069e

Please sign in to comment.