-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #10. Adds example of unit tests. Fixes general folder naming.
- Loading branch information
mtat76
committed
Jan 25, 2016
1 parent
13fc464
commit 0c9a90b
Showing
10 changed files
with
221 additions
and
827 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import atmPy.general.gas_props as gp | ||
import atmPy.general.water as water | ||
|
||
|
||
class Air(gp.Gas): | ||
def __init__(self, t=20.0, p=1013.25, **kwargs): | ||
super(Air, self).__init__(t, p) | ||
|
||
self._Rd = 287.05 | ||
self._Rv = 461.495 | ||
self.e = 0 | ||
|
||
if "ecal_meth" in kwargs: | ||
self._wvObj = kwargs.ecal_meth | ||
else: | ||
self._wvObj = water.MurphyKoop() | ||
|
||
if "e" in kwargs: | ||
self.e = kwargs.e | ||
elif "rh" in kwargs: | ||
self.e = self._wvObj.ew(self.t) * kwargs['rh'] / 100 | ||
else: | ||
self.e = 0 | ||
|
||
def cal_e(self, rh): | ||
self.e = self._wvObj.ew(self.t) * rh / 100 | ||
|
||
def mu(self): | ||
|
||
""" | ||
The following function defines viscosity as a function of T in P-s. | ||
Parameters | ||
--------- | ||
T:temperature in degrees Celsius | ||
Returns | ||
------- | ||
Viscosity in P-s | ||
""" | ||
|
||
# Make sure that the temperature is a float | ||
t = self.t + 273.15 | ||
c = 120.0 # Sutherland's constant | ||
mu0 = 18.27e-6 # Reference viscocity | ||
t0 = 291.15 # Reference temperature | ||
|
||
return (c + t0) / (c + t) * (t / t0) ** 1.5 * mu0 | ||
|
||
def l(self): | ||
|
||
""" | ||
Determine the mean free path of air. | ||
Returns | ||
------- | ||
Mean free path of air in microns. | ||
""" | ||
|
||
# Convert pressure to atmospheres | ||
patm = float(self.p) / 1013.25 | ||
l0 = 0.066 # Reference mean free path at 1 atm | ||
|
||
return l0 / patm | ||
|
||
def rho(self): | ||
|
||
tk = self.t + 273.15 | ||
return self.p * 100 / (self._Rd* tk) + self.e * 100 / (self._Rv * tk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import abc | ||
|
||
class Gas(object): | ||
""" | ||
Generic object defining different properties of gasses. | ||
Attributes | ||
---------- | ||
p: float | ||
Pressure in mb. | ||
t: float | ||
Temperature in degrees Celsius. | ||
""" | ||
__metaclass__ = abc.ABCMeta | ||
|
||
def __init__(self, t=20, p=1013.25): | ||
self.t = t | ||
self.p = p | ||
|
||
def __str__(self): | ||
return "Gas object with T = " + str(self.t) + " and P = " + str(self.p) + "." | ||
|
||
@abc.abstractmethod | ||
def mu(self): | ||
return 0 | ||
|
||
@abc.abstractmethod | ||
def l(self): | ||
return 0 | ||
|
||
@abc.abstractmethod | ||
def rho(self): | ||
return 0 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import atmPy.general.air as air | ||
|
||
from numpy import abs | ||
|
||
|
||
class TestAir(object): | ||
def __init__(self): | ||
self.a = air.Air() | ||
|
||
self.mu_vals = {'T': [-5, 0, 10, 15, 25], | ||
'mu': [1.7105007E-5, 1.7362065e-5, 1.7869785E-5, 1.8120528E-5, 1.861598E-5] | ||
} | ||
|
||
self.rho_vals = {'T': [0, 0, 0, 0, | ||
0, 0, 0, 0, | ||
0, 0, 0, 0, | ||
25, 25, 25, 25, | ||
25, 25, 25, 25, | ||
25, 25, 25, 25], | ||
'P': [200, 200, 200, 200, | ||
800, 800, 800, 800, | ||
1000, 1000, 1000, 1000, | ||
200, 200, 200, 200, | ||
800, 800, 800, 800, | ||
1000, 1000, 1000, 1000], | ||
'RH': [25, 50, 75, 90, | ||
25, 50, 75, 90, | ||
25, 50, 75, 90, | ||
25, 50, 75, 90, | ||
25, 50, 75, 90, | ||
25, 50, 75, 90], | ||
'rho': [0.254, 0.254, 0.253, 0.252, | ||
1.020, 1.019, 1.018, 1.018, | ||
1.275, 1.274, 1.273, 1.273, | ||
0.230, 0.227, 0.223, 0.221, | ||
0.931, 0.928, 0.924, 0.922, | ||
1.165, 1.161, 1.158, 1.156 | ||
] | ||
} | ||
|
||
def test_muvals(self): | ||
print('========= Testing Dynamic Viscocity Calculations =========') | ||
print(' T mu ') | ||
print('======= ========') | ||
|
||
for e, i in enumerate(self.mu_vals['T']): | ||
yield self.check_mu, i, self.mu_vals['mu'][e], 1e-3 | ||
|
||
def test_rhos(self): | ||
print('========= Testing Density Calculations =========') | ||
print(' T P RH rho ') | ||
print('======= ======= ======== =========') | ||
|
||
for e, i in enumerate(self.rho_vals['rho']): | ||
yield self.check_rho, {'T': self.rho_vals['T'][e], | ||
'P': self.rho_vals['P'][e], | ||
'RH': self.rho_vals['RH'][e]}, i, 0.1 | ||
|
||
def check_mu(self, t, val, tol): | ||
self.a.t = t | ||
print(self.a.t, self.a.mu(), abs((val - self.a.mu()) / val)) | ||
assert abs((val - self.a.mu()) / val) < tol | ||
|
||
def check_rho(self, atm, val, tol): | ||
kwargs = {"rh": atm['RH']} | ||
self.a = air.Air(atm['T'], atm['P'], **kwargs) | ||
print(self.a.t, self.a.p, atm['RH'], val, self.a.rho(), abs((val - self.a.rho()) / val)) | ||
assert abs((val - self.a.rho()) / val) < tol |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.