📄 lbm_d2q9view.cpp
字号:
// LBM_D2Q9View.cpp : implementation of the CLBM_D2Q9View class
//
#include "stdafx.h"
#include "LBM_D2Q9.h"
#include "LBM_D2Q9Doc.h"
#include "LBM_D2Q9View.h"
#include "D2Q9.h"
#include "colormap.h"
#include "MyArrays.h"
#include <math.h>
#include "Dialog1.h"
#include <string.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CLBM_D2Q9View
IMPLEMENT_DYNCREATE(CLBM_D2Q9View, CScrollView)
BEGIN_MESSAGE_MAP(CLBM_D2Q9View, CScrollView)
//{{AFX_MSG_MAP(CLBM_D2Q9View)
ON_COMMAND(ID_PAUSE, OnPause)
ON_COMMAND(ID_SHOW, OnShow)
ON_WM_TIMER()
ON_COMMAND(ID_PARA, OnPara)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLBM_D2Q9View construction/destruction
CLBM_D2Q9View::CLBM_D2Q9View()
{
// TODO: add construction code here
pause = show_flag = 1;
m_timer = 0;
arrow_angle = 20;
arrow_size = 8;
arrow_length = 3;
for(int i=0; i<256; i++)
color[i] = RGB(red[i]>>4, green[i]>>4, blue[i]>>4);
u_old = v_old = NULL;
}
CLBM_D2Q9View::~CLBM_D2Q9View()
{
if(v_old) Free2DArray((void**)v_old);
if(u_old) Free2DArray((void**)u_old);
SaveFile();
Finish();
}
BOOL CLBM_D2Q9View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CLBM_D2Q9View drawing
void CLBM_D2Q9View::OnDraw(CDC* pDC)
{
CLBM_D2Q9Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
void CLBM_D2Q9View::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CLBM_D2Q9View printing
BOOL CLBM_D2Q9View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CLBM_D2Q9View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CLBM_D2Q9View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CLBM_D2Q9View diagnostics
#ifdef _DEBUG
void CLBM_D2Q9View::AssertValid() const
{
CScrollView::AssertValid();
}
void CLBM_D2Q9View::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CLBM_D2Q9Doc* CLBM_D2Q9View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CLBM_D2Q9Doc)));
return (CLBM_D2Q9Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CLBM_D2Q9View message handlers
void CLBM_D2Q9View::OnPause()
{
pause = 1 - pause;
}
void CLBM_D2Q9View::OnShow()
{
show_flag = 1 - show_flag;
}
void CLBM_D2Q9View::drawarrow(int i1, int j1, int i2, int j2, long color,
double arrow_angle, double arrow_size)
{
int i, j, x, y;
double a, b, len, cosine, sine;
x = i2 - i1;
y = j1 - j2;
if(x==0 && y==0 || i1<0 || i2<0 || j1<0 || j2<0) return;
a = arrow_angle*3.1415926535/180;
cosine = cos(a);
sine = sin(a);
len = sqrt(x*x+y*y);
a = x/len;
b = y/len;
CClientDC dc(this);
CPen pen(PS_SOLID, 0, color);
CPen *pPen = dc.SelectObject(&pen);
dc.MoveTo(i1, j1);
dc.LineTo(i2, j2);
i = i2 + (int)(arrow_size*(-a*cosine+b*sine));
j = j2 + (int)(arrow_size*(b*cosine+a*sine));
dc.MoveTo(i, j);
dc.LineTo(i2,j2);
i = i2 + (int)(arrow_size*(-a*cosine-b*sine));
j = j2 + (int)(arrow_size*(b*cosine-a*sine));
dc.LineTo(i, j);
}
void CLBM_D2Q9View::show()
{
int i, j, i1, j1, i2, j2, g, color_idx;
char str[300];
static double arr_angle, arr_size, arr_length, r_old;
double r;
CClientDC dc(this);
g = 450/Ny + (450%Ny!=0);
r_old = arr_length*g/U0;
r = arrow_length*g/U0;
sprintf(str, "n=%d, t=%f, (%d,%d): u=%f, v=%f, rho=%f ",
n, t, Nx/2, Ny/2, u[Nx/2][Ny/2], v[Nx/2][Ny/2], rho[Nx/2][Ny/2]);
dc.TextOut(0, 10, str);
for(j=0; j<Ny; (g<4)?j+=4:j++)
{
for(i=0; i<Nx; (g<4)?i+=4:i++)
{
i1 = g*i; j1 = g*j+30;
if(boundary[i][j]<=2)
{
i2 = i1 + (int)(r_old*u_old[i][j]);
j2 = j1 + (int)(r_old*v_old[i][j]);
drawarrow(i1, j1, i2, j2, RGB(255, 255, 255), arr_angle, arr_size);
u_old[i][j] = u[i][j];
v_old[i][j] = v[i][j];
i2 = i1 + (int)(r*u_old[i][j]);
j2 = j1 + (int)(r*v_old[i][j]);
// color_idx = 32*int(log10(1 + 127*rho[i][j]/rho_max)/log10(2));
// color_idx = 32*int(log10(1 + (1E+07)*rho[i][j]/rho_max));
// color_idx = 16*int(log10(1 + (1E+15)*rho[i][j]/rho_max));
color_idx = int(255*rho[i][j]/rho_max);
drawarrow(i1, j1, i2, j2, color[color_idx], arrow_angle, arrow_size);
}
else
dc.Rectangle(i1, j1, i1+g, j1+g);
}
}
i1 = g*Nx/2;
for(j=0; j<Ny; j++)
{
j1 = g*j + 30;
i2 = i1 + (int)(r*u_old[Nx/2][j]);
j2 = j1 + (int)(r*v_old[Nx/2][j]);
drawarrow(i1, j1, i2, j2, RGB(0, 0, 255), arrow_angle, arrow_size);
}
arr_angle = arrow_angle;
arr_size = arrow_size;
arr_length = arrow_length;
r_old = r;
}
void CLBM_D2Q9View::show1()
{
char str[300];
CClientDC dc(this);
sprintf(str, "n=%d, t=%f, (%d,%d): u=%f, v=%f, rho=%f ",
n, t, Nx/2, Ny/2, u[Nx/2][Ny/2], v[Nx/2][Ny/2], rho[Nx/2][Ny/2]);
dc.TextOut(0, 10, str);
}
void CLBM_D2Q9View::OnTimer(UINT nIDEvent)
{
if(n==0)
{
Finish();
if(u_old) Free2DArray((void**)u_old);
if(v_old) Free2DArray((void**)v_old);
Init(filename);
u_old = (double**)Calloc2DArray(Nx, Ny, sizeof(double));
v_old = (double**)Calloc2DArray(Nx, Ny, sizeof(double));
Invalidate();
}
if(!pause)
{
evolution();
if(show_flag) show();
else show1();
}
CScrollView::OnTimer(nIDEvent);
}
BOOL CLBM_D2Q9View::DestroyWindow()
{
KillTimer(m_timer);
return CScrollView::DestroyWindow();
}
void CLBM_D2Q9View::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
m_timer = SetTimer(1, 0, NULL);
}
void CLBM_D2Q9View::OnPara()
{
static CDialog1 dlg; // 将此变量的存储类型设置成static
// 可使对话框中的数据保存至下一次输入
int pause_old = pause;
pause = 1;
dlg.m_bdy_filename = filename;
dlg.m_mu = mu;
dlg.m_Re = Re;
dlg.m_L0 = L0;
dlg.m_U0 = U0;
dlg.m_c_s = c_s;
dlg.m_Ma = U0/c_s;
dlg.m_Lx = Lx;
dlg.m_Ly = Ly;
dlg.m_Nx = Nx;
dlg.m_Ny = Ny;
dlg.m_omega = omega;
dlg.m_dx = dx;
dlg.m_dt = dt;
dlg.m_c = c;
dlg.m_bounceback = bounceback;
dlg.m_arrow_angle = arrow_angle;
dlg.m_arrow_size = arrow_size;
dlg.m_arrow_length = arrow_length;
if(dlg.DoModal() == IDOK)
{
arrow_angle = dlg.m_arrow_angle;
arrow_size = dlg.m_arrow_size;
arrow_length = dlg.m_arrow_length;
show();
}
pause = pause_old;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -