ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/ripple/readh1.c
Revision: 1185
Committed: Fri May 21 20:07:10 2004 UTC (20 years, 1 month ago) by xsun
Content type: text/plain
File size: 22297 byte(s)
Log Message:
this is the ripple codes

File Contents

# Content
1 #include<stdio.h>
2 #include<string.h>
3 #include<stdlib.h>
4 #include<math.h>
5 #include<fftw.h>
6 #include<mkl_lapack64.h>
7
8 //extern void dsyev(char *jobz, char *uplo, int *n, double *a, int *lda,
9 // double *w, double *work, int *lwork,int *info);
10
11 //void direct(double rcut, double box, int n, int nstep, int maxbin);
12
13 //double* dsyev_ctof(double **in, int rows, int cols);
14
15 //void dsyev_ftoc2(double *in, double **out, int rows, int cols);
16
17 // Structures to store our data:
18
19 inline double roundMe( double x ){
20 return ( x >= 0 ) ? floor( x + 0.5 ) : ceil( x - 0.5 );
21 }
22
23 // coords holds the data for a single tethered dipole:
24 struct coords{
25 double pos[3]; // cartesian coords
26 double theta; // orientational angle relative to z axis
27 double phi; // orientational angle in x-y plane
28 double mu; // dipole strength
29 char name[30]; // an identifier for the type of atom
30 };
31
32 // state holds the current "configuration" of the entire system
33 struct system {
34 int nAtoms; // Number of Atoms in this configuration
35 struct coords *r; // The set of coordinates for all atoms
36 double beta; // beta = 1 /(kb*T)
37 double strength; // strength of the dipoles (Debye)
38 double z0; // default z axis position
39 double theta0; // default theta angle
40 double kz; // force constant for z displacement
41 double ktheta; // force constant for theta displacement
42 int nCycles; // How many cycles to do in total
43 int iCycle; // How many cycles have we done?
44 int nMoves; // How many MC moves in each cycle
45 int nSample; // How many cycles between samples
46 double Hmat[2][2]; // The information about the size of the per. box
47 double HmatI[2][2]; // The inverse box
48 double energy; // The current Energy
49 double dtheta; // maximum size of a theta move
50 double deltaz; // maximum size of a z move
51 double deltaphi; // maximum size of a phi move
52 int nAttempts; // number of MC moves that have been attempted
53 int nAccepts; // number of MC moves that have been accepted
54 int nx; // number of unit cells in x direction
55 int ny; // number of unit cells in y direction
56 struct system *next; // Next frame in the linked list
57 };
58
59 char *program_name; /* the name of the program */
60
61 // Function prototypes:
62 void usage(void);
63 void invertMat2(double a[2][2], double b[2][2]);
64 void wrapVector( double thePos[2], double Hmat[2][2], double HmatI[2][2]);
65
66 int main(argc, argv)
67 int argc;
68 char *argv[];
69 {
70 FILE *in_file;
71 char in_name[500];
72 char *eof_test, *foo;
73 char read_buffer[1000];
74 //int lineCount = 0;
75 int lineCount;
76 int nAtoms;
77 double *mag, *newmag;
78 int *present_in_old;
79 double *ux, *uy, *uz, p1;
80 double aLat, bLat;
81 int cells;
82 double sumZ, sumUx, sumUy, sumUz, sumP;
83 double interpsum, value;
84 int ninterp, px, py, newp;
85 int i, j, k, l, nloops;
86 int newx, newy, newindex, index;
87 int new_i, new_j, new_index;
88 int N, nframes;
89 double freq_x, freq_y, zero_freq_x, zero_freq_y, freq;
90 double maxfreqx, maxfreqy, maxfreq, dfreq;
91 double dx, dy, dx1, dy1, xTemp, yTemp, pt1x, pt1y, pt2x, pt2y;
92 int nx, ny;
93 int *samples;
94 double *bin, binmin, binmax, delr;
95 double *x, *y, *z;
96 double dh2, dh, sumh2, sumh, averh2, averh, t, delta, gamma, hi, proj;
97 double *corrhist, *h2hist;
98 double vrhist[100][500];
99 double sum_vrhist[1000], ave_vrhist[1000];
100 int vrsamp[1000][1000];
101 int *ophist;
102 double d[2], hcorr;
103 double hsum, hsum_temp, h2sum, have, h2ave, fluc, bigL, smallA, areaPerMolecule, area, h, h2;
104 int nbins, nbins2, opbin, whichbinx, whichbiny, whichbin2, n1, n2, n3, n4, m, selfx, selfy;
105
106 int which;
107 double omat[3][3];
108 double wrapMat[9];
109 double onethird, ordvals[5000];
110 double max;
111 double director[3][1000], vr[3][1000];
112 double sum_director[3], ave_director[3], sum_vr[3], ave_vr[3];
113 double orderpar[1000];
114 double sum_orderpar, sum2_orderpar, ave_orderpar, ave2_orderpar, err_orderpar;
115 char job, uplo;
116 int ndiag;
117 int nfilled;
118 double evals[100];
119 int lwork;
120 double* work;
121 int ifail;
122 int done;
123 char current_flag;
124
125 lineCount = 0;
126
127 program_name = argv[0];
128 if (argc >= 2)
129 strcpy(in_name, argv[1]);
130 /*
131 for(i = 1; i < argc; i++){
132 if(argv[i][0] == '-'){
133 done = 0;
134 j = 1;
135 current_flag = argv[i][j];
136 while( (current_flag != '\0') && ( !done ) ){
137 switch(current_flag){
138 case 'i':
139 i++;
140 strcpy( in_name, argv[i] );
141 done = 1;
142 break;
143 }
144 }
145 }
146 }
147 */
148
149 struct system* state;
150 struct system* temp_state;
151 struct coords* r;
152
153 lwork = 9;
154
155 work = (double *) malloc(lwork * sizeof(double));
156
157 onethird = 1.0 / 3.0;
158 ndiag = 3;
159 nfilled = 3;
160 job = 'V';
161 uplo = 'U';
162 ifail = 0;
163
164 nbins = 30;
165 nbins2 = 30;
166 binmin = 0.0;
167 binmax = 1.0;
168 delr = (binmax - binmin) / (double) nbins2;
169 corrhist = (double *) calloc(nbins*nbins, sizeof(double));
170 h2hist = (double *) calloc(nbins*nbins, sizeof(double));
171 ophist = (int *) calloc(nbins2, sizeof(int));
172 hsum = 0.0;
173 h2sum = 0.0;
174 sum_orderpar = 0.0;
175 sum2_orderpar = 0.0;
176 ave_orderpar = 0.0;
177 ave2_orderpar = 0.0;
178
179 for(i = 0; i < 3; i++){
180 for(j = 0; j < 1000; j++){
181 director[i][j] = 0.0;
182 vr[i][j] = 0.0;
183 }
184 }
185
186 for(i = 0; i < 1000; i++){
187 sum_vrhist[i] = 0.0;
188 ave_vrhist[i] = 0.0;
189 }
190
191 for(i = 0; i < 3; i++){
192 sum_director[i] = 0.0;
193 ave_director[i] = 0.0;
194 sum_vr[i] = 0.0;
195 ave_vr[i] = 0.0;
196 }
197
198 for (i = 0; i < nbins; i++) {
199 for (j = 0; j < nbins; j++) {
200 corrhist[nbins * i + j] = 0.0;
201 h2hist[nbins * i + j] = 0.0;
202 }
203 }
204
205 for (i = 0; i < 100; i++) {
206 for (j = 0; j < 500; j++) {
207 vrhist[i][j] = 0.0;
208 }
209 }
210
211 for(i = 0; i < nbins2; i++){
212 ophist[i] = 0;
213 }
214
215 t = 300;
216
217 in_file = fopen(in_name, "r");
218 if(in_file == NULL){
219 printf("Cannot open file \"%s\" for reading.\n", in_name);
220 exit(8);
221 }
222
223 nframes = 0;
224 n1 = 0;
225 n2 = 0;
226 n3 = 0;
227 n4 = 0;
228
229 // start reading the first frame
230
231 eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
232 nAtoms = atoi(read_buffer);
233 ux = (double *) calloc(nAtoms, sizeof(double));
234 uy = (double *) calloc(nAtoms, sizeof(double));
235 uz = (double *) calloc(nAtoms, sizeof(double));
236 lineCount++;
237
238 for(i = 0; i < nAtoms; i++){
239 ux[i] = 0.0;
240 uy[i] = 0.0;
241 uz[i] = 0.0;
242 }
243
244 state = (struct system *) malloc(sizeof(struct system));
245 state->next = NULL;
246 state->strength = 7.0;
247
248 while(eof_test != NULL){
249
250 nframes++;
251 (void)sscanf(read_buffer, "%d", &state->nAtoms);
252 N = 2 * state->nAtoms;
253
254 state->r = (struct coords *)calloc(N, sizeof(struct coords));
255
256 for(i = 0; i < 3; i++){
257 for(j = 0; j < 3; j++){
258 omat[i][j] = 0.0;
259 }
260 }
261
262 // read and the comment line and grab the time and box dimensions
263
264 eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
265 lineCount++;
266 if(eof_test == NULL){
267 printf("error in reading file at line: %d\n", lineCount);
268 exit(8);
269 }
270
271 foo = strtok( read_buffer, " ,;\t\n" );
272 (void)sscanf( read_buffer, "%d", &state->iCycle );
273
274 foo = strtok(NULL, " ,;\t\0");
275 if(foo == NULL){
276 printf("error in reading file at line: %d\n", lineCount);
277 exit(8);
278 }
279 (void)sscanf(foo, "%d", &state->nx);
280
281 nx = state->nx;
282
283 foo = strtok(NULL, " ,;\t\0");
284 if(foo == NULL){
285 printf("error in reading file at line: %d\n", lineCount);
286 exit(8);
287 }
288 (void)sscanf(foo, "%d", &state->ny);
289
290 ny = state->ny;
291
292 foo = strtok(NULL, " ,;\t\0");
293 if(foo == NULL){
294 printf("error in reading file at line: %d\n", lineCount);
295 exit(8);
296 }
297 (void)sscanf(foo, "%lf",&state->Hmat[0][0]);
298
299 foo = strtok(NULL, " ,;\t\0");
300 if(foo == NULL){
301 printf("error in reading file at line: %d\n", lineCount);
302 exit(8);
303 }
304 (void)sscanf(foo, "%lf",&state->Hmat[1][0]);
305
306 foo = strtok(NULL, " ,;\t\0");
307 if(foo == NULL){
308 printf("error in reading file at line: %d\n", lineCount);
309 exit(8);
310 }
311 (void)sscanf(foo, "%lf",&state->Hmat[0][1]);
312
313 foo = strtok(NULL, " ,;\t\0");
314 if(foo == NULL){
315 printf("error in reading file at line: %d\n", lineCount);
316 exit(8);
317 }
318 (void)sscanf(foo, "%lf",&state->Hmat[1][1]);
319
320 //Find HmatI:
321
322 invertMat2(state->Hmat, state->HmatI);
323
324 // Length of the two box vectors:
325
326 dx = sqrt(pow(state->Hmat[0][0], 2) + pow(state->Hmat[1][0], 2));
327 dy = sqrt(pow(state->Hmat[0][1], 2) + pow(state->Hmat[1][1], 2));
328
329 aLat = dx / (double)(state->nx);
330 bLat = dy / (double)(state->ny);
331
332 // FFT stuff depends on nx and ny, so delay allocation until we have
333 // that information
334
335 for (i=0;i<state->nAtoms;i++){
336
337 eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
338 lineCount++;
339 if(eof_test == NULL){
340 printf("error in reading file at line: %d\n", lineCount);
341 exit(8);
342 }
343
344 foo = strtok(read_buffer, " ,;\t\0");
345 (void)strcpy(state->r[i].name, foo); //copy the atom name
346
347 // next we grab the positions
348
349 foo = strtok(NULL, " ,;\t\0");
350 if(foo == NULL){
351 printf("error in reading postition x from %s\n"
352 "natoms = %d, line = %d\n",
353 in_name, state->nAtoms, lineCount );
354 exit(8);
355 }
356 (void)sscanf( foo, "%lf", &state->r[i].pos[0] );
357
358 foo = strtok(NULL, " ,;\t\0");
359 if(foo == NULL){
360 printf("error in reading postition y from %s\n"
361 "natoms = %d, line = %d\n",
362 in_name, state->nAtoms, lineCount );
363 exit(8);
364 }
365 (void)sscanf( foo, "%lf", &state->r[i].pos[1] );
366
367 foo = strtok(NULL, " ,;\t\0");
368 if(foo == NULL){
369 printf("error in reading postition z from %s\n"
370 "natoms = %d, line = %d\n",
371 in_name, state->nAtoms, lineCount );
372 exit(8);
373 }
374 (void)sscanf( foo, "%lf", &state->r[i].pos[2] );
375
376 foo = strtok(NULL, " ,;\t\0");
377 if(foo == NULL){
378 printf("error in reading angle phi from %s\n"
379 "natoms = %d, line = %d\n",
380 in_name, state->nAtoms, lineCount );
381 exit(8);
382 }
383 (void)sscanf( foo, "%lf", &state->r[i].phi );
384
385 foo = strtok(NULL, " ,;\t\0");
386 if(foo == NULL){
387 printf("error in reading unit vector x from %s\n"
388 "natoms = %d, line = %d\n",
389 in_name, state->nAtoms, lineCount );
390 exit(8);
391 }
392 (void)sscanf( foo, "%lf", &ux[i] );
393
394 foo = strtok(NULL, " ,;\t\0");
395 if(foo == NULL){
396 printf("error in reading unit vector y from %s\n"
397 "natoms = %d, line = %d\n",
398 in_name, state->nAtoms, lineCount );
399 exit(8);
400 }
401 (void)sscanf( foo, "%lf", &uy[i] );
402
403 foo = strtok(NULL, " ,;\t\0");
404 if(foo == NULL){
405 printf("error in reading unit vector z from %s\n"
406 "natoms = %d, line = %d\n",
407 in_name, state->nAtoms, lineCount );
408 exit(8);
409 }
410 (void)sscanf( foo, "%lf", &uz[i] );
411
412 state->r[i].theta = acos(uz[i]);
413
414 // The one parameter not stored in the dump file is the dipole strength
415 state->r[i].mu = state->strength;
416 }
417
418 hsum_temp = 0.0;
419 for (i = 0; i < state->nAtoms; i++) {
420
421 h = state->r[i].pos[2];
422 h2 = pow(h,2);
423
424 hsum_temp += h;
425 hsum += h;
426 h2sum += h2;
427
428 n1++;
429 }
430
431 for(i = 0; i < state->nAtoms; i++){
432
433 omat[0][0] += ux[i] * ux[i] - onethird;
434 omat[0][1] += ux[i] * uy[i];
435 omat[0][2] += ux[i] * uz[i];
436 omat[1][0] += uy[i] * ux[i];
437 omat[1][1] += uy[i] * uy[i] - onethird;
438 omat[1][2] += uy[i] * uz[i];
439 omat[2][0] += uz[i] * ux[i];
440 omat[2][1] += uz[i] * uy[i];
441 omat[2][2] += uz[i] * uz[i] - onethird;
442
443 }
444
445 for(i = 0; i < 3; i++){
446 for(j = 0; j < 3; j++){
447 omat[i][j] /= (double) state->nAtoms;
448 }
449 }
450
451 // temp_array = dsyev_ctof(omat, nfilled, nfilled);
452
453 for(j=0;j<3;j++)
454 for(i=0;i<3;i++)
455 wrapMat[i+j*3] = omat[i][j];
456
457 ifail = 0;
458 dsyev(&job, &uplo, &nfilled, wrapMat, &ndiag, evals, work, &lwork, &ifail);
459
460 for(j=0;j<3;j++)
461 for(i=0;i<3;i++)
462 omat[i][j] = wrapMat[i+j*3];
463
464 //dsyev_ftoc2(temp_array, omat, nfilled, nfilled);
465
466 //free(temp_array);
467
468 max = 0.0;
469 for(j = 0; j < 3; j++){
470 if(fabs(evals[j]) > max){
471 which = j;
472 max = fabs(evals[j]);
473 }
474 }
475
476 director[0][nframes-1] = omat[0][which];
477 director[1][nframes-1] = omat[1][which];
478 director[2][nframes-1] = omat[2][which];
479
480 vr[0][nframes-1] = fabs(director[1][nframes-1]);
481 vr[1][nframes-1] = fabs(-director[0][nframes-1]);
482 vr[2][nframes-1] = 0;
483
484 orderpar[nframes-1] = 1.5 * max;
485
486 opbin = (int) (orderpar[nframes-1] / delr);
487 if(opbin < nbins2) ophist[opbin] += 1;
488
489 for(i = 0; i < state->nAtoms; i++){
490 proj = vr[0][nframes-1] * state->r[i].pos[0] + vr[1][nframes-1] * state->r[i].pos[1];
491 hi = state->r[i].pos[2] - hsum_temp / (double) state->nAtoms;
492
493 whichbin2 = (int) ((proj / (vr[0][nframes-1] * dx + vr[1][nframes-1] * dy)) * nbins2);
494 vrhist[whichbin2][nframes-1] += hi;
495 vrsamp[whichbin2][nframes-1]++;
496 }
497
498 for(i = 0; i < state->nAtoms; i++){
499 for(j = 0; j < state->nAtoms; j++){
500
501 d[0] = state->r[j].pos[0] - state->r[i].pos[0];
502 d[1] = state->r[j].pos[1] - state->r[i].pos[1];
503
504 wrapVector(d, state->Hmat, state->HmatI);
505
506 whichbinx = (int) ((nbins-1) * (dx/2.0 + d[0]) / dx);
507 whichbiny = (int) ((nbins-1) * (dy/2.0 + d[1]) / dy);
508
509 //if (i == j) {
510 //printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny);
511 //}
512
513 //printf("d0 = %lf, d1 = %lf\n", d[0], d[1]);
514 //printf("wx = %d, wy = %d\n", whichbinx, whichbiny);
515
516 if (whichbinx >= nbins || whichbiny >= nbins) {
517 printf("off by one error\n");
518 printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny);
519 exit(0);
520 }
521 if (whichbinx < 0 || whichbiny < 0) {
522 printf("off by one error\n");
523 printf("whichbinx = %i, whichbiny = %i\n", whichbinx, whichbiny);
524 exit(0);
525 }
526
527 hcorr = state->r[j].pos[2] * state->r[i].pos[2];
528
529 corrhist[nbins * whichbinx + whichbiny] += hcorr;
530
531 dh = state->r[j].pos[2] - state->r[i].pos[2];
532 dh2 = pow(dh, 2);
533
534 h2hist[nbins * whichbinx + whichbiny] += dh2;
535
536 n2++;
537 }
538 }
539
540 temp_state = state->next;
541 state->next = NULL;
542
543 if (temp_state != NULL) {
544 free(temp_state->r);
545 free(temp_state);
546 }
547
548 // Make a new frame
549
550 temp_state = (struct system *) malloc(sizeof(struct system));
551 temp_state->next = state;
552 state = temp_state;
553 eof_test = fgets(read_buffer, sizeof(read_buffer), in_file);
554 lineCount++;
555 }
556
557
558 have = hsum / (double) n1;
559 h2ave = h2sum / (double) n1;
560 fluc = h2ave - pow(have, 2);
561
562 printf("# <h> = %lf\n", have);
563 printf("# <h2> = %lf\n", h2ave);
564 printf("# sigma(h) = %lf\n", sqrt(h2ave - have * have));
565 printf("# fluctuation = %lf\n", fluc);
566
567 for(i = 0; i < nframes; i++){
568 sum_orderpar += orderpar[i];
569 sum2_orderpar += pow(orderpar[i], 2);
570 }
571 ave_orderpar = sum_orderpar / (double) nframes;
572 ave2_orderpar = sum2_orderpar / (double) nframes;
573 err_orderpar = ave2_orderpar - pow(ave_orderpar, 2);
574
575 for(i = 0; i < nframes; i++){
576 sum_director[0] += director[0][i];
577 sum_director[1] += director[1][i];
578 sum_director[2] += director[2][i];
579 }
580 ave_director[0] = sum_director[0] / (double) nframes;
581 ave_director[1] = sum_director[1] / (double) nframes;
582 ave_director[2] = sum_director[2] / (double) nframes;
583
584 for(i = 0; i < nframes; i++){
585 sum_vr[0] += vr[0][i];
586 sum_vr[1] += vr[1][i];
587 sum_vr[2] += vr[2][i];
588 }
589 ave_vr[0] = sum_vr[0] / (double) nframes;
590 ave_vr[1] = sum_vr[1] / (double) nframes;
591 ave_vr[2] = sum_vr[2] / (double) nframes;
592
593 printf("# orderparameter = %lf\n", ave_orderpar);
594 printf("# error = %lf\n", err_orderpar);
595 printf("# director axis is ( %lf\t%lf\t%lf )\n",
596 ave_director[0], ave_director[1], ave_director[2]);
597 printf("# vr axis is ( %lf\t%lf\t%lf )\n", ave_vr[0], ave_vr[1], ave_vr[2]);
598
599 for(i = 0; i < nbins2; i++){
600 for(j = 0; j < nframes; j++){
601 sum_vrhist[i] += vrhist[i][j];
602 }
603 }
604
605 dx = sqrt(pow(state->Hmat[0][0], 2) + pow(state->Hmat[1][0], 2));
606 dy = sqrt(pow(state->Hmat[0][1], 2) + pow(state->Hmat[1][1], 2));
607
608 area = dx * dy;
609
610 bigL = sqrt(area);
611
612 areaPerMolecule = area / (double) state->nAtoms;
613
614 smallA = sqrt(areaPerMolecule);
615
616 gamma = t * log(bigL / smallA) / (2.0 * M_PI * fluc);
617
618 printf("# first gamma estimate = %lf\n", gamma);
619
620 printf("# \n");
621
622 for(i = 0; i < nbins2; i++){
623 ave_vrhist[i] = sum_vrhist[i] / (double) nframes;
624 printf("%lf\t%lf\n", (double) i * (ave_vr[0] * dx + ave_vr[1] * dy) / (double) nbins2,
625 ave_vrhist[i]);
626 }
627
628 selfx = (int) ((double)nbins / 2.0);
629 selfy = (int) ((double)nbins / 2.0);
630
631 /* for (i = 0; i < nbins; i++) { */
632 /* for (j = 0; j < nbins; j++) { */
633 /* printf("%lf\t", h2hist[nbins * i + j] / (double) n2); */
634 /* } */
635 /* printf("\n"); */
636 /* } */
637
638 free(work);
639 free(corrhist);
640 free(h2hist);
641 free(ux);
642 free(uy);
643 free(uz);
644 return 1;
645
646 }
647
648 double matDet2(double a[2][2]) {
649
650 double determinant;
651
652 determinant = (a[0][0] * a[1][1]) - (a[0][1] * a[1][0]);
653
654 return determinant;
655 }
656
657
658 void invertMat2(double a[2][2], double b[2][2]) {
659
660 double determinant;
661
662 determinant = matDet2( a );
663
664 if (determinant == 0.0) {
665 printf("Can't invert a matrix with a zero determinant!\n");
666 }
667
668 b[0][0] = a[1][1] / determinant;
669 b[0][1] = -a[0][1] / determinant;
670 b[1][0] = -a[1][0] / determinant;
671 b[1][1] = a[0][0] / determinant;
672 }
673
674 void matVecMul2(double m[2][2], double inVec[2], double outVec[2]) {
675 double a0, a1, a2;
676
677 a0 = inVec[0]; a1 = inVec[1];
678
679 outVec[0] = m[0][0]*a0 + m[0][1]*a1;
680 outVec[1] = m[1][0]*a0 + m[1][1]*a1;
681 }
682
683 void wrapVector( double thePos[2], double Hmat[2][2], double HmatInv[2][2]){
684
685 int i;
686 double scaled[2];
687
688 // calc the scaled coordinates.
689
690 matVecMul2(HmatInv, thePos, scaled);
691
692 for(i=0; i<2; i++)
693 scaled[i] -= roundMe(scaled[i]);
694
695 // calc the wrapped real coordinates from the wrapped scaled coordinates
696
697 matVecMul2(Hmat, scaled, thePos);
698
699 }
700
701 /* double* dsyev_ctof(double **in, int rows, int cols) */
702 /* { */
703 /* double *out; */
704 /* int i, j; */
705
706 /* out = (double *) calloc(rows * cols, sizeof(double)); */
707
708 /* if (!out){ */
709 /* printf("Fail to allocate memory\n"); */
710 /* exit(1); */
711 /* } */
712
713 /* for (i = 0; i < rows; i++) */
714 /* for (j = 0; j < cols; j++) */
715 /* out[i+j*cols] = in[i][j]; */
716
717 /* return(out); */
718 /* } */
719
720 /* void dsyev_ftoc2(double *in, double **out, int rows, int cols) */
721 /* { */
722 /* int i, j; */
723
724 /* for (i = 0; i < rows; i++) */
725 /* for (j = 0; j < cols; j++) */
726 /* out[i][j] = in[i+j*cols]; */
727 /* } */
728 /* void direct(double rcut, double box, int n, int nstep, int maxbin){ */
729
730 /* int bin, maxbin, nbins, i, j, k, n, bind, which; */
731 /* int hist[maxbin], histd[maxbin], startstep; */
732 /* int nstep, stopstep, ndiag, nfilled, ifail, lwork; */
733 /* double delr, rijsp, rxij, ryij, rzij, rij; */
734 /* double delrd, rijsqd, rijd, orderpar[1000], nideal; */
735 /* double omat[3][3], evals[100], cons, rlower; */
736 /* double rcut, box, dens, director[3][1000], rupper; */
737 /* double rx[1000][1000], ry[1000][1000], rz[1000][1000]; */
738 /* double ux[1000][1000], uy[1000][1000], uz[1000][1000]; */
739 /* double vx[1000][1000], vy[1000][1000], vz[1000][1000]; */
740 /* double jx[1000][1000], jy[1000][1000], jz[1000][1000]; */
741 /* double grd[5000], gr[5000], max, binmin, binmax; */
742 /* double onethird, ordvals[5000]; */
743 /* char job, uplo; */
744 /* int ndiag; */
745 /* int nfilled; */
746 /* double omat[3][3]; */
747 /* double evals[100]; */
748 /* double work[]; */
749 /* int lwork; */
750 /* int ifail; */
751
752 /* lwork = 9; */
753 /* work = (double *)calloc(lwork, sizeof(double)); */
754
755 /* onethird = 1.0 / 3.0; */
756 /* ndiag = 3; */
757 /* nfilled = 3; */
758 /* job = 'V'; */
759 /* uplo = 'U'; */
760 /* ifail = 0; */
761
762 /* binmin = 0.0; */
763 /* binmax = 1.0; */
764 /* delr = (binmax - binmin) / (double) maxbin; */
765
766 /* for(i = 0; i < maxbin; i++){ */
767
768 /* ordvals(i) = 0.0; */
769 /* hist(i) = 0.0; */
770
771 /* } */
772
773 /* for(i = 0; i < stopstep; i++){ */
774
775 /* for(j = 0; j < 3; j++){ */
776 /* for(k = 0; k < 3; k++){ */
777 /* omat[j][k] = 0.0; */
778 /* } */
779 /* } */
780
781 /* for(j = 0; j < n; j++){ */
782
783 /* omat[1][1] = omat[1][1] + ux[j][i] * ux[j][i] - onethird; */
784 /* omat[1][2] = omat[1][2] + ux[j][i] * uy[j][i]; */
785 /* omat[1][3] = omat[1][3] + ux[j][i] * uz[j][i]; */
786 /* omat[2][1] = omat[2][1] + uy[j][i] * ux[j][i]; */
787 /* omat[2][2] = omat[2][2] + uy[j][i] * uy[j][i] - onethird; */
788 /* omat[2][3] = omat[2][3] + uy[j][i] * uz[j][i]; */
789 /* omat[3][1] = omat[3][1] + uz[j][i] * ux[j][i]; */
790 /* omat[3][2] = omat[3][2] + uz[j][i] * uy[j][i]; */
791 /* omat[3][3] = omat[3][3] + uz[j][i] * uz[j][i] - onethird; */
792
793 /* } */
794
795
796 /* for(j = 0; j < 3; j++){ */
797 /* for(k = 0; k < 3; k++){ */
798 /* omat[j][k] = omat[j][k] / (double) n; */
799 /* } */
800 /* } */
801
802 /* dsyev_(job, uplo, nfilled, omat, ndiag, evals, work, lwork, ifail); */
803
804 /* max = 0.0; */
805 /* for(j = 0; j < 3; j++){ */
806 /* if(fabs(evals(j)) > max){ */
807 /* which = j; */
808 /* max = fabs(evals(j)); */
809 /* } */
810 /* } */
811
812 /* director[1][i] = omat[1][which]; */
813 /* director[2][i] = omat[2][which]; */
814 /* director[3][i] = omat[3][which]; */
815
816 /* orderpar(i) = 1.5 * max; */
817
818 /* bin = (int) (orderpar(i) / delr) + 1; */
819
820 /* if(bin < maxbin) */
821 /* hist(bin) = hist(bin) + 1; */
822 /* } */
823
824 /* cons = 1.0; */
825 /* for(bin = 0; bin < maxbin; bin++){ */
826
827 /* rlower = (double) (bin - 1) * delr; */
828 /* rupper = rlower + delr; */
829 /* ordvals(bin) = rlower + (delr / 2.0); */
830 /* nideal = cons * (pow(rupper, 3) - pow(rlower, 3)); */
831 /* gr(bin) = (double) (hist(bin)) / (double) nstep /nideal; */
832
833 /* } */
834 /* } */