Hello, I’m having a convergence error that seems to be rooted
in the PID controller. I was wondering if anyone
could shed some light on the subject. I’m trying to model a long-haul truck sleeper cabin
climate control system. I’m using a Type 23 PID controller in
conjunction with a “seasonal switch” as the climate control
unit. The purpose of the seasonal switch is to turn the heater on
and the air conditioner off when the temperature drops below some low deadband
temperature and vice versa when the temperature rises above the high deadband
temperature. In other words, the purpose of this switch is to keep the
air conditioner from coming on during slight over-heating and the heater from
coming on during slight over-cooling. The deadband in the seasonal switch
is set by default to 5 degrees Celsius. When just this group of components is run, the output signal
from the PID controller and seasonal switch match just as they should (climate
controller.tpf). However, when a fuel-fired heater (Type 151, homegrown)
is added, the control signal starts doing some crazy stuff (Climate controller
with heater.tpf). The control signals, which should align nicely, start diverging considerably. This (I
assume) creates the convergence error that stops the simulation after a little
more than an hour with the current settings. Is there something inherent in the way I am trying to string
together these components that is making the solver diverge? Is there a
better way to go about it? I’m not looking for a total solution-
simply a pointer or two towards why the program is behaving as it is and what I
might do to get back on track. Please let me know if you need any other
files. Thank you in advance for your time, Ethan Lust 301.405.8672 (desk) 757.636.8727 (cell) University of Maryland |
SUBROUTINE TYPE151 (TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*) C************************************************************************ C Object: Espar D2/D4 direct-fired space heater C Simulation Studio Model: Type151 C C Author: Ethan Lust C Editor: C Date: March 31, 2008 last modified: April 1, 2008 C C C *** C *** Model Parameters C *** C model - [2;4] C system_voltage V [0;+Inf] C *** C *** Model Inputs C *** C control_input - [0;+Inf] C *** C *** Model Outputs C *** C heat_output kJ/hr [0;+Inf] C fuel_consumption l/hr [0;+Inf] C air_flow_rate m^3/s [0;+Inf] C power_draw 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 :: TYPE151 !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=2,NI=1,NOUT=4,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 INTEGER model INTEGER system_voltage C INPUTS DOUBLE PRECISION control_input C OUTPUTS DOUBLE PRECISION heat_output DOUBLE PRECISION fuel_consumption DOUBLE PRECISION air_flow_rate DOUBLE PRECISION power_draw C----------------------------------------------------------------------------------------------------------------------- C READ IN THE VALUES OF THE PARAMETERS IN SEQUENTIAL ORDER model=PAR(1) system_voltage=PAR(2) C----------------------------------------------------------------------------------------------------------------------- C RETRIEVE THE CURRENT VALUES OF THE INPUTS TO THIS MODEL FROM THE XIN ARRAY IN SEQUENTIAL ORDER control_input=XIN(1) 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) C PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL VALUES OF THE OUTPUTS HERE C heat_output OUT(1)=0 C fuel_consumption OUT(2)=0 C air_flow_rate OUT(3)=0 C power_draw OUT(4)=0 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 C IF(...) CALL TYPECK(-3,INFO,'BAD INPUT #',0,0) C IF(IERROR.GT.0) RETURN 1 C----------------------------------------------------------------------------------------------------------------------- C----------------------------------------------------------------------------------------------------------------------- C *** PERFORM ALL THE CALCULATION HERE FOR THIS MODEL. *** C----------------------------------------------------------------------------------------------------------------------- C ADD YOUR COMPONENT EQUATIONS HERE; BASICALLY THE EQUATIONS THAT WILL C CALCULATE THE OUTPUTS BASED ON THE PARAMETERS AND THE INPUTS. REFER TO C CHAPTER 3 OF THE TRNSYS VOLUME 1 MANUAL FOR DETAILED INFORMATION ON C WRITING TRNSYS COMPONENTS. !Assumptions !*startup power is negligable over long time scales !D2 Output calculations IF (model .EQ. 2) THEN IF (control_input .GT. 0 .AND. control_input .LE. .25) THEN !low heat_output = 3060 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*0.7*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*0.3*3.6 !(kJ/hr) END IF fuel_consumption = 0.10 !(L/hr) air_flow_rate = 0.008968 !(m^3/s) ELSE IF (control_input .GT.0.25 .AND. control_input .LE. 0.5) THEN !medium heat_output = 4320 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*1.0*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*0.5*3.6 !(kJ/hr) END IF fuel_consumption = 0.14 !(L/hr) air_flow_rate = 0.012744 !(m^3/s) ELSE IF (control_input .GT. 0.5 .AND. control_input .LE. 0.75) THEN !high heat_output = 6480 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*1.9*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*1.0*3.6 !(kJ/hr) END IF fuel_consumption = 0.23 !(L/hr) air_flow_rate = 0.01888 !(m^3/s) ELSE IF (control_input .GT. 0.75 .AND. control_input .LE. 1) THEN !boost heat_output = 7920 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*1.4*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*2.8*3.6 !(kJ/hr) END IF fuel_consumption = 0.28 !(L/hr) air_flow_rate = 0.022656 !(m^3/s) ELSE !off heat_output = 0 !(kJ/hr) power_draw = 0 !(kJ/hr) fuel_consumption = 0 !(L/hr) air_flow_rate = 0 !(m^3/s) END IF END IF !D4 Output calculations IF (model .EQ. 4) THEN IF (control_input .GT. 0 .AND. control_input .LE. .25) THEN !low heat_output = 3600 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*0.6*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*0.3*3.6 !(kJ/hr) END IF fuel_consumption = 0.13 !(L/hr) air_flow_rate = 0.01416 !(m^3/s) ELSE IF (control_input .GT. .25 .AND. control_input .LE. 0.5) THEN !medium heat_output = 7200 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*1.1*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*0.5*3.6 !(kJ/hr) END IF fuel_consumption = 0.25 !(L/hr) air_flow_rate = 0.0236 !(m^3/s) ELSE IF (control_input .GT. 0.5 .AND. control_input .LE. 0.75) THEN !high heat_output = 10800 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*2.0*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*1.0*3.6 !(kJ/hr) END IF fuel_consumption = 0.38 !(L/hr) air_flow_rate = 0.032568 !(m^3/s) ELSE IF (control_input .GT. 0.75 .AND. control_input .LE. 1) THEN !boost heat_output = 14400 !(kJ/hr) IF (system_voltage .EQ. 12) THEN power_draw = system_voltage*3.3*3.6 !(kJ/hr) ELSE IF (system_voltage .EQ. 24) THEN power_draw = system_voltage*1.7*3.6 !(kJ/hr) END IF fuel_consumption = 0.51 !(L/hr) air_flow_rate = 0.04012 !(m^3/s) ELSE !off heat_output = 0 !(kJ/hr) power_draw = 0 !(kJ/hr) fuel_consumption = 0 !(L/hr) air_flow_rate = 0 !(m^3/s) END IF END IF 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 heat_output OUT(1)=heat_output C fuel_consumption OUT(2)=fuel_consumption C air_flow_rate OUT(3)=air_flow_rate C power_draw OUT(4)=power_draw C----------------------------------------------------------------------------------------------------------------------- C EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON RETURN 1 END C-----------------------------------------------------------------------------------------------------------------------
SUBROUTINE TYPE200 (TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*) !************************************************************************ ! Object: Seasonal Switch ! Simulation Studio Model: Type200 ! ! Author: Ethan Lust ! Editor: ! Date: April 23, 2008 last modified: April 23, 2008 ! ! ! *** ! *** Model Parameters ! *** ! setpoint C [-Inf;+Inf] ! deadband C [0;+Inf] ! *** ! *** Model Inputs ! *** ! input_signal - [-Inf;+Inf] ! T_space ! [-Inf;+Inf] ! *** ! *** Model Outputs ! *** ! output_signal - [-Inf;+Inf] ! switch - [0;1] ! *** ! *** Model Derivatives ! *** ! (Comments and routine interface generated by TRNSYS Studio) !************************************************************************ ! TRNSYS acess functions (allow to acess TIME etc.) USE TrnsysConstants USE TrnsysFunctions !----------------------------------------------------------------------------------------------------------------------- ! REQUIRED BY THE MULTI-DLL VERSION OF TRNSYS !DEC$ATTRIBUTES DLLEXPORT :: TYPE200 !SET THE CORRECT TYPE NUMBER HERE !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! 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 !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! USER DECLARATIONS - SET THE MAXIMUM NUMBER OF PARAMETERS (NP), INPUTS (NI), ! OUTPUTS (NOUT), AND DERIVATIVES (ND) THAT MAY BE SUPPLIED FOR THIS TYPE PARAMETER (NP=2,NI=3,NOUT=2,ND=0,NSTORED=1) !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! REQUIRED TRNSYS DIMENSIONS DIMENSION XIN(NI),OUT(NOUT),PAR(NP),YCHECK(NI),OCHECK(NOUT), 1 STORED(NSTORED),T(ND),DTDT(ND) INTEGER NITEMS !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! ADD DECLARATIONS AND DEFINITIONS FOR THE USER-VARIABLES HERE ! PARAMETERS DOUBLE PRECISION setpoint DOUBLE PRECISION deadband ! INPUTS DOUBLE PRECISION input_signal DOUBLE PRECISION T_space ! OUTPUTS DOUBLE PRECISION output_signal DOUBLE PRECISION switch ! LOCAL VARIABLE DOUBLE PRECISION error !----------------------------------------------------------------------------------------------------------------------- ! READ IN THE VALUES OF THE PARAMETERS IN SEQUENTIAL ORDER setpoint=PAR(1) deadband=PAR(2) !----------------------------------------------------------------------------------------------------------------------- ! RETRIEVE THE CURRENT VALUES OF THE INPUTS TO THIS MODEL FROM THE XIN ARRAY IN SEQUENTIAL ORDER input_signal=XIN(1) T_space = XIN(2) switch = XIN(3) IUNIT=INFO(1) ITYPE=INFO(2) !----------------------------------------------------------------------------------------------------------------------- ! SET THE VERSION INFORMATION FOR TRNSYS IF(INFO(7).EQ.-2) THEN INFO(12)=16 RETURN 1 ENDIF !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! DO ALL THE VERY LAST CALL OF THE SIMULATION MANIPULATIONS HERE IF (INFO(8).EQ.-1) THEN RETURN 1 ENDIF !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! PERFORM ANY 'AFTER-ITERATION' MANIPULATIONS THAT ARE REQUIRED HERE ! e.g. save variables to storage array for the next timestep ! IF (INFO(13).GT.0) THEN ! NITEMS=1 ! STORED(1)= switch ! CALL setStorageVars(STORED,NITEMS,INFO) ! RETURN 1 ! ENDIF ! !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! DO ALL THE VERY FIRST CALL OF THE SIMULATION MANIPULATIONS HERE IF (INFO(7).EQ.-1) THEN ! 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 ! SET THE REQUIRED NUMBER OF INPUTS, PARAMETERS AND DERIVATIVES THAT THE USER SHOULD SUPPLY IN THE INPUT FILE ! IN SOME CASES, THE NUMBER OF VARIABLES MAY DEPEND ON THE VALUE OF PARAMETERS TO THIS MODEL.... NIN=NI NPAR=NP NDER=ND ! CALL THE TYPE CHECK SUBROUTINE TO COMPARE WHAT THIS COMPONENT REQUIRES TO WHAT IS SUPPLIED IN ! THE TRNSYS INPUT FILE CALL TYPECK(1,INFO,NIN,NPAR,NDER) ! SET THE NUMBER OF STORAGE SPOTS NEEDED FOR THIS COMPONENT ! NITEMS=1 ! CALL setStorageSize(NITEMS,INFO) ! RETURN TO THE CALLING PROGRAM RETURN 1 ENDIF !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! DO ALL OF THE INITIAL TIMESTEP MANIPULATIONS HERE - THERE ARE NO ITERATIONS AT THE INTIAL TIME IF (TIME .LT. (getSimulationStartTime() + . getSimulationTimeStep()/2.D0)) THEN ! SET THE UNIT NUMBER FOR FUTURE CALLS IUNIT=INFO(1) ITYPE=INFO(2) ! CHECK THE PARAMETERS FOR PROBLEMS AND RETURN FROM THE SUBROUTINE IF AN ERROR IS FOUND ! IF(...) CALL TYPECK(-4,INFO,0,"BAD PARAMETER #",0) ! PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL VALUES OF THE OUTPUTS HERE ! output_signal OUT(1)=0 ! switch ! OUT(2)=0 ! PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL STORAGE VARIABLES HERE ! NITEMS=1 ! STORED(1)= 0 ! PUT THE STORED ARRAY IN THE GLOBAL STORED ARRAY ! CALL setStorageVars(STORED,NITEMS,INFO) ! RETURN TO THE CALLING PROGRAM RETURN 1 ENDIF !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! *** ITS AN ITERATIVE CALL TO THIS COMPONENT *** !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! RETRIEVE THE VALUES IN THE STORAGE ARRAY FOR THIS ITERATION ! NITEMS= 1 ! CALL getStorageVars(STORED,NITEMS,INFO) ! STORED(1)= switch !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! CHECK THE INPUTS FOR PROBLEMS ! IF(...) CALL TYPECK(-3,INFO,'BAD INPUT #',0,0) ! IF(IERROR.GT.0) RETURN 1 !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! *** PERFORM ALL THE CALCULATION HERE FOR THIS MODEL. *** !----------------------------------------------------------------------------------------------------------------------- input_signal = abs(input_signal) error = setpoint - T_space if (switch .EQ. 0D0) then if (error .LE. -deadband) then switch = 1D0 !Turns A/C on and heat off end if else if (switch .EQ. 1D0) then if (error .GE. deadband) then switch = 0D0 !Turns heat on and A/C off end if end if if (switch .EQ. 0D0) then if (error .GE. 0) then output_signal = input_signal else if (error .LT. 0) then output_signal = 0 end if else if (switch .EQ. 1D0) then if (error .LE. 0) then output_signal = -input_signal else if (error .GT. 0) then output_signal = 0 end if end if !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! SET THE STORAGE ARRAY AT THE END OF THIS ITERATION IF NECESSARY ! NITEMS= 1 ! STORED(1)= switch ! CALL setStorageVars(STORED,NITEMS,INFO) !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! REPORT ANY PROBLEMS THAT HAVE BEEN FOUND USING CALLS LIKE THIS: ! CALL MESSAGES(-1,'put your message here','MESSAGE',IUNIT,ITYPE) ! CALL MESSAGES(-1,'put your message here','WARNING',IUNIT,ITYPE) ! CALL MESSAGES(-1,'put your message here','SEVERE',IUNIT,ITYPE) ! CALL MESSAGES(-1,'put your message here','FATAL',IUNIT,ITYPE) !----------------------------------------------------------------------------------------------------------------------- !----------------------------------------------------------------------------------------------------------------------- ! SET THE OUTPUTS FROM THIS MODEL IN SEQUENTIAL ORDER AND GET OUT ! output_signal OUT(1) = output_signal ! switch OUT(2) = switch !----------------------------------------------------------------------------------------------------------------------- ! EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON RETURN 1 END !-----------------------------------------------------------------------------------------------------------------------
Attachment:
Type151.tmf
Description: Binary data
Attachment:
Type200.tmf
Description: Binary data
Attachment:
Climate Controller.tpf
Description: Binary data
Attachment:
Climate Controller with heater.tpf
Description: Binary data