Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*-coding:Latin-1 -*
- from tkinter import *
- from random import randrange
- from math import *
- from numpy import *
- import scipy.linalg
- g=9.81
- dt=0.1
- class Master(object):
- def __init__(self,txt,can,b):
- self.master=b
- self.b=b
- self.can = can
- self.poll()
- def poll (self) :
- self.b.simuler()
- txt.delete(1.0,END)
- txt.insert(END,"Heigh (m) H = ")
- txt.insert(END,ceil(Tank.h*100)/100)
- txt.insert(END,"\nInput Flow Rate (m3/s) U = ")
- txt.insert(END,ceil(Tank.U*100)/100)
- txt.insert(END,"\nOutput Flow Rate (m3/s) Q = ",)
- txt.insert(END,ceil(Tank.s11*sqrt(2*g*Tank.h)*1000)/1000)
- self.master.can.after(20,self.poll)
- def Umoins(self): #on incrémente U1 m3/s
- self.b.U=-0.1+self.b.U
- if (self.b.U<=0):
- self.b.U=0
- # A faire ajouter un controle associé au bouton Uplus
- def Uplus(self): # on incrémente U1 m3/s
- self.b.U = 0.1 + self.b.U
- if (self.b.U <= 2):
- self.b.U = 2
- class Bac(object):
- def __init__(self, can,num): # on definit les valeurs initiales
- self.can = can #ref du canevas
- self.x_can = int(can.cget("width"))
- self.y_can = int(can.cget("height"))
- self.s11=0.1*0.1*pi #rayon de la section de fuite 0.1 m*
- self.S1=1*1*pi # rayon du bac 1 m
- # conditions intiales
- self.h=1 # hauteur initale
- self.U=0 # débit initial
- self.zoom=5
- def drawbac(self,h,U,zoom) :
- self.can.delete(ALL)
- x0=self.x_can/3 # position x0
- y0=self.y_can/3 # position y0
- # Le bac
- Bac1=matrix([[0, 10 ,10, 0, 0],[ 0,0, -h ,-h,0],[1,1,1,1,1]]) # 1 pixel par mètre
- pipe1=matrix([[0, 20 ,20, 0, 0],[ 0,0, -2 ,-2,0],[1,1,1,1,1]])
- Ularge=ceil(U*100)/10 # 5 pixels pour 1 m^3/s
- input1=matrix([[-Ularge, 0 ,0, -Ularge, -Ularge],[ -30,-30, -32 ,-32,0],[1,1,1,1,1]])
- #Facteur d'échelle et translation
- Zoom = matrix([[zoom,0,0],[0,zoom,0],[0,0,1]])
- Tr = matrix([[1,0,x0],[0,1,y0],[0,0,1]])
- Bac1 = Tr*Zoom*Bac1
- pipe1 = Tr * Zoom * pipe1
- input1 = Tr * Zoom * input1
- # A Faire : donner la matrice de transformation
- # Appliquer la transformation
- self.can.create_polygon(Bac1[0,0],Bac1[1,0], Bac1[0,1],Bac1[1,1],Bac1[0,2],Bac1[1,2],Bac1[0,3],Bac1[1,3],Bac1[0,4],Bac1[1,4],fill="blue", width=1)
- self.can.create_polygon(pipe1[0,0],pipe1[1,0], pipe1[0,1],pipe1[1,1],pipe1[0,2],pipe1[1,2],pipe1[0,3],pipe1[1,3],pipe1[0,4],pipe1[1,4],fill="green", width=1)
- self.can.create_polygon(input1[0,0],input1[1,0], input1[0,1],input1[1,1],input1[0,2],input1[1,2],input1[0,3],input1[1,3],input1[0,4],input1[1,4],fill="red", width=1)
- def simuler(self):
- self.h=10 # A faire étbalir par RK4
- # gestion des saturation niveau dans 0 - 30
- if(self.h<=0):
- self.h=0
- if(self.h>=30):
- self.h=30
- self.drawbac(self.h,self.U,self.zoom)
- def f(self,x,u):
- # fonction à écrire
- return(dx)
- #programme de test de la classe Pendule
- if __name__ == "__main__":
- fenetre = Tk()
- fenetre.title(" Evolution du niveau d'eau dans un Bac ")
- fenetre.resizable(width=False, height=False)
- can = Canvas(width =900, height =900, bg ="ivory", bd =2, relief =SUNKEN)
- can.pack(padx =8, pady =8, side =LEFT)
- Tank = Bac(can,1) # creation du bac
- txt=Text(fenetre,width=30,height=5)
- txt.pack()
- Gestion=Master(txt,can,Tank) # objet maître pour gerer l'évolution
- bout_Umoins = Button(fenetre, text ="U--", command =Gestion.Umoins)
- bout_Umoins.pack()
- bout_Uplus = Button(fenetre, text="U++", command=Gestion.Uplus)
- bout_Uplus.pack()
- # A faire un bouton Uplus
- fenetre.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement