[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[TRNSYS-users] variable storage problems



This time with attachment

--
Ir.Jeroen Van der Veken
Afdeling Bouwfysica
Katholieke Universiteit Leuven
Kasteelpark Arenberg 40
3001 Heverlee
T: +32 16 32 13 47
F: +32 16 32 19 80
@: jeroen.vanderveken@bwk.kuleuven.be

NEW MAILADRES WITHOUT .AC !!


Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

			SUBROUTINE TYPE184 (TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*) 
C************************************************************************
C Object: Noname
C IISiBat Model: Type184
C 
C Author: 
C Editor: 
C Date:	 December 23, 2005 last modified: December 23, 2005
C 
C 
C *** 
C *** Model Parameters 
C *** 
C			nominal flow	kg/hr [0;+Inf]
C			nominal temperature difference valve ambient	deltaC [0;+Inf]
C			maximal temperture difference valve ambient	deltaC [0;+Inf]
C			hysteresis temperature	deltaC [0;+Inf]
C			Resistance valve ambient	any [0;+Inf]
C			Resistance valve water	any [0;+Inf]
C			Capacity valve	any [0;+Inf]
C			Valve authority	- [0;1]

C *** 
C *** Model Inputs 
C *** 
C			water supply temperature	C [0;+Inf]
C			ambient temperature	C [-Inf;+Inf]
C			on/off	- [0;1]
C			setpoint temperature valve	C [0;+Inf]

C *** 
C *** Model Outputs 
C *** 
C			flow	kg/hr [-Inf;+Inf]

C *** 
C *** Model Derivatives 
C *** 

C (Comments and routine interface generated by TRNSYS Studio)
C************************************************************************

C    TRNSYS acess functions (allow to acess TIME etc.) 
      USE TrnsysConstants
      USE TrnsysFunctions

C-----------------------------------------------------------------------------------------------------------------------
C    REQUIRED BY THE MULTI-DLL VERSION OF TRNSYS
      !DEC$ATTRIBUTES DLLEXPORT :: TYPE184				!SET THE CORRECT TYPE NUMBER HERE
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C    TRNSYS DECLARATIONS
      IMPLICIT NONE			!REQUIRES THE USER TO DEFINE ALL VARIABLES BEFORE USING THEM

	DOUBLE PRECISION XIN	!THE ARRAY FROM WHICH THE INPUTS TO THIS TYPE WILL BE RETRIEVED
	DOUBLE PRECISION OUT	!THE ARRAY WHICH WILL BE USED TO STORE THE OUTPUTS FROM THIS TYPE
	DOUBLE PRECISION TIME	!THE CURRENT SIMULATION TIME - YOU MAY USE THIS VARIABLE BUT DO NOT SET IT!
	DOUBLE PRECISION PAR	!THE ARRAY FROM WHICH THE PARAMETERS FOR THIS TYPE WILL BE RETRIEVED
	DOUBLE PRECISION STORED !THE STORAGE ARRAY FOR HOLDING VARIABLES FROM TIMESTEP TO TIMESTEP
	DOUBLE PRECISION T		!AN ARRAY CONTAINING THE RESULTS FROM THE DIFFERENTIAL EQUATION SOLVER
	DOUBLE PRECISION DTDT	!AN ARRAY CONTAINING THE DERIVATIVES TO BE PASSED TO THE DIFF.EQ. SOLVER
	INTEGER*4 INFO(15)		!THE INFO ARRAY STORES AND PASSES VALUABLE INFORMATION TO AND FROM THIS TYPE
	INTEGER*4 NP,NI,NOUT,ND	!VARIABLES FOR THE MAXIMUM NUMBER OF PARAMETERS,INPUTS,OUTPUTS AND DERIVATIVES
	INTEGER*4 NPAR,NIN,NDER	!VARIABLES FOR THE CORRECT NUMBER OF PARAMETERS,INPUTS,OUTPUTS AND DERIVATIVES
	INTEGER*4 IUNIT,ITYPE	!THE UNIT NUMBER AND TYPE NUMBER FOR THIS COMPONENT
	INTEGER*4 ICNTRL		!AN ARRAY FOR HOLDING VALUES OF CONTROL FUNCTIONS WITH THE NEW SOLVER
	INTEGER*4 NSTORED		!THE NUMBER OF VARIABLES THAT WILL BE PASSED INTO AND OUT OF STORAGE
	CHARACTER*3 OCHECK		!AN ARRAY TO BE FILLED WITH THE CORRECT VARIABLE TYPES FOR THE OUTPUTS
	CHARACTER*3 YCHECK		!AN ARRAY TO BE FILLED WITH THE CORRECT VARIABLE TYPES FOR THE INPUTS
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    USER DECLARATIONS - SET THE MAXIMUM NUMBER OF PARAMETERS (NP), INPUTS (NI),
C    OUTPUTS (NOUT), AND DERIVATIVES (ND) THAT MAY BE SUPPLIED FOR THIS TYPE
      PARAMETER (NP=9,NI=4,NOUT=4,ND=0,NSTORED=4)
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    REQUIRED TRNSYS DIMENSIONS
      DIMENSION XIN(NI),OUT(NOUT),PAR(NP),YCHECK(NI),OCHECK(NOUT),
	1   STORED(NSTORED),T(ND),DTDT(ND)
      INTEGER NITEMS
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C    ADD DECLARATIONS AND DEFINITIONS FOR THE USER-VARIABLES HERE


C    PARAMETERS
      DOUBLE PRECISION TSETFIX
      DOUBLE PRECISION XMFRN
      DOUBLE PRECISION DTEMPN
      DOUBLE PRECISION DTMAX
      DOUBLE PRECISION HYST
      DOUBLE PRECISION RESAMB
      DOUBLE PRECISION RESWTR
      DOUBLE PRECISION CVLV
      DOUBLE PRECISION AVLV
      DOUBLE PRECISION EPS

C    INPUTS
      DOUBLE PRECISION TSU
      DOUBLE PRECISION TAMB
      DOUBLE PRECISION GAMMA
      DOUBLE PRECISION TSET

      DOUBLE PRECISION ATVLV
      DOUBLE PRECISION ADTEMP
	DOUBLE PRECISION AXMFR
	DOUBLE PRECISION ATSET
      DOUBLE PRECISION TWTR
      DOUBLE PRECISION TVLV
      DOUBLE PRECISION XMFRW
      DOUBLE PRECISION A
	DOUBLE PRECISION B
	DOUBLE PRECISION D
	DOUBLE PRECISION STEP
	DOUBLE PRECISION DTEMP
	DOUBLE PRECISION DTEMP1
	DOUBLE PRECISION DTEMP2
	DOUBLE PRECISION DMFR


C-----------------------------------------------------------------------------------------------------------------------
C       READ IN THE VALUES OF THE PARAMETERS IN SEQUENTIAL ORDER
      TSETFIX=PAR(1)
      XMFRN=PAR(2)
      DTEMPN=PAR(3)
      DTMAX=PAR(4)
      HYST=PAR(5)
      RESAMB=PAR(6)
      RESWTR=PAR(7)
      CVLV=PAR(8)
      AVLV=PAR(9)

C-----------------------------------------------------------------------------------------------------------------------
C    RETRIEVE THE CURRENT VALUES OF THE INPUTS TO THIS MODEL FROM THE XIN ARRAY IN SEQUENTIAL ORDER

      TSU=XIN(1)
      TAMB=XIN(2)
      GAMMA=XIN(3)
	TSET=XIN(4)
	   IUNIT=INFO(1)
	   ITYPE=INFO(2)

C-----------------------------------------------------------------------------------------------------------------------
C    SET THE VERSION INFORMATION FOR TRNSYS
      IF(INFO(7).EQ.-2) THEN
	   INFO(12)=16
	   RETURN 1
	ENDIF
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    DO ALL THE VERY LAST CALL OF THE SIMULATION MANIPULATIONS HERE
      IF (INFO(8).EQ.-1) THEN
	   RETURN 1
	ENDIF
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    PERFORM ANY 'AFTER-ITERATION' MANIPULATIONS THAT ARE REQUIRED HERE
C    e.g. save variables to storage array for the next timestep
      IF (INFO(13).GT.0) THEN
	   NITEMS=4
	   STORED(1)=TVLV
	   STORED(2)=DTEMP
	   STORED(3)=XMFRW
	   STORED(4)=TSET
         CALL setStorageVars(STORED,NITEMS,INFO)
	   RETURN 1
	ENDIF
C
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    DO ALL THE VERY FIRST CALL OF THE SIMULATION MANIPULATIONS HERE
      IF (INFO(7).EQ.-1) THEN

C       SET SOME INFO ARRAY VARIABLES TO TELL THE TRNSYS ENGINE HOW THIS TYPE IS TO WORK
         INFO(6)=NOUT				
         INFO(9)=1				
	   INFO(10)=0	!STORAGE FOR VERSION 16 HAS BEEN CHANGED				

C       SET THE REQUIRED NUMBER OF INPUTS, PARAMETERS AND DERIVATIVES THAT THE USER SHOULD SUPPLY IN THE INPUT FILE
C       IN SOME CASES, THE NUMBER OF VARIABLES MAY DEPEND ON THE VALUE OF PARAMETERS TO THIS MODEL....
         NIN=NI
	   NPAR=NP
	   NDER=ND
	       
C       CALL THE TYPE CHECK SUBROUTINE TO COMPARE WHAT THIS COMPONENT REQUIRES TO WHAT IS SUPPLIED IN 
C       THE TRNSYS INPUT FILE
	   CALL TYPECK(1,INFO,NIN,NPAR,NDER)

C       SET THE NUMBER OF STORAGE SPOTS NEEDED FOR THIS COMPONENT
         NITEMS=4
	   CALL setStorageSize(NITEMS,INFO)

C       RETURN TO THE CALLING PROGRAM
         RETURN 1

      ENDIF
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    DO ALL OF THE INITIAL TIMESTEP MANIPULATIONS HERE - THERE ARE NO ITERATIONS AT THE INTIAL TIME
      IF (TIME .LT. (getSimulationStartTime() +
     . getSimulationTimeStep()/2.D0)) THEN

C       SET THE UNIT NUMBER FOR FUTURE CALLS
         IUNIT=INFO(1)
         ITYPE=INFO(2)

C       CHECK THE PARAMETERS FOR PROBLEMS AND RETURN FROM THE SUBROUTINE IF AN ERROR IS FOUND
C         IF(...) CALL TYPECK(-4,INFO,0,"BAD PARAMETER #",0)

C       PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL VALUES OF THE OUTPUTS HERE
C		 flow
			OUT(1)=100
	        EPS=0.001
			STEP=getSimulationTimeStep()

C       PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL STORAGE VARIABLES HERE
         TWTR = TSU
         TVLV = (RESAMB*TWTR+RESWTR*TAMB)/(RESAMB+RESWTR)
         ATVLV = TVLV
         ADTEMP = TSETFIX - TVLV
         AXMFR=XMFRN
	   NITEMS=4
	   ATSET=TSETFIX
	   STORED(1)=ATVLV
	   STORED(2)=ADTEMP
	   STORED(3)=AXMFR
	   STORED(4)=ATSET

C       PUT THE STORED ARRAY IN THE GLOBAL STORED ARRAY
         CALL setStorageVars(STORED,NITEMS,INFO)

C       RETURN TO THE CALLING PROGRAM
         RETURN 1

      ENDIF
C-----------------------------------------------------------------------------------------------------------------------

C-----------------------------------------------------------------------------------------------------------------------
C    *** ITS AN ITERATIVE CALL TO THIS COMPONENT ***
C-----------------------------------------------------------------------------------------------------------------------

 33     NITEMS=4
	  CALL getStorageVars(STORED,NITEMS,INFO)
        ATVLV = STORED(1)
        ADTEMP = STORED(2)
        AXMFR = STORED(3)
	  ATSET = STORED(4)

C  1. CALCULATION OF THE TEMPERATURE OF THE VALVE                       MSR01480
C            RESWTR TVLV RESAMB                                         MSR01490
C          O---VVV---O---VVV---O                                        MSR01500
C          |         |         |                                        MSR01510
C    TWTR ___  CVLV ___       ___TAMB                                   MSR01520
C          -        ___        -                                        MSR01530
C          |         |         |                                        MSR01540
C          /         /         /                                        MSR01550
C    A. IF ONE OF THE CAPACITANCE OR RESISTANCES IS NIL                 MSR01560
      IF (CVLV.EQ.0) THEN                                               MSR01570
      TVLV = (RESAMB*TWTR+RESWTR*TAMB)/(RESAMB+RESWTR)                  MSR01580
      ELSE IF(RESWTR.EQ.0) THEN                                         MSR01590
      A =1/CVLV/RESAMB                                                  MSR01600
      B = TAMB/CVLV/RESAMB                                              MSR01610
      D = ATVLV - B/A                                                   MSR01620
      TVLV = D*EXP(-A*STEP)+B/A                                         MSR01630
      ELSE IF(RESAMB.EQ.0) THEN                                         MSR01640
      A =1/CVLV/RESWTR                                                  MSR01650
      B = TWTR/CVLV/RESWTR                                              MSR01660
      D = ATVLV - B/A                                                   MSR01670
      TVLV = D*EXP(-A*STEP)+B/A                                         MSR01680
C    B. CAPACITANCE AND RESISTANCES ARE NOT NIL                         MSR01690
      ELSE                                                              MSR01700
      A = (RESWTR+RESAMB)/CVLV/RESAMB/RESWTR                            MSR01710
      B = (RESAMB*TWTR+RESWTR*TAMB)/CVLV/RESAMB/RESWTR                  MSR01720
      D = ATVLV - B/A                                                   MSR01730
      TVLV = D*EXP(-A*STEP)+B/A                                         MSR01740
      ENDIF                                                             MSR01750
C  2. CALCULATION OF THE DIFFERENCE BETWEEN THE VALVE AND THE SET       MSR01760
C      POINT, TAKING INTO ACCOUNT THE HYSTERESIS                        MSR01770
      IF (HYST.EQ.0) THEN                                               MSR01780
      DTEMP = TSET - TVLV                                               MSR01790
      GOTO 10                                                           MSR01800
      ENDIF                                                             MSR01810
      DTEMP1 = TSET - TVLV                                              MSR01820
      DTEMP2 = DTEMP1 - HYST                                            MSR01830
      IF(TVLV.GT.ATVLV) THEN                                            MSR01840
      IF(DTEMP1.GE.ADTEMP) THEN                                         MSR01850
      DTEMP = ADTEMP                                                    MSR01860
      ELSE                                                              MSR01870
      DTEMP = DTEMP1                                                    MSR01880
      ENDIF                                                             MSR01890
      ELSE IF(TVLV.LT.ATVLV) THEN                                       MSR01900
      IF(DTEMP2.LE.ADTEMP) THEN                                         MSR01910
      DTEMP = ADTEMP                                                    MSR01920
      ELSE                                                              MSR01930
      DTEMP = DTEMP2                                                    MSR01940
      ENDIF                                                             MSR01950
      ELSE                                                              MSR01960
      DTEMP = ADTEMP                                                    MSR01970
      ENDIF                                                             MSR01980
 10   IF(DTEMP.GT.DTMAX) DTEMP = DTMAX                                  MSR01990
      IF(DTEMP.LT.0)    DTEMP = 0                                       MSR02000
C 3. CALCULATION OF THE MASSFLOW RATE                                   MSR02010
      XMFRW = XMFRN*DTEMP/DTEMPN*(AVLV+(DTEMP/DTEMPN)**2*(1-AVLV))      MSR02020
     +**(-0.5)                                                          MSR02030
      IF (XMFRW.NE.0) THEN                                              MSR02180
      DMFR=(XMFRW-AXMFR)/XMFRW                                          MSR02190
      ELSE                                                              MSR02200
      IF (AXMFR.EQ.0) THEN                                              MSR02210
      DMFR=0                                                            MSR02220
      ELSE                                                              MSR02230
      DMFR=AXMFR                                                        MSR02240
      ENDIF                                                             MSR02250
      ENDIF                                                             MSR02260
      IF (XMFRW.LT.0) XMFRW = 0
      DMFR=ABS(DMFR)                                                    MSR02270

 100  NITEMS=4
	STORED(1)=TVLV
	STORED(2)=DTEMP
	STORED(3)=XMFRW
	STORED(4)=TSET
	CALL setStorageVars(STORED,NITEMS,INFO)
      IF (DMFR.GE.EPS ) GOTO 33                                         MSR02290

C-----------------------------------------------------------------------------------------------------------------------
C    REPORT ANY PROBLEMS THAT HAVE BEEN FOUND USING CALLS LIKE THIS:
C      CALL MESSAGES(-1,'put your message here','MESSAGE',IUNIT,ITYPE)
C      CALL MESSAGES(-1,'put your message here','WARNING',IUNIT,ITYPE)
C      CALL MESSAGES(-1,'put your message here','SEVERE',IUNIT,ITYPE)
C      CALL MESSAGES(-1,'put your message here','FATAL',IUNIT,ITYPE)
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C    SET THE OUTPUTS FROM THIS MODEL IN SEQUENTIAL ORDER AND GET OUT

C		 flow
	OUT(1)=XMFRW
	OUT(2)=TVLV
	OUT(3)=TSET
	OUT(4)=DTEMP

C-----------------------------------------------------------------------------------------------------------------------
C    EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON
      RETURN 1
      END
C-----------------------------------------------------------------------------------------------------------------------