Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Creation of a new Tank

Creation of a new Tank

Hi everyone,
i'm currently trying to create a Tank model that is able to handle two fluids. Here's my model:


model TankWaterCO2
import Modelica.Constants.pi;
import Modelica.Fluid.Types;
import Modelica.Fluid.Types.Dynamics;
import Modelica.Media.Interfaces.Choices.IndependentVariables;

////////////////////Variablen/Attribute////////////////////

Modelica.SIunits.Mass m "Mass of fluid";
Modelica.SIunits.Mass m2 "Mass of fluid2";

// Tank properties
  Modelica.SIunits.Height level(stateSelect=StateSelect.prefer, start=level_start_eps) "Level height of tank";
  Modelica.SIunits.Volume V(stateSelect=StateSelect.never) "Actual tank volume";
  Modelica.SIunits.Volume V_ges(stateSelect=StateSelect.never) "Actual tank volume";

//Ports
parameter Integer nPortsWater=2;
parameter Integer nPortsCO2=3;

Modelica.SIunits.MassFlowRate mb_flow "Mass flows across boundaries";
Modelica.SIunits.MassFlowRate mb_flow2 "Mass flows across boundaries";

Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsWater[nPortsWater](redeclare each package Medium = Mediumw) annotation(
    Placement(visible = true, transformation(origin = {35, -80}, extent = {{-29, -18}, {29, 18}}, rotation = 0), iconTransformation(origin = {35, -80}, extent = {{-29, -18}, {29, 18}}, rotation = 0)));

Modelica.Fluid.Vessels.BaseClasses.VesselFluidPorts_b portsCO2[nPortsCO2](redeclare each package Medium = Medium) annotation(
    Placement(visible = true, transformation(origin = {-35, -80}, extent = {{-29, -18}, {29, 18}}, rotation = 0), iconTransformation(origin = {-35, -80}, extent = {{-29, -18}, {29, 18}}, rotation = 0)));

//Ambient
outer Modelica.Fluid.System system "System properties";

  ////////////////////Parameter////////////////////
 
  // Tank geometry
parameter Modelica.SIunits.Height height "Height of tank";
parameter Modelica.SIunits.Area crossArea "Area of tank";

  // Ambient

parameter Medium.Temperature T_ambient=system.T_ambient
      "Tank surface Temperature"
    annotation(Dialog(tab = "Assumptions", group = "Ambient"));

  // Initialization
parameter Modelica.SIunits.Height level_start(min=0) = 0
      "Start value of tank level"
    annotation(Dialog(tab="Initialization"));
parameter Boolean initialize_p=true;

parameter Modelica.SIunits.Temperature T=289;
protected
  final parameter Modelica.SIunits.Height level_start_eps = max(level_start, Modelica.Constants.eps);


////////////////////Medium Deklaration////////////////////

//Medium=CO2, Mediumw=Wasser

replaceable package Medium =
    Modelica.Media.Interfaces.PartialMedium "Medium in the component"
      annotation (choicesAllMatching = true);
     
   replaceable package Mediumw =
    Modelica.Media.Interfaces.PartialMedium "Mediumw in the component"
      annotation (choicesAllMatching = true);
   
    // Initialization
  parameter Medium.AbsolutePressure p_start = system.p_start
  "Start value of pressure"
    annotation(Dialog(tab = "Initialization"));
  parameter Boolean use_T_start = true
  "= true, use T_start, otherwise h_start"
    annotation(Dialog(tab = "Initialization"), Evaluate=true);
  parameter Medium.Temperature T_start=
    if use_T_start then system.T_start else Medium.temperature_phX(p_start,h_start,X_start)
  "Start value of temperature"
    annotation(Dialog(tab = "Initialization", enable = use_T_start));
  parameter Medium.SpecificEnthalpy h_start=
    if use_T_start then Medium.specificEnthalpy_pTX(p_start, T_start, X_start) else Medium.h_default
  "Start value of specific enthalpy"
    annotation(Dialog(tab = "Initialization", enable = not use_T_start));
  parameter Medium.MassFraction X_start[Medium.nX] = Medium.X_default
  "Start value of mass fractions m_i/m"
    annotation (Dialog(tab="Initialization", enable=Medium.nXi > 0));
  parameter Medium.ExtraProperty C_start[Medium.nC](
       quantity=Medium.extraPropertiesNames)=fill(0, Medium.nC)
  "Start value of trace substances"
    annotation (Dialog(tab="Initialization", enable=Medium.nC > 0));
   
    //Innitialization2
   
    parameter Mediumw.AbsolutePressure p_start2 = system.p_start
  "Start value of pressure"
    annotation(Dialog(tab = "Initialization"));
  parameter Boolean use_T_start2 = true
  "= true, use T_start2, otherwise h_start"
    annotation(Dialog(tab = "Initialization"), Evaluate=true);
  parameter Mediumw.Temperature T_start2=
    if use_T_start2 then system.T_start else Mediumw.temperature_phX(p_start2,h_start2,X_start2)
  "Start value of temperature"
    annotation(Dialog(tab = "Initialization", enable = use_T_start2));
  parameter Mediumw.SpecificEnthalpy h_start2=
    if use_T_start2 then Mediumw.specificEnthalpy_pTX(p_start2, T_start2, X_start2) else Mediumw.h_default
  "Start value of specific enthalpy"
    annotation(Dialog(tab = "Initialization", enable = not use_T_start2));
  parameter Mediumw.MassFraction X_start2[Mediumw.nX] = Mediumw.X_default
  "Start value of mass fractions m_i/m"
    annotation (Dialog(tab="Initialization", enable=Mediumw.nXi > 0));
  parameter Mediumw.ExtraProperty C_start2[Mediumw.nC](
       quantity=Mediumw.extraPropertiesNames)=fill(0, Mediumw.nC)
  "Start value of trace substances"
    annotation (Dialog(tab="Initialization", enable=Mediumw.nC > 0));
   
//    Medium.ExtraProperty C[Medium.nC] "Trace substance mixture content";
//    Mediumw.ExtraProperty C2[Mediumw.nC] "Trace substance mixture content";
     
  Medium.BaseProperties medium(
    preferredMediumStates=true,
    p(start=p_start),
    h(start=h_start),
    T(start=T_start),
    Xi(start=X_start[1:Medium.nXi]));
   
    Medium.BaseProperties mediumw(
    preferredMediumStates=true,
    p(start=p_start2),
    h(start=h_start2),
    T(start=T_start2),
    Xi(start=X_start2[1:Mediumw.nXi]));

equation
  V_ges=height*crossArea;
  V = crossArea*level "Volume of fluid";
  mb_flow = sum(portsCO2.m_flow);
  mb_flow2 = sum(portsWater.m_flow);
  m=(V_ges-V)*medium.d;
  m2=V*mediumw.d;
  der(m)=mb_flow;
  der(m2)=mb_flow2;
  medium.p=mediumw.p;
  medium.pcurrent/sad(m/0.01801528)*8.3144598*T)/(V_ges-V);
 
 
  for i in 1:nPortsWater loop
  mediumw.p=portsWater[i].p;
  mediumw.h=portsWater[i].h_outflow;
end for;
  for i in 1:nPortsCO2 loop
  medium.p=portsCO2[i].p;
  medium.h=portsCO2[i].h_outflow;
end for;

initial equation
if initialize_p then
  medium.p = p_start;
  der(medium.h) = 0;
end if;
  medium.T = T_start;
  level=level_start_eps;
  p_start=((m/0.01801528)*8.3144598*T)/(V_ges-V);
  m2=V*mediumw.d;
annotation(
    defaultComponentName = "tank",
    Icon(coordinateSystem(initialScale = 0.2), graphics = {Rectangle(lineColor = {255, 255, 255}, fillColor = {255, 255, 255}, fillPattern = FillPattern.VerticalCylinder, extent = {{-100, 100}, {100, -100}}), Rectangle(fillColor = {85, 170, 255}, fillPattern = FillPattern.VerticalCylinder, extent = {{-100, -100}, {100, 10}}), Line(points = {{-100, 100}, {-100, -100}, {100, -100}, {100, 100}}), Text(extent = {{-95, 60}, {95, 40}}, textString = "level ="), Text(origin = {0, 14},extent = {{-95, -24}, {95, -44}}, textString = "%level_start", fontName = "0"), Line(origin = {0, 100}, points = {{-100, 0}, {100, 0}, {100, 0}}), Text(origin = {-36, -52}, extent = {{14, -22}, {-14, 22}}, textString = "CO2"), Text(origin = {34, -52}, extent = {{14, -22}, {-14, 22}}, textString = "H2O")}),
    Documentation(info = "<html>
<p>
Model of a tank that is open to the ambient at the fixed pressure
<code>p_ambient</code>.
</p>
<p>
The vector of connectors <b>ports</b> represents fluid ports at configurable heights, relative to the bottom of tank.
Fluid can flow either out of or in to each port.
</p>
The following assumptions are made:
<ul>
<li>The tank is filled with a single or multiple-substance medium having a density higher than the density of the ambient medium.</li>
<li>The fluid has uniform density, temperature and mass fractions</li>
<li>No liquid is leaving the tank through the open top; the simulation breaks with an assertion if the liquid level growths over the height.</li>
</ul>
<p>
The port pressures represent the pressures just after the outlet (or just before the inlet) in the attached pipe.
The hydraulic resistances <code>portsData.zeta_in</code> and <code>portsData.zeta_out</code> determine the dissipative pressure drop between tank and port depending on
the direction of mass flow. See <a href=\"modelica://Modelica.Fluid.Vessels.BaseClasses.VesselPortsData\">VesselPortsData</a> and <i>[Idelchik, Handbook of Hydraulic Resistance, 2004]</i>.
</p>
<p>
With the setting <code>use_portsData=false</code>, the port pressure represents the static head
at the height of the respective port.
The relationship between pressure drop and mass flow rate at the port must then be provided by connected components;
Heights of ports as well as kinetic and potential energy of fluid entering or leaving are not taken into account anymore.
</p>
</html>", revisions = "<html>
<ul>
<li><i>Dec. 12, 2008</i> by Ruediger Franke: move port definitions
   to BaseClasses.PartialLumpedVessel; also use energy and mass balance from common base class</li>
<li><i>Dec. 8, 2008</i> by Michael Wetter (LBNL):<br>
Implemented trace substances.</li>
<li><i>Jan. 6, 2006</i> by Katja Poschlad, Manuel Remelhe (AST Uni Dortmund),
   Martin Otter (DLR):<br>
   Implementation based on former tank model.</li>
<li><i>Oct. 29, 2007</i> by Carsten Heinrich (ILK Dresden):<br>
Adapted to the new fluid library interfaces:
<ul> <li>FluidPorts_b is used instead of FluidPort_b (due to it is defined as an array of ports)</li>
    <li>Port name changed from port to ports</li></ul>Updated documentation.</li>
<li><i>Apr. 25, 2006</i> by Katrin Pr&ouml;l&szlig; (TUHH):<br>
Limitation to bottom ports only, added inlet and outlet loss factors.</li>
</ul>
</html>"),
    uses(Modelica(version = "3.2.2")));

end TankWaterCO2;


unfortuately, i am missing a equation. Can someone tell me which one that is? What i'd also like to know is: is there a easier way to create that model being able to handle two media? Simply defining a two-substance-medium doesn't work for my purposes as i want the composition of the two media to be variable.
I'd really appreciate any help as i'm trying to find a solution for one week now.

Thanks in advance
lwinklmann

There are 0 guests and 0 other users also viewing this topic