TRNSYS Development Hints
Here is a collection of advice for developing new TRNSYS models.
- Sketch it out
Before launching into TRNSYS code, draw a detailed schematic of the system, or annotate an existing schematic. Label the sketch with the TRNSYS variables, TRNSYS unit & type numbers, flow directions, components, equations… This will help visualise the system before you translate it into TRNSYS code.
.png)
An example of sketching TRNSYS variables onto a schematic to make sense of a difficult system, in this case how to model two tanks in series.
- Build complexity incrementally
Heating systems often have many layers of complexity - interconnected systems of components, complicated control logic… Don’t try and prepare the simulation for the final solution straight away. Start by building the most simple version of the model and test it. Plot the results. Check that the output makes sense. Then add a new layer of complexity and repeat.
If the system contains many components (chillers, heat pumps, pipes, pumps, tanks, loads…), then build each small part of the overall system individually. Set constant input conditions for this section and check that the output is sensible.
If it is a simple component like a single heat pump but uses complex control logic, first model the heat pump with basic control logic to check that all the heat pump parameters are correct. Then incrementally add new layers of control logic.
- Use plotters
Plotters are the best way to debug a simulation and to check the output is sensible. For each component create a plotter with all of its inputs and outputs. You can make multiple plotters for different investigations. Bite size plots are easier to comprehend. For example, to test a control decision, make a plotter with the variables that are used to determine a control signal.
Below is an example of HP control logic where the compressor control signal (hp_onoff) is controlled by two different temperature sensor - one at the HP inlet (Tin) and one inside the tank (Tcontrol).
* Heat pump turns on when Tcontrol < 45, turns off when Tin > 48
hp_on = LT(Tcontrol,45) ! Heat pump turns on when Tcontrol < 45
hp_off = GT(Tin,48) ! Heat pump turns off when Tin > 48
hp_onoff_0 = [93,2] ! hp_onoff signal from previous timestep
*If HP previously off & hp_on=1, turn on
*If HP previously on & hp_off=1, turn off
hp_onoff = EQL(hp_onoff_0,0)*hp_on + EQL(hp_onoff_0,1)*NOT(hp_off)
To test this control logic, create a simple plot with three variables: Tcontrol, Tin and hp_onoff. Run the simulation and check that the compressor (hp_onoff) turns off when Tin>48, and turns on when Tcontrol<45.
.png)
Compressor turns on when Tcontrol (red) drops below 45. Turns off when Tin (blue) hits 48.
- Review the list file
When the simulation throws an error, the error should be reported at the end of the list (***.lst) file. The error codes can be cryptic, but take time to read the error code carefully and you should gain some clues about the source of the error.
If you get an error immediately before the simulation starts, there is a syntax error in the deck file. Open the list file and check what line of the deck file was read just before the error appeared. Investigate this part of the deck for the problem.
Common errors:
- Invalid floating point error
- Unrecognised variable name or bad data card: incorrect number of constants or equations defined i.e. constants 48, eqns 4 - recount the number of constants or equations.
- Error in data stored in logical unit: the assigned file path does not exist or is empty. Check the file path is correct. If it does not exist, an empty file will be created - check file size 0kb will indicate this.
- Units not converged: timestep is too large or insufficient thermal capacitance in a closed fluid loop.
- Reduce the time step - 0.02, 0.01, 0.005, until convergence is reached.
- Add pipes to the system. Increase pipe size and reduce heat loss to achieve equivalent heat loss but with extra fluid volume in the system. Each pipe must have sufficient volume so that the flow through the pipe does not exceed the pipe volume in a single timestep. Perform some calculations on pipe volume and flow rate at the current time step to evaluate what time step or pipe volume is required to avoid this error.
- If many components, check the component order in the simulation so that components are in a logical order in the direction of flow around the system. Define control strategies first, then components, then plotters at the end.
- See more on TRNSYS troubleshooting.