// ■障害物がある流体の流れと圧力 // @障害物の位置をマウスで指定します。 // A「実行初期化」ボタンをクリックします。 // B「実行」ボタンをクリックします。 // C「表示切替」ボタンで速度表示と圧力表示を切り替えます。 // Dさらに実行するときは「実行」ボタンをクリックします。 #include "myWin.h" #include "stdio.h" #include "math.h" #define BT_1 1001 //ボタンの番号 #define BT_2 1002 #define BT_3 1003 #define BT_4 1004 #define ED_1 2001 //エディットボックスの番号 #define ED_2 2002 #define ED_3 2003 #define NUMX 62 // X方向要素数 #define NUMY 32 // Y方向要素数 #define OBSMODE 101 // 障害物表示モード #define VELMODE 102 // 速度絶対値表示 #define PRSMODE 103 // 圧力表示 int flowExist[NUMX][NUMY]; //流体有無(流体がある部分=1, 障害物の部分=0) double DT; //時間刻み double RE; //レイノルズ数 int Iter; //収れん計算用最大繰返し回数 int NDsp; //表示までの繰返し回数 double sizeX, sizeY; //セルのサイズ double pbX[NUMX], pbY[NUMY]; // XY座標 double pbXG[NUMX], pbXA[NUMX],pbXB[NUMX], pbXC[NUMX],pbXD[NUMX]; //X計算用 double pbYG[NUMY], pbYA[NUMY],pbYB[NUMY], pbYC[NUMY],pbYD[NUMY]; //Y計算用 double pbU[NUMX][NUMY], pbV[NUMX][NUMY], pbP[NUMX][NUMY], absV[NUMX][NUMY]; //X,Y方向速度,圧力 double pbQ[NUMX][NUMY], pbD[NUMX][NUMY], pbS[NUMX][NUMY], pbUL[NUMX]; //圧力計算用 int boundaryLine[NUMX][NUMY], boundaryType[NUMX][NUMY]; //境界を示す行列と境界の種類 int dspMode=0; //表示モード int LButtonX, LButtonY, LButton=false; //マウス指定用 int MButtonX, MButtonY; //マウス位置 int XMAX, YMAX; //表示最大位置 static HWND bt1,bt2,bt3, bt4,edit1,edit2,edit3; int ID1, ID2; //現時刻と次時刻切替え用添字 static HDC hBuff; static HBITMAP hBM; //ビットマップ表示用 static TCHAR textDt[32767]; void setGrid(){//■障害物の位置初期設定 for(int i=0;i=1;i--) if( (flowExist[i][j] - flowExist[i - 1][j]) == 1)boundaryLine[i][j] = 1; } for(int i=0;i=1;j--) if((flowExist[i][j] - flowExist[i][j - 1]) == 1 ) boundaryLine[i][j] = 1; } for(int j=0;jMButtonX) {X1=MButtonX;X2=LButtonX;} if(Y1>MButtonY) {Y1=MButtonY;Y2=LButtonY;} X2=X2+10;Y2=Y2+10; SetROP2(hBuff,R2_XORPEN); drawRectangle(X1,Y1,X2,Y2,0xFFFFFF,0x00FF00); SetROP2(hBuff,R2_COPYPEN); } void drawObstacle(HWND hw){ int X=15, Y; for(int i=1; iMV) MV=P[i][j]; return MV; } double minValue(double P[NUMX][NUMY]){ double MV=1E+64; for(int i=1; i0.00001) T=(V-minV)/DV; int R=(int)(T*512); if(R>=512) return RGB(255 , 0 , 0 ); if(R>=384) return RGB(255 , 511- R * 2, 0 ); if(R>=256) return RGB((R-256)*2, 255 , 0 ); if(R>=128) return RGB( 0 , R , 0 ); if(R<0) return RGB( 0 , 0 , 127); return RGB( 0 , R , 127-R); } void drawV(HWND hw, double P[NUMX][NUMY]){ double maxV=maxValue(P), minV=minValue(P); int X=15, Y; for(int i=1; i=15 && X<=XMAX && Y>=20 && Y=15 && X<=XMAX && Y>=20 && YMButtonX) {X1=MButtonX;X2=LButtonX;} if(Y1>MButtonY) {Y1=MButtonY;Y2=LButtonY;} X2=X2+10;Y2=Y2+10; int i1=(X1-15)/10+1, j1=(Y1-20)/10-1, i2=(X2-15)/10, j2=(Y2-20)/10-2; for(int i=i1; i<=i2;i++)for(int j=j1; j<=j2;j++)flowExist[i][j]=!flowExist[i][j]; } void procLButtonUp(HWND hw, WPARAM wp,LPARAM lp){//■左ボタンアップ処理 int ix=-1,iy=-1; int X=LOWORD(lp), Y=HIWORD(lp); if(X>=15 && X<=XMAX && Y>=20 && Y=0){MButtonX=ix*10+15; MButtonY=iy*10+20; MouseRangeSelect();} LButton=false; drawObstacle(hw); InvalidateRect(hw,NULL,TRUE); } } void initBitmap(HWND hw){ //■ビットマップ初期設定 HDC hdc=GetDC(hw); hBM=CreateCompatibleBitmap(hdc,1000,400); hBuff=CreateCompatibleDC(hdc); SelectObject(hBuff,hBM); crearBitmap(); ReleaseDC(hw,hdc); } void createEdit(HWND *edit, HWND hw, int x, int y, int w, int h, int hm){ *edit= CreateWindow(TEXT("EDIT") ,TEXT(""), WS_CHILD|WS_VISIBLE|WS_HSCROLL|WS_VSCROLL| ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_LEFT|ES_MULTILINE|WS_BORDER, x,y,w,h,hw,(HMENU)hm, hInstance, NULL); } void createButton(HWND *bt, HWND hw,TCHAR name[],int x, int y, int w, int h, int hm){ *bt=CreateWindow(TEXT("BUTTON"),name, WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, x, y, w, h,hw, (HMENU)hm,hInstance, NULL); } void procCreate(HWND hw, WPARAM wp,LPARAM lp){ //■Create時処理 SetWindowText(hw,TEXT("障害物がある流体 (障害物表示)")); createButton(&bt1, hw, TEXT("障害物の位置"), 0, 0, 120, 30, BT_1) ; createButton(&bt2, hw, TEXT("実行初期化" ), 120, 0, 120, 30, BT_2) ; createButton(&bt3, hw, TEXT("実行" ), 240, 0, 120, 30, BT_3) ; createButton(&bt4, hw, TEXT("表示切替" ), 360, 0, 120, 30, BT_4) ; createEdit(&edit1, hw, 0, 350, 300, 200, ED_1); createEdit(&edit2, hw, 300, 350, 300, 200, ED_1); createEdit(&edit3, hw, 600, 350, 300, 200, ED_1); MoveWindow(hw,0,0,920,600,TRUE); initBitmap(hw); setGrid(); setParam(); procObstacle(hw); } void procPaint(HWND hw, WPARAM wp,LPARAM lp){ //■Paint時処理 PAINTSTRUCT ps; HDC hdc=BeginPaint(hw, &ps); BitBlt(hdc, 0,0,1000,600,hBuff,0,0,SRCCOPY); EndPaint(hw,&ps); } void procCommand(HWND hw, WPARAM wp,LPARAM lp){ //■Command時処理 switch(LOWORD(wp)){ case BT_1: procObstacle(hw); return; case BT_2: exeInit(hw); return; case BT_3: comp(hw); return; case BT_4: changeDsp(hw); return; } } LRESULT CALLBACK WndProc(HWND hw, UINT msg, WPARAM wp,LPARAM lp){//■Window Procedure switch(msg){ case WM_DESTROY : PostQuitMessage(0) ; return 0; case WM_CREATE : procCreate(hw,wp,lp) ; return 0; case WM_PAINT : procPaint(hw,wp,lp) ; return 0; case WM_LBUTTONDOWN : procLButtonDown(hw,wp,lp) ; break; case WM_LBUTTONUP : procLButtonUp(hw,wp,lp) ; break; case WM_MOUSEMOVE : procMouseMove(hw,wp,lp) ; break; case WM_COMMAND : procCommand(hw,wp,lp) ; break; } return DefWindowProc(hw,msg,wp,lp); }