Physics/Ellipsometry/VASE/Temperature.pm

filter: Statementstmt 98.9% 94 / 95 Branchbran 85.2% 29 / 34 Conditioncond 68.2% 28 / 41 MC/DCmcdc 35.0% 7 / 20 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 84.3% 173 / 205 CC 38 SCAR 23.2
CC
38
Cov
89%
temperature_drude
16.9
temperature_bandgap
12.4
_validate_number
6.5
CRAP 10.2
« Physics/Ellipsometry/VASE/Anisotropy.pm ↑ Summary Physics/Ellipsometry/VASE/MagnetoOptic.pm »
1 package Physics::Ellipsometry::VASE::Temperature;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use PDL::NiceSlice;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use PDL::Constants qw(PI);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our @EXPORT_OK = qw(temperature_bandgap temperature_drude temperature_thermo_optic);
11  
12 1 our $VERSION = '1.04';
13  
14 =encoding utf8
15  
16 =head1 NAME
17  
18 Physics::Ellipsometry::VASE::Temperature - Temperature-dependent optical
19 models for spectroscopic ellipsometry
20  
21 =head1 SYNOPSIS
22  
23 use PDL;
24 use Physics::Ellipsometry::VASE::Temperature qw(
25 temperature_bandgap temperature_drude temperature_thermo_optic
26 );
27  
28 # Track bandgap shift with temperature
29 my $Eg_300K = temperature_bandgap(1.17, 300,
30 model => 'varshni', alpha => 4.73e-4, beta => 636);
31 my $Eg_600K = temperature_bandgap(1.17, 600,
32 model => 'varshni', alpha => 4.73e-4, beta => 636);
33  
34 # Metal optical constants at elevated temperature
35 my $lambda = sequence(100) * 10 + 400;
36 my ($n, $k) = temperature_drude($lambda, 500,
37 omega_p0 => 9.0, gamma_0 => 0.02, gamma_ep => 1e-4);
38  
39 =head1 DESCRIPTION
40  
41 Temperature affects optical properties through several mechanisms:
42  
43 =over 4
44  
45 =item B<Bandgap narrowing> - Thermal expansion and electron-phonon
46 interactions reduce the semiconductor bandgap as temperature increases.
47 This red-shifts absorption edges.
48  
49 =item B<Increased scattering> - In metals and TCOs, electron-phonon
50 scattering increases with temperature, broadening the Drude response
51 and increasing resistivity.
52  
53 =item B<Thermo-optic effect> - In transparent materials, the refractive
54 index changes linearly with temperature (dn/dT), typically
55 10^-6 to 10^-4 per Kelvin.
56  
57 =item B<Carrier density changes> - In semiconductors, thermal excitation
58 increases free carrier density exponentially with temperature.
59  
60 =back
61  
62 This module provides functions to incorporate these effects into
63 ellipsometric models, enabling in-situ analysis at non-ambient
64 temperatures (e.g., CVD monitoring, annealing studies).
65  
66 =head1 FUNCTIONS
67  
68 =head2 temperature_bandgap
69  
70 my $Eg_T = temperature_bandgap($Eg0, $T,
71 model => 'varshni',
72 alpha => $alpha, beta => $beta);
73  
74 Calculates the temperature-dependent optical bandgap using either:
75  
76 B<Varshni model> (1967):
77  
78 Eg(T) = Eg(0) - alpha * T^2 / (T + beta)
79  
80 B<Bose-Einstein model:>
81  
82 Eg(T) = Eg(0) - 2*aB / (exp(Theta/T) - 1)
83  
84 B<Parameters:>
85  
86 =over 4
87  
88 =item C<$Eg0> - bandgap at T=0 K [eV]
89  
90 =item C<$T> - temperature [K]
91  
92 =item C<model> - 'varshni' (default) or 'bose_einstein'
93  
94 =item C<alpha> - Varshni coefficient [eV/K] (Si: 4.73e-4)
95  
96 =item C<beta> - Varshni parameter [K] (Si: 636)
97  
98 =item C<aB> - Bose-Einstein coupling [eV]
99  
100 =item C<Theta> - characteristic phonon temperature [K]
101  
102 =back
103  
104 # Silicon bandgap at various temperatures
105 for my $T (100, 200, 300, 400, 500) {
106 my $Eg = temperature_bandgap(1.166, $T,
107 model => 'varshni', alpha => 4.73e-4, beta => 636);
108 printf "Si Eg(%dK) = %.4f eV\n", $T, $Eg;
109 }
110  
111 =head2 temperature_drude
112  
113 my ($n, $k) = temperature_drude($lambda_nm, $T, %params);
114  
115 Computes the Drude dielectric function with temperature-dependent
116 scattering rate and optional T-dependent carrier density:
117  
118 Gamma(T) = Gamma_0 + Gamma_ep * T + Gamma_ee * T^2
119  
120 where Gamma_0 is residual (impurity) scattering, Gamma_ep is
121 electron-phonon, and Gamma_ee is electron-electron.
122  
123 B<Parameters:>
124  
125 =over 4
126  
127 =item C<$T> - temperature [K]
128  
129 =item C<eps_inf> - high-frequency dielectric constant
130  
131 =item C<omega_p0> - plasma frequency at reference T [eV]
132  
133 =item C<gamma_0> - residual scattering rate [eV]
134  
135 =item C<gamma_ep> - electron-phonon coefficient [eV/K]
136  
137 =item C<gamma_ee> - electron-electron coefficient [eV/K^2]
138  
139 =item C<T_ref> - reference temperature [K] (default 300)
140  
141 =item C<n_exp> - carrier density temperature exponent (0 for metals)
142  
143 =item C<activation_energy> - optional carrier activation energy [eV]. When
144 non-zero, the carrier density is normalized to C<T_ref> and follows
145  
146 n(T) / n(T_ref) = (T/T_ref)^n_exp
147 * exp[-Ea/(2*kB) * (1/T - 1/T_ref)]
148  
149 This is useful for doped semiconductors. The default is zero, preserving the
150 metal-like power-law model.
151  
152 =back
153  
154 # Gold optical constants at 300K vs 600K
155 my $lambda = sequence(200) * 5 + 400;
156 my ($n_300, $k_300) = temperature_drude($lambda, 300,
157 eps_inf => 6.9, omega_p0 => 9.03,
158 gamma_0 => 0.02, gamma_ep => 7e-5);
159 my ($n_600, $k_600) = temperature_drude($lambda, 600,
160 eps_inf => 6.9, omega_p0 => 9.03,
161 gamma_0 => 0.02, gamma_ep => 7e-5);
162  
163 =head2 temperature_thermo_optic
164  
165 my $n_T = temperature_thermo_optic($n_ref, $T,
166 T_ref => 300,
167 dndt => 1e-5);
168  
169 Simple polynomial model for the temperature-dependent refractive index
170 in transparent materials:
171  
172 n(T) = n(T0) + (dn/dT)*(T - T0) + (d²n/dT²)/2 * (T - T0)²
173  
174 B<Typical dn/dT values:>
175  
176 Fused silica: +1.0e-5 /K
177 BK7 glass: +3.0e-6 /K
178 Silicon: +1.8e-4 /K
179 Water: -1.0e-4 /K (negative!)
180  
181 # SiO2 thermal lens calculation
182 my ($n_ref, $k_ref) = cauchy_nk(pdl(633), 1.4580, 0.003, 0);
183 my $n_hot = temperature_thermo_optic($n_ref, 400, T_ref=>300,
184 dndt => 1.0e-5);
185  
186 =head1 SEE ALSO
187  
188 L<Physics::Ellipsometry::VASE::Dispersion>,
189 L<Physics::Ellipsometry::VASE>
190  
191 Y.P. Varshni, "Temperature dependence of the energy gap in semiconductors",
192 I<Physica> B<34>, 149 (1967).
193  
194 =cut
195  
196 # Temperature-dependent bandgap shift
197 # Models how the optical gap changes with temperature using:
198 # - Varshni: Eg(T) = Eg(0) - alpha*T^2 / (T + beta)
199 # - Bose-Einstein: Eg(T) = Eg(0) - 2*aB / (exp(Theta/T) - 1)
200 #
201 # $Eg0: bandgap at T=0 [eV]
202 # $T: temperature [K]
203 # $model: 'varshni' or 'bose_einstein'
204 # Returns: Eg(T) in eV
205 6 ▶sub temperature_bandgap {
Subroutine temperature_bandgap: called CC=12 SCAR=25.2
Pod documented
206 6 my ($Eg0, $T, %params) = @_;
207 6 _validate_number($Eg0, 'Eg0');
208 6 _validate_temperature($T, allow_zero => 1);
209 5 ▶ my $model = $params{model} // 'varshni';
Condition50%1/2
$params{"model"} // "varshni"
l!l
50
MC/DC0%0/1
$params{"model"} // "varshni"
$params{"model"}
Truth table50%1/2
A
A= $params{"model"}
Aresult
11
00
210  
211 5 ▶ if ($model eq 'varshni') {
Branch: 2 branches
BranchTrueFalseTotal
if ($model eq 'varshni') { } 2 3 5
elsif ($model eq 'bose_einstein') { } 2 1 3
212 2 ▶ my $alpha = $params{alpha} // 5.5e-4; # eV/K (Si: 4.73e-4)
Condition100%2/2
$params{"alpha"} // "0.00055"
l!l
11
MC/DC100%1/1
$params{"alpha"} // "0.00055"
$params{"alpha"}
Truth table100%2/2
A
A= $params{"alpha"}
Aresult
11
00
213 2 ▶ my $beta = $params{beta} // 230; # K (Si: 636)
Condition50%1/2
$params{"beta"} // 230
l!l
20
MC/DC0%0/1
$params{"beta"} // 230
$params{"beta"}
Truth table50%1/2
A
A= $params{"beta"}
Aresult
11
00
214 2 _validate_number($alpha, 'alpha');
215 2 _validate_number($beta, 'beta');
216 2 ▶ return $Eg0 if $T == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $T == 0 0 2 2
217 2 ▶ die "T + beta must not be zero" if $T + $beta == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $T + $beta == 0 1 1 2
218 1 return $Eg0 - $alpha * $T**2 / ($T + $beta);
219 }
220 elsif ($model eq 'bose_einstein') {
221 2 ▶ my $aB = $params{aB} // 0.05; # coupling strength [eV]
Condition50%1/2
$params{"aB"} // "0.05"
l!l
02
MC/DC0%0/1
$params{"aB"} // "0.05"
$params{"aB"}
Truth table50%1/2
A
A= $params{"aB"}
Aresult
11
00
222 2 ▶ my $Theta = $params{Theta} // 300; # characteristic temperature [K]
Condition100%2/2
$params{"Theta"} // 300
l!l
11
MC/DC100%1/1
$params{"Theta"} // 300
$params{"Theta"}
Truth table100%2/2
A
A= $params{"Theta"}
Aresult
11
00
223 2 _validate_number($aB, 'aB');
224 2 _validate_number($Theta, 'Theta');
225 2 ▶ die "Theta must be greater than zero" if $Theta <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $Theta <= 0 1 1 2
226 1 ▶ return $Eg0 if $T == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $T == 0 1 0 1
227 0 return $Eg0 - 2 * $aB / (exp($Theta / $T) - 1);
228 }
229 else {
230 1 die "Unknown bandgap model: $model (use 'varshni' or 'bose_einstein')";
231 }
232 }
233  
234 # Temperature-dependent Drude model
235 # Accounts for thermal changes in carrier density and scattering rate:
236 # - Carrier density: n(T) = n0 * (T/T0)^p * exp(-Ea/(2kT)) for semiconductors
237 # or n(T) = n0 for metals
238 # - Scattering rate: Gamma(T) = Gamma0 + Gamma_ee*T^2 + Gamma_ep*T
239 # (electron-electron + electron-phonon contributions)
240 #
241 # Returns (n, k) piddles for the given wavelength range
242 10 ▶sub temperature_drude {
Subroutine temperature_drude: called CC=16 SCAR=28.3
Pod documented
243 10 my ($lambda_nm, $T, %params) = @_;
244 10 _validate_temperature($T);
245 9 my $lambda = pdl($lambda_nm);
246 9 ▶ die "lambda_nm must contain at least one wavelength"
Branch: 1 branch
BranchTrueFalseTotal
unless $lambda->nelem 0 9 9
247 unless $lambda->nelem;
248 9 ▶ die "wavelength values must be finite"
Branch: 1 branch
BranchTrueFalseTotal
unless all($lambda->isfinite) 1 8 9
249 unless all($lambda->isfinite);
250 8 ▶ die "wavelength values must be greater than zero"
Branch: 1 branch
BranchTrueFalseTotal
if any($lambda <= 0) 1 7 8
251 if any($lambda <= 0);
252  
253 7 ▶ my $eps_inf = $params{eps_inf} // 1.0;
Condition50%1/2
$params{"eps_inf"} // 1
l!l
70
MC/DC0%0/1
$params{"eps_inf"} // 1
$params{"eps_inf"}
Truth table50%1/2
A
A= $params{"eps_inf"}
Aresult
11
00
254 7 ▶ my $omega_p0 = $params{omega_p0} // 9.0; # plasma freq at ref T [eV]
Condition50%1/2
$params{"omega_p0"} // 9
l!l
70
MC/DC0%0/1
$params{"omega_p0"} // 9
$params{"omega_p0"}
Truth table50%1/2
A
A= $params{"omega_p0"}
Aresult
11
00
255 7 ▶ my $gamma_0 = $params{gamma_0} // 0.02; # residual scattering [eV]
Condition50%1/2
$params{"gamma_0"} // "0.02"
l!l
70
MC/DC0%0/1
$params{"gamma_0"} // "0.02"
$params{"gamma_0"}
Truth table50%1/2
A
A= $params{"gamma_0"}
Aresult
11
00
256 7 ▶ my $gamma_ep = $params{gamma_ep} // 1e-4; # e-phonon coeff [eV/K]
Condition50%1/2
$params{"gamma_ep"} // "0.0001"
l!l
70
MC/DC0%0/1
$params{"gamma_ep"} // "0.0001"
$params{"gamma_ep"}
Truth table50%1/2
A
A= $params{"gamma_ep"}
Aresult
11
00
257 7 ▶ my $gamma_ee = $params{gamma_ee} // 1e-7; # e-electron coeff [eV/K^2]
Condition50%1/2
$params{"gamma_ee"} // "1e-07"
l!l
70
MC/DC0%0/1
$params{"gamma_ee"} // "1e-07"
$params{"gamma_ee"}
Truth table50%1/2
A
A= $params{"gamma_ee"}
Aresult
11
00
258 7 ▶ my $T_ref = $params{T_ref} // 300; # reference temperature [K]
Condition50%1/2
$params{"T_ref"} // 300
l!l
70
MC/DC0%0/1
$params{"T_ref"} // 300
$params{"T_ref"}
Truth table50%1/2
A
A= $params{"T_ref"}
Aresult
11
00
259 7 ▶ my $n_exp = $params{n_exp} // 0; # carrier density T-exponent
Condition50%1/2
$params{"n_exp"} // 0
l!l
70
MC/DC0%0/1
$params{"n_exp"} // 0
$params{"n_exp"}
Truth table50%1/2
A
A= $params{"n_exp"}
Aresult
11
00
260 7 ▶ my $Ea = $params{activation_energy} // 0; # carrier activation [eV]
Condition100%2/2
$params{"activation_energy"} // 0
l!l
34
MC/DC100%1/1
$params{"activation_energy"} // 0
$params{"activation_energy"}
Truth table100%2/2
A
A= $params{"activation_energy"}
Aresult
11
00
261  
262 7 _validate_temperature($T_ref);
263 7 for my $parameter (
264 [ $eps_inf, 'eps_inf' ],
265 [ $omega_p0, 'omega_p0' ],
266 [ $gamma_0, 'gamma_0' ],
267 [ $gamma_ep, 'gamma_ep' ],
268 [ $gamma_ee, 'gamma_ee' ],
269 [ $n_exp, 'n_exp' ],
270 [ $Ea, 'activation_energy' ],
271 ) {
272 48 _validate_number(@$parameter);
273 }
274 6 ▶ die "activation_energy must be non-negative" if $Ea < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $Ea < 0 1 5 6
275  
276 # Temperature-dependent scattering
277 5 my $gamma_T = $gamma_0 + $gamma_ep * $T + $gamma_ee * $T**2;
278 5 _validate_number($gamma_T, 'temperature-dependent scattering rate');
279  
280 # Temperature-dependent plasma frequency
281 # omega_p^2 ∝ n_carrier/m* ; n_carrier may depend on T
282 5 my $carrier_ratio = ($T / $T_ref)**$n_exp;
283 5 ▶ if ($Ea != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Ea != 0) 2 3 5
284 2 my $k_boltzmann = 8.617333262e-5; # eV/K
285 2 $carrier_ratio *= exp(
286 -$Ea / (2 * $k_boltzmann) * (1 / $T - 1 / $T_ref)
287 );
288 }
289 5 _validate_number($carrier_ratio, 'carrier density ratio');
290 5 ▶ die "carrier density ratio must be non-negative" if $carrier_ratio < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $carrier_ratio < 0 0 5 5
291 5 my $omega_p_T = $omega_p0 * sqrt($carrier_ratio);
292  
293 # Compute dielectric function
294 5 my $E = 1239.842 / $lambda;
295 5 my $eps = $eps_inf - $omega_p_T**2 / ($E**2 + i() * $E * $gamma_T);
296 5 my $N = sqrt($eps);
297 5 return ($N->re, $N->im->abs);
298 }
299  
300 # Thermo-optic coefficient model
301 # n(T) = n(T0) + (dn/dT) * (T - T0) + (d2n/dT2)/2 * (T - T0)^2
302 # Simple polynomial expansion for temperature-dependent refractive index
303 # Works for transparent materials (glasses, crystals) far from resonances
304 #
305 # $n_ref: refractive index at reference temperature (PDL)
306 # $T: temperature [K]
307 # $T_ref: reference temperature [K]
308 # $dndt: first-order thermo-optic coefficient [1/K]
309 # $d2ndt2: second-order coefficient [1/K^2] (optional)
310 3 ▶sub temperature_thermo_optic {
Subroutine temperature_thermo_optic: called CC=4 SCAR=13.9
Pod documented
311 3 my ($n_ref, $T, %params) = @_;
312 3 _validate_temperature($T, allow_zero => 1);
313 3 ▶ my $T_ref = $params{T_ref} // 300;
Condition100%2/2
$params{"T_ref"} // 300
l!l
21
MC/DC100%1/1
$params{"T_ref"} // 300
$params{"T_ref"}
Truth table100%2/2
A
A= $params{"T_ref"}
Aresult
11
00
314 3 ▶ my $dndt = $params{dndt} // 1e-5; # typical for glass
Condition100%2/2
$params{"dndt"} // "1e-05"
l!l
21
MC/DC100%1/1
$params{"dndt"} // "1e-05"
$params{"dndt"}
Truth table100%2/2
A
A= $params{"dndt"}
Aresult
11
00
315 3 ▶ my $d2ndt2 = $params{d2ndt2} // 0;
Condition100%2/2
$params{"d2ndt2"} // 0
l!l
12
MC/DC100%1/1
$params{"d2ndt2"} // 0
$params{"d2ndt2"}
Truth table100%2/2
A
A= $params{"d2ndt2"}
Aresult
11
00
316  
317 3 _validate_temperature($T_ref, allow_zero => 1);
318 2 _validate_number($dndt, 'dndt');
319 1 _validate_number($d2ndt2, 'd2ndt2');
320  
321 1 my $dT = $T - $T_ref;
322 1 my $n_T = $n_ref + $dndt * $dT + 0.5 * $d2ndt2 * $dT**2;
323  
324 1 return $n_T;
325 }
326  
327 29 ▶sub _validate_temperature {
Subroutine _validate_temperature: called CC=4 SCAR=13.9
328 29 my ($temperature, %opts) = @_;
329 29 _validate_number($temperature, 'temperature');
330 29 ▶ my $minimum_ok = $opts{allow_zero} ? $temperature >= 0 : $temperature > 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts{'allow_zero'} ? : 12 17 29
331 29 ▶ die "temperature must be " . ($opts{allow_zero} ? 'non-negative' : 'greater than zero')
Branch: 2 branches
BranchTrueFalseTotal
unless $minimum_ok 3 26 29
$opts{'allow_zero'} ? : 2 1 3
332 unless $minimum_ok;
333 26 return $temperature;
334 }
335  
336 104 ▶sub _validate_number {
Subroutine _validate_number: called CC=6 SCAR=18.7
337 104 my ($value, $name) = @_;
338 104 ▶ my $display = defined($value) ? "$value" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $value ? : 104 0 104
339 104 ▶ die "$name must be a finite number"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and &looks_like_number($value) and $value == $value and not $display =~ /(?:inf|nan)/i 2 102 104
Condition66%6/9
defined $value and &looks_like_number($value) and $value == $value and not $display =~ /(?:inf|nan)/i
!ll&&!rl&&r
20102
defined $value and &looks_like_number($value) and $value == $value
!ll&&!rl&&r
20102
defined $value and &looks_like_number($value)
!ll&&!rl&&r
02102
MC/DC25%1/4
defined $value and &looks_like_number($value) and $value == $value and not $display =~ /(?:inf|nan)/i
defined $value &looks_like_number($value) $value == $value not $display =~ /(?:inf|nan)/i
Truth table40%2/5
A and B and C and not(D)
A= defined $valueB= &looks_like_number($value)C= $value == $valueD= not $display =~ /(?:inf|nan)/i
ABCDresult
0XXX0
10XX0
110X0
11100
11111
340 unless defined($value)
341 && looks_like_number($value)
342 && $value == $value
343 && $display !~ /(?:inf|nan)/i;
344 102 return $value;
345 }
346  
347 1 1;
« Physics/Ellipsometry/VASE/Anisotropy.pm ↑ Summary Physics/Ellipsometry/VASE/MagnetoOptic.pm »