bool SizingPlant_Impl::setPlantLoopAsModelObject(const boost::optional<ModelObject>& modelObject) { if (modelObject) { OptionalPlantLoop intermediate = modelObject->optionalCast<PlantLoop>(); if (intermediate) { PlantLoop plantLoop(*intermediate); return setPlantLoop(plantLoop); } } return false; }
bool Mixer_Impl::isRemovable() const { if( airLoopHVAC() || plantLoop() ) { return false; } else { return true; } }
bool WaterToAirComponent_Impl::removeFromPlantLoop() { if( auto plant = plantLoop() ) { return HVACComponent_Impl::removeFromLoop(plant->demandInletNode(), plant->demandOutletNode(), waterInletPort(), waterOutletPort()); } return false; }
bool WaterToWaterComponent_Impl::removeFromPlantLoop() { if( auto plant = plantLoop() ) { return HVACComponent_Impl::removeFromLoop(plant->supplyInletNode(), plant->supplyOutletNode(), supplyInletPort(), supplyOutletPort()); } return false; }
void TemperingValve_Impl::setControlNodes() { auto plant = plantLoop(); if( ! plant ) return; if( ! pumpOutletNode() ) { std::vector<ModelObject> allpumps; auto pumps = plant->supplyComponents(PumpVariableSpeed::iddObjectType()); allpumps.insert(allpumps.end(),pumps.begin(),pumps.end()); pumps = plant->supplyComponents(PumpConstantSpeed::iddObjectType()); allpumps.insert(allpumps.end(),pumps.begin(),pumps.end()); pumps = plant->supplyComponents(HeaderedPumpsConstantSpeed::iddObjectType()); allpumps.insert(allpumps.end(),pumps.begin(),pumps.end()); pumps = plant->supplyComponents(HeaderedPumpsVariableSpeed::iddObjectType()); allpumps.insert(allpumps.end(),pumps.begin(),pumps.end()); if( ! allpumps.empty() ) { if( auto mo = allpumps.back().cast<StraightComponent>().outletModelObject() ) { if( auto node = mo->optionalCast<Node>() ) { setPumpOutletNode(node); } } } } if( ! temperatureSetpointNode() ) { auto node = plant->supplyOutletNode(); setTemperatureSetpointNode(node); } auto mixer = plant->supplyMixer(); if( ! stream2SourceNode() ) { TemperingValve thisObject = getObject<TemperingValve>(); auto inletObjects = mixer.inletModelObjects(); for( auto & inletObject : inletObjects ) { if( auto node = inletObject.optionalCast<Node>() ) { if( plant->supplyComponents(thisObject,node.get()).empty() ) { setStream2SourceNode(node.get()); } } } } }
boost::optional<ModelObject> SizingPlant_Impl::plantLoopAsModelObject() const { OptionalModelObject result = plantLoop(); return result; }
bool WaterToAirComponent_Impl::removeFromPlantLoop() { boost::optional<PlantLoop> _loop = plantLoop(); OptionalNode targetModelObject; OptionalNode sourceModelObject; OptionalUnsigned targetPort; OptionalUnsigned sourcePort; OptionalModelObject target2ModelObject; OptionalModelObject source2ModelObject; OptionalUnsigned target2Port; OptionalUnsigned source2Port; HVACComponent thisObject = getObject<HVACComponent>(); if( _loop && _loop->demandComponent(handle()) ) { targetModelObject = waterOutletModelObject()->optionalCast<Node>(); sourceModelObject = waterInletModelObject()->optionalCast<Node>(); targetPort = connectedObjectPort(waterOutletPort()); sourcePort = connectedObjectPort(waterInletPort()); target2ModelObject = targetModelObject->outletModelObject(); source2ModelObject = sourceModelObject->inletModelObject(); target2Port = targetModelObject->connectedObjectPort(targetModelObject->outletPort()); source2Port = sourceModelObject->connectedObjectPort(sourceModelObject->inletPort()); boost::optional<Node> demandInletNode = _loop->demandInletNode(); boost::optional<Node> demandOutletNode = _loop->demandOutletNode(); Mixer mixer = _loop->demandMixer(); Splitter splitter = _loop->demandSplitter(); // If the component is stuck directly between the inlet and outlet node. if( demandInletNode->handle() == waterInletModelObject()->handle() && demandOutletNode->handle() == waterOutletModelObject()->handle() ) { model().disconnect(thisObject,waterOutletPort()); model().disconnect(thisObject,waterInletPort()); model().connect( demandInletNode.get(), demandInletNode->outletPort(), demandOutletNode.get(), demandOutletNode->inletPort() ); return true; } // If the component is at the very end of the supply path, but there is another component preceeding this one. else if( demandOutletNode->handle() == waterOutletModelObject()->handle() ) { model().disconnect(thisObject,waterOutletPort()); model().disconnect(thisObject,waterInletPort()); model().connect( source2ModelObject.get(), source2Port.get(), demandOutletNode.get(), demandOutletNode->inletPort() ); sourceModelObject->remove(); return true; } // If the component is the only component (except nodes) between a splitter mixer pair else if( (target2ModelObject.get() == mixer) && (source2ModelObject.get() == splitter) ) { Model _model = model(); int i = splitter.branchIndexForOutletModelObject(sourceModelObject.get()); int j = mixer.branchIndexForInletModelObject(targetModelObject.get()); BOOST_ASSERT(i == j); splitter.removePortForBranch(i); mixer.removePortForBranch(i); _model.disconnect(thisObject,waterOutletPort()); _model.disconnect(thisObject,waterInletPort()); targetModelObject->remove(); sourceModelObject->remove(); if( ! splitter.lastOutletModelObject() ) { Node newNode(_model); _model.connect(splitter,splitter.nextOutletPort(),newNode,newNode.inletPort()); _model.connect(newNode,newNode.outletPort(),mixer,mixer.nextInletPort()); } return true; } // Else remove the component and the outlet node else { model().disconnect(thisObject,waterOutletPort()); model().disconnect(thisObject,waterInletPort()); model().connect( sourceModelObject.get(), sourcePort.get(), target2ModelObject.get(), target2Port.get() ); targetModelObject->remove(); return true; } } return false; }
bool WaterToAirComponent_Impl::addToNode(Node & node) { Model _model = node.model(); ModelObject thisModelObject = getObject<ModelObject>(); boost::optional<AirLoopHVACOutdoorAirSystem> oaSystem = node.airLoopHVACOutdoorAirSystem(); if( node.airLoopHVAC() && ! oaSystem ) { AirLoopHVAC airLoop = node.airLoopHVAC().get(); if( airLoop.demandComponent( node.handle() ) ) { return false; } else { if( airLoopHVAC() ) { removeFromAirLoopHVAC(); } if( node == airLoop.supplyOutletNode() && node.inletModelObject().get() == airLoop.supplyInletNode() ) { unsigned oldOutletPort = node.connectedObjectPort( node.inletPort() ).get(); unsigned oldInletPort = node.inletPort(); ModelObject oldSourceModelObject = node.connectedObject( node.inletPort() ).get(); ModelObject oldTargetModelObject = node; _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, airInletPort() ); _model.connect( thisModelObject, airOutletPort(), oldTargetModelObject, oldInletPort ); return true; } if( node == airLoop.supplyInletNode() && node.outletModelObject().get() == airLoop.supplyOutletNode() ) { unsigned oldOutletPort = node.outletPort(); unsigned oldInletPort = node.connectedObjectPort( node.outletPort() ).get(); ModelObject oldSourceModelObject = node; ModelObject oldTargetModelObject = node.outletModelObject().get(); _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, airInletPort() ); _model.connect( thisModelObject, airOutletPort(), oldTargetModelObject, oldInletPort ); return true; } else if( node == airLoop.supplyOutletNode() ) { unsigned oldOutletPort = node.connectedObjectPort( node.inletPort() ).get(); unsigned oldInletPort = node.inletPort(); ModelObject oldSourceModelObject = node.connectedObject( node.inletPort() ).get(); ModelObject oldTargetModelObject = node; Node newNode( _model ); _model.connect( oldSourceModelObject, oldOutletPort, newNode, newNode.inletPort() ); _model.connect( newNode, newNode.outletPort(), thisModelObject, airInletPort() ); _model.connect( thisModelObject, airOutletPort(), oldTargetModelObject, oldInletPort ); return true; } else { unsigned oldOutletPort = node.outletPort(); unsigned oldInletPort = node.connectedObjectPort( node.outletPort() ).get(); ModelObject oldSourceModelObject = node; ModelObject oldTargetModelObject = node.connectedObject( node.outletPort() ).get(); Node newNode( _model ); _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, airInletPort() ); _model.connect( thisModelObject, airOutletPort(), newNode, newNode.inletPort() ); _model.connect( newNode, newNode.outletPort(), oldTargetModelObject, oldInletPort ); return true; } } } else if( node.plantLoop() ) { PlantLoop _plantLoop = node.plantLoop().get(); if( ! _plantLoop.demandComponent( node.handle() ) ) { return false; } else { if( plantLoop() ) { removeFromPlantLoop(); } if( node == _plantLoop.demandOutletNode() && node.inletModelObject().get() == _plantLoop.demandInletNode() ) { unsigned oldOutletPort = node.connectedObjectPort( node.inletPort() ).get(); unsigned oldInletPort = node.inletPort(); ModelObject oldSourceModelObject = node.connectedObject( node.inletPort() ).get(); ModelObject oldTargetModelObject = node; _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, waterInletPort() ); _model.connect( thisModelObject, waterOutletPort(), oldTargetModelObject, oldInletPort ); return true; } else if( node == _plantLoop.demandOutletNode() ) { unsigned oldOutletPort = node.connectedObjectPort( node.inletPort() ).get(); unsigned oldInletPort = node.inletPort(); ModelObject oldSourceModelObject = node.connectedObject( node.inletPort() ).get(); ModelObject oldTargetModelObject = node; Node newNode( _model ); _model.connect( oldSourceModelObject, oldOutletPort, newNode, newNode.inletPort() ); _model.connect( newNode, newNode.outletPort(), thisModelObject, waterInletPort() ); _model.connect( thisModelObject, waterOutletPort(), oldTargetModelObject, oldInletPort ); return true; } else { unsigned oldOutletPort = node.outletPort(); unsigned oldInletPort = node.connectedObjectPort( node.outletPort() ).get(); ModelObject oldSourceModelObject = node; ModelObject oldTargetModelObject = node.connectedObject( node.outletPort() ).get(); Node newNode( _model ); _model.connect( oldSourceModelObject, oldOutletPort, thisModelObject, waterInletPort() ); _model.connect( thisModelObject, waterOutletPort(), newNode, newNode.inletPort() ); _model.connect( newNode, newNode.outletPort(), oldTargetModelObject, oldInletPort ); return true; } } } else { return false; } }
boost::optional<ModelObject> HVACComponent_Impl::plantLoopAsModelObject() const { if (OptionalPlantLoop intermediate = plantLoop()) { return *intermediate; } return boost::none; }