@@ -27,13 +27,52 @@ def reinitialization(ph, scattering_types):
2727 """Re-thermalize phonon if it comes back to the hot side"""
2828 x , y , _ = move (ph , cf .timestep )
2929
30- # If phonon returns to the hot side, generate it again:
31- if ((cf .hot_side_position_bottom and y < 0 ) or
32- (cf .hot_side_position_top and y > cf .length ) or
33- (cf .hot_side_position_right and x > cf .width / 2 ) or
34- (cf .hot_side_position_left and x < - cf .width / 2 )):
35- ph .assign_angles ()
30+ # Bottom sidewall:
31+ if cf .hot_side_position_bottom and y < 0 :
3632 scattering_types .hot_side = Scattering .DIFFUSE
33+ attempt = 0
34+ while attempt < 10 :
35+ attempt += 1
36+
37+ # Lambert cosine distribution:
38+ ph .theta = asin (2 * random () - 1 )
39+ ph .phi = asin ((asin (2 * random () - 1 ))/ (pi / 2 ))
40+
41+ # Accept the angles only if they do not immediately cause new scattering:
42+ if no_new_scattering (ph ):
43+ break
44+
45+ # Top sidewall:
46+ if cf .hot_side_position_top and y > cf .length :
47+ scattering_types .hot_side = Scattering .DIFFUSE
48+ attempt = 0
49+ while attempt < 10 :
50+ attempt += 1
51+
52+ # Lambert cosine distribution:
53+ rand_sign = sign ((2 * random () - 1 ))
54+ ph .theta = rand_sign * pi / 2 + rand_sign * acos (random ())
55+ ph .phi = asin ((asin (2 * random () - 1 ))/ (pi / 2 ))
56+
57+ # Accept the angles only if they do not immediately cause new scattering:
58+ if no_new_scattering (ph ):
59+ break
60+
61+ # Right and left sidewalls:
62+ if ((cf .hot_side_position_right and x > cf .width / 2 ) or
63+ (cf .hot_side_position_left and x < - cf .width / 2 )):
64+ scattering_types .hot_side = Scattering .DIFFUSE
65+ attempt = 0
66+ while attempt < 10 :
67+ attempt += 1
68+
69+ # Lambert cosine distribution:
70+ ph .theta = - sign (x )* pi / 2 + asin (2 * random () - 1 )
71+ ph .phi = asin ((asin (2 * random () - 1 ))/ (pi / 2 ))
72+
73+ # Accept the angles if they do not cause new scattering:
74+ if no_new_scattering (ph ):
75+ break
3776
3877
3978def top_parabola_scattering (ph , scattering_types ):
@@ -364,7 +403,9 @@ def no_new_scattering(ph):
364403 """Check if new angles do not immediately lead to new top/bottom or sidewall scattering.
365404 This is necessary to prevent phonons leaving the structure boundaries."""
366405 x , y , z = move (ph , cf .timestep )
367- return True if (abs (z ) < cf .thickness / 2 and abs (x ) < cf .width / 2 and y > 0 ) else False
406+ return (abs (z ) < cf .thickness / 2 and
407+ abs (x ) < cf .width / 2 and
408+ cf .length > y > 0 )
368409
369410
370411def scattering_on_right_sidewall (ph , scattering_types ):
0 commit comments