-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstandardAtmosphere.m
160 lines (139 loc) · 5.86 KB
/
standardAtmosphere.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
classdef standardAtmosphere
% class for a standard atmosphere with only contant temperature or gradient layers
% initialized with ISA for Earth
properties
SL % sea-level properties: pressure, temperature
layer % struct with fields startAltitude, pauseAltitude, lapseRate
% initialized with troposphere and stratosphere upto 32 km
constant % atmospheric constants: acceleration due to gravity, gas constant,
% ratio of specific heats, radius of Earth
end
methods
% class constructor
% initializes with ISA constants and sea level propeties
% layers up to 32 km
function atmos = standardAtmosphere()
atmos.constant = standardAtmosphere.setAtmosphereConstants();
atmos.SL = standardAtmosphere.setSeaLevelProperties();
atmos.layer = standardAtmosphere.setLayerProperties(0,11,-6.5);
atmos.layer(2) = standardAtmosphere.setLayerProperties(11,20,0);
atmos.layer(3) = standardAtmosphere.setLayerProperties(20,32,1);
end
% compute temperature at a given altitude
function T = temperature(atmos,h)
nLayer = length(atmos.layer);
iLayer = 0;
isComputed = 0;
while (iLayer < nLayer) && ~isComputed
iLayer = iLayer + 1;
if h <= atmos.layer(iLayer).pauseAltitude
if iLayer == 1
h0 = 0;
T0 = atmos.SL.temperature;
else
h0 = atmos.layer(iLayer).startAltitude;
T0 = atmos.temperature(h0);
end
lambda = atmos.layer(iLayer).lapseRate;
T = T0 + (h-h0)*lambda;
isComputed = 1;
end
end
end
% compute pressure at a given altitude
function p = pressure(atmos,h)
gSL = atmos.constant.gravity;
R = atmos.constant.gasConstant;
nLayer = length(atmos.layer);
iLayer = 0;
isComputed = 0;
while (iLayer < nLayer) && ~isComputed
iLayer = iLayer + 1;
if h <= atmos.layer(iLayer).pauseAltitude
if iLayer == 1
h0 = 0;
p0 = atmos.SL.pressure;
T0 = atmos.SL.temperature;
else
h0 = atmos.layer(iLayer).startAltitude;
p0 = atmos.pressure(h0);
T0 = atmos.temperature(h0);
end
lambda = atmos.layer(iLayer).lapseRate;
if lambda
p = p0*(atmos.temperature(h)./T0).^(-gSL./lambda./R*1000);
else
p = exp(-gSL/R/T0*(h-h0)*1000)*p0;
end
isComputed = 1;
end
end
end
% compute density at a given altitude
function rho = density(atmos,h)
R = atmos.constant.gasConstant;
rho = atmos.pressure(h)./R./atmos.temperature(h);
end
% compute viscosity at a given altitude
function visc = viscosity(atmos,h)
T = atmos.temperature(h);
visc = atmos.computeViscocity(T);
end
% compute speed of sound given the ambient temperature
function a = computeSoundSpeed(atmos,T)
gamma = atmos.constant.specificHeatRatio;
R = atmos.constant.gasConstant;
a = sqrt(gamma*R*T);
end
% compute speed of sound at a given altitude
function a = soundSpeed(atmos,h)
T = atmos.temperature(h);
a = atmos.computeSoundSpeed(T);
end
% add a new layer specifying start and pause altitudes
% and lapse rate in it
function atmos = addLayer(atmos,startAltitude, pauseAltitude, lapseRate)
iLayer = length(atmos.layer) + 1;
atmos(iLayer).startAltitude = startAltitude;
atmos(iLayer).pauseAltitude = pauseAltitude;
atmos(iLayer).lapseRate = lapseRate;
end
% convert geometric to geopotential altitude
function h = geopotentialAltitude(atmos,hGeom)
RE = atmos.constant.radius;
h = hGeom.*(RE./(RE+hGeom));
end
end
methods(Static)
% structure with sea level pressure and temperature corresponding to ISA
% used during instance creation
function propsSL = setSeaLevelProperties()
propsSL.pressure = 101325;
propsSL.temperature = 288.15;
end
% Create a structure with ISA constants
% used during object construction
function atmosConstant = setAtmosphereConstants()
atmosConstant.gravity = 9.80665;
atmosConstant.gasConstant = 287.05287;
atmosConstant.specificHeatRatio = 1.4;
atmosConstant.radius = 6356.766;
end
% Create a structure with layer properties
% used in the constructor method of the class
function layerProps = setLayerProperties(startAltitude, pauseAltitude, lapseRate)
layerProps.startAltitude = startAltitude;
layerProps.pauseAltitude = pauseAltitude;
layerProps.lapseRate = lapseRate;
end
% Compute air viscosity for a given temperature
% Sutherland's law
function viscosity = computeViscocity(T)
viscosity = 1.458e-6*(T).^(1.5)./(T+110.4);
end
% Convert degrees to Kelvin
function T = degree2Kelvin(d)
T = 273.15 + d;
end
end
end