Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. # -*-coding:Latin-1 -*
  2. from tkinter import *
  3. from random import randrange
  4. from math import *
  5. from numpy import *
  6. import scipy.linalg
  7.  
  8. g=9.81
  9. dt=0.1
  10.  
  11.  
  12.  
  13. class Master(object):
  14. def __init__(self,txt,can,b):
  15.  
  16. self.master=b
  17. self.b=b
  18.  
  19. self.can = can
  20. self.poll()
  21.  
  22. def poll (self) :
  23.  
  24.  
  25. self.b.simuler()
  26. txt.delete(1.0,END)
  27.  
  28. txt.insert(END,"Heigh (m) H = ")
  29. txt.insert(END,ceil(Tank.h*100)/100)
  30.  
  31. txt.insert(END,"\nInput Flow Rate (m3/s) U = ")
  32. txt.insert(END,ceil(Tank.U*100)/100)
  33.  
  34. txt.insert(END,"\nOutput Flow Rate (m3/s) Q = ",)
  35. txt.insert(END,ceil(Tank.s11*sqrt(2*g*Tank.h)*1000)/1000)
  36.  
  37. self.master.can.after(20,self.poll)
  38.  
  39.  
  40.  
  41.  
  42. def Umoins(self): #on incrémente U1 m3/s
  43.  
  44. self.b.U=-0.1+self.b.U
  45. if (self.b.U<=0):
  46. self.b.U=0
  47.  
  48. # A faire ajouter un controle associé au bouton Uplus
  49.  
  50. def Uplus(self): # on incrémente U1 m3/s
  51.  
  52. self.b.U = 0.1 + self.b.U
  53. if (self.b.U <= 2):
  54. self.b.U = 2
  55.  
  56.  
  57.  
  58. class Bac(object):
  59.  
  60.  
  61. def __init__(self, can,num): # on definit les valeurs initiales
  62. self.can = can #ref du canevas
  63. self.x_can = int(can.cget("width"))
  64. self.y_can = int(can.cget("height"))
  65.  
  66.  
  67. self.s11=0.1*0.1*pi #rayon de la section de fuite 0.1 m*
  68. self.S1=1*1*pi # rayon du bac 1 m
  69.  
  70.  
  71. # conditions intiales
  72.  
  73. self.h=1 # hauteur initale
  74. self.U=0 # débit initial
  75.  
  76. self.zoom=5
  77.  
  78.  
  79.  
  80.  
  81.  
  82. def drawbac(self,h,U,zoom) :
  83.  
  84. self.can.delete(ALL)
  85.  
  86. x0=self.x_can/3 # position x0
  87. y0=self.y_can/3 # position y0
  88.  
  89. # Le bac
  90. Bac1=matrix([[0, 10 ,10, 0, 0],[ 0,0, -h ,-h,0],[1,1,1,1,1]]) # 1 pixel par mètre
  91. pipe1=matrix([[0, 20 ,20, 0, 0],[ 0,0, -2 ,-2,0],[1,1,1,1,1]])
  92. Ularge=ceil(U*100)/10 # 5 pixels pour 1 m^3/s
  93. input1=matrix([[-Ularge, 0 ,0, -Ularge, -Ularge],[ -30,-30, -32 ,-32,0],[1,1,1,1,1]])
  94. #Facteur d'échelle et translation
  95.  
  96. Zoom = matrix([[zoom,0,0],[0,zoom,0],[0,0,1]])
  97.  
  98. Tr = matrix([[1,0,x0],[0,1,y0],[0,0,1]])
  99.  
  100. Bac1 = Tr*Zoom*Bac1
  101.  
  102. pipe1 = Tr * Zoom * pipe1
  103.  
  104. input1 = Tr * Zoom * input1
  105.  
  106. # A Faire : donner la matrice de transformation
  107.  
  108.  
  109.  
  110. # Appliquer la transformation
  111.  
  112. 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)
  113. 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)
  114. 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)
  115.  
  116.  
  117. def simuler(self):
  118.  
  119.  
  120. self.h=10 # A faire étbalir par RK4
  121.  
  122. # gestion des saturation niveau dans 0 - 30
  123. if(self.h<=0):
  124. self.h=0
  125. if(self.h>=30):
  126. self.h=30
  127.  
  128. self.drawbac(self.h,self.U,self.zoom)
  129.  
  130.  
  131. def f(self,x,u):
  132. # fonction à écrire
  133. return(dx)
  134.  
  135.  
  136.  
  137.  
  138. #programme de test de la classe Pendule
  139. if __name__ == "__main__":
  140. fenetre = Tk()
  141.  
  142. fenetre.title(" Evolution du niveau d'eau dans un Bac ")
  143. fenetre.resizable(width=False, height=False)
  144. can = Canvas(width =900, height =900, bg ="ivory", bd =2, relief =SUNKEN)
  145. can.pack(padx =8, pady =8, side =LEFT)
  146.  
  147. Tank = Bac(can,1) # creation du bac
  148.  
  149. txt=Text(fenetre,width=30,height=5)
  150. txt.pack()
  151.  
  152.  
  153. Gestion=Master(txt,can,Tank) # objet maître pour gerer l'évolution
  154.  
  155. bout_Umoins = Button(fenetre, text ="U--", command =Gestion.Umoins)
  156. bout_Umoins.pack()
  157.  
  158. bout_Uplus = Button(fenetre, text="U++", command=Gestion.Uplus)
  159. bout_Uplus.pack()
  160.  
  161. # A faire un bouton Uplus
  162.  
  163. fenetre.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement