CVD/Chemistry.pm

filter: Statementstmt 45.2% 57 / 126 Branchbran 21.4% 3 / 14 Conditioncond 19.2% 15 / 78 MC/DCmcdc 0.0% 0 / 42 Subroutinesub 56.5% 13 / 23 Podpod 0.0% 0 / 15 totaltotal 29.5% 88 / 298 CC 53 SCAR 35.9
CC
53
Cov
34%
evolve
132.0
add_surface_reaction
72.0
surface_rates
42.0
CRAP 36.1
« CVD/Interface/LAMMPS.pm ↑ Summary CVD/KMC.pm »
1 package Physics::CVD::Chemistry;
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 Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use List::Util qw(sum max min);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ═══════════════════════════════════════════════════════════════════════════════
8 # Gas-phase and surface reaction chemistry for CVD
9 #
10 # Handles:
11 # - Gas-phase decomposition reactions (Arrhenius kinetics)
12 # - Surface adsorption/reaction mechanisms (Langmuir-Hinshelwood, Eley-Rideal)
13 # - Sticking coefficients (temperature-dependent)
14 # - Reaction networks with multiple intermediates
15 # ═══════════════════════════════════════════════════════════════════════════════
16  
17 1 ▶use constant KB => 1.380649e-23; # J/K
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use constant EV => 1.602176634e-19; # J/eV
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use constant R_GAS => 8.314462; # J/(mol·K)
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use constant NA => 6.02214076e23; # /mol
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶sub new {
Subroutine new: called CC=4 SCAR=15.2
Pod undocumented
23 1 my ($class, %opts) = @_;
24 my $self = bless {
25 temperature => $opts{temperature} // 700,
26 pressure => $opts{pressure} // 100,
27 1 ▶ verbose => $opts{verbose} // 0,
Condition50%3/6
$opts{"temperature"} // 700
l!l
10
$opts{"pressure"} // 100
l!l
10
$opts{"verbose"} // 0
l!l
01
MC/DC0%0/1
$opts{"temperature"} // 700
$opts{"temperature"}
MC/DC0%0/1
$opts{"pressure"} // 100
$opts{"pressure"}
MC/DC0%0/1
$opts{"verbose"} // 0
$opts{"verbose"}
Truth table50%1/2
A
A= $opts{"temperature"}
Aresult
11
00
Truth table50%1/2
A
A= $opts{"pressure"}
Aresult
11
00
Truth table50%1/2
A
A= $opts{"verbose"}
Aresult
11
00
28 gas_reactions => [],
29 surface_reactions => [],
30 species => {},
31 concentrations => {},
32 }, $class;
33 1 return $self;
34 }
35  
36 # Add a gas-phase species
37 1 ▶sub add_species {
Subroutine add_species: called CC=6 SCAR=20.7
Pod undocumented
38 1 my ($self, %spec) = @_;
39 1 ▶ croak "Species 'name' required" unless $spec{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $spec{"name"} 0 1 1
40 $self->{species}{$spec{name}} = {
41 name => $spec{name},
42 mass => $spec{mass} // 28, # amu
43 formula => $spec{formula} // $spec{name},
44 1 ▶ type => $spec{type} // 'gas', # gas, surface, bulk
Condition42%3/7
$spec{"mass"} // 28
l!l
10
$spec{"formula"} // $spec{"name"}
l!l&&r!l&&!r
010
$spec{"type"} // "gas"
l!l
01
MC/DC0%0/1
$spec{"mass"} // 28
$spec{"mass"}
MC/DC0%0/2
$spec{"formula"} // $spec{"name"}
$spec{"formula"} $spec{"name"}
MC/DC0%0/1
$spec{"type"} // "gas"
$spec{"type"}
Truth table50%1/2
A
A= $spec{"mass"}
Aresult
11
00
Truth table33%1/3
A // B
A= $spec{"formula"}B= $spec{"name"}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $spec{"type"}
Aresult
11
00
45 };
46 1 ▶ $self->{concentrations}{$spec{name}} = $spec{concentration} // 0;
Condition50%1/2
$spec{"concentration"} // 0
l!l
10
MC/DC0%0/1
$spec{"concentration"} // 0
$spec{"concentration"}
Truth table50%1/2
A
A= $spec{"concentration"}
Aresult
11
00
47 1 return $self;
48 }
49  
50 # Add a gas-phase reaction: A -> B + C with Arrhenius kinetics
51 1 ▶sub add_gas_reaction {
Subroutine add_gas_reaction: called CC=7 SCAR=21.8
Pod undocumented
52 1 my ($self, %rxn) = @_;
53 1 ▶ croak "Reactants required" unless $rxn{reactants};
Branch: 1 branch
BranchTrueFalseTotal
unless $rxn{"reactants"} 0 1 1
54 1 ▶ croak "Products required" unless $rxn{products};
Branch: 1 branch
BranchTrueFalseTotal
unless $rxn{"products"} 0 1 1
55  
56 1 ▶ push @{$self->{gas_reactions}}, {
Condition50%4/8
$rxn{"A"} // "10000000000000"
l!l
10
$rxn{"Ea"} // 1
l!l
10
$rxn{"order"} // 1
l!l
01
$rxn{"name"} // "unnamed"
l!l
10
MC/DC0%0/1
$rxn{"A"} // "10000000000000"
$rxn{"A"}
MC/DC0%0/1
$rxn{"Ea"} // 1
$rxn{"Ea"}
MC/DC0%0/1
$rxn{"order"} // 1
$rxn{"order"}
MC/DC0%0/1
$rxn{"name"} // "unnamed"
$rxn{"name"}
Truth table50%1/2
A
A= $rxn{"A"}
Aresult
11
00
Truth table50%1/2
A
A= $rxn{"Ea"}
Aresult
11
00
Truth table50%1/2
A
A= $rxn{"order"}
Aresult
11
00
Truth table50%1/2
A
A= $rxn{"name"}
Aresult
11
00
57 reactants => $rxn{reactants}, # ['SiH4']
58 products => $rxn{products}, # ['SiH2', 'H2']
59 A => $rxn{A} // 1e13, # pre-exponential (1/s or cm³/mol·s)
60 Ea => $rxn{Ea} // 1.0, # activation energy (eV)
61 order => $rxn{order} // 1, # reaction order
62 1 name => $rxn{name} // 'unnamed',
63 };
64 1 return $self;
65 }
66  
67 # Add a surface reaction (Langmuir-Hinshelwood or Eley-Rideal)
68 0 ▶sub add_surface_reaction {
Subroutine add_surface_reaction: not called CC=8 SCAR=42.8
Pod undocumented
69 0 my ($self, %rxn) = @_;
70 0 ▶ croak "Reactants required" unless $rxn{reactants};
Branch: 1 branch
BranchTrueFalseTotal
unless $rxn{"reactants"} 0 0 0
71 0 ▶ croak "Products required" unless $rxn{products};
Branch: 1 branch
BranchTrueFalseTotal
unless $rxn{"products"} 0 0 0
72  
73 0 ▶ push @{$self->{surface_reactions}}, {
Condition0%0/10
$rxn{"mechanism"} // "LH"
l!l
00
$rxn{"sticking_coeff"} // "0.1"
l!l
00
$rxn{"Ea"} // "0.5"
l!l
00
$rxn{"A"} // "10000000000000"
l!l
00
$rxn{"name"} // "unnamed"
l!l
00
MC/DC0%0/1
$rxn{"mechanism"} // "LH"
$rxn{"mechanism"}
MC/DC0%0/1
$rxn{"sticking_coeff"} // "0.1"
$rxn{"sticking_coeff"}
MC/DC0%0/1
$rxn{"Ea"} // "0.5"
$rxn{"Ea"}
MC/DC0%0/1
$rxn{"A"} // "10000000000000"
$rxn{"A"}
MC/DC0%0/1
$rxn{"name"} // "unnamed"
$rxn{"name"}
Truth table0%0/2
A
A= $rxn{"mechanism"}
Aresult
11
00
Truth table0%0/2
A
A= $rxn{"sticking_coeff"}
Aresult
11
00
Truth table0%0/2
A
A= $rxn{"Ea"}
Aresult
11
00
Truth table0%0/2
A
A= $rxn{"A"}
Aresult
11
00
Truth table0%0/2
A
A= $rxn{"name"}
Aresult
11
00
74 reactants => $rxn{reactants}, # ['SiH2(s)', 'O(s)']
75 products => $rxn{products}, # ['SiO2(b)']
76 mechanism => $rxn{mechanism} // 'LH', # LH or ER
77 sticking_coeff => $rxn{sticking_coeff} // 0.1,
78 Ea => $rxn{Ea} // 0.5, # eV
79 A => $rxn{A} // 1e13,
80 0 name => $rxn{name} // 'unnamed',
81 };
82 0 return $self;
83 }
84  
85 # Compute Arrhenius rate constant k = A × exp(-Ea/kT)
86 0 ▶sub rate_constant {
Subroutine rate_constant: not called CC=4 SCAR=30.0
Pod undocumented
87 0 my ($self, %opts) = @_;
88 0 ▶ my $A = $opts{A} // 1e13;
Condition0%0/2
$opts{"A"} // "10000000000000"
l!l
00
MC/DC0%0/1
$opts{"A"} // "10000000000000"
$opts{"A"}
Truth table0%0/2
A
A= $opts{"A"}
Aresult
11
00
89 0 ▶ my $Ea = $opts{Ea} // 1.0; # eV
Condition0%0/2
$opts{"Ea"} // 1
l!l
00
MC/DC0%0/1
$opts{"Ea"} // 1
$opts{"Ea"}
Truth table0%0/2
A
A= $opts{"Ea"}
Aresult
11
00
90 0 ▶ my $T = $opts{T} // $self->{temperature};
Condition0%0/3
$opts{"T"} // $self->{"temperature"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"T"} // $self->{"temperature"}
$opts{"T"} $self->{"temperature"}
Truth table0%0/3
A // B
A= $opts{"T"}B= $self->{"temperature"}
ABresult
1X1
011
000
91 0 return $A * exp(-$Ea * EV / (KB * $T));
92 }
93  
94 # Compute all gas-phase reaction rates at current conditions
95 1 ▶sub gas_rates {
Subroutine gas_rates: called CC=4 SCAR=13.9
Pod undocumented
96 1 my ($self) = @_;
97 1 my $T = $self->{temperature};
98 1 my @rates;
99 1 for my $rxn (@{$self->{gas_reactions}}) {
100 1 my $k = $rxn->{A} * exp(-$rxn->{Ea} * EV / (KB * $T));
101 # Rate = k × product of reactant concentrations
102 1 my $rate = $k;
103 1 for my $r (@{$rxn->{reactants}}) {
104 1 ▶ $rate *= ($self->{concentrations}{$r} // 0) ** $rxn->{order};
Condition50%1/2
$self->{"concentrations"}{$r} // 0
l!l
10
MC/DC0%0/1
$self->{"concentrations"}{$r} // 0
$self->{"concentrations"}{$r}
Truth table50%1/2
A
A= $self->{"concentrations"}{$r}
Aresult
11
00
105 }
106 1 push @rates, { name => $rxn->{name}, rate => $rate, k => $k };
107 }
108 1 return \@rates;
109 }
110  
111 # Compute surface reaction rates
112 0 ▶sub surface_rates {
Subroutine surface_rates: not called CC=6 SCAR=37.4
Pod undocumented
113 0 my ($self, %opts) = @_;
114 0 my $T = $self->{temperature};
115 0 ▶ my $coverage = $opts{coverage} // {}; # surface coverages θᵢ
Condition0%0/2
$opts{"coverage"} // {}
l!l
00
MC/DC0%0/1
$opts{"coverage"} // {}
$opts{"coverage"}
Truth table0%0/2
A
A= $opts{"coverage"}
Aresult
11
00
116 0 my @rates;
117 0 for my $rxn (@{$self->{surface_reactions}}) {
118 0 my $k = $rxn->{A} * exp(-$rxn->{Ea} * EV / (KB * $T));
119 0 my $rate = $k;
120 0 ▶ if ($rxn->{mechanism} eq 'LH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($rxn->{'mechanism'} eq 'LH') { } 0 0 0
121 # Langmuir-Hinshelwood: rate ∝ θ_A × θ_B
122 0 for my $r (@{$rxn->{reactants}}) {
123 0 ▶ $rate *= ($coverage->{$r} // 0);
Condition0%0/2
$coverage->{$r} // 0
l!l
00
MC/DC0%0/1
$coverage->{$r} // 0
$coverage->{$r}
Truth table0%0/2
A
A= $coverage->{$r}
Aresult
11
00
124 }
125 } else {
126 # Eley-Rideal: rate ∝ P_gas × θ_surface
127 0 $rate *= $rxn->{sticking_coeff};
128 }
129 0 push @rates, { name => $rxn->{name}, rate => $rate, k => $k };
130 }
131 0 return \@rates;
132 }
133  
134 # Hertz-Knudsen flux: impingement rate of gas on surface (molecules/cm²/s)
135 1 ▶sub impingement_flux {
Subroutine impingement_flux: called CC=4 SCAR=15.5
Pod undocumented
136 1 my ($self, %opts) = @_;
137 1 ▶ my $P = $opts{pressure} // $self->{pressure}; # Pa
Condition33%1/3
$opts{"pressure"} // $self->{"pressure"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$opts{"pressure"} // $self->{"pressure"}
$opts{"pressure"} $self->{"pressure"}
Truth table33%1/3
A // B
A= $opts{"pressure"}B= $self->{"pressure"}
ABresult
1X1
011
000
138 1 ▶ my $T = $opts{T} // $self->{temperature};
Condition33%1/3
$opts{"T"} // $self->{"temperature"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$opts{"T"} // $self->{"temperature"}
$opts{"T"} $self->{"temperature"}
Truth table33%1/3
A // B
A= $opts{"T"}B= $self->{"temperature"}
ABresult
1X1
011
000
139 1 ▶ my $mass = $opts{mass} // 28; # amu
Condition50%1/2
$opts{"mass"} // 28
l!l
10
MC/DC0%0/1
$opts{"mass"} // 28
$opts{"mass"}
Truth table50%1/2
A
A= $opts{"mass"}
Aresult
11
00
140 1 my $m_kg = $mass * 1.66054e-27;
141 # Φ = P / sqrt(2πmkT)
142 1 return $P / sqrt(2.0 * 3.14159265 * $m_kg * KB * $T) * 1e-4; # /cm²/s
143 }
144  
145 # Sticking coefficient with temperature dependence: S(T) = S₀ × exp(-Ea/kT)
146 0 ▶sub sticking_coefficient {
Subroutine sticking_coefficient: not called CC=4 SCAR=30.0
Pod undocumented
147 0 my ($self, %opts) = @_;
148 0 ▶ my $S0 = $opts{S0} // 1.0;
Condition0%0/2
$opts{"S0"} // 1
l!l
00
MC/DC0%0/1
$opts{"S0"} // 1
$opts{"S0"}
Truth table0%0/2
A
A= $opts{"S0"}
Aresult
11
00
149 0 ▶ my $Ea = $opts{Ea} // 0; # eV
Condition0%0/2
$opts{"Ea"} // 0
l!l
00
MC/DC0%0/1
$opts{"Ea"} // 0
$opts{"Ea"}
Truth table0%0/2
A
A= $opts{"Ea"}
Aresult
11
00
150 0 ▶ my $T = $opts{T} // $self->{temperature};
Condition0%0/3
$opts{"T"} // $self->{"temperature"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"T"} // $self->{"temperature"}
$opts{"T"} $self->{"temperature"}
Truth table0%0/3
A // B
A= $opts{"T"}B= $self->{"temperature"}
ABresult
1X1
011
000
151 0 return $S0 * exp(-$Ea * EV / (KB * $T));
152 }
153  
154 # Integrate gas-phase chemistry over time (simple Euler)
155 0 ▶sub evolve {
Subroutine evolve: not called CC=11 SCAR=48.8
Pod undocumented
156 0 my ($self, %opts) = @_;
157 0 ▶ my $dt = $opts{dt} // 1e-6; # seconds
Condition0%0/2
$opts{"dt"} // "1e-06"
l!l
00
MC/DC0%0/1
$opts{"dt"} // "1e-06"
$opts{"dt"}
Truth table0%0/2
A
A= $opts{"dt"}
Aresult
11
00
158 0 ▶ my $steps = $opts{steps} // 1000;
Condition0%0/2
$opts{"steps"} // 1000
l!l
00
MC/DC0%0/1
$opts{"steps"} // 1000
$opts{"steps"}
Truth table0%0/2
A
A= $opts{"steps"}
Aresult
11
00
159 0 my $T = $self->{temperature};
160  
161 0 for my $step (1 .. $steps) {
162 0 for my $rxn (@{$self->{gas_reactions}}) {
163 0 my $k = $rxn->{A} * exp(-$rxn->{Ea} * EV / (KB * $T));
164 0 my $rate = $k;
165 0 for my $r (@{$rxn->{reactants}}) {
166 0 ▶ $rate *= ($self->{concentrations}{$r} // 0);
Condition0%0/2
$self->{"concentrations"}{$r} // 0
l!l
00
MC/DC0%0/1
$self->{"concentrations"}{$r} // 0
$self->{"concentrations"}{$r}
Truth table0%0/2
A
A= $self->{"concentrations"}{$r}
Aresult
11
00
167 }
168 # Consume reactants, produce products
169 0 for my $r (@{$rxn->{reactants}}) {
170 0 $self->{concentrations}{$r} -= $rate * $dt;
171 $self->{concentrations}{$r} = 0
172 0 ▶ if ($self->{concentrations}{$r} // 0) < 0;
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"concentrations"}{$r} // 0) < 0 0 0 0
Condition0%0/2
$self->{"concentrations"}{$r} // 0
l!l
00
MC/DC0%0/1
$self->{"concentrations"}{$r} // 0
$self->{"concentrations"}{$r}
Truth table0%0/2
A
A= $self->{"concentrations"}{$r}
Aresult
11
00
173 }
174 0 for my $p (@{$rxn->{products}}) {
175 0 $self->{concentrations}{$p} += $rate * $dt;
176 }
177 }
178 }
179 0 return $self;
180 }
181  
182 # Set/get concentrations
183 0 ▶sub set_concentration {
Subroutine set_concentration: not called CC=1 SCAR=6.9
Pod undocumented
184 0 my ($self, $species, $conc) = @_;
185 0 $self->{concentrations}{$species} = $conc;
186 0 return $self;
187 }
188  
189 0 ▶sub get_concentration {
Subroutine get_concentration: not called CC=2 SCAR=17.9
Pod undocumented
190 0 my ($self, $species) = @_;
191 0 ▶ return $self->{concentrations}{$species} // 0;
Condition0%0/2
$self->{"concentrations"}{$species} // 0
l!l
00
MC/DC0%0/1
$self->{"concentrations"}{$species} // 0
$self->{"concentrations"}{$species}
Truth table0%0/2
A
A= $self->{"concentrations"}{$species}
Aresult
11
00
192 }
193  
194 0 ▶sub concentrations { return $_[0]->{concentrations} }
Subroutine concentrations: not called CC=1 SCAR=6.9
Pod undocumented
195  
196 # Growth rate estimate (nm/min) from surface flux and sticking
197 0 ▶sub growth_rate {
Subroutine growth_rate: not called CC=4 SCAR=30.0
Pod undocumented
198 0 my ($self, %opts) = @_;
199 0 ▶ my $flux = $opts{flux} // $self->impingement_flux(%opts);
Condition0%0/3
$opts{"flux"} // $self->impingement_flux(%opts)
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts{"flux"} // $self->impingement_flux(%opts)
$opts{"flux"} $self->impingement_flux(%opts)
Truth table0%0/3
A // B
A= $opts{"flux"}B= $self->impingement_flux(%opts)
ABresult
1X1
011
000
200 0 ▶ my $S = $opts{sticking} // 0.1;
Condition0%0/2
$opts{"sticking"} // "0.1"
l!l
00
MC/DC0%0/1
$opts{"sticking"} // "0.1"
$opts{"sticking"}
Truth table0%0/2
A
A= $opts{"sticking"}
Aresult
11
00
201 0 ▶ my $density = $opts{film_density} // 2.2e22; # atoms/cm³ (SiO₂)
Condition0%0/2
$opts{"film_density"} // "2.2e+22"
l!l
00
MC/DC0%0/1
$opts{"film_density"} // "2.2e+22"
$opts{"film_density"}
Truth table0%0/2
A
A= $opts{"film_density"}
Aresult
11
00
202 0 my $rate_cm_s = $flux * $S / $density;
203 0 return $rate_cm_s * 1e7 * 60; # nm/min
204 }
205  
206 0 ▶sub stats {
Subroutine stats: not called CC=1 SCAR=6.9
Pod undocumented
207 0 my ($self) = @_;
208 return {
209 0 n_gas_reactions => scalar @{$self->{gas_reactions}},
210 0 n_surface_reactions => scalar @{$self->{surface_reactions}},
211 0 n_species => scalar keys %{$self->{species}},
212 temperature => $self->{temperature},
213 pressure => $self->{pressure},
214 0 concentrations => { %{$self->{concentrations}} },
215 };
216 }
217  
218 1 1;
« CVD/Interface/LAMMPS.pm ↑ Summary CVD/KMC.pm »