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

[TRNSYS-users] R: Create a new type



Dear all,

I'm trying to create a new type, a water tank, using g95 as compiler. Running my script into g95 (the script is in attachment) the only error I get now is  "undefined reference to `trnsysfunctions_MP_getsimulationstarttime'”. 
Any suggestion? 
Thanks,

Tiziano 

Università di Bologna
Dipartimento di Ingegneria Energetica Nucleare e del Controllo Ambientale - DIENCA
Via del Risorgimento, 2 - 40136
Bologna - Italia
________________________________________
Inizio: jeannieboef [jeannieboef@googlemail.com]
Inviato: venerdì 30 marzo 2012 18.24
Fine: David BRADLEY
Cc: Tiziano Terlizzese; trnsys-users@cae.wisc.edu
Oggetto: Re: [TRNSYS-users] Create a new type

Beware! I'm currently trying with g95. As a start the guidelines are
good, but I have found a few problems that are not mentioned there.
Find the gg95 google group. search for DMOD to find my conversation. I
have also posted to this group, but I'm having a bouncing problem atm.
Since that guild has been written there have been updates to the
constants, data, and functions modules  which should be included in
your type code. I would take the source code for these and adjust and
compile them one by one until they compile without error. As I've
said, my type compiles fine and runs, but is not working properly. I
suspect the problem is with the old !DEC$ attributes dllexport::...
statement which is ignored as a comment by g95. The gcc 4.x.x
directive has suggested !gcc$ as an easy replace for !DEC$, which
works a little better, but I'm still having problems. The type
subroutine and some functions are missing an entry point pointer and
information gets lost. I've not solved this issue yet and am a bit out
of my depth here. I think a basic input output function will work fine
without the pointers.

Let me know if anyone has working compiled by g95 source code to
share. I'll post mine when and if it ever works.

goodluck

Sent from my iPhone

On 30.03.2012, at 17:19, David BRADLEY <d.bradley@tess-inc.com> wrote:

> Tiziano,
>  I am not entirely sure that I understand your question. Fortran 90
> is a language while Compaq Visual Fortran is a compiler. Most Types
> in Trnsys16 were written Fortran77 language conventions but some
> where written using Fortran90 conventions; the two language
> conventions should be able to interact with each other without
> problems.
>
>  Whichever set of language conventions you choose, you need some
> kind of compiler that can create a DLL containing the source code
> for your Type. Some users have succeeded in using the free G95
> compiler to make user Types. There is a tutorial available at: http://sel.me.wisc.edu/trnsys/downloads/tutorials_and_examples/tutex17.htm
> . While the tutorial is written based on Trnsys17, most of it
> applies to Trnsys16 as well.
>
> Kind regards,
> David
>
> On 3/30/2012 04:14, Tiziano Terlizzese wrote:
>> Dear trnsys users,
>>
>> I need to create a new type, a rain water tank. It seems that the
>> only way to create a new type is to have at disposal COMPAQ Visual
>> Fortran. Is that correct? Can't you use FORTRAN 90 instead of
>> compaq visual fortran?
>> The problem I faced in using fortran 90 is that transys constants
>> are not already implemented into it. Is there a way out that won't
>> imply to buy Compaq Visual Fortran? I have TRNSYS 16 version.
>>
>> Thank you in advance for your help.
>> Greetings,
>>
>> Tiziano Terlizzese
>>
>> Università di Bologna
>> Dipartimento di Ingegneria Energetica Nucleare e del Controllo
>> Ambientale - DIENCA
>> Via del Risorgimento, 2 - 40136
>> Bologna - Italia
>> _______________________________________________
>> TRNSYS-users mailing list
>> TRNSYS-users@cae.wisc.edu
>> https://mailman.cae.wisc.edu/listinfo/trnsys-users
>>
>
> --
> ***************************
> David BRADLEY
> Principal
> Thermal Energy Systems Specialists, LLC
> 22 North Carroll Street - suite 370
> Madison, WI  53703 USA
>
> P:+1.608.274.2577
> F:+1.608.278.1475
> d.bradley@tess-inc.com
>
> http://www.tess-inc.com
> http://www.trnsys.com
>
> _______________________________________________
> TRNSYS-users mailing list
> TRNSYS-users@cae.wisc.edu
> https://mailman.cae.wisc.edu/listinfo/trnsys-users
                                               SUBROUTINE TYPE241 (TIME,XIN,OUT,T,DTDT,PAR,INFO,ICNTRL,*) 
!************************************************************************
! Object: Rainwater Tank
! Simulation Studio Model: Rainwater Tank
! 
! Author: Francesco Stella
! Editor: 
! Date:  April 16, 2012 last modified: April 16, 2012
! 
! 
! *** 
! *** Model Parameters 
! *** 
!                                             Capacity              m^3 [0;+Inf]
!                                             Level lower limit              m^3 [0;+Inf]
!                                             Level post recovery       m^3 [0;+Inf]
!                                             Starting level     m^3 [0;+Inf]

!*** 
!*** Model Inputs 
!*** 
!                                             Balance                m^3 [-Inf;+Inf]

!*** 
!*** Model Outputs 
!*** 
!                                             Filling tank          m^3 [-inf;+Inf]
!                                             Overflow water               m^3 [0;+Inf]
!                                             Recovery water               m^3 [0;+Inf]

!*** 
!*** 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 :: TYPE241                                                     !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=4,NI=1,NOUT=3,ND=0,NSTORED=0)
!----------------------------------------------------------------------------------------------------------------------

!----------------------------------------------------------------------------------------------------------------------
!   REQUIRED TRNSYS DIMENSIONS
      DIMENSION XIN(NI),OUT(NOUT),PAR(NP),YCHECK(NI),OCHECK(NOUT),STORED(NSTORED),T(ND),DTDT(ND)
      INTEGER NITEMS
!----------------------------------------------------------------------------------------------------------------------
!----------------------------------------------------------------------------------------------------------------------
!   ADD DECLARATIONS AND DEFINITIONS FOR THE USER-VARIABLES HERE


!   PARAMETERS
      DOUBLE PRECISION CAPACITY
      DOUBLE PRECISION LEVELlowerLIMIT
      DOUBLE PRECISION LEVELpostRECOVERY
      DOUBLE PRECISION STARTINGlevel

!   INPUTS
      DOUBLE PRECISION BALANCE

!   OUTPUTS
      DOUBLE PRECISION FILLINGtank
      DOUBLE PRECISION OVERFLOWwater
      DOUBLE PRECISION RECOVERYwater

!----------------------------------------------------------------------------------------------------------------------
!      READ IN THE VALUES OF THE PARAMETERS IN SEQUENTIAL ORDER
      CAPACITY=PAR(1)
      LEVELlowerLIMIT=PAR(2)
      LEVELpostRECOVERY=PAR(3)
      STARTINGlevel=PAR(4)

!----------------------------------------------------------------------------------------------------------------------
!   RETRIEVE THE CURRENT VALUES OF THE INPUTS TO THIS MODEL FROM THE XIN ARRAY IN SEQUENTIAL ORDER

      BALANCE=XIN(1)
                   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=0
!                 STORED(1)=... (if NITEMS > 0)
!       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=0
!                 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
!                              
                                OUT(1)=FILLINGtank
!                              OUT(2)=OVERFLOWwater 
!                              OUT(3)=RECOVERYwater

!      PERFORM ANY REQUIRED CALCULATIONS TO SET THE INITIAL STORAGE VARIABLES HERE
         NITEMS=0
!                 STORED(1)=...

!      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=
!              CALL getStorageVars(STORED,NITEMS,INFO)
!     STORED(1)=
!----------------------------------------------------------------------------------------------------------------------
!----------------------------------------------------------------------------------------------------------------------
!   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. ***
!----------------------------------------------------------------------------------------------------------------------
                FILLINGtank=STARTINGlevel
                FILLINGtank=FILLINGtank + BALANCE
                IF (FILLINGtank < LEVELlowerLIMIT) THEN
                   RECOVERYwater = 0.25 * CAPACITY - FILLINGtank
                   WRITE(*,*) 'RECOVERYwater = ', RECOVERYwater
                  FILLINGtank = 0.25 * CAPACITY
                  RETURN
                ELSE IF (FILLINGtank > CAPACITY) THEN
                   OVERFLOWwater = FILLINGtank - (1.00 * CAPACITY)
                   WRITE(*,*) 'OVERFLOWwater = ', OVERFLOWwater
                  FILLINGtank = 1.00 * CAPACITY
                END IF
                WRITE(*,*) 'FILLINGtank = ', FILLINGtank
!----------------------------------------------------------------------------------------------------------------------
!   SET THE OUTPUTS FROM THIS MODEL IN SEQUENTIAL ORDER AND GET OUT

                OUT(1)=FILLINGtank
                OUT(2)=OVERFLOWwater
                OUT(3)=RECOVERYwater

!----------------------------------------------------------------------------------------------------------------------
!   EVERYTHING IS DONE - RETURN FROM THIS SUBROUTINE AND MOVE ON
      RETURN 1
      END
!----------------------------------------------------------------------------------------------------------------------