Physics/Ellipsometry/VASE/EMA.pm untested

filter: Statementstmt 0.0% 0 / 45 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 67 CC 2 SCAR 10.0
CC
2
Cov
0%
ema_bruggeman
6.0
ema_linear
2.0
ema_maxwell_garnett
2.0
CRAP 2.7
1 package Physics::Ellipsometry::VASE::EMA;
2 use strict;
3 use warnings;
4 use PDL;
5 use PDL::NiceSlice;
6 use Exporter 'import';
7  
8 our @EXPORT_OK = qw(ema_linear ema_bruggeman ema_maxwell_garnett ema_looyenga);
9  
10 our $VERSION = '1.04';
11  
12 =encoding utf8
13  
14 =head1 NAME
15  
16 Physics::Ellipsometry::VASE::EMA - Effective Medium Approximation mixing
17 models for composite thin films
18  
19 =head1 SYNOPSIS
20  
21 use PDL;
22 use Physics::Ellipsometry::VASE::EMA qw(ema_linear ema_bruggeman
23 ema_maxwell_garnett ema_looyenga);
24 use Physics::Ellipsometry::VASE::Dispersion qw(cauchy_nk);
25  
26 my $lambda = sequence(500) * 2 + 300; # 300–1298 nm
27  
28 # Dielectric functions of two constituent materials
29 my ($n_a, $k_a) = cauchy_nk($lambda, 1.46, 0.003, 0.0); # SiO2
30 my ($n_b, $k_b) = (ones($lambda), zeroes($lambda)); # void (air)
31  
32 my $eps_a = ($n_a + i() * $k_a) ** 2;
33 my $eps_b = ($n_b + i() * $k_b) ** 2;
34  
35 # 30% porosity via Bruggeman mixing
36 my $eps_eff = ema_bruggeman($eps_a, $eps_b, 0.30);
37 my $N_eff = sqrt($eps_eff);
38 my $n_eff = $N_eff->re;
39 my $k_eff = $N_eff->im->abs;
40  
41 printf "n(500 nm) = %.3f (bulk SiO2 ≈ 1.46)\n",
42 $n_eff->at(100);
43  
44 =head1 DESCRIPTION
45  
46 Many thin films encountered in ellipsometry are not homogeneous
47 single-phase materials. Surface roughness, porosity, inter-diffusion
48 layers, nano-composites, and graded interfaces are all cases where
49 the optical response arises from a B<mixture> of two (or more)
50 constituent materials at a scale smaller than the wavelength of light.
51  
52 B<Effective Medium Approximation> (EMA) theories provide the dielectric
53 function of such a composite given the dielectric functions of the
54 constituents and their volume fractions. The choice of EMA model
55 depends on the microstructure:
56  
57 =over 4
58  
59 =item *
60  
61 B<Linear> — simplest volume-weighted average; reasonable when the
62 constituents have similar dielectric functions.
63  
64 =item *
65  
66 B<Bruggeman> — symmetric in both constituents; no distinction between
67 host and inclusion. Best for random mixtures, porous films, and
68 surface roughness layers.
69  
70 =item *
71  
72 B<Maxwell-Garnett> — asymmetric; treats one material as isolated
73 spherical inclusions in a continuous host matrix. Best when the
74 volume fraction of the inclusion is small (< 30%).
75  
76 =back
77  
78 All three functions operate on the B<dielectric function> ε = N²
79 (not on n and k directly), because the mixing rules are derived in
80 terms of ε.
81  
82 =head2 Surface roughness modelling
83  
84 A common use is modelling surface roughness as a 50/50 Bruggeman mix
85 of the underlying film material and void:
86  
87 my $eps_rough = ema_bruggeman($eps_film, $eps_void, 0.50);
88  
89 This roughness layer is then included in the TMM stack with a
90 thickness on the order of the RMS roughness.
91  
92 =head1 FUNCTIONS
93  
94 =head2 ema_linear
95  
96 my $eps_eff = ema_linear($eps_a, $eps_b, $vf);
97  
98 B<Linear (volume-weighted) mixing>:
99  
100 ε_eff = (1 − f) · ε_a + f · ε_b
101  
102 where C<$vf> (f) is the volume fraction of material B. This is the
103 simplest mixing rule and does not account for local-field effects.
104 It is exact when the two phases form a laminar (layered) structure
105 with the electric field parallel to the layers.
106  
107 # 20% TiO2 in SiO2 matrix (linear blend)
108 my $eps_mix = ema_linear($eps_sio2, $eps_tio2, 0.20);
109  
110 =head2 ema_bruggeman
111  
112 my $eps_eff = ema_bruggeman($eps_a, $eps_b, $vf);
113  
114 B<Bruggeman EMA> solves the self-consistent equation:
115  
116 f_a · (ε_a − ε_eff)/(ε_a + 2·ε_eff)
117 + f_b · (ε_b − ε_eff)/(ε_b + 2·ε_eff) = 0
118  
119 For a two-component system this has the closed-form solution:
120  
121 ε_eff = ( b + sqrt(b² + 8·ε_a·ε_b) ) / 4
122  
123 where b = (3f − 1)·ε_b + (2 − 3f)·ε_a
124  
125 The implementation selects the root with positive real part to ensure
126 a physically meaningful result.
127  
128 Bruggeman EMA is B<symmetric>: neither material is privileged as host
129 or inclusion. This makes it the standard choice for:
130  
131 =over 4
132  
133 =item * Surface roughness layers (50% film / 50% void)
134  
135 =item * Porous films (variable void fraction)
136  
137 =item * Interdiffusion or intermixed interfaces
138  
139 =item * Cermet and nano-composite films
140  
141 =back
142  
143 # Surface roughness: 50% Ta2O5 + 50% void
144 my $eps_void = ones($lambda) + i() * zeroes($lambda); # ε = 1
145 my $eps_rough = ema_bruggeman($eps_ta2o5, $eps_void, 0.50);
146  
147 # Include as a thin layer in the TMM stack
148 my ($psi, $delta) = psi_delta($lambda, $theta,
149 [$N_air, sqrt($eps_rough), $N_ta2o5, $N_si],
150 [2.0, 100.0], # 2 nm roughness, 100 nm film
151 );
152  
153 =head2 ema_maxwell_garnett
154  
155 my $eps_eff = ema_maxwell_garnett($eps_host, $eps_incl, $vf);
156  
157 B<Maxwell-Garnett EMA> treats material B as dilute spherical inclusions
158 embedded in a continuous host matrix of material A:
159  
160 ε_eff = ε_a · (ε_b + 2ε_a + 2f·(ε_b − ε_a))
161 / (ε_b + 2ε_a − f·(ε_b − ε_a))
162  
163 This model is B<asymmetric>: swapping host and inclusion gives a
164 different result. It is most accurate when the inclusion volume
165 fraction is below about 30% and the inclusions are well separated.
166  
167 Typical applications:
168  
169 =over 4
170  
171 =item * Metal nanoparticles in a dielectric (Au in SiO2)
172  
173 =item * Quantum dots in a polymer matrix
174  
175 =item * Dilute dopant phases
176  
177 =back
178  
179 # 5% Au nanoparticles in SiO2 host
180 my $eps_composite = ema_maxwell_garnett($eps_sio2, $eps_au, 0.05);
181  
182 =head1 CONVERTING BETWEEN ε AND N
183  
184 The functions accept and return the complex dielectric function
185 ε = ε₁ + iε₂. To convert to/from the complex refractive index
186 N = n + ik:
187  
188 # N → ε
189 my $eps = ($n + i() * $k) ** 2;
190  
191 # ε → N
192 my $N_complex = sqrt($eps);
193 my $n = $N_complex->re;
194 my $k = $N_complex->im->abs;
195  
196 =head2 ema_looyenga
197  
198 my $eps_eff = ema_looyenga($eps_a, $eps_b, $volume_fraction_b);
199  
200 The B<Looyenga mixing rule> (1965) uses cube-root averaging:
201  
202 eps_eff^(1/3) = (1-f)*eps_a^(1/3) + f*eps_b^(1/3)
203  
204 This formula treats both components symmetrically (unlike Maxwell-Garnett)
205 and is simpler than solving the self-consistent Bruggeman equation. It
206 works well for random mixtures where neither material forms a clear
207 host-inclusion geometry.
208  
209 B<When to use Looyenga:>
210  
211 =over 4
212  
213 =item - Random mixtures with comparable volume fractions of both phases
214  
215 =item - Porous materials (e.g., porous Si, aerogels)
216  
217 =item - Quick estimate without iterative solving
218  
219 =back
220  
221 B<Example:>
222  
223 # Porous silicon (50% Si / 50% void)
224 my $eps_Si = pdl(15.0) + i() * pdl(0.2);
225 my $eps_void = pdl(1.0) + i() * pdl(0.0);
226 my $eps_eff = ema_looyenga($eps_void, $eps_Si, 0.5);
227 my $n_eff = sqrt($eps_eff)->re; # ~2.35
228  
229 # Compare with Bruggeman for same system
230 my $eps_brug = ema_bruggeman($eps_void, $eps_Si, 0.5); # ~2.50
231  
232 =head1 SEE ALSO
233  
234 L<Physics::Ellipsometry::VASE>,
235 L<Physics::Ellipsometry::VASE::TMM>,
236 L<Physics::Ellipsometry::VASE::Dispersion>,
237 L<Physics::Ellipsometry::VASE::Materials>
238  
239 D.E. Aspnes, "Local-field effects and effective-medium theory: A
240 microscopic perspective", I<Am. J. Phys.> B<50>, 704 (1982).
241  
242 H. Fujiwara, I<Spectroscopic Ellipsometry: Principles and Applications>,
243 John Wiley E<amp> Sons, 2007, Chapter 5.
244  
245 =cut
246  
247 # Linear (volume-weighted) mixing: ε_eff = (1-f)ε_a + f·ε_b
248 sub ema_linear {
249 my ($eps_a, $eps_b, $vf) = @_;
250 return (1.0 - $vf) * $eps_a + $vf * $eps_b;
251 }
252  
253 # Bruggeman EMA: f_a·(ε_a - ε_eff)/(ε_a + 2ε_eff) + f_b·(ε_b - ε_eff)/(ε_b + 2ε_eff) = 0
254 # Solved analytically for 2-component mixtures:
255 # ε_eff = (b ± sqrt(b² + 8ε_aε_b)) / 4
256 # where b = (3f_b - 1)ε_b + (3f_a - 1)ε_a = (3vf - 1)ε_b + (2 - 3vf)ε_a
257 sub ema_bruggeman {
258 my ($eps_a, $eps_b, $vf) = @_;
259 my $fa = 1.0 - $vf;
260  
261 # Quadratic solution for 2-component Bruggeman
262 my $b = (3*$vf - 1) * $eps_b + (3*$fa - 1) * $eps_a;
263 my $discriminant = $b**2 + 8 * $eps_a * $eps_b;
264  
265 # Take the root with positive real part
266 my $sqrt_disc = sqrt($discriminant + i()*0);
267 my $eps_eff = ($b + $sqrt_disc) / 4.0;
268  
269 # Ensure physical result (positive real part of ε)
270 my $eps_eff2 = ($b - $sqrt_disc) / 4.0;
271 my $use_alt = ($eps_eff->re < 0) & ($eps_eff2->re > 0);
272 if (ref $use_alt && $use_alt->any) {
273 my $idx = which($use_alt);
274 $eps_eff->index($idx) .= $eps_eff2->index($idx);
275 }
276  
277 return $eps_eff;
278 }
279  
280 # Maxwell-Garnett EMA: inclusion (b) in host matrix (a)
281 # ε_eff = ε_a · (ε_b + 2ε_a + 2f(ε_b - ε_a)) / (ε_b + 2ε_a - f(ε_b - ε_a))
282 sub ema_maxwell_garnett {
283 my ($eps_a, $eps_b, $vf) = @_;
284  
285 my $numer = $eps_b + 2*$eps_a + 2*$vf*($eps_b - $eps_a);
286 my $denom = $eps_b + 2*$eps_a - $vf*($eps_b - $eps_a);
287  
288 return $eps_a * $numer / $denom;
289 }
290  
291 # Looyenga EMA: ε_eff^(1/3) = (1-f)·ε_a^(1/3) + f·ε_b^(1/3)
292 # Valid for random mixtures where neither component is clearly host/inclusion.
293 # More symmetric than Maxwell-Garnett; simpler than Bruggeman.
294 sub ema_looyenga {
295 my ($eps_a, $eps_b, $vf) = @_;
296 my $fa = 1.0 - $vf;
297  
298 # Cube root of complex numbers: |z|^(1/3) * exp(i*arg(z)/3)
299 my $eps_a_third = _complex_cbrt($eps_a);
300 my $eps_b_third = _complex_cbrt($eps_b);
301  
302 my $mix = $fa * $eps_a_third + $vf * $eps_b_third;
303  
304 # Cube the result
305 return $mix**3;
306 }
307  
308 # Complex cube root: z^(1/3)
309 sub _complex_cbrt {
310 my ($z) = @_;
311 my $mag = abs($z);
312 my $arg = carg($z);
313 return $mag**(1.0/3.0) * (cos($arg/3.0) + i() * sin($arg/3.0));
314 }
315  
316 1;