Users Guide To Models in ATP
Users Guide To Models in ATP
TO
MODELS IN ATP
April 1996
i
ACKNOWLEDGMENTS
The writing of this manual would not have been possible without the
participation of the many users of MODELS who, over the years, have
contributed suggestions and prompted discussions on many aspects of the
language and its use in ATP. These people certainly deserve a large share of
the credit for the work that has been done.
PREFACE
This Users Guide has been written with the purpose of introducing the
MODELS language for use with ATP. It is written mostly in a conversational
style, as opposed to the more formal descriptions found in the MODELS
Language Manual of the ATP Rule Book. The purpose of this guide is to
explain how the MODELS language is held together, and to illustrate its usage
with discussions and examples.
I realize that a manual like this is never done. There are many aspects to using
a programming language and to doing simulation. They are best understood
through one's own experience and glimpses at the experience of others. We
can continue adding examples to this Guide forever.
This first version covers the basic aspects of using the MODELS language.
The main features of the language are discussed in detail and illustrated with
examples. The interface between MODELS and ATP is also discussed at
length. What is not included are detailed examples of electrical and control
components, descriptions which, in my opinion, are beyond the scope of this
introduction. The objective of this manual is to explain the "how" and the "why"
of using MODELS. The "what" of the applications belongs to one or more
separate tutorials covering those subjects, for the application specialists to
provide.
As it is true for any tool, how much a program is used depends to a large
extent on how much its features are understood. With the usual time pressure
of our work, of course we wish to be able to use something like this instantly.
Having the time to play with a new tool is a luxury we can't always afford. But
one has to realize that any product that took a few years to prepare needs at
least a few hours of exposure to it to get the whole picture. I hope that the time
looking at this manual will be time well spent.
OUTLINE
Acknowledgments
Preface
Outline
Contents
Introduction
1. Basic aspects of the MODELS language
2. Writing a model
3. Writing expressions
4. Specifying simulation directives
5. Using a model
6. Using MODELS in ATP
7. Libraries of models and functions
Appendix A – Syntax of the MODELS language
Appendix B – Keywords of the MODELS language
Appendix C – Pre-defined constants and variables
Appendix D – Pre-defined functions
Bibliography
Index
In closing ...
CONTENTS
ACKNOWLEDGMENTS.......................................................................................... i
PREFACE .............................................................................................................. ii
OUTLINE................................................................................................................iii
CONTENTS .......................................................................................................... iv
INTRODUCTION.................................................................................................... 1
1. BASIC ASPECTS OF THE MODELS LANGUAGE........................................... 2
1.1. Why use MODELS..................................................................................... 2
1.1.1. MODELS in ATP................................................................................. 2
1.1.2. Starting to use MODELS .................................................................... 2
1.1.3. Overall form ........................................................................................ 3
1.1.4. Similar to a programming language .................................................... 3
1.1.5. What's particular to MODELS ............................................................. 4
1.1.6. What about TACS?............................................................................. 5
1.1.7. Reasons for using MODELS in a project ............................................ 5
1.2. Value-holding elements, and values .......................................................... 6
1.2.1. Kinds of value-holding elements ......................................................... 6
1.2.2. Scalars and arrays.............................................................................. 7
1.2.3. Use of arrays ...................................................................................... 8
1.2.4. Representation of numbers ................................................................ 8
1.2.5. Limits .................................................................................................. 9
1.3. Notation, format, and conventions ............................................................. 9
1.3.1. Model, MODELS, and MODEL ........................................................... 9
1.3.2. Equal sign and assignment sign ......................................................... 9
1.3.3. Parentheses, brackets, and braces .................................................. 10
1.3.4. Blank lines ........................................................................................ 10
1.3.5. Names .............................................................................................. 10
1.3.6. Delimiters.......................................................................................... 11
1.3.7. Comments ........................................................................................ 11
1.3.8. Line indentation ................................................................................ 11
2. WRITING A MODEL........................................................................................ 12
2.1. Defining the value-holding elements ........................................................ 12
2.1.1. Defining constant elements............................................................... 12
2.1.2. Defining data elements ..................................................................... 13
2.1.2.1. Using a data value as an array dimension................................. 13
2.1.2.2. Dependent data values.............................................................. 13
2.1.3. Defining input elements .................................................................... 14
2.1.4. Defining variable elements................................................................ 14
2.1.5. Defining output elements .................................................................. 15
2.2. Defining the submodels............................................................................ 15
2.2.1. Locally-defined submodels ............................................................... 16
2.2.2. Foreign submodels ........................................................................... 17
2.2.3. External submodels .......................................................................... 20
2.3. Defining the functions............................................................................... 21
2.3.1. Statement functions .......................................................................... 21
2.3.2. Pointlist functions.............................................................................. 22
2.3.2.1. External point list ....................................................................... 23
2.3.3. Foreign functions .............................................................................. 23
2.4. Writing the procedures ............................................................................. 25
5. USING A MODEL............................................................................................ 65
5.1. Assigning data values .............................................................................. 65
5.2. Assigning input values ............................................................................. 65
5.3. Retrieving output values........................................................................... 66
5.4. Specifying simulation directives ............................................................... 66
5.5. Calling a model more than once per time step......................................... 67
5.6. State of a model....................................................................................... 68
6. USING MODELS IN ATP ................................................................................ 69
6.1. The MODELS section of a data case....................................................... 69
6.1.1. Inputs from ATP................................................................................ 70
6.1.1.1. Inputs from the circuit ................................................................ 70
6.1.1.2. Inputs from a PL4 plot file.......................................................... 71
6.1.1.3. Inputs from the TACS section.................................................... 73
6.1.1.4. Inputs from ATP program variables ........................................... 74
6.1.2. Outputs to ATP ................................................................................. 75
6.1.3. Variables in the MODELS section..................................................... 76
6.1.4. RECORD for printout/plotting............................................................ 77
6.1.5. Model descriptions............................................................................ 77
6.1.6. MODELS formatting vs. ATP formatting ........................................... 79
6.2. Using a model in the MODELS section .................................................... 79
6.3. Using a model with the type-94 component ............................................. 81
6.3.1. Thevenin, iterated, and Norton ......................................................... 83
6.3.2. Initializing the type-94 component .................................................... 85
6.3.3. Foreign models with a type-94.......................................................... 86
6.4. Using MODELS with ATP's FREQUENCY SCAN.................................... 87
6.5. Steady-state initialization ......................................................................... 88
6.6. List sizes in ATP for MODELS ................................................................. 89
7. LIBRARIES OF MODELS AND FUNCTIONS ................................................. 90
7.1. Signal sources ......................................................................................... 90
7.1.1. Examples of some common sources ................................................ 90
7.1.2. Sample data case ............................................................................. 92
7.2. Library of complex-value functions........................................................... 93
7.2.1. Examples of complex-value functions............................................... 93
7.2.2. Sample data case ............................................................................. 95
7.3. Library of TACS-like devices.................................................................... 95
7.3.1. TACS type-50 frequency meter ........................................................ 95
7.3.2. TACS type-51 relay-operated switch ................................................ 96
7.3.3. TACS type-52 level-triggered switch................................................. 97
7.3.4. TACS type-53 transport delay........................................................... 97
7.3.5. TACS type-54 pulse delay ................................................................ 97
7.3.6. TACS type-55 digitizer ...................................................................... 99
7.3.7. TACS type-56 point-by-point nonlinearity ......................................... 99
7.3.8. TACS type-57 time-sequenced switch.............................................. 99
7.3.9. TACS type-58 controlled integrator................................................. 100
7.3.10. TACS type-59 simple derivative.................................................... 100
7.3.11. TACS type-60 input-IF component ............................................... 101
7.3.12. TACS type-61 signal selector ....................................................... 101
7.3.13. TACS type-62 sample/hold and track/hold.................................... 101
7.3.14. TACS type-63 instantaneous min/max ......................................... 103
7.3.15. TACS type-64 min/max tracking ................................................... 103
INTRODUCTION
This manual starts with a discussion of the basic aspects of the MODELS
language, providing a general presentation of what the language does, what is
special about the language, and the nuts and bolts of its rules and
conventions.
This is followed by a more in-depth look at the process of writing a model,
writing expressions, and specifying simulation directives in a model.
Various aspects of using a model are discussed next.
This is then followed by a detailed presentation about using MODELS in ATP.
It includes an explanation of the different declarations that can be included in
the MODELS section. It also describes the different ways in which MODELS is
interfaced with ATP, and how each approach can be used in the simulation of
a circuit.
The text concludes with a discussion and examples of building libraries of
models and functions that can be assembled as a toolkit to be used in
present and future simulation projects.
Four sections are added as appendices to this manual. They are built for use
as a quick reference to the MODELS language. The first is a summary
reference to the syntax of the MODELS language. It condenses the contents
of the Language Manual, presenting only the structure and the diagrams,
without the text. Next comes a summary of that summary, providing a
structured overview of only the keywords of the MODELS language, without
the details of the full syntax rules. The other two appendices show the pre-
defined constants and variables, and the pre-defined functions of
MODELS, with discussions and examples.
The other aspect is that MODELS automatically manages the storage and
retrieval of the history values of the variables of a model, as needed during the
execution of the simulation. The time-based functions of the language all have
direct access to the past values of a variable, as needed for the calculations,
without imposing on the user the task of specifying how that information is
stored and accessed.
The naming of the types is not perfect, in the sense that data are as constant
as the constants, and inputs are certainly as variable as the variables. They
are identified by separate type names to underline their difference of being
public or private with respect to the model where they are defined.
The use of an array notation can simplify the description of a model, and also
contributes to reducing the execution time of the simulation.
1.2.5. Limits
Values are specified in expressions. In addition, each expression can be
qualified by a minimum value and a maximum value. These limits are
themselves described using an expression which may vary in value during a
simulation. Limits are discussed in more detail below, in the sections on
COMBINE, differential equations and transfer functions, integrals, and
expressions.
a := 3*b -c {min: amin, max: amax}
y := integral(x) {dmax: 3*a}
laplace(y/x) := (s_numerator)/(s_denominator) {dmin: ymin*cos(omega*t)}
or
laplace(y/x) := (s_numerator)/(s_denominator)
The left and right square bracket characters "[" and "]" are used to identify an
element or a range of elements of an array. In this case, the left bracket must
immediately follow the function name, without any space. They can be used
with an array name to identify elements of that array:
wabs[1..n] := abs(w[1..n])
The left and right brace characters "{" and "}" are used to identify some
attribute, like default value, limit value, type, argument count, etc. For
example:
INPUT va { v(NODEA) }
CONST twopi { val: 2*pi }
DATA freq { dflt: 50 }
FUNCTION windspeed FOREIGN { ixarg: 2 }
1.3.5. Names
Names can be composed using any combination of letters, digits, and the
underscore character "_", with the restriction that a name must start with a
letter.
Names are not case-sensitive. Upper and lower case can be used for
readability, but not for distinguishing two names of the same spelling.
Keywords of the language are typically written in capitals for readability, but
this is not necessary for interpretation by the parser.
Hyphens are not permitted inside a name, and will be interpreted as a minus
sign.
1.3.6. Delimiters
From a parsing point-of-view, all constructs of the language are self-delimiting.
This means that some kind of end delimiter indicates where a construct ends,
whether implicitly or explicitly.
An implicit delimiter is what is used for indicating the end of a name, keyword,
operator, or value. For example, names terminate at the first character that is
not a recognized name character, and values terminate at the first character
that is not a legal value character.
Explicit end delimiters are keywords that indicate the end of a construct, for
example, ENDMODEL or ENDIF.
1.3.7. Comments
Two aspects contribute to making a model understandable. The first is to
choose names that are appropriately descriptive of the value or function they
are representing. The other is the liberal use of in-line comments and block
comments.
An in-line comment starts with a string of two or more hyphens, and
automatically terminates at the end of the line.
A block comment is a block of text starting with the keyword COMMENT and
ending with the keyword ENDCOMMENT. This can be used to annotate a
model, or to temporarily block out a part during model development or testing.
MODEL m1
comment ---------------------------------------------------
| This is a block comment describing this model |
| (the vertical bars and the hyphens are only decorative) |
------------------------------------------------ endcomment
2. WRITING A MODEL
This section introduces the elements used when building a model description
of something. The dynamic operation of a model is represented by the named
elements that hold the values used in and created by the model (constants,
data, inputs, variables, and outputs), and by a description of how these values
are calculated and used. Procedures contain the statements where these
values are used and assigned. Various types of statements are available for
representing how a value is calculated and assigned. Submodels and
functions can also be defined to carry out some of the calculation of these
values. The use of each model and submodel can be customized for each use
instance, by means of simulation directives specified in the model definition
and in the USE statements introducing each instance.
There is a set of constants that have pre-defined names and values. They can
be used without needing to be declared:
- pre-defined numerical constants:
- pi 3.14159...
- inf a large value, typically 1020
- undefined the special value 88888.88888
Data elements are typically used for parameters and dimensions that can be
assigned a different value in different use instances of the model.
Once assigned, DATA values do not vary in time. Their value is constant over
the full length of a simulation. Data values are automatically calculated in the
USE statement the first time the use instance is called.
This is because it's inadvertently making public a name that is really private to
the model. For array dimensions, this is unavoidable, and at best could be
checked for consistency in the INIT procedure of the model.
When the data is not needed as the dimension of an array, it's better practice
to hide it to the outside by declaring it as a variable, and then assign its value
in the INIT procedure in function of the data value it depends on. For example,
instead of doing:
DATA freq {dflt: 50} -- a frequency in Hz
DATA omega {dflt: 2*pi*freq} -- the equivalent frequency in rad/sec
declared as OUTPUT (see section below). Their value can be assigned in any
statement inside the model. Once assigned a value, a variable maintains that
value during the simulation, until it is assigned a new value.
To continue the previous example, one could track the input voltages for
maximum amplitude for each terminal, let's say, and the maximum for all
terminals. Let's define the variables vtmax[ ] and vmax:
DATA n -- number of terminals
INPUT vterm[1..n] -- value of measured terminal voltages
vref {dflt: 0} -- value of a reference voltage, =0 if not used
VAR vtmax[1..n] -- tracked maximum absolute value of each terminal voltage
vmax -- tracked maximum absolute value of all terminal voltages
The $INCLUDE directive is an ATP command used for accessing the contents
of other files. It's a formatted command, and must start in column 1 of a new
line.
In the above example, the local name is "controller", and the foreign name is
"control_program". That foreign name is not necessarily the name of the
foreign program itself. It is a unique identifier used in the subroutine "fgnmod"
of MODELS, to recognize which foreign model is being called. It is inside that
subroutine that the actual call to the foreign program is made. That subroutine
needs to be edited when installing calls to new foreign programs. That
subroutine is fully documented with comments, and should present no difficulty
when used. Part of that subroutine is shown below, showing how the identifier
"controller" of the previous example would be used:
SUBROUTINE FGNMOD ( name, namlen, xdata, xin, xout, xvar,
1 iniflg, ierflg)
IMPLICIT REAL*8 (A-H, O-Z), INTEGER*4 (I-N)
DIMENSION xdata(*), xin(*), xout(*), xvar(*)
...
C In the following lines, register the foreign model names
C as declared in the models:
It is when actually using the foreign model that the contents of the data, input,
and output arrays is identified. Just like when using a local model, it is possible
to specify how data, input, and history values are calculated. One difference is
that the value of the local simulation time must be explicitly passed to the
foreign program as one of the inputs. It's not done "magically" in the
background. Outputs of the foreign model are used just like those of a local
model. The contents of the array of variables is specified and managed inside
the called program, not in the USE statement. However, it is possible to assign
initial values to these variables using HISTORY directives, just like in a regular
USE statement. Note that only initial values are passed to the foreign program,
not full history expressions available only for regular models.
The following example illustrates the definition and the use of a simple foreign
model. Note that the four arrays have the pre-defined names "xdata", "xin",
"xout", and "xvar":
DATA n
VAR a[1..n]
...
MODEL ftnmodel FOREIGN sample_model {ixdata:1, ixin:n, ixout:n, ixvar:n}
...
EXEC
...
USE ftnmodel AS ftnmodel
DATA xdata[1]:=n -- set value of xdata[1]
INPUT xin[1..n]:= ... -- load inputs xin[1..n]
HISTORY xvar[1..n]:=0 -- set history of xvar[1..n]
OUTPUT a[1..n]:=xout[1..n] -- use outputs xout[1..n]
ENDUSE
...
The foreign program, in this case, is a Fortran subroutine that writes some text
and updates the values of the outputs, without using the value of time (which is
thus not passed as an input):
SUBROUTINE samplm(xdata, xin, xout, xvar)
DIMENSION xdata(*), xin(*), xout(*), xvar(*)
CHARACTER*80 text80 ! Buffer used to assemble messages for output
text80 = 'Executing model "sample_model".'
CALL OUTSIX( text80, 80 ) ! Send text80 (arg 1) to ATP listing
DO 1000 i=1,xdata(1)
xvar(i)=(2*xvar(i)+xin(i))/2
xout(i)=xvar(i)+100.0
1000 CONTINUE
RETURN
In the example, "xdata[1]" holds the dimension of the other three arrays, "xin"
holds input values received from the calling model, "xout" holds output values
sent back to the calling model, "xvar" holds state values stored in memory by
MODELS between calls. Note how xvar is referenced before a new value is
assigned to it, requiring a reference to the initial value of xvar at the first
execution of the subroutine.
The full definition of the external model can be placed anywhere at the same
level of the calling model or above. For the previous example, it could be found
either at the same level of the "component" model as a locally-defined model:
MODEL component -- defining a model
...
MODEL controller EXTERNAL
...
ENDMODEL
MODEL controller
CONST ...
DATA ...
...
ENDMODEL
or at a higher level:
MODEL system
MODEL sub_system_1
MODEL component -- defining a model
...
MODEL controller EXTERNAL
...
ENDMODEL
...
ENDMODEL
MODEL sub_system_2
...
ENDMODEL
MODEL controller ...
...
ENDMODEL
The form under which the list of values is provided is flexible, and can be a
mixture of single values and of ranges of array elements, using expressions
and array expressions, for example:
somename(expr, array_expr, ... )
or can be supplied as an array of two values, with the array, in this case, being
a representation of the real and imaginary part of a complex number:
VAR cx[1..2] -- a complex variable as real and imaginary
FUNCTION c_ampl(real, imag) := sqrt(real*real +imag*imag)
...
ym := c_ampl(cx[1..2])
The first coordinate of each pair corresponds to the input value, and the
second coordinate corresponds to the output value of the function.
What gets interesting is that the values of the coordinates can be expressed
using regular expressions making reference to other variables or functions of
the model. Very complex functions can be assembled using this possiblilty.
An interesting example is the description of a parametrized family of curves. A
pointlist function specifies what curve the function will use for different values
of a parameter "k". Each curve can in turn be described using an expression
that contains a reference to another function of any type. The following
example illustrates a simple 1-parameter family of curves.
VAR a, k
FUNCTION curve2(x) ... -- a statement function or a point list for k=2
FUNCTION curve4(x) ... -- a statement function or a point list for k=4
FUNCTION curve6(x) ... -- a statement function or a point list for k=6
FUNCTION f POINTLIST (2, curve1(a))
(4, curve2(a))
(6, curve3(a))
...
a:= some value -- used inside the function f(k)
k:= 2.5 -- any value between 2 and 6
y:=f(k)
Supposing that these coordinates are available in a file named "xy.lst", they
could be included in a model as follows:
FUNCTION xyfun POINTLIST -- with data points located in the following file:
$INCLUDE xy.lst
In the above example, the local name is "windspeed", and the foreign name is
"wind_speed". The dimension of the argument array is indicated as "2",
because even if there is only one input argument when the function is used,
the function returns two values that it places in that array.
The indicated foreign name is not necessarily the name of the foreign
procedure itself. It is a unique identifier used in the subroutine "fgnfun" of
MODELS, to recognize which foreign function is being called. It is inside that
subroutine that the actual call to the foreign procedure is made. That
subroutine needs to be edited when installing calls to new foreign procedures.
That subroutine is fully documented with comments, and should present no
difficulty when used. Part of that subroutine is shown below, showing how the
identifier "wind_speed" of the previous example would be used:
SUBROUTINE fgnfun ( name, namlen, xarg, nval, ierflg)
IMPLICIT REAL*8 (A-H, O-Z), INTEGER*4 (I-N)
DIMENSION xarg(*)
...
C In the following lines, register the foreign function names
C as declared in the models:
It is when actually using the foreign function that the values of the input
arguments are identified. Just as when using a local function, it is possible to
specify how the function arguments are calculated. If the operation of the
function varies in function of time, the value of time must be explicitly passed
to the function as one of its input arguments.
In the example of the wind speed function shown above, the only input
argument used by the function is the value of the simulation time "t". The
function returns two values, the wind velocity and direction, placed in the
argument array of the function. Internally, MODELS uses the value returned by
the function, which in this case will be "2", to find out how many values the
function has placed in the argument array.
The following example illustrates the definition and the use of another simple
foreign function:
VAR y[1..2], k
FUNCTION f1 FOREIGN sample_function {ixarg:2}
...
EXEC
...
y[1..2]:=f1(k+t, -k) -- each argument can be an arbitrary expression
...
The foreign procedure, in this case, is a Fortran function that uses two input
values, and returns two output values placed in the argument array:
FUNCTION samplf(arg)
DIMENSION arg(2)
arg(1)=arg(1) +arg(2)
arg(2)=arg(1)*10
samplf=2
RETURN
END
The procedures describe the methods used by the model for accessing and
modifying the values of the value-holding elements of the model during the
simulation.
Two procedures have pre-defined names: EXEC and INIT. The EXEC
procedure is the procedure that is called when it is time to update an instance
of the model to a new simulation time. It is called automatically each time a
USE statement is executed. It describes how the model operates as time
increases. The INIT procedure describes how to initialize the values of the
where the function deriv() needs to access, behind the scene, the value of v at
the previous time step, which of course has not yet been stored in the model's
running history, and is therefore undefined.
By having both the INIT and EXEC procedures executing at the initial time, we
minimize the size of INIT, and avoid code duplication which would easily
create maintenance problems in the development life of the model. All we
need to do in the INIT procedure is define any past values which will be
referenced in the EXEC procedure before the model has had the opportunity to
store these past values itself in its running history.
PROC write_y
write('In model proc_example, y=', y)
ENDPROC
PROC integral_value
integral_value := integral(x) -- returns the value of the integral
ENDPROC
ENDMODEL
As shown in the above example, a procedure can have zero or more input
arguments, and can return zero or more output values. A procedure can be
called from inside the model where it is defined, using the instance identifier
"self". As shown in the next example, a procedure can also be called from
another model that uses an instance of the model where the procedure is
defined:
MODEL test_proc
MODEL proc_example EXTERNAL -- identifies a model description
VAR k -- counter
INIT k:=0 ENDINIT
EXEC
k:=k+1
USE proc_example AS example -- creates and updates an instance named
-- "example" of the model "proc_example"
DATA inival := -4
INPUT x := 2*t +3
ENDUSE
IF k=4 THEN
example.reset_integral(0) -- calls a proc of "example"
ENDIF
write('In test_proc at t=', t,
', integral value=', example.integral_value) -- calls another proc
ENDEXEC
ENDMODEL
expressed using the keyword DIFFEQ, and the vertical bar as an operator
meaning "applies to":
DIFFEQ(polynomial)|y := x
This is expressed using the following notation, again using the vertical bar as
the operator "applies to":
LAPLACE(y/x) := (numerator)/(denominator)
This is expressed using the following notation, again using the vertical bar as
the operator "applies to":
ZFUN(y/x) := (numerator)/(denominator)
is equivalent to
Y (s) 1
=
X (s) a0 + a1s + a2 s2 +...
becomes
(a0 + a1D + a2D 2 +...) ⋅ y (t ) = (b0 + b1D + b2D 2 +...) ⋅ x(t )
The equation now shows a new set of coefficients, each a function of the
original coefficients of the respective polynomials.
To summarize, differential equations and Laplace transfer functions are
converted to z-transform transfer functions. This is done in the solver by
applying a numerical transformation to the coefficients of each polynomial.
Instead of using values of derivatives, the equation is solved numerically by
making simple references to as many past values of y and x as needed in
each case.
2.5.2.2. Initialization
Because of the transformation discussed above, we can initialize the solution
of any of these equations without having to provide initial conditions for the
derivatives of a differential equation or Laplace transfer function. It is sufficient
to describe the value of the variable at past times before time zero, simply
using a history expression f(t) written in function of time. The solver will
continue the calculation from time zero onward just as if all the initial conditions
on the derivatives had been provided.
Some textbook examples of differential equations set t=0 at a time when the
system is in a transient condition, not a steady-state condition, and need initial
conditions on the derivatives in order to solve the equations analytically. This
situation is not representative of typical simulations, where we start a
simulation from a known simple state, and then let the transient behavior start
only at or after the beginning of the simulation.
In any case, even if one needs to start a simulation from a transient condition,
it can be argued that if one has enough information to know analytically the
initial conditions of all the derivatives, one certainly has enough information to
also know the shape of the variables in the form of a history expression f(t).
Let's look at an example where we have to find the time domain solution for
the following differential equation using Laplace transforms (from Kuo):
2.5.2.3. Values of y at t0
At the first execution of a model-use (that is, at the initial time at which each
instance of that model is called), the above equations don't need to be re-
calculated, because the value of the variable to which they apply is already
defined by its history expression. The same reasoning applies to the value of
the integrals.
2.5.2.5. Limits
The only limit that can be applied directly to the value of a variable calculated
using a differential equation and a Laplace or z transfer function, is a dynamic
limit. This is because when a limit is reached, all the derivatives of that variable
become zero, therefore changing the internal state of the "component" used to
produce the output represented by that variable. If we need to apply a limit
(minimum and/or maximum) which does not modify the internal state of the
t0
∫ x ⋅ dt
−∞
the integral of x with respect to time, from -infinity to the present time. This can
be decomposed, using t1 = t0 - Δt, as:
t0 t1 t0
∫ x ⋅ dt = ∫ x ⋅ dt + ∫ x ⋅ dt
−∞ −∞ t1
or
I (x, t 0 ) = I ( x, t1) + ΔI (x, t1 → t 0 )
The running value of an integral is calculated during a simulation by using the
value of the integral at the previous time, and adding to it the value of the
incremental integral over the past step. This increment, in MODELS, is
calculated using the trapezoidal approximation, as the average of x(t1) and
x(t0), multiplied by the time interval t0-t1:
x(t1) + x(t 0 )
ΔI = ⋅ (t 0 − t1)
2
However, it is possible to bypass this process and assign a value to the
integral directly, in effect resetting the value of the integral, to zero or some
other value, by using an integral value assignment of the form:
integral(x) := expression
This new value becomes the starting point to which the next incremental
integral will be added at the next time step.
One detail to notice is the following. At a given simulation time inside the
EXEC of a model, we may assign a value to x, then use the value of its time
integral (which will use the present value of x to calculate the integral
increment). Then further on in the EXEC at the same time step, we may assign
a different value to x, then again use the value of the integral (which will use
the new x to recalculate its increment), and so on. But from the point in the
EXEC where a value is directly assigned to the integral, the value of the
integral is not dependent on the present value of x anymore for the rest of that
EXEC at that simulation time. No matter how often one changes the value of x
after the reset inside the same time step, any reference to the value of the
integral will always return the same value, the reset value that was assigned
directly to the integral by the integral value assignment.
This is the third form of history assignment, as discussed in the section on the
INIT procedure.
The expression can itself make reference to the history expression associated
with other variables. For example, to make the history expression of y
Notice the difference between the equation above, and the following:
histdef(y) := 2 * x
which would not achieve the intended purpose, but instead only use the most
recent value of x whenever the history expression of y needs to be evaluated.
2.5.5. IF statement
IF statements are used for grouping statements that are executed only when
certain conditions are met.
Multiple clauses can be chained inside the same IF statement. Only the first
clause found with a true condition is executed:
IF condition_is_true THEN
statement list
ELSIF another_condition_is_true THEN
another statement list
ELSIF ...
...
ENDIF
A default clause, the ELSE clause, can also be defined. It is executed only
when no other clause of the IF statement is found with a true condition:
IF condition_is_true THEN
statement list
ELSIF another_condition_is_true THEN
another statement list
...
ELSE
another statement list
ENDIF
IF condition_is_true THEN
statement 1
statement 2
IF condition THEN
another statement list
...
ENDIF
...
ENDIF
The first three conditions can be grouped using a logical expression, and the
IF statement can be rewritten as:
IF onswa=2 AND ia<=ichop AND di_dta<di_lim THEN onswa:=3
ELSIF dva>ds THEN onswa:=2
ENDIF
If cond_1 is true, its numerical value is 1, cond_2 is false, and the expression
evaluates to: 3*1 +2*0 +onswa*0, and so on.
Conditional expressions can also use a variable as a selector:
y := (a=1)*f1(x) +(a=2)*f2(x) + ...
This structure can be used for doing iterations inside a model, with the
simulation time "frozen" for the duration of the iteration:
The word "while", in this case, does not imply a reference to time, and does
not mean "when". If we need to express "when a condition is true then do this",
we can use an IF statement to take care of that, as shown in the example
above with "IF t=timestep THEN".
The other difference is the values to be taken by each parameter are given in
the form of a value list, where each term of the list can be either a single value
or a range of values:
FOR z:= 0 TO 5, -- 0,1,2,3,4,5
6, -- 6
7 TO 9 BY 1 -- 7,8,9
The statement list placed inside the FOR statement is executed repeatedly
until all combinations of the parameter values have been covered:
As shown in this example, the values of the parameters are assigned and
combined in the sequence in which they are specified.
The names of the parameters are local to the FOR statement, and don't need
to be declared as variables of the model.
Even though the simple examples above show only integer values, the
parameters can also be assigned non-integer values:
FOR angle:= 0 TO 2*pi BY pi/4
DO
write('tan(', deg(angle), ') = ', tan(angle))
ENDFOR
As for the WHILE statement, the simulation time is frozen while control of the
execution is kept inside a FOR statement.
2.5.8. DO statement
Like the WHILE statement, the DO statement is used for repeating the
execution of a group of statements.
DO
statement list
ENDDO
The first difference is that in the DO statement, the statement list is executed
at least once.
The second difference is that the condition determining whether the loop will
be repeated or not, is carried by a flag set by executing the REDO statement
anywhere inside the statement list.
The DO statement is like a WHILE statement written as follows:
redo_flag := TRUE
WHILE redo_flag = TRUE DO
statement list
ENDWHILE
COMBINE AS feedback_controller
equations of the feedback controller
ENDCOMBINE
The statement list of a linear COMBINE can include any arrangement of the
following types of linear equations:
- differential equations, which in MODELS use a linear polynomial of the time
derivatives of a variable;
- Laplace transfer functions, which are described using two linear
polynomials of the "s" operator;
- z transfer functions, which are described using two linear polynomials of
the "z -1" operator;
- linear value assignments of a variable or of an array element of a variable,
using:
- a sum expression, which is a linear sum of variables
- a derivative expression, which is a polynomial of the time derivatives of
a variable
- the integral of a variable
- the first or second derivative of a variable
- no regular expression (considered nonlinear)
Here is an example combining two simultaneous linear equations:
a+b=6 ( rewritten as b = 6 - a )
a=t*b
MODEL comb1
VAR a, b
EXEC
COMBINE AS first_group
b := sum( 6| - 1|a )
a := sum( t|b )
ENDCOMBINE
write('t=',t,', a=',a,', b=',b,', a+b=',a+b)
ENDEXEC
ENDMODEL
Each line of the COMBINE group describes how a value is assigned to each
simultaneous variable. This is why the first equation is rewritten to express the
value of b, as we were already using the second line to express the value of a.
The syntax of the sum() expression is explained in the section on
"Expressions". Notice how the format of the sum() expression requires that we
place the coefficient of the left of each term, and the variable on the right of the
term. This is why we could not write a := sum( b | t ), because in this case, t is
not a variable of the group, b is.
The linear COMBINE allows us to add min/max limits to one of the equations:
MODEL comb1
VAR a, b
EXEC
COMBINE AS first_group
b := sum( 6| - 1|a )
a := sum( t|b ) { max: 4 }
ENDCOMBINE
write('t=',t,', a=',a,', b=',b,', a+b=',a+b)
ENDEXEC
ENDMODEL
Here are four versions of the same set of simultaneous equations showing the
relationship between sin(t) and cos(t), all with the same solution of:
y1 = sin(t), y2 = cos(t), y3 = -sin(t)
The fourth set uses a z-transform and Laplace version of the derivatives:
z-transform(y2/y1) = (1 - z -1) / (h + hz -1)
Laplace(y3/y2) = s/1
y1 = - y3
COMBINE AS first_group
y1:= integral(y2)
y2:= integral(y3)
y3:= sum(-1|y1)
ENDCOMBINE
write(sin(t),':',y1)
COMBINE AS second_group
y2:= deriv(y1)
y3:= deriv(y2)
y1:= sum(-1|y3)
ENDCOMBINE
write(sin(t),':',y1)
COMBINE AS third_group
laplace(y1/y2) := 1|s0 / 1|s1
laplace(y2/y3) := 1|s0 / 1|s1
y3:= sum(-1|y1)
ENDCOMBINE
write(sin(t),':',y1)
COMBINE AS fourth_group
zfun(y2/y1) := (1|z0 -1|z-1)/(h|z0 +h|z-1) -- (s/1)
laplace(y3/y2) := 1|s1 / 1|s0
y1:= sum(-1|y3)
ENDCOMBINE
write(sin(t),':',y1)
ENDEXEC
ENDMODEL
Iterated COMBINE groups are solved using the Newton method. The tolerance
value is fixed at 10-8 times each value. The maximum allowed number of
iterations per step is user-definable, with a default of 10.
A maximum number of iterations other than 10 can be specified inside braces
following the keyword ITERATE, for example:
COMBINE ITERATE {5} AS first_group
b := 6 - a
a := t * b
ENDCOMBINE
indicating that we would allow only 5 iterations for convergence to take place.
Here is an example that illustrates how an iterated COMBINE can be used with
different types of assignments and multiple min/max limits. It describes a
somewhat acrobatic set of simultaneous equations that should provide the
following solution:
y1 = y4 -y2 +2 { max: y4/y2 } ( Solution: y1 = 1 )
y2 = 2 * t * y1 ( Solution: y2 = 2 t )
y3 = integral(y2) { max: 7.5 * y2 / t } ( Solution: y3 = t 2 { max: 15 } )
y4 = deriv(y3) * (y2 < 4)
+ 2 * t * (y2 >= 4) ( Solution: y4 = 2 t )
y5 = sum(y3 + y2 - y4) ( Solution: y5 = t 2 { max: 15 } )
letting the USE statement call a different instance of the model for each value
of the loop variable i.
The use directives are described in the section "Using a model".
It could also be called from the model in which it is defined, using the reserved
instance identifier self:
self.reset_integral(expression)
where normalized is the name of a procedure defined, in this case, in the same
model.
3. WRITING EXPRESSIONS
If the variable is an array, we can refer to a single element of that array by also
indicating its index in the form of an expression:
name[expr]
- the constants:
global constants the pre-defined constants pi, inf, true, false, etc...
constants the declared constants of the model
data the declared parameters of the model
- the variables:
Here are the rules of reference, defining what elements are visible in what
parts of a model:
global constants visible in any expression
constants visible in any expression
data visible in any expression, except in a CONST
declaration
variables of any not visible in constant-valued expressions, such as:
type - array index in any declaration
- value of a constant or data
- directives of interpolation degree and delay cells
- array dimensions of foreign models and functions
FOR arguments visible only inside the FOR loop where they are
defined
function visible only inside the statement function where they
arguments are defined
Names used in any other expressions inside a USE statement are taken to be
references to elements of the local model (calling model), not of the used
model.
For example, let's suppose there is a data n defined in both the local model
and the used model (and carrying different values, of course). In a USE
But if the name n is used in an expression on the right-hand side (for example,
defining the assigned value of an input), it would be referring to the value n of
the local model, not of the used model:
USE ...
INPUT a[1..n]:= 2*n*(t-2)
Specifying the context of the named elements we are referring to inside a USE
statement is not a simple matter. The present set of rules allow us to use an
implicit notation. These rules do satisfy most applications, but we can always
find examples where it would be useful to do just the opposite of what the rule
says. For example, it would be useful to write
USE ...
INPUT a[1..n] := b[1..n]
or
USE ...
INPUT i1 := ...
i2 := 2*i1
The only way we can do the first one, according to the above rules, is if n is a
name defined in the local model, not the used model. And the present set of
rules doesn't allow the second example.
The alternative to implicit notation would be to use an explicit notation, that is,
an indication that tells directly if a name belongs to the local model or to the
used submodel, either with a keyword or an operator, for example:
USE ...
INPUT a[1..sub.n] := b[1..sub.n]
or
USE ...
INPUT i1 := ...
i2 := 2*sub.i1
This is not available yet, but it will become available in the future.
Note that this potential ambiguity of names exists only inside a USE statement,
and only when the same name is used for different purposes in both the local
model and the used submodel. It might be tempting to avoid the problem
altogether by not duplicating names in the two models. In a small project, this
is easy to do. But when we start building libraries of models, we need the
flexibility of being able to define names without worrying about their use
somewhere else, that is, we need a local name space for each model, which is
one of the principles on which MODELS is designed.
where status is the name of a procedure defined in a submodel used with the
instance name controller, and normalized is the name of a procedure called
from the same model where it is defined.
The above sequence also shows the default order of precedence among the
operators. Here are some examples:
a AND b OR t-ton>0 -- = (a AND b) OR ((t-ton)>0)
a*b-c/d**2 -- = (a*b) - (c/(d**2))
sequence is found to be true, the rest of the sequence is not evaluated, and
the returned value is true.
In the above example, the minimum is applied to the result of the complete
expression, not to the value of b.
It is possible to apply limits to part of an expression, by enclosing that part in
parenthesis, thus making it a separate expression to which a limit can be
applied:
a*(3*b +c {min: ... , max: ... })
In this example, the limits are applied to the value of 3*b+c. Again, notice that
the limit is applied to the complete expression to which it is attached, not to the
last member of that expression. Here, the expression is not applied to c.
Additional parentheses can be used to make this more explicit:
a*((3*b +c) {min: ... , max: ... })
Functions and procedures can receive lists of values and arrays as arguments,
and can return lists of values in the form of an array. See the respective
sections for details.
To express the bias term a0, a coefficient without a variable, we write that
coefficient followed by an "applies to" operator followed by no variable, to
prevent that coefficient to simply be included in the expression of the
coefficient of the next term.
sum((a+b)| +(b+c*d)|x1 + c|x2)
because, without that first operator, the expression would be interpreted as:
sum((a+b)+(b+c*d)|x1 + c|x2)
The linear sum can also be used outside of a COMBINE statement, but without
any advantage over simply using a regular expression.
Minimum and maximum limits can be attached to this expression, and also to
the value of each of its coefficients. For example:
sum((b+c*d){max:a1max}|x1 +c|x2) {min:minvalue, max:maxvalue}
Minimum and maximum limits can be attached to this expression, and also to
the value of each of its coefficients. For example:
derivpol((b+c*d){max:a1max}|D1 +c|D2)|x {min:minvalue, max:maxvalue}
That value can also be reset, using the integral assignment statement:
integral(x) := new_value
The integral of x with respect to time is calculated using the trapezoidal rule,
with the assumption that x is linear over each step interval.
x1 + x0
Δintegral = ⋅ Δt
2
This is a reasonable assumption to make when the time step is small enough
to follow the faster variations of x with respect to time. In cases where the time
step is too large, these faster variations are simply filtered out of the integral
value, with a possible loss of accuracy, but without consequences on the
numerical stability of the calculation.
To only apply a static limit, that is, a limit that affects only the value of the
output, not the state of the integral, we apply the limit outside the use of the
integral:
y := integral(x)
y := y {min:expression, max:expression} -- static limits
HISTORY x {dflt: 0}
y {dflt: 0}
integral(x) {dflt: 0}
integral(y) {dflt: 0}
EXEC
x:= 1
IF t>1 THEN x:= -1 ENDIF
y:= x
dlim :=integral(x) {dmax: 0.7}
nolim :=integral(y)
slim :=nolim {max:0.7}
ENDEXEC
ENDMODEL
The values of the variables x, nolim, slim, and dlim are shown in the following
figure:
It is possible to define local limits, minimum and maximum, on the size of the
local time step to be used for the step-by-step solution of a model. The
implications of updating a model at a smaller or larger time step than the one
used outside the model, are discussed in the section on "Pre-defined local
variables", in Appendix C.
When a model is called from outside for updating its internal state to a new
simulation time, the interval of time since the last call for update determines
the step that the model could take to carry on its operation. But this outside
step may not be properly scaled to the fineness of representation needed to
follow the internal dynamic operation of the model, being either too large or too
small. By specifying a minimum and/or a maximum limit on the size of the time
step, we can maintain it within an appropriate range.
If the outside time step is too large for the model, that is, larger than the
specified maximum, the model will subdivide the outside step into finer internal
steps. If the outside time step is too small for the model, that is, smaller than
the specified minimum, the model will ignore the request for update, which
would provide no significant change in the state of the model.
The expressions used for describing these limits can make reference to the
value of any variable in the model, providing the possibility to dynamically
adjust these limits, and consequently the size of the time step, to changing
conditions monitored in the operation of the model.
Typically, the size of the time step would be maintained between 1/100 and
1/10 times the size of the smallest time constant of the model. A finer step
would be a waste of execution time. A larger step would affect accuracy.
When the time step size is limited to a maximum value, and the outside step
exceeds that value, the model will select a local time step that is a sub-multiple
of the outer time step, and that fits inside the allowed limit. But when this
happens, we don't have values for the external inputs to the model at those
intermediate time steps.
We use the input interpolation directive to specify what method of interpolation
will be used for estimating the value of the inputs at the sub-steps. The
directives are flexible. We can select different methods for different inputs. A
default method can also be specified. Also, the method specified in the model
definition can be modified later in the USE statement of individual instances of
the model.
The degree of the fitting polynomial can be specified as 0, 1, or 2, for step,
linear, and quadratic interpolation, respectively. When not specified, linear
interpolation is used.
Step interpolation is no interpolation, that is, for all times ti between t-Δt and t0,
y(ti) keeps the value y(t-Δt).
Linear interpolation uses a straight line between the values y(t-Δt) and y(t).
Quadratic interpolation uses the values y(t-2Δt), y(t-Δt), and y(t) to fit a
parabola used for finding the values of y(ti) between t-Δt and t.
The following notation is used:
INTERPOLATION DEGREE DFLT: 0
DEGREE(y1, y2): 1
DEGREE(y3): 2
Many functions of MODELS require past values of a variable for calculating the
value of the function, for example, derivatives and integrals. The storage
needed for recording these past values is taken care of automatically by the
solver. This can be easily determined by the solver, because the storage
window is never much longer than two or three cells back depending on the
level of interpolation needed.
Such is not the case for the delay() function. The size of the storage needed
for recording the past values of a variable to be accessed by a delay() function
depends on what size of delay will be used, and on the size of the time step at
which the samples are recorded. For example, a delay value of 500 ms, in a
simulation using a time step of 1 ms, would require 500 cells of storage for that
variable. And this estimation is not necessarily so simple, considering that both
the size of the delay used and the size of the time step can be described in the
form of symbolic expressions, the value of which may vary dynamically during
a simulation.
Choosing to store all past values in order to avoid having to specify any
storage dimensions is not a practical alternative either. This has been tried in
earlier versions of MODELS, for use with the function pastval(). The storage
needs can be considerable, and require paging from memory to external
storage, a process that consumes more execution time, especially when
considering the fact that most of those past values are never used.
The present approach is to provide a simulation directive, in the model
definition and/or in the USE statement, indicating how many cells must be
reserved for storing a moving window of past values for each variable
accessed by a delay() function.
Typically, the expression specifying the number of cells will include a reference
to the size of the time step used in the model. It must be understood, however,
that this expression is evaluated only once when each instance of the model is
created, and that the size cannot be adjusted later. A reference to the variable
timestep would be using the value of that variable at the time when it is used,
that is, at the time when the instance of the model is created and initialized.
As a footnote, specifying the number of cells is also the approach that was
used in TACS, although in a different form. For each delay device (type 53),
we have to specify the maximum delay time for which the device will be used.
Specifying the maximum time delay in MODELS would not suffice, because
the timestep can also vary.
The following notation is used:
DELAY CELLS DFLT: max(delay1, delay2)/timestep +1
CELLS(y1, y2): 50
CELLS(y3): 10
and the DELAY keyword can also be repeated. When a default value is not
specified, a default value of 100 cells will be used.
started, or when needing pre-simulation values for the first few evaluations of a
laplace(), diffeq(), deriv(), etc.
The other type of reference is one that can be written explicitly in the model
description in any expression. Two functions are available for this. One is
histval(y,t1) which will use the history expression of variable y to evaluate y(t1).
The other is histdef(y), which is equivalent to writing histval(y,t) for the generic
value of time t.
To understand the need to specify history functions, consider, for example,
using a delay function which would make reference to the past value of a
variable for a time preceding the time of the first execution of that model
instance, as in
y := delay(x, delaysize)
As shown here, the history expression may include a reference to the variable
t. When no expression is specified, the directive indicates that a history
expression will be needed for that variable in the USE statement of each
instance where the model is used.
then there may not be enough values in the list to cover the size of the group.
The solution for this is to declare only the names in the model definition:
HISTORY y[n1..n2]
and to specify the history expressions in the USE statement, where the
number of required values will be known:
HISTORY y[n1..n2] := [expr1, expr2, expr3, ... ]
5. USING A MODEL
As discussed in the section about writing a model, data are constant values of
a model, such as parameters and array dimensions, defined when a new
instance of a model is created in a USE statement. The same data name can
carry different values in different instances of the same model.
Data values are assigned in a USE statement using the following notation:
USE modelname AS instance_name
DATA n :=3 -- an array dimension used in the model
freq := 60 -- overriding a default value of 50
...
ENDUSE
A data element that had been assigned a default value in the model definition
does not need to be specified in the USE statement. But if it is, the new value
will replace the default value of the model definition.
An input element that had been assigned a default value in the model
definition does not need to be specified in the USE statement. But if it is, the
new value will replace the default value of the model definition.
The only values of a model that are visible to a calling model in a USE
statement are the values of the model's outputs. The values of the outputs of a
model can be assigned to variables of the calling model, using an output
assignment inside a USE statement, as shown below:
USE modelname AS instance_name
DATA n := 3 -- number of terminals
INPUT vterm[1..3] := [va,vb,vc] -- value of measured terminal voltages
vref := sqrt(3)*abs(v0) -- reference voltage, replacing default value
OUTPUT vmax[1..3] := vtmax[1..3]
maxval := vmax
...
ENDUSE
The simulation directives of a model are the limits on the time step size, the
interpolation method used for different inputs of the model during sub-steps,
the number of delay cells to allocate for the storage of the past values of
some variables and inputs, and the history expressions to associate with
some variables and inputs of the model.
Simulation directives can be specified in the model definition and in the USE
statements. In the model definition, they apply to all instances of the model. In
the USE statements, they can be defined individually for each instance,
possibly replacing the default directives of the model definition.
The formats are similar to those used in the model definition, with the
difference that for history expressions, just as for data and inputs, the
assignment operator ":=" is used instead of the "dflt:" attribute.
TIMESTEP MAX: 1E-4
MIN: 1E-5
It is possible to call a model for update from a USE statement more than once
per simulation time. This is needed when a model is used by another model or
program from inside an iteration loop. It requires that the solver be able to
reset the state of the called model to its previous original state from which to
execute the model again. This is done automatically by the program when
using the option ITERATE in a USE statement.
The ITERATE is indicated just after the instance name, as follows:
USE modelname AS instance_name ITERATE
This option indicates to the solver that the model can be used more than once
at each time step, for example when called from inside an iteration loop. When
this option is specified, MODELS saves the initial state of the model when
called at a new time step, and re-starts from that saved initial state at each re-
update of the model at the same time step.
The following data case provides a simple illustration.
MODEL iteruse
MODEL sub EXTERNAL
VAR a
EXEC
FOR i:=1 TO 3 DO
USE sub AS sub ITERATE
INPUT in:=i*t
OUTPUT a:=out
ENDUSE
write('in iteruse at t=', t, ', a=', a)
ENDFOR
write(' ')
ENDEXEC
ENDMODEL
MODEL sub
INPUT in
OUTPUT out
VAR out
EXEC
out:=10*in
write('in sub at t=', t, ', in=', in, ', out=', out)
ENDEXEC
ENDMODEL
Notice how it is the same instance of the model that is re-updated for each
value of i inside the FOR loop. If we did not indicate the keyword ITERATE, the
program would create separate instances of that model for each pass, and the
instance names would need to be indexed, as:
This section covers the details of using MODELS in ATP. We use the words
MODELS section to refer to the section of an ATP data case containing the
declarations and directives related to defining and using one or more models in
a simulation. All models used in a simulation are defined in the MODELS
section. When a model is used as a control-type component, its use is also
specified in the MODELS section in a USE statement. When a model is used
as a circuit-type component, its use is specified directly in the circuit, using a
type-94 nonlinear component. Models can also be used in ATP for
performing calculations in the frequency domain, when conducting
FREQUENCY SCAN simulations.
When we have one or more models in an ATP data case, we need to define a
MODELS section. It is placed before the branch section, if any, and after the
TACS section, if any.
When we use the MODELS section in conjunction with a circuit, we assemble
the data case as follows:
BEGIN NEW DATA CASE
...
MODELS
INPUT ...
OUTPUT ...
VAR ...
MODEL ...
MODEL ...
...
USE ...
USE ...
...
RECORD ...
ENDMODELS
circuit description ...
plotting instructions ...
BEGIN NEW DATA CASE
BLANK
For a voltage, we just identify the name of the node. For a current, we identify
the switch (the only way to measure a current in ATP) by its branch name, or
by the name of a node to which it is connected. We do the same for a switch
status.
During the simulation, the values of voltages and currents are calculated in the
time domain. But in the steady-state phasor solution, both real and imaginary
parts of a voltage or current are available. At simulation time t=0, the real part
of the complex value is carried in the regular v() and i(), and the imaginary part
in imssv() and imssi().
For a machine value, we use the variable names identified in the description of
the machine.
When the inputs expected by a model are in the form of an array, we declare
them as individual input variables in the MODELS section, and we pass them
to the model in array form, as illustrated below:
MODELS
INPUT va {v(NODEA)}
vb {v(NODEB)}
vc {v(NODEC)}
...
MODEL test
INPUT v[1..3] -- phase-phase
...
ENDMODEL
...
USE test AS example
INPUT v[1..3] := [va-vb, vb-vc, vc-va]
...
where:
- this is the same request as when using POSTPROCESS PLOT FILE with
TACS
- MULPPF defines in what multiple the original plot points will be used
- 1 means all points will be used, n means every nth point is used
- if using a multiple, adjust the time step accordingly to keep the
simulation synchronized with the PL4 data
- LUNPPF indicates the I/O unit allocated to the connection
- if left blank, a default value of 63 is assigned
- selecting a different unit may conflict with units already used by ATP
- L63TYP indicates the type of formatting of the PL4 file
- if left blank, a default value of 1 is assigned
- 1=UNFORMATTED, 2=FORMATTED, 3=C-LIKE
2) before the MODELS section, open the ATP connection to the existing PL4
file:
$OPEN, UNIT=63 FILE=dc45.pl4
3) in the MODELS section, specify any number of signals from the PL4
file as inputs to MODELS:
INPUT gen {PL4(1)}
curr {PL4(2)}
where:
- gen and curr are arbitrary input names of the MODELS section
- PL4 is the input type
- 1, 2, etc indicate the corresponding curve number in the PL4 file
The 3rd subcase of benchmark case DC46.DAT illustrates the use of PL4
values as input to the MODELS section:
BEGIN NEW DATA CASE
C BENCHMARK DC-46
C 3rd of 3 subcases produces the same solution, but illustrates the new
C connection to a plot file from MODELS. Just like with TACS, first line
C of plot data at time t=0 is ignored. It is not required to use MODELS
C as STAND ALONE, but can also be mixed with solution of a circuit.
POSTPROCESS PLOT FILE 2 63 3
$OPEN, UNIT=63 FILE=dc45.pl4 ! { Expected to be C-like (L4BYTE = 1)
C deltat tmax
.000100 .050 { Note DELTAT is twice that of DC-45, since use every 2nd step
C print points connec s-s minmax vary again plot
1 1 0 0 1 -1 0 2
5 5 20 20 50 50
MODELS STAND ALONE
INPUT gen {PL4(1)}, curr {PL4(2)}
MODEL postprocess_example
INPUT voltage, current
VAR flux, energy, power, gen_1
INIT
integral(voltage) := 0
integral(power) := 0
histdef(voltage) := 0 -- needed for the delay function
ENDINIT
EXEC
flux := integral(voltage)
energy := integral(power)
power := voltage * current
gen_1 := delay(voltage, timestep)
ENDEXEC
ENDMODEL
USE postprocess_example AS test
INPUT voltage := gen, current := -curr
ENDUSE
RECORD gen AS gen curr AS curr
test.power AS power test.flux AS flux
test.gen_1 AS gen_1 test.energy AS nrg
ENDMODELS
BLANK card ending plot cards
BEGIN NEW DATA CASE
BLANK
indicating that the TACS variable named signal would be available in the
MODELS section under the name somename.
When both TACS and MODELS are used in a data case, the TACS section
precedes the MODELS section:
BEGIN NEW DATA CASE
...
TACS HYBRID
...
BLANK card ending TACS section
MODELS
...
ENDMODELS
circuit description ...
During the simulation, the order of execution at each time step is:
- circuit solution
- TACS section solution
- MODELS section solution
The following subcase of benchmark case DC30.DAT illustrates the use of
TACS variables as input to the MODELS section:
BEGIN NEW DATA CASE
C 4th of 4 subcases is the same as the first and the third, except that
C it uses both TACS and MODELS. The voltages BUS2 and BUS3 are input to TACS.
C VSW is output from TACS and input to MODELS. GRID is output from MODELS.
C Compare values at t=0 with 3rd subcase.
C deltat tmax xopt copt epsiln tolmat tstart
1.0E-6 3.0E-3
C print points connec s-s minmax vary again plot
1 1 0 0 1 -1
5 5 20 20 100 100
TACS HYBRID
1DUMMY +UNITY
1.0
1.0 0.5E-3
90BUS2
90BUS3
99VSW = BUS2 - BUS3
33BUS2 BUS3 VSW
BLANK card ends all TACS data
C ==============================================================================
MODELS
INPUT deltav {TACS(vsw)}
OUTPUT grid
MODEL dc30
INPUT dv
VAR grid
OUTPUT grid
EXEC
IF abs(dv)>=1.5e8*t +1e5 THEN grid:=1 ELSE grid:=0 ENDIF
ENDEXEC
ENDMODEL
USE dc30 AS dc30
INPUT dv:=deltav
OUTPUT grid:=grid
ENDUSE
RECORD
dc30.dv AS dv
ENDMODELS
C ==============================================================================
GEN BUS1 15.
BUS1 2.9
BUS1 BUS2 0.1
BUS2 0.1
BUS3 .017
BUS3 490.
BUS2 BUS2R 24.34
BUS3 BUS3R BUS2 BUS2R
BLANK card terminates electric network branches
BUS2 BUS3 -1. 1.E9
NAME: Valve ! { Request "NAME: " of cols. 3-8 precedes A6 valve name in 9-14
11BUS2R BUS3R 20. GRID 12
BLANK card ends all switches
14GEN 66500. 50. -2.0508 -1.
BLANK card terminates electric network sources
{ No node voltages printout/plotting
BLANK card ending node voltage request
BLANK card ending plot cards
BEGIN NEW DATA CASE
BLANK
Another way to have access to internal variable values of the ATP program is
to use the special function atp() in an expression inside a model description.
This provides the added advantage of being able to also access elements or
array variables used in the ATP program, which is not possible in the INPUT
declarations of the MODELS section.
MODEL example
...
EXEC
...
step := atp(istep) -- value of ATP variable 'istep'
estimated_voltage := atp(voltk[2*index]) -- value of element of array 'voltk'
...
ENDEXEC
ENDMODEL
MODEL atpvar
VAR step
EXEC
write('*** e(2) = ', atp(e[2])) -- write value of ATP variable e(2)
write(' e(3) = ', atp(e[3])) -- write value of ATP variable e(3)
step := atp(istep) -- get value of ATP variable 'istep'
IF step=4 THEN
deposit(tmax, 0.0095) -- modify value of ATP variable 'tmax'
ENDIF
ENDEXEC
ENDMODEL
RECORD atp_t AS t
example.step AS istep
tmax AS tmax
ENDMODELS
C ==============================================================================
A1 A2 1.
A2 1.
BLANK card ending electric network branches
BLANK card ending switches
14A1 100. 50. -1.
BLANK card ending electric network source cards
BLANK card ending voltage printout requests
BLANK card ending plot requests
BEGIN NEW DATA CASE
BLANK
The names of these outputs are stored and used by ATP, and are therefore
limited to the 6-character naming convention of ATP. Also, no arrays can be
used, only single outputs.
There is a difference between declaring a MODELS variable as output to the
circuit, and specifying a variable to be recorded for printout and plotting during
the simulation. The latter is done using a RECORD directive, discussed in a
separate section below. Variables declared as outputs of the MODELS section
are not automatically recorded for printout or plotting, unless they are also
included in the RECORD directives of the MODELS section.
No modifications have been made to the format rules of ATP branches,
switches, sources, and machines regarding the use of control variables from
TACS or MODELS. In either case, the keyword TACS used on these cards
indicates control variables coming from a "control system" described outside
the circuit, using either TACS or MODELS, without distinguishing between the
two.
Another type of output to ATP can be made directly from inside a model. The
deposit() procedure allows a model to modify the value of any numerical
program variable of ATP that can be changed using ATP's SPY command
DEPOSIT. The ATP documentation of the SPY commands describes what
variables can be modified.
The deposit() procedure can be used to modify the value of single variables
and of single or multiple elements of array variables of the ATP program, using
the following notation:
DEPOSIT( name, value )
DEPOSIT( name[ expr ] , value )
DEPOSIT( name[ expr .. expr ] , value )
where name is the name of a program variable accessible from SPY, and
where the index of the array elements can be specified using regular
expressions. An illustration is included in the example used in the previous
section.
The names of these variables are stored and used by ATP, and are therefore
limited to the 6-character naming convention of ATP. Also, no array variables
can be used, only single variables.
Values are assigned to these variables in the USE statements of the MODELS
section, on the left-hand side of the output assignments, receiving values from
the outputs of the used models. Note that the outputs of the MODELS section
can also be used for the same purpose as the variables.
The first example adds to the printout list, identified in the list as "MODELS -
CTRL", the value of an element named control, from a model used at the top
level of the MODELS section with the instance name controller_A.
The second example adds to the printout list, identified as "MODELS -
FIELD1", the variable field from a model used as subuse in a model with
instance name top.
The third example adds to the printout list, idendified as "MODELS - SRC1",
the element named source1 defined as a variable or input or output of the
MODELS section. Note that no instance name is needed in the path, because
the element source1 exists at the top level of the MODELS section, outside of
any model instance.
The fourth example adds to the printout list, with the label "MODELS - RS", the
element named r from the model named limr used by a type-94 component
connected to the circuit between nodes SRCE and CT1.
Non-existing instance names found in a record path don't trigger an error,
because an instance name starts its existence only at the instant of the
simulation when the associated instance of the model is first used, which is not
necessarily at the initial time of the simulation. It is therefore not an error for
the program to not find a given instance name, as it may simply not have been
yet created in the simulation. The only way to provide a clear indication that
the record has an undefined value would be to be able to assign it the value
"undefined", something like minus zero. And of course we cannot use the
undefined value from MODELS (=88888.88888) because it would affect the
scale limits of a plot if we used that value until the time an actual value starts
being assigned to the variable.
The $INCLUDE command of ATP can also be used to refer to a file containing
a model description, instead of including the full text of the model in the data
case. The example illustrating variables of the MODELS section, above, could
be rewritten in a more simple way using an $INCLUDE command:
MODELS
RECORD atp_t AS t
example.step AS istep
tmax AS tmax
ENDMODELS
In this example, three variables are defined, a1, a2, a3. The foreign model is
declared. One instance of that model is used, identified with the instance name
example. Various values are then recorded during the simulation in the
printout/plotting list of ATP.
To use our own Fortran or C code with ATP, we must link our program with
ATP. The details of this process are dependent on the platform on which we
are running ATP. Typically, we must use the same compiler that the rest of our
version of ATP was compiled on. Then we have to link our compiled file with
the compiled files of ATP using a linker compatible with the compiler(s) that we
have used. For example, for the Salford version of ATP, we can use the
Salford Fortran, C, or Pascal compilers for our routines, and the Salford linker.
It also means that we need all the compiled files of ATP in order to be able to
relink them with the additional files that we create.
When we access a model with a USE statement in the MODELS section, the
model instance that we create interacts with the circuit as a control component.
This is to be compared to the circuit approach available when using a model
with the type-94 circuit element (see a separate section below). The control-
type component receives measurements from the circuit (the inputs), and
sends back control signals (the outputs) to be used in the circuit. In this mode,
ATP performs no iteration. The control signals are simply applied to the
operation of the circuit at the next time step of the simulation.
This is the mode of operation that was also available between the circuit and
TACS. When used for representing true control components, this decoupling,
and its one-step delay, are not a limitation, as any physical control component
will include transmission delays in its operation. This approach can also be
used without problem for representing passive circuit elements in the form of a
Norton equivalent, where the value of the equivalent current source, if present,
is calculated using values of voltages and currents already delayed by one or
more time steps (see the representation of inductance, capacitance, and
transmission lines in ATP).
This forced decoupling will create numerical stability problems when used for
representing circuit components that should be solved simultaneously with the
rest of the circuit. This includes any component for which a Norton equivalent
would use concurrent (as opposed to delayed) values of voltages or currents
to calculate the value of the equivalent source (for example, any type of
voltage- or current-driven voltage source or current source). In this case, it is
necessary to use a type-94 Thevenin or iterated circuit element to connect the
model representing the operation of the component.
The USE statement available in the MODELS section lets us use all features
of the USE statement available inside a regular model (see the section on the
Use statement). This includes assigning data and input values, retrieving
output values, and specifying history expressions, range of time step, input
interpolation methods, and delay cells storage size.
Here is an example where models are used from USE statements in the
MODELS section. The complete data case represents a circuit that uses three
models to describe the operation of a variable source, a variable current-
limiting resistance, and a variable load.
USE limr AS rs
DATA rsmin := 1.0 -- [ohm] source min resistance
ilim := 20 -- [ A ] source max current
INPUT v := srce - vmeas
OUTPUT rs := r
ENDUSE
RECORD rl AS rl
rs.r AS rs
ENDMODELS
C ==============================================================================
91SRCE CT1 TACS RS { Variable limiting resistance
CT2 LOAD 0.1 0.2 { Fixed load R-L
91LOAD TACS RL { Variable load resistance
BLANK card ending branches -----------------------------------------------------
CT1 CT2 MEASURING 1
BLANK card ending switches -----------------------------------------------------
60SRCE { Source driving voltage
BLANK card ending sources ------------------------------------------------------
SRCE CT1
BLANK card ending voltage printout request -------------------------------------
BLANK card ending plot ---------------------------------------------------------
BEGIN NEW DATA CASE
BLANK
RECORD rl AS rl
SRCE__CT1___LIMR__.r AS rs
ENDMODELS
C ============================= Electrical circuit =============================
94SRCE CT1 LIMR ITER { Variable limiting resistance
>DATA RSMIN 1.
>DATA ILIM 20.
>END
CT2 LOAD 0.1 0.2 { Fixed load R-L
91LOAD TACS RL { Variable load resistance
BLANK card ending branches -----------------------------------------------------
CT1 CT2 MEASURING 1
BLANK card ending switches -----------------------------------------------------
60SRCE { Source driving voltage
BLANK card ending sources ------------------------------------------------------
SRCE CT1
BLANK card ending voltage printout request -------------------------------------
BLANK card ending plot ---------------------------------------------------------
BEGIN NEW DATA CASE
BLANK
The included file LIMR-94.M contains the description of the limiting resistance
model, as follows:
Thevenin type-94
input Thevenin voltage source behind Thevenin equivalent
resistance or admittance of the network seen from the
component; if multi-branch, Thevenin source is a vector,
Thevenin resistance is a matrix;
output value of branch current from the component; if multi-
branch, current is a vector;
implementation uses the compensation interface of ATP
usage restricted to one nonlinear component per subnetwork
solution numerical solution is assured (no iteration between ATP
assurance and the type-94 component)
speed faster than iterated, because no iteration is needed;
slower than Norton, because a Thevenin equivalent must
be calculated
Iterated type-94
input most-recent branch voltage value calculated by ATP; if
multi-branch, uses a vector of voltages;
output branch current and branch di/dv calculated by the model;
if multi-branch, current is a vector, [δi/δv] is a matrix;
implementation uses the iteration mechanism of ATP
first time step. This gives us a chance to initialize not only the model, but also
the values of the Norton equivalent that will be used in the circuit at the next
time step, which in this case will be the first time step. Here again, the pre-
defined inputs v0[1..n] and i0[1..n] carry the values of voltages and currents
measured at the end of the steady-state solution, and can be used in a special
section of the EXEC procedure, executed only at time t=0, to properly operate
the model.
To illustrate this last point, compare below the INIT and EXEC procedures of a
simple model representing a constant inductance, built first as a type-94
Thevenin, and next at a type-94 Norton. Notice where the steady-state
measured values of v0 and i0 are used:
Thevenin:
INIT
L := L1 -- initialize variable inductance value
histdef(v) := v0
histdef(i) := i0
ENDINIT
EXEC
COMBINE AS group1
CLAPLACE(i/v) := (1|s0)/(L|s1) -- i/v=1/sL
v := sum(vth| -rth|i) -- sum(a0| +a1|x1)
ENDCOMBINE
ENDEXEC
Norton:
INIT
st:= 2/timestep -- trapezoidal rule conversion from Laplace
L := L1 -- initialize variable inductance value
g := 1/(st*L) -- conductance converted from Laplace 1/sL
ENDINIT
EXEC
IF t=0 THEN
flag := 1 -- conductance values have been changed
i := i0 -- t=0 current through L
is := -i0 -g*v0 -- history term for next step
ELSE
flag := 0 -- reset flag, no more change in g
i := g*v -is -- applying trapezoidal rule, calculate from v(t)
is := -i -g*v -- history term from trapezoidal rule, for next step
ENDIF
ENDEXEC
MODEL m1 -----------------------------------------------------------------------
EXEC
pass:=pass+1
write('************** In models, pass= ', pass)
write(' freq= ', t) -- <<=== <<====
write(' Re{v1}, Im{v1} = ', v_Re_1, ', ', v_Im_1 )
write(' Re{v2}, Im{v2} = ', v_Re_2, ', ', v_Im_2 )
write(' Re{i1}, Im{i1} = ', i_Re_1, ', ', i_Im_1 )
write(' state_1 = ', state_1 )
ENDEXEC
ENDMODEL
USE m1 as m1
INPUT v_Re_1 := v_Re_swit
v_Im_1 := v_Im_swit
v_Re_2 := v_Re_load
v_Im_2 := v_Im_load
i_Re_1 := i_Re_swit
i_Im_1 := i_Im_swit
state_1 := state_swit
ENDUSE
ENDMODELS
C Begin branches ===============================================================
SWIT LOAD 10.
LOAD 1000.
-1SWIT OPEN .3055 5.82 .012 138.
BLANK card ending all branches
GEN SWIT -1.
BLANK card ending all switch cards
14GEN 1.0 0.5 -1.
BLANK card ending source cards
GEN LOAD
BLANK card ends output requests (just node voltages, for FREQUENCY SCAN)
197 .2 0.0 1.6 -20. 60.LOAD angle
BLANK card ending plot cards
BEGIN NEW DATA CASE
BLANK
Two dimensions in the file LISTSIZE.DAT control the size of the storage area
reserved for MODELS in ATP.
list 15: character storage -- needs about 2000 + size of MODELS section
list 28: numerical storage -- integer and real storage of simulation
The user has control on the size of these lists in the file LISTSIZE.DAT, up to
their maximum dimension. In the regular version of ATP, these maxima are
64800 and 126000 respectively. Users requiring storage larger than this must
obtain a version of ATP dimensioned with larger values.
Getting error messages that do not make any sense when using MODELS
may indicate a storage problem. Most cases of memory overflow are reported
with the correct error message, but some cases will create a problem in
another area before being detected correctly.
Most modeling projects involve creating and using a set of basic components,
that can also possibly be re-used in other projects. Using this approach,
assembling a simulation can be reduced to a task of providing the framework
and the logical glue for the use of components gathered out of one's
developed toolkit.
What follows is meant to be used as a starting point for building a library of
various models, functions, and components needed in the simulation projects
that one can consider doing.
or, in fact, doesn't even need a function, because the expression is simple
enough that it can be inserted explicitly in full wherever it needs to be used.
However, a less obvious formulation, like that of the triangular waveform
below, is better described only once in a function definition, and then used as a
function call when it's needed.
The use of a function is possible when the representation of the source is
state-less, that is, doesn't carry history between the times when it is called.
When history is carried, then we need to use a model for describing the
operation of the signal source.
Included below are a few commonly-used signal sources. For those examples,
if turn-on and turn-off times need to be added, this can be easily done on the
outside of the function definition. For example, to have a source operating
between t>=t_on and t<t_off, one would use ramp_train(), for example, as:
signal := (t >= ... AND t < ...)*ramp_train(100, 1e-4, 0)
where the value of the logical expression is taken as numerical "1" when the
expression is true, and zero otherwise, multiplied by the rest of the expression.
Refer to the sample model "test_sources" below to see how this and the
following functions can be used.
The next example is simplified when using a function call. It is easier to call the
function with its four arguments, than to have to figure out how to use the
modulo operator each time the signal needs to be generated. The function
generates a sequence of pulses of a specified amplitude, width, and period,
with the beginning of the reference period (the phase, in seconds) shifted to a
specified time:
FUNCTION pulse_train(ampl, width, period, tshift)
:= ampl*(((t-tshift+period) MOD period) < width)
comment ---------------------------------------------------
| ampl : [ ] on-value of each pulse (off-value is 0) |
| width : [s] width of each pulse |
| period : [s] period of each pulse (on_time + off_time) |
| tshift : [s] period shift time |
| the beginning of the period is shifted by "tshift" sec |
| each pulse is on for "width" seconds |
| pulses are repeated every "period" seconds |
------------------------------------------------ endcomment
The next function shows a simple ramp of specified maximum amplitude and
width, starting at a specified starting time:
FUNCTION single_ramp(ampl, width, tstart)
:= ampl/width*(t-tstart)*(t>=tstart AND t<tstart+width)
comment --------------------------------------------
| ampl : [ ] amplitude of ramp |
| width : [s] width of ramp |
| tstart : [s] ramp start time |
| ramp starts at t=tstart and lasts "width" seconds |
----------------------------------------- endcomment
The next function generates a train of ramps of specified amplitude and width,
with the beginning of the reference period (the phase, in seconds) shifted to a
specified time. In this example, there is no dead zone, and the period is equal
to the width:
FUNCTION ramp_train(ampl, width, tshift)
:= ampl/width*((t-tshift+width) MOD width)
comment ---------------------------------------------------
| ampl : [ ] amplitude of ramp |
| width : [s] widthor period of each ramp |
| tshift : [s] period shift time |
| the beginning of the period is shifted by "tshift" sec |
| each ramp is on for "width" seconds |
| ramps are repeated every "width" seconds |
------------------------------------------------ endcomment
argument is calculated once when calling the function, and is used many times
inside the function. That value is specified as the expression:
(t - tshift + period) MOD period
using values for a specified period and shift time.
FUNCTION triang(ampl, per, tmodT)
:= ampl*4/per*((tmodT/per<0.5)*(-tmodT+0.25*per)
+(tmodT/per>=0.5)*(tmodT-0.75*per))
comment ------------------------------------------------------------
| ampl : [ ] amplitude of triangular waveform |
| per : [s] period of waveform |
| tmodT : [s] pre-calculated value of (t-tshift+period) MOD period |
| where tshift : [s] period shift time |
| the beginning of the period is shifted by "tshift" sec |
| value at start of period is positive maximum, like cosine |
--------------------------------------------------------- endcomment
ENDEXEC
ENDMODEL
-------------------------------------------------------------------- Model uses:
USE test_sources AS test
ENDUSE
----------------------------------------------------- Printed/plotted variables:
RECORD test.pulse AS pulse
test.pulsetrain AS pulset
test.ramp AS ramp
test.ramptrain AS rampt
test.tri AS tri
ENDMODELS
C ==============================================================================
BLANK card ending plot requests
BEGIN NEW DATA CASE
BLANK
comment ---------------------------------------------------------------
| operations on complex numbers using polar coordinates |
| where a[1..2]=[am,aa]: am=magnitude of A, aa=angle of A in radians |
| and b[1..2]=[bm,ba]: bm=magnitude of B, ba=angle of B in radians |
| |
| complex polar multiplication, division, powern, rootn |
------------------------------------------------------------ endcomment
These functions are ready to be used in a model. For example, given the real
variable r, and the array variables c, d, e, f, where:
c[1..2] with c[1] = real part, c[2] = imaginary part
d[1..2] with d[1] = real part, d[2] = imaginary part
e[1..2] with e[1] = magnitude, e[2] = angle in radians
f[1..2] with f[1] = magnitude, f[2] = angle in radians
The control system devices available in TACS can also be described using
MODELS. Some can be expressed using nothing more than an expression.
Others need their operation expressed using a more elaborate algorithm.
Together, they illustrate a good cross-section of the features of the MODELS
language.
When the condition is true, the function returns the value input * 1 . When the
condition is false, the function returns the value input * 0 .
When the condition is true, the function returns the value input * 1 . When the
condition is false, the function returns the value input * 0 . Functions like this
one are so simple that it is as easy to use the expression directly in a model as
it is to create and call a function.
Long models like this one would execute faster by being pre-compiled. One
approach would be to write it in C or in Fortran, and link it with ATP. Then, all
we need to put in this library is the following, replacing the above INIT and
EXEC procedures of the model by a call to the foreign model.
MODEL pulse_delay
DATA ton_ini {dflt:-9999} -- initial value of pulse beginning time
toff_ini {dflt:-9999} -- initial value of pulse ending time
INPUT x -- input signal
delay_val -- variable delay value
VAR out -- delayed pulse
MODEL compiled_pulse_delay FOREIGN C_pulse_delay
{ixdata:2, ixin:2, ixout:1, ixvar:4}
EXEC
USE compiled_pulse_delay AS pdelay
DATA xdata[1..2] := [ton_ini, toff_ini] -- this is array notation
INPUT xin[1..2] := [x, delay_val] -- just loading the values
OUTPUT out := xout[1] -- and retrieving the output
ENDUSE
ENDEXEC
ENDMODEL
This function is then used with the interpolation degree set at zero, resulting in
level steps between the defined points on the line:
y := digitizer( signal, 0)
and using the function with the default interpolation degree of one:
y := point_by_point( signal)
y := signal * time_seq_switch(t)
One may wonder why the above expression did not use the built-in function
deriv() of MODELS as follows:
y := gain * deriv(x)
MODEL sample_hold
DATA out_ini {dflt:0} -- initial value of out
INPUT x -- sampled signal
sample_control -- triggers sampling on rising positive front
VAR out
state -- 0= waiting for control>0
-- 1= waiting for control<=0
OUTPUT out
INIT
state := 0
out := out_ini
ENDINIT
EXEC
IF state = 0 AND sample_control > 0 THEN state:=1 out:=x
ELSIF state = 1 AND sample_control <= 0 THEN state:=0
ENDIF
ENDEXEC
ENDMODEL
The track/hold device passes the value of the input signal when the control
signal is positive, and holds its most recent value when the control signal is not
positive. The only reason why this device needs to be represented as a model
rather than as a function is that we need to carry a value from one time step to
the next, the value last-held by the output variable.
MODEL track_hold
DATA out_ini {dflt:0} -- initial value of out
INPUT x -- tracked signal
track_control -- tracks when positive
VAR out
OUTPUT out
INIT
out := out_ini
ENDINIT
EXEC
IF track_control > 0 THEN out:=x ENDIF
ENDEXEC
ENDMODEL
Notice that we do not need to specify an ELSE clause in the IF statement. The
complete IF statement could be written as:
IF track_control > 0 THEN out:=x
ELSE out:=out
ENDIF
but by default, any variable of a model maintains its value until it is changed to
another value, so writing out := out is redundant.
The track/hold model can be used as follows:
where each argument can be an entire expression, not only the name of a
variable, just as for any function in MODELS except the built-in simulation
functions (deriv, prevval, etc.).
MODEL mintrack_hold
DATA out_ini {dflt:inf} -- initial value of out, defaulted to +infinity
INPUT x -- tracked signal
hold_control {dflt:0} -- holds when positive
reset_control {dflt:0} -- resets when positive
reset_value {dflt:0} -- used on reset
VAR out
OUTPUT out
INIT
IF out_ini = inf THEN out := x
ELSE out := out_ini
ENDIF
ENDINIT
EXEC
IF reset_control > 0 THEN out:=reset_value
ELSIF hold_control <= 0 THEN out:=min(x,out)
ENDIF
ENDEXEC
ENDMODEL
There are two details to notice. First, the reset control signal has priority over
the hold control signal. The second is that we do not need to specify the third
clause of the IF statement to indicate that the output value maintains its value
when the two other conditions are not true, as this is done by default.
This model can be used as follows:
USE mintrack_hold AS somename
DATA out_ini := ________ (optional)
INPUT x := ________
hold_control := ________ (optional)
reset_control := ________ (optional)
reset_value := ________ (optional)
OUTPUT _____________ := out
ENDUSE
The maximum track/hold model is similar, except for the value of the initial
condition:
MODEL maxtrack_hold
DATA out_ini {dflt:-inf} -- initial value of out, defaulted to -infinity
INPUT x -- tracked signal
hold_control {dflt:0} -- holds when positive
reset_control {dflt:0} -- resets when positive
reset_value {dflt:0} -- used on reset
VAR out
OUTPUT out
INIT
IF out_ini = -inf THEN out := x
ELSE out := out_ini
ENDIF
ENDINIT
EXEC
IF reset_control > 0 THEN out:=reset_value
ELSIF hold_control <= 0 THEN out:=max(x,out)
ENDIF
ENDEXEC
ENDMODEL
MODEL rms_meter
DATA freq -- base frequency
xrms_ini {dflt:-1} -- initial rms value
INPUT x -- monitored signal
VAR xrms -- rms value of monitored signal
x2 -- internal, x*x
ix2 -- internal, integral of x2
period -- 1/freq
OUTPUT xrms
DELAY CELLS(ix2): 1/freq/timestep +1
INIT
period := recip(freq)
histdef(ix2) := 0
integral(x2) := 0
IF xrms_ini <0 THEN xrms:=0 ELSE xrms:=xrms_ini ENDIF
ENDINIT
EXEC
x2 := x*x
ix2 := integral(x2)
IF t>period THEN
xrms := sqrt((ix2 - delay(ix2, period))/period)
ENDIF
ENDEXEC
ENDMODEL
Using a pre-determined fixed period keeps the model simple. A more complete
rms meter would allow for variable period and arbitrary dc bias.
The above model can be used as follows:
USE rms_meter AS unique_name_in_your_model
DATA freq := _______ in Hz
xrms_ini := _______ (optional)
INPUT x := _______ in any units
OUTPUT ________ := xrms
ENDUSE
record element
declaration in a model
constant element
data element
input element
output element
variable element
function
submodel
declaration of a function
statement function
point list function
foreign function
declaration of a submodel
local model
foreign model
external model
history directive
time step directive
input interpolation directive
delay cells directive
history directive
Procedure in a model
initialization procedure
execution procedure
named procedure
initialization procedure
execution procedure
named procedure
Statement
assignment statement
algorithm control statement
assignment statement
value assignment
differential equation
Laplace transfer function
z transfer function
integral value reset assignment
history assignment
value assignment
differential equation
y, x
D-polynomial
limits
y, x
S-polynomial
limits
z transfer function
y, x
z-1-polynomial
limits
history assignment
IF statement
WHILE statement
FOR statement
DO statement
REDO statement
COMBINE statement
ERROR statement
USE statement
procedure call
IF statement
WHILE statement
FOR statement
DO statement
REDO statement
COMBINE statement
ERROR statement
USE statement
procedure call
instance.procname(arg-list)
WRITE(write-list)
WRITE1(write-list)
WRITE2(write-list)
write-list
Expression
regular expression
sum expression in a value assignment
derivative expression in a value assignment
integral expression in a value assignment
regular expression
regular expression
regular expression { limits }
Regular expression
logical term
logical factor
logical relation
relational operators
numerical expression
numerical term
numerical factor
exponent relation
modulo relation
value reference
numerical value
array value
named value
function value
Value-holding element
single-value element
array-value element
single-value element
array-value element
Syntactic element
name
numerical value
logical value
text value
in-ine comment
block comment
separator
name
numerical value
logical value
text value
"text" or 'text'
in-line comment
block comment
separator
start/end
element declarations
model declarations
use directives
record directives
start/end
element declarations
function declarations
submodel declarations
simulation directives
procedures
assignment statements
... := ...
DIFFEQ( ... ) | ... { DMIN: ... DMAX: ... } := ...
CDIFFEQ( ... ) | ... { DMIN: ... DMAX: ... } := ...
LAPLACE( ... ) | ... { DMIN: ... DMAX: ... } := ...
CLAPLACE( ... ) | ... { DMIN: ... DMAX: ... } := ...
ZFUN( ... ) | ... { DMIN: ... DMAX: ... } := ...
CZFUN( ... ) | ... { DMIN: ... DMAX: ... } := ...
INTEGRAL( ... ) := ...
HISTDEF( ... ) := ...
IF ... THEN ... ELSIF ... THEN ... ... ELSE ... ENDIF
WHILE ... DO ... ENDWHILE
FOR ... := ... ... DO ... ENDFOR
DO ... REDO ... ENDDO
COMBINE AS ... ENDCOMBINE
COMBINE ITERATE AS ... ENDCOMBINE
COMBINE ITERATE { ... } AS ... ENDCOMBINE
ERROR ... STOP
USE ... ENDUSE
instance.procname( ... )
WRITE( ... )
WRITE1( ... )
WRITE2( ... )
Pre-defined constants
The pre-defined constants have pre-assigned values, and can be used inside
any expression, in any model of a simulation. They are:
pi 3.14159...
inf a large number, typically 1020
undefined 88888.88888
false, true the equivalent numerical values 0 and 1
no, yes the equivalent numerical values 0 and 1
open, closed the equivalent numerical values 0 and 1
off, on the equivalent numerical values 0 and 1
The infinity value inf is dependent on the computer platform being used. The
value undefined is the value carried by any variable that has not yet been
assigned a value during a simulation. The value of the logical constants are
represented internally as the numerical values 0 and 1.
Three variables are defined globally in a simulation. They carry the value of the
starting and ending time of the simulation, and the value of time step imposed
by the environment, shell, or application controlling the simulation.
The value of these variables can be accessed by name inside any expression,
in any model of a simulation. They are:
The values of starttime and startstep are set at the start of the simulation. The
value of stoptime is defined by the application controlling the simulation, and
may change during a simulation.
The names of the pre-defined local variables are the same in all models of a
simulation, but their values are local to each instance of each model used in a
simulation.
The value of these variables can be accessed by name inside any expression,
in any model of a simulation. They are:
These variables carry information about how the state of a model is updated
from a previous simulation time to a target simulation time, on each update call
to a model instance from a USE statement.
In a case where timestep, the time step used in the called model, is the same
size as fullstep, the calling interval, which is also the time step of the calling
model, the relationship between these variables is simple:
t0 endtime
fullstep
t
timestep
In a case where fullstep is smaller than minstep, the model instance does not
update itself to the outside time, because the time increase is considered to be
too small to change the present state of the model significantly. The model
waits until endtime - t0 >= minstep to update its state, in one large time step.
t0 endtime
fullstep fullstep fullstep
t
timestep
In a case where fullstep is larger than the largest time step allowed maxstep,
the full step is subdivided into sub-steps of a size that satisfies the maxstep
upper limit, and the model instance is executed for each sub-step
successively, until the target time endtime is reached. Only then is control
passed back to the calling model, along with the model's output values at time
t = endtime. For this case, the relationship between the variables is as follows:
t0 endtime
fullstep
t
Numerical functions
This is a list of all the pre-defined functions that return numerical values. They
are grouped as one-to-one functions, two-argument functions returning a
single value, and n-argument functions returning a single value.
When used with a single argument, these functions return a single output
value. When used with a list of argument values, they return as many output
values, each corresponding to the function being applied to each value
supplied in the argument list.
This is illustrated below using the absolute value function:
abs(a) -- returns one value: the absolute value of a
abs(expression) -- returns one value: the absolute value of the
expression
abs(a, b) -- returns [abs(a), abs(b)]
abs(expression list) -- returns array of absolute values of each list element
abs(x[1..2]) -- returns [abs(x[1]), abs(x[2])]
abs(a, x[1..2]) -- returns [abs(a), abs(x[1]), abs(x[2])]
abs(array expression) -- returns array of absolute values of each array element
These functions always return a single value, and cannot be extended to array
arithmetic as the previous 1-to-1 functions. Each of the two arguments can be
given in the form of a single-value expression, or the two arguments can be
specified together as a two-element array expression. This is illustrated here
using the atan2() function:
atan2(a, b) -- returns one value: arctan(a/b)
atan2(expr1, expr2) -- returns one value: arctan(expr1/expr2)
atan2(x[1..2]) -- returns one value: arctan(x[1]/x[2])
These functions take as input a list of values, and return a single value. The list
of input expressions can include single values and array values. The following
example illustrates how the input values can be specified:
min(a, b) -- returns the minimum value of the two arguments a and b
min(expr1, expr2, ...) -- returns the minimum value of the argument list
min(x[1..2]) -- returns the minimum value of the two args x[1] and
x[2]
min(a, x[1..2]) -- returns the minimum value of a, x[1], and x[2]
min(array expression) -- returns the minimum value of all array elements
Logical functions
This is a list of all the pre-defined functions that return logical values. They are
grouped as one-to-one functions, and n-argument functions returning a single
value.
The logical values true and false are represented in MODELS by the numerical
values 1 and 0. Conversion between numerical and logical values is automatic,
and is determined by the context in which they are used. This allows numerical
values to be used in a logical context ( >0 is true, <=0 is false ), and logical
values to be used in a numerical context ( true is 1, false is 0 ).
There is only one function in this category. It provides explicit conversion from
numerical to logical ("Boolean").
When used with a single argument, it returns a single output value. When used
with a list of argument values, it return as many output values, corresponding
to each value in the argument list.
bool( ) numerical to logical returns true if arg>0, false if arg<=0
These functions take as input a list of values, and return a single logical value.
The list of input expressions can include single values and array values.
Logical values are expected for each argument. If numerical values are
supplied, they are automatically converted to their logical equivalent, using the
same rule as shown above. The following example illustrates how the input
values can be specified:
and(a, b) -- returns true only if a and b are true
and(expr1, expr2, ...) -- returns true only if all argument values are true
and(x[1..2]) -- returns true only if x[1] and x[2] are true
and(a, x[1..2]) -- returns true only if a and x[1] and x[2] are true
and(array expression) -- returns true only if all array elements are true
There is one random value function pre-defined in MODELS at this point. The
function uses no arguments, and returns a value between zero and one:
random( ) random value returns a random value between 0 and 1
Simulation functions
deriv(x)
The time derivative of x is calculated with the assumption that it is linear over
each time step interval, that is, that the second derivative is constant over the
interval. The program first calculates the two mid-step derivatives
x(t 0 ) − x(t1)
deriv0.5 =
t 0 − t1
x(t1) − x(t 2)
. =
deriv15
t1 − t 2
in order to calculate the second derivative at t1:
deriv0.5 − deriv15
deriv 2t1 = .
t0.5 − t15
.
which is then used to extrapolate linearly the first mid-step derivative, deriv0.5,
to the end of the interval, using the second derivative as its slope:
t 0 − t1
derivt 0 = deriv0.5 + deriv 2t1 ⋅
2
When the time step is small enough to cover the higher frequencies of the
signal, this method is more accurate than using the simple mid-step derivative.
However, the mid-step derivative is less sensitive to discontinuities, and should
be used instead of deriv() when the time step is not well matched to the
frequency contents of the signal, by doing:
y:=(x-prevval(x))/timestep
deriv2(x)
The second order derivative of x with respect to time, d2x/dt2, is calculated as
the mid-step derivative of the first derivative, itself calculated at mid-step for
the last two intervals. The method takes into account the possibility for the time
step to be variable.
The second derivative is calculated using:
deriv0.5 − deriv15
.
t0.5 − t15
.
prevval(x)
This function returns x(t-Δt), the value of a variable at the previous time step. It
can be used in any expression, for example:
y:=prevval(x)
Static limits can be applied as part of the expression where the function is
used:
y:=prevval(x) {min:expression, max:expression}
where the value t-dval does not correspond exactly to one of the discrete
instants of the simulation. By default, when the third argument is not specified,
linear interpolation is used. Otherwise, the pol argument can be given a value
of 0, 1, or 2, for step, linear, or quadratic interpolation.
Using the delay function can require a considerable amount of storage for
keeping track of the past values of a variable (see the simulation directive
DELAY CELLS). However, the calculation is fast, as it uses a binary search to
locate the stored values.
When the requested past time falls after the start of the simulation, where
tracked values of the variable are available, interpolation is used for calculating
the value of the variable between the simulation points. By default, when the
third argument is not specified, linear interpolation is used. Otherwise, the pol
argument can be given a value of 0, 1, or 2, for step, linear, or quadratic
interpolation.
histval(x, tval)
This function uses the history expression specified for the variable x in order to
calculate the value of x(tval). No interpolation is needed, because the history
expression will provide a value calculated at t equal to tval. Although a history
expression is intended to be used for calculating values of a variable at values
of t preceding the start of the simulation, the histval() function can be used
without any restriction on the value of tval. See the section on simulation
directives for a discussion on assigning a history expression to a variable.
histdef(x)
Using this function is equivalent to using histval(x,t). For whatever value of t,
this function will return the corresponding value of the history expression
associated with the variable x. At first look, this may seem useless. It becomes
more interesting when we consider that during the simulation, the solver
manipulates the value of the variable t behind the scenes whenever it needs to
evaluate a history expression at a certain time t. Using the function histdef(x)
inside the expression defining the history expression of another variable y
gives us a way to make a history expression dependent on the history
expression defined for another variable. For example, we would use it in a
history declaration as follows:
HISTORY y {dflt: histdef(x) - 2*histdef(w)}
In each case, it would have been equivalent to write the expression of the
history expression as:
histval(x,t) - 2*histval(w,t)
BIBLIOGRAPHY
"Educational use of EMTP MODELS for the study of rotating machine transients",
J.A.Martinez-Velasco (Univ. Politècnica Catalunya, Spain)
IEEE PES Winter Power Meeting, Paper 93 WM 126-3-PWRS,
Columbus (USA), February 1993
"Connection of user-supplied programs to EMTP using MODELS",
L. Dubé (DEI Simulation Software, Oregon, USA)
EMTP News, Vol. 6, no. 1, Leuven (Belgium), March 1993.
"A 6.3 KV vacuum breaker model for ATP simulations",
J. Kosmac, P. Zunko (Ljubljana Univ., Slovenia)
First European Conference on Power Systems Transients,
Lisbon (Portugal), June 1993.
"EMTP simulation of source-insulator interaction in pollution tests",
J.A. Martinez-Velasco (Univ. Politècnica Catalunya, Spain)
First European Conference on Power Systems Transients,
Lisbon (Portugal), June 1993.
"Power swing simulation studies, measurement of power flow and voltage phasor
oscillation at any point of the simulated system using MODELS",
A. Mechraoui, D.W.P. Thomas (Univ. of Nottingham, UK)
First European Conference on Power Systems Transients,
Lisbon (Portugal), June 1993.
"Using the simulation language MODELS with EMTP",
L. Dubé (DEI Simulation Software, Oregon, USA),
I. Bonfanti (CESI, Milano, Italy),
M.T. Correia de Barros (IST/Univ. Técnica de Lisboa, Lisbon, Portugal),
V. Vanderstockt (LABORELEC, Belgium)
Proc. 11th Power Systems Computation Conference, pp. 1063-1069,
Avignon (France), August 1993.
"Utilizing the frequency scan feature of ATP-EMTP",
M. Kizilcay (Lahmeyer Int'l, Frankfurt, Germany)
European EMTP User Group Meeting,
Lingby (Denmark), April 1994
"Modelling of a travelling wave phase selector for EHV transmission lines",
M.S. Jones, D.W.P. Thomas (Univ. of Nottingham, UK)
European EMTP User Group Meeting,
Lingby (Denmark), April 1994
"Grounding system simulation by means of ATP MODELS",
W. Kalat, M. Loboda, Z. Pochanke (Warsaw Tech. Univ., Poland)
European EMTP User Group Meeting,
Lingby (Denmark), April 1994
"Including a transmission line with corona in ATP using MODELS",
M.T. Correia de Barros, M.E. Almeida (IST/Univ. Técnica de Lisboa, Lisbon,
Portugal),
L. Dubé (DEI Simulation Software, Oregon, USA)
European EMTP User Group Meeting,
Lingby (Denmark), April 1994
"Tower modelling for lightning surge analysis using EMTP",
M.E.Almeida, M.T. Correia de Barros (IST/Univ. Técnica de Lisboa, Lisbon,
Portugal)
European EMTP User Group Meeting,
Lingby (Denmark), April 1994
INDEX
A
Algorithm control ............................................................................... 31, 118
Arithmetic operators.................................................................................. 57
Arrays ................................................................................. 7, 8, 14, 58, 133
Assigning data values ............................................................................... 68
Assigning input values .............................................................................. 68
Assigning output values ............................................................................ 69
Assigning values ......................................................................... 31, 32, 115
Assignment operator................................................................................... 9
ATP inputs .................................................................................... 73, 74, 76
ATP outputs .............................................................................................. 79
ATP variables............................................................................................ 77
B
backtime( ) .............................................................................................. 142
backval( ) ................................................................................................ 141
Basic aspects.......................................................................................... 2, 4
Blank lines .......................................................................................... 10, 82
Block comments........................................................................................ 11
Boolean operators..................................................................................... 57
Boolean values ........................................................................................... 8
Braces '{ }'................................................................................................. 10
Brackets '[ ]' .............................................................................................. 10
C
C programs ......................................................................................... 18, 26
Circuit components ................................................................................... 85
COMBINE statements....................................................................... 44, 118
Comments ................................................................................................ 11
Complex-value functions........................................................................... 97
Conditional control .................................................................................... 38
Constants...................................................................................... 6, 13, 130
Control components.................................................................................. 82
Control systems .......................................................................................... 5
Controlling a procedure..................................................................... 31, 118
Curly braces '{ }' ........................................................................................ 10
D
Data ........................................................................................ 6, 14, 68, 120
Delay storage............................................................................ 64, 114, 120
delay( )...................................................................................... 64, 101, 140
Delimiters .................................................................................................. 11
E
Equal sign ................................................................................................... 9
ERROR statements .......................................................................... 49, 119
EXEC procedure ....................................................................................... 28
Expressions ...................................................................................... 53, 121
External models (either local or foreign) ........................................... 21, 114
External point list for pointlist function....................................................... 25
External programs..................................................................... 6, 18, 26, 90
F
FOR arguments ........................................................................................ 53
FOR statements................................................................................ 42, 118
Foreign functions .............................................................................. 26, 113
Foreign models ........................................................................... 18, 90, 114
Formatting........................................................................................... 10, 82
Fortran programs ................................................................................ 18, 26
Frequency meter..................................................................................... 100
Frequency-domain use of a model............................................................ 90
Functions ...................................................................... 17, 23, 56, 113, 133
G
Global constants ......................................................................................... 6
Global variables .......................................................................................... 6
H
histdef( ).................................................................................................. 142
History............................................................29, 38, 66, 114, 117, 120, 142
histval( ) .................................................................................................. 142
I
IF expressions........................................................................................... 40
IF statements .................................................................................... 38, 118
Indentation ................................................................................................ 12
INIT procedure .......................................................................................... 28
Initialization ............................................................................. 29, 35, 66, 92
Initializing the type-94 component............................................................. 89
Inline comments........................................................................................ 11
Inputs ...................................................................................... 6, 15, 68, 120
Inputs from ATP ...................................................................... 73, 74, 76, 77
Instance of a model................................................................................... 50
Integrals ...................................................................................... 37, 61, 117
Interpolation on inputs at sub-steps of the simulation ............... 64, 114, 120
Iterated type-94 circuit component............................................................ 86
Iteration and re-updating a model ............................................................. 70
Iteration control ............................................................................. 41, 42, 43
K
Keywords of the MODELS language ...................................................... 126
L
Laplace transfer functions................................................................. 32, 116
Libraries of models and functions ............................................................. 94
Limits .............................................................................................. 9, 36, 58
Linear sum ................................................................................................ 59
List sizes in ATP for MODELS .................................................................. 93
Local constants ........................................................................................... 6
Local models..................................................................................... 17, 113
Local variables ............................................................................................ 6
Logical functions ..................................................................................... 135
Logical operators ...................................................................................... 57
Logical values ............................................................................................. 8
M
Min/max tracking..................................................................................... 107
Model description........................................................................ 17, 81, 112
Model instance.......................................................................................... 50
Model, MODELS, and MODEL ................................................................... 9
MODELS in ATP ..................................................................... 2, 72, 93, 111
MODELS language ..................................................................................... 2
N
Named procedures ........................................................................... 30, 115
Names ...................................................................................................... 11
Norton type-94 circuit component ............................................................. 86
Numbers ..................................................................................................... 8
Numerical functions ................................................................................ 133
Numerical operators.................................................................................. 57
Numerical values .................................................................................. 8, 56
O
Operators.......................................................................................... 57, 129
P
Parentheses '( )' ........................................................................................ 10
Parsing...................................................................................................... 11
Plot data as input to a model .................................................................... 74
Plotting results .......................................................................................... 80
Pointlist functions ...................................................................... 24, 103, 113
Polynomials of derivatives ........................................................................ 60
Post-processing existing plot data ............................................................ 74
Pre-defined constants and variables....................................................... 130
Pre-defined functions .............................................................................. 133
predtime( ) .............................................................................................. 141
predval( )................................................................................................. 141
prevval( )................................................................................................. 140
Procedures ........................................................17, 28, 31, 51, 57, 115, 119
Programming language............................................................................... 3
Project......................................................................................................... 6
Prototyping.................................................................................................. 6
R
Random value functions ......................................................................... 136
RECORD printout/plotting data ................................................................. 80
REDO statements ............................................................................. 43, 118
Referring to a named value....................................................................... 53
Regular expressions ................................................................................. 53
Repetition control .......................................................................... 41, 42, 43
Results, plotting ........................................................................................ 80
RMS value .............................................................................................. 109
S
Sample/hold model ................................................................................. 106
Signal sources .......................................................................................... 94
Simulation directives ........................................................... 63, 69, 114, 119
Simulation functions................................................................................ 138
Simulation language = Programming language + Time flow ....................... 4
Simulation results, plotting ........................................................................ 80
Simultaneous equations............................................................................ 44
Sources of signal ...................................................................................... 94
Special expressions .................................................................................. 59
Square brackets '[ ]' .................................................................................. 10
State of a model........................................................................................ 71
Statement function arguments .................................................................. 53
Statement functions .......................................................................... 23, 113
Statements........................................................................................ 31, 115
Static limits.......................................................................................... 36, 58
T
TACS .................................................................................................... 5, 76
TACS devices ........................................................................................... 99
Thevenin type-94 circuit component ......................................................... 86
Time step .......................................................................... 63, 114, 120, 131
Track/hold model .................................................................................... 106
Tracking min/max.................................................................................... 107
U
USE ITERATE .......................................................................................... 70
USE statements .................................................................... 50, 68, 69, 119
Using a model ............................................................................... 68, 82, 85
Using MODELS in ATP............................................................................. 72
V
Value assignment ....................................................................... 31, 32, 115
Value-holding elements .................................................................. 6, 13, 53
Values......................................................................................................... 8
Variables ....................................................................................... 6, 16, 130
Variables of the MODELS section............................................................. 80
Visibility of value-holding elements ....................................................... 6, 53
W
WHILE statements ............................................................................ 41, 118
White space ........................................................................................ 10, 82
Why use MODELS.................................................................................. 2, 6
Windup and no-windup limits .................................................................... 36
write(), write1(), write2() .................................................................... 51, 119
Writing a model ......................................................................................... 13
Writing expressions................................................................................... 53
Z
Z transfer functions ........................................................................... 32, 117
IN CLOSING ...
The available material includes the following files. Some of these file names
are preceded by a three-digit number, for example 964, indicating the year and
month of the file:
ugmus.zip this Users Guide of MODELS in ATP
in Word for Windows 2.0, 8.5x11 format
ugma4.zip this Users Guide of MODELS in ATP
in Word for Windows 2.0, A4 format
ug6us.zip this Users Guide of MODELS in ATP
in Word for Windows 6.0, 8.5x11 format
ug6a4.zip this Users Guide of MODELS in ATP
in Word for Windows 6.0, A4 format
lmusw.zip the Language Manual of MODELS
in Word for Windows 2.0, 8.5x11 format
lma4w.zip the Language Manual of MODELS
in Word for Windows 2.0, A4 format
lmusp.zip the Language Manual of MODELS
in WordPerfect 5.1, 8.5x11 format
lma4p.zip the Language Manual of MODELS
in WordPerfect 5.1, A4 format
techn.zip technical notes on MODELS
libs.zip libraries of models and functions, including:
- signal sources
- complex-value functions
- models of the TACS devices
examp.zip 60+ examples illustrating various MODELS features
typ94.zip 20+ examples of type-94 circuit components using
MODELS