Esempio n. 1
0
def perturb_rot(rpath, wpath, dth):

    # dht - amount to rotate blade

    cdim, sdim, x, y, z = read_blade.read_coords(rpath)

    # split the blade
    xu,yu,zu,xl,yl,zl = read_blade.split_blade(cdim,sdim,x,y,z)

    xle = xu[0,0]; yle = yu[0,0]
    xte = xu[-1,0]; yte = yu[-1,0]
    th = arctan2(y-yle,x-xle)
    r = sqrt((x-xle)**2 + (y-yle)**2)
    xp = xle + r*cos(th+dth)
    yp = yle + r*sin(th+dth)
    zp = copy(z)

    pylab.plot(x[:,0],y[:,0])
    pylab.plot(xp[:,0],yp[:,0])
    pylab.axis('Equal')
    pylab.show()
     
    # write out the blade surface
    f = open(wpath,'w')
    f.write('CDIM:       %d\n' % cdim)
    f.write('SDIM:       %d\n' % sdim)
    for i in arange(cdim):
        for j in arange(sdim):
            f.write('%20.8E' * 3 % (xp[i,j],yp[i,j],zp[i,j]))
            f.write('\n')
    
    f.close()

    # write out to tecplot format
    write_tecplot.write_blade_surf(xp,yp,zp,'tec_blade.dat')
def perturb(rpath, wpath, kl_path, Z_path, dth_path, nkl):
    
    # inputs
    # Z_path   : where to write out the sample normal 
    # dth_path : where to write out the random rotation
    # nkl      : where to truncate the K-L expansion

    cdim, sdim, x, y, z = read_blade.read_coords(rpath)
    
    # translate blade random amount (rotate about x axis)
    random.seed()
    dth = random.randn(1)*pi/180*0.1/3.0
    for i in range(cdim):
        for j in range(sdim):
            r = sqrt(y[i,j]**2 + z[i,j]**2)
            th = math.atan2(z[i,j],y[i,j])
            y[i,j] = r*cos(th+dth)
            z[i,j] = r*sin(th+dth)

    # write out dth
    f = open(dth_path,'w')
    f.write('%e\n' % dth)
    f.close()
    
    # generate and write out the Z for this mesh
    random.seed() 
    Z = random.randn(nkl)    # normal distribution vector
    f = open(Z_path,'w')
    for i in range(nkl):
        f.write('%e\n' % Z[i])
    f.close()

    # read in PCA modes and singular values 
    lines = file(kl_path+'S.dat').readlines()
    S = array([line.strip().split()[0] for line in lines], float).T
    n_modes = len(S)
    fp = zeros((cdim,sdim))
    for i in range(nkl):
        cdim,sdim,V = read_blade.read_mode(kl_path+'V'+str(i+1)+'.dat')
        fp += Z[i]*sqrt(S[i])*V
     
    np = read_blade.calcNormals(x,y,z)
    
    xp = x + np[:,:,0]*fp
    yp = y + np[:,:,1]*fp
    zp = z + np[:,:,2]*fp
     
    # write out the blade surface
    f = open(wpath,'w')
    f.write('CDIM:       %d\n' % cdim)
    f.write('SDIM:       %d\n' % sdim)
    for i in arange(cdim):
        for j in arange(sdim):
            f.write('%20.8E' * 3 % (xp[i,j],yp[i,j],zp[i,j]))
            f.write('\n')
    
    f.close()

    # write out to tecplot format
    write_tecplot.write_blade_surf(xp,yp,zp,fp,'blade.dat')
Esempio n. 3
0
def perturb_chev(rpath, wpath, M):

    # M - amplitudes of the Chevyshev modes

    cdim, sdim, x, y, z = read_blade.read_coords(rpath)

    # split the blade
    xu,yu,zu,xl,yl,zl = read_blade.split_blade(cdim,sdim,x,y,z)

    # compute the s coordinates
    tck, su = splprep([xu[:,0],yu[:,0]],s=0)
    tck, sl = splprep([xl[:,0],yl[:,0]],s=0)

    # form the modes
    nmodes = len(M)
    cheb = zeros((nmodes,x.shape[0],x.shape[1]))
    for i in arange(nmodes):
        n = i + 1
        if mod(n,2) == 0:
            gu =  (1-2*su-cos((n+1)*arccos(1-2*su)))/(n+1.)
            gl = -(1-2*sl-cos((n+1)*arccos(1-2*sl)))/(n+1.)
            cheb[i,:,:] = tile(hstack((gu,gl[::-1][1:])),(sdim,1)).T
        else:
            gu =  (1-cos((n+1)*arccos(1-2*su)))/(n+1.)
            gl = -(1-cos((n+1)*arccos(1-2*sl)))/(n+1.)
            cheb[i,:,:] = tile(hstack((gu,gl[::-1][1:])),(sdim,1)).T

    np = read_blade.calcNormals(x,y,z)

    for i in arange(nmodes):
        xp = x + np[:,:,0]*cheb[i,:,:]*M[i]
        yp = y + np[:,:,1]*cheb[i,:,:]*M[i]
        zp = z + np[:,:,2]*cheb[i,:,:]*M[i]

    pylab.plot(x[:,0],y[:,0])
    pylab.plot(xp[:,0],yp[:,0])
    pylab.axis('Equal')
    pylab.show()
     
    # write out the blade surface
    f = open(wpath,'w')
    f.write('CDIM:       %d\n' % cdim)
    f.write('SDIM:       %d\n' % sdim)
    for i in arange(cdim):
        for j in arange(sdim):
            f.write('%20.8E' * 3 % (xp[i,j],yp[i,j],zp[i,j]))
            f.write('\n')
    
    f.close()

    # write out to tecplot format
    write_tecplot.write_blade_surf(xp,yp,zp,'tec_blade.dat')
Esempio n. 4
0
def perturb_chev(rpath, wpath, M):

    # M - amplitudes of the Chevyshev modes

    cdim, sdim, x, y, z = read_blade.read_coords(rpath)

    # split the blade
    xu, yu, zu, xl, yl, zl = read_blade.split_blade(cdim, sdim, x, y, z)

    # compute the s coordinates
    tck, su = splprep([xu[:, 0], yu[:, 0]], s=0)
    tck, sl = splprep([xl[:, 0], yl[:, 0]], s=0)

    # form the modes
    nmodes = len(M)
    cheb = zeros((nmodes, x.shape[0], x.shape[1]))
    for i in arange(nmodes):
        n = i + 1
        if mod(n, 2) == 0:
            gu = (1 - 2 * su - cos((n + 1) * arccos(1 - 2 * su))) / (n + 1.)
            gl = -(1 - 2 * sl - cos((n + 1) * arccos(1 - 2 * sl))) / (n + 1.)
            cheb[i, :, :] = tile(hstack((gu, gl[::-1][1:])), (sdim, 1)).T
        else:
            gu = (1 - cos((n + 1) * arccos(1 - 2 * su))) / (n + 1.)
            gl = -(1 - cos((n + 1) * arccos(1 - 2 * sl))) / (n + 1.)
            cheb[i, :, :] = tile(hstack((gu, gl[::-1][1:])), (sdim, 1)).T

    np = read_blade.calcNormals(x, y, z)

    for i in arange(nmodes):
        xp = x + np[:, :, 0] * cheb[i, :, :] * M[i]
        yp = y + np[:, :, 1] * cheb[i, :, :] * M[i]
        zp = z + np[:, :, 2] * cheb[i, :, :] * M[i]

    pylab.plot(x[:, 0], y[:, 0])
    pylab.plot(xp[:, 0], yp[:, 0])
    pylab.axis('Equal')
    pylab.show()

    # write out the blade surface
    f = open(wpath, 'w')
    f.write('CDIM:       %d\n' % cdim)
    f.write('SDIM:       %d\n' % sdim)
    for i in arange(cdim):
        for j in arange(sdim):
            f.write('%20.8E' * 3 % (xp[i, j], yp[i, j], zp[i, j]))
            f.write('\n')

    f.close()

    # write out to tecplot format
    write_tecplot.write_blade_surf(xp, yp, zp, 'tec_blade.dat')
Esempio n. 5
0
def perturb_rot(rpath, wpath, dth):

    # dht - amount to rotate blade

    cdim, sdim, x, y, z = read_blade.read_coords(rpath)

    # split the blade
    xu, yu, zu, xl, yl, zl = read_blade.split_blade(cdim, sdim, x, y, z)

    xle = xu[0, 0]
    yle = yu[0, 0]
    xte = xu[-1, 0]
    yte = yu[-1, 0]
    th = arctan2(y - yle, x - xle)
    r = sqrt((x - xle)**2 + (y - yle)**2)
    xp = xle + r * cos(th + dth)
    yp = yle + r * sin(th + dth)
    zp = copy(z)

    pylab.plot(x[:, 0], y[:, 0])
    pylab.plot(xp[:, 0], yp[:, 0])
    pylab.axis('Equal')
    pylab.show()

    # write out the blade surface
    f = open(wpath, 'w')
    f.write('CDIM:       %d\n' % cdim)
    f.write('SDIM:       %d\n' % sdim)
    for i in arange(cdim):
        for j in arange(sdim):
            f.write('%20.8E' * 3 % (xp[i, j], yp[i, j], zp[i, j]))
            f.write('\n')

    f.close()

    # write out to tecplot format
    write_tecplot.write_blade_surf(xp, yp, zp, 'tec_blade.dat')
Esempio n. 6
0
    fname = 'Z_blade'+str(n+1)+'.dat'
    f = open(data_dir+fname,'w')
    for i in arange(Z.shape[1]):
        f.write('%e\n' % Z[n,i])
    f.close()

# mesh surface file for interpolating modes to
mesh_path = '/home/ericdow/code/blade_pca/blade_surf.dat'

# read the surface mesh
xyz_mesh = read_mesh_surf(mesh_path)

xmesh = xyz_mesh[:,:,0]
ymesh = xyz_mesh[:,:,1]
zmesh = xyz_mesh[:,:,2]
write_tecplot.write_blade_surf(xmesh,ymesh,zmesh,V,'pca_modes_r37.dat')

 
'''
# plot the scatter fraction 
pylab.figure()
pylab.semilogy(arange(S.shape[0]-1)+1,S[:-1]**2,'*')
pylab.grid(True)
pylab.xlabel('PCA Mode Index')
pylab.ylabel('PCA Eigenvalue')

pylab.figure()
# pylab.plot(arange(S.shape[0]),0.99*ones((S.shape[0])),'r--')
sf = cumsum(S**2)/sum(S**2)
nn = 10
ind = arange(nn)+1
Esempio n. 7
0
    V2 = transform_mode(xyzn,xe,xyz_mesh,ntip)
    xe_r37[i,:,:] = V2

    fname = 'blade'+str(i+1)+'.dat'
    f = open(data_dir+fname,'w')
    f.write('CDIM:       %d\n' % V2.shape[1])
    f.write('SDIM:       %d\n' % V2.shape[0])
    for i in arange(V2.shape[1]):
        for j in arange(V2.shape[0]):
            f.write('%e\n' % V2[j,i])
    f.close()

xnom = zeros((npps+1,nsec))
ynom = zeros((npps+1,nsec))
znom = zeros((npps+1,nsec))
xnom[:-1,:] = xyzn[:,:,0].T
ynom[:-1,:] = xyzn[:,:,1].T
znom[:-1,:] = xyzn[:,:,2].T
xnom[-1,:] = xnom[0,:]
ynom[-1,:] = ynom[0,:]
znom[-1,:] = znom[0,:]
Vp = zeros((n,npps+1,nsec))
for i in range(n):
    Vp[i,:-1,:] = xe_r5[i,:,:].T
Vp[:,-1,:] = Vp[:,0,:]
write_tecplot.write_blade_surf(xnom,ynom,znom,Vp,'errors_r5.dat')
xmesh = xyz_mesh[:,:,0]
ymesh = xyz_mesh[:,:,1]
zmesh = xyz_mesh[:,:,2]
write_tecplot.write_blade_surf(xmesh,ymesh,zmesh,xe_r37,'errors_r37.dat')
Esempio n. 8
0
n = max_error.shape[0]

xnom = zeros((npps+1,nsec))
ynom = zeros((npps+1,nsec))
znom = zeros((npps+1,nsec))
xnom[:-1,:] = xyzn[:,:,0].T
ynom[:-1,:] = xyzn[:,:,1].T
znom[:-1,:] = xyzn[:,:,2].T
xnom[-1,:] = xnom[0,:]
ynom[-1,:] = ynom[0,:]
znom[-1,:] = znom[0,:]
Vp = zeros((n,npps+1,nsec))
for i in range(n):
    Vp[i,:-1,:] = V[i,:,:].T
Vp[:,-1,:] = Vp[:,0,:]
write_tecplot.write_blade_surf(xnom,ynom,znom,Vp,'pca_modes_r5.dat')

'''
n = max_error.shape[0]
# find max error over all blades and plot
max_error = (max_error[:,:,0]).max(0)

# determine how many modes are needed
e_thresh = 5.0e-4
nmodes = nonzero((max_error - e_thresh) <= 0.0)[0][0]+1
print 'Total modes required: ', nmodes

pylab.semilogy(arange(max_error.shape[0])+1,max_error,'*')
pylab.ylim([1.0e-5,2.0*max(max_error)])
pylab.grid(True)
pylab.xlabel('Number of modes in reconstruction')
        for j in arange(sdim):
            f.write('%e\n' % V_trans[imode,i,j])
    f.close()

# write out the transformed amplitudes
Cov_trans = dot(UT,dot(S_pca**2*eye(NZ),UT.T))
f = open('ob_modes/S.dat','w')
for i in arange(NZ):
    f.write('%e\n' % sqrt(Cov_trans[i,i]))
f.close()

s, t = read_blade.xyz2st(x,y,z)
s /= s[-1]

# tecplot file with ob modes
write_tecplot.write_blade_surf(x,y,z,V_trans,'ob_modes_r37.dat') 

# plot the transformed modes
# make sure they match up with the PCA modes
ls = len(s)+mod(len(s),2)
V_trans_tmp = zeros(V_trans.shape)
V_trans_tmp[:,:ls/2,:] = V_trans[:,ls/2-1:,:]
V_trans_tmp[:,ls/2-1:,:] = V_trans[:,:ls/2,:]
for i in range(4):
    pylab.figure()
    pylab.contourf(s,t,V_trans_tmp[i,:,:].T,50)
    pylab.title('Output-based mode '+str(i+1))
    pylab.xlabel('Chordwise location')
    pylab.ylabel('Spanwise Coordinate')
    pylab.text(0.03,t[0]-0.07,'LE')
    pylab.text(0.5,t[0]-0.07,'TE')
Esempio n. 10
0
eigs_1d = reshape(eigs,ns*nt,1)
ind = flipud(argsort(eigs_1d)[-nkl:])
ind_2d = zeros((nkl,2))
for i in range(nkl):
    ind_2d[i,:] = unravel_index(ind[i],(nt,ns))
ind_2d = fliplr(ind_2d)

# write out the K-L modes/eigenvalues
f = open('kl_modes/S.dat','w')
for n in range(nkl):
    f.write('%e\n' % eigs_1d[ind[n]])
f.close()
for n in range(nkl):
    imode = ind_2d[n,0]
    jmode = ind_2d[n,1]
    V = outer(UX[:,imode],UY[:,jmode])
    # project K-L mode onto mesh geometry
    sABCD = array([0.05, 0.45, 0.55, 0.95])
    slope = 0.1 # how much stuff is pushed towards hub/shroud
    V_proj = project_GP.project(s,t,sABCD,V,x,y,z,slope)

    f = open('kl_modes/V'+str(n+1)+'.dat','w')
    f.write('CDIM:       %d\n' % cdim)
    f.write('SDIM:       %d\n' % sdim)
    for i in arange(cdim):
        for j in arange(sdim):
            f.write('%e\n' % V_proj[i,j])
    f.close()

    write_tecplot.write_blade_surf(x,y,z,V_proj,'blade.dat') 
Esempio n. 11
0
'''

# write out PCA singular values
'''
f = open(data_dir+'S.dat','w')
for s in S:
    f.write('%e\n' % s)
f.close()
'''

# write out the first pca mode to tecplot format
xmesh = xyz_mesh[:,:,0]
ymesh = xyz_mesh[:,:,1]
zmesh = xyz_mesh[:,:,2]
V2 = transform_mode(xyzn,V[0,:,:],xyz_mesh,ntip)
write_tecplot.write_blade_surf(xmesh,ymesh,zmesh,V2,'pca_mode1_r37.dat')

xnom = zeros((npps+1,nsec))
ynom = zeros((npps+1,nsec))
znom = zeros((npps+1,nsec))
xnom[:-1,:] = xyzn[:,:,0].T
ynom[:-1,:] = xyzn[:,:,1].T
znom[:-1,:] = xyzn[:,:,2].T
xnom[-1,:] = xnom[0,:]
ynom[-1,:] = ynom[0,:]
znom[-1,:] = znom[0,:]
Vp = zeros((npps+1,nsec))
Vp[:-1,:] = V[0,:,:].T
Vp[-1,:] = Vp[0,:]
write_tecplot.write_blade_surf(xnom,ynom,znom,Vp,'pca_mode1_meas.dat')