-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgasState.m
103 lines (94 loc) · 2.45 KB
/
gasState.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function [p,s,r,e,a,h,t]=gasState(t,r,p,e,s,h)
% INPUTS (in specific order):
% temperature, t
% density, r
% pressure, p
% energy, e
% entropy, s
% enthalpy, h
% only two of these inputs are expected to be non-zero. An error will occur if this is not the case.
% Example function call: [p,s,r,e,a,h,t]=gasState(0,0,2549,0,7623.8,0)
% this will calcualte all properties using pressure and entropy
%
% OUTPUTS (in specific order):
% pressure, p
% entropy, s
% density, r
% energy, e
% speed of sound, a
% enthalpy, h
% temperature, t
%% units
unitsin=1; %input('\nAre your input units SI(1) or British(2)?\n');
unitsout=1; %input('\nDo you want your output in SI(1) or British units(2)?\n');
if unitsin==2
% British to SI
p=p*6894.747;
r=r*16.01846;
t=t/1.8;
e=e*2325.965;
h=h*2325.965;
s=s*(1.8*2325.965);
end
brk=0;
%%
% Given "Pressure, Entropy" (p,s)
if t==0 && r==0 && e==0 && h==0
r=r_ps(p,s);
a=a_ps(p,s);
e=e_ps(p,s);
t=t_pr(p,r);
h=e+p/r;
% Given "Energy, Density" (e,r)
elseif t==0 && p==0 && s==0 && h==0
[p,a]=pa_er(e,r,1);
s=s_re(r,e);
t=t_pr(p,r);
h=e+p/r;
a=a_ps(p,s);
% Given "Pressure, Density" (p,r)
elseif t==0 && e==0 && s==0 && h==0
h=h_pr(p,r);
t=t_pr(p,r);
e=h-p/r;
s=s_re(r,e);
a=a_ps(p,s);
% Given "Entropy, Enthalpy" (s,h)
elseif t==0 && e==0 && p==0 && r==0
[p,e,r]=per_hs(h,s);
t=t_pr(p,r);
a=a_ps(p,s);
% Given "Pressure, Temperature" (p,t)
elseif r==0 && e==0 && s==0 && h==0
r=r_pt(p,t);
h=h_pr(p,r);
e=h-p/r;
s=s_re(r,e);
a=a_ps(p,s);
else
fprintf('\n\nERROR:\nYou must enter only 2 variables, all others must be zero. \n')
fprintf('Also, the pair of variables MUST be one of the following combinations:\n')
fprintf('(p,t)\n(p,r)\n(s,h)\n(e,r)\n(p,s)\n')
brk=1;
end
%% units
if unitsout==2 && brk==0
% SI to British
p=p/6894.747;
r=r/16.01846;
t=t*1.8;
e=e/2325.965;
h=h/2325.965;
s=s/(1.8*2325.965);
a=a/0.3048;
end
if brk==1
p=p/6894.747;
r=r/16.01846;
t=t*1.8;
e=e/2325.965;
h=h/2325.965;
s=s/(1.8*2325.965);
a=0;
end
end