[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [TRNSYS-users] Intel 8.1 - MVS2003.NET - differential equation
At 10:52 AM 1/26/2006, Jocelyn.Pacquelet@UTBM.fr wrote:
Also we'd like to know if
anybody has already try to solve a differential
equation with the function called Differential_EQN() (manual programmer's
guide
8.4.4.3) as the example provided in the manual is not very
clear.
"Could you please send me an example of differential equation of the
same type as
: dT/dt=(hs/m*cp)*(T-T2). Where hs,m,cp are constant."
Actually the formulation would be: dT/dt=(hs/m*cp)*(T2-T); and that's the
version I coded (m Cp dT/dt = Qin - Qout)
As promised a week or so ago, here is a simple TRNSYS 16 source code
file, input file, and output results demonstrating the use of the
Differental_eqn subroutine. Let me know if you have any
questions.
INPUT FILE:
VERSION 16
CONSTANTS 3
START=0
STOP=168
STEP=1
SIMULATION START STOP
STEP ! Start
time End
time Time
step
TOLERANCES 0.001
0.001
!
Integration Convergence
LIMITS 100 1000
100
! Max
iterations
Max warnings Trace limit
DFQ
1
! TRNSYS
numerical integration solver method
WIDTH
80
! TRNSYS output
file width, number of characters
LIST
! NOLIST
statement
SOLVER 0 1
1
! Solver
statement Minimum
relaxation
factor Maximum
relaxation factor
NAN_CHECK
0
! Nan DEBUG
statement
OVERWRITE_CHECK
0
! Overwrite DEBUG
statement
EQSOLVER
0
! EQUATION SOLVER
statement
EQUATIONS 1
T_2=30+30*SIN(TIME*3)
UNIT 1 TYPE 998 Sample DiffEq
PARAMETERS 4
*Mass Hs Cp Ti
100.0 15.0 4.19 10.0
INPUTS 1
T_2
30.
UNIT 65 TYPE 65
PARAMETERS 12
2 1 -20 80 -1000 1000 1 7
1 0 -1 -1
INPUTS 3
T_2 1,1 1,2
T_2 T_average Q_out
END
______________________________________________________________________________________________
Source code file attached.
Jeff
*********************************************************************************
Thermal Energy System Specialists (TESS)
Jeff
Thornton
2916 Marketplace
Drive
Principal
Suite 104
Phone: (608)
274-2577
Madison WI
53719
Fax: (608)
278-1475
USA
E-mail: thornton@tess-inc.com
Web
Page:
www.tess-inc.com
"Providing software solutions for today's energy engineering
projects"
*********************************************************************************
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
!-----------------------------------------------------------------------------------------------------------------------