VirtualLabBuilder.Examples.tank1OutputSSS

Tank with multipe state selections

Information


 

tank1OutputSSS package

This model intends to illustrate the case of a model supporting several state selections. This model describes a tank with one output at the bottom and one pump placed at the top.

Package Content

NameDescription
tank1OutputModel Physical model
StateSelection1 h: state variable
StateSelection2 V: state variable
StateSelection3 F: state variable
interactiveModel Interactive model
VirtualLabBuilder.Examples.tank1OutputSSS.tank1OutputView tank1OutputView Virtual-lab view
tank1OutputInteractive Interactive model
setParamVar When clauses to change interactive parameter and input variables


VirtualLabBuilder.Examples.tank1OutputSSS.tank1OutputModel

Physical model

Information



This model describes a tank with one output at the bottom and one pump placed at the top. It has been adapted for interactive simulation. The boolean vector isState[:], declared in tank1OutputModel, allows controlling the state selection. The size of this vector is equal to the number of interactive time-dependent magnitudes. The interactive variables of the models are shown in Table 1.

Table 1. Interactive variables.
a Output hole section.
A Tank section.
k Input valve parameter.
vin Input voltage.



Parameters

TypeNameDefaultDescription
BooleanisState[3]{true,false,false}This vector allows controlling the state selection
BooleanhIsStateisState[1]true: h is the state variable
BooleanVIsStateisState[2]true: V is the state variable
BooleanFIsStateisState[3]true: F is the state variable
RealaInitial0.4Initial value of the output hole section
RealAInitial2Initial value of the tank section
RealKInitial100Initial value of the pump parameter
RealvInitial0.01Initial value of the pump voltage
RealhInitial3Initial value of the liquid level
RealVInitial20Initial value of the liquid volume
RealFInitial140Initial value of the liquid flow
Realg981Constant of gravity [cm/s2]

Modelica definition

model tank1OutputModel "Physical model" 
  
// Boolean parameters to set the state variable selection
   parameter Boolean isState[3] = {true, false, false} 
    "This vector allows controlling the state selection";
   parameter Boolean hIsState = isState[1] "true: h is the state variable";
   parameter Boolean VIsState = isState[2] "true: V is the state variable";
   parameter Boolean FIsState = isState[3] "true: F is the state variable";
  
// Initial value of interactive parameters
   parameter Real aInitial = 0.4 "Initial value of the output hole section";
   parameter Real AInitial = 2 "Initial value of the tank section";
   parameter Real KInitial = 100 "Initial value of the pump parameter";
  
// Initial value of interactive input variables
   parameter Real vInitial = 0.01 "Initial value of the pump voltage";
  
// Initial conditions of state variables  
   parameter Real hInitial = 3 "Initial value of the liquid level";
   parameter Real VInitial = 20 "Initial value of the liquid volume";
   parameter Real FInitial = 140 "Initial value of the liquid flow";
  
// Declaration of state variables
   Real h( unit="cm",  stateSelect=if hIsState then StateSelect.always else StateSelect.default, start=hInitial) 
    "Liquid height";
   Real V( unit="cm3",  stateSelect=if VIsState then StateSelect.always else StateSelect.default, start = VInitial) 
    "Liquid volume";
   Real F( unit="cm3/s",  stateSelect=if FIsState then StateSelect.always else StateSelect.default, start = FInitial) 
    "Liquid flow";
  
   // Declaration of Input variables
   Real vin( unit="V", start = vInitial) "Input voltage";
  
   //Algebraic variable  
   Real Fin(   unit="cm3.s-1") "Input flow";
  
   //Declaration of Interactive parameters
  
   Real a(   unit="cm2", start = aInitial) "Output hole section";
   Real A(   unit="cm2", start = AInitial) "Tank section";
   Real K(   unit="cm3/(V.s)", start = KInitial) "Input valve parameter";
  
   parameter Real g( unit="cm/s2") = 981 "Constant of gravity";
  
equation 
   // Interactive parameters
  
   der(a)  = 0;
   der(A) = 0;
   der(K) = 0;
  
   // Input variables
   der(vin)   = 0;
  
   // Model equations
   Fin = K*vin;
   der(V) = Fin-F;
   V = A*h;
   F = A*sqrt(2*g*h);
  
end tank1OutputModel;

VirtualLabBuilder.Examples.tank1OutputSSS.StateSelection1

h: state variable

Information



This model inherits from the setParamVar model. The liquid level (h) is the state variable of this model. It includes the code to reinitialize the value of the state variable.

Parameters

TypeNameDefaultDescription
BooleanisState[3]{true,false,false}This vector allows controlling the state selection
BooleanhIsStateisState[1]true: h is the state variable
BooleanVIsStateisState[2]true: V is the state variable
BooleanFIsStateisState[3]true: F is the state variable
RealaInitial0.4Initial value of the output hole section
RealAInitial2Initial value of the tank section
RealKInitial100Initial value of the pump parameter
RealvInitial0.01Initial value of the pump voltage
RealhInitial3Initial value of the liquid level
RealVInitial20Initial value of the liquid volume
RealFInitial140Initial value of the liquid flow
Realg981Constant of gravity [cm/s2]

Modelica definition

model StateSelection1 "h: state variable" 
  extends setParamVar(isState= {true, false,false});
  Boolean CKstate;
  Real Istate[1];
  
equation 
  when   {CKstate==true and Enabled == true, Enabled == true} then
     reinit(h,  Istate[1]);
    
  end when;
end StateSelection1;

VirtualLabBuilder.Examples.tank1OutputSSS.StateSelection2

V: state variable

Information



This model inherits from the setParamVar model. The liquid volume (V) is the state variable of this model. It includes the code to reinitialize the value of the state variable.

Parameters

TypeNameDefaultDescription
BooleanisState[3]{true,false,false}This vector allows controlling the state selection
BooleanhIsStateisState[1]true: h is the state variable
BooleanVIsStateisState[2]true: V is the state variable
BooleanFIsStateisState[3]true: F is the state variable
RealaInitial0.4Initial value of the output hole section
RealAInitial2Initial value of the tank section
RealKInitial100Initial value of the pump parameter
RealvInitial0.01Initial value of the pump voltage
RealhInitial3Initial value of the liquid level
RealVInitial20Initial value of the liquid volume
RealFInitial140Initial value of the liquid flow
Realg981Constant of gravity [cm/s2]

Modelica definition

model StateSelection2 "V: state variable" 
    extends setParamVar(isState= {false,  true,  false});
  Boolean CKstate;
  Real Istate[1];
  
equation 
  when   {CKstate==true and Enabled == true, Enabled == true} then
     reinit(V,   Istate[1]);
  end when;
end StateSelection2;

VirtualLabBuilder.Examples.tank1OutputSSS.StateSelection3

F: state variable

Information



This model inherits from the setParamVar model. The liquid flow (F) is the state variable of this model. It includes the code to reinitialize the value of the state variable.

Parameters

TypeNameDefaultDescription
BooleanisState[3]{true,false,false}This vector allows controlling the state selection
BooleanhIsStateisState[1]true: h is the state variable
BooleanVIsStateisState[2]true: V is the state variable
BooleanFIsStateisState[3]true: F is the state variable
RealaInitial0.4Initial value of the output hole section
RealAInitial2Initial value of the tank section
RealKInitial100Initial value of the pump parameter
RealvInitial0.01Initial value of the pump voltage
RealhInitial3Initial value of the liquid level
RealVInitial20Initial value of the liquid volume
RealFInitial140Initial value of the liquid flow
Realg981Constant of gravity [cm/s2]

Modelica definition

model StateSelection3 "F: state variable" 
  extends setParamVar(isState= {false,  false, true});
  Boolean CKstate;
  Real Istate[1];
  
equation 
  when   {CKstate==true and Enabled == true, Enabled == true} then
     reinit(F,  Istate[1]);
  end when;
end StateSelection3;

VirtualLabBuilder.Examples.tank1OutputSSS.interactiveModel

Interactive model

Information



This model is composed of three instantiations of the physical-model: SS1, SS2 and SS3. Each model has a different choice of the state variables.

Modelica definition

model interactiveModel "Interactive model" 
    StateSelection1 SS1(I = I, Enabled = Enabled[1],  Istate = {Istate[1]},CK = CK[1], CKstate = CKstate[1]);
    StateSelection2 SS2( I = I, Enabled = Enabled[2],  Istate = {Istate[2]},CK = CK[2], CKstate = CKstate[2]);
    StateSelection3 SS3( I = I, Enabled = Enabled[3],  Istate = {Istate[3]},CK = CK[3], CKstate = CKstate[3]);
  Real I[3];
  Real Istate[3];
  
  Boolean Enabled[3];
  Boolean CK[3];
  Boolean CKstate[3];
  Real O[3];
equation 
  
   O = if (Enabled[1]) then {SS1.h, SS1.V, SS1.F} else 
     if (Enabled[2]) then {SS2.h, SS2.V, SS2.F} else 
     {SS3.h, SS3.V, SS3.F};
end interactiveModel;

VirtualLabBuilder.Examples.tank1OutputSSS.tank1OutputView VirtualLabBuilder.Examples.tank1OutputSSS.tank1OutputView

Virtual-lab view

VirtualLabBuilder.Examples.tank1OutputSSS.tank1OutputView

Information



This model has been composed by extending the PartialView class and by instantiating and connecting the required components of the VirtualLabBuilder library. The connection rules are described in the documentation of the ViewElements package.

Parameters

TypeNameDefaultDescription
RealTcom0.1Communication interval
IntegerserverPort4242Server Port number
StringsourceCodePath"C:/Program Files/Dymola/Sou...Path where the C-functions, graphics.jar and delayrun.exe are located
StringfileName"gui.java"Java file name
IntegerliquidIX[6]{1,1,1,1,1,1}Interactive x components of the liquid polygon
IntegerliquidIY[6]{1,0,0,1,1,1}Interactive y components of the liquid polygon
IntegervaseIX[6]{1,1,1,1,1,1}Interactive x components of the vase polygon
IntegervaseIY[6]{0,0,0,0,0,0}Interactive x components of the vase polygon
IntegerliquidFromPipeIx[4]{1,1,1,1}Interactive x components of the liquidFromPipe polygon

Modelica definition

model tank1OutputView "Virtual-lab view" 
  extends VirtualLabBuilder.VLabModels.PartialView( Tcom = 0.0001);
  
  VirtualLabBuilder.ViewElements.Containers.MainFrame mainFrame(Width=500,
      Height=500);
  
  parameter Integer liquidIX[6] = {1,1,1,1,1,1} 
    "Interactive x components of the liquid polygon";                                             //intVertexesX
  parameter Integer liquidIY[6] = {1,0,0,1,1,1} 
    "Interactive y components of the liquid polygon";                                            //intVertexesY
  
  parameter Integer vaseIX[6] = {1,1,1,1,1,1} 
    "Interactive x components of the vase polygon";                                           //intVertexesX
  parameter Integer vaseIY[6] = {0,0,0,0,0,0} 
    "Interactive x components of the vase polygon";                                           //intVertexesY
  
  parameter Integer liquidFromPipeIx[4] = {1, 1, 1, 1} 
    "Interactive x components of the liquidFromPipe polygon";
  
  VirtualLabBuilder.ViewElements.Containers.DrawingPanel drawingPanel(
    XMin=-3,
    XMax=3,
    YMin=-2,
    YMax=12);
 VirtualLabBuilder.ViewElements.Drawables.Polygon vase(
    nPoints=6,
    filled="false",
    fillColorp={0,0,0,255},
    closed="false",
    intVertexesX=vaseIX,
    intVertexesY=vaseIY);
  
  VirtualLabBuilder.ViewElements.Drawables.Polygon liquid(
    nPoints=6,
    lineColorp={0,0,255,255},
    intVertexesX=liquidIX,
    intVertexesY=liquidIY);
  VirtualLabBuilder.ViewElements.Drawables.Polygon liquidfrompipe(
    nPoints=4,
    lineColorp={0,0,255,255},
    fillColorp={0,0,255,255},
    intVertexesX=liquidFromPipeIx);
  VirtualLabBuilder.ViewElements.InteractiveControls.Slider sliderv(stringFormat="v=0.00");
  VirtualLabBuilder.ViewElements.InteractiveControls.Slider sliderA(stringFormat="A=0.00",
    minimum=1,
    maximum=4);
  
  VirtualLabBuilder.ViewElements.InteractiveControls.Slider slidera(stringFormat="a = 0.00",
    minimum=0.1,
    maximum=0.7);
  VirtualLabBuilder.ViewElements.Containers.Dialog dialog(xPosition=400, varName="var");
  VirtualLabBuilder.ViewElements.Containers.PlottingPanel plottingPanel(title="h", titleX=
        "time (s)",
    autoScaleY="false",
    maxY=5);
  VirtualLabBuilder.ViewElements.Drawables.Trail trail(maximumPoints=1000, nSkip=10);
  VirtualLabBuilder.ViewElements.BasicElements.CheckBox checkBox(label="Show plot",
      position="NORTH");
  VirtualLabBuilder.ViewElements.Containers.Panel panelS(
    LayoutPolicy="GridLayout",
    nRows=2,
    nColumns=1);
  VirtualLabBuilder.ViewElements.InteractiveControls.RadioButton V(
    buttonValue="false",
    text="V");
  VirtualLabBuilder.ViewElements.InteractiveControls.RadioButton F(
      buttonValue="false", text="F");
 VirtualLabBuilder.ViewElements.InteractiveControls.Slider sliderh(
    stringFormat="h  = 0.00",
    minimum=1,
    maximum=10);
 VirtualLabBuilder.ViewElements.InteractiveControls.Slider sliderV(
    minimum=1,
    maximum=10,
    stringFormat="V  = 0.00");
 VirtualLabBuilder.ViewElements.InteractiveControls.Slider sliderF(
    minimum=1,
    maximum=10,
    stringFormat="F  = 0.00");
  VirtualLabBuilder.ViewElements.Containers.Panel panelN(
    LayoutPolicy="GridLayout",
    nRows=1,
    nColumns=4,
    position="NORTH");
  src.ViewElements.InteractiveControls.RadioButton h(text="h");
  src.ViewElements.Drawables.Polygon pipe(nPoints=6, closed="false");
equation 
  
  connect(drawingPanel.cLLeft, panelS.pLLeft);
  connect(checkBox.cLLeft, h.pLLeft);
  connect(h.cLLeft, V.pLLeft);
  connect(V.cLLeft, F.pLLeft);
  connect(pipe.cLeft, vase.pLeft);
  connect(vase.cLeft, liquidfrompipe.pLeft);
  connect(liquidfrompipe.cLeft, liquid.pLeft);
  connect(slidera.cLLeft, sliderA.pLLeft);
  connect(sliderA.cLLeft, sliderv.pLLeft);
  connect(sliderv.cLLeft, sliderh.pLLeft);
  connect(sliderh.cLLeft, sliderV.pLLeft);
  connect(sliderV.cLLeft, sliderF.pLLeft);
  connect(root.cLLeft, mainFrame.pLLeft);
  connect(panelN.cLRight, checkBox.pLLeft);
  connect(panelN.cLLeft, drawingPanel.pLLeft);
  connect(mainFrame.cLRight, panelN.pLLeft);
  connect(dialog.cLRight, plottingPanel.pLLeft);
  connect(dialog.pLLeft, mainFrame.cLLeft);
  connect(panelS.cLRight, slidera.pLLeft);
  connect(drawingPanel.cRight, pipe.pLeft);
  connect(plottingPanel.cRight, trail.pLeft);
end tank1OutputView;

VirtualLabBuilder.Examples.tank1OutputSSS.tank1OutputInteractive

Interactive model

Information



This model has been composed by instantiating the VirtualLab Model, which is included in the VirtualLabBuilder library. The tank1OutputInteractive model includes the equations required to link the model and the view variables.

Modelica definition

model tank1OutputInteractive "Interactive model" 
  
  VirtualLabBuilder.VLabModels.VirtualLab interactive( redeclare model ViewI = 
        tank1OutputView, redeclare model ModelI = interactiveModel,
    Tcom=0.0001);
  Real xl;
  
  Real vaseYv[6] = {8.000000,0.000000,0.000000,0.400000,0.400000,8.000000}; //Vertexes Y
  
  Real pipeXv[6] = {-0.200000,-0.200000,-4.000000,-4.000000,0.200000,0.200000}; //Vertexes X
  Real pipeYv[6] = {9.000000,10.000000,10.000000,11.000000,11.000000,9.000000}; //Vertexes Y
  
  Real liquidPipeY[4] = {0,9,9,0};
  Real vin(start = if (Enabled[1]) then  interactive.Model.SS1.vin else if (Enabled[2]) then interactive.Model.SS2.vin else interactive.Model.SS3.vin);
  Real A( start = if (Enabled[1]) then  interactive.Model.SS1.A else if (Enabled[2]) then interactive.Model.SS2.A else interactive.Model.SS3.A);
  Real a( start = if (Enabled[1]) then  interactive.Model.SS1.a else if (Enabled[2]) then interactive.Model.SS2.a else interactive.Model.SS3.a);
  Real h( start = if (Enabled[1]) then  interactive.Model.SS1.h else if (Enabled[2]) then interactive.Model.SS2.h else interactive.Model.SS3.h);
  Real V( start = if (Enabled[1]) then  interactive.Model.SS1.V else if (Enabled[2]) then interactive.Model.SS2.V else interactive.Model.SS3.V);
  Real F( start =  if (Enabled[1]) then interactive.Model.SS1.F else if (Enabled[2]) then interactive.Model.SS2.F else interactive.Model.SS3.F);
  Real selectSS1(start = 1);
  Real selectSS2( start = 0);
  Real selectSS3( start = 0);
  Boolean CK[3];
  Boolean CKstate[3];
  Boolean Enabled[3];
  Real I[3];
  Real Istate[3];
  
equation 
  interactive.View.sliderh.var = h;
  interactive.View.sliderV.var = V;
  interactive.View.sliderF.var = F;
  interactive.View.sliderv.var = vin;
  interactive.View.sliderA.var = A;
  interactive.View.slidera.var = a;
  
  interactive.View.vase.x = {-A/2,-A/2,A/2 + 0.4,A/2 + 0.4,A/2,A/2};
  interactive.View.liquid.x = {-A/2,-A/2,A/2 + 0.4,A/2 + 0.4,A/2,A/2};
  xl = min(interactive.Model.O[1],0.4);
  interactive.View.liquid.y = {interactive.Model.O[1],0,0,xl,xl,interactive.Model.O[1]};
  
  interactive.View.vase.y = vaseYv;
  interactive.View.pipe.x = pipeXv;
  interactive.View.pipe.y = pipeYv;
  
  interactive.View.liquidfrompipe.x = {-0.05*vin,-0.05*vin,0.05*vin,0.05*vin};
  interactive.View.liquidfrompipe.y = liquidPipeY;
  interactive.View.trail.point = {time, interactive.Model.O[1]};
  
  interactive.View.h.var = selectSS1;
  interactive.View.V.var = selectSS2;
  interactive.View.F.var = selectSS3;
  
//Equations to transmit values to interactiveModel
  
  CK[1] =(interactive.View.sliderA.event or interactive.View.sliderv.event or interactive.View.slidera.event);
  CK[2] =(interactive.View.sliderA.event or interactive.View.sliderv.event or interactive.View.slidera.event);
  CK[3] =(interactive.View.sliderA.event or interactive.View.sliderv.event or interactive.View.slidera.event);
  CKstate[1] = (interactive.View.sliderh.event);
  CKstate[2] = (interactive.View.sliderV.event);
  CKstate[3] = (interactive.View.sliderF.event);
  I = {A,vin,a};
  Istate = if (CKstate[1]==true or CKstate[2]==true or CKstate[3]==true) then {h,V,F} else interactive.Model.O;
  Enabled = {selectSS1>0, selectSS2>0, selectSS3>0};
  interactive.Model.CK = CK;
  interactive.Model.CKstate = CKstate;
  interactive.Model.Enabled = Enabled;
  interactive.Model.I = I;
  interactive.Model.Istate = Istate;
  
//Variables linked to the sliders
  
  der(vin) = 0;
  der(A) = 0;
  der(a) = 0;
  der(h) = 0;
  der(V) = 0;
  der(F) = 0;
  der(selectSS1) = 0;
  der(selectSS2) = 0;
  der(selectSS3) = 0;
end tank1OutputInteractive;

VirtualLabBuilder.Examples.tank1OutputSSS.setParamVar

When clauses to change interactive parameter and input variables

Information



The setParamVar class inherits from physicalModel, and it contains the when-clauses required to change the value of the interactive parameters and input variables. The new values of the interactive magnitudes, specified interactively by the virtual-lab user, are included in the array I[:]. The size of these arrays is equal to the number of interactive parameters plus the number of interactive input variables. The when-clauses are triggered by the boolean variables CK and Enabled. When the value of any of these two variables changes from false to true, then the interactive magnitudes are re-initialized to the value of the I[:] array.

Parameters

TypeNameDefaultDescription
BooleanisState[3]{true,false,false}This vector allows controlling the state selection
BooleanhIsStateisState[1]true: h is the state variable
BooleanVIsStateisState[2]true: V is the state variable
BooleanFIsStateisState[3]true: F is the state variable
RealaInitial0.4Initial value of the output hole section
RealAInitial2Initial value of the tank section
RealKInitial100Initial value of the pump parameter
RealvInitial0.01Initial value of the pump voltage
RealhInitial3Initial value of the liquid level
RealVInitial20Initial value of the liquid volume
RealFInitial140Initial value of the liquid flow
Realg981Constant of gravity [cm/s2]

Modelica definition

model setParamVar 
  "When clauses to change interactive parameter and input variables" 
  extends tank1OutputModel;
  Boolean CK;
  Real I[3] "Array containing the new values of the interactive magnitudes";
  Boolean Enabled;
equation 
  when {CK==true and Enabled ==true, Enabled==true} then
     reinit(A, I[1]);
     reinit(vin, I[2]);
     reinit(a, I[3]);
   end when;
end setParamVar;

HTML-documentation generated by Dymola Tue Jul 24 18:58:12 2007.