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

Re: [TRNSYS-users] controlling the passage to the next time steps (reiter)



Dear Michael,

Thank you so much for your quick answer,

Actually, what i did long time ago in Trnsys 13.1 was the following.

I was simulating a greenhouse with a thermal storage (water tank), the logic of the control was to initiate each time step with the hypothesis that nothing is done (neutral, zero control). Then once converged, check if it is too cold or too warm then going toward controlling the system by iterating again for each possible case (if too warm, case 1, then 2, then 3, then 4 etc, same when heating is needed. This allowed me to reinitiate the iteration and convergence  until the correct physical case be obtained. Like that i did have any trouble of convergence to the wrong physical case.

 

 

See a short description below. Written in good old f77.

the philosophy is the following:
In my own control routine, at each iteration, I check if the control configuration is OK. If it is ok then the variable "ireiter" is set to 0, otherwise it is set to 1, and one start again as if it was the begining of the same time step.

In my control routine I have the various control cases numbered with the variable "icas", the variable "icaschk" represents the numbered cases after check of the physical conditions obtained.
If icaschk does not equal icas after the checks, then I have another variable called "icorrcas" which is set to either +1 or -1 and will drive the control to another control case for the next iteration on the same timestep.

In the routine blockdat.for, I have added two commons. The second /sunsp/ is actually not needed and was just there to print out variable during debugging.
-------------------------------------------------------------------------
in blockdat

C MODIF 00000 PJ BEGIN
       COMMON /CHKSTEP/ ireiter, icas, icaschk
       COMMON /sunsp/ tsunsp, tset, tmax, tload, tsto, text
C MODIF 00000 PJ END
-------------------------------------------------------------------------

Then in main, I have the same commons, I have added a new label 10001 in order to be able to start the iteration from scratch again, which is checked with a test on the variable ireiter (if = 0 then go straight, if .gt. 0, then start to reiter again)

-------------------------------------------------------------------------
-------------------------------------------------------------------------
in main
-------------------------------------------------------------------------

c modif 00000 pj begin
       COMMON /CHKSTEP/ IREITER , icas, icaschk
       COMMON /sunsp/ tsunsp, tset, tmax, tload, tsto, text
c modif 00000 pj end

-------------------------------------------------------------------------

C ********************** MAIN SIMULATION LOOP **************************
100   IF (DONE) GO TO 999
      CALL CLOCK(TIME,DONE,2)
C  modif 00000 pj begin
c added label 10001 used for reiter of the time step
10001 IF (NDERIV.EQ.0) THEN
c modif 00000 pj end

-------------------------------------------------------------------------

370       CONTINUE
         ENDIF

C       SWITCH PREDICTED AND CORRECTED VALUES
        I = PRED
        PRED = CORR
        CORR = I
        INTG = 2
        IF (IRECUR.GT.0) INTG = 3
        IF ((IRECUR.GT.0.OR.NCALLS.GT.0).AND.(ICT.EQ.0)) GO TO 200

C ************************************************************
C MODIF 00000 PJ BEGIN (LABELED COMMON ADDED IN BLOCKDAT_M.FOR, )
c control_iter retuen a variable reiter (in common labelled CHKSTEP)       
C REITER =0 GO ON TO NEXT TIME STEP
C        =1 REITER ON THE SAME TIME STEP
      call control_iter(time)
       if (ireiter .gt. 0) then
       ireiter=ireiter+1
       icasmain=icas
             icaschkm=icaschk
       timereit=max(0.,time)
c      WRITE(*,*) "reiter ", timereit, icasmain, icaschkm
       tsunspm=tsunsp
       tsetm=tset
       tloadm=tload
       tmaxm=tmax
       stom=tsto
       textm=text
c      write (*,*) "  tsunsp=", tsunspm, "  tset=",tsetm," text=",textm
c      write (*,*) "  tload=", tloadm, "  tmax=",tmaxm," tsto=",tsto 
c      write (*,*) icasmain
c      write (*,*) icaschkm
c      CALL PRINT(TIME,DONE)
       goto 10001
       endif
C MODIF 00000 PJ END

-------------------------------------------------------------------------
-------------------------------------------------------------------------

Then in exec.for, one has also modified to set the flag to reiter

-------------------------------------------------------------------------
-------------------------------------------------------------------------
in exec
-------------------------------------------------------------------------
c modif 00000 pj begin
       COMMON /CHKSTEP/ IREITER, icas, icaschk
c modif 00000 pj end
-------------------------------------------------------------------------

110         INFO(7,J) = -1
        ELSE
          DO 111 J = 1, NUNITS
            CALL(J) = CALL1(J)
c modif 00000 pj begin
c added info(7,j) =0 for the case where one wants to reiter on the same
c time step
       if (ireiter .le. 0) then
             INFO(7,J) = -1
       else
             CALL(J) = .TRUE.
             INFO(7,J) = 0
       endif
111   continue     
c modif 00000 pj end
-------------------------------------------------------------------------
-------------------------------------------------------------------------

In the control routine properly, the variable ireiter is the one that I check and control.


(TRNSYS type, control routine used)
c modif 00000 pj begin
       COMMON /CHKSTEP/ IREITER, icas, icaschk
       COMMON /sunsp/ tsunsp, tset, tmax, tload, tsto, text
       SAVE /sunsp/
c modif 00000 pj end

it was working very well, and i have now also  project where the control logic sequence may not always follow a simple sequence at each time step.

I had everthing within the TRNSYS code,

 

I do now know much about ESP-r and its co-simulation, and also does not have much time for that,

So is there a way to use the type 130 to do the same in TRNSYS 17 ?

 

If you have any idea or example…

 

Best regards,

 

Pierre Jaboyedoff,

TRNSYS user since 1987,

 

 

Pierre Jaboyedoff

Ing. Thermicien Dipl. EPFL

Effin’Art

Associé

Chemin de Pré-Fleuri 6

Entrée arrière, 3 ème étage gauche

CH-1006 Lausanne

 

Tel : 00 41 21 616 11 00

Mobile : 00 41 79 668 50 88

pierre.jaboyedoff@effinart.ch

 

 

 

From: Michaël Kummert <michael.kummert@polymtl.ca>
Sent: Monday, 12 July 2021 14:52
To: 'TRNSYS users mailing list at OneBuilding.org' <trnsys-users@lists.onebuilding.org>
Cc: pierre.jaboyedoff@effinart.ch
Subject: RE: [TRNSYS-users] controlling the passage to the next time steps

 

Hello,

The co-simulator with ESP-r available in TRNSYS 17 and 18 implements something that is similar to what you are trying to do, if I understand correctly.

Once TRNSYS has converged for a time step, Type 130 checks that the iterations between the 2 programs have converged, and if that is not the case, Type 130 “forces” TRNSYS to continue iterating at the current time step.

Perhaps you can take a look at Type 130 and how it interacts with the Kernel to see whether you can use that for what you are trying to achieve.

The part I am not sure to understand is that in the co-simulation case, it makes sense to force additional iterations because the inputs coming from ESP-r will be different so the TRNSYS results after new iterations will be different. In your case, I am not sure what would cause TRNSYS to find different results, but I am probably missing something.

In any case, I hope this helps.

 

Michaël Kummert

Polytechnique Montréal

 

 

 

 

 

From: Pierre Jaboyedoff via TRNSYS-users <trnsys-users@lists.onebuilding.org>
Sent: July 9, 2021 08:35
To: trnsys-users@lists.onebuilding.org
Cc: pierre.jaboyedoff@effinart.ch
Subject: [TRNSYS-users] controlling the passage to the next time steps

 

In trnsys 13.1, i had (long time ago ..) modified the kernel of TRNSYS (see below).

The reason was to be able to check if the control routine developed was converging to the correct physical case (e.g. solar, then auxiliary etc …). If not then i was getting TRNSYS to restart the iteration on the same time step until the correct control case was obtained.

 

Has anybody done something similar for TRNSYS 17.2 ?

I have started looking for this, it seems to be located between, exec.for, trnsys.for, etc …

 

Thanks in advance,

 

Pierre Jaboyedoff

Head of BEEP PMTU Switzerland (www.beepindia.org)

Effin’Art

Associate

Chemin de Pré-Fleuri 6

Entrance at the back, 3rd floor on the left

CH-1006 Lausanne

Tel : 00 41 21 616 11 00

Mobile : 00 41 79 668 50 88

pierre.jaboyedoff@effinart.ch

 

 

 

 

 

 

 

 

 

 

 

-------------------------------------------------------------------------

-------------------------------------------------------------------------

in blockdat

 

C MODIF  PJ BEGIN

                COMMON /CHKSTEP/ ireiter, icas, icaschk

                COMMON /sunsp/ tsunsp, tset, tmax, tload, tsto, text

C MODIF  PJ END

-------------------------------------------------------------------------

 

 

 

-------------------------------------------------------------------------

-------------------------------------------------------------------------

in main

-------------------------------------------------------------------------

 

c modif  pj begin

                COMMON /CHKSTEP/ IREITER , icas, icaschk

                COMMON /sunsp/ tsunsp, tset, tmax, tload, tsto, text

c modif  pj end

 

-------------------------------------------------------------------------

 

C ********************** MAIN SIMULATION LOOP **************************

100   IF (DONE) GO TO 999

      CALL CLOCK(TIME,DONE,2)

C  modif  pj begin

c added label 10001 used for reiter of the time step

10001 IF (NDERIV.EQ.0) THEN

c modif  pj end

 

-------------------------------------------------------------------------

 

370       CONTINUE

         ENDIF

 

C       SWITCH PREDICTED AND CORRECTED VALUES

        I = PRED

        PRED = CORR

        CORR = I

        INTG = 2

        IF (IRECUR.GT.0) INTG = 3

        IF ((IRECUR.GT.0.OR.NCALLS.GT.0).AND.(ICT.EQ.0)) GO TO 200

 

C ************************************************************

C MODIF  PJ BEGIN (LABELED COMMON ADDED IN BLOCKDAT_M.FOR, )

c control_iter retuen a variable reiter (in common labelled CHKSTEP)       

C REITER =0 GO ON TO NEXT TIME STEP

C        =1 REITER ON THE SAME TIME STEP

      call control_iter(time)

                if (ireiter .gt. 0) then

                ireiter=ireiter+1

                icasmain=icas

                               icaschkm=icaschk

                timereit=max(0.,time)

c              WRITE(*,*) "reiter ", timereit, icasmain, icaschkm

                tsunspm=tsunsp

                tsetm=tset

                tloadm=tload

                tmaxm=tmax

                stom=tsto

                textm=text

c              write (*,*) "  tsunsp=", tsunspm, "  tset=",tsetm," text=",textm

c              write (*,*) "  tload=", tloadm, "  tmax=",tmaxm," tsto=",tsto 

c              write (*,*) icasmain

c              write (*,*) icaschkm

c             CALL PRINT(TIME,DONE)

                goto 10001

                endif

C MODIF  PJ END

 

-------------------------------------------------------------------------

-------------------------------------------------------------------------

 

 

 

-------------------------------------------------------------------------

-------------------------------------------------------------------------

in exec

-------------------------------------------------------------------------

c modif  pj begin

                COMMON /CHKSTEP/ IREITER, icas, icaschk

c modif  pj end

-------------------------------------------------------------------------

 

110         INFO(7,J) = -1

        ELSE

          DO 111 J = 1, NUNITS

            CALL(J) = CALL1(J)

c modif  pj begin

c added info(7,j) =0 for the case where one wants to reiter on the same

c time step

                if (ireiter .le. 0) then

                      INFO(7,J) = -1

                else

                               CALL(J) = .TRUE.

                      INFO(7,J) = 0

                endif

111   continue     

c modif  pj end

-------------------------------------------------------------------------

-------------------------------------------------------------------------

 

 

 

-------------------------------------------------------------------------

-------------------------------------------------------------------------

In my own control routine

 

c modif  pj begin

                COMMON /CHKSTEP/ IREITER, icas, icaschk

                COMMON /sunsp/ tsunsp, tset, tmax, tload, tsto, text

                SAVE /sunsp/

c modif  pj end

 

 

 

Pierre Jaboyedoff

Head of BEEP PMTU Switzerland (www.beepindia.org)

Effin’Art

Associate

Chemin de Pré-Fleuri 6

Entrance at the back, 3rd floor on the left

CH-1006 Lausanne

Tel : 00 41 21 616 11 00

Mobile : 00 41 79 668 50 88

pierre.jaboyedoff@effinart.ch