Models Primer 2003
Models Primer 2003
Version 1
By Gabor Furst
G.Furst Inc,
Vancouver, Canada
Reviewed by:
Laurent Dube
Bruno Ceresoli
Dr. Kurt Fehrle
Dr. Sayeed Ghani
1. INTRODUCTION . . . . . . . . . . . . . . . . . . . . 1
4. FORMAT, SYNATAX . . . . . . . . . . . . . . . . . . 12
4.1 Format . . . . . . . . . . . . . . . . . . . . 13
4.2 Numbers, Variables, Arrays . . . . . . . . . . 14
4.2.1 Numbers . . . . . . . . . . . . . . . 14
4.2.2 Variables . . . . . . . . . . . . . 14
4.2.3 Arrays . . . . . . . . . . . . . 14
4.3 Delimiters . . . . . . . . . . . . . . . . . . 14
4.4 Blank Lines . . . . . . . . . . . . . . . . . . 14
4.5 Other Syntax Conventions . . . . . . . . . . . 15
4.5.1 The Equal Sign . . . . . . . . . . . 15
4.5.2 The Use of Brackets . . . . . . . . . 15
5. MODELS IN ATP . . . . . . . . . . . . . . . . . . . 16
5.1 INPUT's . . . . . . . . . . . . . . . . . . . . 16
5.2 OUTPUT's . . . . . . . . . . . . . . . . . . . 17
8. EXPRESSIONS, FUNCTIONS . . . . . . . . . . . . . . . 28
8.1 Numerical and Logical Expressions . . . . . . . 29
8.2 Numerical Functions . . . . . . . . . . . . . . 29
8.2.1 Resident functions . . . . . . . . . . . 30
8.2.2 Statement functions (User defined) . . . 30
8.3 Pointlist Functions . . . . . . . . . . . . . . 31
8.4 Simulation Expressions and Functions . . . . 32
8.4.1 DERIVATIVE Function . . . . . . . . . . 32
8.4.2 INTEGRAL Function . . . . . . . . . . . 32
8.4.3 SUM Expression . . . . . . . . . . . . . 34
8.5 Simulation Expressions . . . . . . . . . . . . 34
8.5.1 Resident Simulation Expressions . . . 34
8.5.2 CLAPLACE and LAPLACE Transfer Function 35
9. ALGORITHM CONTROL . . . . . . . . . . . . . . . . . 38
9.1 The IF - ENDIF Statement . . . . . . . . . . . 38
9.2 DO - REDO . . . . . . . . . . . . . . . . . . . 39
9.3 WHILE - DO - ENDWHILE . . . . . . . . . . . . . 39
9.4 FOR - DO - ENDFOR . . . . . . . . . . . . . . . 39
9.5 COMBINE . . . . . . . . . . . . . . . . . . . . 42
9.6 TIMESTEP . . . . . . . . . . . . . . . . . . . 42
APPENDIX . . . . . . . . . . . . . . . . . . . . . . . . 48
MODELS Versions of TACS Sources and Devices . . . . 49
A1. MODELS Equivalents of TACS and EMTP Sources . . 49
A2. MODELS Equivalents of TACS Devices . . . . . . 52
1. INTRODUCTION
1
3. THE MAIN GROUPS IN MODELS
2
For example, the MODEL group can be divided as
follows:
MODEL model_name
-- comments
DATA -- declaration
.... entries
CONST -- declaration
.....entries
HISTORY -- directive
..... entries
DELAY CELLS --directive
..... entries
-- comments
VAR -- declaration
..... entries
INIT -- procedure
..... entries
ENDINIT
-- comments
EXEX -- procedure
.... model simulation algorithm
ENDEXEX
ENDMODEL
3
Figure 1
MODELS Structure
4
3.2 Overview of the MODELS File Structure
5
The last and not mandatory group in MODELS is the
request of output of variables under the keyword
RECORD. In the example the variables to be output
are 'vin' 'vout' and 'vdel'.
The MODELS section of the file is terminated by the
keyword ENDMODELS. ENDMODELS, as noted above has to
be followed by an EMTP file . In Example 1/M this is
a 'dummy network', consisting of one source connected
to a branch.
DATA
tperiod { dflt: 0.0 }
ton { dflt: 0.0 }
6
Note that the USE group does not contain a DATA
section, the default values entered in MODEL ill be
used. If the user wants to change the default values
in DATA under USE, the DATA in USE becomes a
directive e.g.:
DATA
tperiod := 0.05
CONST
kt{val: 0.05}
kgain { val:2.0}
HISTORY
vin {dflt: 0}
vout {dflt: 0}
vdel {dflt: 0}
7
The DELAY CELLS directive instructs MODELS to put
aside a number of MODELS memory cells to record past
values of variables. This can be done either in a
default declaration for all variables declared under
HISTORY, or for individual variables. In Example 1/M
:
INIT
tcount := 0.0
dela := 0.010
ENDINIT
EXEC is the keyword heading the section where the
actual simulation is performed by specifying the
simulation algorithm. This section must be
terminated by the keyword ENDEXEC.
8
The second block which is a simple delay is entered
as:
9
Example 1/M
-----------------------------------------------------------------BEGIN NEW DATA CASE
$CLOSE, UNIT=4 STATUS=DELETE
$OPEN, UNIT=4 FILE=mod_1.pl4 FORM=UNFORMATTED STATUS=UNKNOWN RECL=8000 !
C deltat tmax xopt copt epsiln tolmat tstart
.0001 .150
C print points connec s-s minmax vary again plot
1 1 0 1 1 1
MODELS
C no enty in this group
MODEL model_1 -- the name of this model
DATA
tperiod { dflt: 0.0}, ton { dflt : 0.0), tstart { dflt: 0.0
CONST
kt {val: 0.05}, kgain { val: 2.0}
VAR vin, vout, vdel, tcount, dela
HISTORY
vin {dflt: 0}, vout dflt: 0 } vdel {dflt: 0}
DELAY CELLS DFLT: 10
CELLS (vout): 100
CELLS (vdel): 100
INIT
tcount := 0
dela := 0.010
ENDINIT
EXEC
IF t> tstart THEN
-- generate a train of pulses starting at t= tstart
--
tcount := tcount + timestep
-- reset counter at end of on/off period
IF tcount > tperiod THEN tcount := 0 ENDIF
-- vin 100 or 0 depending time within period
IF tcount < ton THEN
vin := 100.0
ELSE vin := 0.0
ENDIF
--
-- a more compact generation of a train of pulses is given by :
-- vin:= 100 * ( (t - tstart) MOD tperiod < ton)
--
-- calculate output from k /(a+bs) block
laplace (vout/vin) := kgain|s0/(1|s0 + kt|s1)
-- delay output
vdel := delay(vout, dela)
ENDIF
ENDEXEC
ENDMODEL
C ------------------------------------------------------------
USE model_1 AS test
DATA tperiod := 0.05
ton := 0.03
tstart := 0.02
ENDUSE
C
RECORD
test.vin AS vin
test.vout AS vout
test.vdel AS vdel
ENDMODELS
C BRANCH CARDS EMTP data section
SRCE 10.
BLANK CARD ENDING BRANCHES
C no switches
BLANK CARD ENDING SWITCHES
14SRCE 1.0 50.
BLANK CARD ENDING SOURCES
SRCE
BLANK CARD ENDING NODE VOLTAGE REQUEST
BLANK CARD ENDING PLOT
BEGIN NEW DATA CASE
BLANK
10
Example 1/T
-----------------------------------------------------------------
BEGIN NEW DATA CASE
$CLOSE, UNIT=4 STATUS=DELETE
$OPEN, UNIT=4 FILE=tacs_1.pl4 FORM=UNFORMATTED STATUS=UNKNOWN RECL=8000 !
C deltat tmax xopt copt epsiln tolmat tstart
.0001 .150
C print points connec s-s minmax vary again plot
1 1 0 1 1 1
TACS HYBRID
C
99DELA = 0.010
23VIN 100.0 0.050 0.030 0.020
C
1VOUT +VIN 2.0
1.0
1.0 .050
C
98VDEL 53+VOUT 0.011 DELA
C
C initializations
77VIN 0.0
77VOUT1 0.0
77DELA .010
C
C ********* TACS OUTPUTS ************
C
33VIN VOUT VDEL
BLANK end of TACS
C BRANCH CARDS EMTP data section
SRCE 10.
BLANK CARD ENDING BRANCHES
C no switches
BLANK CARD ENDING SWITCHES
14SRCE 1.0 50.
BLANK CARD ENDING SOURCES
SRCE
BLANK CARD ENDING NODE VOLTAGE REQUEST
BLANK CARD ENDING PLOT
BEGIN NEW DATA CASE
BLANK
11
4. FORMAT, SYNATAX
4.1 Format
C this is a comment
or
-- this is a comment
-- this is a continuation of the comment
or
COMMENT
this is the first comment line
this is the second comment line
etc. etc.
ENDCOMMENT
12
4.2 Numbers, Variables, Arrays
4.2.1 Numbers
- Numbers allowed:
12, -3, 0.95, -12.44, -0.4
0.3E-1, -3.6E+9, 4E9, 3.E-04
4.2.2 Variables
- Names allowed:
John
John_and_Mary
test_example
etc.
4.2.3 Arrays
13
4.3 Delimiters
Examples:
VAR a
x1
b[1..3]
or
VAR a, x1, b[1..3]
or
VAR a x1 b[1..3]
HISTORY y{dflt:0}
x{dflt:sin(omega*t)}
or
HISTORY y{dflt:0} x{dflt:sin(omega*t)}
14
4.5 Other Syntax Conventions
x := y * ( a + b )
ya := sqrt (x/b)
laplace ( y/x ) := k:s0 / (1|s0 + b |s1)
xt : = integral ( cos ( omega * t))
Round brackets () are also used in some of the
declaration related statements, such as under the
INIT directive:
a [1..3] := [ 1, 2, 3] meaning
a[1], a[2], a[3] equal to 1,2,3 respectively
15
Braces {} are used in declarations, defining limits
or attributes. For example:
5. MODELS IN ATP
INPUT vv {dflt: 0}
ii {dflt: 0}
16
c) In the USE group, it is declared that the variables
volt and cur imported from an outside source will be
used for the variables vv and ii respectively.
INPUT vv:= volt
ii:= cur
5.2 OUTPUT's
17
Example 2/M
-------------------------------------------------------------------------
BEGIN NEW DATA CASE {active power calculation
$CLOSE, UNIT=4 STATUS=DELETE
$OPEN, UNIT=4 FILE=mod_2.pl4 FORM=UNFORMATTED STATUS=UNKNOWN RECL=8000
!
PRINTED NUMBER WIDTH, 13, 2,
C deltat tmax xopt copt epsiln tolmat tstart
.0001 .200 50. 0.0
C print points connec s-s minmax vary again plot
1 1 0 0 0 0 0 1
C
MODELS
INPUT volt {v(BUSA)}
cur {i(BUSB)}
OUTPUT FIRE
MODEL model_2
DATA freq {dflt: 0}
C
VAR
pavg, tmult
tper,tmult, vdel, idel, aa
C
INPUT vv {dflt: 0} ii {dflt: 0}
C
OUTPUT aa
C
HISTORY vv {dflt: 0} ii {dflt: 0}
C
INIT
tper := 1/freq
tmult := tper/timestep
pavg := 0
aa := 0
ENDINIT
C
DELAY CELLS (vv): 200
CELLS (ii): 200
C
EXEC
C calculate active power
vdel := delay (vv, tper )
idel := delay (ii, tper )
pavg := pavg +( vv * ii - vdel * idel)/tmult
C
IF t > 0.05 then aa :=1.0 endif
-- the above can be replaced with a logical expression
-- a:= t>= 0.05
C
ENDEXEC
ENDMODEL
18
Example 2/M Continued
------------------------------------------------------------------------
USE model_2 AS test
DATA freq := 50
INPUT
vv:= volt
ii:= cur
OUTPUT FIRE := aa
ENDUSE
C
RECORD test.vv AS vv
test.ii AS ii
test.pavg AS pavg
ENDMODELS
C EMTP data
C =============================================================
C BRANCH CARDS
GENA BUSA .010
BUSC 99.01 9.9
BUSA1 BUSC .010
BUSC1 BUSC .010
BLANK CARD ENDING BRANCHES
BUSA BUSB MEASURING
11BUSB BUSA1 0. 0.0 FIRE
11BUSC1 BUSB 0. 0.0 FIRE
BLANK CARD ENDING SWITCHES
14GENA 141000.0 50. 0. -1
BLANK CARD ENDING SOURCES
BUSB
BLANK CARD ENDING NODE VOLTAGE REQUEST
BLANK CARD ENDING PLOT
BEGIN NEW DATA CASE
BLANK
Note:
In the above model the execution is defined in two steps for clarity. In an
actual application the following would execute faster:
p := vv * ii
pavg := pavg * ( p - delay (p,tper) ) / tmult
19
Example 2/T
---------------------------------------------------------------
BEGIN NEW DATA CASE
$CLOSE, UNIT=4 STATUS=DELETE
$OPEN, UNIT=4 FILE=tacs_2.pl4 FORM=UNFORMATTED STATUS=UNKNOWN RECL=8000 !
C deltat tmax xopt copt epsiln tolmat tstart
.0001 .150
C print points connec s-s minmax vary again plot
1 1 0 1 1 1
TACS HYBRID
C
99DELA = 0.020
99FREQ = 50.0
99TPER = 1 / FREQ
99TMULT = TPER / DELTAT
90BUSA
91BUSB
0CURT +BUSB
0VOLT +BUSA
88VDEL 53+VOLT .021 DELA
88IDEL 53+CURT .021 DELA
88PAVG = PAVG1 + ( VOLT * CURT - VDEL * IDEL ) / TMULT
0PAVG1 +PAVG
11FIRE 1.0 0.050
C
C initialization
77PAVG 0.0
77PAVG1 0.0
77FIRE 0.0
C
C ********* TACS OUTPUTS ************
C
33VIN VOLT CURT PAVG VDEL IDEL
BLANK end of TACS
C EMTP data same as for Example 2/M
20
6. MORE ABOUT DECLARATIONS
For the data input that does not come from a source
external to MODEL, that is from another MODEL or from
EMTP, data can be entered either under DATA or CONST.
These entries can be numbers or expressions which may
contain some of the resident constants of MODELS.
The important difference between DATA and CONST is
that the values entered under DATA can be overridden
in a DATA directive under USE, whereas the values
entered under CONST cannot be changed from outside
the MODEL.
DATA
The following entries are acceptable under DATA:
DATA frequency
or
DATA frequency {dflt:0}
or
DATA omega {dflt:2*pi*50}
or for an array
DATA volt[1..3] {dflt: [va,vb,vc}}
MODELS
MODEL test
DATA frequency {dflt:0}
DATA omega {dflt: 2*pi*frequency}
-- etc
-- description of model
ENDMODEL
USE test AS test
DATA frequency := 50
-- etc.
ENDUSE
ENDMODELS
21
Note that DATA frequency or DATA frequency
{dflt:0} are equivalent entries. It is
recommended that the [dflt:0} be always used as
a reminder to enter a value under USE - DATA.
CONST
pi = 3.14...
false = 0, true = 1
no = 0, yes = 1
open = 0, closed = 1
off = 0, on = 1
an undefined variable is given the value
88888.88888
22
As explained in Chapter 5, the INPUT declaration
in MODEL has to be followed up by an INPUT
directive under USE, where MODELS are told what
variables from an another model or EMTP will be
used in MODEL. Assume that the 'receiving'
model which needs the inputs 'volt' and
'current' is named 'Mary', and the 'exporting'
model, which outputs the variables to use as
input by Mary is the EMTP part of MODELS. The
variables from EMTP which will be used by Mary
are named 'voltout' and 'curout' to be used by
Mary as 'volt' and 'current'. The declarations
for Mary will have to be as follows:
MODELS
INPUT voltout {v(BUSA)} -- BUSA from
EMTP
curout {i(BUSB)} -- BUSB from EMTP
MODEL Mary
INPUT volt {dflt:0}
current {dflt:0}
.... other declarations
EXEC
..... simulation
ENDEXEC
ENDMODEL
USE Mary as Mary
INPUT volt := voltout
current := curout
.... other directives
ENDUSE
ENDMODELS
OUTPUT
The declaration OUTPUT tells MODEL that the
variable under this declaration may be passed on
to another MODEL. Like INPUT, the OUTPUT
declaration inside MODEL has to have a
corresponding OUTPUT directive in USE, where the
user defines the name under which the output is
passed to another MODEL.
23
MODELS
MODEL John
....
OUTPUT fia, fib
-- rest of model John
ENDMODEL
USE John AS John
OUTPUT ftxa := fia ftxb := fib
ENDUSE
MODEL Mary
INPUT ff1 ff2
-- rest of model Mary
ENDMODEL
USE Mary AS Mary
INPUT ff1 := ftxa ff2:= ftxb
-- etc.
ENDUSE
ENDMODELS
24
6.4 HISTORY and DELAY CELLS
HISTORY
HISTORY y2 { dft:0 }
(HISTORY y2 can be used only if the history
of y2 is in the USE section. The first
time MODELS user should avoid this)
or
HISTORY y {dflt : ampl*omega*t)}
( with omega entered under DATA or CONST )
or
HISTORY a[1..4] {dflt: 0}
or
HISTORY volt[1..3] {dflt : [va,vb,vc]}
(with va,vb,vc imported by IMPUT)
25
It is important to note that extreme care should be
exercised in defining history in terms of another
function, or even in terms of the same function. In
this case the past history of the function for which
history is declared may be replaced with the history
of the other function. For example:
HISTORY y := 0
y := 2*sin(t)
History in INIT
Both the history declarations in MODEL and in USE are
superseded by the history declaration in INIT. As
noted above, this is not a frequently used option,
and should be avoided by the first time MODELS user.
The syntax is
26
DELAY CELLS
27
For example:
INIT
y1 := 0
x1:= 5
Z := omega*t
histdef(uv) := 3*t
ENDINIT
8. EXPRESSIONS, FUNCTIONS
Numerical expressions:
x := a * b
x := a ** -2.21
x := ( a + b ) * ( c + d) / x ** 2
etc.
note again the use of the := (assignment
symbol) indicating that the expression on
the right hand side is 'assigned to x'.
(Strictly speaking, in terms of the MODELS
language, the above are not expressions but
assignments os expressions)
28
An numerical expression ca be followed by a limiter
put in {} following the expression as follows:
x := ( a + b ) * ( c + d) { min:-0.76}
or
v := 2 * omega*t { min: 0.95 max: 1.8}
or
y := ( a + x ) { max:0.6 }
Logical expressions:
y := a > b
y := a > b or c < a
or in the Boolean form
y := bool (x)
y := AND (a, b, c)
y := NOR (a, b, c )
etc.
29
8.2.1 Resident functions
30
8.3 Pointlist Functions
31
8.4 Simulation Expressions and Functions
DERIVATIVE Expression
with Linear Polynomial
where x is a variable
dmax and dmin are dynamic limits
Example:
MODEL diff
CONST omega { val: 314 }
VAR x, dx, y
HISTORY x {dflt: 0}
--
EXEC
x :=sin ( omega * t )
dx := deriv (x) {max: 0.6 *cos(omega*t)}
ENDEXEC
ENDMODEL
where x is a variable
dmax and dmin are dynamic limits
32
Only dynamic limits can be used with MODELS
integrals. This means that the integral is not
clipped but limited by the process of integration.
For details see Chapter 2.9.5.1 of the Manual.
Integrals can be tricky. The user must declare both
x and integral(x) under HISTORY, and such
declarations may not be trivial.
Examples:
MODEL test
VAR a, x, y
HISTORY x {dflt :0}
integral (x) { dflt
:0 }
--
EXEC
x := a*t
y := integral (x) { dmax: 50 dmin: 10 }
ENDEXEC
ENDMODEL
The value of integral can be reset during the
simulation by the integral reset expression:
Example :
MODEL test
CONST omega { val: 2*pi*50 }
VAR y, y1, x
HISTORY x { dflt: 0 }
33
8.4.3 SUM Expression
k = a + bx + cx 2 + ..... zx n
Example:
Evaluate the polynomial k = a + bx + cx 2
MODEL test
DATA a {dflt : 3.5}
CONST b {val: 2.0}
c {val :4.4}
VAR k, x, x1
--
EXEC
x := t
x1 := t**2
k := sum ( a + b|x + c|x1 )
ENDEXEC
ENDMODEL
delay ( x, d, pol )
34
Warning: The delay function provides the
history of the variable x, at a discrete
interval back from the current time, and
not necessarily at the precise interval t-
d. There ca be an error depending on the
size of the time step used in the model.
Some models can be critically sensitive to
this, resulting in a large error in the
output of the model. An example of this is
the active power model shown in example
2/M, where an error of one timestep could
result in a large error of the power
calculated. In most cases adding a
fraction of the timestep to t-d solves the
problem, but the user should check this
carefully in each individual model.
35
where:
x = input variable
y = output
36
MODEL
--
DATA
kagin {dflt: 50}
kfd {dflt:0.02}
CONST
te {val: 0.5}
tfd {val: 1.2}
VAR serror, sin, sref, sfeed, sed, sout
HISTORY
serror {dflt:0}
sfeed {dflt:0}
sed {dflt:0}
INIT
sin := 1.0
sout := 0
ENDINIT
--
EXEC
serror := sum( 1|sref + 1|sin - 1|sfeed)
CLaplace ( sed / serror) :=
( kgain|s0 / ( 1|s0 + te|s1 )
CLaplace ( sfeed / sed ) :=
( kfd|s1 ) / ( 1|s0 + tfd|s1 )
sout := sed {max: 0.05 min: -0.05 }
ENDEXEC
ENDMODEL
37
9. ALGORITHM CONTROL
- IF .... ENDIF
- FOR .... ENDFOR
- DO ---- ENDDO
- WHILE -- ENDWHILE
- REDO
- SEQUENCE
- COMBINE
Example:
IF case = 1 THEN
a:= 33
cb:=sqrt (d1)
ELSIF case >=2 and case < 5 THEN
a := 24
cb := sqrt (d2)
ELSE
a := 20
cb := d3
ENDIF
38
9.2 DO - REDO
Example:
EXEC
DO
write ( 'start/restart DO ' )
write ( ' k = ',k )
k := k - 1
IF k > 0 REDO ENDIF
x := 10
write ( ' x = ',x )
ENDDO
ENDEXEC
Example:
EXEC
VAR k
WHILE k > 0 DO
k := k-1
write ( ' k = ',k )
ENDWHILE
ENDEXEC
39
The syntax is:
FOR i := k1 TO k2 BY d
DO
-- list of instructions
ENDFOR
BY is optional with a default of 1
FOR i := 1 TO 5
FOR k := 3 to 1 BY -1
DO
instructions
ENDFOR
40
Example 3
---------------------------------------------------------------------------
BEGIN NEW DATA CASE
$CLOSE, UNIT=4 STATUS=DELETE
$OPEN, UNIT=4 FILE=model_3.pl4 FORM=UNFORMATTED STATUS=UNKNOWN
RECL=8000! PRINTED NUMBER WIDTH, 13, 2,
C deltat tmax xopt copt epsiln tolmat tstart
.0001 .080 50. 0.0
C print points connec s-s minmax vary again plot
1 1 0 0 0 0 0 1
C
============================================================================
=MODELS
MODEL test
CONST omega { val: 2*pi*50 }
C
VAR
volt [ 1..3], fire[1..3]
C
C
HISTORY
fire[1..3] {dflt:0}
volt[1..3] {dflt:0}
INIT
-- no initialization req'd, initialized in HISTORY
ENDINIT
C
DELAY CELLS DFLT: 10
C
EXEC
-- generate three phase voltages
FOR i:= 1 TO 3 DO
volt[i] := sin ( omega*t + (i-1)*2*pi/3 )
ENDFOR
-- generate 500 us firing pulses at 0 transition of voltages
-- note use of logical expression
-- fire = 1 if both volt and - volt(delayed) are > zero
FOR i := 1 TO 3 DO
fire[i] := volt[i] and -delay (volt[i],0.0005)
ENDFOR
ENDEXEC
ENDMODEL
USE test AS test
timestep min:0
ENDUSE
C --------------------------------------------------------------
RECORD test.volt[1] AS va
test.volt[2] AS vb
test.volt[3] AS vc
test.fire[1] AS fira
test.fire[2] AS firb
test.fire[3] AS firc
ENDMODELS
C BRANCH CARDS
SRCE 10.
BLANK CARD ENDING BRANCHES
BLANK CARD ENDING SWITCHES
14SRCE 1.0 50.
BLANK CARD ENDING SOURCES
SRCE
BLANK CARD ENDING NODE VOLTAGE REQUEST
BLANK CARD ENDING PLOT
BEGIN NEW DATA CASE
BLANK
41
9.5 COMBINE
COMBINE AS groupx
statements
ENDCOMBINE
9.6 TIMESTEP
42
10. RECORD - Write
10.1 RECORD
modelname.varnamex AS outnam
10.2 Write
For the testing and debugging models, the user may
put 'write' statements in the EXEC part of the model,
to monitor the operation of the step by step
operation and execution of the model. The required
information will be written into the .lis file during
the execution of the model in each time step unless
otherwise directed by an if statement. The syntax of
this Fortran like statement is:
43
11. Multiple MODEL's
MODELS
MODEL John
...........
ENDMODEL
USE John AS John
.......
ENDUSE
MODEL Mary
.........
ENDMODEL
USE Mary AS Mary
...........
ENDUSE
ENDMODELS
Assume that the user has developed two models, one for the
calculation of single phase active power in an ac system,
and for reactive power.
These models are named 'power' and 'reactive'
respectively.
-- POWER
MODEL power
--
VAR pavg, vdel, idel
INPUT vv {dflt: 0}, ii {dflt: 0}
freq {dflt:0}, tper{dflt:0}, tmult{dflt:0}
HISTORY vv {dflt: 0}
ii {dflt: 0}
INIT pav := 0
ENDINIT
DELAY CELLS (vv): tper/timestep
CELLS (ii): tper/timestep
EXEC
-- calculate active power
vdel := delay (vv, tper )
idel := delay (ii, tper )
pavg := pavg +( vv * ii - vdel * idel)/tmult
ENDEXEC
ENDMODEL
44
The reactive model is as follows:
-- REACTIVE
MODEL reactive
VAR qavg, tperq, tmultq, vdel, idel
INPUT vv {dflt: 0}, ii {dflt :0}
freq, tper, tmult
HISTORY vv {dflt: 0}, ii {dflt:0}
INIT
tperq := tper/2, tmultq := tmult/2, qavg := 0
ENDINIT
DELAY CELLS (vv): tper/timestep
CELLS (ii): tper/timestep
-- calculate reactive
EXEC
vdel:= delay (vv, tper )
idel := delay (ii, tperq)
qavg:=qavg+(ii * delay (vv,tperq)-vdel * idel)/tmultq
ENDEXEC
ENDMODEL
45
13. Testing - Debugging
As with EMTP and TACS, the first time MODELS user will no
doubt make a large number of mistakes in preparing the
first MODELS files. To debug these files the KILL
feature, similar to that in ATP is also used by MODELS.
Due to the fact that MODELS has had a smaller field
exposure than ATP/EMTP, the KILL codes are not so well
developed in MODELS as in ATP. Caution should therefore
be exercised in the interpretation of KILL messages, which
occasionally are misleading. The user should report such
messages to Laurent Dube. It is recommended that the
first time user adopts a step by step approach in
developing a MODELS file, starting with only a few
statements and gradually adding to the file. This way the
debugging will be much easier.
Example 4
---------------------------------------------
46
USE reactive AS reactive
INPUT
vv := vv, ii := ii, freq := freq, tper := tper, tmult := tmult
ENDUSE
-- POWER
$INCLUDE power.dat
USE power AS power
INPUT
vv:= vv, ii:= ii
tper := tper, tmult := tmult, freq := freq
ENDUSE
C ---------------------------------------------------------------
--
RECORD test.vv AS vv
test.ii AS ii
reactive.qavg AS qavg
power.pavg AS pavg
ENDMODELS
--
C BRANCH CARDS
GENA BUSA .010
BUSB 99.01 9.9
BLANK CARD ENDING BRANCHES
BUSA BUSB MEASURING
BLANK CARD ENDING SWITCHES
14GENA 141000.0 50. 0. -1
BLANK CARD ENDING SOURCES
BUSB
BLANK CARD ENDING NODE VOLTAGE REQUEST
BLANK CARD ENDING PLOT
BEGIN NEW DATA CASE
BLANK
47
APPENDIX
A0. Intoductiom
To assist first time MODELS users who previously used TACS and
are accustomed to use the TACS sources and devices in
developing data files, the equivalent MODELS version of these
sources and devices has been prepared. This will also provide
help to users who have previously not used TACS to develop
MODELS files.
The sources and devices are presented in the form of individual
MODEL's which the user can integrate in a MODELS file, either
by a separate MODEL, or by copying the coding of the MODEL into
a MODELS file which contains only a single MODEL. Depending
on the method of usage, the DATA declaration in the MODEL, or
DATA directive in the USE section has to be completed by the
user.
48
A1. MODELS Equivalents of TACS and EMTP Sources
List of Sources:
***************************************************************
TACS Source Code 11 - Level Signal and Single Pulse
================================================================
MODEL single_pulse --
--
DATA tstart {dflt:0} -- pulse start time sec.
tstop {dflt:1000} -- cut-off time sec.
ampl {dflt :1} -- amplitude
width {dflt:0} -- pulse width
-- for unit pulse eneter a large pilse width, say 100 sec.
VAR spulse
EXEC
IF t > tstart and tstop > t THEN
spulse := ampl * (t > tstart and t< tstart + width)
ENDIF
ENDEXEC
ENDMODEL
-
****************************************************************
TACS Source Code No. 14 Cosine Wave
================================================================
MODEL cosine -- cosine source
--
DATA tstart {dflt:0} -- start time
tstop {dflt:1000} -- cut-off time
ampl {dflt :1.0} -- amplitude
freq {dflt:60} -- frequency
angle {dflt:0} -- angle deg. at t=tstart
VAR cosine, omega
INIT omega := 2*pi*freq ENDINIT
EXEC
cosine := ampl *( cos (omega*(t-tstart) + angle*pi/180) )
* AND ( (t - tstart),(tstop-t) )
ENDEXEC
ENDMODEL
================================================================
49
****************************************************************
TACS Source Code No. 23 Pulse Train
================================================================
MODEL pulse_train --
--
DATA tstart {dflt:0} -- starting time
tstop {dflt :1000} -- cut-off time
ampl {dflt:1} -- amplitude
width {dflt:0} -- pulse width
period {dflt:0} -- pulse period
VAR pulse_tr
EXEC
pulse_tr := ampl * ((t - tstart) mod period < width)
* AND ( (t - tstart),(tstop-t) )
ENDEXEC
ENDMODEL
================================================================
****************************************************************
TACS Source Code No. 24 Ramp Train
================================================================
MODEL saw_tooth
--
DATA tstart {dflt:0} -- starting time
tstop {dflt :1000} -- cut-off time
ampl {dflt:1} -- amplitude
width {dflt:0} -- pulse width
period {dflt:0} -- pulse period
VAR sawtooth, x
INIT x := ampl/period ENDINIT
EXEC
sawtooth := x * ((t - tstart) mod period )
* AND ( (t - tstart),(tstop-t) )
ENDEXEC
ENDMODEL
================================================================
*******************************************************************
EMTP Type No. 13 Two Slope Ramp
===================================================================
MODEL double_ramp -- linear rise and fall
--
DATA tstart {dflt:0} -- start of signal
ampl {dflt :1.0} -- amplitude at time tstart + t0
a1 {dflt:0} -- amlpitude at time tstart + t1
t0 {dflt:0} -- rise time
t1 {dflt:0} -- time to amplitude a1
--
VAR rampout, rup, rdown, tsl1, tsl2
INIT rampout:=0, tsl1:=ampl/t0, tsl2:= (ampl-a1)/(t1-t0)
ENDINIT
EXEC
rup := (timestep * tsl1)
* AND ( (t-tstart), (tstart + t0 -t) )
rdown := -(timestep * tsl2)
* AND ( t-tstart - t0 - timestep, rampout )
rampout := rampout + rup + rdown
ENDEXEC
ENDMODEL
===================================================================
50
*******************************************************************
EMTP Type No. 15 Double Exponential Surge
===================================================================
MODEL d_surge -- double exponential surge
--
DATA tstart {dflt:0} -- start of signal
tstop {dflt:1000} -- cut-off signal
ampl {dflt :1} -- amplitude
a {dflt:-10} -- 1/a time const. first exponential
b {dflt:-30} -- 1/b time const. second
exponential
VAR surgeout
OUTPUT surgeout -- delete if not used as separate MODEL
EXEC
surgeout:= ampl * (exp(a*(t-tstart)) - exp(b*(t-tstart)))
* AND((t-tstart),(tstop-t))
ENDEXEC
ENDMODEL
===================================================================
51
A2. MODELS Equivalents of TACS Devices
List of Devices:
*******************************************************************
TACS Device 50 Frequency Meter
===================================================================
MODEL freq_meter
--
DATA tstart{dflt:0} -- start metering
tstop {dflt:1000} -- cut off
VAR volt, freq, a, t
volt -- sample signal 60 Hz
-- note that to get a reasonably accurate result the period
-- should be a near exact multiple of at least 50 times of
-- the timestep used. E.g. for 60 Hz timstep = 0.000333
--
-- sin(omega.t) is shown as an example
HISTORY volt {dflt:0}
--
INIT freq:=0, tf:= 10000 ENDINIT
--
EXEC
volt := sin ( 2*pi*60)
a:= AND ( (volt), (- prevval(volt)),(t-tstart),(tstop-t) )
if a then
freq:= 1 /(tf+timestep)
tf := 0
else tf := tf + timestep
endif
ENDEXEC
ENDMODEL
=====================================================================
52
*********************************************************************
TACS Device 51-52 Relay swithch
=====================================================================
MODEL relay_switch -- relay operated switch - TACS Code 51
-- or level triggered switch - TACS Code 52
DATA tstart{dflt:0} -- start metering
tstop {dflt:1000} -- cut-off
gain {dflt:0}
th_hold {dflt:0} -- threshhold value for operation
oper {dflt:0} -- 0 for n/o, 1 for n/c
type { dflt:0} -- 0 abs values ( type 51 )
-- 1 actual values ( type 52 )
-- note: INPUT and OUTPUT statements not required if model is
-- is integrated into another model which generates these
variables
-- see the Primer on the correct use of INPUT / OUTPUT
INPUT drive_s -- driving signal
in1, in2, in3 -- inputs
OUTPUT rel_out -- device 51/52 output
--
VAR rel_out -- output of 51 or 52
sumin
INIT rel_out:= 0 ENDINIT -- initialize because if t> loop
--
EXEC
IF t> tstart and tstop > t then
sumin := in1 + in2 + in3
if oper =0 and type = 0 then
rel_out := (gain *sumin) * (abs(drive_s) >= abs(th_hold) )
-- n/o
elsif oper = 0 and type = 1 then
rel_out := (gain *sumin) * ( drive_s >= th_hold ) -- n/o
elsif oper = 1 and type = 0 then
rel_out := (gain * sumin) * (abs(drive_s) <= abs(th_hold) )
-- n/c
elsif oper = 1 and type = 1 then
rel_out := (gain * sumin) * (drive_s <= th_hold ) -- n/c
endif
ENDIF
ENDEXEC
ENDMODEL
=====================================================================
*********************************************************************
TACS Devices 53 and 54 Transport Delay and Pulse Delay
=====================================================================
-- MODEL transport delay and pulse delay TACS Codes 53, 54
-- these can be simulated in MODELS by the delay function and
-- appropriate history declaration
=====================================================================
53
*********************************************************************
TACS Devices 55 Digitizer
56 Point by point Nonlinearity
57 Time Sequenced Switch
=====================================================================
MODEL point_list
-- *******************************************
-- simulated in MODELS by the POINT LIST functions
C function of angle
VAR x1, e, i, swcont
INIT e := 0 ENDINIT
-- ===========================================================
-- this corresponds to TACS Device 55 Digitizer
FUNCTION stairs POINTLIST -- staircase x1(t) function
-- t x1
( 0.0, 1.0)
( 0.04, 1.0)
( 0.07, 2.0)
( 0.10, 3.0)
( 0.15, 4.0)
( 0.20, 5.0)
( 0.25, 6.0)
( 0.30, 7.0)
-- ===========================================================
-- this corresonds to TACS Device 56 Point - by Point Nonlinearity
FUNCTION saturation POINTLIST -- e(i) saturation function
-- i e
( 0.0, 0.0 )
( 1.0, 0.5 )
( 5.0, 1.0 )
( 5.5, 1.0 ,)
( 6.0, 1.1 )
( 7.0, 1.15 )
( 8.0, 1.2 )
( 10.0, 1.25 )
( 20.0, 1.4 )
54
-- ===============================================================
-- this corresponds to TACS Device 57 Time Sequenced Switch
FUNCTION switch_control POINTLIST
-- t switch_control
( 0.0 0 )
( 0.1 1 )
( 0.2 0 )
( 0.25 1 )
( 0.40 0 )
EXEC
if t> 0 then
x1 := stairs (t,0) -- example for device 55
endif
FOR i := 0 TO 20 BY 1.0 DO
e := saturation(i) -- example for device 56
ENDFOR
swcont := switch_control(t,0) -- example for device 57
--
ENDEXEC
ENDMODEL
USE point_list AS point_list -- example only
timestep min:0
ENDUSE
C
RECORD freq_meter.freq AS freq
relay_switch.rel_out AS relout
point_list.swcont AS swcont
ENDMODELS
C
=====================================================================
***************************************************************
TACS Device 58 Controlled Integrator
=====================================================================
--
-- Covered by the integral expression and value reset
-- expressions in the MODELS language - see Manual Chapter 2.9.5
*********************************************************************
TACS Device 59 Single Derivative
=====================================================================
--
-- Covered by the derivative expressions
-- in the MODELS language - see Manual Chapter 2.9.4
=====================================================================
*********************************************************************
TACS Device 60 Input IF component
=====================================================================
--
-- Covered by the algorithm control statements
-- in the MODELS language - see Manual Chapter 2.3.2
=====================================================================
55
*********************************************************************
TACS Device 61 Signal selecttor
--
-- Covered by the algorithm control statements
-- in the MODELS language - see Manual Chapter 2.3.2
=====================================================================
*********************************************************************
TACS Device 62 Sample and Track
====================================================================
MODEL sample_track
--
DATA tstart {dflt:0} -- start
tstop {dflt:1000} -- cut off
VAR track, x, insig, trackout, sampleout
HISTORY sampleout {dflt:0}
trackout {dflt:0}
INIT trackout:=0 sampleout := 0 ENDINIT
--
EXEC
-- ************************
-- note: insig and track functions are given here as an example only
-- they are to be replaced by the user's respective functions
--
-- assume that the signal to be sampled is :
insig := 2 + 3 * exp (-t) * sin ( 62.8 * t)
-- and the tracking or sampling signal is:
track := (t-0.02) mod 0.1 < 0.03
--
-- ******************
IF t > tstart and tstop > t then
-- output for the tracking option
if track > 0 then
trackout := insig
else trackout := prevval (trackout)
endif
--
-- output for the sampling option
if track > 0 and prevval (track) = 0 then
sampleout := insig
else sampleout := prevval ( sampleout)
endif
ENDIF
ENDEXEC
ENDMODEL
=====================================================================
56
*********************************************************************
TACS Device 63 Instantaneous Maximum/minimum
=====================================================================
MODEL inst_maxmin
DATA tstart {dflt:0}
tstop {dflt: 1000}
VAR in1, in2, in3, max_out, min_out
INIT max_out := 0 min_out := 0 ENDINIT
--
EXEC
-- ************************
-- note: in1, in2, in3 functions are given here as an example only
-- they are to be replaced by the user's respective functions
-- assume that the three input signals are a set of 3-ph voltages
-- at 10 Hz
in1 := sin ( 62.8 * t)
in2 := sin ( 62.8 * t - 2*pi/3)
in3 := sin ( 62.8 * t + 2*pi/3)
-- ****************************
IF t > tstart and t < tstop then
max_out := max ( in1, in2, in3)
min_out := min ( in1, in2, in3)
ENDIF
ENDEXEC
ENDMODEL
====================================================================
57
********************************************************************
TACS Device 64 Maximum/minimum tacking
====================================================================
MODEL maxmin_trak
DATA tstart {dflt:0} -- start
tstop {dflt: 1000} -- cut off
reset_value {dflt:0}
--
VAR in11, in22 -- input variables
smax -- inst. max output
smin -- inst. min output
hold -- hold signal
s1 -- sum of in11 and in22
INIT s1 := 0 smax :=0 smin :=0 hold:=0 ENDINIT
--
--
EXEC
-- ************************
-- note: in11, in22 functions are given here as an example only
-- they are to be replaced by the user's respective functions
in11:= sin ( 62.8 * t) -- 10 Hz sin
in22:= 4.0 *t
hold:= 1 * ( t mod 0.2 < 2*timestep )
-- ***********************************
s1 := SUM ( 1|in11 + 1|in22 )
--
IF t > tstart and tstop > t THEN
if hold = 0 then
if s1 >= smax then smax := s1 endif
if s1 <= smin then smin := s1 endif
endif
--
if hold = 1 then
smax := reset_value
smin := reset_value
endif
ENDIF
ENDEXEC
ENDMODEL
====================================================================
58
*********************************************************************
TACS Device 65 Accumulator - counter
=====================================================================
MODEL accum_count -- Accumulator-counter TACS Code 65
DATA tstart {dflt:0}
tstop {dflt:1000}
reset_value {dflt:0}
VAR inc1, inc2 -- assumed input
hold -- hold signal
count -- output
HISTORY count { dflt :0}
INIT count:=0 ENDINIT
--
EXEC
-- ************************
-- note: inc1, inc2 functions are given here as an example only
-- they are to be replaced by the user's respective functions
inc1 := sin (628 * t)
inc2 := exp (2*t)
hold:= 1 * ( t mod 0.2 < 2*timestep )
-- ***********************************
IF t > tstart and t < tstop then
if hold = 0 then
count := (inc1 + inc2 ) + delay(count,timestep) endif
if hold=1 then count := reset_value endif
ENDIF
ENDEXEC
ENDMODEL
59
********************************************************************
TACS Device 66 R.M.S. Value Calculator
=====================================================================
MODEL rms
-- calculates the rms value of a function for a specified
frequency
-- Warning! the perod time must be a near exact multiple of the
-- timestep used, otherwise a cumulative round-off error occurs.
-- e.g 0.000166 for a 60 Hz signal
DATA tstart{dflt:0} -- start metering
tstop {dflt:1000} -- cut-off
freq {dflt:50} -- frequency
--
VAR volt -- example only 60 Hz sinusoidal
voltrms -- rms value of volt
tper -- period time
tt -- multiplier
omega -- 2 pi f
--
HISTORY volt {dflt:0}
DELAY CELLS (volt): 1000
--
INIT tper:= 1/freq, tt := timestep/tper
tper := 1/freq
tt := timestep/tper
omega := 2*pi*freq
voltrms :=0
ENDINIT
-- note: volt assd track functions are given here as an example only
-- they are to be replaced by the user's respective functions
--
EXEC
if t>tstart and tstop > t then
volt := 141 * sin ( omega * t )
voltrms:= sqrt(voltrms**2 + tt*(volt**2 - delay(volt, tper)**2))
endif
ENDEXEC
ENDMODEL
====================================================================
60