-
Notifications
You must be signed in to change notification settings - Fork 4
/
post_process.cpp
2254 lines (2022 loc) · 95 KB
/
post_process.cpp
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
//////////////////////////////////////////////////////////////////////////////
//
// this code was written by Beat Luthi at IfU, ETH Zürich, Okt 2007
//
// is represents an attempt to have ONE clean non-GUI version of the postPorcessing codes
// that float around in various Borland versions
//
//
// last update/change: August 2011 Marc Wolf
//
//////////////////////////////////////////////////////////////////////////////
/*
This software links 3D particle positions of consequtivee time steps.
Copyright (C) 2006 Beat Luthi, Risø, Nat. Lab, Denmark
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v2, as published by the Free
Software Foundation, provided that the above copyright notices and this
permission notice appear in all copies of the software and related documentation.
You may charge a fee for the physical act of transferring a copy, and you may at
your option offer warranty protection in exchange for a fee.
You may not copy, modify, sublicense, or distribute the Program except as
expressly provided under this License.
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.
*/
#include "stdafx.h"
TpointList pointList;
FILE * input;
FILE *fpp;
int n;
float e;
static void flushline(FILE * fp);
static void map_slices_to_cycles();
static void readPTVFile(int n, int index);
static void read_scanning_PTVFile(int n, int index); // added by Beat March 2013 for scanning
static void prepare_fast_search();
static void doCubicSplines(bool single,int number);
static void setAllMatrixesToZero(int size);
static void makeAT(int n, int m);
static void makeATA(int n, int m);
static void makeATY(int n, int m,int wh);
static bool solve(int n, int m);
static void writeXUAPFile(int t);
static void followTrajPoint(FILE *fpp, int t,int startPoint);
static void readXUAPFile(int n, bool firstTime);
static void readXUAGFile(int n, bool firstTime);
int main(int argc, char *argv[])
{
char garb[10];
char pa[256];
char name[256];
int c;
int deltaFrames,numCycles;
//begin of read in control parameters
///////////////////////////////////////////////////////////////////////////////////
if (argc == 1) {
//if (NULL == (input = fopen("C:/input.inp","r"))){
//if (NULL == (input = fopen("D:/PTV/version_March_2013_scanning/input_2905.txt","r"))){
if (NULL == (input = fopen("input.inp","r"))){
cout<< "\ndid not find input.inp file";
}
else{
cout<< "\n automatically and succesfully opened *.inp file \n";
}
}
else{
if (NULL == (input = fopen(argv[1],"r"))){
cout<< "\ndid not find *.inp file";
}
else{
cout<< "\nsuccesfully opened *.inp file \n";
}
}
//what should be done?
fscanf(input,"%i",&n); flushline(input); if(n==1){pointList.xuap=true;} else{pointList.xuap=false;}
fscanf(input,"%i",&n); flushline(input); if(n==1){pointList.traj_point=true;} else{pointList.traj_point=false;}
fscanf(input,"%i",&n); flushline(input); if(n==1){pointList.derivatives=true;} else{pointList.derivatives=false;}
fscanf(input,"%i",&n); flushline(input); if(n==1){pointList.pressure=true;} else{pointList.pressure=false;}
fscanf(input,"%i",&n); flushline(input); if(n==1){pointList.Hessian=true;} else{pointList.Hessian=false;}
//data
fscanf(input,"%s",pa); flushline(input);sprintf (pointList.path,pa);
fscanf(input,"%i",&n); flushline(input);pointList.firstSFile = n; // the code will compute the cycle numbers,i.e. the firstFile and lastFile by itself
fscanf(input,"%i",&n); flushline(input);pointList.lastSFile = n; // the code will compute the cycle numbers,i.e. the firstFile and lastFile by itself
fscanf(input,"%i",&n); flushline(input);pointList.numSlices = n;
//fact
fscanf(input,"%f",&e); flushline(input);pointList.deltaT_between_slice = e;
fscanf(input,"%f",&e); flushline(input);pointList.deltaT = e; // between scans, or for non-scanning
fscanf(input,"%f",&e); flushline(input);pointList.viscosity = e;
//controls xuap
fscanf(input,"%i",&n); flushline(input);pointList.PL = n;
fscanf(input,"%i",&n); flushline(input);pointList.minLeftRight = n;
fscanf(input,"%f",&e); flushline(input);pointList.tolMaxVel = e;
//controls traj_accc
fscanf(input,"%f",&e); flushline(input);pointList.maxRadius = e;
fscanf(input,"%f",&e); flushline(input);pointList.weDiv = e; // weighting for 2Q+diva error
fscanf(input,"%f",&e); flushline(input);pointList.weAcc = e; // weighting for acceleration error
fscanf(input,"%f",&e); flushline(input);pointList.weVel = e; // weighting for divu error, addeded by Marc, 14.07.2011
flushline(input);
fscanf(input,"%i",&n); flushline(input);pointList.minTrajLength = n;
fscanf(input,"%i",&n); flushline(input);pointList.polyConst = n;
fscanf(input,"%f",&e); flushline(input);pointList.c1 = e;
fscanf(input,"%f",&e); flushline(input);pointList.c2 = e;
fscanf(input,"%i",&n); flushline(input);pointList.maxRank = n;
fscanf(input,"%i",&n); flushline(input);pointList.numOfFrames = n;
fscanf(input,"%i",&n); flushline(input);pointList.max_grid_X = n;
fscanf(input,"%i",&n); flushline(input);pointList.max_grid_Y = n;
fscanf(input,"%i",&n); flushline(input);pointList.max_grid_Z = n;
fscanf(input,"%i",&n); flushline(input);pointList.max_grid_C = n;
flushline(input);
fscanf(input,"%f",&e); flushline(input);pointList.xminChamber = e; //added by Markus, 20.07.2009
fscanf(input,"%f",&e); flushline(input);pointList.xmaxChamber = e;
fscanf(input,"%f",&e); flushline(input);pointList.xminChannel = e;
fscanf(input,"%f",&e); flushline(input);pointList.xmaxChannel = e;
fscanf(input,"%f",&e); flushline(input);pointList.zminChamber = e; //added by Markus, 20.07.2009
fscanf(input,"%f",&e); flushline(input);pointList.zmaxChamber = e;
fscanf(input,"%f",&e); flushline(input);pointList.zminChannel = e;
fscanf(input,"%f",&e); flushline(input);pointList.zmaxChannel = e;
fscanf(input,"%f",&e); flushline(input);pointList.yChamberChannel = e;
//end of read in control parameters
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
// begin of #slice > 1 treatment
if(pointList.numSlices>1){
deltaFrames=pointList.lastSFile-pointList.firstSFile+1;
numCycles=int((double)deltaFrames/(double)pointList.numSlices);
pointList.firstFile=pointList.firstSFile;
pointList.lastFile=pointList.firstSFile+numCycles-1;
}
else{
//business as usual, like it was before scanning.
pointList.firstFile=pointList.firstSFile;
pointList.lastFile=pointList.lastSFile;
}
// end of #slice >1 treatment,
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
if(pointList.xuap){
pointList.PLh=int((double)pointList.PL/2.);
pointList.count=0;
pointList.maxVel=0.;
pointList.meanVel=0.;
pointList.meanAcc=0.;
if(pointList.numSlices>1){
// map slices frame and point id's to cycle frame and point id's
map_slices_to_cycles();
}
for (int i=pointList.firstFile;i<pointList.lastFile+1;i++){
if(i % ((int)((double)20/(double)pointList.numSlices)+1) == 0){
cout << "processing file ........."<<i<<"\n";
cout << "max Vel.................."<<pointList.maxVel<<"\n";
cout << "mean Vel................."<<pointList.meanVel<<"\n";
cout << "mean Acc................."<<pointList.meanAcc<<"\n\n";
}
for (int ii=-pointList.PLh;ii<pointList.PLh+1;ii++){
if(pointList.numSlices>1){
// read in scanned ptv_is files
read_scanning_PTVFile(i,ii);
}
else{ //business as usual, no scanning
readPTVFile(i,ii);
}
}
doCubicSplines(false,0);
writeXUAPFile(i);
}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
if(pointList.traj_point){
pointList.count=0;
pointList.count2=0;
pointList.count3=0;
pointList.count4=0;
pointList.count5=0;
pointList.count6=0;
pointList.meanDiss=0.;
pointList.meanUSq=0.;
cout << "\npreparing grid for neighbor search\n";
prepare_fast_search();
for (int i=pointList.firstFile;i<pointList.lastFile+1;i++){
if((double)pointList.count3/(double)pointList.count>0){
cout << "point per sphere.............."<<(double)pointList.count3/(double)pointList.count<<"\n";
cout << "% rel. diva < 0.1............."<<100.*(double)pointList.count4/(double)pointList.count<<"\n";
cout << "% rel. acc < 0.2............."<<100.*(double)pointList.count5/(double)pointList.count<<"\n";
cout << "% rel. divu < 0.1............."<<100.*(double)pointList.count6/(double)pointList.count<<"\n";
cout << "r.m.s. u [m/s]................"<<pow(pointList.meanUSq,0.5)<<"\n";
cout << "mean dissipation [m^2/s^3]...."<<pointList.meanDiss<<"\n\n";
}
cout << "processing file .............."<<i<<"\n";
c=sprintf (name, pointList.path);
c+=sprintf (name+c, "/trajPoint.");
c+=sprintf (name+c, "%1d", i);
fpp = fopen(name,"w");
followTrajPoint(fpp,i,0);
fclose (fpp);
}
}
///////////////////////////////////////////////////////////////////////////////////
scanf("Please hit a key %s", garb); // to stop console
return 0;
}
void flushline(FILE * fp)
{
while(fgetc(fp)!='\n' && !feof(fp));
}
void map_slices_to_cycles()
{
FILE *fpp;
int c;
int numOfPoints;
int cid,old_cid;
char name[256];
old_cid=-1;
for (int i=pointList.firstSFile;i<pointList.lastSFile+1;i++){
if(i % 100 == 0){
cout << "mapping slice file ..."<<i<<"\n";
}
// determine cycle id
cid=(int)( (double)(i-pointList.firstSFile)/(double)pointList.numSlices );
if(cid>old_cid){
old_cid=cid;
pointList.numPoints_per_cycle[cid]=0; //so now it is initiated for cummulative cycle point_id
}
c=sprintf (name, pointList.path);
c+=sprintf (name+c, "/ptv_is.");
c+=sprintf (name+c, "%1d", i);
fpp = fopen(name,"r");
fscanf (fpp, "%d\0", &numOfPoints);
for (int j=0; j<numOfPoints; j++){
// pointList.map_slice_cycle[i-pointList.firstSFile+1][j][0]=cid;//cycle id
pointList.map_slice_cycle[i-pointList.firstSFile][j]=j+pointList.numPoints_per_cycle[cid];//cummulated cycle point_id
}
fclose (fpp);
pointList.numPoints_per_cycle[cid]+=numOfPoints;
}
}
void readPTVFile(int n, int index)
{
FILE *fpp;
int c;
int numOfPoints;
int left,right;
double x,y,z,rmsDist;
char name[256];
if(n+index>pointList.firstFile-1 && n+index<pointList.lastFile+1){
c=sprintf (name, pointList.path);
c+=sprintf (name+c, "/ptv_is.");
c+=sprintf (name+c, "%1d", n+index);
fpp = fopen(name,"r");
fscanf (fpp, "%d\0", &numOfPoints);
pointList.point[index+pointList.PLh][0][0]=numOfPoints;
for (int i=1; i<numOfPoints+1; i++){ //these lines 218-231 müssen geändert werden
fscanf (fpp, "%d\0", &left);
fscanf (fpp, "%d\0", &right);
fscanf (fpp, "%lf\0", &x);
fscanf (fpp, "%lf\0", &y);
fscanf (fpp, "%lf\0", &z);
rmsDist=0.005;
pointList.point[index+pointList.PLh][i][0]=left+1;//;//
pointList.point[index+pointList.PLh][i][1]=right+1;//;//
pointList.point[index+pointList.PLh][i][2]=x*0.001;//;//
pointList.point[index+pointList.PLh][i][3]=y*0.001;//;//
pointList.point[index+pointList.PLh][i][4]=z*0.001;//;//
pointList.point[index+pointList.PLh][i][15]=rmsDist;
}
fclose (fpp);
}
else{
pointList.point[index+pointList.PLh][0][0]=0;
}
}
void read_scanning_PTVFile(int n, int index)
{
FILE *fpp;
int c;
int numOfPoints;
int fid_left,left,fid_right,right,cid,old_cid,id,cpid,left_pid,right_pid;
double x,y,z,rmsDist;
char name[256];
if(n+index>pointList.firstFile-1 && n+index<pointList.lastFile+1){
pointList.point[index+pointList.PLh][0][0]=pointList.numPoints_per_cycle[n+index-pointList.firstFile];
//now loop through slices etc
for (int s=0;s<pointList.numSlices;s++){
c=sprintf (name, pointList.path);
c+=sprintf (name+c, "/ptv_is.");
//c+=sprintf (name+c, "%1d", n+index); <- as was before scanning
// map n+index to proper slice frame id
id = ((n+index)-pointList.firstFile)*pointList.numSlices+s+pointList.firstSFile;
c+=sprintf (name+c, "%1d", id); // <--and now we have cid mapped to id
fpp = fopen(name,"r");
fscanf (fpp, "%d\0", &numOfPoints);
for (int i=0; i<numOfPoints; i++){ //these lines 218-231 müssen geändert werden
fscanf (fpp, "%d\0", &fid_left);
fscanf (fpp, "%d\0", &left);
fscanf (fpp, "%d\0", &fid_right);
fscanf (fpp, "%d\0", &right);
fscanf (fpp, "%lf\0", &x);
fscanf (fpp, "%lf\0", &y);
fscanf (fpp, "%lf\0", &z);
rmsDist=0.005;
cid = n+index;
cpid = 1+pointList.map_slice_cycle[id-pointList.firstFile][i];
if(fid_left>-1){
left_pid = pointList.map_slice_cycle[fid_left-pointList.firstSFile ][left ];
}
else{
left_pid = left;
}
if(fid_right>-1){
right_pid = pointList.map_slice_cycle[fid_right-pointList.firstSFile][right];
}
else{
right_pid = right;
}
pointList.point[index+pointList.PLh][cpid][0]=left_pid+1;
pointList.point[index+pointList.PLh][cpid][1]=right_pid+1;
pointList.point[index+pointList.PLh][cpid][2]=x*0.001;
pointList.point[index+pointList.PLh][cpid][3]=y*0.001;
pointList.point[index+pointList.PLh][cpid][4]=z*0.001;
pointList.point[index+pointList.PLh][cpid][15]=rmsDist;
pointList.point[index+pointList.PLh][cpid][16]=pointList.deltaT_between_slice*((double)s-(double)pointList.numSlices/2); //delta t relative to time of middle slice
}
fclose (fpp);
}
}
else{
pointList.point[index+pointList.PLh][0][0]=0;
}
}
void doCubicSplines(bool single,int number)
{
//int pointList.PLh=int((double)pointList.PL/2.);
int nP=pointList.point[pointList.PLh][0][0];
int ind[200]; //Marc & Beat: 27.04.2011 changed size from 21 to 200
//double tolerance=0.15;//StrToFloat(paramForm->toleranceEdit->Text);
double velocity;
double weight,time;
int start,end;
if(!single){
start=1;
end=nP;
}
else{
start=number;
end=number;
}
for(int i=start;i<end+1;i++){
pointList.point[pointList.PLh][i][14]=0; //can be cubic splined
int maxIndex=pointList.PLh;
int minIndex=pointList.PLh;
int index=pointList.PLh;
int badCounter=0;
ind[index]=i;
bool ok=true;
while(index>0 && ok){
if(pointList.point[index][ind[index]][0]>0 && pointList.point[index][0][0]>0){
ind[index-1]=pointList.point[index][ind[index]][0];
index--;
minIndex=index;
}
else{
ok=false;
}
}
index=pointList.PLh;
ind[index]=i;
ok=true;
while(index<2*pointList.PLh && ok){
if(pointList.point[index][ind[index]][1]>0 && pointList.point[index][0][0]>0){
ind[index+1]=pointList.point[index][ind[index]][1];
index++;
maxIndex=index;
}
else{
ok=false;
}
}
//first do for x and u, then do for a
if(maxIndex-minIndex>2+badCounter && maxIndex>pointList.PLh-1+pointList.minLeftRight && minIndex<pointList.PLh+1-pointList.minLeftRight){
// if(maxIndex-minIndex>2+badCounter && maxIndex>9+minLength && minIndex<11-minLength){
//if(maxIndex-minIndex>2+badCounter ){ //ok (minIndex<10 && maxIndex>10){//
pointList.point[pointList.PLh][i][14]=1;
//x-Component
setAllMatrixesToZero(4);
for(int t=minIndex-pointList.PLh;t<maxIndex-pointList.PLh+1;t++){ //anpassen so dass t nicht mehr genau Zeit, sondern 'nur' master loop index ist
weight = pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][15];//da muss man anpassen, ind,2
weight = 1.-1./(1.+exp(-300.*(weight-0.015)));
weight = 1.; //Beat March 2009
//this is the only chamge due to scanning, works also if numSlice=0
if(pointList.numSlices>1){
time=(double)t*pointList.deltaT + pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][16];
}
else{
time=(double)t*pointList.deltaT;
}
//end of only chamge due to scanning
pointList.A[t+pointList.PLh][0] = 1.*weight;
pointList.A[t+pointList.PLh][1] = time*weight;
pointList.A[t+pointList.PLh][2] = pow(time,2.)*weight; // t is integer from e.g. -11 to 11
pointList.A[t+pointList.PLh][3] = pow(time,3.)*weight;
pointList.y[0][t+pointList.PLh] = pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][2]*weight;
}
makeAT(pointList.PL,4);
makeATA(pointList.PL,4);
makeATY(pointList.PL,4,0);
solve(pointList.PL,4);
pointList.point[pointList.PLh][i][5]=pointList.X[0];//filtered x position
pointList.point[pointList.PLh][i][8]=pointList.X[1];//filtered velocity, derivative from filtered x
pointList.point[pointList.PLh][i][11]=2.*pointList.X[2];// filtered acc, derivative from velocity
//y-Component
setAllMatrixesToZero(4);
for(int t=minIndex-pointList.PLh;t<maxIndex-pointList.PLh+1;t++){
weight = pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][15];
weight = 1.-1./(1.+exp(-300.*(weight-0.015)));
weight = 1.; //Beat March 2009
//this is the only chamge due to scanning, works also if numSlice=0
if(pointList.numSlices>1){
time=(double)t*pointList.deltaT+pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][16];
}
else{
time=(double)t*pointList.deltaT;
}
//end of only chamge due to scanning
pointList.A[t+pointList.PLh][0] = 1.*weight;
pointList.A[t+pointList.PLh][1] = time*weight;
pointList.A[t+pointList.PLh][2] = pow(time,2.)*weight;
pointList.A[t+pointList.PLh][3] = pow(time,3.)*weight;
pointList.y[0][t+pointList.PLh] = pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][3]*weight;
}
makeAT(pointList.PL,4);
makeATA(pointList.PL,4);
makeATY(pointList.PL,4,0);
solve(pointList.PL,4);
pointList.point[pointList.PLh][i][6]=pointList.X[0]; //pointList.point[pointList.PLh][ind[pointList.PLh]][3];//
pointList.point[pointList.PLh][i][9]=pointList.X[1]; //(1./(2.*pointList.pointList.deltaT))*(pointList.point[11][ind[11]][3]-pointList.point[9][ind[9]][3]);//
pointList.point[pointList.PLh][i][12]=2.*pointList.X[2]; //(1./(pointList.pointList.deltaT*pointList.pointList.deltaT))*(pointList.point[11][ind[11]][3]-2.*pointList.point[pointList.PLh][ind[pointList.PLh]][3]+pointList.point[9][ind[9]][3]);//
//z-Component
setAllMatrixesToZero(4);
for(int t=minIndex-pointList.PLh;t<maxIndex-pointList.PLh+1;t++){
weight = pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][15];
weight = 1.-1./(1.+exp(-300.*(weight-0.015)));
weight = 1.; //Beat March 2009
//this is the only chamge due to scanning, works also if numSlice=0
if(pointList.numSlices>1){
time=(double)t*pointList.deltaT+pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][16];
}
else{
time=(double)t*pointList.deltaT;
}
//end of only chamge due to scanning
pointList.A[t+pointList.PLh][0] = 1.*weight;
pointList.A[t+pointList.PLh][1] = time*weight;
pointList.A[t+pointList.PLh][2] = pow(time,2.)*weight;
pointList.A[t+pointList.PLh][3] = pow(time,3.)*weight;
pointList.y[0][t+pointList.PLh] = pointList.point[t+pointList.PLh][ind[t+pointList.PLh]][4]*weight;
}
makeAT(pointList.PL,4);
makeATA(pointList.PL,4);
makeATY(pointList.PL,4,0);
solve(pointList.PL,4);
pointList.point[pointList.PLh][i][7]=pointList.X[0]; //pointList.point[pointList.PLh][ind[pointList.PLh]][4];//
pointList.point[pointList.PLh][i][10]=pointList.X[1];//(1./(2.*pointList.pointList.deltaT))*(pointList.point[11][ind[11]][4]-pointList.point[9][ind[9]][4]);//
pointList.point[pointList.PLh][i][13]=2.*pointList.X[2]; //(1./(pointList.pointList.deltaT*pointList.pointList.deltaT))*(pointList.point[11][ind[11]][4]-2.*pointList.point[10][ind[10]][4]+pointList.point[9][ind[9]][4]);//
//max break!
velocity=pow(pow(pointList.point[10][i][8],2.)+pow(pointList.point[10][i][9],2.)+pow(pointList.point[10][i][10],2.),0.5);
if(velocity>pointList.tolMaxVel){
pointList.point[pointList.PLh][i][14]=0;
}
}
}
}
void setAllMatrixesToZero(int size)
{
for(int i=0;i<500;i++){
if(i<size){
pointList.X[i]=0.;
pointList.ATY[i]=0.;
pointList.BTY[i]=0.;
pointList.CTY[i]=0.;
}
pointList.Y[i]=0.;
pointList.YuB[i]=0.;
pointList.YvB[i]=0.;
pointList.YwB[i]=0.;
pointList.Yaz[i]=0.;
pointList.Yay[i]=0.;
pointList.Yax[i]=0.;
for(int j=0;j<size;j++){
pointList.A[i][j]=0.;
pointList.AT[j][i]=0.;
if(i<size){pointList.ATA[i][j]=0.;}
pointList.B[i][j]=0.;
pointList.BT[j][i]=0.;
if(i<size){pointList.BTB[i][j]=0.;}
pointList.C[i][j]=0.;
pointList.CT[j][i]=0.;
if(i<size){pointList.CTC[i][j]=0.;}
}
}
}
void makeAT(int n, int m)
{
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
pointList.AT[i][j]=pointList.A[j][i];
}
}
}
void makeATA(int n, int m)
{
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
pointList.ATA[i][j]=0.;
for(int k=0;k<n;k++){
pointList.ATA[i][j]=pointList.ATA[i][j]+pointList.AT[i][k]*pointList.A[k][j];
}
}
}
}
void makeATY(int n, int m,int wh)
{
for(int i=0;i<m;i++){
pointList.ATY[i]=0.;
for(int k=0;k<n;k++){
pointList.ATY[i]=pointList.ATY[i]+pointList.AT[i][k]*pointList.y[wh][k];
}
}
}
bool solve(int n, int m)
{
double faktor;
bool ok=true;
for(int i=1;i<m;i++){
for(int j=i;j<m;j++){
if(fabs(pointList.ATA[j][i-1])>0.){
faktor=pointList.ATA[i-1][i-1]/pointList.ATA[j][i-1];
for(int k=0;k<m;k++){
pointList.ATA[j][k]=pointList.ATA[i-1][k]-faktor*pointList.ATA[j][k];
}
pointList.ATY[j]=pointList.ATY[i-1]-faktor*pointList.ATY[j];
}
}
}
for(int i=m-1;i>-1;i--){
for(int j=i+1;j<m;j++){
pointList.ATY[i]=pointList.ATY[i]-pointList.ATA[i][j]*pointList.X[j];
}
if(fabs(pointList.ATA[i][i])>0.){
pointList.X[i]=pointList.ATY[i]/pointList.ATA[i][i];
}
else{
ok=false;
}
}
return ok;
}
////////////////////von Beat June 2011
void makeBT(int n, int m)
{
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
pointList.BT[i][j]=pointList.B[j][i];
}
}
}
void makeBTB(int n, int m)
{
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
pointList.BTB[i][j]=0.;
for(int k=0;k<n;k++){
pointList.BTB[i][j]=pointList.BTB[i][j]+pointList.BT[i][k]*pointList.B[k][j];
}
}
}
}
void makeBTY(int n, int m,int wh)
{
for(int i=0;i<m;i++){
pointList.BTY[i]=0.;
for(int k=0;k<n;k++){
switch (wh){
case 1:
pointList.BTY[i]=pointList.BTY[i]+pointList.BT[i][k]*pointList.YuB[k];
break;
case 2:
pointList.BTY[i]=pointList.BTY[i]+pointList.BT[i][k]*pointList.YvB[k];
break;
case 3:
pointList.BTY[i]=pointList.BTY[i]+pointList.BT[i][k]*pointList.YwB[k];
break;
}
}
}
}
void makeBTYa(int n, int m,int wh)
{
for(int i=0;i<m;i++){
pointList.BTY[i]=0.;
for(int k=0;k<n;k++){
switch (wh){
case 1:
pointList.BTY[i]=pointList.BTY[i]+pointList.BT[i][k]*pointList.YaxB[k];
break;
case 2:
pointList.BTY[i]=pointList.BTY[i]+pointList.BT[i][k]*pointList.YayB[k];
break;
case 3:
pointList.BTY[i]=pointList.BTY[i]+pointList.BT[i][k]*pointList.YazB[k];
break;
}
}
}
}
bool solveB(int n, int m)
{
double faktor;
bool ok=true;
for(int i=1;i<m;i++){
for(int j=i;j<m;j++){
if(fabs(pointList.BTB[j][i-1])>0.){
faktor=pointList.BTB[i-1][i-1]/pointList.BTB[j][i-1];
for(int k=0;k<m;k++){
pointList.BTB[j][k]=pointList.BTB[i-1][k]-faktor*pointList.BTB[j][k];
}
pointList.BTY[j]=pointList.BTY[i-1]-faktor*pointList.BTY[j];
}
}
}
for(int i=m-1;i>-1;i--){
for(int j=i+1;j<m;j++){
pointList.BTY[i]=pointList.BTY[i]-pointList.BTB[i][j]*pointList.X[j];
}
if(fabs(pointList.BTB[i][i])>0.){
pointList.X[i]=pointList.BTY[i]/pointList.BTB[i][i];
}
else{
ok=false;
}
}
return ok;
}
void makeCT(int n, int m)
{
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
pointList.CT[i][j]=pointList.C[j][i];
}
}
}
void makeCTC(int n, int m)
{
for(int i=0;i<m;i++){
for(int j=0;j<m;j++){
pointList.CTC[i][j]=0.;
for(int k=0;k<n;k++){
pointList.CTC[i][j]=pointList.CTC[i][j]+pointList.CT[i][k]*pointList.C[k][j];
}
}
}
}
void makeCTY(int n, int m,int wh)
{
for(int i=0;i<m;i++){
pointList.CTY[i]=0.;
for(int k=0;k<n;k++){
pointList.CTY[i]=pointList.CTY[i]+pointList.CT[i][k]*pointList.yC[wh][k];
}
}
}
bool solveC(int n, int m)
{
double faktor;
bool ok=true;
for(int i=1;i<m;i++){
for(int j=i;j<m;j++){
if(fabs(pointList.CTC[j][i-1])>0.){
faktor=pointList.CTC[i-1][i-1]/pointList.CTC[j][i-1];
for(int k=0;k<m;k++){
pointList.CTC[j][k]=pointList.CTC[i-1][k]-faktor*pointList.CTC[j][k];
}
pointList.CTY[j]=pointList.CTY[i-1]-faktor*pointList.CTY[j];
}
}
}
for(int i=m-1;i>-1;i--){
for(int j=i+1;j<m;j++){
pointList.CTY[i]=pointList.CTY[i]-pointList.CTC[i][j]*pointList.X[j];
}
if(fabs(pointList.CTC[i][i])>0.){
pointList.X[i]=pointList.CTY[i]/pointList.CTC[i][i];
}
else{
ok=false;
}
}
return ok;
}
void writeXUAPFile(int t)
{
FILE *fpp;
char name[256];
int c;
c=sprintf (name, pointList.path);
c+=sprintf (name+c, "/xuap.");
c+=sprintf (name+c, "%1d", t);
fpp = fopen(name,"w");
for(int i=1;i<pointList.point[pointList.PLh][0][0];i++){
if(pointList.point[pointList.PLh][i][14]>0){
pointList.count++;
double vel=pow( pow(pointList.point[pointList.PLh][i][8],2.)
+pow(pointList.point[pointList.PLh][i][9],2.)
+pow(pointList.point[pointList.PLh][i][10],2.),0.5);
double acc=pow( pow(pointList.point[pointList.PLh][i][11],2.)
+pow(pointList.point[pointList.PLh][i][12],2.)
+pow(pointList.point[pointList.PLh][i][13],2.),0.5);
pointList.meanVel=(pointList.meanVel*(double)(pointList.count-1)+vel)/(double)pointList.count;
pointList.meanAcc=(pointList.meanAcc*(double)(pointList.count-1)+acc)/(double)pointList.count;
if(vel>pointList.maxVel){
pointList.maxVel=vel;
}
}
for(int j=0;j<14;j++){
if(j<5 || pointList.point[pointList.PLh][i][14]>0){
fprintf(fpp, "%lf\t", pointList.point[pointList.PLh][i][j]);
}
else{
fprintf(fpp, "%lf\t", 0.);
}
}
fprintf(fpp, "%lf\n", pointList.point[pointList.PLh][i][14]);
}
fclose (fpp);
}
void followTrajPoint(FILE *fpp, int t,int startPoint)
{
int ind_X,ind_Y,ind_Z,ind_C,ind_count;
short ind_list[1000];
int pCounterA,pCounterB,pCounterC,numInTraj;
int startT, startP;
double dist,dx,dy,dz;
double centerX,centerY,centerZ;
double Liu[5],Liv[5],Liw[5],Liax[4],Liay[4],Liaz[4];
double ux,uy,uz,vx,vy,vz,wx,wy,wz;
double dix,diy,diz,absDi,Dx,Dy,Dz,lx,ly,lz,cx,cy,cz,refx,refy,refz;
double w1,w2,w3,s11,s12,s13,s22,s23,s33,ww1,ww2,ww3,wwsij;
double s111,s222,s333,s112,s113,s221,s223,s331,s332,s123;
double sijsjkski,wsq,twosijsij,R,Q,div,ref,diss,USq;
int time;
double u[3];
double a[3];
double ref_diva,diva,reldiva,quality,reldivu;
double minDistA[500];
int minDistAIndex[500];
double minDistB[500];
int minDistBIndex[500];
double minDistC[500];
int minDistCIndex[500];
double um,up,vm,vp,wm,wp;
bool okc,contin;
int rank;
int start;
int end;
int minCounter;
int counter_f;
double avU[3];
double avA[3];
bool ok;
startT=t;
if(t==pointList.firstFile){
cout << "\nreading initial xuap, may take some time....\n\n";
readXUAPFile(t,true);
}
else{
readXUAPFile(t,false);
}
start=1;
end=(int)(pointList.point[2][0][0]+0.5); // 1. field tells number of rows
int n;
for(int nn=start;nn<end;nn++){
time=2; // is set to 2 to calculate local acc
/*if(end>5000){
if(nn % 2000 == 0){
cout << "processing point ............."<<nn<<"\n";
}
}*/
//if((double)pointList.count3/(double)pointList.count>0){
// cout << "point per sphere.............."<<(double)pointList.count3/(double)pointList.count<<"\n";
//}
if(pointList.point[2][nn][11]>0. && !(pointList.occ[t-pointList.firstFile][nn]) ){
startP=nn;
ok=true;
numInTraj=0;
pointList.noDeriv=0;
n=nn;
while(ok){
pointList.occ[t+time-2-pointList.firstFile][n]=true;
//interpolieren und rausschreiben mit t,n (Zeit und Startpunkt)
//%Da soll jetzt duidxj linear interpoliert werden
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
//%die nächsten Punkte zu Punkt x,y,z, finden
pointList.count++;
setAllMatrixesToZero(4);
contin=true;
if(pointList.derivatives){
centerX=pointList.point[time][n][2]; // filtered x,y,z
centerY=pointList.point[time][n][3];
centerZ=pointList.point[time][n][4];
for(int i=0;i<500;i++){
minDistA[i]=1000; // initialization for the search radius, max. 1000 mm
minDistB[i]=1000;
minDistC[i]=1000;
minDistAIndex[i]=0;
minDistBIndex[i]=0;
minDistCIndex[i]=0;
}
/// Beat March 2013, these 3 for loops are VERY SLOW for large number of particles, i.e. for scanning
//AAAAAAAAAAAA time step t-1
// the following bit has been replaced by fast_search
/*for(int i=1;i<pointList.point[time-1][0][0]+1;i++){
dist=pow(pow(pointList.point[time-1][i][2]-centerX,2.)+pow(pointList.point[time-1][i][3]-centerY,2.)+pow(pointList.point[time-1][i][4]-centerZ,2.),0.5); // distance between measurement point and all points in the xuap file
if(dist<minDistA[pointList.maxRank] && pointList.point[time-1][i][11]>0.){ // check if cubic spline successful
rank=pointList.maxRank; // whole paragraph: sorting the points according to their distance to measurement point: k=0 closest point, k=500 last point
for(int k=pointList.maxRank;k>-1;k--){
if(dist<minDistA[k]){
rank=k;
}
}
for(int l=pointList.maxRank;l>rank;l--){
minDistA[l]=minDistA[l-1];
minDistAIndex[l]=minDistAIndex[l-1];
}
minDistA[rank]=dist;
minDistAIndex[rank]=i;
}
}
for(int i=0;i<500;i++){
minDistA[i]=1000; // initialization for the search radius, max. 1000 mm
minDistAIndex[i]=0;
}*/
//end of replaced stuff
//Beat March 2013 find i not as loop thorugh everything, but only through 3 x 3 surounding grid cells
ind_X=(int)((double)(centerX-pointList.minX)/pointList.dh_X);
ind_Y=(int)((double)(centerY-pointList.minY)/pointList.dh_Y);
ind_Z=(int)((double)(centerZ-pointList.minZ)/pointList.dh_Z);
if(ind_X<0 ){ind_X=0 ;}
if(ind_Y<0 ){ind_Y=0 ;}
if(ind_Z<0 ){ind_Z=0 ;}
if(ind_X>pointList.max_grid_X-1){ind_X=pointList.max_grid_X-1;}
if(ind_Y>pointList.max_grid_Y-1){ind_Y=pointList.max_grid_Y-1;}
if(ind_Z>pointList.max_grid_Z-1){ind_Z=pointList.max_grid_Z-1;}
ind_count=0;
for (int ii=-1;ii<2;ii++){
for (int jj=-1;jj<2;jj++){
for (int kk=-1;kk<2;kk++){
if(ind_X+ii>=0 && ind_Y+jj>=0 && ind_Z+kk>=0 && ind_X+ii<pointList.max_grid_X && ind_Y+jj<pointList.max_grid_Y && ind_Z+kk<pointList.max_grid_Z){
ind_C=pointList.fast_search[time-1][ind_X+ii][ind_Y+jj][ind_Z+kk][pointList.max_grid_C];
if(ind_C>0){
for(int ind=0;ind<ind_C;ind++){
ind_list[ind_count]=pointList.fast_search[time-1][ind_X+ii][ind_Y+jj][ind_Z+kk][ind];
ind_count++;
}
}
}
}
}
}
for(int ind=0;ind<ind_count;ind++){
int i=ind_list[ind];
//end of i replacement
dist=pow(pow(pointList.point[time-1][i][2]-centerX,2.)+pow(pointList.point[time-1][i][3]-centerY,2.)+pow(pointList.point[time-1][i][4]-centerZ,2.),0.5); // distance between measurement point and all points in the xuap file
if(dist<minDistA[pointList.maxRank] && pointList.point[time-1][i][11]>0.){ // check if cubic spline successful
rank=pointList.maxRank; // whole paragraph: sorting the points according to their distance to measurement point: k=0 closest point, k=500 last point
for(int k=pointList.maxRank;k>-1;k--){
if(dist<minDistA[k]){
rank=k;
}
}
for(int l=pointList.maxRank;l>rank;l--){