예제 #1
0
void Mixer_Impl::removePortForBranch(unsigned branchIndex)
{
    int _nextBranchIndex = nextBranchIndex();
    model().disconnect(getObject<ModelObject>(),inletPort(branchIndex));
    for(int i = branchIndex + 1; i < _nextBranchIndex; i++ )
    {
        ModelObject mo = inletModelObject(i).get();
        unsigned port = connectedObjectPort( inletPort(i) ).get();
        model().disconnect(getObject<ModelObject>(),inletPort(i));
        model().connect(mo,port,getObject<ModelObject>(),inletPort(i-1));
    }
}
예제 #2
0
void Splitter_Impl::removePortForBranch(unsigned branchIndex)
{
  int _nextBranchIndex = nextBranchIndex();
  model().disconnect(getObject<ModelObject>(),outletPort(branchIndex));
  //std::vector<ModelObject> modelObjects = outletModelObjects();
  for(int i = branchIndex + 1; i < _nextBranchIndex; i++ )
  {
    ModelObject mo = outletModelObject(i).get();
    unsigned port = connectedObjectPort( outletPort(i) ).get();
    model().disconnect(getObject<ModelObject>(),outletPort(i));
    model().connect(getObject<ModelObject>(),outletPort(i-1),mo,port);
  }
}
예제 #3
0
unsigned PortList_Impl::newPortAfterIndex(unsigned portIndex)
{
  //std::vector<ModelObject> modelObjects = this->modelObjects();
  for(int i = portIndex; i < int(nextPortIndex()) - 1; i++ )
  {
    ModelObject mo = modelObject(i).get();
    unsigned port = connectedObjectPort( this->port(i) ).get();
    model().connect(getObject<ModelObject>(),this->port(i+2),mo,port);
  }

  Model _model = model();
  Node node( _model );

  _model.connect( getObject<ModelObject>(),this->port(portIndex+1),node,node.inletPort() );

  return this->port(portIndex++);
}
예제 #4
0
unsigned Mixer_Impl::newInletPortAfterBranch(unsigned branchIndex)
{
    //std::vector<ModelObject> modelObjects = inletModelObjects();
    unsigned stop = nextBranchIndex();
    for(unsigned i = branchIndex; i < stop; i++ )
    {
        ModelObject mo = inletModelObject(i).get();
        unsigned port = connectedObjectPort( inletPort(i) ).get();
        model().connect(getObject<ModelObject>(),inletPort(i+2),mo,port);
    }

    Model _model = model();
    Node node( _model );

    _model.connect( node,node.outletPort(),getObject<ModelObject>(),inletPort(branchIndex+1) );

    return inletPort(branchIndex++);
}
예제 #5
0
unsigned Splitter_Impl::newOutletPortAfterBranch(unsigned branchIndex)
{
  //std::vector<ModelObject> modelObjects = outletModelObjects();
  int stop = nextBranchIndex() - 1;
  for(int i = branchIndex; i < stop; i++ )
  {
    ModelObject mo = outletModelObject(i).get();
    unsigned port = connectedObjectPort( outletPort(i) ).get();
    model().connect(getObject<ModelObject>(),outletPort(i+2),mo,port);
  }

  Model _model = model();
  Node node( _model );

  _model.connect( getObject<ModelObject>(),outletPort(branchIndex+1),node,node.inletPort() );

  return outletPort(branchIndex++);
}
예제 #6
0
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;
}
예제 #7
0
bool WaterToAirComponent_Impl::removeFromAirLoopHVAC()
{
    Model _model = model();
    ModelObject thisObject = getObject<ModelObject>();

    if( boost::optional<AirLoopHVAC> airLoop = airLoopHVAC() )
    {
        if( airOutletModelObject().get() == airLoop->supplyOutletNodes().front() &&
                airInletModelObject().get() == airLoop->supplyInletNode() )
        {
            ModelObject sourceModelObject = airInletModelObject().get();
            unsigned sourcePort = connectedObjectPort( airInletPort() ).get();
            ModelObject targetModelObject = airOutletModelObject().get();
            unsigned targetPort = connectedObjectPort( airOutletPort() ).get();

            model().disconnect(thisObject,airOutletPort());
            model().disconnect(thisObject,airInletPort());

            _model.connect( sourceModelObject, sourcePort,
                            targetModelObject, targetPort );
            return true;
        }
        else if( airOutletModelObject().get() == airLoop->supplyOutletNodes().front() )
        {
            Node sourceModelObject = airInletModelObject()->optionalCast<Node>().get();
            ModelObject targetModelObject = airOutletModelObject().get();
            unsigned targetPort = connectedObjectPort( airOutletPort() ).get();
            ModelObject source2ModelObject = sourceModelObject.inletModelObject().get();
            unsigned source2Port = sourceModelObject.connectedObjectPort( sourceModelObject.inletPort() ).get();

            model().disconnect(thisObject,airOutletPort());
            model().disconnect(thisObject,airInletPort());

            _model.connect( source2ModelObject, source2Port,
                            targetModelObject, targetPort );

            sourceModelObject.remove();

            return true;
        }
        else
        {
            ModelObject sourceModelObject = airInletModelObject().get();
            unsigned sourcePort = connectedObjectPort( airInletPort() ).get();
            Node targetModelObject = airOutletModelObject()->optionalCast<Node>().get();
            ModelObject target2ModelObject = targetModelObject.outletModelObject().get();
            unsigned target2Port = targetModelObject.connectedObjectPort( targetModelObject.outletPort() ).get();

            model().disconnect(thisObject,airOutletPort());
            model().disconnect(thisObject,airInletPort());


            _model.connect( sourceModelObject, sourcePort,
                            target2ModelObject, target2Port );

            targetModelObject.remove();

            return true;
        }
    }

    return false;
}
예제 #8
0
  bool HVACComponent_Impl::removeFromLoop( const HVACComponent & systemStartComponent, 
    const HVACComponent & systemEndComponent,
    unsigned componentInletPort,
    unsigned componentOutletPort )
  {
    auto _model = model();
    auto thisObject = getObject<HVACComponent>();
    
    if( systemStartComponent.model() != _model ) return false;
    if( systemEndComponent.model() != _model ) return false;

    auto inletComponent = connectedObject( componentInletPort );
    auto outletComponent = connectedObject( componentOutletPort );
    auto inletComponentOutletPort = connectedObjectPort( componentInletPort );
    auto outletComponentInletPort = connectedObjectPort( componentOutletPort );

    if( ! inletComponent ) return false;
    if( ! outletComponent ) return false;
    if( ! inletComponentOutletPort ) return false;
    if( ! outletComponentInletPort ) return false;

    auto inletNode = inletComponent->optionalCast<Node>();
    auto outletNode = outletComponent->optionalCast<Node>();
    boost::optional<Splitter> splitter;
    boost::optional<Mixer> mixer;

    if( inletNode ) {
      if( auto mo = inletNode->inletModelObject() ) {
        splitter = mo->optionalCast<Splitter>();
      }
    }
    if( outletNode ) {
      if( auto mo = outletNode->outletModelObject() ) {
        mixer = mo->optionalCast<Mixer>();
      }
    }

    if( systemStartComponent.handle() == inletComponent->handle() 
        && systemEndComponent.handle() == outletComponent->handle() ) {
      // This component is between the systemStartComponent and the systemEndComponent
      // ie. the supply or demand inlet or outlet Nodes,
      // or the oa system end points on either the relief or inlet air streams.
      _model.disconnect(thisObject,componentInletPort); 
      _model.disconnect(thisObject,componentOutletPort); 

      _model.connect( inletComponent.get(), inletComponentOutletPort.get(), 
                       outletComponent.get(), outletComponentInletPort.get() );
      
      return true;
    } else if( systemEndComponent.handle() == outletComponent->handle() ) {
      // Here the systemEndComponent is immediately downstream of this component,
      // but there are other components (besides systemStartComponent) upstream.
      boost::optional<ModelObject> newInletComponent;
      boost::optional<unsigned> newInletComponentOutletPort;

      // Make sure we don't end up with two nodes next to each other after this component is removed
      if( inletNode && outletNode ) {
        newInletComponent = inletNode->inletModelObject();
        newInletComponentOutletPort = inletNode->connectedObjectPort(inletNode->inletPort());
        OS_ASSERT(newInletComponent);
        OS_ASSERT(newInletComponentOutletPort);
      } else {
        newInletComponent = inletComponent;
        newInletComponentOutletPort = inletComponentOutletPort;
      }

      _model.disconnect(thisObject,componentInletPort); 
      _model.disconnect(thisObject,componentOutletPort); 

      // inletNode->remove() would have failed if we did it before the disconnect
      if( inletNode && outletNode ) {
        inletNode->remove();
      }

      _model.connect( newInletComponent.get(), newInletComponentOutletPort.get(), 
                       outletComponent.get(), outletComponentInletPort.get() );
      return true;
    } else if( splitter && mixer ) {
      // If the component is the only component (except nodes) between a splitter mixer pair
      OS_ASSERT(inletNode);
      OS_ASSERT(outletNode);

      int i = splitter->branchIndexForOutletModelObject(inletNode.get());
      int j = mixer->branchIndexForInletModelObject(outletNode.get());

      OS_ASSERT(i == j);

      splitter->removePortForBranch(i);
      mixer->removePortForBranch(i);

      _model.disconnect(thisObject,componentInletPort); 
      _model.disconnect(thisObject,componentOutletPort); 

      inletNode->remove();
      outletNode->remove();

      if( ! splitter->lastOutletModelObject() )
      {
        Node newNode(_model);
        _model.connect(splitter.get(),splitter->nextOutletPort(),newNode,newNode.inletPort());
        _model.connect(newNode,newNode.outletPort(),mixer.get(),mixer->nextInletPort());
      }

      return true;
    } else {
      boost::optional<ModelObject> newOutletComponent; 
      boost::optional<unsigned> newOutletComponentInletPort;

      if( inletNode && outletNode ) {
        newOutletComponent = outletNode->outletModelObject();
        newOutletComponentInletPort = outletNode->connectedObjectPort(outletNode->outletPort());
      }

      if( ! newOutletComponent ) newOutletComponent = outletComponent;
      if( ! newOutletComponentInletPort ) newOutletComponentInletPort = outletComponentInletPort;

      _model.disconnect(thisObject,componentInletPort); 
      _model.disconnect(thisObject,componentOutletPort); 

      // outletNode->remove() would have failed if we did it before the disconnect
      if( inletNode && outletNode ) {
        outletNode->remove();
      }

      model().connect( inletComponent.get(), inletComponentOutletPort.get(), 
                       newOutletComponent.get(), newOutletComponentInletPort.get() );

      return true;
    }

    return false;
  }