-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytrim_wire2.cc
316 lines (269 loc) · 9.71 KB
/
mytrim_wire2.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/***************************************************************************
* Copyright (C) 2008 by Daniel Schwen *
* daniel@schwen.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <iostream>
#include <fstream>
#include <sstream>
#include "simconf.h"
#include "element.h"
#include "material.h"
#include "sample_wire.h"
#include "sample_burried_wire.h"
#include "ion.h"
#include "trim.h"
#include "invert.h"
#include "functions.h"
using namespace std;
int main(int argc, char *argv[])
{
char fname[200];
if( argc != 8 )
{
cerr << "syntax: " << argv[0] << " basename angle[deg] diameter(nm) burried[0,1] numbermultiplier xyzout[0,1] lbinout[0,1]" << endl;
return 1;
}
double theta = atof(argv[2]) * M_PI/180.0; // 0 = parallel to wire
double diameter = 10.0*atof(argv[3]);
double length = 11000.0; // 1.1 mu
bool burried = ( atoi(argv[4]) != 0 );
double mult = atof(argv[5]);
bool xyz_out = ( atoi(argv[6]) != 0 );
bool ldat_out = ( atoi(argv[7]) != 0 );
// ion series
const int nstep = 5;
double ion_dose[nstep] = { 3.0e13, 2.2e13, 1.5e13, 1.2e13, 2.5e13 }; // in ions/cm^2
int ion_count[nstep];
ionBase* ion_prototype[nstep];
ion_prototype[0] = new ionBase( 5, 11.0 , 320.0e3 ); // Z,m,E
ion_prototype[1] = new ionBase( 5, 11.0 , 220.0e3 ); // Z,m,E
ion_prototype[2] = new ionBase( 5, 11.0 , 160.0e3 ); // Z,m,E
ion_prototype[3] = new ionBase( 5, 11.0 , 120.0e3 ); // Z,m,E
ion_prototype[4] = new ionBase( 15, 31.0 , 250.0e3 ); // Z,m,E
// seed randomnumber generator from system entropy pool
FILE *urand = fopen( "/dev/random", "r" );
int seed;
fread( &seed, sizeof(int), 1, urand );
fclose( urand );
r250_init( seed<0 ? -seed : seed ); // random generator goes haywire with neg. seed
// initialize global parameter structure and read data tables from file
simconf = new simconfType;
//simconf->fullTraj = true;
// initialize sample structure
sampleWire *sample;
if( burried )
sample = new sampleBurriedWire( diameter, diameter, length );
else
{
sample = new sampleWire( diameter, diameter, length );
sample->bc[2] = sampleWire::CUT;
}
// calculate actual ion numbers
for( int s = 0; s < nstep; ++s )
{
double A; // irradiated area in Ang^2
if( burried )
A =( length + sample->w[0] ) * ( length + sample->w[1] );
else
A = cos(theta) * M_PI * 0.25 * sample->w[0] * sample->w[1] + // slanted top face
sin(theta) * length * sample->w[0]; // + projected side
// 1cm^2 = 1e16 Ang**2, 1Ang^2 = 1e-16cm^2
ion_count[s] = ion_dose[s] * A * 1.0e-16 * mult;
cerr << "Ion " << s << ' ' << ion_count[s] << endl;
}
// initialize trim engine for the sample
/* const int z1 = 31;
const int z2 = 33;
trimVacMap *trim = new trimVacMap( sample, z1, z2 ); // GaAs*/
//trimBase *trim = new trimBase( sample );
trimBase *trim = new trimPrimaries( sample );
materialBase *material;
elementBase *element;
// Si
material = new materialBase( 2.329 ); // rho
element = new elementBase;
element->z = 14; // Si
element->m = 28.0;
element->t = 1.0;
material->element.push_back( element );
material->prepare(); // all materials added
sample->material.push_back( material ); // add material to sample
// SiO2 (material[1] for the cover layer in SampleBurriedWire)
material = new materialBase( 2.634 ); // rho
element = new elementBase;
element->z = 14; // Si
element->m = 28.0;
element->t = 1.0;
material->element.push_back( element );
element = new elementBase;
element->z = 8; // O
element->m = 16.0;
element->t = 2.0;
material->element.push_back( element );
material->prepare(); // all materials added
sample->material.push_back( material ); // add material to sample
// create a FIFO for recoils
queue<ionBase*> recoils;
double norm;
double jmp = 2.7; // diffusion jump distance
int jumps;
double dif[3];
//snprintf( fname, 199, "%s.Erec", argv[1] );
//FILE *erec = fopen( fname, "wt" );
//snprintf( fname, 199, "%s.dist", argv[1] );
//FILE *rdist = fopen( fname, "wt" );
ionBase *pka;
// map concentration along length
int *lbins[2];
int lx = 100; // 100 bins
int dl = length/double(lx);
lbins[1] = new int[lx]; // P z=15
for( int i = 0; i < 2; ++i )
{
lbins[i] = new int[lx]; // 0=B (z=5), 1=P (z=15)
for( int l = 0; l < lx; ++l )
lbins[i][l] = 0;
}
// xyz data
int xyz_lines = 0;
stringstream xyz_data;
for( int s = 0; s < nstep; ++s )
{
for( int n = 0; n < ion_count[s]; ++n )
{
if( n % 10000 == 0 )
cerr << "pka #" << n+1 << endl;
// generate new PKA from prototype ion
pka = new ionBase( ion_prototype[s] );
pka->gen = 0; // generation (0 = PKA)
pka->tag = -1;
pka->dir[0] = 0.0;
pka->dir[1] = sin( theta );
pka->dir[2] = cos( theta );
v_norm( pka->dir );
if( burried )
{
// cannot anticipate the straggling in the burrial layer, thus have to shoot onto a big surface
// TODO: take theta into account!
pka->pos[0] = ( dr250() - 0.5 ) * ( length + sample->w[0] );
pka->pos[1] = ( dr250() - 0.5 ) * ( length + sample->w[1] );
pka->pos[2] = -250.0; // overcoat thickness
}
else
{
if( theta == 0.0 )
{
// 0 degrees => start on top of wire!
pka->pos[2] = 0.0;
do
{
pka->pos[0] = dr250() * sample->w[0];
pka->pos[1] = dr250() * sample->w[1];
} while( sample->lookupMaterial(pka->pos ) == 0 );
}
else
{
// start on side _or_ top!
double vpos[3], t;
do
{
do
{
vpos[0] = dr250() * sample->w[0];
vpos[1] = 0.0;
vpos[2] = ( dr250() * ( length + diameter/tan(theta) ) ) - diameter/tan(theta);
t = ( 1.0 - sqrt( 1.0 - sqr( 2*vpos[0]/diameter - 1.0 ) ) ) * diameter/(2.0*pka->dir[1]);
// if we start beyond wire length (that would be inside the substrate) then retry
} while( t*pka->dir[2] + vpos[2] >= length );
// if first intersection with cylinder is at z<0 then check if we hit the top face instead
if( t*pka->dir[2] + vpos[2] < 0.0 )
t = -vpos[2]/pka->dir[2];
// start PKA at calculated intersection point
for( int i = 0; i < 3; i++ )
pka->pos[i] = t*pka->dir[i] + vpos[i];
} while( sample->lookupMaterial(pka->pos ) == 0 );
}
}
//cout << "START " << pka->pos[0] << ' ' << pka->pos[1] << ' ' << pka->pos[2] << ' ' << endl;
//continue;
pka->set_ef();
recoils.push( pka );
while( !recoils.empty() )
{
pka = recoils.front();
recoils.pop();
sample->averages( pka );
// do ion analysis/processing BEFORE the cascade here
if( pka->z1 == ion_prototype[s]->z1 )
{
//printf( "p1 %f\t%f\t%f\n", pka->pos[0], pka->pos[1], pka->pos[2] );
}
// follow this ion's trajectory and store recoils
trim->trim( pka, recoils );
// do ion analysis/processing AFTER the cascade here
// ion is in the wire
if( sample->lookupMaterial( pka->pos ) == sample->material[0] )
{
int l = pka->pos[2] / dl;
if( l >=0 && l < lx )
{
if( xyz_out )
{
xyz_data << simconf->scoef[pka->z1-1].sym << ' '
<< pka->pos[0]/100.0 << ' ' << pka->pos[1]/100.0 << ' ' << pka->pos[2]/100.0 << endl;
xyz_lines++;
}
if( ldat_out )
lbins[ ( pka->z1 == 5 ) ? 0 : 1 ][l]++;
}
}
// done with this recoil
delete pka;
}
}
}
// write xyz file
if( xyz_out )
{
stringstream xyz_name;
xyz_name << argv[1] << ".xyz";
ofstream xyz( xyz_name.str().c_str() );
xyz << xyz_lines << endl << endl << xyz_data.str();
xyz.close();
}
// write lbins file (atoms per nm^3)
if( ldat_out )
{
stringstream ldat_name;
ldat_name << argv[1] << ".ldat";
ofstream ldat( ldat_name.str().c_str() );
double dv = 1e-3 * dl * M_PI * 0.25 *sample->w[0] * sample->w[1]; // volume per bin in nm^3
for( int l = 0; l < lx; ++l )
ldat << l*dl << ' ' << lbins[0][l]/(mult*dv) << ' ' << lbins[1][l]/(mult*dv) << endl;
ldat.close();
}
delete[] lbins[0];
delete[] lbins[1];
return EXIT_SUCCESS;
}