Sunteți pe pagina 1din 5

1 # -----------------------------------------------------------------------------

2 # SimReolMERE.py
3 # -----------------------------------------------------------------------------
4 """
5 Author: George IPATE
6 Created: 2018 Aug 15
7 Modified: 2018 Aug 27
8
9 Description
10 -----------
11 Build a GUI wrapper to explore the rheological properties of applle.
12 """
13 # This will work in Python 3.5
14 import tkinter as Tkinter
15 from tkinter import *
16 # -----------------------------------------------------------------------------
17 # To use matplotlib, the author must use the TkAgg backend, or none of this will
18 # work and a long string of inexplicable error messages will ensue.
19 # -----------------------------------------------------------------------------
20 import matplotlib
21 matplotlib.use('TkAgg')
22 import sys
23 import numpy as np
24 from numpy import exp
25 import matplotlib.pyplot as plt
26 import time
27 from scipy.integrate import odeint
28
29
30 # Define a bold font:
31 BOLD = ('Courier', '14', 'bold')
32
33 # Create main application window.
34 root = Tkinter.Tk()
35 root.geometry("900x500+0+0")
36 #root.configure(background='grey')
37 root.title("SimReolMERE")
38
39 #==========================Time=======================================================
40 localtime=time.asctime(time.localtime(time.time()))
41 #========================Info=========================================================
42 lblInfo = Tkinter.Label(font=('arial',15,'bold'), text="Simulare test fluaj si
recuperare MERE "
43 ,fg="Steel Blue")
44 lblInfo.pack()
45
46 lblInfoTime = Tkinter.Label(font=('arial',10,'bold'), text=localtime
47 ,fg="Steel Blue")
48 lblInfoTime.pack()
49
50
51 # Create a frame for variable names and entry boxes for their values.
52 frame = Tkinter.Frame(root)
53 frame.pack(side='left')
54
55 # Variables for the calculation, and default values.
56 sigmaE = DoubleVar()
57 eta = DoubleVar()
58 youngE = DoubleVar()
59 deformi = DoubleVar()
60 step = IntVar()
61 #step.set('188')
62 durata = IntVar()
63 #durata.set('6.0')
64
65 # Create a text box explaining the application.
66 row_counter = 0
67 greeting = Tkinter.Label(frame,text="Date intrare program", fg="purple",font=BOLD)
68 greeting.grid(row=row_counter, column=0)
69 # Create text boxes and entry boxes for the variables.
70 # Use grid geometry manager instead of packing the entries in.
71
72 row_counter += 1
73 sigmaE_text = Tkinter.Label(frame, text='Tensiunea initiala [N/mm2]:')
74 sigmaE_text.grid(row=row_counter, column=0)
75
76 sigmaE_entry = Tkinter.Entry(frame, width=8, textvariable=sigmaE)
77 sigmaE_entry.grid(row=row_counter, column=1)
78
79 row_counter += 1
80 eta_text = Tkinter.Label(frame, text='coef de frec. vasc. eta_m []:')
81 eta_text.grid(row=row_counter, column=0)
82
83 eta_entry = Tkinter.Entry(frame, width=8, textvariable=eta)
84 eta_entry.grid(row=row_counter, column=1)
85
86 row_counter += 1
87 youngE_text = Tkinter.Label(frame, text='modul elasticitate eta_m [1/h]:')
88 youngE_text.grid(row=row_counter, column=0)
89
90 youngE_entry = Tkinter.Entry(frame, width=8, textvariable=youngE)
91 youngE_entry.grid(row=row_counter, column=1)
92
93 row_counter += 1
94 deformi_text = Tkinter.Label(frame, text='Valoare initiala deformatie [N/mm2]:')
95 deformi_text.grid(row=row_counter, column=0)
96
97 deformi_entry = Tkinter.Entry(frame, width=8, textvariable=deformi)
98 deformi_entry.grid(row=row_counter, column=1)
99
100 row_counter += 1
101 step_text = Tkinter.Label(frame, text='Pasi timp simulare :')
102 step_text.grid(row=row_counter, column=0)
103
104 step_entry = Tkinter.Entry(frame, width=8, textvariable=step)
105 step_entry.grid(row=row_counter, column=1)
106
107 row_counter += 1
108 durata_text = Tkinter.Label(frame, text='Durata test [min]:')
109 durata_text.grid(row=row_counter, column=0)
110
111 durata_entry = Tkinter.Entry(frame, width=8, textvariable=durata)
112 durata_entry.grid(row=row_counter, column=1)
113
114
115 # function that returns dy/dt
116 def modelBranza(s,t):
117 # Convert StringVar data to numerical data.
118
119 sigmaE_ = float(sigmaE.get())
120 eta_ = float(eta.get())
121 youngE_ = float(youngE.get())
122 deformi_ = float(deformi.get())
123 step_ = int(step.get())
124 durata_ = int(durata.get())
125 s = s[0]
126 #dsdt =(-1/eta_)*s + sigmaE_ # Modelul Maxwell
127 dsdt =(-youngE_/eta_)*s + sigmaE_/eta_ # Modelul Kelvin-Voigth
128
129 return [dsdt]
130
131 def modelBranzaR(sol,t):
132 # Convert StringVar data to numerical data.
133
134 sigmaE_ = float(sigmaE.get())
135 eta_ = float(eta.get())
136 youngE_ = float(youngE.get())
137 deformi_ = float(deformi.get())
138 step_ = int(step.get())
139 durata_ = int(durata.get())
140 sol = sol[0]
141 #dsdt =(-1/eta_)*s + sigmaE_ # Modelul Maxwell
142 dsoldt =(-youngE_/eta_)*sol + sigmaE_/(eta_*youngE_) # Modelul Kelvin-Voigth
143
144 return [dsoldt]
145
146 # Define a function to create the desired plot.
147 def make_plot(event=None):
148 # Get these variables from outside the function, and update them.
149 # Convert StringVar data to numerical data.
150 sigmaE_ = float(sigmaE.get())
151 eta_ = float(eta.get())
152 youngE_ = float(youngE.get())
153 deformi_ = float(deformi.get())
154 step_ = int(step.get())
155 durata_ = int(durata.get())
156
157
158 # initial condition
159
160 #s0 = [sigmai_]
161 s0 = [deformi_]
162
163 # Define the range of the plot.
164 t_min = 0
165 t_max = durata_
166 dt = durata_/step_
167 t = np.arange(t_min, t_max+dt, dt)
168
169
170 # solve ODEs
171
172 s = odeint(modelBranza,s0,t)
173
174 deformREL = s[:,0]
175
176
177 t1 = np.arange(t_max, 2*t_max+dt, dt)
178 sol0 = [max(deformREL)]
179 sol = odeint(modelBranzaR,sol0,t1)
180 solEX = sol[:,0]
181
182 t2 = np.linspace(t_min, t_max+dt, 12)
183 t3 = np.linspace(t_max+dt, 2*t_max+dt, 12)
184 t4 = np.linspace(t_min, 2*t_max+dt, 24)
185
186 sigma0F = np.zeros(len(t4))
187
188
189 for i in range(24):
190 if i<=12:
191 sigma0F[i] = float(sigmaE_)
192 else:
193 sigma0F[i] = 0
194
195 #print('t1 ',sigma0F,sigma0R,' t ',len(t),'t2',len(t2),'t3',len(t3))
196
197 deformMas1 =
[0,0.015537686,0.016082868,0.01662805,0.01662805,0.016900641,0.016900641,0.017173232,
0.017718414,0.017991004,0.018536186,0.018808777]
198 deformMas2 =
[0.018808777,0.00845032,0.00845032,0.00845032,0.008177729,0.008177729,0.008177729,0.0
07905138,0.007632547,0.007359956,0.007087365,0.007087365]
199
200
201
202
203 #print(len(SigmaMas))
204
205 # Create the plot.
206 # plot results
207 plt.figure(1)
208 plt.title('Test fluaj si recuperare')
209 plt.grid()
210
211
#plt.plot(t,SigmaREL,'k--',linewidth=3,label='SigmaSIM',t1,solEX,'b-',linewidth=3,lab
el='SigmaEX')
212 plt.plot(t,deformREL,'k-',linewidth=3,label='deformF')
213 plt.plot(t1,solEX,'b-',linewidth=3,label='deformRE')
214 plt.plot(t2,deformMas1,'r-',linewidth=3,marker='o',label='deformF_EXP')
215 plt.plot(t3,deformMas2,'m-',linewidth=3,marker='x',label='deformRE_EXP')
216
217 plt.xlabel('Timp[min]')
218 plt.ylabel('deform [mm]')
219 plt.legend(loc='best')
220
221 time.sleep(5)
222
223 # plot results
224 plt.figure(2)
225 plt.grid()
226 plt.plot(t4,sigma0F,'g-',linewidth=3,label='Sigma0')
227 plt.title('Sarcina')
228 plt.xlabel('Timp[min]')
229 plt.ylabel('Sigma0[N/mm2]')
230 plt.legend(loc='best')
231
232 plt.show()
233
234 def qExit():
235 root.destroy()
236
237 def Date():
238 valueSigmaE = float(sigmaE.get())
239 valueEta = float(eta.get())
240 valueYoungE = float(youngE.get())
241 valueDeformi = float(deformi.get())
242 valueStep = int(step.get())
243 valueDurata = int(durata.get())
244 sigmaE.set(valueSigmaE+0.10092)
245 #eta.set(2.923)
246 eta.set(valueEta+6.993)
247 #eta.set(8.239)
248 youngE.set(valueYoungE+5.3617)
249 deformi.set(valueDeformi+0)
250 step.set(valueStep+500)
251 durata.set(valueDurata+10)
252
253 def Reset():
254 sigmaE.set(0)
255 eta.set(0)
256 youngE.set(0)
257 deformi.set(0)
258 step.set(0)
259 durata.set(0)
260 plt.close()
261
262 # Add a button to create the plot.
263 MakePlot = Tkinter.Button(frame, command=make_plot,width=16,fg="red", text="Ruleaza
program")
264 MakePlot.grid(row=1, column=15)
265
266 BtnDate = Tkinter.Button(frame, command=Date,width=16,fg="blue4", text="Introduceti
datele")
267 BtnDate.grid(row=3, column=15)
268
269 BtnReset = Tkinter.Button(frame, command=Reset,width=16,fg="blue4", text="Reseteaza
grafic")
270 BtnReset.grid(row=5, column=15)
271
272 BtnExit = Tkinter.Button(frame, command=qExit,width=16,fg="green4", text="Exit")
273 BtnExit.grid(row=7, column=15)
274
275
276 canvas = Canvas(root, width = 300, height = 300)
277 canvas.pack()
278 img = PhotoImage(file='D:\MSPE\Fisiere Python\SimPropReologice\Test
fluaj\TestFluaj.png')
279 canvas.create_image(20,20, anchor=NW, image=img)
280
281
282 # Activate the window.
283 root.mainloop()
284

S-ar putea să vă placă și