lbl-srg / modelica-buildings

Modelica Buildings library
249 stars 155 forks source link

Minor changes to stratified tank model to allow multiple inlets/outlets #529

Open damienpicard opened 8 years ago

damienpicard commented 8 years ago

I'm using the storage tank model but I need to be able to inject and extract water at different heights of the storage model.

To do so, I had to add a small modification to the model: Buildings.Fluid.Storage.Stratified. Instead of using constant Integer nPorts = 2 "Number of ports of volume"; I use a vector parameter Integer nPorts[nSeg] = {2 for i in 1:nSeg} "Number of ports of volume"; so that I can specifiy the number of ports of each mixing volume vol:

  MixingVolumes.MixingVolume[nSeg] vol(
    redeclare each package Medium = Medium,
    each energyDynamics=energyDynamics,
    each massDynamics=massDynamics,
    each p_start=p_start,
    each T_start=T_start,
    each X_start=X_start,
    each C_start=C_start,
    each V=VTan/nSeg,
    nPorts=nPorts,
    each m_flow_nominal = m_flow_nominal,
    each final mSenFac=1,
    each final m_flow_small=m_flow_small,
    each final allowFlowReversal=allowFlowReversal) "Tank segment"
      annotation (Placement(transformation(extent={{6,-16},{26,4}})));

I can now easily create a model for stratified tank with multiple inlets, outlets:

model StratifiedMultipleInlet
  import Buildings;
  extends Buildings.Fluid.Storage.Stratified(final nPorts = {if i==nVolIn or i==nVolOut then 3 else 2 for i in 1:nSeg});
  parameter Integer nVolIn(min=1,max=nSeg) = 1 
    "Position where to inject the fluid, starting from the uppermost layer";
  parameter Integer nVolOut(min=1,max=nSeg) = nSeg 
    "Position where to extract the fluid, starting from the uppermost layer";
  Modelica.Fluid.Interfaces.FluidPort_a port_a2(
    redeclare final package Medium = Medium,
     m_flow(min=if allowFlowReversal then -Modelica.Constants.inf else 0)) 
    "Fluid connector a (positive design flow direction is from port_a to port_b)"
    annotation (Placement(transformation(extent={{-50,-110},{-30,-90}}),
        iconTransformation(extent={{-50,-110},{-30,-90}})));
  Modelica.Fluid.Interfaces.FluidPort_b port_b2(
    redeclare final package Medium = Medium,
    m_flow(max=if allowFlowReversal then +Modelica.Constants.inf else 0)) 
    "Fluid connector b (positive design flow direction is from port_a to port_b)"
    annotation (Placement(transformation(extent={{50,-110},{30,-90}}),iconTransformation(extent={{50,-110},
            {30,-90}})));
equation 
  connect(port_a2,vol[nVolIn].ports[3]);
  connect(port_b2,vol[nVolOut].ports[3]);

  connect(port_a2, port_a2) annotation (Line(points={{-40,-100},{-40,-97},{-40,
          -97},{-40,-100}}, color={0,127,255}));
end StratifiedMultipleInlet;

I was wondering if such adaptation of the code could be added to the BuildingsLibrary or not.

mwetter commented 8 years ago

@damienpicard Such a feature would be useful in my view. Could you please make a pull request to the new branch issue529_tank We would also need to understand what the implications are to the stratification model (instance str) as this takes as an input the enthalpy exchanged with the flow between the volumes.

mwetter commented 8 years ago

Todo: