/usr/lib/python2.7/dist-packages/gastables/Isothermal.py is in python-gastables 0.3-2.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | """ Python module for isothermal flow of perfect gases with friction
The combined effect of friction and heat transfer in long ducts can be
condidered to isothermal flow model.
Here the reference value of the properties (p*, rho*,c*,To*,po* and Lmax)
are taken at the Mach number M* = 1/sqrt(gamma)
Assumptions:
1) One dimensional flow with friction and heat transfer
2) Constant area duct
3) Perfect gas with constant specific heat and Molecular weights
4) Isothermal flow
"""
"""
* Copyright (C) 2006 Varun Hiremath.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* Authors: Varun Hiremath, Venkattraman A
* Version 0.2
"""
from math import *
from scipy import optimize
class Isothermal:
def __init__(self, g = 1.4):
""" g is the value of gamma (ratio of specific heats), default = 1.4
"""
self.g = 1.4
def get_P_by_Pstarref_from_M(self,M):
""" Returns the value of p/p* at Mach number M """
if M <= 0:
raise Exception('Value of M negative or zero . M should be greater than zero')
return
else:
return 1.0/self.g**(0.5)/M
def get_rhostarref_by_rho_from_M(self,M):
""" Returns the value of rho*/rho at Mach number M """
if M <= 0:
raise Exception('Value of M negative or zero . M should be greater than zero')
return
else:
return self.g**(0.5)*M
def get_To_by_Tostarref_from_M(self,M) :
""" Returns the value of To/To* at Mach number M """
if M <= 0:
raise Exception('Value of M negative or zero . M should be greater than zero')
return
else:
return 2.0*self.g/(3*self.g-1)*(1+(self.g-1)/2*M**2)
def get_Po_by_Postarref_from_M(self,M):
""" Returns the value of po/po* at Mach number M """
if M <= 0:
raise Exception('Value of M negative or zero . M should be greater than zero')
return
else:
return 1.0/sqrt(self.g)/M*(2.0*self.g/(3.0*self.g-1)*(1+(self.g-1)/2*M**2))**(self.g/(self.g-1))
def get_4fLmax_by_D_from_M(self,M):
""" Returns the value of 4f*(Lmax/D) at Mach number M """
if M <= 0:
raise Exception('Value of M negative or zero . M should be greater than zero')
return
else:
return (1-self.g*M**2)/self.g/M**2 + log(self.g*M**2)
def get_M_from_P_by_Pstarref(self,P_by_Pstarref):
""" Returns Mach number at p/p* equal to P_by_Pstarref """
if P_by_Pstarref<= 0 or P_by_Pstarref > 10000:
raise Exception('Value of P_by_Pstarref should be greater than zero and less than 10000')
return
else:
return 1.0/P_by_Pstarref/sqrt(self.g)
def get_rhostarref_by_rho_from_P_by_Pstarref(self,P_by_Pstarref):
"""Returns rho*/rho at p/p* equal to P_by_Pstarref"""
if P_by_Pstarref<= 0 or P_by_Pstarref > 10000:
raise Exception('Value of P_by_Pstarref should be greater than zero and less than 10000')
return
else:
M = self.get_M_from_P_by_Pstarref(P_by_Pstarref)
return self.get_rhostarref_by_rho_from_M(M)
def get_To_by_Tostarref_from_P_by_Pstarref(self,P_by_Pstarref) :
"""Returns To/To* at p/p* equal to P_by_Pstarref"""
if P_by_Pstarref<= 0 or P_by_Pstarref > 10000:
raise Exception('Value of P_by_Pstarref should be greater than zero and less than 10000')
return
else:
M = self.get_M_from_P_by_Pstarref(P_by_Pstarref)
return self.get_To_by_Tostarref_from_M(M)
def get_Po_by_Postarref_from_P_by_Pstarref(self,P_by_Pstarref):
"""Returns Po/Po* at p/p* equal to P_by_Pstarref"""
if P_by_Pstarref<= 0 or P_by_Pstarref > 10000:
raise Exception('Value of P_by_Pstarref should be greater than zero and less than 10000')
return
else:
M = self.get_M_from_P_by_Pstarref(P_by_Pstarref)
return self.get_Po_by_Postarref_from_M(M)
def get_4fLmax_by_D_from_P_by_Pstarref(self,P_by_Pstarref):
"""Returns 4f*Lmax/D at p/p* equal to P_by_Pstarref"""
if P_by_Pstarref<= 0 or P_by_Pstarref > 10000:
raise Exception('Value of P_by_Pstarref should be greater than zero and less than 10000')
return
else:
M = self.get_M_from_P_by_Pstarref(P_by_Pstarref)
return self.get_4fLmax_by_D_from_M(M)
def get_M_from_rhostarref_by_rho(self,rhostarref_by_rho):
""" Returns Mach number at rho*/rho equal to rhostarref_by_rho """
if rhostarref_by_rho<= 0.0001 or rhostarref_by_rho > 11000:
raise Exception('Value of rhostarref/rho should be greater than 0.0001 and less than 11000')
return
else:
return rhostarref_by_rho/sqrt(self.g)
def get_P_by_Pstarref_from_rhostarref_by_rho(self,rhostarref_by_rho):
""" Returns p/p* at rho*/rho equal to rhostarref_by_rho """
if rhostarref_by_rho<= 0.0001 or rhostarref_by_rho > 11000:
raise Exception('Value of rhostarref/rho should be greater than 0.0001 and less than 11000')
return
else:
M = self.get_M_from_rhostarref_by_rho(rhostarref_by_rho)
return self.get_P_by_Pstarref_from_M(M)
def get_To_by_Tostarref_from_rhostarref_by_rho(self,rhostarref_by_rho) :
""" Returns To/To* at rho*/rho equal to rhostarref_by_rho """
if rhostarref_by_rho<= 0.0001 or rhostarref_by_rho > 11000:
raise Exception('Value of rhostarref/rho should be greater than 0.0001 and less than 11000')
return
else:
M = self.get_M_from_rhostarref_by_rho(rhostarref_by_rho)
return self.get_To_by_Tostarref_from_M(M)
def get_Po_by_Postarref_from_rhostarref_by_rho(self,rhostarref_by_rho):
""" Returns po/po* at rho*/rho equal to rhostarref_by_rho """
if rhostarref_by_rho<= 0.0001 or rhostarref_by_rho > 11000:
raise Exception('Value of rhostarref/rho should be greater than 0.0001 and less than 11000')
return
else:
M = self.get_M_from_rhostarref_by_rho(rhostarref_by_rho)
return self.get_Po_by_Postarref_from_M(M)
def get_4fLmax_by_D_from_rhostarref_by_rho(self,rhostarref_by_rho):
""" Returns 4f*Lmax/D at rho*/rho equal to rhostarref_by_rho """
if rhostarref_by_rho<= 0.0001 or rhostarref_by_rho > 11000:
raise Exception('Value of rhostarref/rho should be greater than 0.0001 and less than 11000')
return
else:
M = self.get_M_from_rhostarref_by_rho(rhostarref_by_rho)
return self.get_4fLmax_by_D_from_M(M)
def get_M_from_To_by_Tostarref(self,To_by_Tostarref):
""" Returns Mach number at To/To* equal to To_by_Tostarref """
if To_by_Tostarref<= 0.875 or To_by_Tostarref > 17500000:
raise Exception('Value of To_by_Tostarref should be greater than 0.875 and less than 17500000')
return
else:
return (((3*self.g-1)/2/self.g*To_by_Tostarref-1)*2/(self.g-1))**0.5
def get_P_by_Pstarref_from_To_by_Tostarref(self,To_by_Tostarref):
""" Returns p/p* at To/To* equal to To_by_Tostarref """
if To_by_Tostarref<= 0.875 or To_by_Tostarref > 17500000:
raise Exception('Value of To_by_Tostarref should be greater than 0.875 and less than 17500000')
return
else:
M = self.get_M_from_To_by_Tostarref(To_by_Tostarref)
return self.get_P_by_Pstarref_from_M(M)
def get_rhostarref_by_rho_from_To_by_Tostarref(self,To_by_Tostarref):
""" Returns rho*/rho at To/To* equal to To_by_Tostarref """
if To_by_Tostarref<= 0.875 or To_by_Tostarref > 17500000:
raise Exception('Value of To_by_Tostarref should be greater than 0.875 and less than 17500000')
return
else:
M = self.get_M_from_To_by_Tostarref(To_by_Tostarref)
return self.get_rhostarref_by_rho_from_M(M)
def get_Po_by_Postarref_from_To_by_Tostarref(self,To_by_Tostarref):
""" Returns po/po* at To/To* equal to To_by_Tostarref """
if To_by_Tostarref<= 0.875 or To_by_Tostarref > 17500000:
raise Exception('Value of To_by_Tostarref should be greater than 0.875 and less than 17500000')
return
else:
M = self.get_M_from_To_by_Tostarref(To_by_Tostarref)
return self.get_Po_by_Postarref_from_M(M)
def get_4fLmax_by_D_from_To_by_Tostarref(self,To_by_Tostarref):
""" Returns 4f*Lmax/D at To/To* equal to To_by_Tostarref """
if To_by_Tostarref<= 0.875 or To_by_Tostarref > 17500000:
raise Exception('Value of To_by_Tostarref should be greater than 0.875 and less than 17500000')
return
else:
M = self.get_M_from_To_by_Tostarref(To_by_Tostarref)
return self.get_4fLmax_by_D_from_M(M)
def get_M_from_Po_by_Postarref(self,Po_by_Postarref):
""" Returns Mach number at po/po* equal to Po_by_Postarref """
#return (optimize.bisect(lambda M : self.get_Po_by_Postarref_from_M(M) - Po_by_Postarref, 0.001 , 1.0/sqrt(self.g)), optimize.bisect(lambda M : self.get_Po_by_Postarref_from_M(M) - Po_by_Postarref, 1.0/(sqrt(self.g), 100.0)))
if Po_by_Postarref<= 1.9 or Po_by_Postarref > 5290:
raise Exception('Value of Po_by_Postarref should be greater than 1.9 and less than 5290')
return
else:
return (optimize.bisect(lambda M : self.get_Po_by_Postarref_from_M(M) - Po_by_Postarref, 0.001 , 1.0), optimize.bisect(lambda M : self.get_Po_by_Postarref_from_M(M) - Po_by_Postarref, 1.0, 100.0))
def get_P_by_Pstarref_from_Po_by_Postarref(self,Po_by_Postarref):
""" Returns p/p* at po/po* equal to Po_by_Postarref """
if Po_by_Postarref<= 1.9 or Po_by_Postarref > 5290:
raise Exception('Value of Po_by_Postarref should be greater than 1.9 and less than 5290')
return
else:
M = self.get_M_from_Po_by_Postarref(Po_by_Postarref)
return (self.get_P_by_Pstarref_from_M(M[0]),self.get_P_by_Pstarref_from_M(M[1]))
def get_rhostarref_by_rho_from_Po_by_Postarref(self,Po_by_Postarref):
""" Returns rho*/rho at po/po* equal to Po_by_Postarref """
if Po_by_Postarref<= 1.9 or Po_by_Postarref > 5290:
raise Exception('Value of Po_by_Postarref should be greater than 1.9 and less than 5290')
return
else:
M = self.get_M_from_Po_by_Postarref(Po_by_Postarref)
return (self.get_rhostarref_by_rho_from_M(M[0]),self.get_rhostarref_by_rho_from_M(M[1]))
def get_To_by_Tostarref_from_Po_by_Postarref(self,Po_by_Postarref) :
""" Returns To/To* at po/po* equal to Po_by_Postarref """
if Po_by_Postarref<= 1.9 or Po_by_Postarref > 5290:
raise Exception('Value of Po_by_Postarref should be greater than 1.9 and less than 5290')
return
else:
M = self.get_M_from_Po_by_Postarref(Po_by_Postarref)
return (self.get_To_by_Tostarref_from_M(M[0]),self.get_To_by_Tostarref_from_M(M[1]))
def get_4fLmax_by_D_from_Po_by_Postarref(self,Po_by_Postarref):
""" Returns 4f*Lmax/D at po/po* equal to Po_by_Postarref """
if Po_by_Postarref<= 1.9 or Po_by_Postarref > 5290:
raise Exception('Value of Po_by_Postarref should be greater than 1.9 and less than 5290')
return
else:
M = self.get_M_from_Po_by_Postarref(Po_by_Postarref)
return (self.get_4fLmax_by_D_from_M(M[0]),self.get_4fLmax_by_D_from_M(M[1]))
def get_M_from_4fLmax_by_D(self,fLmax_by_D):
""" Returns Mach number at 4f*(Lmax/D) equal to fLmax_by_D """
if fLmax_by_D<= 17 or fLmax_by_D > 71428552:
raise Exception('Value of 4fLmax_by_D should be greater than 17 and less than 71428552')
return
else:
return (optimize.bisect(lambda M : self.get_4fLmax_by_D_from_M(M) - fLmax_by_D, 0.001, 1.0/sqrt(self.g)+0.001), optimize.bisect(lambda M : self.get_4fLmax_by_D_from_M(M ) - fLmax_by_D, 1.0/sqrt(self.g)-0.001, 100.0))
def get_P_by_Pstarref_from_4fLmax_by_D(self,fLmax_by_D):
""" Returns p/p* at 4f*(Lmax/D) equal to fLmax_by_D """
if fLmax_by_D<= 17 or fLmax_by_D > 71428552:
raise Exception('Value of 4fLmax_by_D should be greater than 17 and less than 71428552')
return
else:
M = self.get_M_from_4fLmax_by_D(fLmax_by_D)
return (self.get_P_by_Pstarref_from_M(M[0]),self.get_P_by_Pstarref_from_M(M[1]))
def get_rhostarref_by_rho_from_4fLmax_by_D(self,fLmax_by_D):
""" Returns rho*/rho at 4f*(Lmax/D) equal to fLmax_by_D """
if fLmax_by_D<= 17 or fLmax_by_D > 71428552:
raise Exception('Value of 4fLmax_by_D should be greater than 17 and less than 71428552')
return
else:
M = self.get_M_from_4fLmax_by_D(fLmax_by_D)
return (self.get_rhostarref_by_rho_from_M(M[0]),self.get_rhostarref_by_rho_from_M(M[1]))
def get_To_by_Tostarref_from_4fLmax_by_D(self,fLmax_by_D) :
""" Returns To/To* at 4f*(Lmax/D) equal to fLmax_by_D """
if fLmax_by_D<= 17 or fLmax_by_D > 71428552:
raise Exception('Value of 4fLmax_by_D should be greater than 17 and less than 71428552')
return
else:
M = self.get_M_from_4fLmax_by_D(fLmax_by_D)
return (self.get_To_by_Tostarref_from_M(M[0]),self.get_To_by_Tostarref_from_M(M[1]))
def get_Po_by_Postarref_from_4fLmax_by_D(self,fLmax_by_D):
""" Returns po/po* at 4f*(Lmax/D) equal to fLmax_by_D """
if fLmax_by_D<= 17 or fLmax_by_D > 71428552:
raise Exception('Value of 4fLmax_by_D should be greater than 17 and less than 71428552')
return
else:
M = self.get_M_from_4fLmax_by_D(fLmax_by_D)
return (self.get_Po_by_Postarref_from_M(M[0]),self.get_Po_by_Postarref_from_M(M[1]))
|