C************************************************************** ! This component has been assigned Type Number 203. If that number conflicts with ! another user Type number, you will need to change it and recompile the appropriate ! dll. SUBROUTINE TYPE203(TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*) !DEC$ATTRIBUTES DLLEXPORT :: TYPE203 C Version from: 12/13/89 C SAMPLE INPUT AND OUTPUT FOLLOWS THE NOMENCLATURE C-------------------------------------------------------------- C**** This Type represents a Ventilator type load, which is C designed to run with an electric motor. C************************************************************** C**** Nomenclature: C**** TRNSYS specific variables: C XIN == input array C OUT == output array C PAR == parameters C TIME == simulation time C T,DTDT == not used in this component C S == storage array C NSTORE == dimension of S C IAV == pointer within S C ISTORE == index C INFO == array to use TRNSYS internal information C**** C1,C2,C3 -- constants C COUNTER -- counting the number of iterations C CHANGE -- auxilary variable C EPS -- error tolerance for newton iteration C FAIL -- message if operating conditions are out of range C :0 = everything is okay C :1 = max. speed is exceeded C :2 = Newton iteration did not converge within C specified tolerance C FN -- objective function for Newton iteration C FPRIMEN -- first derivative of the objective function C MAXIT -- the limit on the number of iterations to find the C speed C MODE -- determines whether torque or speed is significant C :1 = torque is significant C :2 = speed is significant C N -- Speed C NINIT -- initial value of a speed for the iterative process C to find the motor speed for a given torque C NMAX -- maximum permitted speed C NOLD -- speed from previous iteration C P -- Fan power [watts] C PI - pi C TL -- Torque C************************************************************** C C SAMPLE INPUT AND OUTPUT C C INPUTS SAMPLE VALUES C XIN(1) TL .6 C C PARAMETERS SAMPLE VALUES C PAR(1) C1 .3 C PAR(2) C2 .00039 C PAR(3) C3 1.8 C PAR(4) NMAX 5000.0 C C OUTPUTS SAMPLE VALUES C OUT(1) N 6.385 C OUT(2) TL .6 C OUT(3) P 24.07 C OUT(4) FAIL 0.0 C C*************************************************************** IMPLICIT NONE DOUBLE PRECISION XIN, OUT INTEGER ISTORE,NSTORE,IAV INTEGER INFO,COUNTER,MAXIT,FAIL REAL TIME,T,DTDT,ICNTRL,PAR,S REAL TL,N,NINIT,C1,C2,C3,FN,FPRIMEN,NNEW,CHANGE REAL NMAX,EPS,PI,NOLD,P DIMENSION XIN(1), OUT(4), PAR(4), INFO(15) C************************************************************** COMMON /STORE/ NSTORE,IAV,S(5000) ! Set the version information for TRNSYS IF (INFO(7).EQ.-2) THEN INFO(12) = 15 RETURN 1 ENDIF C-------------------------------------------------------------- C**** Initial call in simulation IF (INFO(7).LT.0) THEN INFO(6)=4 INFO(9)=0 C**** storage allocation: speed from previous iteration C**** is stored in the S-array C**** S(ISTORE) -- NOLD INFO(10)=1 CALL TYPECK(1,INFO,1,4,0) ISTORE=INFO(10) C**** set parameters C1=PAR(1) C2=PAR(2) C3=PAR(3) NMAX=PAR(4) NINIT=0.01*NMAX NOLD=NINIT MAXIT=30 EPS=0.0001 C**** accurate expression for pi PI=ACOS(-1.) C-------------------------------------------------------------- C**** first and following calls in timestep ELSE FAIL=0 C**** set inputs TL=XIN(1) IF(TL.LT.C1)THEN N=0. ELSE C**** Iteration using Newton's method to find speed COUNTER=0 NINIT=S(ISTORE) NNEW=NINIT N=NINIT 100 CONTINUE FN=C1+C2*((2.*PI*N)**C3)-TL FPRIMEN=2.*PI*C3*C2*((2.*PI*N)**(C3-1.)) CHANGE=-FN/FPRIMEN IF (ABS(CHANGE).GE.EPS) THEN NNEW=N+CHANGE IF (COUNTER.GE.MAXIT) THEN FAIL=2 ELSE N=NNEW COUNTER=COUNTER+1 GOTO 100 ENDIF ELSE N=NNEW ENDIF ENDIF ENDIF C-------------------------------------------------------------- C**** Control on speed, speed can't be negative IF (N.LT.0) THEN N=0. ELSE C**** control on max.speed IF(N.GT.NMAX)THEN FAIL=1 ENDIF ENDIF IF(N.NE.0.)THEN NOLD=N ENDIF S(ISTORE)=NOLD P=2.*PI*N*TL C**** set outputs OUT(1)=N OUT(2)=TL OUT(3)=P OUT(4)=FAIL RETURN 1 END