Option Private Module
Option Explicit
Public FP As New FluidProp
'MsgBox FP
'Sub Auto_Open()
' [Link] [Link] & "\[Link]"
'[Link]
' MsgBox "Path is =" & [Link]
' Run [FunCustomize], [Link], [Link]("A2:Z49")
' [Link] "%^{F9}"
'End Sub
'----------------------------------------------------------------------------------'
' Procedures concerning working fluid definition '
'----------------------------------------------------------------------------------'
Function SetFluid(ModelName As String, Optional Components As Variant = "", _
Optional Concentrations As Variant = 1, Optional UnitData As String)
' It defines the thermodynamic model and the fluid
Dim ErrorMsg As String
Dim Comp() As String
Dim Conc() As Double
Dim Num_Comps, Counter As Long
Dim error As Boolean
'In case no component names and concentrations are specified...
error = False
If ModelName <> "IF97" And _
Not IsArray(Components) And Not IsArray(Concentrations) Then
If Components = "" And Concentrations = 1 Then
error = True
SetFluid = ModelName + ". No fluid specified..."
End If
End If
If Not error Then
ErrorMsg = "Init value..."
'Count number of components.
If ModelName = "IF97" Then
Num_Comps = 0
ReDim Comp(1 To 1)
ReDim Conc(1 To 1)
Else
If Not IsArray(Concentrations) Then
Num_Comps = 1
ElseIf IsObject(Concentrations) Then
Num_Comps = [Link]
Else
Num_Comps = UBound(Concentrations)
End If
ReDim Comp(1 To Num_Comps)
ReDim Conc(1 To Num_Comps)
End If
'Store composition.
If Num_Comps = 1 Then
Comp(1) = Components
' For TPSI Moist. Air concentration is used for mass fraction H2O
If ModelName = "TPSI" And Components = "Moist. Air" Then
Conc(1) = Concentrations
Else
Conc(1) = 1
End If
Else
For Counter = 1 To Num_Comps
If ModelName = "StanMix" Or ModelName = "StanMix3" Then
If Counter > 1 Then
Comp(Counter) = ""
Else
Comp(Counter) = Components
End If
Else
Comp(Counter) = Components(Counter)
End If
Conc(Counter) = Concentrations(Counter)
Next Counter
End If
'Define the working fluid just to check the correctness.
Call [Link](ModelName, Num_Comps, Comp, Conc, ErrorMsg)
'Return fluid data in a string or an error message
If ErrorMsg = "No errors" Then
SetFluid = ModelName
'No additional data needed for IF97
If Not ModelName = "IF97" Then
'Store components.
If ModelName = "StanMix" Or ModelName = "StanMix3" Then
SetFluid = SetFluid + ", " + Comp(1)
Else
For Counter = 1 To Num_Comps
SetFluid = SetFluid + ", " + Comp(Counter)
Next Counter
End If
'Store concentrations. If there is just one component then
'its concentration is 1 which needs not to be specified.
If Num_Comps > 1 Then
For Counter = 1 To Num_Comps
SetFluid = SetFluid + ", " + CStr(Conc(Counter))
Next Counter
End If
'For TPSI Moist. Air the mass fraction water is stored
'instead of the concentration
If ModelName = "TPSI" And Comp(1) = "Moist. Air" Then
SetFluid = SetFluid + ", " + CStr(Conc(1))
End If
End If
'Process units
'Test if a correct unit definition is in the cell....
If UnitData <> "" Then
SetFluid = SetFluid + ", units: " + UnitData
End If
Else
SetFluid = ModelName + ". " + ErrorMsg
End If
If Len(SetFluid) > 255 Then
SetFluid = Left(SetFluid, 255)
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Procedures to calculate tmd properties iteratively '
'----------------------------------------------------------------------------------'
Function Solve(FluidData As String, FuncSpec As String, FuncValue As Double, _
InputSpec As String, Target As Long, FixedValue As Double, _
MinVal As Double, MaxVal As Double)
Dim ErrorMsg As String
Dim output As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
Solve = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](FuncSpec, FuncValue, InputSpec, Target, FixedValue, _
MinVal, MaxVal, output, ErrorMsg)
If ErrorMsg = "No errors" Then
Solve = output
Else
Solve = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' General calculation function for all output properties '
'----------------------------------------------------------------------------------'
'Calculate thermodynamic properties if working fluid found...
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, OutputArray, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, OutputArray, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, output, ErrorMsg)
' Call [Link](InputSpec, Value1, Value2, OutputArray, ErrorMsg)
'----------------------------------------------------------------------------------'
' Specific calculation functions for all output properties '
'----------------------------------------------------------------------------------'
'Function Pressure(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the pressure P [bar]
Pressure = Calculate(FluidData, InputSpec, "Pressure", Value1, Value2)
End Function
'Function Temperature(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the temperature T [°C]
Temperature = Calculate(FluidData, InputSpec, "Temperature", Value1, Value2)
End Function
'Function SpecVolume(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the specific volume v [m3/kg]
SpecVolume = Calculate(FluidData, InputSpec, "SpecVolume", Value1, Value2)
End Function
'Function Density(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the density d [kg/m3]
Density = Calculate(FluidData, InputSpec, "Density", Value1, Value2)
End Function
'Function Luca(lc1 As Double, lc2 As Double)
'MsgBox FP
'Luca = Calculate("IF97", "PT", "Enthalpy", lc1, lc2)
'Luca = Luca * 100000
'MsgBox Luca
'End Function
'Function Enthalpy(FluidData As String, InputSpec As String, _
' Value1 As Double, Value2 As Double)
' It calculates the specific enthalpy h [kJ/kg]
' Enthalpy = Calculate(FluidData, InputSpec, "Enthalpy", Value1, Value2)
'End Function
Function Entropy(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the specific entropy s [kJ/kg.K]
Entropy = Calculate(FluidData, InputSpec, "Entropy", Value1, Value2)
End Function
Function IntEnergy(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the specific internal energy u [kJ/kg]
IntEnergy = Calculate(FluidData, InputSpec, "IntEnergy", Value1, Value2)
End Function
Function VaporQual(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the vapor quality q [kg/kg]
VaporQual = Calculate(FluidData, InputSpec, "VaporQual", Value1, Value2)
End Function
Function LiquidCmp(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It returns the liquid phase composition {[mole/mole]} if VLE or
' the overall composition in all other cases
LiquidCmp = Calculate(FluidData, InputSpec, "LiquidCmp", Value1, Value2)
End Function
Function VaporCmp(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It returns the vapor phase composition {[mole/mole]} if VLE or
' the overall composition in all other cases
VaporCmp = Calculate(FluidData, InputSpec, "VaporCmp", Value1, Value2)
End Function
Function HeatCapV(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the isochoric heat capacity cv [kJ/kg.K]
HeatCapV = Calculate(FluidData, InputSpec, "HeatCapV", Value1, Value2)
End Function
Function HeatCapP(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the isobaric heat capacity cp [kJ/kg.K]
HeatCapP = Calculate(FluidData, InputSpec, "HeatCapP", Value1, Value2)
End Function
Function SoundSpeed(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the of sound of speed c [m/s]
SoundSpeed = Calculate(FluidData, InputSpec, "SoundSpeed", Value1, Value2)
End Function
Function alpha(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative alpha = (dP/dRho)u [m2/s2]
alpha = Calculate(FluidData, InputSpec, "Alpha", Value1, Value2)
End Function
Function beta(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative beta = (dP/du)rho [kg/m3]
beta = Calculate(FluidData, InputSpec, "Beta", Value1, Value2)
End Function
Function chi(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative chi = (ds/drho)u [N.m4/kg2.K]
chi = Calculate(FluidData, InputSpec, "Chi", Value1, Value2)
End Function
Function fi(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative fi = (ds/du)rho [1/K]
fi = Calculate(FluidData, InputSpec, "Fi", Value1, Value2)
End Function
Function ksi(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative ksi = (drho/dh)p [kg2/N.m4]
ksi = Calculate(FluidData, InputSpec, "Ksi", Value1, Value2)
End Function
Function psi(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative psi = (drho/dp)h [s2/m2]
psi = Calculate(FluidData, InputSpec, "Psi", Value1, Value2)
End Function
Function zeta(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the partial derivative zeta = (dT/dv)u [kg.K/m3]
zeta = Calculate(FluidData, InputSpec, "Zeta", Value1, Value2)
End Function
Function theta(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the thermal expansion coeff theta = 1/v*(dv/dT)P [1/K]
theta = Calculate(FluidData, InputSpec, "Theta", Value1, Value2)
End Function
Function kappa(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the isothermal compressibility kappa = -1/v*(dv/dP)T [1/bar]
kappa = Calculate(FluidData, InputSpec, "Kappa", Value1, Value2)
End Function
Function gamma(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the fundamental derivative of gasdynamics gamma = 1 + rho/c(dc/drho)s [-]
gamma = Calculate(FluidData, InputSpec, "Gamma", Value1, Value2)
End Function
Function Viscosity(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the dynamic viscosity [Pa.s]
Viscosity = Calculate(FluidData, InputSpec, "Viscosity", Value1, Value2)
End Function
Function ThermCond(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the thermal conductivity [W/m/.K]
ThermCond = Calculate(FluidData, InputSpec, "ThermCond", Value1, Value2)
End Function
Function SurfTens(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the surface tension [N/m]
SurfTens = Calculate(FluidData, InputSpec, "SurfTens", Value1, Value2)
End Function
Function FugaCoef(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
' It calculates the logarithm of the fugacity coefficients of the components in a mixtures [-]
FugaCoef = Calculate(FluidData, InputSpec, "FugaCoef", Value1, Value2)
End Function
'----------------------------------------------------------------------------------'
' Calculation function for all output properties in one go '
'----------------------------------------------------------------------------------'
Function AllProps(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
Dim ErrorMsg As String
Dim Items(1 To 250) As String
Dim Counter As Long
Dim ItemCount As Long
Dim OutputArray(1 To 23) As Double
Dim P As Double
Dim T As Double
Dim v As Double
Dim d As Double
Dim H As Double
Dim s As Double
Dim u As Double
Dim q As Double
Dim cv As Double
Dim cp As Double
Dim c As Double
Dim alpha As Double
Dim beta As Double
Dim chi As Double
Dim fi As Double
Dim ksi As Double
Dim psi As Double
Dim zeta As Double
Dim theta As Double
Dim kappa As Double
Dim gamma As Double
Dim eta As Double
Dim lambda As Double
Dim x() As Double
Dim y() As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
'Parse Fluid data string
ItemCount = 1
For Counter = 1 To Len(FluidData)
If Mid(FluidData, Counter, 1) = "," Then
ItemCount = ItemCount + 1
Else
Items(ItemCount) = Items(ItemCount) + Mid(FluidData, Counter, 1)
End If
Next Counter
'Redimension x and y depending ModelName
If Items(1) = "StanMix" Then
ReDim x(1 To 10)
ReDim y(1 To 10)
ElseIf Items(1) = "RefProp" Or Items(1) = "StanMix3" Or Items(1) = "PCP-SAFT" Then
ReDim x(1 To 20)
ReDim y(1 To 20)
Else
ReDim x(1 To 1)
ReDim y(1 To 1)
End If
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
AllProps = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](InputSpec, Value1, Value2, P, T, v, d, H, s, u, q, x, y, cv, _
cp, c, alpha, beta, chi, fi, ksi, psi, zeta, theta, kappa, _
gamma, eta, lambda, ErrorMsg)
OutputArray(1) = P
OutputArray(2) = T
OutputArray(3) = v
OutputArray(4) = d
OutputArray(5) = H
OutputArray(6) = s
OutputArray(7) = u
OutputArray(8) = q
OutputArray(9) = cv
OutputArray(10) = cp
OutputArray(11) = c
OutputArray(12) = alpha
OutputArray(13) = beta
OutputArray(14) = chi
OutputArray(15) = fi
OutputArray(16) = ksi
OutputArray(17) = psi
OutputArray(18) = zeta
OutputArray(19) = theta
OutputArray(20) = kappa
OutputArray(21) = gamma
OutputArray(22) = eta
OutputArray(23) = lambda
If ErrorMsg = "No errors" Then
AllProps = OutputArray
Else
AllProps = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Calculation function for all output properties in one go '
'----------------------------------------------------------------------------------'
Function AllPropsSat(FluidData As String, InputSpec As String, _
Value1 As Double, Value2 As Double)
Dim ErrorMsg As String
Dim Items(1 To 250) As String
Dim Counter As Long
Dim ItemCount As Long
Dim OutputArray(1 To 33) As Double
Dim P As Double
Dim T As Double
Dim v As Double
Dim d As Double
Dim H As Double
Dim s As Double
Dim u As Double
Dim q As Double
Dim cv As Double
Dim cp As Double
Dim c As Double
Dim alpha As Double
Dim beta As Double
Dim chi As Double
Dim fi As Double
Dim ksi As Double
Dim psi As Double
Dim zeta As Double
Dim theta As Double
Dim kappa As Double
Dim gamma As Double
Dim eta As Double
Dim lambda As Double
Dim d_liq As Double
Dim d_vap As Double
Dim h_liq As Double
Dim h_vap As Double
Dim T_sat As Double
Dim dd_liq_dP As Double
Dim dd_vap_dP As Double
Dim dh_liq_dP As Double
Dim dh_vap_dP As Double
Dim dT_sat_dP As Double
Dim x() As Double
Dim y() As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
'Parse Fluid data string
ItemCount = 1
For Counter = 1 To Len(FluidData)
If Mid(FluidData, Counter, 1) = "," Then
ItemCount = ItemCount + 1
Else
Items(ItemCount) = Items(ItemCount) + Mid(FluidData, Counter, 1)
End If
Next Counter
'Redimension x and y depending ModelName
If Items(1) = "StanMix" Then
ReDim x(1 To 10)
ReDim y(1 To 10)
ElseIf Items(1) = "RefProp" Or Items(1) = "StanMix3" Or Items(1) = "PCP-SAFT" Then
ReDim x(1 To 20)
ReDim y(1 To 20)
Else
ReDim x(1 To 1)
ReDim y(1 To 1)
End If
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
AllPropsSat = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](InputSpec, Value1, Value2, P, T, v, d, H, s, u, q, x, y, cv, _
cp, c, alpha, beta, chi, fi, ksi, psi, zeta, theta, kappa, _
gamma, eta, lambda, d_liq, d_vap, h_liq, h_vap, T_sat, dd_liq_dP, _
dd_vap_dP, dh_liq_dP, dh_vap_dP, dT_sat_dP, ErrorMsg)
OutputArray(1) = P
OutputArray(2) = T
OutputArray(3) = v
OutputArray(4) = d
OutputArray(5) = H
OutputArray(6) = s
OutputArray(7) = u
OutputArray(8) = q
OutputArray(9) = cv
OutputArray(10) = cp
OutputArray(11) = c
OutputArray(12) = alpha
OutputArray(13) = beta
OutputArray(14) = chi
OutputArray(15) = fi
OutputArray(16) = ksi
OutputArray(17) = psi
OutputArray(18) = zeta
OutputArray(19) = theta
OutputArray(20) = kappa
OutputArray(21) = gamma
OutputArray(22) = eta
OutputArray(23) = lambda
OutputArray(24) = d_liq
OutputArray(25) = d_vap
OutputArray(26) = h_liq
OutputArray(27) = h_vap
OutputArray(28) = T_sat
OutputArray(29) = dd_liq_dP
OutputArray(30) = dd_vap_dP
OutputArray(31) = dh_liq_dP
OutputArray(32) = dh_vap_dP
OutputArray(33) = dT_sat_dP
If ErrorMsg = "No errors" Then
AllPropsSat = OutputArray
Else
AllPropsSat = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Calculation function for all output properties in one go '
'----------------------------------------------------------------------------------'
Function zFlow_vu(FluidData As String, v As Double, u As Double)
Dim ErrorMsg As String
Dim Items(1 To 250) As String
Dim Counter As Long
Dim ItemCount As Long
Dim OutputArray(1 To 10) As Double
Dim P As Double
Dim T As Double
Dim H As Double
Dim s As Double
Dim alpha As Double
Dim beta As Double
Dim chi As Double
Dim fi As Double
Dim zeta As Double
Dim gamma As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
'Parse Fluid data string
ItemCount = 1
For Counter = 1 To Len(FluidData)
If Mid(FluidData, Counter, 1) = "," Then
ItemCount = ItemCount + 1
Else
Items(ItemCount) = Items(ItemCount) + Mid(FluidData, Counter, 1)
End If
Next Counter
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
zFlow_vu = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call FP.zFlow_vu(P, T, v, H, s, u, alpha, beta, chi, fi, zeta, gamma, ErrorMsg)
OutputArray(1) = P
OutputArray(2) = T
OutputArray(3) = H
OutputArray(4) = s
OutputArray(5) = alpha
OutputArray(6) = beta
OutputArray(7) = chi
OutputArray(8) = fi
OutputArray(9) = zeta
OutputArray(10) = gamma
If ErrorMsg = "No errors" Then
zFlow_vu = OutputArray
Else
zFlow_vu = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Function to calculate Psat as function of k1 and T '
'----------------------------------------------------------------------------------'
Function Psat_k1(FluidData As String, k1 As Double, T As Double)
'This is a hidden function...
Dim Psat As Double
Dim ErrorMsg As String
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
' Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
Psat_k1 = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call FP.StanMix_Psat_k1(k1, T, Psat, ErrorMsg)
If ErrorMsg = "No errors" Then
Psat_k1 = Psat
Else
Psat_k1 = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Functions to retrieve fluid info '
'----------------------------------------------------------------------------------'
Function GetInfo(FluidData As String, DataSpec As String)
' General fluid info retrieval function
Dim ErrorMsg As String
Dim output As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
' Retrieve fluid data if working fluid found...
If Not ErrorMsg = "No errors" Then
GetInfo = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Select Case DataSpec
Case "Mmol"
Call [Link](output, ErrorMsg)
Case "Tcrit"
Call [Link](output, ErrorMsg)
Case "Pcrit"
Call [Link](output, ErrorMsg)
Case "Tmin"
Call [Link](output, ErrorMsg)
Case "Tmax"
Call [Link](output, ErrorMsg)
End Select
If ErrorMsg = "No errors" Then
GetInfo = output
Else
GetInfo = ErrorMsg
End If
End If
End Function
Function Mmol(FluidData As String)
' It calculates the molar mass [kg/mol]
Mmol = GetInfo(FluidData, "Mmol")
End Function
Function Tcrit(FluidData As String)
' It calculates the critical temperature [°C]
Tcrit = GetInfo(FluidData, "Tcrit")
End Function
Function Pcrit(FluidData As String)
' It calculates the critical pressure [bar]
Pcrit = GetInfo(FluidData, "Pcrit")
End Function
Function Tmin(FluidData As String)
' It calculates the lower temperature limit [°C]
Tmin = GetInfo(FluidData, "Tmin")
End Function
Function Tmax(FluidData As String)
' It calculates the upper temperature limit [°C]
Tmax = GetInfo(FluidData, "Tmax")
End Function
Function AllInfo(FluidData As String)
' It calculates all info in one go.
Dim ErrorMsg As String
Dim OutputArray(1 To 5) As Double
Dim Mmol As Double
Dim Tcrit As Double
Dim Pcrit As Double
Dim Tmin As Double
Dim Tmax As Double
' Get working fluid from from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
' Retrieve fluid data if working fluid found...
If Not ErrorMsg = "No errors" Then
AllInfo = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](Mmol, Tcrit, Pcrit, Tmin, Tmax, ErrorMsg)
OutputArray(1) = Mmol
OutputArray(2) = Tcrit
OutputArray(3) = Pcrit
OutputArray(4) = Tmin
OutputArray(5) = Tmax
If ErrorMsg = "No errors" Then
AllInfo = OutputArray
Else
AllInfo = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Procedures concerning unit set and reference state '
'----------------------------------------------------------------------------------'
Function SetUnits(Optional UnitSet As String = "FluidProp", Optional MassOrMole As String = "", _
Optional PropSymbol As String = "", Optional PropUnit As String = "")
Dim ErrorMsg As String
Call [Link](UnitSet, MassOrMole, PropSymbol, PropUnit, ErrorMsg)
If ErrorMsg = "No errors" Then
SetUnits = UnitSet
If Not MassOrMole = "" Then
SetUnits = SetUnits + ", " + MassOrMole
End If
If Not PropSymbol = "" Then
SetUnits = SetUnits + ", " + PropSymbol
End If
If Not PropUnit = "" Then
SetUnits = SetUnits + ", " + PropUnit
End If
'[Link]
Else
SetUnits = ErrorMsg
End If
End Function
Function Excel_SetUnits(UnitData As String)
' General supporting function to define the units set. It retrieves
' the units set from the cell that specifies the units set. It is
' used by SetFluid.
Dim ErrorMsg As String
Dim Items(1 To 250) As String
Dim Counter As Long
Dim ItemCount As Long
Dim NumUnits As Long
Dim UnitSet As String
Dim MassOrMole As String
Dim PropSymbol As String
Dim PropUnit As String
'Parse units data string.
ItemCount = 1
For Counter = 1 To Len(UnitData)
If Mid(UnitData, Counter, 1) = "," Then
ItemCount = ItemCount + 1
Else
Items(ItemCount) = Items(ItemCount) + Mid(UnitData, Counter, 1)
End If
Next Counter
'Count number of specified property and unit symbols
NumUnits = (ItemCount - 2) / 2
'Store parsed unit data in strings
UnitSet = Trim(Items(1))
MassOrMole = Trim(Items(2))
PropSymbol = ""
PropUnit = ""
For Counter = 1 To NumUnits
If Counter = 1 Then
PropSymbol = Items(2 + Counter)
Else
PropSymbol = PropSymbol + "," + Items(2 + Counter)
End If
If Counter = 1 Then
PropUnit = Items(2 + NumUnits + Counter)
Else
PropUnit = PropUnit + "," + Items(2 + NumUnits + Counter)
End If
Next Counter
'Update units in FluidProp DLL
Call [Link](UnitSet, MassOrMole, PropSymbol, PropUnit, ErrorMsg)
Excel_SetUnits = ErrorMsg
End Function
Function SetRefState(T_ref As Double, P_ref As Double)
' Defines the reference state in order to process nondimensional properties
Dim ErrorMsg As String
Call [Link](T_ref, P_ref, ErrorMsg)
If ErrorMsg = "No errors" Then
SetRefState = "Reference state: T_ref = " + CStr(T_ref) + ", P_ref = " + CStr(P_ref)
Else
SetRefState = ErrorMsg
End If
End Function
Function SaturationLine(FluidData As String)
' Function returns data of saturation line'
Dim ErrorMsg As String
Dim nPnts As Long
Dim T(1 To 5000) As Double
Dim P(1 To 5000) As Double
Dim x(1 To 20, 1 To 5000) As Double
Dim y(1 To 20, 1 To 5000) As Double
Dim OutputArray(1 To 5000, 1 To 2) As Double
Dim i As Integer
ErrorMsg = Excel_SetFluid(FluidData)
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
SaturationLine = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](nPnts, T, P, x, y, ErrorMsg)
If ErrorMsg = "No errors" Then
For i = 1 To nPnts
OutputArray(i, 1) = T(i)
OutputArray(i, 2) = P(i)
Next i
'For i = nPnts + 1 To 5000
' OutputArray(i, 1) = -8888.8
' OutputArray(i, 2) = -8888.8
'Next i
SaturationLine = OutputArray
Else
SaturationLine = ErrorMsg
End If
End If
End Function
Function IsoLine(FluidData As String, PropSpec As String, PropVal As Double, RunSpec As String, _
CalcSpec As String, MinVal As Double, MaxVal As Double, nPnts As Long)
' Function returns data of the isoline, specified by PropSpec.'
Dim ErrorMsg As String
Dim RunVal(1 To 1000) As Double
Dim Calcval(1 To 1000) As Double
Dim OutputArray(1 To 1000, 1 To 2) As Double
Dim i As Integer
ErrorMsg = Excel_SetFluid(FluidData)
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
IsoLine = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](PropSpec, PropVal, RunSpec, CalcSpec, MinVal, MaxVal, nPnts, RunVal, Calcval, _
ErrorMsg)
If ErrorMsg = "No errors" Then
For i = 1 To nPnts
OutputArray(i, 1) = RunVal(i)
OutputArray(i, 2) = Calcval(i)
Next i
IsoLine = OutputArray
Else
IsoLine = ErrorMsg
End If
End If
End Function
'------------------------------------------------------------------------------------------'
' Function to calculate x,y as function of Aij,Aji,alfa and P,T for StanMix mixures '
'------------------------------------------------------------------------------------------'
Function xy_A_alfa(FluidData As String, Aij As Double, Aji As Double, alfa As Double, _
P As Double, T As Double)
'This is a hidden function...
Dim xy(1 To 2) As Double
Dim ErrorMsg As String
Dim x(1 To 2) As Double
Dim y(1 To 2) As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
' Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
xy_A_alfa = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call FP.StanMix_xy_A_alfa(Aij, Aji, alfa, P, T, x, y, ErrorMsg)
If ErrorMsg = "No errors" Then
xy(1) = x(1)
xy(2) = y(1)
xy_A_alfa = xy
Else
xy_A_alfa = ErrorMsg
End If
End If
End Function
'------------------------------------------------------------------------------------------'
' Function to calculate x,y as function of kij and P,T for PCP-SAFT mixures '
'------------------------------------------------------------------------------------------'
Function xy_kij(FluidData As String, kij As Double, P As Double, T As Double)
'This is a hidden function...
Dim xy(1 To 2) As Double
Dim ErrorMsg As String
Dim x(1 To 2) As Double
Dim y(1 To 2) As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
' Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
xy_kij = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call FP.PCP_SAFT_xy_kij(kij, P, T, x, y, ErrorMsg)
If ErrorMsg = "No errors" Then
xy(1) = x(1)
xy(2) = y(1)
xy_kij = xy
Else
xy_kij = ErrorMsg
End If
End If
End Function
'----------------------------------------------------------------------------------'
' Calculation function for all output properties in one go '
'----------------------------------------------------------------------------------'
Function AllTransProps(FluidData As String, T As Double, rho As Double)
Dim ErrorMsg As String
Dim Items(1 To 250) As String
Dim Counter As Long
Dim ItemCount As Long
Dim OutputArray(1 To 2) As Double
Dim eta As Double
Dim eta_T As Double
Dim eta_rho As Double
Dim lambda As Double
Dim lambda_T As Double
Dim lambda_rho As Double
' Get working fluid from fluid definition cell
ErrorMsg = Excel_SetFluid(FluidData)
'Parse Fluid data string
ItemCount = 1
For Counter = 1 To Len(FluidData)
If Mid(FluidData, Counter, 1) = "," Then
ItemCount = ItemCount + 1
Else
Items(ItemCount) = Items(ItemCount) + Mid(FluidData, Counter, 1)
End If
Next Counter
'Calculate thermodynamic properties if working fluid found...
If Not ErrorMsg = "No errors" Then
AllTransProps = "Invalid cell reference. There is not a valid working fluid definition in that cell."
Else
Call [Link](T, rho, eta, eta_T, eta_rho, lambda, lambda_T, lambda_rho, ErrorMsg)
OutputArray(1) = eta
OutputArray(2) = lambda
If ErrorMsg = "No errors" Then
AllTransProps = OutputArray
Else
AllTransProps = ErrorMsg
End If
End If
End Function
'Public Sub Pippo()
Rem prova routine per chiamata diretta da VBA di funzioni fluidprop
'Function Luca(lc1 As Double, lc2 As Double)
'Dim lc1 As Double
'Dim lc2 As Double
'Dim H As Double
'lc1 = 40
'lc2 = 400
'MsgBox "parto"
'H = Calculate("IF97", "PT", "Enthalpy", lc1, lc2)
'Range("O2") = H
'End Sub