Linking REFPROP with Simulink

169 次查看(过去 30 天)
Mohamad Shams
Mohamad Shams 2024-3-10
评论: hui 2024-6-3
Hi there,
I want to link REFPROP with Simulink for a two-phase fluid. I have propane as a working fluid in my thermodynamic system, and during the process, the pressure and temperature of the working fluid change. I want to import the fluid properties to Simulink, considering the changing pressure and temperature. I should import the state of the fluid, whether it is in a liquid state, gas, or supercritical, and other thermodynamic properties so that Simulink can calculate the work of turbines and compressors in the process. Is it possible, and how can I do that?

回答(1 个)

Vandit
Vandit 2024-3-28
Hello Shams,
Yes, it is possible to link REFPROP with Simulink to import fluid properties, including the state of the fluid (liquid, gas, or supercritical) and other thermodynamic properties. You can follow the steps given below to integrate REFPROP with Simulink:
  • After installing REFPROP and MATLAB on your computer, verify that you can access REFPROP from MATLAB using the REFPROP MATLAB interface (refpropm). This ensures MATLAB can call REFPROP functions to calculate the properties of your fluid under various conditions.
  • Create a MATLAB function that uses 'coder.extrinsic' to call the "refpropm" function. This function should take pressure and temperature as inputs and output the desired fluid properties. The use of 'coder.extrinsic' allows you to use the "refpropm" function within Simulink, which is not directly supported for code generation. Below is a sample MATLAB function for your reference:
function [density, enthalpy, quality] = getFluidProperties(P, T)
% Declare refpropm as an extrinsic function
coder.extrinsic('refpropm');
% Call refpropm to calculate properties for the specified fluid (e.g., Propane)
[~, ~, h, ~, ~, rho, ~, ~, Q] = refpropm('TDHQS', 'T', T, 'P', P, 'Propane');
% Assign outputs
density = rho;
enthalpy = h;
quality = Q;
end
  • Open Simulink and use a MATLAB Function block to integrate the MATLAB function from Step 2, connecting inputs for pressure and temperature and outputs for fluid properties.
  • Run your model to dynamically calculate and utilize the fluid properties based on changing conditions for accurate system simulation.
For generating fluid property tables from REFPROP, you may refer to the following documentation:
Hope this helps.
  2 个评论
Mohamad Shams
Mohamad Shams 2024-3-28
Hi Vandit
Thank you so much for your complete response.
Cheers
hui
hui 2024-6-3
Hi Vandit
I used your method of trying to calculate the density of water or water vapor by temperature and pressure under variable operating conditions. The modified code is as follows: However, after running it, the following problem occurs “The system ‘rho_d’ is missing a module corresponding to input port 1. Ports must be numbered consecutively from 1.” Do you have a solution for this problem? If so can you let me know? I would be most grateful.
Thanks again.
Translated with DeepL.com (free version)
function [density, enthalpy, quality] = getFluidProperties(P, T)
% Declare refpropm as an extrinsic function
coder.extrinsic('refpropm');
% Call refpropm to calculate properties for the specified fluid (e.g., Propane)
[~, ~, h, ~, ~, rho, ~, ~, Q] = refpropm('D', 'T', T, 'P', P, 'Water');
% Assign outputs
density = rho;
enthalpy = h;
quality = Q;
end

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Thermal Analysis 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by