Esempio n. 1
0
def get_data(directory):
    files = build_file_list(0, 1000000, path=directory + '/Shell_Avgs')
    a = Shell_Avgs(filename=files[-1], path='')

    nr = a.nr
    nq = a.nq
    nmom = 4
    niter = a.niter
    radius = a.radius
    savg = np.zeros((nr, nmom, nq), dtype='float64')
    for i in range(niter):
        savg[:, :, :] += a.vals[:, :, :, i]
    savg = savg * (1.0 / niter)

    lut = a.lut
    thermal = lut[501]

    return savg[:, 0, thermal], radius
Esempio n. 2
0
def main():
    from rayleigh_diagnostics import build_file_list
    from mpi4py import MPI
    import sys

    ###########################
    # Initialize Communication
    comm_world = MPI.COMM_WORLD
    my_rank = comm_world.rank
    ncpu = comm_world.size

    the_qindex = int(sys.argv[1])
    the_dpi = int(sys.argv[2])
    the_xypix = int(sys.argv[3])
    ttext = sys.argv[4]
    minval = float(sys.argv[5])
    maxval = float(sys.argv[6])
    ctext = sys.argv[7]

    if (my_rank == 0):
        print('')
        print('  Generating equatorial-slice movie frames.')
        print('')
        print('  ///// Parameters //////')
        print('  DPI: ', the_dpi)
        print('  XY-PIXELS: ', the_xypix)
        print('  QUANTITY CODE: ', the_qindex)
        print(' ')

    files = build_file_list(0, 1000000, path='Equatorial_Slices')

    gen_eq_movie(files,
                 my_rank,
                 ncpu,
                 quantity_code=the_qindex,
                 dpi=the_dpi,
                 xypix=the_xypix,
                 minval=minval,
                 maxval=maxval,
                 title_text=ttext,
                 cbar_text=ctext)
Esempio n. 3
0
def get_data(directory):
    files = build_file_list(0, 1000000,path=directory+'/G_Avgs')
    a = G_Avgs(filename=files[0],path='')

    nfiles = len(files)
    for i,f in enumerate(files):
        a = G_Avgs(filename=f,path='')
        if (i == 0):
            nq = a.nq
            niter = a.niter
            gavgs = np.zeros((niter*nfiles,nq), dtype='float64')
            iters = np.zeros((niter*nfiles), dtype='int32')
            time = np.zeros((niter*nfiles), dtype='float64')
        i0 = i*niter
        i1 = (i+1)*niter
        gavgs[i0:i1,:] = a.vals
        time[i0:i1] = a.time
        iters[i0:i1] = a.iters

    lut = a.lut
    ke  = lut[401]

    return gavgs[:,ke], time
Esempio n. 4
0
# We demonstrate how to compute the effective pressure force via post-processing in the example below.

# In[25]:

from rayleigh_diagnostics import Point_Probes,  build_file_list
import numpy
from matplotlib import pyplot as plt

#Decide which direction you want to look at (set direction = {radial,theta, or phi})
#This is used to determine the correct quantity codes below
radial = 0
theta  = 1
phi    = 2
direction=radial
# Build a list of all files ranging from iteration 0 million to 1 million
files = build_file_list(0,1000000,path='Point_Probes')
nfiles = len(files)-1


for i in range(nfiles):
    pp = Point_Probes(files[i],path='')
    if (i == 0):
        nphi = pp.nphi
        ntheta = pp.ntheta
        nr = pp.nr
        nq = pp.nq
        niter = pp.niter
        vals=numpy.zeros( (nphi,ntheta,nr,nq,niter*nfiles),dtype='float64')
        time=numpy.zeros(niter*nfiles,dtype='float64')
    vals[:,:,:,:, i*niter:(i+1)*niter] = pp.vals
    time[i*niter:(i+1)*niter]=pp.time
Esempio n. 5
0
# | 1468       |Radial Conductive Heat Flux |
#
#
# In the example that follows, we will plot the spherically-averaged velocity field as a function of radius, the mean temperature profile, and the radial heat flux.  We begin with a preamble similar to that used for the Global Averages.  Using the help function, we see that the Shell_Avgs data structure is similar to that of the G_Avgs.  There are three important differences:
# *  There is a radius attribute (necessary if we want to plot anything vs. radius)
# *  The dimensionality of the values array has changed;  radial index forms the first dimension.
# *  The second dimension of the values array has a length of 4.  In addition to the spherical mean, the 1st, 2nd and 3rd moments are stored in indices 0,1,2, and 3 respectively.

# In[8]:

from rayleigh_diagnostics import Shell_Avgs, build_file_list
import matplotlib.pyplot as plt
import numpy

# Build a list of all files ranging from iteration 0 million to 1 million
files = build_file_list(0, 1000000, path='Shell_Avgs')
a = Shell_Avgs(filename=files[0], path='')

#
# ***
#
# While it can be useful to look at instaneous snapshots of Shell Averages, it's often useful to examine these outputs in a time-averaged sense.    Let's average of all 200 snapshots in the last file that was output.  We could average over data from multiple files, but since the benchmark run achieves a nearly steady state, a single file will do in this case.

# In[9]:

nfiles = len(files)

nr = a.nr
nq = a.nq
nmom = 4
niter = a.niter
Esempio n. 6
0
#
#
# In the example that follows, we demonstrate how to plot azimuthal averages, including how to generate streamlines of mass flux.   Note that since the benchmark is Boussinesq, our velocity and mass flux fields are identical.  This is not the case when running an anelastic simulation.
#
# We begin with the usual preamble and also import two helper routines used for displaying azimuthal averages.
#
# Examining the data structure, we see that the vals array is dimensioned to account for latitudinal variation, and that we have new attributes costheta and sintheta used for referencing locations in the theta direction.

# In[13]:

from rayleigh_diagnostics import AZ_Avgs, build_file_list, plot_azav, streamfunction
import matplotlib.pyplot as plt
import pylab
import numpy
#from azavg_util import *
files = build_file_list(30000, 40000, path='AZ_Avgs')
az = AZ_Avgs(files[0], path='')

# ***
# Before creating our plots, let's time-average over the last two files that were output (thus sampling the equilibrated phase).

# In[14]:

nfiles = len(files)
tcount = 0
for i in range(nfiles):
    az = AZ_Avgs(files[i], path='')

    if (i == 0):
        nr = az.nr
        ntheta = az.ntheta
Esempio n. 7
0
# In[1]:

from rayleigh_diagnostics import G_Avgs, build_file_list
import matplotlib.pyplot as plt
import numpy

# The preamble for each plotting example will look similar to that above.  We import the numpy and matplotlib.pyplot modules, aliasing the latter to *plt*.   We also import two items from *rayleigh_diagnostics*: a helper function *build_file_list* and the *GlobalAverage* class.
#
# The *G_Avgs* class is the Python class that corresponds to the full-volume averages stored in the *G_Avgs* subdirectory of each Rayleigh run.
#
# We will use the build_file_list function in many of the examples that follow.  It's useful when processing a time series of data, as opposed to a single snapshot.  This function accepts three parameters: a beginning time step, an ending time step, and a subdirectory (path).  It returns a list of all files found in that directory that lie within the inclusive range [beginning time step, ending time step].  The file names are prepended with the subdirectory name, as shown below.

# In[2]:

# Build a list of all files ranging from iteration 0 million to 1 million
files = build_file_list(0, 1000000, path='G_Avgs')
print(files)

# We can create an instance of the G_Avgs class by initializing it with a filename.  The optional keyword parameter *path* is used to specify the directory.  If *path* is not specified, its value will default to the subdirectory name associated with the datastructure (*G_Avgs* in this instance).
#
# Each class was programmed with a **docstring** describing the class attributes.   Once you created an instance of a rayleigh_diagnostics class, you can view its attributes using the help function as shown below.

# In[3]:

a = G_Avgs(filename=files[0], path='')  # Here, files[0]='G_Avgs/00010000'
#a= G_Avgs(filename='00010000') would yield an equivalent result

#help(a)

# Examining the docstring, we see a few important attributes that are common to the other outputs discussed in this document:
# 1.  niter -- the number of time steps in the file
Esempio n. 8
0
def main():

    helicity_type = 1

    saveplot = True
    tindex = -1
    phi_index = 0

    if (helicity_type == 1):  # full
        vr_index = 1
        vt_index = 2
        vp_index = 3
        wr_index = 301
        wt_index = 302
        wp_index = 303
        hr_index = 324
        ht_index = 325
        hp_index = 326
        helicity = 339
        print("full helicity check")
    elif (helicity_type == 2):  # u-prime, w-mean
        vr_index = 4
        vt_index = 5
        vp_index = 6
        wr_index = 307
        wt_index = 308
        wp_index = 309
        hr_index = 336
        ht_index = 337
        hp_index = 338
        helicity = 343
        print("prime-mean helicity check")
    elif (helicity_type == 3):  # u-mean, w-prime
        vr_index = 7
        vt_index = 8
        vp_index = 9
        wr_index = 304
        wt_index = 305
        wp_index = 306
        hr_index = 333
        ht_index = 334
        hp_index = 335
        helicity = 342
        print("mean-prime helicity check")
    elif (helicity_type == 4):  # u-mean, w-mean
        vr_index = 7
        vt_index = 8
        vp_index = 9
        wr_index = 307
        wt_index = 308
        wp_index = 309
        hr_index = 330
        ht_index = 331
        hp_index = 332
        helicity = 341
        print("mean-mean helicity check")
    elif (helicity_type == 5):  # u-prime, w-prime
        vr_index = 4
        vt_index = 5
        vp_index = 6
        wr_index = 304
        wt_index = 305
        wp_index = 306
        hr_index = 327
        ht_index = 328
        hp_index = 329
        helicity = 340
        print("prime-prime helicity check")

    # build file list and get data
    files = build_file_list(0, 10000000, path="./Meridional_Slices/")
    F = Meridional_Slices(filename=files[-1], path='')

    radius = F.radius
    costh = F.costheta
    sinth = F.sintheta

    # extract data
    vr = F.vals[phi_index, :, :, F.lut[vr_index], tindex]
    vt = F.vals[phi_index, :, :, F.lut[vt_index], tindex]
    vp = F.vals[phi_index, :, :, F.lut[vp_index], tindex]
    wr = F.vals[phi_index, :, :, F.lut[wr_index], tindex]
    wt = F.vals[phi_index, :, :, F.lut[wt_index], tindex]
    wp = F.vals[phi_index, :, :, F.lut[wp_index], tindex]
    hr = F.vals[phi_index, :, :, F.lut[hr_index], tindex]
    ht = F.vals[phi_index, :, :, F.lut[ht_index], tindex]
    hp = F.vals[phi_index, :, :, F.lut[hp_index], tindex]
    hel = F.vals[phi_index, :, :, F.lut[helicity], tindex]

    # True value
    hr_T = vr * wr
    ht_T = vt * wt
    hp_T = vp * wp
    hel_T = hr_T + ht_T + hp_T

    # setup grid
    fig = plt.figure(1, dpi=100, figsize=(9, 9))
    Grid = gridspec.GridSpec(ncols=3, nrows=4)

    ax = fig.add_subplot(Grid[0, 0])
    plot_azav(fig,
              ax,
              hr_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Radial True")

    ax = fig.add_subplot(Grid[1, 0])
    plot_azav(fig,
              ax,
              ht_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Theta True")

    ax = fig.add_subplot(Grid[2, 0])
    plot_azav(fig,
              ax,
              hp_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Phi True")

    ax = fig.add_subplot(Grid[3, 0])
    plot_azav(fig,
              ax,
              hel_T,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Total True")

    ax = fig.add_subplot(Grid[0, 1])
    plot_azav(fig,
              ax,
              hr,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Radial Diag")

    ax = fig.add_subplot(Grid[1, 1])
    plot_azav(fig,
              ax,
              ht,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Theta Diag")

    ax = fig.add_subplot(Grid[2, 1])
    plot_azav(fig,
              ax,
              hp,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Phi Diag")

    ax = fig.add_subplot(Grid[3, 1])
    plot_azav(fig,
              ax,
              hel,
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Total Diag")

    ax = fig.add_subplot(Grid[0, 2])
    plot_azav(fig,
              ax,
              np.abs(hr_T - hr),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Radial Error")
    print("Max error, radial", np.amax(np.abs(hr_T - hr)))

    ax = fig.add_subplot(Grid[1, 2])
    plot_azav(fig,
              ax,
              np.abs(ht_T - ht),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Theta Error")
    print("Max error, theta", np.amax(np.abs(ht_T - ht)))

    ax = fig.add_subplot(Grid[2, 2])
    plot_azav(fig,
              ax,
              np.abs(hp_T - hp),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Phi Error")
    print("Max error, phi", np.amax(np.abs(hp_T - hp)))

    ax = fig.add_subplot(Grid[3, 2])
    plot_azav(fig,
              ax,
              np.abs(hel_T - hel),
              radius,
              costh,
              sinth,
              mycmap='RdYlBu_r',
              boundsfactor=4.5,
              boundstype='rms')
    ax.set_title("Total Error")
    print("Max error, total", np.amax(np.abs(hel_T - hel)))

    fig.tight_layout()

    if (saveplot):
        output = "test_helicity_{}.png".format(helicity_type)
        plt.savefig(output, bbox_inches='tight', dpi=300)
    else:
        plt.show()
Esempio n. 9
0
# | 2        | 0,1,2 |
# | 4        | 0,1,2,3,4 |
# | 8        | 0,1,2,3,4,5,6,7,8 |
#
#

# In[26]:

from rayleigh_diagnostics import SPH_Modes, build_file_list
import matplotlib.pyplot as plt
import numpy

qind = 1  # Radial velocity
rind = 0  # First radius stored in file

files = build_file_list(0, 1000000, path='SPH_Modes')
nfiles = len(files)
for i in range(nfiles):
    spm = SPH_Modes(files[i], path='')
    if (i == 0):
        nell = spm.nell
        nr = spm.nr
        nq = spm.nq
        niter = spm.niter
        lvals = spm.lvals
        max_ell = numpy.max(lvals)
        nt = niter * nfiles
        vr = spm.lut[qind]
        vals = numpy.zeros((max_ell + 1, nell, nr, nq, nt), dtype='complex64')
        time = numpy.zeros(nt, dtype='float64')
    vals[:, :, :, :, i * niter:(i + 1) * niter] = spm.vals
Esempio n. 10
0
my_rank = comm_world.rank
ncpu = comm_world.size
this_batch = int(sys.argv[1])
nbatch = int(sys.argv[2])

if (len(sys.argv) > 3):
    qindex = int(sys.argv[3])
else:
    qindex = 1

if (len(sys.argv) > 4):
    hsize = float(sys.argv[4])
else:
    hsize = 0.005

files = build_file_list(0, 1000000, path='Shell_Slices')
nfiles = len(files)

dfile = nfiles / nbatch
file_mod = nfiles % nbatch
fstart = dfile * (this_batch - 1)
fend = fstart + dfile

#Add any leftovers to the last batch
if (this_batch == nbatch):
    if (file_mod != 0):
        fend = fend + file_mod

files = files[fstart:fend]

if (my_rank == 0):
Esempio n. 11
0
    print(records[5] + ": " + str(kappa))

    return rmin, rmax, luminosity, cp, nu, kappa, omega

# Loop over several subdirectories and extract values from each main_input file.
for i in dirlist:
    os.chdir(rootdir + "/" + i)
    print()
    print("Working directory: " + os.getcwd())

    # Define variables
    rmin, rmax, luminosity, cp, nu, kappa, omega = extract_input('main_input') 
 
    b = ReferenceState(filename='', path='reference')
    # Change values to get Shell_Avgs at different times
    files = build_file_list(400000,500000, path='Shell_Avgs')
    c = Shell_Avgs(filename=files[0], path='')

    nfiles = len(files)

    nr = c.nr
    nq = c.nq 
    nmom = 4
    niter = c.niter
    radius = c.radius
    savg = np.zeros((nr,nmom,nq),dtype='float64')
    for i in range(niter):
        savg[:,:,:] += c.vals[:,:,:,i]
    savg = savg*(1.0/niter)

    lut = c.lut