Skip to content

Commit 5df6aa9

Browse files
committed
Improving hot side behaviour
1 parent 8aecea7 commit 5df6aa9

5 files changed

Lines changed: 112 additions & 1956 deletions

File tree

freepaths/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import freepaths.main_tracing
66
import freepaths.main_mfp_sampling
77

8-
__version__ = "1.3"
8+
__version__ = "1.4"
99

1010
# Parse user arguments:
1111
parser = argparse.ArgumentParser(

freepaths/config.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,29 @@ def check_parameter_validity(self):
179179
if self.output_path_animation and self.number_of_timesteps > 5000:
180180
print("WARNING: NUMBER_OF_TIMESTEPS is rather large for animation.\n")
181181

182-
if self.cold_side_position_top and self.include_top_sidewall:
183-
print("WARNING: Top side is assigned both as cold side and a wall.\n")
182+
if (self.cold_side_position_top and self.include_top_sidewall or
183+
self.hot_side_position_top and self.include_top_sidewall or
184+
self.cold_side_position_top and self.hot_side_position_top):
185+
print("ERROR: Top side is assigned multiple functions.\n")
186+
sys.exit()
184187

185-
if self.cold_side_position_bottom and self.include_bottom_sidewall:
186-
print("WARNING: Bottom side is assigned both as cold side and a wall.\n")
188+
if (self.cold_side_position_bottom and self.include_bottom_sidewall or
189+
self.hot_side_position_bottom and self.include_bottom_sidewall or
190+
self.cold_side_position_bottom and self.hot_side_position_bottom):
191+
print("ERROR: Bottom side is assigned multiple functions.\n")
192+
sys.exit()
187193

188-
if self.cold_side_position_right and self.include_right_sidewall:
189-
print("WARNING: Right side is assigned both as cold side and a wall.\n")
194+
if (self.cold_side_position_right and self.include_right_sidewall or
195+
self.hot_side_position_right and self.include_right_sidewall or
196+
self.cold_side_position_right and self.hot_side_position_right):
197+
print("ERROR: Right side is assigned multiple functions.\n")
198+
sys.exit()
190199

191-
if self.cold_side_position_left and self.include_left_sidewall:
192-
print("WARNING: Left side is assigned both as cold side and a wall.\n")
200+
if (self.cold_side_position_left and self.include_left_sidewall or
201+
self.hot_side_position_left and self.include_left_sidewall or
202+
self.cold_side_position_left and self.hot_side_position_left):
203+
print("ERROR: Left side is assigned multiple functions.\n")
204+
sys.exit()
193205

194206

195207
def check_depricated_parameters(self):

freepaths/scattering.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3978
def 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

370411
def scattering_on_right_sidewall(ph, scattering_types):

schemes/angle_distributions.svg

Lines changed: 32 additions & 31 deletions
Loading

0 commit comments

Comments
 (0)