TRNSYS - Matlab link example

Note: Before running this example, you should modify your TRNSYS DLL to include Type155 and the required Matlab libraries, as described in the Type155 manual.

This simple example illustrate the use of 2 Type155 units in a simulation. A simple solar collector (type1b) is simulated with constant inlet conditions and daily sinusoidal ambient temperature and solar radiation. A scatter plot of the collector efficiency is then generated.
screenshot

Simulation parameters

Matlab routines

First unit: Type155-weather

The first Type155 unit has mFileId set to 1, so the following m-files are called by Type155:

ComponentKind is set to 0, which means that Type155simulate_001.m will be called at each iteration of each time step
ignoreEngClose is set to 0, so this routine allows Matlab to be closed when TRNSYS exits

type155initialize_001.m
This routine just stores some information about the unit (nb of inputs, outputs, etc.) and the simulation (nb. of time steps)

type155simulate_001.m
This routine generates sinusoidal profiles for the ambient temperature and the solar radiation using Tamb,min and Tamb,max and Gmax given by type 155 (respectively inputs 1, 2 and 3)

type155terminate_001.m
This routine is empty

Second unit: Type155-efficiency plot

The first Type155 unit has mFileId set to 2, so the following m-files are called by Type155:

ComponentKind is set to 10, which means that Type155simulate_002.m will be called only once per time step. The routine is actually called at the first iteration of a time step with the stored inputs from last call, i.e. the converged inputs from previous time step. This is useful for real-time controllers or for plotting routines, as it is the case here.
ignoreEngClose is set to 1, so this routine does not allow Matlab to be closed when TRNSYS exits. As mentioned in Type155 parameters description, Matlab will keep running after the TRNSYS simulation is done if at least one type 155 unit has this parameter set to 1.

type155initialize_002.m
This routine stores some information about the unit (nb of inputs, outputs, etc.) and the simulation (nb. of time steps). It initializes the history variable, which will be used to store the inputs at each call.

type155simulate_002.m
This routine stores the inputs in the history variable.

type155terminate_002.m
This routine actually draws the plot. It is called at the very last call of the simulation, i.e. after the user presses the "yes" button in the "exit online plotter?" window.
The values corresponding to solar radiation levels lower than 10 W/m² are ignored.

An example plot is given here below

Example results

Some TRNSYS-Matlab tips & tricks

Keeping history of inputs/outputs
As always in Matlab, it is a good idea to create history-keeping variables during the initialization call and fill them during the simulation rather than increasing the size of a Matlab variable at each call. This can have a very large effect on the speed of TRNSYS-Matlab simulations.

Troubleshooting m-files

Comments, Questions? Please contact trnsys@engr.wisc.edu

Michaël Kummert
Solar Energy Lab, UW-Madison
2003-06-25