Borrar filtros
Borrar filtros

Linking REFPROP with Simulink

154 visualizaciones (últimos 30 días)
Mohamad Shams
Mohamad Shams el 10 de Mzo. de 2024
Comentada: hui el 3 de Jun. de 2024
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?

Respuestas (1)

Vandit
Vandit el 28 de Mzo. de 2024
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 comentarios
Mohamad Shams
Mohamad Shams el 28 de Mzo. de 2024
Hi Vandit
Thank you so much for your complete response.
Cheers
hui
hui el 3 de Jun. de 2024
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

Iniciar sesión para comentar.

Categorías

Más información sobre Gas Models en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by