⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sandsand.cpp

📁 河口海岸潮波模拟程序
💻 CPP
字号:


/*---------------------------------------

   MULTI1.C -- Multitasking Demo

               (c) Charles Petzold, 1998

  ---------------------------------------*/



#include <stdafx.h>

#include <math.h>

#include "stdlib.h"
/*
!!!!!变量说明
  !!UNEW[i],UREN[I],UOLD[i]     U(n+1),U(n),U(n-1)流速值
  !!HNEW[i],HREN[I],HOLD[i]     H(n+1),H(n),H(n-1)的水深值
  !!S1,S2           上游和下游边界的波浪波高 
  !!IMAX=800         断面个数
  !!HO              初始水深值
  !!DT=30           时间步长
  !!DX=1000         距离步长
  */
 
 int IMAX=800;
 int i,I;

 double UNEW[801],UREN[801],UOLD[801],HNEW[801],HREN[801],HOLD[801];
 double H0=10.0,DT=30,DX=1000;
 double C=122.3167,W=2*3.142/12.4/3600,G=9.81,S1=1.5,S2 ,T;
 int IMAX1=IMAX-1;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;



int cyChar ;



int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,

                    PSTR szCmdLine, int iCmdShow)

{

   for(i=0;i<=IMAX;i++)
 {
  HNEW[i]=1.5*(800-i)/800;
 
  HOLD[i]=1.5*(800-i)/800;
  UNEW[i]=0.0;

  UOLD[i]=0.0;
 }
    
    
//!欧拉步进
    for(I=1;I<=IMAX1;I++)	
	{
	  
	  HREN[I]=HOLD[I]-DT/2./DX*(10.0+HOLD[I])*(UOLD[I+1]-UOLD[I-1]);
	  UREN[I]=UOLD[I]-DT/2./DX*G*(HOLD[I+1]-HOLD[I-1]);
	 // UREN[I]=UOLD[I]-DT/2/DX*G*(HOLD[I+1]-HOLD[I-1])-DT*B/(10.0+HOLD[I])*ABS(UOLD[I])*UOLD[I]
    }
	 UREN[IMAX]=UREN[IMAX1];
	 UREN[0]=UREN[1];
	 HREN[0]=1.5;
	 HREN[IMAX]=0.;
     static TCHAR szAppName[] = TEXT ("Multi1") ;

     HWND         hwnd ;

     MSG          msg ;

     WNDCLASS     wndclass ;

     

     wndclass.style         = CS_HREDRAW | CS_VREDRAW ;

     wndclass.lpfnWndProc   = WndProc ;

     wndclass.cbClsExtra    = 0 ;

     wndclass.cbWndExtra    = 0 ;

     wndclass.hInstance     = hInstance ;

     wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;

     wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;

     wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;

     wndclass.lpszMenuName  = NULL ;

     wndclass.lpszClassName = szAppName ;

     

     if (!RegisterClass (&wndclass))

     {

          MessageBox (NULL, TEXT ("This program requires Windows NT!"),

                      szAppName, MB_ICONERROR) ;

          return 0 ;

     }

     hwnd = CreateWindow (szAppName, TEXT ("Multitasking Demo"),

                          WS_OVERLAPPEDWINDOW,

                          CW_USEDEFAULT, CW_USEDEFAULT,

                          CW_USEDEFAULT, CW_USEDEFAULT,

                          NULL, NULL, hInstance, NULL) ;

     

     ShowWindow (hwnd, iCmdShow) ;

     UpdateWindow (hwnd) ;

     

     while (GetMessage (&msg, NULL, 0, 0))

     {

          TranslateMessage (&msg) ;

          DispatchMessage (&msg) ;

     }

     return msg.wParam ;

}



int CheckBottom (HWND hwnd, int cyClient, int iLine)

{

     if (iLine * cyChar + cyChar > cyClient)

     {

          InvalidateRect (hwnd, NULL, TRUE) ;

          UpdateWindow (hwnd) ;

          iLine = 0 ;

     }

     return iLine ;

}



// ------------------------------------------------

// Window 1: Display increasing sequence of numbers

// ------------------------------------------------
#define NUM 1000
#define TWOPI	(2 * 3.14159)


LRESULT APIENTRY WndProc1 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

     static int cxClient, cyClient ;
	 static int iAdd=0;

     HDC        hdc ;
	int         i ,j;
//	PAINTSTRUCT ps ;
	
    POINT       apt [801] ;
    

  
   
    
     switch (message)

     {

	//case WM_CREATE:

     case WM_SIZE:

          cxClient = LOWORD (lParam) ;

          cyClient = HIWORD (lParam) ;
		  

          return 0 ;

     case WM_TIMER:

          InvalidateRect (hwnd, NULL, TRUE) ;

          UpdateWindow (hwnd) ;

           for(j=0;j<801;j++)
		   {
              apt[j].x=(800-j)*cxClient/800;
	          apt[j].y=cyClient-100.0;
		   }
          T=T+DT;
	
     
     S2=0.5*sin(W*T);
     HNEW[IMAX]=S2;
	 HNEW[0]=1.5;
      for( I=0;I<=IMAX1;I++) 
	  {
    
      HNEW[I]=HOLD[I]-DT/DX*(10.0+HREN[I])*(UREN[I+1]-UREN[I-1]);
      UNEW[I]=UOLD[I]-DT/DX*G*(HREN[I+1]-HREN[I-1])-2.0*DT*G*abs(UOLD[I])*UREN[I]/C/C/(10.0+HREN[I]);
  
	  }
	  UNEW[IMAX]=UNEW[IMAX1];
	  UNEW[0]=UNEW[1];
 
 
 
      for(I=0;I<=IMAX;I++)
	  {
      UOLD[I]=UREN[I];
      UREN[I]=UNEW[I];
      
      HOLD[I]=HREN[I];
      HREN[I]=HNEW[I];
      }
       

		for(j=0;j<801;j++)
		{
			apt[j].y=cyClient-100.0-HNEW[j]*100;
		}
	


			hdc = GetDC (hwnd) ;
		//PolyBezier(hdc,apt,801);
        Polyline (hdc, apt, 801) ;
			
			
          
//	MoveToEx (hdc, 0,		cyClient / 2, NULL) ;
	//	LineTo   (hdc, cxClient, cyClient / 2) ;
 
          
	//	Polyline (hdc, aptn, NUM) ;

      
          ReleaseDC (hwnd, hdc) ;

          return 0 ;

     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;

}



// ------------------------------------------------------

// Window 2: Display increasing sequence of prime numbers

// ------------------------------------------------------



LRESULT APIENTRY WndProc2 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

     static int iNum = 1, iLine, cyClient ;

     HDC        hdc ;

     int        i, iSqrt ;

     TCHAR      szBuffer[16] ;

     

     switch (message)

     {

     case WM_SIZE:

          cyClient = HIWORD (lParam) ;

          return 0 ;

          

     case WM_TIMER:

          

          

          iLine = CheckBottom (hwnd, cyClient, iLine) ;

          hdc = GetDC (hwnd) ;

           

          

          ReleaseDC (hwnd, hdc) ;

         

          return 0 ;

     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;

}



// ----------------------------------------------------------

// Window 3: Display increasing sequence of Fibonacci numbers

// ----------------------------------------------------------



LRESULT APIENTRY WndProc3 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

     static int iNum = 0, iNext = 1, iLine, cyClient ;

     HDC        hdc ;

     int        iTemp ;

     TCHAR      szBuffer[16] ;

     

     switch (message)

     {

     case WM_SIZE:

          cyClient = HIWORD (lParam) ;

          return 0 ;

          

     case WM_TIMER:

          if (iNum < 0)

          {

               iNum  = 0 ;

               iNext = 1 ;

          }

          

          iLine = CheckBottom (hwnd, cyClient, iLine) ;

          hdc = GetDC (hwnd) ;

          TextOut (hdc, 0, iLine * cyChar, szBuffer, 

                   wsprintf (szBuffer, "%d", iNum)) ;



          ReleaseDC (hwnd, hdc) ;

          iTemp  = iNum ;

          iNum   = iNext ;

          iNext += iTemp ;

          iLine++ ;

          return 0 ;

     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;

}



// -----------------------------------------

// Window 4: Display circles of random radii

// -----------------------------------------

#define NUM 1000
#define TWOPI	(2 * 3.14159)

LRESULT APIENTRY WndProc4 (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

     static int cxClient, cyClient ;
	 static int iAdd=0;

     HDC        hdc ;
	int         i ;
//	PAINTSTRUCT ps ;
	POINT       apto [NUM] ;
    POINT       aptn [NUM] ;
     

     switch (message)

     {

 
     case WM_SIZE:

          cxClient = LOWORD (lParam) ;

          cyClient = HIWORD (lParam) ;
		  

          return 0 ;

          

     case WM_TIMER:

          InvalidateRect (hwnd, NULL, TRUE) ;

          UpdateWindow (hwnd) ;

          
         for (i = 0 ; i < NUM; i++)
          {
			apto[i].x = i * cxClient / NUM ;
			apto[i].y = (int) (cyClient / 2 - 50*sin (TWOPI * i / NUM)) ;
          }
          
		 for (i = 0 ; i < NUM ; i++)
          {
			aptn[i].x = apto[i].x;
			aptn[i].y = apto[(i+iAdd)%NUM].y ;
          }
            iAdd++;
			if(iAdd==NUM)
				iAdd=0;
          hdc = GetDC (hwnd) ;
          
		MoveToEx (hdc, 0,		cyClient / 2, NULL) ;
		LineTo   (hdc, cxClient, cyClient / 2) ;
 
          
		Polyline (hdc, aptn, NUM) ;

      
          ReleaseDC (hwnd, hdc) ;

          return 0 ;

     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;

}



// -----------------------------------

// Main window to create child windows

// -----------------------------------



LRESULT APIENTRY WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)

{

     static HWND    hwndChild[4] ;

     static TCHAR * szChildClass[] = { TEXT ("Child1"), TEXT ("Child2"),

                                       TEXT ("Child3"), TEXT ("Child4") } ;

     static WNDPROC ChildProc[] = { WndProc1, WndProc2, WndProc3, WndProc4 } ;

     HINSTANCE      hInstance ;

     int            i, cxClient, cyClient ;

     WNDCLASS       wndclass ;

     

     switch (message)

     {

     case WM_CREATE:

          hInstance = (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE) ;

          

          wndclass.style         = CS_HREDRAW | CS_VREDRAW ;

          wndclass.cbClsExtra    = 0 ;

          wndclass.cbWndExtra    = 0 ;

          wndclass.hInstance     = hInstance ;

          wndclass.hIcon         = NULL ;

          wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;

          wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;

          wndclass.lpszMenuName  = NULL ;

          

          for (i = 0 ; i < 4 ; i++)

          {

               wndclass.lpfnWndProc   = ChildProc[i] ;

               wndclass.lpszClassName = szChildClass[i] ;

               

               RegisterClass (&wndclass) ;

               

               hwndChild[i] = CreateWindow (szChildClass[i], NULL,

                                   WS_CHILDWINDOW | WS_BORDER | WS_VISIBLE,

                                   0, 0, 0, 0, 

                                   hwnd, (HMENU) i, hInstance, NULL) ;

          }

          

          cyChar = HIWORD (GetDialogBaseUnits ()) ;

          SetTimer (hwnd, 1, 10, NULL) ;

          return 0 ;

          

     case WM_SIZE:

          cxClient = LOWORD (lParam) ;

          cyClient = HIWORD (lParam) ;

          

         

               MoveWindow (hwndChild[0], 0,

                                         0,

                           cxClient , cyClient / 2, TRUE) ;
			    MoveWindow (hwndChild[1], 0,

                                        cyClient / 2,

                           cxClient / 2, cyClient / 2, TRUE) ;
                MoveWindow (hwndChild[3], cxClient/2,

                                        cyClient / 2,

                           cxClient / 2, cyClient / 2, TRUE) ;


          return 0 ;

          

     case WM_TIMER:

          for (i = 0 ; i < 4 ; i++)

               SendMessage (hwndChild[i], WM_TIMER, wParam, lParam) ;

          

          return 0 ;

          

     case WM_CHAR:

          if (wParam == '\x1B')

               DestroyWindow (hwnd) ;

          

          return 0 ;

          

     case WM_DESTROY:

          KillTimer (hwnd, 1) ;

          PostQuitMessage (0) ;

          return 0 ;

     }

     return DefWindowProc (hwnd, message, wParam, lParam) ;

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -