src/model/ConnectorSplitter.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 "ConnectorSplitter.hpp" | ||
| 7 | #include "ConnectorSplitter_Impl.hpp" | ||
| 8 | #include "AirLoopHVAC.hpp" | ||
| 9 | #include "AirLoopHVAC_Impl.hpp" | ||
| 10 | #include "Node.hpp" | ||
| 11 | #include "Model.hpp" | ||
| 12 | #include "Model_Impl.hpp" | ||
| 13 | |||
| 14 | #include "../utilities/core/Assert.hpp" | ||
| 15 | #include "../utilities/core/Compare.hpp" | ||
| 16 | #include "../utilities/data/DataEnums.hpp" | ||
| 17 | |||
| 18 | #include <utilities/idd/OS_Connector_Splitter_FieldEnums.hxx> | ||
| 19 | #include <utilities/idd/IddEnums.hxx> | ||
| 20 | |||
| 21 | namespace openstudio { | ||
| 22 | |||
| 23 | namespace model { | ||
| 24 | |||
| 25 | namespace detail { | ||
| 26 | |||
| 27 | 1086 | ConnectorSplitter_Impl::ConnectorSplitter_Impl(const IdfObject& idfObject, Model_Impl* model, bool keepHandle) | |
| 28 | 1086 | : Splitter_Impl(idfObject, model, keepHandle) { | |
| 29 |
4/6✓ Branch 1 taken 1086 times.
✓ Branch 4 taken 1086 times.
✓ Branch 7 taken 1086 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 1086 times.
✗ Branch 13 not taken.
|
1086 | OS_ASSERT(idfObject.iddObject().type() == ConnectorSplitter::iddObjectType()); |
| 30 | 1086 | } | |
| 31 | |||
| 32 | 28 | ConnectorSplitter_Impl::ConnectorSplitter_Impl(const openstudio::detail::WorkspaceObject_Impl& other, Model_Impl* model, bool keepHandle) | |
| 33 | 28 | : Splitter_Impl(other, model, keepHandle) { | |
| 34 |
4/6✓ Branch 1 taken 28 times.
✓ Branch 4 taken 28 times.
✓ Branch 7 taken 28 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 28 times.
✗ Branch 13 not taken.
|
28 | OS_ASSERT(other.iddObject().type() == ConnectorSplitter::iddObjectType()); |
| 35 | 28 | } | |
| 36 | |||
| 37 | 555 | ConnectorSplitter_Impl::ConnectorSplitter_Impl(const ConnectorSplitter_Impl& other, Model_Impl* model, bool keepHandle) | |
| 38 | 555 | : Splitter_Impl(other, model, keepHandle) {} | |
| 39 | |||
| 40 | ✗ | const std::vector<std::string>& ConnectorSplitter_Impl::outputVariableNames() const { | |
| 41 | ✗ | static const std::vector<std::string> result; | |
| 42 | ✗ | return result; | |
| 43 | } | ||
| 44 | |||
| 45 | 506 | IddObjectType ConnectorSplitter_Impl::iddObjectType() const { | |
| 46 | 506 | return ConnectorSplitter::iddObjectType(); | |
| 47 | } | ||
| 48 | |||
| 49 | 5 | std::vector<openstudio::IdfObject> ConnectorSplitter_Impl::remove() { | |
| 50 |
3/3✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
|
5 | OptionalConnectorSplitter self = model().getModelObject<ConnectorSplitter>(handle()); |
| 51 |
5/5✓ Branch 1 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 7 taken 5 times.
✓ Branch 10 taken 5 times.
✓ Branch 13 taken 5 times.
|
5 | model().disconnect(*self, inletPort()); |
| 52 |
2/3✓ Branch 1 taken 5 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5 times.
|
5 | for (int i = 0; i < int(nextBranchIndex()) - 1; i++) { |
| 53 | ✗ | model().disconnect(*self, outletPort(i)); | |
| 54 | } | ||
| 55 |
1/1✓ Branch 1 taken 5 times.
|
10 | return ModelObject_Impl::remove(); |
| 56 | 5 | } | |
| 57 | |||
| 58 | 1088 | unsigned ConnectorSplitter_Impl::inletPort() const { | |
| 59 | 1088 | return OS_Connector_SplitterFields::InletBranchName; | |
| 60 | } | ||
| 61 | |||
| 62 | 53261 | unsigned ConnectorSplitter_Impl::outletPort(unsigned branchIndex) const { | |
| 63 | unsigned result; | ||
| 64 | 53261 | result = numNonextensibleFields(); | |
| 65 | 53261 | result = result + branchIndex; | |
| 66 | 53261 | return result; | |
| 67 | } | ||
| 68 | |||
| 69 | 1264 | unsigned ConnectorSplitter_Impl::nextOutletPort() const { | |
| 70 | 1264 | return outletPort(this->nextBranchIndex()); | |
| 71 | } | ||
| 72 | |||
| 73 | 24 | bool ConnectorSplitter_Impl::addToNode(Node& node) { | |
| 74 |
1/1✓ Branch 1 taken 24 times.
|
24 | auto t_model = model(); |
| 75 | |||
| 76 |
3/4✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 24 times.
|
24 | if (node.model() != t_model) { |
| 77 | ✗ | return false; | |
| 78 | } | ||
| 79 | |||
| 80 |
2/3✓ Branch 1 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 24 times.
|
48 | if (loop()) { |
| 81 | ✗ | return false; | |
| 82 | } | ||
| 83 | |||
| 84 |
2/3✓ Branch 1 taken 24 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
|
24 | if (!outletModelObjects().empty()) { |
| 85 | ✗ | LOG(Warn, briefDescription() << " must not have existing outlet connections to use addToNode method."); | |
| 86 | ✗ | return false; | |
| 87 | } | ||
| 88 | |||
| 89 |
1/1✓ Branch 1 taken 24 times.
|
24 | auto t_nodeAirLoop = node.airLoopHVAC(); |
| 90 | |||
| 91 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24 times.
|
24 | if (!t_nodeAirLoop) { |
| 92 | ✗ | LOG(Warn, briefDescription() << " must be added to an AirLoopHVAC supply node use addToNode method."); | |
| 93 | ✗ | return false; | |
| 94 | } | ||
| 95 | |||
| 96 |
4/5✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 7 taken 24 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 24 times.
|
24 | if (!t_nodeAirLoop->supplyComponent(node.handle())) { |
| 97 | ✗ | LOG(Warn, briefDescription() << " must be added to an AirLoopHVAC supply node use addToNode method."); | |
| 98 | ✗ | return false; | |
| 99 | } | ||
| 100 | |||
| 101 |
4/5✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 7 taken 24 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 24 times.
|
24 | if (!t_nodeAirLoop->supplyComponents(iddObjectType()).empty()) { |
| 102 | ✗ | LOG(Warn, briefDescription() << " already has a splitter."); | |
| 103 | ✗ | return false; | |
| 104 | } | ||
| 105 | |||
| 106 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
|
24 | auto supplyInletNode = t_nodeAirLoop->supplyInletNode(); |
| 107 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
|
24 | auto supplyOutletNode = t_nodeAirLoop->supplyOutletNode(); |
| 108 | |||
| 109 | // Hook Up Duct "A" | ||
| 110 |
1/1✓ Branch 1 taken 24 times.
|
24 | auto t_inletPort = inletPort(); |
| 111 |
1/1✓ Branch 1 taken 24 times.
|
24 | auto portA = nextOutletPort(); |
| 112 |
1/1✓ Branch 1 taken 24 times.
|
24 | HVACComponent_Impl::addToNode(node, supplyInletNode, supplyOutletNode, t_inletPort, portA); |
| 113 | |||
| 114 | // Hook Up Duct "B" | ||
| 115 |
1/1✓ Branch 1 taken 24 times.
|
24 | Node supplyOutletNodeB(t_model); |
| 116 |
1/1✓ Branch 1 taken 24 times.
|
24 | auto thisObject = getObject<model::HVACComponent>(); |
| 117 |
1/1✓ Branch 1 taken 24 times.
|
24 | auto portB = nextOutletPort(); |
| 118 |
4/4✓ Branch 1 taken 24 times.
✓ Branch 4 taken 24 times.
✓ Branch 7 taken 24 times.
✓ Branch 10 taken 24 times.
|
24 | t_model.connect(thisObject, portB, supplyOutletNodeB, supplyOutletNodeB.inletPort()); |
| 119 |
6/6✓ Branch 2 taken 24 times.
✓ Branch 5 taken 24 times.
✓ Branch 8 taken 24 times.
✓ Branch 11 taken 24 times.
✓ Branch 14 taken 24 times.
✓ Branch 17 taken 24 times.
|
24 | t_model.connect(supplyOutletNodeB, supplyOutletNodeB.outletPort(), t_nodeAirLoop.get(), |
| 120 |
1/1✓ Branch 1 taken 24 times.
|
48 | t_nodeAirLoop->getImpl<detail::AirLoopHVAC_Impl>()->supplyOutletPortB()); |
| 121 | |||
| 122 | 24 | return true; | |
| 123 | 24 | } | |
| 124 | |||
| 125 | ✗ | ModelObject ConnectorSplitter_Impl::clone(Model model) const { | |
| 126 | ✗ | return HVACComponent_Impl::clone(model); | |
| 127 | } | ||
| 128 | |||
| 129 | 741 | ComponentType ConnectorSplitter_Impl::componentType() const { | |
| 130 |
1/1✓ Branch 1 taken 741 times.
|
741 | return ComponentType::None; |
| 131 | } | ||
| 132 | |||
| 133 | 27 | std::vector<FuelType> ConnectorSplitter_Impl::coolingFuelTypes() const { | |
| 134 | 27 | return {}; | |
| 135 | } | ||
| 136 | |||
| 137 | 43 | std::vector<FuelType> ConnectorSplitter_Impl::heatingFuelTypes() const { | |
| 138 | 43 | return {}; | |
| 139 | } | ||
| 140 | |||
| 141 | 41 | std::vector<AppGFuelType> ConnectorSplitter_Impl::appGHeatingFuelTypes() const { | |
| 142 | 41 | return {}; | |
| 143 | } | ||
| 144 | |||
| 145 | } // namespace detail | ||
| 146 | |||
| 147 | 1058 | ConnectorSplitter::ConnectorSplitter(const Model& model) : Splitter(ConnectorSplitter::iddObjectType(), model) { | |
| 148 |
1/3✗ Branch 2 not taken.
✓ Branch 3 taken 1058 times.
✗ Branch 5 not taken.
|
1058 | OS_ASSERT(getImpl<detail::ConnectorSplitter_Impl>()); |
| 149 | 1058 | } | |
| 150 | |||
| 151 |
1/1✓ Branch 3 taken 6 times.
|
6 | ConnectorSplitter::ConnectorSplitter(std::shared_ptr<detail::ConnectorSplitter_Impl> p) : Splitter(std::move(p)) {} |
| 152 | |||
| 153 | ✗ | std::vector<openstudio::IdfObject> ConnectorSplitter::remove() { | |
| 154 | ✗ | return getImpl<detail::ConnectorSplitter_Impl>()->remove(); | |
| 155 | } | ||
| 156 | |||
| 157 | 1034 | unsigned ConnectorSplitter::inletPort() const { | |
| 158 |
1/1✓ Branch 3 taken 1034 times.
|
1034 | return getImpl<detail::ConnectorSplitter_Impl>()->inletPort(); |
| 159 | } | ||
| 160 | |||
| 161 | ✗ | unsigned ConnectorSplitter::outletPort(unsigned branchIndex) const { | |
| 162 | ✗ | return getImpl<detail::ConnectorSplitter_Impl>()->outletPort(branchIndex); | |
| 163 | } | ||
| 164 | |||
| 165 | 1034 | unsigned ConnectorSplitter::nextOutletPort() const { | |
| 166 |
1/1✓ Branch 3 taken 1034 times.
|
1034 | return getImpl<detail::ConnectorSplitter_Impl>()->nextOutletPort(); |
| 167 | } | ||
| 168 | |||
| 169 | 24 | bool ConnectorSplitter::addToNode(Node& node) { | |
| 170 |
1/1✓ Branch 3 taken 24 times.
|
24 | return getImpl<detail::ConnectorSplitter_Impl>()->addToNode(node); |
| 171 | } | ||
| 172 | |||
| 173 | ✗ | ModelObject ConnectorSplitter::clone(Model model) const { | |
| 174 | ✗ | return getImpl<detail::ConnectorSplitter_Impl>()->clone(model); | |
| 175 | } | ||
| 176 | |||
| 177 | 10291 | IddObjectType ConnectorSplitter::iddObjectType() { | |
| 178 |
1/1✓ Branch 1 taken 10291 times.
|
10291 | IddObjectType result(IddObjectType::OS_Connector_Splitter); |
| 179 | 10291 | return result; | |
| 180 | } | ||
| 181 | |||
| 182 | } // namespace model | ||
| 183 | } // namespace openstudio | ||
| 184 |