[TRNSYS-users] Where to allocate dynamic arrays in new types

David BRADLEY d.bradley at tess-inc.com
Thu Oct 16 06:48:50 PDT 2014


Hans,
   Using dynamically allocated arrays can be a little tricky. Remember 
that when you use more than one instance of a Type in a simulation, the 
same data structures are being used in the code for each instance. That 
means that you cannot rely on locally defined data structures to hold 
values from one iteration (or timestep) to the next. Incidentally, that 
is why we reread parameters if we notice that INFO(1) is not equal to 
IUNIT (in Trnsys16) or if the getIsReReadParameters() function returns 
.true. (in Trnsys17); the local variables that hold the parameter values 
have to be reset for each instance.

   If you want to use dynamically allocated arrays then the safest thing 
to do is to reallocate and deallocate them each iteration. That is 
likely going to be time consuming and may also defeat the purpose of the 
arrays. Another option would be to use TRNSYS's built-in storage (the S 
array in Trnsys15, the setStorageSize(), setStorageVars(), and 
getStorageVars() functions in Trnsys16 and the 
setNumberStoredVariables(), setStaticArrayValue() and 
getStaticArrayValue() functions in Trnsys17). You can reserve however 
many spaces you want at the beginning of the simulation (and it doesn't 
have to be the same number for each instance of the Type in the 
simulation). All of the allocating and deallocating is taking place 
behind the scenes.
Kind regards,
  David


On 10/16/2014 04:04, Hans Böhm wrote:
> Dear trnsys users,
>
>  i wrote a new type for my trnsys project, which uses allocatable/dynamic
>  arrays. The array size is defined by a parameter in the proforma.
>
>  Currently i allocate the arrays during initialization call (INFO(7) 
> == -1)
>  and deallocate them during the last call (INFO(8) == -1) as 
> recommended at
> https://www.mail-archive.com/trnsys-users@engr.wisc.edu/msg01360.html.
>
>  This works so far as long as i only use one unit of this type in my
> simulation. When i add another one i get the following error:
>
>  forrtl: severe (151): allocatable array is already allocated
>
>  So where/how do i have to allocate and deallocate my arrays to be 
> able to
> use multiple units of my type? Any ideas?
>
> Thanks,
>
> Hans Böhm
>
>
> _______________________________________________
> TRNSYS-users mailing list
> TRNSYS-users at lists.onebuilding.org
> http://lists.onebuilding.org/listinfo.cgi/trnsys-users-onebuilding.org
>

-- 
***************************
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 at tess-inc.com

http://www.tess-inc.com
http://www.trnsys.com




More information about the TRNSYS-users mailing list