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

📄 main.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
字号:
#include<stdafx.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<afxtempl.h>
#include "fkn.h"
#include "fknDlg.h"
#include "complex.h"
#include "spars.h"
#include "mesh.h"
#include "FemmeDocCore.h"

void old_main(void *inptr)
{
	CFknDlg *TheView;
	CFemmeDocCore Doc;
	char PathName[256];
	CFileDialog *fname_dia;
	char outstr[1024];
	int i;

	TheView=(CFknDlg *) inptr;

	if (__argc<2){
		
		fname_dia=new CFileDialog(
			TRUE,
			"fem | * ",
			NULL,
			OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
			"FEMM datafile (*.fem) | *.fem; *.FEM | All Files (*.*) | *.*||",
			NULL);

		if(fname_dia->DoModal()==IDCANCEL){
			delete[] fname_dia;
			AfxMessageBox("No file name!");
			return;
		}
	
		CString fname=fname_dia->GetPathName();
		fname=fname.Left(fname.GetLength()-4);
		strcpy(PathName,fname);
		delete[] fname_dia;
	}
	else strcpy(PathName,__argv[1]);

	Doc.PathName=PathName;
	Doc.TheView=TheView;

	if (Doc.OnOpenDocument()!=TRUE){
		AfxMessageBox("problem loading .fem file");
		exit(1);
	}

	// load mesh
	if (Doc.LoadMesh()!=TRUE){
		AfxMessageBox("problem loading mesh");
		exit(2);
	}

	// label the dialog to report which problem is being solved
	char PaneText[256];
	char *ProbName;
	ProbName=PathName;
	for(i=0;i< (int) strlen(PathName);i++)
		if(PathName[i]=='\\') ProbName=PathName+i;
	if (strlen(PathName)>0){
		ProbName++;
		sprintf(PaneText,"%s - fkern",ProbName);
	}
	TheView->SetWindowText(PaneText);

	// renumber using Cuthill-McKee
	TheView->SetDlgItemText(IDC_STATUSWINDOW,"renumbering nodes");
	if (Doc.Cuthill()!=TRUE){
		AfxMessageBox("problem renumbering node points");
		exit(3);
	}
	TheView->SetDlgItemText(IDC_STATUSWINDOW,"solving...");
	sprintf(outstr,"Problem Statistics:\n%i nodes\n%i elements\nPrecision: %3.2e\n",
			Doc.NumNodes,Doc.NumEls,Doc.Precision);	
	TheView->SetDlgItemText(IDC_PROBSTATS,outstr);
	
	double mr=(8.*((double) Doc.NumNodes)*((double) Doc.BandWidth))/ 1.e06;

	if(Doc.Frequency==0){
		CBigLinProb L;
		L.TheView=TheView;
		L.Precision=Doc.Precision;
		// initialize the problem, allocating the space required to solve it.
		if (L.Create(Doc.NumNodes,Doc.BandWidth)==FALSE){
			AfxMessageBox("couldn't allocate enough space for matrices");
			exit(4);
		}
	
		// Create element matrices and solve the problem;
		if (Doc.ProblemType==FALSE){
			if (Doc.Static2D(L)==FALSE){
				AfxMessageBox("Couldn't solve the problem");
				exit(5);
			}
			TheView->SetDlgItemText(IDC_STATUSWINDOW,"Static 2-D problem solved");
		}
		else{
			if (Doc.StaticAxisymmetric(L)==FALSE){
				AfxMessageBox("Couldn't solve the problem");
				exit(5);
			}
			TheView->SetDlgItemText(IDC_STATUSWINDOW,"Static axisymmetric problem solved");
		}

		if (Doc.WriteStatic2D(L)==FALSE)
		{
			AfxMessageBox("couldn't write results to disk");
			exit(6);
		}
		TheView->SetDlgItemText(IDC_STATUSWINDOW,"results written to disk");
	}

	else{
		CBigComplexLinProb L;
		L.TheView=TheView;
		L.Precision=Doc.Precision;

		// initialize the problem, allocating the space required to solve it.

		if (L.Create(Doc.NumNodes+Doc.NumCircProps,Doc.BandWidth,Doc.NumNodes)==FALSE){
				AfxMessageBox("couldn't allocate enough space for matrices");
				exit(4);
		}
	
		// Create element matrices and solve the problem;
		if (Doc.ProblemType==FALSE){
			if (Doc.Harmonic2D(L)==FALSE){
				AfxMessageBox("Couldn't solve the problem");
				exit(5);
			}
			TheView->SetDlgItemText(IDC_STATUSWINDOW,"Harmonic 2-D problem solved");
		}
		else{
		if (Doc.HarmonicAxisymmetric(L)==FALSE){
				AfxMessageBox("Couldn't solve the problem");
				exit(5);
			}
			TheView->SetDlgItemText(IDC_STATUSWINDOW,"Harmonic axisymmetric problem solved");
		}

	
		if (Doc.WriteHarmonic2D(L)==FALSE)
		{
			AfxMessageBox("couldn't write results to disk");
			exit(6);
		}
		TheView->SetDlgItemText(IDC_STATUSWINDOW,"results written to disk.");
	}

	Doc.CleanUp();

	exit(0);
}		

⌨️ 快捷键说明

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