src/model/Mixer.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 "Model.hpp" | ||
| 7 | #include "Mixer.hpp" | ||
| 8 | #include "Mixer_Impl.hpp" | ||
| 9 | #include "Node.hpp" | ||
| 10 | #include "Node_Impl.hpp" | ||
| 11 | |||
| 12 | #include "../utilities/core/Assert.hpp" | ||
| 13 | |||
| 14 | namespace openstudio { | ||
| 15 | |||
| 16 | namespace model { | ||
| 17 | |||
| 18 | namespace detail { | ||
| 19 | |||
| 20 | ✗ | Mixer_Impl::Mixer_Impl(IddObjectType type, Model_Impl* model) : HVACComponent_Impl(type, model) {} | |
| 21 | |||
| 22 | 1857 | Mixer_Impl::Mixer_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) : HVACComponent_Impl(idfObject, model, keepHandle) {} | |
| 23 | |||
| 24 | 71 | Mixer_Impl::Mixer_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 25 | 71 | : HVACComponent_Impl(other, model, keepHandle) {} | |
| 26 | |||
| 27 | 827 | Mixer_Impl::Mixer_Impl(const Mixer_Impl& other, Model_Impl* model, bool keepHandles) : HVACComponent_Impl(other, model, keepHandles) {} | |
| 28 | |||
| 29 | 27607 | boost::optional<ModelObject> Mixer_Impl::outletModelObject() const { | |
| 30 | 27607 | return connectedObject(outletPort()); | |
| 31 | } | ||
| 32 | |||
| 33 | 1847 | boost::optional<ModelObject> Mixer_Impl::inletModelObject(unsigned branchIndex) const { | |
| 34 | 1847 | return connectedObject(inletPort(branchIndex)); | |
| 35 | } | ||
| 36 | |||
| 37 | 740 | boost::optional<ModelObject> Mixer_Impl::lastInletModelObject() const { | |
| 38 |
1/1✓ Branch 1 taken 740 times.
|
740 | std::vector<ModelObject> objects = inletModelObjects(); |
| 39 |
1/2✓ Branch 1 taken 740 times.
✗ Branch 2 not taken.
|
740 | if (!objects.empty()) { |
| 40 |
1/1✓ Branch 2 taken 740 times.
|
740 | return OptionalModelObject(objects.back()); |
| 41 | } else { | ||
| 42 | ✗ | return {}; | |
| 43 | } | ||
| 44 | 740 | } | |
| 45 | |||
| 46 | ✗ | unsigned Mixer_Impl::newInletPortAfterBranch(unsigned branchIndex) { | |
| 47 | //std::vector<ModelObject> modelObjects = inletModelObjects(); | ||
| 48 | ✗ | unsigned stop = nextBranchIndex(); | |
| 49 | ✗ | for (unsigned i = branchIndex; i < stop; i++) { | |
| 50 | ✗ | ModelObject mo = inletModelObject(i).get(); | |
| 51 | ✗ | unsigned port = connectedObjectPort(inletPort(i)).get(); | |
| 52 | ✗ | model().connect(getObject<ModelObject>(), inletPort(i + 2), mo, port); | |
| 53 | ✗ | } | |
| 54 | |||
| 55 | ✗ | Model _model = model(); | |
| 56 | ✗ | Node node(_model); | |
| 57 | |||
| 58 | ✗ | _model.connect(node, node.outletPort(), getObject<ModelObject>(), inletPort(branchIndex + 1)); | |
| 59 | |||
| 60 | ✗ | return inletPort(branchIndex++); | |
| 61 | ✗ | } | |
| 62 | |||
| 63 | 133 | unsigned Mixer_Impl::branchIndexForInletModelObject(const ModelObject& modelObject) const { | |
| 64 | 133 | unsigned stop = nextBranchIndex(); | |
| 65 | |||
| 66 |
1/2✓ Branch 0 taken 184 times.
✗ Branch 1 not taken.
|
184 | for (unsigned i = 0; i < stop; i++) { |
| 67 |
4/4✓ Branch 1 taken 184 times.
✓ Branch 4 taken 184 times.
✓ Branch 7 taken 133 times.
✓ Branch 8 taken 51 times.
|
184 | if (inletModelObject(i) == modelObject) { |
| 68 | 133 | return i; | |
| 69 | } | ||
| 70 | } | ||
| 71 | ✗ | return 0; | |
| 72 | } | ||
| 73 | |||
| 74 | 3822 | unsigned Mixer_Impl::nextBranchIndex() const { | |
| 75 | 3822 | unsigned i = 0; | |
| 76 | 3822 | OptionalModelObject modelObject; | |
| 77 |
2/2✓ Branch 1 taken 3822 times.
✓ Branch 4 taken 3822 times.
|
3822 | modelObject = connectedObject(this->inletPort(i)); |
| 78 |
2/2✓ Branch 0 taken 2817 times.
✓ Branch 1 taken 3822 times.
|
10461 | while (modelObject) { |
| 79 | 2817 | i++; | |
| 80 |
2/2✓ Branch 1 taken 2817 times.
✓ Branch 4 taken 2817 times.
|
2817 | modelObject = connectedObject(this->inletPort(i)); |
| 81 | } | ||
| 82 | 3822 | return i; | |
| 83 | 3822 | } | |
| 84 | |||
| 85 | 123 | void Mixer_Impl::removePortForBranch(unsigned branchIndex) { | |
| 86 | 123 | int _nextBranchIndex = nextBranchIndex(); | |
| 87 |
4/4✓ Branch 1 taken 123 times.
✓ Branch 4 taken 123 times.
✓ Branch 7 taken 123 times.
✓ Branch 10 taken 123 times.
|
123 | model().disconnect(getObject<ModelObject>(), inletPort(branchIndex)); |
| 88 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 123 times.
|
150 | for (int i = branchIndex + 1; i < _nextBranchIndex; i++) { |
| 89 |
3/3✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
|
27 | ModelObject mo = inletModelObject(i).get(); |
| 90 |
3/3✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
|
27 | unsigned port = connectedObjectPort(inletPort(i)).get(); |
| 91 |
4/4✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
✓ Branch 10 taken 27 times.
|
27 | model().disconnect(getObject<ModelObject>(), inletPort(i)); |
| 92 |
5/5✓ Branch 1 taken 27 times.
✓ Branch 4 taken 27 times.
✓ Branch 7 taken 27 times.
✓ Branch 10 taken 27 times.
✓ Branch 13 taken 27 times.
|
27 | model().connect(mo, port, getObject<ModelObject>(), inletPort(i - 1)); |
| 93 | 27 | } | |
| 94 | 123 | } | |
| 95 | |||
| 96 | 1453 | std::vector<ModelObject> Mixer_Impl::inletModelObjects() const { | |
| 97 | 1453 | std::vector<ModelObject> result; | |
| 98 |
1/1✓ Branch 1 taken 1453 times.
|
1453 | unsigned stop = nextBranchIndex(); |
| 99 |
2/2✓ Branch 0 taken 1589 times.
✓ Branch 1 taken 1453 times.
|
3042 | for (unsigned i = 0; i < stop; i++) { |
| 100 |
3/3✓ Branch 1 taken 1589 times.
✓ Branch 4 taken 1589 times.
✓ Branch 7 taken 1589 times.
|
1589 | result.push_back(this->inletModelObject(i).get()); |
| 101 | } | ||
| 102 | 1453 | return result; | |
| 103 | ✗ | } | |
| 104 | |||
| 105 | 27371 | std::vector<HVACComponent> Mixer_Impl::edges(const boost::optional<HVACComponent>& /*prev*/) { | |
| 106 | 27371 | std::vector<HVACComponent> edges; | |
| 107 |
2/3✓ Branch 1 taken 27371 times.
✓ Branch 3 taken 27371 times.
✗ Branch 4 not taken.
|
54742 | if (auto edgeModelObject = this->outletModelObject()) { |
| 108 |
3/4✓ Branch 1 taken 27371 times.
✓ Branch 4 taken 27371 times.
✓ Branch 6 taken 27371 times.
✗ Branch 7 not taken.
|
54742 | if (auto edgeObject = edgeModelObject->optionalCast<HVACComponent>()) { |
| 109 |
2/2✓ Branch 1 taken 27371 times.
✓ Branch 4 taken 27371 times.
|
27371 | edges.push_back(*edgeObject); |
| 110 | 27371 | } | |
| 111 | 27371 | } | |
| 112 | 27371 | return edges; | |
| 113 | ✗ | } | |
| 114 | |||
| 115 | 21 | bool Mixer_Impl::isRemovable() const { | |
| 116 |
7/16✓ Branch 1 taken 21 times.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 21 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 21 times.
✓ Branch 12 taken 21 times.
✗ Branch 13 not taken.
✓ Branch 15 taken 21 times.
✗ Branch 16 not taken.
✗ Branch 18 not taken.
✓ Branch 19 taken 21 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
|
63 | if (airLoopHVAC() || plantLoop()) { |
| 117 | ✗ | return false; | |
| 118 | } else { | ||
| 119 | 21 | return true; | |
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | } // namespace detail | ||
| 124 | |||
| 125 |
1/1✓ Branch 3 taken 2670 times.
|
2670 | Mixer::Mixer(std::shared_ptr<detail::Mixer_Impl> p) : HVACComponent(std::move(p)) {} |
| 126 | |||
| 127 | 1785 | Mixer::Mixer(IddObjectType type, const Model& model) : HVACComponent(type, model) { | |
| 128 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1785 times.
✗ Branch 5 not taken.
|
1785 | OS_ASSERT(getImpl<detail::Mixer_Impl>()); |
| 129 | 1785 | } | |
| 130 | |||
| 131 | ✗ | unsigned Mixer::outletPort() const { | |
| 132 | ✗ | return getImpl<detail::Mixer_Impl>()->outletPort(); | |
| 133 | } | ||
| 134 | |||
| 135 | ✗ | unsigned Mixer::inletPort(unsigned branchIndex) const { | |
| 136 | ✗ | return getImpl<detail::Mixer_Impl>()->inletPort(branchIndex); | |
| 137 | } | ||
| 138 | |||
| 139 | 198 | unsigned Mixer::nextInletPort() const { | |
| 140 |
1/1✓ Branch 3 taken 198 times.
|
198 | return getImpl<detail::Mixer_Impl>()->nextInletPort(); |
| 141 | } | ||
| 142 | |||
| 143 | 232 | boost::optional<ModelObject> Mixer::outletModelObject() const { | |
| 144 |
1/1✓ Branch 3 taken 232 times.
|
232 | return getImpl<detail::Mixer_Impl>()->outletModelObject(); |
| 145 | } | ||
| 146 | |||
| 147 | 29 | boost::optional<ModelObject> Mixer::inletModelObject(unsigned branchIndex) const { | |
| 148 |
1/1✓ Branch 3 taken 29 times.
|
29 | return getImpl<detail::Mixer_Impl>()->inletModelObject(branchIndex); |
| 149 | } | ||
| 150 | |||
| 151 | 740 | boost::optional<ModelObject> Mixer::lastInletModelObject() const { | |
| 152 |
1/1✓ Branch 3 taken 740 times.
|
740 | return getImpl<detail::Mixer_Impl>()->lastInletModelObject(); |
| 153 | } | ||
| 154 | |||
| 155 | 706 | std::vector<ModelObject> Mixer::inletModelObjects() const { | |
| 156 |
1/1✓ Branch 3 taken 706 times.
|
706 | return getImpl<detail::Mixer_Impl>()->inletModelObjects(); |
| 157 | } | ||
| 158 | |||
| 159 | ✗ | unsigned Mixer::newInletPortAfterBranch(unsigned branchIndex) { | |
| 160 | ✗ | return getImpl<detail::Mixer_Impl>()->newInletPortAfterBranch(branchIndex); | |
| 161 | } | ||
| 162 | |||
| 163 | 123 | unsigned Mixer::branchIndexForInletModelObject(const ModelObject& modelObject) const { | |
| 164 |
1/1✓ Branch 3 taken 123 times.
|
123 | return getImpl<detail::Mixer_Impl>()->branchIndexForInletModelObject(modelObject); |
| 165 | } | ||
| 166 | |||
| 167 | 2 | unsigned Mixer::nextBranchIndex() const { | |
| 168 |
1/1✓ Branch 3 taken 2 times.
|
2 | return getImpl<detail::Mixer_Impl>()->nextBranchIndex(); |
| 169 | } | ||
| 170 | |||
| 171 | 123 | void Mixer::removePortForBranch(unsigned branchIndex) { | |
| 172 |
1/1✓ Branch 3 taken 123 times.
|
123 | return getImpl<detail::Mixer_Impl>()->removePortForBranch(branchIndex); |
| 173 | } | ||
| 174 | |||
| 175 | } // namespace model | ||
| 176 | |||
| 177 | } // namespace openstudio | ||
| 178 |