src/model/SetpointManagerScheduled.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 "SetpointManagerScheduled.hpp" | ||
| 7 | #include "SetpointManagerScheduled_Impl.hpp" | ||
| 8 | #include "Model.hpp" | ||
| 9 | #include "Node.hpp" | ||
| 10 | #include "Node_Impl.hpp" | ||
| 11 | #include "AirLoopHVAC.hpp" | ||
| 12 | #include "PlantLoop.hpp" | ||
| 13 | #include "Schedule.hpp" | ||
| 14 | #include "Schedule_Impl.hpp" | ||
| 15 | |||
| 16 | #include <utilities/idd/IddFactory.hxx> | ||
| 17 | |||
| 18 | #include "../utilities/idd/IddKey.hpp" | ||
| 19 | #include <utilities/idd/OS_SetpointManager_Scheduled_FieldEnums.hxx> | ||
| 20 | #include <utilities/idd/IddEnums.hxx> | ||
| 21 | |||
| 22 | #include "../utilities/core/Assert.hpp" | ||
| 23 | |||
| 24 | namespace openstudio { | ||
| 25 | |||
| 26 | namespace model { | ||
| 27 | |||
| 28 | namespace detail { | ||
| 29 | |||
| 30 | 51 | SetpointManagerScheduled_Impl::SetpointManagerScheduled_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 31 | 51 | : SetpointManager_Impl(idfObject, model, keepHandle) { | |
| 32 |
4/6✓ Branch 1 taken 51 times.
✓ Branch 4 taken 51 times.
✓ Branch 7 taken 51 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 51 times.
✗ Branch 13 not taken.
|
51 | OS_ASSERT(idfObject.iddObject().type() == SetpointManagerScheduled::iddObjectType()); |
| 33 | 51 | } | |
| 34 | |||
| 35 | 11 | SetpointManagerScheduled_Impl::SetpointManagerScheduled_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, | |
| 36 | 11 | bool keepHandle) | |
| 37 | 11 | : SetpointManager_Impl(other, model, keepHandle) { | |
| 38 |
4/6✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 11 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 11 times.
✗ Branch 13 not taken.
|
11 | OS_ASSERT(other.iddObject().type() == SetpointManagerScheduled::iddObjectType()); |
| 39 | 11 | } | |
| 40 | |||
| 41 | 57 | SetpointManagerScheduled_Impl::SetpointManagerScheduled_Impl(const SetpointManagerScheduled_Impl& other, Model_Impl* model, bool keepHandles) | |
| 42 | 57 | : SetpointManager_Impl(other, model, keepHandles) {} | |
| 43 | |||
| 44 | ✗ | const std::vector<std::string>& SetpointManagerScheduled_Impl::outputVariableNames() const { | |
| 45 | ✗ | static const std::vector<std::string> result; | |
| 46 | ✗ | return result; | |
| 47 | } | ||
| 48 | |||
| 49 | ✗ | IddObjectType SetpointManagerScheduled_Impl::iddObjectType() const { | |
| 50 | ✗ | return SetpointManagerScheduled::iddObjectType(); | |
| 51 | } | ||
| 52 | |||
| 53 | /** This SPM is allowed on a PlantLoop */ | ||
| 54 | 19 | bool SetpointManagerScheduled_Impl::isAllowedOnPlantLoop() const { | |
| 55 | 19 | return true; | |
| 56 | } | ||
| 57 | |||
| 58 | ✗ | std::vector<ScheduleTypeKey> SetpointManagerScheduled_Impl::getScheduleTypeKeys(const Schedule& schedule) const { | |
| 59 | ✗ | std::vector<ScheduleTypeKey> result; | |
| 60 | ✗ | UnsignedVector fieldIndices = getSourceIndices(schedule.handle()); | |
| 61 | ✗ | UnsignedVector::const_iterator b(fieldIndices.begin()); | |
| 62 | ✗ | UnsignedVector::const_iterator e(fieldIndices.end()); | |
| 63 | ✗ | if (std::find(b, e, OS_SetpointManager_ScheduledFields::ScheduleName) != e) { | |
| 64 | ✗ | result.push_back(ScheduleTypeKey("SetpointManagerScheduled", scheduleDisplayName())); | |
| 65 | } | ||
| 66 | ✗ | return result; | |
| 67 | ✗ | } | |
| 68 | |||
| 69 | 152 | boost::optional<Node> SetpointManagerScheduled_Impl::setpointNode() const { | |
| 70 |
2/2✓ Branch 1 taken 152 times.
✓ Branch 4 taken 152 times.
|
152 | return getObject<ModelObject>().getModelObjectTarget<Node>(OS_SetpointManager_ScheduledFields::SetpointNodeorNodeListName); |
| 71 | } | ||
| 72 | |||
| 73 | 36 | bool SetpointManagerScheduled_Impl::setSetpointNode(const Node& node) { | |
| 74 |
2/2✓ Branch 1 taken 36 times.
✓ Branch 4 taken 36 times.
|
36 | return setPointer(OS_SetpointManager_ScheduledFields::SetpointNodeorNodeListName, node.handle()); |
| 75 | } | ||
| 76 | |||
| 77 | 2 | void SetpointManagerScheduled_Impl::resetSetpointNode() { | |
| 78 |
2/2✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
|
4 | bool result = setString(OS_SetpointManager_ScheduledFields::SetpointNodeorNodeListName, ""); |
| 79 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | OS_ASSERT(result); |
| 80 | 2 | } | |
| 81 | |||
| 82 | 94 | std::string SetpointManagerScheduled_Impl::controlVariable() const { | |
| 83 |
1/1✓ Branch 1 taken 94 times.
|
94 | boost::optional<std::string> value = getString(OS_SetpointManager_ScheduledFields::ControlVariable, true); |
| 84 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 94 times.
✗ Branch 4 not taken.
|
94 | OS_ASSERT(value); |
| 85 |
2/2✓ Branch 1 taken 94 times.
✓ Branch 4 taken 94 times.
|
188 | return value.get(); |
| 86 | 94 | } | |
| 87 | |||
| 88 | 64 | bool SetpointManagerScheduled_Impl::setControlVariable(const std::string& value) { | |
| 89 | 64 | std::string result; | |
| 90 |
4/4✓ Branch 1 taken 64 times.
✓ Branch 4 taken 64 times.
✓ Branch 7 taken 49 times.
✓ Branch 8 taken 15 times.
|
128 | if (istringEqual(value, "Temperature")) { |
| 91 |
1/1✓ Branch 1 taken 49 times.
|
49 | result = "Temperature"; |
| 92 |
4/4✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 4 times.
✓ Branch 8 taken 11 times.
|
30 | } else if (istringEqual(value, "MaximumTemperature")) { |
| 93 |
1/1✓ Branch 1 taken 4 times.
|
4 | result = "MaximumTemperature"; |
| 94 |
4/4✓ Branch 1 taken 11 times.
✓ Branch 4 taken 11 times.
✓ Branch 7 taken 5 times.
✓ Branch 8 taken 6 times.
|
22 | } else if (istringEqual(value, "MinimumTemperature")) { |
| 95 |
1/1✓ Branch 1 taken 5 times.
|
5 | result = "MinimumTemperature"; |
| 96 |
4/4✓ Branch 1 taken 6 times.
✓ Branch 4 taken 6 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 5 times.
|
12 | } else if (istringEqual(value, "HumidityRatio")) { |
| 97 |
1/1✓ Branch 1 taken 1 time.
|
1 | result = "HumidityRatio"; |
| 98 |
4/4✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 4 times.
|
10 | } else if (istringEqual(value, "MaximumHumidityRatio")) { |
| 99 |
1/1✓ Branch 1 taken 1 time.
|
1 | result = "MaximumHumidityRatio"; |
| 100 |
4/4✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 3 times.
|
8 | } else if (istringEqual(value, "MinimumHumidityRatio")) { |
| 101 |
1/1✓ Branch 1 taken 1 time.
|
1 | result = "MinimumHumidityRatio"; |
| 102 |
4/4✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 2 times.
|
6 | } else if (istringEqual(value, "MassFlowRate")) { |
| 103 |
1/1✓ Branch 1 taken 1 time.
|
1 | result = "MassFlowRate"; |
| 104 |
4/4✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 1 time.
✓ Branch 8 taken 1 time.
|
4 | } else if (istringEqual(value, "MaximumMassFlowRate")) { |
| 105 |
1/1✓ Branch 1 taken 1 time.
|
1 | result = "MaximumMassFlowRate"; |
| 106 |
3/4✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
|
2 | } else if (istringEqual(value, "MinimumMassFlowRate")) { |
| 107 |
1/1✓ Branch 1 taken 1 time.
|
1 | result = "MinimumMassFlowRate"; |
| 108 | } | ||
| 109 | |||
| 110 |
1/2✓ Branch 1 taken 64 times.
✗ Branch 2 not taken.
|
64 | if (!result.empty()) { |
| 111 |
1/1✓ Branch 1 taken 64 times.
|
64 | return setString(OS_SetpointManager_ScheduledFields::ControlVariable, result); |
| 112 | } else { | ||
| 113 | ✗ | return false; | |
| 114 | } | ||
| 115 | 64 | } | |
| 116 | |||
| 117 | 21 | Schedule SetpointManagerScheduled_Impl::schedule() const { | |
| 118 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
21 | boost::optional<Schedule> value = getObject<ModelObject>().getModelObjectTarget<Schedule>(OS_SetpointManager_ScheduledFields::ScheduleName); |
| 119 |
1/3✗ Branch 1 not taken.
✓ Branch 2 taken 21 times.
✗ Branch 4 not taken.
|
21 | OS_ASSERT(value); |
| 120 |
2/2✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
|
42 | return value.get(); |
| 121 | 21 | } | |
| 122 | |||
| 123 | 19 | bool SetpointManagerScheduled_Impl::hasSchedule() const { | |
| 124 | 19 | bool empty = isEmpty(OS_SetpointManager_ScheduledFields::ScheduleName); | |
| 125 | 19 | return (!empty); | |
| 126 | } | ||
| 127 | |||
| 128 | 40 | bool SetpointManagerScheduled_Impl::setSchedule(Schedule& schedule) { | |
| 129 | bool result = | ||
| 130 |
3/3✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
✓ Branch 7 taken 40 times.
|
120 | ModelObject_Impl::setSchedule(OS_SetpointManager_ScheduledFields::ScheduleName, "SetpointManagerScheduled", scheduleDisplayName(), schedule); |
| 131 | 40 | return result; | |
| 132 | } | ||
| 133 | |||
| 134 | ✗ | bool SetpointManagerScheduled_Impl::setControlVariableAndSchedule(const std::string& controlVariable, Schedule& schedule) { | |
| 135 | ✗ | bool result(false); | |
| 136 | ✗ | if (OptionalIddKey key = iddObject().getField(OS_SetpointManager_ScheduledFields::ControlVariable).get().getKey(controlVariable)) { | |
| 137 | ✗ | result = ModelObject_Impl::setSchedule(OS_SetpointManager_ScheduledFields::ScheduleName, "SetpointManagerScheduled", | |
| 138 | ✗ | scheduleDisplayName(key->name()), schedule); | |
| 139 | ✗ | if (result) { | |
| 140 | ✗ | result = setString(OS_SetpointManager_ScheduledFields::ControlVariable, key->name()); | |
| 141 | ✗ | OS_ASSERT(result); | |
| 142 | } | ||
| 143 | ✗ | } | |
| 144 | ✗ | return result; | |
| 145 | } | ||
| 146 | |||
| 147 | 40 | std::string SetpointManagerScheduled_Impl::scheduleDisplayName() const { | |
| 148 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
|
40 | return scheduleDisplayName(controlVariable()); |
| 149 | } | ||
| 150 | |||
| 151 | 40 | std::string SetpointManagerScheduled_Impl::scheduleDisplayName(const std::string& candidateControlVariable) const { | |
| 152 | 40 | std::string result; | |
| 153 |
4/7✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
40 | static const boost::regex temperatureRegex("Temperature"); |
| 154 |
4/7✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
40 | static const boost::regex humidityRatioRegex("HumidityRatio"); |
| 155 |
4/7✓ Branch 0 taken 20 times.
✓ Branch 1 taken 20 times.
✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 20 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
|
40 | static const boost::regex massFlowRateRegex("MassFlowRate"); |
| 156 |
2/3✓ Branch 1 taken 40 times.
✓ Branch 3 taken 40 times.
✗ Branch 4 not taken.
|
40 | if (boost::regex_search(candidateControlVariable, temperatureRegex)) { |
| 157 |
1/1✓ Branch 1 taken 40 times.
|
80 | result = std::string("(Exact, Min, Max) Temperature"); |
| 158 | ✗ | } else if (boost::regex_search(candidateControlVariable, humidityRatioRegex)) { | |
| 159 | ✗ | result = std::string("(Exact, Min, Max) Humidity Ratio"); | |
| 160 | ✗ | } else if (boost::regex_search(candidateControlVariable, massFlowRateRegex)) { | |
| 161 | ✗ | result = std::string("(Exact, Min, Max) Mass Flow Rate"); | |
| 162 | } | ||
| 163 | 40 | return result; | |
| 164 | ✗ | } | |
| 165 | |||
| 166 | ✗ | std::vector<std::string> SetpointManagerScheduled_Impl::controlVariableValues() const { | |
| 167 | ✗ | return SetpointManagerScheduled::controlVariableValues(); | |
| 168 | } | ||
| 169 | |||
| 170 | ✗ | boost::optional<ModelObject> SetpointManagerScheduled_Impl::scheduleAsModelObject() const { | |
| 171 | ✗ | OptionalModelObject result = schedule(); | |
| 172 | ✗ | return result; | |
| 173 | } | ||
| 174 | |||
| 175 | ✗ | bool SetpointManagerScheduled_Impl::setScheduleAsModelObject(const boost::optional<ModelObject>& modelObject) { | |
| 176 | ✗ | if (modelObject) { | |
| 177 | ✗ | OptionalSchedule intermediate = modelObject->optionalCast<Schedule>(); | |
| 178 | ✗ | if (intermediate) { | |
| 179 | ✗ | Schedule schedule(*intermediate); | |
| 180 | ✗ | return setSchedule(schedule); | |
| 181 | ✗ | } | |
| 182 | ✗ | } | |
| 183 | ✗ | return false; | |
| 184 | } | ||
| 185 | |||
| 186 | } // namespace detail | ||
| 187 | |||
| 188 | 40 | SetpointManagerScheduled::SetpointManagerScheduled(const Model& model, Schedule& schedule) | |
| 189 | 40 | : SetpointManager(SetpointManagerScheduled::iddObjectType(), model) { | |
| 190 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 40 times.
✗ Branch 5 not taken.
|
40 | OS_ASSERT(getImpl<detail::SetpointManagerScheduled_Impl>()); |
| 191 |
2/2✓ Branch 1 taken 40 times.
✓ Branch 4 taken 40 times.
|
40 | bool ok = setControlVariable("Temperature"); |
| 192 |
1/3✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
✗ Branch 3 not taken.
|
40 | OS_ASSERT(ok); |
| 193 |
1/1✓ Branch 1 taken 40 times.
|
40 | ok = setSchedule(schedule); |
| 194 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 40 times.
|
40 | if (!ok) { |
| 195 | ✗ | LOG_AND_THROW("Unable to set " << schedule.briefDescription() << " as " << briefDescription() << "'s temperature setpoint schedule."); | |
| 196 | } | ||
| 197 | 40 | } | |
| 198 | |||
| 199 | ✗ | SetpointManagerScheduled::SetpointManagerScheduled(const Model& model, const std::string& controlVariable, Schedule& setpointSchedule) | |
| 200 | ✗ | : SetpointManager(SetpointManagerScheduled::iddObjectType(), model) { | |
| 201 | ✗ | OS_ASSERT(getImpl<detail::SetpointManagerScheduled_Impl>()); | |
| 202 | ✗ | bool ok = setControlVariable(controlVariable); | |
| 203 | ✗ | if (!ok) { | |
| 204 | ✗ | LOG_AND_THROW("Unable to set " << briefDescription() << "'s control variable to " << controlVariable << "."); | |
| 205 | } | ||
| 206 | ✗ | ok = setSchedule(setpointSchedule); | |
| 207 | ✗ | if (!ok) { | |
| 208 | ✗ | LOG_AND_THROW("Unable to set " << setpointSchedule.briefDescription() << " as " << briefDescription() << "'s " << this->controlVariable() | |
| 209 | << " setpoint schedule."); | ||
| 210 | } | ||
| 211 | ✗ | } | |
| 212 | |||
| 213 |
1/1✓ Branch 3 taken 32 times.
|
32 | SetpointManagerScheduled::SetpointManagerScheduled(std::shared_ptr<detail::SetpointManagerScheduled_Impl> p) : SetpointManager(std::move(p)) {} |
| 214 | |||
| 215 | 7837 | IddObjectType SetpointManagerScheduled::iddObjectType() { | |
| 216 |
1/1✓ Branch 1 taken 7837 times.
|
7837 | IddObjectType result(IddObjectType::OS_SetpointManager_Scheduled); |
| 217 | 7837 | return result; | |
| 218 | } | ||
| 219 | |||
| 220 | ✗ | std::vector<std::string> SetpointManagerScheduled::controlVariableValues() { | |
| 221 | ✗ | return getIddKeyNames(IddFactory::instance().getObject(iddObjectType()).get(), OS_SetpointManager_ScheduledFields::ControlVariable); | |
| 222 | } | ||
| 223 | |||
| 224 | 24 | boost::optional<Node> SetpointManagerScheduled::setpointNode() const { | |
| 225 |
1/1✓ Branch 3 taken 24 times.
|
24 | return getImpl<detail::SetpointManagerScheduled_Impl>()->setpointNode(); |
| 226 | } | ||
| 227 | |||
| 228 | 30 | std::string SetpointManagerScheduled::controlVariable() const { | |
| 229 |
1/1✓ Branch 3 taken 30 times.
|
30 | return getImpl<detail::SetpointManagerScheduled_Impl>()->controlVariable(); |
| 230 | } | ||
| 231 | |||
| 232 | 64 | bool SetpointManagerScheduled::setControlVariable(const std::string& value) { | |
| 233 |
1/1✓ Branch 3 taken 64 times.
|
64 | return getImpl<detail::SetpointManagerScheduled_Impl>()->setControlVariable(value); |
| 234 | } | ||
| 235 | |||
| 236 | 21 | Schedule SetpointManagerScheduled::schedule() const { | |
| 237 |
1/1✓ Branch 3 taken 21 times.
|
21 | return getImpl<detail::SetpointManagerScheduled_Impl>()->schedule(); |
| 238 | } | ||
| 239 | |||
| 240 | 19 | bool SetpointManagerScheduled::hasSchedule() const { | |
| 241 |
1/1✓ Branch 3 taken 19 times.
|
19 | return getImpl<detail::SetpointManagerScheduled_Impl>()->hasSchedule(); |
| 242 | } | ||
| 243 | |||
| 244 | 40 | bool SetpointManagerScheduled::setSchedule(Schedule& schedule) { | |
| 245 |
1/1✓ Branch 3 taken 40 times.
|
40 | return getImpl<detail::SetpointManagerScheduled_Impl>()->setSchedule(schedule); |
| 246 | } | ||
| 247 | |||
| 248 | ✗ | bool SetpointManagerScheduled::setControlVariableAndSchedule(const std::string& controlVariable, Schedule& schedule) { | |
| 249 | ✗ | return getImpl<detail::SetpointManagerScheduled_Impl>()->setControlVariableAndSchedule(controlVariable, schedule); | |
| 250 | } | ||
| 251 | |||
| 252 | } // namespace model | ||
| 253 | } // namespace openstudio | ||
| 254 |