src/energyplus/ReverseTranslator/ReverseTranslateRunPeriod.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #include "../ReverseTranslator.hpp" | ||
| 7 | |||
| 8 | #include "../../model/RunPeriod.hpp" | ||
| 9 | #include "../../model/RunPeriod_Impl.hpp" | ||
| 10 | #include "../../model/YearDescription.hpp" | ||
| 11 | #include "../../model/YearDescription_Impl.hpp" | ||
| 12 | |||
| 13 | #include <utilities/idd/RunPeriod_FieldEnums.hxx> | ||
| 14 | |||
| 15 | #include "../../utilities/time/Date.hpp" | ||
| 16 | |||
| 17 | using namespace openstudio::model; | ||
| 18 | |||
| 19 | namespace openstudio { | ||
| 20 | |||
| 21 | namespace energyplus { | ||
| 22 | |||
| 23 | 39 | OptionalModelObject ReverseTranslator::translateRunPeriod(const WorkspaceObject& workspaceObject) { | |
| 24 | 39 | OptionalModelObject result; | |
| 25 |
1/1✓ Branch 1 taken 39 times.
|
39 | openstudio::model::RunPeriod runPeriod = m_model.getUniqueModelObject<openstudio::model::RunPeriod>(); |
| 26 |
1/1✓ Branch 1 taken 39 times.
|
39 | OptionalString optS = workspaceObject.name(); |
| 27 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 28 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | runPeriod.setName(*optS); |
| 29 | } | ||
| 30 | 39 | OptionalInt i; | |
| 31 | |||
| 32 |
1/1✓ Branch 1 taken 39 times.
|
39 | i = workspaceObject.getInt(openstudio::RunPeriodFields::BeginMonth); |
| 33 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (i) { |
| 34 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | runPeriod.setBeginMonth(*i); |
| 35 | } | ||
| 36 | |||
| 37 |
1/1✓ Branch 1 taken 39 times.
|
39 | i = workspaceObject.getInt(openstudio::RunPeriodFields::BeginDayofMonth); |
| 38 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (i) { |
| 39 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | runPeriod.setBeginDayOfMonth(*i); |
| 40 | } | ||
| 41 | |||
| 42 |
1/1✓ Branch 1 taken 39 times.
|
39 | i = workspaceObject.getInt(openstudio::RunPeriodFields::EndMonth); |
| 43 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (i) { |
| 44 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | runPeriod.setEndMonth(*i); |
| 45 | } | ||
| 46 | |||
| 47 |
1/1✓ Branch 1 taken 39 times.
|
39 | i = workspaceObject.getInt(openstudio::RunPeriodFields::EndDayofMonth); |
| 48 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (i) { |
| 49 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | runPeriod.setEndDayOfMonth(*i); |
| 50 | } | ||
| 51 | |||
| 52 |
1/1✓ Branch 1 taken 39 times.
|
39 | optS = workspaceObject.getString(RunPeriodFields::DayofWeekforStartDay); |
| 53 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 54 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | boost::optional<model::YearDescription> yd = runPeriod.model().getOptionalUniqueModelObject<model::YearDescription>(); |
| 55 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 39 times.
|
39 | if (yd) { |
| 56 | ✗ | if (!istringEqual(*optS, yd->dayofWeekforStartDay())) { | |
| 57 | ✗ | LOG(Warn, "Multiple values detected for dayofWeekforStartDay, using " << yd->dayofWeekforStartDay()); | |
| 58 | } | ||
| 59 | } else { | ||
| 60 | // create a year description | ||
| 61 |
3/3✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
✓ Branch 7 taken 39 times.
|
39 | yd = runPeriod.model().getUniqueModelObject<model::YearDescription>(); |
| 62 |
3/3✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
✓ Branch 7 taken 39 times.
|
39 | yd->setDayofWeekforStartDay(*optS); |
| 63 | } | ||
| 64 | |||
| 65 | 39 | } //if(optS) | |
| 66 | |||
| 67 |
1/1✓ Branch 1 taken 39 times.
|
39 | optS = workspaceObject.getString(RunPeriodFields::UseWeatherFileHolidaysandSpecialDays); |
| 68 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 69 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | std::string temp = *optS; |
| 70 |
1/1✓ Branch 2 taken 39 times.
|
39 | boost::to_lower(temp); |
| 71 |
3/3✓ Branch 1 taken 39 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 3 times.
|
39 | if (temp == "no") { |
| 72 |
1/1✓ Branch 1 taken 36 times.
|
36 | runPeriod.setUseWeatherFileHolidays(false); |
| 73 | } else { | ||
| 74 |
1/1✓ Branch 1 taken 3 times.
|
3 | runPeriod.setUseWeatherFileHolidays(true); |
| 75 | } | ||
| 76 | 39 | } | |
| 77 |
1/1✓ Branch 1 taken 39 times.
|
39 | optS = workspaceObject.getString(RunPeriodFields::UseWeatherFileDaylightSavingPeriod); |
| 78 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 79 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | std::string temp = *optS; |
| 80 |
1/1✓ Branch 2 taken 39 times.
|
39 | boost::to_lower(temp); |
| 81 |
3/3✓ Branch 1 taken 39 times.
✓ Branch 3 taken 36 times.
✓ Branch 4 taken 3 times.
|
39 | if (temp == "no") { |
| 82 |
1/1✓ Branch 1 taken 36 times.
|
36 | runPeriod.setUseWeatherFileDaylightSavings(false); |
| 83 | } else { | ||
| 84 |
1/1✓ Branch 1 taken 3 times.
|
3 | runPeriod.setUseWeatherFileDaylightSavings(true); |
| 85 | } | ||
| 86 | 39 | } | |
| 87 |
1/1✓ Branch 1 taken 39 times.
|
39 | optS = workspaceObject.getString(RunPeriodFields::ApplyWeekendHolidayRule); |
| 88 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 89 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | std::string temp = *optS; |
| 90 |
1/1✓ Branch 2 taken 39 times.
|
39 | boost::to_lower(temp); |
| 91 |
2/3✓ Branch 1 taken 39 times.
✓ Branch 3 taken 39 times.
✗ Branch 4 not taken.
|
39 | if (temp == "no") { |
| 92 |
1/1✓ Branch 1 taken 39 times.
|
39 | runPeriod.setApplyWeekendHolidayRule(false); |
| 93 | } else { | ||
| 94 | ✗ | runPeriod.setApplyWeekendHolidayRule(true); | |
| 95 | } | ||
| 96 | 39 | } | |
| 97 |
1/1✓ Branch 1 taken 39 times.
|
39 | optS = workspaceObject.getString(RunPeriodFields::UseWeatherFileRainIndicators); |
| 98 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 99 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | std::string temp = *optS; |
| 100 |
1/1✓ Branch 2 taken 39 times.
|
39 | boost::to_lower(temp); |
| 101 |
3/3✓ Branch 1 taken 39 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 38 times.
|
39 | if (temp == "no") { |
| 102 |
1/1✓ Branch 1 taken 1 time.
|
1 | runPeriod.setUseWeatherFileRainInd(false); |
| 103 | } else { | ||
| 104 |
1/1✓ Branch 1 taken 38 times.
|
38 | runPeriod.setUseWeatherFileRainInd(true); |
| 105 | } | ||
| 106 | 39 | } | |
| 107 |
1/1✓ Branch 1 taken 39 times.
|
39 | optS = workspaceObject.getString(RunPeriodFields::UseWeatherFileSnowIndicators); |
| 108 |
1/2✓ Branch 0 taken 39 times.
✗ Branch 1 not taken.
|
39 | if (optS) { |
| 109 |
2/2✓ Branch 1 taken 39 times.
✓ Branch 4 taken 39 times.
|
39 | std::string temp = *optS; |
| 110 |
1/1✓ Branch 2 taken 39 times.
|
39 | boost::to_lower(temp); |
| 111 |
3/3✓ Branch 1 taken 39 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 38 times.
|
39 | if (temp == "no") { |
| 112 |
1/1✓ Branch 1 taken 1 time.
|
1 | runPeriod.setUseWeatherFileSnowInd(false); |
| 113 | } else { | ||
| 114 |
1/1✓ Branch 1 taken 38 times.
|
38 | runPeriod.setUseWeatherFileSnowInd(true); |
| 115 | } | ||
| 116 | 39 | } | |
| 117 | |||
| 118 |
1/1✓ Branch 1 taken 39 times.
|
39 | auto beginYear = workspaceObject.getInt(openstudio::RunPeriodFields::BeginYear); |
| 119 |
1/1✓ Branch 1 taken 39 times.
|
39 | auto endYear = workspaceObject.getInt(openstudio::RunPeriodFields::EndYear); |
| 120 | |||
| 121 |
2/2✓ Branch 0 taken 31 times.
✓ Branch 1 taken 8 times.
|
39 | if (beginYear) { |
| 122 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
|
31 | auto yd = runPeriod.model().getUniqueModelObject<model::YearDescription>(); |
| 123 |
2/2✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
|
31 | yd.setCalendarYear(beginYear.get()); |
| 124 | |||
| 125 |
1/2✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
|
31 | if (endYear) { |
| 126 |
3/3✓ Branch 1 taken 31 times.
✓ Branch 4 taken 31 times.
✓ Branch 7 taken 31 times.
|
31 | runPeriod.setNumTimePeriodRepeats(endYear.get() - beginYear.get()); |
| 127 | } | ||
| 128 | 31 | } | |
| 129 | |||
| 130 |
1/1✓ Branch 1 taken 39 times.
|
39 | result = runPeriod; |
| 131 | 78 | return result; | |
| 132 | 39 | } | |
| 133 | |||
| 134 | } // namespace energyplus | ||
| 135 | |||
| 136 | } // namespace openstudio | ||
| 137 |