Commit 573aa506 authored by SAHEB ETTABAA Mohamed Yassine's avatar SAHEB ETTABAA Mohamed Yassine
Browse files

Upload New File

parent d8fdcaea
#motor.py
import timeseries
import tkinter as tk
#Constructeurs
def create(a,b,c,f):
m = {
#On a ay" + by' + cy = f
"a" : a,
"b" : b,
"c" : c,
"f" : f
}
m["y0"]=0.0
m["y1"]=0.0
m["y2"]=0.0
return m
#Accesseurs
def get_a(m): return m['a']
def get_b(m): return m['b']
def get_c(m): return m['c']
def get_f(m): return m['f']
def get_y0(m): return m['y0']
def get_y1(m): return m['y1']
def get_y2(m): return m['y2']
#Modificateurs
def set_a(m,value): m['a'] = value
def set_b(m,value): m['b'] = value
def set_c(m,value): m['c'] = value
def set_f(m,value): m['f'] = value
def set_y0(m,value): m['y0'] = value
def set_y1(m,value): m['y1'] = value
def set_y2(m,value): m['y2'] = value
def simulate(m,sim_dt, log_dt, duration):
ts = timeseries.create()
t = 0
data = []
log_timer = 0
#définition des constantes
y0 = m['y0']
y1 = m['y1']
y2 = m['y2']
a = m["a"]
b = m["b"]
c = m["c"]
f = m["f"]
while t < duration :
#Méthode d'Euler implicite
y2 = (f/a) - (b/a)*y1 -(c/a)*y0
y1 += y2 * sim_dt
y0 += y1 * sim_dt
t += sim_dt
log_timer += sim_dt
if log_timer > log_dt :
log_timer = 0
data.append([t,y0,y1,y2])
timeseries.set_data(ts,data)
timeseries.set_labels(ts,['Time(s)','y','y\'','y"'])
return ts
def main(a,b,c,f,sim_dt,log_dt,duration):
motor = create(a,b,c,f)
ts = simulate(motor,sim_dt,log_dt,duration)
timeseries.plot(ts)
timeseries.dump(ts,'motor.csv')
if __name__ == '__main__':
#Paramètres initiales pour l'interface
r = tk.Tk()
r.title("Simulateur d'équations différentielles")
#Corps de l'interface
model = tk.Label(r, text="l'équa diff est de type: ay\" + by' + cy = f")
model.grid(row=0, column=0)
a_label = tk.Label(r,text="a: ")
a_label.grid(row=2,column=0)
a_entry = tk.Entry(r)
a_entry.grid(row=2,column=1)
b_label = tk.Label(r,text="b: ")
b_label.grid(row=3,column=0)
b_entry = tk.Entry(r)
b_entry.grid(row=3,column=1)
c_label = tk.Label(r,text="c: ")
c_label.grid(row=4,column=0)
c_entry = tk.Entry(r)
c_entry.grid(row=4,column=1)
f_label = tk.Label(r,text="f: ")
f_label.grid(row=5,column=0)
f_entry = tk.Entry(r)
f_entry.grid(row=5,column=1)
sim_dt_label = tk.Label(r,text="sim_dt: ")
sim_dt_label.grid(row=6,column=0)
sim_dt_entry = tk.Entry(r)
sim_dt_entry.grid(row=6,column=1)
log_dt_label = tk.Label(r,text="log_dt: ")
log_dt_label.grid(row=7,column=0)
log_dt_entry = tk.Entry(r)
log_dt_entry.grid(row=7,column=1)
duration_label = tk.Label(r,text="Durée: ")
duration_label.grid(row=8,column=0)
duration_entry = tk.Entry(r)
duration_entry.grid(row=8,column=1)
def all():
a = float(a_entry.get())
b = float(b_entry.get())
c = float(c_entry.get())
f = float(f_entry.get())
sim_dt = float(sim_dt_entry.get())
log_dt = float(log_dt_entry.get())
duration = float(duration_entry.get())
main(a,b,c,f,sim_dt,log_dt,duration)
Generate_button = tk.Button(r,text="Simuler", command=all)
Generate_button.grid(row=9,column=1)
r.mainloop()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment