Parent Directory | Revision Log

Revision **1810** -
(**show annotations**)
(**download**)
(**as text**)

*Tue Jul 29 07:45:48 2008 UTC*
(12 years, 1 month ago)
by *jpye*

File MIME type: text/x-csrc

File size: 2802 byte(s)

File MIME type: text/x-csrc

File size: 2802 byte(s)

Added new code for calculating properties according to modified BWR correlation, also some initial work on Helmholtz free energy correlation.

1 | /* ASCEND modelling environment |

2 | Copyright (C) 2006 Carnegie Mellon University |

3 | |

4 | This program is free software; you can redistribute it and/or modify |

5 | it under the terms of the GNU General Public License as published by |

6 | the Free Software Foundation; either version 2, or (at your option) |

7 | any later version. |

8 | |

9 | This program is distributed in the hope that it will be useful, |

10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |

11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |

12 | GNU General Public License for more details. |

13 | |

14 | You should have received a copy of the GNU General Public License |

15 | along with this program; if not, write to the Free Software |

16 | Foundation, Inc., 59 Temple Place - Suite 330, |

17 | Boston, MA 02111-1307, USA. |

18 | *//** @file |

19 | Implementation of the reduced molar Helmholtz free energy equation of state. |

20 | |

21 | John Pye, 29 Jul 2008. |

22 | */ |

23 | |

24 | /** |

25 | Data structure for fluid-specific data for the Helmholtz free energy EOS. |

26 | */ |

27 | typedef struct HelmholtzData_struct{ |

28 | double R /**< ??? */ |

29 | double rho_c; /**< critical molar density in mol/L */ |

30 | double beta[32]; /**< constants in MBWR for the fluid in question */ |

31 | } HelmholtzData; |

32 | |

33 | /** |

34 | Function to calculate pressure from Helmholtz free energy EOS, given temperature |

35 | and molar density. |

36 | |

37 | @param T temperature in K |

38 | @param rhob molar density in mol/L |

39 | @return pressure in Pa |

40 | */ |

41 | double mbwr_p(double T, double rhob, MbwrData *data){ |

42 | int i; |

43 | double p = 0; |

44 | double Ti, Ti2, Ti3, Ti4; |

45 | double rhob2, rhobpow, sum10, rhob_r; |

46 | |

47 | /* precalculate powers of T^-1 for faster evaluation */ |

48 | Ti =1. / T; |

49 | Ti2 = Ti*Ti; |

50 | Ti3 = Ti2*Ti; |

51 | Ti4 = Ti3*Ti; |

52 | |

53 | /* values of alpha in MBWR are functions of temperature */ |

54 | double *B = data->beta; |

55 | #define R data->R |

56 | alpha[0] = R * T; |

57 | alpha[1] = B[0]*T + B[1]*sqrt(T] + B[2] + B[3]*Ti + B[4]*Ti2; |

58 | alpha[2] = B[5]*T + B[6] + B[7]*Ti + B[8]*Ti2; |

59 | alpha[3] = B[9]*T + B[10] + B[11]*Ti; |

60 | alpha[4] = B[12]; |

61 | alpha[5] = B[13]*Ti + B[14]*Ti2; |

62 | alpha[6] = B[15]*Ti; |

63 | alpha[7] = B[16]*Ti + B[17]*Ti2; |

64 | alpha[8] = B[18]*Ti2; |

65 | alpha[9] = B[19]*Ti2 + B[20]*Ti3; |

66 | alpha[10] = B[21]*Ti2 + B[22]*Ti4; |

67 | alpha[11] = B[23]*Ti2 + B[24]*Ti3; |

68 | alpha[12] = B[25]*Ti2 + B[26]*Ti4; |

69 | alpha[13] = B[27]*Ti2 + B[28]*Ti3; |

70 | alpha[14] = B[29]*Ti2 + B[30]*Ti3 + B[31]*Ti4; |

71 | #undef R |

72 | |

73 | /* add up the first sum in the MBWR correlation */ |

74 | rhobpow = 1; |

75 | for(i=0;i<9;++i){ |

76 | rhobpow *= rhob; |

77 | p += alpha[i]* rhobpow; |

78 | } |

79 | |

80 | /* work out the second sum in the MBWR correlation */ |

81 | sum10 = 0; |

82 | rhobpow = rhob; |

83 | rhob2 = rhob*rhob; |

84 | for(i=9; i<15; ++i){ |

85 | rhobpow *= rhob2; |

86 | sum10 += alpha[i] * rhobpow; |

87 | } |

88 | |

89 | /* calculate the exponential term and add it to 'p' */ |

90 | #define RHO_C data->rhob_c |

91 | double rhob_r = rhob/RHO_C; |

92 | p += exp(rhob_r*rhob_r) * sum10; |

93 | #undef RHO_C |

94 | |

95 | return p * 1e-5; /* convert bar to Pa on return */ |

96 | } |

97 | |

98 |

john.pye@anu.edu.au | ViewVC Help |

Powered by ViewVC 1.1.22 |