Matlab and Simulink Examples

Using FluidProp from Matlab is very easy. Look into the examples provided in:

<FluidProp folder>\Sample Clients\The MathWorks Matlab

Try running the Test_FluidProp.m procedure.

COM, the technology on which FluidProp is based, is (well enough) supported from Matlab Release 13 on.

Still some little discrepancies from the standard in the Matlab implementation of COM make the SetFluid function a little different. The setting of the Model and the Fluid in Matlab is done with the SetFluid_M function (the _M denote a different function from the standard FluidProp SetFluid).

 

General syntax:

ErrorMsg = invoke(ObjID,'SetFluid_M', ModelName, nComp, Comp, Conc)

 

Arguments:

ObjID:

Object variable as set by the actxserver Matlab function (e.g. FP = actxserver ('FluidProp.FluidProp');)

ModelName:

String (possible values: TPSI, RefProp, StanMix, GasMix, IF97)

nComp:

Integer

Comp():

String containing the comma separated list of the components (IMPORTANT: it must match exactly the string returned by GetFluidNames but it is not case dependent; both short and long names can be used.)

Conc():

Double Array. Dimensions: nComp rows X 2 columns. The second column is formed by 0's. This is due to the Matlab implementation of COM: arrays can only be passed if they are matrices and not vectors.

ErrorMsg:

String (value returned)

 

Examples:

Model = 'GasMix';

nCmp = 5;

Cmp = 'AR,CO2,H2O,N2,O2';

Cnc = [0.0092,0; 0.0003,0; 0.0101,0; 0.7729,0; 0.2075,0];

ErrorMsg = invoke(FP,'SetFluid_M',Model,nCmp,Cmp,Cnc)

 

Model = 'RefProp';

nCmp = 1;

Cmp = 'Toluene';

Cnc = [1, 0];

ErrorMsg = invoke(FP,'SetFluid_M',Model,nCmp,Cmp,Cnc)

 

Any of the functions to compute a fluid property can be called with the same syntax, e.g.:

[Enthalpy,ErrorMsg] = invoke(FP,'Enthalpy','PT', P, T);

Alternatively, one can also call a FluidProp function with:

[Enthalpy,ErrorMsg] = FP.Enthalpy("PT", P, T);

 

Special note for Simulink:

Unfortunately object variables cannot be passed between blocks so they must be stored in the Matlab Workspace.

Look into the provided SimulinkExample.mdl file for a simple implementation.