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

📄 dtcview.cpp

📁 工程电磁场数值方法编程 1、根据实验要求设计工作界面: 界面应包含已知条件
💻 CPP
字号:
// dtcView.cpp : implementation of the CDtcView class
//

#include "stdafx.h"
#include "dtc.h"

#include "dtcDoc.h"
#include "dtcView.h"
#include "matlib.h"

#include <stdio.h>
#include <math.h>
#define ds 10
#define pi 3.1415926

double Br=0,Bz=0,U=4*pi*0.0000001;

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDtcView

IMPLEMENT_DYNCREATE(CDtcView, CFormView)

BEGIN_MESSAGE_MAP(CDtcView, CFormView)
	//{{AFX_MSG_MAP(CDtcView)
	ON_BN_CLICKED(IDC_BUTTON_jishuan, OnBUTTONjishuan)
	ON_BN_CLICKED(IDC_BUTTON_r, OnBUTTONr)
	ON_BN_CLICKED(IDC_BUTTON_z, OnBUTTONz)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDtcView construction/destruction

CDtcView::CDtcView()
	: CFormView(CDtcView::IDD)
{
	//{{AFX_DATA_INIT(CDtcView)
	m_Br = 0.0;
	m_Bz = 0.0;
	m_J = 1.0f;
	m_r1 = 3.0f;
	m_r2 = 4.0f;
	m_rx = 0.0f;
	m_z1 = -2.0f;
	m_z2 = 2.0f;
	m_zx = 0.0f;
	m_rt = 0.0;
	m_zt = 0.0;
	m_zp = 2.0f;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

}

CDtcView::~CDtcView()
{
}

void CDtcView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDtcView)
	DDX_Text(pDX, IDC_EDIT_Br, m_Br);
	DDX_Text(pDX, IDC_EDIT_Bz, m_Bz);
	DDX_Text(pDX, IDC_EDIT_J, m_J);
	DDX_Text(pDX, IDC_EDIT_r1, m_r1);
	DDX_Text(pDX, IDC_EDIT_r2, m_r2);
	DDX_Text(pDX, IDC_EDIT_rx, m_rx);
	DDX_Text(pDX, IDC_EDIT_z1, m_z1);
	DDX_Text(pDX, IDC_EDIT_z2, m_z2);
	DDX_Text(pDX, IDC_EDIT_zx, m_zx);
	DDX_Text(pDX, IDC_EDIT_rt, m_rt);
	DDX_Text(pDX, IDC_EDIT_zt, m_zt);
	DDX_Text(pDX, IDC_EDIT_zp, m_zp);
	//}}AFX_DATA_MAP
}

BOOL CDtcView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CFormView::PreCreateWindow(cs);
}

void CDtcView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CDtcView printing

BOOL CDtcView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDtcView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDtcView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

void CDtcView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CDtcView diagnostics

#ifdef _DEBUG
void CDtcView::AssertValid() const
{
	CFormView::AssertValid();
}

void CDtcView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

CDtcDoc* CDtcView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDtcDoc)));
	return (CDtcDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDtcView message handlers

void f(float a,float z,double I,float r)
{
	int j=16;
	double k,Kk,Ek;
	double ( * p)(float x,double k);

	double fK(float x,double k);
	double fE(float x,double k);
	double xps(float m,float n,int j,double k,double ( * p)(float x,double k));

	if (r==0)
	{
		Bz=I*a*a/(2*pow(a*a+z*z,1.5));
		Br=0;
	}
	else
	{
		k=sqrt(4*a*r/((a+r)*(a+r)+z*z));  // printf("k=%f\n",k);
		p=fK;
		Kk=xps(0,pi/2,j,k,p);
		p=fE;
		Ek=xps(0,pi/2,j,k,p);
	//	printf("Kk=%f\tEk=%f\n",Kk,Ek);
		Br=I*z*((a*a+r*r+z*z)*Ek/((a-r)*(a-r)+z*z)-Kk)/(2*pi*r*sqrt((a+r)*(a+r)+z*z));
		Bz=I*((a*a-r*r-z*z)*Ek/((a-r)*(a-r)+z*z)+Kk)/(2*pi*r*sqrt((a+r)*(a+r)+z*z));
	}
	
}

double fK(float x,double k)
{
	double f;

	f=1/(sqrt(1-k*k*sin(x)*sin(x)));

	return (f); 
}
double fE(float x,double k)
{
	double f;

	f=sqrt(1-k*k*sin(x)*sin(x));

	return (f);
}

double xps(float m,float n,int j,double k,double ( * p)(float x,double k))
{
	double div,h=m,l,divs,sum=0;
	int i;
	
	div=(n-m)/j;
	l=h+div;
	for(i=0;i<j;i++)
	{
		divs=div*(( * p)(h,k)+( * p)(l,k)+4*( * p)((h+l)/2,k))/6;
		sum+=divs; 
		h+=div;
		l+=div;
	}
	return (sum);
}

void xps2(float r1,float r2,float z1,float z2,float J,float a,float z)
{
	float rh=r1,rl,zh=z1,zl;
	float divr,divz;
	double sumr=0,sumz=0;
	double I=1;
	double junr=0,junz=0,her=0,hez=0;
	int i,j,n1=1,n2=1;
	
	n1=(int)((r2-r1)*ds);	//	printf("nr=%d\n",n1);
	n2=(int)((z2-z1)*ds);	//	printf("nz=%d\n",n2);
	divr=(r2-r1)/n1;		//	printf("divr=%f\n",divr);
	divz=(z2-z1)/n2;		//	printf("divz=%f\n",divz);
	rl=rh+divr;
	zl=zh+divz;
	I=J*divr*divz;
	for(i=0;i<n1;i++)
	{
		for(j=0;j<n2;j++)
		{
			f(rh,z-zh,I,a);
			her+=Br;	printf("Br=%f\t",Br);
			hez+=Bz;
			f(rl,z-zh,I,a);
			her+=Br;//	printf("Br=%f\t",Br);
			hez+=Bz;
			f(rl,z-zl,I,a);
			her+=Br;//	printf("Br=%f\t",Br);
			hez+=Bz;
			f(rh,z-zl,I,a);
			her+=Br;	//printf("Br=%f\t",Br);
			hez+=Bz;
			junr=her/4;//	printf("junr=%f\t",junr);
			junz=hez/4;
			sumr+=junr;		//	printf("sum=%f\t",sum);
			sumz+=junz;
			zl+=divz;
			zh+=divz;
			her=0;
		}
		rh+=divr;
		rl+=divr;
		zh=z1;zl=zh+divz;
	}
	Br=sumr;
	Bz=sumz;
}

void CDtcView::OnBUTTONjishuan() 
{
	// TODO: Add your control notification handler code here
	  UpdateData(TRUE);

      float r1=m_r1;
	  float r2=m_r2;
	  float rx=m_rx;
	  float z1=m_z1;
	  float z2=m_z2;
	  float zx=m_zx;
	  float J=m_J;
	  float a=0,z=0;
      float rt=m_rt;
	  float zt=m_zt;

	xps2(r1,r2,z1,z2,J,rx,zx);
	if(zx==0) Br=0;

	m_Br=Br;
	m_Bz=Bz;
	m_zt=Bz*U;
	m_rt=Br*U;

    UpdateData(FALSE);

}

void CDtcView::OnBUTTONr() 
{
	// TODO: Add your control notification handler code here

	  float r1=m_r1;
	  float r2=m_r2;
	  float z1=m_z1;
	  float z2=m_z2;
	  float J=m_J;
	  float a=0,z=0;
	  UpdateData(FALSE);
	
	dMm(x);
	dMm(y);
//	FILE * p;
//	p=fopen("rd.txt","w");
	double dx;
	int i;
	float N,zxr=0,yi;
	N=100;
	dx=2/N;
	for(i=1;i<N;i++)
	{
		zxr=i*dx;
		xps2(r1,r2,z1,z2,J,1+zxr,0);
		yi=Bz;
//		fprintf(p,"%f\t%f\n",zxr,yi);
		x(i)=1+zxr;y(i)=yi;
	}
//	fclose(p);

	plot((CL(x),y));
	exitM();
}

void CDtcView::OnBUTTONz() 
{
	// TODO: Add your control notification handler code here
	 UpdateData(TRUE);

      float r1=m_r1;
	  float r2=m_r2;
	  float z1=m_z1;
	  float z2=m_z2;
	  float zp=m_zp;
	  float J=m_J;
	  float a=0,z=0;
	  UpdateData(FALSE);
	
	dMm(x);
	dMm(y);
//	FILE * pz;
//	pz=fopen("zd.txt","w");
	double dxz;
	int i;
	float Nz,zxz=0,yi;
	Nz=100;
	dxz=zp/Nz;
	for(i=1;i<Nz;i++)
	{
		zxz=i*dxz;
		xps2(r1,r2,z1,z2,J,0,zxz);
		yi=Bz;
//		fprintf(pz,"%f\t%f\n",zxz,yi);
		x(i)=zxz;y(i)=yi;
	}
//	fclose(pz);

	plot((CL(x),y));
	exitM();
}

⌨️ 快捷键说明

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