[TRNSYS-users] problem between GetStorageVars and type65d

David BRADLEY d.bradley at tess-inc.com
Fri Oct 17 09:31:23 PDT 2014


Sergio,
   The caveats first: I have no experience with writing C++ components 
and don't have a compiler that I can use to remake your dll and test the 
projects.

   That said, try switching TRNSYS into it's "debug" mode. This does not 
mean that the TRNDLL or your Type need to be recompiled in debug mode. 
It simply means that you change a the "debug mode" switch from "false" 
to "true" in the project's control cards (where you set the simulation 
start and stop time). This will activate a number of checks when the 
simulation is run. The checks are time consuming so the simulation runs 
more slowly (thus the switch). Specifically you will get a more helpful 
error message if your Type writes outside of the out() array space that 
it reserved for itself or if one of its outputs was set to an NaN 
condition. From the behavior that you describe I would guess that one of 
these two situations is at fault.
Kind regards,
  David


On 10/16/2014 22:40, Sergio.Pintaldi at csiro.au wrote:
>
> Dear TRNSYS users,
>
> I have a problem, when I try to use the storage array in TRNSYS using 
> the specific funcions (setstoragesize , getstoragevars, 
> setstoragevars). I created a new type and use the type65d to see the 
> results while the simulation is running. The main problem is that the 
> type on itself works properly without any error, but as soon as I link 
> their outputs to the input of the online plotter, I obtained a 
> "invalid floating point operation" error at the initial timestep, 
> forcing the simulation to stop. Also if the two types are not linked, 
> it give me the error. Only if I set the number of right and left axis 
> variables both to 0, the simulation runs properly.
>
> This error has been encountered by others too (e.g. 
> http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/2013-April/011470.html 
> , 
> http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/2012-February/009376.html 
> , 
> http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/2010-July/006481.html 
> ).
>
> TRNSYS version: 17 OS: Windows 7 64bit, the type is compiled as .cpp 
> with Microsoft Visual Studio Express 2012 and linked as .dll
>
> TRNSYS.h has been modified to include the storage functions:
>
> extern "C" __declspec(dllimport) double         _cdecl 
> SETSTORAGESIZE(int* NSTORE,int info[]);
>
> extern "C" __declspec(dllimport) double         _cdecl 
> SETSTORAGEVARS(double* STORE_IN,int* NSTORE,int info[]);
>
> extern "C" __declspec(dllimport) double         _cdecl 
> GETSTORAGEVARS(double* STORE_OUT,int* NSTORE,int info[]);
>
> #define SetStorageSize SETSTORAGESIZE
>
> #define SetStorageVars SETSTORAGEVARS
>
> #define GetStorageVars GETSTORAGEVARS
>
> Below there is a description of my type:
>
> In order to make it simple I created a simplified version that takes 
> as input one temperature, as parameters the number of nodes of the 
> tube and the shell and the initial temperaure, and produces 4 outputs, 
> outlet tube temperture and 3 temperatures in the shell. The role of 
> the type is to increase the temperatures of the tube and the shell by 
> 1, every timestep. The heat exchanger is modelled as vary layers (like 
> a storage tank), set by the heat transferfluid (htf) nodes.
>
> The purpose of the type is to simulate a shell and tube heat 
> exchanger, thus I need to store the "old" values at the very end of 
> the timestep into the storage arrays, and retrieve them every call of 
> the type. In order to simplify the problem let's assume a single tube 
> in a shell.
>
> In order to understand the general idea, I should say that I need to 
> use the dynamic allocation in order to create the arrays based on the 
> number of nodes, defined by the user, in the parameters. Once the user 
> sets as parameters the nodes along the tubes direction (nodes_htf) and 
> along the radial direction in the shell (nodes_shell), a vector for 
> the tube temperatures and a matrix (nodes_htf x nodes_shell) for the 
> shell temperatures should be created.
>
> I implemented the following steps, compiling each time and check the 
> simulation run in trnsys:
>
> 1.I set up the dimension of the storage array in the section "very 
> first call of the simulation" (it works perfectly but of course the 
> type does do anything)
>
>                    int store_size = nodes_htf*(nodes_shell+1); //set 
> the storage size to store Nhtf + Nhtf * Nshell temperatures
>
> SetStorageSize(&store_size,info);
>
> 2.I set up the initial values of the outputs and store them in the 
> section "do all the initial timestep manipulations" (it works 
> perfectly but of course the type does do anything)
>
>                              int store_size = nodes_htf*(nodes_shell+1);
>
>                              stored = new double[store_size];
>
>                              for(int i=0;i<store_size;i++)
>
>                              {
>
> stored[i]=Tini;
>
>                              }
>
> SetStorageVars(stored,&store_size,info);
>
>                              delete[] stored;
>
> 3.I retrieve the storage values on before make chenge to them, section 
> "Retrieve the values in the storage array for this iteration" (if I 
> use the type alonein the deck it works perfectly, but as soon as I 
> introduce the type65 it gives the _floating point error!!!_).
>
>             int store_size = nodes_htf*(nodes_shell+1);
>
>             stored = new double[store_size];
>
> GetStorageVars(stored,&store_size,info);
>
>             delete[] stored;
>
> The files are attached:
>
> -Type205 cpp
>
> -Project6: deck with type alone
>
> -Project7: deck with type205 + type65
>
> Thank you for the help. In you need to understand the purpose, you can 
> read the next steps here below (which are commented in the type205 code):
>
> 4.I save the storage values in the "old" arrays for the htf and the shell
>
>             Thtf_old = new double [nodes_htf];
>
>             Tshell_old = new double *[nodes_htf];
>
>             for (int i=0;i<nodes_htf;i++){Tshell_old[i]=new 
> double[nodes_shell];}
>
>             //assign the storage values to the old array
>
>             for (int i=0;i<nodes_htf;i++)
>
>             {
>
>                      Thtf_old[i] = stored[i*(nodes_shell+1)];// the 
> values are supposed to be stored per layer so the first value is for 
> the HTF and the others are for the shell
>
>                      for (int j=1;j<nodes_shell+1;j++)
>
>                      {
>
> Tshell_old[i][j-1] = stored[i*(nodes_shell+1)+j];
>
>                      }
>
>             }
>
>             delete[] stored;
>
> 5.I create the new values arrays at the first iteration for the 
> current timestep (info[6] = 0, otherwise if every I create them every 
> call I allocate too much memory), and calculate the new values from 
> the old ones and set the outputs
>
>   if (info[6] == 0)
>
>   {
>
>   Thtf = new double[nodes_htf];
>
>   Tshell = new double *[nodes_htf];
>
>   for (int i=0;i<nodes_htf;i++){Tshell[i] = new double[nodes_shell];}
>
>   }
>
>   for (int i=0;i<nodes_htf;i++)
>
>   {
>
>   Thtf[i] = Thtf_old[i] + 1.0;
>
>   for (int j=0;j<nodes_shell;j++)
>
>   {
>
>   Tshell[i][j] = Tshell_old[i][j] + 1.0;
>
>   }
>
>   }
>
>   delete[] Thtf_old;
>
>   for (int i=0;i<nodes_htf;i++){delete[] Tshell_old[i];}
>
>   delete[] Tshell_old;
>
>   //Set the outputs
>
>   Tout = Thtf[nodes_htf-1];
>
>   Tshell_top = Tshell[0][nodes_shell-1];
>
>   Tshell_mid = Tshell[int(floor(nodes_htf/2.0))-1][nodes_shell-1];
>
>   Tshell_bot = Tshell[nodes_htf-1][nodes_shell-1];
>
> 6.I save the new values in the trnsys storage array in the after 
> iteration section in oder to make them available for the next time 
> step iterations. I should save in that section otherwise every call 
> the type would retrieve the wrong values.
>
>                      int store_size = nodes_htf*(nodes_shell+1);
>
>                      stored = new double[store_size];
>
>                      for (int i = 0; i < nodes_htf; i++)
>
>                      {
>
> stored[i*(nodes_shell+1)] = Thtf[i];
>
>                                for (int j=1;j<nodes_shell+1;j++)
>
>                                {
>
> stored[i*(nodes_shell+1)+j] = Tshell[i][j-1];
>
>                                }
>
>                      }
>
>                      delete[] Thtf;
>
>                      for(int i=0;i<nodes_htf;i++){delete[] Tshell[i];}
>
>                      delete[] Tshell;
>
> SetStorageVars(stored,&store_size,info);
>
>                      delete[] stored;
>
> Thank you very much for the help! J
>
> Sergio Pintaldi
>
>
>
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.onebuilding.org/pipermail/trnsys-users-onebuilding.org/attachments/20141017/07ecc9ed/attachment-0002.htm>


More information about the TRNSYS-users mailing list