Пример #1
0
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')
Пример #2
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')
Пример #3
0
def perturb(rpath, wpath, pca_path, scale, mode):

    # inputs
    # Z_path : where to write out the sample normal 
    # npca   : where to truncate the PCA expansion

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

    # perturb using only one of the transformed modes
    lines = file(pca_path+'S.dat').readlines()
    S = array([line.strip().split()[0] for line in lines], float).T
    fp = zeros((cdim,sdim))
    cdim,sdim,V = read_blade.read_mode(pca_path+'V'+str(mode)+'.dat')
    fp += scale*S[mode-1]*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()

    # test to see how they look
    '''
    i = 3
    cdim,sdim,V = read_blade.read_mode(pca_path+'V'+str(i+1)+'.dat')
    s, t = read_blade.xyz2st(x,y,z)
    print s[0],s[1]
    pylab.contourf(s,t,V.T,50)
    pylab.colorbar()
    pylab.show()
    '''
     
    '''
    fig = pylab.figure()
    ax = Axes3D(fig)
    surf = ax.plot_surface(sg, tg, fp, rstride=1, cstride=1, cmap = cm.jet)
    '''
    
    '''
    fig = pylab.figure()
    ax = Axes3D(fig)
    surf = ax.plot_surface(tg, sg, nf[1:-1,1:-1,2], rstride=1, cstride=1, cmap = cm.jet)
    # fig.colorbar(surf)
    '''

    ''' 
Пример #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')
Пример #5
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')
Пример #6
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')
Пример #7
0
def perturb(rpath, wpath):

    cdim, sdim, x, y, z = read_blade.read_coords(rpath)
    
    # scale coordinates to be in cm
    scale = 1.0
    x *= scale
    y *= scale
    z *= scale
    
    xu, yu, zu, xl, yl, zl = read_blade.split_blade(cdim, sdim, x, y, z)
    xmc = 0.5*(xu+xl)
    ymc = 0.5*(yu+yl)
    zmc = 0.5*(zu+zl)
    
    dx = xu - xmc
    dy = yu - ymc
    dz = zu - zmc
    
    # camber random process
    sc,tc = read_blade.xyz2st(xmc,ymc,zmc)
    ns = xmc.shape[0]
    nt = xmc.shape[1]
    # mode cutoff
    Ks = ns
    Kt = nt
    fc = simulate.randProcess(sc, tc, ns, nt, Ks, Kt)
    
    tg, sg = meshgrid(tc,sc)
                         
    nc = read_blade.calcNormals(xmc,ymc,zmc)
    
    xmc = xmc + nc[:,:,0]*fc
    ymc = ymc + nc[:,:,1]*fc
    zmc = zmc + nc[:,:,2]*fc
     
    xu = xmc + dx
    yu = ymc + dy
    zu = zmc + dz
    
    xl = xmc - dx
    yl = ymc - dy
    zl = zmc - dz
    
    xp = vstack((xu[:-1,:],xl[::-1,:]))
    yp = vstack((yu[:-1,:],yl[::-1,:]))
    zp = vstack((zu[:-1,:],zl[::-1,:]))
 
    # normal random process
    sp,tp = read_blade.xyz2st(xp,yp,zp)
    ns = xp.shape[0]
    nt = xp.shape[1]
    Ks = ns
    Kt = nt
    fp = simulate.randProcessPeriodic(sp, tp, ns, nt, Ks, Kt)
    fp[0,:] = fp[-1,:]
    # fp = zeros(fp.shape)
    
    '''
    # interpolate back to original mesh
    ss = linspace(0,sp[-1]-sp[0],ns)
    tt = linspace(0,tp[-1]-tp[0],nt)
    ff = simulate.randProcessPeriodic(ss, tt, ns, nt, Ks, Kt)
    fp = simulate.interp(ss, tt, ff, sp, tp)
    
    tg, sg = meshgrid(tt,ss)
    pylab.contourf(sg,tg,ff,30)
    pylab.contourf(sg+sg[-1],tg,ff,30)
    pylab.colorbar()
    pylab.axes().set_aspect('equal', 'datalim')
    pylab.figure()
    '''
    tg, sg = meshgrid(tp,sp)
    pylab.contourf(sg,tg,fp,30)
    # pylab.contourf(sg+sg[-1],tg,fp,30)
    pylab.colorbar()
    pylab.xlim(0.0,sp[-1])
    pylab.axes().set_aspect('equal', 'datalim')
    pylab.xlabel('x')
    pylab.ylabel('y')
    pylab.show()
    
    np = read_blade.calcNormals(xp,yp,zp)
    
    xp = xp + np[:,:,0]*fp
    yp = yp + np[:,:,1]*fp
    zp = zp + np[:,:,2]*fp
    
    # scale coordinates back to original units
    x /= scale
    y /= scale
    z /= scale
    xp /= scale
    yp /= scale
    zp /= scale
    
    # 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 the normal perturbation
    g = open('normal_field.dat','w')
    for i in arange(cdim):
        for j in arange(sdim):
            g.write('%20.8E' * 4 % (x[i,j],y[i,j],z[i,j],fp[i,j]))
            g.write('\n')
    
    g.close()
    
    '''
    fig = pylab.figure()
    ax = Axes3D(fig)
    surf = ax.plot_surface(sg, tg, fp, rstride=1, cstride=1, cmap = cm.jet)
    '''
    
    '''
    fig = pylab.figure()
    ax = Axes3D(fig)
    surf = ax.plot_surface(tg, sg, nf[1:-1,1:-1,2], rstride=1, cstride=1, cmap = cm.jet)
    # fig.colorbar(surf)
    '''
    
    '''
Пример #8
0
    J = linalg.lstsq(A,Y)[0][1:]
    # form the stacked Jacobian
    if isim == 0:
        stackJ = J.T
    else:
        stackJ = vstack([stackJ, J.T])

# mean of the Jacobians
meanJ = mean(stackJ,axis=0)

# compute SVD of stacked Jacobian
V,S,UT = linalg.svd(stackJ)

# read in the surface mesh
rpath = '/mnt/pwfiles/ericdow/random_blade/input/rotor37_coarse/blade_surf.dat'
cdim, sdim, x, y, z = read_blade.read_coords(rpath)

# read in the PCA modes
pca_path = '/mnt/pwfiles/ericdow/random_blade/input/rotor37_coarse/pca_modes_gp/'
V_pca = zeros((NZ,cdim,sdim))
for i in range(NZ):
    cdim,sdim,V_pca[i,:,:] = read_blade.read_mode(pca_path+'V'+str(i+1)+'.dat')

V_pca_tmp = zeros((NZ,cdim*sdim))
for i in range(NZ):
    V_pca_tmp[i,:] = reshape(V_pca[i,:,:],(cdim*sdim))

# transform the modes
V_trans_tmp = dot(dot(UT.T,eye(NZ)*S_pca),V_pca_tmp)

V_trans = zeros((NZ,cdim,sdim))
Пример #9
0
import pylab, os, math, string
from numpy import *
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
import read_blade

inp = '/mnt/pwfiles/ericdow/random_blade/input/rotor37_coarse/'
rundir = '/mnt/pwfiles/ericdow/random_blade/runs/'

# read in original blade surface
cdim, sdim, xn, yn, zn = read_blade.read_coords(inp+'blade_surf.dat')

# read in blade surfaces of completed runs
iran = zeros((len(os.listdir(rundir))))
i = 0
for rd in os.listdir(rundir):
    if os.path.exists(rundir+str(rd)+'/utcfd_out.monitoring.dat'):
        lines = file(rundir+str(rd)+'/utcfd_out.monitoring.dat').readlines()
        if lines[-1][1:4] == 'Job':
            iran[i] = 1
        lines = file(rundir+str(rd)+'/Z.dat').readlines()
        npca = len(lines)
    i += 1

nruns = int(sum(iran))

# perturbed coordinates
xp = zeros((nruns,cdim,sdim))
yp = zeros((nruns,cdim,sdim))
zp = zeros((nruns,cdim,sdim))
Пример #10
0
def perturb(rpath, wpath, pca_path, Z_path, npca):

    # inputs
    # Z_path : where to write out the sample normal 
    # npca   : where to truncate the PCA expansion

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

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

    ################################
    # SCALE PCA MODES BY CHORD RATIO
    ################################
    # r5_chord = 0.859 # inches at hub
    # r37_chord = 2.17 # inches at hub
    # scale = r37_chord/r5_chord
    scale = 1.0 

    # read in PCA modes and singular values 
    lines = file(pca_path+'S.dat').readlines()
    S = array([line.strip().split()[0] for line in lines], float).T
    n_modes = len(S)
    # add the mean
    cdim,sdim,fp = read_blade.read_mode(pca_path+'mean.dat')
    # add the PCA modes
    for i in range(npca):
        cdim,sdim,V = read_blade.read_mode(pca_path+'V'+str(i+1)+'.dat')
        fp += scale*Z[i]*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')

    # test to see how they look
    '''
    i = 3
    cdim,sdim,V = read_blade.read_mode(pca_path+'V'+str(i+1)+'.dat')
    s, t = read_blade.xyz2st(x,y,z)
    print s[0],s[1]
    pylab.contourf(s,t,V.T,50)
    pylab.colorbar()
    pylab.show()
    '''
     
    '''
    fig = pylab.figure()
    ax = Axes3D(fig)
    surf = ax.plot_surface(sg, tg, fp, rstride=1, cstride=1, cmap = cm.jet)
    '''
    
    '''
    fig = pylab.figure()
    ax = Axes3D(fig)
    surf = ax.plot_surface(tg, sg, nf[1:-1,1:-1,2], rstride=1, cstride=1, cmap = cm.jet)
    # fig.colorbar(surf)
    '''

    '''