The following example shows the usage of the user state point
function to calculate the specific heat capacity for various materials.
The heat capacity is calculated for a mixture (MyAir) as well as for each component of the mixture (MyAir.N2
Ideal Gas, MyAir.O2 Ideal Gas, MyAir.CO2 Ideal Gas and MyAir.CO2 Const Prop).
The CCL that is required to plot the efficiency in the CFX-Solver Manager is as follows:
LIBRARY:
CEL:
FUNCTION: Function 1
Argument Units = [[],[K],[Pa],[],[],[],[]]
Option = User Function
Result Units = [J kg^-1 K^-1]
User Routine Name = User Routine 1
END
EXPRESSIONS:
MyCp1 = Function 1(1,Tave,Pave,N2mf,O2mf,CO2mf,CO21mf)
MyCp2 = Function 1(2,Tave,Pave,N2mf,O2mf,CO2mf,CO21mf)
MyCp3 = Function 1(3,Tave,Pave,N2mf,O2mf,CO2mf,CO21mf)
MyCp4 = Function 1(4,Tave,Pave,N2mf,O2mf,CO2mf,CO21mf)
MyCp5 = Function 1(5,Tave,Pave,N2mf,O2mf,CO2mf,CO21mf)
#
A = 0.1 [J kg^-1 K^-2]
MyCp = 1004 [J kg^-1 K^-1] + A*Temperature
CpCO2 = 851 [J kg^-1 K^-1] + A*Temperature
CpO2 = 920 [J kg^-1 K^-1] + A*Temperature
CpN2 = 1040 [J kg^-1 K^-1] + A*Temperature
#
Tave = massFlowAve(Temperature)@Outflow
Pave = massFlowAve(Absolute Pressure)@Outflow
N2mf = massFlowAve(N2 Ideal Gas.Mass Fraction)@Outflow
O2mf = massFlowAve(O2 Ideal Gas.Mass Fraction)@Outflow
CO2mf = massFlowAve(CO2 Ideal Gas.Mass Fraction)@Outflow
CO21mf = massFlowAve(CO2 Const Prop.Mass Fraction)@Outflow
END
END
USER ROUTINE DEFINITIONS:
USER ROUTINE: User Routine 1
Calling Name = my_test
Library Name = mytest
Library Path = ..
Option = User CEL Function
END
END
END
FLOW: Flow Analysis 1
OUTPUT CONTROL:
MONITOR OBJECTS:
MONITOR POINT: Monitor Point 1
Expression Value = MyCp1
Option = Expression
END
MONITOR POINT: Monitor Point 2
Expression Value = MyCp2
Option = Expression
END
MONITOR POINT: Monitor Point 3
Expression Value = MyCp3
Option = Expression
END
MONITOR POINT: Monitor Point 4
Expression Value = MyCp4
Option = Expression
END
MONITOR POINT: Monitor Point 5
Expression Value = MyCp5
Option = Expression
END
END
MONITOR OBJECTS:
MONITOR BALANCES:
Option = Full
END
MONITOR FORCES:
Option = Full
END
MONITOR PARTICLES:
Option = Full
END
MONITOR RESIDUALS:
Option = Full
END
MONITOR TOTALS:
Option = Full
END
END
RESULTS:
File Compression Level = Default
Option = Standard
END
END
END
The Fortran source code for this example is given below:
#include "cfx5ext.h"
dllexport(my_test)
SUBROUTINE MY_TEST (
& NLOC, NRET, NARG, RET, ARGS, CRESLT, CZ,DZ,IZ,LZ,RZ )
CC
CD User routine: template for user CEL function
CC
CC --------------------
CC Input
CC --------------------
CC
CC NLOC - size of current locale
CC NRET - number of components in result
CC NARG - number of arguments in call
CC ARGS() - (NLOC,NARG) argument values
CC
CC --------------------
CC Modified
CC --------------------
CC
CC Stacks possibly.
CC
CC --------------------
CC Output
CC --------------------
CC
CC RET() - (NLOC,NRET) return values
CC CRESLT - 'GOOD' for success
CC
CC --------------------
CC Details
CC --------------------
CC
CC Template routine for user state point code
CC
CC======================================================================
C
C ------------------------------
C Argument list
C ------------------------------
C
INTEGER NLOC,NARG,NRET
C
CHARACTER CRESLT*(*)
C
REAL ARGS(NLOC,NARG), RET(NLOC,NRET)
C
INTEGER IZ(*)
CHARACTER CZ(*)*(1)
DOUBLE PRECISION DZ(*)
LOGICAL LZ(*)
REAL RZ(*)
C
C ------------------------------
C External routines
C ------------------------------
C
INTEGER LENACT
EXTERNAL LENACT
C
C ------------------------------
C Local Parameters
C ------------------------------
C
C ------------------------------
C Local Variables
C ------------------------------
C
INTEGER NPROPIND, NTESTPROP, IMAT, NMAT, IPROP
CHARACTER*(80) CPROPCALC, CPROPIND(6)
C
REAL RPROPIND(6)
C
CHARACTER*(30) INDPROP(13)
CHARACTER*(30) MAT(5)
C
DATA INDPROP /'Static Enthalpy','Static Entropy','Cp','Cv',
& 'Dynamic Viscosity','Density',
& 'Pressure','Absolute Pressure',
& 'Temperature','Absolute Temperature',
& 'Isentropic Compressibility',
& 'Isothermal Compressibility',
& 'Local Speed of Sound'/
C
DATA MAT /'MyAir','MyAir.N2 Ideal Gas',
& 'MyAir.O2 Ideal Gas','MyAir.CO2 Ideal Gas',
& 'MyAir.CO2 Const Prop'/
C
C ------------------------------
C Stack pointers
C ------------------------------
C
C=======================================================================
C
C ---------------------------
C Executable Statements
C ---------------------------
C
C---- Initialize RET(1:NLOC*NRET) to zero.
C
CALL SET_A_0(RET,NLOC*NRET)
C
C-----------------------------------------------------------------------
C Setup data required for state point calculation
C-----------------------------------------------------------------------
C
NPROPIND = 6
C
CPROPIND(1) = 'Temperature'
CPROPIND(2) = 'Absolute Pressure'
C
CPROPIND(3) = 'N2 Ideal Gas.mf'
CPROPIND(4) = 'O2 Ideal Gas.mf'
CPROPIND(5) = 'CO2 Ideal Gas.mf'
CPROPIND(6) = 'CO2 Const Prop.mf'
C
C---- 'Material' number:
C --> '1': Mixture
C '2': N2 Ideal Gas
C '3': O2 Ideal Gas
C '4': CO2 Ideal Gas
C '5': CO2 Const Prop
IMAT = ARGS(NLOC,1)
C
C---- Input values of temperature and absolute pressure
C
RPROPIND(1) = ARGS(NLOC,2)
RPROPIND(2) = ARGS(NLOC,3)
C
C---- Input values of component mass fractions
C
RPROPIND(3) = ARGS(NLOC,4)
RPROPIND(4) = ARGS(NLOC,5)
RPROPIND(5) = ARGS(NLOC,6)
RPROPIND(6) = ARGS(NLOC,7)
C
C-----------------------------------------------------------------------
C Compute return variable value
C-----------------------------------------------------------------------
C
C---- Compute Specific Heat capacity (= property ‘3’ in above list)
C
IPROP = 3
C
IF (IMAT.GT.1) THEN
NPROPIND = 2
ENDIF
C
C---- Create output property name
C
CPROPCALC = MAT(IMAT)(1:LENACT(MAT(IMAT)))//'.'//
& INDPROP(IPROP)
CALL USER_STATEPT(RVALUE,CPROPCALC,CPROPIND,RPROPIND,
& NPROPIND,'SKIP',CRESLT, CZ,DZ,IZ,LZ,RZ)
C
C---- Copy output property value to RET(1:NLOC,1).
C --> NLOC = 1
C
RET(1,1) = RVALUE
C
END