Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions shared/lib_battery_dispatch_manual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ dispatch_manual_t::dispatch_manual_t(battery_t * Battery, double dt, double SOC_
util::matrix_t<size_t> dm_dynamic_sched, util::matrix_t<size_t> dm_dynamic_sched_weekend,
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,
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,
size_t start_day_of_year,
bool chargeOnlySystemExceedLoad, bool dischargeOnlyLoadExceedSystem, double SOC_min_outage, bool priorityChargeBattery)
: 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,
t_min, mode, battMeterPosition, interconnection_limit, chargeOnlySystemExceedLoad, dischargeOnlyLoadExceedSystem, SOC_min_outage)
{
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);
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, start_day_of_year);
}

void dispatch_manual_t::init_with_vects(
Expand All @@ -64,7 +66,8 @@ void dispatch_manual_t::init_with_vects(
std::map<size_t, double> dm_percent_gridcharge,
bool can_clip_charge,
bool can_curtail_charge,
bool priorityChargeBattery)
bool priorityChargeBattery,
size_t start_day_of_year)
{
_sched = dm_dynamic_sched;
_sched_weekend = dm_dynamic_sched_weekend;
Expand All @@ -79,6 +82,7 @@ void dispatch_manual_t::init_with_vects(
_can_curtail_charge = can_curtail_charge;
_priority_charge_battery = priorityChargeBattery;
_iprofile = 0;
_start_day_of_year = start_day_of_year;
}

// deep copy from dispatch to this
Expand All @@ -88,7 +92,7 @@ dispatch_t(dispatch)
const dispatch_manual_t * tmp = dynamic_cast<const dispatch_manual_t *>(&dispatch);
init_with_vects(tmp->_sched, tmp->_sched_weekend,
tmp->_charge_array, tmp->_discharge_array, tmp->_gridcharge_array, tmp->_fuelcellcharge_array, tmp->_discharge_grid_array,
tmp->_percent_discharge_array, tmp->_percent_charge_array, tmp->_can_clip_charge, tmp->_can_curtail_charge, tmp->_priority_charge_battery);
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);
}

// shallow copy from dispatch to this
Expand All @@ -98,7 +102,7 @@ void dispatch_manual_t::copy(const dispatch_t * dispatch)
const dispatch_manual_t * tmp = dynamic_cast<const dispatch_manual_t *>(dispatch);
init_with_vects(tmp->_sched, tmp->_sched_weekend,
tmp->_charge_array, tmp->_discharge_array, tmp->_gridcharge_array, tmp->_fuelcellcharge_array, tmp->_discharge_grid_array,
tmp->_percent_discharge_array, tmp->_percent_charge_array, tmp->_can_clip_charge, tmp->_can_curtail_charge, tmp->_priority_charge_battery);
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);
}

void dispatch_manual_t::prepareDispatch(size_t hour_of_year, size_t )
Expand All @@ -108,7 +112,7 @@ void dispatch_manual_t::prepareDispatch(size_t hour_of_year, size_t )
size_t column = h - 1;
_iprofile = 0;

bool is_weekday = util::weekday(hour_of_year);
bool is_weekday = util::weekday(hour_of_year, _start_day_of_year);
if (!is_weekday && _mode == MANUAL)
_iprofile = _sched_weekend(m - 1, column);
else
Expand Down
6 changes: 5 additions & 1 deletion shared/lib_battery_dispatch_manual.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class dispatch_manual_t : public dispatch_t
bool can_clip_charge,
bool can_curtail_charge,
double interconnection_limit,
size_t start_day_of_year,
bool chargeOnlySystemExceedLoad = true,
bool dischargeOnlyLoadExceedSystem = true,
double SOC_min_outage = 0.0,
Expand Down Expand Up @@ -104,7 +105,8 @@ class dispatch_manual_t : public dispatch_t
std::map<size_t, double> dm_percent_gridcharge,
bool can_clip_charge,
bool can_curtail_charge,
bool priorityChargeBattery);
bool priorityChargeBattery,
size_t start_day_of_year);

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

size_t _start_day_of_year;

};

#endif // __LIB_BATTERY_DISPATCH_MANUAL_H__
9 changes: 5 additions & 4 deletions shared/lib_fuel_cell_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "lib_power_electronics.h"


FuelCellDispatch::FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, int dispatchOption, int shutdownOption, double dt_hour, double fixed_percent,
FuelCellDispatch::FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, int dispatchOption, int shutdownOption, double dt_hour, double fixed_percent, size_t start_day_of_year,
std::vector<double> dispatchInput_kW, std::vector<bool> canCharge, std::vector<bool> canDischarge,
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)
: m_powerTotal_kW(0), m_numberOfUnits(numberOfUnits), m_dispatchOption(dispatchOption), m_shutdownOption(shutdownOption), dt_hour(dt_hour), m_fixed_percent(fixed_percent * 0.01),
m_dispatchInput_kW(dispatchInput_kW), m_canCharge(canCharge), m_canDischarge(canDischarge),
m_discharge_percent(discharge_percent), m_discharge_units(discharge_units),
m_scheduleWeekday(scheduleWeekday), m_scheduleWeekend(scheduleWeekend)
m_scheduleWeekday(scheduleWeekday), m_scheduleWeekend(scheduleWeekend),
m_start_day_of_year(start_day_of_year)
{
// Convert percentages to fractions
for (auto percent = m_discharge_percent.begin(); percent != m_discharge_percent.end(); percent++) {
Expand Down Expand Up @@ -75,7 +76,7 @@ FuelCellDispatch::FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, in
else if (m_dispatchOption == FuelCellDispatch::FC_DISPATCH_OPTION::MANUAL) {
size_t period = m_scheduleWeekday(0, 0);

if (!util::weekday(0)) {
if (!util::weekday(0, m_start_day_of_year)) {
period = m_scheduleWeekend(0, 0);
}
double discharge_percent_init = 0;
Expand Down Expand Up @@ -163,7 +164,7 @@ void FuelCellDispatch::runSingleTimeStep(size_t hour_of_year, size_t year_idx, d
util::month_hour(hour_of_year, month, hour);
size_t period = m_scheduleWeekday(month - 1, hour - 1);

if (!util::weekday(hour_of_year)) {
if (!util::weekday(hour_of_year, m_start_day_of_year)) {
period = m_scheduleWeekend(month - 1, hour - 1);
}

Expand Down
2 changes: 2 additions & 0 deletions shared/lib_fuel_cell_dispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FuelCellDispatch
/// Construct with arguments
FuelCellDispatch(FuelCell * fuelCell, size_t numberOfUnits, int dispatchOption, int shutdownOption, double dt_hour,
double fixed_percent,
size_t start_day_of_year,
std::vector<double> dispatchInput_kW,
std::vector<bool> canCharge,
std::vector<bool> canDischarge,
Expand Down Expand Up @@ -115,6 +116,7 @@ class FuelCellDispatch
int m_shutdownOption;
double dt_hour;
double m_fixed_percent;
size_t m_start_day_of_year;

std::vector<double> m_dispatchInput_kW;
std::vector< FuelCell *> m_fuelCellVector;
Expand Down
6 changes: 3 additions & 3 deletions shared/lib_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ template void single_year_to_lifetime_interpolated<float>(bool, size_t, size_t,
* \param[out] flat_vector - The 8760*steps per hour values at each hour
*/
template <class T>
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)
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)
{
std::vector<T> flat_vector;
flat_vector.reserve(8760 * steps_per_hour);
Expand All @@ -162,7 +162,7 @@ std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::ma
for (size_t hour_of_year = 0; hour_of_year != 8760; hour_of_year++)
{
util::month_hour(hour_of_year % 8760, month, hour);
if (util::weekday(hour_of_year))
if (util::weekday(hour_of_year, start_day_of_year))
iprofile = weekday_schedule(month - 1, hour - 1);
else
iprofile = weekend_schedule(month - 1, hour - 1);
Expand All @@ -175,7 +175,7 @@ std::vector<T> flatten_diurnal(util::matrix_t<size_t> weekday_schedule, util::ma
return flat_vector;
}

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);
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);


/**
Expand Down
2 changes: 1 addition & 1 deletion shared/lib_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Function takes in a weekday and weekend schedule, plus the period values and an
a vector
*/
template<typename T>
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);
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);

/**
Function takes input values, desired steps per hour, and an optional multiplier and returns
Expand Down
12 changes: 6 additions & 6 deletions shared/lib_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,10 +949,10 @@ size_t util::hour_of_year(size_t month, size_t day, size_t hour)
return h;
}

bool util::weekday(size_t hour_of_year)
bool util::weekday(size_t hour_of_year, size_t start_day_of_year)
{
int day_of_year = (int)(floor((float)(hour_of_year) / 24));
int day_of_week = day_of_year;
int day_of_week = day_of_year + start_day_of_year;

if (day_of_week > 6)
day_of_week = day_of_year % 7;
Expand Down Expand Up @@ -1033,7 +1033,7 @@ std::string util::schedule_int_to_month( int m )
return ret;
}

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

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


bool util::translate_schedule(int tod[8760], const matrix_t<double> &wkday, const matrix_t<double> &wkend, int min_val, int max_val)
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)
{
size_t i = 0;
if ((wkday.nrows() != 12) || (wkend.nrows() != 12) || (wkday.ncols() != 24) || (wkend.ncols() != 24) )
Expand All @@ -1075,7 +1075,7 @@ bool util::translate_schedule(int tod[8760], const matrix_t<double> &wkday, cons
return false;
}

int wday = 5; // start on Monday
int wday = 5 - start_day; // start_day: 0 == Monday, 6 == Sunday
bool is_weekday = true;
for (size_t m = 0; m<12; m++)
{
Expand Down
6 changes: 3 additions & 3 deletions shared/lib_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ namespace util
int day_of_month(int month, double time); /* month: 1-12 time: hours, starting 0=jan 1st 12am, returns 1-nday*/
int days_in_month(int month); /*month: 0-11, return 0-30, depending on the month*/
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*/
bool weekday(size_t hour_of_year); /* return true if is a weekday, assuming first hour of year is Monday at 12 am*/
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*/
size_t lifetimeIndex(size_t year, size_t hour_of_year, size_t step_of_hour, size_t steps_per_hour);
size_t yearOneIndex(double dtHour, size_t lifetimeIndex);
size_t yearIndex(size_t year, size_t month, size_t day, size_t hour, double minute, size_t step_per_hour);

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

bool file_exists( const char *file );
bool dir_exists( const char *path );
Expand Down Expand Up @@ -860,7 +860,7 @@ namespace util
double linterp_col( const matrix_t<double> &mat, size_t ixcol, double xval, size_t iycol );
size_t nearest_col_index(const matrix_t<double>& mat, size_t col, double val);
size_t nearest_col_index(const std::vector<std::vector<double>>& mat, size_t col, double val);
bool translate_schedule(int tod[8760], const matrix_t<double> &wkday, const matrix_t<double> &wkend, int min_val, int max_val);
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);

std::vector<double> frequency_table(double* values, size_t n_vals, double bin_width);
};
Expand Down
7 changes: 5 additions & 2 deletions shared/lib_utility_rate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

UtilityRate::UtilityRate(
bool useRealTimePrices,
size_t start_day_of_year,
util::matrix_t<size_t> ecWeekday,
util::matrix_t<size_t> ecWeekend,
util::matrix_t<double> ecRatesMatrix,
std::vector<double> ecRealTimeBuy)
{
m_useRealTimePrices = useRealTimePrices,
m_useRealTimePrices = useRealTimePrices;
m_start_day_of_year = start_day_of_year;
m_ecWeekday = ecWeekday;
m_ecWeekend = ecWeekend;
m_ecRatesMatrix = ecRatesMatrix;
Expand All @@ -53,6 +55,7 @@ UtilityRate::UtilityRate(

UtilityRate::UtilityRate(const UtilityRate& tmp){
m_useRealTimePrices = tmp.m_useRealTimePrices;
m_start_day_of_year = tmp.m_start_day_of_year;
m_ecWeekday = tmp.m_ecWeekday;
m_ecWeekend = tmp.m_ecWeekend;
m_ecRatesMatrix = tmp.m_ecRatesMatrix;
Expand Down Expand Up @@ -144,7 +147,7 @@ size_t UtilityRateCalculator::getEnergyPeriod(size_t hourOfYear)
size_t period, month, hour;
util::month_hour(hourOfYear, month, hour);

if (util::weekday(hourOfYear)) {
if (util::weekday(hourOfYear, m_start_day_of_year)) {
if (m_ecWeekday.nrows() == 1 && m_ecWeekday.ncols() == 1) {
period = m_ecWeekday.at(0, 0);
}
Expand Down
6 changes: 6 additions & 0 deletions shared/lib_utility_rate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class UtilityRate
UtilityRate(){};

UtilityRate(bool useRealTimePrices,
size_t start_day_of_year,
util::matrix_t<size_t> ecWeekday,
util::matrix_t<size_t> ecWeekend,
util::matrix_t<double> ecRatesMatrix,
Expand Down Expand Up @@ -77,6 +78,11 @@ class UtilityRate

/// Use real time prices or not
bool m_useRealTimePrices;

/// <summary>
/// Monday = 0, Sunday = 6
/// </summary>
size_t m_start_day_of_year;
};

class UtilityRateCalculator : protected UtilityRate
Expand Down
8 changes: 4 additions & 4 deletions shared/lib_utility_rate_equations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ void rate_data::setup_time_series(size_t cnt, ssc_number_t* ts_sr, ssc_number_t*
}

void rate_data::setup_energy_rates(ssc_number_t* ec_weekday, ssc_number_t* ec_weekend,
size_t ec_tou_rows, ssc_number_t* ec_tou_in, bool sell_eq_buy)
size_t ec_tou_rows, ssc_number_t* ec_tou_in, bool sell_eq_buy, size_t start_day_of_year)
{
size_t nrows, ncols, r, c, m, i, j;
int period, tier;
Expand All @@ -527,7 +527,7 @@ void rate_data::setup_energy_rates(ssc_number_t* ec_weekday, ssc_number_t* ec_we

size_t max_tou_periods = 36;

if (!util::translate_schedule(ec_tod, ec_schedwkday, ec_schedwkend, 1, max_tou_periods))
if (!util::translate_schedule(ec_tod, ec_schedwkday, ec_schedwkend, 1, max_tou_periods, start_day_of_year))
throw general_error("Could not translate weekday and weekend schedules for energy rates.");
for (i = 0; i < 8760; i++)
{
Expand Down Expand Up @@ -711,7 +711,7 @@ void rate_data::setup_energy_rates(ssc_number_t* ec_weekday, ssc_number_t* ec_we
}

void rate_data::setup_demand_charges(ssc_number_t* dc_weekday, ssc_number_t* dc_weekend,
size_t dc_tou_rows, ssc_number_t* dc_tou_in, size_t dc_flat_rows, ssc_number_t* dc_flat_in) {
size_t dc_tou_rows, ssc_number_t* dc_tou_in, size_t dc_flat_rows, ssc_number_t* dc_flat_in, size_t start_day_of_year) {
size_t nrows, ncols, r, c, m, i, j, idx;
int period, tier, month;

Expand All @@ -734,7 +734,7 @@ void rate_data::setup_demand_charges(ssc_number_t* dc_weekday, ssc_number_t* dc_

size_t max_tou_periods = 36;

if (!util::translate_schedule(dc_tod, dc_schedwkday, dc_schedwkend, 1, max_tou_periods))
if (!util::translate_schedule(dc_tod, dc_schedwkday, dc_schedwkend, 1, max_tou_periods, start_day_of_year))
throw general_error("Could not translate weekday and weekend schedules for demand charges");

idx = 0;
Expand Down
4 changes: 2 additions & 2 deletions shared/lib_utility_rate_equations.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ class rate_data {
/* Optional function if time series buy or sell rates are being used */
void setup_time_series(size_t cnt, ssc_number_t* ts_sr, ssc_number_t* ts_br);
/* Required function for setting up energy rate data */
void setup_energy_rates(ssc_number_t* ec_weekday, ssc_number_t* ec_weekend, size_t ec_tou_rows, ssc_number_t* ec_tou_in, bool sell_eq_buy);
void setup_energy_rates(ssc_number_t* ec_weekday, ssc_number_t* ec_weekend, size_t ec_tou_rows, ssc_number_t* ec_tou_in, bool sell_eq_buy, size_t start_day_of_year);
/* Optional function if demand charges are present */
void setup_demand_charges(ssc_number_t* dc_weekday, ssc_number_t* dc_weekend, size_t dc_tou_rows, ssc_number_t* dc_tou_in, size_t dc_flat_rows, ssc_number_t* dc_flat_in);
void setup_demand_charges(ssc_number_t* dc_weekday, ssc_number_t* dc_weekend, size_t dc_tou_rows, ssc_number_t* dc_tou_in, size_t dc_flat_rows, ssc_number_t* dc_flat_in, size_t start_day_of_year);
/* Optional function if energy charges use a ratchet for the billing demand - returns error code based on data validitiy (at least one active period) */
bool setup_ratcheting_demand(ssc_number_t* ratchet_percent_matrix, ssc_number_t* bd_tou_period_matrix);

Expand Down
Loading
Loading