More Custom Model Examples

 

A picture is worth a thousand words – or at least in this case, an example is worth a thousand words.  The following examples attempt to reveal some of the most important aspects of model development in EMTDC.  Each example includes additional discussion as situations arise.  If you remain unsure about a certain topic, and cannot find it here, please contact the PSCAD Support Desk (support@pscad.com) for help.

Simple Integrator Model

An integrator component is a purely system dynamics model.  In other words, at no point does it attempt to interface, nor control the electric network.  It operates purely on control signals; modifying an input signal to produce an output.

 

 

 

EXAMPLE 5-7:

 

To illustrate the above concept, consider the following simple integrator circuit constructed in PSCAD:

 

 

Figure 5-8 - Simple Integrator in PSCAD

 

The user desires to represent an equivalent flux using the following equation:

 

(5-4)

 

Which leads to,

 

(5-5)

 

In other words, the measured electric network voltage V, is input every time step to an integrator control component.  This integrated value can then be used to determine the equivalent flux . If desired, the flux can then be used as an input control for an electric element, such as a current source.  The following example code is for a simple integrator function, written in Fortran:

 

!

      SUBROUTINE U_DYN_MYINTGL(IN,OUT,LIMITS,ULIMIT,LLIMIT)

!

! Purpose  - Integration of a real signal

! Language - Fortran 90

! Date     -

! Author   -

!

! Include Files

!

      INCLUDE 'nd.h'

      INCLUDE 'emtstor.h'

      INCLUDE 'rtconfig.h'

      INCLUDE 's1.h'

      INCLUDE 'emtconst.h'

!

! Variable Declarations

!

      REAL    IN, OUT, ULIMIT, LLIMIT

      INTEGER LIMITS, MY_STORF, MY_RTCF

      REAL    INOLD, OUTOLD

!

! Copy and increment pointers

!

      MY_STORF = NSTORF

      MY_RTCF  = NRTCF

      NSTORF   = NSTORF + 2

      NRTCF    = NRTCF + 1

!

! Main Program

!

      OUT = 0.5*(IN + STORF(MY_STORF))*DELT + STORF(MY_STORF + 1)

!

! Initial output at time zero

!

      IF ( TIMEZERO )  OUT = RTCF(MY_RTCF)    

!

! Limit the output if requested

!

      IF ( LIMITS .EQ. 1 ) THEN

         IF ( OUT .GE. ULIMIT ) THEN

            OUT = ULIMIT

         ELSEIF ( OUT .LE. LLIMIT ) THEN

            OUT = LLIMIT

         ENDIF

      ENDIF

!

! Store data for next time step

!

      STORF(MY_STORF)     = IN

      STORF(MY_STORF + 1) = OUT

!

      RETURN

      END

!

 

Listing 5-23 – Example Code Defining a Simple Integrator

 

Something similar to the following script needs to be added to the component definition itself, to ensure that the model subroutine U_DYN_MYINTGL is called. Note that a #BEGIN directive has been added to define the initial output quantity for time zero.

 

#BEGIN

      RTCF(NRTCF) = $Out0

      NRTCF       = NRTCF + 1

#ENDBEGIN

!

#SUBROUTINE U_DYN_MYINTGL ‘Integrator Model’

#STORAGE REAL:2 RTCF:1

      CALL U_DYN_MYINTGL($In,$Out,$Limits,$ULimit,$LLimit)

!

 

Listing 5-24 – Calling Simple Integrator Subroutine from within the Component Definition