This file is indexed.

/usr/share/pyshared/gastables/NormalShock.py is in python-gastables 0.3-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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
""" Python module for properties across a normal shock in perfect gases

Assumptions:
1) One dimensional flow
2) Constant area duct
3) Perfect gas with constant specific heat and molecular weights
4) Adiabatic 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 scipy import optimize
from math import *
from Isentropic import Isentropic

class NormalShock:
    def __init__(self, g=1.4):
        """ g is the value of gamma (ratio of specific heats), default = 1.4
        """
        self.g = 1.4
        self.Isentropic = Isentropic(self.g)

    def get_My_from_Mx(self, Mx):
        """Returns Mach No My behind a normal shock from Mach No Mx ahead of the shock"""
        if Mx <= 1:
            raise Exception("Mach No ahead of ths shock Mx should be greater than 1")
        else:
            return sqrt((2/(self.g-1) + Mx**2)/(2*self.g/(self.g-1)*Mx**2 -1))

    def get_Py_by_Px_from_Mx(self, Mx):
        """Returns py/px across a normal shock from  Mx """
        if Mx <= 1:
            raise Exception("Mach No ahead of ths shock Mx should be greater than 1")
        else:
            return 2*self.g/(self.g+1)* Mx**2 - (self.g-1)/(self.g+1)

    def get_Ty_by_Tx_from_Mx(self, Mx):
        """Returns Ty/Tx across a normal shock from  Mx """
        if Mx <= 1:
            raise Exception("Mach No ahead of ths shock Mx should be greater than 1")
        else:
            return (1 + (self.g-1)*0.5* Mx**2)*(2*self.g/(self.g-1)*Mx**2 - 1)/((self.g+1)**2/(self.g-1)*0.5* Mx**2)

    def get_rhoy_by_rhox_from_Mx(self, Mx):
        """Returns rhoy/rhox across a normal shock from Mx"""
        if Mx <= 1:
            raise Exception("Mach No ahead of ths shock Mx should be greater than 1")
        else:
            return self.get_Py_by_Px_from_Mx(Mx) / self.get_Ty_by_Tx_from_Mx(Mx)
    
    def get_Poy_by_Pox_from_Mx(self, Mx):
        """Returns poy/pox across a normal shock from Mx"""
        if Mx <= 1:
            raise Exception("Mach No ahead of ths shock Mx should be greater than 1")
        else:
            My = self.get_My_from_Mx(Mx)
            return self.Isentropic.get_P_by_Po_from_M(Mx) * self.get_Py_by_Px_from_Mx(Mx) / self.Isentropic.get_P_by_Po_from_M(My)

    def get_Poy_by_Px_from_Mx(self, Mx):
        """Returns poy/px across a normal shock from Mx"""
        if Mx <= 1:
            raise Exception("Mach No ahead of ths shock Mx should be greater than 1")
        else:
            My = self.get_My_from_Mx(Mx)
            return self.get_Py_by_Px_from_Mx(Mx) / self.Isentropic.get_P_by_Po_from_M(My)
    
    def get_Mx_from_My(self, My):
        """Returns Mach No Mx ahead of a normal shock from Mach No My behind the shock"""
        if My >= 1.0 or My <= sqrt((self.g-1)/self.g * 0.5):
            raise Exception("Mach No behind a normal shock My should be between %s and 1.0" % str(sqrt((self.g-1)/self.g * 0.5)))
        else:
            return sqrt((1 + (self.g-1)* 0.5 * My**2)/(self.g * My**2 - (self.g-1)*0.5))

    def get_Py_by_Px_from_My(self, My):
        """Returns py/px across a normal shock from  My """
        if My >= 1.0 or My <= sqrt((self.g-1)/self.g * 0.5):
            raise Exception("Mach No behind a normal shock My should be between %s and 1.0" % str(sqrt((self.g-1)/self.g * 0.5)))
        else :
            Mx = self.get_Mx_from_My(My)
            return self.get_Py_by_Px_from_Mx(Mx)
    
    def get_Ty_by_Tx_from_My(self, My):
        """Returns Ty/Tx across a normal shock from  My """
        if My >= 1.0 or My <= sqrt((self.g-1)/self.g * 0.5):
            raise Exception("Mach No behind a normal shock My should be between %s and 1.0" % str(sqrt((self.g-1)/self.g * 0.5)))
        else :
            Mx = self.get_Mx_from_My(My)
            return self.get_Ty_by_Tx_from_Mx(Mx)
    
    def get_rhoy_by_rhox_from_My(self, My):
        """Returns rhoy/rhox across a normal shock from My"""
        if My >= 1.0 or My <= sqrt((self.g-1)/self.g * 0.5):
            raise Exception("Mach No behind a normal shock My should be between %s and 1.0" % str(sqrt((self.g-1)/self.g * 0.5)))
        else :
            Mx = self.get_Mx_from_My(My)
            return self.get_rhoy_by_rhox_from_Mx(Mx)
     
    def get_Poy_by_Pox_from_My(self, My):
        """Returns poy/pox across a normal shock from My"""
        if My >= 1.0 or My <= sqrt((self.g-1)/self.g * 0.5):
            raise Exception("Mach No behind a normal shock My should be between %s and 1.0" % str(sqrt((self.g-1)/self.g * 0.5)))
        else :
            Mx = self.get_Mx_from_My(My)
            return self.get_Poy_by_Pox_from_Mx(Mx)

    def get_Poy_by_Px_from_My(self, My):
        """Returns poy/px across a normal shock from My"""
        if My >= 1.0 or My <= sqrt((self.g-1)/self.g * 0.5):
            raise Exception("Mach No behind a normal shock My should be between %s and 1.0" % str(sqrt((self.g-1)/self.g * 0.5)))
        else :
            Mx = self.get_Mx_from_My(My)
            return self.get_Poy_by_Px_from_Mx(Mx)
    

    def get_Mx_from_Ty_by_Tx(self, Ty_by_Tx):
        """Returns Mx from Ty/Tx equal to Ty_by_Tx"""
        if Ty_by_Tx <= 1.0:
            raise Exception("Ty/Tx must be greater than 1")
        else:
            a = 2*self.g*(self.g-1)
            b = 4*self.g - (self.g-1)**2 - Ty_by_Tx * (self.g+1)**2
            c = -2*(self.g-1)
            return sqrt((-b + sqrt(b**2 - 4*a*c))/a *0.5)
    
    def get_My_from_Ty_by_Tx(Self, Ty_by_Tx):
        """Returns Mx from Ty/Tx equal to Ty_by_Tx"""
        if Ty_by_Tx <= 1.0:
            raise Exception("Ty/Tx must be greater than 1")
        else:
            Mx = self.get_Mx_from_Ty_by_Tx(Ty_by_Tx)
            return self.get_My_from_Mx(Mx)

    def get_Py_by_Px_from_Ty_by_Tx(self, Ty_by_Tx):
        """Returns Py/Px from Ty/Tx equal to Ty_by_Tx"""
        if Ty_by_Tx <= 1.0:
            raise Exception("Ty/Tx must be greater than 1")
        else:
            Mx = self.get_Mx_from_Ty_by_Tx(Ty_by_Tx)
            return self.get_Py_by_Px_from_Mx(Mx)

    def get_Poy_by_Pox_from_Ty_by_Tx(self, Ty_by_Tx):
        """Returns poy/pox from Ty/Tx equal to Ty_by_Tx"""
        if Ty_by_Tx <= 1.0:
            raise Exception("Ty/Tx must be greater than 1")
        else:
            Mx = self.get_Mx_from_Ty_by_Tx(Ty_by_Tx)
            return self.get_Poy_by_Pox_from_Mx(Mx)

    def get_Poy_by_Px_from_Ty_by_Tx(self, Ty_by_Tx):
        """Returns poy/px from Ty/Tx equal to Ty_by_Tx"""
        if Ty_by_Tx <= 1.0:
            raise Exception("Ty/Tx must be greater than 1")
        else:
            Mx = self.get_Mx_from_Ty_by_Tx(Ty_by_Tx)
            return self.get_Poy_by_Px_from_Mx(Mx)

    def get_Mx_from_Py_by_Px(self, Py_by_Px):
        """Returns Mx from py/px equal to Py_by_Px"""
        if Py_by_Px <= 1:
            raise Exception("py/px must be greater than 1")
        else:
            return sqrt((Py_by_Px - 1)* (self.g+1)/self.g * 0.5 + 1)

    def get_My_from_Py_by_Px(self, Py_by_Px):
        """Returns My from py/px equal to Py_by_Px"""
        if Py_by_Px <= 1:
            raise Exception("py/px must be greater than 1")
        else:
            Mx = self.get_Mx_from_Py_by_Px(Py_by_Px)
            return self.get_My_from_Mx(Mx)

    def get_Ty_by_Tx_from_Py_by_Px(self, Py_by_Px):
        """Returns Ty/Tx from py/px equal to Py_by_Px"""
        if Py_by_Px <= 1:
            raise Exception("py/px must be greater than 1")
        else:
            Mx = self.get_Mx_from_Py_by_Px(Py_by_Px)
            return self.get_Ty_by_Tx_from_Mx(Mx)

    def get_Poy_by_Pox_from_Py_by_Px(self, Py_by_Px):
        """Returns poy/pox from Py/Px equal to Py_by_Px"""
        if Py_by_Px <= 1:
            raise Exception("py/px must be greater than 1")
        else:
            Mx = self.get_Mx_from_Py_by_Px(Py_by_Px)
            return self.get_Poy_by_Pox_from_Mx(Mx)

    def get_Poy_by_Px_from_Py_by_Px(self, Py_by_Px):
        """Returns Poy/Px from Py/Px equal to Py_by_Px"""
        if Py_by_Px <= 1:
            raise Exception("py/px must be greater than 1")
        else:
            Mx = self.get_Mx_from_Py_by_Px(Py_by_Px)
            return self.get_Poy_by_Px_from_Mx(Mx)

    def get_Mx_from_rhoy_by_rhox(self, rhoy_by_rhox):
        """Returns Mx from rhoy/rhox equal to rhoy_by_rhox"""
        if rhoy_by_rhox <=1.0 or rhoy_by_rhox >= (self.g+1)/(self.g-1):
            raise Exception("rhoy/rhox should be between 1 and ",(self.g+1)/(self.g-1))
        else:
            return sqrt(2*rhoy_by_rhox/(self.g+1- rhoy_by_rhox*(self.g-1)))

    def get_My_from_rhoy_by_rhox(self, rhoy_by_rhox):
        """Returns My from rhoy/rhox equal to rhoy_by_rhox"""
        if rhoy_by_rhox <=1.0 or rhoy_by_rhox >= (self.g+1)/(self.g-1):
            raise Exception("rhoy/rhox should be between 1 and ",(self.g+1)/(self.g-1))
        else:
            Mx = self.get_Mx_from_rhoy_by_rhox(rhoy_by_rhox)
            return self.get_My_from_Mx(Mx)

    def get_Ty_by_Tx_from_rhoy_by_rhox(self, rhoy_by_rhox):
        """Returns Ty/Tx from rhoy/rhox equal to rhoy_by_rhox"""
        if rhoy_by_rhox <=1.0 or rhoy_by_rhox >= (self.g+1)/(self.g-1):
            raise Exception("rhoy/rhox should be between 1 and ",(self.g+1)/(self.g-1))
        else:
            Mx = self.get_Mx_from_rhoy_by_rhox(rhoy_by_rhox)
            return self.get_Ty_by_Tx_from_Mx(Mx)

    def get_Poy_by_Pox_from_rhoy_by_rhox(self, rhoy_by_rhox):
        """Returns poy/pox from rhoy/rhox equal to rhoy_by_rhox"""
        if rhoy_by_rhox <=1.0 or rhoy_by_rhox >= (self.g+1)/(self.g-1):
            raise Exception("rhoy/rhox should be between 1 and ",(self.g+1)/(self.g-1))
        else:
            Mx = self.get_Mx_from_rhoy_by_rhox(rhoy_by_rhox)
            return self.get_Poy_by_Pox_from_Mx(Mx)

    def get_Poy_by_Px_from_rhoy_by_rhox(self, rhoy_by_rhox):
        """Returns poy/px from rhoy/rhox equal to rhoy_by_rhox"""
        if rhoy_by_rhox <=1.0 or rhoy_by_rhox >= (self.g+1)/(self.g-1):
            raise Exception("rhoy/rhox should be between 1 and ",(self.g+1)/(self.g-1))
        else:
            Mx = self.get_Mx_from_rhoy_by_rhox(rhoy_by_rhox)
            return self.get_Poy_by_Px_from_Mx(Mx)


    def get_Mx_from_Poy_by_Pox(self, Poy_by_Pox):
        """Returns Mx from poy/pox equal to Poy_by_Pox"""
        if Poy_by_Pox <= 0 or Poy_by_Pox >= 1:
            raise Exception("Poy/Pox must be between 0 and 1")
        else:
            return optimize.fsolve(lambda Mx: self.get_Poy_by_Pox_from_Mx(Mx) - Poy_by_Pox, 2.0)

    def get_My_from_Poy_by_Pox(self, Poy_by_Pox):
        """Returns My from poy/pox equal to Poy_by_Pox"""
        if Poy_by_Pox <= 0 or Poy_by_Pox >= 1:
            raise Exception("Poy/Pox must be between 0 and 1")
        else:
            Mx = self.get_Mx_from_Poy_by_Pox(Poy_by_Pox)
            return self.get_My_from_Mx(Mx)

    def get_Ty_by_Tx_from_Poy_by_Pox(self, Poy_by_Pox):
        """Returns Ty/Tx from poy/pox equal to Poy_by_Pox"""
        if Poy_by_Pox <= 0 or Poy_by_Pox >= 1:
            raise Exception("Poy/Pox must be between 0 and 1")
        else:
            Mx = self.get_Mx_from_Poy_by_Pox(Poy_by_Pox)
            return self.get_Ty_by_Tx_from_Mx(Mx)

    def get_Py_by_Px_from_Poy_by_Pox(self, Poy_by_Pox):
        """Returns py/px from poy/pox equal to Poy_by_Pox"""
        if Poy_by_Pox <= 0 or Poy_by_Pox >= 1:
            raise Exception("Poy/Pox must be between 0 and 1")
        else:
            Mx = self.get_Mx_from_Poy_by_Pox(Poy_by_Pox)
            return self.get_Py_by_Px_from_Mx(Mx)

    def get_Poy_by_Px_from_Poy_by_Pox(self, Poy_by_Pox):
        """Returns poy/px from poy/pox equal to Poy_by_Pox"""
        if Poy_by_Pox <= 0 or Poy_by_Pox >= 1:
            raise Exception("Poy/Pox must be between 0 and 1")
        else:
            Mx = self.get_Mx_from_Poy_by_Pox(Poy_by_Pox)
            return self.get_Poy_by_Px_from_Mx(Mx)


    def get_Mx_from_Poy_by_Px(self, Poy_by_Px):
        """Returns Mx from poy/px equal to Poy_by_Px"""
        if Poy_by_Px <= ((self.g+1)*0.5)**(self.g/(self.g-1)):
            raise Exception("Poy/Px should be greater than",((self.g+1)*0.5)**(self.g/(self.g-1)))
        else:
            return optimize.fsolve(lambda Mx: self.get_Poy_by_Px_from_Mx(Mx) - Poy_by_Px, 2.0)

    def get_My_from_Poy_by_Px(self, Poy_by_Px):
        """Returns My from poy/px equal to Poy_by_Px"""
        if Poy_by_Px <= ((self.g+1)*0.5)**(self.g/(self.g-1)):
            raise Exception("Poy/Px should be greater than",((self.g+1)*0.5)**(self.g/(self.g-1)))
        else:
            Mx = self.get_Mx_from_Poy_by_Px(Poy_by_Px)
            return self.get_My_from_Mx(Mx)

    def get_Ty_by_Tx_from_Poy_by_Px(self, Poy_by_Px):
        """Returns Mx from poy/px equal to Poy_by_Px"""
        if Poy_by_Px <= ((self.g+1)*0.5)**(self.g/(self.g-1)):
            raise Exception("Poy/Px should be greater than",((self.g+1)*0.5)**(self.g/(self.g-1)))
        else:
            Mx = self.get_Mx_from_Poy_by_Px(Poy_by_Px)
            return self.get_Ty_by_Tx_from_Mx(Mx)

    def get_Py_by_Px_from_Poy_by_Px(self, Poy_by_Px):
        """Returns py/px from poy/px equal to Poy_Px"""
        if Poy_by_Px <= ((self.g+1)*0.5)**(self.g/(self.g-1)):
            raise Exception("Poy/Px should be greater than",((self.g+1)*0.5)**(self.g/(self.g-1)))
        else:
            Mx = self.get_Mx_from_Poy_by_Px(Poy_by_Px)
            return self.get_Py_by_Px_from_Mx(Mx)

    def get_Poy_by_Pox_from_Poy_by_Px(self, Poy_by_Px):
        """Returns poy/pox from poy/px equal to Poy_by_Px """
        if Poy_by_Px <= ((self.g+1)*0.5)**(self.g/(self.g-1)):
            raise Exception("Poy/Px should be greater than",((self.g+1)*0.5)**(self.g/(self.g-1)))
        else:
            Mx = self.get_Mx_from_Poy_by_Px(Poy_by_Px)
            return self.get_Poy_by_Pox_from_Mx(Mx)