Ejemplo n.º 1
0
def time_series_plot(eps_filename, results_dir, times, field = 'density',
                     zlim = [1e-4, 1e8], nrows = 3, ncols = 3, smallplt = False,
                     colormap = 'hot', zoom = 1.0, xticks = None, yticks = None):
    """Make a time series plot of the density."""

    if not is_root():
        return

    import os

    if os.path.isfile(eps_filename):
        return

    if not os.path.exists(results_dir):
        return

    print "Generating plot with filename " + eps_filename

    directory = results_dir + '/output/'
    pltfiles = [directory + plt for plt in wdmerger.get_plotfiles(directory)]

    wdmerger.multipanel_slice_plot(field, eps_filename,
                                   [wdmerger.get_nearest_plotfile(pltfiles, time) for time in times],
                                   nrows = nrows, ncols = ncols,
                                   annotate_time = True,
                                   zlim = zlim,
                                   zoom = zoom,
                                   xticks = xticks,
                                   yticks = yticks,
                                   colormap = colormap
                                  )
Ejemplo n.º 2
0
def collision_time(results_dir):
    """Calculate the time of the collision."""

    out_file = results_dir + '/collision_time.txt'

    if os.path.isfile(out_file):
        return

    print("Calculating collision time in directory " + results_dir)

    import yt

    # Load all the output files in the output directory.
    # Search them one by one (in reverse) until we find
    # the time where the density threshold is crossed
    # at the center of the simulation.

    density_threshold = 1.0e2

    plots = wdmerger.get_plotfiles(results_dir, prefix='smallplt')
    plots.reverse()

    if (plots == []) or (plots == None):
        return

    for i, plot in enumerate(plots):

        ds = yt.load(results_dir + '/output/' + plot)

        # Get a region that is only one coarse zone-width wide

        dx = ds.domain_width / ds.domain_dimensions

        sph = ds.sphere([0.0, 0.0, 0.0], max(dx))

        # Find the maximum density in that region

        rho_max = sph.max("density")

        if rho_max < density_threshold:
            idx = i - 1
            break

    ds = yt.load(results_dir + '/output/' + plots[idx])

    file = open(out_file, 'w')

    file.write(str(ds.current_time.v))

    file.close()
Ejemplo n.º 3
0
def vol_renders():
    """Volume render the simulations."""

    import os
    import yt
    yt.enable_parallelism()

    results_base = 'results/approximate/'
    plots_base = 'plots/'

    for mass_P in ['0.90']:
        for mass_S in ['0.60', '0.90']:
            for roche in ['0.90', '1.00']:
                for rot in ['0', '1']:
                    for hybrid in ['0', '1']:
                        for ncell in ['256', '512', '1024']:

                            mass_string = "_m_P_" + mass_P + "_m_S_" + mass_S

                            results_dir = 'mass_P_' + mass_P + '/mass_S_' + mass_S + '/roche' + roche + '/rot' + rot + '/hybrid' + hybrid + '/n' + ncell + '/'

                            output_dir = results_base + results_dir + '/output/'

                            if not os.path.exists(output_dir):
                                continue

                            plot_list = wdmerger.get_plotfiles(output_dir, prefix='smallplt')

                            plot_list = [output_dir + plot for plot in plot_list]

                            plot_dir = plots_base + results_dir

                            if not os.path.exists(plot_dir) and is_root():
                                os.makedirs(plot_dir)

                            ts = yt.DatasetSeries(plot_list)

                            for ds in ts.piter():

                                pltname = ds.basename

                                outfile_name = plot_dir + 'approximate' + mass_string + '_roche_' + roche + '_rot_' + rot + '_hybrid_' + hybrid + '_n_' + ncell + '_' + pltname + '.png'

                                if os.path.isfile(outfile_name):
                                    continue

                                wdmerger.vol_render_density(outfile_name, ds)
Ejemplo n.º 4
0
def amr_ignition(file_base, results_base, do_amr=True):
    """Plot the effect of the resolution on the detonation conditions."""

    if not os.path.isdir(results_base):
        return

    size = 1.6384e9

    ncell_list = sorted([int(n[1:]) for n in os.listdir(results_base)])

    res_lists = [[]] * len(ncell_list)
    dist_lists = [[]] * len(ncell_list)
    time_lists = [[]] * len(ncell_list)

    base_res_list = []

    for i, ncell in enumerate(ncell_list):

        base_res_list.append(size / ncell / 1.e5)

        dir = results_base + '/n' + str(ncell)

        if not os.path.isdir(dir):
            continue

        # Generate a plot of the distance from the center of the ignition point,
        # and also the time of the ignition.

        # Get the list of refinement values we have tried.

        r_list = wdmerger.get_parameter_list(dir)

        if (r_list == []):
            continue

        # Sort them numerically.

        r_list = ['r' + str(r) for r in sorted([int(r[1:]) for r in r_list])]

        # Cycle through the plot files.
        # Get the distance from the origin of the point where T > 4e9 K, if it exists.

        zonesPerDim = []
        res_list = []
        dist_list = []
        time_list = []

        for r in r_list:
            results_dir = results_base + '/n' + str(ncell) + '/' + r

            if not os.path.isdir(results_dir):
                continue

            print('Searching in directory ' + results_dir)

            prefix = 'det_x_plt'
            plot_list = [
                results_dir + '/output/' + plot
                for plot in wdmerger.get_plotfiles(results_dir, prefix=prefix)
            ]

            # Since we'll have stopped after the ignition has occurred,
            # we'll search through the plotfiles backward.

            T_max = -1.0
            T_last = -1.0

            for plot in reversed(plot_list):

                [T_max, x, y, z] = wdmerger.get_maxloc(plot, 'Temp')

                if (T_max < 4.0e9 and T_last >= 4.0e9) or (T_max >= 4.0e9
                                                           and T_last < 0.0):
                    dist = abs(x.v) / 1.0e5
                    time = wdmerger.get_time_from_plotfile(plot)

                    zonesPerDim.append(ncell * int(r[1:]))

                    ds = yt.load(plot)
                    problo = ds.domain_left_edge.v
                    probhi = ds.domain_right_edge.v
                    size = probhi[0] - problo[0]

                    res_list.append(size / (ncell * int(r[1:])) / 1.0e5)
                    dist_list.append(dist)
                    time_list.append(time)

                    break

                else:
                    T_last = T_max

            res_lists[i] = res_list
            dist_lists[i] = dist_list
            time_lists[i] = time_list

    # Plot location of the ignition and time on the same axis.
    # We want to combine data at low resolution using their coarse
    # grid runs, with the AMR data at the highest resolution.

    res_list = []
    dist_list = []
    time_list = []

    for i in range(len(ncell_list) - 1):
        res_list.append(res_lists[i][0])
        dist_list.append(dist_lists[i][0])
        time_list.append(time_lists[i][0])

    for res in res_lists[-1]:
        res_list.append(res)

    for dist in dist_lists[-1]:
        dist_list.append(dist)

    for time in time_lists[-1]:
        time_list.append(time)

    fig, ax1 = plt.subplots()
    ax1.plot(res_list,
             dist_list,
             linestyle=linestyles[0],
             marker=markers[0],
             color=colors[0],
             lw=2.0,
             label='Ignition location')

    ax1.set_xscale('log', basex=10)
    ax1.set_xlabel(r"Finest resolution (km)", fontsize=24)
    ax1.set_ylabel(r"Ignition location (km)", fontsize=24, color=colors[0])
    ax1.tick_params(axis='y', labelcolor=colors[0], labelsize=16)
    ax1.tick_params(axis='x', labelsize=16)
    ax1.set_ylim(bottom=0.0)

    ax2 = ax1.twinx()
    ax2.plot(res_list,
             time_list,
             linestyle=linestyles[1],
             marker=markers[1],
             color=colors[1],
             lw=2.0,
             label='Ignition time')
    ax2.set_ylabel(r"Ignition time (s)", fontsize=24, color=colors[1])
    ax2.tick_params(axis='y', labelcolor=colors[1], labelsize=16)
    ax2.set_ylim(bottom=0.0)

    fig.set_size_inches(11, 8.5)
    fig.tight_layout()
    plt.savefig(file_base + '.eps')
    plt.savefig(file_base + '.png')

    plt.close()
Ejemplo n.º 5
0
def rho_T_sliceplots(output_base,
                     results_base,
                     smallplt=True,
                     prefix="",
                     domain_frac=1.0,
                     x_ticks=[2.0e9, 4.0e9],
                     y_ticks=[2.0e9, 4.0e9],
                     scale_exp=9):
    """Create a rho/T sliceplot for every plotfile in a given directory."""

    import os

    if not os.path.isdir(output_base):
        os.makedirs(output_base)

    from PIL import Image

    if (smallplt):
        plt_prefix = 'smallplt'

    r_list = wdmerger.get_parameter_list(results_base)

    # Strip out the non-refinement directories

    r_list = [r for r in r_list if r[0] == 'r']

    if (r_list == []):
        return

    dir_list = [results_base + r + '/output/' for r in r_list]

    for param, directory in zip(r_list, dir_list):

        output_dir = output_base + param

        if not os.path.isdir(output_dir):
            os.makedirs(output_dir)

        plt_list = wdmerger.get_plotfiles(directory, plt_prefix)
        eps_list = [
            output_dir + "/rho_T_slice" + prefix + "_" + param + "_t_" +
            str("%.2f" % wdmerger.get_time_from_plotfile(directory + pltfile))
            + '.eps' for pltfile in plt_list
        ]

        # Generate the plot

        for eps_file, pltfile in zip(eps_list, plt_list):

            if os.path.isfile(eps_file):
                continue

            print("Generating plot with filename " + eps_file)

            wdmerger.rho_T_sliceplot(eps_file,
                                     directory + pltfile,
                                     domain_frac=domain_frac,
                                     x_ticks=x_ticks,
                                     y_ticks=y_ticks,
                                     scale_exp=scale_exp)

        jpg_list = [eps.replace('eps', 'jpg') for eps in eps_list]

        mpg_filename = output_dir + "/rho_T_slice" + prefix + "_" + param + ".mpg"

        if not os.path.isfile(mpg_filename):
            print("Generating file %s" % mpg_filename)
            wdmerger.make_movie(output_dir, jpg_list, mpg_filename)
Ejemplo n.º 6
0
def amr_detonation(eps_filename, results_base):
    """Plot the effect of the refinement based on the nuclear burning rate on the detonation conditions."""

    import os

    if os.path.isfile(eps_filename):
        return
    else:
        print("Generating file %s" % eps_filename)

    import math
    import numpy as np
    from matplotlib import pyplot as plt

    if not os.path.isdir(results_base):
        return

    diag_file = None

    # First, generate a plot of nickel production.

    ncell_list = sorted([int(n[1:]) for n in os.listdir(results_base)])

    # Now, generate a plot of the distance from the center of the ignition point.

    i = 0

    for ncell in ncell_list:

        results_dir = results_base + 'n' + str(ncell) + '/self-heat/dxnuc/'

        if not os.path.isdir(results_dir):
            continue

        # Get the list of parameter values we have tried

        r_list = wdmerger.get_parameter_list(results_dir)

        # Strip out the non-refinement directories

        r_list = [r for r in r_list if r[0] == 'r']

        if (r_list == []):
            continue

        # Sort them numerically.

        r_list = ['r' + str(r) for r in sorted([int(r[1:]) for r in r_list])]

        # Cycle through the plot files.
        # Get the maximum value of t_sound_t_enuc, and its distance from the origin.
        # Stop if we hit a detonation (t_sound_t_enuc > 1).

        for r in r_list:
            results_dir = results_base + 'n' + str(
                ncell) + '/self-heat/dxnuc/' + r

            prefix = 'smallplt'
            plt_list = [
                results_dir + '/output/' + plt
                for plt in wdmerger.get_plotfiles(results_dir, prefix=prefix)
            ]

            for plt in plt_list:
                [ts_te_max, x, y,
                 z] = wdmerger.get_maxloc(plt, 't_sound_t_enuc')

                if ts_te_max > 1.0:
                    [rho_max, x, y, z] = wdmerger.get_maxloc(plt, 'density')
                    dist = np.sqrt(x**2 + y**2)
                    time = wdmerger.get_time_from_plotfile(plt)
                    print(ncell, r, time, rho_max, ts_te_max, dist.v / 1.e5)

                    break

        i += 1
Ejemplo n.º 7
0
                # Generate the plot name, and skip this iteration if it already exists.

                eps_filename = plots_dir + 'kh_t' + str(t) + '_p' + str(problem) + '_v' + str(v) + '_n' + str(ncell) + '.eps'

                if (os.path.isfile(eps_filename)):
                    print "Plot with filename " + eps_filename + " already exists; skipping."
                    continue

                print "Generating plot with filename " + eps_filename

                # First we load in the numerical data.

                # Get the list of plotfiles in the directory.

                plotfiles = wdmerger.get_plotfiles(dir)

                # Figure out which one in the list we want by searching through
                # and checking the Header file. We'll take the first plotfile 
                # after the desired time.

                plotfile_times = np.zeros(len(plotfiles))

                for n in range(len(plotfiles)):                
                    plotfile_times[n] = wdmerger.get_time_from_plotfile(dir + '/' + plotfiles[n])

                for n in range(len(plotfile_times)):

                    index = n

                    time_curr = plotfile_times[n]