test/shared_test/lib_resilience_test.cpp
// for dc-connected battery, the dispatch array units are kwDC. This doesn't affect
// dispatch_resiliency which decides the dispatch based on the ac load, but it will affect
// batt::advance, which will be dispatching less power per time step than in the AC case
// where the dispatch kWAC was converted to kWDC
for dc-connected battery, the dispatch array units are kwDC. This doesn't affect
dispatch_resiliency which decides the dispatch based on the ac load, but it will affect
batt::advance, which will be dispatching less power per time step than in the AC case
where the dispatch kWAC was converted to kWDC
for dc - connected battery the dispatch array units are kwDC . This doesn ' t affect dispatch_resiliency which decides the dispatch based on the ac load but it will affect batt :: advance which will be dispatching less power per time step than in the AC case where the dispatch kWAC was converted to kWDC
TEST_F(ResilienceTest_lib_resilience, PVWattsDCHourly_Discharge)
{
    CreateBattery(false, 1, 0. ,1., 1.);
    resilience_runner resilience(batt);
    const double voltage = 500;
    std::vector<double> batt_power, charge_total;
    for (size_t i = 0; i < 10; i++){
        batt->initialize_time(0, i, 0);
        resilience.add_battery_at_outage_timestep(*dispatch, i);
        resilience.run_surviving_batteries(load[i], 0, 0, 0, 0, 0);
        batt->advance(vartab, ac[i], voltage, load[i]);
        charge_total.emplace_back(batt->battery_model->battery_charge_total());
        if (i < 5)
            EXPECT_NEAR(batt->outBatteryPower[i], 1. * inverter->efficiencyAC/100. * batt_vars->batt_dc_dc_bms_efficiency/100., 1e-3) << "timestep " << i << " battery discharging";
        else if (i == 5)
            EXPECT_NEAR(batt->outBatteryPower[i], 0.92, 1e-3) << "timestep 5 battery SOC limits";
        else
            EXPECT_NEAR(batt->outBatteryPower[i], 0, 1e-3) << "timestep " << i << " battery at min SOC";
    }
    std::vector<double> correct_charge_total = {13.94, 12.12, 10.28, 8.42, 6.51, 4.57, 4.57, 4.57, 4.57, 4.57};
    for (size_t i = 0; i < correct_charge_total.size(); i++){
        EXPECT_NEAR(charge_total[i], correct_charge_total[i], 0.1);
    }
    resilience.run_surviving_batteries_by_looping(&load[0], &ac[0]);
    double avg_hours = resilience.compute_metrics();
    EXPECT_NEAR(avg_hours, 0.0028, 1e-4);
    auto survived_hours = resilience.get_hours_survived();
    EXPECT_EQ(survived_hours[0], 6);
    EXPECT_EQ(survived_hours[1], 5);
    EXPECT_EQ(survived_hours[2], 4);
    EXPECT_EQ(survived_hours[3], 3);
    EXPECT_EQ(survived_hours[4], 2);
    EXPECT_EQ(survived_hours[5], 1);
    EXPECT_EQ(survived_hours[9], 1);
    auto outage_durations = resilience.get_outage_duration_hrs();
    EXPECT_EQ(outage_durations[0], 0);
    EXPECT_EQ(outage_durations[1], 1);
    EXPECT_EQ(outage_durations[2], 2);
    EXPECT_EQ(outage_durations[3], 3);
    EXPECT_EQ(outage_durations[4], 4);
    EXPECT_EQ(outage_durations[5], 5);
    EXPECT_EQ(outage_durations[6], 6);
    auto probs = resilience.get_probs_of_surviving();
    EXPECT_NEAR(probs[0], 0.999, 1e-3);
    EXPECT_NEAR(probs[1], 0.000571, 1e-6);
    EXPECT_NEAR(probs[2], 0.000114, 1e-6);
    EXPECT_NEAR(probs[3], 0.000114, 1e-6);
    EXPECT_NEAR(probs[4], 0.000114, 1e-6);
    double avg_load = resilience.get_avg_crit_load_kwh();
    EXPECT_NEAR(avg_load, 0.00352, 1e-5);
}
TEST_F ( ResilienceTest_lib_resilience , PVWattsDCHourly_Discharge ) { CreateBattery ( false , 1 , 0. , 1. , 1. ) ; resilience_runner resilience ( batt ) ; const double voltage = 500 ; std :: vector < double > batt_power , charge_total ; for ( size_t i = 0 ; i < 10 ; i ++ ) { batt -> initialize_time ( 0 , i , 0 ) ; resilience . add_battery_at_outage_timestep ( * dispatch , i ) ; resilience . run_surviving_batteries ( load [ i ] , 0 , 0 , 0 , 0 , 0 ) ; batt -> advance ( vartab , ac [ i ] , voltage , load [ i ] ) ; charge_total . emplace_back ( batt -> battery_model -> battery_charge_total ( ) ) ; if ( i < 5 ) EXPECT_NEAR ( batt -> outBatteryPower [ i ] , 1. * inverter -> efficiencyAC / 100. * batt_vars -> batt_dc_dc_bms_efficiency / 100. , 1e-3 ) << " " << i << " " ; else if ( i == 5 ) EXPECT_NEAR ( batt -> outBatteryPower [ i ] , 0.92 , 1e-3 ) << " " ; else EXPECT_NEAR ( batt -> outBatteryPower [ i ] , 0 , 1e-3 ) << " " << i << " " ; } std :: vector < double > correct_charge_total = { 13.94 , 12.12 , 10.28 , 8.42 , 6.51 , 4.57 , 4.57 , 4.57 , 4.57 , 4.57 } ; for ( size_t i = 0 ; i < correct_charge_total . size ( ) ; i ++ ) { EXPECT_NEAR ( charge_total [ i ] , correct_charge_total [ i ] , 0.1 ) ; } resilience . run_surviving_batteries_by_looping ( & load [ 0 ] , & ac [ 0 ] ) ; double avg_hours = resilience . compute_metrics ( ) ; EXPECT_NEAR ( avg_hours , 0.0028 , 1e-4 ) ; auto survived_hours = resilience . get_hours_survived ( ) ; EXPECT_EQ ( survived_hours [ 0 ] , 6 ) ; EXPECT_EQ ( survived_hours [ 1 ] , 5 ) ; EXPECT_EQ ( survived_hours [ 2 ] , 4 ) ; EXPECT_EQ ( survived_hours [ 3 ] , 3 ) ; EXPECT_EQ ( survived_hours [ 4 ] , 2 ) ; EXPECT_EQ ( survived_hours [ 5 ] , 1 ) ; EXPECT_EQ ( survived_hours [ 9 ] , 1 ) ; auto outage_durations = resilience . get_outage_duration_hrs ( ) ; EXPECT_EQ ( outage_durations [ 0 ] , 0 ) ; EXPECT_EQ ( outage_durations [ 1 ] , 1 ) ; EXPECT_EQ ( outage_durations [ 2 ] , 2 ) ; EXPECT_EQ ( outage_durations [ 3 ] , 3 ) ; EXPECT_EQ ( outage_durations [ 4 ] , 4 ) ; EXPECT_EQ ( outage_durations [ 5 ] , 5 ) ; EXPECT_EQ ( outage_durations [ 6 ] , 6 ) ; auto probs = resilience . get_probs_of_surviving ( ) ; EXPECT_NEAR ( probs [ 0 ] , 0.999 , 1e-3 ) ; EXPECT_NEAR ( probs [ 1 ] , 0.000571 , 1e-6 ) ; EXPECT_NEAR ( probs [ 2 ] , 0.000114 , 1e-6 ) ; EXPECT_NEAR ( probs [ 3 ] , 0.000114 , 1e-6 ) ; EXPECT_NEAR ( probs [ 4 ] , 0.000114 , 1e-6 ) ; double avg_load = resilience . get_avg_crit_load_kwh ( ) ; EXPECT_NEAR ( avg_load , 0.00352 , 1e-5 ) ; }
for dc-connected battery, the dispatch array units are kwDC.
for dc - connected battery the dispatch array units are kwDC .