Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to create Holiday Schedules in ScheduleRuleset #3814

Merged
merged 18 commits into from
Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 5 additions & 7 deletions resources/model/OpenStudio.idd
Original file line number Diff line number Diff line change
Expand Up @@ -4742,12 +4742,7 @@ OS:Schedule:Rule,
\default No
\key Yes
\key No
A12, \field Apply Holiday
\type choice
\default No
\key Yes
\key No
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this (currently unused) field from Schedule:Rule. Handled in Version Translation.

A13, \field Date Specification Type
A12, \field Date Specification Type
\type choice
\default DateRange
\key DateRange
Expand Down Expand Up @@ -4804,7 +4799,10 @@ OS:Schedule:Ruleset,
A5, \field Summer Design Day Schedule Name
\type object-list
\object-list DayScheduleNames
A6; \field Winter Design Day Schedule Name
A6, \field Winter Design Day Schedule Name
\type object-list
\object-list DayScheduleNames
A7; \field Holiday Schedule Name
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New field on Schedule:Ruleset

\type object-list
\object-list DayScheduleNames

Expand Down
1 change: 1 addition & 0 deletions src/energyplus/ForwardTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ Workspace ForwardTranslator::translateModelPrivate( model::Model & model, bool f
}


// TODO: is it time to uncomment that?
// temp code
if (!m_keepRunControlSpecialDays){
// DLM: we will not translate these objects until we support holidays in the GUI
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's time to uncomment that.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct WeekScheduleStruct{
std::string thursdaySchedule;
std::string fridaySchedule;
std::string saturdaySchedule;
std::string holidayDaySchedule;
std::string holidaySchedule;
std::string summerDesignDaySchedule;
std::string winterDesignDaySchedule;
std::string customDay1Schedule;
Expand Down Expand Up @@ -100,7 +100,7 @@ struct WeekScheduleStruct{
thursdaySchedule == other.thursdaySchedule &&
fridaySchedule == other.fridaySchedule &&
saturdaySchedule == other.saturdaySchedule &&
holidayDaySchedule == other.holidayDaySchedule &&
holidaySchedule == other.holidaySchedule &&
summerDesignDaySchedule == other.summerDesignDaySchedule &&
winterDesignDaySchedule == other.winterDesignDaySchedule &&
customDay1Schedule == other.customDay1Schedule &&
Expand All @@ -118,7 +118,7 @@ struct WeekScheduleStruct{
weekSchedule.setString(Schedule_Week_DailyFields::ThursdaySchedule_DayName, thursdaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::FridaySchedule_DayName, fridaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::SaturdaySchedule_DayName, saturdaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::HolidaySchedule_DayName, holidayDaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::HolidaySchedule_DayName, holidaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::SummerDesignDaySchedule_DayName, summerDesignDaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::WinterDesignDaySchedule_DayName, winterDesignDaySchedule);
weekSchedule.setString(Schedule_Week_DailyFields::CustomDay1Schedule_DayName, customDay1Schedule);
Expand Down Expand Up @@ -149,6 +149,8 @@ boost::optional<IdfObject> ForwardTranslator::translateScheduleRuleset( Schedule
ScheduleDay defaultDaySchedule = modelObject.defaultDaySchedule();
ScheduleDay summerDesignDaySchedule = modelObject.summerDesignDaySchedule();
ScheduleDay winterDesignDaySchedule = modelObject.winterDesignDaySchedule();
// ScheduleRuleset is the one carrying the Holiday Schedule
ScheduleDay holidaySchedule = modelObject.holidaySchedule();

// initialize day of week schedules
ScheduleDay sundaySchedule = defaultDaySchedule;
Expand All @@ -160,7 +162,6 @@ boost::optional<IdfObject> ForwardTranslator::translateScheduleRuleset( Schedule
ScheduleDay saturdaySchedule = defaultDaySchedule;

// these are not yet exposed
ScheduleDay holidayDaySchedule = defaultDaySchedule;
ScheduleDay customDay1Schedule = defaultDaySchedule;
ScheduleDay customDay2Schedule = defaultDaySchedule;

Expand Down Expand Up @@ -243,9 +244,11 @@ boost::optional<IdfObject> ForwardTranslator::translateScheduleRuleset( Schedule
weekSchedule->thursdaySchedule = thursdaySchedule.name().get();
weekSchedule->fridaySchedule = fridaySchedule.name().get();
weekSchedule->saturdaySchedule = saturdaySchedule.name().get();
weekSchedule->holidayDaySchedule = holidayDaySchedule.name().get();
// from Schedule:Ruleset
weekSchedule->holidaySchedule = holidaySchedule.name().get();
weekSchedule->summerDesignDaySchedule = summerDesignDaySchedule.name().get();
weekSchedule->winterDesignDaySchedule = winterDesignDaySchedule.name().get();
// Not exposed yet
weekSchedule->customDay1Schedule = customDay1Schedule.name().get();
weekSchedule->customDay2Schedule = customDay2Schedule.name().get();

Expand Down Expand Up @@ -309,7 +312,7 @@ boost::optional<IdfObject> ForwardTranslator::translateScheduleRuleset( Schedule
weekSchedule->thursdaySchedule = thursdaySchedule.name().get();
weekSchedule->fridaySchedule = fridaySchedule.name().get();
weekSchedule->saturdaySchedule = saturdaySchedule.name().get();
weekSchedule->holidayDaySchedule = holidayDaySchedule.name().get();
weekSchedule->holidaySchedule = holidaySchedule.name().get();
weekSchedule->summerDesignDaySchedule = summerDesignDaySchedule.name().get();
weekSchedule->winterDesignDaySchedule = winterDesignDaySchedule.name().get();
weekSchedule->customDay1Schedule = customDay1Schedule.name().get();
Expand Down Expand Up @@ -409,10 +412,12 @@ boost::optional<IdfObject> ForwardTranslator::translateScheduleRuleset( Schedule
ScheduleDay defaultDaySchedule = modelObject.defaultDaySchedule();
ScheduleDay summerDesignDaySchedule = modelObject.summerDesignDaySchedule();
ScheduleDay winterDesignDaySchedule = modelObject.winterDesignDaySchedule();
ScheduleDay holidaySchedule = modelObject.holidaySchedule();

translateAndMapModelObject(defaultDaySchedule);
translateAndMapModelObject(summerDesignDaySchedule);
translateAndMapModelObject(winterDesignDaySchedule);
translateAndMapModelObject(holidaySchedule);

// translate schedule rules, these are returned in order
for (ScheduleRule scheduleRule : modelObject.scheduleRules()){
Expand Down
84 changes: 84 additions & 0 deletions src/energyplus/Test/ScheduleRuleset_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,3 +541,87 @@ TEST_F(EnergyPlusFixture, ForwardTranslator_ScheduleWeek_Bug243_3)

EXPECT_EQ("Schedule Ruleset Week Rule - Dec28-Dec31", _scheduleWeekDaily3->nameString());
}

TEST_F(EnergyPlusFixture,ForwardTranslator_SpecialDays)
{

Model model;
model::YearDescription yd = model.getUniqueModelObject<model::YearDescription>();
EXPECT_TRUE(yd.setDayofWeekforStartDay("Sunday"));

ScheduleRuleset scheduleRuleset(model);
scheduleRuleset.setName("Schedule Ruleset");
ScheduleDay defaultDaySchedule = scheduleRuleset.defaultDaySchedule();
defaultDaySchedule.setName("Default Day Schedule");

// Add Special Days schedules
scheduleRuleset.setSummerDesignDaySchedule(defaultDaySchedule);
ScheduleDay summerDesignDaySchedule = scheduleRuleset.summerDesignDaySchedule();
summerDesignDaySchedule.setName("Summer Design Day Schedule");

scheduleRuleset.setWinterDesignDaySchedule(defaultDaySchedule);
ScheduleDay winterDesignDaySchedule = scheduleRuleset.winterDesignDaySchedule();
winterDesignDaySchedule.setName("Winter Design Day Schedule");

scheduleRuleset.setHolidaySchedule(defaultDaySchedule);
ScheduleDay holidaySchedule = scheduleRuleset.holidaySchedule();
holidaySchedule.setName("Holiday Schedule");


// annual weekday rule
ScheduleRule weekdayRule(scheduleRuleset);
weekdayRule.setName("All Year Weekdays Rule");
ScheduleDay weekdaySchedule = weekdayRule.daySchedule();
weekdaySchedule.setName("Weekdays Schedule");
weekdayRule.setApplySunday(false);
weekdayRule.setApplyMonday(true);
weekdayRule.setApplyTuesday(true);
weekdayRule.setApplyWednesday(true);
weekdayRule.setApplyThursday(true);
weekdayRule.setApplyFriday(true);
weekdayRule.setApplySaturday(false);

// annual weekend rule
ScheduleRule weekendRule(scheduleRuleset);
weekendRule.setName("All Year Weekends Rule");
ScheduleDay weekendSchedule = weekendRule.daySchedule();
weekendSchedule.setName("Weekends Schedule");
weekendRule.setApplyMonday(false);
weekendRule.setApplyTuesday(false);
weekendRule.setApplyWednesday(false);
weekendRule.setApplyThursday(false);
weekendRule.setApplyFriday(false);
weekendRule.setApplySaturday(true);
weekendRule.setApplySunday(true);

ForwardTranslator ft;
Workspace workspace = ft.translateModel(model);

std::vector<WorkspaceObject> scheduleYears = workspace.getObjectsByType(IddObjectType::Schedule_Year);
ASSERT_EQ(1u, scheduleYears.size());
std::vector<IdfExtensibleGroup> extensibleGroups = scheduleYears[0].extensibleGroups();
ASSERT_EQ(1u, extensibleGroups.size());
std::vector<WorkspaceObject> scheduleWeekDailys = workspace.getObjectsByType(IddObjectType::Schedule_Week_Daily);
ASSERT_EQ(1u, scheduleWeekDailys.size());
WorkspaceObject scheduleWeekDaily(scheduleWeekDailys[0]);

// Weekdays
EXPECT_EQ(weekdaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::MondaySchedule_DayName).get());
EXPECT_EQ(weekdaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::TuesdaySchedule_DayName).get());
EXPECT_EQ(weekdaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::WednesdaySchedule_DayName).get());
EXPECT_EQ(weekdaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::ThursdaySchedule_DayName).get());
EXPECT_EQ(weekdaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::FridaySchedule_DayName).get());

// Weekends
EXPECT_EQ(weekendSchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::SaturdaySchedule_DayName).get());
EXPECT_EQ(weekendSchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::SundaySchedule_DayName).get());

// Special Days
EXPECT_EQ(holidaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::HolidaySchedule_DayName).get());
EXPECT_EQ(summerDesignDaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::SummerDesignDaySchedule_DayName).get());
EXPECT_EQ(winterDesignDaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::WinterDesignDaySchedule_DayName).get());
// Not Exposed yet
EXPECT_EQ(defaultDaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::CustomDay1Schedule_DayName).get());
EXPECT_EQ(defaultDaySchedule.nameString(), scheduleWeekDaily.getString(Schedule_Week_DailyFields::CustomDay2Schedule_DayName).get());

}
10 changes: 10 additions & 0 deletions src/model/RunPeriodControlSpecialDays.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <utilities/idd/OS_RunPeriodControl_SpecialDays_FieldEnums.hxx>
#include <utilities/idd/IddEnums.hxx>
#include <utilities/idd/IddFactory.hxx>

#include "../utilities/time/Date.hpp"
#include "../utilities/core/Assert.hpp"
Expand Down Expand Up @@ -261,6 +262,15 @@ RunPeriodControlSpecialDays::RunPeriodControlSpecialDays(const openstudio::NthDa
Date test = this->startDate();
}

std::vector<std::string> RunPeriodControlSpecialDays::specialDayTypeValues() {
return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(),
OS_RunPeriodControl_SpecialDaysFields::SpecialDayType);
}

std::vector<std::string> RunPeriodControlSpecialDays::validSpecialDayTypeValues() {
return specialDayTypeValues();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhat unrelated, but I realized this didn't exist, so adding it (this object can be used to define new Special Day Type "Holiday", so it matters)

}

Date RunPeriodControlSpecialDays::startDate() const
{
return getImpl<detail::RunPeriodControlSpecialDays_Impl>()->startDate();
Expand Down
9 changes: 9 additions & 0 deletions src/model/RunPeriodControlSpecialDays.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ class MODEL_API RunPeriodControlSpecialDays : public ModelObject {

virtual ~RunPeriodControlSpecialDays() {}

/** @name Static Methods */
//@{

static std::vector<std::string> specialDayTypeValues();

// Forwards to specialDayTypeValues()
static std::vector<std::string> validSpecialDayTypeValues();


//@}
/** @name Getters */
//@{
Expand Down
88 changes: 0 additions & 88 deletions src/model/ScheduleRule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,6 @@ namespace detail {
OS_ASSERT(value);
return openstudio::istringEqual(value.get(), "Yes");
}
/*
bool ScheduleRule_Impl::applyHoliday() const {
boost::optional<std::string> value = getString(OS_Schedule_RuleFields::ApplyHoliday,true);
OS_ASSERT(value);
return openstudio::istringEqual(value.get(), "Yes");
}
*/
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting all already-commented-out regarding Apply Holiday in Schedule:Rule now that the IDD doesn't bear the field => No API change


std::string ScheduleRule_Impl::dateSpecificationType() const {
boost::optional<std::string> value = getString(OS_Schedule_RuleFields::DateSpecificationType,true);
Expand Down Expand Up @@ -347,49 +340,6 @@ namespace detail {
return result;
}

bool ScheduleRule_Impl::applyWeekdays() const {
return (this->applyMonday() && this->applyTuesday() && this-applyWednesday() && this->applyThursday() && this->applyFriday());
}

bool ScheduleRule_Impl::applyWeekends() const {
return (this->applySaturday() && this->applySunday());
}

bool ScheduleRule_Impl::applyAllDays() const {
return (this->applyWeekdays() && this->applyWeekends());
}

bool ScheduleRule_Impl::setApplyWeekdays(bool applyWeekdays) {
return (this->setApplyMonday(applyWeekdays) && this->setApplyTuesday(applyWeekdays) &&
this-setApplyWednesday(applyWeekdays) && this->setApplyThursday(applyWeekdays) && this->setApplyFriday(applyWeekdays));
}

bool ScheduleRule_Impl::setApplyWeekends(bool applyWeekends) {
return (this->setApplySaturday(applyWeekends) && this->setApplySunday(applyWeekends));
}

bool ScheduleRule_Impl::setApplyAllDays(bool applyAllDays) {
return (this->setApplyWeekdays(applyAllDays) && this->setApplyWeekends(applyAllDays));
}

/*
bool ScheduleRule_Impl::setApplyHoliday(bool applyHoliday) {
bool result = false;
if (applyHoliday) {
result = setString(OS_Schedule_RuleFields::ApplyHoliday, "Yes");
} else {
result = setString(OS_Schedule_RuleFields::ApplyHoliday, "No");
}
OS_ASSERT(result);
return result;
}

bool ScheduleRule_Impl::setDateSpecificationType(std::string dateSpecificationType) {
bool result = setString(OS_Schedule_RuleFields::DateSpecificationType, dateSpecificationType);
return result;
}
*/

bool ScheduleRule_Impl::setStartDate(const openstudio::Date& date) {
bool result = setString(OS_Schedule_RuleFields::DateSpecificationType, "DateRange");
OS_ASSERT(result);
Expand Down Expand Up @@ -715,11 +665,6 @@ bool ScheduleRule::applyFriday() const {
bool ScheduleRule::applySaturday() const {
return getImpl<detail::ScheduleRule_Impl>()->applySaturday();
}
/*
bool ScheduleRule::applyHoliday() const {
return getImpl<detail::ScheduleRule_Impl>()->applyHoliday();
}
*/

boost::optional<openstudio::Date> ScheduleRule::startDate() const
{
Expand Down Expand Up @@ -807,47 +752,14 @@ void ScheduleRule::setApplySaturdayNoFail(bool applySaturday) {
OS_ASSERT(result);
}

bool ScheduleRule::applyWeekdays() const {
return getImpl<detail::ScheduleRule_Impl>()->applyWeekdays();
}
bool ScheduleRule::setApplyWeekdays(bool applyWeekdays) {
return getImpl<detail::ScheduleRule_Impl>()->setApplyWeekdays(applyWeekdays);
}

bool ScheduleRule::applyWeekends() const {
return getImpl<detail::ScheduleRule_Impl>()->applyWeekends();
}
bool ScheduleRule::setApplyWeekends(bool applyWeekends) {
return getImpl<detail::ScheduleRule_Impl>()->setApplyWeekends(applyWeekends);
}

bool ScheduleRule::applyAllDays() const {
return getImpl<detail::ScheduleRule_Impl>()->applyAllDays();
}
bool ScheduleRule::setApplyAllDays(bool applyAllDays) {
return getImpl<detail::ScheduleRule_Impl>()->setApplyAllDays(applyAllDays);
}

/*
bool ScheduleRule::setApplyHoliday(bool applyHoliday) {
return getImpl<detail::ScheduleRule_Impl>()->setApplyHoliday(applyHoliday);
}

void ScheduleRule::setApplyHolidayNoFail(bool applyHoliday) {
bool result = getImpl<detail::ScheduleRule_Impl>()->setApplyHoliday(applyHoliday);
}
*/

bool ScheduleRule::setStartDate(const openstudio::Date& date) {
return getImpl<detail::ScheduleRule_Impl>()->setStartDate(date);
}


bool ScheduleRule::setEndDate(const openstudio::Date& date) {
return getImpl<detail::ScheduleRule_Impl>()->setEndDate(date);
}


bool ScheduleRule::addSpecificDate(const openstudio::Date& date) {
return getImpl<detail::ScheduleRule_Impl>()->addSpecificDate(date);
}
Expand Down
8 changes: 2 additions & 6 deletions src/model/ScheduleRule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MODEL_API ScheduleRule : public ParentObject {

bool applySaturday() const;

//bool applyHoliday() const;
// Note: there is no applyHoliday, instead that's implemented at the ScheduleRule's level

std::string dateSpecificationType() const;

Expand Down Expand Up @@ -141,11 +141,7 @@ class MODEL_API ScheduleRule : public ParentObject {

void setApplySaturdayNoFail(bool applySaturday);

//bool setApplyHoliday(bool applyHoliday);

//void setApplyHolidayNoFail(bool applyHoliday);

/// Sets the start date of the date range, will delete any specific dates specified.
/// Sets the start date of the date range, will delete any specific dates specified.
/// A start date > end date indicates that the range wraps around the year.
bool setStartDate(const openstudio::Date& date);

Expand Down
Loading