My Project
programmer's documentation
Examples of enthalpy-temperature conversion law (usthht.f90)

The usthht subroutine is used to encapsulate a simple enthalpy-temperature conversion law and its inverse.

Introduction

The usthht function allows one to define a simple enthalpy-temperature conversion law and its inverse. The parameters mode allows one to know in which direction the conversion will be made.

Examples

The following code blocks show two examples of entahlpy-temperature conversion law.

Example 1

The first example corresponds to a simple law :

\[H = C_p dt \]

! First example, corresponding to H = CpT with Cp = 4000
! ======================================================
! --- Mode H -> T
if (mode .eq. 1) then
temper = enthal / 4000.d0
! --- Mode T -> H
else
enthal = temper * 4000.d0
endif

Example 2

The second example corresponds to a simple interpolation based on a tabulation defined hereafter and declared as a variable :

! For the second example below,
! input of ntab > 1 (fictitious) tabulated values of H (=HT)
! as a function of NTAB values of T (=TH) (be careful with unit K or C)
integer ntab
parameter(ntab=5)
double precision ht(ntab), th(ntab)
data ht /100000.d0,200000.d0,300000.d0, &
400000.d0,500000.d0 /
data th / 100.d0, 200.d0, 300.d0, &
400.d0, 500.d0 /

The enthalpy-temperature conversion law is then defined :

! Second example, corresponding to a simple interpolation
! based on a tabulation H = f(T) entered as DATA
! ======================================================
! --- Mode H -> T
if (mode .eq. 1) then
! Default initialization
temper = 0.d0
! If H is smaller than the smallest tabulated value,
! set T to smallest temperature.
if (enthal.le.ht(1)) then
temper = th(1)
! If H is larger than the largest tabulated value,
! set T to largest temperature.
else if (enthal.ge.ht(ntab)) then
temper = th(ntab)
! Otherwise, use piecewise linear interpolation
else
do it = 2, ntab
if(enthal.le.ht(it)) then
temper = th(it-1) &
+(enthal-ht(it-1))*(th(it)-th(it-1))/(ht(it)-ht(it-1))
endif
enddo
endif
! --- Mode T -> H
else
! Default initialization
enthal = 0.d0
! If T is smaller than the smallest tabulated value,
! set H to smallest enthalpy.
if (temper.le.th(1)) then
enthal = ht(1)
! If T is larger than the largest tabulated value,
! set H to largest enthalpy.
else if (temper.ge.th(ntab)) then
enthal = ht(ntab)
! Otherwise, use piecewise linear interpolation
else
do it = 2, ntab
if(temper.le.th(it)) then
enthal = ht(it-1) &
+(temper-th(it-1))*(ht(it)-ht(it-1))/(th(it)-th(it-1))
endif
enddo
endif
endif