-
Notifications
You must be signed in to change notification settings - Fork 19
Serial Data Readers
There are several serial data readers provided in FloATPy to read data in different format. The abstract methods and properties defined in the BaseReader
class are all implemented in the serial data readers.
- use only the methods and properties defined in the
BaseReader
class to handle viz data generated from WCHR-Regent code - compute vorticity using a derivative class in FloATPy
- visualize the 3D voriticity field
"""
Import the modules
"""
from floatpy.readers import base_reader, wchr_ascii_reader
import numpy
from matplotlib import pyplot as plt
Most serial data readers require the paths to the directory/prefix of the data. The prefix to the data is required for the WCHR-regent reader being used in this tutorial.
data_reader = wchr_ascii_reader.WchrAsciiReader('./Taylor_Green_vortex/TGV')
# Check whether it is an instance of the abstract base data reader.
print "Serial data reader is instance of base reader: ", isinstance(data_reader, base_reader.BaseReader)
Serial data reader is instance of base reader: True
The domain size, order of data, periodicity of the data, etc. can be obtained from different properties that are defined in the base data reader.
# Get the basic information of the dataset.
print "Domain size: ", data_reader.domain_size
print "Order of data (Fortran or C order): ", data_reader.data_order
print "Periodicity: ", data_reader.periodic_dimensions
print "Current step number: ", data_reader.step
print "Current simulation time: ", data_reader.time
steps = numpy.sort(data_reader.steps)
print("All steps: %s" % steps)
Domain size: (64, 64, 64)
Order of data (Fortran or C order): F
Periodicity: (True, True, True)
Current step number: 0
Current simulation time: 0.0
All steps: [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
90 91 92 93 94 95 96 97 98 99 100]
All the serial data readers have the capability to load data in a sub-domain/chunk. However, the sub-domain has to be set by user first before loading the data.
# Set the step number and the sub-domain size.
data_reader.step = steps[20]
print "Current step number: ", data_reader.step
data_reader.sub_domain = (7,7,7), (63,63,63)
print "Sub-domain size: ", data_reader.sub_domain
Current step number: 20
Sub-domain size: ((7, 7, 7), (63, 63, 63))
# Read the coordinates and velocity data.
x_coords, y_coords, z_coords = data_reader.readCoordinates()
u, v, w = data_reader.readData(('u','v','w'))
print "Shape of x coordinates: ", x_coords.shape
print "Shape of y coordinates: ", y_coords.shape
print "Shape of z coordinates: ", z_coords.shape
print "Shape of u: ", u.shape
print "Shape of v: ", v.shape
print "Shape of w: ", w.shape
Shape of x coordinates: (57, 57, 57)
Shape of y coordinates: (57, 57, 57)
Shape of z coordinates: (57, 57, 57)
Shape of u: (57, 57, 57)
Shape of v: (57, 57, 57)
Shape of w: (57, 57, 57)
FloATPy also provides classes to compute derivatives. The cell below shows how to take curl on the velocity vector field to obtain the vorticity using the explicit derivative class.
# Load the explict differentiator class.
from floatpy.derivatives.explicit_differentiator import ExplicitDifferentiator
# Get the velocity data and compute the vorticity.
dx = x_coords[1,0,0] - x_coords[0,0,0]
dy = y_coords[0,1,0] - y_coords[0,0,0]
dz = z_coords[0,0,1] - y_coords[0,0,0]
explicit_diff = ExplicitDifferentiator((dx, dy, dz), (6, 6, 6), dimension=3, data_order='F')
u = u.reshape(u.shape + (1, ))
v = v.reshape(v.shape + (1, ))
w = w.reshape(w.shape + (1, ))
vel = numpy.concatenate((u,v,w), axis=3)
print "Shape of vel: ", vel.shape
vorticity = explicit_diff.curl(vel, use_one_sided=True)
print "Shape of voriticity data: ", vorticity.shape
Shape of vel: (57, 57, 57, 3)
Shape of voriticity data: (57, 57, 57, 3)
from mpl_toolkits.mplot3d import Axes3D
vorticity_mag = numpy.sqrt(vorticity[:,:,:,0]**2 + vorticity[:,:,:,1]**2 + vorticity[:,:,:,2]**2)
colormap = plt.cm.viridis
min_val = vorticity_mag.min()
max_val = vorticity_mag.max()
N_x = vorticity_mag.shape[0]
N_y = vorticity_mag.shape[1]
N_z = vorticity_mag.shape[2]
x_cut = vorticity_mag[N_x-1,:,:]
y_cut = vorticity_mag[:,0,:]
z_cut = vorticity_mag[:,:,N_z-1]
fig = plt.figure(figsize=(4, 4), dpi= 300)
ax = fig.add_subplot(111, projection='3d')
# Make the x-slice.
ax.plot_surface(x_coords[N_x-1,:,:], y_coords[N_x-1,:,:], z_coords[N_x-1,:,:], \
rstride=1, cstride=1, facecolors=colormap((x_cut-min_val)/(max_val-min_val)), shade=False)
# Make the y-slice.
ax.plot_surface(x_coords[:,0,:], y_coords[:,0,:], z_coords[:,0,:], \
rstride=1, cstride=1, facecolors=colormap((y_cut-min_val)/(max_val-min_val)), shade=False)
# Make the z-slice.
ax.plot_surface(x_coords[:,:,N_z-1], y_coords[:,:,N_z-1], z_coords[:,:,N_z-1], \
rstride=1, cstride=1, facecolors=colormap((z_cut-min_val)/(max_val-min_val)), shade=False)
ax.set_title("Vorticity magnitude")
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
- User Guide
- Tutorials