src/model/Splitter.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 "Splitter.hpp" | ||
| 7 | #include "Splitter_Impl.hpp" | ||
| 8 | #include "Model.hpp" | ||
| 9 | #include "Node.hpp" | ||
| 10 | #include "Node_Impl.hpp" | ||
| 11 | #include "PortList.hpp" | ||
| 12 | #include "PortList_Impl.hpp" | ||
| 13 | |||
| 14 | #include "../utilities/core/Assert.hpp" | ||
| 15 | |||
| 16 | namespace openstudio { | ||
| 17 | |||
| 18 | namespace model { | ||
| 19 | |||
| 20 | namespace detail { | ||
| 21 | |||
| 22 | ✗ | Splitter_Impl::Splitter_Impl(IddObjectType type, Model_Impl* model) : HVACComponent_Impl(type, model) {} | |
| 23 | |||
| 24 | 1872 | Splitter_Impl::Splitter_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : HVACComponent_Impl(idfObject, model, keepHandle) {} | |
| 25 | |||
| 26 | 71 | Splitter_Impl::Splitter_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 27 | 71 | : HVACComponent_Impl(other, model, keepHandle) {} | |
| 28 | |||
| 29 | 823 | Splitter_Impl::Splitter_Impl(const Splitter_Impl& other, Model_Impl* model, bool keepHandles) : HVACComponent_Impl(other, model, keepHandles) {} | |
| 30 | |||
| 31 | 227 | boost::optional<ModelObject> Splitter_Impl::inletModelObject() const { | |
| 32 | 227 | return connectedObject(inletPort()); | |
| 33 | } | ||
| 34 | |||
| 35 | 31659 | boost::optional<ModelObject> Splitter_Impl::outletModelObject(unsigned branchIndex) const { | |
| 36 | 31659 | return connectedObject(outletPort(branchIndex)); | |
| 37 | } | ||
| 38 | |||
| 39 | 20965 | std::vector<HVACComponent> Splitter_Impl::edges(const boost::optional<HVACComponent>& /*prev*/) { | |
| 40 |
2/2✓ Branch 1 taken 20965 times.
✓ Branch 4 taken 20965 times.
|
20965 | return castVector<HVACComponent>(outletModelObjects()); |
| 41 | } | ||
| 42 | |||
| 43 | 629 | boost::optional<ModelObject> Splitter_Impl::lastOutletModelObject() const { | |
| 44 |
1/1✓ Branch 1 taken 629 times.
|
629 | std::vector<ModelObject> objects = outletModelObjects(); |
| 45 |
2/2✓ Branch 1 taken 542 times.
✓ Branch 2 taken 87 times.
|
629 | if (!objects.empty()) { |
| 46 |
1/1✓ Branch 2 taken 542 times.
|
542 | return OptionalModelObject(objects.back()); |
| 47 | } else { | ||
| 48 | 87 | return {}; | |
| 49 | } | ||
| 50 | 629 | } | |
| 51 | |||
| 52 | ✗ | unsigned Splitter_Impl::newOutletPortAfterBranch(unsigned branchIndex) { | |
| 53 | //std::vector<ModelObject> modelObjects = outletModelObjects(); | ||
| 54 | ✗ | int stop = nextBranchIndex() - 1; | |
| 55 | ✗ | for (int i = branchIndex; i < stop; i++) { | |
| 56 | ✗ | ModelObject mo = outletModelObject(i).get(); | |
| 57 | ✗ | unsigned port = connectedObjectPort(outletPort(i)).get(); | |
| 58 | ✗ | model().connect(getObject<ModelObject>(), outletPort(i + 2), mo, port); | |
| 59 | ✗ | } | |
| 60 | |||
| 61 | ✗ | Model _model = model(); | |
| 62 | ✗ | Node node(_model); | |
| 63 | |||
| 64 | ✗ | _model.connect(getObject<ModelObject>(), outletPort(branchIndex + 1), node, node.inletPort()); | |
| 65 | |||
| 66 | ✗ | return outletPort(branchIndex++); | |
| 67 | ✗ | } | |
| 68 | |||
| 69 | 138 | unsigned Splitter_Impl::branchIndexForOutletModelObject(ModelObject modelObject) const { | |
| 70 | 138 | int stop = nextBranchIndex(); | |
| 71 |
1/2✓ Branch 0 taken 186 times.
✗ Branch 1 not taken.
|
186 | for (int i = 0; i < stop; i++) { |
| 72 |
4/4✓ Branch 1 taken 186 times.
✓ Branch 4 taken 186 times.
✓ Branch 7 taken 138 times.
✓ Branch 8 taken 48 times.
|
186 | if (outletModelObject(i) == modelObject) { |
| 73 | 138 | return i; | |
| 74 | } | ||
| 75 | } | ||
| 76 | ✗ | return 0; | |
| 77 | } | ||
| 78 | |||
| 79 | 25312 | unsigned Splitter_Impl::nextBranchIndex() const { | |
| 80 | 25312 | unsigned i = 0; | |
| 81 | 25312 | OptionalModelObject modelObject; | |
| 82 |
2/2✓ Branch 1 taken 25312 times.
✓ Branch 4 taken 25312 times.
|
25312 | modelObject = connectedObject(this->outletPort(i)); |
| 83 |
2/2✓ Branch 0 taken 32721 times.
✓ Branch 1 taken 25312 times.
|
83345 | while (modelObject) { |
| 84 | 32721 | i++; | |
| 85 |
2/2✓ Branch 1 taken 32721 times.
✓ Branch 4 taken 32721 times.
|
32721 | modelObject = connectedObject(this->outletPort(i)); |
| 86 | } | ||
| 87 | 25312 | return i; | |
| 88 | 25312 | } | |
| 89 | |||
| 90 | 127 | void Splitter_Impl::removePortForBranch(unsigned branchIndex) { | |
| 91 | 127 | int _nextBranchIndex = nextBranchIndex(); | |
| 92 |
4/4✓ Branch 1 taken 127 times.
✓ Branch 4 taken 127 times.
✓ Branch 7 taken 127 times.
✓ Branch 10 taken 127 times.
|
127 | model().disconnect(getObject<ModelObject>(), outletPort(branchIndex)); |
| 93 | //std::vector<ModelObject> modelObjects = outletModelObjects(); | ||
| 94 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 127 times.
|
155 | for (int i = branchIndex + 1; i < _nextBranchIndex; i++) { |
| 95 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | ModelObject mo = outletModelObject(i).get(); |
| 96 |
3/3✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
|
28 | unsigned port = connectedObjectPort(outletPort(i)).get(); |
| 97 |
4/4✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
|
28 | model().disconnect(getObject<ModelObject>(), outletPort(i)); |
| 98 |
5/5✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✓ Branch 10 taken 28 times.
✓ Branch 13 taken 28 times.
|
28 | model().connect(getObject<ModelObject>(), outletPort(i - 1), mo, port); |
| 99 | 28 | } | |
| 100 | 127 | } | |
| 101 | |||
| 102 | 22837 | std::vector<ModelObject> Splitter_Impl::outletModelObjects() const { | |
| 103 | 22837 | std::vector<ModelObject> result; | |
| 104 |
1/1✓ Branch 1 taken 22837 times.
|
22837 | int stop = nextBranchIndex(); |
| 105 |
2/2✓ Branch 0 taken 31442 times.
✓ Branch 1 taken 22837 times.
|
54279 | for (int i = 0; i < stop; i++) { |
| 106 |
3/3✓ Branch 1 taken 31442 times.
✓ Branch 4 taken 31442 times.
✓ Branch 7 taken 31442 times.
|
31442 | result.push_back(this->outletModelObject(i).get()); |
| 107 | } | ||
| 108 | 22837 | return result; | |
| 109 | ✗ | } | |
| 110 | |||
| 111 | 28 | bool Splitter_Impl::isRemovable() const { | |
| 112 |
7/16✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 28 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 28 times.
✓ Branch 12 taken 28 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 28 times.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 28 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
84 | if (airLoopHVAC() || plantLoop()) { |
| 113 | ✗ | return false; | |
| 114 | } else { | ||
| 115 | 28 | return true; | |
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 119 | 5 | void Splitter_Impl::disconnect() { | |
| 120 |
1/1✓ Branch 1 taken 5 times.
|
5 | auto mo = this->getObject<ModelObject>(); |
| 121 |
1/1✓ Branch 1 taken 5 times.
|
5 | auto _model = model(); |
| 122 | |||
| 123 |
3/3✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
|
5 | _model.disconnect(mo, inletPort()); |
| 124 |
1/1✓ Branch 1 taken 5 times.
|
5 | auto end = nextBranchIndex(); |
| 125 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | for (unsigned i = 0; i != end; ++i) { |
| 126 |
3/3✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 7 taken 2 times.
|
2 | _model.disconnect(mo, outletPort(i)); |
| 127 | } | ||
| 128 | 5 | } | |
| 129 | |||
| 130 | //bool Splitter_Impl::addToNode(Node & node) | ||
| 131 | //{ | ||
| 132 | // return false; | ||
| 133 | //} | ||
| 134 | |||
| 135 | //ModelObject Splitter_Impl::clone(Model model) const | ||
| 136 | //{ | ||
| 137 | // return HVACComponent_Impl::clone( model ); | ||
| 138 | //} | ||
| 139 | |||
| 140 | } // namespace detail | ||
| 141 | |||
| 142 |
1/1✓ Branch 3 taken 3584 times.
|
3584 | Splitter::Splitter(std::shared_ptr<detail::Splitter_Impl> p) : HVACComponent(std::move(p)) {} |
| 143 | |||
| 144 | 1800 | Splitter::Splitter(IddObjectType type, const Model& model) : HVACComponent(type, model) { | |
| 145 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1800 times.
✗ Branch 5 not taken.
|
1800 | OS_ASSERT(getImpl<detail::Splitter_Impl>()); |
| 146 | 1800 | } | |
| 147 | |||
| 148 | ✗ | unsigned Splitter::inletPort() const { | |
| 149 | ✗ | return getImpl<detail::Splitter_Impl>()->inletPort(); | |
| 150 | } | ||
| 151 | |||
| 152 | ✗ | unsigned Splitter::outletPort(unsigned branchIndex) const { | |
| 153 | ✗ | return getImpl<detail::Splitter_Impl>()->outletPort(branchIndex); | |
| 154 | } | ||
| 155 | |||
| 156 | 198 | unsigned Splitter::nextOutletPort() const { | |
| 157 |
1/1✓ Branch 3 taken 198 times.
|
198 | return getImpl<detail::Splitter_Impl>()->nextOutletPort(); |
| 158 | } | ||
| 159 | |||
| 160 | 222 | boost::optional<ModelObject> Splitter::inletModelObject() const { | |
| 161 |
1/1✓ Branch 3 taken 222 times.
|
222 | return getImpl<detail::Splitter_Impl>()->inletModelObject(); |
| 162 | } | ||
| 163 | |||
| 164 | 3 | boost::optional<ModelObject> Splitter::outletModelObject(unsigned branchIndex) const { | |
| 165 |
1/1✓ Branch 3 taken 3 times.
|
3 | return getImpl<detail::Splitter_Impl>()->outletModelObject(branchIndex); |
| 166 | } | ||
| 167 | |||
| 168 | 629 | boost::optional<ModelObject> Splitter::lastOutletModelObject() const { | |
| 169 |
1/1✓ Branch 3 taken 629 times.
|
629 | return getImpl<detail::Splitter_Impl>()->lastOutletModelObject(); |
| 170 | } | ||
| 171 | |||
| 172 | 1214 | std::vector<ModelObject> Splitter::outletModelObjects() const { | |
| 173 |
1/1✓ Branch 3 taken 1214 times.
|
1214 | return getImpl<detail::Splitter_Impl>()->outletModelObjects(); |
| 174 | } | ||
| 175 | |||
| 176 | ✗ | unsigned Splitter::newOutletPortAfterBranch(unsigned branchIndex) { | |
| 177 | ✗ | return getImpl<detail::Splitter_Impl>()->newOutletPortAfterBranch(branchIndex); | |
| 178 | } | ||
| 179 | |||
| 180 | 127 | unsigned Splitter::branchIndexForOutletModelObject(ModelObject modelObject) const { | |
| 181 |
2/2✓ Branch 3 taken 127 times.
✓ Branch 6 taken 127 times.
|
127 | return getImpl<detail::Splitter_Impl>()->branchIndexForOutletModelObject(modelObject); |
| 182 | } | ||
| 183 | |||
| 184 | 4 | unsigned Splitter::nextBranchIndex() const { | |
| 185 |
1/1✓ Branch 3 taken 4 times.
|
4 | return getImpl<detail::Splitter_Impl>()->nextBranchIndex(); |
| 186 | } | ||
| 187 | |||
| 188 | 127 | void Splitter::removePortForBranch(unsigned branchIndex) { | |
| 189 |
1/1✓ Branch 3 taken 127 times.
|
127 | return getImpl<detail::Splitter_Impl>()->removePortForBranch(branchIndex); |
| 190 | } | ||
| 191 | |||
| 192 | } // namespace model | ||
| 193 | |||
| 194 | } // namespace openstudio | ||
| 195 |