Professional Documents
Culture Documents
Version No. 1
For First Time MODELS Users
By
Gabor Furst
Reviewed by:
Laurent Dube
Bruno Ceresoli
Dr. Kurt Fehrle
Dr. Sayeed Ghani
1.
INTRODUCTION.......................................................
2.
3.
4.
FORMAT, SYNATAX...................................................
4.1 Format........................................................
4.2 Numbers, Variables, Arrays....................................
4.2.1
Numbers.............................................
4.2.2
Variables ..........................................
4.2.3
Arrays
..........................................
4.3 Delimiters....................................................
4.4 Blank Lines...................................................
4.5
Other Syntax Conventions.....................................
4.5.1
The Equal Sign......................................
4.5.2
The Use of Brackets.................................
5.
MODELS IN ATP......................................................
5.1 INPUT's.......................................................
5.2 OUTPUT's......................................................
6.
MORE
6.1
6.2
6.3
6.4
7.
INIT -
8.
EXPRESSIONS, FUNCTIONS.............................................
8.1 Numerical and Logical Expressions.............................
8.2 Numerical Functions...........................................
8.2.1 Resident functions.....................................
8.2.2 Statement functions (User defined)......................
8.3 Pointlist Functions...........................................
8.4 Simulation Expressions and Functions........................
ABOUT DECLARATIONS............................................
DATA and CONST................................................
INPUT and OUTPUT..............................................
VAR ( Variables ).............................................
HISTORY and DELAY CELLS.......................................
Initialization
Procedure..................................
8.5
9.
ALGORITHM CONTROL..................................................
9.1 The IF - ENDIF Statement.....................................
9.2 DO - REDO.....................................................
9.3 WHILE - DO - ENDWHILE.........................................
9.4 FOR - DO - ENDFOR.............................................
9.5 COMBINE.......................................................
9.6 TIMESTEP......................................................
10.
RECORD - Write.....................................................
10.1 RECORD ......................................................
10.2 Write.........................................................
11.
Multiple MODEL's...................................................
12.
13.
Testing - Debugging................................................ 48
APPENDIX................................................................
MODELS Versions of TACS Sources and Devices........................
A1. MODELS Equivalents of TACS and EMTP Sources...................
A2. MODELS Equivalents of TACS Devices............................
1.
INTRODUCTION
The objective of this Primer is to help first time MODELS users to
familiarize themselves with the rules and techniques of MODELS, for
the development of data files for ATP-EMTP related studies.
The
Primer is not a substitute to the MODELS Manual prepared by laurent
Dube.
It is simply an aid to help overcome some of the initial
hurdles common to new languages and software. The user is advised to
skim through the Manual before using this Primer. This will give a
familiarity
of the general principles underlying the MODELS
language. A more in-depth study of the Manual, however, will only be
required after having completed the study of this Primer.
It is
assumed that the reader is fully familiar with ATP-EMTP.
All readers of this Primer are invited to make their comments on
errors, ommissions, and whatever suggestions they may have to imrove
the next edition of the Primer.
2.
3.
MODELS GROUPS
The following is only applicable to MODELS used as part of an
ATP-EMTP data file.
The MODELS section of the ATP data file must have at least
three major MODELS groups of code, each introduced by a
keyword, much like the keywords or Request Words in EMTP. The
three groups are headed by MODELS, MODEL and USE. The keyword
MODELS starts the MODELS part of the ATP data file. The MODEL
and USE groups are terminated by ENDMODEL and ENDUSE
respectively. After ENDUSE, an optional fourth group headed by
the keyword RECORD can be inserted for the disk output and
plotting of variables. The MODELS part of the ATP data file is
terminated
by the keyword ENDMODELS.
MODELS is inserted in
the ATP file exactly the same way as in TACS, following the
miscellaneous data lines.
Thus the main structure of MODELS
is:
BEGIN NEW DATA CASE
...
.... misc. data lines
MODELS
..... coding
MODEL
......coding
............
............
ENDMODEL
USE
......coding
ENDUSE
RECORD
.... coding
ENDMODELS
C ....
... EMTP data file mandatory
The two main groups in MODELS are MODEL and USE. These groups
are divided into sections headed by keywords referred to as
DECLARATIONS, DIRECTIVES and PROCEDURES.
While in the
general
structure
of
MODELS
there
can
be
several
Figure 1
MODELS
Structure
3.2
30 ms.
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 is the declaration for the second section in this MODEL.
The data entered here is a fixed constant in the model, and
cannot be changed in the USE group. In Example 1/M the entry
is:
CONST
kt{val: 0.05}
kgain { val:2.0}
where kgain is the gain in the first control block transfer
function, and kt is the coefficient of the s term in the
denominator.
VAR
is the declaration for the next section in this MODEL.
This section serves to declare all variables used in the MODEL
group, except those declared under INPUT, DATA and CONST.
Unlike TACS, MODELS does not automatically identify the
variables used, and omission of entering it under VAR or the
other directive listed, will result in KILL.
In Example 1/M
the following variables are declared
VAR vin, vout, vdel, tcount, dela
where
HISTORY
is the directive for the next section.
A number of
the simulation functions require the knowledge of the past
history of the variables involved.
An obvious example is the
delay of a signal. In Example 1, the input and output variables
of the Laplace transform and the signal delay function require
keeping track of past time values. Therefore, history is
required for the following variables::
10
HISTORY
vin {dflt: 0}
vout {dflt: 0}
vdel {dflt: 0}
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 :
DELAY CELLS DFLT: 10
CELLS (vout) : 100
CELLS (vdel) : 100
INIT is procedure for the initialization section, terminated by
the keyword ENDINIT. All variables used in the EXEC section of
MODEL have to be initialized., except data, history variables,
constants and inputs.
MODELS cannot be relied on to
initialize, not even to zero. No initialization of a variable
can produce incorrect results. In addition to initialization,
the INIT section also allows the user to define constants in
terms of the constants entered or defined in the DATA and CONST
sections. The first time
MODELS user may initialize all variables used in EXEC, except
the ones entered in DATA and CONST, to avoid any potential
errors. 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.
Example 1/M illustrates a simple control system consisting of
two blocks in series. The first block is kgain/( 1+kts) with
an input 'vin' and output 'vout'. The output vout of the first
block is fed through a delay of 10 ms, giving a final output of
'vdel'.
The input vin is a pulse train of amplitude 100.0, starting at
t = 20 ms, a period time of 50 ms and a pulse ON time of 30 ms.
The first control block id described by MODELS' Laplace
function:
11
12
3.5
The User is encouraged to copy the files Example 1/M and 1/T run them
on ABS and use TPPL to plot the results.
13
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
14
ENDMODEL
15
16
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
17
4. FORMAT, SYNATAX
The MODELS Manual uses terminology and some syntax which may not be familiar to engineers not
conversed in the programming languages MODELS is based on. The Primer will attempt to point out
some of the conventions and syntax for the benefit of the first time MODELS user.
4.1
Format
The syntax of MODELS allows free-style formatting. None of the keywords, declarations or
statements have to be typed in certain columns, like in TACS. The entries are not case sensitive,
but it is a good idea to enter keywords, e.g MODEL, INPUT, VAR, USE etc. in upper case to
emphasize the structure of the file for ease of reading and editing. The only restriction is that
blank lines are not allowed, they will be rejected by ATP. The user can, however put in quasiblank lines with a "C" in column 1. See further comments on BLANK lines in Chapter 4.3
There are three ways to enter comment lines:
type "C" in the first column followed by a blank
-
type "--" anywhere on the line followed by the comment; note that the CR/LF will terminate
the comment
by entering a COMMENT keyword followed by the comment, which, in this case can be
several lines long. The keyword ENDCOMMENTS will terminate the COMMENT section
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
18
4.2
Numbers
Variables
Arrays
y[1..3]
y[1..n]
19
20
4.3
Delimiters
The MODELS language uses blank spaces, commas, semicolons,
carriage returns and line feeds as delimiters or separators.
The only exception is the carriage return/line feed following
a comment introduced by the symbol "--".
Examples:
The declaration of variables used in MODEL is in the VAR
section and can be typed as:
VAR
a
x1
b[1..3]
VAR
a, x1, b[1..3]
VAR
or
or
x1
b[1..3]
y{dflt:0}
x{dflt:sin(omega*t)}
y{dflt:0}
x{dflt:sin(omega*t)}
Blank Lines
It follows from the use of delimiters in MODELS that the
MODELS ignores blank lines. As ATP users are aware of, the
default version of the STARTUP file distributed, does not
allows blank lines only in places where these lines serve as
the terminators of data sections.
This can be overridden by
the NOBLAN entry in the STARTUP file. For the first time
MODELS and not experienced ATP user, it is not recommended to
do this. It can lead to users' errors in the EMTP section of
the file. It is much easier not use blank lines in MODELS, or
if from a layout point of view such lines are desirable, type
"C" in column 1. If the NOBLAN option is not used, blank lines
must be removed or C entered in the example files distributed
with the MODELS manual.
21
22
4.5
23
a [1..3] := [ 1, 2, 3] meaning
a[1], a[2], a[3] equal to 1,2,3 respectively
24
defining limits or
DATA
xf { dflt :1.0 }
HISTORY xy { dflt : sin ( omega * t) }
y := sum ( c4| -t|a + t|b ) { min -0.5 max +1.0 }
See also Chapter 5.0
5.
MODELS IN ATP
The model in Example 1 had no connection to EMTP. The only
connection of Model_1 to the outside was the definition of the
transfer function parameters in the DATA declaration in the USE
group.
Example 2/M demonstrates how MODELS is connected to EMTP.
The
network shown in the EMTP part of Example 2 is a 50 Hz a.c. source
GENA connected to BUSA, a measuring switch from BUSA to BUSB, a
full wave thyristor switch between BUSB and BUSC and a 100 MW 10
MAVAR load represented by a r +jx branch between BUSC and ground.
MODEL has the name model_2, is required to do two things. To
connect the load to the source through firing the thyristors at
time = 50 ms, and then calculate the active power absorbed by the
resistor. Recall that the type 4 output in EMTP provides only the
instantaneous value of the apparent power S = iv.
Model_2 determines the active power flow through the measuring
switch between BUSA and BUSB. The variables to be passed from EMTP
to model_2 are the BUSA voltage and the current from BUSA to BUSB.
MODELS requires three steps to accomplish this.
5.1
INPUT's
a)
b)
25
INPUT
c)
5.2
vv {dflt: 0}
ii {dflt: 0}
vv:= volt
ii:= cur
OUTPUT's
b)
c)
In the USE group it is stated that 'aa' will have the name
FIRE to pass on to another MODEL or to EMTP.
26
27
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
28
29
30
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
31
6.
to Directives and
MODELS.
Some further
and declarations will be
the user should refer to
32
=
=
=
=
3.14...
0, true =
0, yes =
0, closed
0, on
1
1
= 1
= 1
33
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.
Use of the OUTPUT declaration was demonstrated earlier in
this Chapter for passing output from model_2 to EMTP. In
the example below it is assumed that variables 'fia' and
'fib' generated in model 'John' are passed to another
model 'Mary' under the name 'ftxa' and 'ftxb'. MMODEL
'Mary' uses these variables under the MODEL name ff1 and
ff2 in Mary.
The two models are used in the same MODELS
34
file.
35
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
It must be noted that the variables appearing in the INPUT and
OUTPUT directives in any MODEL group in a MODELS file, must
also be repeated in the section following the MODELS keyword
and the first MODEL group as shown later in Chapter 11.
6.3
VAR ( Variables )
MODELS require that all variables be declared once, but not
more than once. No declaration, or declaration of a variable
more than once will result in a KILL. Variables can be
declared in the DATA, CONST and INPUT declarations. Variables
used in MODEL, but not declared in these sections must be
entered in the VAR declaration. The variables declared in an
OUTPUT statement as generated inside the MODEL must be
declared under VAR. The name of the output variables as used
in passing them to another MODEL or externally, are not to be
declared under VAR. The syntax of the VAR declaration is as
shown in the following example::
VAR
y, x, a[1..3], ba[1..n]
36
37
6.4
38
39
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
histdef (y) := sin(omega*t)
histdef (x) := 0
40
DELAY CELLS
Hand in hand with the history declaration goes the declaration
of DELAY CELLS. In TACS the assignment of cells for past
history is internal to ATP as long as the size of TACS tables
are not exceeded, in which case a KILL tells the user what to
do. In MODELS, the user has to tell ATP how many MODELS
memory cells are required. This requirement is governed by
the maximum delay specified in whatever delay function is used
in the MODEL, typically y:= delay (x,td), where td is delay in
seconds. For example: y:= delay(x, 0.03) means that the
value of x is requested at a time 30 ms behind the current
simulation time, or y = x(t-td).
The number of memory cells
MODELS has to put aside for the simulation is then 30 ms
divided by the time step used in the simulation. If the time
step is 0.1 ms, then in the above example the number of delay
cells required is 300. Delay cells can be requested
individually for a variable, or globally by a default
declaration for all variables for which delay cells are
required. Alternative forms of declaration are
DELAY CELLS DEFAULT: 10
or
DELAY CELLS y: 200
CELLS x: 100
or
DELAY CELLS DEFAULT :2
CELLS y: tper/timestep
CELLS x: 300
Note that the default value specified applies to all variables
which require delay cells, but for which no specific number of
cells is entered.
7.
INIT -
Initialization
Procedure
41
42
For example:
INIT
y1 := 0
x1:= 5
Z := omega*t
histdef(uv) := 3*t
ENDINIT
In the above example the value of 'omega' was declared either under
DATA or CONST.
8.
EXPRESSIONS, FUNCTIONS
The following type of functions are used i MODEL
-
43
44
a > b
a > b or c < a
Numerical Functions
Numerical functions in MODELS, as expressions, are much the
same as numerical functions in Fortran or Basic.
45
8.2.1
Resident functions
46
8.3
Pointlist Functions
The user can define an y=f(x) function by entering a
tabulation of y and x in increasing order of x. The syntax
is:
FUNCTION name POINTLIST
(x1, y1)
(x2, y2)
......
(xn, ynn)
the pointlist function can than be used as:
z:= name ( xi, pol )
'pol' provides the mode of interpolation between the x values.
pol=0, 1, 2 will supply the value of y as discontinuous,
linear or quadratic interpolation. Omitting pol will give
linear interpolation as default.
The following example is the normalized relation between
firing angle delay and current through a thyristor, giving
only five points on the curve:
--
47
8.4
Simulation Expressions
and
Functions
DERIVATIVE Expression
with Linear Polynomial
This is described in Chapter 2.9.4 of the Manual.
used by advanced MODELS users.
DIFFEQ
Differential Equation
It will be
DERIVATIVE Function
dmin:b }
where
x is a variable
dmax and dmin are dynamic limits
The syntax of the second
y := DERIV2 ( x ) { max:a
min:b }
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
8.4.2
INTEGRAL Function
dmin:b }
is a variable
48
49
be calculated
MODEL test
VAR a, x, y
HISTORY x {dflt :0}
integral (x) { dflt :0 }
-EXEC
x := a*t
y := integral (x) { dmax: 50
ENDEXEC
ENDMODEL
dmin: 10 }
50
...... ) {max:5
min: -1}
Example:
Evaluate the polynomial k = a + bx + cx2
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
Note that what is done by the SUM expression can be done
without it by simply writing a numerical expression statement.
The reason for the SUM expression is that it can be used
inside a COMBINE group for the simultaneous solution of
statements.
8.5
Simulation
8.5.1
Expressions
Resident
Simulation Expressions
51
52
histdef ( x )
process
53
where:
x = input variable
y = output
k0...l0.. are constant coefficients
s0, s1, s2, s3 symbolize the s operator to the n'th
power
The Laplace function can be used with both static and dynamic
limits. With static limits the output is clipped, with
dynamic limits the output is limited by the process of
evaluating the function. See Chapter 2.3.13 in the Manual.
The syntax of applying the limits is:
For static limits: CLAPLACE (y/x) {max: u min: l } := ...
For dynamic limits: CLAPLACE (y/x) {dmax: u dmin: l } := ...
Both y and x must be declared in a history declaration. In
most cases it will be sufficient to enter the history with
dflt:0
Example 1/M shows a simple Laplace function. The LAPLACE
version was used there but based on the above discussions, the
CLAPLACE would be preferred as the coefficients of the
function ate constant throughout the simulation. Results will
be the same, but solution is faster with CLAPLACE.
The following example illustrates part of a control system.
The input signal to the first block is the sum of a reference
signal 'sref', a signal 'sin', and a derivative feedback
signal 'sfeed', taken from the output signal 'sed'. The
output signal 'sout' is clipped to +/- 0.05.
The transfer function for the forward block is :
kgain/(1+ tes )
The transfer function for the feedback is:
kfds/(1 + tfds)
54
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
Note that for the 'correct' evaluation of a
feedback, the COMBINE option has to be used as
explained in the next Chapter.
55
9. ALGORITHM CONTROL
MODELS uses algorithm control statements similar to those used in other
programming languages, like Fortran and Basic.
The following algorithm controls are
-
IF ....
FOR ....
DO ---WHILE -REDO
SEQUENCE
COMBINE
possible:
ENDIF
ENDFOR
ENDDO
ENDWHILE
Only the first three will be described here. The last three control
statements are described in the Manual, see Chapters 2.3.2.5,
2.3.2.6 and 2.3.2.7.
9.1
The IF -
ENDIF Statement
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
56
9.2
DO - REDO
The DO statement instructs MODELS to execute a set of instructions
between the DO and the terminating ENDDO. If any looping is
required inside DO, it can be done by a REDO statement or
directive.
REDO, subject to a logical expression satisfied,
will restart the execution of instructions after DO and before
REDO.
Example:
EXEC
DO
write ( 'start/restart
write ( ' k = ',k )
k := k - 1
IF k > 0 REDO ENDIF
x := 10
write ( ' x = ',x )
ENDDO
ENDEXEC
9.3
DO ' )
WHILE - DO - ENDWHILE
The WHILE statement instruct MODELS to execute the instruction
after WHILE and before ENDWHILE subject to a logical expression
being satisfied.
Example:
EXEC
VAR
k
WHILE k > 0 DO
k := k-1
write ( ' k =
ENDWHILE
ENDEXEC
9.4
',k )
FOR - DO - ENDFOR
FOR allows the repetition of a set of instructions controlled by
a monotonously increasing or decreasing index, in defined steps,
and where the range of the index is defined by a i TO k
expression. This is similar to the FOR - NEXT loop in BASIC.
57
58
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
59
Example 3 Continued
-------------------------------------------------------------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
60
9.5
COMBINE
As in TACS, MODELS will execute the instuction in the EXEC
section in the sequence entered. In many control system
applications it is desirable for greater accuracy, to execute
some of the statements, or control blocks, concurrently. A
typical example would be a feedback control loop. COMBINE ENDCOMBINE provides the means within MODELS to do this. The
syntax is
COMBINE AS groupx
statements
ENDCOMBINE
The significance of 'groupx' is to allow more than one COMBINE
section in one MODEL. The following simple example is the same
as shown in Chapter 8.5 but with the use of COMBINE. Only the
EXEC section is repeated here.
EXEC
COMBINE AS group1
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 )
-ENDCOMBINE
sout := sed {max: 0.05 min: -0.05 }
ENDEXEC
For a better understanding of COMBINE applications in general, the
user should consult Chapter 2.3.2.6 of the Manual.
9.6
TIMESTEP
MODELS allows the user to have an execution time step in MODELS
different from that in EMTP. The directive TIMESTEP can be
entered either in the MODEL group, or in the USE group. The
syntax is
TIMESTEP max:xx min:yy
e.g. TIMESTEP max: 0.001
TIMESTEP min: 0.002
61
62
10.
RECORD - Write
10.1 RECORD
The RECORD statement is placed at the end of the MODELS file as the
last group in MODELS, following the USE groups. The RECORD
request word is followed by the request of variables to be output
in the form of:
modelname.varnamex
AS
outnam
any text
63
11.
Multiple MODEL's
For example:
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.
The power model is as follows:
-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
64
65
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.
66
Example 4
BEGIN NEW DATA CASE
$CLOSE, UNIT=4 STATUS=DELETE
$OPEN, UNIT=4 FILE=mod_4.pl4 FORM=UNFORMATTED STATUS=UNKNOWN
RECL=8000 !
PRINTED NUMBER WIDTH, 13, 2,
C deltat
tmax
xopt
copt epsiln tolmat tstart
.0001
.100
50.
0.0
C print points connec
s-s minmax
vary
again
plot
1
1
0
0
0
0
0
1
MODELS
INPUT volt {v(BUSA)}
cur
{i(BUSB)}
OUTPUT freq, tper, tmult, vv, ii
MODEL model_3
DATA freq {dflt: 0}
-VAR
tmult, tper
INPUT vv {dflt: 0}
ii {dflt: 0}
OUTPUT freq, tper, tmult
vv, ii
HISTORY vv {dflt: 0} ii {dflt:0}
INIT
tper := 1/freq
tmult := tper/timestep
ENDINIT
-EXEC
ENDEXEC
ENDMODEL
-USE model_3 AS test
DATA freq := 50
INPUT
vv:= volt ii := cur
OUTPUT freq:= freq, tpe := tper, tmult : tmult
vv := vv, ii := ii
ENDUSE
-REACTIVE
MODEL
$INCLUDE reactive.dat
USE reactive AS reactive
INPUT
vv := vv, ii := ii, freq := freq, tper := tper, tmult := tmult
ENDUSE
-POWER
$INCLUDE power.dat
67
USE power
AS power
INPUT
vv:= vv, ii:= ii
tper := tper, tmult := tmult,
ENDUSE
freq := freq
68
Example 4 Continued
---------------------------------------------------------------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
69
APPENDIX
MODELS Versions of TACS Sources and Devices
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.
The user is advised to study the Primer before attempting to use these
models.
70
A1.
List of Sources:
TACS
TACS
TACS
TACS
EMTP
EMTP
Code
Code
Code
Code
Type
Type
11
14
23
24
13
15
-------
71
***************************************************************
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
================================================================
72
****************************************************************
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
================================================================
73
*******************************************************************
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
===================================================================
*******************************************************************
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
===================================================================
74
A2.
List of Devices:
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
TACS
Device
Device
Device
Device
Device
Device
Device
Device
Device
Device
Device
Device
Device
Device
Device
50
51/52
53/54
55
56
57
58
59
60
61
62
63
64
65
66
----------------
Frequency Meter
Relay Switch
Transport and Pulse Delay
Digitizer
Point by Point Nonlinearity
Time Sequenced Switch
ControlledIntegrator
Single Derivative
Input IF Component
Signal Selector
Sample and Track
Inst. Maximum/minimum
Maximum/minimum Tracking
Accumulator - Counter
R.M.S. Value
75
*******************************************************************
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
=====================================================================
76
*********************************************************************
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
========================================================================
=
77
************************************************************************
*
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
========================================================================
==
************************************************************************
***
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 ,)
78
(
(
(
(
(
6.0,
7.0,
8.0,
10.0,
20.0,
1.1
1.15
1.2
1.25
1.4
)
)
)
)
)
79
---
==================================================================
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
=====================================================================
80
*********************************************************************
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
=====================================================================
*********************************************************************
TACS Device 61 Signal selecttor
--Covered by the algorithm control statements
-in the MODELS language - see Manual Chapter 2.3.2
=====================================================================
81
*********************************************************************
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
======================================================================
82
*********************************************************************
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
====================================================================
83
********************************************************************
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
====================================================================
84
*********************************************************************
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
85
************************************************************************
*
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
========================================================================
86
87