CVD/Interface/OpenFOAM.pm

filter: Statementstmt 19.7% 13 / 66 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 30.7% 4 / 13 Podpod 0.0% 0 / 3 totaltotal 13.2% 17 / 128 CC 19 SCAR 27.1
CC
19
Cov
13%
_write_blockMeshDict
30.0
_write_controlDict
20.0
_write_boundary_conditions
20.0
CRAP 15.1
« CVD/Interface/Cantera.pm ↑ Summary CVD/Transport.pm »
1 package Physics::CVD::Interface::OpenFOAM;
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 File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ═══════════════════════════════════════════════════════════════════════════════
8 # OpenFOAM interface for CVD reactor-scale simulation
9 #
10 # Generates case directories for:
11 # - reactingFoam (reacting gas flow)
12 # - simpleFoam + scalarTransport (simplified transport)
13 # - buoyantSimpleFoam (natural convection)
14 # ═══════════════════════════════════════════════════════════════════════════════
15  
16 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod undocumented
17 0 my ($class, %opts) = @_;
18 my $self = bless {
19 case_dir => $opts{case_dir} // './cvd_case',
20 0 ▶ solver => $opts{solver} // 'reactingFoam',
Condition0%0/4
$opts{"case_dir"} // "./cvd_case"
l!l
00
$opts{"solver"} // "reactingFoam"
l!l
00
MC/DC0%0/1
$opts{"case_dir"} // "./cvd_case"
$opts{"case_dir"}
MC/DC0%0/1
$opts{"solver"} // "reactingFoam"
$opts{"solver"}
Truth table0%0/2
A
A= $opts{"case_dir"}
Aresult
11
00
Truth table0%0/2
A
A= $opts{"solver"}
Aresult
11
00
21 }, $class;
22 0 return $self;
23 }
24  
25 0 ▶sub generate_case {
Subroutine generate_case: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my ($self, %opts) = @_;
27 0 my $dir = $self->{case_dir};
28 0 make_path("$dir/constant/polyMesh", "$dir/system", "$dir/0");
29  
30 0 $self->_write_controlDict(%opts);
31 0 $self->_write_fvSchemes;
32 0 $self->_write_fvSolution;
33 0 $self->_write_blockMeshDict(%opts);
34 0 $self->_write_thermophysicalProperties(%opts);
35 0 $self->_write_boundary_conditions(%opts);
36  
37 0 return $dir;
38 }
39  
40 0 ▶sub _write_controlDict {
Subroutine _write_controlDict: not called CC=4 SCAR=30.0
41 0 my ($self, %opts) = @_;
42 0 ▶ my $end_time = $opts{end_time} // 1.0;
Condition0%0/2
$opts{"end_time"} // 1
l!l
00
MC/DC0%0/1
$opts{"end_time"} // 1
$opts{"end_time"}
Truth table0%0/2
A
A= $opts{"end_time"}
Aresult
11
00
43 0 ▶ my $dt = $opts{dt} // 1e-5;
Condition0%0/2
$opts{"dt"} // "1e-05"
l!l
00
MC/DC0%0/1
$opts{"dt"} // "1e-05"
$opts{"dt"}
Truth table0%0/2
A
A= $opts{"dt"}
Aresult
11
00
44 0 ▶ open my $fh, '>', "$self->{case_dir}/system/controlDict" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$self->{"case_dir"}/system/controlDict] or die $! 0 0 0
45 0 print $fh <<EOF;
46 FoamFile
47 {
48 version 2.0;
49 format ascii;
50 class dictionary;
51 object controlDict;
52 }
53  
54 application $self->{solver};
55 startFrom startTime;
56 startTime 0;
57 stopAt endTime;
58 endTime $end_time;
59 deltaT $dt;
60 writeControl adjustableRunTime;
61 writeInterval 0.1;
62 purgeWrite 5;
63 writeFormat ascii;
64 writePrecision 8;
65 writeCompression off;
66 timeFormat general;
67 timePrecision 6;
68 runTimeModifiable true;
69 EOF
70 0 close $fh;
71 }
72  
73 0 ▶sub _write_fvSchemes {
Subroutine _write_fvSchemes: not called CC=2 SCAR=17.9
74 0 my ($self) = @_;
75 0 ▶ open my $fh, '>', "$self->{case_dir}/system/fvSchemes" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$self->{"case_dir"}/system/fvSchemes] or die $! 0 0 0
76 0 print $fh <<'EOF';
77 FoamFile
78 {
79 version 2.0;
80 format ascii;
81 class dictionary;
82 object fvSchemes;
83 }
84  
85 ddtSchemes { default Euler; }
86 gradSchemes { default Gauss linear; }
87 divSchemes
88 {
89 default none;
90 div(phi,U) Gauss linearUpwind grad(U);
91 div(phi,Yi_h) Gauss linearUpwind grad(Yi_h);
92 div(phi,K) Gauss linear;
93 div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear;
94 }
95 laplacianSchemes { default Gauss linear corrected; }
96 interpolationSchemes { default linear; }
97 snGradSchemes { default corrected; }
98 EOF
99 0 close $fh;
100 }
101  
102 0 ▶sub _write_fvSolution {
Subroutine _write_fvSolution: not called CC=2 SCAR=17.9
103 0 my ($self) = @_;
104 0 ▶ open my $fh, '>', "$self->{case_dir}/system/fvSolution" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$self->{"case_dir"}/system/fvSolution] or die $! 0 0 0
105 0 print $fh <<'EOF';
106 FoamFile
107 {
108 version 2.0;
109 format ascii;
110 class dictionary;
111 object fvSolution;
112 }
113  
114 solvers
115 {
116 "rho.*" { solver diagonal; }
117 p { solver PCG; preconditioner DIC; tolerance 1e-6; relTol 0.01; }
118 "(U|Yi|h)" { solver PBiCGStab; preconditioner DILU; tolerance 1e-6; relTol 0.1; }
119 }
120  
121 PIMPLE
122 {
123 nOuterCorrectors 2;
124 nCorrectors 1;
125 nNonOrthogonalCorrectors 0;
126 }
127 EOF
128 0 close $fh;
129 }
130  
131 0 ▶sub _write_blockMeshDict {
Subroutine _write_blockMeshDict: not called CC=5 SCAR=34.0
132 0 my ($self, %opts) = @_;
133 0 ▶ my $radius = $opts{reactor_radius} // 0.075; # m
Condition0%0/2
$opts{"reactor_radius"} // "0.075"
l!l
00
MC/DC0%0/1
$opts{"reactor_radius"} // "0.075"
$opts{"reactor_radius"}
Truth table0%0/2
A
A= $opts{"reactor_radius"}
Aresult
11
00
134 0 ▶ my $length = $opts{reactor_length} // 0.5; # m
Condition0%0/2
$opts{"reactor_length"} // "0.5"
l!l
00
MC/DC0%0/1
$opts{"reactor_length"} // "0.5"
$opts{"reactor_length"}
Truth table0%0/2
A
A= $opts{"reactor_length"}
Aresult
11
00
135 0 ▶ my $gap = $opts{gap} // 0.02; # m (showerhead-wafer gap)
Condition0%0/2
$opts{"gap"} // "0.02"
l!l
00
MC/DC0%0/1
$opts{"gap"} // "0.02"
$opts{"gap"}
Truth table0%0/2
A
A= $opts{"gap"}
Aresult
11
00
136  
137 0 ▶ open my $fh, '>', "$self->{case_dir}/system/blockMeshDict" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$self->{"case_dir"}/system/blockMeshDict] or die $! 0 0 0
138 0 printf $fh <<'EOF', $radius, $gap, $length;
139 FoamFile
140 {
141 version 2.0;
142 format ascii;
143 class dictionary;
144 object blockMeshDict;
145 }
146  
147 scale 1;
148  
149 vertices
150 (
151 (0 0 0)
152 (%g 0 0)
153 (%g %g 0)
154 (0 %g 0)
155 (0 0 %g)
156 (%g 0 %g)
157 (%g %g %g)
158 (0 %g %g)
159 );
160  
161 blocks ( hex (0 1 2 3 4 5 6 7) (20 10 40) simpleGrading (1 1 1) );
162  
163 boundary
164 (
165 inlet { type patch; faces ((4 5 6 7)); }
166 outlet { type patch; faces ((0 1 2 3)); }
167 walls { type wall; faces ((0 4 7 3) (1 5 6 2) (0 1 5 4) (3 2 6 7)); }
168 wafer { type wall; faces ((0 1 2 3)); }
169 );
170 EOF
171 0 close $fh;
172 }
173  
174 0 ▶sub _write_thermophysicalProperties {
Subroutine _write_thermophysicalProperties: not called CC=2 SCAR=17.9
175 0 my ($self, %opts) = @_;
176 0 ▶ open my $fh, '>', "$self->{case_dir}/constant/thermophysicalProperties" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$self->{"case_dir"}/constant/thermophysicalProperties] or die $! 0 0 0
177 0 print $fh <<'EOF';
178 FoamFile
179 {
180 version 2.0;
181 format ascii;
182 class dictionary;
183 object thermophysicalProperties;
184 }
185  
186 thermoType
187 {
188 type hePsiThermo;
189 mixture multiComponentMixture;
190 transport sutherland;
191 thermo janaf;
192 equationOfState perfectGas;
193 specie specie;
194 energy sensibleEnthalpy;
195 }
196 EOF
197 0 close $fh;
198 }
199  
200 0 ▶sub _write_boundary_conditions {
Subroutine _write_boundary_conditions: not called CC=4 SCAR=30.0
201 0 my ($self, %opts) = @_;
202 0 ▶ my $T_wafer = $opts{temperature} // 700;
Condition0%0/2
$opts{"temperature"} // 700
l!l
00
MC/DC0%0/1
$opts{"temperature"} // 700
$opts{"temperature"}
Truth table0%0/2
A
A= $opts{"temperature"}
Aresult
11
00
203 0 ▶ my $T_inlet = $opts{inlet_temp} // 300;
Condition0%0/2
$opts{"inlet_temp"} // 300
l!l
00
MC/DC0%0/1
$opts{"inlet_temp"} // 300
$opts{"inlet_temp"}
Truth table0%0/2
A
A= $opts{"inlet_temp"}
Aresult
11
00
204  
205 0 ▶ open my $fh, '>', "$self->{case_dir}/0/T" or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", qq[$self->{"case_dir"}/0/T] or die $! 0 0 0
206 0 printf $fh <<'EOF', $T_inlet, $T_wafer;
207 FoamFile
208 {
209 version 2.0;
210 format ascii;
211 class volScalarField;
212 object T;
213 }
214  
215 dimensions [0 0 0 1 0 0 0];
216 internalField uniform %g;
217  
218 boundaryField
219 {
220 inlet { type fixedValue; value uniform %g; }
221 wafer { type fixedValue; value uniform %g; }
222 walls { type zeroGradient; }
223 outlet { type zeroGradient; }
224 }
225 EOF
226 0 close $fh;
227 }
228  
229 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod undocumented
230 0 my ($self, %opts) = @_;
231 0 ▶ my $np = $opts{processors} // 1;
Condition0%0/2
$opts{"processors"} // 1
l!l
00
MC/DC0%0/1
$opts{"processors"} // 1
$opts{"processors"}
Truth table0%0/2
A
A= $opts{"processors"}
Aresult
11
00
232 0 my $dir = $self->{case_dir};
233  
234 0 ▶ system("cd $dir && blockMesh > log.blockMesh 2>&1") == 0
Branch: 1 branch
BranchTrueFalseTotal
system("cd $dir && blockMesh > log.blockMesh 2>&1") == 0 or carp("blockMesh failed") 0 0 0
235 or carp "blockMesh failed";
236  
237 0 ▶ if ($np > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($np > 1) { } 0 0 0
238 0 system("cd $dir && decomposePar > log.decomposePar 2>&1");
239 0 system("cd $dir && mpirun -np $np $self->{solver} -parallel > log.solver 2>&1");
240 } else {
241 0 system("cd $dir && $self->{solver} > log.solver 2>&1");
242 }
243 0 return $self;
244 }
245  
246 1 1;
« CVD/Interface/Cantera.pm ↑ Summary CVD/Transport.pm »