Пример #1
0
def plot_q_of_t(qname='mdot_eh',
                diag=None,
                path=None,
                op=None,
                save=False,
                display=False,
                ymin=None,
                ymax=None,
                log=False):
    """Plot quantity q, given in the diag dict object by qname,
    as a function of time. Options are:

    qname -- String, Name of quantity to plot out of diag. Default is 'modt_eh'

    diag  -- String, diag object attained by using hdf5_to_dict.load_diag.
             Default is None, but must be set unless path is not None.
          
    path  -- String, path to directory containing diag file. Default is None,
             but must be set unless diag is not None.
          
    op    -- unary function, operation to apply to q before plotting.
             default is the identity.
          
    save  -- Save the plot to a file? Plot is saved into
            current working directory. Default is False.

    ymin -- Minimum y value. Defaults to letting the code choose.

    ymax -- Maximum y value. Defaults to letting the code choose.

    display -- Whether or not to show the plot. Default is False.    

    """
    if diag is None:
        if path is None:
            raise ValueError("Either path or diag must be non-none.")
        import hdf5_to_dict as io
        diag = io.load_diag(path)
    t = diag['t']
    q = diag[qname]
    if op is not None:
        q = op(q)
    if log:
        plt.semilogy(t, q)
    else:
        plt.plot(t, q)
    plt.xlabel('t (code units)')
    plt.ylabel(qname + ' (code units)')
    if ymin is not None or ymax is not None:
        if ymin is None:
            ymin = np.min(q)
        if ymax is None:
            ymin = np.max(q)
        plt.ylim(ymin, ymax)
    if save:
        for postfix in ['pdf', 'png']:
            plt.savefig(qname + '.' + postfix, bbox_inches='tight')
    if display:
        plt.show()
    return
Пример #2
0
def plot(args):
    n = args
    print '%08d / ' % (n + 1) + '%08d' % len(files)
    diag = io.load_diag(path)
    dump = io.load_dump(files[n], geom)
    #hdr = dump['hdr']
    fig = plt.figure(figsize=(FIGX, FIGY), frameon=False)
    ax = fig.gca()
    #ax = plt.subplot(1,1,1)

    x = geom['x']
    y = geom['y']
    z = geom['z']
    x = bplt.flatten_xz(x, hdr, flip=True)
    y = bplt.flatten_xz(y, hdr, flip=True)
    z = bplt.flatten_xz(z, hdr)

    # rcylindrical
    rcyl = np.sqrt(x**2 + y**2)

    lrho = bplt.flatten_xz(np.log10(dump['RHO']), hdr)
    mesh = ax.pcolormesh(rcyl[0:N1, 0:N2],
                         z[0:N1, 0:N2],
                         lrho[0:N1, 0:N2],
                         cmap='jet',
                         vmin=-4,
                         vmax=0,
                         shading='gouraud')
    cax = fig.add_axes([0.135, 0.15, 0.025, 0.7])
    cb = fig.colorbar(mesh, cax=cax, ticks=[-4, -2, 0])
    cb.set_label(label='Density', fontsize=20)
    cax.tick_params(axis='both', which='major', labelsize=20)

    lbeta = bplt.flatten_xz(np.log10(dump['beta']), hdr)
    mesh = ax.pcolormesh(rcyl[N1:, 0:N2],
                         z[N1:, 0:N2],
                         lbeta[N1:, 0:N2],
                         cmap='inferno',
                         vmin=-2,
                         vmax=2,
                         shading='gouraud')
    cax = fig.add_axes([0.865, 0.15, 0.025, 0.7])
    cb = fig.colorbar(mesh, cax=cax, ticks=[-2, 0, 2])
    cb.set_label(label='Plasma beta', fontsize=20)
    cb.ax.yaxis.set_label_position('left')
    cax.yaxis.set_ticks_position('left')
    cax.tick_params(axis='both', which='major', labelsize=20)

    ax.set_xlim([-4. / 3. * SIZE, 4. / 3. * SIZE])
    ax.set_ylim([-SIZE, SIZE])
    ax.set_xticks([])
    ax.set_yticks([])
    circle1 = plt.Circle((0, 0),
                         1. + np.sqrt(1. - hdr['a']**2),
                         color='k',
                         zorder=2)
    ax.add_artist(circle1)

    #ax.axvline(hdr['Risco'], color='k', linestyle='--', linewidth=2)
    #ax.axvline(-hdr['Risco'], color='k', linestyle='--', linewidth=2)

    bplt.overlay_field(ax,
                       geom,
                       dump,
                       linestyle='-',
                       linewidth=1,
                       linecolor='k',
                       NLEV=10)

    plt.savefig(os.path.join(FRAMEDIR, 'frame_%08d.png' % n),
                bbox_inches='tight',
                pad_inches=0,
                dpi=100)
    plt.close(fig)
Пример #3
0
    rho = dump['RHO'].mean()
    Te_code[n] = (hdr['gam'] - 1.) * uu * hdr['U_unit'] / (
        2. * rho * hdr['Ne_unit'] * cgs['KBOL'])
    #Te_code[n] = dump['Thetae'][0][0][0]*cgs['ME']*cgs['CL']**2/cgs['KBOL']

    #Te_code[n] = (hdr['gam']-1.)*dump['UU'][0,0,0]*hdr['U_unit']/(2.*dump['RHO']*hdr['Ne_unit']*cgs['KBOL'])
    R00 = -dump['Rmunu'][:, :, :, 0, 0].mean()
    Tr_code[n] = (R00 * hdr['U_unit'] / cgs['AR'])**(1. / 4.)
    #Tr2_code[n] = (-dump['Rmunu'][0,0,0,0,0]*hdr['U_unit']/cgs['AR'])**(1./4.)
    ne = rho * hdr['Ne_unit']
    #ne = dump['RHO'][0,0,0]*hdr['Ne_unit']
    Etot[n] = 2. * ne * cgs['KBOL'] * Te_code[n] / (
        hdr['gam'] - 1.) + cgs['AR'] * Tr_code[n]**4.
print(ne)
print('gam = %e' % hdr['gam'])
diag = io.load_diag(os.path.join(TMP_DIR, 'dumps/'), hdr=hdr)
print(diag['egas'] + diag['erad'])

# SEMIANALYTIC SOLUTION
from scipy.integrate import odeint
tf = 1.e3
t = np.logspace(-4, np.log10(tf), 1000)
nubins = 100
numin = 1.e13
numax = 1.e18
dlnu = (np.log(numax) - np.log(numin)) / nubins
nu = np.zeros(nubins)
for n in range(nubins):
    nu[n] = np.exp(np.log(numin) + (0.5 + n) * dlnu)

gamma_e = hdr['gam']
Пример #4
0
hdr = io.load_hdr(dumps[0])
geom = io.load_geom(hdr)

# Calculate jmin, jmax
ths = geom['th'][-1, :, 0]
for n in xrange(len(ths)):
    if ths[n] > THMIN:
        jmin = n
        break
for n in xrange(len(ths)):
    if ths[n] > THMAX:
        jmax = n
        break

diag = io.load_diag(path)

dx1 = hdr['dx1']
dx2 = hdr['dx2']
dx3 = hdr['dx3']
N1 = hdr['N1']
N2 = hdr['N2']
N3 = hdr['N3']

r = geom['r'][:, N2 / 2, 0]

ND = len(dumps)

t = np.zeros(ND)
rho_r = np.zeros([ND, N1])
Theta_r = np.zeros([ND, N1])
Пример #5
0
def plot(args):
    n = args
    print '%08d / ' % (n + 1) + '%08d' % len(files)
    diag = io.load_diag(path)
    dump = io.load_dump(files[n], geom)
    #hdr = dump['hdr']
    fig = plt.figure(figsize=(FIGX, FIGY))

    # GET SHELL AVERAGES
    Thetae_sadw = np.zeros(hdr['N1'])
    sigma = np.zeros(hdr['N1'])
    mdot = np.zeros(hdr['N1'])

    for i in xrange(hdr['N1']):
        vol = 0.
        for j in xrange(hdr['N2']):
            for k in xrange(hdr['N3']):
                Thetae_sadw[i] += dump['Thetae'][i, j, k] * dump['RHO'][
                    i, j,
                    k] * geom['gdet'][i,
                                      j] * hdr['dx1'] * hdr['dx2'] * hdr['dx3']
                sigma[i] += dump['RHO'][i, j, k] * hdr['dx2'] * geom['gdet'][i,
                                                                             j]
                mdot[i] += dump['RHO'][
                    i, j, k] * hdr['dx2'] * hdr['dx3'] * geom['gdet'][i, j]
                vol += dump['RHO'][i, j, k] * geom['gdet'][
                    i, j] * hdr['dx1'] * hdr['dx2'] * hdr['dx3']
        sigma[i] /= (hdr['N2'] * hdr['N3'])
        Thetae_sadw[i] /= vol

    ax = plt.subplot(3, 3, 1)
    bplt.plot_xz(ax,
                 geom,
                 np.log10(dump['RHO']),
                 dump,
                 vmin=-4,
                 vmax=0,
                 label='RHO',
                 ticks=[-4, -3, -2, -1, 0])
    ax.set_xlim([-SIZE, SIZE])
    ax.set_ylim([-SIZE, SIZE])
    ax.set_xticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])
    ax.set_yticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])

    ax = plt.subplot(3, 3, 2)
    bplt.plot_xz(ax,
                 geom,
                 np.log10(dump['Thetae']),
                 dump,
                 vmin=-2,
                 vmax=2,
                 label='Thetae',
                 cmap='RdBu_r',
                 ticks=[-2, -1, 0, 1, 2])
    ax.set_xlim([-SIZE, SIZE])
    ax.set_ylim([-SIZE, SIZE])
    ax.set_xticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])
    ax.set_yticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])

    ax = plt.subplot(3, 3, 3)
    ax.plot(geom['r'][:, 0, 0], sigma, color='b', label='Sigma')
    ax.set_xscale('log')
    ax.set_yscale('log')
    ax.set_xlim([1, SIZE])
    ax.set_ylim([1.e-2, 1.e2])
    ax.set_aspect(np.log(SIZE / 1) / np.log(1.e2 / 1.e-2))
    ax.plot(geom['r'][:, 0, 0], Thetae_sadw, color='r', label='SADW Thetae')
    ax.legend(loc=2, fontsize=10)
    ax.set_xlabel('r/M')

    ax = plt.subplot(3, 3, 4)
    bplt.plot_xy(ax,
                 geom,
                 np.log10(dump['RHO']),
                 dump,
                 vmin=-4,
                 vmax=0,
                 label='RHO',
                 ticks=[-4, -3, -2, -1, 0])
    ax.set_xlim([-SIZE, SIZE])
    ax.set_ylim([-SIZE, SIZE])
    ax.set_xticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])
    ax.set_yticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])

    ax = plt.subplot(3, 3, 5)
    bplt.plot_xy(ax,
                 geom,
                 np.log10(dump['Thetae']),
                 dump,
                 vmin=-2,
                 vmax=2,
                 label='Thetae',
                 cmap='RdBu_r',
                 ticks=[-2, -1, 0, 1, 2])
    ax.set_xlim([-SIZE, SIZE])
    ax.set_ylim([-SIZE, SIZE])
    ax.set_xticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])
    ax.set_yticks([-SIZE, -SIZE / 2, 0, SIZE / 2, SIZE])

    ax = plt.subplot(3, 1, 3)
    ax.plot(diag['t'], diag['mdot'], color='k')
    ax.axvline(dump['t'], color='k', linestyle='--')
    ax.set_xlim([0, dump['hdr']['tf']])
    ax.set_xlabel('t/M')
    ax.set_ylabel('mdot')
    ax2 = ax.twinx()
    ax2.set_ylabel('phi')

    plt.subplots_adjust(hspace=0.25)

    #ax.pcolormesh(dump['X1'][:,:,0], dump['X2'][:,:,0], dump['RHO'][:,:,0])
    plt.savefig(os.path.join(FRAMEDIR, 'frame_%08d.png' % n),
                bbox_inches='tight',
                dpi=100)
    plt.close(fig)
Пример #6
0
    print('  diag_summary.py [dumpfolder] [fluid/rad/perf]')
    sys.exit()

folder = sys.argv[1]
if not os.path.exists(folder):
    print('ERROR File ' + folder + ' does not exist!')
    sys.exit()

if sys.argv[2] in ['fluid', 'rad', 'perf']:
    mode = sys.argv[2]
else:
    print('ERROR supported modes are')
    print('  fluid rad perf')
    sys.exit()

diag = io.load_diag(folder)

if mode == 'perf':
    fig = plt.figure(figsize=(14, 12))

    vals = [
        'TIMER_UPDATE', 'TIMER_FLUXCALC', 'TIMER_FIXUP', 'TIMER_BOUND',
        'TIMER_DIAG', 'TIMER_OUT', 'TIMER_MAKE', 'TIMER_PUSH',
        'TIMER_INTERACT', 'TIMER_ALL'
    ]
    if diag['hdr']['ELECTRONS']:
        vals.append('TIMER_ELECTRON')
    for n, val in enumerate(vals):
        ax = fig.add_subplot(4, 3, n + 1)
        ax.plot(diag['t'], diag[val])
        ax.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))