-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.py
131 lines (106 loc) · 4.63 KB
/
run.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
# This script serves as an entry point to the package.
import tkinter as tk
from tkinter import font
import numpy as np
from brain import ResultsApp, ParameterApp, WaveFunction2D, ImaginaryTimeStepper
from time import time
from enum import Enum
class ProgramChoice(Enum):
'''This enumerator is just a good practice, but really not neccessary.
It keeps track of which program the user has selected.
'''
PARAMETERS = 0
RESULTS = 1
NOT_IMPLEMENTED = 2
class BECApp(tk.Frame):
'''Class that produces the initial GUI where the user selects, which operation they want to perform.
'''
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
# set up padding of GUI elements to make it look nicer.
self.padx = 25
self.pady = 25
self.ipadx = 15
self.ipady = 15
self.init_frame()
def init_frame(self):
'''Initializes the GUI elements.
'''
self.top_level_frame = tk.Frame(self.parent)
self.top_level_frame.pack()
# set up fonts
self.font_medium = font.Font(family="Helvetica", size=12, weight=tk.NORMAL)
self.font_large = font.Font(family="Helvetica", size=18, weight=tk.NORMAL)
t = ("Welcome!\n"
"If you want to simulate a Bose-Einstein Condensate and choose the Parameters for the simulation,\n"
"click the button on the left.\n"
"If you have a finished simulation and want to look at the results,\n"
"click the button in the right.")
# set up welcome text
info_label = tk.Label(self.top_level_frame, text=t, font=self.font_medium)
info_label.pack(side=tk.TOP, padx=self.padx, pady=self.pady, ipadx=self.ipadx, ipady=self.ipady)
# set up buttons
self.parameters_button = tk.Button(self.top_level_frame, command=self.run_parameters, text="Parameters", font=self.font_large, borderwidth=5)
self.parameters_button.pack(side=tk.LEFT, padx=self.padx, pady=self.pady, ipadx=self.ipadx, ipady=self.ipady)
self.results_button = tk.Button(self.top_level_frame, command=self.run_results, text="Results", font=self.font_large, borderwidth=5)
self.results_button.pack(side=tk.RIGHT, padx=self.padx, pady=self.pady, ipadx=self.ipadx, ipady=self.ipady)
def run_parameters(self):
'''Executed when the user chose the parameter app.
Destroys window and spawns the parameter app.
'''
global root, choice
choice = ProgramChoice.PARAMETERS
root.destroy()
def run_results(self):
'''Executed when the user chose the results app.
Destroys window and spawns the results app.
'''
global root, choice
choice = ProgramChoice.RESULTS
root.destroy()
if __name__ == "__main__":
choice = None
# set up the window for the startup GUI
root = tk.Tk("Bose Einstein Kondensation")
root.title("Numerical ground state of rotating Bose-Einstein Condensates")
root.geometry('+30+30')
app = BECApp(root)
root.mainloop()
# if case: react to user input
if choice == ProgramChoice.PARAMETERS:
# launch parameters app
root = tk.Tk("Bose Einstein Kondensation")
root.title("Numerical ground state of rotating Bose-Einstein Condensates : Parameter Selection")
root.geometry("+40+40")
app = ParameterApp(root)
root.mainloop()
# executed when the start simulation button was clicked
if app.pressedStart:
start = time()
# set up parameters and initial wave function according to user input
p = app.paramObj
del app
del root
psi0 = WaveFunction2D(p)
psi0.initPsi_0()
i = ImaginaryTimeStepper(psi0, p)
# starting the simulation
i.BFFP()
# it's better to close the file manually...
i.dataM.closeFile()
print("[INFO] File {} was created.".format(p.filename))
# time the simulation took
m, s = divmod(int(time()-start), 60)
h, m = divmod(m, 60)
print("[INFO] This calculation took {} h {} min {} s.".format(h, m, s))
elif choice == ProgramChoice.RESULTS:
# Launch results app
root = tk.Tk()
root.geometry("+40+40")
root.title("Numerical ground state of rotating Bose-Einstein Condensates : Result Presentation")
app = ResultsApp(root)
root.mainloop()
else:
# nothing was selected, quitting the program
print("[INFO] Nothing was selected, quitting.")