In the previous chapter we saw how GPSS-Plus can simulate apparently continuous behaviors by using TIMERs and very small time steps. We observed, for example, how a tank was filled on screen, simulating a constant process.
Now we go one step further:
We are not only going to see what happens… we are going to record it and automatically plot it for later analysis.
Because in many cases, observing motion is not enough: we need a curve, a graph, a historical record of the behavior.
For that purpose, GPSS-Plus provides a data tracing system:
PLOTTER and PLOT
PLOTTER {}: declares a graphical table where values will be stored.PLOT: adds a point to that table, using the current time or another variable as the X axis.
Each added point is like a system “frame”, and when the simulation ends, GPSS-Plus draws a curve using all recorded points.
Usage example
In our case, we will record:
PLOTTER {NAME:thePlot, Y_0:level, Y_1:flow, X:TIME_AC1}
This means:
- We will plot two value series:
levelandflow. - The horizontal axis (X) will be time (
AC1$), referenced asTIME_AC1.
To add points at each instant:
PLOT thePlot, X$level, X$flow
This is executed inside the PROCEDURE, on every call, gradually building the process history.
“LEVEL is obtained by accumulating FLOW. The system simulates a continuous integration.”
“Each point corresponds to an instant automatically generated by the TIMER.”
Example
/*
PLOT data collection
*/
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
SYSTEM {type:OPTIONS, TIME_DECIMALS:1, SPEED:5}
SYSTEM {TYPE:ON_TIMER, TRIGGER:filling, INTERVAL: 0.1}
PLOTTER {NAME:thePlot, Y_0:level, Y_1:flow, X:TIME_AC1}
Graphic {NAME:warning,Type:TEXT,X:291,Y:342,Text:"warning"}
Function {Name:fcFlow, Type:Math, Expression:"0.6 + SIN(A) * 4"}
INITIAL level, 0
INITIAL flow, 1.2
INITIAL phase, 0
include ./library_graphics/speedometer.lib
START 100
PROCEDURE PRE_RUN
assign config,{title:"Tank"
,x:100,y:60
,width:100 ,height:180
,min_value: 0
,max_value: 100
,"color":"#ff0000"}
call tank.speedometer.init,V$config
assign config,{title:"Flow"
,x:300,y:60
,width:100 ,height:180
,min_value: -10
,max_value: 10
,"color":"orange"}
call flow.speedometer.init,V$config
TERMINATE_VE
ENDPROCEDURE
PROCEDURE filling
; Oscillate flow as a function of simulated time
SAVEVALUE flow, FN$(fcFlow,X$phase)
; Increase phase
SAVEVALUE phase, X$phase + 0.1
; Add flow to the level
SAVEVALUE level, X$level + X$flow * 0.1
; Record data into the plotter
PLOT thePlot, X$level, X$flow
; Display rounded values
ASSIGN tFlow, round(X$flow, 2)
ASSIGN tLevel, round(X$level, 2)
; Update visual indicators
CALL tank.speedometer.set, P$tLevel
CALL flow.speedometer.set, P$tFlow
IF (X$level>=100)
MOVE {name:warning, text:"TANK FULL!"}
STOP
ELSE
MOVE {name:warning, text:"Level: P$tLevel - Flow: P$tFlow"}
ENDIF
TERMINATE
ENDPROCEDURE 1