-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubwindows.cpp
More file actions
executable file
·1279 lines (1029 loc) · 30.7 KB
/
Copy pathsubwindows.cpp
File metadata and controls
executable file
·1279 lines (1029 loc) · 30.7 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
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
#include "subwindow.h"
int Open_app(char path[256],char file[256])
{
//HINSTANCE hNewExe = ShellExecuteA(NULL, "open", "G:\\Ideas\\DSCM-CAU\\test\\ParallelEPCA.exe", NULL, NULL, SW_SHOW);
//HINSTANCE hNewExe1= ShellExecute(NULL,"open","C:\\xxx.exe",NULL,“c:\\”,SW_SHOW);
//HINSTANCE hNewExe = ShellExecuteA(NULL, "open", "G:\\Ideas\\DSCM-CAU\\test\\ParallelEPCA.exe", NULL, "G:\\Ideas\\DSCM-CAU\\test\\", SW_SHOWNORMAL);
//HINSTANCE hNewExe = ShellExecuteA(NULL, "open", file, NULL, path, SW_SHOWNORMAL);
HINSTANCE hNewExe = ShellExecuteA(NULL, "open", file, NULL, path, SW_SHOW);
if ((DWORD)hNewExe <= 32)
{
printf("return value:%d\n", (DWORD)hNewExe);
}
else
{
printf("successed!\n");
}
/*printf("GetLastError: %d\n", GetLastError());*/
//system("pause");
return 1;
}
BOOL FindandKill_process(HWND hWnd)
{
DWORD ProcessID;
HANDLE hProcess;
if (hWnd == NULL)
{
return FALSE;
}
else
{
if (GetWindowThreadProcessId(hWnd, &ProcessID) == 0)//ハァーワ
{
return FALSE;
}
else
{
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessID);
if (hProcess == NULL)
{
return FALSE;
}
else
{
if (TerminateProcess(hProcess, 0))
{
return TRUE;
}
else
{
return FALSE;
}
}
}
}
}
void SAPSO_main1(int particleN[1],double learningCof[4],double SimuACof[2],int maxIter[1],int inverseD[1],int *paraLocation,int randSeed[1],double *inverseUp,double *inverseDn,double epX[1],int monitorN[1],double *monitorX,double *monitorY,double *monitorV,double *inversePara,double misFit[1],char workingPath[256],int parallelN[1],int sectionN[1],int *sectionOrder,int monitorT[1])
{
//*开发日志--------------------------------------------------------------------------------------------------------------------------------
//Developer:Jade Wang
//Version: 1.0
//2022.12.04:搭建软件基本框架
//2022.12.05:编好SA-PSO主程序
//*输入------------------------------------------------------------------------------------------------------------------------------------
//particleN:粒子数
//learningCof:学习率,0-wmin,1-wmax,2-c1,3-c2
//SimuACof:退火因子,0-初始温度,1-衰减系数
//maxIter:最大迭代数
//inverseD:反分析参数个数
//paralocation:反分析参数在material.txt的位置
//randSeed:随机种子数
//inverseUp:反分析参数上限,包括位置和速度,如果是2维度的,10,0.49,1,0.05
//inverseDn:反分析参数下限,包括位置和速度,如果是2维度的,2,0.2,-1,-0.05
//epX:误差
//monitorN:监测点个数
//monitorX:监测点X
//monitorY:监测点Y
//monitorV:监测点实测值
//workingPath:工作目录
//parallelN:并行个数
//sectionN:监测时刻个数
//sectionOrder:监测时刻代号(步数)
//*输出------------------------------------------------------------------------------------------------------------------------------------
//inversePara:反分析参数值
//misFit:误差
//*初始声明与赋值--------------------------------------------------------------------------------------------------------------------------------
int i,j,k;
double **x;
double **v;
double **p;
double *pg;
double *ifit;
double *TF;
double gfit;
double ***simunateV;
x = new double *[particleN[0]];
v = new double *[particleN[0]];
p = new double *[particleN[0]];
pg = new double [inverseD[0]];
ifit = new double [particleN[0]];
TF = new double [particleN[0]];
for (i = 0; i< particleN[0];i++)
{
x[i] = new double [inverseD[0]];
v[i] = new double [inverseD[0]];
p[i] = new double [inverseD[0]];
}
double sumTF;
double T;
int iter;
double w;
int materialN;
double **materialV;
//int **materialI;
char materialPath[256];
simunateV = new double **[particleN[0]];
for(i = 0; i<particleN[0];i++)
{
simunateV[i] = new double *[sectionN[0]];
for (j = 0; j<sectionN[0];j++)
{
simunateV[i][j] = new double [monitorN[0]*2];
}
}
int *infoMonitor;
infoMonitor = new int [5*monitorN[0]];
char misFitPath[256];
char processPath[256];
//*主程序---------------------------------------------------------------------------------------------------------------------------------------
sprintf(misFitPath,"%s\\MisFit.txt",workingPath);
sprintf(processPath,"%s\\Process.txt",workingPath);
ofstream misFitFile(misFitPath);
ofstream processFile(processPath);
sprintf(materialPath,"%sMODEL\\Materials.txt",workingPath);
FILE *materialFile=fopen(materialPath,"r");
fscanf(materialFile, "%d" ,&materialN);
materialV = new double *[materialN];
//materialI = new int *[materialN];
for (i = 0;i<materialN;i++)
{
materialV[i] = new double [22];
//materialI[i] = new int [2];
for (j=0;j<22;j++)
fscanf(materialFile, "%lf",&materialV[i][j]);
}
/*for (i = 0; i< materialN;i++)
{
for (j=0;j<22;j++)
printf("%lf\n",materialV[i][j]);
}*/
fclose(materialFile);
//--找到监测点所属的单元
Find_monitors(workingPath,monitorN,monitorX,monitorY,infoMonitor);
iter = 0;
//--初始化速度和位置
Initial_rand(randSeed[0]);
for (i = 0 ; i<particleN[0];i++)
{
for (j = 0; j<inverseD[0];j++)
{
x[i][j] = inverseDn[j] + (inverseUp[j] - inverseDn[j]) * Get_rand();
v[i][j] = inverseDn[j+inverseD[0]] + (inverseUp[j+inverseD[0]] - inverseDn[j+inverseD[0]]) * Get_rand();
p[i][j] = x[i][j];
}
}
//--计算适应值
//新建文件夹
Create_dir(workingPath,iter+1,parallelN);
//更改txt参数赋值
Assign_para(workingPath,iter+1,parallelN,inverseD,paraLocation,x,materialN,materialV,sectionN,sectionOrder);
//并行计算
Cal_parallel(workingPath,iter+1,parallelN);
//提取对应点的数据
Extract_data(workingPath,iter+1,parallelN,monitorT,monitorN,monitorX,monitorY,infoMonitor,simunateV,sectionN,sectionOrder);
/*for (i=0;i<particleN[0];i++)
{
for (j = 0;j<monitorN[0];j++)
{
printf("%d %d %e\n",i,j,simunateV[i][j]);
}
}
exit(0);*/
//计算适应值大小,比较局部最优适应值,存入ifit[i]
Cal_fitness(ifit,monitorT,particleN,monitorN,simunateV,monitorV,iter,sectionN,p,x);
/*for (i = 0;i<particleN[0];i++)
printf("%d %e\n",i,ifit[i]);*/
//--计算全局最优
gfit = ifit[0];
for (j=0;j<inverseD[0];j++)
pg[0]=p[0][j];
for (i=1;i<particleN[0];i++)
{
if (ifit[i]<gfit)
{
gfit = ifit[i];
for (j=0;j<inverseD[0];j++)
pg[j]=p[i][j];
}
}
//--确定初始温度
T = SimuACof[0];
do{
//--确定温度适配值
sumTF = 0.0;
for (i=0;i<particleN[0];i++)
{
TF[i] = exp(-(ifit[i]-gfit)/T);
sumTF += TF[i];
}
for (i=0;i<particleN[0];i++)
{
TF[i]/=sumTF;
}
//轮盘赌
sumTF = 0.0;
for (i=0;i<particleN[0];i++)
{
sumTF += TF[i];
if (Get_rand()<=sumTF)
{
gfit = ifit[i];
for (j=0;j<inverseD[0];j++)
pg[j]=p[i][j];
break;
}
}
//速度更新
w = learningCof[1] - (learningCof[1]-learningCof[0])*iter/maxIter[0];
for (i=0;i<particleN[0];i++)
{
for (j=0;j<inverseD[0];j++)
{
v[i][j] = w * v[i][j] + learningCof[2] * Get_rand() * (p[i][j] - x[i][j]) + learningCof[3] * Get_rand() * (pg[j] - x[i][j]) ;
if (v[i][j]>inverseUp[j+inverseD[0]])
v[i][j] = inverseUp[j+inverseD[0]];
if (v[i][j]<inverseDn[j+inverseD[0]])
v[i][j] = inverseDn[j+inverseD[0]];
x[i][j] = x[i][j] + v[i][j];
if (x[i][j]>inverseUp[j])
x[i][j] = inverseUp[j];
if (x[i][j]<inverseDn[j])
x[i][j] = inverseDn[j];
}
}
iter++;
//processFile.precision(9);
processFile<<"Step "<<iter <<endl;
for (i =0;i<particleN[0];i++)
{
for (j =0;j<sectionN[0];j++)
{
for (k=0;k<monitorN[0];k++)
{
processFile<<i+1<<" "<<j+1<<" "<<k+1<<" "<<simunateV[i][j][k]<<" "<<monitorV[k]<<endl;
}
}
}
for (j=0;j<inverseD[0];j++)
inversePara[j]=pg[j];
misFit[0] = gfit;
misFitFile.precision(9);
misFitFile<<iter<<" "<<1e4*misFit[0];
for (j=0;j<inverseD[0];j++)
misFitFile<<" "<<inversePara[j];
misFitFile<<endl;
//--计算适应值
//新建文件夹
Create_dir(workingPath,iter+1,parallelN);
//更改txt参数赋值
Assign_para(workingPath,iter+1,parallelN,inverseD,paraLocation,x,materialN,materialV,sectionN,sectionOrder);
//并行计算
Cal_parallel(workingPath,iter+1,parallelN);
//提取对应点的数据
Extract_data(workingPath,iter+1,parallelN,monitorT,monitorN,monitorX,monitorY,infoMonitor,simunateV,sectionN,sectionOrder);
/*for (i=0;i<particleN[0];i++)
{
for (j = 0;j<monitorN[0];j++)
{
printf("%d %d %e\n",i,j,simunateV[i][j]);
}
}
exit(0);*/
//计算适应值大小,比较局部最优适应值,存入ifit[i]
Cal_fitness(ifit,monitorT,particleN,monitorN,simunateV,monitorV,iter,sectionN,p,x);
/*for (i = 0;i<particleN[0];i++)
printf("%d %e\n",i,ifit[i]);*/
//--计算全局最优
gfit = ifit[0];
for (j=0;j<inverseD[0];j++)
pg[0]=p[0][j];
for (i=1;i<particleN[0];i++)
{
if (ifit[i]<gfit)
{
gfit = ifit[i];
for (j=0;j<inverseD[0];j++)
pg[j]=p[i][j];
}
}
//--存储
/*for (i=1;i<particleN[0];i++)
{
printf("%e\n",ifit[i]);
}*/
//if (gfit<epX[0])
if (misFit[0]<epX[0])
{
break;
}
T *= SimuACof[1];
//iter++;
}while(iter<maxIter[0]);
misFitFile.close();
processFile.close();
//*主程序end---------------------------------------------------------------------------------------------------------------------------------------
//*内存清零------------------------------------------------------------------------------------------------------------------------------------
for (i = 0; i< particleN[0];i++)
{
delete []x[i];
delete []v[i];
delete []p[i];
}
delete []x;
delete []v;
delete []pg;
delete []ifit;
delete []TF;
for (i=0;i<materialN;i++)
{
delete []materialV[i];
//delete []materialI[i];
}
for (i = 0;i<particleN[0];i++)
{
for (j=0;j<sectionN[0];j++)
{
delete []simunateV[i][j];
}
delete []simunateV[i];
}
delete []materialV;
delete []simunateV;
delete []infoMonitor;
//delete []materialI;
}
double Get_rand()
{
//srand(time(0));//srand()函数产生一个以当前时间开始的随机种子.应该放在for等循环语句前面 不然要很长时间等待
//return rand()%(NNN+1)/(double)(NNN+1);
//std::default_random_engine e;
//for (size_t i = 0; i < 5; ++i) //生成五个随机数
// std::cout << e() << std::endl;
//
//return 0;
//int nn = 99999;
//static uniform_int_distribution<unsigned> u(0,nn);
return ((double)u(e));
}
void Initial_rand(int index)
{
if (index == 0)
{
e.seed(time(0));
}
else
{
e.seed(index);
}
}
void Create_dir(char workingPath[256],int iter,int parallelN[1])
{
int i;
char command[256];
char iter_Char[256];
char currentDir[256];
//system("stty -echo");
itoa(iter,iter_Char,10);
sprintf(currentDir,"%s\\iter%s", workingPath,iter_Char);
std::string prefix = currentDir;
if (_access(prefix.c_str(), 0) == -1) //如果文件夹不存在
_mkdir(prefix.c_str()); //则创建
for (i=0;i<parallelN[0];i++)
{
char path1[256];
char path2[256];
char path3[256];
char path4[256];
char oldDir[256];
char newDir[256];
char oldDir2[256];
char newDir2[256];
char i_Char[256];
itoa(i+1,i_Char,10);
sprintf(path1,"%s\\%s", currentDir,i_Char);
sprintf(path2,"%s\\%s\\cal\\", currentDir,i_Char);
sprintf(path3,"%s\\%s\\cal\\data\\", currentDir,i_Char);
sprintf(path4,"%s\\%s\\cal\\input\\", currentDir,i_Char);
prefix = path1;
if (_access(prefix.c_str(), 0) == -1) //如果文件夹不存在
_mkdir(prefix.c_str()); //则创建
prefix = path2;
if (_access(prefix.c_str(), 0) == -1) //如果文件夹不存在
_mkdir(prefix.c_str()); //则创建
prefix = path3;
if (_access(prefix.c_str(), 0) == -1) //如果文件夹不存在
_mkdir(prefix.c_str()); //则创建
prefix = path4;
if (_access(prefix.c_str(), 0) == -1) //如果文件夹不存在
_mkdir(prefix.c_str()); //则创建
sprintf(oldDir,"%s\\MODEL", workingPath);
sprintf(newDir,"%s\\%s\\cal\\input", currentDir,i_Char);
std::string pre = oldDir;
std::string now = newDir;
Dir::copy(pre, now);
sprintf(oldDir2,"%s\\APP", workingPath);
sprintf(newDir2,"%s\\%s", currentDir,i_Char);
pre = oldDir2;
now = newDir2;
Dir::copy(pre, now);
}
}
void Assign_para(char workingPath[256],int iter,int parallelN[1],int inverseD[1],int *paraLocation,double **x,int materialN,double **materialV, int sectionN[1],int *sectionOrder)
{
int i,j,k;
char currentDir[256];
char iter_Char[256];
itoa(iter,iter_Char,10);
sprintf(currentDir,"%s\\iter%s", workingPath,iter_Char);
for (i=0;i<parallelN[0];i++)
{
char path[256];
char path2[256];
char path3[256];
char i_Char[256];
itoa(i+1,i_Char,10);
sprintf(path,"%s\\%s\\cal\\input\\Materials.txt", currentDir,i_Char);
sprintf(path2,"%s\\%s\\cal\\input\\Monitoring.txt", currentDir,i_Char);
sprintf(path3,"%s\\%s\\cal\\data\\IsEnd.txt", currentDir,i_Char);
for(k = 0;k<materialN;k++)
{
for (j = 0; j<inverseD[0];j++)
{
if (paraLocation[2*j]==k+1)
{
materialV[k][paraLocation[2*j+1]-1] = x[i][j];
}
}
}
ofstream materialNew(path);
materialNew<<materialN<<endl;
for(k = 0;k<materialN;k++)
{
/*materialNew<<(int)materialV[k][0]<<" "<<(int)materialV[k][1]<<" "<<materialV[k][2]<<" "<<materialV[k][3]<<" "<<materialV[k][4]<<" " \
<<materialV[k][5]<<" "<<materialV[k][6]<<" "<<materialV[k][7]<<" "<<materialV[k][8]<<" "<<materialV[k][9]<<" "\
<<materialV[k][10]<<" "<<materialV[k][11]<<" "<<materialV[k][12]<<" "<<materialV[k][13]<<" "<<materialV[k][14]<<" "\
<<materialV[k][15]<<" "<<materialV[k][16]<<" "<<materialV[k][17]<<" "<<materialV[k][18]<<" "<<(int)materialV[k][19]<<" "\
<<materialV[k][20]<<" "<<materialV[k][21]<<" "<<materialV[k][22]<<endl;*/
materialNew<<(int)materialV[k][0]<<" "<<(int)materialV[k][1]<<" "<<materialV[k][2]<<" "<<materialV[k][3]<<" "<<materialV[k][4]<<" " \
<<materialV[k][5]<<" "<<materialV[k][6]<<" "<<materialV[k][7]<<" "<<materialV[k][8]<<" "<<materialV[k][9]<<" "\
<<materialV[k][10]<<" "<<materialV[k][11]<<" "<<materialV[k][12]<<" "<<materialV[k][13]<<" "<<materialV[k][14]<<" "\
<<materialV[k][15]<<" "<<materialV[k][16]<<" "<<materialV[k][17]<<" "<<materialV[k][18]<<" "<<(int)materialV[k][19]<<" "\
<<materialV[k][20]<<" "<<materialV[k][21]<<endl;
}
materialNew.close();
ofstream monitoringFile(path2);
monitoringFile<<sectionN[0]<<endl;
for(j=0;j<sectionN[0];j++)
{
monitoringFile<<sectionOrder[j]<<endl;
}
monitoringFile.close();
std::string isEndFile = path3;
if (access(isEndFile.c_str(), 0) == 0)//文件存在
{
if (remove(isEndFile.c_str()) == 0)
{
}
}
}
}
void Cal_parallel(char workingPath[256],int iter,int parallelN[1])
{
int i,j;
int index = 0;
int indexTemp;
char currentDir[256];
char iter_Char[256];
itoa(iter,iter_Char,10);
sprintf(currentDir,"%s\iter%s", workingPath,iter_Char);
//for (i=0;i<2;i++)
for (i=0;i<parallelN[0];i++)
{
char path[256];
char file[256];
char i_Char[256];
itoa(i+1,i_Char,10);
sprintf(path,"%s\\%s\\", currentDir,i_Char);
sprintf(file,"%s\\%s\\ParallelEPCA.exe", currentDir,i_Char);
printf("%d app running ",i+1);
Open_app(path,file);
}
do
{
index = 1;
//for (i=0;i<2;i++)
for (i=0;i<parallelN[0];i++)
{
char path[256];
char i_Char[256];
itoa(i+1,i_Char,10);
sprintf(path,"%s\\%s\\cal\\data\\IsEnd.txt", currentDir,i_Char);
std::string isEndFile = path;
if (access(isEndFile.c_str(), 0) == 0)//文件存在
{
FILE *fpIsEnd = fopen(path,"r");
fscanf(fpIsEnd,"%d",&indexTemp);
fclose(fpIsEnd);
index = index * indexTemp;
}
else
{
index = 0;
}
}
//printf("%d",index);
if (index == 1)
{
break;
}
}while(1);
//_sleep(2*1000);
HWND *hWndRcv;
hWndRcv = new HWND [parallelN[0]];
if (index == 1)
{
//for (i=0;i<4;i++)
for (i=0;i<parallelN[0];i++)
{
char path[256];
char file[256];
char i_Char[256];
itoa(i+1,i_Char,10);
sprintf(path,"%s\\%s\\", currentDir,i_Char);
sprintf(file,"%s\\%s\\ParallelEPCA.exe", currentDir,i_Char);
char* szStr = file;
CString str = CString(szStr);
USES_CONVERSION;
LPCWSTR wszClassName = A2CW(W2A(str));
str.ReleaseBuffer();
//HWND hWndRcv = ::FindWindow(NULL,TEXT("G:\\Ideas\\DSCM-CAU\\test\\ParallelEPCA.exe"));
if (i==0)
{
//hWndRcv[0] = ::FindWindow(NULL,TEXT("G:\\Ideas\\DSCM-CAU\\test\\ParallelEPCA.exe"));
//hWndRcv[0] = ::FindWindow(NULL,TEXT("G:\\Ideas\\DSCM-CAU\\SAPSO\\SAPSO1\\SAPSO1\\Zhao1\\iter1\\1\\ParallelEPCA.exe"));
hWndRcv[0] = ::FindWindow(NULL,wszClassName);
//printf("%x\n",hWndRcv[0]);
}
else
{
hWndRcv[i] = ::FindWindow(NULL,wszClassName);
//hWndRcv[i] = ::FindWindowEx(NULL,hWndRcv[i-1],NULL,wszClassName);
//printf("%x\n",hWndRcv[i]);
}
FindandKill_process(hWndRcv[i]);
//_sleep(500);
//HWND hWndRcv = ::FindWindow(NULL,TEXT("G:\\Ideas\\DSCM-CAU\\SAPSO\\SAPSO1\\SAPSO1\\Zhao1\\iter1\\1\\ParallelEPCA.exe"));
//HWND hWndRcv = ::FindWindow(NULL,TEXT("ParallelEPCA.exe"));
//HWND hWndRcv = ::FindWindow(NULL,TEXT("ParallelEPCA"));
//HWND hWndRcv = ::FindWindow(NULL,wszClassName);
printf("%d app is closed!\n",i+1);
}
}
delete []hWndRcv;
}
void Extract_data(char workingPath[256],int iter,int parallelN[1],int monitorT[1],int monitorN[1],double *monitorX,double *monitorY,int *infoMonitor,double ***simunateV,int sectionN[1],int *sectionOrder)
{
int i,j,k;
char currentDir[256];
char iter_Char[256];
char headFile[256];
char tailFile[256];
double tmp[20];
double x,y,x1,y1,x2,y2,x3,y3,x4,y4;
double N1,N2,N3,N4;
int n[4];
double **nodeX,**nodeY,**nodeDispX,**nodeDispY;
nodeX = new double *[monitorN[0]];
nodeY = new double *[monitorN[0]];
nodeDispX = new double *[monitorN[0]];
nodeDispY = new double *[monitorN[0]];
for (i = 0 ; i<monitorN[0];i++)
{
nodeX[i] = new double [4];
nodeY[i] = new double [4];
nodeDispX[i] = new double [4];
nodeDispY[i] = new double [4];
}
itoa(iter,iter_Char,10);
sprintf(currentDir,"%s\iter%s", workingPath,iter_Char);
sprintf(headFile,"stress_strain");
sprintf(tailFile,"-2.3depca");
for (i=0;i<parallelN[0];i++)
{
char path[256];
char file[256];
char i_Char[256];
char order_Char[256];
itoa(i+1,i_Char,10);
for (j = 0;j<sectionN[0];j++)
{
sprintf(path,"%s\\%s\\cal\\data\\", currentDir,i_Char);
itoa(sectionOrder[j]-1,order_Char,10);
sprintf(file,"%s%s%s",headFile,order_Char,tailFile);
strcat(path,file);
for (k = 0;k<monitorN[0];k++)
{
/*x = monitorX[k];
y = monitorY[k];*/
n[0] = infoMonitor[5*k+1];
n[1] = infoMonitor[5*k+2];
n[2] = infoMonitor[5*k+3];
n[3] = infoMonitor[5*k+4];
int index = 4;
if (n[2]==n[3])
index = 3;
int nCount = 0;
if (index == 3)
{
//三角形
for (nCount =0; nCount<3;nCount++)
{
ifstream fin(path);
if (fin)
{
string str;
char ttt[1024];
int curLine = 0;
//int nCount = 0;
while (getline(fin, str))
{
curLine++;
if (curLine>2)
{
//三角形
if (curLine-3==n[nCount])
{
strcpy(ttt,str.c_str());
sscanf(ttt, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &nodeX[k][nCount],&nodeY[k][nCount],&tmp[0],&nodeDispX[k][nCount],&nodeDispY[k][nCount] ,\
&tmp[1],&tmp[2],&tmp[3],&tmp[4],&tmp[5],\
&tmp[6],&tmp[7],&tmp[8],&tmp[9],&tmp[10],\
&tmp[11],&tmp[12],&tmp[13],&tmp[14],&tmp[15]) ;
}
}
}
}
else
{
std::cout << "Open file faild." << std::endl;
printf("%s\n",path);
}
fin.close();
}
}
else
{
//四边形
for (nCount =0; nCount<4;nCount++)
{
ifstream fin(path);
if (fin)
{
string str;
char ttt[1024];
int curLine = 0;
//int nCount = 0;
while (getline(fin, str))
{
curLine++;
if (curLine>2)
{
//四边形
if (curLine-3==n[nCount])
{
strcpy(ttt,str.c_str());
sscanf(ttt, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &nodeX[k][nCount],&nodeY[k][nCount],&tmp[0],&nodeDispX[k][nCount],&nodeDispY[k][nCount] ,\
&tmp[1],&tmp[2],&tmp[3],&tmp[4],&tmp[5],\
&tmp[6],&tmp[7],&tmp[8],&tmp[9],&tmp[10],\
&tmp[11],&tmp[12],&tmp[13],&tmp[14],&tmp[15]) ;
}
}
}
}
else
{
std::cout << "Open file faild." << std::endl;
printf("%s\n",path);
}
fin.close();
}
}
}
for (k = 0;k<monitorN[0];k++)
{
x = monitorX[k];
y = monitorY[k];
if (infoMonitor[5*k+3] == infoMonitor[5*k+4])
{
//三角形
N1 = ((nodeX[k][1]*nodeY[k][2] -nodeX[k][2]*nodeY[k][1] ) + (nodeY[k][1]-nodeY[k][2])*x + (nodeX[k][2] - nodeX[k][1])*y) \
/ (nodeX[k][1]*nodeY[k][2] + nodeX[k][2]*nodeY[k][0] + nodeX[k][0] * nodeY[k][1] - nodeX[k][2] * nodeY[k][1] - nodeX[k][0] * nodeY[k][2] - nodeX[k][1] * nodeY[k][0] );
N2 = ((nodeX[k][2]*nodeY[k][0] -nodeX[k][0]*nodeY[k][2] ) + (nodeY[k][2]-nodeY[k][0])*x + (nodeX[k][0] - nodeX[k][2])*y) \
/ (nodeX[k][2]*nodeY[k][0] + nodeX[k][0]*nodeY[k][1] + nodeX[k][1] * nodeY[k][2] - nodeX[k][0] * nodeY[k][2] - nodeX[k][1] * nodeY[k][0] - nodeX[k][2] * nodeY[k][1] );
N3 = ((nodeX[k][0]*nodeY[k][1] -nodeX[k][1]*nodeY[k][0] ) + (nodeY[k][0]-nodeY[k][1])*x + (nodeX[k][1] - nodeX[k][0])*y) \
/ (nodeX[k][0]*nodeY[k][1] + nodeX[k][1]*nodeY[k][2] + nodeX[k][2] * nodeY[k][0] - nodeX[k][1] * nodeY[k][0] - nodeX[k][2] * nodeY[k][1] - nodeX[k][0] * nodeY[k][2] );
if (monitorT[0] == 0)
{
simunateV[i][j][k] = nodeDispX[k][0] * N1 + nodeDispX[k][1] * N2 + nodeDispX[k][2] * N3;
simunateV[i][j][k+monitorN[0]] = nodeDispY[k][0] * N1 + nodeDispY[k][1] * N2 + nodeDispY[k][2] * N3;
}
else if (monitorT[0] == 1)
{
simunateV[i][j][k] = nodeDispX[k][0] * N1 + nodeDispX[k][1] * N2 + nodeDispX[k][2] * N3;
}
else
{
simunateV[i][j][k+monitorN[0]] = nodeDispY[k][0] * N1 + nodeDispY[k][1] * N2 + nodeDispY[k][2] * N3;
}
}
else
{
//四边形
N1 = 0.25*(1.0+nodeX[k][0]*x) * (1.0 + nodeY[k][0] * y);
N2 = 0.25*(1.0+nodeX[k][1]*x) * (1.0 + nodeY[k][1] * y);
N3 = 0.25*(1.0+nodeX[k][2]*x) * (1.0 + nodeY[k][2] * y);
N4 = 0.25*(1.0+nodeX[k][3]*x) * (1.0 + nodeY[k][3] * y);
if (monitorT[0] == 0)
{
simunateV[i][j][k] = nodeDispX[k][0] * N1 + nodeDispX[k][1] * N2 + nodeDispX[k][2] * N3 + nodeDispX[k][3] * N4;
simunateV[i][j][k+monitorN[0]] = nodeDispY[k][0] * N1 + nodeDispY[k][1] * N2 + nodeDispY[k][2] * N3+ nodeDispY[k][3] * N4;
}
else if (monitorT[0] == 1)
{
simunateV[i][j][k] = nodeDispX[k][0] * N1 + nodeDispX[k][1] * N2 + nodeDispX[k][2] * N3 + nodeDispX[k][3] * N4;
}
else
{
simunateV[i][j][k+monitorN[0]] = nodeDispY[k][0] * N1 + nodeDispY[k][1] * N2 + nodeDispY[k][2] * N3+ nodeDispY[k][3] * N4;
}
}
/*printf("%d %d %d %d\n",infoMonitor[5*k+1],infoMonitor[5*k+2],infoMonitor[5*k+3],infoMonitor[5*k+4]);
printf("%lf %lf %lf %lf\n",nodeX[k][0],nodeX[k][1],nodeX[k][2],nodeX[k][3]);
printf("%lf %lf %lf %lf\n",nodeY[k][0],nodeY[k][1],nodeY[k][2],nodeY[k][3]);
printf("%lf %lf %lf %lf\n",nodeDispX[k][0],nodeDispX[k][1],nodeDispX[k][2],nodeDispX[k][3]);
printf("%lf %lf %lf %lf\n",nodeDispY[k][0],nodeDispY[k][1],nodeDispY[k][2],nodeDispY[k][3]);*/
}
//exit(0);
}
}
//----------------------------------------------------------
for (i = 0 ; i<monitorN[0];i++)
{
delete []nodeX[i];
delete []nodeY[i];
delete []nodeDispX[i];
delete []nodeDispY[i];
}
delete []nodeX;
delete []nodeY;
delete []nodeDispX;
delete []nodeDispY;
}
void Find_monitors(char workingPath[256],int monitorN[1],double *monitorX,double *monitorY,int *infoMonitor)
{
int i,j;
char nodePath[256];
char elementPath[256];
int nodeN,elementN;
double *nodeX,*nodeY;
int *elementC;
int temp,temp1;
double tmp,tmp1;
double x,y,x1,y1,x2,y2,x3,y3,x4,y4;
double area1,area2,area3,area4,area;
double lengthMax;
double lengthMin;
double valueX;
double valueY;
sprintf(nodePath,"%sMODEL\\Nodes.txt",workingPath);
sprintf(elementPath,"%sMODEL\\elements.txt",workingPath);
FILE *nodeFile=fopen(nodePath,"r");
fscanf(nodeFile, "%d" ,&nodeN);
nodeX = new double [nodeN];
nodeY = new double [nodeN];
for (i = 0; i<nodeN; i++)
{
fscanf(nodeFile, "%d %lf %lf %lf" ,&temp, &nodeX[i],&nodeY[i],&tmp);
}
fclose(nodeFile);
FILE *elementFile=fopen(elementPath,"r");
fscanf(elementFile, "%d" ,&elementN);