src/model/SetpointManager.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 "SetpointManager.hpp" | ||
| 7 | #include "SetpointManager_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 "Splitter.hpp" | ||
| 14 | #include "Mixer.hpp" | ||
| 15 | |||
| 16 | #include "../utilities/core/Assert.hpp" | ||
| 17 | #include "../utilities/data/DataEnums.hpp" | ||
| 18 | |||
| 19 | #include <algorithm> | ||
| 20 | |||
| 21 | namespace openstudio { | ||
| 22 | |||
| 23 | namespace model { | ||
| 24 | |||
| 25 | namespace detail { | ||
| 26 | |||
| 27 | 1261 | SetpointManager_Impl::SetpointManager_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 28 | 1261 | : HVACComponent_Impl(idfObject, model, keepHandle) {} | |
| 29 | |||
| 30 | 149 | SetpointManager_Impl::SetpointManager_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 31 | 149 | : HVACComponent_Impl(other, model, keepHandle) {} | |
| 32 | |||
| 33 | 509 | SetpointManager_Impl::SetpointManager_Impl(const SetpointManager_Impl& other, Model_Impl* model, bool keepHandles) | |
| 34 | 509 | : HVACComponent_Impl(other, model, keepHandles) {} | |
| 35 | |||
| 36 | ✗ | SetpointManager_Impl::SetpointManager_Impl(IddObjectType type, Model_Impl* model) : HVACComponent_Impl(type, model) {} | |
| 37 | |||
| 38 | ✗ | const std::vector<std::string>& SetpointManager_Impl::outputVariableNames() const { | |
| 39 | ✗ | static const std::vector<std::string> result; | |
| 40 | ✗ | return result; | |
| 41 | } | ||
| 42 | |||
| 43 | 69 | boost::optional<ParentObject> SetpointManager_Impl::parent() const { | |
| 44 |
2/2✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
|
69 | NodeVector nodes = getObject<ModelObject>().getModelObjectSources<Node>(); |
| 45 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
|
69 | if (nodes.size() == 1u) { |
| 46 | ✗ | return nodes[0]; | |
| 47 | } | ||
| 48 | 69 | return boost::none; | |
| 49 | 69 | } | |
| 50 | |||
| 51 | 309 | std::vector<ModelObject> SetpointManager_Impl::children() const { | |
| 52 | 309 | std::vector<ModelObject> result; | |
| 53 | 309 | return result; | |
| 54 | } | ||
| 55 | |||
| 56 | /** Returns false by default. This is a virtual method which will be overriden for specific SPMs to return true | ||
| 57 | * if they are allowed on a plantLoop | ||
| 58 | **/ | ||
| 59 | 15 | bool SetpointManager_Impl::isAllowedOnPlantLoop() const { | |
| 60 | 15 | return false; | |
| 61 | } | ||
| 62 | |||
| 63 | 1106 | bool SetpointManager_Impl::addToNode(Node& node) { | |
| 64 |
4/5✓ Branch 1 taken 1106 times.
✓ Branch 4 taken 1106 times.
✓ Branch 7 taken 1106 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1106 times.
|
1106 | if (node.model() != this->model()) { |
| 65 | ✗ | return false; | |
| 66 | } | ||
| 67 | |||
| 68 | // Erase any existing setpoint manager that has the same control variable | ||
| 69 | // eg you can't have two temperature ones. But Humidity ones can be MaximumHumidityRatio or MinimumHumidityRatio so you can have a Min and Max | ||
| 70 |
1/1✓ Branch 1 taken 1106 times.
|
1106 | std::vector<SetpointManager> _setpointManagers = node.setpointManagers(); |
| 71 |
2/2✓ Branch 1 taken 42 times.
✓ Branch 2 taken 1064 times.
|
1106 | if (!_setpointManagers.empty()) { |
| 72 |
2/2✓ Branch 4 taken 59 times.
✓ Branch 5 taken 42 times.
|
101 | for (auto it = _setpointManagers.begin(); it != _setpointManagers.end(); ++it) { |
| 73 |
5/5✓ Branch 2 taken 59 times.
✓ Branch 5 taken 59 times.
✓ Branch 8 taken 59 times.
✓ Branch 12 taken 23 times.
✓ Branch 13 taken 36 times.
|
59 | if (istringEqual(this->controlVariable(), it->controlVariable())) { |
| 74 |
1/1✓ Branch 2 taken 23 times.
|
23 | it->remove(); |
| 75 | } | ||
| 76 | } | ||
| 77 | } | ||
| 78 | |||
| 79 |
3/3✓ Branch 1 taken 1106 times.
✓ Branch 3 taken 1060 times.
✓ Branch 4 taken 46 times.
|
2212 | if (OptionalAirLoopHVAC airLoop = node.airLoopHVAC()) { |
| 80 | // If this is one of the regular nodes of the supply path (eg not in the AirLoopHVACOASys) | ||
| 81 |
5/5✓ Branch 1 taken 1060 times.
✓ Branch 4 taken 1060 times.
✓ Branch 7 taken 1060 times.
✓ Branch 10 taken 888 times.
✓ Branch 11 taken 172 times.
|
2120 | if (airLoop->supplyComponent(node.handle())) { |
| 82 |
1/1✓ Branch 1 taken 888 times.
|
888 | return this->setSetpointNode(node); |
| 83 | } | ||
| 84 | 1106 | } | |
| 85 | |||
| 86 |
3/3✓ Branch 1 taken 218 times.
✓ Branch 3 taken 174 times.
✓ Branch 4 taken 44 times.
|
436 | if (OptionalAirLoopHVACOutdoorAirSystem oaSystem = node.airLoopHVACOutdoorAirSystem()) { |
| 87 | // We only accept it if it's neither the relief or the OA node (doesn't make sense to place one there) | ||
| 88 |
11/20✓ Branch 1 taken 174 times.
✓ Branch 4 taken 174 times.
✓ Branch 7 taken 174 times.
✓ Branch 9 taken 174 times.
✗ Branch 10 not taken.
✓ Branch 12 taken 174 times.
✓ Branch 15 taken 174 times.
✓ Branch 18 taken 174 times.
✓ Branch 20 taken 174 times.
✗ Branch 21 not taken.
✓ Branch 22 taken 174 times.
✗ Branch 23 not taken.
✓ Branch 25 taken 174 times.
✗ Branch 26 not taken.
✓ Branch 28 taken 174 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
|
174 | if ((node != oaSystem->outboardReliefNode()) && (node != oaSystem->outboardOANode())) { |
| 89 |
1/1✓ Branch 1 taken 174 times.
|
174 | return this->setSetpointNode(node); |
| 90 | } | ||
| 91 | 218 | } | |
| 92 | |||
| 93 | // If the specific SPM (derived class) is allowed on PlantLoop, then we allow it on the supply side, | ||
| 94 | // or the demand side EXCEPT on a demand branch | ||
| 95 |
3/3✓ Branch 1 taken 44 times.
✓ Branch 3 taken 43 times.
✓ Branch 4 taken 1 time.
|
88 | if (boost::optional<PlantLoop> plant = node.plantLoop()) { |
| 96 |
3/3✓ Branch 1 taken 43 times.
✓ Branch 3 taken 25 times.
✓ Branch 4 taken 18 times.
|
43 | if (this->isAllowedOnPlantLoop()) { |
| 97 | // If it's the supply side | ||
| 98 |
4/5✓ Branch 1 taken 25 times.
✓ Branch 4 taken 25 times.
✓ Branch 7 taken 25 times.
✓ Branch 10 taken 25 times.
✗ Branch 11 not taken.
|
50 | if (plant->supplyComponent(node.handle())) { |
| 99 |
1/1✓ Branch 1 taken 25 times.
|
25 | return this->setSetpointNode(node); |
| 100 | } else { | ||
| 101 | // On the demand side | ||
| 102 | ✗ | Splitter splitter = plant->demandSplitter(); | |
| 103 | ✗ | Mixer mixer = plant->demandMixer(); | |
| 104 | // We check that the node is NOT between the splitter and the mixer | ||
| 105 | ✗ | auto branchcomps = plant->demandComponents(splitter, mixer); | |
| 106 | ✗ | if (std::find(branchcomps.begin(), branchcomps.end(), node) == branchcomps.end()) { | |
| 107 | ✗ | return this->setSetpointNode(node); | |
| 108 | } else { | ||
| 109 | ✗ | LOG(Info, this->briefDescription() << " cannot be added on a demand branch"); | |
| 110 | } | ||
| 111 | ✗ | } | |
| 112 | } else { | ||
| 113 |
7/7✓ Branch 1 taken 18 times.
✓ Branch 4 taken 18 times.
✓ Branch 7 taken 18 times.
✓ Branch 10 taken 18 times.
✓ Branch 14 taken 18 times.
✓ Branch 17 taken 18 times.
✓ Branch 20 taken 18 times.
|
18 | LOG(Info, "This SetpointManager cannot be connected to a PlantLoop, for " << this->briefDescription()); |
| 114 | } | ||
| 115 | 44 | } | |
| 116 | |||
| 117 | 19 | return false; | |
| 118 | 1106 | } | |
| 119 | |||
| 120 | 106 | std::vector<openstudio::IdfObject> SetpointManager_Impl::remove() { | |
| 121 | 106 | return HVACComponent_Impl::remove(); | |
| 122 | } | ||
| 123 | |||
| 124 | 69 | ModelObject SetpointManager_Impl::clone(Model model) const { | |
| 125 |
3/3✓ Branch 1 taken 69 times.
✓ Branch 4 taken 69 times.
✓ Branch 7 taken 69 times.
|
69 | auto clonedObject = HVACComponent_Impl::clone(model).cast<SetpointManager>(); |
| 126 |
1/1✓ Branch 3 taken 69 times.
|
69 | clonedObject.getImpl<detail::SetpointManager_Impl>()->resetSetpointNode(); |
| 127 | 138 | return std::move(clonedObject); | |
| 128 | 69 | } | |
| 129 | |||
| 130 | 1 | boost::optional<Loop> SetpointManager_Impl::loop() const { | |
| 131 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
2 | if (boost::optional<Node> node = setpointNode()) { |
| 132 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | return node->loop(); |
| 133 | 1 | } | |
| 134 | ✗ | return boost::none; | |
| 135 | } | ||
| 136 | |||
| 137 | 1 | boost::optional<AirLoopHVAC> SetpointManager_Impl::airLoopHVAC() const { | |
| 138 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
2 | if (boost::optional<Node> node = setpointNode()) { |
| 139 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | return node->airLoopHVAC(); |
| 140 | 1 | } | |
| 141 | ✗ | return boost::none; | |
| 142 | } | ||
| 143 | |||
| 144 | 1 | boost::optional<AirLoopHVACOutdoorAirSystem> SetpointManager_Impl::airLoopHVACOutdoorAirSystem() const { | |
| 145 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
2 | if (boost::optional<Node> node = setpointNode()) { |
| 146 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | return node->airLoopHVACOutdoorAirSystem(); |
| 147 | 1 | } | |
| 148 | ✗ | return boost::none; | |
| 149 | } | ||
| 150 | |||
| 151 | 1 | boost::optional<PlantLoop> SetpointManager_Impl::plantLoop() const { | |
| 152 |
2/3✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
|
2 | if (boost::optional<Node> node = setpointNode()) { |
| 153 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
|
1 | return node->plantLoop(); |
| 154 | 1 | } | |
| 155 | ✗ | return boost::none; | |
| 156 | } | ||
| 157 | |||
| 158 | ✗ | ComponentType SetpointManager_Impl::componentType() const { | |
| 159 | ✗ | return ComponentType::None; | |
| 160 | } | ||
| 161 | |||
| 162 | ✗ | std::vector<FuelType> SetpointManager_Impl::coolingFuelTypes() const { | |
| 163 | ✗ | return {}; | |
| 164 | } | ||
| 165 | |||
| 166 | ✗ | std::vector<FuelType> SetpointManager_Impl::heatingFuelTypes() const { | |
| 167 | ✗ | return {}; | |
| 168 | } | ||
| 169 | |||
| 170 | ✗ | std::vector<AppGFuelType> SetpointManager_Impl::appGHeatingFuelTypes() const { | |
| 171 | ✗ | return {}; | |
| 172 | } | ||
| 173 | |||
| 174 | } // namespace detail | ||
| 175 | |||
| 176 | 1107 | SetpointManager::SetpointManager(IddObjectType type, const Model& model) : HVACComponent(type, model) { | |
| 177 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1107 times.
✗ Branch 5 not taken.
|
1107 | OS_ASSERT(getImpl<detail::SetpointManager_Impl>()); |
| 178 | 1107 | } | |
| 179 | |||
| 180 |
1/1✓ Branch 3 taken 4148 times.
|
4148 | SetpointManager::SetpointManager(std::shared_ptr<detail::SetpointManager_Impl> impl) : HVACComponent(std::move(impl)) {} |
| 181 | |||
| 182 | 3352 | boost::optional<Node> SetpointManager::setpointNode() const { | |
| 183 |
1/1✓ Branch 3 taken 3352 times.
|
3352 | return getImpl<detail::SetpointManager_Impl>()->setpointNode(); |
| 184 | } | ||
| 185 | |||
| 186 | 248 | std::string SetpointManager::controlVariable() const { | |
| 187 |
1/1✓ Branch 3 taken 248 times.
|
248 | return getImpl<detail::SetpointManager_Impl>()->controlVariable(); |
| 188 | } | ||
| 189 | |||
| 190 | 169 | bool SetpointManager::setControlVariable(const std::string& value) { | |
| 191 |
1/1✓ Branch 3 taken 169 times.
|
169 | return getImpl<detail::SetpointManager_Impl>()->setControlVariable(value); |
| 192 | } | ||
| 193 | |||
| 194 | ✗ | bool SetpointManager::isAllowedOnPlantLoop() const { | |
| 195 | ✗ | return getImpl<detail::SetpointManager_Impl>()->isAllowedOnPlantLoop(); | |
| 196 | } | ||
| 197 | |||
| 198 | } // namespace model | ||
| 199 | } // namespace openstudio | ||
| 200 |