src/model/ScheduleCompact.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 "ScheduleCompact.hpp" | ||
| 7 | #include "ScheduleCompact_Impl.hpp" | ||
| 8 | #include "Model.hpp" | ||
| 9 | |||
| 10 | #include "ScheduleTypeLimits.hpp" | ||
| 11 | #include "ScheduleTypeLimits_Impl.hpp" | ||
| 12 | |||
| 13 | #include "../utilities/idf/IdfExtensibleGroup.hpp" | ||
| 14 | |||
| 15 | #include <utilities/idd/OS_Schedule_Compact_FieldEnums.hxx> | ||
| 16 | #include <utilities/idd/IddEnums.hxx> | ||
| 17 | |||
| 18 | #include "../utilities/core/Assert.hpp" | ||
| 19 | |||
| 20 | using openstudio::Handle; | ||
| 21 | using openstudio::OptionalHandle; | ||
| 22 | using openstudio::HandleVector; | ||
| 23 | using openstudio::IdfObject; | ||
| 24 | using openstudio::WorkspaceObject; | ||
| 25 | using openstudio::OptionalWorkspaceObject; | ||
| 26 | using openstudio::WorkspaceObjectVector; | ||
| 27 | using openstudio::Workspace; | ||
| 28 | |||
| 29 | namespace openstudio { | ||
| 30 | namespace model { | ||
| 31 | |||
| 32 | namespace detail { | ||
| 33 | |||
| 34 | 773 | ScheduleCompact_Impl::ScheduleCompact_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 35 | 773 | : Schedule_Impl(idfObject, model, keepHandle) { | |
| 36 |
4/6✓ Branch 1 taken 773 times.
✓ Branch 4 taken 773 times.
✓ Branch 7 taken 773 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 773 times.
✗ Branch 13 not taken.
|
773 | OS_ASSERT(idfObject.iddObject().type() == ScheduleCompact::iddObjectType()); |
| 37 | 773 | } | |
| 38 | |||
| 39 | 194 | ScheduleCompact_Impl::ScheduleCompact_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 40 | 194 | : Schedule_Impl(other, model, keepHandle) { | |
| 41 |
4/6✓ Branch 1 taken 194 times.
✓ Branch 4 taken 194 times.
✓ Branch 7 taken 194 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 194 times.
✗ Branch 13 not taken.
|
194 | OS_ASSERT(other.iddObject().type() == ScheduleCompact::iddObjectType()); |
| 42 | 194 | } | |
| 43 | |||
| 44 | 217 | ScheduleCompact_Impl::ScheduleCompact_Impl(const ScheduleCompact_Impl& other, Model_Impl* model, bool keepHandle) | |
| 45 | 217 | : Schedule_Impl(other, model, keepHandle) {} | |
| 46 | |||
| 47 | // return the parent object in the hierarchy | ||
| 48 | 30 | boost::optional<ParentObject> ScheduleCompact_Impl::parent() const { | |
| 49 | 30 | return {}; | |
| 50 | } | ||
| 51 | |||
| 52 | // return any children objects in the hierarchy | ||
| 53 | 136 | std::vector<ModelObject> ScheduleCompact_Impl::children() const { | |
| 54 | 136 | std::vector<ModelObject> result; | |
| 55 | 136 | return result; | |
| 56 | } | ||
| 57 | |||
| 58 | // Get all output variable names that could be associated with this object. | ||
| 59 | 1 | const std::vector<std::string>& ScheduleCompact_Impl::outputVariableNames() const { | |
| 60 |
5/11✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 11 taken 1 time.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
|
4 | static const std::vector<std::string> result{"Schedule Value"}; |
| 61 | 1 | return result; | |
| 62 | 3 | } | |
| 63 | |||
| 64 | 2 | IddObjectType ScheduleCompact_Impl::iddObjectType() const { | |
| 65 | 2 | return ScheduleCompact::iddObjectType(); | |
| 66 | } | ||
| 67 | |||
| 68 | ✗ | std::vector<double> ScheduleCompact_Impl::values() const { | |
| 69 | ✗ | DoubleVector result; | |
| 70 | ✗ | for (const IdfExtensibleGroup& eg : extensibleGroups()) { | |
| 71 | ✗ | std::string str = eg.getString(0, true).get(); | |
| 72 | ✗ | boost::trim(str); | |
| 73 | ✗ | if (!str.empty()) { | |
| 74 | ✗ | char firstChar = str[0]; | |
| 75 | ✗ | switch (firstChar) { | |
| 76 | ✗ | case 'T': | |
| 77 | ✗ | break; | |
| 78 | ✗ | case 'F': | |
| 79 | ✗ | break; | |
| 80 | ✗ | case 'U': | |
| 81 | ✗ | break; | |
| 82 | ✗ | default: { | |
| 83 | try { | ||
| 84 | ✗ | auto value = boost::lexical_cast<double>(str); | |
| 85 | ✗ | result.push_back(value); | |
| 86 | ✗ | } catch (...) { | |
| 87 | ✗ | } | |
| 88 | } | ||
| 89 | } | ||
| 90 | } | ||
| 91 | ✗ | } | |
| 92 | ✗ | return result; | |
| 93 | ✗ | } | |
| 94 | |||
| 95 | 1566 | boost::optional<ScheduleTypeLimits> ScheduleCompact_Impl::scheduleTypeLimits() const { | |
| 96 |
2/2✓ Branch 1 taken 1566 times.
✓ Branch 4 taken 1566 times.
|
1566 | return getObject<ModelObject>().getModelObjectTarget<ScheduleTypeLimits>(OS_Schedule_CompactFields::ScheduleTypeLimitsName); |
| 97 | } | ||
| 98 | |||
| 99 | 418 | bool ScheduleCompact_Impl::setScheduleTypeLimits(const ScheduleTypeLimits& scheduleTypeLimits) { | |
| 100 |
4/5✓ Branch 1 taken 418 times.
✓ Branch 4 taken 418 times.
✓ Branch 7 taken 418 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 418 times.
|
418 | if (scheduleTypeLimits.model() != model()) { |
| 101 | ✗ | return false; | |
| 102 | } | ||
| 103 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 418 times.
|
418 | if (!candidateIsCompatibleWithCurrentUse(scheduleTypeLimits)) { |
| 104 | ✗ | return false; | |
| 105 | } | ||
| 106 |
2/2✓ Branch 1 taken 418 times.
✓ Branch 4 taken 418 times.
|
418 | return setPointer(OS_Schedule_CompactFields::ScheduleTypeLimitsName, scheduleTypeLimits.handle()); |
| 107 | } | ||
| 108 | |||
| 109 | ✗ | bool ScheduleCompact_Impl::resetScheduleTypeLimits() { | |
| 110 | ✗ | if (okToResetScheduleTypeLimits()) { | |
| 111 | ✗ | return setString(OS_Schedule_CompactFields::ScheduleTypeLimitsName, ""); | |
| 112 | } | ||
| 113 | ✗ | return false; | |
| 114 | } | ||
| 115 | |||
| 116 | 12 | bool ScheduleCompact_Impl::setToConstantValue(double value) { | |
| 117 |
1/1✓ Branch 1 taken 12 times.
|
12 | clearExtensibleGroups(); |
| 118 | 12 | StringVector values; | |
| 119 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 4 taken 12 times.
|
12 | values.push_back("Through: 12/31"); |
| 120 |
1/1✓ Branch 1 taken 12 times.
|
12 | IdfExtensibleGroup eg = pushExtensibleGroup(values); |
| 121 |
2/4✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 6 not taken.
|
12 | OS_ASSERT(!eg.empty()); |
| 122 |
1/1✓ Branch 2 taken 12 times.
|
12 | values[0] = "For: AllDays"; |
| 123 |
1/1✓ Branch 1 taken 12 times.
|
12 | eg = pushExtensibleGroup(values); |
| 124 |
2/4✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 6 not taken.
|
12 | OS_ASSERT(!eg.empty()); |
| 125 |
1/1✓ Branch 2 taken 12 times.
|
12 | values[0] = "Until: 24:00"; |
| 126 |
1/1✓ Branch 1 taken 12 times.
|
12 | eg = pushExtensibleGroup(values); |
| 127 |
2/4✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 6 not taken.
|
12 | OS_ASSERT(!eg.empty()); |
| 128 |
1/1✓ Branch 2 taken 12 times.
|
12 | values[0] = ""; |
| 129 |
1/1✓ Branch 1 taken 12 times.
|
12 | eg = pushExtensibleGroup(values); |
| 130 |
2/4✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 6 not taken.
|
12 | OS_ASSERT(!eg.empty()); |
| 131 |
1/1✓ Branch 1 taken 12 times.
|
12 | bool ok = eg.setDouble(0, value); |
| 132 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
✗ Branch 3 not taken.
|
12 | OS_ASSERT(ok); |
| 133 | 12 | return true; | |
| 134 | 12 | } | |
| 135 | |||
| 136 | ✗ | void ScheduleCompact_Impl::ensureNoLeapDays() { | |
| 137 | ✗ | LOG(Warn, "Ensure no leap days is not yet implemented for schedule compact"); | |
| 138 | ✗ | } | |
| 139 | |||
| 140 | ✗ | bool ScheduleCompact_Impl::isConstantValue() const { | |
| 141 | ✗ | IdfExtensibleGroupVector scheduleData = extensibleGroups(); | |
| 142 | ✗ | if (scheduleData.size() == 4u) { | |
| 143 | ✗ | if (scheduleData[3].getDouble(0)) { | |
| 144 | ✗ | return true; | |
| 145 | } | ||
| 146 | } | ||
| 147 | ✗ | return false; | |
| 148 | ✗ | } | |
| 149 | |||
| 150 | ✗ | boost::optional<double> ScheduleCompact_Impl::constantValue() const { | |
| 151 | ✗ | IdfExtensibleGroupVector scheduleData = extensibleGroups(); | |
| 152 | ✗ | if (scheduleData.size() == 4u) { | |
| 153 | ✗ | return scheduleData[3].getDouble(0); | |
| 154 | } | ||
| 155 | ✗ | return boost::none; | |
| 156 | ✗ | } | |
| 157 | |||
| 158 | ✗ | std::vector<EMSActuatorNames> ScheduleCompact_Impl::emsActuatorNames() const { | |
| 159 | ✗ | std::vector<EMSActuatorNames> actuators{{"Schedule:Compact", "Schedule Value"}}; | |
| 160 | ✗ | return actuators; | |
| 161 | ✗ | } | |
| 162 | |||
| 163 | ✗ | std::vector<std::string> ScheduleCompact_Impl::emsInternalVariableNames() const { | |
| 164 | ✗ | std::vector<std::string> types; | |
| 165 | ✗ | return types; | |
| 166 | } | ||
| 167 | } // namespace detail | ||
| 168 | |||
| 169 | // create a new ScheduleCompact object in the model's workspace | ||
| 170 | 566 | ScheduleCompact::ScheduleCompact(const Model& model) : Schedule(ScheduleCompact::iddObjectType(), model) { | |
| 171 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 566 times.
✗ Branch 5 not taken.
|
566 | OS_ASSERT(getImpl<detail::ScheduleCompact_Impl>()); |
| 172 | 566 | } | |
| 173 | |||
| 174 | 12 | ScheduleCompact::ScheduleCompact(const Model& model, double constantValue) : Schedule(ScheduleCompact::iddObjectType(), model) { | |
| 175 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 5 not taken.
|
12 | OS_ASSERT(getImpl<detail::ScheduleCompact_Impl>()); |
| 176 |
1/1✓ Branch 1 taken 12 times.
|
12 | setToConstantValue(constantValue); |
| 177 | 12 | } | |
| 178 | |||
| 179 | // constructor | ||
| 180 |
1/1✓ Branch 3 taken 112 times.
|
112 | ScheduleCompact::ScheduleCompact(std::shared_ptr<detail::ScheduleCompact_Impl> impl) : Schedule(std::move(impl)) {} |
| 181 | |||
| 182 | 12 | bool ScheduleCompact::setToConstantValue(double value) { | |
| 183 |
1/1✓ Branch 3 taken 12 times.
|
12 | return getImpl<detail::ScheduleCompact_Impl>()->setToConstantValue(value); |
| 184 | } | ||
| 185 | |||
| 186 | ✗ | bool ScheduleCompact::isConstantValue() const { | |
| 187 | ✗ | return getImpl<detail::ScheduleCompact_Impl>()->isConstantValue(); | |
| 188 | } | ||
| 189 | |||
| 190 | ✗ | boost::optional<double> ScheduleCompact::constantValue() const { | |
| 191 | ✗ | return getImpl<detail::ScheduleCompact_Impl>()->constantValue(); | |
| 192 | } | ||
| 193 | |||
| 194 | 9282 | IddObjectType ScheduleCompact::iddObjectType() { | |
| 195 |
1/1✓ Branch 1 taken 9282 times.
|
9282 | IddObjectType result(IddObjectType::OS_Schedule_Compact); |
| 196 | 9282 | return result; | |
| 197 | } | ||
| 198 | |||
| 199 | } // namespace model | ||
| 200 | } // namespace openstudio | ||
| 201 |