p) dRhoL = rho1 ; dPRhoL = p1 ; dRhoH = rho2 ; dPRhoH = p2 ; ptAGA10->lStatus = NORMAL ; return; } else if (p2 > p1) { if (ptAGA10->lStatus == MAX_DENSITY_IN_BRAKET_EXCEEDED) del *= 2.0 ; rho1 = rho2 ; p1 = p2 ; rho2 = rho1 + del ; continue ; } else { // lStatus= NEGATIVE_DENSITY_DERIVATIVEindicates that // pressure has a negative density derivative, since p2 is less than // some previous pressure ptAGA10->lStatus = NEGATIVE_DENSITY_DERIVATIVE; dRho = rho1;
91
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. return; } } // maximum number of iterations exceeded if we fall through the bottom ptAGA10->lStatus = MAX_NUM_OF_ITERATIONS_EXCEEDED ; dRho = rho2 ; return ; }
// Detail::braket()
/************************************************************************** * Function : Detail::pdetail() * Arguments : double * Returns : void * Purpose : calculates pressure, given D and T. Calls zdetail() * Revisions : **************************************************************************/ void Detail::pdetail(double dD) { dPCalc = zdetail(dD) * dD * RGASKJ * dT ; } // Detail::pdetail()
92
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Detail::zdetail() * Arguments : double * Returns : void * Purpose : calculates compressibility * Revisions : **************************************************************************/ double Detail::zdetail(double d) { // variables local to function double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4 ; // D1 D2 D3 D4 D5 D6 D7 D8 D9
powers = dKp3 = D1 * = D2 * = D3 * = D4 * = D5 * = D6 * = D7 * = D8 *
exp1 exp2 exp3 exp4
= = = =
of reduced density * d ; D1 ; D1 ; D1 ; D1 ; D1 ; D1 ; D1 ; D1 ;
exp(-D1) exp(-D2) exp(-D3) exp(-D4)
; ; ; ;
// the following expression for Z was adopted from FORTRAN example in AGA8 dZ = 1.0 + dB * d + adFn[12] * D1 * (exp3 - 1.0 - 3.0 * D3 * exp3) + (adFn[13] + adFn[14] + adFn[15]) * D1 * (exp2 - 1.0 - 2.0 * D2 * exp2) + (adFn[16] + adFn[17]) * D1 * (exp4 - 1.0 - 4.0 * D4 * exp4) + (adFn[18] + adFn[19]) * D2 * 2.0 + (adFn[20] + adFn[21] + adFn[22]) * D2 * (2.0 - 2.0 * D2) * exp2 + (adFn[23] + adFn[24] + adFn[25]) * D2 * (2.0 - 4.0 * D4) * exp4 + adFn[26] * D2 * (2.0 - 4.0 * D4) * exp4 + adFn[27] * D3 * 3.0 + (adFn[28] + adFn[29]) * D3 * (3.0 - D1) * exp1
93
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. + + + + + + + + + + + + + + + + }
(adFn[30] (adFn[32] (adFn[34] (adFn[37] (adFn[39] (adFn[42] adFn[44] (adFn[45] (adFn[47] adFn[49] adFn[50] adFn[51] adFn[52] adFn[53] (adFn[54] (adFn[56]
+ + + + + + * + + * * * * * + +
adFn[31]) * D3 * (3.0 - 2.0 * D2) * exp2 adFn[33]) * D3 * (3.0 - 3.0 * D3) * exp3 adFn[35] + adFn[36]) * D3 * (3.0 - 4.0 * D4) * exp4 adFn[38]) * D4 * 4.0 adFn[40] + adFn[41]) * D4 * (4.0 - 2.0 * D2) * exp2 adFn[43]) * D4 * (4.0 - 4.0 * D4) * exp4 D5 * 5.0 adFn[46]) * D5 * (5.0 - 2.0 * D2) * exp2 adFn[48]) * D5 * (5.0 - 4.0 * D4) * exp4 D6 * 6.0 D6 * (6.0 - 2.0 * D2) * exp2 D7 * 7.0 D7 * (7.0 - 2.0 * D2) * exp2 D8 * (8.0 - D1) * exp1 adFn[55]) * D8 * (8.0 - 2.0 * D2) * exp2 adFn[57]) * D9 * (9.0 - 2.0 * D2) * exp2 ;
return dZ ; // Detail::zdetail()
/************************************************************************** * Function : Detail::dZdT() * Arguments : double * Returns : double * Purpose : calculates the first partial derivative of Z wrt T * Revisions : **************************************************************************/ double Detail::dZdT(double d) { // variables local to function double tmp ; int i ; double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4 ; // set up powers of reduced density D1 = dKp3 * d ; D2 = D1 * D1 ;
94
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. D3 D4 D5 D6 D7 D8 D9
= = = = = = =
exp1 exp2 exp3 exp4
D2 D3 D4 D5 D6 D7 D8 = = = =
* * * * * * *
D1 D1 D1 D1 D1 D1 D1
; ; ; ; ; ; ;
exp(-D1) exp(-D2) exp(-D3) exp(-D4)
; ; ; ;
// create terms uC*T^-(un+1) from coefficients we've already computed (An[n]) for (i=12; i < 58; i++) { if (adUn[i] && adFn[i]) { fx[i] = (adFn[i] * adUn[i] * D1) / dT; } else { fx[i] = 0.0 ; } } // initial part of equation ddZdT = d * ddBdT ; // n=13 evaluates to zero except for hydrogen, for whom fn = 1 if (dF) ddZdT += fx[12] - (fx[12] * (1.0 - 3.0 * D3) * exp3) ; tmp = ddZdT ddZdT ddZdT
(1.0 - 2.0 * D2) * exp2 ; += (fx[13] - (fx[13] * tmp)) ; += fx[14] - (fx[14] * tmp) ; += fx[15] - (fx[15] * tmp) ;
tmp = (1.0 - 4.0 * D4) * exp4 ; ddZdT += fx[16] - (fx[16] * tmp) ; ddZdT += fx[17] - (fx[17] * tmp) ;
95
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. ddZdT = }
ddZdT - (fx[18] + fx[19]) * D1 * 2.0 (fx[21] + fx[22]) * D1 * (2.0 - 2.0 * D2) * exp2 (fx[23] + fx[24] + fx[25]) * D1 * (2.0 - 4.0 * D4) * exp4 fx[26] * D1 * (2.0 - 4.0 * D4) * exp4 fx[27] * D2 * 3.0 (fx[28] + fx[29]) * D2 * (3.0 - D1) * exp1 (fx[30] + fx[31]) * D2 * (3.0 - 2.0 * D2) * exp2 (fx[32] + fx[33]) * D2 * (3.0 - 3.0 * D3) * exp3 (fx[34] + fx[35] + fx[36]) * D2 * (3.0 - 4.0 * D4) * exp4 fx[37] * D3 * 4.0 (fx[39] + fx[40] + fx[41]) * D3 * (4.0 - 2.0 * D2) * exp2 (fx[42] + fx[43]) * D3 * (4.0 - 4.0 * D4) * exp4 fx[44] * D4 * 5.0 (fx[45] + fx[46]) * D4 * (5.0 - 2.0 * D2) * exp2 (fx[47] + fx[48]) * D4 * (5.0 - 4.0 * D4) * exp4 fx[49] * D5 * 6.0 fx[50] * D5 * (6.0 - 2.0 * D2) * exp2 fx[51] * D6 * 7.0 fx[52] * D6 * (7.0 - 2.0 * D2) * exp2 fx[53] * D7 * (8.0 - D1) * exp1 fx[54] * D7 * (8.0 - 2.0 * D2) * exp2 fx[56] * D8 * (9.0 - 2.0 * D2) * exp2 ;
return ddZdT ; // Detail::dDdT()
96
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Detail::d2ZdT2() * Arguments : double * Returns : double * Purpose : calculates the second partial derivative of Z wrt T * Revisions : **************************************************************************/ double Detail::d2ZdT2(double d) { // variables local to function double tmp ; int i ; double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4 ; // set up powers of reduced density D1 = dKp3 * d ; D2 = D1 * D1 ; D3 = D2 * D1 ; D4 = D3 * D1 ; D5 = D4 * D1 ; D6 = D5 * D1 ; D7 = D6 * D1 ; D8 = D7 * D1 ; D9 = D8 * D1 ; exp1 = exp(-D1) ; exp2 = exp(-D2) ; exp3 = exp(-D3) ; exp4 = exp(-D4) ; // create terms uC*T^-(un+1) from coefficients we've already computed (An[n]) for (i=12; i < 58; i++) { if (adUn[i] && adFn[i]) { fx[i] = (adFn[i] * D1 * adUn[i] * (adUn[i] + 1.0)) / (dT * dT) ; } else { fx[i] = 0.0 ;
97
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. } } // initial part of equation dd2ZdT2 = d * dd2BdT2 ; // n=13 evaluates to zero except for hydrogen, for whom fn = 1 if (dF) dd2ZdT2 += fx[12] - (fx[12] * (1.0 - 3.0 * D3) * exp3) ; tmp = (1.0 dd2ZdT2 += dd2ZdT2 += dd2ZdT2 +=
- 2.0 * -fx[13] -fx[14] -fx[15]
D2) * exp2 ; + (fx[13] * tmp) ; + (fx[14] * tmp) ; + (fx[15] * tmp) ;
tmp = (1.0 - 4.0 * D4) * exp4 ; dd2ZdT2 += -fx[16] + (fx[16] * tmp) ; dd2ZdT2 += -fx[17] + (fx[17] * tmp) ; dd2ZdT2 + + + + + + + + + + + + + + + + + + + + +
= dd2ZdT2 + (fx[18] + fx[19]) * D1 * 2.0 (fx[21] + fx[22]) * D1 * (2.0 - 2.0 * D2) * exp2 (fx[23] + fx[24] + fx[25]) * D1 * (2.0 - 4.0 * D4) * exp4 fx[26] * D1 * (2.0 - 4.0 * D4) * exp4 fx[27] * D2 * 3.0 (fx[28] + fx[29]) * D2 * (3.0 - D1) * exp1 (fx[30] + fx[31]) * D2 * (3.0 - 2.0 * D2) * exp2 (fx[32] + fx[33]) * D2 * (3.0 - 3.0 * D3) * exp3 (fx[34] + fx[35] + fx[36]) * D2 * (3.0 - 4.0 * D4) * exp4 fx[37] * D3 * 4.0 (fx[39] + fx[40] + fx[41]) * D3 * (4.0 - 2.0 * D2) * exp2 (fx[42] + fx[43]) * D3 * (4.0 - 4.0 * D4) * exp4 fx[44] * D4 * 5.0 (fx[45] + fx[46]) * D4 * (5.0 - 2.0 * D2) * exp2 (fx[47] + fx[48]) * D4 * (5.0 - 4.0 * D4) * exp4 fx[49] * D5 * 6.0 fx[50] * D5 * (6.0 - 2.0 * D2) * exp2 fx[51] * D6 * 7.0 fx[52] * D6 * (7.0 - 2.0 * D2) * exp2 fx[53] * D7 * (8.0 - D1) * exp1 fx[54] * D7 * (8.0 - 2.0 * D2) * exp2 fx[56] * D8 * (9.0 - 2.0 * D2) * exp2 ;
98
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA.
}
return dd2ZdT2 ; // Detail::d2ZdT2()
/************************************************************************** * Function : Detail::dZdD() * Arguments : double * Returns : double * Purpose : calculates the first partial derivative of Z wrt D * Revisions : **************************************************************************/ // // // //
For efficiency and continuity with AGA 8 code example, each term is evaluated individually rather than through looping through tables. Temporary storage is used to hold portions of complex equations and to facilitate debugging. Additional speed optimization is possible.
double Detail::dZdD(double d) { double temp, temp1, temp2, temp3; int i ; double D1, D2, D3, D4, D5, D6, D7, D8, D9, exp1, exp2, exp3, exp4 ; // set up powers of reduced density D1 = dKp3 * d ; D2 = D1 * D1 ; D3 = D2 * D1 ; D4 = D3 * D1 ; D5 = D4 * D1 ; D6 = D5 * D1 ; D7 = D6 * D1 ; D8 = D7 * D1 ; D9 = D8 * D1 ; exp1 = exp(-D1) ; exp2 = exp(-D2) ; exp3 = exp(-D3) ; exp4 = exp(-D4) ;
99
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // create terms uC*T^-(un+1) from coefficients we've already computed (An[n]) for (i=12; i < 58; i++) { fx[i] = adFn[i] ; } // initial part of equation ddZdD = dB / dKp3 ; // evaluate all remaining terms, simplifying where possible // n=13 evaluates to zero except for hydrogen, for whom fn = 1 if (dF) { temp1 = -9.0 * D3 * exp3 ; temp2 = (1.0 - 3.0 * D3) * exp3 ; temp3 = -temp2 * 3.0 * D6; temp = temp1 + temp2 + temp3 ; ddZdD += -fx[12] + fx[12] * temp ; } // n = 14..16 temp1 = -4.0 * D2 * exp2 ; temp2 = (1.0 - 2.0 * D2) * exp2 ; temp3 = -temp2 * 2.0 * D2; temp = temp1 + temp2 + temp3 ; ddZdD += -fx[13] + fx[13] * temp ; ddZdD += -fx[14] + fx[14] * temp ; ddZdD += -fx[15] + fx[15] * temp ; // n = 17..18 temp1 = -16.0 * D4 * exp4 ; temp2 = (1.0 - 4.0 * D4) * exp4 ; temp3 = -temp2 * 4.0 * D4 ; temp = temp1 + temp2 + temp3 ; ddZdD += -fx[16] + fx[16] * temp ; ddZdD += -fx[17] + fx[17] * temp ; // n = 19..20 temp = 4.0 * D1 ; ddZdD += fx[18] * temp ; ddZdD += fx[19] * temp ;
100
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // n = 21..23 temp1 = -4.0 * D3 * exp2 ; temp2 = (2.0 - 2.0 * D2) * 2.0 * D1 * exp2 ; temp3 = -temp2 * D2; temp = temp1 + temp2 + temp3 ; ddZdD += fx[20] * temp ; ddZdD += fx[21] * temp ; ddZdD += fx[22] * temp ; // n = 24..27 temp1 = -16.0 * D5 * exp4 ; temp2 = (2.0 - 4.0 * D4) * 2.0 * D1 * exp4 ; temp3 = -temp2 * 2.0 * D4 ; temp = temp1 + temp2 + temp3 ; ddZdD += fx[23] * temp ; ddZdD += fx[24] * temp ; ddZdD += fx[25] * temp ; ddZdD += fx[26] * temp ; // n = 28 temp = 9.0 * D2 ; ddZdD += fx[27] * temp ; // n = 29..30 temp = -D3 * exp1 + (3.0 - D1) * 3.0 * D2 * exp1 ; temp -= (3.0 - D1) * D3 * exp1 ; ddZdD += fx[28] * temp ; ddZdD += fx[29] * temp ; // n = 31..32 temp1 = -4.0 * D4 * exp2 ; temp2 = (3.0 - 2.0 * D2) * 3.0 * D2 * exp2 ; temp3 = -(3.0 - 2.0 * D2) * 2.0 * D4 * exp2 ; temp = temp1 + temp2 + temp3 ; ddZdD += fx[30] * temp ; ddZdD += fx[31] * temp ; // n = 33..34 temp1 = -9.0 * D5 * exp3 ;
101
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. temp2 = (3.0 - 3.0 * D3) * 3.0 * D2 * exp3 ; temp3 = -(3.0 - 3.0 * D3) * 3.0 * D5 * exp3 ; temp = temp1 + temp2 + temp3 ; ddZdD += fx[32] * temp ; ddZdD += fx[33] * temp ; // n = 35..37 temp1 = -16.0 * D6 * exp4 ; temp2 = (3.0 - 4.0 * D4) * 3.0 * D2 * exp4 ; temp3 = -(3.0 - 4.0 * D4) * D6 * 4.0 * exp4 ; temp = temp1 + temp2 + temp3 ; ddZdD += fx[34] * temp ; ddZdD += fx[35] * temp ; ddZdD += fx[36] * temp ; // n = 38..39 temp = 16.0 * D3 ; ddZdD += fx[37] * temp ; ddZdD += fx[38] * temp ; // n = 40..42 temp1 = -4.0 * D5 * exp2 ; temp2 = (4.0 - 2.0 * D2) * 4.0 * D3 * exp2 ; temp3 = -(4.0 - 2.0 * D2) * 2.0 * D5 * exp2 ; temp = temp1 + temp2 + temp3 ; ddZdD += fx[39] * temp ; ddZdD += fx[40] * temp ; ddZdD += fx[41] * temp ; // n = 43..44 temp = -16.0 * D7 * exp4 + (4.0 - 4.0 * D4) * 4.0 * D3 * exp4 ; temp -= (4.0 - 4.0 * D4) * D7 * 4.0 * exp4 ; ddZdD += fx[42] * temp ; ddZdD += fx[43] * temp ; // n = 45 temp = 25.0 * D4 ; ddZdD += fx[44] * temp ; // n =
46..47
102
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. temp = -4.0 * D6 * exp2 + (5.0 - 2.0 * D2) * 5.0 * D4 * exp2 ; temp -= (5.0 - 2.0 * D2) * D6 * 2.0 * exp2 ; ddZdD += fx[45] * temp ; ddZdD += fx[46] * temp ; // n = 48..49 temp = -16.0 * D8 * exp4 + (5.0 - 4.0 * D4) * 5.0 * D4 * exp4 ; temp -= (5.0 - 4.0 * D4) * D8 * 4.0 * exp4 ; ddZdD += fx[47] * temp ; ddZdD += fx[48] * temp ; // n = 50 temp = 36.0 * D5 ; ddZdD += fx[49] * temp ; // n = 51 temp = -4.0 * D7 * exp2 + (6.0 - 2.0 * D2) * 6.0 * D5 * exp2 ; temp -= (6.0 - 2.0 * D2) * D7 * 2.0 * exp2 ; ddZdD += fx[50] * temp ; // n = 52 temp = 49.0 * D6 ; ddZdD += fx[51] * temp ; // n = 53 temp = -4.0 * D8 * exp2 + (7.0 - 2.0 * D2) * 7.0 * D6 * exp2 ; temp -= (7.0 - 2.0 * D2) * D8 * 2.0 * exp2 ; ddZdD += fx[52] * temp ; // n = 54 temp = -1.0 * D8 * exp1 + (8.0 - D1) * 8.0 * D7 * exp1 ; temp -= (8.0 - D1) * D8 * exp1 ; ddZdD += fx[53] * temp ; // n = 55..56 temp = -4.0 * D1 * D8 * exp2 + (8.0 - 2.0 * D2) * 8.0 * D7 * exp2 ; temp -= (8.0 - 2.0 * D2) * D8 * 2.0 * D1 * exp2 ; ddZdD += fx[54] * temp ; ddZdD += fx[55] * temp ;
103
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // n = 57..58 temp = -4.0 * D2 * D8 * exp2 + (9.0 - 2.0 * D2) * 9.0 * D8 * exp2 ; temp -= (9.0 - 2.0 * D2) * D2 * D8 * 2.0 * exp2 ; ddZdD += fx[56] * temp ; ddZdD += fx[57] * temp ; ddZdD *= dKp3 ; }
return ddZdD ; // Detail::dZdD()
104
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Detail::relativedensity() * Arguments : AGA10STRUCT * * Returns : void * Purpose : calculates relative density via methods listed in AGA 8 * Revisions : **************************************************************************/ void Detail::relativedensity(AGA10STRUCT *ptAGA10) { double dBX, dZa ; const double dMWair = 28.96256 ; // calculate second virial coefficient for air dBX = -0.12527 + 5.91e-4 * ptAGA10->dTb - 6.62e-7 * ptAGA10->dTb * ptAGA10->dTb ; // calculate compressibility of air dZa = 1.0 + (dBX * dP) / (RGASKJ * ptAGA10->dTb) ;
}
// calculate ideal gas and real gas relative densities ptAGA10->dRD_Ideal = ptAGA10->dMrx / dMWair ; ptAGA10->dRD_Real = ptAGA10->dRD_Ideal * (dZa / ptAGA10->dZb) ; // Detail::relativedensity()
105
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * File : therm.h * Description : Header file for class 'Therm' * See therm.cpp for implementation of this class * Version : ver 1.7 2002.11.17 * Author : W.B. Peterson * Revisions: * Copyright (c) 2002 American Gas Association **************************************************************************/ #ifndef _THERM_H #define _THERM_H #include "aga10.h" #include "detail.h" class Therm { private: // member data double dT ; double dP ; double dD ; double dRho ; double dPdD ; double dPdT ; double dSi ; double dTold ; double dMrxold ;
// current temperature, in Kelvins // current pressure, in Pascals // molar density, in moles/dm3 // mass density, in kg/m3 // partial deriv of P wrt D // partial deriv of P wrt T // ideal gas specific entropy, kJ/kg.K // temperature previously used // mixture molar mass previously used
// private methods double CpiMolar(AGA10STRUCT *) ; protected: public: Therm(void) ; ~Therm() ;
// default constructor // default destructor
106
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. void Run(AGA10STRUCT *, Detail *) ; // runs an object based on this class double Ho(AGA10STRUCT *) ; // ideal gas enthalpy double So(AGA10STRUCT *) ; // ideal gas entropy void CprCvrHS(AGA10STRUCT *, Detail *) ; // specific heat capacities + k_ideal + H + S double H(AGA10STRUCT *, Detail *) ; // real gas specific enthalpy double S(AGA10STRUCT *, Detail *) ; // real gas specific entropy void HS_Mode(AGA10STRUCT *, Detail *, double, double, bool) ; // estimates P & T, given H & S } ; //
Other data used by Therm class
// Roots and Weights for gaussian quadrature const long double GK_root[5] = { 0.14887433898163121088, 0.43339539412924719080, 0.67940956829902440263, 0.86506336668898451073, 0.97390652851717172008 }; const long double GK_weight[5] = { 0.29552422471475286217, 0.26926671930999634918, 0.21908636251598204295, 0.14945134915058059038, 0.066671344308688137179 }; // set the number of points for quadrature const int GK_points = 5 ;
107
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. //equation constants for ideal gas heat capacity, enthalpy and entropy const double ThermConstants[NUMBEROFCOMPONENTS[11] = {{-29776.4, 7.95454, 43.9417, 1037.09, 1.56373, 813.205, -24.9027, 1019.98,-10.1601, 1070.14,-20.0615}, {-3495.34, 6.95587, 0.272892, 662.738,-0.291318,-680.562, 1.78980, 1740.06, 0.0, 100.0, 4.49823}, { 20.7307, 6.96237, 2.68645, 500.371,-2.56429,-530.443, 3.91921, 500.198, 2.13290, 2197.22, 5.81381}, {-37524.4, 7.98139, 24.3668, 752.320, 3.53990, 272.846, 8.44724, 1020.13,-13.2732, 869.510,-22.4010}, {-56072.1, 8.14319, 37.0629, 735.402, 9.38159, 247.190, 13.4556, 1454.78,-11.7342, 984.518,-24.0426}, {-13773.1, 7.97183, 6.27078, 2572.63, 2.05010, 1156.72, 0.0, 100.0, 0.0, 100.0, -3.24989}, {-10085.4, 7.94680,-0.08380, 433.801, 2.85539, 843.792, 6.31595, 1481.43,-2.88457, 1102.23,-0.51551}, {-5565.60, 6.66789, 2.33458, 2584.98, .749019, 559.656, 0.0, 100.0, 0.0, 100.0, -7.94821}, {-2753.49, 6.95854, 2.02441, 1541.22, .096774, 3674.81, 0.0, 100.0, 0.0, 100.0, 6.23387}, {-3497.45, 6.96302, 2.40013, 2522.05, 2.21752, 1154.15, 0.0, 100.0, 0.0, 100.0, 9.19749}, {-72387.0, 17.8143, 58.2062, 1787.39, 40.7621, 808.645, 0.0, 100.0, 0.0, 100.0, -44.1341}, {-72674.8, 18.6383, 57.4178, 1792.73, 38.6599, 814.151, 0.0, 100.0, 0.0, 100.0, -46.1938}, {-91505.5, 21.3861, 74.3410, 1701.58, 47.0587, 775.899, 0.0, 100.0, 0.0, 100.0, -60.2474}, {-83845.2, 22.5012, 69.5789, 1719.58, 46.2164, 802.174, 0.0, 100.0, 0.0, 100.0, -62.2197}, {-94982.5, 26.6225, 80.3819, 1718.49, 55.6598, 802.069, 0.0, 100.0, 0.0, 100.0, -77.5366}, {-103353., 30.4029, 90.6941, 1669.32, 63.2028, 786.001, 0.0, 100.0, 0.0, 100.0, -92.0164}, {-109674., 34.0847, 100.253, 1611.55, 69.7675, 768.847, 0.0, 100.0, 0.0, 100.0, -106.149}, {-122599., 38.5014, 111.446, 1646.48, 80.5015, 781.588, 0.0, 100.0, 0.0, 100.0, -122.444}, {-133564., 42.7143, 122.173, 1654.85, 90.2255, 785.564, 0.0, 100.0, 0.0, 100.0, -138.006}, { 0.0, 4.9680, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0 }, { 0.0, 4.9680, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0, 100.0, 0.0 }};
// enumerations for indexing of coefficients enum CoefficientList{ coefA = 0, coefB, coefC, coefD, coefE, coefF, coefG, coefH, coefI, coefJ, coefK } ; // conversion constant for thermochemical calories to Joules: const double CalTH = 4.1840 ; #endif
108
1 cal(IT) = 4.1840 J
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * File: therm.cpp * Description: Contains thermodynamic functions for the meter object. * heat capacity, enthalpy, entropy, sound speed * Contains the functions: * Therm(), ~Therm(), Run(), coth(), CpiMolar(), Ho(), So(), * CprCvrHS(), HS_Mode(), H(), S() * Version: ver 1.7 2002.11.17 * Author: W.B. Peterson * Revisions: * Copyright (c) 2002 American Gas Association **************************************************************************/ #include #include #include #include
"aga10.h" "detail.h" "therm.h"
/************************************************************************** * Function : Therm::Therm() * Arguments : void * Returns : * Purpose : default constructor * Revisions : **************************************************************************/ Therm::Therm(void) { // initialize 3 history-sensitive variables dSi = 0.0 ; dTold = 0.0 ; dMrxold = 0.0 ; } // Therm::Therm()
109
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::~Therm() * Arguments : * Returns : default destructor * Purpose : void * Revisions : **************************************************************************/ Therm::~Therm() { } // Therm::~Therm()
/************************************************************************** * Function : coth() * Arguments : double * Returns : double * Purpose : calculate hyperbolic cotangent; used in Ho calculations * Revisions : * Notes : Not a Therm object class member, just a utility for this * file. The C++ language has no intrinsic support for * hyperbolic cotangent **************************************************************************/ double coth (double x) { return cosh(x)/sinh(x); } // coth()
110
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::Run() * Arguments : AGA10STRUCT *, Detail * * Returns : void * Purpose : overall execution control; top level math for SOS and k * Revisions : **************************************************************************/ void Therm::Run(AGA10STRUCT *ptAGA10, Detail *ptD) { // local variables double c, x, y, z ; // first run basic set of functions within AGA 8 (1994) Detail Method ptD->Run(ptAGA10) ; // find first partial derivative of Z wrt D ptD->dZdD(ptAGA10->dDf) ; // find real gas cv, cp, specific enthalpy and entropy CprCvrHS(ptAGA10, ptD) ; // ratio of real gas specific heats ptAGA10->dk = ptAGA10->dCp / ptAGA10->dCv ; // solve c in three steps, for clarity and ease of debugging x = ptAGA10->dk * RGAS * 1000.0 * ptAGA10->dTf ; y = ptAGA10->dMrx ; z = ptAGA10->dZf + ptAGA10->dDf * ptD->ddZdD ; // calculate c, which is SOS^2 c = (x / y) * z ; // speed of sound ptAGA10->dSOS = sqrt(c) ; // calculate the real gas isentropic exponent // using expression functionally equivalent to Equation 3.2 ptAGA10->dKappa = (c * ptAGA10->dRhof) / ptAGA10->dPf ;
111
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. }
return ; // Therm::Run()
/************************************************************************** * Function : Therm::CpiMolar() * Arguments : AGA10STRUCT * * Returns : double * Purpose : Calculate constant pressure ideal gas molar heat capacity * in (J/mol-K), applying eqns from Aly, Lee, McFall * Notes : For continuity, the original constants and eqn's have been * retained. Conversion from thermochemical calories(th) to * Joules is applied after the primary calculations are complete. * Revisions : **************************************************************************/ double Therm::CpiMolar(AGA10STRUCT *ptAGA10) { double Cp = 0.0 ; double Cpx ; double DT, FT, HT, JT ; double Dx, Fx, Hx, Jx ; double T ; int i ; // to maximize readability of this section, use intermediate variable T T = ptAGA10->dTf ; // calculate heat capacity for each component for (i= 0; i< NUMBEROFCOMPONENTS; i++) { // skip species whose concentration is zero if (ptAGA10->adMixture[i] <= 0.0) continue ; // initialize Cp of species to zero Cpx = 0.0 ; // calculate species intermediate terms DT = ThermConstants[i][coefD] / T ;
112
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. FT = ThermConstants[i][coefF] / T ; HT = ThermConstants[i][coefH] / T ; JT = ThermConstants[i][coefJ] / T ; // Dx Fx Hx Jx
use intermediate terms to avoid redundant calcs = DT/sinh(DT) ; = FT/cosh(FT) ; = HT/sinh(HT) ; = JT/cosh(JT) ;
Cpx Cpx Cpx Cpx Cpx
+= += += += +=
ThermConstants[i][coefB] ThermConstants[i][coefC] ThermConstants[i][coefE] ThermConstants[i][coefG] ThermConstants[i][coefI]
; * * * *
Dx Fx Hx Jx
* * * *
Dx Fx Hx Jx
; ; ; ;
// use current mole fraction to weight the contribution Cpx *= ptAGA10->adMixture[i]; // add this contribution to the sum Cp += Cpx ; } // convert from cal(th)/mol-K to J/mol-K Cp *= CalTH ; }
return Cp ; // Therm::CpiMolar()
113
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::Ho() * Arguments : AGA10STRUCT * * Returns : double * Purpose : Calculate ideal gas specific enthalpy (J/kg) * Notes : For continuity, the original constants and eqn's have been * retained. Conversion from thermochemical calories(th) to * Joules is applied after the primary calculations are complete. * Revisions : **************************************************************************/ double Therm::Ho(AGA10STRUCT *ptAGA10) { double H = 0.0 ; double Hx ; double DT, FT, HT, JT ; double cothDT, tanhFT, cothHT, tanhJT ; double T ; int i ; // to maximize readability of this section, use intermediate variable T T = ptAGA10->dTf ; for (i= 0; i< NUMBEROFCOMPONENTS; i++) { // skip species whose concentration is zero if (ptAGA10->adMixture[i] <= 0.0) continue ; Hx = 0.0 ; // DT FT HT JT
calculate species intermediate = ThermConstants[i][coefD] / T = ThermConstants[i][coefF] / T = ThermConstants[i][coefH] / T = ThermConstants[i][coefJ] / T
cothDT tanhFT cothHT tanhJT
= = = =
coth(DT) tanh(FT) coth(HT) tanh(JT)
terms ; ; ; ;
; ; ; ;
114
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. Hx Hx Hx Hx Hx Hx
+= += += -= += -=
ThermConstants[i][coefA] ThermConstants[i][coefB] ThermConstants[i][coefC] ThermConstants[i][coefE] ThermConstants[i][coefG] ThermConstants[i][coefI]
; * * * * *
T ; ThermConstants[i][coefD] ThermConstants[i][coefF] ThermConstants[i][coefH] ThermConstants[i][coefJ]
// use current mole fraction to weight the contribution Hx *= ptAGA10->adMixture[i]; // add this contribution to the sum H += Hx ; } // convert from cal(th)/g-mol to kJ/kg-mol H *= CalTH ; // convert from kJ/kg-mol to J/kg H /= ptAGA10->dMrx ;
}
// return in J/kg return H * 1.e3; // Therm::Ho()
115
* * * *
cothDT; tanhFT; cothHT; tanhJT;
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::So() * Arguments : AGA10STRUCT * * Returns : double * Purpose : ideal gas specific entropy (J/kg-K) * Notes : For continuity, the original constants and eqn's have been * retained. Conversion from thermochemical calories(th) to * Joules is applied after the primary calculations are complete. * Revisions : **************************************************************************/ double Therm::So(AGA10STRUCT *ptAGA10) { double S = 0.0 ; double Sx ; double DT, FT, HT, JT ; double cothDT, tanhFT, cothHT, tanhJT ; double sinhDT, coshFT, sinhHT, coshJT ; double T ; int i ; // to improve readability of this section, use intermediate variable T T = ptAGA10->dTf ; for (i= 0; i< NUMBEROFCOMPONENTS; i++) { // skip species whose concentration is zero if (ptAGA10->adMixture[i] <= 0.0) continue ; Sx = 0.0 ; // DT FT HT JT
calculate species intermediate = ThermConstants[i][coefD] / T = ThermConstants[i][coefF] / T = ThermConstants[i][coefH] / T = ThermConstants[i][coefJ] / T
terms ; ; ; ;
cothDT = coth(DT) ; tanhFT = tanh(FT) ; cothHT = coth(HT) ;
116
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. tanhJT = tanh(JT) ; sinhDT coshFT sinhHT coshJT Sx Sx Sx Sx Sx Sx
+= += += -= += -=
= = = =
sinh(DT) cosh(FT) sinh(HT) cosh(JT)
; ; ; ;
ThermConstants[i][coefK] ThermConstants[i][coefB] ThermConstants[i][coefC] ThermConstants[i][coefE] ThermConstants[i][coefG] ThermConstants[i][coefI]
; * * * * *
log(T) ; (DT * cothDT (FT * tanhFT (HT * cothHT (JT * tanhJT
-
log(sinhDT)) log(coshFT)) log(sinhHT)) log(coshJT))
// use current mole fraction to weight the contribution Sx *= ptAGA10->adMixture[i]; // add this contribution to the sum S += Sx ; } // convert cal(th)/mol-K basis to to kJ/kg mol-K S *= CalTH ; // convert from kJ/kg mol-K to kJ/kg-K S /= ptAGA10->dMrx ;
}
// return in J/kg-K return S * 1.e3; // Therm::So()
117
; ; ; ;
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::CprCvrHS() * Arguments : AGA10STRUCT *, Detail * * Returns : void * Purpose : reasonably efficient group calculation of Cp, Cv, H and S * Revisions : **************************************************************************/ void Therm::CprCvrHS(AGA10STRUCT *ptAGA10, Detail *ptD) { double Cvinc, Cvr, Cpr ; double Hinc ; double Sinc ; double Smixing ; double Cp, Si ; double a, b, x ; int i ; // initialize integrals to zero Cvinc = 0.0 ; Hinc = 0.0 ; Sinc = 0.0 ; // initialize entropy of mixing Smixing = 0.0 ; // find ideal gas Cp Cp = CpiMolar(ptAGA10) ; // find ideal gas enthalpy ptAGA10->dHo = Ho(ptAGA10) ; // find ideal gas entropy Si = So(ptAGA10) ; // calculate ideal gas specific heat capacity at constant pressure in J/kgK ptAGA10->dCpi = (Cp * 1000.0) / ptAGA10->dMrx ; // integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature for ( i= 0; i < GK_points; i++)
118
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. { // set calculation point at + abscissa x = ptAGA10->dDf * (1.0 + GK_root[i]) / 2.0 ; // get Z at D ptD->zdetail(x) ; ptD->dZdT(x) ; ptD->d2ZdT2(x) ; // gather contributions Hinc += GK_weight[i] * Cvinc += GK_weight[i] * Sinc += GK_weight[i] *
at + abscissa; applying weighting factor ptD->ddZdT / x ; (2.0 * ptD->ddZdT + ptAGA10->dTf * ptD->dd2ZdT2) / x ; (ptD->dZ + ptAGA10 ->dTf * ptD->ddZdT - 1.0) / x ;
// set calculation point at - abscissa x = ptAGA10->dDf * (1.0 - GK_root[i]) / 2.0 ; // get Z at D ptD->zdetail(x) ; // calculate 1st and 2nd partial derivatives of Z wrt T ptD->dZdT(x) ; ptD->d2ZdT2(x) ; // gather contributions Hinc += GK_weight[i] * Cvinc += GK_weight[i] * Sinc += GK_weight[i] *
at - abscissa; applying weighting factor ptD->ddZdT / x ; (2.0 * ptD->ddZdT + ptAGA10->dTf * ptD->dd2ZdT2) / x ; (ptD->dZ + ptAGA10 ->dTf * ptD->ddZdT - 1.0) / x ;
} // return Z and partial derivatives to full molar density ptD->zdetail(ptAGA10->dDf) ; ptD->dZdT(ptAGA10->dDf) ; ptD->d2ZdT2(ptAGA10->dDf) ; // complete Cv molar Cvr = Cp - RGAS * (1.0 + ptAGA10->dTf * Cvinc * 0.5 * ptAGA10->dDf) ; // intermediate values for Cp, containing 2 partial derivatives a =(ptAGA10->dZf + ptAGA10->dTf * ptD->ddZdT) ; b =(ptAGA10->dZf + ptAGA10->dDf * ptD->ddZdD) ; // calculate dPdT, the partial derivative of P wrt T, at D
119
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. dPdT = RGAS * ptAGA10->dDf * a ; // calculate dPdD, the partial derivative of P wrt D, at T dPdD = RGAS * ptAGA10->dTf * b ; // equation completing molar Cp, cancelling appropriate terms Cpr = Cvr + RGAS * ((a * a)/b) ; // change from molar to mass basis Cpr /= ptAGA10->dMrx ; Cvr /= ptAGA10->dMrx ; // write to the data stucture ptAGA10->dCv = Cvr * 1000.0 ; ptAGA10->dCp = Cpr * 1000.0 ;
// convert from joules/kgK to kilojoules/kgK
// calculate specific enthalpy ptAGA10->dH = ptAGA10->dHo + 1000.0 * RGAS * ptAGA10->dTf * (ptAGA10->dZf - 1.0 - ptAGA10->dTf * Hinc * 0.5 * ptAGA10->dDf) / ptAGA10->dMrx ; // calculate entropy of mixing for (i= 0; i< NUMBEROFCOMPONENTS; i++) { if (ptAGA10->adMixture[i]) Smixing += ptAGA10->adMixture[i] * log(ptAGA10->adMixture[i]) ; } Smixing *= RGAS ; // calculate specific entropy ptAGA10->dS = Si – Smixing - 1000.0 * RGAS * (log(ptAGA10->dPf/101325.0) - log(ptAGA10->dZf) + Sinc * 0.5 * ptAGA10->dDf) / ptAGA10->dMrx ; }
return ; // Therm::CprCvrHS()
120
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::HS_Mode() * Arguments : AGA10STRUCT *, Detail *, double, double, bool * Returns : void * Purpose : Calculates a pressure & temperature from known enthalpy & entropy, * with or without prior estimates.This function has a role in the * calculation of C*. * Solution based on a doubly-nested trial & error algorithm and Newton's * method. * * For illustrative purpose, two approaches are supported by this example. * If you are starting without advance knowledge of P & T, set the input parm * bGuess to false, thus specifying a conservative search approach. * If, however, you have a basis for guessing P & T (plenum conditions of a * critical flow nozzle, for example) set P & T via AGA10STRUCT and set * bGuess = true. The initial guess allows the search function to be more * aggressive and, typically, faster. * * Revisions : **************************************************************************/ void Therm::HS_Mode(AGA10STRUCT *ptAGA10, Detail *ptD, double H, double S, bool bGuess) { double s0, s1, s2, t0, t1, t2, tmin, tmax ; double h0, h1, h2, p0, p1, p2, px, pmin, pmax ; double delta1, delta2 ; double tolerance = 0.001 ;// convergence tolerance (used for both H and S searches) int i, j ; // s0and h0 are our real gas reference points s0 = S ; h0 = H ; // calling function specifies whether search parameters are supplied thru ptAGA10 or unknown if (bGuess) { t1 = ptAGA10->dTf ; px = ptAGA10->dPf ; pmax = px * 2.0 ; pmin = px * 0.1 ;
121
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. tmax = t1 * 1.5 ; tmin = t1 * 0.67 ; } else else {
// use arbitra arbitrary, ry, generic generic limits limits t1 = px = pmax pmin pmin tmax tmin
273.15 ; 101 10132 3250. 50.0 0 ; = P_MAX ; = 100 10000 00.0 .0 ; = T_MAX ; = T_MIN ;
// 10 10 atmo atmosph spher eres es // 10 kPa kPa
} // set the temperature differential t2 = t1 + 10.0 ; /////////////////////////////////////////// // begin double trial-and-error, searching for T & P // run the calculation with initial guesses ptD->Run(ptAGA10) ; // h1 is difference between h given and h@Tf, Pf h1 = this->H(ptAGA10, ptD) - h0; // outer loop: search for a t2 which will satisfy constant enthalpy for ( i= 0; i < MAX_NUM_OF_ITERATIONS; i++) { ptAGA10->dTf = t2 ; p1 = px ; // reset one bracket p2 = px * 0.1 ;// set other bracket to 0.1x the upper bracket ptAGA10->dPf = p1 ; ptD->Run(ptAGA10) ; s1 = this->S(ptAGA10, ptD) - s0; // inside loop: search for a p2 which will satisfy constant entropy for (j= 0; j < MAX_NUM_OF_ITERATIONS; j++) { ptAGA10->dPf = p2 ; ptD->Run(ptAGA10) ; s2 = this->S(ptAGA10, ptD) - s0 ; // calculate our proportional change
122
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. delta2 = fabs(s1 - s2) / s0 ; // close enough? if (delta2 < tolerance) break ; // revise our estimate to p2 p0 = p2 ; p2 = (p1 * s2 - p2 * s1) / (s2 - s1) ; // check for negative pressure and clamp to pmin for safety if (p2 <= pmin) { p2 = pmin ; } // check if we've created an unrealistic pressure if (p2 >= pmax ) p2 = pmax ; // swap values p1 = p0 ; s1 = s2 ; } // check for failure to converge if (j >= MAX_NUM_OF_ITERATIONS) ptAGA10->lStatus = MAX_NUM_OF_ITERATIONS_EXCEEDED ; // calc enthalpy at guessed P & current iter T h2 = this->H(ptAGA10, ptD) - h0 ; // calculate our proportional change delta1 = fabs(h1 - h2) / h0 ; // close enough? if (delta1 < tolerance && i > 0) break ; // revise our estimate to t2 t0 = t2 ; t2 = (t1 * h2 - t2 * h1) / (h2 - h1) ; // check if we've created an unrealistic temperature if (t2 >= tmax ) t2 = tmax ; // revise t2, if necessary if (t2 <= tmin ) { t2 = t0 + 10.0 ;
123
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. ptAGA10->dTf = t2 ; ptD->Run(ptAGA10) ; h2 = this->H(ptAGA10, ptD) - h0 ; } t1 = t0 ; h1 = h2 ;
}
} // check for failure to converge if (i >= MAX_NUM_OF_ITERATIONS) ptAGA10->lStatus = MAX_NUM_OF_ITERATIONS_EXCEEDED ; // Therm::HS_Mode()
/************************************************************************** * Function : Therm::H() * Arguments : AGA10STRUCT *, Detail * * Returns : double * Purpose : real gas specific enthalpy * Revisions : **************************************************************************/ double Therm::H(AGA10STRUCT *ptAGA10, Detail *ptD) { double Hinc ; double x ; int i ; // initialize integral Hinc = 0.0 ; // find ideal gas enthalpy ptAGA10->dHo = Ho(ptAGA10) ; // integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature for ( i= 0; i < GK_points; i++) { // calculate 1st and 2nd partial derivatives of Z wrt T x = ptAGA10->dDf * (1.0 + GK_root[i]) / 2.0 ; ptD->zdetail(x) ; ptD->dZdT(x) ;
124
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. ptD->d2ZdT2(x) ; Hinc += GK_weight[i] * ptD->ddZdT / x ; if (i == 10) break; x = ptAGA10->dDf * (1.0 - GK_root[i]) / 2.0 ; ptD->zdetail(x) ; ptD->dZdT(x) ; ptD->d2ZdT2(x) ; Hinc +=
GK_weight[i] * ptD->ddZdT / x ;
} ptD->zdetail(ptAGA10->dDf) ; ptD->dZdT(ptAGA10->dDf) ; ptD->d2ZdT2(ptAGA10->dDf) ; // calculate specific enthalpy ptAGA10->dH = ptAGA10->dHo + 1000.0 * RGAS * ptAGA10->dTf * (ptAGA10->dZf - 1.0 - ptAGA10->dTf * Hinc * 0.5 * ptAGA10->dDf) / ptAGA10->dMrx ; }
return(ptAGA10->dH) ; // Therm::H()
125
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************** * Function : Therm::S() * Arguments : AGA10STRUCT *, Detail * * Returns : double * Purpose : real gas specific entropy * Revisions : **************************************************************************/ double Therm::S(AGA10STRUCT *ptAGA10, Detail *ptD) { double Sinc ; double Smixing ; double x ; int i ; // initialize integral Sinc = 0.0 ; // initialize entropy of mixing Smixing = 0.0 ; // integrate partial derivatives from D=0 to D=D, applying Gauss-Kronrod quadrature for ( i= 0; i < GK_points; i++) { // calculate 1st and 2nd partial derivatives of Z wrt T x = ptAGA10->dDf * (1.0 + GK_root[i]) / 2.0 ; ptD->zdetail(x) ; ptD->dZdT(x) ; ptD->d2ZdT2(x) ; Sinc += GK_weight[i] * (ptD->dZ + ptAGA10 ->dTf * ptD->ddZdT - 1.0) / x ; if (i == 10) break; x = ptAGA10->dDf * (1.0 - GK_root[i]) / 2.0 ; ptD->zdetail(x) ; ptD->dZdT(x) ; ptD->d2ZdT2(x) ; Sinc +=
GK_weight[i] * (ptD->dZ + ptAGA10 ->dTf * ptD->ddZdT - 1.0) / x ;
}
126
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // reset Z and partial deivatives dZdT and d2ZdT2 ptD->zdetail(ptAGA10->dDf) ; ptD->dZdT(ptAGA10->dDf) ; ptD->d2ZdT2(ptAGA10->dDf) ; // find ideal gas entropy, but only if temperature or composition have changed if (ptAGA10->dTf != dTold || ptAGA10->dMrx != dMrxold) { dSi = So(ptAGA10) ; dTold = ptAGA10->dTf ; dMrxold = ptAGA10->dMrx ; } // calculate entropy of mixing for (i= 0; i< NUMBEROFCOMPONENTS; i++) { if (ptAGA10->adMixture[i]) Smixing += ptAGA10->adMixture[i] * log(ptAGA10->adMixture[i]) ; } Smixing *= RGAS ; // calculate specific entropy ptAGA10->dS = dSi – Smixing - 1000.0 * RGAS * (log(ptAGA10->dPf/101325.0) - log(ptAGA10->dZf) + Sinc * 0.5 * ptAGA10->dDf) / ptAGA10->dMrx ; }
return(ptAGA10->dS) ; // Therm::S()
127
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * * File : entry.cpp * Purpose : This file contains the startup code for aga10.dll * and is only required for Windows DLL creation. * Project : AGA10 DLL * Version : ver 1.7 2002.11.17 * Author : W.B. Peterson * Revisions: * Copyright (c) 2002 American Gas Association * **************************************************************************/ #include
128
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // // // // // //
File Description Version Author Revisions Copyright (c)
: script1.rc : resource script for aga10 dll : 1.7 2002.11.17 : W.B. Peterson : 2002 American Gas Association
//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 #ifndef _MAC ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,7,0,0 PRODUCTVERSION 1,7,0,0 FILEFLAGSMASK 0x3fL
129
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. #ifdef _DEBUG FILEFLAGS 0x21L #else FILEFLAGS 0x20L #endif FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "Comments", "Post-Ballot Version\0" VALUE "CompanyName", "American Gas Association\0" VALUE "FileDescription", "aga10\0" VALUE "FileVersion", "1, 7, 0, 0\0" VALUE "InternalName", "aga10\0" VALUE "LegalCopyright", "Copyright © 2002 American Gas Association\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "aga10.dll\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "AGA10.DLL\0" VALUE "ProductVersion", "1, 6, 0, 0\0" VALUE "SpecialBuild", "2002.11.17 Build\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END #endif
// !_MAC
#ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE
130
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif
// APSTUDIO_INVOKED
#endif // English (U.S.) resources /////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED
131
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. File Group #2
-
Example Windows Application
132
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * File : aga10win.h * De Descr scription ion : function ion pr proto ototypes and de defines for ag aga10win win.cpp * Version : 1.7 2002.11.17 * Author : W.B. Peterson * Revisions : * Copyright (c) 2002 American Gas Association **************************************************************************/ #ifndef _AGA10WIN_H #define _AGA10WIN_H #include
*/
133
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define
IDC_TB IDC_PF IDC_TF IDC_MRX IDC_ZB IDC_ZF IDC_FPV IDC_DB IDC_DF IDC_RHOB IDC_RHOF IDC_RD_IDEAL IDC_RD_REAL IDC_HO IDC_H IDC_S IDC_CPI IDC_CP IDC_CV IDC_K IDC_KAPPA IDC_SOS IDC_CSTAR IDC_PB_U IDC_TB_U IDC_PF_U IDC_TF_U IDC_SOS_U IDC_RHOB_U IDC_RHOF_U ID IDC_ENTHALPY_U IDC_ENTROPY_U IDC_TOTAL IDC_CLEAR IDC_NORMALIZE KILOPASCAL MEGAPASCAL PSI KELVIN CELSIUS
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
134
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define #define
RANKINE FAHRENHEIT KG KGPERCUBICMETRE LB LBMPERCUBICFOOT ME METREPERSECOND FOOTPERSECOND KJPERKG BTUPERLBM KJPERKGK BTUPERLBMF CM_FILEOPEN CM_FILESAVE CM_FILESAVEAS CM_HELPABOUT IDR_MENU1 IDC_STATIC
/* buffer sizes */ #define FIELD40 #define FIELD30
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 (-1) 40 30
/* function prototypes */ LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; void PressureDlgHelp(HWND) ; void TemperatureDlgHelp(HWND) ; void DensityDlgHelp(HWND) ; void SOSDlgHelp(HWND) ; void EnthalpyDlgHelp(HWND) ; void EntropyDlgHelp(HWND) ; void FileInitialize (HWND) ; BOOL FileOpenDlg (HWND, PSTR, PSTR) ; BOOL FileSaveDlg (HWND, PSTR, PSTR) ; #endif
135
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * File : aga10win.cpp * Description : Simple Win32 program demonstrating use of aga10.dll * Supports Windows dialog box and file operations * Version : 1.7 2002.11.17 * Author : W.B. Peterson * Revisions : * Copyright (c) 2002 American Gas Association **************************************************************************/ #include "aga10win.h" #include "aga10.h" /* create pointer to a data structure for exchanging data with aga10.dll static AGA10STRUCT *A10 ; /* global variables for strings, filenames, etc static char szAppName[] = "aga10win" ; static char szBuffer[FIELD40] ; char szFileName[_MAX_PATH] ; char szTitleName[_MAX_FNAME + _MAX_EXT] ;
*/
*/
/* declare one application instance */ HINSTANCE hInst ; /* global variables for units of measure and critical flow coefficient C* */ double total = 0.0 ; long int lPb_unit ; /* unit of measure for base pressure */ long int lPf_unit ; /* unit of measure for flowing pressure */ long int lTb_unit ; /* unit of measure for base temperature */ long int lTf_unit ; /* unit of measure for flowing temperature */ long int lRhob_unit ; /* unit of measure for density at base conditions */ long int lRhof_unit ; /* unit of measure for density at flowing conditions */ long int lSOS_unit ; /* unit of measure for speed of sound */ long int lEnthalpy_unit ; /* unit of measure for specific enthalpy */ long int lEntropy_unit ; /* unit of measure for specific entropy */ // prototypes for support functions not prototyped in aga10win.h bool FileRead(HWND, PSTR, AGA10STRUCT *); bool FileWrite(HWND, PSTR, AGA10STRUCT *) ;
136
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. void void void void
ReadInputs(HWND, AGA10STRUCT *) ; WriteInputs(HWND, AGA10STRUCT *) ; WriteOutputs(HWND, AGA10STRUCT *) ; SetDefaults(AGA10STRUCT *) ;
/************************************************************************** * Function : WinMain() * Arguments : HINSTANCE, HINSTANCE, PSTR, int * Returns : int * Purpose : Every Windows application has a WinMain() * Revisions : **************************************************************************/ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd ; MSG msg ; WNDCLASSEX wndclass ; /* set window class properties */ wndclass.cbSize = sizeof (wndclass) ; wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = WndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = DLGWINDOWEXTRA ; wndclass.hInstance = hInstance ; wndclass.hIcon = LoadIcon (hInstance, szAppName) ; wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; wndclass.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1) ; wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1) ; wndclass.lpszClassName = szAppName ; wndclass.hIconSm = LoadIcon (hInstance, szAppName) ; /* register the class */ RegisterClassEx (&wndclass) ; /* create a dialog box */ hWnd = CreateDialog (hInstance, "aga10win", 0, NULL) ;
137
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /* start the application's message pump */ while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage(&msg) ; DispatchMessage(&msg) ; } return msg.wParam ; } /************************************************************************** * Function : WndProc() * Arguments : HWND, UINT, WPARAM, LPARAM * Returns : LRESULT * Purpose : One and only window process for this app * Revisions : **************************************************************************/ LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { int i = 0 ; double temp ; switch (iMsg) { case WM_CREATE : /* get application instance */ hInst = ((LPCREATESTRUCT) lParam)->hInstance ; /* initialize file data */ FileInitialize (hwnd) ; /* initialize calculation library */ AGA10_Init() ; /* create an object at the pointer we have already defined */ if (NULL == (A10 = new AGA10STRUCT)) return TRUE ; /* set the defaults for this application */
138
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. SetDefaults(A10) ; return FALSE ; case WM_COMMAND : /* refresh the input data, triggered by focus change */ if (lParam && HIWORD (wParam) == EN_KILLFOCUS) { ReadInputs(hwnd, A10) ; WriteInputs(hwnd, A10) ; lstrcpy(szBuffer, "Press Calculate") ; SetDlgItemText (hwnd, IDC_LSTATUS, szBuffer) ; return FALSE ; } /* decode WM_COMMAND messages */ switch (LOWORD (wParam)) { case IDOK : /* refresh input fields */ ReadInputs(hwnd, A10) ; WriteInputs(hwnd, A10) ; // ensure the compositions adds up before proceeding // find the current sum of fractions temp = 0.0 ; for (i = 0 ; i < NUMBEROFCOMPONENTS ; i++) temp += A10->adMixture[i] ; if (temp < 0.9999 || temp > 1.0001) { MessageBox (hwnd,"Error. Composition must total 100%, +/- 0.01%", szAppName, MB_OK | MB_ICONERROR) ; lstrcpy(szBuffer, "Error. Composition <> 100%.") ; SetDlgItemText (hwnd, IDC_LSTATUS, szBuffer) ; return FALSE ; } // ensure the pressure is acceptable before proceeding if (A10->dPf < P_MIN || A10->dPf > P_MAX) { MessageBox (hwnd,"Error. Pf out of range.", szAppName, MB_OK | MB_ICONERROR) ;
139
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. lstrcpy(szBuffer, "Error. Pf out of range.") ; SetDlgItemText (hwnd, IDC_LSTATUS, szBuffer) ; return FALSE ; } // ensure the temperature is acceptable before proceeding if (A10->dTf < T_MIN || A10->dTf > T_MAX) { MessageBox (hwnd,"Error. Tf out of range.", szAppName, MB_OK | MB_ICONERROR) ; lstrcpy(szBuffer, "Error. Tf out of range.") ; SetDlgItemText (hwnd, IDC_LSTATUS, szBuffer) ; return FALSE ; } /* indicate that a calculation has begun */ lstrcpy(szBuffer, "Calculation In Progress") ; SetDlgItemText (hwnd, IDC_LSTATUS, szBuffer) ; /* run the sound speed AND C* calculation Crit(A10, 0.0) ;
*/
/* write the outputs to the dialog box */ WriteOutputs(hwnd, A10) ; return FALSE ; case IDC_CLEAR : /* zero out the composition and then display it */ for (i = 0 ; i < NUMBEROFCOMPONENTS ; i++) A10->adMixture[i] = 0.0 ; WriteInputs(hwnd, A10) ; return FALSE ; case IDC_NORMALIZE : // normalize the composition to equal 1.0000 ReadInputs(hwnd, A10) ; temp = 0.0 ; // find the current sum of fractions for (i = 0 ; i < NUMBEROFCOMPONENTS ; i++) temp += A10->adMixture[i] ; // adjust each non-zero entry by the required proportion for (i = 0 ; i < NUMBEROFCOMPONENTS ; i++)
140
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. if (A10->adMixture[i] > 0.0) A10->adMixture[i] /= temp ; // write the adjusted values to the screen WriteInputs(hwnd, A10) ; return FALSE ; case IDCANCEL : /* start tear-down process */ SendMessage(hwnd, WM_CLOSE, 0,0L) ; return FALSE ; case IDRETRY : // reset the defaults SetDefaults(A10) ; // display the input data to the screen WriteInputs(hwnd, A10) ; // send a message back to this proc, requesting a calculation SendMessage(hwnd, WM_COMMAND, IDOK,0L) ; return FALSE ; case CM_FILEOPEN : // standard Windows file operations GetFileTitle (szFileName, szTitleName, sizeof (szTitleName)) ; if (FileOpenDlg (hwnd, szFileName, szTitleName)) { if (!FileRead (hwnd, szFileName, A10)) { MessageBox(hwnd,"Could not read file.", szTitleName, MB_OK | MB_ICONSTOP) ; } } else return FALSE ; // Write the new values to the window WriteInputs(hwnd, A10) ; // send a message back to this proc, requesting a calculation SendMessage(hwnd, WM_COMMAND, IDOK,0L) ;
141
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. return FALSE
;
case CM_FILESAVE : // standard Windows file operations GetFileTitle (szFileName, szTitleName, sizeof (szTitleName)) ; if (szFileName[0]) { if (FileWrite(hwnd, szFileName, A10)) { return TRUE ; } else { MessageBox(hwnd,"Could not write file.", szTitleName, MB_OK | MB_ICONSTOP) ; } return FALSE ; } // fall through case CM_FILESAVEAS : // standard Windows file operations GetFileTitle (szFileName, szTitleName, sizeof (szTitleName)) ; if (FileSaveDlg (hwnd, szFileName, szTitleName)) { if (FileWrite (hwnd, szFileName, A10)) { return 1 ; } else { MessageBox(hwnd,"Could not write file.", szTitleName, MB_OK | MB_ICONSTOP) ; } } return FALSE ; case CM_HELPABOUT : MessageBox (hwnd,
142
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. "AGA10win.exe and AGA10.dll (c) American Gas Association, 2002", szAppName, MB_OK | MB_ICONINFORMATION) ; return FALSE ; } return FALSE ; case WM_CLOSE : /* un-initialize the calculation library */ AGA10_UnInit() ; // remove the AGA10STRUCT object from memory delete A10 ; /* request Windows to terminate the app */ DestroyWindow (hwnd) ; return FALSE ; case WM_DESTROY : /* final message exhange with Windows during shut-down */ PostQuitMessage (0) ; return FALSE ; } return DefWindowProc (hwnd, iMsg, wParam, lParam) ; }
143
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * File : file.cpp * Description : Supports file access to AGA10 functions * Author : W.B. Peterson * Version : 1.7 2002.11.17 * Revisions : * Copyright (c) 2002 American Gas Association **************************************************************************/ #include "aga10.h" // declare a Windows-defined structure for file names static OPENFILENAME ofn ; /************************************************************************** * Function : FileInitialize() * Arguments : HWND * Returns : void * Purpose : Prepares for Windows file access * Revisions : **************************************************************************/ void FileInitialize (HWND hWnd) { /* set file filters; assign the filename extension 'sos' for files of this type */ static char szFilter[] = "AGA10 Files (*.sos)\0*.sos\0" ; static char szExt[] = "sos" ; // populate a OPENFILENAME structure ofn.lStructSize = sizeof (OPENFILENAME) ofn.hwndOwner = hWnd ; ofn.hInstance = NULL ; ofn.lpstrFilter = szFilter ; ofn.lpstrCustomFilter = NULL ; ofn.nMaxCustFilter = 0 ; ofn.nFilterIndex = 0 ; ofn.lpstrFile = NULL ; ofn.nMaxFile = _MAX_PATH ; ofn.lpstrFileTitle = NULL ;
;
144
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. ofn.nMaxFileTitle ofn.lpstrInitialDir ofn.lpstrTitle ofn.Flags ofn.nFileOffset ofn.nFileExtension ofn.lpstrDefExt ofn.lCustData ofn.lpfnHook ofn.lpTemplateName
= = = = = = = = = =
_MAX_FNAME + _MAX_EXT NULL ; NULL ; 0 ; 0 ; 0 ; szExt ; 0L ; NULL ; NULL ;
;
} /************************************************************************** * Function : FileOpenDlg() * Arguments : HWND, PSTR, PSTR * Returns : BOOL * Purpose : Access common controls for file-open operation * Revisions : **************************************************************************/ BOOL FileOpenDlg (HWND hWnd, PSTR pstrFileName, PSTR pstrTitleName) { ofn.hwndOwner = hWnd ; ofn.lpstrFile = pstrFileName ; ofn.lpstrFileTitle = pstrTitleName ; ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ; return GetOpenFileName (&ofn)
;
}
/************************************************************************** * Function : FileSaveDlg() * Arguments : HWND, PSTR, PSTR * Returns : BOOL * Purpose : Access common controls for file-save operation * Revisions : **************************************************************************/
145
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. BOOL FileSaveDlg (HWND hWnd, PSTR pstrFileName, PSTR pstrTitleName) { ofn.hwndOwner = hWnd ; ofn.lpstrFile = pstrFileName ; ofn.lpstrFileTitle = pstrTitleName ; ofn.Flags = OFN_OVERWRITEPROMPT ; return GetSaveFileName (&ofn)
;
}
/************************************************************************** * Function : FileRead() * Arguments : HWND, PSTR, AGA10STRUCT * Returns : bool * Purpose : Reads contents of a .sos file into a AGA10STRUCT * Revisions : **************************************************************************/ bool FileRead(HWND hWnd, PSTR pstrFileName, AGA10STRUCT *A10) { FILE *file ; // open the file in binary mode, if it exists if (NULL == (file = fopen (pstrFileName, "rb"))) return false ; // set file position to beginning rewind(file) ; // read one (only) data structure if (fread(A10, sizeof (AGA10STRUCT), 1, file)) { fclose (file) ; return true; } else { // some problem encountered
146
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. fclose (file) ; return false ; } } /************************************************************************** * Function : FileWrite() * Arguments : HWND, PSTR, AGA10STRUCT * Returns : bool * Purpose : Writes contents of a AGA10STRUCT into a .vos file * Revisions : **************************************************************************/ bool FileWrite(HWND hWnd, PSTR pstrFileName, AGA10STRUCT *A10) { FILE *file ; // open the file in binary mode; create if necessary if (NULL == (file = fopen (pstrFileName, "wb"))) return false ; // set file position to beginning rewind(file) ; // write one (only) data structure if (fwrite(A10, sizeof (AGA10STRUCT), 1, file)) { fclose (file) ; return true; } else { // problem encountered; close and return 'false' fclose (file) ; return false ; } }
147
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. /************************************************************************* * File : dlghlp.cpp * Description : Helper functions for aga10win main dialog box * Version : 1.7 2002.11.17 * Author : W.B. Peterson * Revisions : * Copyright (c) 2002 American Gas Association **************************************************************************/ #include "aga10win.h" #include "aga10.h" /* variables declared externally */ extern HINSTANCE hInst ; extern double total ; extern long int lPb_unit ; extern long int lPf_unit ; extern long int lTb_unit ; extern long int lTf_unit ; extern long int lRhob_unit ; extern long int lRhof_unit ; extern long int lSOS_unit ; extern long int lEnthalpy_unit ; extern long int lEntropy_unit ; /* a local buffer for text strings */ static char szBuffer[FIELD40] ; /************************************************************************** * Function : WriteInputs() * Arguments : HWND * Returns : void * Purpose : Function for writing the input fields of the main window * Notes : Uses non-portable, run-time library function _gcvt() * for converting strings to double precision floats. * Revisions : **************************************************************************/ void WriteInputs(HWND hDlg, AGA10STRUCT *A10) {
148
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. HWND hListBox; int i ; double Pbx, Tbx, Pfx, Tfx ; /* calculate Pb in specified unit of measure */ switch (lPb_unit) { case KILOPASCAL : Pbx = A10->dPb * 1.0e-3 ; break ; case MEGAPASCAL : Pbx = A10->dPb * 1.0e-6 ; break ; case PSI : Pbx = A10->dPb / 6894.75729 ; } /* calculate Pf in specified unit of measure */ switch (lPf_unit) { case KILOPASCAL : Pfx = A10->dPf * 1.0e-3 ; break ; case MEGAPASCAL : Pfx = A10->dPf * 1.0e-6 ; break ; case PSI : Pfx = A10->dPf / 6894.75729 ; } /* calculate Tb in specified unit of measure */ switch (lTb_unit) { case CELSIUS : Tbx = A10->dTb - 273.15 ; break ;
149
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. case FAHRENHEIT : Tbx = (A10->dTb * 1.8) - 459.67 ; break ; case KELVIN : Tbx = A10->dTb ; break ; case RANKINE : Tbx = A10->dTb * 1.8 ; } /* calculate Tf in specified unit of measure */ switch (lTf_unit) { case CELSIUS : Tfx = A10->dTf - 273.15 ; break ; case FAHRENHEIT : Tfx = (A10->dTf * 1.8) - 459.67 ; break ; case KELVIN : Tfx = A10->dTf ; break ; case RANKINE : Tfx = A10->dTf * 1.8 ; } // Pb _gcvt (Pbx, 9, SetDlgItemText // Tb _gcvt (Tbx, 9, SetDlgItemText // Pf _gcvt (Pfx, 9,
szBuffer); (hDlg, IDC_PB, szBuffer) ; szBuffer); (hDlg, IDC_TB, szBuffer) ; szBuffer);
150
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. SetDlgItemText (hDlg, IDC_PF, szBuffer) ; // Tf _gcvt (Tfx, 9, szBuffer); SetDlgItemText (hDlg, IDC_TF, szBuffer) ; // composition _gcvt (A10->adMixture[XiC1] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIC1, szBuffer) ; _gcvt (A10->adMixture[XiN2] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIN2, szBuffer) ; _gcvt (A10->adMixture[XiCO2] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XICO2, szBuffer) ; _gcvt (A10->adMixture[XiC2] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIC2, szBuffer) ; _gcvt (A10->adMixture[XiC3] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIC3, szBuffer) ; _gcvt (A10->adMixture[XiH2O] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIH2O, szBuffer) ; _gcvt (A10->adMixture[XiH2S] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIH2S, szBuffer) ; _gcvt (A10->adMixture[XiH2] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIH2, szBuffer) ; _gcvt (A10->adMixture[XiCO] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XICO, szBuffer) ; _gcvt (A10->adMixture[XiO2] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIO2, szBuffer) ; _gcvt (A10->adMixture[XiIC4] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIIC4, szBuffer) ; _gcvt (A10->adMixture[XiNC4] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XINC4, szBuffer) ; _gcvt (A10->adMixture[XiIC5] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIIC5, szBuffer) ; _gcvt (A10->adMixture[XiNC5] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XINC5, szBuffer) ; _gcvt (A10->adMixture[XiNC6] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XINC6, szBuffer) ; _gcvt (A10->adMixture[XiNC7] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XINC7, szBuffer) ; _gcvt (A10->adMixture[XiNC8] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XINC8, szBuffer) ; _gcvt (A10->adMixture[XiNC9] * 100.0, 9, szBuffer);
151
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. SetDlgItemText (hDlg, IDC_XINC9, szBuffer) ; _gcvt (A10->adMixture[XiNC10] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XINC10, szBuffer) ; _gcvt (A10->adMixture[XiHe] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIHE, szBuffer) ; _gcvt (A10->adMixture[XiAr] * 100.0, 9, szBuffer); SetDlgItemText (hDlg, IDC_XIAR, szBuffer) ; for (i=0, total = 0.0 ; i
152
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. SendMessage(hListBox, CB_SELECTSTRING, -1,(LONG)(LPSTR)szBuffer) ; hListBox = GetDlgItem(hDlg, IDC_SOS_U) ; if (!SendMessage(hListBox, CB_GETCOUNT, 0,0)) SOSDlgHelp(hListBox) ; LoadString(hInst, lSOS_unit, szBuffer, FIELD40) ; SendMessage(hListBox, CB_SELECTSTRING, -1,(LONG)(LPSTR)szBuffer) ; hListBox = GetDlgItem(hDlg, IDC_ENTHALPY_U) ; if (!SendMessage(hListBox, CB_GETCOUNT, 0,0)) EnthalpyDlgHelp(hListBox) ; LoadString(hInst, lEnthalpy_unit, szBuffer, FIELD40) ; SendMessage(hListBox, CB_SELECTSTRING, -1,(LONG)(LPSTR)szBuffer) ; hListBox = GetDlgItem(hDlg, IDC_ENTROPY_U) ; if (!SendMessage(hListBox, CB_GETCOUNT, 0,0)) EntropyDlgHelp(hListBox) ; LoadString(hInst, lEntropy_unit, szBuffer, FIELD40) ; SendMessage(hListBox, CB_SELECTSTRING, -1,(LONG)(LPSTR)szBuffer) ; } /************************************************************************** * Function : WriteInputs() * Arguments : HWND * Returns : void * Purpose : Function for writing the input fields of the main window * Notes : Uses non-portable, run-time library function _gcvt() * for converting strings to double precision floats. * Revisions : **************************************************************************/ void WriteOutputs(HWND hDlg, AGA10STRUCT *A10) { double Rhofx, SOSx, Enthalpyx, Entropyx ; /* calculate Rhof in specified unit of measure switch (lRhof_unit) { case KGPERCUBICMETRE : Rhofx = A10->dRhof ; break ; case LBMPERCUBICFOOT :
153
*/
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. Rhofx = (A10->dRhof
/ 0.45359237) * pow(0.3048, 3.0)
;
} /* calculate SOS in specified unit of measure switch (lSOS_unit) { case METREPERSECOND : SOSx = A10->dSOS ; break ; case FOOTPERSECOND : SOSx = A10->dSOS / 0.3048
*/
;
} /* calculate specific enthalpy in specified unit of measure switch (lEnthalpy_unit) { case KJPERKG : Enthalpyx = A10->dH * 0.001 ; break ;
*/
case BTUPERLBM : Enthalpyx = A10->dH / ((5000./9.) * 4.1868) ; } /* calculate specific entropy in specified unit of measure switch (lEntropy_unit) { case KJPERKGK : Entropyx = A10->dS * 0.001 ; break ; case BTUPERLBMF : Entropyx = A10->dS / (1.0e3 * 4.1868)
;
} /* write the outputs to the window */ _gcvt (Rhofx, 9, szBuffer); SetDlgItemText (hDlg, IDC_RHOF, szBuffer) ;
154
*/
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. _gcvt (SOSx, 9, szBuffer); SetDlgItemText (hDlg, IDC_SOS, szBuffer) ; _gcvt (A10->dZb, 9, szBuffer); SetDlgItemText (hDlg, IDC_ZB, szBuffer) ; _gcvt (A10->dZf, 9, szBuffer); SetDlgItemText (hDlg, IDC_ZF, szBuffer) ; _gcvt (A10->dFpv, 9, szBuffer); SetDlgItemText (hDlg, IDC_FPV, szBuffer) ; _gcvt (A10->dDf, 9, szBuffer); SetDlgItemText (hDlg, IDC_DF, szBuffer) ; _gcvt (A10->dRD_Ideal, 9, szBuffer); SetDlgItemText (hDlg, IDC_RD_IDEAL, szBuffer) ; _gcvt (A10->dRD_Real, 9, szBuffer); SetDlgItemText (hDlg, IDC_RD_REAL, szBuffer) ; _gcvt (A10->dMrx, 9, szBuffer); SetDlgItemText (hDlg, IDC_MRX, szBuffer) ; _gcvt (A10->dCpi * 0.001, 9, szBuffer); SetDlgItemText (hDlg, IDC_CPI, szBuffer) ; _gcvt (A10->dCp * 0.001, 9, szBuffer); SetDlgItemText (hDlg, IDC_CP, szBuffer) ; _gcvt (A10->dCv * 0.001, 9, szBuffer); SetDlgItemText (hDlg, IDC_CV, szBuffer) ; _gcvt (A10->dk, 9, szBuffer); SetDlgItemText (hDlg, IDC_K, szBuffer) ; _gcvt (A10->dKappa, 9, szBuffer); SetDlgItemText (hDlg, IDC_KAPPA, szBuffer) ; _gcvt (A10->dHo * 0.001, 9, szBuffer);
155
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. SetDlgItemText (hDlg, IDC_HO, szBuffer) ; _gcvt (Enthalpyx, 9, szBuffer); SetDlgItemText (hDlg, IDC_H, szBuffer) ; _gcvt (Entropyx, 9, szBuffer); SetDlgItemText (hDlg, IDC_S, szBuffer) ; // reality check included for C* if (A10->dCstar > 0.3 && A10->dCstar < 1.3) { _gcvt (A10->dCstar, 9, szBuffer); SetDlgItemText (hDlg, IDC_CSTAR, szBuffer) ; } else { lstrcpy(szBuffer, "Cannot Solve!") ; SetDlgItemText (hDlg, IDC_CSTAR, szBuffer) ; } /* update status indicator, based on return codes if (A10->lStatus == 9000) { lstrcpy(szBuffer, "Calculation Completed") ; SetDlgItemText (hDlg, IDC_LSTATUS, szBuffer) ; } else { _ltoa (A10->lStatus, szBuffer, 10); SetDlgItemText (hDlg, IDC_LSTATUS, szBuffer) ; }
*/
} /************************************************************************** * Function : ReadInputs() * Arguments : HWND * Returns : void * Purpose : Function for reading the input fields of the main window * Revisions : **************************************************************************/
156
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. void ReadInputs(HWND hDlg, AGA10STRUCT *A10) { HWND hListBox; int iSelection; int i ; char * stopstr; //Pb GetDlgItemText(hDlg, IDC_PB, szBuffer, FIELD30) ; hListBox = GetDlgItem(hDlg, IDC_PB_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lPb_unit = KILOPASCAL ; A10->dPb = strtod(szBuffer, &stopstr) * 1.0e3 ; break ; case 1 : lPb_unit = MEGAPASCAL ; A10->dPb = strtod(szBuffer, &stopstr) * 1.0e6 ; break ; case 2 : lPb_unit = PSI ; A10->dPb = strtod(szBuffer, &stopstr) * 6894.75729 ; } //Pf GetDlgItemText(hDlg, IDC_PF, szBuffer, FIELD30) ; hListBox = GetDlgItem(hDlg, IDC_PF_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lPf_unit = KILOPASCAL ; A10->dPf = strtod(szBuffer, &stopstr) * 1.0e3 ; break ; case 1 : lPf_unit = MEGAPASCAL ; A10->dPf = strtod(szBuffer, &stopstr) * 1.0e6 ;
157
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. break ; case 2 : lPf_unit = PSI ; A10->dPf = strtod(szBuffer, &stopstr) * 6894.75729 ; } //Tb GetDlgItemText(hDlg, IDC_TB, szBuffer, FIELD30) ; hListBox = GetDlgItem(hDlg, IDC_TB_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lTb_unit = CELSIUS ; A10->dTb = strtod(szBuffer, &stopstr) + 273.15; break ; case 1 : lTb_unit = FAHRENHEIT ; A10->dTb = (strtod(szBuffer, &stopstr) + 459.67) / 1.8 ; break ; case 2 : lTb_unit = KELVIN ; A10->dTb = strtod(szBuffer, &stopstr) ; break ; case 3 : lTb_unit = RANKINE ; A10->dTb = strtod(szBuffer, &stopstr) / 1.8; } //Tf GetDlgItemText(hDlg, IDC_TF, szBuffer, FIELD30) ; hListBox = GetDlgItem(hDlg, IDC_TF_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lTf_unit = CELSIUS ; A10->dTf = strtod(szBuffer, &stopstr) + 273.15; break ;
158
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. case 1 : lTf_unit A10->dTf break ; case 2 : lTf_unit A10->dTf break ; case 3 : lTf_unit A10->dTf
= FAHRENHEIT ; = (strtod(szBuffer, &stopstr) + 459.67) / 1.8 ; = KELVIN ; = strtod(szBuffer, &stopstr) ; = RANKINE ; = strtod(szBuffer, &stopstr) / 1.8;
} //Rhof hListBox = GetDlgItem(hDlg, IDC_RHOF_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lRhof_unit = KGPERCUBICMETRE ; break ; case 1 : lRhof_unit = LBMPERCUBICFOOT ; } //SOS hListBox = GetDlgItem(hDlg, IDC_SOS_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lSOS_unit = METREPERSECOND ; break ; case 1 : lSOS_unit = FOOTPERSECOND ; } //Enthalpy hListBox = GetDlgItem(hDlg, IDC_ENTHALPY_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ;
159
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. switch (iSelection) { case 0 : lEnthalpy_unit = KJPERKG ; break ; case 1 : lEnthalpy_unit = BTUPERLBM ; } //Entropy hListBox = GetDlgItem(hDlg, IDC_ENTROPY_U) ; iSelection = SendMessage(hListBox, CB_GETCURSEL, 0,0) ; switch (iSelection) { case 0 : lEntropy_unit = KJPERKGK ; break ; case 1 : lEntropy_unit = BTUPERLBMF ; } // composition GetDlgItemText(hDlg,IDC_XIC1, szBuffer, FIELD30) ; A10->adMixture[XiC1] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIN2, szBuffer, FIELD30) ; A10->adMixture[XiN2] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XICO2, szBuffer, FIELD30) ; A10->adMixture[XiCO2] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIC2, szBuffer, FIELD30) ; A10->adMixture[XiC2] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIC3, szBuffer, FIELD30) ; A10->adMixture[XiC3] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIH2O, szBuffer, FIELD30) ; A10->adMixture[XiH2O] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIH2S, szBuffer, FIELD30) ; A10->adMixture[XiH2S] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIH2, szBuffer, FIELD30) ; A10->adMixture[XiH2] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XICO, szBuffer, FIELD30) ; A10->adMixture[XiCO] = strtod(szBuffer, &stopstr) * 0.01 ;
160
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. GetDlgItemText(hDlg,IDC_XIO2, szBuffer, FIELD30) ; A10->adMixture[XiO2] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIIC4, szBuffer, FIELD30) ; A10->adMixture[XiIC4] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC4, szBuffer, FIELD30) ; A10->adMixture[XiNC4] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIIC5, szBuffer, FIELD30) ; A10->adMixture[XiIC5] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC5, szBuffer, FIELD30) ; A10->adMixture[XiNC5] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC6, szBuffer, FIELD30) ; A10->adMixture[XiNC6] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC7, szBuffer, FIELD30) ; A10->adMixture[XiNC7] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC8, szBuffer, FIELD30) ; A10->adMixture[XiNC8] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC9, szBuffer, FIELD30) ; A10->adMixture[XiNC9] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XINC10, szBuffer, FIELD30) ; A10->adMixture[XiNC10] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIHE, szBuffer, FIELD30) ; A10->adMixture[XiHe] = strtod(szBuffer, &stopstr) * 0.01 ; GetDlgItemText(hDlg,IDC_XIAR, szBuffer, FIELD30) ; A10->adMixture[XiAr] = strtod(szBuffer, &stopstr) * 0.01 ; // sum up the mole fractions for (i=0,total = 0.0; i
161
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. void PressureDlgHelp(HWND hListBox) { LoadString(hInst, KILOPASCAL, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 0, (LONG)(LPSTR) szBuffer) ; LoadString(hInst, MEGAPASCAL, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 1, (LONG)(LPSTR) szBuffer) ; LoadString(hInst, PSI, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 2, (LONG)(LPSTR) szBuffer) ; } /************************************************************************** * Function : TemperatureDlgHelp() * Arguments : HWND * Returns : void * Purpose : Helper function for loading strings into temperature * drop-list controls * Revisions : **************************************************************************/ void TemperatureDlgHelp(HWND hListBox) { LoadString(hInst, CELSIUS, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 0, (LONG)(LPSTR) LoadString(hInst, FAHRENHEIT, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 1, (LONG)(LPSTR) LoadString(hInst, KELVIN, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 2, (LONG)(LPSTR) LoadString(hInst, RANKINE, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 3, (LONG)(LPSTR) }
szBuffer) ; szBuffer) ; szBuffer) ; szBuffer) ;
/************************************************************************** * Function : DensityDlgHelp() * Arguments : HWND * Returns : void * Purpose : Helper function for loading strings into density * drop-list controls
162
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. * Revisions : **************************************************************************/ void DensityDlgHelp(HWND hListBox) { LoadString(hInst, KGPERCUBICMETRE, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 0, (LONG)(LPSTR) szBuffer) ; LoadString(hInst, LBMPERCUBICFOOT, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 1, (LONG)(LPSTR) szBuffer) ; } /************************************************************************** * Function : SOSDlgHelp() * Arguments : HWND * Returns : void * Purpose : Helper function for loading strings into SOS * drop-list controls * Revisions : **************************************************************************/ void SOSDlgHelp(HWND hListBox) { LoadString(hInst, METREPERSECOND, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 0, (LONG)(LPSTR) szBuffer) ; LoadString(hInst, FOOTPERSECOND, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 1, (LONG)(LPSTR) szBuffer) ; } /************************************************************************** * Function : EnthalpyDlgHelp() * Arguments : HWND * Returns : void * Purpose : Helper function for loading strings into enthalpy * drop-list controls * Revisions : **************************************************************************/ void EnthalpyDlgHelp(HWND hListBox)
163
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. { LoadString(hInst, KJPERKG, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 0, (LONG)(LPSTR) szBuffer) ; LoadString(hInst, BTUPERLBM, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 1, (LONG)(LPSTR) szBuffer) ; } /************************************************************************** * Function : EntropyDlgHelp() * Arguments : HWND * Returns : void * Purpose : Helper function for loading strings into entropy * drop-list controls * Revisions : **************************************************************************/ void EntropyDlgHelp(HWND hListBox) { LoadString(hInst, KJPERKGK, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 0, (LONG)(LPSTR) szBuffer) ; LoadString(hInst, BTUPERLBMF, szBuffer, FIELD40) ; SendMessage(hListBox, CB_INSERTSTRING, 1, (LONG)(LPSTR) szBuffer) ; } /************************************************************************** * Function : SetDefaults() * Arguments : void * Returns : void * Purpose : initializes AGA10STRUCT and units of measure * Revisions : **************************************************************************/ void SetDefaults(AGA10STRUCT *A10) { A10->lStatus = 9000 ; A10->bForceUpdate = true; A10->dPb = 101325.0 ; A10->dTb = 288.15; A10->dPf = 4000000.0 ; A10->dTf = 283.15;
/* /* /* /* /* /*
9000 is status code for 'ok' */ ensures that full calculation is performed */ 1 atm */ 15 C */ 4 MPa */ 10 C */
164
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. A10->adMixture[XiC1] = 0.906724; A10->adMixture[XiN2] = 0.031284; A10->adMixture[XiCO2] = 0.004676; A10->adMixture[XiC2] = 0.045279; A10->adMixture[XiC3] = 0.00828; A10->adMixture[XiH2O] = 0.0; A10->adMixture[XiH2S] = 0.0; A10->adMixture[XiH2] = 0.0; A10->adMixture[XiCO] = 0.0; A10->adMixture[XiO2] = 0.0; A10->adMixture[XiIC4] = 0.001037; A10->adMixture[XiNC4] = 0.001563; A10->adMixture[XiIC5] = 0.000321; A10->adMixture[XiNC5] = 0.000443; A10->adMixture[XiNC6] = 0.000393; A10->adMixture[XiNC7] = 0.0; A10->adMixture[XiNC8] = 0.0; A10->adMixture[XiNC9] = 0.0; A10->adMixture[XiNC10] = 0.0; A10->adMixture[XiHe] = 0.0; A10->adMixture[XiAr] = 0.0;
/* AMARILLO example composition...*/
/* reset units of measure */ lPb_unit = KILOPASCAL ; lPf_unit = KILOPASCAL ; lTb_unit = CELSIUS ; lTf_unit = CELSIUS ; lRhob_unit = KGPERCUBICMETRE ; lRhof_unit = KGPERCUBICMETRE ; lSOS_unit = METREPERSECOND ; lEnthalpy_unit = KJPERKG ; lEntropy_unit = KJPERKGK ; }
165
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // // // // // //
File Description Version Author Revisions Copyright (c)
: resource.h : header file used for Windows resource file : 1.7 2002.11.17 : W.B. Peterson : 2002 American Gas Association
//{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by aga10win.rc // // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC #define _APS_NEXT_RESOURCE_VALUE #define _APS_NEXT_COMMAND_VALUE #define _APS_NEXT_CONTROL_VALUE #define _APS_NEXT_SYMED_VALUE #endif #endif
1 105 40003 1018 101
166
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. // // // // // //
File Description Version Author Revisions Copyright (c)
: aga10win.rc : resource script for aga10win’s interface : 1.7 2002.11.17 : W.B. Peterson : 2002 American Gas Association
//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #define APSTUDIO_HIDDEN_SYMBOLS #include "windows.h" #undef APSTUDIO_HIDDEN_SYMBOLS #include "aga10win.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // English (U.S.) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) #ifdef _WIN32 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US #pragma code_page(1252) #endif //_WIN32 ///////////////////////////////////////////////////////////////////////////// // // Icon // // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems.
167
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. AGA10WIN
ICON
DISCARDABLE
"aga10win.ico"
///////////////////////////////////////////////////////////////////////////// // // Dialog // AGA10WIN DIALOGEX 0, 0, 575, 315 STYLE DS_3DLOOK | WS_MINIMIZEBOX | WS_VISIBLE | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_CLIENTEDGE | WS_EX_CONTROLPARENT CAPTION "AGA 10 Example Program" MENU IDR_MENU1 CLASS "aga10win" FONT 8, "MS Sans Serif" BEGIN EDITTEXT IDC_XIHE,55,15,44,14,ES_AUTOHSCROLL | WS_GROUP EDITTEXT IDC_XIH2,55,33,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIN2,55,51,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XICO2,55,69,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIH2S,55,87,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIC1,55,105,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIC2,55,123,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIC3,153,16,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIIC4,153,34,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC4,153,52,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIIC5,153,70,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC5,154,89,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC6,154,107,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC7,154,125,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC8,259,16,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC9,259,34,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XINC10,259,52,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIAR,259,70,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIH2O,259,88,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XICO,259,106,44,14,ES_AUTOHSCROLL EDITTEXT IDC_XIO2,259,124,44,14 PUSHBUTTON "Clear Mixture",IDC_CLEAR,47,149,60,20 EDITTEXT IDC_PB,34,196,60,14,ES_AUTOHSCROLL COMBOBOX IDC_PB_U,98,197,60,44,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
168
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. EDITTEXT COMBOBOX EDITTEXT COMBOBOX EDITTEXT COMBOBOX DEFPUSHBUTTON PUSHBUTTON PUSHBUTTON GROUPBOX LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT GROUPBOX LTEXT
IDC_TB,34,215,60,14,ES_AUTOHSCROLL IDC_TB_U,98,216,60,44,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP IDC_PF,191,196,60,14,ES_AUTOHSCROLL IDC_PF_U,254,196,60,44,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP IDC_TF,191,215,60,14,ES_AUTOHSCROLL IDC_TF_U,255,215,60,44,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP "Calculate",IDOK,137,282,50,20 "Initialize",IDRETRY,61,282,50,20 "Quit",IDCANCEL,213,282,50,20,WS_GROUP "Composition (Mole Percent)",IDC_STATIC,5,3,322,175 "Helium",IDC_STATIC,21,18,28,8,NOT WS_GROUP "Hydrogen",IDC_STATIC,21,36,32,8,NOT WS_GROUP "Nitrogen",IDC_STATIC,21,55,28,8,NOT WS_GROUP "CO2",IDC_STATIC,22,71,15,8,NOT WS_GROUP "H2S",IDC_STATIC,22,89,15,8,NOT WS_GROUP "Methane",IDC_STATIC,22,108,29,8,NOT WS_GROUP "Ethane",IDC_STATIC,22,126,24,8,NOT WS_GROUP "Propane",IDC_STATIC,116,18,28,8,NOT WS_GROUP "i-Butane",IDC_STATIC,116,37,27,8,NOT WS_GROUP "n-Butane",IDC_STATIC,116,55,30,8,NOT WS_GROUP "i-Pentane",IDC_STATIC,116,72,31,8,NOT WS_GROUP "n-Pentane",IDC_STATIC,115,92,34,8,NOT WS_GROUP "n-Hexane",IDC_STATIC,115,110,32,8,NOT WS_GROUP "n-Heptane",IDC_STATIC,115,128,34,8,NOT WS_GROUP "n-Octane",IDC_STATIC,218,19,30,8,NOT WS_GROUP "n-Nonane",IDC_STATIC,218,37,32,8,NOT WS_GROUP "n-Decane",IDC_STATIC,218,55,32,8,NOT WS_GROUP "Argon",IDC_STATIC,219,73,27,8,NOT WS_GROUP "Water",IDC_STATIC,219,91,23,8,NOT WS_GROUP "CO",IDC_STATIC,219,109,11,8,NOT WS_GROUP "O2",IDC_STATIC,219,128,24,8,NOT WS_GROUP "TOTAL",IDC_STATIC,218,147,24,8,NOT WS_GROUP "Static",IDC_TOTAL,259,146,44,12,SS_SUNKEN | NOT WS_GROUP "Gas Temperature and Absolute Pressure",IDC_STATIC,6,182, 322,56 "Pb",IDC_STATIC,12,199,10,8
169
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. LTEXT LTEXT LTEXT GROUPBOX LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT
"Tb",IDC_STATIC,11,217,10,8 "Pf",IDC_STATIC,177,199,8,8 "Tf",IDC_STATIC,176,217,8,8 "Calculation Results",IDC_STATIC,334,3,234,306 "Speed of Sound",IDC_STATIC,348,24,52,8 "Zf",IDC_STATIC,348,173,8,8 "Zb",IDC_STATIC,348,158,10,8 "Fpv",IDC_STATIC,348,187,13,8 "Cp (real gas)",IDC_STATIC,348,232,40,8 "Cv (real gas)",IDC_STATIC,348,248,40,8 "Cp/Cv",IDC_STATIC,348,264,22,8 "Isentropic Exponent",IDC_STATIC,348,53,67,8 "Mass Density",IDC_STATIC,348,113,43,8 "Molar Density",IDC_STATIC,348,98,44,8 "Specific Enthalpy",IDC_STATIC,348,68,56,8 "Specific Entropy",IDC_STATIC,348,83,52,8 "Enthalpy (ideal gas)",IDC_STATIC,348,280,62,8 "Cp (ideal gas)",IDC_STATIC,348,216,44,8 "Molar Mass",IDC_STATIC,348,201,37,8 "0",IDC_SOS,422,24,50,8,NOT WS_GROUP "0",IDC_H,422,69,50,8,NOT WS_GROUP "0",IDC_S,422,83,50,8,NOT WS_GROUP "0",IDC_DF,422,99,60,8,NOT WS_GROUP "0",IDC_RHOF,422,113,55,8,NOT WS_GROUP "0",IDC_ZB,422,157,50,8,NOT WS_GROUP "0",IDC_ZF,422,171,50,8,NOT WS_GROUP "0",IDC_FPV,422,186,50,8,NOT WS_GROUP "0",IDC_MRX,422,201,50,8,NOT WS_GROUP "0",IDC_CPI,422,216,50,8,NOT WS_GROUP "0",IDC_HO,422,280,50,8,NOT WS_GROUP "0",IDC_CP,422,232,50,8,NOT WS_GROUP "0",IDC_CV,422,248,50,8,NOT WS_GROUP "0",IDC_K,422,264,50,8,NOT WS_GROUP "0",IDC_KAPPA,422,53,50,8,NOT WS_GROUP "moles/dm3",IDC_STATIC,483,98,32,8 "kJ/kg-K",IDC_STATIC,483,216,26,8 "kJ/kg",IDC_STATIC,483,280,20,8 "RD (ideal gas)",IDC_STATIC,348,128,46,8 "RD (real gas)",IDC_STATIC,348,143,42,8 "0",IDC_RD_IDEAL,422,128,50,8,NOT WS_GROUP
170
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. LTEXT LTEXT LTEXT LTEXT LTEXT LTEXT COMBOBOX COMBOBOX COMBOBOX COMBOBOX GROUPBOX PUSHBUTTON
"0",IDC_RD_REAL,422,143,50,8,NOT WS_GROUP "Press Initialize Button to Begin",IDC_LSTATUS,106,259, 107,8 "kJ/kg-K",IDC_STATIC,483,232,26,8 "kJ/kg-K",IDC_STATIC,483,248,26,8 "C*",IDC_STATIC,348,39,10,8 "0",IDC_CSTAR,422,39,58,8 IDC_SOS_U,482,21,80,43,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP IDC_RHOF_U,482,111,80,44,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP IDC_ENTHALPY_U,482,66,80,40,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP IDC_ENTROPY_U,482,82,80,37,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP "Current Status",IDC_STATIC,5,247,322,27 "Normalize",IDC_NORMALIZE,118,149,60,20
END #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" "#include ""windows.h""\r\n" "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" "#include ""aga10win.h""\r\n" "\0" END
171
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif
// APSTUDIO_INVOKED
///////////////////////////////////////////////////////////////////////////// // // DESIGNINFO // #ifdef APSTUDIO_INVOKED GUIDELINES DESIGNINFO DISCARDABLE BEGIN "AGA10WIN", DIALOG BEGIN LEFTMARGIN, 5 RIGHTMARGIN, 568 BOTTOMMARGIN, 309 END END #endif // APSTUDIO_INVOKED #ifndef _MAC ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,7,0,0 PRODUCTVERSION 1,7,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x21L #else
172
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. FILEFLAGS 0x20L #endif FILEOS 0x40004L FILETYPE 0x1L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904b0" BEGIN VALUE "Comments", "Post Ballot Version\0" VALUE "CompanyName", "American Gas Association\0" VALUE "FileDescription", "aga10win\0" VALUE "FileVersion", "1, 7, 0, 0\0" VALUE "InternalName", "aga10win\0" VALUE "LegalCopyright", "Copyright © 2002 American Gas Association\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "aga10win.exe\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "aga10win\0" VALUE "ProductVersion", "1, 7, 0, 0\0" VALUE "SpecialBuild", "2002.11.17 Build\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x409, 1200 END END #endif
// !_MAC
///////////////////////////////////////////////////////////////////////////// // // Menu // IDR_MENU1 MENU DISCARDABLE BEGIN
173
This report is the property of AGA and is part of its process for developing new documents. This report or any of its part shall not be copied, disseminated, cited in literature, presentations or discussions without prior approval from AGA. POPUP "&File" BEGIN MENUITEM "&Open...", MENUITEM "&Save...", MENUITEM "Save &As...", MENUITEM "E&xit", END POPUP "&Help" BEGIN MENUITEM "&About", END
CM_FILEOPEN CM_FILESAVE CM_FILESAVEAS IDCANCEL
CM_HELPABOUT
END ///////////////////////////////////////////////////////////////////////////// // // String Table // STRINGTABLE DISCARDABLE BEGIN KILOPASCAL MEGAPASCAL END STRINGTABLE DISCARDABLE BEGIN PSI KELVIN CELSIUS RANKINE FAHRENHEIT KGPERCUBICMETRE LBMPERCUBICFOOT METREPERSECOND FOOTPERSECOND KJPERKG BTUPERLBM KJPERKGK BTUPERLBMF
"kilopascals" "megapascals"
"PSI" "Kelvin" "Celsius" "Rankine" "Fahrenheit" "kg per cubic metre" "lbm per cubic foot" "metres per second" "feet per second" "kJ per kg" "Btu per lbm" "kJ per kg-K" "Btu per lbm-F"
174