-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_compare_methods.py
1153 lines (785 loc) · 43.2 KB
/
test_compare_methods.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 pytest import approx, mark
import numpy as np
import sys
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_tmm_rcwa_structure_comparison():
from solcore import si, material
from solcore.structure import Layer
from solcore.solar_cell import SolarCell
from rayflare.rigorous_coupled_wave_analysis import rcwa_structure
from rayflare.transfer_matrix_method import tmm_structure
from rayflare.options import default_options
InGaP = material('GaInP')(In=0.5)
GaAs = material('GaAs')()
Ge = material('Ge')()
Ag = material('Ag')()
Air = material('Air')()
Al2O3 = material('Al2O3')()
wavelengths = np.linspace(250, 1900, 500) * 1e-9
options = default_options()
options.wavelengths = wavelengths
options.orders = 2
size = ((100, 0), (0, 100))
# anti-reflection coating
ARC = [Layer(si('80nm'), Al2O3)]
solar_cell = SolarCell(ARC + [Layer(material=InGaP, width=si('400nm')),
Layer(material=GaAs, width=si('4000nm')),
Layer(material=Ge, width=si('3000nm'))], substrate=Ag)
rcwa_setup = rcwa_structure(solar_cell, size=size, options=options, incidence=Air, transmission=Ag)
tmm_setup = tmm_structure(solar_cell, incidence=Air, transmission=Ag, no_back_reflection=False)
for pol in ['s', 'p', 'u']:
for angle in [0, np.pi / 3]:
options['pol'] = pol
options['theta_in'] = angle
rcwa_result = rcwa_setup.calculate(options)
tmm_result = tmm_setup.calculate(options)
assert tmm_result['A_per_layer'] == approx(rcwa_result['A_per_layer'])
assert tmm_result['R'] == approx(rcwa_result['R'])
assert tmm_result['T'] == approx(rcwa_result['T'])
assert np.sum(tmm_result['A_per_layer'], 1) + tmm_result['R'] + tmm_result['T'] == approx(1)
assert np.sum(rcwa_result['A_per_layer'], 1) + rcwa_result['R'] + rcwa_result['T'] == approx(1)
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_planar_structure():
# solcore imports
from solcore.structure import Layer
from solcore import material
from solcore.absorption_calculator import calculate_rat, OptiStack
# rayflare imports
from rayflare.textures.standard_rt_textures import planar_surface
from rayflare.structure import Interface, BulkLayer, Structure
from rayflare.matrix_formalism import process_structure, calculate_RAT
from rayflare.options import default_options
# Thickness of bottom Ge layer
bulkthick = 300e-6
wavelengths = np.linspace(300, 1850, 50) * 1e-9
# set options
options = default_options()
options.wavelengths = wavelengths
options.project_name = 'method_comparison_test'
options.n_rays = 250
options.n_theta_bins = 3
options.lookuptable_angles = 100
options.parallel = True
options.c_azimuth = 0.001
options.I_thresh = 1e-8
options.bulk_profile = False
# set up Solcore materials
Ge = material('Ge')()
GaAs = material('GaAs')()
GaInP = material('GaInP')(In=0.5)
Ag = material('Ag')()
SiN = material('Si3N4')()
Air = material('Air')()
Ta2O5 = material('TaOx1')() # Ta2O5 (SOPRA database)
MgF2 = material('MgF2')() # MgF2 (SOPRA database)
front_materials = [Layer(120e-9, MgF2), Layer(74e-9, Ta2O5), Layer(464e-9, GaInP),
Layer(1682e-9, GaAs)]
back_materials = [Layer(100E-9, SiN)]
# TMM, matrix framework
front_surf = Interface('TMM', layers=front_materials, name = 'GaInP_GaAs_TMM',
coherent=True)
back_surf = Interface('TMM', layers=back_materials, name = 'SiN_Ag_TMM',
coherent=True)
bulk_Ge = BulkLayer(bulkthick, Ge, name = 'Ge_bulk') # bulk thickness in m
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_TMM_Matrix = calculate_RAT(SC, options)
results_per_pass_TMM_matrix = results_TMM_Matrix[1]
results_per_layer_front_TMM_matrix = np.sum(results_per_pass_TMM_matrix['a'][0], 0)
## RT with TMM lookup tables
surf = planar_surface() # [texture, flipped texture]
front_surf = Interface('RT_TMM', layers=front_materials, texture=surf, name = 'GaInP_GaAs_RT',
coherent=True)
back_surf = Interface('RT_TMM', layers=back_materials, texture = surf, name = 'SiN_Ag_RT_50k',
coherent=True)
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RT = calculate_RAT(SC, options)
results_per_pass_RT = results_RT[1]
# only select absorbing layers, sum over passes
results_per_layer_front_RT = np.sum(results_per_pass_RT['a'][0], 0)
## RCWA
front_surf = Interface('RCWA', layers=front_materials, name = 'GaInP_GaAs_RCWA',
coherent=True, d_vectors = ((500,0), (0,500)), rcwa_orders=2)
back_surf = Interface('RCWA', layers=back_materials, name = 'SiN_Ag_RCWA',
coherent=True, d_vectors = ((500,0), (0,500)), rcwa_orders=2)
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RCWA_Matrix = calculate_RAT(SC, options)
results_per_pass_RCWA = results_RCWA_Matrix[1]
# only select absorbing layers, sum over passes
results_per_layer_front_RCWA = np.sum(results_per_pass_RCWA['a'][0], 0)
## pure TMM (from Solcore)
all_layers = front_materials + [Layer(bulkthick, Ge)] + back_materials
coh_list = len(front_materials)*['c'] + ['i'] + ['c']
OS_layers = OptiStack(all_layers, substrate=Ag, no_back_reflection=False)
TMM_res = calculate_rat(OS_layers, wavelength=wavelengths*1e9,
no_back_reflection=False, angle=options['theta_in']*180/np.pi, coherent=False,
coherency_list=coh_list, pol=options['pol'])
# stack results for comparison
TMM_reference = TMM_res['A_per_layer'][1:-2].T
TMM_matrix = np.hstack((results_per_layer_front_TMM_matrix, results_TMM_Matrix[0].A_bulk[0].data[:,None]))
RCWA_matrix = np.hstack((results_per_layer_front_RCWA, results_RCWA_Matrix[0].A_bulk[0].data[:, None]))
RT_matrix = np.hstack((results_per_layer_front_RT, results_RT[0].A_bulk[0].data[:, None]))
assert TMM_reference == approx(TMM_matrix, abs=0.02)
assert TMM_reference == approx(RCWA_matrix, abs=0.02)
assert TMM_reference == approx(RT_matrix, abs=0.2)
# check normalization
assert (results_TMM_Matrix[0].R[0] + results_TMM_Matrix[0].T[0] + np.sum(results_per_layer_front_TMM_matrix, 1) + results_TMM_Matrix[0].A_bulk[0]).data == approx(1)
assert (results_RCWA_Matrix[0].R[0] + results_RCWA_Matrix[0].T[0] + np.sum(results_per_layer_front_RCWA, 1) + results_RCWA_Matrix[0].A_bulk[0]).data == approx(1)
assert (results_RT[0].R[0] + results_RT[0].T[0] + np.sum(results_per_layer_front_RT, 1) +
results_RT[0].A_bulk[0]).data == approx(1)
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_planar_structure_45deg():
# solcore imports
from solcore.structure import Layer
from solcore import material
from solcore.absorption_calculator import calculate_rat, OptiStack
# rayflare imports
from rayflare.textures.standard_rt_textures import planar_surface
from rayflare.structure import Interface, BulkLayer, Structure
from rayflare.matrix_formalism import process_structure, calculate_RAT
from rayflare.options import default_options
# Thickness of bottom Ge layer
bulkthick = 300e-6
wavelengths = np.linspace(300, 1850, 30) * 1e-9
# set options
options = default_options()
options.wavelengths = wavelengths
options.project_name = 'method_comparison_test_45deg'
options.n_rays = 500
options.n_theta_bins = 20
options.lookuptable_angles = 100
options.parallel = True
options.c_azimuth = 0.001
options.theta_in = 0.6*np.pi/2
options.nx = 1
options.ny = 1
options.I_thresh = 1e-8
options.bulk_profile = False
# set up Solcore materials
Ge = material('Ge')()
GaAs = material('GaAs')()
GaInP = material('GaInP')(In=0.5)
Ag = material('Ag')()
SiN = material('Si3N4')()
Air = material('Air')()
Ta2O5 = material('TaOx1')() # Ta2O5 (SOPRA database)
MgF2 = material('MgF2')() # MgF2 (SOPRA database)
front_materials = [Layer(120e-9, MgF2), Layer(74e-9, Ta2O5), Layer(464e-9, GaInP),
Layer(1682e-9, GaAs)]
back_materials = [Layer(100E-9, SiN)]
# TMM, matrix framework
front_surf = Interface('TMM', layers=front_materials, name = 'GaInP_GaAs_TMM',
coherent=True)
back_surf = Interface('TMM', layers=back_materials, name = 'SiN_Ag_TMM',
coherent=True)
bulk_Ge = BulkLayer(bulkthick, Ge, name = 'Ge_bulk') # bulk thickness in m
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_TMM_Matrix = calculate_RAT(SC, options)
results_per_pass_TMM_matrix = results_TMM_Matrix[1]
results_per_layer_front_TMM_matrix = np.sum(results_per_pass_TMM_matrix['a'][0], 0)
## RT with TMM lookup tables
surf = planar_surface() # [texture, flipped texture]
front_surf = Interface('RT_TMM', layers=front_materials, texture=surf, name = 'GaInP_GaAs_RT',
coherent=True)
back_surf = Interface('RT_TMM', layers=back_materials, texture = surf, name = 'SiN_Ag_RT_50k',
coherent=True)
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RT = calculate_RAT(SC, options)
results_per_pass_RT = results_RT[1]
# only select absorbing layers, sum over passes
results_per_layer_front_RT = np.sum(results_per_pass_RT['a'][0], 0)
## RCWA
front_surf = Interface('RCWA', layers=front_materials, name = 'GaInP_GaAs_RCWA',
coherent=True, d_vectors = ((500,0), (0,500)), rcwa_orders=2)
back_surf = Interface('RCWA', layers=back_materials, name = 'SiN_Ag_RCWA',
coherent=True, d_vectors = ((500,0), (0,500)), rcwa_orders=2)
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RCWA_Matrix = calculate_RAT(SC, options)
results_per_pass_RCWA = results_RCWA_Matrix[1]
# only select absorbing layers, sum over passes
results_per_layer_front_RCWA = np.sum(results_per_pass_RCWA['a'][0], 0)
## pure TMM (from Solcore)
all_layers = front_materials + [Layer(bulkthick, Ge)] + back_materials
coh_list = len(front_materials)*['c'] + ['i'] + ['c']
OS_layers = OptiStack(all_layers, substrate=Ag, no_back_reflection=False)
TMM_res = calculate_rat(OS_layers, wavelength=wavelengths*1e9,
no_back_reflection=False, angle=options['theta_in']*180/np.pi, coherent=False,
coherency_list=coh_list, pol=options['pol'])
# stack results for comparison
TMM_reference = TMM_res['A_per_layer'][1:-2].T
TMM_matrix = np.hstack((results_per_layer_front_TMM_matrix, results_TMM_Matrix[0].A_bulk[0].data[:,None]))
RCWA_matrix = np.hstack((results_per_layer_front_RCWA, results_RCWA_Matrix[0].A_bulk[0].data[:, None]))
RT_matrix = np.hstack((results_per_layer_front_RT, results_RT[0].A_bulk[0].data[:, None]))
assert TMM_reference == approx(TMM_matrix, abs=0.05)
assert TMM_reference == approx(RCWA_matrix, abs=0.05)
assert TMM_reference == approx(RT_matrix, abs=0.3)
assert (results_TMM_Matrix[0].R[0] + results_TMM_Matrix[0].T[0] + np.sum(results_per_layer_front_TMM_matrix, 1) +
results_TMM_Matrix[0].A_bulk[0]).data == approx(1)
assert (results_RCWA_Matrix[0].R[0] + results_RCWA_Matrix[0].T[0] + np.sum(results_per_layer_front_RCWA, 1) +
results_RCWA_Matrix[0].A_bulk[0]).data == approx(1)
assert (results_RT[0].R[0] + results_RT[0].T[0] + np.sum(results_per_layer_front_RT, 1) +
results_RT[0].A_bulk[0]).data == approx(1)
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_tmm_rcwa_pol_angle():
# solcore imports
from solcore.structure import Layer
from solcore import material
from solcore.absorption_calculator import calculate_rat, OptiStack
# rayflare imports
from rayflare.structure import Interface, BulkLayer, Structure
from rayflare.matrix_formalism import process_structure, calculate_RAT
from rayflare.options import default_options
# Thickness of bottom Ge layer
bulkthick = 300e-6
wavelengths = np.linspace(300, 1850, 30) * 1e-9
# set options
options = default_options()
options.wavelengths = wavelengths
options.project_name = 'method_comparison_test_angle_pol'
options.n_theta_bins = 50
options.lookuptable_angles = 100
options.parallel = True
options.c_azimuth = 0.001
options.I_thresh = 1e-8
options.only_incidence_angle = False
options.bulk_profile = False
# set up Solcore materials
Ge = material('Ge')()
GaAs = material('GaAs')()
GaInP = material('GaInP')(In=0.5)
Ag = material('Ag')()
SiN = material('Si3N4')()
Air = material('Air')()
Ta2O5 = material('TaOx1')() # Ta2O5 (SOPRA database)
MgF2 = material('MgF2')() # MgF2 (SOPRA database)
front_materials = [Layer(120e-9, MgF2), Layer(74e-9, Ta2O5), Layer(464e-9, GaInP),
Layer(1682e-9, GaAs)]
back_materials = [Layer(100E-9, SiN)]
angles = [0, np.pi/5, np.pi/3]
pols = ['s', 'p', 'u']
# TMM, matrix framework
for angle in angles:
for pol in pols:
options.pol = pol
options.theta_in = angle
options.phi_in = angle
front_surf = Interface('TMM', layers=front_materials, name='GaInP_GaAs_TMM'+str(pol),
coherent=True)
back_surf = Interface('TMM', layers=back_materials, name='SiN_Ag_TMM'+str(pol),
coherent=True)
bulk_Ge = BulkLayer(bulkthick, Ge, name='Ge_bulk') # bulk thickness in m
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_TMM_Matrix = calculate_RAT(SC, options)
results_per_pass_TMM_matrix = results_TMM_Matrix[1]
results_per_layer_front_TMM_matrix = np.sum(results_per_pass_TMM_matrix['a'][0], 0)
## RCWA
front_surf = Interface('RCWA', layers=front_materials, name='GaInP_GaAs_RCWA'+str(pol),
coherent=True, d_vectors=((500, 0), (0, 500)), rcwa_orders=2)
back_surf = Interface('RCWA', layers=back_materials, name='SiN_Ag_RCWA'+str(pol),
coherent=True, d_vectors=((500, 0), (0, 500)), rcwa_orders=2)
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RCWA_Matrix = calculate_RAT(SC, options)
results_per_pass_RCWA = results_RCWA_Matrix[1]
# only select absorbing layers, sum over passes
results_per_layer_front_RCWA = np.sum(results_per_pass_RCWA['a'][0], 0)
## pure TMM (from Solcore)
all_layers = front_materials + [Layer(bulkthick, Ge)] + back_materials
coh_list = len(front_materials) * ['c'] + ['i'] + ['c']
OS_layers = OptiStack(all_layers, substrate=Ag, no_back_reflection=False)
TMM_res = calculate_rat(OS_layers, wavelength=wavelengths * 1e9,
no_back_reflection=False, angle=options.theta_in * 180 / np.pi, coherent=False,
coherency_list=coh_list, pol=options.pol)
# stack results for comparison
TMM_reference = TMM_res['A_per_layer'][1:-2].T
TMM_matrix = np.hstack((results_per_layer_front_TMM_matrix, results_TMM_Matrix[0].A_bulk[0].data[:, None]))
RCWA_matrix = np.hstack((results_per_layer_front_RCWA, results_RCWA_Matrix[0].A_bulk[0].data[:, None]))
print(pol, angle)
assert TMM_reference == approx(TMM_matrix, abs=0.05)
assert TMM_reference == approx(RCWA_matrix, abs=0.05)
assert (results_TMM_Matrix[0].R[0] + results_TMM_Matrix[0].T[0] + np.sum(results_per_layer_front_TMM_matrix, 1) +
results_TMM_Matrix[0].A_bulk[0]).data == approx(1)
assert (results_RCWA_Matrix[0].R[0] + results_RCWA_Matrix[0].T[0] + np.sum(results_per_layer_front_RCWA, 1) +
results_RCWA_Matrix[0].A_bulk[0]).data == approx(1)
def test_absorption_profile():
from rayflare.ray_tracing import rt_structure
from rayflare.textures import planar_surface
from rayflare.options import default_options
from solcore import material
from solcore import si
from rayflare.transfer_matrix_method import tmm_structure
from solcore.structure import Layer
Air = material('Air')()
Si = material('Si')()
GaAs = material('GaAs')()
Ge = material('Ge')()
triangle_surf = planar_surface()
options = default_options()
options.wavelengths = np.linspace(700, 1400, 4)*1e-9
options.theta_in = 45*np.pi/180
options.nx = 5
options.ny = 5
options.pol = 'u'
options.n_rays = 2000
options.depth_spacing = 1e-6
rtstr = rt_structure(textures=[triangle_surf, triangle_surf, triangle_surf, triangle_surf],
materials = [GaAs, Si, Ge],
widths=[si('100um'), si('70um'), si('50um')], incidence=Air, transmission=Air)
result_rt = rtstr.calculate(options)
stack = [Layer(si('100um'), GaAs), Layer(si('70um'), Si), Layer(si('50um'), Ge)]
strt = tmm_structure(stack, incidence=Air, transmission=Air,
no_back_reflection=False)
output = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile = output['profile'][output['profile'] > 1e-7]
rt_profile = result_rt['profile'][output['profile'] > 1e-7]
assert output['profile'].shape == result_rt['profile'].shape
assert rt_profile == approx(tmm_profile, rel=0.4)
def test_absorption_profile_incoh_angles():
from rayflare.ray_tracing import rt_structure
from rayflare.textures import planar_surface
from rayflare.options import default_options
from solcore import material
from solcore import si
from rayflare.transfer_matrix_method import tmm_structure
from solcore.structure import Layer
Air = material('Air')()
Si = material('Si')()
GaAs = material('GaAs')()
Ge = material('Ge')()
triangle_surf = planar_surface()
options = default_options()
options.wavelengths = np.linspace(700, 1400, 4)*1e-9
options.nx = 5
options.ny = 5
options.n_rays = 2000
options.depth_spacing = 1e-6
options.coherent = False
options.coherency_list = ['c', 'i', 'i']
options.theta_in = np.pi/4
options.phi_in = np.pi/3
options.pol = 's'
rtstr = rt_structure(textures=[triangle_surf, triangle_surf, triangle_surf, triangle_surf],
materials = [GaAs, Si, Ge],
widths=[si('100um'), si('70um'), si('50um')], incidence=Air, transmission=Air)
result_rt_s = rtstr.calculate(options)
stack = [Layer(si('100um'), GaAs), Layer(si('70um'), Si), Layer(si('50um'), Ge)]
strt = tmm_structure(stack, incidence=Air, transmission=Air,
no_back_reflection=False)
output_s = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile_s = output_s['profile'][output_s['profile'] > 1e-7]
rt_profile_s = result_rt_s['profile'][output_s['profile'] > 1e-7]
assert output_s['profile'].shape == result_rt_s['profile'].shape
assert rt_profile_s == approx(tmm_profile_s, rel=0.2)
options.pol = 'p'
result_rt_p = rtstr.calculate(options)
output_p = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile_p = output_p['profile'][output_p['profile'] > 1e-7]
rt_profile_p = result_rt_p['profile'][output_p['profile'] > 1e-7]
assert output_p['profile'].shape == result_rt_p['profile'].shape
assert rt_profile_p == approx(tmm_profile_p, rel=0.2)
options.pol = 'u'
result_rt_u = rtstr.calculate(options)
output_u = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile_u = output_u['profile'][output_u['profile'] > 1e-7]
rt_profile_u = result_rt_u['profile'][output_u['profile'] > 1e-7]
assert output_u['profile'].shape == result_rt_u['profile'].shape
assert rt_profile_u == approx(tmm_profile_u, rel=0.2)
def test_absorption_profile_coh_angles():
from rayflare.ray_tracing import rt_structure
from rayflare.textures import planar_surface
from rayflare.options import default_options
from solcore import material
from solcore import si
from rayflare.transfer_matrix_method import tmm_structure
from solcore.structure import Layer
Air = material('Air')()
Si = material('Si')()
GaAs = material('GaAs')()
Ge = material('Ge')()
triangle_surf = planar_surface()
options = default_options()
options.wavelengths = np.linspace(700, 1400, 4)*1e-9
options.nx = 5
options.ny = 5
options.n_rays = 2000
options.depth_spacing = 1e-6
options.theta_in = np.pi/4
options.phi_in = np.pi/3
options.pol = 's'
rtstr = rt_structure(textures=[triangle_surf, triangle_surf, triangle_surf, triangle_surf],
materials = [GaAs, Si, Ge],
widths=[si('100um'), si('70um'), si('50um')], incidence=Air, transmission=Air)
result_rt_s = rtstr.calculate(options)
stack = [Layer(si('100um'), GaAs), Layer(si('70um'), Si), Layer(si('50um'), Ge)]
strt = tmm_structure(stack, incidence=Air, transmission=Air,
no_back_reflection=False)
output_s = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile_s = output_s['profile'][output_s['profile'] > 1e-7]
rt_profile_s = result_rt_s['profile'][output_s['profile'] > 1e-7]
assert output_s['profile'].shape == result_rt_s['profile'].shape
assert rt_profile_s == approx(tmm_profile_s, rel=0.4)
options.pol = 'p'
result_rt_p = rtstr.calculate(options)
output_p = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile_p = output_p['profile'][output_p['profile'] > 1e-7]
rt_profile_p = result_rt_p['profile'][output_p['profile'] > 1e-7]
assert output_p['profile'].shape == result_rt_p['profile'].shape
assert rt_profile_p == approx(tmm_profile_p, rel=0.4)
options.pol = 'u'
result_rt_u = rtstr.calculate(options)
output_u = strt.calculate(options, profile=True, layers=[1, 2, 3])
tmm_profile_u = output_u['profile'][output_u['profile'] > 1e-7]
rt_profile_u = result_rt_u['profile'][output_u['profile'] > 1e-7]
assert output_u['profile'].shape == result_rt_u['profile'].shape
assert rt_profile_u == approx(tmm_profile_u, rel=0.4)
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_rcwa_tmm_profiles_coh():
from rayflare.options import default_options
from solcore import material
from solcore import si
from rayflare.transfer_matrix_method import tmm_structure
from rayflare.rigorous_coupled_wave_analysis import rcwa_structure
from solcore.structure import Layer
Air = material('Air')()
Si = material('Si')()
GaAs = material('GaAs')()
Ge = material('Ge')()
options = default_options()
options.wavelengths = np.linspace(700, 1400, 4)*1e-9
options.depth_spacing = 10e-9
options.theta_in = np.pi/3
options.phi_in = np.pi/4
options.pol = 's'
stack = [Layer(si('500nm'), GaAs), Layer(si('1.1um'), Si), Layer(si('0.834um'), Ge)]
strt = tmm_structure(stack, incidence=Air, transmission=Air,
no_back_reflection=False)
strt_rcwa = rcwa_structure(stack, ((100, 0), (0, 100)), options, Air, Air)
strt_rcwa.calculate(options)
output_rcwa_s = strt_rcwa.calculate_profile(options)['profile']
output_s = strt.calculate_profile(options)['profile']
tmm_profile_s = output_s[output_s > 1e-7]
rcwa_profile_s = output_rcwa_s[output_s > 1e-7]
assert rcwa_profile_s == approx(tmm_profile_s, rel=0.02)
options.pol = 'p'
stack = [Layer(si('500nm'), GaAs), Layer(si('1.1um'), Si), Layer(si('0.834um'), Ge)]
strt = tmm_structure(stack, incidence=Air, transmission=Air,
no_back_reflection=False)
strt_rcwa = rcwa_structure(stack, ((100, 0), (0, 100)), options, Air, Air)
strt_rcwa.calculate(options)
output_rcwa_p = strt_rcwa.calculate_profile(options)['profile']
output_p = strt.calculate_profile(options)['profile']
tmm_profile_p = output_p[output_p > 1e-7]
rcwa_profile_p = output_rcwa_p[output_p > 1e-7]
assert rcwa_profile_p == approx(tmm_profile_p, rel=0.02)
options.pol = 'u'
stack = [Layer(si('500nm'), GaAs), Layer(si('1.1um'), Si), Layer(si('0.834um'), Ge)]
strt = tmm_structure(stack, incidence=Air, transmission=Air,
no_back_reflection=False)
strt_rcwa = rcwa_structure(stack, ((100, 0), (0, 100)), options, Air, Air)
strt_rcwa.calculate(options)
output_rcwa_u = strt_rcwa.calculate_profile(options)['profile']
output_u = strt.calculate_profile(options)['profile']
tmm_profile_u = output_u[output_u > 1e-7]
rcwa_profile_u = output_rcwa_u[output_u > 1e-7]
assert rcwa_profile_u == approx(tmm_profile_u, rel=0.02)
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_rcwa_tmm_matrix_check_sums():
from solcore.structure import Layer
from solcore import material
# rayflare imports
from rayflare.textures import planar_surface
from rayflare.structure import Interface, BulkLayer, Structure
from rayflare.matrix_formalism import process_structure, calculate_RAT
from rayflare.options import default_options
from rayflare.transfer_matrix_method import tmm_structure
from rayflare.angles import make_angle_vector
# Thickness of bulk Ge layer
bulkthick = 30e-9
wavelengths = np.linspace(640, 850, 6) * 1e-9
# set options
options = default_options()
options.wavelengths = wavelengths
options.n_rays = 4000
options.n_theta_bins = 20
options.lookuptable_angles = 100
options.depth_spacing = 1e-9
options.only_incidence_angle = False
options.nx = 4
options.ny = 4
options.bulk_profile = False
_, _, angle_vector = make_angle_vector(options.n_theta_bins,
options.phi_symmetry, options.c_azimuth)
for pol in ['s', 'p', 'u']:
options.project_name = 'rcwa_tmm_matrix_profiles_' + pol
options.pol = pol
SiN = material('Si3N4')()
GaAs = material('GaAs')()
GaInP = material('GaInP')(In=0.5)
Ag = material('Ag')()
Air = material('Air')()
Ta2O5 = material('TaOx1')() # Ta2O5 (SOPRA database)
MgF2 = material('MgF2')() # MgF2 (SOPRA database)
front_materials = [Layer(100e-9, MgF2), Layer(50e-9, GaInP), Layer(100e-9, Ta2O5), Layer(200e-9, GaAs)]
back_materials = [Layer(50E-9, GaInP)]
prof_layers = np.arange(len(front_materials)) + 1
## pure TMM with incoherent thick layer
all_layers = front_materials + [Layer(bulkthick, SiN)] + back_materials
coh_list = len(front_materials) * ['c'] + ['i'] + ['c']
options.coherent = False
options.coherency_list = coh_list
OS_layers = tmm_structure(all_layers, incidence=Air,
transmission=Ag, no_back_reflection=False)
th_ind = np.random.randint(0, 4)
phi_in = np.random.uniform(0, np.pi)
options.theta_in = angle_vector[th_ind, 1]
options.phi_in = phi_in
TMM_res = OS_layers.calculate(options, profile=True, layers=[1, 2, 3, 4, 5, 6])
## TMM Matrix method
front_surf = Interface('TMM', layers=front_materials, name='TMM_f',
coherent=True, prof_layers=prof_layers)
back_surf = Interface('TMM', layers=back_materials, name='TMM_b',
coherent=True, prof_layers=[1])
bulk_Ge = BulkLayer(bulkthick, SiN, name='SiN_bulk') # bulk thickness in m
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_TMM_Matrix = calculate_RAT(SC, options)
results_per_pass = results_TMM_Matrix[1]
results_per_layer_front_TMM = np.sum(results_per_pass['a'][0], 0)
results_per_layer_back_TMM = np.sum(results_per_pass['a'][1], 0)[:,0]
assert np.all(results_TMM_Matrix[0]['A_interface'][0].data == np.sum(results_per_pass['a'][0], (0, 2)))
assert np.all(results_TMM_Matrix[0]['A_interface'][1].data == np.sum(results_per_pass['a'][1], (0,2)))
assert np.all((results_TMM_Matrix[0]['R'] + results_TMM_Matrix[0]['T'] + results_TMM_Matrix[0]['A_bulk'] + np.sum(
results_TMM_Matrix[0]['A_interface'], 0)) == approx(1, abs=0.01))
surf = planar_surface()
front_surf = Interface('RT_TMM', layers=front_materials, texture=surf, name='RT_TMM_f',
coherent=True, prof_layers=prof_layers)
back_surf = Interface('RT_TMM', layers=back_materials, texture=surf, name='RT_TMM_b',
coherent=True, prof_layers=[1])
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RT = calculate_RAT(SC, options)
results_per_pass = results_RT[1]
# only select absorbing layers, sum over passes
results_per_layer_front_RT = np.sum(results_per_pass['a'][0], 0)
# results_per_layer_back_RT = np.sum(results_per_pass['a'][1], 0)[:,0]
assert np.all(results_RT[0]['A_interface'][0].data == np.sum(results_per_pass['a'][0], (0, 2)))
assert np.all(results_RT[0]['A_interface'][1].data == np.sum(results_per_pass['a'][1], (0, 2)))
assert np.all((results_RT[0]['R'] + results_RT[0]['T'] + results_RT[0]['A_bulk'] + np.sum(
results_RT[0]['A_interface'], 0)) == approx(1, abs=0.01))
## RCWA Matrix
front_surf = Interface('RCWA', layers=front_materials, name='RCWA_f', d_vectors=((500, 0), (0, 500)),
rcwa_orders=2, prof_layers=prof_layers)
back_surf = Interface('RCWA', layers=back_materials, name='RCWA_b', d_vectors=((500, 0), (0, 500)),
rcwa_orders=2, prof_layers=[1])
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RCWA_Matrix = calculate_RAT(SC, options)
results_per_pass = results_RCWA_Matrix[1]
results_per_layer_front_RCWA = np.sum(results_per_pass['a'][0], 0)
results_per_layer_back_RCWA = np.sum(results_per_pass['a'][1], 0)[:,0]
assert np.all(results_RCWA_Matrix[0]['A_interface'][0] == np.sum(results_per_pass['a'][0], (0, 2)))
assert np.all(results_RCWA_Matrix[0]['A_interface'][1] == np.sum(results_per_pass['a'][1], (0, 2)))
assert np.all((results_RCWA_Matrix[0]['R'] + results_RCWA_Matrix[0]['T'] + results_RCWA_Matrix[0]['A_bulk'] + np.sum(
results_RCWA_Matrix[0]['A_interface'], 0)) == approx(1, abs=0.01))
results_per_layer_front_TMM_ref = TMM_res['A_per_layer'][:,:len(front_materials)]
results_per_layer_back_TMM_ref = TMM_res['A_per_layer'][:, -1]
c_i = results_per_layer_front_TMM_ref > 1e-2
assert results_per_layer_front_TMM[c_i] == approx(results_per_layer_front_TMM_ref[c_i], rel=0.05)
assert results_per_layer_front_RCWA[c_i] == approx(results_per_layer_front_TMM_ref[c_i], rel=0.05)
assert results_per_layer_front_RT[c_i] == approx(results_per_layer_front_TMM_ref[c_i], rel=0.8)
c_i = results_per_layer_back_TMM_ref > 1e-2
assert results_per_layer_back_TMM[c_i] == approx(results_per_layer_back_TMM_ref[c_i], rel=0.05)
assert results_per_layer_back_RCWA[c_i] == approx(results_per_layer_back_TMM_ref[c_i], rel=0.05)
@mark.skipif(sys.platform != "linux", reason="S4 (RCWA) only installed for tests under Linux")
def test_rcwa_tmm_matrix_profiles():
from solcore.structure import Layer
from solcore import material
# rayflare imports
from rayflare.textures.standard_rt_textures import planar_surface
from rayflare.structure import Interface, BulkLayer, Structure
from rayflare.matrix_formalism import process_structure, calculate_RAT
from rayflare.options import default_options
from rayflare.transfer_matrix_method import tmm_structure
from rayflare.angles import make_angle_vector
# Thickness of bulk Ge layer
bulkthick = 30e-9
wavelengths = np.linspace(640, 850, 6) * 1e-9
# set options
options = default_options()
options.wavelengths = wavelengths
options.n_rays = 4000
options.n_theta_bins = 20
options.lookuptable_angles = 100
options.parallel = True
options.c_azimuth = 0.25
options.depth_spacing = 1e-9
options.only_incidence_angle = False
options.nx = 4
options.ny = 4
_, _, angle_vector = make_angle_vector(options.n_theta_bins,
options.phi_symmetry, options.c_azimuth)
for pol in ['s', 'p', 'u']:
options.project_name = 'rcwa_tmm_matrix_profiles_' + pol
options.pol = pol
SiN = material('Si3N4')()
GaAs = material('GaAs')()
GaInP = material('GaInP')(In=0.5)
Ag = material('Ag')()
Air = material('Air')()
Ta2O5 = material('TaOx1')() # Ta2O5 (SOPRA database)
MgF2 = material('MgF2')() # MgF2 (SOPRA database)
front_materials = [Layer(100e-9, MgF2), Layer(50e-9, GaInP), Layer(100e-9, Ta2O5), Layer(200e-9, GaAs)]
back_materials = [Layer(50E-9, GaInP)]
prof_layers = np.arange(len(front_materials)) + 1
## pure TMM with incoherent thick layer
all_layers = front_materials + [Layer(bulkthick, SiN)] + back_materials
coh_list = len(front_materials) * ['c'] + ['i'] + ['c']
options.coherent = False
options.coherency_list = coh_list
OS_layers = tmm_structure(all_layers, incidence=Air,
transmission=Ag, no_back_reflection=False)
th_ind = np.random.randint(0, 4)
phi_in = np.random.uniform(0, np.pi)
options.theta_in = angle_vector[th_ind, 1]
options.phi_in = phi_in
# set up Solcore materials
TMM_res = OS_layers.calculate(options, profile=True, layers=[1, 2, 3, 4, 5, 6])
## TMM Matrix method
front_surf = Interface('TMM', layers=front_materials, name='TMM_f',
coherent=True, prof_layers=prof_layers)
back_surf = Interface('TMM', layers=back_materials, name='TMM_b',
coherent=True, prof_layers=[1])
bulk_Ge = BulkLayer(bulkthick, SiN, name='SiN_bulk') # bulk thickness in m
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_TMM_Matrix = calculate_RAT(SC, options)
profile = results_TMM_Matrix[2]
prof_plot_TMM = profile[0]
prof_plot_TMM_back = profile[1]
depths = np.linspace(0, len(prof_plot_TMM[0, :]) * options['depth_spacing'] * 1e9, len(prof_plot_TMM[0, :]))
integrated_A = np.trapz(prof_plot_TMM, depths, axis=1)
depths_back = np.linspace(0, len(prof_plot_TMM_back[0, :]) * options['depth_spacing'] * 1e9, len(prof_plot_TMM_back[0, :]))
integrated_A_back = np.trapz(prof_plot_TMM_back, depths_back, axis=1)
assert approx(integrated_A == results_TMM_Matrix[0]['A_interface'][0].data)
assert approx(integrated_A_back == results_TMM_Matrix[0]['A_interface'][1].data)
## RT_TMM Matrix method
surf = planar_surface() # [texture, flipped texture]
front_surf = Interface('RT_TMM', layers=front_materials, texture=surf, name='RT_TMM_f',
coherent=True, prof_layers=prof_layers)
back_surf = Interface('RT_TMM', layers=back_materials, texture=surf, name='RT_TMM_b',
coherent=True, prof_layers=[1])
SC = Structure([front_surf, bulk_Ge, back_surf], incidence=Air, transmission=Ag)
process_structure(SC, options)
results_RT = calculate_RAT(SC, options)
profile = results_RT[2]
prof_plot_RT = profile[0]
prof_plot_RT_back = profile[1]
depths = np.linspace(0, len(prof_plot_RT[0, :]) * options['depth_spacing'] * 1e9, len(prof_plot_RT[0, :]))
integrated_A = np.trapz(prof_plot_RT, depths, axis=1)
depths_back = np.linspace(0, len(prof_plot_RT_back[0, :]) * options['depth_spacing'] * 1e9,
len(prof_plot_RT_back[0, :]))