# -*- coding: utf-8 -*-
"""
Created on Fri Apr 27 10:21:44 2018

@author: m.aguirre

GENERADOR DE SISTEMA DE REFERENCIA
"""
############################################################################################################
############################################### MODULES LOAD ###############################################
############################################################################################################
from vtk.numpy_interface import algorithms as algs
from vtk.numpy_interface import dataset_adapter as dsa
import numpy as np


############################################################################################################
############################################# INPUT PARAMETERS #############################################
############################################################################################################
#UpwardAxis=1
#Alfa = 20
#Size = 2
#X0 = 0
#Y0 = 0
#Z0 = 0

############################################################################################################
############################################# STRING TO FLOAT ##############################################
############################################################################################################

# Input parameters are defined as string in Paraview GUI, thus a string to float convertion is required:
UpwardAxis=float(UpwardAxis)
Alfa = float(Alfa)
Size = float(Size)
X0 = float(X0)
Y0 = float(Y0)
Z0 = float(Z0)

############################################################################################################
############################################# VECTOR GENERATION ############################################
############################################################################################################

# Origin of the reference axes:
Xmesh = np.array([X0+0.0001,X0,X0,X0])
Ymesh = np.array([Y0,Y0+0.0001,Y0,Y0])
Zmesh = np.array([Z0,Z0,Z0+0.0001,Z0])

# Assigning an ID to each point:
ID = np.array([2,1.5,1.0,0])

# Reference axes vectors in the original reference system:
Vx = np.array([Size,0,0,0])
Vy = np.array([0,Size,0,0])
Vz = np.array([0,0,Size,0])

# Vector components refered to the standard aerodynamic reference axis:
if UpwardAxis==0:
    u = Vx*algs.cos(-Alfa*np.pi/180) + Vz*algs.sin(-Alfa*np.pi/180)       # Axial velocity component (alligned with upstream direction)
    v = Vz*algs.cos(-Alfa*np.pi/180) - Vx*algs.sin(-Alfa*np.pi/180)                                                           # Transverse-spanwise velocity component (Perpendicular to upstream direction)
    w = -1*Vy       # Transverse-upwards velocity component (Perpendicular to upstream direction)
else :
    u = Vx*algs.cos(-Alfa*np.pi/180) + Vz*algs.sin(-Alfa*np.pi/180)       # Axial velocity component (alligned with upstream direction)
    v = Vy                                                              # Transverse-spanwise velocity component (Perpendicular to upstream direction)
    w = Vz*algs.cos(-Alfa*np.pi/180) - Vx*algs.sin(-Alfa*np.pi/180)       # Transverse-upwards velocity component (Perpendicular to upstream direction)

Reference_Vectors = algs.make_vector(u, v, w)



############################################################################################################
################################################ OUTPUT DATA ###############################################
############################################################################################################

# Coordinates:
coordinates = algs.make_vector(Xmesh, Ymesh, Zmesh)
pts = vtk.vtkPoints()                                           # create a vtkPoints container to store all the point coordinates.
pts.SetData(dsa.numpyTovtkDataArray(coordinates , "Points"))    # numpyTovtkDataArray converts the NumPy array to a vtkDataArray, which is the format needed by SetData()
output.SetPoints(pts) 

# ID:
output.PointData.append(ID.ravel() , 'ID')

#Vectors:
output.PointData.append(Reference_Vectors , 'Reference_Vectors')





