#################################################################################
#
# Tutorial file how to read in hdf5 data from SP-Wind Windfarm simulations,
# generated in the context of the TotalControl project.
#
# A thorough description of the simulations and data can be found at in the deliverable report
#
# author: Ishaan Sood
# date: 24 Feb 2020
# email: sood.ishaan26@gmail.com
#
#################################################################################

'''
Read and plot velocity field data from 3D box hdf5 file around turbine 2.5

1) Retrieve volume of streamwise velocity component at discrete time and plot slices of different views
2) Retrieve and plot planes of streamwise velocity component at a discrete height for several time instants
3) Retrieve time series of all three velocity components at specific grid location

'''

# Import
import import_dataset as idset
import visualize_dataset as vdset
import importlib
import matplotlib.pyplot as plt
importlib.reload(idset)
importlib.reload(vdset)

plt.close('all')

PLOT = True


# open the files
fname = '3D_box.h5'
metadata = idset.get_metadata(fname)

############## Plot 1: Snapshot of the velocity field #####################

# Time step of visualization in [0-900]
nt = 600

# Grid locations of front, side and top view visualization slice in [0-67, 0-27, 0-45]

i, j, k = 33, 13, 9

# Specify u, v or w component for visualization

component = 'u'

Vel = idset.get_volume(metadata, component, nt)
if PLOT:
    fig1 = vdset.plot_slices(Vel, i, j, k, metadata, component, nt)

############## Plot 2: Time series of snapshots the velocity field #####################

u = []
# Time steps of visualization in [0-900]
nt = [100,450,900]

# Grid location for visualization slice. Hub ht z = 9
index = 9

# 'u', 'v' or 'w' velocity component
component = 'u'

# Front 'x', Side 'y', or Top 'z' view

view = 'z'

for k in range(len(nt)):
    u.append(idset.get_plane(metadata, component, nt[k], view, index))
if PLOT:
    fig2 = vdset.plot_tplanes(u, metadata, component, nt, view, index)

############## Plot 3: Time series of velocity components at a point in the box #####################

# Grid locations of visualization in [0-67, 0-27, 0-45]
ind = [10,10,9]
V = idset.get_tserie(metadata, ind)
if PLOT:
    fig3 = vdset.plot_tserie(V,metadata, ind)

