Linking REFPROP with Simulink

56 views (last 30 days)
Mohamad Shams
Mohamad Shams on 10 Mar 2024
Commented: Mohamad Shams on 28 Mar 2024 at 5:27
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?

Answers (1)

Vandit
Vandit on 28 Mar 2024 at 4:25
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.
  1 Comment
Mohamad Shams
Mohamad Shams on 28 Mar 2024 at 5:27
Hi Vandit
Thank you so much for your complete response.
Cheers

Sign in to comment.

Categories

Find more on Gas Models in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!