0% found this document useful (0 votes)
126 views

Models Primer 2003

This document provides an introduction and primer for first time users of MODELS, a language for describing time-variant systems to be used with ATP-EMTP. It outlines the main groups and structure of MODELS files, which must include at minimum a MODELS group containing the coding, a MODEL group containing declarations and directives, and a USE group containing the coding. It may optionally include a RECORD group for outputting variables. The MODEL and USE groups contain sections headed by keywords for declarations, directives, and procedures. The primer is intended to help users familiarize themselves with the basic rules and coding structure of MODELS files.

Uploaded by

Alberto Jimenez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views

Models Primer 2003

This document provides an introduction and primer for first time users of MODELS, a language for describing time-variant systems to be used with ATP-EMTP. It outlines the main groups and structure of MODELS files, which must include at minimum a MODELS group containing the coding, a MODEL group containing declarations and directives, and a USE group containing the coding. It may optionally include a RECORD group for outputting variables. The MODEL and USE groups contain sections headed by keywords for declarations, directives, and procedures. The primer is intended to help users familiarize themselves with the basic rules and coding structure of MODELS files.

Uploaded by

Alberto Jimenez
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

MODELS PRIMER

For First Time MODELS Users

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

2. THE NATURE AND STRUCTURE OF THE MODELS LANGUAGE . . 1

3. THE MAIN GROUPS IN MODELS . . . . . . . . . . . . . 2


3.1 MODELS GROUPS . . . . . . . . . . . . . . . . . 2
3.2 Overview of the MODELS File Structure . . . . . 5
3.3 The MODEL - Group . . . . . . . . . . . . . . . 6
3.4 USE and RECORD in Example 1/M . . . . . . . . . 9
3.5 An Equivalent TACS File . . . . . . . . . . . . 9

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

6. MORE ABOUT DECLARATIONS . . . . . . . . . . . . . . 21


6.1 DATA and CONST . . . . . . . . . . . . . . . . 21
6.2 INPUT and OUTPUT . . . . . . . . . . . . . . . 22
6.3 VAR ( Variables ) . . . . . . . . . . . . . . . 24
6.4 HISTORY and DELAY CELLS . . . . . . . . . . . . 25

7. INIT - Initialization Procedure . . . . . . . . . 27

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

10. RECORD - Write . . . . . . . . . . . . . . . . . . . 43


10.1 RECORD . . . . . . . . . . . . . . . . . . . 43
10.2 Write . . . . . . . . . . . . . . . . . . . . . 43

11. Multiple MODEL's . . . . . . . . . . . . . . . . . . 44


12. Features Not Covered In the Primer . . . . . . . . . 45

13. Testing - Debugging . . . . . . . . . . . . . . . . 46

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

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. THE NATURE AND STRUCTURE OF THE MODELS LANGUAGE

For an in-depth description of the MODELS language refer


to Chapter 1. of the MODELS Manual. A brief extract is
given below:

MODELS is a general purpose description language supported


by a set of simulation tools for the study of time-variant
systems". This simply means that a MODELS file is easily
readable like some of the high level programming
languages. The coding of a file is at the same time the
description of the model which can be followed without
explanation of the coding, which would be necessary for
reading a TACS file by persons not intimately familiar
with the TACS code.

MODELS is a structured language, requiring the coding to


be prepared according to a strict rule of groupings of the
type of blocks in the file. This will become clear from
the examples in the Primer. While the reference to
'structured' language may sound somewhat 'prohibitive' to
some new users of MODELS, it is probably the easiest
aspect of MODELS to become familiar with.

MODELS files are coded in an entirely free format, which


enables the user to enhance the readability of the file.
Keywords, declarations, directives, function names are
such that a user with a minimal knowledge of any
programming language can identify the meaning of
statements. For details of the formatting rules see
Chapter 4.

1
3. THE MAIN GROUPS IN MODELS

3.1 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 MODEL-ENDMODEL-USE-ENDUSE
groups as discussed in Chapter 11.

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

In the above illustration the capitalized words DATA,


CONST, etc. are the directives, declarations and
procedure (EXEC) , followed by entries as discussed
later in this Primer. Note that some of the sections
are terminated by an END keyword, some are not. Not
all the available directives and declarations of
MODELS have to be used in a specific MODEL, nor is
the sequence of their entry important. The exception
is the EXEX section which should come last, although
the Manual does not specify this as a requirements.
The above listing also shows one way of entering
comments in MODELS. The symbol '--' , anywhere on the
line , is followed by the comment.

A graphical, block diagram presentation of the MODELS


structure is shown in Figure 1 with the input-output
linkages between EMTP and MODELS and the various
MODEL's within MODELS.

3
Figure 1

MODELS Structure

4
3.2 Overview of the MODELS File Structure

Before elaborating on the rules and procedures used


in developing a MODELS file, a brief example is given
of a relatively simple MODELS file, as an
introduction to MODELS. Example 1/M illustrates a
simple control problem solved in MODELS. A train of
pulses is the input to a k/(1 + Ts) type transfer
block. The output of this block is put through a
delay of t ms. The example has no connection with
the EMTP network, no EMTP inputs or outputs are
required. It is, however, mandatory, as noted above,
to enter an EMTP network segment, which, in the
example is a simple one bus 'dummy network'. Without
this, MODELS will not run.

The request word MODELS after the miscellaneous data


entries signals to ATP that MODELS will be used as
part of the data file, the same way as TACS or TACS
HYBRID introduces the TACS part of the data file.
There is no entry in the first group after MODELS.
The section between the keywords MODELS and MODEL
would normally be used to specify inputs and outputs
from an external source, usually from the EMTP
network, and inputs and outputs between MODEL's.

The second group is introduced by the keyword MODEL


followed by the name given to the model, which is
model_1. This is the main part of MODELS where the
all the history declarations, initialization, data
processing and the execution of the model simulation
takes place. This group is terminated by the keyword
ENDMODEL. As noted above , in Example 1/M, the model
to be simulated is a simple transfer function block
kgain/(1+kts) to which the input is a train of pulses
'vin'. The output of the block, 'vout', is fed
through a delay of 10 ms to get the final output
signal 'vdel'. This simple example contains a few
important elements of the model which will be
discussed below. But first,the two remaining groups
of MODELS will be briefly described.

The next group in models starts with the keyword USE


and terminates with the keyword ENDUSE. This group
performs the task of liaison between MODEL and the
user or what is using the MODEL. In USE the user can
specify the inputs and outputs to the MODEL and can
override certain declarations which are inside MODEL.
In the USE of Example 1/M, the MODEL is given a name
'test' for this run, and there is a DATA declaration
in USE to tell MODEL what values to use for the
variables 'tperiod' and 'ton'. The rules require
to have at least one entry in USE, which can be a
'dummy statement' TIMESTEP MIN:0, used in the Manual
examples.

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.

MODELS, as it can be seen see from the above summary,


is a highly structured language, allowing several
MODEL groups in MODELS, and several USE groups to
tell MODELS how to use them. This may sound somewhat
complicated, but there is no need to be concerned
with this at this stage of learning. As noted above,
for the time being, only one MODEL and one USE group
will be used. Multiple MODEL's will be discussed in
Chapter 11.
3.3 The MODEL - Group

The MODEL group in Example 1/M shows a simple


simulation illustrating some of the frequently used
elements of MODEL. This a brief introduction only,
to get a feel for what is happening inside the MODEL.
The various sections will be described in more
detail in Chapter 6.

As noted above, this model is the simulation of a


transfer function kgain/(1+kts), with the output
through a 10 ms delay.

The name of this MODEL is 'model_1'. This is the


name by which the Model will be called from another
MODEL or referred to, outside the MODEL, in the USE
or RECORD group.

DATA is the declaration for the first section is this


MODEL. The data entered here enables the user to
assign values to elements. This values can be over-
written in the group USE, without having to change
the MODEL. In example 1/M the data entered is:

DATA
tperiod { dflt: 0.0 }
ton { dflt: 0.0 }

where tperiod and ton are the parameters of the


impulse train, 'vin', input to the first block in the
model. Note that these parameters are over-written
under the DATA directive in the USE group with the
actual values to be used, tperiod 50 ms and ton 30
ms.

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 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 vin is the input signal


vout is the output from the first block
vdel is the delayed output
dela is the time delay in the delay block
tcount is the counter for generating the
input signal pulse train

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:

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
:

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:

laplace (vout/vin) := kgain|s0/(1|s0 + kt|s1)

8
The second block which is a simple delay is entered
as:

vdel := delay(vout, dela)


where the variable 'dela' is set to 10 ms
in the INIT section

The use of an IF block for the generation of the


pulse of train 'vin' is explained in the Example.
The example also shows a simpler generation of a
pulse train by a logical expression.

The available MODELS statements to develop a


simulation algorithm, their use and syntax will be
discussed in Chapter 6.

3.4 USE and RECORD in Example 1/M

The USE group in Example 1/M states that the model


'model_1' is used in the context of this data file
under the name 'test'. The DATA section in the USE
group, specifies the period of the pulse train as
50 ms, the length of the signal on time, ton, as
30 ms and the start time as 20 ms. This
specification overrides the zero default values in
the MODEL group.

The RECORD group in example 1/M specifies 'vin',


'vout' and 'vdel' as three variables in MODEL 'test'
for output.

3.5 An Equivalent TACS File


For those familiar with TACS Example 1/T shows the
TACS portion of the ATP file, for the simulation of
the same control blocks as in Example 1/M. It would
be too early at this point to draw conclusions from
the comparison of the two files. This will be done
in Chapter X. As a very rough comparison, however,
it could be said, that TACS is a coded interface
between a program and the user, while MODELS is the
program itself.

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.

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

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 quasi-
blank 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

The following will illustrate the entering of


comments.

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

A number (numerical value) has to be a string of


decimal digits, with a leading plus or minus sign,
decimal point where required. The first character of
the number must be a digit. For scientific notation,
this numerical value is followed without a space by
the letter E and a signed integer. The following
examples will clarify this.

- Numbers allowed:
12, -3, 0.95, -12.44, -0.4
0.3E-1, -3.6E+9, 4E9, 3.E-04

note that a number with a leading decimal point


.4 is not allowed

4.2.2 Variables

Variables are referred by their names. Names are to


be typed as a string of contiguous characters. The
first character of a name MUST NOT be a digit. Any
character other than a letter, digit, or underscore,
is interpreted as the end of the name. A name can be
of any length, it is not limited to 6 characters as
in EMTP. When passing names to EMTP or for plotting
via the RECORDS group, the six character limitation
applies.

- Names allowed:

John
John_and_Mary
test_example
etc.

4.2.3 Arrays

Array variables are referred to by the array name,


followed by the array range in square brackets.
Examples:

y[3] the third element of an array

y[1..3] an array with three elements

y[1..n] an array with n elements

13
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]
or
VAR a, x1, b[1..3]
or
VAR a x1 b[1..3]

The HISTORY declaration of variables can be typed as:

HISTORY y{dflt:0}
x{dflt:sin(omega*t)}
or
HISTORY y{dflt:0} x{dflt:sin(omega*t)}

While blank spaces are allowed as separators


(delimiters) as shown above, their use is not
recommended as it can easily lead to typing errors
which are not easy to detect.

4.4 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.

14
4.5 Other Syntax Conventions

4.5.1 The Equal Sign

The MODELS language discriminates between equal sign


and assignment sign, which could be confusing for
users with Fortran or Basic background. The
assignment symbol used in MODELS is " : ", used for
example in DATA or HISTORY declarations, the assign
a value and make a variable equal to is " := ", and
the test for equality used in logical expressions is
" = ". For example:

DATA kx {dflt: 1.1}


k2 := 20
IF a =30 THEN etc

4.5.2 The Use of Brackets

Three types of brackets are used in MODELS. The


round bracket (), the square bracket [], and the
braces {}.
Round brackets () are used in MODELS the same way as
round brackets are commonly used in mathematics.
MODELS uses round brackets in logical and numerical
expressions, function arguments etc., but not for
denoting indices or ranges of arrays. For example:

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:

histdef ( x ) : cos ( omega * t)

Such exceptions will be noted when discussing the


directives and declarations.

Square brackets [ ] are used for arrays only, to


denote an element or range of elements of arrays.
E.g.

a [1..3] := 3.0 meaning that all elements of 'a'


are equal to 3.0

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:

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) Following the request word MODELS, it stated that


the EMTP voltage BUSA is used as 'volt', and the EMTP
current measured through the measuring switch BUSA-
BUSB at BUSB will be used as the variable 'cur'
INPUT volt {v(BUSA)}
cur {i(BUSB)}

b) MODEL has to be told that which of the variables used


in model_2 are input from outside model_2. This is
done by the INPUT directive ( or declaration) in
MODEL by entering

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

In Example 2 an output from model__2 is required to fire


the thyristors in EMTP. The model_2 variable to do this
is 'aa'. As for the inputs into MODEL the outputs are
declared as follows:

a) Under the request word MODELS it is declared that


FIRE will be passed to EMTP.

b) Model_2 is told that the variable 'aa' will be output


from MODEL
OUTPUT aa

c) In the USE group it is stated that 'aa' will have the


name FIRE to pass on to another MODEL or to EMTP.

Other features of Example 2

The DATA declaration has only one variable 'freq',


with the desired freq entered in USE under DATA.

Under the VAR declaration, all variables used in


MODEL are listed with the exception of the variables
declared under INPUT and DATA.

HISTORY lists vv and ii as variables for which past


history will be required in the simulation.
In the INIT section the values of tper and tmult are
defined, which are used as constants in the
simulation. In addition pavg and aa are initialized
to zero.

The DELAY CELLS declaration specifies the required


memory cells for past history values.

The simulation in the EXEC section is explained by


the coding itself. The active power is updated at
each time step by adding (1/period)(u.i) to the
current value of power and subtracting the same
product of t-tperiod. The signal to fire the
thyristors in EMTP is generated by a simple IF block.

Example 2/T shows the TACS version of Example 2/M.

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

In Chapter 3, an introduction was given to Directives and


Declarations used in the MODEL group of MODELS. Some
further comments on the use of these directives and
declarations will be given below, but as noted in Chapter
1, the user should refer to the MODLELS Manual complete
guide.

6.1 DATA and CONST 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}}

In the above, pi is a resident constant 3.14...


.
If the user wishes to use the model at different
frequencies, he can do it by entering:

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

The syntax for entering a constant under CONST


is:

CONST k1 {val : 50}


or
CONST id {val : pi*20.3}
or for an array
CONST
a[1..3] {val: [ 20, 30, 40 ] }

The values of a constant declared under CONST


cannot be changed from outside the MODEL. A
CONST declaration may not include a variable
declared under another declaration or outside
MODEL.

The resident constants are :

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

6.2 INPUT and OUTPUT


INPUT

INPUT signals to MODEL that the variables


declared here will be passed to MODEL from
outside MODEL, from another model or from EMTP.
The syntax is:
INPUT volt {dflt: 0}
current {dflt: 0}
or
INPUT volt
current

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.

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 file. The procedure
is:

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

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]

MODELS has a number of resident variables which are


listed in Chapter 2.4.6 of the Manual. The
frequently used ones are:

t present value of simulation time in


sec.
prevtime previous value of simulation time sec.
timestep simulation tine interval sec.
starttime starting time of the simulation sec.
stoptime end of simulation sec.

24
6.4 HISTORY and DELAY CELLS

There are some functions in MODELS, like in TACS,


which require the knowledge of the history of
variables prior to the current execution time step.
This history may be required for just one time step
as in the evaluation of most transfer functions, or
for a longer time. History is not generated by
MODELS without user's intervention as it is in TACS.
The user has to define the variables for which
history is required.

HISTORY

MODELS has three ways to request history. Under the


directive HISTORY in MODEL, under the directive
HISTORY in USE or under the history assignment
histdef in INIT in Model.
MODELS assigns a priority to these history
assignments. First the HISTORY directive in MODEL is
scanned, then the HISTORY directive in USE which
overrides the definitions in the HISTORY directive in
MODEL. Third, the histdef assignments in INIT are
examined, which override the previous two
assignments. The first time MODELS user should not
use the histdef assignment, which can cause confusion
and would rarely be required.

History must be defined for variables in delay


functions, integrals, Laplace functions, differential
equations, etc. The requirement should be obvious
from the use of a variable. Where the user may not
be clear on the requirement, history can be defined
as a precaution. If it is omitted when required,
MODELS will send a KILL message to instruct the user
to add the history definition.

HISTORY declaration in MODEL

The syntax of the history definition is:

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 {dflt: y*cos(omega*t)}


or
HISTORY y {dflt: x }
x {dflt: sin(t)}
will cause the history of y to over-written by
y.cos(omega.t) or x.sin(t) respectively. This is,
in most cases, not what the user wants to do. It is
for this reason that in the vast majority of cases
the HISTORY y {dflt:0} is the safe declaration to
use. The advanced user should study the manual for
more sophisticated applications.

HISTORY directive in USE

As noted above the HISTORY declared in MODEL can be


re-entered in USE and will be the governing history.
The benefit to the user being that the MODEL itself
need not be changed by the user, when re-using a
particular model. The history declaration in USE
follows the same rules as the history declaration
under MODEL, except the syntax is different and there
is no default option. The syntax is:

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

histdef (y) := sin(omega*t)


histdef (x) := 0

26
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

Initialization of variables is done in the INIT procedure.


This section is headed by the keyword INIT and terminated
by ENDINIT. MODELS require all variables used in he
simulation to be initialized before a value of that
variable is assigned to another variable. MODELS will
not initialize to zero. This is done in the INIT section,
except for the variables defined in the DATA, CONST and
HISTORY declarations. Initialization can be done in terms
of a constant entered under DATA or CONST as shown in
Example 2/M.

Initialization of a variable can be simply assigning a


value (including zero) to the variable, or assigning an
expression, or history using the histdef function as noted
above. The first time user of MODELS should use only
assignment of numerical values.

27
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

- Numerical and logical expressions and functions


- Simulation functions
- Foreign functions
- External functions

Foreign functions and external functions will not be


described in this Primer. The interested user can
refer to Chapters 2.6.4 and 2.6.5 and related
chapters in the MODELS Manual.

The Manual discusses Derivative and Integral


Expressions in Chapter 2.9. This Primer includes
them, for easier readability of the Primer, under
Simulation Expressions and Functions, in Chapter 8.4.

8.1 Numerical and Logical Expressions

Numerical and logical expressions are very similar to


those used by FORTRAN or BASIC. For example:

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.

for true y = 1, otherwise y = 0

Logical and numerical expressions can be combined as


in the following example yielding train of pulses:

y:= 100*(fract(t-tstrt)/period) <= ton/period)

8.2 Numerical Functions

Numerical functions in MODELS, as expressions, are


much the same as numerical functions in Fortran or
Basic.

29
8.2.1 Resident functions

The following resident functions are available:

abs(x), sqrt(x), exp(x), ln(x), log10(x),


log2(x)
recip(x), factorial(x), trunc(x), fract(x),
round(x)
sign(x), rad(x), deg(x), random(), sin(x),
cos(x)
tan(x), asin(x), acos(x), atan(x), sinh(x), cosh(x)
asinh(x), acosh(x), atanh(x), atan2(x1,x2),
binom(n,r)
permut(n,r), x1 mod x2
min(x1, x2, x3, .....), max(x1, x2, x3, ....)
norm( x1, x2, x3.....), ( sqrt of squares of x1,
x2, x3... )

Further explanation of these functions is given in


Chapter 2.6.6 of the Manual. The x1 MOD x2
function, oitted from the Manual yield the fractional
part of x1/x2.

8.2.2 Statement functions (User defined)

The user can define a function and use it as in the


following simple example:

FUNCTION Cathy (a1, a2, b) := (1.3*a1 + a2**2) / b


used as
y:= Cathy (x1, x2, x3)

note that the order of x1, x2, x3 has to be the


same as a1, a2, b.

The arguments of the FUNCTION are local (dummy


arguments), they do not have to be declared under
VAR. The dummy arguments are not visible outside the
function. Their names are allowed to be identical to
those outside the function. Duplication of names of
resident constants and variables of MODELS is,
however, prohibited. More information available in
Chapter 2.6. of the Manual.

30
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)
......
(x n, ynn)

the pointlist function can than be used as:

z:= name ( x i, 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:

FUNCTION alpha POINTLIST


-- firing anlgle current
(0.0000, 0.000)
(0.0576, 0.333)
(0.2414, 0.555)
(0.5718, 0.777)
(1.0000, 1.000)

then to get the value at a delay angle dela


ix := alpha (dela)

31
8.4 Simulation Expressions and Functions

DERIVATIVE Expression
with Linear Polynomial

This is described in Chapter 2.9.4 of the Manual. It


will be used by advanced MODELS users.

DIFFEQ Differential Equation

Recommended for advanced users. Described in Chapter


2.3.1.2 of the Manual.

8.4.1 DERIVATIVE Function


The syntax of the first order time derivative is:

y := DERIV ( x ) { dmax:a dmin:b }

where x is a variable
dmax and dmin are dynamic limits

The syntax of the second order time derivative is:


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

The syntax of the integral expression is:

y := INTEGRAL ( x ) { dmax:a dmin:b }

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:

Let the integral of x = at 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 dmin: 10 }
ENDEXEC
ENDMODEL
The value of integral can be reset during the
simulation by the integral reset expression:

integral (x) := expression

Example :

MODEL test
CONST omega { val: 2*pi*50 }
VAR y, y1, x
HISTORY x { dflt: 0 }

integral(x) { dflt : -1/omega }


--
EXEC
x := sin ( omega*t )
y1 := integral ( x )
y := omega * y1
IF t > 0.05 THEN integral ( x ) := 0 ENDIF
ENDEXEC
ENDMOEL

33
8.4.3 SUM Expression

The SUM expression evaluates the numerical value of a


polynomial.

k = a + bx + cx 2 + ..... zx n

The syntax of this expression is:

k := SUM ( a + b|x1 + c|x2 + ... ) {max:5 min: -1}

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

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 Expressions

8.5.1 Resident Simulation Expressions

MODELS provides a number of simulation


functions. These are described in Chapter
2.6.7 of the Manual. The more frequently used
ones are:

delay ( x, d, pol )

the value of the variable a at a time t-d.


'pol' is the optional interpolation
indicator. If 'pol' is omitted the
interpolation is linear. pol = 0,1,2 stand
for discrete, linear and quadratic
interpolation respectively.

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.

prevval ( x ) the value of x at the previous


simulation time

histdef ( x ) history declaration used under


the INIT process
Example 2 shows an application of the delay function
for the calculation of active power.

8.5.2 CLAPLACE and LAPLACE Transfer Function

MODELS provides two versions of the Laplace


(transfer) function. The most commonly used one is a
transfer function with constant coefficients. The
second one is the Laplace function where the
coefficients are variable. With variable
coefficients the function LAPLACE must be used. With
constant coefficients CLAPLACE should be used
because it is faster than LAPLACE. With CLAPLACE the
coefficients of the transfer function are evaluated
only once at the start of simulation, whereas with
LAPLACE they are evaluated at the beginning of each
time step.

The syntax of the LAPLACE or CLAPLACE function is


(given for CLAPLACE only as this would be used mostly
by the first time MODELS user:

CLAPLACE (y/x) := ( k0|s0 + k1|s1 + k2|s2 ....


etc) /
( l0|s0 + l1|s1 + l2|s2 etc)

35
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)

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

Note that for the 'correct' evaluation


of a feedback, the COMBINE option has
to be used as explained in the next
Chapter.

Block Diagram of Example

37
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 possible:

- IF .... ENDIF
- FOR .... ENDFOR
- DO ---- ENDDO
- WHILE -- ENDWHILE
- REDO
- SEQUENCE
- COMBINE

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

The structure of this control is:

IF logical expr. THEN


statement list
ELSIF logical expr. THEN
statement list
ELSE
statement list
ENDIF

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

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 DO ' )
write ( ' k = ',k )
k := k - 1
IF k > 0 REDO ENDIF
x := 10
write ( ' x = ',x )
ENDDO
ENDEXEC

9.3 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 = ',k )
ENDWHILE
ENDEXEC

9.4 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.

39
The syntax is:

FOR i := k1 TO k2 BY d
DO
-- list of instructions
ENDFOR
BY is optional with a default of 1

Like in BASIC, FOR loops can be nested, the ENDFOR


statement has to be given only once.

FOR i := 1 TO 5
FOR k := 3 to 1 BY -1
DO
instructions
ENDFOR

Example 3 illustrates the generation of three


sinusoidal voltages with 120 degrees phase shift, and
the generation of firing 500 microsec. pulses
synchronized with the zero transition of the
voltages.

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

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

This can substantially speed up the execution of an


ATP file where a very small time step is used to
accommodate requirements of the electrical network,
but the solution in MODELS does not require this
small time step.

42
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

Where 'modelname' is the name of the MODEL which


contains the variable named 'varnamex' and 'outnam'
is the name given to this variable for the recording
of the output on disk. The reason for this apparent
duplication is that MODELS allows names of any
length, whereas ATP allows names only 6 characters
long. Apart from this, the requested output of
variables are treated by ATP exactly the same way as
they are in EMTP or in the 33 code TACS output
request.

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:

write ( ' any text ', x1,' ',x2,' ' etc )

where 'any text' is a description of the variables to


be recorded, and x1, x2 etc are the variables to be
monitored. Note that x1, x2 etc. may not only
variables but also expressions like delay(x,t).

43
11. Multiple MODEL's

There can be more than one MODEL in a MODELS file. 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

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

In Example 4, active power and reactive power will be


calculated for a branch in the EMTP network, by passing
the voltage and current to the MODEL ' model_3 ', and
integrating into model_3 the models 'power' and 'reactive'
by $INCLUDE statements.

Note that the inclusion of the two MODEL groups in the


MODELS file by $INCLUDE is just an editing feature, it
saves copying the complete files into MODELS. USE
statements have to be added to each MODEL. They have to
specify the inputs to the MODEL group.

12. Features Not Covered In the Primer

There are a number of features and capabilities of the


MODELS language which are not covered in the Primer, at it
was thought that the first time MODELS user would not
need them, and their discussion would detract from the
readability of the Primer. Such features are for example,
Differential Equations, Foreign MODEL's, SEQUENCE,
Nonlinear Groups, the use of the Type 94 feature in EMTP
etc. These features are discussed in the Manual.
Comments by the Primer users will be welcome as to which
of these features to incluse in future versions of the
Primer.

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
---------------------------------------------

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

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

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.

48
A1. MODELS Equivalents of TACS and EMTP Sources

List of Sources:

TACS Code 11 -- Lavel Signal and Single Pulse


TACS Code 14 -- Cosine
TACS Code 23 -- Pulse Train
TACS Code 24 -- Ramp Train (Saw-tooth)
EMTP Type 13 -- Two-slope Ramp
EMTP Type 15 -- Double Exponential

***************************************************************
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


TACS Device 51/52 -- Relay Switch
TACS Device 53/54 -- Transport and Pulse Delay
TACS Device 55 -- Digitizer
TACS Device 56 -- Point by Point Nonlinearity
TACS Device 57 -- Time Sequenced Switch
TACS Device 58 -- ControlledIntegrator
TACS Device 59 -- Single Derivative
TACS Device 60 -- Input IF Component
TACS Device 61 -- Signal Selector
TACS Device 62 -- Sample and Track
TACS Device 63 -- Inst. Maximum/minimum
TACS Device 64 -- Maximum/minimum Tracking
TACS Device 65 -- Accumulator - Counter
TACS Device 66 -- R.M.S. Value

*******************************************************************
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

You might also like