pySIMSalabim 1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pySIMsalabim/__init__.py +21 -0
- pySIMsalabim/aux_funcs/SCLC_funcs.py +561 -0
- pySIMsalabim/aux_funcs/__init__.py +0 -0
- pySIMsalabim/aux_funcs/addons.py +55 -0
- pySIMsalabim/experiments/CV.py +918 -0
- pySIMsalabim/experiments/EQE.py +461 -0
- pySIMsalabim/experiments/JV_steady_state.py +259 -0
- pySIMsalabim/experiments/__init__.py +0 -0
- pySIMsalabim/experiments/hysteresis.py +753 -0
- pySIMsalabim/experiments/impedance.py +848 -0
- pySIMsalabim/experiments/imps.py +630 -0
- pySIMsalabim/install/__init__.py +20 -0
- pySIMsalabim/install/compile_simsalabim.py +76 -0
- pySIMsalabim/install/get_SIMsalabim.py +505 -0
- pySIMsalabim/install/get_gnu_parallel.py +107 -0
- pySIMsalabim/plots/__init__.py +0 -0
- pySIMsalabim/plots/band_diagram.py +209 -0
- pySIMsalabim/plots/plot_def.py +19 -0
- pySIMsalabim/plots/plot_functions.py +240 -0
- pySIMsalabim/tests/__init__.py +0 -0
- pySIMsalabim/tests/test_CV.py +91 -0
- pySIMsalabim/tests/test_EQE.py +97 -0
- pySIMsalabim/tests/test_IMPS.py +92 -0
- pySIMsalabim/tests/test_JV.py +88 -0
- pySIMsalabim/tests/test_hyst.py +92 -0
- pySIMsalabim/tests/test_impedance.py +89 -0
- pySIMsalabim/utils/__init__.py +25 -0
- pySIMsalabim/utils/clean_up.py +96 -0
- pySIMsalabim/utils/device_parameters.py +720 -0
- pySIMsalabim/utils/general.py +521 -0
- pySIMsalabim/utils/parallel_sim.py +654 -0
- pySIMsalabim/utils/utils.py +129 -0
- pySIMsalabim-1.dist-info/LICENSE +674 -0
- pySIMsalabim-1.dist-info/METADATA +159 -0
- pySIMsalabim-1.dist-info/RECORD +37 -0
- pySIMsalabim-1.dist-info/WHEEL +5 -0
- pySIMsalabim-1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
"""Perform EQE simulations"""
|
|
2
|
+
|
|
3
|
+
######### Package Imports #########################################################################
|
|
4
|
+
|
|
5
|
+
import os, uuid, sys
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import numpy as np
|
|
8
|
+
import matplotlib.pyplot as plt
|
|
9
|
+
from scipy import constants
|
|
10
|
+
# import pySIMsalabim
|
|
11
|
+
## Import pySIMsalabim, if not successful, add the parent directory to the system path
|
|
12
|
+
try :
|
|
13
|
+
import pySIMsalabim as sim
|
|
14
|
+
except ImportError:
|
|
15
|
+
# Add the parent directory to the system path
|
|
16
|
+
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
|
17
|
+
import pySIMsalabim as sim
|
|
18
|
+
from pySIMsalabim.utils import general as utils_gen
|
|
19
|
+
from pySIMsalabim.utils.parallel_sim import *
|
|
20
|
+
from pySIMsalabim.utils.utils import update_cmd_pars
|
|
21
|
+
|
|
22
|
+
######### Constants #################################################################################
|
|
23
|
+
|
|
24
|
+
h=constants.h
|
|
25
|
+
c=constants.c
|
|
26
|
+
q=constants.e
|
|
27
|
+
|
|
28
|
+
######### Functions #################################################################################
|
|
29
|
+
|
|
30
|
+
def EQE_create_spectrum_files(lambda_array, p, session_path, spectrum_path, tmp_spectrum_path):
|
|
31
|
+
"""Create all the spectrum files with monochromatic peaks at the specified wavelength,
|
|
32
|
+
with a fixed height set by the number of added photons p. The files are stored in a temporary folder: tmp_spectrum.
|
|
33
|
+
|
|
34
|
+
Parameters
|
|
35
|
+
----------
|
|
36
|
+
lambda_array : array
|
|
37
|
+
Array with the wavelengths at which the monochromatic peaks will be created.
|
|
38
|
+
p : float
|
|
39
|
+
Number of photons that are added to the irradiance.
|
|
40
|
+
session_path : string
|
|
41
|
+
Path to the session folder where the files must be created.
|
|
42
|
+
spectrum_path : string
|
|
43
|
+
Path to the original spectrum file.
|
|
44
|
+
tmp_spectrum_path : string
|
|
45
|
+
Path to the temporary folder where the modified spectrum files will be stored.
|
|
46
|
+
"""
|
|
47
|
+
for i in lambda_array:
|
|
48
|
+
# Reset the spectrum data on every iteration to avoid accumulation of the added photons at each wavelength
|
|
49
|
+
org_spectrum_data = pd.read_csv(os.path.join(session_path,spectrum_path), sep=r'\s+')
|
|
50
|
+
|
|
51
|
+
# Get the filename of the spectrum without any possible path
|
|
52
|
+
spectrum_filename = os.path.basename(spectrum_path)
|
|
53
|
+
|
|
54
|
+
#find row with value closest to i and multiply the value in the irradiance column with 10
|
|
55
|
+
row = org_spectrum_data.iloc[(org_spectrum_data['lambda']-i).abs().argsort()[:1]]
|
|
56
|
+
org_spectrum_data.loc[row.index, 'I'] += (p*((h*c)/i)/1e-9) #2% of absorbed photons of Si
|
|
57
|
+
org_spectrum_data.to_csv(os.path.join(tmp_spectrum_path,f'{int(i*1e9)}nm_{spectrum_filename}'), sep=' ', index=False, float_format='%.3e')
|
|
58
|
+
|
|
59
|
+
def get_CurrDens(JV_file, session_path):
|
|
60
|
+
""" Get the current density and its from the JV_file as stored in the first row.
|
|
61
|
+
Parameters
|
|
62
|
+
----------
|
|
63
|
+
JV_file : str, optional
|
|
64
|
+
Name of the file where the JV data is stored. Must be unique for each simulation, by default 'JV.dat'
|
|
65
|
+
session_path : string
|
|
66
|
+
Path to the session folder where the simulation will run.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
float, float
|
|
71
|
+
Short-circuit current and its error.
|
|
72
|
+
"""
|
|
73
|
+
data_JV = pd.read_csv(os.path.join(session_path,JV_file), sep=r'\s+')
|
|
74
|
+
J0=data_JV['Jext'][0]
|
|
75
|
+
J0_err=data_JV['errJ'][0]
|
|
76
|
+
|
|
77
|
+
# Remove the JV file as it is not needed anymore
|
|
78
|
+
os.remove(os.path.join(session_path,JV_file))
|
|
79
|
+
|
|
80
|
+
return J0, J0_err
|
|
81
|
+
|
|
82
|
+
def calc_EQE(Jext,Jext_err,J0_single, J0_err_single, lambda_array,p):
|
|
83
|
+
"""Calculate the EQE values for the monochromatic peaks at each wavelength. Based on the change in the short-circuit current and the number of added photons.
|
|
84
|
+
|
|
85
|
+
Parameters
|
|
86
|
+
----------
|
|
87
|
+
Jext : array
|
|
88
|
+
Short-circuit current density for each monochromatic peak.
|
|
89
|
+
Jext_err : array
|
|
90
|
+
Error in the short-circuit current density for each monochromatic peak.
|
|
91
|
+
J0_single : float
|
|
92
|
+
Short-circuit current density for the normal spectrum.
|
|
93
|
+
J0_err_single : float
|
|
94
|
+
Error in the short-circuit current density for the normal spectrum.
|
|
95
|
+
lambda_array : array
|
|
96
|
+
Array with the wavelengths at which the monochromatic peaks were created.
|
|
97
|
+
p : float
|
|
98
|
+
Number of photons that are added to the irradiance.
|
|
99
|
+
|
|
100
|
+
Returns
|
|
101
|
+
-------
|
|
102
|
+
array, array, array, array, array
|
|
103
|
+
Arrays with the change in short-circuit current density, error in the change in short-circuit currentdensity,
|
|
104
|
+
monochromatic intensity, EQE values and error in the EQE values.
|
|
105
|
+
"""
|
|
106
|
+
# Calculate the change in short-circuit current density and its error
|
|
107
|
+
deltaJ = [abs(x - J0_single) for x in Jext]
|
|
108
|
+
deltaJerr = [x + J0_err_single for x in Jext_err]
|
|
109
|
+
|
|
110
|
+
# Calculate the increase in intensity/photon flux/energy of the monochromatic peaks
|
|
111
|
+
I_diff = [((p * h * c) / x) / 1e-9 for x in lambda_array]
|
|
112
|
+
area = 1e-9 * np.array(I_diff)
|
|
113
|
+
E_photon = np.array([(h * c) / x for x in lambda_array])
|
|
114
|
+
|
|
115
|
+
# Calculate the EQE values and their errors
|
|
116
|
+
EQE_val=deltaJ/((q*area)/E_photon)
|
|
117
|
+
EQE_err=np.multiply(deltaJerr,((q*area)/E_photon))
|
|
118
|
+
|
|
119
|
+
return deltaJ, deltaJerr, I_diff, EQE_val, EQE_err
|
|
120
|
+
|
|
121
|
+
def run_EQE(simss_device_parameters, session_path, spectrum, lambda_min, lambda_max, lambda_step, Vext, output_file = 'EQE.dat', JV_file_name = 'JV.dat', varFile = 'none',remove_dirs = True, parallel = False, max_jobs = max(1,os.cpu_count()-1), run_mode = True, **kwargs):
|
|
122
|
+
"""Run the EQE calculation for a given spectrum and external voltage, and save the results in a file.
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
simss_device_parameters : string
|
|
127
|
+
Name of the device parameters file.
|
|
128
|
+
session_path : string
|
|
129
|
+
Path to the session folder where the simulation will run.
|
|
130
|
+
spectrum : string
|
|
131
|
+
Path to the original spectrum file.
|
|
132
|
+
lambda_min : float
|
|
133
|
+
Minimum wavelength for the spectrum.
|
|
134
|
+
lambda_max : float
|
|
135
|
+
Maximum wavelength for the spectrum.
|
|
136
|
+
lambda_step : float
|
|
137
|
+
Step size for the wavelength.
|
|
138
|
+
Vext : float
|
|
139
|
+
External voltage at which the simulation will run and the EQE must be calculated.
|
|
140
|
+
output_file : string, optional
|
|
141
|
+
Name of the file where the results will be stored. The file will be stored in the session folder, by default 'EQE.dat'
|
|
142
|
+
JV_file_name : string, optional
|
|
143
|
+
Name of the JV file. Must be unique for each simulation, by default 'JV.dat'
|
|
144
|
+
varFile : string, optional
|
|
145
|
+
Name of the var file, by default 'none'
|
|
146
|
+
remove_dirs : bool, optional
|
|
147
|
+
Remove the temporary directories, by default True
|
|
148
|
+
parallel : bool, optional
|
|
149
|
+
Run the simulations in parallel, by default False
|
|
150
|
+
max_jobs : int, optional
|
|
151
|
+
Maximum number of parallel jobs, by default max(1,os.cpu_count()-1)
|
|
152
|
+
run_mode : bool, optional
|
|
153
|
+
indicate whether the script is in 'web' mode (True) or standalone mode (False). Used to control the console output, by default True
|
|
154
|
+
**kwargs : dict
|
|
155
|
+
Additional arguments to be passed to the function.
|
|
156
|
+
|
|
157
|
+
Returns
|
|
158
|
+
-------
|
|
159
|
+
int
|
|
160
|
+
0 if the function runs successfully.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
UUID = kwargs.get('UUID', '') # Check if the user wants to add a UUID to the JV file name
|
|
164
|
+
cmd_pars = kwargs.get('cmd_pars', None) # Check if the user wants to add additional command line parameters to the simulation
|
|
165
|
+
force_multithreading = kwargs.get('force_multithreading', False) # Check if the user wants to force multithreading instead of using GNU parallel
|
|
166
|
+
if os.name == 'nt':
|
|
167
|
+
threadsafe = kwargs.get('threadsafe', True) # Check if the user wants to force the use of threads instead of processes
|
|
168
|
+
else:
|
|
169
|
+
threadsafe = kwargs.get('threadsafe', False) # Check if the user wants to force the use of threads instead of processes
|
|
170
|
+
|
|
171
|
+
turnoff_autoTidy = kwargs.get('turnoff_autoTidy', None) # Check if the user wants to turn off the autoTidy function in SIMsalabim
|
|
172
|
+
if turnoff_autoTidy is None:
|
|
173
|
+
if not threadsafe:
|
|
174
|
+
turnoff_autoTidy = True
|
|
175
|
+
else:
|
|
176
|
+
turnoff_autoTidy = False
|
|
177
|
+
|
|
178
|
+
# Update the JV file name with the UUID
|
|
179
|
+
if UUID != '':
|
|
180
|
+
dum_str = f'_{UUID}'
|
|
181
|
+
else:
|
|
182
|
+
dum_str = ''
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
JV_file_name = os.path.join(session_path, JV_file_name)
|
|
186
|
+
output_file = os.path.join(session_path, output_file)
|
|
187
|
+
if UUID != '':
|
|
188
|
+
JV_file_name_base, JV_file_name_ext = os.path.splitext(JV_file_name)
|
|
189
|
+
JV_file_name = JV_file_name_base + dum_str + JV_file_name_ext
|
|
190
|
+
output_file_base, output_file_ext = os.path.splitext(output_file)
|
|
191
|
+
output_file = output_file_base + dum_str + output_file_ext
|
|
192
|
+
if varFile != 'none':
|
|
193
|
+
varFile = os.path.join(session_path,varFile)
|
|
194
|
+
var_file_base, var_file_ext = os.path.splitext(varFile)
|
|
195
|
+
varFile = var_file_base + dum_str + var_file_ext
|
|
196
|
+
# varFile = 'none' # we don't use a var file for this simulation
|
|
197
|
+
|
|
198
|
+
msg_list = [] # Init the returnmessage list
|
|
199
|
+
p=0.03*1e21 #number of photons that are added to the irradiance. in this example it is 3% of the number of photons absorbed by a Silicon solar cell in m-2
|
|
200
|
+
|
|
201
|
+
# Create a tmp folder to store the modified AM1.5G spectra
|
|
202
|
+
# rnd_ID = str(uuid.uuid4())
|
|
203
|
+
tmp_spectrum_path = os.path.join(session_path,'tmp_spectrum'+UUID)
|
|
204
|
+
if not os.path.exists(tmp_spectrum_path):
|
|
205
|
+
os.makedirs(tmp_spectrum_path)
|
|
206
|
+
|
|
207
|
+
# Create wavelength array. If the last point in the array is outside the specified range, remove it
|
|
208
|
+
lambda_array_init = np.arange(lambda_min,lambda_max+lambda_step,lambda_step)
|
|
209
|
+
if lambda_array_init[-1] > lambda_max:
|
|
210
|
+
lambda_array = np.delete(lambda_array_init,-1)
|
|
211
|
+
else:
|
|
212
|
+
lambda_array = lambda_array_init
|
|
213
|
+
|
|
214
|
+
# convert to m
|
|
215
|
+
lambda_array = lambda_array*1e-9
|
|
216
|
+
|
|
217
|
+
EQE_create_spectrum_files(lambda_array, p, session_path, spectrum, tmp_spectrum_path)
|
|
218
|
+
|
|
219
|
+
#runs for no monochromatic peak (normal spectrum) and obtains J0 and its err
|
|
220
|
+
# Prepare the arguments for the simulation
|
|
221
|
+
EQE_args = [{'par':'dev_par_file','val':simss_device_parameters},
|
|
222
|
+
{'par':'outputRatio','val':str(0)}, # we don't care about the var file here
|
|
223
|
+
{'par':'Vmin','val':str(Vext)},
|
|
224
|
+
{'par':'Vmax','val':str(Vext)},
|
|
225
|
+
{'par':'spectrum','val':spectrum},
|
|
226
|
+
{'par':'JVFile','val':os.path.join(session_path,JV_file_name)}, # need to add the session path to the JV file name to make sure it is stored in the session folder
|
|
227
|
+
# below are unecessary output files but we asign them to avoid errors
|
|
228
|
+
{'par':'logFile','val':'log'+dum_str+'.txt'},
|
|
229
|
+
{'par':'varFile','val':varFile},
|
|
230
|
+
{'par':'scParsFile','val':'scPars'+dum_str+'.txt'}
|
|
231
|
+
]
|
|
232
|
+
if turnoff_autoTidy:
|
|
233
|
+
EQE_args.append({'par':'autoTidy','val':'0'})
|
|
234
|
+
|
|
235
|
+
if cmd_pars is not None:
|
|
236
|
+
EQE_args = update_cmd_pars(EQE_args, cmd_pars)
|
|
237
|
+
|
|
238
|
+
if threadsafe:
|
|
239
|
+
result, message = utils_gen.run_simulation_filesafe('simss', EQE_args, session_path, run_mode)
|
|
240
|
+
else:
|
|
241
|
+
result, message = utils_gen.run_simulation('simss', EQE_args, session_path, run_mode)
|
|
242
|
+
# result, message = run_sim_EQE(simss_device_parameters, session_path, spectrum, Vext, JV_file_name, run_mode)
|
|
243
|
+
|
|
244
|
+
# If the simulation fails, stop running the script and exit
|
|
245
|
+
if not result.returncode == 0:
|
|
246
|
+
if result.returncode == 95:
|
|
247
|
+
message = f'SIMsalabim raised an error with errorcode {result.returncode}, simulation did not converge.'
|
|
248
|
+
msg_list.append(message)
|
|
249
|
+
return result.returncode, msg_list
|
|
250
|
+
|
|
251
|
+
# Get the current density Jext and its error
|
|
252
|
+
J0_single, J0_err_single = get_CurrDens(JV_file_name, session_path)
|
|
253
|
+
|
|
254
|
+
Jext,Jext_err = [],[]
|
|
255
|
+
|
|
256
|
+
#obtains Jext and Jext error for a monochromatic peak at each wavelength
|
|
257
|
+
if parallel and len(lambda_array) > 1 : # Run the simulations in parallel
|
|
258
|
+
JV_file_name_base, JV_file_name_ext = os.path.splitext(JV_file_name)
|
|
259
|
+
log_file_name_base, log_file_name_ext = os.path.splitext('log'+dum_str+'.txt')
|
|
260
|
+
scParsFile_name_base, scParsFile_name_ext = os.path.splitext('scPars'+dum_str+'.txt')
|
|
261
|
+
|
|
262
|
+
EQE_args_list = []
|
|
263
|
+
for i in lambda_array:
|
|
264
|
+
JV_file_name_single = f'{JV_file_name_base}{dum_str}_{int(i*1e9)}nm{JV_file_name_ext}'
|
|
265
|
+
if varFile != 'none':
|
|
266
|
+
varFile_single = f'{var_file_base}+{dum_str}_{int(i*1e9)}nm{var_file_ext}'
|
|
267
|
+
varFile_single = os.path.join(session_path,varFile_single)
|
|
268
|
+
else:
|
|
269
|
+
varFile_single = 'none'
|
|
270
|
+
dum_args = [{'par':'dev_par_file','val':simss_device_parameters},
|
|
271
|
+
{'par':'outputRatio','val':str(0)}, # we don't care about the var file here
|
|
272
|
+
{'par':'Vmin','val':str(Vext)},
|
|
273
|
+
{'par':'Vmax','val':str(Vext)},
|
|
274
|
+
{'par':'spectrum','val':os.path.join(tmp_spectrum_path,f'{int(i*1e9)}nm_{os.path.basename(spectrum)}')},
|
|
275
|
+
{'par':'JVFile','val':os.path.join(session_path,JV_file_name_single)}, # makes sure that the JV file is unique for each simulation and is stored in the session folder
|
|
276
|
+
# below are unecessary output files but we asign them to avoid errors
|
|
277
|
+
{'par':'logFile','val':f'{log_file_name_base}_{int(i*1e9)}nm{log_file_name_ext}'},
|
|
278
|
+
{'par':'varFile','val':varFile_single},
|
|
279
|
+
{'par':'scParsFile','val':f'{scParsFile_name_base}_{int(i*1e9)}nm{scParsFile_name_ext}'}
|
|
280
|
+
]
|
|
281
|
+
if turnoff_autoTidy:
|
|
282
|
+
dum_args.append({'par':'autoTidy','val':'0'}) # necessary to avoid autoTidy messing up the files in parallel mode
|
|
283
|
+
|
|
284
|
+
if cmd_pars is not None:
|
|
285
|
+
dum_args = update_cmd_pars(dum_args, cmd_pars)
|
|
286
|
+
EQE_args_list.append(dum_args)
|
|
287
|
+
|
|
288
|
+
results = run_simulation_parallel('simss', EQE_args_list, session_path, max_jobs, force_multithreading=force_multithreading)
|
|
289
|
+
|
|
290
|
+
for i in lambda_array:
|
|
291
|
+
JV_file_name_single = f'{JV_file_name_base}{dum_str}_{int(i*1e9)}nm{JV_file_name_ext}'
|
|
292
|
+
J_single, Jerr_single = get_CurrDens(os.path.join(session_path,JV_file_name_single),session_path)
|
|
293
|
+
Jext.append(J_single)
|
|
294
|
+
Jext_err.append(Jerr_single)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
else:
|
|
299
|
+
for i in lambda_array:
|
|
300
|
+
JV_file_name_base, JV_file_name_ext = os.path.splitext(JV_file_name)
|
|
301
|
+
JV_file_name_single = f'{JV_file_name_base}_{int(i*1e9)}nm{JV_file_name_ext}'
|
|
302
|
+
log_file_name_base, log_file_name_ext = os.path.splitext('log'+dum_str+'.txt')
|
|
303
|
+
scParsFile_name_base, scParsFile_name_ext = os.path.splitext('scPars'+dum_str+'.txt')
|
|
304
|
+
if varFile != 'none':
|
|
305
|
+
varFile_single = f'{var_file_base}_{int(i*1e9)}nm{var_file_ext}'
|
|
306
|
+
varFile_single = os.path.join(session_path,varFile_single)
|
|
307
|
+
else:
|
|
308
|
+
varFile_single = 'none'
|
|
309
|
+
|
|
310
|
+
EQE_args = [{'par':'dev_par_file','val':simss_device_parameters},
|
|
311
|
+
{'par':'outputRatio','val':str(0)}, # we don't care about the var file here
|
|
312
|
+
{'par':'Vmin','val':str(Vext)},
|
|
313
|
+
{'par':'Vmax','val':str(Vext)},
|
|
314
|
+
{'par':'spectrum','val':os.path.join(tmp_spectrum_path,f'{int(i*1e9)}nm_{os.path.basename(spectrum)}')},
|
|
315
|
+
{'par':'JVFile','val':os.path.join(session_path,JV_file_name_single)},#JV_file_name_single}, # makes sure that the JV file is unique for each simulation and is stored in the session folder
|
|
316
|
+
# below are unecessary output files but we asign them to avoid errors
|
|
317
|
+
{'par':'logFile','val':f'{log_file_name_base}_{int(i*1e9)}nm{log_file_name_ext}'},
|
|
318
|
+
{'par':'varFile','val':varFile_single},
|
|
319
|
+
{'par':'scParsFile','val':f'{scParsFile_name_base}_{int(i*1e9)}nm{scParsFile_name_ext}'}
|
|
320
|
+
]
|
|
321
|
+
if turnoff_autoTidy:
|
|
322
|
+
EQE_args.append({'par':'autoTidy','val':'0'})
|
|
323
|
+
|
|
324
|
+
if cmd_pars is not None:
|
|
325
|
+
EQE_args = update_cmd_pars(EQE_args, cmd_pars)
|
|
326
|
+
|
|
327
|
+
if threadsafe:
|
|
328
|
+
result, message = utils_gen.run_simulation_filesafe('simss', EQE_args, session_path, run_mode)
|
|
329
|
+
else:
|
|
330
|
+
result, message = utils_gen.run_simulation('simss', EQE_args, session_path, run_mode)
|
|
331
|
+
# result, message = run_sim_EQE(simss_device_parameters, session_path, os.path.join('tmp_spectrum',f'{int(i*1e9)}_{os.path.basename(spectrum)}'), Vext, JV_file_name_single,run_mode)
|
|
332
|
+
|
|
333
|
+
if not result.returncode == 0:
|
|
334
|
+
msg_list.append(message)
|
|
335
|
+
|
|
336
|
+
J_single, Jerr_single = get_CurrDens(JV_file_name_single,session_path)
|
|
337
|
+
|
|
338
|
+
Jext.append(J_single)
|
|
339
|
+
Jext_err.append(Jerr_single)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
# Remove the tmp folder as it is not needed anymore
|
|
343
|
+
if remove_dirs:
|
|
344
|
+
for file in os.listdir(tmp_spectrum_path):
|
|
345
|
+
os.remove(os.path.join(tmp_spectrum_path,file))
|
|
346
|
+
os.rmdir(os.path.join(tmp_spectrum_path))
|
|
347
|
+
|
|
348
|
+
# remove all files starting with 'log'+dum_str and 'scPars'+dum_str
|
|
349
|
+
for file in os.listdir(session_path):
|
|
350
|
+
if file.startswith('log'+dum_str) or file.startswith('scPars'+dum_str):
|
|
351
|
+
os.remove(os.path.join(session_path,file))
|
|
352
|
+
|
|
353
|
+
# Calculate EQE
|
|
354
|
+
deltaJ, deltaJerr, I_diff, EQE_val, EQE_err = calc_EQE(Jext,Jext_err,J0_single, J0_err_single, lambda_array,p)
|
|
355
|
+
|
|
356
|
+
# Save the results in a file
|
|
357
|
+
fp = open(os.path.join(session_path,output_file), 'w')
|
|
358
|
+
fp.write('lambda Jext Jerr deltaJ deltaJerr Imonopeak EQE EQEerr\n')
|
|
359
|
+
for i in range(len(lambda_array)):
|
|
360
|
+
fp.write(f'{lambda_array[i]:.3e} {Jext[i]:.3e} {Jext_err[i]:.3e} {deltaJ[i]:.3e} {deltaJerr[i]:.3e} {I_diff[i]:.3e} {EQE_val[i]:.3e} {EQE_err[i]:.3e}\n')
|
|
361
|
+
fp.close()
|
|
362
|
+
|
|
363
|
+
if len(msg_list) != 0:
|
|
364
|
+
return 1, msg_list
|
|
365
|
+
else:
|
|
366
|
+
return 0, msg_list
|
|
367
|
+
|
|
368
|
+
if __name__ == '__main__':
|
|
369
|
+
## Manual EQE input parameters. These are overwritten by command line arguments if provided
|
|
370
|
+
lambda_min = 280 # Lower limit of the wavelength range in nm
|
|
371
|
+
lambda_max = 1000 # Upper limit of the wavelength range in nm
|
|
372
|
+
lambda_step = 20 # Step size of the wavelength range in nm
|
|
373
|
+
Vext = [0] # Array with applied voltages in V
|
|
374
|
+
|
|
375
|
+
# Define folder and file paths
|
|
376
|
+
session_path = os.path.join('../../','SIMsalabim','SimSS')
|
|
377
|
+
|
|
378
|
+
simss_device_parameters = 'simulation_setup.txt'
|
|
379
|
+
spectrum = os.path.join('..','Data','AM15G.txt') # Path of the original spectrum file
|
|
380
|
+
|
|
381
|
+
# UUID = str(uuid.uuid4()) # Add a UUID to the simulation
|
|
382
|
+
UUID = ''
|
|
383
|
+
|
|
384
|
+
############## Command line arguments ##############
|
|
385
|
+
## Notes
|
|
386
|
+
## - The command line arguments are optional and can be provided in any order
|
|
387
|
+
## - Each command line argument must be provided in the format -par_name value
|
|
388
|
+
## - Possible arguments include all SIMsalabim parameters and EQE specific parameters as listed before
|
|
389
|
+
## - Special arguments
|
|
390
|
+
## - sp : string
|
|
391
|
+
## - The session path, i.e. the working directory for the simulation
|
|
392
|
+
## - simsetup : string
|
|
393
|
+
## - The name of the simss simulation setup parameters file
|
|
394
|
+
## - UUID : string
|
|
395
|
+
## - An UUID to add to the simulation (output)
|
|
396
|
+
|
|
397
|
+
cmd_pars_dict = {}
|
|
398
|
+
cmd_pars = []
|
|
399
|
+
|
|
400
|
+
# Check if any arguments are provided.
|
|
401
|
+
if len(sys.argv) >= 2:
|
|
402
|
+
# Each arguments should be in the format -par val, i.e. in pairs of two. Skip the first argument as this is the script name
|
|
403
|
+
if not len(sys.argv[1:]) % 2 == 0:
|
|
404
|
+
print('Error in command line parameters. Please provide arguments in the format -par_name value -par_name value ...')
|
|
405
|
+
sys.exit(1)
|
|
406
|
+
else:
|
|
407
|
+
input_list = sys.argv[1:]
|
|
408
|
+
# Loop over the input list and put pairs into a dictionary with the first argument as key and the second argument as value
|
|
409
|
+
for i in range(0,len(input_list),2):
|
|
410
|
+
# Check if the key already exists, if not, add it to the cmd_pars_dict
|
|
411
|
+
if str(input_list[i][1:]) in cmd_pars_dict:
|
|
412
|
+
print(f'Duplicate parameter found in the command line parameters: {str(input_list[i][1:])}')
|
|
413
|
+
sys.exit(1)
|
|
414
|
+
else:
|
|
415
|
+
cmd_pars_dict[str(input_list[i][1:])] = str(input_list[i+1])
|
|
416
|
+
|
|
417
|
+
# Check and process specific keys/arguments that are not native SIMsalabim arguments
|
|
418
|
+
# Handle the session_path/sp argument separately, as the other parameters depend on this
|
|
419
|
+
if 'sp' in cmd_pars_dict:
|
|
420
|
+
session_path = cmd_pars_dict['sp']
|
|
421
|
+
# remove from cmd_pars
|
|
422
|
+
cmd_pars_dict.pop('sp')
|
|
423
|
+
|
|
424
|
+
# Define mappings for keys and variables
|
|
425
|
+
key_action_map = {
|
|
426
|
+
'simsetup': lambda val: {'simss_device_parameters': val},
|
|
427
|
+
'lambda_min': lambda val: {'lambda_min': float(val)},
|
|
428
|
+
'lambda_max': lambda val: {'lambda_max': float(val)},
|
|
429
|
+
'lambda_step': lambda val: {'lambda_step': int(val)},
|
|
430
|
+
'Vext': lambda val: {'Vext': val.split(',')}, # IMPORTANT: if multiple voltages are provided, they must be separated by a comma!!
|
|
431
|
+
'spectrum': lambda val: {'spectrum': val},
|
|
432
|
+
'UUID': lambda val: {'UUID': val},
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
for key in list(cmd_pars_dict.keys()): # Use list to avoid modifying the dictionary while iterating
|
|
436
|
+
if key in key_action_map:
|
|
437
|
+
# Apply the corresponding action
|
|
438
|
+
result = key_action_map[key](cmd_pars_dict[key])
|
|
439
|
+
globals().update(result) # Dynamically update global variables
|
|
440
|
+
cmd_pars_dict.pop(key)
|
|
441
|
+
|
|
442
|
+
# Handle remaining keys in `cmd_pars_dict` and add them to the cmd_pars list
|
|
443
|
+
cmd_pars.extend({'par': key, 'val': value} for key, value in cmd_pars_dict.items())
|
|
444
|
+
|
|
445
|
+
for i in range(len(Vext)):
|
|
446
|
+
output_file = f'output_{Vext[i]}V.dat'
|
|
447
|
+
retval = run_EQE(simss_device_parameters, session_path, spectrum, lambda_min, lambda_max, lambda_step, Vext[i], output_file, remove_dirs=True, run_mode=False, UUID=UUID)
|
|
448
|
+
|
|
449
|
+
plt.figure()
|
|
450
|
+
for i in range(len(Vext)):
|
|
451
|
+
res = pd.read_csv(os.path.join(session_path,f'output_{Vext[i]}V.dat'), sep=r'\s+')
|
|
452
|
+
plt.scatter(res['lambda']/1E-9, res['EQE'], label=f'V = {i}')
|
|
453
|
+
plt.title('EQE for solar cell', fontsize = 16)
|
|
454
|
+
plt.tick_params(axis='both',direction='in')
|
|
455
|
+
plt.xlabel('Wavelength [nm]', fontsize = 16)
|
|
456
|
+
plt.ylabel('EQE', fontsize = 16)
|
|
457
|
+
plt.xlim(lambda_min, lambda_max)
|
|
458
|
+
plt.ylim(0,1)
|
|
459
|
+
plt.legend()
|
|
460
|
+
|
|
461
|
+
plt.show()
|