Skip to content

Commit 2afff4f

Browse files
authored
Merge pull request #1352 from NREL/ssc_195_day_of_week_improvements
Ssc 195 day of week improvements
2 parents 0485963 + 071e3ee commit 2afff4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+289
-127
lines changed

shared/lib_battery_dispatch_manual.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ dispatch_manual_t::dispatch_manual_t(battery_t * Battery, double dt, double SOC_
4545
util::matrix_t<size_t> dm_dynamic_sched, util::matrix_t<size_t> dm_dynamic_sched_weekend,
4646
std::vector<bool> dm_charge, std::vector<bool> dm_discharge, std::vector<bool> dm_gridcharge, std::vector<bool> dm_fuelcellcharge, std::vector<bool> dm_btm_to_grid,
4747
std::map<size_t, double> dm_percent_discharge, std::map<size_t, double> dm_percent_gridcharge, bool can_clip_charge, bool can_curtail_charge, double interconnection_limit,
48+
size_t start_day_of_year,
4849
bool chargeOnlySystemExceedLoad, bool dischargeOnlyLoadExceedSystem, double SOC_min_outage, bool priorityChargeBattery)
4950
: dispatch_t(Battery, dt, SOC_min, SOC_max, current_choice, Ic_max, Id_max, Pc_max_kwdc, Pd_max_kwdc, Pc_max_kwac, Pd_max_kwac,
5051
t_min, mode, battMeterPosition, interconnection_limit, chargeOnlySystemExceedLoad, dischargeOnlyLoadExceedSystem, SOC_min_outage)
5152
{
52-
init_with_vects(dm_dynamic_sched, dm_dynamic_sched_weekend, dm_charge, dm_discharge, dm_gridcharge, dm_fuelcellcharge, dm_btm_to_grid, dm_percent_discharge, dm_percent_gridcharge, can_clip_charge, can_curtail_charge, priorityChargeBattery);
53+
init_with_vects(dm_dynamic_sched, dm_dynamic_sched_weekend, dm_charge, dm_discharge, dm_gridcharge, dm_fuelcellcharge, dm_btm_to_grid, dm_percent_discharge, dm_percent_gridcharge,
54+
can_clip_charge, can_curtail_charge, priorityChargeBattery, start_day_of_year);
5355
}
5456

5557
void dispatch_manual_t::init_with_vects(
@@ -64,7 +66,8 @@ void dispatch_manual_t::init_with_vects(
6466
std::map<size_t, double> dm_percent_gridcharge,
6567
bool can_clip_charge,
6668
bool can_curtail_charge,
67-
bool priorityChargeBattery)
69+
bool priorityChargeBattery,
70+
size_t start_day_of_year)
6871
{
6972
_sched = dm_dynamic_sched;
7073
_sched_weekend = dm_dynamic_sched_weekend;
@@ -79,6 +82,7 @@ void dispatch_manual_t::init_with_vects(
7982
_can_curtail_charge = can_curtail_charge;
8083
_priority_charge_battery = priorityChargeBattery;
8184
_iprofile = 0;
85+
_start_day_of_year = start_day_of_year;
8286
}
8387

8488
// deep copy from dispatch to this
@@ -88,7 +92,7 @@ dispatch_t(dispatch)
8892
const dispatch_manual_t * tmp = dynamic_cast<const dispatch_manual_t *>(&dispatch);
8993
init_with_vects(tmp->_sched, tmp->_sched_weekend,
9094
tmp->_charge_array, tmp->_discharge_array, tmp->_gridcharge_array, tmp->_fuelcellcharge_array, tmp->_discharge_grid_array,
91-
tmp->_percent_discharge_array, tmp->_percent_charge_array, tmp->_can_clip_charge, tmp->_can_curtail_charge, tmp->_priority_charge_battery);
95+
tmp->_percent_discharge_array, tmp->_percent_charge_array, tmp->_can_clip_charge, tmp->_can_curtail_charge, tmp->_priority_charge_battery, tmp->_start_day_of_year);
9296
}
9397

9498
// shallow copy from dispatch to this
@@ -98,7 +102,7 @@ void dispatch_manual_t::copy(const dispatch_t * dispatch)
98102
const dispatch_manual_t * tmp = dynamic_cast<const dispatch_manual_t *>(dispatch);
99103
init_with_vects(tmp->_sched, tmp->_sched_weekend,
100104
tmp->_charge_array, tmp->_discharge_array, tmp->_gridcharge_array, tmp->_fuelcellcharge_array, tmp->_discharge_grid_array,
101-
tmp->_percent_discharge_array, tmp->_percent_charge_array, tmp->_can_clip_charge, tmp->_can_curtail_charge, tmp->_priority_charge_battery);
105+
tmp->_percent_discharge_array, tmp->_percent_charge_array, tmp->_can_clip_charge, tmp->_can_curtail_charge, tmp->_priority_charge_battery, tmp->_start_day_of_year);
102106
}
103107

104108
void dispatch_manual_t::prepareDispatch(size_t hour_of_year, size_t )
@@ -108,7 +112,7 @@ void dispatch_manual_t::prepareDispatch(size_t hour_of_year, size_t )
108112
size_t column = h - 1;
109113
_iprofile = 0;
110114

111-
bool is_weekday = util::weekday(hour_of_year);
115+
bool is_weekday = util::weekday(hour_of_year, _start_day_of_year);
112116
if (!is_weekday && _mode == MANUAL)
113117
_iprofile = _sched_weekend(m - 1, column);
114118
else

shared/lib_battery_dispatch_manual.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class dispatch_manual_t : public dispatch_t
6767
bool can_clip_charge,
6868
bool can_curtail_charge,
6969
double interconnection_limit,
70+
size_t start_day_of_year,
7071
bool chargeOnlySystemExceedLoad = true,
7172
bool dischargeOnlyLoadExceedSystem = true,
7273
double SOC_min_outage = 0.0,
@@ -104,7 +105,8 @@ class dispatch_manual_t : public dispatch_t
104105
std::map<size_t, double> dm_percent_gridcharge,
105106
bool can_clip_charge,
106107
bool can_curtail_charge,
107-
bool priorityChargeBattery);
108+
bool priorityChargeBattery,
109+
size_t start_day_of_year);
108110

109111
void SOC_controller() override;
110112
bool check_constraints(double &I, size_t count) override;
@@ -129,6 +131,8 @@ class dispatch_manual_t : public dispatch_t
129131
std::map<size_t, double> _percent_discharge_array;
130132
std::map<size_t, double> _percent_charge_array;
131133

134+
size_t _start_day_of_year;
135+
132136
};
133137

134138
#endif // __LIB_BATTERY_DISPATCH_MANUAL_H__

shared/lib_fuel_cell_dispatch.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939
#include "lib_power_electronics.h"
4040

4141

42-
FuelCellDispatch::FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, int dispatchOption, int shutdownOption, double dt_hour, double fixed_percent,
42+
FuelCellDispatch::FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, int dispatchOption, int shutdownOption, double dt_hour, double fixed_percent, size_t start_day_of_year,
4343
std::vector<double> dispatchInput_kW, std::vector<bool> canCharge, std::vector<bool> canDischarge,
4444
std::map<size_t, double> discharge_percent, std::map<size_t, size_t> discharge_units, util::matrix_t<size_t> scheduleWeekday, util::matrix_t<size_t> scheduleWeekend)
4545
: m_powerTotal_kW(0), m_numberOfUnits(numberOfUnits), m_dispatchOption(dispatchOption), m_shutdownOption(shutdownOption), dt_hour(dt_hour), m_fixed_percent(fixed_percent * 0.01),
4646
m_dispatchInput_kW(dispatchInput_kW), m_canCharge(canCharge), m_canDischarge(canDischarge),
4747
m_discharge_percent(discharge_percent), m_discharge_units(discharge_units),
48-
m_scheduleWeekday(scheduleWeekday), m_scheduleWeekend(scheduleWeekend)
48+
m_scheduleWeekday(scheduleWeekday), m_scheduleWeekend(scheduleWeekend),
49+
m_start_day_of_year(start_day_of_year)
4950
{
5051
// Convert percentages to fractions
5152
for (auto percent = m_discharge_percent.begin(); percent != m_discharge_percent.end(); percent++) {
@@ -75,7 +76,7 @@ FuelCellDispatch::FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, in
7576
else if (m_dispatchOption == FuelCellDispatch::FC_DISPATCH_OPTION::MANUAL) {
7677
size_t period = m_scheduleWeekday(0, 0);
7778

78-
if (!util::weekday(0)) {
79+
if (!util::weekday(0, m_start_day_of_year)) {
7980
period = m_scheduleWeekend(0, 0);
8081
}
8182
double discharge_percent_init = 0;
@@ -163,7 +164,7 @@ void FuelCellDispatch::runSingleTimeStep(size_t hour_of_year, size_t year_idx, d
163164
util::month_hour(hour_of_year, month, hour);
164165
size_t period = m_scheduleWeekday(month - 1, hour - 1);
165166

166-
if (!util::weekday(hour_of_year)) {
167+
if (!util::weekday(hour_of_year, m_start_day_of_year)) {
167168
period = m_scheduleWeekend(month - 1, hour - 1);
168169
}
169170

shared/lib_fuel_cell_dispatch.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class FuelCellDispatch
4848
/// Construct with arguments
4949
FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, int dispatchOption, int shutdownOption, double dt_hour,
5050
double fixed_percent,
51+
size_t start_day_of_year,
5152
std::vector<double> dispatchInput_kW,
5253
std::vector<bool> canCharge,
5354
std::vector<bool> canDischarge,
@@ -115,6 +116,7 @@ class FuelCellDispatch
115116
int m_shutdownOption;
116117
double dt_hour;
117118
double m_fixed_percent;
119+
size_t m_start_day_of_year;
118120

119121
std::vector<double> m_dispatchInput_kW;
120122
std::vector< FuelCell *> m_fuelCellVector;

shared/lib_time.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ template void single_year_to_lifetime_interpolated<float>(bool, size_t, size_t,
152152
* \param[out] flat_vector - The 8760*steps per hour values at each hour
153153
*/
154154
template <class T>
155-
std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::matrix_t<size_t> weekend_schedule, size_t steps_per_hour, std::vector<T> period_values, T multiplier)
155+
std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::matrix_t<size_t> weekend_schedule, size_t steps_per_hour, std::vector<T> period_values, size_t start_day_of_year, T multiplier)
156156
{
157157
std::vector<T> flat_vector;
158158
flat_vector.reserve(8760 * steps_per_hour);
@@ -162,7 +162,7 @@ std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::ma
162162
for (size_t hour_of_year = 0; hour_of_year != 8760; hour_of_year++)
163163
{
164164
util::month_hour(hour_of_year % 8760, month, hour);
165-
if (util::weekday(hour_of_year))
165+
if (util::weekday(hour_of_year, start_day_of_year))
166166
iprofile = weekday_schedule(month - 1, hour - 1);
167167
else
168168
iprofile = weekend_schedule(month - 1, hour - 1);
@@ -175,7 +175,7 @@ std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::ma
175175
return flat_vector;
176176
}
177177

178-
template std::vector<double> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::matrix_t<size_t> weekend_schedule, size_t steps_per_hour, std::vector<double> period_values, double multiplier);
178+
template std::vector<double> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::matrix_t<size_t> weekend_schedule, size_t steps_per_hour, std::vector<double> period_values, size_t start_day_of_year, double multiplier);
179179

180180

181181
/**

shared/lib_time.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Function takes in a weekday and weekend schedule, plus the period values and an
6161
a vector
6262
*/
6363
template<typename T>
64-
std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::matrix_t<size_t> weekend_schedule, size_t steps_per_hour, std::vector<T> period_values, T multiplier = 1.0);
64+
std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::matrix_t<size_t> weekend_schedule, size_t steps_per_hour, std::vector<T> period_values, size_t start_day_of_year, T multiplier = 1.0);
6565

6666
/**
6767
Function takes input values, desired steps per hour, and an optional multiplier and returns

shared/lib_util.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,10 @@ size_t util::hour_of_year(size_t month, size_t day, size_t hour)
949949
return h;
950950
}
951951

952-
bool util::weekday(size_t hour_of_year)
952+
bool util::weekday(size_t hour_of_year, size_t start_day_of_year)
953953
{
954954
int day_of_year = (int)(floor((float)(hour_of_year) / 24));
955-
int day_of_week = day_of_year;
955+
int day_of_week = day_of_year + start_day_of_year;
956956

957957
if (day_of_week > 6)
958958
day_of_week = day_of_year % 7;
@@ -1033,7 +1033,7 @@ std::string util::schedule_int_to_month( int m )
10331033
return ret;
10341034
}
10351035

1036-
bool util::translate_schedule( int tod[8760], const char *wkday, const char *wkend, int min_val, int max_val)
1036+
bool util::translate_schedule( int tod[8760], const char *wkday, const char *wkend, int min_val, int max_val, int start_day)
10371037
{
10381038
size_t i=0;
10391039
if (!wkday || !wkend || strlen(wkday) != 288 || strlen(wkend) != 288)
@@ -1042,7 +1042,7 @@ bool util::translate_schedule( int tod[8760], const char *wkday, const char *wke
10421042
return false;
10431043
}
10441044

1045-
int wday = 5;
1045+
int wday = 5 - start_day; // start_day: 0 == Monday, 6 == Sunday
10461046
for (size_t m=0;m<12;m++)
10471047
{
10481048
for (size_t d=0;d<nday[m];d++)
@@ -1066,7 +1066,7 @@ bool util::translate_schedule( int tod[8760], const char *wkday, const char *wke
10661066
}
10671067

10681068

1069-
bool util::translate_schedule(int tod[8760], const matrix_t<double> &wkday, const matrix_t<double> &wkend, int min_val, int max_val)
1069+
bool util::translate_schedule(int tod[8760], const matrix_t<double> &wkday, const matrix_t<double> &wkend, int min_val, int max_val, int start_day)
10701070
{
10711071
size_t i = 0;
10721072
if ((wkday.nrows() != 12) || (wkend.nrows() != 12) || (wkday.ncols() != 24) || (wkend.ncols() != 24) )
@@ -1075,7 +1075,7 @@ bool util::translate_schedule(int tod[8760], const matrix_t<double> &wkday, cons
10751075
return false;
10761076
}
10771077

1078-
int wday = 5; // start on Monday
1078+
int wday = 5 - start_day; // start_day: 0 == Monday, 6 == Sunday
10791079
bool is_weekday = true;
10801080
for (size_t m = 0; m<12; m++)
10811081
{

shared/lib_util.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@ namespace util
140140
int day_of_month(int month, double time); /* month: 1-12 time: hours, starting 0=jan 1st 12am, returns 1-nday*/
141141
int days_in_month(int month); /*month: 0-11, return 0-30, depending on the month*/
142142
void month_hour(size_t hour_of_year, size_t & out_month, size_t & out_hour); /*given the hour of year, return the month, and hour of day*/
143-
bool weekday(size_t hour_of_year); /* return true if is a weekday, assuming first hour of year is Monday at 12 am*/
143+
bool weekday(size_t hour_of_year, size_t start_day_of_year); /* return true if is a weekday, start day of year = 0 is Monday at 12 am*/
144144
size_t lifetimeIndex(size_t year, size_t hour_of_year, size_t step_of_hour, size_t steps_per_hour);
145145
size_t yearOneIndex(double dtHour, size_t lifetimeIndex);
146146
size_t yearIndex(size_t year, size_t month, size_t day, size_t hour, double minute, size_t step_per_hour);
147147

148148
int schedule_char_to_int( char c );
149149
std::string schedule_int_to_month( int m );
150-
bool translate_schedule(int tod[8760], const char *wkday, const char *wkend, int min_val, int max_val);
150+
bool translate_schedule(int tod[8760], const char *wkday, const char *wkend, int min_val, int max_val, int start_day);
151151

152152
bool file_exists( const char *file );
153153
bool dir_exists( const char *path );
@@ -860,7 +860,7 @@ namespace util
860860
double linterp_col( const matrix_t<double> &mat, size_t ixcol, double xval, size_t iycol );
861861
size_t nearest_col_index(const matrix_t<double>& mat, size_t col, double val);
862862
size_t nearest_col_index(const std::vector<std::vector<double>>& mat, size_t col, double val);
863-
bool translate_schedule(int tod[8760], const matrix_t<double> &wkday, const matrix_t<double> &wkend, int min_val, int max_val);
863+
bool translate_schedule(int tod[8760], const matrix_t<double> &wkday, const matrix_t<double> &wkend, int min_val, int max_val, int start_day);
864864

865865
std::vector<double> frequency_table(double* values, size_t n_vals, double bin_width);
866866
};

shared/lib_utility_rate.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3939

4040
UtilityRate::UtilityRate(
4141
bool useRealTimePrices,
42+
size_t start_day_of_year,
4243
util::matrix_t<size_t> ecWeekday,
4344
util::matrix_t<size_t> ecWeekend,
4445
util::matrix_t<double> ecRatesMatrix,
4546
std::vector<double> ecRealTimeBuy)
4647
{
47-
m_useRealTimePrices = useRealTimePrices,
48+
m_useRealTimePrices = useRealTimePrices;
49+
m_start_day_of_year = start_day_of_year;
4850
m_ecWeekday = ecWeekday;
4951
m_ecWeekend = ecWeekend;
5052
m_ecRatesMatrix = ecRatesMatrix;
@@ -53,6 +55,7 @@ UtilityRate::UtilityRate(
5355

5456
UtilityRate::UtilityRate(const UtilityRate& tmp){
5557
m_useRealTimePrices = tmp.m_useRealTimePrices;
58+
m_start_day_of_year = tmp.m_start_day_of_year;
5659
m_ecWeekday = tmp.m_ecWeekday;
5760
m_ecWeekend = tmp.m_ecWeekend;
5861
m_ecRatesMatrix = tmp.m_ecRatesMatrix;
@@ -144,7 +147,7 @@ size_t UtilityRateCalculator::getEnergyPeriod(size_t hourOfYear)
144147
size_t period, month, hour;
145148
util::month_hour(hourOfYear, month, hour);
146149

147-
if (util::weekday(hourOfYear)) {
150+
if (util::weekday(hourOfYear, m_start_day_of_year)) {
148151
if (m_ecWeekday.nrows() == 1 && m_ecWeekday.ncols() == 1) {
149152
period = m_ecWeekday.at(0, 0);
150153
}

shared/lib_utility_rate.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class UtilityRate
5050
UtilityRate(){};
5151

5252
UtilityRate(bool useRealTimePrices,
53+
size_t start_day_of_year,
5354
util::matrix_t<size_t> ecWeekday,
5455
util::matrix_t<size_t> ecWeekend,
5556
util::matrix_t<double> ecRatesMatrix,
@@ -77,6 +78,11 @@ class UtilityRate
7778

7879
/// Use real time prices or not
7980
bool m_useRealTimePrices;
81+
82+
/// <summary>
83+
/// Monday = 0, Sunday = 6
84+
/// </summary>
85+
size_t m_start_day_of_year;
8086
};
8187

8288
class UtilityRateCalculator : protected UtilityRate

0 commit comments

Comments
 (0)