<< Click to Display Table of Contents >> Navigation: MODELS > Examples > Models Time Delays |
This example illustrates how to used the delay function in MODELS. The delay function gives access to history values of an expression. E.g. y:=delay(x, Ts) assigns a value to y equal the value of x Ts time steps ago. Ts does not need to be a whole number since interpolation is used.
The interpolation degree can be controlled by a third optional parameter delay(x,Ts,i) with
i=0: x considered as a step function of time.
i=1: uses linear interpolation based the two most recent values of x. Default.
i=2: uses quadratic interpolation based on three most recent values of x.
Before using delay(x,Ts,i) the history of the variable x must be specified. This can be done in three ways:
•In HISTORY x {dflt:2.3+t}
•In INIT histdef(x):=2.3+t
•In USE HISTORY x:=2.3+t . -- Not supported by ATPDraw!!
Memory storage for the variable x in the delay function must also be declared. As default 100 time steps are stored for each variable in a delay function. This could be changed by specifying the number of required CELLS (time steps) for each variable in the model definition of in the use statement (not supported by ATPDraw).
E.g. DELAY CELLS DFLT: 200 allocated 200 cells for all variables
DELAY CELLS (x):10 allocates 10 cells for variable x.
BEGIN NEW DATA CASE { DELAY1.DAT }
C deltat tmax xopt copt epsiln tolmat tstart
1. 20.
C print points connec s-s minmax vary again plot
1 1 0 0 0 0 0 1
C ==============================================================================
MODELS
MODEL delay1 -- illustrates the function delay(x,t) in MODELS
DATA d {dflt: 0} -- delay value, may be set from USE statement
VAR a0, a1, a2, a3
b0, b1, b2, b3
HISTORY a2 {dflt: t} -- set default history of a2(t) = t
b0 {flt: 0} -- set default history of b0(t) = 0
b1 {t: 0} -- set default history of b1(t) = 0
b2 {flt: 0} -- set default history of b2(t) = 0
DELAY CELLS DFLT: 2 -- set default number of delay cells
CELLS(b0, b3): 3 -- reserve 3 delay cells each for b0 and b3
CELLS(a2): 8 -- reserve 8 delay cells for a2
INIT
histdef(b3) := t+d -- privately set history of b3(t) = t+d
write('histval(b3,(t=', t-3, '..', t, ') = ')
write(' ',histval(b3,t-3),',') -- evaluate history of b3 at time t-3
write(' ',histval(b3,t-2),',') -- evaluate history of b3 at time t-2
write(' ',histval(b3,t-1),',') -- evaluate history of b3 at time t-1
write(' ',histval(b3,t-0)) -- evaluate history of b3 at time t
ENDINIT
EXEC
b0 := t
b1 := t+10
-- note: when a delay function refers to a time t1 preceding the start of the
-- simulation of the model, it uses the history function of the variable
-- in order to calculate the value of the variable at time t1
a0 := delay(b0, 2) -- returns value of b0(t-2)
a1 := delay(b1, 1.3, 0) -- = b1(t-1.3) (interpolation degree =0)
a2 := delay(a2, 6) -- returns value of a2(t-6)
a3 := delay(b3, d) -- returns value of b3(t-d) (lin. interpolation)
b3 := a3
ENDEXEC
ENDMODEL
USE delay1 AS delay1
DATA d:=2.5 -- assigns a value to the data parameter 'd'
HISTORY b0:=t -- replaces default history set in model for b0. Not supported by ATPDraw.
DELAY CELLS DFLT: 5 -- replaces default delay cell number set in model. Not supported by ATPDraw.
ENDUSE
RECORD delay1.a0 AS a0
RECORD delay1.a1 AS a1
RECORD delay1.a2 AS a2
RECORD delay1.a3 AS a3
ENDMODELS
C ==============================================================================
C BRANCH CARDS
SRCE 10.
BLANK CARD ENDING BRANCHES
BLANK CARD ENDING SWITCHES
14SRCE 1.0 50.
BLANK CARD ENDING SOURCES
{ No node voltages printout/plotting
BLANK CARD ENDING NODE VOLTAGE REQUEST
BLANK CARD ENDING PLOT
BEGIN NEW DATA CASE
BLANK