-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThermoelectricOptimizer.py
3551 lines (2851 loc) · 167 KB
/
ThermoelectricOptimizer.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from tkinter import OptionMenu, Button, Checkbutton, Label, Entry, Text, Menu, Frame
from tkinter import Tk, Toplevel
from tkinter import INSERT, END, RIDGE, NORMAL, DISABLED
from tkinter import messagebox, filedialog
from tkinter import StringVar, IntVar, DoubleVar, BooleanVar
from tkinter import font as tkFont
from os import path, remove
import json
from numpy import exp, log10, log, pi, arcsinh, sqrt, arctan
from numpy import inf, vectorize, arange, meshgrid, zeros_like, zeros
from scipy import integrate
from scipy import constants
from scipy.optimize import fsolve
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.backend_bases import key_press_handler
from matplotlib.figure import Figure
###Physical constants
k = constants.k
e = constants.e
h = constants.h
hbar = constants.hbar
m_e = constants.m_e
e0=constants.epsilon_0
class FullScreenApp(object):
def __init__(self, screen, **kwargs):
"""
Change to fullscreen
Input:
-------------------
screen: computer screen
"""
self.screen = screen
edge = 3
self._small = '400x200+0+0'
screen.geometry("{0}x{1}+0+0".format(
screen.winfo_screenwidth() - edge, screen.winfo_screenheight() - edge))
screen.bind('<Escape>', self.toggle_screen)
def toggle_screen(self, event):
small = self.screen.winfo_geometry()
self.screen.geometry(self._small)
self._small = small
class Help:
"""
Produce help windows
"""
def __init__(self):
self.screen_help = Toplevel()
self.screen_help.configure(bg = MainApplication._from_rgb(self, (241, 165, 193)))
self.screen_help.geometry('700x300')
self.screen_help.iconbitmap('icon_spb.ico')
def welcome(self):
"""
Welcome window
"""
text = Text(self.screen_help, height=15)
text.insert(INSERT, 'Welcome to TOSSPB (Thermoelectric Optimizer - SPB Model) App! It is the first Single Parabolic Band (SPB) Model GUI using different scattering mechanisms to determine the optimum carrier concentration for your thermoelectric materials! \n')
text.insert(INSERT, '\n')
text.insert(INSERT, 'You can compute the thermoelectric properties as a function of Hall carrier con-centration or determine the electronic and lattice contribution to the thermal conductivity. ')
text.insert(INSERT, 'The thermoelectric properties can be computed using diverse scat- tering mechanism such as acoustic deformation potential, polar optical phonon, or ionized impurity scattering mechanism. \n')
text.insert(INSERT, '\n')
text.insert(END, 'Furthermore, you can plot and save the data as function of Hall carrier concen- tration(and temperature)! Please check out the documentaries for more informa- tion! \n \n Thank you for choosing the Thermoelectric Optimizer - SPB Model App')
text.grid(row=0, column=0, padx=10, pady=(30, 10))
def documentary(self, *args):
"""
Documentary window
"""
text = Text(self.screen_help, height=15)
text.insert(INSERT, 'Welcome to TOSSPB (Thermoelectric Optimizer - SPB Model) App! \n')
text.insert(INSERT, '\n')
text.insert(END, 'Please read the documentations or send an email to: \n Jan.Poehls@dal.ca \n')
text.grid(row=0, column=0, padx=10, pady=(30, 10))
def about(self):
"""
About window
"""
text = Text(self.screen_help)
text.insert(INSERT, 'This is a program to compute the thermoelectric properties using the SPB model and diverse scattering parameters. \n')
text.insert(INSERT, '\n')
text.insert(INSERT, 'The software was written in Python and Tkinter! This is version v1.0 and I am looking for any suggestions and reports of errors. \n')
text.insert(INSERT, '\n')
text.insert(INSERT, 'This is a free software and should not be used for commercial reasons. \n')
text.insert(INSERT, '\n')
text.insert(INSERT, 'If you have suggestions, concerns, or find errors, please send me an email: \n Jan.Poehls@dal.ca \n ')
text.insert(INSERT, '\n')
text.insert(INSERT, 'I would like to acknowledge the FRQNT PBEEE postdoctoral fellowship! \n \n')
text.insert(INSERT, 'Thank you for choosing the TOSSPB App. \n \n --Jan-- \n \n')
text.insert(INSERT, '\xa9 Jan-Hendrik Poehls, PhD, MSc, BSc, 2020')
text.grid(row=0, column=0, padx=10, pady=(30, 10))
class Computed_Parameters:
"""
Write a temporary file and produce a dictionary and list
Input:
-----------------------------------
compound: str
compound name
temperature: float
temperature in Kelvin
seebeck: float
Seebeck coefficient in microvolts per Kelvin
carrier: float
carrier concentration in per centimeters cube
mobility: float
mobility in centimeters squared per volt and second
thermal: float
total thermal conductivity in watts per meter and Kelvin
dielectric: float
dielectric constant
scatter: int
scatter mechanism
chemical_potential: float
chemical potential in meV
effective_mass: float
density of states effective mass in electron mass
intrinsic_mobility: float
intrinsic mobility in centimeters squared per volt and second
lorenz: float
effective Lorenz number in watts Omega per Kelvin squared
electrical_thermal: float
electronic contribution to the thermal conductivity in watts per Kelvin and meter
lattice_thermal: float
phononic contribution to the thermal conductivity in watts per Kelvin and meter
beta: float
quality factor
zT: float
dimensionless thermoelectric figure of merit
"""
def __init__(self, compound, temperature, seebeck, carrier, mobility, thermal, dielectric, scatter, chemical_potential, effective_mass, intrinsic_mobility, lorenz, electrical_thermal, lattice_thermal, beta, zT):
self.compound = compound
self.temperature = temperature
self.seebeck = seebeck
self.carrier = carrier
self.mobility = mobility
self.thermal = thermal
self.dielectric = dielectric
self.scatter = scatter
self.chemical_potential = chemical_potential
self.effective_mass = effective_mass
self.intrinsic_mobility = intrinsic_mobility
self.lorenz = lorenz
self.electrical_thermal = electrical_thermal
self.lattice_thermal = lattice_thermal
self.beta = beta
self.zT = zT
def temporary_file(self):
"""
write dictionary in temporary file
"""
dic_data = self.get_dictionary()
with open('~temp.json', 'w') as js_file:
json.dump(dic_data, js_file)
def get_dictionary(self):
"""
Create dictionary
Output:
-------------------------
dic_data: dic
dictionary of thermoelectric properties
"""
dic_data = {
'Compound' : self.compound,
'Temperature' : [self.temperature, 'K'],
'Seebeck Coefficient' : [self.seebeck, 'mu V K-1'],
'Hall Carrier Concentration' : [self.carrier, 'cm-3'],
'Hall Mobility' : [self.mobility, 'cm2 V-1 s-1'],
'Thermal Conductivity' : [self.thermal, 'W m-1 K-1'],
'Dielectric Constant' : self.dielectric,
'Scattering Mechanism' : self.scatter,
'Chemical Potential' : [self.chemical_potential, 'meV'],
'Effective Mass' : [self.effective_mass, 'm_e'],
'Intrinsic Mobility' : [self.intrinsic_mobility, 'cm2 V-1 s-1'],
'Lorenz Number' : [self.lorenz, 'W Omega K-2'],
'Electronic Thermal Conductivity' : [self.electrical_thermal, 'W m-1 K-1'],
'Lattice Thermal Conductivity' : [self.lattice_thermal, 'W m-1 K-1'],
'Thermoelectric Figure of Merit' : self.zT,
}
return dic_data
def csv_file(self):
"""
Write a list
Output:
------------------------
file_csv: lst
list of thermoelectric properties
"""
file_csv = ['Compound :, {}'.format(self.compound)]
file_csv.append('Temperature :, {}, K'.format(self.temperature))
file_csv.append('Seebeck Coefficient :, {}, mu V K-1'.format(self.seebeck))
file_csv.append('Hall Carrier Concentration :, {}, cm-3'.format(self.carrier))
file_csv.append('Hall Mobility :, {}, cm2 V-1 s-1'.format(self.mobility))
file_csv.append('Thermal Conductivity :, {}, W m-1 K-1'.format(self.thermal))
file_csv.append('Dielectric Constant :, {}'.format(self.dielectric))
file_csv.append('')
file_csv.append('Scattering Mechanism :, {}'.format(self.scatter))
file_csv.append('Chemical Potential :, {}, meV'.format(self.chemical_potential))
file_csv.append('Effective Mass :, {}, m_e'.format(self.effective_mass))
file_csv.append('Intrinsic Mobility :, {}, cm2 V-1 K-1'.format(self.intrinsic_mobility))
file_csv.append('Lorenz Number :, {}, W Omega K-2'.format(self.lorenz))
file_csv.append('Electronic Thermal Conductivity :, {}, W m-1 K-1'.format(self.electrical_thermal))
file_csv.append('Lattice Thermal Conductivity :, {}, W m-1 K-1'.format(self.lattice_thermal))
file_csv.append('Thermoelectric Figure of Merit :, {}'.format(self.zT))
return file_csv
class Computed_Parameters_Carrier:
"""
Write a temporary file for carrier-dependent paramters
Input:
----------------------
compound: str
compound name
temperature: float
temperature in Kelvin
effective_mass: float
Density of states effective mass in meV
intrinsic_mobility: float
intrinsic mobility in centimeters squared per volt and second
scattering_mechanism: str
scattering mechanism
carrier_range: ndarray(N), dtype: float
array of N carrier concentration in per centimeters cube
mobility_cc: ndarray(N), dtype: float
array of N mobilities in centimeter squared per volt and second
seebeck_cc: ndarray(N), dtype: float
array of N Seebeck coefficients in microvolts per Kelvin
lorenz_cc: ndarray(N), dtype: float
array of N effective Lorenz numbers in watts Omega per Kelvin squared
zT_cc: ndarray(N), dtype: float
array of N dimensionless thermoelectric figure of merits
"""
def __init__(self, compound, temperature, effective_mass, intrinsic_mobility, scattering_mechanism, carrier_range, mobility_cc, seebeck_cc, lorenz_cc, zT_cc):
self.compound = compound
self.temperature = temperature
self.effective_mass = effective_mass
self.intrinsic_mobility = intrinsic_mobility
self.scattering_mechanism = scattering_mechanism
self.carrier_range = carrier_range
self.mobility_cc = mobility_cc
self.seebeck_cc = seebeck_cc
self.lorenz_cc = lorenz_cc
self.zT_cc = zT_cc
def get_dictionary(self):
"""
Prepare a dictionary
Output:
--------------------
dic_data: dic
dictionary of thermoelectric data
"""
dic_data = {
'Compound' : self.compound,
'Temperature' : [self.temperature, 'K'],
'Effective Mass' : [self.effective_mass, 'meV'],
'Intrinsic Mobility' : [self.intrinsic_mobility, 'cm2 V-1 K-1'],
'Scattering Mechanism' : self.scattering_mechanism,
'Hall Carrier Concentration List' : [self.carrier_range, 'cm-3'],
'Hall Mobility List' : [self.mobility_cc, 'cm2 V-1 K-1'],
'Seebeck Coefficient List' : [self.seebeck_cc, 'mu V K-1'],
'Lorenz Number List' : [self.lorenz_cc, 'W Omega K-2'],
'Thermoelectric Figure of Merit List' : self.zT_cc
}
return dic_data
def temporary_file(self):
"""
Write temporary folder
"""
dic_data = self.get_dictionary()
with open('~temp_plot.json', 'w') as js_file:
json.dump(dic_data, js_file)
def csv_file(self):
"""
Write list of thermoelectric properties for a csv file
Output:
-----------------
file_csv: lst
list of thermoelectric properties
"""
file_csv = ['Compound :, {}'.format(self.compound)]
file_csv.append('Temperature :, {}, K'.format(self.temperature))
file_csv.append('Scattering Mechanism :, {}'.format(self.scattering_mechanism))
file_csv.append('Effective Mass :, {}, m_e'.format(self.effective_mass))
if self.intrinsic_mobility != 0:
file_csv.append('Intrinsic Mobility :, {}, cm2 V-1 K-1'.format(self.intrinsic_mobility))
file_csv.append('')
if len(self.zT_cc) != 0:
file_csv.append('Hall Carrier Concentration / cm-3, Seebeck Coefficient / mu V K-1, Hall Mobility / cm2 V-1 s-1, Lorenz Number / W Omega K-2, Thermoelectric Figure of Merit')
for n_r in range(len(self.carrier_range)):
file_csv.append('{}, {}, {}, {}, {}'.format(self.carrier_range[n_r], self.seebeck_cc[n_r], self.mobility_cc[n_r], self.lorenz_cc[n_r], self.zT_cc[n_r]))
else:
file_csv.append('Hall Carrier Concentration / cm-3, Seebeck Coefficient / mu V K-1, Hall Mobility / cm2 V-1 s-1, Lorenz Number / W Omega K-2')
for n_r in range(len(self.carrier_range)):
file_csv.append('{}, {}, {}, {}'.format(self.carrier_range[n_r], self.seebeck_cc[n_r], self.mobility_cc[n_r], self.lorenz_cc[n_r]))
else:
file_csv.append('Intrinsic Mobility :, NaN, cm2 V-1 K-1')
file_csv.append('')
file_csv.append('Hall Carrier Concentration / cm-3, Seebeck Coefficient / mu V K-1, Lorenz Number / W Omega K-2')
for n_r in range(len(self.carrier_range)):
file_csv.append('{}, {}, {}'.format(self.carrier_range[n_r], self.seebeck_cc[n_r], self.lorenz_cc[n_r]))
return file_csv
class Fermi_IMP:
"""
Get the Fermi integrals assuming ionized screened impurity scattering using Brooks-Herring approach
Input:
------------------
m_s: float
Density of states effective mass in electron mass
epsilon: float
reduced energy
temperature: float
temperature in Kelvin
carrier: float
carrier concentration in cm-3
"""
def __init__(self, m_s, epsilon, temperature, carrier):
self.m_s = m_s
self.epsilon = epsilon
self.temperature = temperature
self.carrier = carrier
def bh(self, x):
"""
Brooks-Herring approach
"""
return 8 * self.m_s * x * self.epsilon * e0 * k * self.temperature / (hbar**2 * self.carrier * e)
def Fermi_integral_tau_S(self, eta):
FI = lambda x: (x**4 / (log(1 + self.bh(x)) - self.bh(x) / (1 + self.bh(x))) - eta * x**3 / (log(1 + self.bh(x)) - self.bh(x) / (1 + self.bh(x)))) * exp(x - eta)/(1 + exp(x - eta))**2
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau(self, eta):
FI = lambda x: (x**3 / (log(1 + self.bh(x)) - self.bh(x) / (1 + self.bh(x))) * exp(x - eta)/(1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau_E2(self, eta):
FI = lambda x: (x**5 / (log(1 + self.bh(x)) - self.bh(x) / (1 + self.bh(x))) * exp(x - eta)/(1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau_E(self, eta):
FI = lambda x: (x**4 / (log(1 + self.bh(x)) - self.bh(x) / (1 + self.bh(x))) * exp(x - eta) / (1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau2(self, eta):
FI = lambda x: (x**4.5 / (log(1 + self.bh(x)) - self.bh(x) / (1 + self.bh(x)))**2 * exp(x - eta) / (1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
class Fermi_POP:
"""
Get the Fermi integrals assuming polar optical phonons
"""
def Fermi_integral_tau_S(eta):
FI = lambda x: (x**3 / arcsinh(sqrt(x)) - eta * x**2 / arcsinh(sqrt(x))) * exp(x - eta)/(1 + exp(x - eta))**2
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau(eta):
FI = lambda x: (x**2 / arcsinh(sqrt(x)) * exp(x - eta)/(1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau_E2(eta):
FI = lambda x: (x**4 / arcsinh(sqrt(x)) * exp(x - eta)/(1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau_E(eta):
FI = lambda x: (x**3 / arcsinh(sqrt(x)) * exp(x - eta)/(1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
def Fermi_integral_tau2(eta):
FI = lambda x: (x**2.5 / (arcsinh(sqrt(x)))**2 * exp(x - eta) / (1 + exp(x - eta))**2)
return integrate.quad(FI, 0, 300)
class EntryItem:
"""
Create an entry widget in Tkinter including a label
Input:
--------------------------
parent: parent
window
name: str
name of the entry
row: int
row in the window
column: int
column in the window
padx: int
pixels to pad widget horizontally
pady: int
pixels to pad widget vertically
width: int
width of the widget
columnspan: int
number of columns widget takes up
state: str
Normal or disabled
ipadx: int
pixels to pad widget horizontally inside the widget's borders
options: list
list of different options
"""
def __init__(self, parent, name, row=0, column=1, padx=10, pady=6, width=20, columnspan=1, state=NORMAL, ipadx=0, options=['0']):
self.parent = parent
self.name = name
self.row = row
self.column = column
self.padx = padx
self.pady = pady
self.width = width
self.columnspan = columnspan
self.state = state
self.ipadx = ipadx
self.options = options
self.initial_val = StringVar()
self.var = StringVar()
self.entry = Entry(self.parent, textvariable=self.var, state=self.state, width=self.width)
self.label = Label(self.parent, text=name, relief=RIDGE, anchor='w')
self.menu = OptionMenu(self.parent, self.initial_val, *self.options)
def create_EntryItem(self, padx_label=10, pady_label=6, ipadx_label=0):
"""
Create entry widget
Input:
--------------------------
padx_label: int
pixels to pad widget horizontally of the label
pady_label: int
pixels to pad widget vertically of the label
ipadx_label: int
pixels to pad widget horizontally inside the widget's borders
"""
self.entry.grid(row=self.row, column=self.column, columnspan=self.columnspan, padx=self.padx, pady=self.pady, ipadx=self.ipadx)
self.label.grid(row=self.row, column=self.column-1, columnspan=self.columnspan, padx=padx_label, pady=pady_label, ipadx=ipadx_label)
def set_name(self, new_name='NaN'):
"""
Change the variable name
Input:
------------------------
new_name: str
Name of the variable
"""
self.var.set(new_name)
def delete(self):
"""
Delete the entry
"""
self.entry.delete(0, END)
def entry_forget(self):
"""
Remove entry from grid
"""
self.entry.grid_forget()
def set_menu(self, name):
"""
Change the initial value of a menu widget
Input:
------------------------
name: str
name of the initial value for the menu widget
"""
self.initial_val.set(name)
def set_entry(self):
"""
Place entry widget on the window
"""
self.entry.grid(row=self.row, column=self.column, columnspan=self.columnspan, padx=self.padx, pady=self.pady, ipadx=self.ipadx)
def set_label(self, padx_label=10, pady_label=6, ipadx_label=0):
"""
Place the label widget on the window
Input:
-------------------
padx_label: int
pixels to pad widget horizontally of the label
pady_label: int
pixels to pad widget vertically of the label
ipadx_label: int
pixels to pad widget horizontally inside the widget's borders
"""
self.label.grid(row=self.row, column=self.column-1, columnspan=self.columnspan, padx=padx_label, pady=pady_label, ipadx=ipadx_label)
def create_MenuOption(self):
"""
Create a menu widget with various options
"""
self.initial_val.set(self.options[0])
self.menu = OptionMenu(self.parent, self.initial_val, *self.options)
self.menu.grid(row=self.row, column=self.column, columnspan=self.columnspan, padx=self.padx, pady=self.pady, ipadx=self.ipadx)
def font(self, new_font):
"""
Change the font menu widget
Input:
---------------------
new_font: str
new font
"""
self.menu['font'] = new_font
class Entries:
"""
Create and update entry widget
Input:
----------------------------
window: window
window to include widget
initial_var: str
initial variable
row: int
row for menu
"""
def __init__(self, window, initial_var, row):
self.window = window
self.initial_var = initial_var
self.row = row
self.entries = [Entry(self.window) for i in range(int(self.initial_var.get()))]
self.labels = [Label(self.window) for i in range(int(self.initial_var.get()))]
def create_entry(self, row, column, number):
"""
Create entry widget
Input:
---------------------------------
row: int
row in the window to place the widget
column: int
column in the window to place the widget
number: int
coefficient of the temperature of the polynominal fit
Output:
------------------------------------
entry: widget
entry widget
label: widget
label widget
"""
entry = Entry(self.window, width=10)
entry.grid(row=row, column=column, pady=9)
label = Label(self.window, text='* T^{}'.format(number))
label.grid(row=row, column=column+1, pady=10)
return entry, label
def update_entries(self, *args):
"""
Update entry widget
"""
[ent.grid_forget() for ent in self.entries]
[lab.grid_forget() for lab in self.labels]
self.entries = [Entry(self.window) for i in range(int(self.initial_var.get()))]
self.labels = [Label(self.window) for i in range(int(self.initial_var.get()))]
for col in range(int(self.initial_var.get())):
self.entries[col], self.labels[col] = self.create_entry(self.row, 2 + 2 * col, col)
def create_menu(self, name, x_add, options):
"""
Create a menu widget to define the number of polynominal functions
Input:
-------------------------------
name: str
label of the menu widget
x_add: int
pixels to pad widget horizontally inside widget's borders
options: lst
possible options for polynominal function
"""
label_start = Label(self.window, text=name, relief=RIDGE, anchor='w')
label_start.grid(row=self.row, column=0, padx=10, pady=10, ipadx=x_add)
coefficient_menu = OptionMenu(self.window, self.initial_var, *options)
coefficient_menu.grid(row=self.row, column=1, padx=10, pady=9)
self.entries[0] = Entry(self.window, width=10)
self.entries[0].grid(row=self.row, column=2, pady=9)
self.labels[0] = Label(self.window, text='* T^0')
self.labels[0].grid(row=self.row, column=3, pady=10)
def get_thermoelectric_parameters(self, T_range):
"""
Get the polynominal parameters from the entry widgets using the coefficients
Input:
-------------------------
T_range: ndarray (N), dtype: float
arrays of temperatures
Output:
------------------------
param: lst
list of temperature-dependent thermoelectric parameters
"""
param = []
for temp in T_range:
accumulator = 0
for col in range(len(self.entries)):
coeff = MainApplication.check_number(self.window, self.entries[col].get(), 'Coefficient {}'.format(col), -1E40, 1E40, True)
if coeff == []:
return []
else:
accumulator += coeff * temp**col
param.append(accumulator)
return param
class MainApplication:
"""
Main application including all functions used on the main window
Input:
-----------------------------
parent: window
window of the main application
"""
def __init__(self, parent, *args, **kwargs):
self.parent = parent
self.parent.configure(bg=self._from_rgb((241, 165, 193)))
self.title = self.parent.title('Thermoelectric Optimizer - SPB Model App')
self.icon = self.parent.iconbitmap('icon_spb.ico')
self.font_window = tkFont.Font(family='Helvetica', size=10, weight='bold')
# Create Frame
self.input = Frame(self.parent, height=308, width=395, bg=self._from_rgb((191, 112, 141)))
self.input.grid(row=0, column=0, columnspan=2, rowspan=9, pady=(10, 5))
self.label_input = Label(self.parent, text='Input parameters')
self.label_input.grid(row=0, column=0, pady=(10, 5))
self.label_input['font'] = self.font_window
self.output = Frame(self.parent, height=302, width=395, bg=self._from_rgb((175, 188, 205)))
self.output.grid(row=9, column=0, columnspan=2, rowspan=9, pady=(0, 5))
self.label_output = Label(self.parent, text='Output parameters')
self.label_output.grid(row=9, column=0, pady=(0, 5))
self.label_output['font'] = self.font_window
self.plot_input = Frame(self.parent, height=93, width=835, bg=self._from_rgb((191, 112, 141)))
self.plot_input.grid(row=0, column=2, columnspan=5, rowspan=3, pady=(10, 5))
self.plot_input_label = Label(self.parent, text='Input Parameters for Plot')
self.plot_input_label.grid(row=0, column=2, pady=(10, 5))
self.plot_input_label['font'] = self.font_window
self.calculations = 'manual'
# Create Plot Data
self.font_size = DoubleVar(); self.font_size.set(16)
self.size_x = DoubleVar(); self.size_x.set(8)
self.size_y = DoubleVar(); self.size_y.set(4.3)
self.size_x_space = DoubleVar(); self.size_x_space.set(0.18)
self.size_x_length = DoubleVar(); self.size_x_length.set(0.78)
self.size_y_space = DoubleVar(); self.size_y_space.set(0.23)
self.size_y_length = DoubleVar(); self.size_y_length.set(0.68)
self.dpi = DoubleVar(); self.dpi.set(100)
self.font_size_thermal = DoubleVar(); self.font_size_thermal.set(16)
self.size_x_thermal = DoubleVar(); self.size_x_thermal.set(6)
self.size_y_thermal = DoubleVar(); self.size_y_thermal.set(3)
self.size_x_space_thermal = DoubleVar(); self.size_x_space_thermal.set(0.25)
self.size_x_length_thermal = DoubleVar(); self.size_x_length_thermal.set(0.70)
self.size_y_space_thermal = DoubleVar(); self.size_y_space_thermal.set(0.20)
self.size_y_length_thermal = DoubleVar(); self.size_y_length_thermal.set(0.70)
self.dpi_thermal = DoubleVar(); self.dpi_thermal.set(100)
self.font_size_3D = DoubleVar(); self.font_size_3D.set(14)
self.surface = BooleanVar(); self.surface.set(True)
self.size_x_3D = DoubleVar(); self.size_x_3D.set(6)
self.size_y_3D = DoubleVar(); self.size_y_3D.set(4)
self.dpi_3D = DoubleVar(); self.dpi_3D.set(100)
# Create MenuBar
self.temperature_menu = EntryItem(self.parent, 'Temperature', row = 1, pady = 5)
my_Menu = Menu(self.parent)
self.parent.config(menu = my_Menu)
file_menu = Menu(my_Menu)
my_Menu.add_cascade(label='File', menu=file_menu)
file_menu.add_command(label='New', command=self.clear)
file_menu.add_command(label='Open File', command=self.open_file)
file_menu.add_separator()
file_menu.add_command(label='Exit', command=self.close_program)
edit_menu = Menu(my_Menu)
my_Menu.add_cascade(label='Edit', menu=edit_menu)
edit_menu.add_command(label='Edit Graph', command=self.Edit_graph)
edit_menu.add_command(label='Edit 3D Graph', command=self.Edit_graph_3D)
edit_menu.add_command(label='Edit Thermal Graph', command=self.Edit_thermal_graph)
self.compute_menu = Menu(my_Menu)
my_Menu.add_cascade(label='Compute', menu=self.compute_menu)
self.compute_menu.add_command(label='Compute All', command=self.compute_all, state=DISABLED)
self.compute_menu.add_command(label='Compute Optimize Carrier Concentration', command=self.optimization_temperature)
thermal_menu = Menu(my_Menu)
my_Menu.add_cascade(label='Thermal', menu=thermal_menu)
thermal_menu.add_command(label='Compute Thermal', command=self.compute_thermal)
thermal_menu.add_command(label='Minimum Thermal Conductivity', command=self.minimum_thermal)
thermal_menu.add_command(label='Klemens Model', command=self.klemens)
#thermal_menu.add_cascade(label='Callaway Model', command=self.callaway)
help_menu = Menu(my_Menu)
my_Menu.add_cascade(label='Help', menu=help_menu)
help_menu.add_command(label='Welcome', command=self.welcome)
help_menu.add_command(label='Documentations', command=self.documentary)
help_menu.add_separator()
help_menu.add_command(label='About', command=self.about)
self.app = FullScreenApp(self.parent)
# Create Entries for MainApplication
self.compound = EntryItem(self.parent, name='Compound Name (req.)', row=1)
self.compound.create_EntryItem(ipadx_label=50)
self.temperature = EntryItem(self.parent, name='Temperature / K (req.)', row=2)
self.temperature.create_EntryItem(ipadx_label=56)
self.seebeck = EntryItem(self.parent, name='Seebeck Coefficient / mu V K-1 (req.)', row=3)
self.seebeck.create_EntryItem(ipadx_label=17)
self.carrier = EntryItem(self.parent, name='Hall Carrier Concentration / cm-3', row=4)
self.carrier.create_EntryItem(ipadx_label=26)
self.mobility = EntryItem(self.parent, name='Hall Mobility / cm2 V-1 s-1', row=5)
self.mobility.create_EntryItem(ipadx_label = 44)
self.thermal = EntryItem(self.parent, name='Thermal Conductivity / W m-1 K-1', row=6)
self.thermal.create_EntryItem(ipadx_label=25)
self.dielectric = EntryItem(self.parent, name='Dielectric Constant (Only Ionized Impurity)', row=7)
self.dielectric.create_EntryItem(ipadx_label=3)
self.chemical_potential = EntryItem(self.parent, name='Chemical Potential / meV', row=10, state=DISABLED)
self.chemical_potential.create_EntryItem(ipadx_label=50)
self.chemical_potential.set_name()
self.effective_mass = EntryItem(self.parent, name='Effective Mass / m_e', row=11, state=DISABLED)
self.effective_mass.create_EntryItem(ipadx_label=63)
self.effective_mass.set_name()
self.intrinsic_mobility = EntryItem(self.parent, name='Intrinsic Mobility / cm2 V-1 s-1', row=12, state=DISABLED)
self.intrinsic_mobility.create_EntryItem(ipadx_label=36)
self.intrinsic_mobility.set_name()
self.lorenz_number = EntryItem(self.parent, name='Lorenz Number / W Omega K-2', row=13, state=DISABLED)
self.lorenz_number.create_EntryItem(ipadx_label=35)
self.lorenz_number.set_name()
self.electrical_thermal = EntryItem(self.parent, name='Electronic Thermal Conductivity / W m-1 K-1', row=14, state=DISABLED)
self.electrical_thermal.create_EntryItem()
self.electrical_thermal.set_name()
self.lattice_thermal = EntryItem(self.parent, name='Lattice Thermal Conductivity / W m-1 K-1', row=15, state=DISABLED)
self.lattice_thermal.create_EntryItem(ipadx_label=8)
self.lattice_thermal.set_name()
self.zT = EntryItem(self.parent, name='Thermoelectric Figure of Merit', row=16, state=DISABLED)
self.zT.create_EntryItem(ipadx_label=39)
self.zT.set_name()
self.n_range_min = EntryItem(self.parent, name='Min. Carrier Concentration / cm-3', row=1, column=3)
self.n_range_min.create_EntryItem()
self.n_range_max = EntryItem(self.parent, name='Max. Carrier Concentration / cm-3', row=1, column=5)
self.n_range_max.create_EntryItem()
# Create Buttons for MainApplication
self.btn_calculate = Button(self.parent, text='Calculate', command=self.calculate, bg=self._from_rgb((118, 61, 76)), fg='white')
self.btn_calculate.grid(row=8, column=1, padx=10, pady=10, ipadx=30)
self.btn_calculate['font'] = self.font_window
self.btn_save = Button(self.parent, text='Save', command=self.save, bg=self._from_rgb((122, 138, 161)))
self.btn_save.grid(row=17, column=1, padx=10, pady=5, ipadx=45)
self.btn_save['font'] = self.font_window
self.btn_plot = Button(self.parent, text='Plot', command=self.plot, bg=self._from_rgb((118, 61, 76)), fg='white')
self.btn_plot['font'] = self.font_window
self.btn_plot.grid(row=1, column=6, padx=10, ipadx=43)
self.btn_save_plot = Button(self.parent, text='Save Plot', command=self.save_plot, bg=self._from_rgb((122, 138, 161)))
self.btn_save_plot.grid(row=2, column=6, padx=10, pady=5, ipadx=25)
self.btn_save_plot['font'] = self.font_window
# Create MenuOptions for MainApplication
self.scattering_options = [
'Acoustic Deformation Potential',
'Polar Optical Phonon',
'Ionized Impurity',
'Polar Optical Phonon (Fermi)',
'Ionized Impurity (Fermi)'
]
self.scattering_menu = EntryItem(self.parent, 'Scattering', row=8, column=0, pady=10, options=self.scattering_options)
self.scattering_menu.create_MenuOption()
self.scattering_menu.font(self.font_window)
self.save_options = [
'.csv',
'.json'
]
self.save_menu = EntryItem(self.parent, 'Save', row=17, column=0, pady=5, ipadx=75, options=self.save_options)
self.save_menu.create_MenuOption()
self.save_menu.font(self.font_window)
self.plot_options = [
'Seebeck Coefficient',
'Hall Mobility',
'Lorenz Number',
'Figure of Merit'
]
self.plot_menu = EntryItem(self.parent, 'Plot', row=2, column=3, columnspan=2, pady=5, ipadx=80, options=self.plot_options)
self.plot_menu.create_MenuOption()
self.plot_menu.font(self.font_window)
self.font_options = [
'Times New Roman',
'Arial',
'Gabriola',
'Courier New',
'Cambria',
'Calibri',
]
self.initial_font = StringVar(); self.initial_font.set(self.font_options[0])
self.initial_font_3D = StringVar(); self.initial_font_3D.set(self.font_options[0])
self.initial_font_thermal = StringVar(); self.initial_font_thermal.set(self.font_options[0])
# Variables for Open Files
self.cmpds = {}
self.initial_compound = StringVar()
self.compound_menu = OptionMenu(self.parent, self.initial_compound, '0')
self.initial_temperature = StringVar()
self.temperature_menu = OptionMenu(self.parent, self.initial_temperature, '0')
self.create_empty_plot()
def create_empty_plot(self):
"""
Create an emplty plot at the start and when it is cleared
"""
plt.rcParams["font.family"] = self.initial_font.get()
plt.rcParams.update({'font.size': self.font_size.get()})
self.fig = Figure(figsize=(self.size_x.get(), self.size_y.get()), dpi=self.dpi.get())
self.canvas = FigureCanvasTkAgg(self.fig, master=self.parent)
self.canvas.draw()
self.plot_widget = self.canvas.get_tk_widget()
self.plot_widget.grid(row=3, column=2, columnspan=5, rowspan=13)
ax1 = self.fig.add_axes([self.size_x_space.get(), self.size_y_space.get(), self.size_x_length.get(), self.size_y_length.get()])
ax1.set_xlabel('Hall Carrier Concentration / cm$^{-3}$')
ax1.set_xlim(1e18, 1e21)
ax1.set_xscale('log')
toolbar_frame = Frame(self.parent)
toolbar_frame.grid(row=16,column=2,columnspan=4)
toolbar = NavigationToolbar2Tk(self.canvas, toolbar_frame)
toolbar.update()
def _from_rgb(self, rgb):
"""translates an rgb tuple of int to a tkinter friendly color code
"""
return "#%02x%02x%02x" % rgb
def check_number(self, param, name, min_value, max_value, mandatory):
"""
Check if the number in the entry widget is in the approriate range
Input:
-----------------------------
param: int
value in the entry
name: str
name of the thermoelectric property
min_value: float
minimum allowed value
max_value: float
maximum allowed value
mandatory: boolean
if true, the entry widget is mandatory for the thermoelectric calculations, else an empty list will be returned
Output:
-----------------------------------
param: float
value in the entry if it is a number and in the required range, else an empty list will be returned
"""
if param.replace('.', '', 1).replace('e', '', 1).replace('+', '', 2).replace('-', '', 2).replace('E', '', 1).isdigit():
if min_value < float(param) and max_value > float(param):
return float(param)
else:
messagebox.showerror(
message='{} is below {} or above {}! Calculations will not work, please check if values are correct!'.format(name, min_value, max_value))
return []
else:
if mandatory:
messagebox.showerror(message='{} is not a number or empty!'.format(name))
return []
else:
return []
def compute_scattering_carrier(self, n_min, n_max):
"""
Produce a range of carrier concentrations, compute the thermoelectric properties as function of carrier concentration and place the data in a dictionary
Input:
------------------------
n_min: float
minimum carrier concentration in per centimeter cube
n_max: float
maximum carrier concentration in per centimeter cube
Output:
-----------------------
SPB_list: dic
dictionary of thermoelectric properties as a function of carrier concentration
"""
n_range = []
for i in range(int(log10(n_max / n_min))):
for j in range(2, 20):
n_range.append(j / 2. * (n_min * 10**i))
n_range.append(n_max)
SPB_For_List = self.calculate()
mu_list, S_list, L_list, zT_list = self.calculation_scattering_parameters_list(
SPB_For_List.temperature,
SPB_For_List.carrier,
SPB_For_List.chemical_potential,
SPB_For_List.effective_mass,
SPB_For_List.intrinsic_mobility * 1E-4,
SPB_For_List.beta,
n_range,
SPB_For_List.scatter)
SPB_List = Computed_Parameters_Carrier(
SPB_For_List.compound,
SPB_For_List.temperature,
SPB_For_List.effective_mass,
SPB_For_List.intrinsic_mobility,
SPB_For_List.scatter,
n_range,
mu_list,
S_list,
L_list,
zT_list
)
return SPB_List
def Fermi_integral(self, eta, lam):
"""
Fermi integral for acoustic deformation potential scattering
"""
FI = lambda x: (x**lam)/(1 + exp(x - eta))