Exemple #1
0
else:  # nothing given
    print("read_parts error: Invalid commandline arguments.")
    print("Usage: ")
    print("   ./read_parts.py <./path/to/sim/output> <start_time>")
    print(" or")
    print("   ./read_parts.py <./path/to/sim/output>")
    sys.exit()

# initialize the reader
times = bbparts.init(data_dir)

# visit all outputted time values
for time in times:
    # open the CGNS file for this particular output time
    bbparts.open(time)

    # read the CGNS file
    t = bbparts.read_time()
    n = bbparts.read_nparts()
    (x, y, z) = bbparts.read_part_position()
    (u, v, w) = bbparts.read_part_velocity()

    print("time = ", time, "t =", t, "n =", n)

    print(u)
    sys.exit()

    # close the CGNS file
    bbparts.close()
nparts = bbparts.read_nparts()
bbparts.close()

# Init data arays
u = np.zeros((len(times), nparts))
v = np.zeros((len(times), nparts))
w = np.zeros((len(times), nparts))
t = np.zeros(len(times))

# Loop over time and pull data
for tt, time in enumerate(times):
    bbparts.open(time)

    t[tt] = bbparts.read_time()

    (u[tt, :], v[tt, :], w[tt, :]) = bbparts.read_part_velocity()

    #print(np.mean(u[tt,:]), np.mean(v[tt,:]), np.mean(w[tt,:]))

    bbparts.close()

# Plot
fig = plt.figure()

ax1 = fig.add_subplot(311)
plt.plot(t, u)
plt.plot(t, np.mean(u, 1), 'ko-')
plt.xlabel("$t$")
plt.ylabel("$u$")

ax1 = fig.add_subplot(312)
    nt = round(len(timeseries)/100) + 1

  # close this output
  bb.close()

# overwrite number of time outputs to read (for testing)
#nt = 10
#t_end = 21

####################################################################
# store particle position data at initial time t_init
####################################################################

timeseries = bb.init(ensemble[-1] + "/output")[int(timestart/DT_out):]
bb.open(timeseries[0])  # using time step 0 for now
(U_init, V_init, W_init) = bb.read_part_velocity()
T_init = bb.read_time()
np = len(U_init)  # also store particle number
bb.close()

# create particle lists
# current particle velocity
U = numpy.zeros(np)
V = numpy.zeros(np)
W = numpy.zeros(np)
# mean square displacements
uCOR = numpy.zeros((nt,np))
vCOR = numpy.zeros((nt,np))
wCOR = numpy.zeros((nt,np))
# mean for each particle
umean = numpy.zeros(np)
Exemple #4
0
#!/usr/bin/env python

# bluebottle_particle_reader python module example code

import sys, getopt
import numpy as np
import bluebottle_particle_reader as bb

# initialize the reader
times = bb.init("/home/asiera/bluebottle/sim/output")

# visit all outputted time values
for time in times:
  # open the CGNS file for this particular output time
  bb.open(time)

  # read the CGNS file
  t = bb.read_time()
  (x,y,z) = bb.read_part_position()
  (u,v,w) = bb.read_part_velocity()

  print("t =", t)

  # close the CGNS file
  bb.close()
  tind = 0 # time index
  # read all time outputs in timeseries
  for time in timeseries:
    # tell user where we are
    #print("\rrealization", rcount, "of", len(ensemble), ": time =", time, "of",
    #  round(t_end, 2), "(" + str(round(percent)) + "%)    ", end='')
    print("realization", rcount, "of", len(ensemble), ": time =", time, "of",
      round(t_end, 2), "(" + str(round(percent)) + "%)    ")
    sys.stdout.flush()

    # open and process each time step in each realization
    f = bb.open(time)
    if f != None:
      t = bb.read_time()
      if t < t_end: # only read until reach end time of shortest simulation
        [u, v, w] = bb.read_part_velocity()
        U[tind] = U[tind] + bb.part_mean(u)
        V[tind] = V[tind] + bb.part_mean(v)
        W[tind] = W[tind] + bb.part_mean(w)
        T[tind] = t
        tind = tind + 1
        bb.close()
      else:
        bb.close()
        break
    percent = percent + dpercent

# add an extra linebreak for better stdout
print()

# finish averaging