Skip to content

Commit d801049

Browse files
author
Brian Mirletz
committed
Merge branch 'patch' of https://github.com/NREL/ssc into patch_to_develop_2_19_25
2 parents d62652f + 8e31c5d commit d801049

File tree

7 files changed

+53
-34
lines changed

7 files changed

+53
-34
lines changed

shared/lib_battery_capacity.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,11 @@ void capacity_t::check_SOC() {
162162

163163
// do not switch to discharging
164164
state->cell_current = fmin(0, state->cell_current);
165+
166+
// Correct state given current change
167+
state->q0 = q_upper;
165168
}
166-
state->q0 = q_upper;
169+
167170
}
168171
else if (state->q0 < q_lower - tolerance) {
169172
// if undercharged then reduce discharhing
@@ -172,8 +175,10 @@ void capacity_t::check_SOC() {
172175

173176
// do not switch to charging
174177
state->cell_current = fmax(0, state->cell_current);
178+
179+
// Correct state given current change
180+
state->q0 = q_lower;
175181
}
176-
state->q0 = q_lower;
177182
}
178183
}
179184

shared/lib_windfile.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ static float col_or_nan(const std::string& s)
115115
}
116116
}
117117
else
118-
return std::numeric_limits<float>::quiet_NaN();;
118+
return std::numeric_limits<float>::quiet_NaN();
119119
}
120120

121121
static int locate2(std::string buf, std::vector<std::string> &vstring, char delim)
@@ -479,7 +479,12 @@ bool windfile::open( const std::string &file )
479479
std::vector<std::string> hdr;
480480
int ncols = locate2(m_buf, hdr, ',');
481481

482-
for (size_t i = 0; (int)i < ncols; i++)
482+
lat = std::numeric_limits<float>::quiet_NaN();
483+
lon = std::numeric_limits<float>::quiet_NaN();
484+
elev = std::numeric_limits<float>::quiet_NaN();
485+
486+
// for (size_t i = 0; (int)i < ncols; i++) SAM issue 1990
487+
for (size_t i = 0; (int)i < ncols && (i+1) < hdr.size(); i++)
483488
{
484489
hdr_item = util::lower_case(trimboth(hdr[i]));
485490

@@ -509,13 +514,18 @@ bool windfile::open( const std::string &file )
509514
}
510515

511516
}
512-
513-
// time stamps expected to be in local time
514-
// wind data files provide both site timezone and data timezone in header
515-
// if the values are different, we can't determine the time zone of the time stamps
516-
if (tz_data != tz_site)
517+
// elevation required for hub-height power curve adjustment
518+
if (isnan(elev)) {
519+
m_errorMsg = "Elevation must be specified in header. Please check resource data.";
520+
return false;
521+
}
522+
523+
// time stamps expected to be in local time. wind data files provide both site timezone and data timezone in header
524+
// if the values are different, we can't determine the time zone of the time stamps for financial model time-dependent features (TOU, TOD, etc.)
525+
if (tz_data != tz_site) {
517526
m_errorMsg = util::format("data must be in local time: data time zone %s and site time zone %s are not the same", tz_data.c_str(), tz_site.c_str());
518-
527+
return false;
528+
}
519529
// line 2 data column headings
520530
getline(m_ifs, m_buf);
521531
nhdrs++;

ssc/cmod_mhk_tidal.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ class cm_mhk_tidal : public compute_module
114114

115115
//Store the number of rows- this will have to change if resource and power curve can have different stream speeds
116116
int number_rows = (int)tidal_resource_matrix.nrows();
117+
// malloc issue for calculated power curve
118+
if (tidal_power_curve.nrows() > tidal_resource_matrix.nrows())
119+
number_rows = (int)tidal_power_curve.nrows();
117120

118121
//Check that the power matrix only has two columns
119122
if (tidal_power_curve.ncols() != (size_t)2)
@@ -261,6 +264,7 @@ class cm_mhk_tidal : public compute_module
261264

262265
}
263266
}
267+
264268
p_gen[i] = tidal_power_curve.at(power_bin, 1) * (1 - total_loss/100.0) * number_devices * haf(i); //kW
265269
//p_annual_energy_dist[i] = p_gen[i] * 8760.0 / number_records;
266270
annual_energy += p_gen[i] * 8760.0 / number_records;

test/shared_test/lib_battery_dispatch_automatic_btm_test.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutagePeakShavingDai
867867
// Battery will discharge as much as possible for the outage, charge when PV is available, then discharge when load increases at 7 pm
868868
std::vector<double> expectedPower = { 52.1, 52.1, 52.1, 52.1, 39.4, 3.7, // 0 - 5
869869
0, -48, -48, -48, -48, -48, // Able to charge when SOC at 0, 6- 11
870-
-48, -48, -48, -48.0, -11, 0, // 12 - 17
870+
-48, -48, -48, -48.0, -48, -38.57, // 12 - 17
871871
0, 52.1, 52.1, 52.1, 52.1, 52.1, // 18 - 23
872872
52.1, 52.1, 52.1, 52.1 };
873873

@@ -938,7 +938,7 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageWithAvailabili
938938
std::vector<double> expectedPower = { 52.1, 52.1, 52.1, 52.1, 39.4, 3.7,
939939
0, 0, 0, 0, 0, 0,
940940
0, -48, -48, -48.0, -48.0, -48.0,
941-
0, 52.1, 52.1, 52.28, 52.48, 27.6 };
941+
0, 52.22, 52.34, 52.28, 4.47, 0 };
942942

943943
std::vector<double> expectedCritLoadUnmet = { 0, 0, 0, 0, 12.19, 46.46,
944944
50, 50, 50, 50, 50, 50, // Losses below prevent any crit load from being met in hrs 6 - 12 while battery is discharged
@@ -1085,7 +1085,7 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageWithInverterLo
10851085
// Battery will discharge as much as possible for the outage, charge when PV is available, then discharge when load increases at 7 pm
10861086
std::vector<double> expectedPower = { 52.1, 52.1, 52.1, 52.1, 39.4, 3.7,
10871087
0, -48, -48, -48, -48, -48,
1088-
-48, -48, -48, -48.0, -11, 0,
1088+
-48, -48, -48, -48.0, -48, -38.57,
10891089
0, 52.16, 52.16, 52.16, 52.16, 52.16, 52.16, };
10901090

10911091
std::vector<double> expectedCritLoadUnmet = { 50, 50, 50, 50, 50, 50, // Losses below prevent any crit load from being met in first hours
@@ -1206,20 +1206,20 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutagePeakShavingEmp
12061206
SOC = batteryModel->SOC();
12071207
}
12081208

1209-
EXPECT_NEAR(batteryModel->SOC(), 100, 0.01);
1210-
EXPECT_EQ(h, 17);
1209+
EXPECT_NEAR(batteryModel->SOC(), 96.67, 0.01);
1210+
EXPECT_EQ(h, 18);
12111211

12121212
// Show that the battery can discharge above max SOC after outage
1213-
batteryPower->powerLoad = 680;
1213+
batteryPower->powerLoad = 670;
12141214
batteryPower->powerSystem = 0;
12151215
batteryPower->isOutageStep = false;
12161216
batteryPower->powerCritLoad = 14;
1217-
dispatchAutoBTM->dispatch(0, h, 0);
1217+
dispatchAutoBTM->dispatch(0, h-1, 0);
12181218
h++;
12191219

1220-
EXPECT_NEAR(batteryPower->powerBatteryDC, 12.84, 0.5) << " error in expected at hour " << h;
1220+
EXPECT_NEAR(batteryPower->powerBatteryDC, 2.08, 0.5) << " error in expected at hour " << h;
12211221

1222-
EXPECT_NEAR(batteryModel->SOC(), 95, 0.01);
1222+
EXPECT_NEAR(batteryModel->SOC(), 96.31, 0.01);
12231223

12241224
// Battery cannot charge above max SOC
12251225
batteryPower->powerLoad = 700;
@@ -1327,7 +1327,7 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageRetailRAteEmpt
13271327
SOC = batteryModel->SOC();
13281328
}
13291329

1330-
EXPECT_NEAR(batteryModel->SOC(), 100, 0.01);
1330+
EXPECT_NEAR(batteryModel->SOC(), 96.67, 0.01);
13311331
EXPECT_EQ(h, 18);
13321332

13331333
// Show that the battery can discharge above max SOC after outage
@@ -1338,9 +1338,9 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageRetailRAteEmpt
13381338
dispatchAutoBTM->dispatch(0, h, 0);
13391339
h++;
13401340

1341-
EXPECT_NEAR(batteryPower->powerBatteryDC, 14.6, 0.5) << " error in expected at hour " << h;
1341+
EXPECT_NEAR(batteryPower->powerBatteryDC, 9.80, 0.5) << " error in expected at hour " << h;
13421342

1343-
EXPECT_NEAR(batteryModel->SOC(), 95, 0.01);
1343+
EXPECT_NEAR(batteryModel->SOC(), 94.93, 0.01);
13441344

13451345
// Battery cannot charge above max SOC
13461346
batteryPower->powerLoad = 700;
@@ -1450,20 +1450,20 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageCustomEmptyAnd
14501450
SOC = batteryModel->SOC();
14511451
}
14521452

1453-
EXPECT_NEAR(batteryModel->SOC(), 100, 0.01);
1453+
EXPECT_NEAR(batteryModel->SOC(), 96.67, 0.01);
14541454
EXPECT_EQ(h, 17);
14551455

14561456
// Show that the battery can discharge above max SOC after outage
1457-
batteryPower->powerLoad = 700;
1457+
batteryPower->powerLoad = 8;
14581458
batteryPower->powerSystem = 0;
14591459
batteryPower->isOutageStep = false;
1460-
batteryPower->powerCritLoad = 50;
1460+
batteryPower->powerCritLoad = 8;
14611461
dispatchAutoBTM->dispatch(0, h, 0);
14621462
h++;
14631463

1464-
EXPECT_NEAR(batteryPower->powerBatteryDC, 14.8, 0.5) << " error in expected at hour " << h;
1464+
EXPECT_NEAR(batteryPower->powerBatteryDC, 9.45, 0.5) << " error in expected at hour " << h;
14651465

1466-
EXPECT_NEAR(batteryModel->SOC(), 95, 0.01);
1466+
EXPECT_NEAR(batteryModel->SOC(), 95.01, 0.01);
14671467

14681468
// Battery cannot charge above max SOC
14691469
batteryPower->powerLoad = 700;
@@ -1716,7 +1716,7 @@ TEST_F(AutoBTMTest_lib_battery_dispatch, DispatchAutoBTMGridOutageWithBatteryAva
17161716
std::vector<double> expectedPower = { 0, 0, 0, 0, 0, 0,
17171717
52.1, 52.1, 52.1, 52.1, 39.4, 3.7,
17181718
0, -48, -48, -48.0, -48.0, -48.0,
1719-
0, 52.1, 52.1, 52.28, 52.48, 27.6 };
1719+
0, 52.22, 52.34, 52.28, 4.46, 0 };
17201720

17211721
std::vector<double> expectedCritLoadUnmet = { 50, 50, 50, 50, 50, 50, // Losses below prevent any crit load from being met in hrs 0 - 5 while battery is unavailable
17221722
0, 0, 0, 0, 12.2, 46.5, // Battery meets losses until it runs out of SOC

test/shared_test/lib_battery_dispatch_manual_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ TEST_F(ManualTest_lib_battery_dispatch, OutageWithManualDispatch) {
680680
batteryPower->powerLoad = 50;
681681
dispatchManual->dispatch(year, hour_of_year, step_of_hour);
682682
hour_of_year += 1;
683-
EXPECT_NEAR(batteryPower->powerBatteryDC, -50.0, 0.1);
683+
EXPECT_NEAR(batteryPower->powerBatteryDC, -47.7, 0.1);
684684

685685
// Turn outage back on, should charge to 100%
686686
batteryPower->powerSystem = 700; batteryPower->voltageSystem = 600; batteryPower->powerLoad = 50;
@@ -691,7 +691,7 @@ TEST_F(ManualTest_lib_battery_dispatch, OutageWithManualDispatch) {
691691
soc = dispatchManual->battery_soc();
692692
}
693693
EXPECT_NEAR(100, dispatchManual->battery_soc(), 0.1);
694-
EXPECT_NEAR(17, hour_of_year, 0.1);
694+
EXPECT_NEAR(19, hour_of_year, 0.1);
695695

696696
// With outage off, can discharge above max SOC
697697
batteryPower->powerSystem = 0; batteryPower->voltageSystem = 600; batteryPower->powerLoad = 14;
@@ -701,7 +701,7 @@ TEST_F(ManualTest_lib_battery_dispatch, OutageWithManualDispatch) {
701701
EXPECT_NEAR(batteryPower->powerBatteryDC, 14.6, 0.1);
702702

703703
// With outage off, cannot charge above max soc
704-
EXPECT_NEAR(95, dispatchManual->battery_soc(), 0.1);
704+
EXPECT_NEAR(97.42, dispatchManual->battery_soc(), 0.1);
705705
batteryPower->powerSystem = 700; batteryPower->voltageSystem = 600; batteryPower->powerLoad = 14;
706706
batteryPower->powerCritLoad = 14; batteryPower->isOutageStep = false;
707707
dispatchManual->dispatch(year, hour_of_year, step_of_hour);

test/ssc_test/cmod_battery_pvsamv1_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ TEST_F(CMPvsamv1BatteryIntegration_cmod_pvsamv1, ResidentialACBatteryModelIntegr
124124
ssc_number_t peakKwCharge[4] = { -2.91, -2.66, -2.25, -3.30 };
125125
ssc_number_t peakKwDischarge[4] = { 1.39, 1.73, 0.97, 1.96 };
126126
ssc_number_t peakCycles[4] = { 1, 1, 1, 3 };
127-
ssc_number_t avgCycles[4] = { 1, 1, 0.4904, 1.0110 };
127+
ssc_number_t avgCycles[4] = { 1, 1, 0.4822, 1.0110 };
128128

129129
// Test peak shaving look ahead, peak shaving look behind, and automated grid power target, and self-consumption. Others require additional input data
130130
for (int i = 0; i < 4; i++) {

test/ssc_test/cmod_hybrid_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ TEST_F(CmodHybridTest, PVWattsv8WindBatterySingleOwner) {
101101
ssc_data_get_number(hybrid_outputs, "project_return_aftertax_npv", &npv);
102102

103103
EXPECT_NEAR(om_expenses[1], 10425847, 1);
104-
EXPECT_NEAR(revenue[1], 33062516, 1);
105-
EXPECT_NEAR(ebitda[1], 22636669, 1);
104+
EXPECT_NEAR(revenue[1], 33062517, 1);
105+
EXPECT_NEAR(ebitda[1], 22636670, 1);
106106
EXPECT_NEAR(npv, -227222606, 227222606 * 0.001);
107107

108108
EXPECT_NEAR(total_energy, battannualenergy, total_energy * 0.001);

0 commit comments

Comments
 (0)