-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsourceSinkGUI.py
160 lines (131 loc) · 6.29 KB
/
sourceSinkGUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 6 20:43:55 2019
@author: DIPAK
"""
from tkinter import *
from tkinter import ttk
import tkinter
from matplotlib import pyplot as plt
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
# Implement the default Matplotlib key bindings.
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
import numpy as np
import sourceSink
#Make the root widget
root = tkinter.Tk()
root.wm_title("Source Sink")
root.geometry('1500x850')
###importing values for source and sink
u_source, v_source = sourceSink.Source()
X, Y = sourceSink.pos()
u_sink, v_sink = sourceSink.Sink()
#######################################
#########Function to plot the graph #########################################
def plotgraph(X, Y, u_source, v_source, f1):
fig1 = Figure(figsize=(9,7), dpi=100)
fig1.add_subplot(111, xlabel = "X Axis", ylabel = "Y Axis").streamplot(X,Y, u_source, v_source, density = 2, linewidth = 1, arrowsize = 2, arrowstyle = '->' )
#fig.add_subplot(111).scatter(0,0)
canvas = FigureCanvasTkAgg(fig1, master=f1) # A tk.DrawingArea.
canvas.draw()
#canvas.get_tk_widget().pack(side=tkinter.RIGHT, fill=tkinter.NONE, expand=0)
canvas.get_tk_widget().grid(row = 2, column = 3, sticky = S)
def getSourceStrength(f1):
source_strength = Entry.get(sourceStrength_entry)
#source_strength = float(source_strength)
u_source, v_source = sourceSink.SourceTry((source_strength))
X, Y = sourceSink.pos()
plotgraph(X, Y, u_source, v_source, f1)
#Make the notebook
nb = ttk.Notebook(root)
#Make 1st tab
f1 = tkinter.Frame(nb)
#Add the tab
nb.add(f1, text=" Source ")
sourceStrength_label = Label(f1, text = 'Source Strength', font=('bold, 10'))
sourceStrength_label.grid(row = 1, column =0, sticky = W, pady = 30, padx =10)
sourceStrength_entry = Entry(f1, textvariable = StringVar())
sourceStrength_entry.grid(row = 1, column=1, sticky = W)
sourceStrength_button = tkinter.Button(master = f1, text = "Submit", command = getSourceStrength(f1))
sourceStrength_button.grid(row = 1 , column = 2, sticky = W, padx =10)
plotgraph(X, Y, u_source, v_source, f1)
#Make 2nd tab
f2 = tkinter.Frame(nb)
#Add 2nd tab
nb.add(f2, text=" Sink ")
#nb.pack(expand = 1, fill = tkinter.BOTH, side = tkinter.RIGHT)
nb.grid(row = 0 , column = 0 , padx = 10)
sinkStrength_label = Label(f2, text = 'Sink Strength', font=('bold, 10'))
sinkStrength_label.grid(row = 1, column =0, sticky = W, pady = 30, padx =10)
sinkStrength_entry = Entry(f2, textvariable = DoubleVar())
sinkStrength_entry.grid(row = 1, column=1, sticky = W)
sinkStrength_button = tkinter.Button(master = f2, text = "Submit")
sinkStrength_button.grid(row = 1 , column = 2, sticky = W, padx =10)
plotgraph(X, Y, u_sink, v_sink, f2)
#Make 3rd tab
f3 = tkinter.Frame(nb)
#Add 3rd tab
nb.add(f3, text=" Source + Sink ")
#nb.pack(expand = 1, fill = tkinter.BOTH, side = tkinter.RIGHT)
nb.grid(row = 0 , column = 0 , padx = 10)
sourceStrength_label = Label(f3, text = 'Source Strength', font=('bold, 10'))
sourceStrength_label.grid(row = 1, column =0, sticky = W, pady = 20, padx =10)
sourceStrength_entry = Entry(f3, textvariable = DoubleVar())
sourceStrength_entry.grid(row = 1, column=1, sticky = W)
sourceStrength_button = tkinter.Button(master = f3, text = "Submit")
sourceStrength_button.grid(row = 1 , column = 2, sticky = W, padx =10)
sinkStrength_label = Label(f3, text = 'Sink Strength', font=('bold, 10'))
sinkStrength_label.grid(row = 2, column =0, sticky = W, pady = 20, padx =10)
sinkStrength_entry = Entry(f3, textvariable = DoubleVar())
sinkStrength_entry.grid(row = 2, column=1, sticky = W)
sinkStrength_button = tkinter.Button(master = f3, text = "Submit")
sinkStrength_button.grid(row = 2 , column = 2, sticky = W, padx =10)
plotgraph(X, Y, u_source + u_sink,v_source + v_sink , f3)
###############################4th Tab########################################
#Make 4th tab
f4 = tkinter.Frame(nb)
#Add 4th tab
nb.add(f4, text=" Source + Freestream ")
#nb.pack(expand = 1, fill = tkinter.BOTH, side = tkinter.RIGHT)
nb.grid(row = 0 , column = 0 , padx = 10)
N = 50
u_inf = 1.0 # freestream speed
# compute the freestream velocity field
u_freestream = u_inf * np.ones((N, N), dtype=float)
v_freestream = np.zeros((N, N), dtype=float)
# compute the stream-function
psi_freestream = u_inf * Y
psi_source = sourceSink.streamFunction(5.0, 0.0, 0.0, X, Y)
u_SF = u_freestream + u_source
v_SF = v_freestream + v_source
freestream_label = Label(f4, text = 'Freestream Velocity', font=('bold, 10'))
freestream_label.grid(row = 1, column =0, sticky = W, pady = 10, padx =10)
freestream_entry = Entry(f4, textvariable = DoubleVar())
freestream_entry.grid(row = 1, column=1, sticky = W)
freestream_button = tkinter.Button(master = f4, text = "Submit")
freestream_button.grid(row = 1 , column = 2, sticky = W, padx =10)
sourceStrength_label = Label(f4, text = 'Source Strength', font=('bold, 10'))
sourceStrength_label.grid(row = 2, column =0, sticky = W, pady = 10, padx =10)
sourceStrength_entry = Entry(f4, textvariable = DoubleVar())
sourceStrength_entry.grid(row = 2, column=1, sticky = W)
sourceStrength_button = tkinter.Button(master = f4, text = "Submit")
sourceStrength_button.grid(row = 2 , column = 2, sticky = W, padx =10)
sinkStrength_label = Label(f4, text = 'Sink Strength', font=('bold, 10'))
sinkStrength_label.grid(row = 3, column =0, sticky = W, pady = 10, padx =10)
sinkStrength_entry = Entry(f4, textvariable = DoubleVar())
sinkStrength_entry.grid(row = 3, column=1, sticky = W)
sinkStrength_button = tkinter.Button(master = f4, text = "Submit")
sinkStrength_button.grid(row = 3 , column = 2, sticky = W, padx =10)
plotgraph(X, Y, u_SF, v_SF, f4)
def _quit():
root.quit() # stops mainloop
root.destroy() # this is necessary on Windows to prevent
# Fatal Python Error: PyEval_RestoreThread: NULL tstate
quitButton = tkinter.Button(master=root, text="Quit", command=_quit)
quitButton.grid(row = 4, column = 3, sticky = W )
###############################################################################
nb.select(f1)
nb.enable_traversal()
#Enter the mainloop
root.mainloop()