Advertisement
bolverk

capricorn_breakout_analysis

Feb 27th, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. def whitham_mu(g):
  2.  
  3.     import math
  4.  
  5.     return 1./(2+math.sqrt(2*g/(g-1)))
  6.  
  7. def theoretical_density_powerlaw_index(omega, gamma):
  8.  
  9.     mu = whitham_mu(gamma)
  10.  
  11.     return (1.+omega*mu+omega)/(omega*mu)
  12.  
  13. def consolidate(fname):
  14.  
  15.     import h5py
  16.     import numpy
  17.  
  18.     with h5py.File(fname) as f:
  19.         res = dict((key,numpy.array(f[key])) for key in f)
  20.     res['centres'] = 0.5*(res['grid'][1:]+res['grid'][:-1])
  21.     return res
  22.  
  23. def main():
  24.  
  25.     import numpy
  26.     import pylab
  27.  
  28.     initial = consolidate('temp_breakout/initial.h5')
  29.     final = consolidate('temp_breakout/final.h5')
  30.  
  31.     #cd_pos = final['grid'][numpy.argmax(1/numpy.array(initial['grid']))]
  32.  
  33.     filtered = dict((key,numpy.array([v for x,v in zip(final['centres'],
  34.                                                        final[key])
  35.                                       if x>0.1*numpy.max(final['centres'])]))
  36.                     for key in ['centres','pressure','velocity','density'])
  37.     fit_data = numpy.polyfit(filtered['centres'],
  38.                              filtered['velocity'], 1)
  39.     d_fit = numpy.polyfit(numpy.log(filtered['centres']),
  40.                         numpy.log(filtered['density']),1)
  41.     print(d_fit)
  42.     print('expected '+str(theoretical_density_powerlaw_index(1.5,5./3.)))
  43.    
  44.     for n, var_name in enumerate(['density','pressure','velocity']):
  45.         pylab.subplot(3,1,n+1)
  46.         if var_name == 'velocity' or var_name == 'pressure':
  47.             #pylab.plot(initial['centres'], initial[var_name])
  48.             pylab.plot(final['centres'], final[var_name])
  49.         else:
  50.             #pylab.plot(initial['centres'], numpy.log(initial[var_name]))
  51.             pylab.semilogy(final['centres'], final[var_name])
  52.     pylab.plot(final['centres'], numpy.polyval(fit_data, final['centres']))
  53.     pylab.subplot(311)
  54.     pylab.semilogy(filtered['centres'],
  55.                    numpy.exp(numpy.polyval(d_fit,numpy.log(filtered['centres']))))
  56.     pylab.show()
  57.  
  58. if __name__ == '__main__':
  59.  
  60.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement