Exemplo n.º 1
0
def getFlap(airfoilPath, node1,node2, vectLenRatio1, theta, gap, overlap, deflection,zTE):
    dx = 1e-4
    dt = 1e-4
    Npts = ny.array([25,10]) #flap, main section
    tmpAxis = ny.array([.8,-.5])
    theta = math.radians(theta)
    if overlap < -0.9*gap: gap = ny.abs(overlap)/0.9
    
    airfoil = afLib.readAirfoil(airfoilPath)
    
    node1[0,1] = airfoil.upCurve(node1[0,0])
    node1[1,1] = airfoil.getThicknessAtX(node1[1,0])*node1[1,1] + airfoil.loCurve(node1[1,0])
    node1[2,1] = airfoil.loCurve(node1[2,0])
    
    tan1 = ny.zeros([3,2]) #tangency of vectors forming flap curve
    tan1[0,0] = -dx
    tan1[0,1] = -(airfoil.upCurve(node1[0,0]+dx) - airfoil.upCurve(node1[0,0]))
    tan1[1,1] = -1.0
    tan1[2,0] = dx
    tan1[2,1] = airfoil.loCurve(node1[2,0]+dx) - airfoil.loCurve(node1[2,0])
    
    tan2 = ny.zeros([2,2]) #tangency of vectors forming main section lower curve
    tan2[0,0] = dx
    tan2[0,1] = airfoil.loCurve(node2[0,0]+dx) - airfoil.loCurve(node2[0,0])
    tan2[1,0] = math.cos(theta)
    tan2[1,1] = math.sin(theta)
    
    for ii in range(3): tan1[ii,:] = curves.normVect(tan1[ii,:])
    for ii in range(2): tan2[ii,:] = curves.normVect(tan2[ii,:])
    
    line1 = curves.linePtDir2D(node1[0,:],tan1[0,:])
    line2 = curves.linePtDir2D(node1[1,:],tan1[1,:])
    line3 = curves.linePtDir2D(node1[2,:],tan1[2,:])
    
    intersect1 = curves.lineIntersect(line1,line2)
    intersect2 = curves.lineIntersect(line3,line2)
    
    vectLenMax1 = ny.zeros(3)
    vectLenMax1[0] = curves.dist2pts(intersect1,node1[0,:])
    vectLenMax1[2] = curves.dist2pts(intersect2,node1[2,:])
    tmp = ny.array([airfoil.upCurve(node1[1,0])-node1[1,1] , node1[1,1] - airfoil.loCurve(node1[1,0])])
    vectLenMax1[1] = ny.min(tmp)
    del tmp
    
    vectLen1 = vectLenRatio1 * vectLenMax1
    vect1 = ny.zeros([3,2])
    for ii in range(3): vect1[ii,:] = tan1[ii,:] * vectLen1[ii]
    
    xytCurve1,_ = curves.pwBezier(node1,vect1,Npts[0])
    xytCurve2 = curves.rotate2D(xytCurve1,ny.array([0.7,0]),math.degrees(theta))
    splitPt1 = xytCurve2[ny.argmin(xytCurve2[:,0]),:]
    splitPt2 = xytCurve2[ny.argmax(xytCurve2[:,0]),:]
    xytCurveInt2 = curves.xytCurveInterp(xytCurve2)
    def get_dydt(t):
        if t == xytCurve2[-1,2]: t -=dt
        pt1 = xytCurveInt2.getCoord(t)
        pt2 = xytCurveInt2.getCoord(t+dt)
        return (pt2[1]-pt1[1])/dt
    t_theta = root.bisect(get_dydt,splitPt1[2],splitPt2[2])
    
    xytCurveInt1 = curves.xytCurveInterp(xytCurve1)
    node2[0,1] = airfoil.loCurve(node2[0,0])
    node2[2,:] = xytCurveInt1.getCoord(t_theta)[0:2]
    line4 = curves.linePtDir2D(node2[0,:],tan2[0,:])
    line5 = curves.linePtDir2D(node2[2,:],tan2[1,:])
    node2[1,:] = curves.lineIntersect(line4,line5)

    xytCurve3 = curves.BezierCurve(node2,Npts[1])

    def getTEthickness(t):
        pt1 = xytCurveInt1.getCoord(t)
        yy = airfoil.upCurve(pt1[0])
        thickness = yy-pt1[1]
        return thickness-zTE

    t_split = root.bisect(getTEthickness,0,1.)
    x_split = xytCurveInt1.getCoord(t_split)[0]
    
    split1 = curves.xyCurveSplit(airfoil.up,[],x_split)
    split2 = curves.xyCurveSplit(airfoil.up,node1[0,0])
    split3 = curves.xyCurveSplit(airfoil.lo,[],node2[0,0])
    split4 = curves.xyCurveSplit(airfoil.lo,node1[-1,0])
    split5 = curves.xytCurveSplit(xytCurve1,t_split,t_theta)
    
    mainSecCurve = ny.array([split1,split3,xytCurve3[:,0:2],split5[:,0:2]])
    mainSecCurve = curves.join(mainSecCurve,[True,False,False,True])
    
    flapCurve = ny.array([split2,xytCurve1[:,0:2],split4])
    flapCurve = curves.join(flapCurve,[True,False,False])
    flapCurve = curves.rotate2D(flapCurve,tmpAxis,deflection)
    
    tmpFlap = curves.rotate2D(xytCurve1,tmpAxis,deflection)
    xytCurveInt3 = curves.xytCurveInterp(tmpFlap)
    refPt = mainSecCurve[-1,:]
    
    def getFlapX(t):
        return xytCurveInt3.getCoord(t)[0]
    dist = minimize(getFlapX,1)
    dx = (refPt[0]-overlap) - dist.fun
    tmpFlap[:,0] += dx
    xytCurveInt2 = curves.xytCurveInterp(tmpFlap)

    def getGap(dy):
        tmpFlap2 = ny.copy(tmpFlap)
        tmpFlap2[:,1] = tmpFlap2[:,1] + dy
        xytCurveInt4 = curves.xytCurveInterp(tmpFlap2)
        def getDist(t):
            pt = xytCurveInt4.getCoord(t)
            return curves.dist2pts(pt,refPt)
        currentGap = minimize_scalar(getDist,bounds=(0.,2.),method='bounded')
        return (currentGap.fun - gap)
    
    dy = root.fsolve(getGap,0)
    flapCurve[:,0] = flapCurve[:,0] + dx
    flapCurve[:,1] = flapCurve[:,1] + dy
    
    airfoil.mainSec = mainSecCurve
    airfoil.flap = flapCurve
    airfoil.hasFlap = True
    
    return airfoil
Exemplo n.º 2
0
def getFlap(airfoilPath, nodes1,nodes2, vectLen1, theta, gap, overlap, deflection,teThickness):
    dx = 1e-4
    
    flapNpts = 100
    mainSecTEpts = 8
    tmpAxis = ny.array([.8,-.5])
    if overlap < -0.9*gap: gap = ny.abs(overlap)/0.9
    af = afLib.readAirfoil(airfoilPath)

    af.loCurve = af.loCurve
    
    nodes1[0,1] = af.upCurve(nodes1[0,0])
    nodes1[2,1] = af.loCurve(nodes1[2,0])
    nodes2[0,1] = af.loCurve(nodes2[0,0])
    
    vectLenMax1 = ny.zeros([3,1])
    
    nodes1[1,1] = nodes1[1,1]*af.getThicknessAtX(nodes1[1,0])+af.loCurve(nodes1[1,0])
    tmpVecLen   = ny.array([af.upCurve(nodes1[1,0])-nodes1[1,1], nodes1[1,1]-af.loCurve(nodes1[1,0])])
    print tmpVecLen
    vectLenMax1[1] = ny.min(tmpVecLen)
    del tmpVecLen
    
    tangency1 = ny.zeros([3,2])
    tangency2 = ny.zeros([2,2])
    tangency1[0,0] = dx
    tangency1[0,1] = af.upCurve(nodes1[0,0]+dx) - af.upCurve(nodes1[0,0])
    tangency1[1,1] = -1.
    tangency1[2,0] = dx
    tangency1[2,1] = af.loCurve(nodes1[2,0]+dx) - af.loCurve(nodes1[2,0])
    tangency1[0,:] = - tangency1[0,:]
    for ii in range(3): tangency1[ii,:] = curves.normVect(tangency1[ii,:])
    
    #create two lines and get allowable length
    line3 = curves.linePtDir2D(nodes1[0,:],tangency1[0,:])
    line4 = curves.linePtDir2D(nodes1[1,:],tangency1[1,:])
    line5 = curves.linePtDir2D(nodes1[2,:],tangency1[2,:])
    
    Intersect1 = curves.lineIntersect(line3,line4)
    Intersect2 = curves.lineIntersect(line4,line5)
    
    vectLenMax1[0] = curves.dist2pts(nodes1[0,:],Intersect1)
    vectLenMax1[1] = curves.dist2pts(nodes1[2,:],Intersect2)

    for ii in range(3): vectLen1[ii] = vectLen1[ii]*vectLenMax1[ii]
    
    vect1 = ny.zeros([3,2])
    for ii in range(3): vect1[ii,:] = tangency1[ii,:]*vectLen1[ii]
    
    tangency2[0,0] = dx
    tangency2[0,1] = af.loCurve(nodes2[0,0]+dx) - af.loCurve(nodes2[0,0])
    tangency2[1,0] = math.cos(math.radians(theta))
    tangency2[1,1] = math.sin(math.radians(theta))
    
    xytCurve1,_ = curves.pwBezier(nodes1,vect1,flapNpts) #flap curve
    xytCurveInt1 = curves.xytCurveInterp(xytCurve1)

    def getTangency(t):
        dt = 1e-4
        pt1 = xytCurveInt1.getCoord(t)
        pt2 = xytCurveInt1.getCoord(t+dt)
        ctan = (pt1[0]-pt2[0])/(pt1[1]-pt2[1])
        ctanTheta = math.cos(math.radians(theta))/math.sin(math.radians(theta))
        return ctanTheta - ctan

    t_theta = root.bisect(getTangency,0.25,1.75)
    nodes2[2,:] = xytCurveInt1.getCoord(t_theta)[0:2]
    line1 = curves.linePtDir2D(nodes2[0,:],tangency2[0,:])
    line2 = curves.linePtDir2D(nodes2[2,:],tangency2[1,:])
    nodes2[1,:] = curves.lineIntersect(line1,line2)
    
    xytCurve2 = curves.BezierCurve(nodes2,mainSecTEpts)
    
    def getTEthickness(t):
        pt1 = xytCurveInt1.getCoord(t)
        yy = af.upCurve(pt1[0])
        thickness = yy-pt1[1]
        return thickness-teThickness
        
    t_split = root.bisect(getTEthickness,0,1.0)
    x_split = xytCurveInt1.getCoord(t_split)[0]
    
    split1 = curves.xyCurveSplit(af.up,[],x_split)
    split2 = curves.xyCurveSplit(af.up,nodes1[0,0])
    split3 = curves.xyCurveSplit(af.lo,[],nodes2[0,0])
    split4 = curves.xyCurveSplit(af.lo,nodes1[-1,0])
    split5 = curves.xytCurveSplit(xytCurve1,t_split,t_theta)
    
    mainSecCurve = ny.array([split1,split3,xytCurve2[:,0:2],split5[:,0:2]])
    mainSecCurve = curves.join(mainSecCurve,[True,False,False,True])
    
    flapCurve = ny.array([split2,xytCurve1[:,0:2],split4])
    flapCurve = curves.join(flapCurve,[True,False,False])
    flapCurve = curves.rotate2D(flapCurve,tmpAxis,deflection)
    
    tmpFlap = curves.rotate2D(xytCurve1,tmpAxis,deflection)
    xytCurveInt2 = curves.xytCurveInterp(tmpFlap)
    refPt = mainSecCurve[-1,:]
    
    def getFlapX(t):
        return xytCurveInt2.getCoord(t)[0]
    dist = minimize(getFlapX,1)
    dx = (refPt[0]-overlap) - dist.fun
    
    tmpFlap[:,0] += dx
    xytCurveInt2 = curves.xytCurveInterp(tmpFlap)
    
    def getGap(dy):
        tmpCurve = ny.copy(tmpFlap)
        tmpCurve[:,1] += dy
        xytCurveInt3 = curves.xytCurveInterp(tmpCurve)
        def getDist(t):
            pt = xytCurveInt3.getCoord(t)
            return curves.dist2pts(pt,refPt)
        CurGap = minimize(getDist,1.).fun
        return CurGap-gap

    dy = root.fsolve(getGap,0)
    
    flapCurve[:,0] = flapCurve[:,0] + dx
    flapCurve[:,1] = flapCurve[:,1] + dy
    
    af.mainSec = mainSecCurve
    af.flap = flapCurve
    af.hasFlap = True
    
    testNode = ny.zeros([7,2])
    testNode[0,:] = nodes1[0,:]
    testNode[3,:] = nodes1[1,:]
    testNode[6,:] = nodes1[2,:]
    testNode[1,:] = nodes1[0,:] + vect1[0,:]
    testNode[2,:] = nodes1[1,:] - vect1[1,:]
    testNode[4,:] = nodes1[1,:] + vect1[1,:]
    testNode[5,:] = nodes1[2,:] - vect1[2,:]
    
    
    plt.plot(mainSecCurve[:,0],mainSecCurve[:,1])
    plt.hold(True)
    plt.plot(xytCurve1[:,0],xytCurve1[:,1])
    plt.plot(xytCurve2[:,0],xytCurve2[:,1])
    plt.plot(af.up[:,0],af.up[:,1])
    plt.plot(af.lo[:,0],af.lo[:,1])
    plt.axis([0,1.2,-0.5,0.5])
    plt.grid(True)
    plt.plot(flapCurve[:,0],flapCurve[:,1])
    plt.plot(testNode[:,0],testNode[:,1])
    plt.show()
    
    return af