Skip to content

Commit

Permalink
Merge pull request #4072 from NREL/4064_RunPeriodControlSpecialDays_FT
Browse files Browse the repository at this point in the history
Fix #4064 - RunPeriodControlSpecialDays are not Forward Translated
  • Loading branch information
kbenne committed Sep 14, 2020
2 parents ed2a80e + edc48b5 commit 2aeb103
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 16 deletions.
1 change: 1 addition & 0 deletions src/energyplus/CMakeLists.txt
Expand Up @@ -646,6 +646,7 @@ set(${target_name}_test_src
Test/PlantComponentUserDefined_GTest.cpp
Test/RunPeriod_GTest.cpp
Test/RunPeriodControlDaylightSavingTime_GTest.cpp
Test/RunPeriodControlSpecialDays_GTest.cpp
Test/ScheduleInterval_GTest.cpp
Test/ScheduleRuleset_GTest.cpp
Test/SetpointManagerFollowGroundTemperature_GTest.cpp
Expand Down
10 changes: 2 additions & 8 deletions src/energyplus/ForwardTranslator.cpp
Expand Up @@ -103,8 +103,7 @@ ForwardTranslator::ForwardTranslator()
m_logSink.setThreadId(std::this_thread::get_id());
createFluidPropertiesMap();

// temp code
m_keepRunControlSpecialDays = false;
m_keepRunControlSpecialDays = true; // At 3.1.0 this was changed to true.
m_ipTabularOutput = false;
m_excludeLCCObjects = false;
m_excludeSQliteOutputReport = false;
Expand Down Expand Up @@ -161,7 +160,6 @@ std::vector<LogMessage> ForwardTranslator::errors() const
return result;
}

// temp code
void ForwardTranslator::setKeepRunControlSpecialDays(bool keepRunControlSpecialDays)
{
m_keepRunControlSpecialDays = keepRunControlSpecialDays;
Expand Down Expand Up @@ -498,12 +496,8 @@ 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
// we will not warn users because these objects are not exposed in the GUI
LOG(Warn, "You have manually choosen to not translate the RunPeriodControlSpecialDays, ignoring them.");
for (model::RunPeriodControlSpecialDays holiday : model.getConcreteModelObjects<model::RunPeriodControlSpecialDays>()){
holiday.remove();
}
Expand Down
3 changes: 1 addition & 2 deletions src/energyplus/ForwardTranslator.hpp
Expand Up @@ -489,7 +489,7 @@ class ENERGYPLUS_API ForwardTranslator {
*/
std::vector<LogMessage> errors() const;

/** Temporary code, use to preserve holidays in the model.
/** keepRunControlSpecialDays is enabled by default. You can use this method to NOT translate the holidays in the model.
*/
void setKeepRunControlSpecialDays(bool keepRunControlSpecialDays);

Expand Down Expand Up @@ -1483,7 +1483,6 @@ class ENERGYPLUS_API ForwardTranslator {

ProgressBar* m_progressBar;

// temp code
bool m_keepRunControlSpecialDays;
bool m_ipTabularOutput;
bool m_excludeLCCObjects;
Expand Down
2 changes: 1 addition & 1 deletion src/energyplus/ReverseTranslator.cpp
Expand Up @@ -850,7 +850,7 @@ boost::optional<ModelObject> ReverseTranslator::translateAndMapWorkspaceObject(c
}
case openstudio::IddObjectType::RunPeriodControl_SpecialDays :
{
//modelObject = translateRunPeriodControlSpecialDays(workspaceObject);
modelObject = translateRunPeriodControlSpecialDays(workspaceObject);
break;
}
case openstudio::IddObjectType::Schedule_Compact :
Expand Down
166 changes: 166 additions & 0 deletions src/energyplus/Test/RunPeriodControlSpecialDays_GTest.cpp
@@ -0,0 +1,166 @@
/***********************************************************************************************************************
* OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC, and other contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
* following conditions are met:
*
* (1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following
* disclaimer.
*
* (2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided with the distribution.
*
* (3) Neither the name of the copyright holder nor the names of any contributors may be used to endorse or promote products
* derived from this software without specific prior written permission from the respective party.
*
* (4) Other than as required in clauses (1) and (2), distributions in any form of modifications or other derivative works
* may not use the "OpenStudio" trademark, "OS", "os", or any other confusingly similar designation without specific prior
* written permission from Alliance for Sustainable Energy, LLC.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE UNITED STATES GOVERNMENT, OR THE UNITED
* STATES DEPARTMENT OF ENERGY, NOR ANY OF THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
***********************************************************************************************************************/

#include <gtest/gtest.h>
#include "EnergyPlusFixture.hpp"

#include "../ErrorFile.hpp"
#include "../ForwardTranslator.hpp"
#include "../ReverseTranslator.hpp"

#include "../../model/Model.hpp"
#include "../../model/RunPeriodControlSpecialDays.hpp"
#include "../../model/RunPeriodControlSpecialDays_Impl.hpp"

#include "../../utilities/time/Date.hpp"

#include "../../utilities/idf/IdfFile.hpp"
#include "../../utilities/idf/Workspace.hpp"
#include "../../utilities/idf/IdfObject.hpp"
#include "../../utilities/idf/WorkspaceObject.hpp"

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

using namespace openstudio::energyplus;
using namespace openstudio::model;
using namespace openstudio;

TEST_F(EnergyPlusFixture, ForwardTranslator_RunPeriodControlSpecialDays)
{
ForwardTranslator ft;

// Create a model
Model m;

RunPeriodControlSpecialDays holiday(openstudio::MonthOfYear::Jul, 4, m);
holiday.setName("4th of July");
holiday.setSpecialDayType("Holiday");
holiday.setDuration(1);

{
Workspace w = ft.translateModel(m);

ASSERT_EQ(1u, w.getObjectsByType(IddObjectType::RunPeriodControl_SpecialDays).size());
WorkspaceObject idf_holiday = w.getObjectsByType(IddObjectType::RunPeriodControl_SpecialDays)[0];
EXPECT_EQ("4th of July", idf_holiday.nameString(false));
EXPECT_EQ("7/4", idf_holiday.getString(RunPeriodControl_SpecialDaysFields::StartDate).get());
EXPECT_EQ(1, idf_holiday.getInt(RunPeriodControl_SpecialDaysFields::Duration).get());
EXPECT_EQ("Holiday", idf_holiday.getString(RunPeriodControl_SpecialDaysFields::SpecialDayType).get());
}

holiday.setName("A week off");
EXPECT_TRUE(holiday.setStartDate(openstudio::NthDayOfWeekInMonth::first, openstudio::DayOfWeek::Monday, openstudio::MonthOfYear::Mar));
EXPECT_TRUE(holiday.setDuration(5));
EXPECT_TRUE(holiday.setSpecialDayType("CustomDay1"));

{
Workspace w = ft.translateModel(m);

ASSERT_EQ(1u, w.getObjectsByType(IddObjectType::RunPeriodControl_SpecialDays).size());
WorkspaceObject idf_holiday = w.getObjectsByType(IddObjectType::RunPeriodControl_SpecialDays)[0];
EXPECT_EQ("A week off", idf_holiday.nameString(false));
EXPECT_EQ("1st Monday in March", idf_holiday.getString(RunPeriodControl_SpecialDaysFields::StartDate).get());
EXPECT_EQ(5, idf_holiday.getInt(RunPeriodControl_SpecialDaysFields::Duration).get());
EXPECT_EQ("CustomDay1", idf_holiday.getString(RunPeriodControl_SpecialDaysFields::SpecialDayType).get());
}

// 5th replaced by Last
EXPECT_TRUE(holiday.setStartDate(openstudio::NthDayOfWeekInMonth::fifth, openstudio::DayOfWeek::Tuesday, openstudio::MonthOfYear::Aug));
{
Workspace w = ft.translateModel(m);

ASSERT_EQ(1u, w.getObjectsByType(IddObjectType::RunPeriodControl_SpecialDays).size());
WorkspaceObject idf_holiday = w.getObjectsByType(IddObjectType::RunPeriodControl_SpecialDays)[0];
EXPECT_EQ("Last Tuesday in August", idf_holiday.getString(RunPeriodControl_SpecialDaysFields::StartDate).get());
}

}

// TODO: RT of RunPeriodControlSpecialDays is disabled
TEST_F(EnergyPlusFixture, DISABLED_ReverseTranslator_RunPeriodControlSpecialDays) {

ReverseTranslator rt;

Workspace w(StrictnessLevel::None, IddFileType::EnergyPlus);

// Not there, Model shouldn't have it either
{
Model m = rt.translateWorkspace(w);
EXPECT_EQ(0u, m.getConcreteModelObjects<RunPeriodControlSpecialDays>().size());
}

OptionalWorkspaceObject _i_specialDay = w.addObject(IdfObject(IddObjectType::RunPeriodControl_SpecialDays));
ASSERT_TRUE(_i_specialDay);

EXPECT_TRUE(_i_specialDay->setName("Memorial Day"));
EXPECT_TRUE(_i_specialDay->setString(RunPeriodControl_SpecialDaysFields::StartDate, "last MoNday in Aug"));
EXPECT_TRUE(_i_specialDay->setInt(RunPeriodControl_SpecialDaysFields::Duration, 1));
EXPECT_TRUE(_i_specialDay->setString(RunPeriodControl_SpecialDaysFields::SpecialDayType, "Holiday"));

{
Model m = rt.translateWorkspace(w);

std::vector<openstudio::model::RunPeriodControlSpecialDays> specialDays = m.getModelObjects<openstudio::model::RunPeriodControlSpecialDays>();
ASSERT_EQ(1u, specialDays.size());
RunPeriodControlSpecialDays specialDay = specialDays[0];

EXPECT_EQ("Memorial Day", specialDay.nameString());
EXPECT_EQ("last MoNday in Aug", specialDay.getString(OS_RunPeriodControl_SpecialDaysFields::StartDate).get());
ASSERT_NO_THROW(specialDay.startDate());
// Assumed base year is 2009, so last one falls on the 31th
EXPECT_EQ(31u, specialDay.startDate().dayOfMonth());
EXPECT_EQ(MonthOfYear::Aug, specialDay.startDate().monthOfYear().value());
EXPECT_EQ(DayOfWeek::Monday, specialDay.startDate().dayOfWeek().value());
EXPECT_EQ(1u, specialDay.duration());
EXPECT_EQ("Holiday", specialDay.specialDayType());
}

EXPECT_TRUE(_i_specialDay->setString(RunPeriodControl_SpecialDaysFields::StartDate, "7/1"));
EXPECT_TRUE(_i_specialDay->setInt(RunPeriodControl_SpecialDaysFields::Duration, 15));
EXPECT_TRUE(_i_specialDay->setString(RunPeriodControl_SpecialDaysFields::SpecialDayType, "CustomDay1"));

{
Model m = rt.translateWorkspace(w);

std::vector<openstudio::model::RunPeriodControlSpecialDays> specialDays = m.getModelObjects<openstudio::model::RunPeriodControlSpecialDays>();
ASSERT_EQ(1u, specialDays.size());
RunPeriodControlSpecialDays specialDay = specialDays[0];

EXPECT_EQ("7/1", specialDay.getString(OS_RunPeriodControl_SpecialDaysFields::StartDate).get());
ASSERT_NO_THROW(specialDay.startDate());
// Assumed base year is 2009, so last one falls on the 31th
EXPECT_EQ(1u, specialDay.startDate().dayOfMonth());
EXPECT_EQ(MonthOfYear::Jul, specialDay.startDate().monthOfYear().value());
EXPECT_EQ(15u, specialDay.duration());
EXPECT_EQ("CustomDay1", specialDay.specialDayType());
}

}
11 changes: 6 additions & 5 deletions src/model/RunPeriodControlSpecialDays.cpp
Expand Up @@ -111,21 +111,22 @@ namespace detail {
bool RunPeriodControlSpecialDays_Impl::setStartDate(const openstudio::NthDayOfWeekInMonth& nth, const openstudio::DayOfWeek& dayOfWeek, const openstudio::MonthOfYear& monthOfYear)
{
std::stringstream ss;
// Note: MonthOfYear::Jul => valueName() is "Jul", valueDescription is "July"
switch (nth.value()){
case NthDayOfWeekInMonth::first:
ss << "1st " << dayOfWeek.valueName() << " in " << monthOfYear.valueName();
ss << "1st " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
break;
case NthDayOfWeekInMonth::second:
ss << "2nd " << dayOfWeek.valueName() << " in " << monthOfYear.valueName();
ss << "2nd " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
break;
case NthDayOfWeekInMonth::third:
ss << "3rd " << dayOfWeek.valueName() << " in " << monthOfYear.valueName();
ss << "3rd " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
break;
case NthDayOfWeekInMonth::fourth:
ss << "4th " << dayOfWeek.valueName() << " in " << monthOfYear.valueName();
ss << "4th " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
break;
case NthDayOfWeekInMonth::fifth:
ss << "5th " << dayOfWeek.valueName() << " in " << monthOfYear.valueName();
ss << "5th " << dayOfWeek.valueName() << " in " << monthOfYear.valueDescription();
break;
default:
OS_ASSERT(false);
Expand Down
4 changes: 4 additions & 0 deletions src/model/test/RunPeriodControlSpecialDays_GTest.cpp
Expand Up @@ -39,6 +39,9 @@

#include "../../utilities/time/Date.hpp"

// Unusual, but here I'm interested in finding out the actual string it stored for the Start Date
#include <utilities/idd/OS_RunPeriodControl_SpecialDays_FieldEnums.hxx>

#include <iostream>

using namespace openstudio;
Expand Down Expand Up @@ -76,6 +79,7 @@ TEST_F(ModelFixture, RunPeriodControlSpecialDays)
EXPECT_EQ(25u, day.startDate().dayOfMonth());
EXPECT_EQ(MonthOfYear::Feb, day.startDate().monthOfYear().value());
EXPECT_EQ(DayOfWeek::Monday, day.startDate().dayOfWeek().value());
EXPECT_EQ("4th Monday in February", day.getString(OS_RunPeriodControl_SpecialDaysFields::StartDate).get());

// there is no fifth monday, this will return the last
day = RunPeriodControlSpecialDays(NthDayOfWeekInMonth::fifth, DayOfWeek::Monday, MonthOfYear::Feb, model);
Expand Down

0 comments on commit 2aeb103

Please sign in to comment.