1. IntroductionTRNSYS, as an energy system simulation software, primarily focuses on the thermal simulation between integrated units. Taking the air conditioning water system as an example, it mainly simulates the dynamic operation of chillers, cooling towers, water pumps, and terminal fans. However, simulating the refrigerant cycle within the chiller is challenging due to the involvement of phase change micro-processes, which cannot be simulated in TRNSYS that models macro systems. Similarly, models containing steam generators, such as the Rankine cycle, cannot be simulated.Therefore, for this type of simulation, I generally do not recommend using TRNSYS. Instead, I often suggest using software like MATLAB/Simulink, Modelica, or ASPENONE for simulations. However, since I am not proficient in these software packages, whether they can effectively simulate the processes still requires readers to verify personally.Nonetheless, TRNSYS is not entirely incapable of simulating such systems, but it cannot be accomplished using built-in modules alone. Typically, users need to fit mathematical formulas based on actual projects and program custom modules using languages like C++ or Fortran. Commonly used custom modules include those written by Yang Shaogang, such as modules 225, 228, and 227. These excellent custom modules somewhat compensate for the shortcomings of TRNSYS, but this approach tests the user’s programming skills and is limited by certain constraints of the TRNSYS core language, resulting in a high programming threshold, which can cause significant difficulties for users.In light of the above issues, I personally used MATLAB to write the evaporator and utilized Type 155 for reading, attempting to address some of the software’s inherent problems. However, due to my limited knowledge, there may be certain shortcomings, and I hope readers can approach this with a critical perspective.2. Writing the Original CodeThe original MATLAB code is as follows:
I mainly considered the area dimensions of the heat exchanger and the flow rates of the refrigerant and cooling water. By utilizing MATLAB’s custom Function feature, I defined the enthalpy of the refrigerant R134a, conducting targeted queries based on the inlet dryness X and inlet pressure P to ensure the enthalpy within the evaporator achieves dynamic transformation, successfully implementing dynamic data transfer between MATLAB and TRNSYS using Type 155.During the coding process, I believe that using MATLAB for custom module development has several advantages over coding in Fortran and C++:(1) There is no need for complex DLL creation and repeated updates; errors can be corrected promptly without needing to relink the DLL;(2) The fitting formulas and language logic in MATLAB are relatively simpler compared to the complex Info() and various formula calls in custom modules, making it more accessible for beginners;(3) Users can write Functions and mathematical formulas according to their needs, making it relatively open-source;In summary, the interaction between MATLAB and TRNSYS greatly expands the usage of TRNSYS in various scenarios and reduces the difficulty of developing custom modules.I hope everyone reads this with a critical mindset.