-
Notifications
You must be signed in to change notification settings - Fork 0
/
lmp2sqt.c
2202 lines (2026 loc) · 61.8 KB
/
lmp2sqt.c
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
* \file lmp2sqt.c
* \brief
*
* \author KIM Hyeok (kh), [email protected]
*
* \internal
* Created: 2017-05-29
* Revision: 2019-04-12
* Compiler: gcc
* Organization: Konkuk University
* Copyright: Copyright (c) 2017, KIM Hyeok
*
* This source code is released for free distribution under the terms of the
* GNU General Public License as published by the Free Software Foundation.
*/
#include "lmp2sqt.h"
#include "snapshot.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <getopt.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include <math.h>
#include "snapshot.h"
#include <time.h>
#define DIM 3
//#define flagSelf 1
typedef enum {N_I, N_R} VType;
typedef struct {
char *vName;
void *vPtr;
VType vType;
size_t vLen ;
int vStatus;
} NameList;
#define NameI(x) \
{#x, &x, N_I, sizeof (x) / sizeof (int), 0}
#define NameR(x) \
{#x, &x, N_R, sizeof (x) / sizeof (real),0}
typedef struct {
void *vPtr;
VType vType;
int vLen;
} ValList;
#define ValI(x) \
{&x, N_I, sizeof (x) / sizeof (int)}
#define ValR(x) \
{&x, N_R, sizeof (x) / sizeof (real)}
#define NP_I \
((int *) (nameList[k].vPtr) + j)
#define NP_R \
((real *) (nameList[k].vPtr) + j)
/*!
* \brief Data List
* kVal
* deltaT
* mass
* rVal
* limitCorrAv
* limitCorrAv
* nCBuffer = number of simul. time seq
* nCSpatial = number of spatial seq
* nCTime = number of time seq
* nCSkip = number of time seq
*
*/
#define DATALIST { \
NameR (kVal), \
NameR (deltaT), \
NameR (mass), \
NameR (rVal), \
NameI (limitCorrAv),\
NameI (nCBuffer), \
NameI (nCSpatial), \
NameI (nCTime), \
NameI (nCSkip) \
}
NameList nameList[] = DATALIST;
bool flag_f=false;
bool flag_F=false;
bool flag_t=false;
bool flag_s=false;
bool flag_d=false;
bool flag_magnet=false;
bool flag_velocity=false;
char inputFilename[100]= "in.lmp2sqt";
void UpdateNameList ();
void PrintNameList2File (FILE *fp);
int GetNameList ();
int Number_call_Print =0;
int flag_global_alloc =0 ;
int flag_global_alloc_more =0 ;
void PrintSpacetimeCorr_binary ( FILE*);
char datetime_data[100] ;
int main(int argc, char** argv) {
char filename[100];
int n_snap;
int opt_num, opt;
int full_n_snaps=0, full_n_snaps_index=0,progress=-1;
bool files_on [argc+3];
long int num_data [argc+3];
limitCorrAv = 0;
time_t rawtime;
struct tm* timeinfo;
rawtime = time(NULL);
timeinfo = localtime(&rawtime);
// strftime(datetime_data,100,"%y%m%d_%H%M", timeinfo);
strftime(datetime_data,100,"%y%m%d", timeinfo);
char help_message[2000];
sprintf(help_message,"%s -f -t -s fn_Dt filename 2 ... \n"
" options: \n"
" -f) collective full calculation required long time and large memory \n"
" -F) collective self calculation required long time and large memory \n"
" space-time, twotime, stress etc...\n"
" -t) only twotime correlation \n"
" -s) only twotime correlation + stress tensor \n"
" -V) velocity correlation \n"
" -M) magnet correlation \n"
" -d) Get Amount of dynamic memory allocation \n"
" -i) argment filename for input variable \n"
, argv[0]);
if( argc <2) {
puts(help_message);
return EXIT_FAILURE;
}
while (1) {
opt = getopt (argc,argv, "tfFsVMi:d");
if (opt == -1) break;
switch (opt) {
case 's' :
puts("flag_s on : stress tensor calculation on");
puts("require flag_t : also on");
flag_t = true;
flag_s = true; break;
case 't' :
puts("flag_t on : two time correlation");
flag_t = true; break;
case 'f' :
puts("flag_f on : collective space time correlation ");
flag_f = true; break;
case 'F' :
puts("flag_F on : self-collective space time correlation ");
puts("flag_f on : collective space time correlation ");
flag_f= flag_F = true; break;
case 'V' :
puts("flag_velocity on : velocity correlation on");
flag_velocity = true; break;
case 'd' :
puts("flag_d on : get amount of dynamic memory allocation");
flag_d = true; break;
case 'M' :
puts("flag_magnet on : magnet correlation on");
flag_magnet = true; break;
case 'i' :
strcpy(inputFilename, optarg);
printf("intput filename : %s\n" ,inputFilename);
break;
case 'h':
case '?':
default:
puts(help_message);
return EXIT_FAILURE;
}
}
if(optind ==argc ) {
puts(help_message);
return EXIT_FAILURE;
}
int runable = 0;
GetNameList();
for( opt_num = optind; opt_num < argc; opt_num++) {
strcpy( filename,argv[opt_num]);
FILE* fp = fopen( filename ,"r");
if( fp == NULL) {
files_on [opt_num] = false;
fprintf(stderr,"Can`t open file (%s)!!\n", filename);
continue;
}
// kVal value have be changed because reciprocal information
n_snap = 0;
while(1) {
bool check = ReadDumpForOnlyCheck(fp);
if (check == false)
break;
n_snap++;
}
// if ( flag_Max_eval)
if (n_snap <5){
fprintf(stderr,"The # of snap is too small(<5) \n"
", or this file is not valid \n"
"We would not use this file(%s)!!\n", filename);
files_on [opt_num] = false;
// return 23;
}
else if ( floor((n_snap - nCTime) /(nCTime/ nCBuffer)) <1) {
fprintf(stderr,"The # of snap is too small()\n"
"it dont make a infomation\n"
"floor((n_snap - nCTime) /(nCTime/ nCBuffer)) <1\n"
"floor((%d - %d) /(%d/ %d)) <1\n"
"We would not use this file(%s)!!\n",
n_snap,nCTime, nCTime, nCBuffer,
filename);
files_on [opt_num] = false;
}
else {
num_data [opt_num ] = n_snap;
if (nCBuffer < 1) {
nCBuffer =1;
}
limitCorrAv += floor((n_snap - nCTime) /(nCTime/ nCBuffer));
full_n_snaps += n_snap;
files_on [opt_num] = true;
runable += 1;
}
fclose (fp);
}
if ( runable ==0 ) {
puts("Check your input options or datafile length!!");
exit(1);
}
PrintNameList2File(stderr);
UpdateNameList ();
int num_files =0;
for( opt_num = optind; opt_num < argc; opt_num++) {
if (files_on[opt_num] == true) num_files ++;
}
// One process serially use each file.
real r_done_works;
int i_done_works;
AllocMem(classSqt,1,MakeSqtClass);
classSqt->flag_alloc = 0;
classSqt->flag_alloc_more = 0;
i_done_works= 0;
// recoding without openmp that is not suitable.
for( opt_num = optind; opt_num < argc; opt_num++) {
if (files_on[opt_num] == false) continue;
strcpy( filename,argv[opt_num]);
FILE* fp = fopen( filename ,"r");
Snapshot* snap, *firstSnap;
MakeSqtClass* cl_sqt = classSqt;
InitSpacetimeCorr(cl_sqt);
/*!
* \brief Start Calculation.
*/
rewind(fp);
firstSnap = ReadDump(fp);
Init_reciprocal_space(firstSnap);
rewind(fp);
fprintf(stderr,"FULL_SNAPS = %5d\n",full_n_snaps);
for (int ns = 0 ; ns < num_data[opt_num] ; ns++ ) {
/* while(1) {}
*/
snap = ReadDump(fp);
if (snap == NULL)
break;
cl_sqt->snap = snap;
EvalSpacetimeCorr(cl_sqt);
FreeSnapshot(snap);
//#pragma omp atomic
full_n_snaps_index++;
i_done_works++;
int new_progress =(10000.0*full_n_snaps_index/ full_n_snaps);
r_done_works =
(10000.0*i_done_works/ full_n_snaps);
/* fprintf(stderr,"FULL_SNAPS = %5d, newprogress %d\n",full_n_snaps_index,
* new_progress);
*/
if (new_progress != progress ) {
progress = new_progress;
fprintf(stderr, "\r %4.2f%%(", progress*.01);
fprintf(stderr, "main:%4.2f%%", r_done_works*.01);
fflush(stderr);
}
}
// opt_num ++;
fclose (fp);
fprintf(stderr, "\nEnd : file : %s\n", filename);
}
if ( Number_call_Print ==0 ) {
fprintf(stderr, "limit corr = %d, countCorrAv = %d\n",
limitCorrAv,countCorrAv);
limitCorrAv =countCorrAv;
MakeSqtClass* cl_sqt = classSqt;
PrintProcess(cl_sqt);
}
return 0;
}
void PrintProcess(MakeSqtClass* cl_sqt)
{
FILE* fout_log = fopen( "output.log", "w+");
fputs("Call PrintProcess : \n", fout_log);
if(NULL== cl_sqt){
fprintf(stderr,"FILE : %s, FUNCTION : %s, LINE : %d, cl_sqt is NULL\n", __FILE__, __func__ , __LINE__);
exit(1);
}
void prePrintProcess () ;
void PrintEtc();
prePrintProcess ();
PrintEtc ();
if (flag_f == true) {
char* fout_filename = "output.binary";
FILE* fout = fopen( fout_filename, "w+");
FILE* fout_text = fopen( "output.txt", "w+");
fprintf(fout_log, "%s %ld %d \n", fout_filename,ftell(fout), limitCorrAv);
fprintf(stderr, "%s %ld %d \n", fout_filename,ftell(fout), limitCorrAv);
PrintSpacetimeCorr (fout_text);
PrintSpacetimeCorr_binary( fout);
fclose(fout_text);
fclose(fout);
}
fclose(fout_log);
ZeroAvSpacetimeCorr (); //FIXIT 아무의미없음 출력에서 교체합시다.
}
void AccumSpacetimeCorr (MakeSqtClass* cl_sqt) // __thread_safe__
/*!
* \brief 계산된 현재 시간의 SpaceTime correlation을 누적한다.
*/
{
int k, nb, nr, n, nt;
TBuf* tBuf = cl_sqt->tBuf;
TBuf* pt;
for (nb = 0; nb < nCBuffer; nb ++) {
if (tBuf[nb].count == nCTime) {
//omp_set_lock(&write_lock);
// check!! that data is full
// S(q,t), M(q,t) part
pt = &tBuf[nb];
if (flag_f == true) {
for (k = 0; k < AVDOF * nCSpatial; k ++) {
for (n = 0; n < nCTime; n ++) {
avF_qq2[k][n] += pt->F_qq2[k][n];
StdDevF_qq2[k][n] += pt->F_qq2[k][n]*pt->F_qq2[k][n];
if (flag_F == true ) {
avF_s_qq2[k][n] += pt->F_s_qq2[k][n];
StdDevF_s_qq2[k][n] += pt->F_s_qq2[k][n]*pt->F_s_qq2[k][n];
avF_d_qq2[k][n] += pt->F_d_qq2[k][n];
StdDevF_d_qq2[k][n] += pt->F_d_qq2[k][n]*pt->F_d_qq2[k][n];
}
if(flag_velocity==true){
avC2_v_rho[k][n] += pt->C2_v_rho[k][n];
avC2_rho_v[k][n] += pt->C2_rho_v[k][n];
avC2_v_v[k][n] += pt->C2_v_v[k][n];
}
if(flag_velocity && flag_magnet){
avC2_v_mu[k][n] += pt->C2_v_mu[k][n];
avC2_mu_v[k][n] += pt->C2_mu_v[k][n];
}
if(flag_magnet==true){
avC2_mu_rho[k][n] += pt->C2_mu_rho[k][n];
avC2_rho_mu[k][n] += pt->C2_rho_mu[k][n];
avC2_mu_mu[k][n] += pt->C2_mu_mu[k][n];
}
}
}
for (nt = 0; nt < nCTime; nt ++) {
for ( nr=0; nr<nCSpatial; nr++) {
avDrTable[nr][nt] += pt->DrTable[nr][nt];
}
}
}
// Diffuse Part
if (flag_t == true) {
#pragma omp parallel for
for (nt = 0; nt < nCTime; nt ++) {
rrMSDAv[nt] += pt->rrMSD[nt];
rrMSDCMAv[nt] += pt->rrMSDCM[nt];
rrMQDAv[nt] += pt->rrMQD[nt];
if (flag_velocity == true) {
rrCvvAv[nt] += pt->rrCvv[nt];
rrCvcmvcmAv[nt] += pt->rrCvcmvcm[nt];
}
if (flag_s == true) {
real_tensor_increase_r1_r1(&rrMSR1_R_Av[nt],
&pt->rrMSR1_R[nt]);
real_tensor_increase_r2_r2(&rrMSR2_VR_Av[nt],
&pt->rrMSR2_VR[nt]);
}
}
}
// buffer nb reset
pt->count = 0;
++ countCorrAv;
if (countCorrAv == limitCorrAv) {
PrintProcess (cl_sqt);
}
//omp_unset_lock(&write_lock);
} // if tBuf[nb].count is full
} // for all buffer
}
void InitSpacetimeCorr (MakeSqtClass* cl_sqt)
/*!
* \brief 프로그램 초기에 시간 평균을 낼 수 있도록 index를 부여하는 과정
*/
{
cl_sqt->nSkip =0;
if (cl_sqt->flag_alloc == 0 ) {
//omp_set_lock(&write_lock);
if(flag_d == true ) {
AmountAllocArray(cl_sqt);
}
AllocArray(cl_sqt);
cl_sqt->flag_alloc = 1;
flag_global_alloc =1;
AllocMemCheck();
//omp_unset_lock(&write_lock);
}
if (nCBuffer > nCTime) {
fputs("Error nCBuffer> nCTime\n", stderr);
exit(1);
}
TBuf* tBuf = cl_sqt->tBuf;
for (int nb = 0; nb < nCBuffer; nb ++){
tBuf[nb].count = - nb * nCTime / nCBuffer;
tBuf[nb].countDiff = - nb * nCTime / nCBuffer;
}
}
void ZeroAvSpacetimeCorr ()
/*!
* \brief 출력 후 또는, 프로그램 시작시 평균 계산을 위한 메모리를
* 0값으로 초기화
*/
{
int nk,nt, nr;
countCorrAv = 0;
if (flag_f == true) {
#pragma GCC ivdep
for (nk = 0; nk < AVDOF * nCSpatial; nk ++) {
for (nt = 0; nt < nCTime; nt ++) {
avF_qq2[nk][nt] = 0.;
StdDevF_qq2[nk][nt] = 0.;
if (flag_F == true) {
avF_s_qq2[nk][nt] = 0.;
avF_d_qq2[nk][nt] = 0.;
StdDevF_s_qq2[nk][nt] = 0.;
StdDevF_d_qq2[nk][nt] = 0.;
}
if (flag_velocity == true) {
avC2_v_rho [nk][nt] = 0. ;
avC2_rho_v [nk][nt] = 0. ;
avC2_v_v [nk][nt] = 0. ;
}
if (flag_velocity && flag_magnet ) {
avC2_mu_v [nk][nt] = 0. ;
avC2_v_mu [nk][nt] = 0. ;
}
if (flag_magnet == true) {
avC2_mu_rho [nk][nt] = 0. ;
avC2_rho_mu [nk][nt] = 0. ;
avC2_mu_mu [nk][nt] = 0. ;
}
}
}
for (nt = 0; nt < nCTime; nt ++) {
for (nr = 0; nr < nCSpatial; nr ++) {
avDrTable[nr][nt]= 0.;
}
}
}
if (flag_t == true) {
#pragma omp parallel for
for (nt = 0; nt < nCTime; nt ++) {
rrMSDAv[nt] = 0.; rrMQDAv[nt] = 0.;
rrMSDCMAv[nt] = 0.;
if (flag_velocity == true) {
rrCvvAv[nt] = 0.;
rrCvcmvcmAv[nt] = 0.;
}
if (flag_magnet == true) {
rrCmmAv[nt] = 0.;
}
if (flag_s == true) {
real_tensor_zero_r1( &rrMSR1_R_Av[nt] );
real_tensor_zero_r2( &rrMSR2_VR_Av [nt] ) ;
rrMSR2_VR_Av_offdig[nt] = 0.;
rrMSR2_VR_Av_dig [nt] = 0.;
}
}
}
}
void EvalOtherInformation ()
/*!
* \brief \f$ F(q,t) \f$를 출력전에 미분해서 data를 뽑아낸다.
*
*/
{ // this evaluation yield analysis.c
#define Fqt_FIX_q avF_qq2[AVDOF*(nk) +AV_DEN]
int nk, n, ppT, pT, cT, nT, nnT;
real kVal2 = kVal*kVal, q_sqr;
n=0; nnT = n+2; nT = n+1; cT = n;
{ //Forward O(h^2)
for (nk = 0; nk < nCSpatial; nk ++) {
valGammaQT[nk][n]= (-(Fqt_FIX_q[nnT]) +4.*(Fqt_FIX_q[nT]) -3.*(Fqt_FIX_q[cT]) )/ (2.0* deltaT*Fqt_FIX_q[cT]);
q_sqr = kVal2 * (nk+1)*(nk+1);
valDqt [nk][n] = - valGammaQT[nk][n] / q_sqr ;
}
}
for (n = 1; n < nCTime-1; n ++) { /* centerd O(h^2) */
pT = n-1; nT = n+1; cT = n;
for (nk = 0; nk < nCSpatial; nk ++) {
valGammaQT[nk][n] = ( (Fqt_FIX_q[nT]) -(Fqt_FIX_q[pT]) )/ (2.0* deltaT*Fqt_FIX_q[cT]);
q_sqr = kVal2 * (nk+1)*(nk+1);
valDqt [nk][n] = - valGammaQT[nk][n] / q_sqr ;
}
}
n= nCTime-1; ppT = n-2; pT = n-1; cT = n; { /* Backward O(h^2) */
for (nk = 0; nk < nCSpatial; nk ++) {
valGammaQT[nk][n] = (+(3.*Fqt_FIX_q[cT]) -4.*(Fqt_FIX_q[pT]) +(Fqt_FIX_q[ppT]) )/ (2.0* deltaT*Fqt_FIX_q[cT]);
q_sqr = kVal2 * (nk+1)*(nk+1);
valDqt [nk][n] = - valGammaQT[nk][n] / q_sqr ;
}
}
}
void prePrintProcess ()
{
real inverseNptls = 1./nPtls;
real inverseNptlsSq = 1./(nPtls*nPtls);
real average_number = 1./(3.0*countCorrAv);
if (flag_f == true) {
#pragma omp parallel for
for (int nr = 0; nr < AVDOF * nCSpatial; nr ++) {
for (int nt = 0; nt < nCTime; nt ++){
real average = (avF_qq2[nr][nt] * inverseNptls) * average_number ;
real averageSq = (StdDevF_qq2[nr][nt] * inverseNptlsSq) * average_number;
avF_qq2[nr][nt] = average;
StdDevF_qq2[nr][nt] = sqrt( (averageSq - average*average) );
// ErrF_qq2[nr][nt] = sqrt( average_number * (averageSq - average*average) );
if (flag_F == true) {
/* avF_s_qq2[nr][nt] *= scale_factor;
* avF_d_qq2[nr][nt] *= 1.*scale_factor;
* StdDevF_s_qq2[nr][nt] *= scale_factor;
* StdDevF_d_qq2[nr][nt] *= 1. *scale_factor;
*/
average = (avF_s_qq2[nr][nt] * inverseNptls ) * average_number;
averageSq = (StdDevF_s_qq2[nr][nt] * inverseNptlsSq )* average_number;
avF_s_qq2[nr][nt] = average;
StdDevF_s_qq2[nr][nt] = sqrt( (averageSq - average*average) );
// ErrF_s_qq2[nr][nt] = sqrt( average_number * (averageSq - average*average) );
average = (avF_d_qq2[nr][nt] * inverseNptls ) * average_number;
averageSq = (StdDevF_d_qq2[nr][nt] * inverseNptlsSq) * average_number;
avF_d_qq2[nr][nt] = average;
StdDevF_d_qq2[nr][nt] = sqrt( 1. * (averageSq - average*average) );
// ErrF_d_qq2[nr][nt] = sqrt( average_number * 1. * (averageSq - average*average) );
}
if (flag_velocity == true) {
avC2_v_rho [nr][nt] *= inverseNptls * average_number ;
avC2_rho_v [nr][nt] *= inverseNptls * average_number ;
avC2_v_v [nr][nt] *= inverseNptls * average_number ;
}
if (flag_velocity && flag_magnet ) {
avC2_mu_v [nr][nt] *= inverseNptls * average_number ;
avC2_v_mu [nr][nt] *= inverseNptls * average_number ;
}
if (flag_magnet == true) {
avC2_mu_rho [nr][nt] *= inverseNptls * average_number ;
avC2_rho_mu [nr][nt] *= inverseNptls * average_number ;
avC2_mu_mu [nr][nt] *= inverseNptls * average_number ;
}
}
}
#pragma omp parallel for
for (int nt = 1; nt < nCTime; nt ++) {
for ( int nr=0; nr<nCSpatial; nr++) {
avDrTable[nr][nt] *= factorDr[nr];
}
}
}
// fac = 1./ ( DIM * 2 * nPtls * deltaT * limitCorrAv);
/*-----------------------------------------------------------------------------
* rrMSDAv -> mean square displacemnt
* rrMQDAv -> mean quadropole displacemnt
*-----------------------------------------------------------------------------*/
// fac = 1./ ( DIM * 2 * nPtls * deltaT * limitCorrAv);
real scale_countAv = 1./countCorrAv;
real scale_4stress = .5*mass*mass/(countCorrAv* g_Vol);
real scale_factor = 1./ ( nPtls * countCorrAv);
real factor_Cvv = 1./(nPtls* countCorrAv*3.);
real factor_msdcm = 1./( countCorrAv);
real factor_Cvcmvcm = 1./( countCorrAv*3.);
if (flag_t == true) {
#pragma omp parallel for
for (int nt = 0; nt < nCTime; nt ++) {
rrMSDAv[nt] *= scale_factor;
rrMSDCMAv[nt] *= factor_msdcm;
rrMQDAv[nt] *= scale_factor;
if (flag_velocity == true ) {
rrCvvAv[nt] *= factor_Cvv;
rrCvcmvcmAv[nt] *= factor_Cvcmvcm;
}
/*!
* \brief if all mass of particles is same value
*/
if (flag_s == true) {
real_tensor_product_r1_r0r1(&rrMSR1_R_Av[nt], scale_factor,
&rrMSR1_R_Av[nt]);
real_tensor_product_r2_r0r2(&rrMSR2_VR_Av[nt]
, scale_4stress,&rrMSR2_VR_Av[nt]);
rrMSR2_VR_Av_dig[nt] =
real_tensor_avg_dig_r2(&rrMSR2_VR_Av[nt]);
rrMSR2_VR_Av_offdig[nt] =
real_tensor_avg_offdig_r2(&rrMSR2_VR_Av[nt]);
}
}
}
Number_call_Print ++;
}
void PrintSpacetimeCorr (FILE *fp)
/*!
* \brief 결과를 출력하는 함수
*
* \param fp output file descriptor
*/
{
extern real kVal;
size_t k2;
int nType, nr;
// char *header[] = {"cur-long", "cur-trans", "density", "vanHove-self"};
char *header[] = {
"full-density", // 0
"self-density", // 1
"cross-density", // 2
"self-vanHove" // 3
};
fprintf (fp, "%s\n",txtCorr);
for (k2 = 0; k2 < sizeof(header)/ sizeof(char*); k2 ++) {
// EvalOtherInformation ();
fprintf (fp, "# %s %7.3f %7.3f %7.3f\n",
header[k2] , kVal,
(nCSkip+1)*deltaT,
rVal);
switch ( k2) {
case 0:
/*!-----------------------------------------------------------------------------
* avF_qq2[AVDOF*i+nType][k] -> F(q_i,t_k)
*-----------------------------------------------------------------------------*/
nType= 0;
for (int nt = 0; nt < nCTime; nt ++) {
real time_d = nt *1. * deltaT;
fprintf (fp, "%7.3f", time_d);
for (int nk = 0; nk < nCSpatial; nk ++){
fprintf (fp, " %8.4e %8.4e", avF_qq2[AVDOF * nk + nType][nt], StdDevF_qq2[AVDOF * nk + nType][nt]);
}
fprintf (fp, "\n");
}
break;
/*-----------------------------------------------------------------------------
* avF_s_qq2[3*i+nType][j] -> F_s(q_i,t_j)
*-----------------------------------------------------------------------------*/
case 1:
if ( flag_F == true) {
nType = 0;
for (int nt = 0; nt < nCTime; nt ++) {
real time_d = nt *1. * deltaT;
fprintf (fp, "%7.3f", time_d);
for (int nk = 0; nk < nCSpatial; nk ++){
fprintf (fp, " %8.4e %8.4e", avF_s_qq2[AVDOF * nk + nType][nt],StdDevF_s_qq2[AVDOF * nk + nType][nt]);
}
fprintf (fp, "\n");
}
}
break;
/*-----------------------------------------------------------------------------
* avF_d_qq2[3*i+nType][j] -> F_d(q_i,t_j)
* magnetic
*-----------------------------------------------------------------------------*/
case 2:
if (flag_F==true) {
nType = 0;
for (int nt = 0; nt < nCTime; nt ++) {
real time_d = nt *1. * deltaT;
fprintf (fp, "%7.3f", time_d);
for (int nk = 0; nk < nCSpatial; nk ++){
fprintf (fp, " %8.4e %8.4e", avF_d_qq2[AVDOF * nk + nType][nt], StdDevF_d_qq2[AVDOF * nk + nType][nt]);
}
fprintf (fp, "\n");
}
}
break;
case 3:
// fprintf (fp, "#van Hove function\n");
for (int nt = 0; nt < nCTime; nt ++) {
for ( nr=0; nr<nCSpatial; nr++) {
fprintf (fp, " %8.4e", avDrTable[nr][nt] );
}
fprintf (fp, "\n");
}
break;
}
fprintf (fp, "\n");
}
}
void PrintSpacetimeCorr_binary (FILE *fp)
/*!
* \brief 결과를 binary형태로 출력함
*
* \param fp output file descriptor
*/
{
extern real kVal;
int nType, k2;
int nr __attribute__((unused));
// Number_call_Print ++;
// char *header[] = {"cur-long", "cur-trans", "density", "vanHove-self"};
char *header[] = {
"full-density" , // 0
"self-density" , // 1
"cross-density" , // 2
"self-vanHove" // 3
};
int nTypes = sizeof(header)/ sizeof(char*);
int header_txtCorr = strlen(txtCorr);
fwrite (&header_txtCorr,sizeof(int),1,fp);
fwrite (txtCorr,1,header_txtCorr,fp);
fwrite (&nTypes,sizeof(int) ,1,fp);
for (k2 = 0; k2 < nTypes; k2 ++) {
real col2 = kVal;
real col3 = 1.0*deltaT*(nCSkip+1);
real col4 = rVal;
int DataYes = 1;
int DataNo = 0;
int length = strlen(header[k2]);
fwrite(&length, sizeof(int),1,fp);
fwrite(header[k2],sizeof(char), length, fp);
fwrite(&col2, sizeof(real),1,fp);
fwrite(&col3, sizeof(real),1,fp);
fwrite(&col4, sizeof(real),1,fp);
switch ( k2) {
case 0:
/*!-----------------------------------------------------------------------------
* avF_qq2[AVDOF*i+nType][k] -> F(q_i,t_k)
*-----------------------------------------------------------------------------*/
nType= 0;
fwrite(&DataYes, sizeof(int),1,fp);
for (int nt = 0; nt < nCTime; nt ++) {
for (int nk = 0; nk < nCSpatial; nk ++){
fwrite( &(avF_qq2[AVDOF * nk + nType][nt]), sizeof(real),1,fp);
}
}
break;
/*-----------------------------------------------------------------------------
* avF_s_qq2[3*i+nType][j] -> F_s(q_i,t_j)
*-----------------------------------------------------------------------------*/
case 1:
if (flag_F==true) {
nType = 0;
fwrite(&DataYes, sizeof(int),1,fp);
for (int nt = 0; nt < nCTime; nt ++) {
for (int nk = 0; nk < nCSpatial; nk ++){
fwrite( &(avF_s_qq2[AVDOF * nk + nType][nt]), sizeof(real),1,fp);
}
}
}
else fwrite(&DataNo, sizeof(int),1,fp);
break;
/*-----------------------------------------------------------------------------
* avF_d_qq2[3*i+nType][j] -> F_d(q_i,t_j)
* magnetic
*-----------------------------------------------------------------------------*/
case 2:
if (flag_F==true) {
nType = 0;
fwrite(&DataYes, sizeof(int),1,fp);
for (int nt = 0; nt < nCTime; nt ++) {
for (int nk = 0; nk < nCSpatial; nk ++){
fwrite( &(avF_d_qq2[AVDOF * nk + nType][nt]), sizeof(real),1,fp);
}
}
}
else fwrite(&DataNo, sizeof(int),1,fp);
break;
case 3:
// fprintf (fp, "#van Hove function\n");
fwrite(&DataYes, sizeof(int),1,fp);
for (int nt = 0; nt < nCTime; nt ++) {
for (int nk = 0; nk < nCSpatial; nk ++){
fwrite( &(avDrTable[nk][nt]), sizeof(real),1,fp);
}
}
break;
}
}
}
void PrintEtc () {
// char fn_Dt[100] ="Dq00.info" ;
// char fn_vanHove[100] ="Ft00.info" ;
char fn_Dt[200];
char fn_vanHove[200];
char fn_SSF[200];
char fn_C2_v_rho[200];
char fn_C2_rho_v[200];
char fn_C2_v_v[200];
char fn_C2_mu_v[200];
char fn_C2_v_mu[200];
char fn_C2_mu_rho[200];
char fn_C2_rho_mu[200];
char fn_C2_mu_mu[200];
char filename_stress[200];
int nfile = 0;
do {
sprintf(fn_Dt, "Dt%03d.info.%s",nfile,datetime_data);
sprintf(filename_stress, "Stress%03d.info.%s",nfile,datetime_data);
sprintf(fn_vanHove, "vanHove%03d.info.%s",nfile,datetime_data);
sprintf(fn_SSF, "SSF%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_v_v, "C2_v_v%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_v_rho, "C2_v_rho%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_rho_v, "C2_rho_v%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_mu_v, "C2_mu_v%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_v_mu, "C2_v_mu%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_mu_rho, "C2_mu_rho%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_mu_mu, "C2_mu_mu%03d.info.%s",nfile,datetime_data);
sprintf(fn_C2_rho_mu, "C2_rho_mu%03d.info.%s",nfile,datetime_data);
nfile++;
} while( 0 == access(fn_Dt,F_OK) ) ;
/* FILE* fp_Dq = fopen(fn_Dt,"w");
* fprintf (fp_Dq, "# dt = %7.3f\n", deltaT);
* for (j = 0; j < nCSpatial; j ++) {
* fprintf (fp_Dq, "%8.4f" , j*kVal );
* for (n = 1; n < nCTime; n ++) {
* fprintf (fp_Dq, " %8.4e" , valDqt[j][n]);
* }
* fprintf (fp_Dq, "\n");
* }
* fclose(fp_Dq);
*/
/* FILE* fp_Ft = fopen(fn_vanHove,"w");
* fprintf (fp_Ft, "# dq = %7.3e\n", kVal);
* for (n = 0; n < nCTime; n ++) {
* fprintf (fp_Ft, "%8.4f" , n*deltaT );
* for (j = 0; j < nCSpatial; j ++) {
* fprintf (fp_Ft, " %8.4e" , avF_qq2[(3*j)+2][n]/avF_qq2[(3*j)+2][0]);
* }
* fprintf (fp_Ft, "\n");
* }
* fclose(fp_Ft);
*/
if (flag_f == true) {
FILE* fp_SSF = fopen(fn_SSF,"w");
FILE *fp_C2_mu_mu, *fp_C2_v_v;
FILE *fp_C2_mu_rho, *fp_C2_v_rho;
FILE *fp_C2_rho_mu, *fp_C2_rho_v;
FILE *fp_C2_v_mu, *fp_C2_mu_v;
if (flag_velocity == true) {
fp_C2_v_rho = fopen(fn_C2_v_rho,"w");
fp_C2_rho_v = fopen(fn_C2_rho_v,"w");
fp_C2_v_v = fopen(fn_C2_v_v,"w");
}
if (flag_velocity && flag_magnet) {
fp_C2_v_mu = fopen(fn_C2_v_mu,"w");
fp_C2_mu_v = fopen(fn_C2_mu_v,"w");
}
if (flag_magnet == true) {
fp_C2_mu_rho = fopen(fn_C2_mu_rho,"w");
fp_C2_rho_mu = fopen(fn_C2_rho_mu,"w");
fp_C2_mu_mu = fopen(fn_C2_mu_mu,"w");
}
for (int nt = 0; nt < nCTime; nt ++) {
int nType= 0;
real time_d = nt *1. * deltaT;
if (flag_velocity == true) {
fprintf (fp_C2_v_v, "%7.3f", time_d);
fprintf (fp_C2_rho_v, "%7.3f", time_d);
fprintf (fp_C2_v_rho, "%7.3f", time_d);
}
if (flag_velocity && flag_magnet ) {
fprintf (fp_C2_v_mu, "%7.3f", time_d);
fprintf (fp_C2_mu_v, "%7.3f", time_d);
}
if (flag_magnet == true) {
fprintf (fp_C2_mu_mu, "%7.3f", time_d);
fprintf (fp_C2_rho_mu, "%7.3f", time_d);
fprintf (fp_C2_mu_rho, "%7.3f", time_d);
}
for (int nk = 0; nk < nCSpatial; nk ++){
if (flag_velocity == true) {
fprintf (fp_C2_v_v, " %8.4e", avC2_v_v[AVDOF * nk + nType][nt]);
fprintf (fp_C2_rho_v, " %8.4e", avC2_rho_v[AVDOF * nk + nType][nt]);
fprintf (fp_C2_v_rho, " %8.4e", avC2_v_rho[AVDOF * nk + nType][nt]);
}
if (flag_velocity && flag_magnet ) {
fprintf (fp_C2_v_mu, " %8.4e", avC2_v_mu[AVDOF * nk + nType][nt]);
fprintf (fp_C2_mu_v, " %8.4e", avC2_mu_v[AVDOF * nk + nType][nt]);
}
if (flag_magnet == true) {
fprintf (fp_C2_mu_mu, " %8.4e", avC2_mu_mu[AVDOF * nk + nType][nt]);
fprintf (fp_C2_rho_mu, " %8.4e", avC2_rho_mu[AVDOF * nk + nType][nt]);
fprintf (fp_C2_mu_rho, " %8.4e", avC2_mu_rho[AVDOF * nk + nType][nt]);
}
}
if (flag_velocity == true) {
fprintf (fp_C2_v_v, "\n");
fprintf (fp_C2_rho_v, "\n");
fprintf (fp_C2_v_rho, "\n");
}
if (flag_velocity && flag_magnet ) {
fprintf (fp_C2_v_mu, "\n");
fprintf (fp_C2_mu_v, "\n");
}
if (flag_magnet == true) {
fprintf (fp_C2_mu_mu, "\n");
fprintf (fp_C2_rho_mu, "\n");
fprintf (fp_C2_mu_rho, "\n");
}
}
for (int nk = 0; nk < nCSpatial; nk ++){
real value1 = avF_qq2[(AVDOF*nk)+0][0];
real value2 = sqrt( StdDevF_qq2[(AVDOF*nk)+0][0] - value1*value1 );
fprintf (fp_SSF, "%8.4f" " %8.4g" " %8.4g""\n" , (nk+1)*kVal ,
// avF_qq2[(AVDOF*nr)+AV_DEN][0]);
value1, value2);