필터 지우기
필터 지우기

Linking REFPROP with Simulink

조회 수: 106 (최근 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에서 Gas Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by