src/energyplus/ForwardTranslator/ForwardTranslateScheduleYear.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 "../ForwardTranslator.hpp" | ||
| 7 | #include "../../model/Model.hpp" | ||
| 8 | |||
| 9 | #include "../../model/ScheduleTypeLimits.hpp" | ||
| 10 | #include "../../model/ScheduleTypeLimits_Impl.hpp" | ||
| 11 | #include "../../model/ScheduleYear.hpp" | ||
| 12 | #include "../../model/ScheduleYear_Impl.hpp" | ||
| 13 | #include "../../model/ScheduleWeek.hpp" | ||
| 14 | #include "../../model/ScheduleWeek_Impl.hpp" | ||
| 15 | |||
| 16 | #include "../../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 17 | #include "../../utilities/idf/Workspace.hpp" | ||
| 18 | #include "../../utilities/time/Date.hpp" | ||
| 19 | #include "../../utilities/time/Time.hpp" | ||
| 20 | |||
| 21 | #include "../../utilities/core/Logger.hpp" | ||
| 22 | #include "../../utilities/core/Assert.hpp" | ||
| 23 | |||
| 24 | #include <utilities/idd/Schedule_Year_FieldEnums.hxx> | ||
| 25 | #include <utilities/idd/IddEnums.hxx> | ||
| 26 | |||
| 27 | using namespace openstudio::model; | ||
| 28 | |||
| 29 | using namespace std; | ||
| 30 | |||
| 31 | namespace openstudio { | ||
| 32 | |||
| 33 | namespace energyplus { | ||
| 34 | |||
| 35 | 10 | boost::optional<IdfObject> ForwardTranslator::translateScheduleYear(ScheduleYear& modelObject) { | |
| 36 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | IdfObject scheduleYear = createRegisterAndNameIdfObject(openstudio::IddObjectType::Schedule_Year, modelObject); |
| 37 | |||
| 38 |
1/1✓ Branch 1 taken 10 times.
|
10 | std::vector<ScheduleWeek> scheduleWeeks = modelObject.scheduleWeeks(); |
| 39 |
1/1✓ Branch 1 taken 10 times.
|
10 | std::vector<openstudio::Date> dates = modelObject.dates(); |
| 40 | |||
| 41 | 10 | unsigned N = scheduleWeeks.size(); | |
| 42 | |||
| 43 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
|
10 | if (N != dates.size()) { |
| 44 | ✗ | LOG(Error, | |
| 45 | "Could not translate " << modelObject.briefDescription() << ", because the number of week schedules does not match the number of dates."); | ||
| 46 | |||
| 47 | ✗ | return boost::none; | |
| 48 | } | ||
| 49 | |||
| 50 |
1/1✓ Branch 1 taken 10 times.
|
10 | boost::optional<ScheduleTypeLimits> scheduleTypeLimits = modelObject.scheduleTypeLimits(); |
| 51 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 1 time.
|
10 | if (scheduleTypeLimits) { |
| 52 |
2/2✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
|
9 | boost::optional<IdfObject> idfScheduleTypeLimits = translateAndMapModelObject(*scheduleTypeLimits); |
| 53 |
1/2✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
|
9 | if (idfScheduleTypeLimits) { |
| 54 |
4/4✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
✓ Branch 10 taken 9 times.
|
9 | scheduleYear.setString(Schedule_YearFields::ScheduleTypeLimitsName, idfScheduleTypeLimits->name().get()); |
| 55 | } | ||
| 56 | 9 | } | |
| 57 | |||
| 58 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
|
10 | openstudio::Date startDate(MonthOfYear::Jan, 1); |
| 59 | |||
| 60 |
1/1✓ Branch 1 taken 10 times.
|
10 | scheduleYear.clearExtensibleGroups(); |
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 10 times.
|
24 | for (unsigned i = 0; i < N; ++i) { |
| 63 |
1/1✓ Branch 1 taken 14 times.
|
14 | IdfExtensibleGroup group = scheduleYear.pushExtensibleGroup(); |
| 64 | |||
| 65 |
1/1✓ Branch 2 taken 14 times.
|
14 | boost::optional<IdfObject> idfScheduleWeek = translateAndMapModelObject(scheduleWeeks[i]); |
| 66 |
1/2✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
|
14 | if (idfScheduleWeek) { |
| 67 |
4/4✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
✓ Branch 10 taken 14 times.
|
14 | group.setString(Schedule_YearExtensibleFields::Schedule_WeekName, idfScheduleWeek->name().get()); |
| 68 | } | ||
| 69 | |||
| 70 |
3/3✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
✓ Branch 7 taken 14 times.
|
14 | group.setInt(Schedule_YearExtensibleFields::StartMonth, startDate.monthOfYear().value()); |
| 71 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 4 taken 14 times.
|
14 | group.setUnsigned(Schedule_YearExtensibleFields::StartDay, startDate.dayOfMonth()); |
| 72 |
3/3✓ Branch 2 taken 14 times.
✓ Branch 5 taken 14 times.
✓ Branch 8 taken 14 times.
|
14 | group.setInt(Schedule_YearExtensibleFields::EndMonth, dates[i].monthOfYear().value()); |
| 73 |
2/2✓ Branch 2 taken 14 times.
✓ Branch 5 taken 14 times.
|
14 | group.setUnsigned(Schedule_YearExtensibleFields::EndDay, dates[i].dayOfMonth()); |
| 74 | |||
| 75 |
3/3✓ Branch 1 taken 14 times.
✓ Branch 5 taken 14 times.
✓ Branch 8 taken 14 times.
|
14 | startDate = dates[i] + openstudio::Time(1, 0, 0); |
| 76 | 14 | } | |
| 77 | |||
| 78 |
1/1✓ Branch 1 taken 10 times.
|
10 | return scheduleYear; |
| 79 | 10 | } | |
| 80 | |||
| 81 | } // namespace energyplus | ||
| 82 | |||
| 83 | } // namespace openstudio | ||
| 84 |