PLaSK library
Loading...
Searching...
No Matches
temp.py
Go to the documentation of this file.
1
#!/usr/bin/env python3
2
# This file is part of PLaSK (https://plask.app) by Photonics Group at TUL
3
# Copyright (c) 2022 Lodz University of Technology
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, version 3.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
13
14
import
unittest
15
16
from
numpy
import
*
17
import
matplotlib
18
19
from
plask
import
*
20
from
plask
import
material, geometry, mesh
21
from
optical.modal
import
Fourier2D
22
23
24
class
TempGradientTest
(
unittest.TestCase
):
25
26
def
setUp
(self):
27
plask.config.axes
=
'xy'
28
self.
manager
=
plask.Manager
()
29
self.
manager
.load(
'''
30
<plask>
31
<materials>
32
<material name="termic" base="semiconductor">
33
<nr>T</nr>
34
</material>
35
</materials>
36
<geometry>
37
<cartesian2d axes="xy" name="main" left="mirror" right="extend" bottom="GaAs">
38
<stack name="layers">
39
<rectangle dx="2" dy="18" material="termic"/>
40
<rectangle dx="2" dy="2" material="termic"/>
41
<zero/>
42
</stack>
43
</cartesian2d>
44
</geometry>
45
<grids>
46
<mesh name="term" type="rectangular2d">
47
<axis0>1</axis0>
48
<axis1 start="0" stop="20" num="2001"/>
49
</mesh>
50
</grids>
51
<solvers>
52
<optical name="fourier" solver="Fourier2D">
53
<geometry ref="main"/>
54
<expansion temp-diff="1.0" temp-dist="0.1"/>
55
</optical>
56
</solvers>
57
</plask>'''
)
58
self.
solver
= self.
manager
.
solvers.fourier
59
self.
solver
.wavelength = 1000.
60
self.
temp
=
Data
(300. + 4. /
linspace
(8., 1.,
len
(self.
manager
.
msg.term.axis1
)), self.
manager
.
msg.term
)
61
self.
solver
.inTemperature = self.
temp
62
63
64
def
testLayers
(self):
65
stack = list(self.
solver
.stack)
66
vaxis = self.
solver
.layer_edges
67
centers = self.
solver
.layer_centers
68
self.assertEqual(stack, [0, 1, 3, 4, 5, 2])
69
self.assertEqual(
str
(vaxis),
'[0, 15.45, 18.35, 19.6, 20]'
)
70
if
__name__ ==
'__main__'
:
71
temp = self.
temp
.
interpolate
(
mesh.Rectangular2D
([0.5], vaxis),
'linear'
)
72
for
x
in
mesh.Rectangular2D.SimpleGenerator
()(self.
solver
.geometry).axis1:
73
axvline
(x, color=
'0.5'
, lw=0.5)
74
print(stack)
75
print(list(vaxis))
76
cmap =
matplotlib.cm.get_cmap
()
77
f = 1. / (
len
(set(stack))-1)
78
axvspan
(-2., vaxis[0], color=
cmap
(f*stack[0]), alpha=0.5)
79
for
i,c
in
enumerate
(stack[1:-1]):
80
axvspan
(vaxis[i], vaxis[i+1], color=
cmap
(f*c), alpha=0.5)
81
axvspan
(vaxis[-1], 22., color=
cmap
(f*stack[-1]), alpha=0.5)
82
plot
(centers, self.
temp
.
interpolate
(
mesh.Rectangular2D
([0.5], centers),
'linear'
),
'r.'
)
83
for
v
in
vaxis:
84
axvline
(v, color=
'k'
, lw=0.5)
85
for
t
in
temp:
86
axhline
(t, color=
'k'
, lw=0.5, alpha=0.5)
87
plot_profile
(self.
temp
, color=
'r'
)
88
xlim
(-1., 21.)
89
90
if
__name__ ==
'__main__'
:
91
test =
unittest.main
(exit=
False
)
92
show
()
93
sys.exit
(
not
test.result.wasSuccessful
())
solvers
optical
modal
tests
temp.py
Generated by
1.9.8