-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytrim_clusters.cc
330 lines (266 loc) · 10.1 KB
/
mytrim_clusters.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
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/***************************************************************************
* 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 "simconf.h"
#include "element.h"
#include "material.h"
#include "sample_clusters.h"
#include "ion.h"
#include "trim.h"
#include "invert.h"
#include "functions.h"
int main(int argc, char *argv[])
{
char fname[200];
if( argc != 4 ) // 2
{
fprintf( stderr, "syntax:\n%s basename r Cbfactor\n\nCbfactor=1 => 7e-4 bubbles/nm^3\n", argv[0] );
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
sampleClusters *sample = new sampleClusters( 400.0, 400.0, 400.0 );
//sampleClusters *sample = new sampleClusters( 200.0, 200.0, 200.0 );
// initialize trim engine for the sample
snprintf( fname, 199, "%s.phon", argv[1] );
//FILE *phon = fopen( fname, "wt" );
//trimPhononOut *trim = new trimPhononOut( sample, phon );
trimBase *trim = new trimBase( sample );
//trimBase *trim = new trimPrimaries( sample );
//double r = 10.0;
double r = atof( argv[2] ); //10.0;
double Cbf = atof( argv[3] );
//sample->bc[0] = CUT; // no pbc in x dir
sample->initSpatialhash( int( sample->w[0] / r ) - 1,
int( sample->w[1] / r ) - 1,
int( sample->w[2] / r ) - 1 );
// double atp = 0.1; // 10at% Mo 90at%Cu
double v_sam = sample->w[0] * sample->w[1] * sample->w[2];
double v_cl = 4.0/3.0 * M_PI * cub(r);
int n_cl; // = atp * scoef[29-1].atrho * v_sam / ( v_cl * ( ( 1.0 - atp) * scoef[42-1].atrho + atp * scoef[29-1].atrho ) );
n_cl = v_sam * 7.0e-7 * Cbf ; // Ola06 7e-4/nm^3
//fprintf( stderr, "adding %d clusters to reach %fat%% Mo\n", n_cl, atp * 100.0 );
fprintf( stderr, "adding %d clusters...\n", n_cl );
// cluster surfaces must be at least 25.0 Ang apart
sample->addRandomClusters( n_cl, r, 15.0 );
//sample->addCluster( 100.0, 100.0, 100.0, 10.0 );
// write cluster coords with tag numbers
snprintf( fname, 199, "%s.clcoor", argv[1] );
FILE *ccf = fopen( fname, "wt" );
for( int i = 0; i < sample->cn; i++)
fprintf( ccf, "%f %f %f %f %d\n", sample->c[0][i], sample->c[1][i], sample->c[2][i], sample->c[3][i], i );
fclose( ccf );
fprintf( stderr, "sample built.\n" );
//return 0;
materialBase *material;
elementBase *element;
// UO2
material = new materialBase( 10.0 ); // rho
element = new elementBase;
element->z = 92; // U
element->m = 235.0;
element->t = 1.0;
material->element.push_back( element );
element = new elementBase;
element->z = 16; // O
element->m = 32.0;
element->t = 2.0;
material->element.push_back( element );
material->prepare(); // all materials added
sample->material.push_back( material ); // add material to sample
// xe bubble
material = new materialBase( 3.5 ); // rho
element = new elementBase;
element->z = 54; // Xe
element->m = 132.0;
element->t = 1.0;
// element->t = 0.002;
material->element.push_back( element );
material->prepare();
sample->material.push_back( material ); // add material to sample
// 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], dif2[3];
massInverter *m = new massInverter;
energyInverter *e = new energyInverter;
double A1, A2, Etot, E1, E2;
int Z1, Z2;
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], pos2[3];
ionMDtag *ff1, *ff2, *pka;
int id = 1;
// 1000 fission events
for( int n = 0; n < 1000; n++ ) // 2000 ff
{
if( n % 10 == 0 ) fprintf( stderr, "pka #%d\n", n+1 );
ff1 = new ionMDtag;
ff1->gen = 0; // generation (0 = PKA)
ff1->tag = -1;
ff1->md = 0;
ff1->id = simconf->id++;
// generate fission fragment data
A1 = m->x( dr250() );
//A1 = 131;
A2 = 235.0 - A1;
Etot = e->x( dr250() );
E1 = Etot * A2 / ( A1 + A2 );
//E1 = 100;
E2 = Etot - E1;
Z1 = round( ( A1 * 92.0 ) / 235.0 );
//Z1 = 54;
Z2 = 92 - Z1;
ff1->z1 = Z1;
ff1->m1 = A1;
ff1->e = E1 * 1.0e6;
// ff1->z1 = 53;
// ff1->m1 = 127;
// ff1->e = 70.0 * 1.0e6;
do
{
for( int i = 0; i < 3; i++ ) ff1->dir[i] = dr250() - 0.5;
norm = v_dot( ff1->dir, ff1->dir );
}
while( norm <= 0.0001 );
/*
norm = 1.0;
ff1->dir[0] = 1.0;
ff1->dir[1] = 0.0;
ff1->dir[2] = 0.0;
*/
v_scale( ff1->dir, 1.0 / sqrtf( norm ) );
// random origin (outside cluster!)
do {
for( int i = 0; i < 3; i++ ) ff1->pos[i] = dr250() * sample->w[i];
} while( sample->lookupCluster( ff1->pos ) >= 0 );
ff1->set_ef();
recoils.push( ff1 );
ff2 = new ionMDtag( *ff1 ); // copy constructor
//ff1->id = simconf->id++;
// reverse direction
for( int i = 0; i < 3; i++ ) ff2->dir[i] *= -1.0;
ff2->z1 = Z2;
ff2->m1 = A2;
ff2->e = E2 * 1.0e6;
ff2->set_ef();
recoils.push( ff2 );
//fprintf( stderr, "A1=%f Z1=%d (%f MeV)\tA2=%f Z2=%d (%f MeV)\n", A1, Z1, E1, A2, Z2, E2 );
while( !recoils.empty() )
{
pka = dynamic_cast<ionMDtag*>(recoils.front());
recoils.pop();
sample->averages( pka );
// do ion analysis/processing BEFORE the cascade here
if( pka->z1 == 54 )
{
// mark the first recoil that falls into the MD energy gap with 1 (child generations increase the number)
if( pka->e > 200 && pka->e < 12000 && pka->md == 0 ) pka->md = 1;
if( pka->gen > 0 )
{
// output energy and recoil generation
fprintf( erec, "%f\t%d\t%d\n", pka->e, pka->gen, pka->md );
}
if( pka->tag >= 0 )
{
for( int i = 0; i < 3; i++ )
{
dif[i] = sample->c[i][pka->tag] - pka->pos[i];
pos2[i] = pka->pos[i];
if( sample->bc[i] == sampleBase::PBC ) dif[i] -= round( dif[i] / sample->w[i] ) * sample->w[i];
pos1[i] = pka->pos[i] + dif[i];
//printf( "%f\t%f\t%f\n", sample->c[i][pka->tag], pka->pos[i], pos1[i] );
}
//printf( "\n" );
//if(pka->z1 == 54 && pka->gen > 0 && pka->tag >= 0 ) printf( "clust %f %f %f %d", pos1[0], pos1[1], pos1[2], pka->id );
}
}
// follow this ion's trajectory and store recoils
// printf( "%f\t%d\n", pka->e, pka->z1 );
//pka->md = id++;
//printf( "\nstart %f %f %f %d %d %d\n", pka->pos[0], pka->pos[1], pka->pos[2], pka->z1, pka->md, pka->id );
trim->trim( pka, recoils );
//fprintf( phon, "%f %f %f %f %d %d\n", pka->e, pka->pos[0], pka->pos[1], pka->pos[2], pka->z1, pka->id );
// do ion analysis/processing AFTER the cascade here
// pka is Xe
if( pka->z1 == 54 )
{
// output
//printf( "%f %f %f %d\n", pka->pos[0], pka->pos[1], pka->pos[2], pka->tag );
// print out distance to cluster of origin center (and depth of recoil)
if( pka->tag >= 0 )
{
for( int i = 0; i < 3; i++ )
{
dif[i] = pos1[i] - pka->pos[i]; // distance to cluster center
dif2[i] = pos2[i] - pka->pos[i]; // total distance it moved
}
fprintf( rdist, "%f %d %f %f %f %f\n", sqrt( v_dot( dif, dif ) ), pka->md, pka->pos[0], pka->pos[1], pka->pos[2], sqrt( v_dot( dif2, dif2 ) ) );
}
// do a random walk
/* jumps = 0;
do
{
material = sample->lookupLayer( pka->pos );
if( material->tag >= 0 ) break;
do
{
for( int i = 0; i < 3; i++ ) pka->dir[i] = dr250() - 0.5;
norm = v_dot( pka->dir, pka->dir );
}
while( norm <= 0.0001 );
v_scale( pka->dir, jmp / sqrtf( norm ) );
for( int i = 0; i < 3; i++ ) pka->pos[i] += pka->dir[i];
jumps++;
}
while ( pka->pos[0] > 0 && pka->pos[0] < sample->w[0] );
if( material->tag >= 0 && jumps > 0 )
fprintf( stderr, "walked to cluster %d (originated at %d, %d jumps)\n", material->tag, pka->tag, jumps ); */
}
// 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 );
return EXIT_SUCCESS;
}