Skip to content

Commit

Permalink
requirements example
Browse files Browse the repository at this point in the history
  • Loading branch information
lenaRB authored and OpenModelica-Hudson committed May 11, 2017
1 parent 4f5fdf9 commit 7aeaf08
Show file tree
Hide file tree
Showing 25 changed files with 266 additions and 0 deletions.
@@ -0,0 +1,18 @@
within TwoTanksExample.Design.Components;

partial model BaseController
parameter Real K= 2;
parameter Real T= 10;
input Real ref= 0.25;
Real error;
Real outCtr;
TwoTanksExample.Design.Interfaces.ReadSignalIn cIn annotation(
Placement(visible = true, transformation(origin = {-78, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {-78, 4}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
Interfaces.ActSignalOut cOut annotation(
Placement(visible = true, transformation(origin = {82, 8}, extent = {{-10, -10}, {10, 10}}, rotation = 0), iconTransformation(origin = {82, 8}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
error = ref - cIn;
cOut = outCtr;
annotation(
Diagram,
Icon(graphics = {Rectangle(origin = {2, 10}, extent = {{-70, 52}, {70, -52}}), Line(origin = {3.51258, 14.8423}, points = {{-59.5126, -32.8423}, {-37.5126, 9.15768}, {14.4874, -36.8423}, {54.4874, 33.1577}, {62.4874, 15.1577}, {62.4874, 17.1577}, {62.4874, 17.1577}, {60.4874, 19.1577}})}));end BaseController;
@@ -0,0 +1,10 @@
within TwoTanksExample.Design.Components;

model PIContinuousController
extends TwoTanksExample.Design.Components.BaseController ;
Real x;
equation
der(x) = error/T;
outCtr = K*(error + x);

end PIContinuousController;
@@ -0,0 +1,14 @@
within TwoTanksExample.Design.Components;

model Source

input Real flowLevel= 0;
TwoTanksExample.Design.Interfaces.LiquidFlowOut qOut annotation(
Placement(visible = true, transformation(origin = {74, 12}, extent = {{-24, -24}, {24, 24}}, rotation = 0), iconTransformation(origin = {74, 12}, extent = {{-24, -24}, {24, 24}}, rotation = 0)));
equation

qOut = flowLevel;

annotation(
Diagram,
Icon(graphics = {Ellipse(origin = {-14, 10}, fillColor = {82, 235, 205}, fillPattern = FillPattern.Sphere, extent = {{-64, 62}, {64, -62}}, endAngle = 360)}));end Source;
@@ -0,0 +1,33 @@
within TwoTanksExample.Design.Components;

model Tank

parameter Real flowGain= 0.05;
parameter Real minV= 0;
parameter Real maxV= 10;
parameter Real area= 1;
parameter Real height= 2;


TwoTanksExample.Design.Interfaces.LiquidFlowIn qIn annotation(
Placement(visible = true, transformation(origin = {-64, 20}, extent = {{-18, -18}, {18, 18}}, rotation = 0), iconTransformation(origin = {-64, 20}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));
TwoTanksExample.Design.Interfaces.LiquidFlowOut qOut annotation(
Placement(visible = true, transformation(origin = {72, 18}, extent = {{-16, -16}, {16, 16}}, rotation = 0), iconTransformation(origin = {72, 18}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
TwoTanksExample.Design.Interfaces.ReadSignalOut tSensor annotation(
Placement(visible = true, transformation(origin = {72, -36}, extent = {{-16, -16}, {16, 16}}, rotation = 0), iconTransformation(origin = {72, -36}, extent = {{-16, -16}, {16, 16}}, rotation = 0)));
TwoTanksExample.Design.Interfaces.ActSignalIn tActuator annotation(
Placement(visible = true, transformation(origin = {-64, -36}, extent = {{-18, -18}, {18, 18}}, rotation = 0), iconTransformation(origin = {-64, -36}, extent = {{-18, -18}, {18, 18}}, rotation = 0)));

public Real volume= area * height;
public Real levelOfLiquid;

equation
// Mass balance equation
der(levelOfLiquid) = (qIn - qOut)/area; qOut =
TwoTanksExample.Design.Components.limitValue(minV, maxV, -flowGain*tActuator);

tSensor = levelOfLiquid;

annotation(
Icon(graphics = {Rectangle(origin = {5, 36}, extent = {{-51, 16}, {51, -16}}), Rectangle(origin = {5, 4}, fillColor = {82, 235, 205}, fillPattern = FillPattern.VerticalCylinder, extent = {{-51, 16}, {51, -70}})}));
end Tank;
@@ -0,0 +1,9 @@
within TwoTanksExample.Design.Components;

function limitValue
input Real pMin; input Real pMax;
input Real p; output Real pLim; protected
algorithm
pLim := if p>pMax then pMax
else if p<pMin then pMin else p;
end limitValue;
@@ -0,0 +1,5 @@
within TwoTanksExample.Design;

package Components

end Components;
@@ -0,0 +1,17 @@
within TwoTanksExample.Design;

package Interfaces

connector ActSignalIn = Modelica.Blocks.Interfaces.RealInput;

connector ActSignalOut = Modelica.Blocks.Interfaces.RealOutput;

connector LiquidFlowIn = Modelica.Blocks.Interfaces.RealInput;

connector LiquidFlowOut = Modelica.Blocks.Interfaces.RealOutput;

connector ReadSignalIn = Modelica.Blocks.Interfaces.RealInput;

connector ReadSignalOut = Modelica.Blocks.Interfaces.RealOutput;

end Interfaces;
31 changes: 31 additions & 0 deletions openmodelica/requirements/TwoTanksExample/Design/TwoTanksDesign.mo
@@ -0,0 +1,31 @@
within TwoTanksExample.Design;

model TwoTanksDesign
extends VVDRlib.Verification.Design;
public TwoTanksExample.Design.Components.Tank tank1 annotation(
Placement(visible = true, transformation(origin = {-25, 21}, extent = {{-29, -29}, {29, 29}}, rotation = 0)));
public TwoTanksExample.Design.Components.Tank tank2 annotation(
Placement(visible = true, transformation(origin = {47, 21}, extent = {{-29, -29}, {29, 29}}, rotation = 0)));
TwoTanksExample.Design.Components.PIContinuousController pIContinuousController1 annotation(
Placement(visible = true, transformation(origin = {-24, -50}, extent = {{22, -22}, {-22, 22}}, rotation = 0)));
TwoTanksExample.Design.Components.PIContinuousController pIContinuousController2 annotation(
Placement(visible = true, transformation(origin = {49, -51}, extent = {{25, -25}, {-25, 25}}, rotation = 0)));
public TwoTanksExample.Design.Components.Source source annotation(
Placement(visible = true, transformation(origin = {-88, 18}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
equation
connect(pIContinuousController1.cOut, tank1.tActuator) annotation(
Line(points = {{-42, -48}, {-56, -48}, {-56, 12}, {-44, 12}, {-44, 10}}, color = {0, 0, 127}));
connect(tank1.tSensor, pIContinuousController1.cIn) annotation(
Line(points = {{-4, 10}, {2, 10}, {2, -48}, {-6, -48}, {-6, -50}}));
connect(pIContinuousController2.cOut, tank2.tActuator) annotation(
Line(points = {{28, -48}, {20, -48}, {20, 10}, {28, 10}, {28, 10}}, color = {0, 0, 127}));
connect(tank2.tSensor, pIContinuousController2.cIn) annotation(
Line(points = {{68, 10}, {78, 10}, {78, -50}, {68, -50}, {68, -50}}));
connect(tank1.qOut, tank2.qIn) annotation(
Line(points = {{-4, 26}, {30, 26}, {30, 26}, {28, 26}}));
connect(source.qOut, tank1.qIn) annotation(
Line(points = {{-80, 20}, {-60, 20}, {-60, 28}, {-44, 28}, {-44, 26}}, color = {0, 0, 127}));



end TwoTanksDesign;
5 changes: 5 additions & 0 deletions openmodelica/requirements/TwoTanksExample/Design/package.mo
@@ -0,0 +1,5 @@
within TwoTanksExample;

package Design

end Design;
@@ -0,0 +1,7 @@
within TwoTanksExample;

package Mediators

import VVDRlib.Bindings.Mediator;

end Mediators;
@@ -0,0 +1,10 @@
within TwoTanksExample.Mediators;

record sourceFlowLevel
extends Mediator(mType = "Real",
clients = {Client(modelID = "TwoTanksExample.Design.Components.Source", component = "flowLevel")},
providers = {Provider(modelID = "TwoTanksExample.Scenarios.Normal_operation",
template = "%getPath.flowLevel"),
Provider(modelID = "TwoTanksExample.Scenarios.Overflow",
template = "%getPath.flowLevel")});
end sourceFlowLevel;
@@ -0,0 +1,8 @@
within TwoTanksExample.Mediators;

record tankWaterLevel
extends Mediator(mType = "Real",
clients = {Client(modelID = "TwoTanksExample.Requirements.LiquidLevel", component = "waterLevel")},
providers = {Provider(modelID = "TwoTanksExample.Design.Components.Tank",
template = "%getPath.levelOfLiquid")});
end tankWaterLevel;
@@ -0,0 +1,8 @@
within TwoTanksExample.Mediators;

record volumeLevel
extends Mediator(mType = "Real",
clients = {Client(modelID = "TwoTanksExample.Requirements.Volume_of_a_tank", component = "tankVolume")},
providers = {Provider(modelID = "TwoTanksExample.Design.Components.Tank",
template = "%getPath.volume")});
end volumeLevel;
@@ -0,0 +1,9 @@
within TwoTanksExample.Requirements;

model LiquidLevel
extends VVDRlib.Verification.Requirement;
input Real waterLevel;
equation
status = if (waterLevel < 8) then
VVDRlib.ReqStatus.NOT_VIOLATED else VVDRlib.ReqStatus.VIOLATED;
end LiquidLevel;
@@ -0,0 +1,10 @@
within TwoTanksExample.Requirements;

model Volume_of_a_tank "The volume of each tank shall be at least 2 m3. "
extends VVDRlib.Verification.Requirement;
input Real tankVolume;
parameter Modelica.SIunits.Volume requiredVolume = 2;
equation
status = if tankVolume < requiredVolume
then VVDRlib.ReqStatus.VIOLATED else VVDRlib.ReqStatus.NOT_VIOLATED;
end Volume_of_a_tank;
@@ -0,0 +1,5 @@
within TwoTanksExample;

package Requirements

end Requirements;
@@ -0,0 +1,7 @@
within TwoTanksExample.Scenarios;
model Normal_operation
extends VVDRlib.Verification.Scenario;

output Real flowLevel = 0.5;

end Normal_operation;
11 changes: 11 additions & 0 deletions openmodelica/requirements/TwoTanksExample/Scenarios/Overflow.mo
@@ -0,0 +1,11 @@
within TwoTanksExample.Scenarios;
model Overflow
extends VVDRlib.Verification.Scenario;
output Real flowLevel(start = 0.5);

equation
when time > 5 then
flowLevel = 1.5;
end when;

end Overflow ;
@@ -0,0 +1,5 @@
within TwoTanksExample;

package Scenarios

end Scenarios;
8 changes: 8 additions & 0 deletions openmodelica/requirements/TwoTanksExample/Scripts/run.mos
@@ -0,0 +1,8 @@
// script to test updating of bindings for a specific scenario

loadFile("../package.mo");
getErrorString();
inferBindings(TwoTanksExample.UserDefinedVerificationModels.UDVModel1);
getErrorString();
list(test.TestModel);
getErrorString();
@@ -0,0 +1,8 @@
// script to test updating of bindings for a specific scenario

loadFile("../package.mo");
getErrorString();
generateVerificationScenarios(TwoTanksExample.VerificationModels);
getErrorString();
list(TwoTanksExample.VerificationModels);
getErrorString();
@@ -0,0 +1,12 @@
within TwoTanksExample.UserDefinedVerificationModels;

model UDVModel1
TwoTanksExample.Design.TwoTanksDesign twoTanksDesign1 annotation(
Placement(visible = true, transformation(origin = {42, -28}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
TwoTanksExample.Requirements.Volume_of_a_tank volume_of_a_tank1 annotation(
Placement(visible = true, transformation(origin = {-60, 34}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
TwoTanksExample.Requirements.LiquidLevel liquidLevel1 annotation(
Placement(visible = true, transformation(origin = {-60, -26}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
TwoTanksExample.Scenarios.Overflow overflow1 annotation(
Placement(visible = true, transformation(origin = {42, 28}, extent = {{-10, -10}, {10, 10}}, rotation = 0)));
end UDVModel1;
@@ -0,0 +1,5 @@
within TwoTanksExample;

package UserDefinedVerificationModels

end UserDefinedVerificationModels;
@@ -0,0 +1,7 @@
within TwoTanksExample;

package VerificationModels



end VerificationModels;
4 changes: 4 additions & 0 deletions openmodelica/requirements/TwoTanksExample/package.mo
@@ -0,0 +1,4 @@
within ;

package TwoTanksExample
end TwoTanksExample;

0 comments on commit 7aeaf08

Please sign in to comment.