PDA

View Full Version : EMTDC Storage Arrays



John Nordstrom
08-17-2004, 01:06 PM
A well defined storage method is an important part of an iterative type program like EMTDC. Quite often, variables defined in the present time step must be saved for use in a future time step. EMTDC utilizes a storage index method, where variables can be transferred to a storage array, by means of an indexed address. For example, transferring a variable 'X' into the 9th position within a storage array 'Y' is accomplished as follows:

[code:1:de36a50321]Y(9) = X[/code:1:de36a50321]

The original version of EMTDC used a single storage array entitled 'STOR' for the storage of all variable types. The STOR array itself is defined as type REAL, and so all variables stored within it must also be REAL. This means that other variable types, such as INTEGER and LOGICAL, must be converted to REAL before being transferred into, and then converted back when transferring from STOR. For example, transferring an INTEGER 'X' to and from the 9th element of the STOR array is accompilshed as follows:

[code:1:de36a50321]STOR(9) = FLOAT( X ) ! to...
.
.
X = NINT( STOR(9) ) ! and from...[/code:1:de36a50321]

Directly entering the storage index number (as shown in the above examples) is not a recommended practice. Direct entry of the index number can quickly become complicated and unrulely as the program becomes larger. What's more, the modularity of the program is lost, as external subroutines and functions, which utilize storage, would need to be reindexed each call. Even then, the probability of storage being overwritten is still high.

EMTDC uses an index pointer method to circumvent this problem. The original STOR array described above has associated with it an EMTDC global INTEGER variable called 'NEXC'. At the begining of each time step, NEXC is set to 0 and then incremented by 1 whenever a STOR location is used. This process ensures that no matter where in the program a variable is transferred to storage, previous values will never be overwritten. It also allows for program modularity, as the storage index pointer becomes localized within any subroutine or function.

For example, a certain function transfers REAL variables X and Y into and out of two separate STOR locations within its code body:

[code:1:de36a50321]X = STOR(NEXC + 1) ! transfer from storage
Y = STOR(NEXC + 2)
.
.
STOR(NEXC + 1) = X ! transfer to storage
STOR(NEXC + 2) = Y
.
.
NEXC = NEXC + 2 ! Increment storage pointer[/code:1:de36a50321]

The last line of the above code ensures that the value of the NEXC pointer has been incremented to the next available STOR location. Now when a subsequent subroutine or function is called, values stored there will not overwrite previously stored quantities.

In EMTDC V3 (released with PSCAD V3), four new storage arrays were added to address the problem with storing the various data types. Now there is an array for each type of Fortran variable: REAL, INTEGER, LOGICAL and COMPLEX. Each of these arrays has associated with it a separate index pointer as in the following table:

[code:1:de36a50321]
Array Pointer Data Type

STORF(...) NSTORF REAL
STORI(...) NSTORI INTEGER
STORL(...) NSTORL LOGICAL
STORC(...) NSTORC COMPLEX [/code:1:de36a50321]

The use of these arrays is identical to that described above for STOR. The only difference besides the obvious is that the NSTORx index pointers are set to 1 at the beginning of each time step, and so the first storage location used in each subroutine or function does not need to be incremented. For example, referring to the 'XFUNC' example above:

[code:1:de36a50321]X = STORF(NSTORF) ! transfer from storage
Y = STORF(NSTORF + 1)
.
.
STORF(NSTORF) = X ! transfer to storage
STORF(NSTORF + 1) = Y
.
.
NSTORF = NSTORF + 2 ! Increment storage pointer
[/code:1:de36a50321]
Although the STOR array is still fully functional in EMTDC, the use of the STORx arrays is recommended as STOR will eventually become obsolete.