/
DeviceStructure.py
executable file
·469 lines (385 loc) · 20.9 KB
/
DeviceStructure.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
import copy
import os
import sys
import numpy as np
from scipy.interpolate import interp1d
from solcore import constants, material
from solcore.absorption_calculator import adachi_alpha, calculate_absorption_profile, calculate_rat
from solcore.material_data import calculate_mobility
from solcore.structure import *
from .QWunit import QWunit
Epsi0 = constants.vacuum_permittivity
q = constants.q
pi = constants.pi
h = constants.h
kb = constants.kb
m0 = constants.electron_mass
vacuum_permittivity = constants.vacuum_permittivity
# The default material is a set of minimum properties that are used for the layers unless otherwise stated
DefaultMaterial = material("GaAs")(T=293)
DefaultProperties = {'band_gap': DefaultMaterial.band_gap, # J
'electron_affinity': DefaultMaterial.electron_affinity, # J
'eff_mass_electron_Gamma': DefaultMaterial.eff_mass_electron_Gamma, # relative to m0
'eff_mass_hh_z': DefaultMaterial.eff_mass_hh_z, # relative to m0
'eff_mass_lh_z': DefaultMaterial.eff_mass_lh_z, # relative to m0
'electron_mobility': calculate_mobility("GaAs", 0, 1), # m2 V-1 s-1
'hole_mobility': calculate_mobility("GaAs", 1, 1), # m2 V-1 s-1
'electron_minority_lifetime': 3e-6, # s
'hole_minority_lifetime': 2.5e-7, # s
'permittivity': 12.9, # relative to epsilon0
'electron_auger_recombination': 1e-42, # m6 s-1,
'hole_auger_recombination': 1e-42, # m6 s-1
'radiative_recombination': 7.2e-16, # m3 s-1
'Nd': 1, # m-3
'Na': 1, # m3
'sn': 1e6, # m s-1
'sp': 1e6} # m s-1
def CreateDeviceStructure(name, role='device', T=293, layers=None, comments='', repeat=1, substrate=DefaultMaterial,
reflection=None):
""" Creates the structure of a device to be used in drift diffusion calculations.
This class defines an object that can be used in drift diffusion calculations.
It has the advantage over the old Sample class (based on the Structure class) of being organised in a format that than be easily stored
using Json or managed by the upcoming front end, Sunglasses.
With minimum coding effort, it should be possible to use it with the Schrodinger solver, analythical methods, etc.
TO BE DONE: This should be replaced by a state_object, the same way it is done in the analytical solar cell solvers
:param name: Name of the structure
:param role: Role of the structure (eg. "device", "MQW", etc)
:param T: Temperature
:param layers: List containing all the layers of the structure
:param comments: A string with comments
:param repeat: If the structure is actually something that is repeated many times, for example a quantum well
:param substrate: A solcore material defining the substrate of the structure.
:param reflection: The reflexion of the structure
:return: A dictionary-like object with all the information related to the device
"""
output = {}
output['name'] = name
output['role'] = role
output['T'] = T
output['numlayers'] = 0
output['comments'] = comments
output['repeat'] = repeat
output['layers'] = []
output['substrate'] = SolcoreMaterialToStr(substrate)
output['reflection'] = reflection
output['absorption'] = layers.absorbed if hasattr(layers, 'absorbed') else lambda x: 0
AddLayers(output, layers)
return output
def AddLayers(device, layers):
""" Add layers to the structure
:param device: The device structure
:param layers: A list with the layers to add
:return: None
"""
for layer in layers:
NewLayer = {}
if type(layer) is Layer:
NewLayer['label'] = layer.role
NewLayer['class'] = 'Layer'
NewLayer['group'] = None
NewLayer['numlayers'] = 1
NewLayer['repeat'] = 1
NewLayer['properties'] = GetLayerProperties(layer, device['T'])
if 'absorption_file' in layer.material.__dict__.keys():
NewLayer['absorption_file'] = layer.material.absorption_file
device['layers'].append(NewLayer)
device['numlayers'] = device['numlayers'] + 1
elif type(layer) is dict:
for sublayer in layer['layers']:
device['layers'].append(copy.deepcopy(sublayer))
device['numlayers'] = device['numlayers'] + 1
device['layers'][-1]['group'] = layer['name']
device['layers'][-1]['numlayers'] = layer['numlayers']
device['layers'][-1]['repeat'] = layer['repeat']
def Load(filename, yaml=False):
""" Loads a device structure stored in a file. By default, the file must be JSON format
:param filename: The filename
:param yaml: If the format is YALM rather than JSON
:return: A device structure
"""
if yaml:
try:
# If chosen, we try to use yaml. If anything fails, we try with json.
import yaml
stream = open(filename + '.yaml', 'r')
output = yaml.load(stream)
except:
import json
stream = open(filename + '.json', 'r')
output = json.load(stream)
else:
import json
stream = open(filename + '.json', 'r')
output = json.load(stream)
stream.close()
for i in range(output['numlayers']):
if 'absorption_file' in output['layers'][i].keys():
# If there is a file containing the absorption in this layer, we try to load it. It must have at least to columns: wavelengths and absorption coefficient. Both must be in SI units. The result is interpolated to the current working wavelengths.
try:
data = np.loadtxt(output['layers'][i]['absorption_file'])
output['layers'][i]['properties']['absorption'] = [data[:, 0].tolist(), data[:, 1].tolist()]
except:
# The file can not be loaded. Maybe it does not exists or is not in the correct format. We move forward to calculating the absorption. Later, the calculated absorption can be saved with this filename.
print('Error loading absorption file %s. The absorption will be calculated later if necesary. ' % (
output['layers'][i]['absorption_file']))
return output
def Save(device, filename, save_absorptions_individually=False, remove_absorption_from_json=False,
override_absorption=False, directory='default', yaml=False):
""" Save the device structure to a file.
:param device: The device structure to save
:param filename: The filename
:param save_absorptions_individually: If the absorption of the materials must be saved in individual files
:param remove_absorption_from_json: If the absorption must be removed from the JSON file to make it more readable
:param override_absorption: If the external absrption files must override the default absorption
:param directory: Directory in which to save the absorption data
:param yaml: If YALM should be used rather than JSON
:return: None
"""
if save_absorptions_individually:
# The absorption coefficient of each layer is saved in an individual file. Optionally, it removes them from the structure so they are not saved also in in the json file
for i in range(device['numlayers']):
if 'absorption' not in device['layers'][i]['properties'].keys(): continue
# if ('absorption_file' in device['layers'][i].keys()) and override_absorption:
# abs_filename = device['layers'][i]['absorption_file']
# else:
# abs_filename = '%s_inputs/%s_%s_%s_%s.dat' %(filename.split('.')[0], device['name'], InLineComposition(device['layers'][i]), device['layers'][i]['label'], i)
if directory == 'default': directory = '%s_inputs' % (filename)
abs_filename = '%s/%s_%s_%s_%s.dat' % (
directory, device['name'], i, InLineComposition(device['layers'][i]), device['layers'][i]['label'])
os.makedirs(directory, exist_ok=True)
device['layers'][i]['absorption_file'] = abs_filename
np.savetxt(abs_filename, np.transpose(device['layers'][i]['properties']['absorption']))
if remove_absorption_from_json:
for i in range(device['numlayers']):
if 'absorption' not in device['layers'][i]['properties'].keys(): continue
del device['layers'][i]['properties']['absorption']
if yaml:
try:
# If chosen, we try to use yaml. If anything fails, we try with json.
import yaml
stream = open(filename + '.yaml', 'w')
yaml.dump(device, stream, default_flow_style=False)
except:
import json
stream = open(filename + '.json', 'w')
json.dump(device, stream, sort_keys=True, indent=2)
else:
import json
stream = open(filename + '.json', 'w')
json.dump(device, stream, sort_keys=True, indent=2)
stream.close()
def RemoveLayer(device, i):
""" Remove a layer from the device structure
:param device: the device structure
:param i: the index of the layer to remove
:return: None
"""
del device['layers'][i]
device['numlayers'] = device['numlayers'] - 1
def GetLayerProperties(layer, T):
""" Given a layer, get all the properties of that layer and the material it is made of at the given temperature
:param layer: The layer of interest
:param T: The temperature
:return: Dictionary with all the properties
"""
# Get all the properties of the new layer. If they dont exist in the layer definition, the default values are used.
NewProperties = {}
NewProperties['composition'] = SolcoreMaterialToStr(layer.material)
NewProperties['width'] = layer.width
updateMun = False
updateMup = False
for key in DefaultProperties.keys():
# Numpy floats are not the same as python's so we need to make a conversion in order for Yaml to produce sensible files.
try:
NewProperties[key] = getattr(layer.material, key)
except ValueError:
NewProperties[key] = DefaultProperties[key]
# The drift diffusion model uses the density of states. We calculate them now
try:
NewProperties["Nc"] = getattr(layer.material, 'Nc')
except:
me = NewProperties['eff_mass_electron_Gamma']
NewProperties["Nc"] = 2 * (2 * pi * me * m0 * kb * T / h ** 2) ** 1.5
try:
NewProperties["Nv"] = getattr(layer.material, 'Nv')
except:
mhh = NewProperties['eff_mass_hh_z']
mlh = NewProperties['eff_mass_lh_z']
NewProperties["Nv"] = 2 * (2 * pi * mhh * m0 * kb * T / h ** 2) ** 1.5 + 2 * (
2 * pi * mlh * m0 * kb * T / h ** 2) ** 1.5
NewProperties["ni"] = np.sqrt(
NewProperties["Nc"] * NewProperties["Nv"] * np.exp(-NewProperties["band_gap"] / (kb * T)))
return NewProperties
def LoadAbsorption(layer, T, wavelengths, use_Adachi=False):
""" If there is a file containing the absorption in this layer, we try to load it. It must have at least two
columns: wavelengths and absorption coefficient. Both must be in SI units. The result is interpolated to the current
working wavelengths.
The file can not be loaded: Maybe it does not exists or is not in the correct format. We move forward to
calculating the absorption. Later, the calculated absorption can be saved with this filename.
:param layer: The layer we want to get the absorption coefficient from.
:param T: The temperature
:param wavelengths: The wavelength we want the absorption at
:param use_Adachi: If we should use the Adachi method to get the absorption coeficient.
:return: A list with two columns, the wavelnegths and the absorption coeficient.
"""
if 'absorption_file' in layer.keys():
try:
data = np.loadtxt(layer['absorption_file'])
absorption = np.interp(wavelengths, data[:, 0], data[:, 1])
return [wavelengths.tolist(), absorption.tolist()]
except:
print('Error loading the absorption file or layer {}'.format(layer))
sys.exit()
if use_Adachi:
try:
# 0 = Energy, 1 = n, 2 = k.txt, 3 = Absorption
absorption = adachi_alpha.create_adachi_alpha(InLineComposition(layer), T=T, wl=wavelengths)[3]
except:
print("Warning: Using experimental data to estimate the absorption coefficient of material: ",
InLineComposition(layer))
absorption = ToSolcoreMaterial(layer['properties']['composition'], T, execute=True).alpha(wavelengths)
if layer['properties']['composition']['material'] == 'InGaAs':
print(
"Warning: Extrapolation of experimental absorption data for InGaAs is not reliable at longer wavelengths.")
print(" >>>: We truncate the absorption at the bandgap wavelength.")
edge = 1240e-9 / (layer['properties']['band_gap'] / q)
edgeidx = np.abs(wavelengths - edge).argmin()
absorption[edgeidx:] = 0
else:
try:
absorption = ToSolcoreMaterial(layer['properties']['composition'], T, execute=True).alpha(wavelengths)
if layer['properties']['composition']['material'] == 'InGaAs':
print(
"Warning: Extrapolation of experimental absorption data for InGaAs is not reliable at longer wavelengths.")
print(" >>>: We truncate the absorption at the bandgap wavelength.")
edge = 1240e-9 / (layer['properties']['band_gap'] / q)
edgeidx = np.abs(wavelengths - edge).argmin()
absorption[edgeidx:] = 0
except:
print("Warning: Using Adachi calculation to estimate the absorption coefficient of material: ",
InLineComposition(layer))
# 0 = Energy, 1 = n, 2 = k.txt, 3 = Absorption
try:
absorption = adachi_alpha.create_adachi_alpha(InLineComposition(layer), T=T, wl=wavelengths)[3]
except:
print("Warning: No absorption information found for material {}. Setting it equal to zero.".format(
InLineComposition(layer)))
absorption = 0 * wavelengths
return [wavelengths.tolist(), absorption.tolist()]
def SolveQWproperties(device, calculate_absorption=True, WLsteps=(300e-9, 1100e-9, 201), wavelengths=None,
periodic=True, filter_strength=0.0, blur=None, blurmode="left", mode='kp8x8_bulk',
use_Adachi=False,
alpha_params=None):
""" Considers the device as a QW and solves its properties, including the modification of the bandeges due to strain, the efective mases and the absorption coefficient. Without calling this function, the structure is just a colection of layers with bulk-like properties.
:param device: The device structure
:param calculate_absorption: If absorption must be calculated
:param WLsteps: wavelengths in which to calculate the absorption (input for np.linspace function)
:param wavelengths: An array with the waveengths
:param periodic: If it has to be assumed that the structure is perdiodic
:param filter_strength:
:param blur:
:param blurmode:
:param mode:
:param use_Adachi:
:param alpha_params:
:return: A dictionary with the output of the Schrodinger solver.
"""
QW = QWunit(ToStructure(device), substrate=ToSolcoreMaterial(device['substrate'], device['T'], execute=True))
output = QW.solve(calculate_absorption=calculate_absorption, WLsteps=WLsteps, wavelengths=wavelengths,
T=device['T'], periodic=periodic, filter_strength=filter_strength, blur=blur, blurmode=blurmode,
mode=mode, use_Adachi=use_Adachi, alpha_params=alpha_params)
for i in range(len(QW)):
device['layers'][i]['properties']['band_gap'] = QW[i].eff_band_gap
device['layers'][i]['properties']['electron_affinity'] = QW[i].eff_electron_affinity
device['layers'][i]['properties']['eff_mass_electron_Gamma'] = QW[i].material.eff_mass_electron_Gamma
device['layers'][i]['properties']['eff_mass_hh_z'] = QW[i].material.eff_mass_hh_z
device['layers'][i]['properties']['eff_mass_lh_z'] = QW[i].material.eff_mass_lh_z
device['layers'][i]['properties']['Nc'] = QW[i].material.Nc
device['layers'][i]['properties']['Nv'] = QW[i].material.Nv
if calculate_absorption:
device['layers'][i]['properties']['absorption'] = [QW.wl.tolist(), QW[i].material.absorption.tolist()]
# Finally, we re-build a list of layers with the effective properties
N = device['repeat']
T = device['T']
new_QW = []
for i in range(len(QW)):
# First, we create a dictionary with all the updated parameters
param = dict(device['layers'][i]['properties'])
del param['absorption']
del param['composition']
del param['width']
# We recover the composition and thickness
mat = device['layers'][i]['properties']['composition']
width = device['layers'][i]['properties']['width']
# Create the material with the updated properties
layer_mat = ToSolcoreMaterial(mat, T, execute=True, **param)
# In the end, we convert the absorption coeficient in extinction coefficient
kk = QW[i].material.absorption * QW.wl / 4 / np.pi
layer_mat.k = interp1d(QW.wl, kk, bounds_error=False, fill_value=(0, 0))
# And add the layer to the list of layers
new_QW.append(Layer(width, layer_mat))
# As the QW might be actually a MQW, we repeat this as many times as needed
new_QW = N * new_QW
return new_QW
def calculate_reflection(device, wavelengths):
""" Calculates the reflexion of a device structure
:param device: The device structure
:param wavelengths: The wavelengths
:return: The reflexion at the given wavelengths
"""
if device['reflection'] is not None:
try:
# We asumme that we have a file with the reflection
print('Loading reflection from file %s ...' % (device['reflection']))
data = np.loadtxt(device['reflection'])
R = np.interp(wavelengths, data[:, 0], data[:, 1])
print('...Sucess!!')
except:
# If it fails, we calculate it based on the refractive index of the first layer
comp = device['layers'][0]['properties']['composition']
n = ToSolcoreMaterial(comp, device['T'], execute=True).n(wavelengths)
R = ((1 - n) / (1 + n)) ** 2
print(
'... Error!! Device surface reflection calculated from the refractive index of the first layer, instead. ')
else:
# Otherwise, we calculate it based on the refractive index of the first layer
comp = device['layers'][0]['properties']['composition']
n = ToSolcoreMaterial(comp, device['T'], execute=True).n(wavelengths)
k = ToSolcoreMaterial(comp, device['T'], execute=True).k(wavelengths)
nc = n + k * 1.0j
R = np.abs((1 - nc) / (1 + nc)) ** 2
print('Device surface reflection calculated from the refractive index of the first layer. ')
return R
def calculate_optics(device, wavelengths, dist=None):
""" Uses the transfer matrix solver to calculate the optical properties of the structure: that is, the reflection
and the absorption as a function of the position.
:param device: A device structure
:param wavelengths: The wavelengths at which to calculate the optical information (in m)
:param dist: The positions at which to calculate the absorption (in m). If None, it is calculated internally.
:return: A dictionary with the reflection, the position, the wavelengths and the absorption as a function of
the wavelength and position.
"""
output = {}
output['wavelengths'] = wavelengths
wl = wavelengths * 1e9 # Input is in meters but the calculators use nm
if dist is None:
d = dist
else:
d = dist * 1e9 # Input is in meters but the calculators use nm
rat = calculate_rat(device, wl)
output['R'] = rat['R']
absorption = calculate_absorption_profile(device, wl, dist=d)
output['absorption'] = absorption['absorption'] * 1e9
output['position'] = absorption['position'] * 1e-9
optics_thickness = 0
for layer in device['layers']:
if layer['label'] in ['optics', 'Optics']:
optics_thickness += layer['properties']['width']
else:
break
output['position'] -= optics_thickness
return output
def CalculateAbsorptionProfile(z, wl, absorption):
out = np.array(wl)
out = np.vstack((out, absorption(z)))
return out