Beispiel #1
0
def fun(cd,D,d,yx,θ,E,mo,Xs,Ys,F,ff1,canvas1,ff2,canvas2):
    def a_ij(x,y,b,a):
    
        f1 = lambda x, y: x + np.sqrt(x**2 + y**2)
    
        return (x+b) * np.log(f1(y+a,x+b)/f1(y-a,x+b)) + \
               (y+a) * np.log(f1(x+b,y+a)/f1(x-b,y+a)) + \
               (x-b) * np.log(f1(y-a,x-b)/f1(y+a,x-b)) + \
               (y-a) * np.log(f1(x-b,y-a)/f1(x+b,y-a))
    
    #材料1
    E_1 = E   # MPa
    mu_1 = mo
    
    #材料2
    E_2 = E# MPa
    mu_2 = mo
    
    k = ( (1 - mu_1**2)/E_1 + (1 - mu_2**2)/E_2) / np.pi
    
    E_d = 1/(k*np.pi)
    
    # x的界限
    x1 = -(cd/2)
    x2 = cd/2
    x_yx = yx/2
    
    y1 = -1
    y2 = 1
    # x方向网格数
    x_grid_number = Xs
    # y方向网格数
    y_grid_number = Ys
    # 网格大小
    x_grid_size = (x2 - x1) / (2 * x_grid_number)   # nuit:mm
    y_grid_size = (y2 - y1) / (2 * y_grid_number)  # nuit:mm
    
    def influence_coefficient_matrix(x_number, y_number, x_size, y_size):
        Matrix_mother = np.zeros([2 * x_number - 1, 2 * y_number - 1])
        for i in range(2 * x_number - 1):
            for j in range(2 * y_number - 1):
                Matrix_mother[i, j] = a_ij(np.abs(i - x_number+1) * 2 * x_size, np.abs(j - y_number+1) * 2 * y_size, x_size, y_size)
    
        n = 0
        P = np.zeros([x_number*y_number, x_number * y_number])
        for i in range(x_number):
            for j in range(y_number):
                t1 = Matrix_mother[(x_number-1-i):(x_number-1-i+x_number),(y_number-1-j):(y_number-1-j+y_number)]
                P[n,:] = t1.reshape(1,-1)
                n = n + 1
    
        return P
    
    P = influence_coefficient_matrix(x_grid_number, y_grid_number, x_grid_size, y_grid_size)
    
    
    ###
    
    # 圆柱的表面坐标
    D1=d
    D2=D
    theta=θ*(2*np.pi/360)
    F_ext = F
    
    
    R=(D1+D2)/4
    
    xa = [x1 +  (2*i + 1)* x_grid_size for i in range(x_grid_number)]
    ya = [y1 +  (2*i + 1)* y_grid_size for i in range(y_grid_number)]
    
    #xx, yy = np.meshgrid(xa, ya)#, sparse=True)
    
    #曲率半径
    def Ri(x):
        Di=(1-(x-x1)/(2*x2))*D1+(x-x1)/(2*x2)*D2
        Ri=Di/(2*np.cos(theta))
        return Ri
    
    #对数曲线
    def duishu(x_n):
        ds = (F_ext/(np.pi*2*x_yx*E_d))*np.log(1/(1-(2*x_n/(2*x_yx))**2))
        R_r = Ri(x_n) - ds
        return R_r
    
    
    z = np.zeros([x_grid_number, y_grid_number])
    for i in range(x_grid_number):
        for j in range(y_grid_number):
            if np.logical_and(np.logical_and(xa[i] <x_yx, xa[i] >-x_yx), np.logical_and(ya[j]<y2, ya[j] > -y2)):
                z[i,j] = np.sqrt(duishu(xa[i])**2 - ya[j]**2)
    
    Ri_M=np.zeros(x_grid_number)
    Ri_M.shape=x_grid_number,1
    for i in range(x_grid_number):
        Ri_M[i,0]=Ri(xa[i])
    
    shape = z
    #shape= np.zeros_like(z)
    #shape = np.zeros([x_grid_number, y_grid_number])
    #positon = np.logical_and(np.logical_and(xx < 1, xx > -1), np.logical_and(yy<1.5, yy > -1.5))
    #shape[positon] = z[positon]
    
    n=0
    
    d_test = 0.003
    # 确定位移下限
    
    while True:
        alpha = shape - Ri_M + d_test
        b = alpha.reshape(1,-1)
        # plt.plot(b[0,:])
        for i in range(b.size):
            if b[0,i] < 0:
                b[0,i] = 0
        c = np.linalg.solve(P,b.T/k)
    
        F_calculate = 0
        for i in range(c.shape[0]):
            if(c[i,0]>0):
                F_calculate += c[i,0] * 4 * x_grid_size * y_grid_size
    
        #print(F_calculate)
    
        if(F_ext < F_calculate):
            d_test = 0.5 * d_test
        else:
            break
    d_low = d_test
    
    # 确定位移上限
    d_test = 0.01
    while True:
        alpha = shape - Ri_M  + d_test
        b = alpha.reshape(1,-1)
        b[b<0] = 0
        # plt.plot(b[0,:])
    
        c = np.linalg.solve(P, b.T/k)
    
        c[c<0] = 0
    
        F_calculate = (c * 4 * x_grid_size * y_grid_size).sum()
    
        #print(F_calculate)
    
        if(F_ext > F_calculate):
            d_test = 2 * d_test
        else:
            break
    
    d_up = d_test
    
    d_test = 0.5 * (d_up + d_low)
    
    while np.abs(d_up - d_low) > 1e-8:
    
        alpha = shape - Ri_M  + d_test
        b = alpha.reshape(1,-1)
        b[b<0] = 0
        # plt.plot(b[0,:])
    
        c = np.linalg.solve(P, b.T/k)
    
        c[c<0] = 0
    
        F_calculate = (c * 4 * x_grid_size * y_grid_size).sum()
    
        #print(F_calculate)
    
    
        if(F_ext > F_calculate):
            d_low = d_test
            d_test = 0.5 * (d_up + d_low)
    
        else:
            d_up = d_test
            d_test = 0.5 * (d_up + d_low)
    
        #print(d_low,d_up)
    
    
        n = n+1
        if(n>20000):
            break
    
    
    #
    #d.max()
    #
    #a1 = (1 - mu_1**2)/E_1
    #a2 = (1 - mu_2**2)/E_2
    #
    #np.sqrt(6 * F_ext * (1/(a1+a2))**2)/np.pi
    
    Hz_s1 = 0.388 * (F_ext * (2*E_1*E_2/(E_1 + E_2))**2 / R**2)**(1/3)
    
    #0.388 * (10000 * (2*E_1*E_2/(E_1 + E_2))**2)**(1/3)
    #
    #0.388 * (10000 * E_1**2)**(1/3)
    #1.231 * (10000**2 / E_1**2)**(1/3)
    #d_test
    Hz_d1 = 1.231 * (F_ext**2 / E_1**2/R)**(1/3)
    
# =============================================================================
#     print('赫兹接触应力 = %0.3f, \t 计算接触应力 = %0.3f ' % (Hz_s1, c.max()))
#     print('赫兹接触深度 = %0.3f, \t 计算接触深度 = %0.3f ' % (Hz_d1, d_test))
# =============================================================================
    #print('赫兹接触半径 = %0.3f' % r1)
    
    qjbl.set_v('De',c.reshape(x_grid_number, y_grid_number))
        ###图1
    ff1.clf()
    a1 = ff1.add_subplot(111)
    s1 = qjbl.get_v('De')[:,int((y_grid_number+1)/2)]
    a1.plot(s1)
    canvas1.show()
    #text1.set('图1 - 最大接触应力分布图'+'  F='+F_ext+'N')
    
    ###图2
    ff2.clf()
    a2 = ff2.gca(projection='3d')
    x = np.arange(0, x_grid_number)
    y = np.arange(0, y_grid_number)
    X, Y = np.meshgrid(x, y)
    Z = qjbl.get_v('De').T
    # Plot the surface.
    surf = a2.plot_surface(X, Y, Z, cmap=cm.coolwarm,
                         linewidth=0,)
    ff2.colorbar(surf, shrink=0.5, aspect=10)
    canvas2.show()
def func6(win,tl):
    qjbl.set_v('Dd',0)

####绘图函数###################################################
    def hui1():
        f1.clf()
        a1 = f1.add_subplot(111)
        s1 = qjbl.get_v('Dd')[:,int((int(Ys.get())+1)/2)]
        a1.plot(s1)
        canvas1.show()
        text1.set('图1 - 最大接触应力分布图'+'  F='+F.get()+'N')
    
       
        
    def hui2():
        f2.clf()
        a2 = f2.gca(projection='3d')
        x = np.arange(0, int(Xs.get()))
        y = np.arange(0, int(Ys.get()))
        X, Y = np.meshgrid(x, y)
        Z = qjbl.get_v('Dd').T
        # Plot the surface.
        surf = a2.plot_surface(X, Y, Z, cmap=cm.coolwarm,
                             linewidth=0,)
        f2.colorbar(surf, shrink=0.5, aspect=10)
        canvas2.show()
        text2.set('图2 - 滚子接触应力三维分布图'+'  F='+F.get()+'N')
    #####################################################    
    
    ########################################
    # =============================================================================
    # root2 = Tk()
    # root2.title('滚子修形计算')
    # =============================================================================
    
    #tl = Toplevel()
    #tl.title('圆锥直线型修形')
    Fr = Frame(tl)
    Fr.grid()
    f1 = Frame(Fr)
    f1.grid(row=0,column=0,sticky=N,pady=20,)
    
    f1_1 = Frame(f1)
    f1_1.grid(row=0,column=0,pady=2,padx=20,sticky=N+W)
    
    ll = Label(f1_1,text='参数设置',font=('黑体',15))
    ll.grid(row=0,column=0,padx=20,pady=2,sticky=W+N)
    
    l1 = Label(f1_1,text='滚子长度 L',font=(10))
    l1.grid(row=1,column=0,padx=20,pady=8,sticky=W)
    cd = StringVar()
    cd.set(20)
    e1 = Entry(f1_1,textvariable=cd,)
    e1.grid(row=1,column=1)
    l1_1 = Label(f1_1,text='mm',font=(10))
    l1_1.grid(row=1,column=2,pady=8,sticky=W)
    
    l2 = Label(f1_1,text='有效长度 Lw',font=(10))
    l2.grid(row=2,column=0,padx=20,pady=8,sticky=W)
    yx = StringVar()
    yx.set(18)
    e2 = Entry(f1_1,textvariable=yx)
    e2.grid(row=2,column=1)
    l2_2 = Label(f1_1,text='mm',font=(10))
    l2_2.grid(row=2,column=2,pady=8,sticky=W)
    
    l3 = Label(f1_1,text='滚子半径 R',font=(10))
    l3.grid(row=3,column=0,padx=20,pady=8,sticky=W)
    R = StringVar()
    R.set(16)
    e3 = Entry(f1_1,textvariable=R)
    e3.grid(row=3,column=1)
    l3_3 = Label(f1_1,text='mm',font=(10))
    l3_3.grid(row=3,column=2,pady=8,sticky=W)
    
    l6 = Label(f1_1,text='弹性模量 E',font=(10))
    l6.grid(row=6,column=0,padx=20,pady=8,sticky=W)
    E = StringVar()
    E.set(200000)
    e6 = Entry(f1_1,textvariable=E)
    e6.grid(row=6,column=1)
    l6_6 = Label(f1_1,text='Mpa',font=(10))
    l6_6.grid(row=6,column=2,pady=8,sticky=W)
    
    l7 = Label(f1_1,text='泊松比 μ',font=(10))
    l7.grid(row=7,column=0,padx=20,pady=8,sticky=W)
    mo = StringVar()
    mo.set(0.3)
    e7 = Entry(f1_1,textvariable=mo)
    e7.grid(row=7,column=1)
    
    l8 = Label(f1_1,text='滚子轴向网格数 Xs',font=(10))
    l8.grid(row=8,column=0,padx=20,pady=8,sticky=W)
    Xs = StringVar()
    Xs.set(60)
    e8 = Entry(f1_1,textvariable=Xs)
    e8.grid(row=8,column=1)
    
    l9 = Label(f1_1,text='滚子径向网格数 Ys',font=(10))
    l9.grid(row=9,column=0,padx=20,pady=8,sticky=W)
    Ys = StringVar()
    Ys.set(40)
    e9 = Entry(f1_1,textvariable=Ys)
    e9.grid(row=9,column=1)
    
    l10 = Label(f1_1,text='施加载荷 F',font=(10))
    l10.grid(row=10,column=0,padx=20,pady=8,sticky=W)
    F = StringVar()
    F.set(1000)
    e10 = Entry(f1_1,textvariable=F)
    e10.grid(row=10,column=1)
    l10_10 = Label(f1_1,text='N',font=(10))
    l10_10.grid(row=10,column=2,pady=8,sticky=W)
    
    
    b = Button(f1_1,text='开始计算',command=lambda :yzds.fun(float(cd.get()),float(R.get()),float(yx.get()),float(E.get())
                  ,float(mo.get()),int(Xs.get()),int(Ys.get()),float(F.get()),f1,canvas1,f2,canvas2),fg='red')
    b.grid(row=11,column=0,columnspan=2,padx=30,pady=5,ipadx=25,)
    
    
    
    
    f1_2 = Frame(Fr)
    f1_2.grid(row=1,column=0,sticky=N+W,padx=20)
    l9 = Label(f1_2,text='参数对应示意图',font=('黑体',15))
    l9.grid(row=0,column=0,padx=20,pady=8,sticky=W)
    c = Canvas(f1_2,bg='white',height=270,width=320)
    c.grid(row=1,column=0,padx=20,pady=40)
    img = PhotoImage(file = 'syt.gif')
    c.create_image(0,0,anchor='nw',image=img)
    
    
    
    
    #########  绘图   ###################################
    f2_1 = Frame(Fr)
    f2_1.grid(row=0,column=1,pady=20,sticky=W,padx=30)
    
    lr = Label(f2_1,text='计算结果',font=('黑体',15))
    lr.pack(anchor='w',pady=2)
# =============================================================================
#     b1 = Button(f2_1,text='绘图1',command=hui1,fg='blue')
#     b1.pack(anchor='w',ipadx=20)
# =============================================================================
    text1=StringVar()
    text1.set('图1 - 最大接触应力分布图')
    lr_1 = Label(f2_1,textvariable=text1,font=(10))
    lr_1.pack()
    
    f1 = Figure(figsize=(7, 3), dpi=100)
    canvas1 = FigureCanvasTkAgg(f1, master=f2_1)
    canvas1.show()
    canvas1.get_tk_widget().pack(pady=10,anchor='w')
    #工具按钮
    toolbar1 = NavigationToolbar2TkAgg(canvas1, f2_1)
    toolbar1.update()
    canvas1._tkcanvas.pack()
    
        
    f2_2 = Frame(Fr)
    f2_2.grid(row=1,column=1,pady=2,sticky=W,padx=30)
# =============================================================================
#     b2 = Button(f2_2,text='绘图2',command=hui2,fg='blue')
#     b2.pack(anchor='w',ipadx=20)
# =============================================================================
    text2=StringVar()
    text2.set('图2 - 滚子接触应力三维分布图')
    lr_2 = Label(f2_2,textvariable=text2,font=(10))
    lr_2.pack()
    
    f2 = Figure(figsize=(7, 3), dpi=100)
    canvas2 = FigureCanvasTkAgg(f2, master=f2_2)
    canvas2.show()
    canvas2.get_tk_widget().pack(pady=2,anchor='w')
    #工具按钮
    toolbar2 = NavigationToolbar2TkAgg(canvas2, f2_2)
    toolbar2.update()
    canvas2._tkcanvas.pack()
    #############################################
    win.mainloop()