[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[TRNSYS-users] invalid floating point
Hello TRNSYS-Users,
I have been creating a simple model of a radiative heater.
Unfortunatelly I get the error "invalid floating point" while running this modell. To solve the equation of the outlet temperature of the radiator I applied the Newton-method and I guess the iteration I wrote is incorrect.
I attached the source code for the case anybody would like to look through!
I appreciate every sugesstion to get this model work!!
Thanks in advance,
Michael
SUBROUTINE TYPE840 (TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*)
C************************************************************************
C Object: Radiator
C Simulation Studio Model: Type840
C
C Author: Michael Hartl
C Editor: FH-Wels
C Date: March 30, 2007 last modified: March 30, 2007
C
C
C ***
C *** Model Parameters
C ***
C nominal power of radiator kJ/hr [-Inf;+Inf]
C radiator exponent - [1;1.5]
C nominal water supply temperature C [0;100]
C nominal outlet water temperature C [0;100]
C nominal room air temperature C [0;100]
C nominal fraction of radiativ power %(base100) [0;100]
C specific heat of supply water kJ/kg.K [0;+Inf]
C ***
C *** Model Inputs
C ***
C water supply temperature C [0;100]
C inside room air temperature C [0;100]
C mass flow rate of supply water kg/hr [0;+Inf]
C ***
C *** Model Outputs
C ***
C convective power emitted kJ/hr [-Inf;+Inf]
C radiative power emitted kJ/hr [-Inf;+Inf]
C outlet water temperature C [-Inf;+Inf]
C mass flow rate of supply water kg/hr [-Inf;+Inf]
C mean radiator temperature C [-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 :: TYPE840 !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=7,NI=3,NOUT=5,ND=0,NSTORED=0)
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 Q_N,R_EX,cp,T_S_N,T_O_N,T_R_N,FR_N,T_S,T_R,
1 Q_CONV,Q_RAD,T_O,FLOW,T_MEAN,DELTA_T_N,FCT,DFCT,
1 EPS,DELTA,x,xnew,FR
C-----------------------------------------------------------------------------------------------------------------------
C READ IN THE VALUES OF THE PARAMETERS IN SEQUENTIAL ORDER
Q_N=PAR(1)
R_EX=PAR(2)
T_S_N=PAR(3)
T_O_N=PAR(4)
T_R_N=PAR(5)
FR_N=PAR(6)/100
cp=PAR(7)
C-----------------------------------------------------------------------------------------------------------------------
C RETRIEVE THE CURRENT VALUES OF THE INPUTS TO THIS MODEL FROM THE XIN ARRAY IN SEQUENTIAL ORDER
T_S=XIN(1)
T_R=XIN(2)
FLOW=XIN(3)
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=0
C STORED(1)=... (if NITEMS > 0)
C 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=0
C 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)
IF(cp.LE.0) CALL TYPECK(-4,INFO,0,7,0)
IF(Q_N.LT.0) CALL TYPECK(-4,INFO,0,1,0)
IF(T_S_N.LT.0) CALL TYPECK(-4,INFO,0,3,0)
IF(T_O_N.LT.0) CALL TYPECK(-4,INFO,0,4,0)
IF(T_R_N.LT.0) CALL TYPECK(-4,INFO,0,5,0)
IF(R_EX.LT.1) CALL TYPECK(-4,INFO,0,2,0)
C PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL VALUES OF THE OUTPUTS HERE
C convective power emitted
OUT(1)=0
C radiative power emitted
OUT(2)=0
C outlet water temperature
OUT(3)=T_R
C mass flow rate of supply water
OUT(4)=FLOW
C mean radiator temperature
OUT(5)=T_R
C PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL STORAGE VARIABLES HERE
NITEMS=0
C STORED(1)=...
C PUT THE STORED ARRAY IN THE GLOBAL STORED ARRAY
C 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-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C RETRIEVE THE VALUES IN THE STORAGE ARRAY FOR THIS ITERATION
C NITEMS=
C CALL getStorageVars(STORED,NITEMS,INFO)
C STORED(1)=
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C CHECK THE INPUTS FOR PROBLEMS
IF(FLOW.LT.0.) CALL TYPECK(-3,INFO,3,0,0)
IF(ErrorFound()) RETURN 1
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C *** PERFORM ALL THE CALCULATION HERE FOR THIS MODEL. ***
C-----------------------------------------------------------------------------------------------------------------------
C NO FLOW CONDITIONS
IF (FLOW.LE.0) THEN
T_O=T_R
T_MEAN=T_R
Q_CONV=0
Q_RAD=0
ELSE
DELTA_T_N=(T_S_N-T_O_N)/LOG((T_S_N-T_R_N)/(T_O_N-T_R_N))
EPS=1.e-4
x=T_S*0.99
20 CONTINUE
FCT=FLOW*cp*(T_S-x)-Q_N*((T_S-x)/(LOG((T_S-T_R)/(x-T_R))
1 /DELTA_T_N))**R_EX
DFCT=-cp*FLOW-R_EX*Q_N*((x-T_R)*(T_S-x)*DELTA_T_N/LOG
1 (T_S-T_R))**(R_EX-1)*(-(x-T_R)*DELTA_T_N/LOG(T_S-T_R)
1 +(T_S-x)*DELTA_T_N/LOG(T_S-T_R))
xnew=x
x=x-FCT/DFCT
DELTA=ABS(xnew-x)
IF (DELTA.GT.EPS) THEN
GOTO 20
ELSE
xnew=T_O
T_MEAN=(T_S-T_O)/LOG((T_S-T_R)/(T_O-T_R))
FR=FR_N*((T_R+273.15+T_MEAN)**4-(T_R+273.15)**4)/((T_R+273.15+
1 DELTA_T_N)**4-(T_R+273.15)**4)/(T_MEAN/DELTA_T_N)**R_EX
Q_CONV=Q_N*(T_MEAN/DELTA_T_N)**R_EX*(1-FR)
Q_RAD=Q_N*(T_MEAN/DELTA_T_N)**R_EX-Q_CONV
ENDIF
ENDIF
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C-----------------------------------------------------------------------------------------------------------------------
C SET THE STORAGE ARRAY AT THE END OF THIS ITERATION IF NECESSARY
C NITEMS=
C STORED(1)=
C CALL setStorageVars(STORED,NITEMS,INFO)
C-----------------------------------------------------------------------------------------------------------------------
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 convective power emitted
OUT(1)=Q_CONV
C radiative power emitted
OUT(2)=Q_RAD
C outlet water temperature
OUT(3)=T_O
C mass flow rate of supply water
OUT(4)=FLOW
C mean radiator temperature
OUT(5)=T_MEAN
C-----------------------------------------------------------------------------------------------------------------------
C EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON
RETURN 1
END
C-----------------------------------------------------------------------------------------------------------------------