-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytrim_layers.cc
212 lines (171 loc) · 6.11 KB
/
mytrim_layers.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
/***************************************************************************
* 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 <string>
#include <limits>
using namespace std;
#include "simconf.h"
#include "element.h"
#include "material.h"
#include "sample_layers.h"
#include "ion.h"
#include "trim.h"
#include "invert.h"
#include "functions.h"
int main(int argc, char *argv[])
{
char fname[200];
if( argc != 2 ) // 2
{
cerr << "syntax:\n" << argv[0] << " basename" << endl;
return 1;
}
// 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 = false;
simconf->tmin = 0.2;
//simconf->tmin = 0.2;
// initialize sample structure
double sx, sy, sz;
cin >> sx >> sy >> sz;
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
cout << "SS " << sx << ' ' << sy << ' ' << sz << endl;
const int nmax = 10000;
cout << "NN " << nmax << " PKAs" << endl;
sampleLayers *sample = new sampleLayers( sx, sy, sz );
//trimBase *trim = new trimBase( sample );
trimBase *trim = new trimRecoils( sample );
// Read Materials description from stdin
int nlayer;
double lthick, lrho, nelem;
string lename;
cin >> nlayer;
cin.ignore( numeric_limits<streamsize>::max(), '\n' );
cout << "n_layers=" << nlayer << endl;
materialBase *material;
elementBase *element;
for( int i = 0; i < nlayer; i++ )
{
cin >> lename >> lthick >> lrho >> nelem;
cin.ignore( numeric_limits<streamsize>::max(), '\n');
cout << "Layer: " << lename << " d=" << lthick << "Ang rho="
<< lrho << "g/ccm n_elements=" << nelem << endl;
material = new materialBase( lrho ); // rho
for( int j = 0; j < nelem; j++ )
{
element = new elementBase;
cin >> lename >> element->z >> element->m >> element->t;
cin.ignore( numeric_limits<streamsize>::max(), '\n');
cout << " Element: " << lename << " Z=" << element->z
<< " m=" << element->m << " fraction=" << element->t << endl;
material->element.push_back( element );
}
material->prepare(); // all elements added
sample->material.push_back( material ); // add material to sample
sample->layerThickness.push_back( lthick );
}
// create a FIFO for recoils
queue<ionBase*> recoils;
double norm;
double jmp = 2.7; // diffusion jump distance
int jumps;
double dif[3];
massInverter *m = new massInverter;
energyInverter *e = new energyInverter;
//double A = 74.0, E = 1.0e5; int Z = 36; // 100keV Kr
double A = 131.0, E = 5.0e5; int Z = 54; // 500keV Xe
snprintf( fname, 199, "%s.Erec", argv[1] );
FILE *erec = fopen( fname, "wt" );
snprintf( fname, 199, "%s.dist", argv[1] );
FILE *rdist = fopen( fname, "wt" );
double pos1[3];
ionBase *ff1, *ff2, *pka;
int id = 1;
int nrec = 0;
double sum_r2, opos[3];
// 1000 PKA
for( int n = 0; n < nmax; n++ )
{
if( n % 100 == 0 ) fprintf( stderr, "pka #%d\n", n+1 );
ff1 = new ionBase;
ff1->gen = 0; // generation (0 = PKA)
ff1->tag = -1;
ff1->id = simconf->id++;
ff1->z1 = Z;
ff1->m1 = A;
ff1->e = E;
ff1->dir[0] = 1;
ff1->dir[1] = 0;
ff1->dir[2] = 0;
ff1->pos[0] = 0;
ff1->pos[1] = sample->w[1] / 2.0;
ff1->pos[2] = sample->w[2] / 2.0;
ff1->set_ef();
recoils.push( ff1 );
while( !recoils.empty() )
{
pka = recoils.front();
recoils.pop();
sample->averages( pka );
// do ion analysis/processing BEFORE the cascade here
//fprintf( erec, "%f\t%d\t%d\n", pka->e, pka->gen, pka->z1 );
for( int i = 0; i < 3; i++ )
opos[i] = pka->pos[i];
// follow this ion's trajectory and store recoils
//if( pka->z1 == 29 || pka->z1 == Z )
//if( pka->z1 == 29 || pka->z1 == Z )
trim->trim( pka, recoils );
// do ion analysis/processing AFTER the cascade here
if( pka->z1 != Z )
{
for( int i = 0; i < 3; i++ )
sum_r2 += sqr( opos[i] - pka->pos[i] );
nrec++;
}
// pka is O or Ag
//if( pka->z1 == 29 && pka->pos[0] >= 500.0 )
if( pka->z1 == 29 )
{
// output
printf( "RP %f %d %d\n", pka->pos[0], n, pka->gen);
}
// done with this recoil
delete pka;
// this should rather be done with spawnRecoil returning false
//if( simconf->primariesOnly ) while( !recoils.empty() ) { delete recoils.front(); recoils.pop(); };
}
}
fclose( rdist );
fclose( erec );
cout << "n=" << nrec << " sum_r2=" << sum_r2 << endl;
return EXIT_SUCCESS;
}