forked from PaulENorman/balloon_trajectory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstd_atm.cpp
148 lines (133 loc) · 3.43 KB
/
std_atm.cpp
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
/*
* Code for finding the state (density, Pressure, Temperature)
* and transport (viscosity and thermal conductivity) properties
* using US 1976 Standard Atm and Sutherlands Law
*/
#include "std_atm.h"
const double Std_atm::Cp_air0 = 1003.8;
const double Std_atm::Rsp_air = 287.058;
const double Std_atm::visc0 = 1.725E-5;
const double Std_atm::cond0 = 2.428E-2;
const double Std_atm::T_ref = 275;
const double Std_atm::C = 110.4;
/*
* @param T Temperature (K)
* @param rho Density (kg/m^3)
* @return Sutherland's Law thermal diffusivity (W/(m*K))
*/
double Std_atm::get_cond(double T) const {
return 0.0241*pow((T/273.15),0.9);
}
/*
* @param T Temperature (K)
* @param rho Density (kg/m^3)
* @return Sutherland's Law thermal diffusivity (m^2/s)
*/
double Std_atm::get_td(double T, double rho) const {
return get_cond(T)/(rho*Cp_air0);
}
/*
* @param T Temperature (K)
* @param rho Density (kg/m^3)
* @return Sutherland's Law viscosity (Pa*s)
*/
double Std_atm::get_visc(double T) const {
return 1.458E-6*pow(T,1.5)/(T+110.4);
}
/*
* @param T Temperature (K)
* @param rho Density (kg/m^3)
* @return Sutherland's Law kinematic viscosity (m^2/s)
*/
double Std_atm::get_kin_visc(double T, double rho) const {
return get_visc(T)/rho;
}
/*
* @param T Temperature (K)
* @return Prantl Number
*/
double Std_atm::get_Pr(double T) const{
return get_visc(T)*Cp_air0/get_cond(T);
}
/*
* Interpolate between two nearest points in standard atm
* @param h Elevation (m)
* @return Interpolated densiity (kg/m^3)
*/
double Std_atm::get_rho(double h) const{
unsigned int i = 0;
for(i = 0; i < atm_ar.size(); i++) {
if(atm_ar[i].h>h) break;
}
double rho = (atm_ar[i].rho - atm_ar[i-1].rho)/(atm_ar[i].h - atm_ar[i-1].h);
rho *= (h - atm_ar[i-1].h);
rho += atm_ar[i-1].rho;
return rho;
}
/*
* Interpolate between two nearest points in standard atm
* @param h Elevation (m)
* @return Interpolated Temperature (K)
*/
double Std_atm::get_T(double h) const{
unsigned int i = 0;
for(i = 0; i < atm_ar.size(); i++) {
if(atm_ar[i].h>h) break;
}
double T = (atm_ar[i].T - atm_ar[i-1].T)/(atm_ar[i].h - atm_ar[i-1].h);
T *= (h - atm_ar[i-1].h);
T += atm_ar[i-1].T;
return T;
}
/*
* Interpolate between two nearest points in standard atm
* @param h Elevation (m)
* @return Interpolated g (m/s^2)
*/
double Std_atm::get_g(double h) const {
unsigned int i = 0;
for(i = 0; i < atm_ar.size(); i++) {
if(atm_ar[i].h>h) break;
}
double g = (atm_ar[i].g - atm_ar[i-1].g)/(atm_ar[i].h - atm_ar[i-1].h);
g *= (h - atm_ar[i-1].h);
g += atm_ar[i-1].g;
return g;
}
/*
* Interpolate between two nearest points in standard atm
* @param h Elevation (m)
* @return Interpolated pressure (Pa)
*/
double Std_atm::get_P(double h) const{
unsigned int i = 0;
for(i = 0; i < atm_ar.size(); i++) {
if(atm_ar[i].h>h) break;
}
double p = (atm_ar[i].p - atm_ar[i-1].p)/(atm_ar[i].h - atm_ar[i-1].h);
p *= (h - atm_ar[i-1].h);
p += atm_ar[i-1].p;
return p;
}
/*
* Reads in us1976_std_atm.dat file
*/
void Std_atm::read_atm() {
char line[BUFSIZ];
FILE * in = fopen("us1976_std_atm.dat", "r");
while(fgets(line, BUFSIZ, in)) {
atm_ref a;
if(line[0] == '#') continue;
sscanf(line, "%lg %lg %lg %lg %lg", &a.h, &a.T, &a.g, &a.p, &a.rho);
a.T += 273.15; //convert to K
a.p *= 1E4; //convert to Pa
a.rho /= 10; //convert to kg/m^3
atm_ar.push_back(a);
}
fclose(in);
}
Std_atm::Std_atm() {
read_atm();
}
Std_atm::~Std_atm() {
}