[TRNSYS-users] Intel 8.1 - MVS2003.NET - differential equation

Jeff Thornton thornton at tess-inc.com
Tue Feb 7 16:02:57 PST 2006


An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20060207/c16da92e/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 75d9cac.jpg
Type: image/jpeg
Size: 167762 bytes
Desc: not available
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20060207/c16da92e/attachment-0001.jpg>
-------------- next part --------------
SUBROUTINE TYPE998(TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*)

!-----------------------------------------------------------------------------------------------------------------------
! This subroutine demonstrates the proper technique for using the Differental_Eqn subroutine to solve
! a linear differential equation in TRNSYS 16.
!
! Copyright © 2006 Thermal Energy System Specialists, LLC. All rights reserved.
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
 USE TrnsysConstants
 USE TrnsysFunctions
!-----------------------------------------------------------------------------------------------------------------------

!DEC$ATTRIBUTES DLLEXPORT :: TYPE998

!-----------------------------------------------------------------------------------------------------------------------
!TRNSYS Declarations
 IMPLICIT NONE
 DOUBLE PRECISION XIN,OUT,TIME,PAR,T,DTDT,TIME0,TFINAL,DELT,STORED            
 INTEGER*4 INFO(15),NP,NI,NOUT,ND,IUNIT,ITYPE,ICNTRL,NSTORED
 CHARACTER*3 YCHECK,OCHECK
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!User Declarations
 PARAMETER (NP=4,NI=1,NOUT=2,ND=0,NSTORED=2)
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Required TRNSYS Dimensions
 DIMENSION XIN(NI),OUT(NOUT),PAR(NP),YCHECK(NI),OCHECK(NOUT),T(ND),DTDT(ND),STORED(NSTORED)
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Declarations & Definitions for the User Variables
 DOUBLE PRECISION T_init,T_final,T_average,T_start,hs,mass,cp,T_2,a,b,Q_out
 CHARACTER (LEN=maxMessageLength) MESSAGE1
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Error Messages
 MESSAGE1='Fill in this error message and use a call to "Messages" wherever you need to reprt an error.'
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Get Global TRNSYS Simulation Variables
 TIME0=getSimulationStartTime()
 TFINAL=getSimulationStopTime()
 DELT=getSimulationTimeStep()
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Set the Version Information
 IF(INFO(7).EQ.-2) THEN
    INFO(12)=16
    RETURN 1
 ENDIF
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Do All of the Very Last Call Manipulations Here
 IF (INFO(8).EQ.-1) THEN
    RETURN 1
 ENDIF
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Do All of the After-Convergence Manipulations Here
 IF(INFO(13).GT.0) THEN

! Get the values from storage
   CALL getStorageVars(STORED,NSTORED,INFO)
   IF(ErrorFound()) RETURN 1

! Update the stored values (reset the initial temperature to the final temperature from the converged timestep)
   STORED(2)=STORED(1)

! Set the new values in storage
   CALL SetStorageVars(STORED,NSTORED,INFO)

   RETURN 1
 ENDIF
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Do All of the First Call Manipulations Here
 IF (INFO(7).EQ.-1) THEN

!  Get the Unit Number and Type Number
    IUNIT=INFO(1)
    ITYPE=INFO(2)

!  Set the INFO Array Variables to Tell TRNSYS How This Type Should Work
    INFO(6)=NOUT           
    INFO(9)=1          
    INFO(10)=0               

!  Call the TYPECK Subroutine to Compare What This Component Wants to What is Supplied in the Input File
    CALL TYPECK(1,INFO,NI,NP,ND)

!  Set the Variable Types for the Inputs and the Outputs
    DATA YCHECK/'TE1'/             
    DATA OCHECK/'TE1','PW1'/             
    CALL RCHECK(INFO,YCHECK,OCHECK)

!  Set the Size of the Storage Array
    CALL setStorageSize(NSTORED,INFO)

!  Return to the TRNSYS Engine
    RETURN 1

 ENDIF
!-----------------------------------------------------------------------------------------------------------------------

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

!  Get the Unit Number and Type Number
    IUNIT=INFO(1)
    ITYPE=INFO(2)

!  Read in the Values of the Parameters
    Mass=PAR(1) 
	hs=PAR(2)  
	Cp=PAR(3)
	T_start=PAR(4)

!  Check the Parameters for Problems
    IF(Mass<=0.) CALL TYPECK(-4,INFO,0,1,0)
    IF(hs<=0.) CALL TYPECK(-4,INFO,0,2,0)
    IF(Cp<=0.) CALL TYPECK(-4,INFO,0,3,0)
	IF(ErrorFound()) RETURN 1

!  Set the initial values of the Outputs
    OUT(1)=T_start
    OUT(2)=0.

!  Set the initial storage variables
    STORED(1)=T_start
    STORED(2)=T_start
    CALL setStorageVars(STORED,NSTORED,INFO)

!  Return to the TRNSYS Engine
    RETURN 1

ENDIF
!-----------------------------------------------------------------------------------------------------------------------

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

!-----------------------------------------------------------------------------------------------------------------------
!Reread the Parameters If Another Unit of this Type Has Been Called
  IF(INFO(1).NE.IUNIT) THEN

!  Get the Unit Number and Type Number
    IUNIT=INFO(1)
    ITYPE=INFO(2)
        
!  Read in the Values of the Parameters
    Mass=PAR(1) 
	hs=PAR(2)  
	Cp=PAR(3)
	T_start=PAR(4)

 ENDIF
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Get the Values of the Inputs to the Model at the Current Iteration
 T_2=XIN(1)							!Driving force temperature [C]
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Check the Inputs for Problems
 If(DABS(T_2)>1.D+10) CALL TYPECK(-3,INFO,1,0,0)
 If(ErrorFound()) RETURN 1
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Retrieve the Values from Storage
 CALL getStorageVars(STORED,NSTORED,INFO)
 IF(ErrorFound()) RETURN 1

 T_init=STORED(2)
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Perform all of the iterative call calculations here.

!Set up the differential equation in the form dT/dt = aT + b from:  mass * Cp * dT/dt = - hs * (T-T_2)
 a=-hs/mass/Cp
 b=hs/mass/Cp*T_2

!Call the differential equation solver
 CALL Differential_Eqn(TIME,a,b,T_init,T_final,T_average)

!Solve for the energy lost from the mass
 Q_out=hs*(T_average-T_2)
!-----------------------------------------------------------------------------------------------------------------------


!-----------------------------------------------------------------------------------------------------------------------
!Set the Temporary Values in Storage
 STORED(1)=T_final
 CALL SetStorageVars(STORED,NSTORED,INFO)
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Set the Outputs from the Model
 Out(1)=T_average
 Out(2)=Q_out
!-----------------------------------------------------------------------------------------------------------------------

!-----------------------------------------------------------------------------------------------------------------------
!Everything is Done at this Iteration, Return to the Engine
 RETURN 1
 END
!-----------------------------------------------------------------------------------------------------------------------






More information about the TRNSYS-users mailing list