| Name | Description |
|---|---|
| tank1OutputModel | Physical model |
| StateSelection1 | h: state variable |
| StateSelection2 | V: state variable |
| StateSelection3 | F: state variable |
| interactiveModel | Interactive model |
| Virtual-lab view | |
| tank1OutputInteractive | Interactive model |
| setParamVar | When clauses to change interactive parameter and input variables |
| a | Output hole section. |
| A | Tank section. |
| k | Input valve parameter. |
| vin | Input voltage. |
| Type | Name | Default | Description |
|---|---|---|---|
| Boolean | isState[3] | {true,false,false} | This vector allows controlling the state selection |
| Boolean | hIsState | isState[1] | true: h is the state variable |
| Boolean | VIsState | isState[2] | true: V is the state variable |
| Boolean | FIsState | isState[3] | true: F is the state variable |
| Real | aInitial | 0.4 | Initial value of the output hole section |
| Real | AInitial | 2 | Initial value of the tank section |
| Real | KInitial | 100 | Initial value of the pump parameter |
| Real | vInitial | 0.01 | Initial value of the pump voltage |
| Real | hInitial | 3 | Initial value of the liquid level |
| Real | VInitial | 20 | Initial value of the liquid volume |
| Real | FInitial | 140 | Initial value of the liquid flow |
| Real | g | 981 | Constant of gravity [cm/s2] |
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;
| Type | Name | Default | Description |
|---|---|---|---|
| Boolean | isState[3] | {true,false,false} | This vector allows controlling the state selection |
| Boolean | hIsState | isState[1] | true: h is the state variable |
| Boolean | VIsState | isState[2] | true: V is the state variable |
| Boolean | FIsState | isState[3] | true: F is the state variable |
| Real | aInitial | 0.4 | Initial value of the output hole section |
| Real | AInitial | 2 | Initial value of the tank section |
| Real | KInitial | 100 | Initial value of the pump parameter |
| Real | vInitial | 0.01 | Initial value of the pump voltage |
| Real | hInitial | 3 | Initial value of the liquid level |
| Real | VInitial | 20 | Initial value of the liquid volume |
| Real | FInitial | 140 | Initial value of the liquid flow |
| Real | g | 981 | Constant of gravity [cm/s2] |
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;
| Type | Name | Default | Description |
|---|---|---|---|
| Boolean | isState[3] | {true,false,false} | This vector allows controlling the state selection |
| Boolean | hIsState | isState[1] | true: h is the state variable |
| Boolean | VIsState | isState[2] | true: V is the state variable |
| Boolean | FIsState | isState[3] | true: F is the state variable |
| Real | aInitial | 0.4 | Initial value of the output hole section |
| Real | AInitial | 2 | Initial value of the tank section |
| Real | KInitial | 100 | Initial value of the pump parameter |
| Real | vInitial | 0.01 | Initial value of the pump voltage |
| Real | hInitial | 3 | Initial value of the liquid level |
| Real | VInitial | 20 | Initial value of the liquid volume |
| Real | FInitial | 140 | Initial value of the liquid flow |
| Real | g | 981 | Constant of gravity [cm/s2] |
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;
| Type | Name | Default | Description |
|---|---|---|---|
| Boolean | isState[3] | {true,false,false} | This vector allows controlling the state selection |
| Boolean | hIsState | isState[1] | true: h is the state variable |
| Boolean | VIsState | isState[2] | true: V is the state variable |
| Boolean | FIsState | isState[3] | true: F is the state variable |
| Real | aInitial | 0.4 | Initial value of the output hole section |
| Real | AInitial | 2 | Initial value of the tank section |
| Real | KInitial | 100 | Initial value of the pump parameter |
| Real | vInitial | 0.01 | Initial value of the pump voltage |
| Real | hInitial | 3 | Initial value of the liquid level |
| Real | VInitial | 20 | Initial value of the liquid volume |
| Real | FInitial | 140 | Initial value of the liquid flow |
| Real | g | 981 | Constant of gravity [cm/s2] |
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;
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
| Type | Name | Default | Description |
|---|---|---|---|
| Real | Tcom | 0.1 | Communication interval |
| Integer | serverPort | 4242 | Server Port number |
| String | sourceCodePath | "C:/Program Files/Dymola/Sou... | Path where the C-functions, graphics.jar and delayrun.exe are located |
| String | fileName | "gui.java" | Java file name |
| Integer | liquidIX[6] | {1,1,1,1,1,1} | Interactive x components of the liquid polygon |
| Integer | liquidIY[6] | {1,0,0,1,1,1} | Interactive y components of the liquid polygon |
| Integer | vaseIX[6] | {1,1,1,1,1,1} | Interactive x components of the vase polygon |
| Integer | vaseIY[6] | {0,0,0,0,0,0} | Interactive x components of the vase polygon |
| Integer | liquidFromPipeIx[4] | {1,1,1,1} | Interactive x components of the liquidFromPipe polygon |
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;
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;
| Type | Name | Default | Description |
|---|---|---|---|
| Boolean | isState[3] | {true,false,false} | This vector allows controlling the state selection |
| Boolean | hIsState | isState[1] | true: h is the state variable |
| Boolean | VIsState | isState[2] | true: V is the state variable |
| Boolean | FIsState | isState[3] | true: F is the state variable |
| Real | aInitial | 0.4 | Initial value of the output hole section |
| Real | AInitial | 2 | Initial value of the tank section |
| Real | KInitial | 100 | Initial value of the pump parameter |
| Real | vInitial | 0.01 | Initial value of the pump voltage |
| Real | hInitial | 3 | Initial value of the liquid level |
| Real | VInitial | 20 | Initial value of the liquid volume |
| Real | FInitial | 140 | Initial value of the liquid flow |
| Real | g | 981 | Constant of gravity [cm/s2] |
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;