Skip to content

Commit

Permalink
Merge SSC patch into develop (#1033)
Browse files Browse the repository at this point in the history
* Address loss diagram issue for POA reference cell in SAM issue 1366

* Working without pressure column 

Need to remove some modifications in cmod_pvsamv1 - set to SAM_1366 branch

* Reset POA_P mode - uses decomposition with and without pressure column

* Add wfpoa to reported outputs to facilitate troubleshooting

* Size the collector loop mass flow based on n_collectors (#1004)

* create new battery reopt sizing function. move variable mapping functions to vartab to make them accessible to both functions

* Remove redundant variables between PV and battery sizing functions. PV now calls battery sizing

* Update to GitHub Actions to latest Ubuntu

Ubuntu-18.04 deprecated as of 4/2023 https://github.blog/changelog/2022-08-09-github-actions-the-ubuntu-18-04-actions-runner-image-is-being-deprecated-and-will-be-removed-by-12-1-22/

* add comment

* Initial sg2 implementation, currently debugging

* Commented out unused code sections, prepped for speed testing

* update ssc version for testing and benchmarking

* Removed commented lines, update test results (irrad tests, pvwatts
tests)

* Updated test results

* Re-run PVWatts cmod tests for different DC-AC ratio, updated remaining
tests

* Allow more flexible SAM CSV for solar weather file format (#1017)

- Allow files that have minimum required metadata, regardless of number of columns in metadata header rows.
- Add Version to list of metadata columns to support NSRDB version numbers.
- Test with files from NSRDB, PVWatts API, and hand-edited to have different metadata row lengths.

* Update to fix broken MacOS build

"Call to undeclared function 'gettimeofday'; ISO C99 and later do not support implicit function declarations" compile error

* Throw an error if duplicate entries in the voltage table produce zero slope

* adjust voltage profile to comply with new restrictions

* Add errors for length mismatch between critical load and electric load (#1021)

* Add errors for length mismatch between critical load and electric load

* Review and revise battery error messages.

---------

Co-authored-by: Paul Gilman <cpaulgilman@gmail.com>

* update documentation for standalone battery params

* fix fabs error on linux

* Add test for reopt sizing post for standalone battery

* Better explanation of this function's limitations

* Fix day_of function to return 0-364 rather than 0-6

* Update tests

* Setup test for ssc issue 1023

* Create ssc test to match python script issue in #1023

* additional test outputs and verify "good" results on amd64 Windows 11

* fix issue on arm64 in lib_battery_voltage

TODO - test on Windows and regenerate pysam and test on arm64, aarch64 and amd64

* update test not to write out all values and check final iteration

* Update test comment for future reference

* Turn all ssc tests back on for pull request #1025

* Remove sf_adjustment_factors class and use adjustment_factors class for sf_adjustment

* Remove unused callbacks causing Github Actions to fail

* Update CMakeLists.txt to skip removed include files for Github Actions

* Restore commented out files

* Restore all per patch and build locally on Linux

* Remove extra qualification on size() function causing platforms other than Windows to fail

Note - no error message in Github Actions log....

* Give price signals dispatch info about real time system power and load for dispatch for apples to apples comparison of forecast error

* Update integration tests with new cycling value for look behind case

* Fix conflict for merge of patch into develop

Remove duplicate definition of size() in adjustment factors class.

* Fix broken tests

Run ssc/tes/\input_json/ssc_test_save_as_JSON_test.sam in latest SAM and generate updated json files for 'save_as_JSON_test'.
Run ssc/test/input_json/TechnologyModel/pvwattsv8/generate_json.lk for all CmodPVWattsv8Test.DCACRatio* tests

---------

Co-authored-by: Steven Janzou <sjanzou@gmail.com>
Co-authored-by: Matthew Boyd <30417543+Matthew-Boyd@users.noreply.github.com>
Co-authored-by: Brian Mirletz <brian.mirletz@nrel.gov>
Co-authored-by: Matt Prilliman <Matthew.Prilliman@nrel.gov>
Co-authored-by: Steven Janzou <steven@janzouconsulting.com>
Co-authored-by: Matt Prilliman <54449384+mjprilliman@users.noreply.github.com>
Co-authored-by: tyneises <ty.neises@nrel.gov>
  • Loading branch information
8 people authored Jun 10, 2023
1 parent 390291d commit c5d0412
Show file tree
Hide file tree
Showing 63 changed files with 2,007 additions and 1,098 deletions.
2 changes: 2 additions & 0 deletions nlopt/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
# include <windows.h>
#endif

// header needed to build on MacOS "Call to undeclared function 'gettimeofday'; ISO C99 and later do not support implicit function declarations" compile error
int gettimeofday(struct timeval * __restrict, void * __restrict);

/* return time in seconds since some arbitrary point in the past */
double nlopt_seconds(void)
{
Expand Down
21 changes: 20 additions & 1 deletion shared/lib_battery_dispatch_automatic_btm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ dispatch_automatic_behind_the_meter_t::dispatch_automatic_behind_the_meter_t(
bool chargeOnlySystemExceedLoad,
bool dischargeOnlyLoadExceedSystem,
bool behindTheMeterDischargeToGrid,
double SOC_min_outage
double SOC_min_outage,
int load_forecast_mode
) : dispatch_automatic_t(Battery, dt_hour, SOC_min, SOC_max, current_choice, Ic_max, Id_max, Pc_max_kwdc, Pd_max_kwdc, Pc_max_kwac, Pd_max_kwac,
t_min, dispatch_mode, weather_forecast_mode, pv_dispatch, nyears, look_ahead_hours, dispatch_update_frequency_hours, can_charge, can_clip_charge, can_grid_charge, can_fuelcell_charge,
battReplacementCostPerkWh, battCycleCostChoice, battCycleCost, battOMCost, interconnection_limit, chargeOnlySystemExceedLoad, dischargeOnlyLoadExceedSystem,
Expand All @@ -81,6 +82,8 @@ dispatch_automatic_behind_the_meter_t::dispatch_automatic_behind_the_meter_t(
_P_target_use.reserve(_num_steps);
_P_battery_use.reserve(_num_steps);

_load_forecast_mode = load_forecast_mode;

grid.reserve(_num_steps);
sorted_grid.reserve(_num_steps);

Expand Down Expand Up @@ -264,6 +267,20 @@ void dispatch_automatic_behind_the_meter_t::initialize(size_t hour_of_year, size
m_batteryPower->powerBatteryTarget = 0;
_day_index = 0;

// Give all algorithms real data for the current step (overwrite forecast if needed)
if (_load_forecast_mode != LOAD_LOOK_AHEAD) {
_P_load_ac[lifetimeIndex] = m_batteryPower->powerLoad;
}
// Lookahead forecasts may better account for losses than the code below, so don't run this if lookahead
if (_weather_forecast_mode != WF_LOOK_AHEAD) {
if (m_batteryPower->connectionMode == AC_CONNECTED) {
_P_pv_ac[lifetimeIndex] = m_batteryPower->powerSystem;
}
else {
_P_pv_ac[lifetimeIndex] = m_batteryPower->powerSystem * m_batteryPower->sharedInverter->efficiencyAC;
}
}

// clean up vectors
size_t lifetimeMax = _P_pv_ac.size();
for (size_t ii = 0; ii != _num_steps && lifetimeIndex < lifetimeMax; ii++)
Expand All @@ -274,6 +291,7 @@ void dispatch_automatic_behind_the_meter_t::initialize(size_t hour_of_year, size
_P_battery_use.push_back(0.);
lifetimeIndex++;
}

}
bool dispatch_automatic_behind_the_meter_t::check_new_month(size_t hour_of_year, size_t step)
{
Expand Down Expand Up @@ -320,6 +338,7 @@ void dispatch_automatic_behind_the_meter_t::sort_grid(size_t idx, FILE *p, const

// compute grid net from pv and load (no battery)
size_t count = 0;

for (size_t hour = 0; hour != 24 && idx < _P_load_ac.size(); hour++)
{
for (size_t step = 0; step != _steps_per_hour; step++)
Expand Down
6 changes: 5 additions & 1 deletion shared/lib_battery_dispatch_automatic_btm.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class dispatch_automatic_behind_the_meter_t : public dispatch_automatic_t
bool chargeOnlySystemExceedLoad,
bool dischargeOnlyLoadExceedSystem,
bool behindTheMeterDischargeToGrid,
double SOC_min_outage
double SOC_min_outage,
int load_forecast_mode
);

~dispatch_automatic_behind_the_meter_t() override {};
Expand Down Expand Up @@ -166,6 +167,9 @@ class dispatch_automatic_behind_the_meter_t : public dispatch_automatic_t
/*! Full time-series of loads [kW] */
double_vec _P_load_ac;

/*! Forecast mode for loads (look ahead, look behind, custom) */
int _load_forecast_mode;

/*! Full time-series of target power [kW] */
double_vec _P_target_input;

Expand Down
17 changes: 10 additions & 7 deletions shared/lib_battery_voltage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ void voltage_table_t::initialize() {
double V0 = params->voltage_table[i - 1][1];
slope = (V - V0) / (DOD - DOD0);
intercept = V0 - (slope * DOD0);

if (fabs(slope) < 1e-7)
throw std::runtime_error("voltage_table_t error: Battery voltage matrix cannot have two identical voltages.");
}
slopes.emplace_back(slope);
intercepts.emplace_back(intercept);
Expand Down Expand Up @@ -253,9 +256,9 @@ double voltage_table_t::calculate_current_for_target_w(double P_watts, double q,

P_watts /= params->num_cells_series;
P_watts *= params->dt_hr;
double multiplier = 1.;
int multiplier = 1;
if (P_watts < 0)
multiplier = -1.;
multiplier = -1;

size_t row = 0;
while (row < params->voltage_table.size() && DOD > params->voltage_table[row][0]) {
Expand All @@ -266,12 +269,12 @@ double voltage_table_t::calculate_current_for_target_w(double P_watts, double q,
double B = qmax / 100.;

double DOD_new = 0.;
double incr = 0;
double DOD_best = DOD_best = multiplier == -1. ? 0 : 100;
int incr = 0;
double DOD_best = DOD_best = (multiplier == -1) ? 0 : 100;
double P_best = 0;
while (incr + row < slopes.size() && incr + row >= 0) {
size_t i = row + (size_t) incr;
incr += 1 * multiplier;
while (((incr + row) < slopes.size()) && ((incr + row) >= 0)) {
size_t i = row + incr;
incr += multiplier;

double a = B * slopes[i];
double b = A * slopes[i] + B * intercepts[i];
Expand Down
Loading

0 comments on commit c5d0412

Please sign in to comment.