NORMA (1158464), страница 6
Текст из файла (страница 6)
VARIABLE X DEFINED ON Ox. FOR OxII ASSUME X = F(Y) .
As we mentioned earlier functions may be included into arithmetical expression and scalar
arithmetical expression.
5.2.3. Function calls in Norma
call-function :
call-reduction-function
call-standard-function
call-external-function
call-reduction-function :
name-reduction-function ( ( name-domain )arithm-expression )
call-standard-function :
name-standard-function ( arithm-expression )
name-reduction-function :
{ SUM,MULT,MAX,MIN }
call-external-function :
name-external-function [ ( list-in-parameter ) ]
in-parameter :
arithm-expression
name-variable-on-domain ON domain-of -parameter
iterated-variable-on-domain ON domain-of-parameter
name-external-simple-part
name-external-function
domain-of-parameter :
name-unconditional-domain
name-unconditional-domain / index-expression
name-unconditional-domain / ( list-index-expression )
iterated-variable-on-domain :
name-variable-on-domain [ name-iteration-index [-1] ]
There are defined standard arithmetical functions, reduction functions and external user’s functions in the language.
5.2.3.1. Standard arithmetical functions
Functions: sqrt(x), abs(x), exp(x), alog(x), alog10(x), sin(x), cos(x), asin(x), atan(x), sign(x), dsqrt(x), dabs(x), dexp(x), dalog(x), dalog10(x), dsin(x), dcos(x), dasin(x), datan(x), dsign(x), entier(x), amax1(x,y,...), amin1(x,y,...), dmax1(x,y,...), dmin1(x,y,...), are standard functions.
These functions are analogous of a corresponding Fortran function.
5.2.3.2. Reduction functions
Functions: SUM (sum), MULT (multiplication), MAX (maximum), MIN (minimum) are reduction functions. Result of calcukation of these function is DOUBLE. Call to these functions :
name-function ( ( name-domain ) arithm-expression ).
Domain defines the number of domain’s point where the function will be computed, arithmetical expression defines the number of values which the function are applied to. Here is an example :
The fragment of this computation in NORMA :
Grid: (Oi: (I1..N) ; Oj: (J=1..M) ).
VARIABLE A DEFINED ON Grid.
VARIABLE V,W DEFINED ON Oi. VARIABLE X DEFINED ON Oj.
FOR Oi ASSUME V = W + SUM( ( OJ ) A*X) .
Here is an example of embeded reduction functions:
SurfaceMax:
(Left: (Three:(IV=1..3) ; A:(J=0..2*M);B:(I=0..2*N) );
Right: ( ( IK=1..9) ; (W=0..2*M) ; BNU:(NU=0..2*N) ) ).
SUMPOL:( (W=0..2*M) ;BNU).
ThreeAB:(Three;A;B). OLINE:(LINE=1..3).
VARIABLE VV,V DEFINED ON ThreeAB DOUBLE.
VARIABLE S DEFINED ON SurfaceMax DOUBLE.
FOR ThreeAB ASSUME
VV=SUM( (SUMPOL) SUM((OLINE)
V[IV=LINE] (V[IV=1] *S[IK=LINE]+V[IV=2]*S[IK=LINE+3]+V[IV=3]*S[IK=LINE+6]) ) ) .
The rule of index localization is true for reduction functions: domain declared as argument of reduction function has its own index system. The subject of this system action is arithmetical expression declared as the second argument of reduction function. It means that indexes used in the arithmetical expression may be divided into two types: “internal” which coincide with the indexes of the reduction domain and defined by them and “external” which don’t coincide with indexes of reduction domain and defined by external domains (e.g. domains of other reduction functions or ASSUME operator). The set of “internal” indexes values is completely defined by the domain set as an argument of reduction function. The set of “external” indexes values is defined by the domains which are external for reduction function.
E.g. operator
FOR Oik ASSUME X=(i+k) / SUM( (Oij5) B*C).
defines request for computation
if the declarations are :
Oij5 : ((i=1..5) ; (j=1..5)). Oik: (i=1..10) ; (k=1..10)).
Oijk: (Oij:((i=1..15) ; (j=1..15)) ;(k=1..15)).
VARIABLE B DEFINED ON Oijk. VARIABLE C DEFINED ON Oij.
VARIABLE X DEFINED ON Oik.
If external domain is conditional the condition acts on all the external indexes of arithmetical expression which are under the sign of reduction function. E.g. formula
sets computation
..............
may be written as :
Oij: (Oi: (i=1..10); Oj: (1..10)) . OiLTj:Oij / i<j.
OiLTjYLTO, OiLTjYGEO:OiLTj / Y<0.
Oi100: (i=1..100). Oij100: (Oi100;Oj).
VARIABLE B DEFINED ON Oij100. VARIABLE X DEFINED ON Oij.
VARIABLE Y DEFINED ON Oj.
FOR OiLTjYLTO ASSUME X=SUM( ( Oi100) B*Y).
Recursive computations are prohibited for the values used in both the left part of ASSUME operator and arithmetical expression in reduction function. E.g. formula
can not be represented in one ASSUME operator
FOR Oij ASSUME X = SUM ((Oij1)X).
5.2.3.3. User’s external functions
External function is defined by user. One can call this function by name, the list of actual parameters divided by comma is put into brackets and placed after the name. The result of function’s computations is represented by function’s name. If all the actual parameters have their values computation is available . All the actual parameters are considered initial data for function computation, side effect is prohibited.
Arithmetical expressions, part and function names or variables on domain (arrays) can be actual parameters of external function.
Here is an example of external function with different ways of actual parameters setting .
Grid: (Oi: (I=1..N) ; Oj: (J=1..M)).
VARIABLE A, B DEFINED ON Grid.
VARIABLE X,Y DEFINED ON Oi. VARIABLE T DEFINED ON Oj.
VARIABLE Gamma DOUBLE.
INPUT A,B ON Grid, Y ON Oi, T ON Oj. INPUT Gamma.
OUTPUT X ON Oi.
DOMAIN PARAMETERS N = 10, M = 20. EXTERNAL FUNCTION DxDy.
FOR Oi ASSUME
X = F(DxDy, Gamma+0.5*Y, T ON Oj, A ON Grid / (i=2..8,J=M-2), B ON Grid /J=I+2).
ASSUME operator set the rule of array Xi,i =1,10 computation. User’s function F with parameters values are to be computed for every i. The list of parameters :
1-st parameter - name DxDy of external user’s function;
2-nd parameter- arithmetical expression Gamma+0.5*Yi;
3-rd parameter - Tj, j=1,...,20 values of static array;
4-th parameter - Ai,j ,i=2,...,8, j=18 values of array’s section : one-dimensional array consists of the 2-8 rows elements from the 18th column of A matrix;
5-th parameter - Bi,j, i=1,...,10,j=i+2 of dynamic array’s section : i+2 column of B matrix.
The rules of formal and actual parameters correspondence :
-
The number of actual and formal parameters must be equal; correspondence is set from the left to the right in writing order.
Formal parameter | Actual parameter |
function name | function name |
part name | part name |
scalar | arithmetical expression |
variable on domain | variable on domain |
(3) If both formal and actual parameters are variables on domain then the number of domain indexes and the number of points in the ranges on corresponding indexes must be the same (5.1.2).
5.2.4. Part call
call-part :
COMPUTE name-part [ ( actual-parameters )]
actual-parameters :
[ list-in-parameter ] [ RESULT list-out-parameter ]
out-parameter :
name-scalar
name-variable-on-domain ON domain-of-parameter
iterated-variable-on-domain ON domain-of-parameter
Arithmetical expressions, part and function names or variables on domains (arrays) can be actual parameters.
Actual parameters may be declared as initial or results by key word RESULT.
E.g.:
COMPUTE Velocity ( Delta+0.5, Fi ON Oijk RESULT V ON Oij).
The first two parameters are initial, the third is result. Side effect is impossible: if sets of initial parameters and parameters-results intersect the result of intersection will be reassignment which is prohibited in NORMA.
Part call is a development of notion relation in ASSUME operator because it allows to obtain several results at once. Part call without ASSUME operator is a development of scalar operator notion.
The ways of part initial actual parameters setting and the ways of function actual parameters settings (5.2.3.3) are the same.
Scalars, variables with indexes (may be set by the rule of default indexes), variables on domains (arrays) may be actual parameters-results.
If part call is in the body of ASSUME operator then scalars and variables on static domain (which don’t change for different values of indexes from ASSUME header) can’t be parameters-values - it causes reassignment.
If part call isn’t in the body of ASSUME operator then scalar names, variables with index-constants and variables on static domains can be parameters-results only.
Part call in the part with declaration DISTRIBUTION INDEX is prohibited.
Here is an example of actual parameters settings in different ways .
VARIABLE A,B DEFINED ON Grid: (Oi: (I=1..N);Oj: (J=1..M) ).
VARIABLE X,Y DEFINED ON Oi. VARIABLE T DEFINED ON Oj.
VARIABLE Gamma DOUBLE.
INPUT A ON Grid ,Y ON Oi,T ON OJ. INPUT Gamma.
OUTPUT X ON Oi, B ON Grid /J=2..12.
DOMAIN PARAMETERS N =10, M =20.
EXTERNAL PART DzDy.
FOR Oi ASSUME
COMPUTE TEST ( DzDy, T ON Oj, Y RESULT X, B ON Grid /J=I+2).
COMPUTE SCALAR( A ON Grid RESULT Gamma, B ON Grid /J=2).
The rule of Xi,j, i=1,...,10 and part of matrix B : Bi,j, i=,...,10, j=3,...,12 computation is defined in ASSUME operator.
Scalar call of part SCALAR defines scalar Gamma and the second column of B matrix.
The rules of actual and formal parameters-results correspondence are the same as for correspondence rules for functions (5.2.3):
Formal parameter | Actual parameter |
scalar | scalar |
scalar | variable with index constant |
variable on domain | variable on domain |
5.2.5. Interface with FORTRAN programs
Subroutines and functions written in Fortran may be called from the program written in NORMA by usual tools of part and function call. Reassignment control is carried out in actual parameters analysis.