示例#1
0
def ReadMoment_Zeroth(filename, Dir, iSpecies=1):
    # read moment J from chk as a functionn of energy
    import numpy as np
    import flashytlib.io as fyio
    import flashytlib.io_basis as fyiobasis
    import flashytlib.calculator as fycal

    nNodeE = 2  # default and only avaliable @ Mar.20
    # read in chk and determine nPointsE
    nPointsE = 0
    nPointsE = int(fyio.IO_FLASH_nPointsE(filename))
    [eL, eR, zoomE] = fyiobasis.IO_CheckESetting(Dir + '/flash.par', False)
    Radius = fyio.IO_FLASH_1D_1Var(filename, 'r_cm', False)
    nPointsX = len(Radius)
    J_PhaseSpace_Nodes = np.zeros([nPointsX, nPointsE * nNodeE])
    J_PhaseSpace_SubCE = np.zeros([nPointsX, nPointsE])
    J_str = nPointsE * nNodeE * ['']
    for i in range(nPointsE * nNodeE):
        J_str[i] = 't' + '{:03d}'.format(i + 1 + (nPointsE * nNodeE) * 4 *
                                         (iSpecies - 1))
        J_PhaseSpace_Nodes[:,
                           i] = fyio.IO_FLASH_1D_1Var(filename, J_str[i],
                                                      False)
    for ix in range(nPointsX):
        for ie in range(nPointsE):
            J_PhaseSpace_SubCE[ix, ie] = fycal.CellAve_Gaussian(
                J_PhaseSpace_Nodes[ix, ie * nNodeE:ie * nNodeE + 2])

    NumberDensity = np.zeros([nPointsX])
    EnergyDensity = np.zeros([nPointsX])
    # default Energy Grid setting

    [Ecenter, Ewidth,
     Enodes] = fycal.CreateGeometricMesh(nPointsE, nNodeE, eL, eR, zoomE)

    const = 4.0 * np.pi
    for ix in range(nPointsX):
        NumberDensity[ix] = const * fycal.TrapezoidalIntegral(
            Ecenter, J_PhaseSpace_SubCE[ix], 2.)
        # 2. => energy ** 2
        EnergyDensity[ix] = const * fycal.TrapezoidalIntegral(
            Ecenter, J_PhaseSpace_SubCE[ix], 3.)
        # 3. => energy ** 3

    AverageEnergy = np.true_divide(EnergyDensity, NumberDensity)

    return (NumberDensity, EnergyDensity, AverageEnergy, J_PhaseSpace_SubCE,
            Ecenter, Radius)
示例#2
0
def plt_1D_Eos_multi(filenames, optional_title='', optional_legend=''):
    import flashytlib.io as fyio
    import matplotlib.pyplot as plt
    import flashytlib.plot_basis as fypltb

    # loading density, temperature, electron fraction
    nfile = len(filenames)
    plotvariables = ['r_cm', 'dens', 'temp', 'ye  ']
    nvar = len(plotvariables) * nfile
    var_data = nvar * ['?']
    ivar = 0

    for var_name in plotvariables:
        for ifile in range(nfile):
            buffdata = fyio.IO_FLASH_1D_1Var(filenames[ifile],
                                             var_name,
                                             Verbose=False)
            var_data[ivar] = buffdata
            ivar = ivar + 1

    fypltb.plt_Eos_DTY( \
                       var_data[0:nfile], \
                       var_data[nfile:2*nfile], \
                       var_data[2*nfile:3*nfile],\
                       var_data[3*nfile:4*nfile], \
                       optional_title, nfile = nfile, \
                       optional_legend = optional_legend )
示例#3
0
def ReadMoment_First(filename, Dir, iSpecies=1):
    # read moment H1 from chk as a functionn of energy
    import numpy as np
    import flashytlib.io as fyio
    import flashytlib.io_basis as fyiobasis
    import flashytlib.calculator as fycal

    nNodeE = 2  # default and only avaliable @ Mar.20
    # read in chk and determine nPointsE
    nPointsE = 0
    nPointsE = int(fyio.IO_FLASH_nPointsE(filename))
    [eL, eR, zoomE] = fyiobasis.IO_CheckESetting(Dir + '/flash.par', False)

    Radius = fyio.IO_FLASH_1D_1Var(filename, 'r_cm', False)
    nPointsX = len(Radius)
    H1_PhaseSpace_Nodes = np.zeros([nPointsX, nPointsE * nNodeE])
    H1_PhaseSpace_SubCE = np.zeros([nPointsX, nPointsE])
    H1_str = nPointsE * nNodeE * ['']
    for i in range(nPointsE * nNodeE):
        H1_str[i] = 't' + '{:03d}'.format(i + 1 + nPointsE * nNodeE +
                                          (nPointsE * nNodeE) * 4 *
                                          (iSpecies - 1))
        H1_PhaseSpace_Nodes[:,
                            i] = fyio.IO_FLASH_1D_1Var(filename, H1_str[i],
                                                       False)
    for ix in range(nPointsX):
        for ie in range(nPointsE):
            H1_PhaseSpace_SubCE[ix, ie] = fycal.CellAve_Gaussian(
                H1_PhaseSpace_Nodes[ix, ie * nNodeE:ie * nNodeE + 2])

    Luminosity = np.zeros([nPointsX])
    FluxDensity = np.zeros([nPointsX])

    [Ecenter, Ewidth,
     Enodes] = fycal.CreateGeometricMesh(nPointsE, nNodeE, eL, eR, zoomE)

    const = 4.0 * np.pi
    for ix in range(nPointsX):
        FluxDensity[ix] = const * fycal.TrapezoidalIntegral(
            Ecenter, H1_PhaseSpace_SubCE[ix], 3.)
        # 3. => energy ** 3
        Luminosity[ix] = const * Radius[ix] * Radius[ix] * FluxDensity[ix]

    return (FluxDensity, Luminosity, H1_PhaseSpace_SubCE, Ecenter, Radius)
示例#4
0
def plt_1D_Eos(filename, optional_title=''):
    import flashytlib.io as fyio
    import matplotlib.pyplot as plt
    import flashytlib.plot_basis as fypltb

    # loading density, temperature, electron fraction
    plotvariables = ['r_cm', 'dens', 'temp', 'ye  ']
    nvar = len(plotvariables)
    var_data = nvar * ['?']
    ivar = 0
    for var_name in plotvariables:
        buffdata = fyio.IO_FLASH_1D_1Var(filename, var_name, Verbose=False)
        var_data[ivar] = buffdata
        ivar = ivar + 1

    fypltb.plt_Eos_DTY(var_data[0], var_data[1], var_data[2], var_data[3],
                       optional_title)
示例#5
0
def plt_1D_NuclearComprehensive(chkfilename, weaklibTabDir):
    import flashytlib.io as fyio
    import matplotlib.pyplot as plt

    print('flash5   chk :', chkfilename)

    [eosfile, opfiles] = fyio.IO_CheckWeaklibFile(weaklibTabDir, Verbose=False)

    # loading density, temperature, electron fraction
    plotvariables = ['r_cm', 'dens', 'temp', 'ye  ']
    nvar = len(plotvariables)
    var_data = nvar * ['?']
    ivar = 0
    for var_name in plotvariables:
        buffdata = fyio.IO_FLASH_1D_1Var(chkfilename, var_name, Verbose=False)
        var_data[ivar] = buffdata
        ivar = ivar + 1

    fig = plt.figure(num=None,
                     figsize=(12, 8),
                     dpi=80,
                     facecolor='w',
                     edgecolor='k')

    # === 1 == rho-temp-ye plot ===== #
    ax1 = fig.add_subplot(2, 2, 1)
    # --- density ---
    color = 'tab:red'
    ax1.set_xlabel('Radius [cm]')
    ax1.set_ylabel('Density [g cm-3] / Temperature [K]', color=color)
    lns1 = ax1.plot(var_data[0], var_data[1], color=color, label='Density')
    ax1.set_yscale('log')
    ax1.tick_params(axis='y', labelcolor=color)
    # --- temperature
    color = 'tab:green'
    lns2 = ax1.plot(var_data[0], var_data[2], color=color, label='Temperature')
    # --- electron fraction
    ax2 = ax1.twinx()  # instantiate a second axes that shares the same x-axis
    color = 'tab:blue'
    ax2.set_ylabel('Electron Fraction',
                   color=color)  # we already handled the x-label with ax1
    lns3 = ax2.plot(var_data[0],
                    var_data[3],
                    color=color,
                    label='Electron Fraction')
    ax2.tick_params(axis='y', labelcolor=color)
    # -- finalize
    time = fyio.IO_FLASH_Time(chkfilename)
    plt.title(' t = %.4f' % (time) + 's ')
    fig.tight_layout()  # otherwise the right y-label is slightly clipped
    lns = lns1 + lns2 + lns3
    labs = [l.get_label() for l in lns]
    ax1.legend(lns, labs, loc='right')

    ax2 = fig.add_subplot(2, 2, 2)

    ax3 = fig.add_subplot(2, 2, 3)
    ax4 = fig.add_subplot(2, 2, 4)

    # ===== adjust ===== #
    plt.subplots_adjust(
        left=0.125,  # the left side of the subplots of the figure
        right=0.9,  # the right side of the subplots of the figure
        bottom=0.1,  # the bottom of the subplots of the figure
        top=0.9,  # the top of the subplots of the figure
        wspace=0.4,  # the amount of width reserved for space between subplots,
        hspace=0.4)  # the amount of height reserved for space between subplots
    plt.show()