-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathptmc_data.c
More file actions
335 lines (296 loc) · 9.74 KB
/
Copy pathptmc_data.c
File metadata and controls
335 lines (296 loc) · 9.74 KB
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
331
332
333
334
335
/*! \file ptmc_data.c
* \brief This program processes the data produced by ptmc.c
*
* Input : The program requieres 1 or 2 files depending on wether
* the radial distribution function will be calculated or
* not. These files should be passes at the time of
* execution. It is assumed that this program will be run
* in the same directory in which the output of files of
* ptmc.c are located. \n\n\n
*
* The first file that should be passed is the same file
* that was passed as first argument to the main program
* ptmc.c . See the documentation of ptmc.c and ptmc.h
*
* The second file should only be passed if the macro
* CALCULATE_RDF was set to a nonzero value in the file
* ptmc.h when the ptmc.c was compiled, which implies
* that ptmc.c also calculated values of the radial
* distribution function. In such case the file that should
* be passed is the 3 file that was passed as an argument
* to ptmc.c, i.e., the configuration file for the
* radial distribution functions.
*
* Output : Assuming the ptmc_data is run in the same directory
* in which the output of the ptmc is the program will
* process the data files generated by ptmc.
*
* The most important file it will generate is
* data.dat this file will contain the following
* information in columns: \n
* 1. Replica number, i. \n
* 2. Temperature of the replica, ti.\n
* 3. Internal energy of the replica ui. \n
* 4. Constant volume heat capacity, C_vi. \n
* 5. Number of times the replica i tried to move out of
* of the simulation box. \n
* 6. % of rejected moves. \n
* 7. Number exchanges attempted between replica i and i+1.
* \n
* 8. Number of exchanges between replica i and i+1.\n
* 9. Ratio of exchanges and attempted exchanges between
* replica i and replica i+1.\n\n
*
* If the macro NUMBER_OF_DOPANTS was set to a nonzero value
* then the following extra column will appear:\n
* 10. Ratio of accepted exchanges between the two
* different types of atoms.\n\n
*
* Then the program will also generate the following files
* for each replica i:\n\n
*
* energy[i].dat: the first column of this file will contain
* the energy and the second the probability having that
* energy for the ith replica.\n\n
*
* If CALCULATE_RDF was set to a nonzero value then also
* the following files will be generated:\n\n
*
* radialA[i].dat: the first column of this file will contain
* the distance from the center of mass and the second the
* probability of the particles of the matrix being at that
* distance from the center of mass.\n\n
*
* If also NUMBER_OF_DOPANTS is set to a non zero then
* also the following files will be generated:
* radialB[i].dat: the first column of this file will contain
* the distance from the center of mass and the second the
* probability of the particles of the dopant being at that
* distance from the center of mass.\n\n
*
* If the macro CALCULATE_RDF is set to a nonzero value
* then this program will also generate a file called
* rdf_data.dat that will contain the following:\n
* 1. Replica number, i. \n
* 2. Temperature of the replica, ti.\n
* 3. Average position of the matrix atoms measured from the
* geometric center of the distribution.\n
* 4. Standard deviation of the main position of the matrix
* atoms from the geometric center of the distribution.\n
*
* If also NUMBER_OF_DOPANTS is non zero the the two extra
* colums will be produced:\n
*
* 5. Average position of the dopant atoms measured from the
* geometric center of the distribution.\n
* 6. Standard deviation of the main position of the dopant
* atoms from the geometric center of the distribution.\n
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include"ptmc.h"
int
main (int argc, char *argv[])
{
char charU[MAX_LENGTH_CHAR], average_save[MAX_LENGTH_CHAR],
charE[MAX_LENGTH_CHAR];
int gg, i, j, nU;
int nprocs;
int n, swap_freq, mc_steps, save_freq, eq_steps;
double t0, tf, U0, Uf, dU, box_radius;
double tried, accepted;
double counter, countrej, outmoves, normU, U, U2;
double t;
FILE *np;
FILE *exc;
FILE *in;
FILE *out;
FILE *dat;
#if CALCULATE_RDF
FILE *rdf_dat;
#endif
#if CALCULATE_RDF
char rpf1char[MAX_LENGTH_CHAR], ordchar[MAX_LENGTH_CHAR],
rdf1char[MAX_LENGTH_CHAR], pos[MAX_LENGTH_CHAR];
int rdf_freq, nradial;
double radialmin, radialmax, dradial, r;
double rpf1a, rpf1a2, normrpf1;
#if NUMBER_OF_DOPANTS
char rpf2char[MAX_LENGTH_CHAR], rdf2char[MAX_LENGTH_CHAR];
double rpf2a, rpf2a2, normrpf2;
#endif
#endif
#if NUMBER_OF_DOPANTS
double swap, swap_rejected;
#endif
dat = fopen ("data.dat", "w");
#if CALCULATE_RDF
rdf_dat=fopen ("rdf_data.dat", "w");
#endif
np = fopen ("nprocs.dat", "r");
exc = fopen ("exchange.dat", "r");
gg = fscanf (np, "%d", &nprocs);
fprintf (stdout, "%d\n", nprocs);
in = fopen (argv[1], "r");
if (in == NULL)
{
fprintf (stdout, "The input file %s was not found\n", argv[1]);
exit (0);
}
else
{
gg = fscanf (in, "%d %d %d %d %d %lf %lf %lf %lf %lf %lf",
&n, &swap_freq, &mc_steps, &save_freq, &eq_steps, &t0, &tf,
&U0, &Uf, &dU, &box_radius);
fclose (in);
}
#if CALCULATE_RDF
in = fopen (argv[2], "r");
if (in == NULL)
{
fprintf (stdout, "The input file %s was not found\n", argv[2]);
exit (0);
}
else
{
gg =
fscanf (in, "%d %lf %lf %lf", &rdf_freq, &radialmin, &radialmax,
&dradial);
fclose (in);
}
nradial = (int) ((radialmax - radialmin) / dradial);
#endif
nU = (int) ((Uf - U0) / dU);
for (i = 1; i < nprocs; i++)
{
/****************************************************************
* Write the names of the input files in their respective strings
***************************************************************/
sprintf (charU, "e%d.dat", i);
sprintf (charE, "energy%d.dat", i);
sprintf (average_save, "avs%d.dat", i);
#if CALCULATE_RDF
sprintf (rpf1char, "rpfA%d.dat", i);
sprintf (rdf1char, "radialA%d.dat", i);
#if NUMBER_OF_DOPANTS
sprintf (rpf2char, "rpfB%d.dat", i);
sprintf (rdf2char, "radialB%d.dat", i);
#endif
sprintf (ordchar, "ord%d.dat", i);
sprintf (pos, "pos%d.dat", i);
#endif
/*******************************************************************
* Generates energy Historams with their proper origin
******************************************************************/
in = fopen (charU, "r");
out = fopen (charE, "w");
for (j = 0; j < nU; j++)
{
gg = fscanf (in, "%lf", &U);
fprintf (out, "%lf %lf\n", U0 + j * dU + dU / 2, U / (nU));
}
fclose (in);
fclose (out);
/*******************************************************************
* Calculates the main observables such as internal energy and
* C_v for each replica running at a different temperature
******************************************************************/
gg = fscanf (np, "%lf", &t);
gg = fscanf (exc, "%lf %lf", &tried, &accepted);
in = fopen (average_save, "r");
if (in == NULL)
{
fprintf (stdout, "The file %s was not found\n", average_save);
}
else
{
while (!feof (in))
{
#if NUMBER_OF_DOPANTS
gg = fscanf (in, "%lf %lf %lf %lf %lf %lf %lf %lf",
&counter, &countrej, &outmoves, &normU, &U, &U2,
&swap, &swap_rejected);
#else
gg = fscanf (in, "%lf %lf %lf %lf %lf %lf",
&counter, &countrej, &outmoves, &normU, &U, &U2);
#endif
}
fclose (in);
fprintf (dat, "%d %lf %lf %lf %lf %lf %lf %lf %lf ", i, t, U / normU,
((U2 / normU) - (U / normU) * (U / normU)) / (t * t),
outmoves, countrej / counter, tried, accepted,
accepted / tried);
#if NUMBER_OF_DOPANTS
fprintf (dat, "%lf ", swap_rejected / swap);
#endif
fprintf (dat, "\n");
}
/*******************************************************************
* Calculates the observables related to the RDFS
* for each replica running at a different temperature
******************************************************************/
#if CALCULATE_RDF
in = fopen (rpf1char, "r");
out = fopen (rdf1char, "w");
for (j = 0; j < nradial; j++)
{
gg = fscanf (in, "%lf", &r);
fprintf (out, "%lf %lf\n", radialmin + j * dradial + dradial / 2,
r / (nradial));
}
fclose (in);
fclose (out);
#if NUMBER_OF_DOPANTS
in = fopen (rpf2char, "r");
out = fopen (rdf2char, "w");
for (j = 0; j < nradial; j++)
{
gg = fscanf (in, "%lf", &r);
fprintf (out, "%lf %lf\n", radialmin + j * dradial + dradial / 2,
r / (nradial));
}
fclose (in);
fclose (out);
#endif
#endif
#if CALCULATE_RDF
in = fopen (ordchar, "r");
if (in == NULL)
{
fprintf (stdout, "The file %s was not found\n", ordchar);
}
else
{
while (!feof (in))
{
#if NUMBER_OF_DOPANTS
gg =
fscanf (in, "%lf %lf %lf %lf %lf %lf", &normrpf1, &rpf1a,
&rpf1a2, &normrpf2, &rpf2a, &rpf2a2);
#else
gg = fscanf (in, "%lf %lf %lf", &normrpf1, &rpf1a, &rpf1a2);
#endif
}
#endif
fclose (in);
}
#if CALCULATE_RDF
fprintf (rdf_dat, "%d %lf %lf %lf ", i, t, rpf1a / normrpf1,
sqrt (rpf1a2 / normrpf1 -
(rpf1a / normrpf1) * (rpf1a / normrpf1)));
#if NUMBER_OF_DOPANTS
fprintf (rdf_dat, "%lf %lf", rpf2a / normrpf2,
sqrt (rpf2a2 / normrpf2 -
(rpf2a / normrpf2) * (rpf2a / normrpf2)));
#endif
fprintf (rdf_dat, "\n");
#endif
}
fclose (np);
fclose (dat);
#if CALCULATE_RDF
fclose (rdf_dat);
#endif
return 0;
}