Init. I deleted the entire GUI, then did what was required just to compile the lua, backend and math engines with clang.

It all compiles now. They designed well in the first place, so it was much easier than many projects would have been.

I can now begin with the GUI, I will write it in Rust and ICED.

Should be fun, I think.
This commit is contained in:
jess 2026-05-12 04:16:16 -07:00
commit 7cbb497478
516 changed files with 196315 additions and 0 deletions

8
belasolv/StdAfx.h Normal file
View File

@ -0,0 +1,8 @@
// stdafx.h: portable shim pulling in compat/afx.h for BOOL, CString, and stdlib basics.
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <afx.h>
int MsgBox(const char* sz, ...);
int MsgBox(const std::string& s);

82
belasolv/belasolv.cpp Normal file
View File

@ -0,0 +1,82 @@
// belasolv.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "belasolv.h"
#include "belasolvDlg.h"
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CbelasolvApp
BEGIN_MESSAGE_MAP(CbelasolvApp, CWinApp)
//{{AFX_MSG_MAP(CbelasolvApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CbelasolvApp construction
CbelasolvApp::CbelasolvApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
CbelasolvApp::~CbelasolvApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CbelasolvApp object
CbelasolvApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CbelasolvApp initialization
BOOL CbelasolvApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
// Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CbelasolvDlg dlg;
m_pMainWnd = &dlg;
dlg.ComLine=m_lpCmdLine;
//<DP> SetDialogBkColor();
_beginthread( old_main, 0, (void *) &dlg );
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

4
belasolv/belasolv.h Normal file
View File

@ -0,0 +1,4 @@
// solver entry point.
#pragma once
void old_main(void *inptr);

96
belasolv/belasolvDlg.cpp Normal file
View File

@ -0,0 +1,96 @@
// belasolvDlg.cpp : implementation file
//
#include "stdafx.h"
#include "belasolv.h"
#include "belasolvDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CbelasolvDlg dialog
CbelasolvDlg::CbelasolvDlg(CWnd* pParent /*=NULL*/)
: CDialog(CbelasolvDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CbelasolvDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CbelasolvDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CbelasolvDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_prog1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CbelasolvDlg, CDialog)
//{{AFX_MSG_MAP(CbelasolvDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CbelasolvDlg message handlers
BOOL CbelasolvDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return FALSE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CbelasolvDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CbelasolvDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CbelasolvDlg::OnOK()
{
}

20
belasolv/belasolvDlg.h Normal file
View File

@ -0,0 +1,20 @@
// MFC-free CbelasolvDlg with empty progress, label, and window-update calls.
#pragma once
#include <string>
struct CProgressStub { void SetPos(int) {} };
class CbelasolvDlg {
public:
CProgressStub m_prog1;
CProgressStub m_prog2;
void* m_hWnd = nullptr;
std::string ComLine;
void SetDlgItemText(int, const char*) {}
void SetWindowText(const char*) {}
void UpdateWindow() {}
int InvalidateRect(void* = nullptr, int = 1) { return 1; }
};
extern CbelasolvDlg* TheView;

266
belasolv/cuthill.cpp Normal file
View File

@ -0,0 +1,266 @@
// does Cuthill-McKee algorithm as described in Hoole;
#include<stdafx.h>
#include<afxtempl.h>
#include<stdio.h>
#include<math.h>
#include "belasolv.h"
#include "belasolvDlg.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"
#define muo 1.2566370614359173e-6
BOOL CFemmeDocCore::SortElements()
{
// Comb Sort -- see http://en.wikipedia.org/wiki/Comb_sort
int *Score;
int i,j,k,gap;
CElement e;
Score=(int*)calloc(NumEls,sizeof(int));
for(k=0;k<NumEls;k++)
{
Score[k]=meshele[k].p[0]+meshele[k].p[1]+meshele[k].p[2];
}
gap = NumEls;
do{
//update the gap value for a next comb
if (gap > 1)
{
gap=(gap*10)/13;
if ((gap==10) || (gap==9)) gap=11;
}
//a single "comb" over the input list
for(j=0,i=0;(j+gap)<NumEls;j++)
{
if (Score[j]>Score[j+gap])
{
k=j+gap;
i=Score[k];Score[k]=Score[j];Score[j]=i;
e=meshele[k];meshele[k]=meshele[j];meshele[j]=e;
i=1;
}
}
}while((gap>1)&&(i>0));
free(Score);
return TRUE;
}
BOOL CFemmeDocCore::Cuthill()
{
FILE *fp;
int i,j,k,n0,n1,n;
int newwide,*newnum,**ocon;
int *numcon,*nxtnum;
CNode swap;
char infile[256];
// allocate storage
nxtnum=(int *)calloc(NumNodes,sizeof(int));
newnum=(int *)calloc(NumNodes,sizeof(int));
numcon=(int *)calloc(NumNodes,sizeof(int));
ocon=(int **)calloc(NumNodes,sizeof(int *));
// initialize node array;
for(i=0;i<NumNodes;i++) newnum[i]= -1;
// read in connectivity from nodefile
sprintf(infile,"%s.edge",PathName);
if((fp=fopen(infile,"rt"))==NULL)
{
fprintf(stderr,"Couldn't open %s",infile);
return FALSE;
}
fscanf(fp,"%i",&k); // read in number of lines
fscanf(fp,"%i",&j); // read in boundarymarker flag;
// allocate space for connections;
ocon[0]=(int *)calloc(2*k,sizeof(int));
// with first pass, figure out how many connections
// there are for each node;
for(i=0;i<k;i++)
{
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&n0);
fscanf(fp,"%i",&n1);
fscanf(fp,"%i",&j);
numcon[n0]++;
numcon[n1]++;
}
// mete out connection storage space;
for(i=1,n=0;i<NumNodes;i++)
{
n+=numcon[i-1];
ocon[i]=ocon[0]+n;
}
// on second pass through file, store connections;
rewind(fp);
fscanf(fp,"%li",&k); // read in number of lines
fscanf(fp,"%li",&j); // read in boundarymarker flag;
for(i=0;i<k;i++)
{
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&n0);
fscanf(fp,"%i",&n1);
fscanf(fp,"%i",&j);
ocon[n0][nxtnum[n0]]=n1; nxtnum[n0]++;
ocon[n1][nxtnum[n1]]=n0; nxtnum[n1]++;
}
fclose(fp);
DeleteFile(infile);
// sort connections in order of increasing connectivity;
// I'm lazy, so I'm doing a bubble sort;
for(n0=0;n0<NumNodes;n0++)
{
for(i=1;i<numcon[n0];i++)
for(j=1;j<numcon[n0];j++)
if(numcon[ocon[n0][j]]<numcon[ocon[n0][j-1]])
{
n1=ocon[n0][j];
ocon[n0][j]=ocon[n0][j-1];
ocon[n0][j-1]=n1;
}
}
// search for a node to start with;
j=numcon[0]; n0=0;
for(i=1;i<NumNodes;i++){
if(numcon[i]<j){
j=numcon[i];
n0=i;
}
if(j==2) i=k; // break out if j==2,
// because this is the best we can do
}
// do renumbering algorithm;
for(i=0;i<NumNodes;i++) nxtnum[i]=-1;
newnum[n0]=0; n=1; nxtnum[0]=n0;
do{
// renumber in order of increasing number of connections;
for(i=0;i<numcon[n0];i++)
{
if (newnum[ocon[n0][i]]<0)
{
newnum[ocon[n0][i]]=n;
nxtnum[n]=ocon[n0][i];
n++;
}
}
// need to catch case in which problem is multiply
// connected and still renumber right.
if(nxtnum[newnum[n0]+1]<0){
// MsgBox("Multiply Connected!");
// exit(0);
// first, get a node that hasn't been visited yet;
for(i=0;i<NumNodes;i++)
if(newnum[i]<0){
j=numcon[i];
n0=i;
i=NumNodes;
}
// now, get a new starting node;
for(i=0;i<NumNodes;i++)
{
if((newnum[i]<0) && (numcon[i]<j))
{
j=numcon[i];
n0=i;
}
if(j==2) i=NumNodes; // break out if j==2,
// because this is the
// best we can do
}
// now, set things to restart;
newnum[n0]=n;
nxtnum[n]=n0;
n++;
}
else n0=nxtnum[newnum[n0]+1];
} while(n<NumNodes);
// remap connectivities;
for(i=0;i<NumNodes;i++)
for(j=0;j<numcon[i];j++)
ocon[i][j]=newnum[ocon[i][j]];
// remap (anti)periodic boundary points
for(i=0;i<NumPBCs;i++)
{
pbclist[i].x=newnum[pbclist[i].x];
pbclist[i].y=newnum[pbclist[i].y];
}
// find new bandwidth;
// PBCs fuck up the banding, som could have to do
// something like:
// if(NumPBCs!=0) BandWidth=0;
// else{
// but if we apply the PCBs the last thing before the
// solver is called, we can take advantage of banding
// speed optimizations without messing things up.
for(n0=0,newwide=0;n0<NumNodes;n0++)
{
for(i=0;i<numcon[n0];i++)
if(abs(newnum[n0]-ocon[n0][i])>newwide)
{
newwide=abs(newnum[n0]-ocon[n0][i]);
}
}
BandWidth=newwide+1;
// }
// free up the variables that we needed during the routine....
free(numcon);
free(nxtnum);
free(ocon[0]);
free(ocon);
// new mapping remains in newnum;
// apply this mapping to elements first.
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
meshele[i].p[j]=newnum[meshele[i].p[j]];
// now, sort nodes based on newnum;
for(i=0;i<NumNodes;i++)
while(newnum[i]!=i)
{
j=newnum[i];
n=newnum[j]; newnum[j]=newnum[i]; newnum[i]=n;
swap=meshnode[j]; meshnode[j]=meshnode[i]; meshnode[i]=swap;
}
free(newnum);
SortElements();
return TRUE;
}

594
belasolv/femmedoccore.cpp Normal file
View File

@ -0,0 +1,594 @@
// FemmeDocCore.cpp : implementation of the CFemmeDocCore class
//
#include <stdafx.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "belasolv.h"
#include "belasolvDlg.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"
/////////////////////////////////////////////////////////////////////////////
// CFemmeDocCore construction/destruction
CFemmeDocCore::CFemmeDocCore()
{
TheView=NULL;
Precision=NULL;
LengthUnits=NULL;
ProblemType=NULL;
Coords=NULL;
BandWidth=NULL;
NumNodes=NULL;
NumEls=NULL;
NumBlockProps=NULL;
NumPBCs=NULL;
NumLineProps=NULL;
NumPointProps=NULL;
NumCircProps=NULL;
NumBlockLabels=NULL;
meshnode=NULL;
meshele=NULL;
blockproplist=NULL;
lineproplist=NULL;
nodeproplist=NULL;
circproplist=NULL;
labellist=NULL;
pbclist=NULL;
PathName=NULL;
extRo=extRi=extZo=NULL;
}
CFemmeDocCore::~CFemmeDocCore()
{
// This space for rent.
}
void CFemmeDocCore::CleanUp()
{
if (meshnode!=NULL) free(meshnode);
if (meshele!=NULL) free(meshele);
if (blockproplist!=NULL) free(blockproplist);
if (lineproplist!=NULL) free(lineproplist);
if (nodeproplist!=NULL) free(nodeproplist);
if (circproplist!=NULL) free(circproplist);
if (labellist!=NULL) free(labellist);
if (pbclist!=NULL) free(pbclist);
}
/////////////////////////////////////////////////////////////////////////////
// CFemmeDocCore commands
char* StripKey(char *c)
{
char *d;
int i,k;
k=(int) strlen(c);
for(i=0;i<k;i++){
if (c[i] == '='){
d=c+i+1;
return d;
}
}
return c+k;
}
BOOL CFemmeDocCore::OnOpenDocument()
{
FILE *fp;
int k;
char s[1024],q[1024];
char *v;
CPointProp PProp;
CBoundaryProp BProp;
CMaterialProp MProp;
CCircuit CProp;
CBlockLabel blk;
sprintf(s,"%s.fee",PathName);
if ((fp=fopen(s,"rt"))==NULL){
fprintf(stderr,"Couldn't read from specified .fee file\n");
return FALSE;
}
// define some defaults
Precision=1.e-08;
Depth=-1;
ProblemType=0;
Coords=0;
NumPointProps=0;
NumLineProps=0;
NumBlockProps=0;
NumCircProps=0;
// parse the file
while (fgets(s,1024,fp)!=NULL)
{
sscanf(s,"%s",q);
// Precision
if( _strnicmp(q,"[precision]",11)==0){
v=StripKey(s);
sscanf(v,"%lf",&Precision);
q[0]=NULL;
}
// Units of length used by the problem
if( _strnicmp(q,"[lengthunits]",13)==0){
v=StripKey(s);
sscanf(v,"%s",q);
if( _strnicmp(q,"inches",6)==0) LengthUnits=0;
else if( _strnicmp(q,"millimeters",11)==0) LengthUnits=1;
else if( _strnicmp(q,"centimeters",1)==0) LengthUnits=2;
else if( _strnicmp(q,"mils",4)==0) LengthUnits=4;
else if( _strnicmp(q,"microns",6)==0) LengthUnits=5;
else if( _strnicmp(q,"meters",6)==0) LengthUnits=3;
q[0]=NULL;
}
// Depth for 2D planar problems;
if( _strnicmp(q,"[depth]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&Depth);
q[0]=NULL;
}
// Problem Type (planar or axisymmetric)
if( _strnicmp(q,"[problemtype]",13)==0){
v=StripKey(s);
sscanf(v,"%s",q);
if( _strnicmp(q,"planar",6)==0) ProblemType=0;
if( _strnicmp(q,"axisymmetric",3)==0) ProblemType=1;
q[0]=NULL;
}
// Coordinates (cartesian or polar)
if( _strnicmp(q,"[coordinates]",13)==0){
v=StripKey(s);
sscanf(v,"%s",q);
if ( _strnicmp(q,"cartesian",4)==0) Coords=0;
if ( _strnicmp(q,"polar",5)==0) Coords=1;
q[0]=NULL;
}
// properties for axisymmetric external region
if( _strnicmp(q,"[extzo]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&extZo);
q[0]=NULL;
}
if( _strnicmp(q,"[extro]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&extRo);
q[0]=NULL;
}
if( _strnicmp(q,"[extri]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&extRi);
q[0]=NULL;
}
// Point Properties
if( _strnicmp(q,"[pointprops]",12)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) nodeproplist=(CPointProp *)calloc(k,sizeof(CPointProp));
q[0]=NULL;
}
if( _strnicmp(q,"<beginpoint>",11)==0){
PProp.V=0;
PProp.qp=0;
q[0]=NULL;
}
if( _strnicmp(q,"<vp>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&PProp.V);
q[0]=NULL;
}
if( _strnicmp(q,"<qp>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&PProp.qp);
q[0]=NULL;
}
if( _strnicmp(q,"<endpoint>",9)==0){
nodeproplist[NumPointProps]=PProp;
NumPointProps++;
q[0]=NULL;
}
// Boundary Properties;
if( _strnicmp(q,"[bdryprops]",11)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) lineproplist=(CBoundaryProp *)calloc(k,sizeof(CBoundaryProp));
q[0]=NULL;
}
if( _strnicmp(q,"<beginbdry>",11)==0){
BProp.BdryFormat=0;
BProp.V=0;
BProp.qs=0;
BProp.c0=0;
BProp.c1=0;
q[0]=NULL;
}
if( _strnicmp(q,"<bdrytype>",10)==0){
v=StripKey(s);
sscanf(v,"%i",&BProp.BdryFormat);
q[0]=NULL;
}
if( _strnicmp(q,"<vs>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.V);
q[0]=NULL;
}
if( _strnicmp(q,"<qs>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.qs);
q[0]=NULL;
}
if( _strnicmp(q,"<c0>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.c0);
q[0]=NULL;
}
if( _strnicmp(q,"<c1>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.c1);
q[0]=NULL;
}
if( _strnicmp(q,"<endbdry>",9)==0){
lineproplist[NumLineProps]=BProp;
NumLineProps++;
q[0]=NULL;
}
// Block Properties;
if( _strnicmp(q,"[blockprops]",12)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) blockproplist=(CMaterialProp *)calloc(k,sizeof(CMaterialProp));
q[0]=NULL;
}
if( _strnicmp(q,"<beginblock>",12)==0){
MProp.ex=1;
MProp.ey=1; // permittivity, relative
MProp.qv=1; // charge density, C/m^3
q[0]=NULL;
}
if( _strnicmp(q,"<ex>",6)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.ex);
q[0]=NULL;
}
if( _strnicmp(q,"<ey>",6)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.ey);
q[0]=NULL;
}
if( _strnicmp(q,"<qv>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.qv);
q[0]=NULL;
}
if( _strnicmp(q,"<endblock>",9)==0){
blockproplist[NumBlockProps]=MProp;
NumBlockProps++;
q[0]=NULL;
}
// Conductor Properties
if( _strnicmp(q,"[conductorprops]",16)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if(k>0) circproplist=(CCircuit *)calloc(k,sizeof(CCircuit));
q[0]=NULL;
}
if( _strnicmp(q,"<beginconductor>",16)==0){
CProp.V=0;
CProp.q=0;
CProp.CircType=0;
q[0]=NULL;
}
if( _strnicmp(q,"<vc>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&CProp.V);
q[0]=NULL;
}
if( _strnicmp(q,"<qc>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&CProp.q);
q[0]=NULL;
}
if( _strnicmp(q,"<conductortype>",15)==0){
v=StripKey(s);
sscanf(v,"%i",&CProp.CircType);
q[0]=NULL;
}
if( _strnicmp(q,"<endconductor>",14)==0){
circproplist[NumCircProps]=CProp;
NumCircProps++;
q[0]=NULL;
}
// read in regional attributes
if(_strnicmp(q,"[numblocklabels]",13)==0){
int i;
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) labellist=(CBlockLabel *)calloc(k, sizeof(CBlockLabel));
NumBlockLabels=k;
for(i=0;i<k;i++)
{
fgets(s,1024,fp);
sscanf(s,"%lf %lf %i %lf %i %i",&blk.x,&blk.y,&blk.BlockType,
&blk.MaxArea,&blk.InGroup,&blk.IsExternal);
blk.IsDefault = blk.IsExternal & 2;
blk.IsExternal = blk.IsExternal & 1;
blk.BlockType--;
labellist[i]=blk;
}
q[0]=NULL;
}
}
fclose(fp);
return TRUE;
}
BOOL CFemmeDocCore::LoadMesh()
{
int i,j,k,q,n0,n1,n;
char infile[256];
FILE *fp;
char s[1024];
double c[]={25.4,1.,10.,1000.,0.0254,0.001};
//read meshnodes;
sprintf(infile,"%s.node",PathName);
if((fp=fopen(infile,"rt"))==NULL){
return FALSE;
}
fgets(s,1024,fp);
sscanf(s,"%i",&k); NumNodes=k;
meshnode=(CNode *)calloc(k,sizeof(CNode));
CNode node;
for(i=0;i<k;i++){
fscanf(fp,"%i",&j);
fscanf(fp,"%lf",&node.x);
fscanf(fp,"%lf",&node.y);
fscanf(fp,"%i",&n);
if(n>1){
// strip off point BC number;
j=n & 0xffff;
j=j-2;
if (j<0) j=-1;
// strip off Conductor number
n= (n - (n & 0xffff))/0x10000 - 1;
}
else{
j=-1;
n=-1;
}
node.bc=j;
node.InConductor=n;
// convert all lengths to internal working units of mm
node.x*=c[LengthUnits];
node.y*=c[LengthUnits];
meshnode[i]=node;
}
fclose(fp);
//read in periodic boundary conditions;
sprintf(infile,"%s.pbc",PathName);
if((fp=fopen(infile,"rt"))==NULL){
return FALSE;
}
fgets(s,1024,fp);
sscanf(s,"%i",&k); NumPBCs=k;
if (k!=0) pbclist=(CCommonPoint *)calloc(k,sizeof(CCommonPoint));
CCommonPoint pbc;
for(i=0;i<k;i++){
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&pbc.x);
fscanf(fp,"%i",&pbc.y);
fscanf(fp,"%i",&pbc.t);
pbclist[i]=pbc;
}
fclose(fp);
// read in elements;
sprintf(infile,"%s.ele",PathName);
if((fp=fopen(infile,"rt"))==NULL){
return FALSE;
}
fgets(s,1024,fp);
sscanf(s,"%i",&k); NumEls=k;
meshele=(CElement *)calloc(k,sizeof(CElement));
CElement elm;
int defaultLabel;
for(i=0,defaultLabel=-1;i<NumBlockLabels;i++)
if (labellist[i].IsDefault) defaultLabel=i;
for(i=0;i<k;i++){
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&elm.p[0]);
fscanf(fp,"%i",&elm.p[1]);
fscanf(fp,"%i",&elm.p[2]);
fscanf(fp,"%i",&elm.lbl);
elm.lbl--;
if(elm.lbl<0) elm.lbl=defaultLabel;
if(elm.lbl<0){
CString msg;
msg ="Material properties have not been defined for\n";
msg+="all regions. Press the \"Run Mesh Generator\"\n";
msg+="button to highlight the problem regions.";
MsgBox(msg);
fclose(fp);
sprintf(infile,"%s.ele",PathName); DeleteFile(infile);
sprintf(infile,"%s.node",PathName); DeleteFile(infile);
sprintf(infile,"%s.pbc",PathName); DeleteFile(infile);
sprintf(infile,"%s.poly",PathName); DeleteFile(infile);
sprintf(infile,"%s.edge",PathName); DeleteFile(infile);
exit(1);
}
// look up block type out of the list of block labels
elm.blk=labellist[elm.lbl].BlockType;
meshele[i]=elm;
}
fclose(fp);
// initialize edge bc's and element permeabilities;
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
meshele[i].e[j] = -1;
// read in edges to which boundary conditions are applied;
// first, do a little bookkeeping so that element
// associated with a give edge can be identified fast
int *nmbr;
int **mbr;
nmbr=(int *)calloc(NumNodes,sizeof(int));
// Make a list of how many elements that tells how
// many elements to which each node belongs.
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
nmbr[meshele[i].p[j]]++;
// mete out some memory to build a list of the
// connectivity...
mbr=(int **)calloc(NumNodes,sizeof(int *));
for(i=0;i<NumNodes;i++){
mbr[i]=(int *)calloc(nmbr[i],sizeof(int));
nmbr[i]=0;
}
// fill up the connectivity information;
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
{
k=meshele[i].p[j];
mbr[k][nmbr[k]]=i;
nmbr[k]++;
}
sprintf(infile,"%s.edge",PathName);
if((fp=fopen(infile,"rt"))==NULL)
{
return FALSE;
}
fscanf(fp,"%i",&k); // read in number of lines
fscanf(fp,"%i",&j); // read in boundarymarker flag;
for(i=0;i<k;i++)
{
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&n0);
fscanf(fp,"%i",&n1);
fscanf(fp,"%i",&n);
// BC number;
if (n<0)
{
n=(-n);
j = (n & 0xffff) - 2;
if (j<0) j = -1;
// Conductor number;
n= (n - (n & 0xffff))/0x10000 - 1;
if (n>=0)
{
meshnode[n0].InConductor=n;
meshnode[n1].InConductor=n;
}
}
else j=-1;
if (j>=0)
{
// search through elements to find one containing the line;
// set corresponding edge equal to the bc number
for(q=0,n=FALSE;q<nmbr[n0];q++)
{
elm=meshele[mbr[n0][q]];
if ((elm.p[0] == n0) && (elm.p[1] == n1)) {elm.e[0]=j; n=TRUE;}
if ((elm.p[0] == n1) && (elm.p[1] == n0)) {elm.e[0]=j; n=TRUE;}
if ((elm.p[1] == n0) && (elm.p[2] == n1)) {elm.e[1]=j; n=TRUE;}
if ((elm.p[1] == n1) && (elm.p[2] == n0)) {elm.e[1]=j; n=TRUE;}
if ((elm.p[2] == n0) && (elm.p[0] == n1)) {elm.e[2]=j; n=TRUE;}
if ((elm.p[2] == n1) && (elm.p[0] == n0)) {elm.e[2]=j; n=TRUE;}
meshele[mbr[n0][q]]=elm;
//this is a little hack: line charge distributions should be applied
//to at most one element;
if((lineproplist[j].BdryFormat==2) && (n)) q=nmbr[n0];
}
}
}
fclose(fp);
// free up the connectivity information
free(nmbr);
for(i=0;i<NumNodes;i++) free(mbr[i]);
free(mbr);
// clear out temporary files
sprintf(infile,"%s.ele",PathName); DeleteFile(infile);
sprintf(infile,"%s.node",PathName); DeleteFile(infile);
sprintf(infile,"%s.pbc",PathName); DeleteFile(infile);
sprintf(infile,"%s.poly",PathName); DeleteFile(infile);
return TRUE;
}

73
belasolv/femmedoccore.h Normal file
View File

@ -0,0 +1,73 @@
// femmeDoc.h : interface of the CFemmeDoc class
//
/////////////////////////////////////////////////////////////////////////////
#define muo 1.2566370614359173e-6
#define Golden 0.3819660112501051517954131656
class CFemmeDocCore
{
// Attributes
public:
CFemmeDocCore();
~CFemmeDocCore();
// General problem attributes
double Precision;
double Depth;
int LengthUnits;
BOOL ProblemType;
BOOL Coords;
// Axisymmetric external region parameters
double extRo,extRi,extZo;
CbelasolvDlg *TheView;
// CArrays containing the mesh information
int BandWidth;
CNode *meshnode;
CElement *meshele;
int NumNodes;
int NumEls;
// lists of properties
int NumBlockProps;
int NumPBCs;
int NumLineProps;
int NumPointProps;
int NumCircProps;
int NumBlockLabels;
CMaterialProp *blockproplist;
CBoundaryProp *lineproplist;
CPointProp *nodeproplist;
CCircuit *circproplist;
CBlockLabel *labellist;
CCommonPoint *pbclist;
// stuff usually kept track of by CDocument
char *PathName;
// Operations
public:
BOOL LoadMesh();
BOOL OnOpenDocument();
BOOL Cuthill();
BOOL SortElements();
BOOL AnalyzeProblem(CBigLinProb &L);
double ChargeOnConductor(int OnConductor, CBigLinProb &L);
BOOL WriteResults(CBigLinProb &L);
void CleanUp();
};
/////////////////////////////////////////////////////////////////////////////
double Power(double x, int n);

128
belasolv/main.cpp Normal file
View File

@ -0,0 +1,128 @@
#include<stdafx.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<afxtempl.h>
#include "belasolv.h"
#include "belasolvDlg.h"
#include "spars.h"
#include "mesh.h"
#include "FemmeDocCore.h"
void old_main(void *inptr)
{
CbelasolvDlg *TheView;
CFemmeDocCore Doc;
char PathName[256];
CFileDialog *fname_dia;
char outstr[1024];
int i;
TheView=(CbelasolvDlg *) inptr;
// get the name of the file to be processed,
// either from argv or from the user
if (__argc<2){
fname_dia=new CFileDialog(
TRUE,
"fem | * ",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"belaview datafile (*.fee) | *.fee; *.FEE | All Files (*.*) | *.*||",
NULL);
if(fname_dia->DoModal()==IDCANCEL){
delete[] fname_dia;
MsgBox("No file name!");
exit(0);
}
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;
// load problem geometry
if (Doc.OnOpenDocument()!=TRUE){
MsgBox("problem loading .fee file");
exit(7);
}
// load mesh
if (Doc.LoadMesh()!=TRUE){
MsgBox("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 - belasolve",ProbName);
}
while(!IsWindow(TheView->m_hWnd)) Sleep(1);
TheView->SetWindowText(PaneText);
// renumber using Cuthill-McKee
TheView->SetDlgItemText(IDC_STATUSWINDOW,"renumbering nodes");
if (Doc.Cuthill()!=TRUE){
MsgBox("problem renumbering nodes");
exit(3);
}
// display details about the problem to be solved
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);
// initialize the problem, allocating the space required to solve it.
CBigLinProb L;
L.TheView=TheView;
L.Precision=Doc.Precision;
if (L.Create(Doc.NumNodes+Doc.NumCircProps,Doc.BandWidth)==FALSE){
MsgBox("couldn't allocate enough space for matrices");
Doc.CleanUp();
L.~CBigLinProb();
exit(4);
}
// Create element matrices and solve the problem;
if (Doc.AnalyzeProblem(L)==FALSE)
{
MsgBox("Couldn't solve the problem");
Doc.CleanUp();
L.~CBigLinProb();
exit(5);
}
TheView->SetDlgItemText(IDC_STATUSWINDOW,"Problem solved");
// now that we have results, write 'em to dist
if (Doc.WriteResults(L)==FALSE)
{
MsgBox("couldn't write results to disk");
Doc.CleanUp();
L.~CBigLinProb();
exit(6);
}
TheView->SetDlgItemText(IDC_STATUSWINDOW,"results written to disk");
// make sure that everything is freed up to avoid memory leaks
Doc.CleanUp();
L.~CBigLinProb();
exit(0);
}

100
belasolv/mesh.h Normal file
View File

@ -0,0 +1,100 @@
#define PI 3.141592653589793238462643383
#define eo 8.85418781762e-12
#define AXISYMMETRIC 1
#define PLANAR 0
class CNode
{
public:
double x,y;
int bc;
int InConductor;
private:
};
class CElement
{
public:
int p[3]; // nodes at the corners of the element
int e[3]; // boundary condition applied to each edge of the element
int blk; // block property applied to the element
int lbl; // block label associated with the element
private:
};
class CBlockLabel
{
public:
double x,y;
double MaxArea;
int BlockType,InGroup;
BOOL IsExternal;
BOOL IsDefault;
private:
};
class CCommonPoint
{
public:
int x,y,t;
private:
};
/////////////////////////////////////////////////////////////////////////////
// Classes that hold property data: CMaterialProp, CBoundaryProp, CPointProp
class CMaterialProp
{
public:
double ex,ey; // permittivity, relative
double qv; // charge density, C/m^3
private:
};
class CBoundaryProp
{
public:
int BdryFormat; // type of boundary condition we are applying
// 0 = fixed voltage
// 1 = mixed BC
// 2 = surface charge
// 3 = periodic
// 4 = antiperiodic
double V; // set value of V for BdryFormat=0;
double qs; // surface charge density
double c0,c1; // coefficients for mixed BC
private:
};
class CPointProp
{
public:
double V; // fixed nodal voltage
double qp; // point current density;
private:
};
class CCircuit
{
public:
double V,q;
int CircType;
private:
};

381
belasolv/prob1big.cpp Normal file
View File

@ -0,0 +1,381 @@
#include<stdafx.h>
#include<stdio.h>
#include<math.h>
#include "belasolv.h"
#include "belasolvDlg.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"
//conversion to internal working units of mm
double units[]={25.4,1.,10.,1000.,0.0254,0.001};
double sq(double x){ return x*x; }
BOOL CFemmeDocCore::AnalyzeProblem(CBigLinProb &L)
{
int i,j,k,pctr=0;
double Me[3][3],be[3]; // element matrices;
double l[3],p[3],q[3]; // element shape parameters;
int n[3],ne[3]; // numbers of nodes for a particular element;
double a,K,r,z,kludge;
CElement *El;
double c = (1.e-6)/eo;
Depth*=units[LengthUnits];
extRo*=units[LengthUnits];
extRi*=units[LengthUnits];
extZo*=units[LengthUnits];
kludge=1;
TheView->SetDlgItemText(IDC_FRAME1,"Matrix Construction");
// do some book-keeping related to fixed boundary conditions;
// The P vector denotes which nodes have an assigned value
// The V vector denotes the assigned value
for(i=0;i<NumNodes;i++)
{
L.Q[i]=-2;
if(meshnode[i].bc >=0)
if(nodeproplist[meshnode[i].bc].qp==0)
{
L.V[i]=nodeproplist[meshnode[i].bc].V;
L.Q[i]=-1;
}
if(meshnode[i].InConductor>=0)
if(circproplist[meshnode[i].InConductor].CircType==1)
{
L.V[i]=circproplist[meshnode[i].InConductor].V;
L.Q[i]=meshnode[i].InConductor;
}
}
// account for fixed boundary conditions along segments;
for(i=0;i<NumEls;i++)
{
for(j=0;j<3;j++){
k=j+1; if(k==3) k=0;
if(meshele[i].e[j]>=0)
{
if(lineproplist[ meshele[i].e[j] ].BdryFormat==0)
{
L.V[meshele[i].p[j]]=lineproplist[meshele[i].e[j]].V;
L.V[meshele[i].p[k]]=lineproplist[meshele[i].e[j]].V;
L.Q[meshele[i].p[j]]=-1;
L.Q[meshele[i].p[k]]=-1;
}
}
}
}
// build element matrices using the matrices derived in Allaire's book.
for(i=0;i<NumEls;i++)
{
// update progress bar
j=5*((i*20)/NumEls);
if(j!=pctr){ pctr=j; TheView->m_prog1.SetPos(pctr); }
// zero out Me, be;
for(j=0;j<3;j++){
for(k=0;k<3;k++) Me[j][k]=0;
be[j]=0;
}
// Determine shape parameters.
// l's are element side lengths;
// p's corresponds to the `b' parameter in Allaire
// q's corresponds to the `c' parameter in Allaire
El=&meshele[i];
for(k=0;k<3;k++) n[k]=El->p[k];
p[0]=meshnode[n[1]].y - meshnode[n[2]].y;
p[1]=meshnode[n[2]].y - meshnode[n[0]].y;
p[2]=meshnode[n[0]].y - meshnode[n[1]].y;
q[0]=meshnode[n[2]].x - meshnode[n[1]].x;
q[1]=meshnode[n[0]].x - meshnode[n[2]].x;
q[2]=meshnode[n[1]].x - meshnode[n[0]].x;
for(j=0,k=1;j<3;k++,j++){
if (k==3) k=0;
l[j]=sqrt( sq(meshnode[n[k]].x-meshnode[n[j]].x) +
sq(meshnode[n[k]].y-meshnode[n[j]].y) );
}
a=(p[0]*q[1]-p[1]*q[0])/2.;
r=(meshnode[n[0]].x+meshnode[n[1]].x+meshnode[n[2]].x)/3.;
if (ProblemType==AXISYMMETRIC){
Depth=2.*PI*r;
// "Warp" the permeability of this element is part of
// the conformally mapped external region
if(labellist[meshele[i].lbl].IsExternal)
{
z=(meshnode[n[0]].y+meshnode[n[1]].y+meshnode[n[2]].y)/3. - extZo;
kludge=(r*r+z*z)/(extRi*extRo);
}
else kludge=1;
}
// x-contribution;
K = -Depth*blockproplist[El->blk].ex/(4.*a)/kludge;
for(j=0;j<3;j++)
for(k=j;k<3;k++)
{
Me[j][k] += K*p[j]*p[k];
if (j!=k) Me[k][j]+=K*p[j]*p[k];
}
// y-contribution;
K = -Depth*blockproplist[El->blk].ey/(4.*a)/kludge;
for(j=0;j<3;j++)
for(k=j;k<3;k++)
{
Me[j][k] +=K*q[j]*q[k];
if (j!=k) Me[k][j]+=K*q[j]*q[k];
}
// contribution to be[] from volume charge density
for(j = 0;j<3;j++){
K = -Depth*c*(blockproplist[El->blk].qv)*a/3.;
be[j]+=K;
}
for(j=0;j<3;j++)
{
if (El->e[j] >= 0)
{
k=j+1; if(k==3) k=0;
if (ProblemType==AXISYMMETRIC)
Depth=PI*(meshnode[n[j]].x + meshnode[n[k]].x);
// contributions to Me, be from derivative boundary conditions;
if (lineproplist[El->e[j]].BdryFormat==1)
{
K =-1000.*Depth*c*lineproplist[El->e[j]].c0*l[j]/6.;
Me[j][j]+=K*2.;
Me[k][k]+=K*2.;
Me[j][k]+=K;
Me[k][j]+=K;
K = 1000.*Depth*c*lineproplist[El->e[j]].c1*l[j]/2.;
be[j]+=K;
be[k]+=K;
}
// contribution to be[] from surface charge density;
if (lineproplist[El->e[j]].BdryFormat==2)
{
K =-1000.*Depth*c*lineproplist[El->e[j]].qs*l[j]/2.;
be[j]+=K;
be[k]+=K;
}
}
}
// process any prescribed nodal values;
for(j=0;j<3;j++)
{
if(L.Q[n[j]]!=-2)
{
for(k=0;k<3;k++)
{
if(j!=k){
be[k]-=Me[k][j]*L.V[n[j]];
Me[k][j]=0;
Me[j][k]=0;
}
}
be[j]=L.V[n[j]]*Me[j][j];
}
}
// combine block matrices into global matrices;
for (j=0;j<3;j++)
{
ne[j]=n[j];
if(meshnode[n[j]].InConductor>=0)
if(circproplist[meshnode[n[j]].InConductor].CircType==0)
ne[j]=meshnode[n[j]].InConductor+NumNodes;
}
for (j=0;j<3;j++){
for (k=j;k<3;k++)
L.Put(L.Get(ne[j],ne[k])-Me[j][k],ne[j],ne[k]);
L.b[ne[j]]-=be[j];
if(ne[j]!=n[j])
{
L.Put(L.Get(n[j],n[j])-Me[j][j],n[j],n[j]);
L.Put(L.Get(n[j],ne[j])+Me[j][j],n[j],ne[j]);
}
}
} // end of loop that builds element matrices
// add in contribution from point charge density;
for(i=0;i<NumNodes;i++)
{
if((meshnode[i].bc>=0) && (L.Q[i]==-2))
{
if (ProblemType==AXISYMMETRIC) Depth=2.*PI*meshnode[i].x;
L.b[i]+=((1.e6)*Depth*c*nodeproplist[meshnode[i].bc].qp);
L.Q[i]=-1;
}
// some bookkeeping to denote which nodes we can smooth over
if(meshnode[i].InConductor>=0) L.Q[i]=meshnode[i].InConductor;
}
// Apply any periodicity/antiperiodicity boundary conditions that we have
for(k=0,pctr=0;k<NumPBCs;k++)
{
if (pbclist[k].t==0) L.Periodicity(pbclist[k].x,pbclist[k].y);
if (pbclist[k].t==1) L.AntiPeriodicity(pbclist[k].x,pbclist[k].y);
}
// Finish building the equations that assign conductor voltage;
for(i=0;i<NumCircProps;i++)
{
// put a placeholder on the main diagonal;
k=NumNodes+i;
if (circproplist[i].CircType==1)
{
K=L.Get(0,0);
L.Put(K,k,k);
L.b[k]=K*circproplist[i].V;
}
if(circproplist[i].CircType==0)
{
for(j=0,K=0;j<L.n;j++) if(j!=k) K+=L.Get(k,j);
if(K!=0){
L.Put(-K,k,k);
L.b[k]=(1.e9)*c*circproplist[i].q;
}
else L.Put(L.Get(0,0),k,k);
}
}
// solve the problem;
if (L.PCGSolve(FALSE)==FALSE) return FALSE;
// compute total charge on conductors
// with a specified voltage
for(i=0;i<NumCircProps;i++)
if(circproplist[i].CircType==1)
circproplist[i].q=ChargeOnConductor(i,L);
return TRUE;
}
//=========================================================================
//=========================================================================
BOOL CFemmeDocCore::WriteResults(CBigLinProb &L)
{
// write solution to disk;
char c[1024];
FILE *fp,*fz;
int i;
double cf;
// first, echo input .fee file to the .res file;
sprintf(c,"%s.fee",PathName);
if((fz=fopen(c,"rt"))==NULL){
Sleep(500);
if((fz=fopen(c,"rt"))==NULL){
fprintf(stderr,"Couldn't open %s.fee\n",PathName);
return FALSE;
}
}
sprintf(c,"%s.res",PathName);
if((fp=fopen(c,"wt"))==NULL){
Sleep(500);
if((fp=fopen(c,"wt"))==NULL){
fprintf(stderr,"Couldn't write to %s.res\n",PathName);
return FALSE;
}
}
while(fgets(c,1024,fz)!=NULL) fputs(c,fp);
fclose(fz);
// then print out node, line, and element information
fprintf(fp,"[Solution]\n");
cf=units[LengthUnits];
fprintf(fp,"%i\n",NumNodes);
for(i=0;i<NumNodes;i++)
fprintf(fp,"%.17g %.17g %.17g %i\n",meshnode[i].x/cf,meshnode[i].y/cf,L.V[i],L.Q[i]);
fprintf(fp,"%i\n",NumEls);
for(i=0;i<NumEls;i++)
fprintf(fp,"%i %i %i %i\n",
meshele[i].p[0],meshele[i].p[1],meshele[i].p[2],meshele[i].lbl);
// print out circuit info
fprintf(fp,"%i\n",NumCircProps);
for(i=0;i<NumCircProps;i++)
fprintf(fp,"%.17g %.17g\n",L.V[NumNodes+i],circproplist[i].q);
fclose(fp);
return TRUE;
}
//=========================================================================
//=========================================================================
double CFemmeDocCore::ChargeOnConductor(int u, CBigLinProb &L)
{
int i,k;
double b[3],c[3]; // element shape parameters;
int n[3]; // numbers of nodes for a particular element;
double a,da,Dx,Dy,vx,vy,Z;
double LengthConv=0.001;
for(i=0;i<NumNodes;i++)
if(meshnode[i].InConductor==u) L.P[i]=1;
else L.P[i]=0;
// build element matrices using the matrices derived in Allaire's book.
for(i=0,Z=0;i<NumEls;i++)
{
for(k=0;k<3;k++) n[k]=meshele[i].p[k];
if((L.P[n[0]]!=0) || (L.P[n[1]]!=0) || (L.P[n[2]]!=0))
{
// Determine shape parameters.
b[0]=meshnode[n[1]].y - meshnode[n[2]].y;
b[1]=meshnode[n[2]].y - meshnode[n[0]].y;
b[2]=meshnode[n[0]].y - meshnode[n[1]].y;
c[0]=meshnode[n[2]].x - meshnode[n[1]].x;
c[1]=meshnode[n[0]].x - meshnode[n[2]].x;
c[2]=meshnode[n[1]].x - meshnode[n[0]].x;
da=(b[0]*c[1]-b[1]*c[0]);
a=da*LengthConv*LengthConv/2.;
if (ProblemType==AXISYMMETRIC)
a*=(2.*PI*LengthConv*(meshnode[n[0]].x+meshnode[n[1]].x+meshnode[n[2]].x)/3.);
else a*=(Depth*LengthConv);
// get normal vector and element flux density;
for(k=0,vx=0,vy=0,Dx=0,Dy=0;k<3;k++)
{
vx-=(L.P[n[k]]*b[k])/(da*LengthConv);
vy-=(L.P[n[k]]*c[k])/(da*LengthConv);
Dx-=(L.V[n[k]]*b[k])/(da*LengthConv);
Dy-=(L.V[n[k]]*c[k])/(da*LengthConv);
}
Dx*=(eo*blockproplist[meshele[i].blk].ex);
Dy*=(eo*blockproplist[meshele[i].blk].ey);
Z+=a*(Dx*vx+Dy*vy);
}
}
return Z;
}

BIN
belasolv/res/belasolv.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

402
belasolv/spars.cpp Normal file
View File

@ -0,0 +1,402 @@
#include <stdafx.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "belasolv.h"
#include "belasolvDlg.h"
#include "spars.h"
#define KLUDGE
CEntry::CEntry()
{
next=NULL;
x=0;
c=0;
}
CBigLinProb::CBigLinProb()
{
n=0;
}
CBigLinProb::~CBigLinProb()
{
if (n==0) return;
int i;
CEntry *uo,*ui;
free(b); free(P); free(R);
free(V); free(U); free(Z);
free(Q);
for(i=0;i<n;i++)
{
ui=M[i];
do{
uo=ui;
ui=uo->next;
delete uo;
} while(ui!=NULL);
}
free(M);
n=0;
}
int CBigLinProb::Create(int d, int bw)
{
int i;
bdw=bw;
b=(double *)calloc(d,sizeof(double));
V=(double *)calloc(d,sizeof(double));
P=(double *)calloc(d,sizeof(double));
R=(double *)calloc(d,sizeof(double));
U=(double *)calloc(d,sizeof(double));
Z=(double *)calloc(d,sizeof(double));
Q=(BOOL *) calloc(d,sizeof(BOOL));
M=(CEntry **)calloc(d,sizeof(CEntry *));
n=d;
for(i=0;i<d;i++){
M[i] = new CEntry;
M[i]->c = i;
}
return 1;
}
void CBigLinProb::Put(double v, int p, int q)
{
CEntry *e,*l;
int i;
if(q<p){ i=p; p=q; q=i; }
e=M[p];
while((e->c < q) && (e->next != NULL))
{
l=e;
e=e->next;
}
if(e->c == q){
e->x=v;
return;
}
CEntry *m = new CEntry;
if((e->next == NULL) && (q > e->c)){
e->next = m;
m->c = q;
m->x = v;
}
else{
l->next=m;
m->next=e;
m->c=q;
m->x=v;
}
return;
}
double CBigLinProb::Get(int p, int q)
{
CEntry *e;
if(q<p){ int i; i=p; p=q; q=i; }
e=M[p];
while((e->c < q) && (e->next != NULL)) e=e->next;
if(e->c == q) return e->x;
return 0;
}
void CBigLinProb::MultA(double *X, double *Y)
{
int i;
CEntry *e;
for(i=0;i<n;i++) Y[i]=0;
for(i=0;i<n;i++){
Y[i]+=M[i]->x*X[i];
e=M[i]->next;
while(e!=NULL)
{
Y[i]+=e->x*X[e->c];
Y[e->c]+=e->x*X[i];
e=e->next;
}
}
}
double CBigLinProb::Dot(double *X, double *Y)
{
int i;
double z;
for(i=0,z=0;i<n;i++) z+=X[i]*Y[i];
return z;
}
void CBigLinProb::MultPC(double *X, double *Y)
{
// Jacobi preconditioner:
// int i;
// for(i=0;i<n;i++) Y[i]=X[i]/M[i]->x;
// SSOR preconditioner:
int i;
double c;
CEntry *e;
c= Lambda*(2-Lambda);
for(i=0;i<n;i++) Y[i]=X[i]*c;
// invert Lower Triangle;
for(i=0;i<n;i++){
Y[i]/= M[i]->x;
e=M[i]->next;
while(e!=NULL)
{
Y[e->c] -= e->x * Y[i] * Lambda;
e=e->next;
}
}
for(i=0;i<n;i++) Y[i]*=M[i]->x;
// invert Upper Triangle
for(i=n-1;i>=0;i--){
e=M[i]->next;
while(e!=NULL)
{
Y[i] -= e->x * Y[e->c] * Lambda;
e=e->next;
}
Y[i]/= M[i]->x;
}
}
int CBigLinProb::PCGSolve(int flag)
{
int i;
double res,res_o,res_new;
double er,del,rho,pAp;
// quick check for most obvious sign of singularity;
for(i=0;i<n;i++) if(M[i]->x==0){
MsgBox("singular flag tripped at %i of %i",i,n);
return FALSE;
}
// initialize progress bar;
TheView->SetDlgItemText(IDC_FRAME1,"Conjugate Gradient Solver");
TheView->m_prog1.SetPos(0);
int prg1=0;
int prg2;
// Best guess for relaxation parameter
Lambda=1.5;
// residual with V=0
MultPC(b,Z);
res_o=Dot(Z,b);
if(res_o==0) return 1;
// if flag is false, initialize V with zeros;
if (flag==0) for(i=0;i<n;i++) V[i]=0;
// form residual;
MultA(V,R);
for(i=0;i<n;i++) R[i]=b[i]-R[i];
// form initial search direction;
MultPC(R,Z);
for(i=0;i<n;i++) P[i]=Z[i];
res=Dot(Z,R);
// do iteration;
do{
// step i)
MultA(P,U);
pAp=Dot(P,U);
del=res/pAp;
// step ii)
for(i=0;i<n;i++) V[i]+=(del*P[i]);
// step iii)
for(i=0;i<n;i++) R[i]-=(del*U[i]);
// step iv)
MultPC(R,Z);
res_new=Dot(Z,R);
rho=res_new/res;
res=res_new;
// step v)
for(i=0;i<n;i++) P[i]=Z[i]+(rho*P[i]);
// have we converged yet?
er=sqrt(res/res_o);
prg2=(int) (20.*log10(er)/(log10(Precision)));
if(prg2>prg1){
prg1=prg2;
prg2=(prg1*5);
if(prg2>100) prg2=100;
TheView->m_prog1.SetPos(prg2);
TheView->InvalidateRect(NULL, FALSE);
TheView->UpdateWindow();
}
} while(er>Precision);
return 1;
}
void CBigLinProb::SetValue(int i, double x)
{
int k,fst,lst;
double z;
if(bdw==0){
fst=0;
lst=n;
}
else{
fst=i-bdw; if (fst<0) fst=0;
lst=i+bdw; if (lst>n) lst=n;
}
for(k=fst;k<lst;k++)
{
z=Get(k,i);
if(z!=0){
b[k]=b[k]-(z*x);
if(i!=k) Put(0.,k,i);
}
}
b[i]=Get(i,i)*x;
}
void CBigLinProb::Wipe()
{
int i;
CEntry *e;
for(i=0;i<n;i++){
b[i]=0.;
e=M[i];
do{
e->x=0;
e=e->next;
} while(e!=NULL);
}
}
void CBigLinProb::AntiPeriodicity(int i, int j)
{
int k,fst,lst;
double v1,v2,c;
#ifdef KLUDGE
int tmpbdw=bdw;
bdw=0;
#endif
if (j<i) {k=j;j=i;i=k;}
if(bdw==0){
fst=0;
lst=n;
}
else{
fst=i-bdw; if (fst<0) fst=0;
lst=j+bdw; if (lst>n) lst=n;
}
for(k=fst;k<lst;k++)
{
if((k!=i) && (k!=j))
{
v1=Get(k,i);
v2=Get(k,j);
if ((v1!=0) || (v2!=0)){
c=(v1-v2)/2.;
Put(c,k,i);
Put(-c,k,j);
}
}
if((k==i+bdw) && (k<j-bdw) && (bdw!=0)) k=j-bdw;
}
c=0.5*(Get(i,i)+Get(j,j));
Put(c,i,i);
Put(c,j,j);
c=0.5*(b[i]-b[j]);
b[i]=c;
b[j]=-c;
#ifdef KLUDGE
bdw=tmpbdw;
#endif
}
void CBigLinProb::Periodicity(int i, int j)
{
int k,fst,lst;
double v1,v2,c;
#ifdef KLUDGE
int tmpbdw=bdw;
bdw=0;
#endif
if (j<i) {k=j;j=i;i=k;}
if(bdw==0){
fst=0;
lst=n;
}
else{
fst=i-bdw; if (fst<0) fst=0;
lst=j+bdw; if (lst>n) lst=n;
}
for(k=fst;k<lst;k++){
if((k!=i) && (k!=j))
{
v1=Get(k,i);
v2=Get(k,j);
if ((v1!=0) || (v2!=0)) {
c=(v1+v2)/2.;
Put(c,k,i);
Put(c,k,j);
}
}
if((k==i+bdw) && (k<j-bdw) && (bdw!=0)) k=j-bdw;
}
c=(Get(i,i)+Get(j,j))/2.;
Put(c,i,i);
Put(c,j,j);
c=0.5*(b[i]+b[j]);
b[i]=c;
b[j]=c;
#ifdef KLUDGE
bdw=tmpbdw;
#endif
}

54
belasolv/spars.h Normal file
View File

@ -0,0 +1,54 @@
class CEntry
{
public:
double x; // value stored in the entry
int c; // column that the entry lives in
CEntry *next; // pointer to next entry in row;
CEntry();
private:
};
class CBigLinProb
{
public:
// data members
double *V; // solution
double *P; // search direction;
double *R; // residual;
double *U; // A * P;
double *Z;
double *b; // RHS of linear equation
BOOL *Q;
CEntry **M; // pointer to list of matrix entries;
int n; // dimensions of the matrix;
int bdw; // Optional matrix bandwidth parameter;
double Lambda; // relaxation factor;
double Precision; // error tolerance for solution
// member functions
CBigLinProb(); // constructor
~CBigLinProb(); // destructor
int Create(int d, int bw); // initialize the problem
void Put(double v, int p, int q);
// use to create/set entries in the matrix
double Get(int p, int q);
int PCGSolve(int flag); // flag==true if guess for V present;
void MultPC(double *X, double *Y);
void MultA(double *X, double *Y);
void SetValue(int i, double x);
void Periodicity(int i, int j);
void AntiPeriodicity(int i, int j);
void Wipe();
double Dot(double *X, double *Y);
CbelasolvDlg *TheView;
private:
};

107
compat/afx.h Normal file
View File

@ -0,0 +1,107 @@
// portable umbrella for the MFC surface FEMM math files touch: BOOL/TRUE/FALSE, CString, _strnicmp, DeleteFile.
#pragma once
#include <string>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <strings.h>
#define __AFXWIN_H__
#ifndef BOOL
typedef int BOOL;
#endif
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
// MFC-flavored thin wrapper around std::string.
class CString {
std::string s;
public:
CString() = default;
CString(const char* p) : s(p ? p : "") {}
CString(const std::string& x) : s(x) {}
operator const char*() const { return s.c_str(); }
const char* c_str() const { return s.c_str(); }
const char* GetString() const { return s.c_str(); }
const std::string& Std() const { return s; }
std::string& Std() { return s; }
int GetLength() const { return (int)s.size(); }
bool IsEmpty() const { return s.empty(); }
void Empty() { s.clear(); }
char operator[](int i) const { return s[(size_t)i]; }
CString& operator=(const char* p) { s = p ? p : ""; return *this; }
CString& operator=(const std::string& x) { s = x; return *this; }
CString& operator+=(const CString& o) { s += o.s; return *this; }
CString& operator+=(const char* p) { s += p ? p : ""; return *this; }
CString& operator+=(char c) { s += c; return *this; }
CString operator+(const CString& o) const { CString r(*this); r += o; return r; }
CString operator+(const char* p) const { CString r(*this); r += p; return r; }
bool operator==(const CString& o) const { return s == o.s; }
bool operator==(const char* p) const { return s == (p ? p : ""); }
bool operator!=(const CString& o) const { return !(*this == o); }
bool operator!=(const char* p) const { return !(*this == p); }
bool operator<(const CString& o) const { return s < o.s; }
CString Mid(int start) const { return CString(s.substr((size_t)start)); }
CString Mid(int start, int n) const { return CString(s.substr((size_t)start, (size_t)n)); }
CString Left(int n) const { return CString(s.substr(0, (size_t)n)); }
CString Right(int n) const { int sz = (int)s.size(); return CString(s.substr((size_t)(sz > n ? sz - n : 0))); }
int Find(char c) const { auto p = s.find(c); return p == std::string::npos ? -1 : (int)p; }
int Find(const char* p) const { auto i = s.find(p ? p : ""); return i == std::string::npos ? -1 : (int)i; }
int ReverseFind(char c) const { auto p = s.rfind(c); return p == std::string::npos ? -1 : (int)p; }
void MakeLower() { for (auto& c : s) c = (char)std::tolower((unsigned char)c); }
void MakeUpper() { for (auto& c : s) c = (char)std::toupper((unsigned char)c); }
void TrimLeft() { while (!s.empty() && std::isspace((unsigned char)s.front())) s.erase(s.begin()); }
void TrimRight() { while (!s.empty() && std::isspace((unsigned char)s.back())) s.pop_back(); }
int Format(const char* fmt, ...) {
va_list ap; va_start(ap, fmt);
int n = vsnprintf(nullptr, 0, fmt, ap); va_end(ap);
if (n <= 0) { s.clear(); return 0; }
s.resize((size_t)n);
va_start(ap, fmt);
vsnprintf(&s[0], (size_t)n + 1, fmt, ap);
va_end(ap);
return n;
}
};
// concatenation of CString and a C string literal on either side.
inline CString operator+(const char* p, const CString& r) { return CString(p) + r; }
// Win32 stand-ins used by FEMM math files.
inline int DeleteFile(const char* path) { return std::remove(path) == 0; }
inline int _strnicmp(const char* a, const char* b, size_t n) { return strncasecmp(a, b, n); }
inline int _stricmp (const char* a, const char* b) { return strcasecmp(a, b); }
inline void Sleep(unsigned int /*ms*/) {}
// MSVC math-intrinsic macros.
#ifndef __min
#define __min(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef __max
#define __max(a, b) ((a) > (b) ? (a) : (b))
#endif
// forward decls for MFC dialog/binding types femm/ headers reference.
class CDataExchange;
class CWnd;
class CDialog;
class CFile;
class CFileException;
class CArchive;
class CObject;
class CRuntimeClass;
#include "resource.h"

2
compat/afxcmn.h Normal file
View File

@ -0,0 +1,2 @@
// empty stand-in for the MFC common-controls header.
#pragma once

2
compat/afxdisp.h Normal file
View File

@ -0,0 +1,2 @@
// empty stand-in for the MFC automation header.
#pragma once

2
compat/afxdtctl.h Normal file
View File

@ -0,0 +1,2 @@
// empty stand-in for the MFC date/time control header.
#pragma once

2
compat/afxext.h Normal file
View File

@ -0,0 +1,2 @@
// empty stand-in for the MFC extensions header.
#pragma once

38
compat/afxtempl.h Normal file
View File

@ -0,0 +1,38 @@
// CArray<T, ARG_T> wrapping std::vector with MFC's method names.
#pragma once
#include "afx.h"
#include <vector>
#include <cstddef>
template<class T, class ARG_T = const T&>
class CArray {
std::vector<T> v;
public:
CArray() = default;
int GetSize() const { return (int)v.size(); }
int GetCount() const { return (int)v.size(); }
bool IsEmpty() const { return v.empty(); }
int GetUpperBound() const { return (int)v.size() - 1; }
void SetSize(int n, int /*growBy*/ = -1) { v.resize((size_t)n); }
void RemoveAll() { v.clear(); }
void RemoveAt(int i, int n = 1) { v.erase(v.begin() + i, v.begin() + i + n); }
int Add(ARG_T x) { v.push_back(x); return (int)v.size() - 1; }
void InsertAt(int i, ARG_T x, int n = 1) { v.insert(v.begin() + i, (size_t)n, x); }
T GetAt(int i) const { return v[(size_t)i]; }
void SetAt(int i, ARG_T x) { v[(size_t)i] = x; }
T& ElementAt(int i) { return v[(size_t)i]; }
void SetAtGrow(int i, ARG_T x) { if ((size_t)i >= v.size()) v.resize((size_t)i + 1); v[(size_t)i] = x; }
T* GetData() { return v.data(); }
const T* GetData() const { return v.data(); }
T& operator[](int i) { return v[(size_t)i]; }
const T& operator[](int i) const { return v[(size_t)i]; }
void Copy(const CArray& src) { v = src.v; }
int Append(const CArray& src) { int s = (int)v.size(); v.insert(v.end(), src.v.begin(), src.v.end()); return s; }
};

106
compat/afxwin.h Normal file
View File

@ -0,0 +1,106 @@
// MFC widget skeletons so GUI headers parse without dragging in real MFC.
#pragma once
#include "afx.h"
typedef unsigned int UINT;
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned char BYTE;
typedef long LONG;
typedef void* HCURSOR;
typedef void* HICON;
typedef void* HWND;
typedef void* HINSTANCE;
typedef void* HANDLE;
typedef int LPCRECT;
typedef const char* LPCSTR;
typedef const char* LPCTSTR;
typedef char* LPSTR;
typedef char* PSTR;
typedef const char* PCSTR;
typedef DWORD COLORREF;
typedef unsigned long WPARAM;
typedef long LPARAM;
typedef long LRESULT;
struct CPoint { int x = 0, y = 0; CPoint() = default; CPoint(int a, int b) : x(a), y(b) {} };
struct CRect { int left = 0, top = 0, right = 0, bottom = 0; };
struct CSize { int cx = 0, cy = 0; };
struct MSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; CPoint pt; };
#define RGB(r,g,b) ((COLORREF)(((BYTE)(r)) | ((WORD)((BYTE)(g))<<8) | ((DWORD)((BYTE)(b))<<16)))
#define PM_REMOVE 1
#define PM_NOREMOVE 0
#define MB_ICONEXCLAMATION 0x30
#define MB_OK 0
#define VK_ESCAPE 0x1B
#define WM_PAINT 0x000F
#define WM_CHAR 0x0102
#define WM_CLOSE 0x0010
#define WM_RBUTTONUP 0x0205
#define WM_KEYDOWN 0x0100
#define WM_KEYUP 0x0101
#define WM_LBUTTONDOWN 0x0201
#define WM_LBUTTONUP 0x0202
#define WM_QUIT 0x0012
inline int PeekMessage(MSG*, HWND, UINT, UINT, UINT) { return 0; }
inline int TranslateMessage(const MSG*) { return 0; }
inline long DispatchMessage(const MSG*) { return 0; }
inline int MessageBox(HWND, const char*, const char*, UINT) { return 0; }
inline int GetAsyncKeyState(int) { return 0; }
inline int MessageBeep(UINT) { return 0; }
#define afx_msg
#define DECLARE_MESSAGE_MAP()
#define BEGIN_MESSAGE_MAP(...)
#define END_MESSAGE_MAP()
#define ON_COMMAND(...)
#define ON_WM_PAINT()
#define ON_WM_CHAR()
#define ON_WM_RBUTTONUP()
#define ON_WM_CLOSE()
#define ON_BN_CLICKED(...)
#define DECLARE_DYNCREATE(x)
#define IMPLEMENT_DYNCREATE(...)
#define DECLARE_DYNAMIC(x)
#define IMPLEMENT_DYNAMIC(...)
class CObject {};
class CCmdTarget : public CObject {};
class CWnd : public CCmdTarget {
public:
void* m_hWnd = nullptr;
int SetDlgItemText(int, const char*) { return 0; }
int SetWindowText(const char*) { return 0; }
int UpdateWindow() { return 0; }
int InvalidateRect(void* = nullptr, int = 1) { return 1; }
};
class CDialog : public CWnd {
public:
CDialog(int = 0, CWnd* = nullptr) {}
virtual int DoModal() { return 0; }
virtual void OnOK() {}
virtual void OnCancel() {}
virtual int OnInitDialog() { return 1; }
};
class CEdit : public CWnd {
public:
int Create(unsigned long, const CRect&, CWnd*, unsigned int) { return 0; }
void SetSel(int, int, int = 0) {}
};
class CProgressCtrl : public CWnd { public: void SetPos(int) {} };
class CButton : public CWnd {};
class CStatic : public CWnd {};
class CComboBox : public CWnd {};
class CListBox : public CWnd {};
class CTreeCtrl : public CWnd {};
class CTabCtrl : public CWnd {};
class CDataExchange {};

640
compat/femm_resource_ids.h Normal file
View File

@ -0,0 +1,640 @@
// every IDD/IDC/IDR/IDS/IDM identifier femm/ names, mapped to 0 for parse-only builds.
#pragma once
#define IDC_A_RE 0
#define IDC_A0 0
#define IDC_A1 0
#define IDC_A2 0
#define IDC_ABCN 0
#define IDC_ABCR 0
#define IDC_ABCX 0
#define IDC_ABCY 0
#define IDC_ABOUTX 0
#define IDC_ABOUTY 0
#define IDC_ACKBLK 0
#define IDC_ACKNODE 0
#define IDC_ACKSEG 0
#define IDC_ADD_PROP 0
#define IDC_AGENAME 0
#define IDC_AHIGH 0
#define IDC_ALOW 0
#define IDC_AMPM 0
#define IDC_ARCANGLE 0
#define IDC_ARCGRP 0
#define IDC_ARCHIDE 0
#define IDC_ARCSEGBDRY 0
#define IDC_ARCSEGBDRY2 0
#define IDC_AUTOMESH 0
#define IDC_AUTOMESHCHECK 0
#define IDC_B 0
#define IDC_BASEX 0
#define IDC_BASEY 0
#define IDC_BD_ACKBLK 0
#define IDC_BD_ACKNODE 0
#define IDC_BD_ACKSEG 0
#define IDC_BD_ARCGRP 0
#define IDC_BD_ARCHIDE 0
#define IDC_BD_ARCSEG_COND 0
#define IDC_BD_ARCSEGBDRY2 0
#define IDC_BD_AUTOMESH 0
#define IDC_BD_AUTOMESHCHECK 0
#define IDC_BD_BDRYFORMAT 0
#define IDC_BD_BDRYNAME 0
#define IDC_BD_BLKGROUP 0
#define IDC_BD_BLOCKNAME 0
#define IDC_BD_C0 0
#define IDC_BD_C1 0
#define IDC_BD_CIRCNAME 0
#define IDC_BD_DACTION 0
#define IDC_BD_DCOLOR 0
#define IDC_BD_DCOORD 0
#define IDC_BD_DDEPTH 0
#define IDC_BD_DGRIDSIZE 0
#define IDC_BD_DLENGTH 0
#define IDC_BD_DMINANGLE 0
#define IDC_BD_DPIXELS 0
#define IDC_BD_DPREC 0
#define IDC_BD_DSHOWGRID 0
#define IDC_BD_DSNAPGRID 0
#define IDC_BD_DTYPE 0
#define IDC_BD_EDIT_DEPTH 0
#define IDC_BD_EX 0
#define IDC_BD_EXTERNAL 0
#define IDC_BD_EY 0
#define IDC_BD_ISDEFAULT 0
#define IDC_BD_LENGTH_UNITS 0
#define IDC_BD_LINEMESHSIZE 0
#define IDC_BD_MAXSEG2 0
#define IDC_BD_MINANG 0
#define IDC_BD_MODBTN 0
#define IDC_BD_MU1LABEL 0
#define IDC_BD_MU2LABEL 0
#define IDC_BD_NODE_COND 0
#define IDC_BD_NODENAME 0
#define IDC_BD_PRC 0
#define IDC_BD_PROBNOTE 0
#define IDC_BD_PROBTYPE 0
#define IDC_BD_PTGRP 0
#define IDC_BD_Q 0
#define IDC_BD_QP 0
#define IDC_BD_QS 0
#define IDC_BD_QV 0
#define IDC_BD_RADIOAMP 0
#define IDC_BD_RADIOVOLT 0
#define IDC_BD_RESTORE 0
#define IDC_BD_SEG_COND 0
#define IDC_BD_SEGGRP 0
#define IDC_BD_SEGHIDE 0
#define IDC_BD_SETA 0
#define IDC_BD_SETI 0
#define IDC_BD_SHOW_NAMES 0
#define IDC_BD_SHOW_ORIGIN 0
#define IDC_BD_SIDELENGTH 0
#define IDC_BD_V 0
#define IDC_BD_VBDRY 0
#define IDC_BD_VP 0
#define IDC_BDATA 0
#define IDC_BDRYFORMAT 0
#define IDC_BDRYNAME 0
#define IDC_BENDANGLE 0
#define IDC_BENDSEGMENT 0
#define IDC_BFIRST 0
#define IDC_BHEDIT 0
#define IDC_BHNAME 0
#define IDC_BINTTYPE 0
#define IDC_BLKGROUP 0
#define IDC_BLOCKNAME 0
#define IDC_BSMART 0
#define IDC_BTU 0
#define IDC_BV_AHIGH 0
#define IDC_BV_ALOW 0
#define IDC_BV_BINTTYPE 0
#define IDC_BV_CIRCNAME 0
#define IDC_BV_CIRCRESULT 0
#define IDC_BV_COLORS 0
#define IDC_BV_DENSITYPLOT 0
#define IDC_BV_DFLT1 0
#define IDC_BV_DPLOTTYPE 0
#define IDC_BV_EDITACTION 0
#define IDC_BV_FILEFORMAT 0
#define IDC_BV_GREY 0
#define IDC_BV_GSCALE2 0
#define IDC_BV_LB2 0
#define IDC_BV_LEGEND 0
#define IDC_BV_LINTTYPE 0
#define IDC_BV_LIPOINTS 0
#define IDC_BV_MODBTN 0
#define IDC_BV_NCONT 0
#define IDC_BV_NPOINTS 0
#define IDC_BV_NUMCONTOURS 0
#define IDC_BV_ONRELOAD 0
#define IDC_BV_PLOTPOINTS 0
#define IDC_BV_RESBTN2 0
#define IDC_BV_RESET 0
#define IDC_BV_SCALEFACTOR 0
#define IDC_BV_SHOW_A 0
#define IDC_BV_SHOW_LEG2 0
#define IDC_BV_SHOW_MASK2 0
#define IDC_BV_SHOWGRID 0
#define IDC_BV_SHOWIT 0
#define IDC_BV_SHOWMASK 0
#define IDC_BV_SHOWMESH 0
#define IDC_BV_SHOWNAMES 0
#define IDC_BV_SHOWPTS 0
#define IDC_BV_SHOWREAL 0
#define IDC_BV_SMOOTHING 0
#define IDC_BV_SNAPGRID 0
#define IDC_BV_TOFILE 0
#define IDC_BV_UB2 0
#define IDC_BV_VECTORPLOT 0
#define IDC_BV_VPLOTTYPE 0
#define IDC_BV_XYPLOTTYPE 0
#define IDC_C 0
#define IDC_C0 0
#define IDC_C1 0
#define IDC_CD_ACKBLK 0
#define IDC_CD_ACKNODE 0
#define IDC_CD_ACKSEG 0
#define IDC_CD_ARCGRP 0
#define IDC_CD_ARCHIDE 0
#define IDC_CD_ARCSEG_COND 0
#define IDC_CD_ARCSEGBDRY2 0
#define IDC_CD_AUTOMESH 0
#define IDC_CD_AUTOMESHCHECK 0
#define IDC_CD_BDRYFORMAT 0
#define IDC_CD_BDRYNAME 0
#define IDC_CD_BLKGROUP 0
#define IDC_CD_BLOCKNAME 0
#define IDC_CD_C0 0
#define IDC_CD_C1 0
#define IDC_CD_CIRCNAME 0
#define IDC_CD_EDIT_DEPTH 0
#define IDC_CD_EDIT_FREQ 0
#define IDC_CD_EX 0
#define IDC_CD_EXTERNAL 0
#define IDC_CD_EY 0
#define IDC_CD_ISDEFAULT 0
#define IDC_CD_LENGTH_UNITS 0
#define IDC_CD_LINEMESHSIZE 0
#define IDC_CD_LTX 0
#define IDC_CD_LTY 0
#define IDC_CD_MAXSEG2 0
#define IDC_CD_MINANG 0
#define IDC_CD_MU1LABEL 0
#define IDC_CD_MU1LABEL2 0
#define IDC_CD_MU1LABEL3 0
#define IDC_CD_MU2LABEL 0
#define IDC_CD_MU2LABEL2 0
#define IDC_CD_MU2LABEL3 0
#define IDC_CD_NODE_COND 0
#define IDC_CD_NODENAME 0
#define IDC_CD_OX 0
#define IDC_CD_OY 0
#define IDC_CD_PRC 0
#define IDC_CD_PROBNOTE 0
#define IDC_CD_PROBTYPE 0
#define IDC_CD_PTGRP 0
#define IDC_CD_Q 0
#define IDC_CD_QP 0
#define IDC_CD_QS 0
#define IDC_CD_RADIOAMP 0
#define IDC_CD_RADIOVOLT 0
#define IDC_CD_SEG_COND 0
#define IDC_CD_SEGGRP 0
#define IDC_CD_SEGHIDE 0
#define IDC_CD_SETA 0
#define IDC_CD_SETI 0
#define IDC_CD_SIDELENGTH 0
#define IDC_CD_V 0
#define IDC_CD_VBDRY 0
#define IDC_CD_VP 0
#define IDC_CDUCT 0
#define IDC_CELC 0
#define IDC_CIRCBLK 0
#define IDC_CIRCNAME 0
#define IDC_CIRCRESULT 0
#define IDC_CLEAR_INPUT 0
#define IDC_CLEAR_OUTPUT 0
#define IDC_COLORS 0
#define IDC_COMBO1 0
#define IDC_COMPILEDATE 0
#define IDC_COORD1 0
#define IDC_COORD2 0
#define IDC_COORDS 0
#define IDC_CV_AHIGH 0
#define IDC_CV_ALOW 0
#define IDC_CV_BINTTYPE 0
#define IDC_CV_CIRCNAME 0
#define IDC_CV_CIRCRESULT 0
#define IDC_CV_DFLT1 0
#define IDC_CV_DPLOTTYPE 0
#define IDC_CV_FILEFORMAT 0
#define IDC_CV_GSCALE2 0
#define IDC_CV_LB2 0
#define IDC_CV_LINTTYPE 0
#define IDC_CV_NPOINTS 0
#define IDC_CV_NUMCONTOURS 0
#define IDC_CV_RESBTN2 0
#define IDC_CV_SCALEFACTOR 0
#define IDC_CV_SHOW_A 0
#define IDC_CV_SHOW_A2 0
#define IDC_CV_SHOW_LEG2 0
#define IDC_CV_SHOW_MASK2 0
#define IDC_CV_SHOWIT 0
#define IDC_CV_TOFILE 0
#define IDC_CV_UB2 0
#define IDC_CV_VPLOTTYPE 0
#define IDC_CV_XYPLOTTYPE 0
#define IDC_DACTION 0
#define IDC_DCOLOR 0
#define IDC_DCOORD 0
#define IDC_DDEPTH 0
#define IDC_DEF_DOC 0
#define IDC_DEF_LUA_CONSOLE 0
#define IDC_DEF_SHOWOUTWND 0
#define IDC_DEF_SMARTMESH 0
#define IDC_DEF_XYPLOT 0
#define IDC_DEL_PROP 0
#define IDC_DELTAX 0
#define IDC_DELTAY 0
#define IDC_DENSITYPLOT 0
#define IDC_DFLT1 0
#define IDC_DFREQ 0
#define IDC_DGRIDSIZE 0
#define IDC_DLENGTH 0
#define IDC_DMINANGLE 0
#define IDC_DOCTYPES 0
#define IDC_DPIXELS 0
#define IDC_DPREC 0
#define IDC_DSHOWGRID 0
#define IDC_DSNAPGRID 0
#define IDC_DSOLVER 0
#define IDC_DTYPE 0
#define IDC_DXFTOL 0
#define IDC_EDIT_DEPTH 0
#define IDC_EDIT_FREQ 0
#define IDC_EDIT1 0
#define IDC_EDITACTION 0
#define IDC_EDITCURVE 0
#define IDC_EVALUATE 0
#define IDC_EX 0
#define IDC_EY 0
#define IDC_FAHR 0
#define IDC_FE_EXTERNAL 0
#define IDC_FE_ISDEFAULT 0
#define IDC_FILEFORMAT 0
#define IDC_FOLDERNAME 0
#define IDC_FOLDERURL 0
#define IDC_FOLDERVENDOR 0
#define IDC_FV_CIRCNAME 0
#define IDC_FV_MODBTN 0
#define IDC_FV_RESET 0
#define IDC_GAPINTTYPE 0
#define IDC_GAUSS 0
#define IDC_GREY 0
#define IDC_GRIDSIZE 0
#define IDC_GROUPNUMBER 0
#define IDC_H_ 0
#define IDC_H_C 0
#define IDC_H1LABEL 0
#define IDC_H2LABEL 0
#define IDC_HD_ACKBLK 0
#define IDC_HD_ACKNODE 0
#define IDC_HD_ACKSEG 0
#define IDC_HD_ARCGRP 0
#define IDC_HD_ARCHIDE 0
#define IDC_HD_ARCSEG_COND 0
#define IDC_HD_ARCSEGBDRY2 0
#define IDC_HD_AUTOMESH 0
#define IDC_HD_AUTOMESHCHECK 0
#define IDC_HD_BDRYFORMAT 0
#define IDC_HD_BDRYNAME 0
#define IDC_HD_BETA 0
#define IDC_HD_BLKGROUP 0
#define IDC_HD_BLOCKNAME 0
#define IDC_HD_CIRCNAME 0
#define IDC_HD_DT 0
#define IDC_HD_EDIT_DEPTH 0
#define IDC_HD_EX 0
#define IDC_HD_EXTERNAL 0
#define IDC_HD_EY 0
#define IDC_HD_HTC 0
#define IDC_HD_ISDEFAULT 0
#define IDC_HD_KT 0
#define IDC_HD_LENGTH_UNITS 0
#define IDC_HD_LINEMESHSIZE 0
#define IDC_HD_MAXSEG2 0
#define IDC_HD_MINANG 0
#define IDC_HD_MU1LABEL 0
#define IDC_HD_MU2LABEL 0
#define IDC_HD_NODE_COND 0
#define IDC_HD_NODENAME 0
#define IDC_HD_PRC 0
#define IDC_HD_PREVSOLN 0
#define IDC_HD_PROBNOTE 0
#define IDC_HD_PROBTYPE 0
#define IDC_HD_PTGRP 0
#define IDC_HD_Q 0
#define IDC_HD_QP 0
#define IDC_HD_QS 0
#define IDC_HD_QV 0
#define IDC_HD_RADIOAMP 0
#define IDC_HD_RADIOVOLT 0
#define IDC_HD_SEG_COND 0
#define IDC_HD_SEGGRP 0
#define IDC_HD_SEGHIDE 0
#define IDC_HD_SETA 0
#define IDC_HD_SETI 0
#define IDC_HD_SIDELENGTH 0
#define IDC_HD_TBDRY 0
#define IDC_HD_TINF1 0
#define IDC_HD_TINF2 0
#define IDC_HD_V 0
#define IDC_HD_VP 0
#define IDC_HDATA 0
#define IDC_HFIRST 0
#define IDC_HV_AHIGH 0
#define IDC_HV_ALOW 0
#define IDC_HV_BINTTYPE 0
#define IDC_HV_CIRCNAME 0
#define IDC_HV_CIRCRESULT 0
#define IDC_HV_DFLT1 0
#define IDC_HV_DPLOTTYPE 0
#define IDC_HV_FILEFORMAT 0
#define IDC_HV_GSCALE2 0
#define IDC_HV_LB2 0
#define IDC_HV_LINTTYPE 0
#define IDC_HV_NPOINTS 0
#define IDC_HV_NUMCONTOURS 0
#define IDC_HV_RESBTN2 0
#define IDC_HV_SCALEFACTOR 0
#define IDC_HV_SHOW_A 0
#define IDC_HV_SHOW_LEG2 0
#define IDC_HV_SHOW_MASK2 0
#define IDC_HV_SHOWIT 0
#define IDC_HV_TOFILE 0
#define IDC_HV_UB2 0
#define IDC_HV_VPLOTTYPE 0
#define IDC_HV_XYPLOTTYPE 0
#define IDC_INGRP 0
#define IDC_INNERANGLE 0
#define IDC_J 0
#define IDC_J_RE 0
#define IDC_JR 0
#define IDC_KAMPM 0
#define IDC_KCAL 0
#define IDC_KELV 0
#define IDC_KFIRST 0
#define IDC_KGAUSS 0
#define IDC_KOERSTED 0
#define IDC_KT 0
#define IDC_L 0
#define IDC_LABEL1 0
#define IDC_LABEL2 0
#define IDC_LAM_D 0
#define IDC_LAM_DIR 0
#define IDC_LAM_FILL 0
#define IDC_LEGEND 0
#define IDC_LENGTH_UNITS 0
#define IDC_LINEMESHSIZE 0
#define IDC_LINTTYPE 0
#define IDC_LIPOINTS 0
#define IDC_LOGPLOT_BHCURVE 0
#define IDC_LTX 0
#define IDC_LTY 0
#define IDC_LUA_INPUT 0
#define IDC_LUA_OUTPUT 0
#define IDC_M 0
#define IDC_MAGDIR 0
#define IDC_MAXSEG 0
#define IDC_MAXSEG2 0
#define IDC_MINANG 0
#define IDC_MOD_PROP 0
#define IDC_MODBTN 0
#define IDC_MU 0
#define IDC_MU_X 0
#define IDC_MU_Y 0
#define IDC_MU1LABEL 0
#define IDC_MU2LABEL 0
#define IDC_MYLIST 0
#define IDC_MYMSGBOXOUTPUT 0
#define IDC_MYTREE 0
#define IDC_NAME_LIST 0
#define IDC_NCONT 0
#define IDC_NCOPIES 0
#define IDC_NLCOMBO 0
#define IDC_NODENAME 0
#define IDC_NPOINTS 0
#define IDC_NS 0
#define IDC_NSTRANDS 0
#define IDC_NUMCONTOURS 0
#define IDC_OERSTED 0
#define IDC_ONRELOAD 0
#define IDC_OUTBOX 0
#define IDC_OUTERANGLE 0
#define IDC_OX 0
#define IDC_OY 0
#define IDC_P 0
#define IDC_PAX 0
#define IDC_PAY 0
#define IDC_PBX 0
#define IDC_PBY 0
#define IDC_PHI 0
#define IDC_PLOT_BHCURVE 0
#define IDC_PLOTPOINTS 0
#define IDC_PRC 0
#define IDC_PREVSOLN 0
#define IDC_PREVTYPE 0
#define IDC_PROBNOTE 0
#define IDC_PROBTYPE 0
#define IDC_PROGRESS1 0
#define IDC_PTGRP 0
#define IDC_QS 0
#define IDC_QV 0
#define IDC_RADIOAMP 0
#define IDC_RADIOVOLT 0
#define IDC_RANK 0
#define IDC_READ_BHCURVE 0
#define IDC_RESTORE 0
#define IDC_RI 0
#define IDC_RO 0
#define IDC_ROTATE 0
#define IDC_S 0
#define IDC_SCALEFACTOR 0
#define IDC_SCRBOTTOM 0
#define IDC_SCRLEFT 0
#define IDC_SCRRIGHT 0
#define IDC_SCRTOP 0
#define IDC_SEGGRP 0
#define IDC_SEGHIDE 0
#define IDC_SETA 0
#define IDC_SETI 0
#define IDC_SHIFTANGLE 0
#define IDC_SHIFTH 0
#define IDC_SHOW_A 0
#define IDC_SHOW_A_IM 0
#define IDC_SHOW_A_RE 0
#define IDC_SHOW_MASK1 0
#define IDC_SHOW_MASK2 0
#define IDC_SHOW_ORIGIN 0
#define IDC_SHOWGRID 0
#define IDC_SHOWIMAGINARY 0
#define IDC_SHOWMASK 0
#define IDC_SHOWMESH 0
#define IDC_SHOWNAMES 0
#define IDC_SHOWNAMEZ 0
#define IDC_SHOWPTS 0
#define IDC_SHOWREAL 0
#define IDC_SIDELENGTH 0
#define IDC_SIGMA 0
#define IDC_SMOOTHING 0
#define IDC_SNAPGRID 0
#define IDC_SOLVER 0
#define IDC_STATIC_SYMB1 0
#define IDC_STATIC_SYMB2 0
#define IDC_STATIC_SYMB3 0
#define IDC_STATIC_SYMBOL1 0
#define IDC_STATIC_SYMBOL2 0
#define IDC_STATIC_SYMBOL3 0
#define IDC_STATIC_SYMBOL4 0
#define IDC_STATIC_SYMBOL5 0
#define IDC_STATIC_SYMBOL6 0
#define IDC_STATIC_SYMBOL7 0
#define IDC_STATIC_SYMBOL8 0
#define IDC_T 0
#define IDC_TAB1 0
#define IDC_TESLA 0
#define IDC_TFIRST 0
#define IDC_THETA_H 0
#define IDC_THETA_HX 0
#define IDC_THETA_HY 0
#define IDC_TOFILE 0
#define IDC_TOTCURRENT_RE 0
#define IDC_TRANSLATE 0
#define IDC_TURNS 0
#define IDC_VBDRY 0
#define IDC_VECTORPLOT 0
#define IDC_VPLOT_SCALE 0
#define IDC_VPLOTTYPE 0
#define IDC_W 0
#define IDC_WIRED 0
#define IDC_WMK 0
#define IDC_WST 0
#define IDC_XYPLOTTYPE 0
#define IDC_ZO 0
#define IDD_ABOUTBOX 0
#define IDD_ARCDLG 0
#define IDD_BD_BDRYDLG 0
#define IDD_BD_CIRCPROP 0
#define IDD_BD_MATDLG 0
#define IDD_BD_NODEPROP 0
#define IDD_BD_OPARCSEGDLG 0
#define IDD_BD_OPBLKDLG 0
#define IDD_BD_OPNODEDLG 0
#define IDD_BD_OPSEGDLG 0
#define IDD_BD_PREF 0
#define IDD_BD_PROBDLG 0
#define IDD_BDRYDLG 0
#define IDD_BENDCONTOUR 0
#define IDD_BHCURVE 0
#define IDD_BHDATAFILE 0
#define IDD_BLOCKINT 0
#define IDD_BV_BLOCKINT 0
#define IDD_BV_CIRCPROPS 0
#define IDD_BV_CPLOTDLG2 0
#define IDD_BV_DPLOTDLG2 0
#define IDD_BV_LINEINT 0
#define IDD_BV_PREF 0
#define IDD_BV_VPLOTDLG 0
#define IDD_BV_XYPLOTDLG 0
#define IDD_CD_BDRYDLG 0
#define IDD_CD_CIRCPROP 0
#define IDD_CD_MATDLG 0
#define IDD_CD_NODEPROP 0
#define IDD_CD_OPARCSEGDLG 0
#define IDD_CD_OPBLKDLG 0
#define IDD_CD_OPNODEDLG 0
#define IDD_CD_OPSEGDLG 0
#define IDD_CD_PREF 0
#define IDD_CD_PROBDLG 0
#define IDD_CIRCPROP 0
#define IDD_CIRCPROPS 0
#define IDD_COPYDLG 0
#define IDD_CPLOTDLG 0
#define IDD_CPLOTDLG2 0
#define IDD_CV_BLOCKINT 0
#define IDD_CV_CIRCPROPS 0
#define IDD_CV_CPLOTDLG2 0
#define IDD_CV_DPLOTDLG2 0
#define IDD_CV_LINEINT 0
#define IDD_CV_PREF 0
#define IDD_CV_VPLOTDLG 0
#define IDD_CV_XYPLOTDLG 0
#define IDD_DXFIMPORT 0
#define IDD_EDITPREF 0
#define IDD_ENTERPT 0
#define IDD_EXTERIORPROPS 0
#define IDD_GAPINTEGRAL 0
#define IDD_GAPPLOTDLG 0
#define IDD_GENPREFS 0
#define IDD_GRIDMOD 0
#define IDD_GROUPNO 0
#define IDD_HD_BDRYDLG 0
#define IDD_HD_CIRCPROP 0
#define IDD_HD_MATDLG 0
#define IDD_HD_NODEPROP 0
#define IDD_HD_OPARCSEGDLG 0
#define IDD_HD_OPBLKDLG 0
#define IDD_HD_OPNODEDLG 0
#define IDD_HD_OPSEGDLG 0
#define IDD_HD_PREF 0
#define IDD_HD_PROBDLG 0
#define IDD_HV_BLOCKINT 0
#define IDD_HV_CIRCPROPS 0
#define IDD_HV_CPLOTDLG2 0
#define IDD_HV_DPLOTDLG2 0
#define IDD_HV_LINEINT 0
#define IDD_HV_PREF 0
#define IDD_HV_VPLOTDLG 0
#define IDD_HV_XYPLOTDLG 0
#define IDD_KBDZOOM 0
#define IDD_KCURVE 0
#define IDD_LIBFOLDERINFO 0
#define IDD_LINEINT 0
#define IDD_LUACONSOLE 0
#define IDD_MAKE_ABC 0
#define IDD_MASKPROGRESS 0
#define IDD_MATDLG 0
#define IDD_MIRRORDLG 0
#define IDD_MYMSGBOX 0
#define IDD_NEWDOC 0
#define IDD_NODEPROP 0
#define IDD_OPARCSEGDLG 0
#define IDD_OPBLKDLG 0
#define IDD_OPGRPDLG 0
#define IDD_OPNODEDLG 0
#define IDD_OPSEGDLG 0
#define IDD_OUTBOX 0
#define IDD_PREFERENCES 0
#define IDD_PROBDLG 0
#define IDD_PROMPTBOX 0
#define IDD_PTPROP 0
#define IDD_SCALE 0
#define IDD_TKDATAFILE 0
#define IDD_TREETEST_DIALOG 0
#define IDD_VIEWPREF 0
#define IDD_VPLOTDLG 0
#define IDD_XYPLOTDLG 0
#define IDR_BELADRAWTYPE 0
#define IDR_BELAVIEWTYPE 0
#define IDR_CDRAWTYPE 0
#define IDR_CVIEWTYPE 0
#define IDR_FEMMETYPE 0
#define IDR_FEMMPLOTTYPE 0
#define IDR_FEMMVIEWTYPE 0
#define IDR_HDRAWTYPE 0
#define IDR_HVIEWTYPE 0
#define IDR_LEFTBAR 0
#define IDR_MAIN1 0
#define IDR_MAIN2 0
#define IDR_MAINFRAME 0

3
compat/malloc.h Normal file
View File

@ -0,0 +1,3 @@
// forwards malloc.h to stdlib.h.
#pragma once
#include <stdlib.h>

8
compat/resource.h Normal file
View File

@ -0,0 +1,8 @@
// stand-in for the deleted MFC resource header.
#pragma once
#define IDC_FRAME1 0
#define IDC_FRAME2 0
#define IDC_FRAME3 0
#include "femm_resource_ids.h"

4
csolv/CSOLV.H Normal file
View File

@ -0,0 +1,4 @@
// solver entry point.
#pragma once
void old_main(void *inptr);

96
csolv/CSOLVDLG.CPP Normal file
View File

@ -0,0 +1,96 @@
// csolvDlg.cpp : implementation file
//
#include "stdafx.h"
#include "csolv.h"
#include "csolvDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CcsolvDlg dialog
CcsolvDlg::CcsolvDlg(CWnd* pParent /*=NULL*/)
: CDialog(CcsolvDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CcsolvDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CcsolvDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CcsolvDlg)
DDX_Control(pDX, IDC_PROGRESS1, m_prog1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CcsolvDlg, CDialog)
//{{AFX_MSG_MAP(CcsolvDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CcsolvDlg message handlers
BOOL CcsolvDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return FALSE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CcsolvDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CcsolvDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CcsolvDlg::OnOK()
{
}

20
csolv/CSOLVDLG.H Normal file
View File

@ -0,0 +1,20 @@
// MFC-free CcsolvDlg with empty progress, label, and window-update calls.
#pragma once
#include <string>
struct CProgressStub { void SetPos(int) {} };
class CcsolvDlg {
public:
CProgressStub m_prog1;
CProgressStub m_prog2;
void* m_hWnd = nullptr;
std::string ComLine;
void SetDlgItemText(int, const char*) {}
void SetWindowText(const char*) {}
void UpdateWindow() {}
int InvalidateRect(void* = nullptr, int = 1) { return 1; }
};
extern CcsolvDlg* TheView;

267
csolv/CUTHILL.CPP Normal file
View File

@ -0,0 +1,267 @@
// does Cuthill-McKee algorithm as described in Hoole;
#include<stdafx.h>
#include<afxtempl.h>
#include<stdio.h>
#include<math.h>
#include "complex.h"
#include "csolv.h"
#include "csolvDlg.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"
#define muo 1.2566370614359173e-6
BOOL CFemmeDocCore::SortElements()
{
// Comb Sort -- see http://en.wikipedia.org/wiki/Comb_sort
int *Score;
int i,j,k,gap;
CElement e;
Score=(int*)calloc(NumEls,sizeof(int));
for(k=0;k<NumEls;k++)
{
Score[k]=meshele[k].p[0]+meshele[k].p[1]+meshele[k].p[2];
}
gap = NumEls;
do{
//update the gap value for a next comb
if (gap > 1)
{
gap=(gap*10)/13;
if ((gap==10) || (gap==9)) gap=11;
}
//a single "comb" over the input list
for(j=0,i=0;(j+gap)<NumEls;j++)
{
if (Score[j]>Score[j+gap])
{
k=j+gap;
i=Score[k];Score[k]=Score[j];Score[j]=i;
e=meshele[k];meshele[k]=meshele[j];meshele[j]=e;
i=1;
}
}
}while((gap>1)&&(i>0));
free(Score);
return TRUE;
}
BOOL CFemmeDocCore::Cuthill()
{
FILE *fp;
int i,j,k,n0,n1,n;
int newwide,*newnum,**ocon;
int *numcon,*nxtnum;
CNode swap;
char infile[256];
// allocate storage
nxtnum=(int *)calloc(NumNodes,sizeof(int));
newnum=(int *)calloc(NumNodes,sizeof(int));
numcon=(int *)calloc(NumNodes,sizeof(int));
ocon=(int **)calloc(NumNodes,sizeof(int *));
// initialize node array;
for(i=0;i<NumNodes;i++) newnum[i]= -1;
// read in connectivity from nodefile
sprintf(infile,"%s.edge",PathName);
if((fp=fopen(infile,"rt"))==NULL)
{
fprintf(stderr,"Couldn't open %s",infile);
return FALSE;
}
fscanf(fp,"%i",&k); // read in number of lines
fscanf(fp,"%i",&j); // read in boundarymarker flag;
// allocate space for connections;
ocon[0]=(int *)calloc(2*k,sizeof(int));
// with first pass, figure out how many connections
// there are for each node;
for(i=0;i<k;i++)
{
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&n0);
fscanf(fp,"%i",&n1);
fscanf(fp,"%i",&j);
numcon[n0]++;
numcon[n1]++;
}
// mete out connection storage space;
for(i=1,n=0;i<NumNodes;i++)
{
n+=numcon[i-1];
ocon[i]=ocon[0]+n;
}
// on second pass through file, store connections;
rewind(fp);
fscanf(fp,"%li",&k); // read in number of lines
fscanf(fp,"%li",&j); // read in boundarymarker flag;
for(i=0;i<k;i++)
{
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&n0);
fscanf(fp,"%i",&n1);
fscanf(fp,"%i",&j);
ocon[n0][nxtnum[n0]]=n1; nxtnum[n0]++;
ocon[n1][nxtnum[n1]]=n0; nxtnum[n1]++;
}
fclose(fp);
DeleteFile(infile);
// sort connections in order of increasing connectivity;
// I'm lazy, so I'm doing a bubble sort;
for(n0=0;n0<NumNodes;n0++)
{
for(i=1;i<numcon[n0];i++)
for(j=1;j<numcon[n0];j++)
if(numcon[ocon[n0][j]]<numcon[ocon[n0][j-1]])
{
n1=ocon[n0][j];
ocon[n0][j]=ocon[n0][j-1];
ocon[n0][j-1]=n1;
}
}
// search for a node to start with;
j=numcon[0]; n0=0;
for(i=1;i<NumNodes;i++){
if(numcon[i]<j){
j=numcon[i];
n0=i;
}
if(j==2) i=k; // break out if j==2,
// because this is the best we can do
}
// do renumbering algorithm;
for(i=0;i<NumNodes;i++) nxtnum[i]=-1;
newnum[n0]=0; n=1; nxtnum[0]=n0;
do{
// renumber in order of increasing number of connections;
for(i=0;i<numcon[n0];i++)
{
if (newnum[ocon[n0][i]]<0)
{
newnum[ocon[n0][i]]=n;
nxtnum[n]=ocon[n0][i];
n++;
}
}
// need to catch case in which problem is multiply
// connected and still renumber right.
if(nxtnum[newnum[n0]+1]<0){
// MsgBox("Multiply Connected!");
// exit(0);
// first, get a node that hasn't been visited yet;
for(i=0;i<NumNodes;i++)
if(newnum[i]<0){
j=numcon[i];
n0=i;
i=NumNodes;
}
// now, get a new starting node;
for(i=0;i<NumNodes;i++)
{
if((newnum[i]<0) && (numcon[i]<j))
{
j=numcon[i];
n0=i;
}
if(j==2) i=NumNodes; // break out if j==2,
// because this is the
// best we can do
}
// now, set things to restart;
newnum[n0]=n;
nxtnum[n]=n0;
n++;
}
else n0=nxtnum[newnum[n0]+1];
} while(n<NumNodes);
// remap connectivities;
for(i=0;i<NumNodes;i++)
for(j=0;j<numcon[i];j++)
ocon[i][j]=newnum[ocon[i][j]];
// remap (anti)periodic boundary points
for(i=0;i<NumPBCs;i++)
{
pbclist[i].x=newnum[pbclist[i].x];
pbclist[i].y=newnum[pbclist[i].y];
}
// find new bandwidth;
// PBCs fuck up the banding, som could have to do
// something like:
// if(NumPBCs!=0) BandWidth=0;
// else{
// but if we apply the PCBs the last thing before the
// solver is called, we can take advantage of banding
// speed optimizations without messing things up.
for(n0=0,newwide=0;n0<NumNodes;n0++)
{
for(i=0;i<numcon[n0];i++)
if(abs(newnum[n0]-ocon[n0][i])>newwide)
{
newwide=abs(newnum[n0]-ocon[n0][i]);
}
}
BandWidth=newwide+1;
// }
// free up the variables that we needed during the routine....
free(numcon);
free(nxtnum);
free(ocon[0]);
free(ocon);
// new mapping remains in newnum;
// apply this mapping to elements first.
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
meshele[i].p[j]=newnum[meshele[i].p[j]];
// now, sort nodes based on newnum;
for(i=0;i<NumNodes;i++)
while(newnum[i]!=i)
{
j=newnum[i];
n=newnum[j]; newnum[j]=newnum[i]; newnum[i]=n;
swap=meshnode[j]; meshnode[j]=meshnode[i]; meshnode[i]=swap;
}
free(newnum);
SortElements();
return TRUE;
}

129
csolv/MAIN.CPP Normal file
View File

@ -0,0 +1,129 @@
#include<stdafx.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<afxtempl.h>
#include "complex.h"
#include "csolv.h"
#include "csolvDlg.h"
#include "spars.h"
#include "mesh.h"
#include "FemmeDocCore.h"
void old_main(void *inptr)
{
CcsolvDlg *TheView;
CFemmeDocCore Doc;
char PathName[256];
CFileDialog *fname_dia;
char outstr[1024];
int i;
TheView=(CcsolvDlg *) inptr;
// get the name of the file to be processed,
// either from argv or from the user
if (__argc<2){
fname_dia=new CFileDialog(
TRUE,
"fem | * ",
NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"cview datafile (*.fec) | *.fec; *.FEC | All Files (*.*) | *.*||",
NULL);
if(fname_dia->DoModal()==IDCANCEL){
delete[] fname_dia;
MsgBox("No file name!");
exit(0);
}
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;
// load problem geometry
if (Doc.OnOpenDocument()!=TRUE){
MsgBox("problem loading input file");
exit(7);
}
// load mesh
if (Doc.LoadMesh()!=TRUE){
MsgBox("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 - csolve",ProbName);
}
while(!IsWindow(TheView->m_hWnd)) Sleep(1);
TheView->SetWindowText(PaneText);
// renumber using Cuthill-McKee
TheView->SetDlgItemText(IDC_STATUSWINDOW,"renumbering nodes");
if (Doc.Cuthill()!=TRUE){
MsgBox("problem renumbering nodes");
exit(3);
}
// display details about the problem to be solved
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);
// initialize the problem, allocating the space required to solve it.
CBigComplexLinProb L;
L.TheView=TheView;
L.Precision=Doc.Precision;
if (L.Create(Doc.NumNodes+Doc.NumCircProps,Doc.BandWidth,Doc.NumNodes)==FALSE){
MsgBox("couldn't allocate enough space for matrices");
Doc.CleanUp();
L.~CBigComplexLinProb();
exit(4);
}
// Create element matrices and solve the problem;
if (Doc.AnalyzeProblem(L)==FALSE)
{
MsgBox("Couldn't solve the problem");
Doc.CleanUp();
L.~CBigComplexLinProb();
exit(5);
}
TheView->SetDlgItemText(IDC_STATUSWINDOW,"Problem solved");
// now that we have results, write 'em to dist
if (Doc.WriteResults(L)==FALSE)
{
MsgBox("couldn't write results to disk");
Doc.CleanUp();
L.~CBigComplexLinProb();
exit(6);
}
TheView->SetDlgItemText(IDC_STATUSWINDOW,"results written to disk");
// make sure that everything is freed up to avoid memory leaks
Doc.CleanUp();
L.~CBigComplexLinProb();
exit(0);
}

101
csolv/MESH.H Normal file
View File

@ -0,0 +1,101 @@
#define PI 3.141592653589793238462643383
#define eo 8.85418781762e-12
#define AXISYMMETRIC 1
#define PLANAR 0
class CNode
{
public:
double x,y;
int bc;
int InConductor;
private:
};
class CElement
{
public:
int p[3]; // nodes at the corners of the element
int e[3]; // boundary condition applied to each edge of the element
int blk; // block property applied to the element
int lbl; // block label associated with the element
private:
};
class CBlockLabel
{
public:
double x,y;
double MaxArea;
int BlockType,InGroup;
BOOL IsExternal;
BOOL IsDefault;
private:
};
class CCommonPoint
{
public:
int x,y,t;
private:
};
/////////////////////////////////////////////////////////////////////////////
// Classes that hold property data: CMaterialProp, CBoundaryProp, CPointProp
class CMaterialProp
{
public:
CComplex ex,ey; // permittivity, relative
double ox,oy; // conductivity
CComplex kx,ky;
private:
};
class CBoundaryProp
{
public:
int BdryFormat; // type of boundary condition we are applying
// 0 = fixed voltage
// 1 = mixed BC
// 2 = surface charge
// 3 = periodic
// 4 = antiperiodic
CComplex V; // set value of V for BdryFormat=0;
CComplex qs; // surface current density
CComplex c0,c1; // coefficients for mixed BC
private:
};
class CPointProp
{
public:
CComplex V; // fixed nodal voltage
CComplex qp; // point current density;
private:
};
class CCircuit
{
public:
CComplex V,q;
int CircType;
private:
};

378
csolv/PROB1BIG.CPP Normal file
View File

@ -0,0 +1,378 @@
#include<stdafx.h>
#include<stdio.h>
#include<math.h>
#include "complex.h"
#include "csolv.h"
#include "csolvDlg.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"
//conversion to internal working units of mm
double units[]={25.4,1.,10.,1000.,0.0254,0.001};
double sq(double x){ return x*x; }
BOOL CFemmeDocCore::AnalyzeProblem(CBigComplexLinProb &L)
{
int i,j,k,pctr=0;
CComplex Me[3][3],be[3]; // element matrices;
double l[3],p[3],q[3]; // element shape parameters;
int n[3],ne[3]; // numbers of nodes for a particular element;
double a,r,z,kludge;
CComplex K;
CElement *El;
double c = (1.e-6)/eo;
Depth*=units[LengthUnits];
extRo*=units[LengthUnits];
extRi*=units[LengthUnits];
extZo*=units[LengthUnits];
kludge=1;
TheView->SetDlgItemText(IDC_FRAME1,"Matrix Construction");
// do some book-keeping related to fixed boundary conditions;
// The P vector denotes which nodes have an assigned value
// The V vector denotes the assigned value
for(i=0;i<NumNodes;i++)
{
L.Q[i]=-2;
if(meshnode[i].bc >=0)
if(nodeproplist[meshnode[i].bc].qp==0)
{
L.V[i]=nodeproplist[meshnode[i].bc].V;
L.Q[i]=-1;
}
if(meshnode[i].InConductor>=0)
if(circproplist[meshnode[i].InConductor].CircType==1)
{
L.V[i]=circproplist[meshnode[i].InConductor].V;
L.Q[i]=meshnode[i].InConductor;
}
}
// account for fixed boundary conditions along segments;
for(i=0;i<NumEls;i++)
{
for(j=0;j<3;j++){
k=j+1; if(k==3) k=0;
if(meshele[i].e[j]>=0)
{
if(lineproplist[ meshele[i].e[j] ].BdryFormat==0)
{
L.V[meshele[i].p[j]]=lineproplist[meshele[i].e[j]].V;
L.V[meshele[i].p[k]]=lineproplist[meshele[i].e[j]].V;
L.Q[meshele[i].p[j]]=-1;
L.Q[meshele[i].p[k]]=-1;
}
}
}
}
// build element matrices using the matrices derived in Allaire's book.
for(i=0;i<NumEls;i++)
{
// update progress bar
j=5*((i*20)/NumEls);
if(j!=pctr){ pctr=j; TheView->m_prog1.SetPos(pctr); }
// zero out Me, be;
for(j=0;j<3;j++){
for(k=0;k<3;k++) Me[j][k]=0;
be[j]=0;
}
// Determine shape parameters.
// l's are element side lengths;
// p's corresponds to the `b' parameter in Allaire
// q's corresponds to the `c' parameter in Allaire
El=&meshele[i];
for(k=0;k<3;k++) n[k]=El->p[k];
p[0]=meshnode[n[1]].y - meshnode[n[2]].y;
p[1]=meshnode[n[2]].y - meshnode[n[0]].y;
p[2]=meshnode[n[0]].y - meshnode[n[1]].y;
q[0]=meshnode[n[2]].x - meshnode[n[1]].x;
q[1]=meshnode[n[0]].x - meshnode[n[2]].x;
q[2]=meshnode[n[1]].x - meshnode[n[0]].x;
for(j=0,k=1;j<3;k++,j++){
if (k==3) k=0;
l[j]=sqrt( sq(meshnode[n[k]].x-meshnode[n[j]].x) +
sq(meshnode[n[k]].y-meshnode[n[j]].y) );
}
a=(p[0]*q[1]-p[1]*q[0])/2.;
r=(meshnode[n[0]].x+meshnode[n[1]].x+meshnode[n[2]].x)/3.;
if (ProblemType==AXISYMMETRIC){
Depth=2.*PI*r;
// "Warp" the permeability of this element is part of
// the conformally mapped external region
if(labellist[meshele[i].lbl].IsExternal)
{
z=(meshnode[n[0]].y+meshnode[n[1]].y+meshnode[n[2]].y)/3. - extZo;
kludge=(r*r+z*z)/(extRi*extRo);
}
else kludge=1;
}
// x-contribution;
K = -Depth*blockproplist[El->blk].kx/(4.*a)/kludge;
for(j=0;j<3;j++)
for(k=j;k<3;k++)
{
Me[j][k] += K*p[j]*p[k];
if (j!=k) Me[k][j]+=K*p[j]*p[k];
}
// y-contribution;
K = -Depth*blockproplist[El->blk].ky/(4.*a)/kludge;
for(j=0;j<3;j++)
for(k=j;k<3;k++)
{
Me[j][k] +=K*q[j]*q[k];
if (j!=k) Me[k][j]+=K*q[j]*q[k];
}
for(j=0;j<3;j++)
{
if (El->e[j] >= 0)
{
k=j+1; if(k==3) k=0;
if (ProblemType==AXISYMMETRIC)
Depth=PI*(meshnode[n[j]].x + meshnode[n[k]].x);
// contributions to Me, be from derivative boundary conditions;
if (lineproplist[El->e[j]].BdryFormat==1)
{
K =-1000.*Depth*c*lineproplist[El->e[j]].c0*l[j]/6.;
Me[j][j]+=K*2.;
Me[k][k]+=K*2.;
Me[j][k]+=K;
Me[k][j]+=K;
K = 1000.*Depth*c*lineproplist[El->e[j]].c1*l[j]/2.;
be[j]+=K;
be[k]+=K;
}
// contribution to be[] from surface charge density;
if (lineproplist[El->e[j]].BdryFormat==2)
{
K =-1000.*Depth*c*lineproplist[El->e[j]].qs*l[j]/2.;
be[j]+=K;
be[k]+=K;
}
}
}
// process any prescribed nodal values;
for(j=0;j<3;j++)
{
if(L.Q[n[j]]!=-2)
{
for(k=0;k<3;k++)
{
if(j!=k){
be[k]-=Me[k][j]*L.V[n[j]];
Me[k][j]=0;
Me[j][k]=0;
}
}
be[j]=L.V[n[j]]*Me[j][j];
}
}
// combine block matrices into global matrices;
for (j=0;j<3;j++)
{
ne[j]=n[j];
if(meshnode[n[j]].InConductor>=0)
if(circproplist[meshnode[n[j]].InConductor].CircType==0)
ne[j]=meshnode[n[j]].InConductor+NumNodes;
}
for (j=0;j<3;j++){
for (k=j;k<3;k++)
L.Put(L.Get(ne[j],ne[k])-Me[j][k],ne[j],ne[k]);
L.b[ne[j]]-=be[j];
if(ne[j]!=n[j])
{
L.Put(L.Get(n[j],n[j])-Me[j][j],n[j],n[j]);
L.Put(L.Get(n[j],ne[j])+Me[j][j],n[j],ne[j]);
}
}
} // end of loop that builds element matrices
// add in contribution from point charge density;
for(i=0;i<NumNodes;i++)
{
if((meshnode[i].bc>=0) && (L.Q[i]==-2))
{
if (ProblemType==AXISYMMETRIC) Depth=2.*PI*meshnode[i].x;
L.b[i]+=((1.e6)*Depth*c*nodeproplist[meshnode[i].bc].qp);
L.Q[i]=-1;
}
// some bookkeeping to denote which nodes we can smooth over
if(meshnode[i].InConductor>=0) L.Q[i]=meshnode[i].InConductor;
}
// Apply any periodicity/antiperiodicity boundary conditions that we have
for(k=0,pctr=0;k<NumPBCs;k++)
{
if (pbclist[k].t==0) L.Periodicity(pbclist[k].x,pbclist[k].y);
if (pbclist[k].t==1) L.AntiPeriodicity(pbclist[k].x,pbclist[k].y);
}
// Finish building the equations that assign conductor voltage;
for(i=0;i<NumCircProps;i++)
{
// put a placeholder on the main diagonal;
k=NumNodes+i;
if (circproplist[i].CircType==1)
{
K=L.Get(0,0);
L.Put(K,k,k);
L.b[k]=K*circproplist[i].V;
}
if(circproplist[i].CircType==0)
{
for(j=0,K=0;j<L.n;j++) if(j!=k) K+=L.Get(k,j);
if(K!=0){
L.Put(-K,k,k);
L.b[k]=(1.e9)*c*circproplist[i].q;
}
else L.Put(L.Get(0,0),k,k);
}
}
// solve the problem;
if (L.PBCGSolveMod(FALSE)==FALSE) return FALSE;
// compute total charge on conductors
// with a specified voltage
for(i=0;i<NumCircProps;i++)
if(circproplist[i].CircType==1)
circproplist[i].q=ChargeOnConductor(i,L);
return TRUE;
}
//=========================================================================
//=========================================================================
BOOL CFemmeDocCore::WriteResults(CBigComplexLinProb &L)
{
// write solution to disk;
char c[1024];
FILE *fp,*fz;
int i;
double cf;
// first, echo input .fec file to the .res file;
sprintf(c,"%s.fec",PathName);
if((fz=fopen(c,"rt"))==NULL){
Sleep(500);
if((fz=fopen(c,"rt"))==NULL){
fprintf(stderr,"Couldn't open %s.fec\n",PathName);
return FALSE;
}
}
sprintf(c,"%s.anc",PathName);
if((fp=fopen(c,"wt"))==NULL){
Sleep(500);
if((fp=fopen(c,"wt"))==NULL){
fprintf(stderr,"Couldn't write to %s.anc\n",PathName);
return FALSE;
}
}
while(fgets(c,1024,fz)!=NULL) fputs(c,fp);
fclose(fz);
// then print out node, line, and element information
fprintf(fp,"[Solution]\n");
cf=units[LengthUnits];
fprintf(fp,"%i\n",NumNodes);
for(i=0;i<NumNodes;i++)
fprintf(fp,"%.17g %.17g %.17g %.17g %i\n",meshnode[i].x/cf,meshnode[i].y/cf,Re(L.V[i]),Im(L.V[i]),L.Q[i]);
fprintf(fp,"%i\n",NumEls);
for(i=0;i<NumEls;i++)
fprintf(fp,"%i %i %i %i\n",
meshele[i].p[0],meshele[i].p[1],meshele[i].p[2],meshele[i].lbl);
// print out circuit info
fprintf(fp,"%i\n",NumCircProps);
for(i=0;i<NumCircProps;i++)
fprintf(fp,"%.17g %.17g %.17g %.17g\n",
Re(L.V[NumNodes+i]),Im(L.V[NumNodes+i]),Re(circproplist[i].q),Im(circproplist[i].q));
fclose(fp);
return TRUE;
}
//=========================================================================
//=========================================================================
CComplex CFemmeDocCore::ChargeOnConductor(int u, CBigComplexLinProb &L)
{
int i,k;
double b[3],c[3]; // element shape parameters;
int n[3]; // numbers of nodes for a particular element;
double a,da;
CComplex Dx,Dy,vx,vy,Z;
double LengthConv=0.001;
for(i=0;i<NumNodes;i++)
if(meshnode[i].InConductor==u) L.P[i]=1;
else L.P[i]=0;
// build element matrices using the matrices derived in Allaire's book.
for(i=0,Z=0;i<NumEls;i++)
{
for(k=0;k<3;k++) n[k]=meshele[i].p[k];
if((L.P[n[0]]!=0) || (L.P[n[1]]!=0) || (L.P[n[2]]!=0))
{
// Determine shape parameters.
b[0]=meshnode[n[1]].y - meshnode[n[2]].y;
b[1]=meshnode[n[2]].y - meshnode[n[0]].y;
b[2]=meshnode[n[0]].y - meshnode[n[1]].y;
c[0]=meshnode[n[2]].x - meshnode[n[1]].x;
c[1]=meshnode[n[0]].x - meshnode[n[2]].x;
c[2]=meshnode[n[1]].x - meshnode[n[0]].x;
da=(b[0]*c[1]-b[1]*c[0]);
a=da*LengthConv*LengthConv/2.;
if (ProblemType==AXISYMMETRIC)
a*=(2.*PI*LengthConv*(meshnode[n[0]].x+meshnode[n[1]].x+meshnode[n[2]].x)/3.);
else a*=(Depth*LengthConv);
// get normal vector and element flux density;
for(k=0,vx=0,vy=0,Dx=0,Dy=0;k<3;k++)
{
vx-=(L.P[n[k]]*b[k])/(da*LengthConv);
vy-=(L.P[n[k]]*c[k])/(da*LengthConv);
Dx-=(L.V[n[k]]*b[k])/(da*LengthConv);
Dy-=(L.V[n[k]]*c[k])/(da*LengthConv);
}
Dx*=(eo*blockproplist[meshele[i].blk].kx);
Dy*=(eo*blockproplist[meshele[i].blk].ky);
Z+=a*(Dx*vx+Dy*vy);
}
}
return Z;
}

64
csolv/SPARS.H Normal file
View File

@ -0,0 +1,64 @@
/////////////////////////////////////////////////////////////////////
// for complex matrices......
class CComplexEntry
{
public:
CComplex x; // value stored in the entry
int c; // column that the entry lives in
CComplexEntry *next; // pointer to next entry in the row;
CComplexEntry();
private:
};
class CBigComplexLinProb
{
public:
// data members
BOOL *Q;
CComplex *P;
CComplex *U;
CComplex *R;
CComplex *V;
CComplex *Z;
CComplex *b; // RHS of linear equation
CComplexEntry **M; // pointer to list of matrix entries;
int n; // dimensions of the matrix;
int bdw; // optional bandwidth parameter;
int NumNodes;
double Precision;
CComplex Lambda;
// member functions
CBigComplexLinProb(); // constructor
~CBigComplexLinProb(); // destructor
int Create(int d, int bw, int nodes); // initialize the problem
void Put(CComplex v, int p, int q);
// use to create/set entries in the matrix
CComplex Get(int p, int q);
int PBCGSolve(int flag); // flag==true if guess for V present;
int QMRSolve(int flag);
void MultA(CComplex *X, CComplex *Y);
void MultConjA(CComplex *X, CComplex *Y);
CComplex Dot(CComplex *x, CComplex *y);
CComplex ConjDot(CComplex *x, CComplex *y);
void SetValue(int i, CComplex x);
void Periodicity(int i, int j);
void AntiPeriodicity(int i, int j);
void Wipe();
void MultPC(CComplex *X, CComplex *Y);
void MultAPPA(CComplex *X, CComplex *Y);
int PCGSQSolve(int flag);
int PCGSQStart(int flag);
int PBCGSolveMod(int flag);
CcsolvDlg *TheView;
private:
};

8
csolv/StdAfx.h Normal file
View File

@ -0,0 +1,8 @@
// stdafx.h: portable shim pulling in compat/afx.h for BOOL, CString, and stdlib basics.
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <afx.h>
int MsgBox(const char* sz, ...);
int MsgBox(const std::string& s);

624
csolv/complex.cpp Normal file
View File

@ -0,0 +1,624 @@
#include <stdafx.h>
#include "math.h"
#include "stdio.h"
#include "complex.h"
CComplex::CComplex(double x)
{
re=x; im=0.;
}
CComplex::CComplex(int x)
{
re=(double) x;
im=0.;
}
CComplex::CComplex()
{
re=0.; im=0.;
}
CComplex::CComplex(double x, double y)
{
re=x; im=y;
}
CComplex CComplex::Sqrt()
{
double w,z;
CComplex y;
if((re==0) && (im==0)) w=0;
else if(fabs(re)>fabs(im)){
z=im/re;
w=sqrt(fabs(re))*sqrt( (1.+sqrt(1.+z*z))/2. );
}
else{
z=re/im;
w=sqrt(fabs(im))*sqrt( (fabs(z)+sqrt(1.+z*z))/2. );
}
if(w==0){
y.re=0;
y.im=0;
return y;
}
if(re>=0){
y.re=w;
y.im=im/(2.*w);
return y;
}
if(im>=0){
y.re=fabs(im)/(2.*w);
y.im=w;
return y;
}
y.re=fabs(im)/(2.*w);
y.im= (-w);
return y;
}
CComplex CComplex::Conj()
{
return CComplex(re,-im);
}
double CComplex::Abs()
{
if ((re==0) && (im==0)) return 0.;
if (fabs(re)>fabs(im))
return fabs(re)*sqrt(1.+(im/re)*(im/re));
else
return fabs(im)*sqrt(1.+(re/im)*(re/im));
}
double CComplex::Arg()
{
if ((re==0) && (im==0)) return 0.;
return atan2(im,re);
}
CComplex CComplex::Inv()
{
double c;
CComplex z;
if(fabs(re)>fabs(im))
{
c=im/re;
z.re=1./(re*(1.+c*c));
z.im=(-c)*z.re;
}
else{
c=re/im;
z.im=(-1.)/(im*(1.+c*c));
z.re=(-c)*z.im;
}
return z;
}
double CComplex::Re()
{
return re;
}
double CComplex::Im()
{
return im;
}
void CComplex::Set(double x, double y)
{
re=x; im=y;
}
char* CComplex::ToString(char *s)
{
if (im<0)
sprintf(s,"%.3e - j %.3e",re,fabs(im));
else
sprintf(s,"%.3e + j %.3e",re,im);
return s;
}
//******* Addition ***************************************************
CComplex CComplex::operator+( const CComplex& z )
{
return CComplex(re+z.re,im+z.im);
};
CComplex CComplex::operator+( int z )
{
return CComplex(re+((double) z),im);
};
CComplex CComplex::operator+( double z )
{
return CComplex(re+z,im);
};
void CComplex::operator+=( const CComplex& z)
{
re+=z.re;
im+=z.im;
};
void CComplex::operator+=( double z )
{
re+=z;
};
void CComplex::operator+=( int z )
{
re+=(double) z;
};
CComplex operator+( int x, const CComplex& y )
{
return CComplex( ((double) x) + y.re, y.im );
}
CComplex operator+( double x, const CComplex& y )
{
return CComplex( x + y.re, y.im );
}
CComplex operator+( const CComplex& x, const CComplex& y )
{
return CComplex( x.re + y.re, x.im + y.im );
}
//******* Subtraction ***************************************************
CComplex CComplex::operator-()
{
return CComplex(-re,-im);
}
CComplex CComplex::operator-( const CComplex& z)
{
return CComplex(re-z.re,im-z.im);
};
CComplex CComplex::operator-( int z )
{
return CComplex(re-((double) z),im);
};
CComplex CComplex::operator-( double z )
{
return CComplex(re-z,im);
};
void CComplex::operator-=( const CComplex& z)
{
re-=z.re;
im-=z.im;
};
void CComplex::operator-=( double z )
{
re-=z;
};
void CComplex::operator-=( int z )
{
re-=(double) z;
};
CComplex operator-( int x, const CComplex& y )
{
return CComplex( ((double) x) - y.re, - y.im );
}
CComplex operator-( double x, const CComplex& y )
{
return CComplex( x - y.re, - y.im );
}
CComplex operator-( const CComplex& x, const CComplex& y )
{
return CComplex( x.re - y.re, x.im - y.im );
}
CComplex operator-( const CComplex& y )
{
return CComplex( -y.re,-y.im );
}
//******* Multiplication ***************************************************
CComplex CComplex::operator*( const CComplex& z)
{
return CComplex(re*z.re - im*z.im,re*z.im + im*z.re);
};
CComplex CComplex::operator*( int z )
{
return CComplex( re*((double) z),im*((double) z) );
};
CComplex CComplex::operator*( double z )
{
return CComplex(re*z,im*z);
};
void CComplex::operator*=( const CComplex& z)
{
CComplex x(re*z.re - im*z.im,re*z.im + im*z.re);
re=x.re; im=x.im;
};
void CComplex::operator*=( double z )
{
re*=z; im*=z;
};
void CComplex::operator*=( int z )
{
re*=(double) z;
im*=(double) z;
};
CComplex operator*( int x, const CComplex& y )
{
return CComplex( ((double) x) * y.re, ((double) x)*y.im );
}
CComplex operator*( double x, const CComplex& y )
{
return CComplex( x*y.re, x*y.im );
}
CComplex operator*( const CComplex& x, const CComplex& y )
{
return CComplex( x.re*y.re-x.im*y.im, x.re*y.im+x.im*y.re );
}
//******* Division ***************************************************
CComplex CComplex::operator/( const CComplex& z)
{
double c;
CComplex y;
if(fabs(z.re)>fabs(z.im))
{
c=z.im/z.re;
y.re=1./(z.re*(1.+c*c));
y.im=(-c)*y.re;
}
else{
c=z.re/z.im;
y.im=(-1.)/(z.im*(1.+c*c));
y.re=(-c)*y.im;
}
return *this * y;
};
CComplex CComplex::operator/( int z )
{
return CComplex(re/((double) z),im/((double) z));
};
CComplex CComplex::operator/( double z )
{
return CComplex(re/z,im/z);
};
void CComplex::operator/=( const CComplex& z)
{
*this=*this/z;
};
void CComplex::operator/=( double z )
{
re/=z;
im/=z;
};
void CComplex::operator/=( int z )
{
re/=(double) z;
im/=(double) z;
};
CComplex operator/( int x, const CComplex& z )
{
double c;
CComplex y;
if(fabs(z.re)>fabs(z.im))
{
c=z.im/z.re;
y.re=1./(z.re*(1.+c*c));
y.im=(-c)*y.re;
}
else{
c=z.re/z.im;
y.im=(-1.)/(z.im*(1.+c*c));
y.re=(-c)*y.im;
}
y.re*=(double) x;
y.im*=(double) x;
return y;
}
CComplex operator/( double x, const CComplex& z )
{
double c;
CComplex y;
if(fabs(z.re)>fabs(z.im))
{
c=z.im/z.re;
y.re=1./(z.re*(1.+c*c));
y.im=(-c)*y.re;
}
else{
c=z.re/z.im;
y.im=(-1.)/(z.im*(1.+c*c));
y.re=(-c)*y.im;
}
y.re*= x;
y.im*= x;
return y;
}
CComplex operator/( const CComplex& x, const CComplex& z )
{
double c;
CComplex y;
if(fabs(z.re)>fabs(z.im))
{
c=z.im/z.re;
y.re=1./(z.re*(1.+c*c));
y.im=(-c)*y.re;
}
else{
c=z.re/z.im;
y.im=(-1.)/(z.im*(1.+c*c));
y.re=(-c)*y.im;
}
return x*y;
}
//****** Equals definitions ********************************
void CComplex::operator=(double z)
{
re=z;
im=0;
}
void CComplex::operator=(int z)
{
re=(double) z;
im=0;
}
//***** Tests ***********************************************
BOOL CComplex::operator==( const CComplex& z){
if ((z.im==im) && (z.re==re)) return TRUE;
return FALSE;
}
BOOL CComplex::operator==(double z){
if ((z==re) && (im==0)) return TRUE;
return FALSE;
}
BOOL CComplex::operator==(int z){
if ((re==(double) z) && (im==0)) return TRUE;
return FALSE;
}
BOOL CComplex::operator!=( const CComplex& z){
if ((z.re==re) && (z.im==im)) return FALSE;
return TRUE;
}
BOOL CComplex::operator!=(double z){
if ((re!=z) || (im!=0)) return TRUE;
return FALSE;
}
BOOL CComplex::operator!=(int z){
if ((re!=(double) z) || (im!=0)) return TRUE;
return FALSE;
}
//***** Useful functions ************************************
CComplex conj( const CComplex& x)
{
return CComplex(x.re,-x.im);
}
CComplex exp( const CComplex& x)
{
CComplex y;
y.re=cos(x.im)*exp(x.re);
y.im=sin(x.im)*exp(x.re);
return y;
}
CComplex sqrt( const CComplex& x)
{
double w,z;
CComplex y;
if((x.re==0) && (x.im==0)) w=0;
else if(fabs(x.re)>fabs(x.im)){
z=x.im/x.re;
w=sqrt(fabs(x.re))*sqrt( (1.+sqrt(1.+z*z))/2. );
}
else{
z=x.re/x.im;
w=sqrt(fabs(x.im))*sqrt( (fabs(z)+sqrt(1.+z*z))/2. );
}
if(w==0){
y.re=0;
y.im=0;
return y;
}
if(x.re>=0){
y.re=w;
y.im=x.im/(2.*w);
return y;
}
if(x.im>=0){
y.re=fabs(x.im)/(2.*w);
y.im=w;
return y;
}
y.re=fabs(x.im)/(2.*w);
y.im= (-w);
return y;
}
CComplex tanh( const CComplex& x)
{
CComplex y;
if (x.re>0){
y=(1-exp(-2*x))/(1+exp(-2*x));
}
else{
y=(exp(2*x)-1)/(exp(2*x)+1);
}
return y;
}
CComplex sinh( const CComplex& x)
{
return (exp(x)-exp(-x))/2;
}
CComplex cosh( const CComplex& x)
{
return (exp(x)+exp(-x))/2;
}
CComplex cos( const CComplex& x)
{
return (exp(I*x)+exp(-I*x))/2;
}
CComplex acos( const CComplex& x)
{
return PI/2. - arg(I*x + sqrt(1 - x*x)) + I*log(abs(I*x + sqrt(1 - x*x)));
}
CComplex sin( const CComplex& x)
{
return (exp(I*x)-exp(-I*x))/(2*I);
}
CComplex asin( const CComplex& x)
{
return arg(I*x + sqrt(1 - x*x)) - I*log(abs(I*x + sqrt(1 - x*x)));
}
CComplex tan( const CComplex& x)
{
return sin(x)/cos(x);
}
CComplex atan( const CComplex& x)
{
return (arg(1+I*x) - arg(1-I*x) - I*(log(abs(1+I*x)/abs(1-I*x))))/ 2;
}
double abs( const CComplex& x)
{
if ((x.re==0) && (x.im==0)) return 0.;
if (fabs(x.re)>fabs(x.im))
return fabs(x.re)*sqrt(1.+(x.im/x.re)*(x.im/x.re));
else
return fabs(x.im)*sqrt(1.+(x.re/x.im)*(x.re/x.im));
}
double arg( const CComplex& x)
{
if ((x.re==0) && (x.im==0)) return 0.;
return atan2(x.im,x.re);
}
CComplex log( const CComplex& x)
{
CComplex y;
y.im=arg(x);
y.re=log(abs(x));
return y;
}
CComplex pow( const CComplex& x, double y)
{
return exp(y*log(x));
}
CComplex pow( const CComplex& x, int y)
{
if (y==0) return CComplex(1,0);
int i;
CComplex z;
if (y>0){
z=x;
for(i=1;i<y;i++) z*=x;
}
else{
z=1/x;
CComplex w=z;
for(i=1;i<(-y);i++) z*=w;
}
return z;
}
CComplex pow( const CComplex& x, const CComplex& y)
{
return exp(y*log(x));
}
double Re( const CComplex& a)
{
return a.re;
}
double Im( const CComplex& a)
{
return a.im;
}

114
csolv/complex.h Normal file
View File

@ -0,0 +1,114 @@
#include<afx.h> // just needs afx.h to define BOOL, TRUE, and FALSE
#define PI 3.141592653589793238462643383
#define SmallNo 1.e-14
#define DEG 0.01745329251994329576923690768
class CComplex
{
public:
// data members
double re,im;
// member functions
CComplex();
CComplex(double x);
CComplex(int x);
CComplex(double x, double y);
CComplex Sqrt();
CComplex Conj();
CComplex Inv();
void Set(double x, double y);
double Abs();
double Arg();
double Re();
double Im();
char* ToString(char *s);
//operator redefinition
//Addition
CComplex operator+( const CComplex& z );
CComplex operator+(double z);
CComplex operator+(int z);
friend CComplex operator+( int x, const CComplex& y );
friend CComplex operator+( double x, const CComplex& y );
friend CComplex operator+( const CComplex& x, const CComplex& y );
void operator+=( const CComplex& z);
void operator+=(double z);
void operator+=(int z);
//Subtraction
CComplex operator-();
CComplex operator-( const CComplex& z );
CComplex operator-(double z);
CComplex operator-(int z);
friend CComplex operator-( int x, const CComplex& y );
friend CComplex operator-( double x, const CComplex& y );
friend CComplex operator-( const CComplex& x, const CComplex& y );
friend CComplex operator-( const CComplex& x );
void operator-=( const CComplex& z);
void operator-=(double z);
void operator-=(int z);
//Multiplication
CComplex operator*( const CComplex& z );
CComplex operator*(double z);
CComplex operator*(int z);
friend CComplex operator*( int x, const CComplex& y );
friend CComplex operator*( double x, const CComplex& y );
friend CComplex operator*( const CComplex& x, const CComplex& y );
void operator*=( const CComplex& z);
void operator*=(double z);
void operator*=(int z);
//Division
CComplex operator/( const CComplex& z );
CComplex operator/(double z);
CComplex operator/(int z);
friend CComplex operator/( int x, const CComplex& y );
friend CComplex operator/( double x, const CComplex& y );
friend CComplex operator/( const CComplex &x, const CComplex& y );
void operator/=( const CComplex& z);
void operator/=(double z);
void operator/=(int z);
//Equals
void operator=(double z);
void operator=(int z);
//Tests
BOOL operator==( const CComplex& z);
BOOL operator==(double z);
BOOL operator==(int z);
BOOL operator!=( const CComplex& z);
BOOL operator!=(double z);
BOOL operator!=(int z);
private:
};
// useful functions...
#define I CComplex(0,1)
double Re( const CComplex& a);
double Im( const CComplex& a);
double abs( const CComplex& x );
double arg( const CComplex& x );
CComplex conj( const CComplex& x);
CComplex exp( const CComplex& x );
CComplex sqrt( const CComplex& x );
CComplex tanh( const CComplex& x );
CComplex sinh( const CComplex& x );
CComplex cosh( const CComplex& x );
CComplex cos( const CComplex& x );
CComplex acos( const CComplex& x );
CComplex sin( const CComplex& x );
CComplex asin( const CComplex& x );
CComplex tan( const CComplex& x );
CComplex atan( const CComplex& x );
CComplex log( const CComplex& x );
CComplex pow( const CComplex& x, int y);
CComplex pow( const CComplex& x, double y);
CComplex pow( const CComplex& x, const CComplex& y);

82
csolv/csolv.cpp Normal file
View File

@ -0,0 +1,82 @@
// csolv.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "csolv.h"
#include "csolvDlg.h"
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CcsolvApp
BEGIN_MESSAGE_MAP(CcsolvApp, CWinApp)
//{{AFX_MSG_MAP(CcsolvApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CcsolvApp construction
CcsolvApp::CcsolvApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
CcsolvApp::~CcsolvApp()
{
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CcsolvApp object
CcsolvApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CcsolvApp initialization
BOOL CcsolvApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
// Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CcsolvDlg dlg;
m_pMainWnd = &dlg;
dlg.ComLine=m_lpCmdLine;
//<DP> SetDialogBkColor();
_beginthread( old_main, 0, (void *) &dlg );
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}

779
csolv/cspars.cpp Normal file
View File

@ -0,0 +1,779 @@
#include <stdafx.h>
#include <math.h>
#include <stdio.h>
#include "csolv.h"
#include "csolvDlg.h"
#include "complex.h"
#include "spars.h"
#define KLUDGE
CComplexEntry::CComplexEntry()
{
next=NULL;
x=0;
c=0;
}
CBigComplexLinProb::CBigComplexLinProb()
{
n=0;
}
CBigComplexLinProb::~CBigComplexLinProb()
{
if (n==0) return;
int i;
CComplexEntry *uo,*ui;
free(b); free(P); free(R);
free(V); free(U); free(Z);
free(Q);
for(i=0;i<n;i++)
{
ui=M[i];
do{
uo=ui;
ui=uo->next;
delete uo;
} while(ui!=NULL);
}
free(M);
}
int CBigComplexLinProb::Create(int d, int bw, int nodes)
{
int i;
bdw=bw;
NumNodes=nodes;
b=(CComplex *)calloc(d,sizeof(CComplex));
V=(CComplex *)calloc(d,sizeof(CComplex));
P=(CComplex *)calloc(d,sizeof(CComplex));
R=(CComplex *)calloc(d,sizeof(CComplex));
U=(CComplex *)calloc(d,sizeof(CComplex));
Z=(CComplex *)calloc(d,sizeof(CComplex));
Q=(BOOL *)calloc(d,sizeof(BOOL));
M=(CComplexEntry **)calloc(d,sizeof(CComplexEntry *));
n=d;
for(i=0;i<d;i++){
M[i] = new CComplexEntry;
M[i]->c = i;
}
return 1;
}
void CBigComplexLinProb::Put(CComplex v, int p, int q)
{
CComplexEntry *e,*l;
int i;
if(q<p){ i=p; p=q; q=i; }
e=M[p];
while((e->c < q) && (e->next != NULL))
{
l=e;
e=e->next;
}
if(e->c == q){
e->x=v;
return;
}
CComplexEntry *m = new CComplexEntry;
if((e->next == NULL) && (q > e->c)){
e->next = m;
m->c = q;
m->x = v;
}
else{
l->next=m;
m->next=e;
m->c=q;
m->x=v;
}
return;
}
CComplex CBigComplexLinProb::Get(int p, int q)
{
CComplexEntry *e;
if(q<p){ int i; i=p; p=q; q=i; }
e=M[p];
while((e->c < q) && (e->next != NULL)) e=e->next;
if(e->c == q) return e->x;
// if no entry in the list, this entry must be zero...
return CComplex(0,0);
}
void CBigComplexLinProb::MultA(CComplex *X, CComplex *Y)
{
int i;
CComplexEntry *e;
for(i=0;i<n;i++) Y[i]=0;
for(i=0;i<n;i++){
Y[i]+=(M[i]->x*X[i]);
e=M[i]->next;
while(e!=NULL)
{
Y[i]+=(e->x*X[e->c]);
Y[e->c]+=(e->x*X[i]);
e=e->next;
}
}
}
void CBigComplexLinProb::MultConjA(CComplex *X, CComplex *Y)
{
int i;
CComplexEntry *e;
for(i=0;i<n;i++) Y[i]=0;
for(i=0;i<n;i++){
Y[i]+=(M[i]->x.Conj()*X[i]);
e=M[i]->next;
while(e!=NULL)
{
Y[i]+=(e->x.Conj()*X[e->c]);
Y[e->c]+=(e->x.Conj()*X[i]);
e=e->next;
}
}
}
void CBigComplexLinProb::MultAPPA(CComplex *X, CComplex *Y)
{
int i;
MultA(X,Z);
MultPC(Z,Y);
for(i=0;i<n;i++) Y[i].im=-Y[i].im;
MultPC(Y,Z);
MultA(Z,Y);
for(i=0;i<n;i++) Y[i].im=-Y[i].im;
}
CComplex CBigComplexLinProb::Dot(CComplex *x, CComplex *y)
{
int i;
CComplex z;
z=0;
for(i=0;i<n;i++) z+=x[i]*y[i];
return z;
}
CComplex CBigComplexLinProb::ConjDot(CComplex *x, CComplex *y)
{
int i;
CComplex z;
z=0;
for(i=0;i<n;i++) z+=x[i].Conj()*y[i];
return z;
}
void CBigComplexLinProb::MultPC(CComplex *X, CComplex *Y)
{
/* // Jacobi preconditioner:
int i;
for(i=0;i<n;i++) Y[i]=X[i]/M[i]->x; */
// SSOR preconditioner
int i;
CComplex c;
CComplexEntry *e;
c= Lambda*(2-Lambda);
for(i=0;i<n;i++) Y[i]=X[i]*c;
// invert Lower Triangle;
for(i=0;i<n;i++){
Y[i]/= M[i]->x;
e=M[i]->next;
while(e!=NULL)
{
Y[e->c] -= e->x * Y[i] * Lambda;
e=e->next;
}
}
for(i=0;i<n;i++) Y[i]*=M[i]->x;
// invert Upper Triangle
for(i=n-1;i>=0;i--){
e=M[i]->next;
while(e!=NULL)
{
Y[i] -= e->x * Y[e->c] * Lambda;
e=e->next;
}
Y[i]/= M[i]->x;
}
}
int CBigComplexLinProb::PBCGSolve(int flag)
{
int i;
CComplex res,res_new,del,rho,pAp;
double er,res_o;
// quick check for most obvious sign of singularity;
for(i=0;i<n;i++) if((M[i]->x.re==0) && (M[i]->x.im==0)){
fprintf(stderr,"singular flag tripped.");
return 0;
}
// initialize progress bar;
TheView->SetDlgItemText(IDC_FRAME1,"BiConjugate Gradient Solver");
TheView->m_prog1.SetPos(0);
int prg1=0;
int prg2;
// Guess for best relaxation parameter
Lambda=1.5;
// residual with V=0
MultPC(b,Z);
res_o=abs(Dot(Z,b));
if(res_o==0) return 1;
// if flag is false, initialize V with zeros;
if (flag==0) for(i=0;i<n;i++) V[i]=0;
// form residual;
MultA(V,R);
for(i=0;i<n;i++) R[i]=b[i]-R[i];
// form initial search direction;
MultPC(R,Z);
for(i=0;i<n;i++) P[i]=Z[i];
res=Dot(Z,R);
// do iteration;
do{
// step i)
MultA(P,U);
pAp=Dot(P,U);
del=res/pAp;
// step ii)
for(i=0;i<n;i++) V[i]+=(del*P[i]);
// step iii)
for(i=0;i<n;i++) R[i]-=(del*U[i]);
// step iv)
MultPC(R,Z);
res_new=Dot(Z,R);
rho=res_new/res;
res=res_new;
// step v)
for(i=0;i<n;i++) P[i]=Z[i]+(rho*P[i]);
er=sqrt(res.Abs()/res_o);
// add a little bit more precision to account
// for "bumpy" nature of BiCG
prg2=(int) (20.*log10(er)/(log10(Precision)-2.));
if(prg2>prg1){
prg1=prg2;
prg2=(prg1*5);
if(prg2>100) prg2=100;
TheView->m_prog1.SetPos(prg2);
TheView->InvalidateRect(NULL, FALSE);
TheView->UpdateWindow();
}
} while(er>(Precision*0.01));
return 1;
}
void CBigComplexLinProb::SetValue(int i, CComplex x)
{
int k,fst,lst;
CComplex z;
if(bdw==0){
fst=0;
lst=n;
}
else{
fst=i-bdw; if (fst<0) fst=0;
lst=i+bdw; if (lst>NumNodes) lst=NumNodes;
}
for(k=fst;k<n;k++)
{
if (k==lst) k=NumNodes;
z=Get(k,i);
if((z.re!=0) || (z.im!=0)){
b[k]-=(z*x);
if(i!=k){
z=0;
Put(z,k,i);
}
}
}
b[i]=Get(i,i)*x;
}
void CBigComplexLinProb::Wipe()
{
int i;
CComplexEntry *e;
for(i=0;i<n;i++){
b[i]=0;
e=M[i];
do{
e->x=0;
e=e->next;
} while(e!=NULL);
}
}
void CBigComplexLinProb::AntiPeriodicity(int i, int j)
{
int k,fst,lst;
CComplex v1,v2,c;
#ifdef KLUDGE
int tmpbdw=bdw;
bdw=0;
#endif
if (j<i) {k=j;j=i;i=k;}
if(bdw==0){
fst=0;
lst=n;
}
else{
fst=i-bdw; if (fst<0) fst=0;
lst=j+bdw; if (lst>NumNodes-1) lst=NumNodes-1;
}
for(k=fst;k<n;k++)
{
if((k!=i) && (k!=j))
{
v1=Get(k,i);
v2=Get(k,j);
if ((v1!=0) || (v2!=0)){
c=(v1-v2)/2.;
Put(c,k,i);
Put(-c,k,j);
}
}
if((k==i+bdw) && (k<j-bdw) && (bdw!=0)) k=j-bdw;
else if(k==lst) k=NumNodes;
}
c=0.5*(Get(i,i)+Get(j,j));
Put(c,i,i);
Put(c,j,j);
c=0.5*(b[i]-b[j]);
b[i]=c;
b[j]=-c;
#ifdef KLUDGE
bdw=tmpbdw;
#endif
}
void CBigComplexLinProb::Periodicity(int i, int j)
{
int k,fst,lst;
CComplex v1,v2,c;
#ifdef KLUDGE
int tmpbdw=bdw;
bdw=0;
#endif
if (j<i) {k=j;j=i;i=k;}
if(bdw==0){
fst=0;
lst=n;
}
else{
fst=i-bdw; if (fst<0) fst=0;
lst=j+bdw; if (lst>NumNodes-1) lst=NumNodes-1;
}
for(k=fst;k<n;k++){
if((k!=i) && (k!=j))
{
v1=Get(k,i);
v2=Get(k,j);
if ((v1!=0) || (v2!=0)) {
c=(v1+v2)/2.;
Put(c,k,i);
Put(c,k,j);
}
}
if((k==i+bdw) && (k<j-bdw) && (bdw!=0)) k=j-bdw;
else if(k==lst) k=NumNodes;
}
c=(Get(i,i)+Get(j,j))/2.;
Put(c,i,i);
Put(c,j,j);
c=0.5*(b[i]+b[j]);
b[i]=c;
b[j]=c;
#ifdef KLUDGE
bdw=tmpbdw;
#endif
}
// Alternate solver that could be used for the heck of it
// The preconditioner hasn't been integrated with the QMR solver yet.
int CBigComplexLinProb::QMRSolve(int flag)
{
int i;
CComplex alpha,beta,tau,rho,theta,sigma,psi,z;
double tau_o,er;
// quick check for most obvious sign of singularity;
for(i=0;i<n;i++) if((M[i]->x.re==0) && (M[i]->x.im==0)){
fprintf(stderr,"singular flag tripped.");
return 0;
}
// initialize progress bar;
TheView->SetDlgItemText(IDC_FRAME1,"QMR Solver");
TheView->m_prog1.SetPos(0);
int prg1=0;
int prg2;
// if flag is false, initialize V with zeros;
if (flag==0) for(i=0;i<n;i++) V[i]=0;
// form residual and initial search direction;
MultA(V,R);
for(i=0;i<n;i++){
R[i]=b[i]-R[i];
P[i]=R[i];
Z[i]=0;
}
tau=ConjDot(R,R);
rho=Dot(P,R);
theta=0;
tau_o=Re(tau);
// do iteration;
int k=0;
do{
// step 1)
MultA(P,U);
// step 2)
sigma=Dot(P,U);
// step 3)
alpha=rho/sigma;
for(i=0;i<n;i++) R[i] = R[i] - alpha*U[i];
// step 4)
z=theta;
theta = ConjDot(R,R)/tau;
psi = 1/(1+theta);
tau = tau*theta*psi;
for(i=0;i<n;i++){
Z[i]=Z[i]*psi*z + P[i]*psi*alpha;
V[i] = V[i]+Z[i];
}
// step 7)
z=rho;
rho=Dot(R,R);
beta=rho/z;
for(i=0;i<n;i++) P[i]=R[i]+P[i]*beta;
er=sqrt(tau.Abs()/tau_o);
prg2=(int) (20.*log10(er)/(log10(Precision)));
if(prg2>prg1){
prg1=prg2;
prg2=(prg1*5);
if(prg2>100) prg2=100;
TheView->m_prog1.SetPos(prg2);
TheView->InvalidateRect(NULL, FALSE);
TheView->UpdateWindow();
}
} while(er > Precision);
return 1;
}
// Make into a Hermitian problem and solve.
// This ought to be slower than BiPCG, but the idea is to avoid
// the situations where BiPCG breaks down.
// This works, but to do the whole problem this way can be
// painfully slow in practice.
int CBigComplexLinProb::PCGSQSolve(int flag)
{
int i;
CComplex res,res_new,del,rho,pAp;
double er,res_o;
// quick check for most obvious sign of singularity;
for(i=0;i<n;i++) if((M[i]->x.re==0) && (M[i]->x.im==0)){
fprintf(stderr,"singular flag tripped.");
return 0;
}
// initialize progress bar;
TheView->SetDlgItemText(IDC_FRAME1,"Conjugate Gradient Solver");
TheView->m_prog1.SetPos(0);
int prg1=0;
int prg2;
// Guess for best relaxation parameter
Lambda=1.0;
// Operate on RHS to scale for squared problem
MultPC(b,Z);
for(i=0;i<n;i++) Z[i].im=-Z[i].im;
MultPC(Z,b);
MultA(b,Z);
for(i=0;i<n;i++) b[i]=Z[i].Conj();
// residual with V=0
res_o=abs(ConjDot(b,b));
if(res_o==0) return 1;
// if flag is false, initialize V with zeros;
if (flag==0) for(i=0;i<n;i++) V[i]=0;
// form residual;
MultAPPA(V,R);
for(i=0;i<n;i++) R[i]=b[i]-R[i];
// form initial search direction
for(i=0;i<n;i++) P[i]=R[i];
res=ConjDot(R,R);
// do iteration;
do{
// step i)
MultAPPA(P,U);
pAp=ConjDot(P,U);
del=res/pAp;
// step ii)
for(i=0;i<n;i++) V[i]+=(del*P[i]);
// step iii)
for(i=0;i<n;i++) R[i]-=(del*U[i]);
// step iv)
res_new=ConjDot(R,R);
rho=res_new/res;
res=res_new;
// step v)
for(i=0;i<n;i++) P[i]=R[i]+(rho*P[i]);
er=sqrt(res.Abs()/res_o);
// Display convergence results
prg2=(int) (20.*log10(er)/log10(Precision));
if(prg2>prg1){
prg1=prg2;
prg2=(prg1*5);
if(prg2>100) prg2=100;
TheView->m_prog1.SetPos(prg2);
TheView->InvalidateRect(NULL, FALSE);
TheView->UpdateWindow();
}
} while(er>Precision);
return 1;
}
// Make into a Hermitian problem and solve.
// Just use for a few iterations to get a good starting point
// for the regular BiPCG, which can sometimes get initialized
// with a pathological starting point.
int CBigComplexLinProb::PCGSQStart(int flag)
{
int i,k;
CComplex res,res_new,del,rho,pAp;
// quick check for most obvious sign of singularity;
for(i=0;i<n;i++) if((M[i]->x.re==0) && (M[i]->x.im==0)){
fprintf(stderr,"singular flag tripped.");
return 0;
}
// Guess for best relaxation parameter
Lambda=1.0;
// Operate on RHS to scale for squared problem
MultPC(b,Z);
for(i=0;i<n;i++) Z[i].im=-Z[i].im;
MultPC(Z,P);
MultA(P,Z);
for(i=0;i<n;i++) P[i]=Z[i].Conj();
// initialize V with zeros;
for(i=0;i<n;i++) V[i]=0;
// form residual;
MultAPPA(V,R);
for(i=0;i<n;i++) R[i]=P[i]-R[i];
// form initial search direction
for(i=0;i<n;i++) P[i]=R[i];
res=ConjDot(R,R);
// do iteration;
for(k=0;k<3;k++)
{
// step i)
MultAPPA(P,U);
pAp=ConjDot(P,U);
del=res/pAp;
// step ii)
for(i=0;i<n;i++) V[i]+=(del*P[i]);
// step iii)
for(i=0;i<n;i++) R[i]-=(del*U[i]);
// step iv)
res_new=ConjDot(R,R);
rho=res_new/res;
res=res_new;
// step v)
for(i=0;i<n;i++) P[i]=R[i]+(rho*P[i]);
}
return 1;
}
// Slightly modified version of the preconditioned biconjugate gradient.
// This version calls PCGSQStart to do a small number of iterations,
// moving the starting point for PBCG away from the pathological starting
// points that can sometimes crop up.
int CBigComplexLinProb::PBCGSolveMod(int flag)
{
int i;
CComplex res,res_new,del,rho,pAp;
double er;
static double res_o;
// initialize progress bar;
TheView->m_prog1.SetPos(0);
int prg1=0;
int prg2;
// get starting point; singularity check;
if(flag==FALSE){
TheView->SetDlgItemText(IDC_FRAME1,"Initializing Solver");
if (PCGSQStart(flag)==0) return 0;
}
TheView->SetDlgItemText(IDC_FRAME1,"BiConjugate Gradient Solver");
// Guess for best relaxation parameter
Lambda=1.5;
// residual with V from PCGSQ
// if flag==TRUE, carry residual target over from the last iteration.
if (flag==FALSE)
{
MultPC(V,Z);
res_o=abs(Dot(Z,V));
if(res_o==0) return 1;
}
// form residual;
MultA(V,R);
for(i=0;i<n;i++) R[i]=b[i]-R[i];
// form initial search direction;
MultPC(R,Z);
for(i=0;i<n;i++) P[i]=Z[i];
res=Dot(Z,R);
// do iteration;
do{
// step i)
MultA(P,U);
pAp=Dot(P,U);
del=res/pAp;
// step ii)
for(i=0;i<n;i++) V[i]+=(del*P[i]);
// step iii)
for(i=0;i<n;i++) R[i]-=(del*U[i]);
// step iv)
MultPC(R,Z);
res_new=Dot(Z,R);
rho=res_new/res;
res=res_new;
// step v)
for(i=0;i<n;i++) P[i]=Z[i]+(rho*P[i]);
er=sqrt(res.Abs()/res_o);
// add a little bit more precision to account
// for "bumpy" nature of BiCG
prg2=(int) (20.*log10(er)/(log10(Precision)-2.));
if(prg2>prg1){
prg1=prg2;
prg2=(prg1*5);
if(prg2>100) prg2=100;
TheView->m_prog1.SetPos(prg2);
TheView->InvalidateRect(NULL, FALSE);
TheView->UpdateWindow();
}
} while(er>(Precision*0.01));
return 1;
}

682
csolv/femmedoccore.cpp Normal file
View File

@ -0,0 +1,682 @@
// FemmeDocCore.cpp : implementation of the CFemmeDocCore class
//
#include <stdafx.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "complex.h"
#include "csolv.h"
#include "csolvDlg.h"
#include "mesh.h"
#include "spars.h"
#include "FemmeDocCore.h"
/////////////////////////////////////////////////////////////////////////////
// CFemmeDocCore construction/destruction
CFemmeDocCore::CFemmeDocCore()
{
TheView=NULL;
Precision=NULL;
LengthUnits=NULL;
ProblemType=NULL;
Coords=NULL;
BandWidth=NULL;
NumNodes=NULL;
NumEls=NULL;
NumBlockProps=NULL;
NumPBCs=NULL;
NumLineProps=NULL;
NumPointProps=NULL;
NumCircProps=NULL;
NumBlockLabels=NULL;
meshnode=NULL;
meshele=NULL;
blockproplist=NULL;
lineproplist=NULL;
nodeproplist=NULL;
circproplist=NULL;
labellist=NULL;
pbclist=NULL;
PathName=NULL;
extRo=extRi=extZo=NULL;
}
CFemmeDocCore::~CFemmeDocCore()
{
// This space for rent.
}
void CFemmeDocCore::CleanUp()
{
if (meshnode!=NULL) free(meshnode);
if (meshele!=NULL) free(meshele);
if (blockproplist!=NULL) free(blockproplist);
if (lineproplist!=NULL) free(lineproplist);
if (nodeproplist!=NULL) free(nodeproplist);
if (circproplist!=NULL) free(circproplist);
if (labellist!=NULL) free(labellist);
if (pbclist!=NULL) free(pbclist);
}
/////////////////////////////////////////////////////////////////////////////
// CFemmeDocCore commands
char* StripKey(char *c)
{
char *d;
int i,k;
k=(int)strlen(c);
for(i=0;i<k;i++){
if (c[i] == '='){
d=c+i+1;
return d;
}
}
return c+k;
}
BOOL CFemmeDocCore::OnOpenDocument()
{
FILE *fp;
int k;
char s[1024],q[1024];
char *v;
CPointProp PProp;
CBoundaryProp BProp;
CMaterialProp MProp;
CCircuit CProp;
CBlockLabel blk;
sprintf(s,"%s.fec",PathName);
if ((fp=fopen(s,"rt"))==NULL){
fprintf(stderr,"Couldn't read from specified %s\n",s);
return FALSE;
}
// define some defaults
Precision=1.e-08;
Depth=-1;
ProblemType=0;
Frequency=0;
Coords=0;
NumPointProps=0;
NumLineProps=0;
NumBlockProps=0;
NumCircProps=0;
// parse the file
while (fgets(s,1024,fp)!=NULL)
{
sscanf(s,"%s",q);
// Precision
if( _strnicmp(q,"[precision]",11)==0){
v=StripKey(s);
sscanf(v,"%lf",&Precision);
q[0]=NULL;
}
// Units of length used by the problem
if( _strnicmp(q,"[lengthunits]",13)==0){
v=StripKey(s);
sscanf(v,"%s",q);
if( _strnicmp(q,"inches",6)==0) LengthUnits=0;
else if( _strnicmp(q,"millimeters",11)==0) LengthUnits=1;
else if( _strnicmp(q,"centimeters",1)==0) LengthUnits=2;
else if( _strnicmp(q,"mils",4)==0) LengthUnits=4;
else if( _strnicmp(q,"microns",6)==0) LengthUnits=5;
else if( _strnicmp(q,"meters",6)==0) LengthUnits=3;
q[0]=NULL;
}
// Depth for 2D planar problems;
if( _strnicmp(q,"[depth]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&Depth);
q[0]=NULL;
}
// Frequency in Hz; convert to rad/sec
if( _strnicmp(q,"[frequency]",11)==0){
v=StripKey(s);
sscanf(v,"%lf",&Frequency);
Frequency*=(2.*PI);
q[0]=NULL;
}
// Problem Type (planar or axisymmetric)
if( _strnicmp(q,"[problemtype]",13)==0){
v=StripKey(s);
sscanf(v,"%s",q);
if( _strnicmp(q,"planar",6)==0) ProblemType=0;
if( _strnicmp(q,"axisymmetric",3)==0) ProblemType=1;
q[0]=NULL;
}
// Coordinates (cartesian or polar)
if( _strnicmp(q,"[coordinates]",13)==0){
v=StripKey(s);
sscanf(v,"%s",q);
if ( _strnicmp(q,"cartesian",4)==0) Coords=0;
if ( _strnicmp(q,"polar",5)==0) Coords=1;
q[0]=NULL;
}
// properties for axisymmetric external region
if( _strnicmp(q,"[extzo]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&extZo);
q[0]=NULL;
}
if( _strnicmp(q,"[extro]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&extRo);
q[0]=NULL;
}
if( _strnicmp(q,"[extri]",7)==0){
v=StripKey(s);
sscanf(v,"%lf",&extRi);
q[0]=NULL;
}
// Point Properties
if( _strnicmp(q,"[pointprops]",12)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) nodeproplist=(CPointProp *)calloc(k,sizeof(CPointProp));
q[0]=NULL;
}
if( _strnicmp(q,"<beginpoint>",11)==0){
PProp.V=0;
PProp.qp=0;
q[0]=NULL;
}
if( _strnicmp(q,"<vpr>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&PProp.V.re);
q[0]=NULL;
}
if( _strnicmp(q,"<vpi>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&PProp.V.im);
q[0]=NULL;
}
if( _strnicmp(q,"<qpr>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&PProp.qp.re);
q[0]=NULL;
}
if( _strnicmp(q,"<qpi>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&PProp.qp.im);
q[0]=NULL;
}
if( _strnicmp(q,"<endpoint>",9)==0){
nodeproplist[NumPointProps]=PProp;
NumPointProps++;
q[0]=NULL;
}
// Boundary Properties;
if( _strnicmp(q,"[bdryprops]",11)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) lineproplist=(CBoundaryProp *)calloc(k,sizeof(CBoundaryProp));
q[0]=NULL;
}
if( _strnicmp(q,"<beginbdry>",11)==0){
BProp.BdryFormat=0;
BProp.V=0;
BProp.qs=0;
BProp.c0=0;
BProp.c1=0;
q[0]=NULL;
}
if( _strnicmp(q,"<bdrytype>",10)==0){
v=StripKey(s);
sscanf(v,"%i",&BProp.BdryFormat);
q[0]=NULL;
}
if( _strnicmp(q,"<vsr>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.V.re);
q[0]=NULL;
}
if( _strnicmp(q,"<vsi>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.V.im);
q[0]=NULL;
}
if( _strnicmp(q,"<qsr>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.qs.re);
q[0]=NULL;
}
if( _strnicmp(q,"<qsi>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.qs.im);
q[0]=NULL;
}
if( _strnicmp(q,"<c0r>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.c0.re);
q[0]=NULL;
}
if( _strnicmp(q,"<c0i>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.c0.im);
q[0]=NULL;
}
if( _strnicmp(q,"<c1r>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.c1.re);
q[0]=NULL;
}
if( _strnicmp(q,"<c1i>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&BProp.c1.im);
q[0]=NULL;
}
if( _strnicmp(q,"<endbdry>",9)==0){
lineproplist[NumLineProps]=BProp;
NumLineProps++;
q[0]=NULL;
}
// Block Properties;
if( _strnicmp(q,"[blockprops]",12)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) blockproplist=(CMaterialProp *)calloc(k,sizeof(CMaterialProp));
q[0]=NULL;
}
if( _strnicmp(q,"<beginblock>",12)==0){
MProp.ex=1;
MProp.ey=1;
MProp.ox=1;
MProp.oy=1;
q[0]=NULL;
}
if( _strnicmp(q,"<ox>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.ox);
q[0]=NULL;
}
if( _strnicmp(q,"<oy>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.oy);
q[0]=NULL;
}
if( _strnicmp(q,"<ex>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.ex.re);
MProp.ex.im=0;
q[0]=NULL;
}
if( _strnicmp(q,"<ey>",4)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.ey.re);
MProp.ey.im=0;
q[0]=NULL;
}
if( _strnicmp(q,"<ltx>",5)==0){
v=StripKey(s);
double lt;
sscanf(v,"%lf",&lt);
lt=-atan(lt);
MProp.ex=MProp.ex*exp(I*lt);
q[0]=NULL;
}
if( _strnicmp(q,"<lty>",5)==0){
v=StripKey(s);
double lt;
sscanf(v,"%lf",&lt);
lt=-atan(lt);
MProp.ey=MProp.ey*exp(I*lt);
q[0]=NULL;
}
if( _strnicmp(q,"<endblock>",9)==0){
MProp.kx=MProp.ox/eo+I*Frequency*MProp.ex;
MProp.ky=MProp.oy/eo+I*Frequency*MProp.ey;
blockproplist[NumBlockProps]=MProp;
NumBlockProps++;
q[0]=NULL;
}
// Conductor Properties
if( _strnicmp(q,"[conductorprops]",16)==0){
v=StripKey(s);
sscanf(v,"%i",&k);
if(k>0) circproplist=(CCircuit *)calloc(k,sizeof(CCircuit));
q[0]=NULL;
}
if( _strnicmp(q,"<beginconductor>",16)==0){
CProp.V=0;
CProp.q=0;
CProp.CircType=0;
q[0]=NULL;
}
if( _strnicmp(q,"<vcr>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&CProp.V.re);
q[0]=NULL;
}
if( _strnicmp(q,"<vcr>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&CProp.V.im);
q[0]=NULL;
}
if( _strnicmp(q,"<qcr>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&CProp.q.re);
q[0]=NULL;
}
if( _strnicmp(q,"<qci>",5)==0){
v=StripKey(s);
sscanf(v,"%lf",&CProp.q.im);
q[0]=NULL;
}
if( _strnicmp(q,"<conductortype>",15)==0){
v=StripKey(s);
sscanf(v,"%i",&CProp.CircType);
q[0]=NULL;
}
if( _strnicmp(q,"<endconductor>",14)==0){
circproplist[NumCircProps]=CProp;
NumCircProps++;
q[0]=NULL;
}
// read in regional attributes
if(_strnicmp(q,"[numblocklabels]",13)==0){
int i;
v=StripKey(s);
sscanf(v,"%i",&k);
if (k>0) labellist=(CBlockLabel *)calloc(k, sizeof(CBlockLabel));
NumBlockLabels=k;
for(i=0;i<k;i++)
{
fgets(s,1024,fp);
sscanf(s,"%lf %lf %i %lf %i %i",&blk.x,&blk.y,&blk.BlockType,
&blk.MaxArea,&blk.InGroup,&blk.IsExternal);
blk.IsDefault = blk.IsExternal & 2;
blk.IsExternal = blk.IsExternal & 1;
blk.BlockType--;
labellist[i]=blk;
}
q[0]=NULL;
}
}
fclose(fp);
return TRUE;
}
BOOL CFemmeDocCore::LoadMesh()
{
int i,j,k,q,n0,n1,n;
char infile[256];
FILE *fp;
char s[1024];
double c[]={25.4,1.,10.,1000.,0.0254,0.001};
//read meshnodes;
sprintf(infile,"%s.node",PathName);
if((fp=fopen(infile,"rt"))==NULL){
return FALSE;
}
fgets(s,1024,fp);
sscanf(s,"%i",&k); NumNodes=k;
meshnode=(CNode *)calloc(k,sizeof(CNode));
CNode node;
for(i=0;i<k;i++){
fscanf(fp,"%i",&j);
fscanf(fp,"%lf",&node.x);
fscanf(fp,"%lf",&node.y);
fscanf(fp,"%i",&n);
if(n>1){
// strip off point BC number;
j=n & 0xffff;
j=j-2;
if (j<0) j=-1;
// strip off Conductor number
n= (n - (n & 0xffff))/0x10000 - 1;
}
else{
j=-1;
n=-1;
}
node.bc=j;
node.InConductor=n;
// convert all lengths to internal working units of mm
node.x*=c[LengthUnits];
node.y*=c[LengthUnits];
meshnode[i]=node;
}
fclose(fp);
//read in periodic boundary conditions;
sprintf(infile,"%s.pbc",PathName);
if((fp=fopen(infile,"rt"))==NULL){
return FALSE;
}
fgets(s,1024,fp);
sscanf(s,"%i",&NumPBCs);
if (NumPBCs!=0) pbclist=(CCommonPoint *)calloc(NumPBCs,sizeof(CCommonPoint));
CCommonPoint pbc;
for(i=0;i<NumPBCs;i++){
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&pbc.x);
fscanf(fp,"%i",&pbc.y);
fscanf(fp,"%i",&pbc.t);
pbclist[i]=pbc;
}
fclose(fp);
// read in elements;
sprintf(infile,"%s.ele",PathName);
if((fp=fopen(infile,"rt"))==NULL){
return FALSE;
}
fgets(s,1024,fp);
sscanf(s,"%i",&k); NumEls=k;
meshele=(CElement *)calloc(k,sizeof(CElement));
CElement elm;
int defaultLabel;
for(i=0,defaultLabel=-1;i<NumBlockLabels;i++)
if (labellist[i].IsDefault) defaultLabel=i;
for(i=0;i<k;i++){
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&elm.p[0]);
fscanf(fp,"%i",&elm.p[1]);
fscanf(fp,"%i",&elm.p[2]);
fscanf(fp,"%i",&elm.lbl);
elm.lbl--;
if(elm.lbl<0) elm.lbl=defaultLabel;
if(elm.lbl<0){
CString msg;
msg ="Material properties have not been defined for\n";
msg+="all regions. Press the \"Run Mesh Generator\"\n";
msg+="button to highlight the problem regions.";
MsgBox(msg);
fclose(fp);
sprintf(infile,"%s.ele",PathName); DeleteFile(infile);
sprintf(infile,"%s.node",PathName); DeleteFile(infile);
sprintf(infile,"%s.pbc",PathName); DeleteFile(infile);
sprintf(infile,"%s.poly",PathName); DeleteFile(infile);
sprintf(infile,"%s.edge",PathName); DeleteFile(infile);
exit(1);
}
// look up block type out of the list of block labels
elm.blk=labellist[elm.lbl].BlockType;
meshele[i]=elm;
}
fclose(fp);
// initialize edge bc's and element permeabilities;
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
meshele[i].e[j] = -1;
// read in edges to which boundary conditions are applied;
// first, do a little bookkeeping so that element
// associated with a give edge can be identified fast
int *nmbr;
int **mbr;
nmbr=(int *)calloc(NumNodes,sizeof(int));
// Make a list of how many elements that tells how
// many elements to which each node belongs.
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
nmbr[meshele[i].p[j]]++;
// mete out some memory to build a list of the
// connectivity...
mbr=(int **)calloc(NumNodes,sizeof(int *));
for(i=0;i<NumNodes;i++){
mbr[i]=(int *)calloc(nmbr[i],sizeof(int));
nmbr[i]=0;
}
// fill up the connectivity information;
for(i=0;i<NumEls;i++)
for(j=0;j<3;j++)
{
k=meshele[i].p[j];
mbr[k][nmbr[k]]=i;
nmbr[k]++;
}
sprintf(infile,"%s.edge",PathName);
if((fp=fopen(infile,"rt"))==NULL)
{
return FALSE;
}
fscanf(fp,"%i",&k); // read in number of lines
fscanf(fp,"%i",&j); // read in boundarymarker flag;
for(i=0;i<k;i++)
{
fscanf(fp,"%i",&j);
fscanf(fp,"%i",&n0);
fscanf(fp,"%i",&n1);
fscanf(fp,"%i",&n);
// BC number;
if (n<0)
{
n=(-n);
j = (n & 0xffff) - 2;
if (j<0) j = -1;
// Conductor number;
n= (n - (n & 0xffff))/0x10000 - 1;
if (n>=0)
{
meshnode[n0].InConductor=n;
meshnode[n1].InConductor=n;
}
}
else j=-1;
if (j>=0)
{
// search through elements to find one containing the line;
// set corresponding edge equal to the bc number
for(q=0,n=FALSE;q<nmbr[n0];q++)
{
elm=meshele[mbr[n0][q]];
if ((elm.p[0] == n0) && (elm.p[1] == n1)) {elm.e[0]=j; n=TRUE;}
if ((elm.p[0] == n1) && (elm.p[1] == n0)) {elm.e[0]=j; n=TRUE;}
if ((elm.p[1] == n0) && (elm.p[2] == n1)) {elm.e[1]=j; n=TRUE;}
if ((elm.p[1] == n1) && (elm.p[2] == n0)) {elm.e[1]=j; n=TRUE;}
if ((elm.p[2] == n0) && (elm.p[0] == n1)) {elm.e[2]=j; n=TRUE;}
if ((elm.p[2] == n1) && (elm.p[0] == n0)) {elm.e[2]=j; n=TRUE;}
meshele[mbr[n0][q]]=elm;
//this is a little hack: line charge distributions should be applied
//to at most one element;
if((lineproplist[j].BdryFormat==2) && (n)) q=nmbr[n0];
}
}
}
fclose(fp);
// free up the connectivity information
free(nmbr);
for(i=0;i<NumNodes;i++) free(mbr[i]);
free(mbr);
// clear out temporary files
sprintf(infile,"%s.ele",PathName); DeleteFile(infile);
sprintf(infile,"%s.node",PathName); DeleteFile(infile);
sprintf(infile,"%s.pbc",PathName); DeleteFile(infile);
sprintf(infile,"%s.poly",PathName); DeleteFile(infile);
return TRUE;
}

74
csolv/femmedoccore.h Normal file
View File

@ -0,0 +1,74 @@
// femmeDoc.h : interface of the CFemmeDoc class
//
/////////////////////////////////////////////////////////////////////////////
#define muo 1.2566370614359173e-6
#define Golden 0.3819660112501051517954131656
class CFemmeDocCore
{
// Attributes
public:
CFemmeDocCore();
~CFemmeDocCore();
// General problem attributes
double Precision;
double Frequency;
double Depth;
int LengthUnits;
BOOL ProblemType;
BOOL Coords;
// Axisymmetric external region parameters
double extRo,extRi,extZo;
CcsolvDlg *TheView;
// CArrays containing the mesh information
int BandWidth;
CNode *meshnode;
CElement *meshele;
int NumNodes;
int NumEls;
// lists of properties
int NumBlockProps;
int NumPBCs;
int NumLineProps;
int NumPointProps;
int NumCircProps;
int NumBlockLabels;
CMaterialProp *blockproplist;
CBoundaryProp *lineproplist;
CPointProp *nodeproplist;
CCircuit *circproplist;
CBlockLabel *labellist;
CCommonPoint *pbclist;
// stuff usually kept track of by CDocument
char *PathName;
// Operations
public:
BOOL LoadMesh();
BOOL OnOpenDocument();
BOOL Cuthill();
BOOL SortElements();
BOOL AnalyzeProblem(CBigComplexLinProb &L);
CComplex ChargeOnConductor(int OnConductor, CBigComplexLinProb &L);
BOOL WriteResults(CBigComplexLinProb &L);
void CleanUp();
};
/////////////////////////////////////////////////////////////////////////////
double Power(double x, int n);

BIN
csolv/res/csolv.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

20
debug/condlib.dat Normal file
View File

@ -0,0 +1,20 @@
<BeginBlock>
<BlockName> = "Copper"
<ox> = 58000000
<oy> = 58000000
<ex> = 1
<ey> = 1
<ltx> = 0
<lty> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Aluminum"
<ox> = 37700000
<oy> = 37700000
<ex> = 1
<ey> = 1
<ltx> = 0
<lty> = 0
<EndBlock>

1537
debug/heatlib.dat Normal file

File diff suppressed because it is too large Load Diff

679
debug/init.lua Normal file
View File

@ -0,0 +1,679 @@
-- Define some common quantities for use in Lua
uo=PI*4.e-7; -- magnetic permeability of free space
eo=8.85418781762e-12; -- electrical permittivity of free space
Pi=PI; pi=PI; -- various ways that one might possibly denote PI
-- Useful unit definitions
meter=1;
meters=meter; Meter=meter; Meters=meter;
inch=0.0254;
inches=inch; Inch=inch; Inches=inch; in=inch;
cm=0.01;
centimeter=cm; centimeters=cm; Centimeters=cm; Centimeter=cm;
mm=0.001;
millimeters=mm; millimeter=mm; Millimeter=mm; Millimeters=mm; milimeter=mm; milimeters=mm;
um=0.000001;
micrometer=um; Micrometer=um; micrometers=um; Micrometers=um;
micron=um; Micron=um; microns=um; Microns=um;
mil=0.001*inch;
mils=mil; Mils=mil; Mil=mil;
Tesla = 1;
mTesla = 0.001;
Gauss = 0.0001;
kGauss = 0.1;
AmpMeter = 1;
kAmpMeter = 1000;
Oersted = 250/PI;
kOersted = 1000*Oersted;
-- Useful functions
-- Function to determine the diameter in mm of a specified AWG wire gauge
function AWG(awg) return 8.2514694*exp(-0.115943*awg) end
-- Function to read in BH points for a material from a file
-- Contributed by Dr. Henning Kiel
function mi_setbhpointsfromfile(filename, materialname, unitb, unith, order)
fact_b = Tesla
fact_h = AmpMeter
bh = 1
if unitb ~= nil then
fact_b = unitb
end
if unith ~= nil then
fact_h = unith
end
if order == 1 then
bh = 0
end
bhfile = openfile(filename,"r")
if bhfile ~= nil then
mi_clearbhpoints(materialname)
if bh == 1 then
b, h = read(bhfile,"*n","*n")
else
h, b = read(bhfile,"*n","*n")
end
while b ~= nil do
mi_addbhpoint(materialname, b, h)
if bh == 1 then
b, h = read(bhfile,"*n","*n")
else
h, b = read(bhfile,"*n","*n")
end
end
closefile(bhfile)
end
end
--permeability tables used to create asymptotic boundary conditions
uAx0 = {{10.06344410876133},
{0.18870625462846807, 39.997500411566335},
{4.374794457961015, 0.07511795918154143, 85.85566438727763},
{0.28509610532711227, 12.493269046515916, 0.051874008856059424, 147.65207370446487},
{3.0607674892527865, 0.11237818729856126, 22.026456394011774, 0.042316694272791736, 225.43020812455183},
{0.3748159380792134, 8.172423914252851, 0.07400271964825651, 33.01915762825664, 0.037123381446484645, 319.2335657378115},
{2.4089242666740582, 0.14929929105743517, 13.817592213008757, 0.05821722458526954, 45.655954531895645, 0.03386729523177279, 429.0464280099345},
{0.4577193805314985, 6.152383059834071, 0.09519535460494778, 19.79502033933107, 0.04958213970480729, 60.00201778458946, 0.031639182082296755, 554.8893696637082},
{2.0187133623041955, 0.1872419300750821, 10.322990689266506, 0.07322869764123259, 26.290072452745143, 0.0441395144643266, 76.08450824714102, 0.030019516604331355, 696.7499046385117},
{0.5332409067449392, 4.931200653946399, 0.11642450959044752, 14.522111149156393, 0.0612363797098224, 33.37497351570902, 0.04039926157266519, 93.91981759395829, 0.028790057140879656, 854.6396765772441},
{1.7619160942694887, 0.2265234822569949, 8.305694616317721, 0.08811132253969434, 18.911084918162924, 0.053672710920365976, 41.08415574149624, 0.03767250616088464, 113.51592772683063, 0.02782511889284403, 1028.551339640375},
{0.6010640087773658, 4.100907065931257, 0.13795163994918203, 11.604922157909524, 0.07274062063786199, 23.5602014704398, 0.048468764953025635, 49.437385787628045, 0.035597711447375925, 134.87895858524496, 0.02704793878013551, 1218.4906640339432}};
u2D0 = {{10.523809523809524},
{0.14531359011819187, 32.14290974079077},
{5.14939698507243, 0.053268993904189134, 54.10636468483519},
{0.2419609512179885, 13.681253040072905, 0.03301443572330777, 76.07498920312688},
{3.4661091134486472, 0.09209257399023746, 21.797339506447933, 0.02406322785653838, 98.05449854377491},
{0.3336928992521675, 9.023667719158183, 0.05789695118959376, 29.573300006204246, 0.018966499540708268, 120.04039743815603},
{2.649899689611667, 0.12953316809300527, 14.398967120915913, 0.04288257435633827, 37.197476986533054, 0.01566424606410637, 142.03015659052124},
{0.4194212714207981, 6.739646495379991, 0.0807327554079406, 19.40925290947297, 0.034255287061558344, 44.73740232258131, 0.013346899201001426, 164.02239651319712},
{2.1751715650719827, 0.16743379223593088, 10.885675868734184, 0.05987838745046158, 24.237375183864483, 0.028600398122246736, 52.225223074983184, 0.0116295354236669, 186.01632084646832},
{0.4982294821100038, 5.3544134782776664, 0.10291820111116401, 14.696545405270147, 0.048003097591685244, 28.95632726953973, 0.024587012459820066, 59.67849241525681, 0.010305182059498453, 208.01143556937637},
{1.8696806205952006, 0.2063934470334104, 8.775890039744148, 0.07607619682670601, 18.328256642424236, 0.04023921548166901, 33.60353647639198, 0.021581843440607016, 67.10765452494896, 0.009252450549701629, 230.0074236348898},
{0.5695628007801712, 4.41799489542221, 0.12499429930905502, 11.902080658968998, 0.06098009575496433, 21.847988015751035, 0.03472775671050834, 38.20087849238854, 0.01924286302232932, 74.51932204012905, 0.00839537165467591, 252.00407064779833}};
uAx1 = {{0.09090909090909091},
{10.050515900211503, 0.04349612665401649},
{0.16015012096541084, 31.212316587655547, 0.035617897941640685},
{5.075223589959199, 0.06747975164123507, 58.83076738028796, 0.032496412704901965},
{0.24983741484804536, 13.959519296714365, 0.04850942160789329, 93.62679411332631, 0.030834135426565015},
{3.438673996192938, 0.10007632616355028, 23.68319910391683, 0.040588823403447945, 135.81886600712073, 0.029800226566381535},
{0.33861114976053774, 9.11830816329029, 0.06748841981310061, 34.53152988922068, 0.03624009732510784, 185.4917052298402, 0.02909733301094425},
{2.6364338943965455, 0.13486508168984512, 15.097445398169498, 0.05395605788825772, 46.75319306175651, 0.03349209595847733, 242.6651438041285, 0.028587355212278894},
{0.4227311219273812, 6.773013674320017, 0.08745530894064872, 21.301429520550652, 0.04651420711694375, 60.44151623434645, 0.03160001126426384, 307.3631853353253, 0.028201318378415573},
{2.1675591338727647, 0.171316009911807, 11.198891625678383, 0.0680375716016307, 27.948228063433724, 0.041804487302954434, 75.63799976250523, 0.030217675069207188, 379.586805599126, 0.027898435150547626},
{0.5005548322806631, 5.365891158623955, 0.1079474936583888, 15.594898520264833, 0.05739172309462815, 35.12584682017268, 0.03855673261275498, 92.36682653198929, 0.029164062639383995, 459.3468429136272, 0.027654812310257123},
{1.864938491614021, 0.20938145992414733, 8.933546101982833, 0.08240945574778373, 20.142380617987286, 0.05066029544301638, 42.87550155678245, 0.036182409831124134, 110.63472923382548, 0.0283338992149914, 546.6150102543896, 0.027453323354323905}};
u2D1 = {{0.09502262443438914},
{6.88166880459455, 0.031111060201589526},
{0.19419749592018187, 18.77264665066931, 0.018482113995736214},
{4.13289828365353, 0.07309272016758717, 30.28978015498877, 0.013144924639159823},
{0.28850793996067764, 10.858638831248303, 0.04587715852680953, 41.55718451247941, 0.010198410219328852},
{2.9967673937356176, 0.1108196834283798, 17.27206665382645, 0.0338142851758244, 52.724541914214335, 0.008330528899783033},
{0.37737277525645235, 7.720030434644211, 0.0694494258951436, 23.31949550539958, 0.026883543752277105, 63.83965087550882, 0.0070407582729502555},
{2.384237702546398, 0.14837573304995255, 12.386546277094604, 0.05152181760881001, 29.192574288770942, 0.022352660997929614, 74.923770274119, 0.006096728349565376},
{0.45973385090978197, 5.972510009155741, 0.09186384125878651, 16.700516539917132, 0.04125859307841753, 34.96454824599637, 0.019147835875477914, 85.98795769304176, 0.005375872372109578},
{2.007107238545973, 0.1867618188354154, 9.71645432200938, 0.06804320147518493, 20.83198897925314, 0.0345347664671527, 40.67187917337226, 0.01675645545872318, 97.03855732255441, 0.004807428001555607},
{0.5348507060428623, 4.845115067234294, 0.11394855626850516, 13.144715978348659, 0.05456056293348216, 24.85137913425649, 0.029758772583431677, 46.33524484374972, 0.014901429756097718, 108.07947522964582, 0.004347685758123113},
{1.755732640246568, 0.22634702476369292, 8.00036486086015, 0.08401892313227052, 16.39879353450492, 0.04577080504067754, 28.795410205618264, 0.026177408464552673, 51.96731893999375, 0.013419338402750022, 119.11324967287628, 0.003968189868637491}};
function mi_drawarc(x1,y1,x2,y2,tta,dtta)
mi_addnode(x1,y1);
mi_addnode(x2,y2);
mi_addarc(x1,y1,x2,y2,tta,dtta);
end
function mi_drawline(x1,y1,x2,y2)
mi_addnode(x1,y1);
mi_addnode(x2,y2);
mi_addsegment(x1,y1,x2,y2);
end
function mi_makeABC(enn,arr,ex,wye,bc)
local k, d, dp, z, r, x0, x1, y0, y1, flag, p1, p2, p3, x, y, R, n
x0, x1, y0, y1 = mi_getboundingbox();
flag, p1, p2, p3 = mi_getprobleminfo();
-- unpack parameters;
if (enn == nil) then
n=7;
else
if (enn>12) then
n=12;
elseif (enn<1) then
n=1;
else
n=enn;
end
end
if (bc == nil) then
bctype=0;
else
bctype=bc;
end
if(flag == 0) then -- 2D planar case
if (arr == nil) then
R=(3/4)*abs((x0+I*y0)-(x1+I*y1));
else
R = arr;
end
if (ex == nil) then
x=(x0+x1)/2;
else
x=ex;
end
if (wye == nil) then
y=(y0+y1)/2;
else
y=wye;
end
else -- Axi case
x=0;
if (wye ~= nil) then
y=wye;
R=arr;
elseif (ex ~= nil) then
y=ex;
R=arr;
elseif (arr ~= nil) then
y=(y0+y1)/2;
R=arr;
else
y=(y0+y1)/2;
R=(3/2)*abs(x1+I*(y1-y0)/2);
end
end
-- draw left boundary of interior domain
if (flag == 0) then
mi_drawarc(x, y + R, x, y - R, 180, 1);
else
mi_drawline(0, y-1.1*R, 0, y+1.1*R);
end
-- draw right boundary of interior domain
mi_drawarc(x, y - R, x, y + R, 180, 1);
d = 0.1*R/(2*n);
for k = 1,n do
r = R*(1 + (2*k - 1)/(20*n));
mi_drawarc(x, y - r - d, x, y + r + d, 180, 1);
z = r*exp(I*(90/(n+1))*k*Pi/180);
mi_addblocklabel(x+re(z),y+im(z));
mi_selectlabel(x+re(z),y+im(z));
mi_setblockprop("u" .. k, 1, 0, "<None>", 0, 0, 1);
mi_clearselected();
if(flag == 0) then
if (bctype==0) then
mi_addmaterial("u" .. k, u2D0[n][k]);
else
mi_addmaterial("u" .. k, u2D1[n][k]);
end
mi_drawarc(x, y + r + d, x, y - r - d, 180, 1);
else
if (bctype==0) then
mi_addmaterial("u" .. k, uAx0[n][k]);
else
mi_addmaterial("u" .. k, uAx1[n][k]);
end
end
end
if (bctype==0) then
mi_addboundprop("A=0", 0, 0, 0, 0, 0, 0, 0, 0, 0);
mi_selectarcsegment(1.1*R+x, y);
if(flag == 0) then
mi_selectarcsegment(-1.1*R+x, y);
end
mi_setarcsegmentprop(1, "A=0", 0, 0);
mi_clearselected();
end
mi_zoomnatural();
end
--functions used to create asymptotic boundary conditions for electrostatic problems
function ei_drawarc(x1,y1,x2,y2,tta,dtta)
ei_addnode(x1,y1);
ei_addnode(x2,y2);
ei_addarc(x1,y1,x2,y2,tta,dtta);
end
function ei_drawline(x1,y1,x2,y2)
ei_addnode(x1,y1);
ei_addnode(x2,y2);
ei_addsegment(x1,y1,x2,y2);
end
function ei_makeABC(enn,arr,ex,wye,bc)
local k, d, dp, z, r, x0, x1, y0, y1, flag, p1, p2, p3, x, y, R
x0, x1, y0, y1 = ei_getboundingbox();
flag, p1, p2, p3 = ei_getprobleminfo();
-- unpack parameters;
if (enn == nil) then
n=7;
else
if (enn>12) then
n=12;
elseif (enn<1) then
n=1;
else
n=enn;
end
end
if (bc == nil) then
if (flag == 0) then
-- if 2D, use Neumann-type BC by default
bctype=1;
else
-- if Axisymmetric, use Dirichlet-type BC by default
bctype=0;
end
else
bctype=bc;
end
if(flag == 0) then -- 2D planar case
if (arr == nil) then
R=(3/4)*abs((x0+I*y0)-(x1+I*y1));
else
R = arr;
end
if (ex == nil) then
x=(x0+x1)/2;
else
x=ex;
end
if (wye == nil) then
y=(y0+y1)/2;
else
y=wye;
end
else -- Axi case
x=0;
if (wye ~= nil) then
y=wye;
R=arr;
elseif (ex ~= nil) then
y=ex;
R=arr;
elseif (arr ~= nil) then
y=(y0+y1)/2;
R=arr;
else
y=(y0+y1)/2;
R=(3/2)*abs(x1+I*(y1-y0)/2);
end
end
-- draw left boundary of interior domain
if (flag == 0) then
ei_drawarc(x, y + R, x, y - R, 180, 1);
else
ei_drawline(0, y-1.1*R, 0, y+1.1*R);
end
-- draw right boundary of interior domain
ei_drawarc(x, y - R, x, y + R, 180, 1);
d = 0.1*R/(2*n);
for k = 1,n do
r = R*(1 + (2*k - 1)/(20*n));
ei_drawarc(x, y - r - d, x, y + r + d, 180, 1);
z = r*exp(I*(90/(n+1))*k*Pi/180);
ei_addblocklabel(x+re(z),y+im(z));
ei_selectlabel(x+re(z),y+im(z));
ei_setblockprop("e" .. k, 1, 0, "<None>", 0, 0, 1);
ei_clearselected();
if(flag == 0) then
if (bctype==0) then
ei_addmaterial("e" .. k, u2D1[n][k]);
else
ei_addmaterial("e" .. k, u2D0[n][k]);
end
ei_drawarc(x, y + r + d, x, y - r - d, 180, 1);
else
if (bctype==0) then
ei_addmaterial("e" .. k, uAx1[n][k]);
else
ei_addmaterial("e" .. k, uAx0[n][k]);
end
end
end
if (bctype==0) then
ei_addboundprop("V=0", 0, 0, 0, 0, 0, 0, 0, 0, 0);
ei_selectarcsegment(1.1*R+x, y);
if(flag == 0) then
ei_selectarcsegment(-1.1*R+x, y);
end
ei_setarcsegmentprop(1, "V=0", 0, 0);
ei_clearselected();
end
ei_zoomnatural();
end
--functions used to create asymptotic boundary conditions for current flow problems
function ci_drawarc(x1,y1,x2,y2,tta,dtta)
ci_addnode(x1,y1);
ci_addnode(x2,y2);
ci_addarc(x1,y1,x2,y2,tta,dtta);
end
function ci_drawline(x1,y1,x2,y2)
ci_addnode(x1,y1);
ci_addnode(x2,y2);
ci_addsegment(x1,y1,x2,y2);
end
function ci_makeABC(enn,arr,ex,wye,bc)
local k, d, dp, z, r, x0, x1, y0, y1, flag, p1, p2, p3, x, y, R
x0, x1, y0, y1 = ci_getboundingbox();
flag, p1, p2, p3 = ci_getprobleminfo();
-- unpack parameters;
if (enn == nil) then
n=7;
else
if (enn>12) then
n=12;
elseif (enn<1) then
n=1;
else
n=enn;
end
end
if (bc == nil) then
if (flag == 0) then
-- if 2D, use Neumann-type BC by default
bctype=1;
else
-- if Axisymmetric, use Dirichlet-type BC by default
bctype=0;
end
else
bctype=bc;
end
if(flag == 0) then -- 2D planar case
if (arr == nil) then
R=(3/4)*abs((x0+I*y0)-(x1+I*y1));
else
R = arr;
end
if (ex == nil) then
x=(x0+x1)/2;
else
x=ex;
end
if (wye == nil) then
y=(y0+y1)/2;
else
y=wye;
end
else -- Axi case
x=0;
if (wye ~= nil) then
y=wye;
R=arr;
elseif (ex ~= nil) then
y=ex;
R=arr;
elseif (arr ~= nil) then
y=(y0+y1)/2;
R=arr;
else
y=(y0+y1)/2;
R=(3/2)*abs(x1+I*(y1-y0)/2);
end
end
-- draw left boundary of interior domain
if (flag == 0) then
ci_drawarc(x, y + R, x, y - R, 180, 1);
else
ci_drawline(0, y-1.1*R, 0, y+1.1*R);
end
-- draw right boundary of interior domain
ci_drawarc(x, y - R, x, y + R, 180, 1);
d = 0.1*R/(2*n);
for k = 1,n do
r = R*(1 + (2*k - 1)/(20*n));
ci_drawarc(x, y - r - d, x, y + r + d, 180, 1);
z = r*exp(I*(90/(n+1))*k*Pi/180);
ci_addblocklabel(x+re(z),y+im(z));
ci_selectlabel(x+re(z),y+im(z));
ci_setblockprop("e" .. k, 1, 0, "<None>", 0, 0, 1);
ci_clearselected();
if(flag == 0) then
if (bctype==0) then
ci_addmaterial("e" .. k, u2D1[n][k]);
else
ci_addmaterial("e" .. k, u2D0[n][k]);
end
ci_drawarc(x, y + r + d, x, y - r - d, 180, 1);
else
if (bctype==0) then
ci_addmaterial("e" .. k, uAx1[n][k]);
else
ci_addmaterial("e" .. k, uAx0[n][k]);
end
end
end
if (bctype==0) then
ci_addboundprop("V=0", 0, 0, 0, 0, 0, 0, 0, 0, 0);
ci_selectarcsegment(1.1*R+x, y);
if(flag == 0) then
ci_selectarcsegment(-1.1*R+x, y);
end
ci_setarcsegmentprop(1, "V=0", 0, 0);
ci_clearselected();
end
ci_zoomnatural();
end
--functions used to create asymptotic boundary conditions for heat flow problems
function hi_drawarc(x1,y1,x2,y2,tta,dtta)
hi_addnode(x1,y1);
hi_addnode(x2,y2);
hi_addarc(x1,y1,x2,y2,tta,dtta);
end
function hi_drawline(x1,y1,x2,y2)
hi_addnode(x1,y1);
hi_addnode(x2,y2);
hi_addsegment(x1,y1,x2,y2);
end
function hi_makeABC(enn,arr,ex,wye,bc)
local k, d, dp, z, r, x0, x1, y0, y1, flag, p1, p2, p3, x, y, R
x0, x1, y0, y1 = hi_getboundingbox();
flag, p1, p2, p3 = hi_getprobleminfo();
-- unpack parameters;
if (enn == nil) then
n=7;
else
if (enn>12) then
n=12;
elseif (enn<1) then
n=1;
else
n=enn;
end
end
if (bc == nil) then
if (flag == 0) then
-- if 2D, use Neumann-type BC by default
bctype=1;
else
-- if Axisymmetric, use Dirichlet-type BC by default
bctype=0;
end
else
bctype=bc;
end
if(flag == 0) then -- 2D planar case
if (arr == nil) then
R=(3/4)*abs((x0+I*y0)-(x1+I*y1));
else
R = arr;
end
if (ex == nil) then
x=(x0+x1)/2;
else
x=ex;
end
if (wye == nil) then
y=(y0+y1)/2;
else
y=wye;
end
else -- Axi case
x=0;
if (wye ~= nil) then
y=wye;
R=arr;
elseif (ex ~= nil) then
y=ex;
R=arr;
elseif (arr ~= nil) then
y=(y0+y1)/2;
R=arr;
else
y=(y0+y1)/2;
R=(3/2)*abs(x1+I*(y1-y0)/2);
end
end
-- draw left boundary of interior domain
if (flag == 0) then
hi_drawarc(x, y + R, x, y - R, 180, 1);
else
hi_drawline(0, y-1.1*R, 0, y+1.1*R);
end
-- draw right boundary of interior domain
hi_drawarc(x, y - R, x, y + R, 180, 1);
d = 0.1*R/(2*n);
for k = 1,n do
r = R*(1 + (2*k - 1)/(20*n));
hi_drawarc(x, y - r - d, x, y + r + d, 180, 1);
z = r*exp(I*(90/(n+1))*k*Pi/180);
hi_addblocklabel(x+re(z),y+im(z));
hi_selectlabel(x+re(z),y+im(z));
hi_setblockprop("e" .. k, 1, 0, "<None>", 0, 0, 1);
hi_clearselected();
if(flag == 0) then
if (bctype==0) then
hi_addmaterial("e" .. k, u2D1[n][k]);
else
hi_addmaterial("e" .. k, u2D0[n][k]);
end
hi_drawarc(x, y + r + d, x, y - r - d, 180, 1);
else
if (bctype==0) then
hi_addmaterial("e" .. k, uAx1[n][k]);
else
hi_addmaterial("e" .. k, uAx0[n][k]);
end
end
end
if (bctype==0) then
hi_addboundprop("V=0", 0, 0, 0, 0, 0, 0, 0, 0, 0);
hi_selectarcsegment(1.1*R+x, y);
if(flag == 0) then
hi_selectarcsegment(-1.1*R+x, y);
end
hi_setarcsegmentprop(1, "V=0", 0, 0);
hi_clearselected();
end
hi_zoomnatural();
end
-- convenience functions
function mi_drawrectangle(x1,y1,x2,y2)
mi_drawline(x1,y1,x2,y1);
mi_drawline(x2,y1,x2,y2);
mi_drawline(x2,y2,x1,y2);
mi_drawline(x1,y2,x1,y1);
end
function ei_drawrectangle(x1,y1,x2,y2)
ei_drawline(x1,y1,x2,y1);
ei_drawline(x2,y1,x2,y2);
ei_drawline(x2,y2,x1,y2);
ei_drawline(x1,y2,x1,y1);
end
function ci_drawrectangle(x1,y1,x2,y2)
ci_drawline(x1,y1,x2,y1);
ci_drawline(x2,y1,x2,y2);
ci_drawline(x2,y2,x1,y2);
ci_drawline(x1,y2,x1,y1);
end
function hi_drawrectangle(x1,y1,x2,y2)
hi_drawline(x1,y1,x2,y1);
hi_drawline(x2,y1,x2,y2);
hi_drawline(x2,y2,x1,y2);
hi_drawline(x1,y2,x1,y1);
end

412
debug/license.txt Normal file
View File

@ -0,0 +1,412 @@
Finite Element Method Magnetics is distributed under
the terms of the Aladdin Free Public License:
------------------------------------------------------
Aladdin Free Public License
(Version 8, November 18, 1999)
Copyright (C) 1994, 1995, 1997, 1998, 1999
Aladdin Enterprises,Menlo Park, California, U.S.A.
All rights reserved.
NOTE: This License is not the same as any of the GNU
Licenses published by the Free Software Foundation.
Its terms are substantially different from those of
the GNU Licenses. If you are familiar with the GNU
Licenses, please read this license with extra care.
Aladdin Enterprises hereby grants to anyone the
permission to apply this License to their own work,
as long as the entire License (including the above
notices and this paragraph) is copied with no
changes, additions, or deletions except for changing
the first paragraph of Section 0 to include a
suitable description of the work to which the
license is being applied and of the person or entity
that holds the copyright in the work, and, if the
License is being applied to a work created in a
country other than the United States, replacing the
first paragraph of Section 6 with an appropriate
reference to the laws of the appropriate country.
0. Subject Matter
This License applies to the computer program known
as "Finite Element Method Magnetics." The "Program",
below, refers to such program. The Program is a
copyrighted work whose copyright is held by David C.
Meeker of Natick, MA, dmeeker@ieee.org (the
"Licensor"). Please note that the program Triangle,
written by Jonathan Shewchuk and used by FEMM
for the purposes of mesh generation is NOT covered
by this license and is subject to its own licensure terms.
The licensure terms for Triangle are attached after
this license. The Lua scripting language used by
FEMM is also distributed under its own licensing
terms. The licensing terms of Lua are also attached.
A "work based on the Program" means either the
Program or any derivative work of the Program, as
defined in the United States Copyright Act of 1976,
such as a translation or a modification.
BY MODIFYING OR DISTRIBUTING THE PROGRAM (OR ANY
WORK BASED ON THE PROGRAM), YOU INDICATE YOUR
ACCEPTANCE OF THIS LICENSE TO DO SO, AND ALL ITS
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTING OR
MODIFYING THE PROGRAM OR WORKS BASED ON IT. NOTHING
OTHER THAN THIS LICENSE GRANTS YOU PERMISSION TO
MODIFY OR DISTRIBUTE THE PROGRAM OR ITS DERIVATIVE
WORKS. THESE ACTIONS ARE PROHIBITED BY LAW. IF YOU
DO NOT ACCEPT THESE TERMS AND CONDITIONS, DO NOT
MODIFY OR DISTRIBUTE THE PROGRAM.
1. Licenses.
Licensor hereby grants you the following rights,
provided that you comply with all of the
restrictions set forth in this License and provided,
further, that you distribute an unmodified copy of
this License with the Program:
(a) You may copy and distribute literal (i.e.,
verbatim) copies of the Program's source code as you
receive it throughout the world, in any medium.
(b) You may modify the Program, create works based
on the Program and distribute copies of such
throughout the world, in any medium.
2. Restrictions.
This license is subject to the following restrictions:
(a) Distribution of the Program or any work based on
the Program by a commercial organization to any
third party is prohibited if any payment is made in
connection with such distribution, whether directly
(as in payment for a copy of the Program) or
indirectly (as in payment for some service related
to the Program, or payment for some product or
service that includes a copy of the Program "without
charge"; these are only examples, and not an
exhaustive enumeration of prohibited activities).
The following methods of distribution involving
payment shall not in and of themselves be a
violation of this restriction:
(i) Posting the Program on a public access
information storage and retrieval service for
which a fee is received for retrieving
information (such as an on-line service),
provided that the fee is not content- dependent
(i.e., the fee would be the same for retrieving
the same volume of information consisting of
random data) and that access to the service and
to the Program is available independent of any
other product or service. An example of a
service that does not fall under this section
is an on-line service that is operated by a
company and that is only available to customers
of that company. (This is not an exhaustive
enumeration.)
(ii) Distributing the Program on removable
computer-readable media, provided that the
files containing the Program are reproduced
entirely and verbatim on such media, that all
information on such media be redistributable
for non-commercial purposes without charge, and
that such media are distributed by themselves
(except for accompanying documentation)
independent of any other product or service.
Examples of such media include CD-ROM, magnetic
tape, and optical storage media. (This is not
intended to be an exhaustive list.) An example
of a distribution that does not fall under this
section is a CD-ROM included in a book or
magazine. (This is not an exhaustive
enumeration.)
(b) Activities other than copying, distribution and
modification of the Program are not subject to this
License and they are outside its scope. Functional
use (running) of the Program is not restricted, and
any output produced through the use of the Program
is subject to this license only if its contents
constitute a work based on the Program (independent
of having been made by running the Program).
(c) You must meet all of the following conditions
with respect to any work that you distribute or
publish that in whole or in part contains or is
derived from the Program or any part thereof ("the
Work"):
(i) If you have modified the Program, you must cause
the Work to carry prominent notices stating
that you have modified the Program's files and
the date of any change. In each source file
that you have modified, you must include a
prominent notice that you have modified the
file, including your name, your e-mail address
(if any), and the date and purpose of the
change;
(ii) You must cause the Work to be licensed as a
whole and at no charge to all third parties
under the terms of this License;
(iii) If the Work normally reads commands
interactively when run, you must cause it, at
each time the Work commences operation, to
print or display an announcement including an
appropriate copyright notice and a notice that
there is no warranty (or else, saying that you
provide a warranty). Such notice must also
state that users may redistribute the Work only
under the conditions of this License and tell
the user how to view the copy of this License
included with the Work. (Exceptions: if the
Program is interactive but normally prints or
displays such an announcement only at the
request of a user, such as in an "About box",
the Work is required to print or display the
notice only under the same circumstances; if
the Program itself is interactive but does not
normally print such an announcement, the Work
is not required to print an announcement.);
(iv) You must accompany the Work with the complete
corresponding machine-readable source code,
delivered on a medium customarily used for
software interchange. The source code for a
work means the preferred form of the work for
making modifications to it. For an executable
work, complete source code means all the source
code for all modules it contains, plus any
associated interface definition files, plus the
scripts used to control compilation and
installation of the executable code. If you
distribute with the Work any component that is
normally distributed (in either source or
binary form) with the major components
(compiler, kernel, and so on) of the operating
system on which the executable runs, you must
also distribute the source code of that
component if you have it and are allowed to do
so;
(v) If you distribute any written or printed
material at all with the Work, such material
must include either a written copy of this
License, or a prominent written indication that
the Work is covered by this License and written
instructions for printing and/or displaying the
copy of the License on the distribution medium;
(vi) You may not impose any further restrictions on
the recipient's exercise of the rights granted
herein. If distribution of executable or
object code is made by offering the equivalent
ability to copy from a designated place, then
offering equivalent ability to copy the source
code from the same place counts as distribution
of the source code, even though third parties
are not compelled to copy the source code along
with the object code.
3. Reservation of Rights.
No rights are granted to the Program except as
expressly set forth herein. You may not copy,
modify, sublicense, or distribute the Program except
as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense or
distribute the Program is void, and will
automatically terminate your rights under this
License. However, parties who have received copies,
or rights, from you under this License will not have
their licenses terminated so long as such parties
remain in full compliance.
4. Other Restrictions.
If the distribution and/or use of the Program is
restricted in certain countries for any reason,
Licensor may add an explicit geographical
distribution limitation excluding those countries,
so that distribution is permitted only in or among
countries not thus excluded. In such case, this
License incorporates the limitation as if written in
the body of this License.
5. Limitations.
THE PROGRAM IS PROVIDED TO YOU "AS IS," WITHOUT
WARRANTY. THERE IS NO WARRANTY FOR THE PROGRAM,
EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. THE
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY
SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR
AGREED TO IN WRITING WILL LICENSOR, OR ANY OTHER
PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM
AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
LIMITED TO LOSS OF DATA OR DATA BEING RENDERED
INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH
ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
6. General.
This License is governed by the laws of the
Commonwealth of Massachusetts, U.S.A., excluding
choice of law rules.
If any part of this License is found to be in
conflict with the law, that part shall be
interpreted in its broadest meaning consistent with
the law, and no other parts of the License shall be
affected.
For United States Government users, the Program is
provided with RESTRICTED RIGHTS. If you are a unit
or agency of the United States Government or are
acquiring the Program for any such unit or agency,
the following apply:
If the unit or agency is the Department of Defense
("DOD"), the Program and its documentation are
classified as "commercial computer software" and
"commercial computer software documentation"
respectively and, pursuant to DFAR Section 227.7202,
the Government is acquiring the Program and its
documentation in accordance with the terms of this
License. If the unit or agency is other than DOD,
the Program and its documentation are classified as
"commercial computer software" and "commercial
computer software documentation" respectively and,
pursuant to FAR Section 12.212, the Government is
acquiring the Program and its documentation in
accordance with the terms of this License.
------------------------------------------------------
Triangle
A Two-Dimensional Quality Mesh Generator
and Delaunay Triangulator.
Version 1.3
Copyright 1996 Jonathan Richard Shewchuk
School of Computer Science
Carnegie Mellon University
5000 Forbes Avenue
Pittsburgh, Pennsylvania 15213-3891
Please send bugs and comments to jrs@cs.cmu.edu
Created as part of the Archimedes project (tools for
parallel FEM). Supported in part by NSF Grant
CMS-9318163 and an NSERC 1967 Scholarship. There is
no warranty whatsoever. Use at your own risk.
Triangle generates exact Delaunay triangulations,
constrained Delaunay triangulations, and quality
conforming Delaunay triangulations. The latter can
be generated with no small angles, and are thus
suitable for finite element analysis.
Information on the algorithms used by Triangle,
including complete references, can be found in the
comments at the beginning of the triangle.c source
file. Another listing of these references, with
PostScript copies of some of the papers, is available
from the Web page
http://www.cs.cmu.edu/~quake/triangle.research.html
[Triangle] may be freely redistributed under the
condition that the copyright notices (including the
copy of this notice in the code comments and the
copyright notice printed when the `-h' switch is
selected) are not removed, and no compensation is
received. Private, research, and institutional use
is free. You may distribute modified versions of
this code UNDER THE CONDITION THAT THIS CODE AND ANY
MODIFICATIONS MADE TO IT IN THE SAME FILE REMAIN
UNDER COPYRIGHT OF THE ORIGINAL AUTHOR, BOTH SOURCE
AND OBJECT CODE ARE MADE FREELY AVAILABLE WITHOUT
CHARGE, AND CLEAR NOTICE IS GIVEN OF THE
MODIFICATIONS. Distribution of this code as part of
a commercial system is permissible ONLY BY DIRECT
ARRANGEMENT WITH THE AUTHOR. (If you are not
directly supplying this code to a customer, and you
are instead telling them how they can obtain it for
free, then you are not required to make any
arrangement with [JRS].)
If you use Triangle, and especially if you use it to
accomplish real work, I would like very much to hear
from you. A short letter or email (to
jrs@cs.cmu.edu) describing how you use Triangle will
mean a lot to me. The more people I know are using
this program, the more easily I can justify spending
time on improvements and on the three-dimensional
successor to Triangle, which in turn will benefit
you. Also, I can put you on a list to receive email
whenever a new version of Triangle is available.
If you use a mesh generated by Triangle, please
include an acknowledgment as well.
Jonathan Richard Shewchuk
July 20, 1996
------------------------------------------------------
Lua Copyright Notice
Copyright © 1994-2000 TeCGraf, PUC-Rio. All rights reserved.
Permission is hereby granted, without written agreement
and without license or royalty fees, to use, copy, modify,
translate, and distribute this software and its documentation
(hereby called the "package") for any purpose, including
commercial applications, subject to the following conditions:
* The above copyright notice and this permission notice shall
appear in all copies or substantial portions of this package.
* The origin of this package must not be misrepresented;
you must not claim that you wrote the original package.
If you use this package in a product, an acknowledgment
in the product documentation would be greatly appreciated
(but it is not required).
* Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original package.
The authors specifically disclaim any warranties, including,
but not limited to, the implied warranties of merchantability
and fitness for a particular purpose. The package provided
hereunder is on an "as is" basis, and the authors have no
obligation to provide maintenance, support, updates,
enhancements, or modifications. In no event shall TeCGraf,
PUC-Rio, or the authors be held liable to any party for direct,
indirect, special, incidental, or consequential damages arising
out of the use of this package and its documentation.
The Lua language and this implementation have been entirely
designed and written by Waldemar Celes, Roberto Ierusalimschy
and Luiz Henrique de Figueiredo at TeCGraf, PUC-Rio in Brazil.
This implementation contains no third-party code.

2602
debug/matlib.dat Normal file

File diff suppressed because it is too large Load Diff

182
debug/statlib.dat Normal file
View File

@ -0,0 +1,182 @@
<BeginBlock>
<BlockName> = "Air"
<ex> = 1
<ey> = 1
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Delrin"
<ex> = 3.7000000000000002
<ey> = 3.7000000000000002
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Ethanol"
<ex> = 25
<ey> = 25
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Germanium"
<ex> = 16
<ey> = 16
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Kapton 100"
<ex> = 3.8999999999999999
<ey> = 3.8999999999999999
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Kapton 150"
<ex> = 2.8999999999999999
<ey> = 2.8999999999999999
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Lexan"
<ex> = 2.96
<ey> = 2.96
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Marble"
<ex> = 8
<ey> = 8
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Mica"
<ex> = 6
<ey> = 6
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Mylar"
<ex> = 3.2000000000000002
<ey> = 3.2000000000000002
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Nylon"
<ex> = 3.7999999999999998
<ey> = 3.7999999999999998
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Paper"
<ex> = 3
<ey> = 3
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Polyamide"
<ex> = 2.5
<ey> = 2.5
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Polyethylene LDPE/HDPE"
<ex> = 2.2999999999999998
<ey> = 2.2999999999999998
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Polypropylene"
<ex> = 2.2000000000000002
<ey> = 2.2000000000000002
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Polystyrene"
<ex> = 2.5
<ey> = 2.5
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Porcelain"
<ex> = 5.9000000000000004
<ey> = 5.9000000000000004
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "PVC"
<ex> = 3
<ey> = 3
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Pyrex"
<ex> = 4.7000000000000002
<ey> = 4.7000000000000002
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Rubber"
<ex> = 3
<ey> = 3
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Silicon"
<ex> = 12
<ey> = 12
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Teflon"
<ex> = 2.1000000000000001
<ey> = 2.1000000000000001
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Transformer Oil"
<ex> = 4.5
<ey> = 4.5
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Vinyl"
<ex> = 3
<ey> = 3
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Water@20C"
<ex> = 80.400000000000006
<ey> = 80.400000000000006
<qv> = 0
<EndBlock>
<BeginBlock>
<BlockName> = "Water@50C"
<ex> = 78.5
<ey> = 78.5
<qv> = 0
<EndBlock>

222
femm/ActiveFEMM.cpp Normal file
View File

@ -0,0 +1,222 @@
// ActiveFEMM.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "lua.h"
#include "luadebug.h"
#include "luaconsoledlg.h"
#include "ActiveFEMM.h"
#include "mainfrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern lua_State *lua;
extern BOOL bLinehook;
extern BOOL lua_byebye;
extern HANDLE hProc;
extern int m_luaWindowStatus;
extern CFemmApp theApp;
CString LuaResult;
/////////////////////////////////////////////////////////////////////////////
// ActiveFEMM
IMPLEMENT_DYNCREATE(ActiveFEMM, CCmdTarget)
ActiveFEMM::ActiveFEMM()
{
EnableAutomation();
EnableTypeLib();
// To keep the application running as long as an OLE automation
// object is active, the constructor calls AfxOleLockApp.
AfxOleLockApp();
lua_register(lua,"actxprint", lua_to_string);
lua_register(lua,"lua2matlab",lua_to_matlab);
}
ActiveFEMM::~ActiveFEMM()
{
// To terminate the application when all objects created with
// with OLE automation, the destructor calls AfxOleUnlockApp.
AfxOleUnlockApp();
}
void ActiveFEMM::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
// We have to close things in a funny way so that FEMM shuts down
// the way that it expects to. First, the call to AfxOleSetUserCtrl
// makes it so that the the application won't get closed when the
// base class version of OnFinalRelease gets called.
AfxOleSetUserCtrl(TRUE);
// Then, post a message to the main window requesting a shutdown.
// This is the way that FEMM likes to shut down. Since the message
// has been posted rather than sent, it will be acted upon after
// ActiveFEMM has shut itself down.
AfxGetMainWnd()->PostMessage(WM_CLOSE);
// Then, call the base class to shut down ActiveFEMM
CCmdTarget::OnFinalRelease();
}
BEGIN_MESSAGE_MAP(ActiveFEMM, CCmdTarget)
//{{AFX_MSG_MAP(ActiveFEMM)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(ActiveFEMM, CCmdTarget)
//{{AFX_DISPATCH_MAP(ActiveFEMM)
DISP_FUNCTION(ActiveFEMM, "call2femm", call2femm, VT_BSTR, VTS_BSTR)
DISP_FUNCTION(ActiveFEMM, "mlab2femm", mlab2femm, VT_BSTR, VTS_BSTR)
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
// {04EF434A-1A91-495A-85AA-C625602B4AF4}
static const GUID _tlid =
{ 0x04EF434A, 0x1A91, 0x495A, { 0x85, 0xAA, 0xC6, 0x25, 0x60, 0x2B, 0x4A, 0xF4 } };
const WORD _wVerMajor = 1;
const WORD _wVerMinor = 0;
IMPLEMENT_OLETYPELIB(ActiveFEMM, _tlid, _wVerMajor, _wVerMinor)
// Note: we add support for IID_IActiveFEMM to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {E08185B4-FEDF-4B1B-A88D-D40C97625060}
static const IID IID_IActiveFEMM =
{ 0xe08185b4, 0xfedf, 0x4b1b, { 0xa8, 0x8d, 0xd4, 0xc, 0x97, 0x62, 0x50, 0x60 } };
BEGIN_INTERFACE_MAP(ActiveFEMM, CCmdTarget)
INTERFACE_PART(ActiveFEMM, IID_IActiveFEMM, Dispatch)
END_INTERFACE_MAP()
// {0A35D5BD-DCA9-4C39-9512-1D89A1A37047}
IMPLEMENT_OLECREATE2(ActiveFEMM, "femm.ActiveFEMM", 0xa35d5bd, 0xdca9, 0x4c39, 0x95, 0x12, 0x1d, 0x89, 0xa1, 0xa3, 0x70, 0x47)
BOOL ActiveFEMM::GetDispatchIID(IID* pIID)
{
*pIID = IID_IActiveFEMM;
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// ActiveFEMM message handlers
BSTR ActiveFEMM::call2femm(LPCTSTR luacmd)
{
// executes the line contained in luacmd
// and returns a string containing the results
// of the command with the results separated
// by newline characters.
CString strToLua;
theApp.MatlabLoveNote.Empty();
strToLua=luacmd;
strToLua="actxprint(" + strToLua +")";
DoLuaCmd(strToLua);
// Returns the result of errors that are trapped
// via message boxes during a normal UI session
if(theApp.MatlabLoveNote.GetLength()>0)
{
LuaResult.Format("error: %s",theApp.MatlabLoveNote);
}
return LuaResult.AllocSysString();
}
BSTR ActiveFEMM::mlab2femm(LPCTSTR luacmd)
{
// executes the line contained in luacmd
// and returns a string containing the results
// of the command formatted in matlab format.
// One would expect that all the results are
// real numbers, in which case we can eval()
// the result in matlab to get a vector of numbers.
CString strToLua;
theApp.MatlabLoveNote.Empty();
strToLua=luacmd;
strToLua="lua2matlab(" + strToLua +")";
DoLuaCmd(strToLua);
// Returns the result of errors that are trapped
// via message boxes during a normal UI session
if(theApp.MatlabLoveNote.GetLength()>0)
{
LuaResult.Format("error: %s",theApp.MatlabLoveNote);
}
return LuaResult.AllocSysString();
}
void ActiveFEMM::DoLuaCmd(CString strToLua)
{
LuaResult.Empty();
if(m_luaWindowStatus==SW_SHOW) bLinehook=NormalLua;
else bLinehook=HiddenLua;
theApp.bActiveX=TRUE;
if (lua_dostring(lua,strToLua)!=0) LuaResult=theApp.LuaErrmsg;
theApp.bActiveX=FALSE;
lua_byebye=FALSE;
bLinehook=FALSE;
}
int ActiveFEMM::lua_to_string(lua_State *L)
{
CString s;
int n = lua_gettop(L);
LuaResult="";
for(int k=1;k<=n;k++)
{
s=lua_tostring(L,k);
LuaResult = LuaResult + s +"\n";
}
return 0;
}
int ActiveFEMM::lua_to_matlab(lua_State *L)
{
CString s;
int n = lua_gettop(L);
if(n>0){
LuaResult="[ ";
for(int k=1;k<=n;k++)
{
s=lua_tostring(L,k);
LuaResult = LuaResult + s + " ";
}
LuaResult += "]";
}
else LuaResult.Empty();
return 0;
}

69
femm/ActiveFEMM.h Normal file
View File

@ -0,0 +1,69 @@
#if !defined(AFX_ACTIVEFEMM_H__B28DBF46_5DAD_4398_AD40_58F1D7107DFA__INCLUDED_)
#define AFX_ACTIVEFEMM_H__B28DBF46_5DAD_4398_AD40_58F1D7107DFA__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ActiveFEMM.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// ActiveFEMM command target
class ActiveFEMM : public CCmdTarget
{
DECLARE_DYNCREATE(ActiveFEMM)
DECLARE_OLETYPELIB(ActiveFemm)
ActiveFEMM(); // protected constructor used by dynamic creation
// Attributes
public:
// Operations
public:
static int lua_to_string(lua_State *L);
static int lua_to_matlab(lua_State *L);
void DoLuaCmd(CString strToLua);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(ActiveFEMM)
public:
virtual void OnFinalRelease();
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~ActiveFEMM();
// Generated message map functions
//{{AFX_MSG(ActiveFEMM)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
DECLARE_OLECREATE(ActiveFEMM)
// Generated OLE dispatch map functions
//{{AFX_DISPATCH(ActiveFEMM)
afx_msg BSTR call2femm(LPCTSTR luacmd);
afx_msg BSTR mlab2femm(LPCTSTR luacmd);
//}}AFX_DISPATCH
DECLARE_DISPATCH_MAP()
DECLARE_INTERFACE_MAP()
virtual BOOL GetDispatchIID(IID* pIID);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_ACTIVEFEMM_H__B28DBF46_5DAD_4398_AD40_58F1D7107DFA__INCLUDED_)

75
femm/ArcDlg.cpp Normal file
View File

@ -0,0 +1,75 @@
// ArcDlg.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "ArcDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CArcDlg dialog
CArcDlg::CArcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CArcDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CArcDlg)
m_ArcAngle = 0.0;
m_MaxSeg = 0.0;
//}}AFX_DATA_INIT
}
void CArcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CArcDlg)
DDX_Control(pDX, IDC_ARCSEGBDRY, m_ArcSegBdry);
DDX_Text(pDX, IDC_ARCANGLE, m_ArcAngle);
DDV_MinMaxDouble(pDX, m_ArcAngle, 1., 180.);
DDX_Text(pDX, IDC_MAXSEG, m_MaxSeg);
DDV_MinMaxDouble(pDX, m_MaxSeg, 1.e-002, 10.);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_ARCANGLE, mIDC_ARCANGLE);
DDX_Control(pDX, IDC_MAXSEG, m_IDC_MAXSEG);
}
BEGIN_MESSAGE_MAP(CArcDlg, CDialog)
//{{AFX_MSG_MAP(CArcDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CArcDlg message handlers
BOOL CArcDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int i;
m_ArcSegBdry.AddString("<None>");
for(i=0;i<namelist.GetSize();i++)
m_ArcSegBdry.AddString(namelist[i]);
m_ArcSegBdry.SetCurSel(cursel);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CArcDlg::OnOK()
{
cursel=m_ArcSegBdry.GetCurSel();
CDialog::OnOK();
}

44
femm/ArcDlg.h Normal file
View File

@ -0,0 +1,44 @@
// ArcDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CArcDlg dialog
#include "afxwin.h"
class CArcDlg : public CDialog
{
// Construction
public:
CArcDlg(CWnd* pParent = NULL); // standard constructor
int cursel;
CArray<CString,CString&> namelist;
// Dialog Data
//{{AFX_DATA(CArcDlg)
enum { IDD = IDD_ARCDLG };
CComboBox m_ArcSegBdry;
double m_ArcAngle;
double m_MaxSeg;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CArcDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CArcDlg)
virtual BOOL OnInitDialog();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit mIDC_ARCANGLE, m_IDC_MAXSEG;
};

440
femm/BHData.cpp Normal file
View File

@ -0,0 +1,440 @@
// BHData.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "BHData.h"
#include "fullmatrix.h"
#include "BHPlot.h"
#include "BHDatafile.h"
#include <process.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBHData dialog
CBHData::CBHData(CWnd* pParent /*=NULL*/)
: CDialog(CBHData::IDD, pParent)
{
//{{AFX_DATA_INIT(CBHData)
m_Bdata = _T("");
m_Hdata = _T("");
m_BHname = _T("");
//}}AFX_DATA_INIT
logplot=FALSE;
}
void CBHData::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBHData)
DDX_Text(pDX, IDC_BDATA, m_Bdata);
DDX_Text(pDX, IDC_HDATA, m_Hdata);
DDX_Text(pDX, IDC_BHNAME, m_BHname);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_BDATA, m_IDC_BDATA);
DDX_Control(pDX, IDC_HDATA, m_IDC_HDATA);
}
BEGIN_MESSAGE_MAP(CBHData, CDialog)
//{{AFX_MSG_MAP(CBHData)
ON_BN_CLICKED(IDC_PLOT_BHCURVE, OnPlotBHcurve)
ON_BN_CLICKED(IDC_LOGPLOT_BHCURVE, OnLogPlotBHcurve)
ON_BN_CLICKED(IDC_READ_BHCURVE, OnReadBhcurve)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBHData message handlers
void CBHData::StripBHData()
{
int k;
char *buff,*nptr,*endptr;
double z;
B.RemoveAll();
H.RemoveAll();
BHpoints=0;
if((m_Bdata.GetLength()==0) || (m_Hdata.GetLength()==0)) return;
k=m_Bdata.GetLength()*2;
buff=(char *)calloc(k,sizeof(char));
strcpy(buff,m_Bdata);
nptr=buff;
while (sscanf(nptr,"%lf",&z)!=EOF){
z=strtod(nptr,&endptr );
if(nptr==endptr) nptr++; //catch special case
else nptr=endptr;
if(B.GetSize()>0){ // enforce monotonicity
if (z<=B[B.GetSize()-1])
break;
}
else if(z!=0) B.Add(0);
B.Add(z);
}
free(buff);
k=m_Hdata.GetLength()*2;
buff=(char *)calloc(k,sizeof(char));
strcpy(buff,m_Hdata);
nptr=buff;
while (sscanf(nptr,"%lf",&z)!=EOF){
z=strtod(nptr,&endptr );
if(nptr==endptr) nptr++;
else nptr=endptr;
if(H.GetSize()>0){
if (z<=H[H.GetSize()-1])
break;
}
else if(z!=0) H.Add(0);
H.Add(z);
}
BHpoints=(int) B.GetSize();
if ((int) H.GetSize()<BHpoints) BHpoints=(int) H.GetSize();
free(buff);
}
void CBHData::GetSlopes()
{
if (BHpoints==0) return; // catch trivial case;
CFullMatrix Z;
int i;
BOOL CurveOK=FALSE;
BOOL Smooth=FALSE;
double l1,l2;
double *bn,*hn;
Z.Create(BHpoints);
slope=(double *)calloc(BHpoints,sizeof(double));
bn=(double *)calloc(BHpoints,sizeof(double));
hn=(double *)calloc(BHpoints,sizeof(double));
while(CurveOK!=TRUE)
{
// make sure that the space for computing slopes is cleared out
Z.Wipe();
// impose natural BC on the `left'
l1=B[1]-B[0];
Z.M[0][0]=4./l1;
Z.M[0][1]=2./l1;
Z.b[0]=6.*(H[1]-H[0])/(l1*l1);
// impose natural BC on the `right'
int n=BHpoints;
l1=B[n-1]-B[n-2];
Z.M[n-1][n-1]=4./l1;
Z.M[n-1][n-2]=2./l1;
Z.b[n-1]=6.*(H[n-1]-H[n-2])/(l1*l1);
for(i=1;i<BHpoints-1;i++)
{
l1=B[i]-B[i-1];
l2=B[i+1]-B[i];
Z.M[i][i-1]=2./l1;
Z.M[i][i]=4.*(l1+l2)/(l1*l2);
Z.M[i][i+1]=2./l2;
Z.b[i]=6.*(H[i]-H[i-1])/(l1*l1) +
6.*(H[i+1]-H[i])/(l2*l2);
}
Z.GaussSolve();
for(i=0;i<BHpoints;i++) slope[i]=Z.b[i];
// now, test to see if there are any "bad" segments in there.
for(i=1,CurveOK=TRUE;i<BHpoints;i++)
{
double L,c0,c1,c2,d0,d1,u0,u1,X0,X1;
d0=slope[i-1];
d1=slope[i];
u0=H[i-1];
u1=H[i];
L=B[i]-B[i-1];
c0=d0;
c1= -(2.*(2.*d0*L + d1*L + 3.*u0 - 3.*u1))/(L*L);
c2= (3.*(d0*L + d1*L + 2.*u0 - 2.*u1))/(L*L*L);
X0=-1.;
X1=-1.;
u0=c1*c1-4.*c0*c2;
// check out degenerate cases
if(c2==0)
{
if(c1!=0) X0=-c0/c1;
}
else if(u0>0)
{
u0=sqrt(u0);
X0=-(c1 + u0)/(2.*c2);
X1=(-c1 + u0)/(2.*c2);
}
//now, see if we've struck gold!
if (((X0>=0.)&&(X0<=L))||((X1>=0.)&&(X1<=L)))
CurveOK=FALSE;
}
if(CurveOK!=TRUE) //remedial action
{
// Smooth out input points
// to get rid of rapid transitions;
// Uses a 3-point moving average
for(i=1;i<BHpoints-1;i++)
{
bn[i]=(B[i-1]+B[i]+B[i+1])/3.;
hn[i]=(H[i-1]+H[i]+H[i+1])/3.;
}
for(i=1;i<BHpoints-1;i++){
H[i]=hn[i];
B[i]=bn[i];
}
Smooth++;
}
}
free(bn);
free(hn);
// alert user if smoothing was required
// if(Smooth!=FALSE) MsgBox("Data was smoothed %i times\nto obtain a single-valued BH curve fit",Smooth);
return;
}
/*
void CBHData::GetSlopes()
{
if (BHpoints==0) return; // catch trivial case;
int i,bDone;
double m1,m2;
slope=(double *)calloc(BHpoints,sizeof(double));
do{
for(i=1;i<BHpoints-1;i++)
{
// calculate nominal slope of each intermediate knot
m1=(H[i]-H[i-1])/(B[i]-B[i-1]);
m2=(H[i+1]-H[i])/(B[i+1]-B[i]);
// average of the linear interpolation slope on either side of the knot
slope[i]=(m1+m2)/2.;
// check a sufficient condition for monotonicity.
bDone=TRUE;
if ((slope[i]>3.*m1) || (slope[i]>3.*m2))
{
H[i]=(8.*H[i]+H[i-1]+H[i+1])/10.;
B[i]=(8.*B[i]+B[i-1]+B[i+1])/10.;
bDone=FALSE;
}
}
}while(!bDone);
// do endpoints
slope[0]=(H[1]-H[0])/(B[1]-B[0]);
slope[i]=(H[i]-H[i-1])/(B[i]-B[i-1]);
return;
}
*/
double CBHData::GetH(double x)
{
double b,h,z,z2,l;
int i;
b=fabs(x);
if ((BHpoints==0) || (b==0)) return 0;
if(b>B[BHpoints-1])
return (H[BHpoints-1] + slope[BHpoints-1]*(b-B[BHpoints-1]));
for(i=0;i<BHpoints-1;i++)
if((b>=B[i]) && (b<=B[i+1])){
l=(B[i+1]-B[i]);
z=(b-B[i])/l;
z2=z*z;
h=(1.-3.*z2+2.*z2*z)*H[i] +
z*(1.-2.*z+z2)*l*slope[i] +
z2*(3.-2.*z)*H[i+1] +
z2*(z-1.)*l*slope[i+1];
return h;
}
return 0;
}
void CBHData::OnLogPlotBHcurve()
{
logplot=TRUE;
OnPlotBHcurve();
}
void CBHData::OnPlotBHcurve()
{
CBHPlot xyplot;
int i;
double b,db;
BOOL logscale=logplot;
logplot=FALSE;
slope=NULL;
UpdateData();
StripBHData();
if (BHpoints<3){
MsgBox("Must have at least 3 pairs of data points");
return;
}
// copy raw B-H data for plotting in comparison to
// splined (and possibly smoothed) curve
xyplot.NumPts=BHpoints;
xyplot.Pts=(CComplex *)calloc(BHpoints,sizeof(CComplex));
for(i=0;i<BHpoints;i++) xyplot.Pts[i]=H[i]+I*B[i];
GetSlopes();
// get path to femmplot that we will need to display
// the plot of the B-H curve...
CString comline=((CFemmApp *)AfxGetApp())->GetExecutablePath();
// Actually evaluate all the points on the line...
if(xyplot.Create(101,2)==FALSE){
free(slope);
return;
}
db=(B[BHpoints-1]-B[0])/100.;
for(i=0,b=B[0];i<=100;i++,b+=db)
{
xyplot.M[i][1]=b;
xyplot.M[i][0]=GetH(b);
}
sprintf(xyplot.lbls[0],"H, Amp/Meter");
sprintf(xyplot.lbls[1],"B, Tesla");
// Create the plot, send it to the clipboard, spawn viewer...
CMetaFileDC Meta;
Meta.CreateEnhanced(NULL,NULL,NULL,NULL);
xyplot.MakePlot(&Meta,logscale);
HENHMETAFILE hMeta=Meta.CloseEnhanced();
if (hMeta==NULL) MsgBox("No Handle...");
if (OpenClipboard()==FALSE)
MsgBox("Cannot access the Clipboard");
else{
EmptyClipboard();
if(SetClipboardData(CF_ENHMETAFILE,hMeta)==NULL)
{
MsgBox("Couldn't SetClipboardData");
}
CloseClipboard();
// fire up plot viewer;
// ((CFemmApp *)AfxGetApp())->CreateNewDocument(8);
// in this case call the external program rather than
// displaying in the window. Since dialog is running modal,
// it obscures the plotted BH curve--this is an annoying kludge.
char CommandLine[MAX_PATH];
sprintf(CommandLine,"%sfemmplot.exe", (const char *) ((CFemmApp *)AfxGetApp())->GetExecutablePath());
STARTUPINFO StartupInfo2 = {0};
PROCESS_INFORMATION ProcessInfo2;
StartupInfo2.cb = sizeof(STARTUPINFO);
CreateProcess(NULL,CommandLine, NULL, NULL, FALSE,0, NULL, NULL, &StartupInfo2, &ProcessInfo2);
CloseHandle(ProcessInfo2.hProcess);
CloseHandle(ProcessInfo2.hThread);
}
if (slope!=NULL) free(slope);
}
void CBHData::OnReadBhcurve()
{
// TODO: Add your control notification handler code here
CFileDialog *fname_dia;
CString infile;
fname_dia=new CFileDialog(
TRUE,
"dat | * ",
infile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"Two column text data file (*.dat) | *.dat; *.DAT | All Files (*.*) | *.*||",
NULL);
if(fname_dia->DoModal()==IDCANCEL){
delete[] fname_dia;
return;
}
infile=fname_dia->GetPathName();
delete[] fname_dia;
CBHDatafile dlg;
if(dlg.DoModal()==IDCANCEL) return;
// read in data from text file;
m_Bdata.Empty();
m_Hdata.Empty();
double bunits[]={1.,0.0001,0.1};
double hunits[]={1.,1000.,79.5775,79577.5};
char s[1024];
double b_in,h_in,b_off,h_off;
b_off=0;h_off=0;
FILE *fp=fopen(infile,"rt");
if (fp==NULL){
MsgBox("problem opening data file");
return;
}
do{
if(fgets(s,1024,fp)==NULL) break;
if(dlg.BHOrder==0) sscanf(s,"%lf %lf",&b_in,&h_in);
else sscanf(s,"%lf %lf",&h_in,&b_in);
b_in *= bunits[dlg.BUnits];
if ((b_off==0) && (b_in<0)) b_off=fabs(b_in);
b_in += b_off;
h_in *= hunits[dlg.HUnits];
if ((h_off==0) && (h_in<0)) h_off=fabs(h_in);
h_in += h_off;
sprintf(s,"%f\r\n",b_in); m_Bdata += s;
sprintf(s,"%f\r\n",h_in); m_Hdata += s;
} while(1>0);
SetDlgItemText(IDC_BDATA,m_Bdata);
SetDlgItemText(IDC_HDATA,m_Hdata);
fclose(fp);
if(h_off!=0){
sprintf(s,"Suggested Hc = %.0f A/m",h_off);
AfxMessageBox(s,MB_ICONINFORMATION);
}
}

53
femm/BHData.h Normal file
View File

@ -0,0 +1,53 @@
// BHData.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBHData dialog
#include <afxtempl.h>
#include "afxwin.h"
class CBHData : public CDialog
{
// Construction
public:
CBHData(CWnd* pParent = NULL); // standard constructor
CArray <double, double> B;
CArray <double, double> H;
int BHpoints;
double *slope;
BOOL logplot;
void StripBHData();
void GetSlopes();
double GetH(double x);
// Dialog Data
//{{AFX_DATA(CBHData)
enum { IDD = IDD_BHCURVE };
CString m_Bdata;
CString m_Hdata;
CString m_BHname;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBHData)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CBHData)
afx_msg void OnPlotBHcurve();
afx_msg void OnLogPlotBHcurve();
afx_msg void OnReadBhcurve();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_BDATA;
CLuaEdit m_IDC_HDATA;
};

136
femm/BHDatafile.cpp Normal file
View File

@ -0,0 +1,136 @@
// BHDatafile.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "BHDatafile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBHDatafile dialog
CBHDatafile::CBHDatafile(CWnd* pParent /*=NULL*/)
: CDialog(CBHDatafile::IDD, pParent)
{
//{{AFX_DATA_INIT(CBHDatafile)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CBHDatafile::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBHDatafile)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBHDatafile, CDialog)
//{{AFX_MSG_MAP(CBHDatafile)
ON_BN_CLICKED(IDC_AMPM, OnAmpm)
ON_BN_CLICKED(IDC_BFIRST, OnBfirst)
ON_BN_CLICKED(IDC_GAUSS, OnGauss)
ON_BN_CLICKED(IDC_KAMPM, OnKampm)
ON_BN_CLICKED(IDC_KGAUSS, OnKgauss)
ON_BN_CLICKED(IDC_KOERSTED, OnKoersted)
ON_BN_CLICKED(IDC_OERSTED, OnOersted)
ON_BN_CLICKED(IDC_TESLA, OnTesla)
ON_BN_CLICKED(IDC_HFIRST, OnHfirst)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBHDatafile message handlers
BOOL CBHDatafile::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
BHOrder=0;
BUnits=0;
HUnits=0;
CheckRadioButton(
IDC_BFIRST,// identifier of first radio button in group
IDC_HFIRST, // identifier of last radio button in group
IDC_BFIRST // identifier of radio button to select
);
CheckRadioButton(
IDC_TESLA,// identifier of first radio button in group
IDC_KGAUSS, // identifier of last radio button in group
IDC_TESLA // identifier of radio button to select
);
CheckRadioButton(
IDC_AMPM,// identifier of first radio button in group
IDC_KOERSTED, // identifier of last radio button in group
IDC_AMPM // identifier of radio button to select
);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBHDatafile::OnAmpm()
{
// TODO: Add your control notification handler code here
HUnits=0;
}
void CBHDatafile::OnBfirst()
{
// TODO: Add your control notification handler code here
BHOrder=0;
}
void CBHDatafile::OnGauss()
{
// TODO: Add your control notification handler code here
BUnits=1;
}
void CBHDatafile::OnKampm()
{
// TODO: Add your control notification handler code here
HUnits=1;
}
void CBHDatafile::OnKgauss()
{
// TODO: Add your control notification handler code here
BUnits=2;
}
void CBHDatafile::OnKoersted()
{
// TODO: Add your control notification handler code here
HUnits=3;
}
void CBHDatafile::OnOersted()
{
// TODO: Add your control notification handler code here
HUnits=2;
}
void CBHDatafile::OnTesla()
{
// TODO: Add your control notification handler code here
BUnits=0;
}
void CBHDatafile::OnHfirst()
{
// TODO: Add your control notification handler code here
BHOrder=1;
}

45
femm/BHDatafile.h Normal file
View File

@ -0,0 +1,45 @@
// BHDatafile.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBHDatafile dialog
class CBHDatafile : public CDialog
{
// Construction
public:
CBHDatafile(CWnd* pParent = NULL); // standard constructor
int BHOrder,BUnits,HUnits;
// Dialog Data
//{{AFX_DATA(CBHDatafile)
enum { IDD = IDD_BHDATAFILE };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBHDatafile)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CBHDatafile)
virtual BOOL OnInitDialog();
afx_msg void OnAmpm();
afx_msg void OnBfirst();
afx_msg void OnGauss();
afx_msg void OnKampm();
afx_msg void OnKgauss();
afx_msg void OnKoersted();
afx_msg void OnOersted();
afx_msg void OnTesla();
afx_msg void OnHfirst();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

217
femm/BdryDlg.cpp Normal file
View File

@ -0,0 +1,217 @@
// BdryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "BdryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBdryDlg dialog
CBdryDlg::CBdryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBdryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBdryDlg)
m_A0 = 0.0;
m_A1 = 0.0;
m_A2 = 0.0;
m_BdryName = _T("");
m_c0 = 0.0;
m_c1 = 0.0;
m_Mu = 0.0;
m_Phi = 0.0;
m_Sig = 0.0;
m_innerangle = 0.0;
m_outerangle = 0.0;
//}}AFX_DATA_INIT
}
void CBdryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBdryDlg)
DDX_Control(pDX, IDC_STATIC_SYMB3, m_static3);
DDX_Control(pDX, IDC_STATIC_SYMB2, m_static2);
DDX_Control(pDX, IDC_STATIC_SYMB1, m_static1);
DDX_Control(pDX, IDC_BDRYFORMAT, m_BdryFormat);
DDX_Text(pDX, IDC_A0, m_A0);
DDX_Text(pDX, IDC_A1, m_A1);
DDX_Text(pDX, IDC_A2, m_A2);
DDX_Text(pDX, IDC_BDRYNAME, m_BdryName);
DDX_Text(pDX, IDC_C0, m_c0);
DDX_Text(pDX, IDC_C1, m_c1);
DDX_Text(pDX, IDC_MU, m_Mu);
DDX_Text(pDX, IDC_PHI, m_Phi);
DDX_Text(pDX, IDC_SIGMA, m_Sig);
DDX_Text(pDX, IDC_INNERANGLE, m_innerangle);
DDX_Text(pDX, IDC_OUTERANGLE, m_outerangle);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_A0, m_IDC_A0);
DDX_Control(pDX, IDC_A1, m_IDC_A1);
DDX_Control(pDX, IDC_A2, m_IDC_A2);
DDX_Control(pDX, IDC_BDRYNAME, m_IDC_BDRYNAME);
DDX_Control(pDX, IDC_C0, m_IDC_c0);
DDX_Control(pDX, IDC_C1, m_IDC_c1);
DDX_Control(pDX, IDC_MU, m_IDC_Mu);
DDX_Control(pDX, IDC_PHI, m_IDC_Phi);
DDX_Control(pDX, IDC_SIGMA, m_IDC_Sig);
DDX_Control(pDX, IDC_INNERANGLE, m_IDC_INNERANGLE);
DDX_Control(pDX, IDC_OUTERANGLE, m_IDC_OUTERANGLE);
}
BEGIN_MESSAGE_MAP(CBdryDlg, CDialog)
//{{AFX_MSG_MAP(CBdryDlg)
ON_CBN_SELCHANGE(IDC_BDRYFORMAT, OnSelchangeBdryformat)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBdryDlg message handlers
void CBdryDlg::OnOK()
{
UpdateData();
for(int nn=0;nn<namelist.GetSize();nn++)
{
if (m_BdryName==namelist[nn]){
MsgBox("The name \"%s\" has already been used.\nSelect a different name for this property.",m_BdryName);
return;
}
}
BdryFormat=m_BdryFormat.GetCurSel();
CDialog::OnOK();
}
BOOL CBdryDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_BdryFormat.SetCurSel(BdryFormat);
OnSelchangeBdryformat();
symbfont.CreateFont(0, 0, 0, 0, FW_BOLD, TRUE, 0, 0, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, DEFAULT_PITCH | FF_DECORATIVE, "Symbol");
m_static1.SetFont(&symbfont);
m_static2.SetFont(&symbfont);
m_static3.SetFont(&symbfont);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBdryDlg::OnSelchangeBdryformat()
{
// 0 Prescribed A;
// 1 Small skin depth;
// 2 Mixed;
// 3 Strategic Dual Image;
// 4 Periodic;
// 5 Anti-periodic;
// 6 Periodic Air Gap;
// 7 Anti-periodic Air Gap;
switch(m_BdryFormat.GetCurSel())
{
case 0:
m_IDC_A0.EnableWindow(TRUE);
m_IDC_A1.EnableWindow(TRUE);
m_IDC_A2.EnableWindow(TRUE);
m_IDC_Phi.EnableWindow(TRUE);
m_IDC_c0.EnableWindow(FALSE);
m_IDC_c1.EnableWindow(FALSE);
m_IDC_Mu.EnableWindow(FALSE);
m_IDC_Sig.EnableWindow(FALSE);
m_IDC_INNERANGLE.EnableWindow(FALSE);
m_IDC_OUTERANGLE.EnableWindow(FALSE);
break;
case 1:
m_IDC_A0.EnableWindow(FALSE);
m_IDC_A1.EnableWindow(FALSE);
m_IDC_A2.EnableWindow(FALSE);
m_IDC_Phi.EnableWindow(FALSE);
m_IDC_c0.EnableWindow(FALSE);
m_IDC_c1.EnableWindow(FALSE);
m_IDC_Mu.EnableWindow(TRUE);
m_IDC_Sig.EnableWindow(TRUE);
m_IDC_INNERANGLE.EnableWindow(FALSE);
m_IDC_OUTERANGLE.EnableWindow(FALSE);
break;
case 2:
m_IDC_A0.EnableWindow(FALSE);
m_IDC_A1.EnableWindow(FALSE);
m_IDC_A2.EnableWindow(FALSE);
m_IDC_Phi.EnableWindow(FALSE);
m_IDC_c0.EnableWindow(TRUE);
m_IDC_c1.EnableWindow(TRUE);
m_IDC_Mu.EnableWindow(FALSE);
m_IDC_Sig.EnableWindow(FALSE);
m_IDC_INNERANGLE.EnableWindow(FALSE);
m_IDC_OUTERANGLE.EnableWindow(FALSE);
break;
case 6:
case 7:
m_IDC_A0.EnableWindow(FALSE);
m_IDC_A1.EnableWindow(FALSE);
m_IDC_A2.EnableWindow(FALSE);
m_IDC_Phi.EnableWindow(FALSE);
m_IDC_c0.EnableWindow(FALSE);
m_IDC_c1.EnableWindow(FALSE);
m_IDC_Mu.EnableWindow(FALSE);
m_IDC_Sig.EnableWindow(FALSE);
m_IDC_INNERANGLE.EnableWindow(TRUE);
m_IDC_OUTERANGLE.EnableWindow(TRUE);
break;
default:
m_IDC_A0.EnableWindow(FALSE);
m_IDC_A1.EnableWindow(FALSE);
m_IDC_A2.EnableWindow(FALSE);
m_IDC_Phi.EnableWindow(FALSE);
m_IDC_c0.EnableWindow(FALSE);
m_IDC_c1.EnableWindow(FALSE);
m_IDC_Mu.EnableWindow(FALSE);
m_IDC_Sig.EnableWindow(FALSE);
m_IDC_INNERANGLE.EnableWindow(FALSE);
m_IDC_OUTERANGLE.EnableWindow(FALSE);
break;
}
}

63
femm/BdryDlg.h Normal file
View File

@ -0,0 +1,63 @@
// BdryDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBdryDlg dialog
class CBdryDlg : public CDialog
{
// Construction
public:
CBdryDlg(CWnd* pParent = NULL); // standard constructor
int BdryFormat;
CArray<CString,CString&> namelist;
CFont symbfont;
// Dialog Data
//{{AFX_DATA(CBdryDlg)
enum { IDD = IDD_BDRYDLG };
CStatic m_static3;
CStatic m_static2;
CStatic m_static1;
CComboBox m_BdryFormat;
double m_A0;
double m_A1;
double m_A2;
CString m_BdryName;
CComplex m_c0;
CComplex m_c1;
double m_Mu;
double m_Phi;
double m_Sig;
double m_innerangle;
double m_outerangle;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBdryDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CBdryDlg)
virtual void OnOK();
virtual BOOL OnInitDialog();
afx_msg void OnSelchangeBdryformat();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_A0, m_IDC_A1, m_IDC_A2, m_IDC_BDRYNAME;
CLuaEdit m_IDC_c0, m_IDC_c1, m_IDC_Mu, m_IDC_Phi, m_IDC_Sig;
CLuaEdit m_IDC_INNERANGLE, m_IDC_OUTERANGLE;
};

39
femm/BendContourDlg.cpp Normal file
View File

@ -0,0 +1,39 @@
// BendContourDlg.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "BendContourDlg.h"
// CBendContourDlg dialog
IMPLEMENT_DYNAMIC(CBendContourDlg, CDialog)
CBendContourDlg::CBendContourDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBendContourDlg::IDD, pParent)
, m_angle(0)
, m_anglestep(1)
{
}
CBendContourDlg::~CBendContourDlg()
{
}
void CBendContourDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_BENDANGLE, m_angle);
DDV_MinMaxDouble(pDX, m_angle, -180, 180);
DDX_Text(pDX, IDC_BENDSEGMENT, m_anglestep);
DDV_MinMaxDouble(pDX, m_anglestep, 0, 180);
DDX_Control(pDX, IDC_BENDANGLE, m_IDC_angle);
DDX_Control(pDX, IDC_BENDSEGMENT, m_IDC_anglestep);
}
BEGIN_MESSAGE_MAP(CBendContourDlg, CDialog)
END_MESSAGE_MAP()
// CBendContourDlg message handlers

26
femm/BendContourDlg.h Normal file
View File

@ -0,0 +1,26 @@
#pragma once
// CBendContourDlg dialog
class CBendContourDlg : public CDialog
{
DECLARE_DYNAMIC(CBendContourDlg)
public:
CBendContourDlg(CWnd* pParent = NULL); // standard constructor
virtual ~CBendContourDlg();
// Dialog Data
enum { IDD = IDD_BENDCONTOUR };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
double m_angle;
double m_anglestep;
CLuaEdit m_IDC_angle;
CLuaEdit m_IDC_anglestep;
};

62
femm/BlockInt.cpp Normal file
View File

@ -0,0 +1,62 @@
// BlockInt.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "BlockInt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBlockInt dialog
CBlockInt::CBlockInt(CWnd* pParent /*=NULL*/)
: CDialog(CBlockInt::IDD, pParent)
{
//{{AFX_DATA_INIT(CBlockInt)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CBlockInt::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBlockInt)
DDX_Control(pDX, IDC_BINTTYPE, m_binttype);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBlockInt, CDialog)
//{{AFX_MSG_MAP(CBlockInt)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBlockInt message handlers
BOOL CBlockInt::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
binttype=0;
m_binttype.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBlockInt::OnOK()
{
// TODO: Add extra validation here
binttype=m_binttype.GetCurSel();
CDialog::OnOK();
}

38
femm/BlockInt.h Normal file
View File

@ -0,0 +1,38 @@
// BlockInt.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CBlockInt dialog
class CBlockInt : public CDialog
{
// Construction
public:
CBlockInt(CWnd* pParent = NULL); // standard constructor
int binttype;
// Dialog Data
//{{AFX_DATA(CBlockInt)
enum { IDD = IDD_BLOCKINT };
CComboBox m_binttype;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CBlockInt)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CBlockInt)
virtual BOOL OnInitDialog();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

2658
femm/CDRAWDOC.CPP Normal file

File diff suppressed because it is too large Load Diff

259
femm/CDRAWDOC.H Normal file
View File

@ -0,0 +1,259 @@
#include "cd_nosebl.h"
#include <afx.h>
#include <afxtempl.h>
#include "lua.h"
#include "luaconsoledlg.h"
#include "luadebug.h"
extern void lua_baselibopen (lua_State *L);
extern void lua_iolibopen (lua_State *L);
extern void lua_strlibopen (lua_State *L);
extern void lua_mathlibopen (lua_State *L);
extern void lua_dblibopen (lua_State *L);
extern CFemmApp theApp; //<DP>
// cdrawDoc.h : interface of the CcdrawDoc class
//
/////////////////////////////////////////////////////////////////////////////
class CcdrawDoc : public CDocument
{
protected: // create from serialization only
CcdrawDoc();
DECLARE_DYNCREATE(CcdrawDoc)
// Attributes
public:
// General problem attributes
double Precision;
double MinAngle;
int SmartMesh;
double Depth;
double Frequency;
int LengthUnits;
BOOL ProblemType;
BOOL Coords;
CString ProblemNote;
BOOL FirstDraw;
BOOL NoDraw;
// default behaviors
double d_prec;
double d_minangle;
double d_depth;
double d_frequency;
int d_coord;
int d_length;
int d_type;
CString BinDir;
// lists of nodes, segments, and block labels
CArray< cdrawdata::CNode, cdrawdata::CNode&> nodelist;
CArray< cdrawdata::CSegment, cdrawdata::CSegment&> linelist;
CArray< cdrawdata::CArcSegment, cdrawdata::CArcSegment&> arclist;
CArray< cdrawdata::CBlockLabel, cdrawdata::CBlockLabel&> blocklist;
// lists of nodes, segments, and block labels for undo purposes...
CArray< cdrawdata::CNode, cdrawdata::CNode&> undonodelist;
CArray< cdrawdata::CSegment, cdrawdata::CSegment&> undolinelist;
CArray< cdrawdata::CArcSegment, cdrawdata::CArcSegment&> undoarclist;
CArray< cdrawdata::CBlockLabel, cdrawdata::CBlockLabel&> undoblocklist;
// CArrays containing the mesh information
CArray< CPoint, CPoint&> meshline;
CArray< CPoint, CPoint&> greymeshline;
CArray< cdrawdata::CNode, cdrawdata::CNode&> meshnode;
// lists of properties
CArray< cdrawdata::CMaterialProp, cdrawdata::CMaterialProp& > blockproplist;
CArray< cdrawdata::CBoundaryProp, cdrawdata::CBoundaryProp& > lineproplist;
CArray< cdrawdata::CPointProp, cdrawdata::CPointProp& > nodeproplist;
CArray< cdrawdata::CCircuit, cdrawdata::CCircuit& > circproplist;
double extRo,extRi,extZo;
// Operations
public:
void UnselectAll();
double ShortestDistance(double p, double q, int segm);
BOOL AddNode(double x, double y, double d);
BOOL AddSegment(int n0, int n1, double tol=0);
BOOL AddSegment(int n0, int n1, cdrawdata::CSegment *parsegm, double tol=0);
BOOL AddArcSegment(cdrawdata::CArcSegment &asegm, double tol=0);
BOOL AddBlockLabel(double x, double y, double d);
BOOL AddNode(cdrawdata::CNode &node, double d);
BOOL AddSegment(CComplex p0, CComplex p1, cdrawdata::CSegment &segm, double tol=0);
BOOL AddArcSegment(CComplex p0, CComplex p1, cdrawdata::CArcSegment &asegm, double tol=0);
BOOL AddBlockLabel(cdrawdata::CBlockLabel &blabel, double d);
int ClosestNode(double x, double y);
int ClosestBlockLabel(double x, double y);
int ClosestSegment(double x, double y);
BOOL GetIntersection(int n0, int n1, int segm, double *xi, double *yi);
int ClosestArcSegment(double x, double y);
void GetCircle(cdrawdata::CArcSegment &asegm,CComplex &c, double &R);
int GetLineArcIntersection(cdrawdata::CSegment &seg, cdrawdata::CArcSegment &arc, CComplex *p);
int GetArcArcIntersection(cdrawdata::CArcSegment &arc1, cdrawdata::CArcSegment &arc2, CComplex *p);
double ShortestDistanceFromArc(CComplex p, cdrawdata::CArcSegment &arc);
void RotateMove(CComplex c, double t, int EditAction);
void TranslateMove(double dx, double dy, int EditAction);
void ScaleMove(double bx, double by, double sf, int EditAction);
void MirrorSelected(double x0, double y0, double x1, double y1, int ea);
void RotateCopy(CComplex c, double t, int ncopies, int EditAction);
void TranslateCopy(double dx, double dy, int ncopies, int EditAction);
BOOL DeleteSelectedNodes();
BOOL DeleteSelectedSegments();
BOOL DeleteSelectedArcSegments();
BOOL DeleteSelectedBlockLabels();
BOOL OpBlkDlg();
void OpNodeDlg();
void OpSegDlg();
void OpArcSegDlg();
void OpGrpDlg();
BOOL LoadMesh();
BOOL OnWritePoly();
BOOL FunnyOnWritePoly();
BOOL ReadDXF(CString fname, double DefTol=-1.);
BOOL WriteDXF(CString fname);
BOOL HasPeriodicBC();
BOOL CanCreateRadius(int n);
BOOL CreateRadius(int n, double r);
double LineLength(int i);
BOOL ScanPreferences();
void UpdateUndo();
void Undo();
void EnforcePSLG(); // makes sure that everything is kosher...
void EnforcePSLG(double tol);
void FancyEnforcePSLG(double tol);
BOOL SelectOrphans();
BOOL dxf_line_hook();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CcdrawDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
//}}AFX_VIRTUAL
// Implementation
public:
void initalise_lua();
static int lua_prob_def(lua_State *L);
static int luaSaveDocument(lua_State *L);
static int lua_create_mesh(lua_State *L);
static int lua_smartmesh(lua_State *L);
static int lua_purge_mesh(lua_State *L);
static int lua_show_mesh(lua_State *L);
static int lua_analyze(lua_State *L);
static int lua_runpost(lua_State *L);
static int lua_addnode(lua_State *L);
static int lua_addlabel(lua_State *L);
static int lua_addline(lua_State *L);
static int lua_addarc(lua_State *L);
static int lua_selectnode(lua_State *L);
static int lua_selectlabel(lua_State *L);
static int lua_selectsegment(lua_State *L);
static int lua_selectarcsegment(lua_State *L);
static int lua_clearselected(lua_State *L);
static int lua_setnodeprop(lua_State *L);
static int lua_setblockprop(lua_State *L);
static int lua_setsegmentprop(lua_State *L);
static int lua_setarcsegmentprop(lua_State *L);
static int lua_deleteselected(lua_State *L);
static int lua_deleteselectedsegments(lua_State *L);
static int lua_deleteselectednodes(lua_State *L);
static int lua_deleteselectedlabels(lua_State *L);
static int lua_deleteselectedarcsegments(lua_State *L);
static int lua_zoomout(lua_State *L);
static int lua_zoomnatural(lua_State *L);
static int lua_zoomin(lua_State *L);
static int lua_move_translate(lua_State *L);
static int lua_move_rotate(lua_State *L);
static int lua_copy_translate(lua_State *L);
static int lua_copy_rotate(lua_State *L);
static int lua_mirror(lua_State *L);
static int lua_scale(lua_State *L);
static int lua_addmatprop(lua_State *L);
static int lua_addpointprop(lua_State *L);
static int lua_addboundprop(lua_State *L);
static int lua_addcircuitprop(lua_State *L);
static int lua_delcircuitprop(lua_State *L);
static int lua_delpointprop(lua_State *L);
static int lua_delboundprop(lua_State *L);
static int lua_delmatprop(lua_State *L);
static int lua_seteditmode(lua_State *L);
static int lua_selectgroup(lua_State *L);
static int lua_zoom(lua_State *L);
static int lua_newdocument(lua_State *L);
static int lua_savebitmap(lua_State * L);
static int lua_modmatprop(lua_State *L);
static int lua_modboundprop(lua_State *L);
static int lua_modpointprop(lua_State *L);
static int lua_modcircprop(lua_State *L);
static int lua_exitpre(lua_State *L);
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,HBITMAP hBMP, HDC hDC);
static int lua_saveWMF(lua_State *L);
static int lua_updatewindow(lua_State *L);
static int lua_shownames(lua_State * L);
static int lua_showgrid(lua_State *L);
static int lua_hidegrid(lua_State *L);
static int lua_gridsnap(lua_State *L);
static int lua_setgrid(lua_State *L);
static int lua_switchfocus(lua_State *L);
static int lua_readdxf(lua_State *L);
static int lua_savedxf(lua_State *L);
static int luaResize(lua_State *L);
static int luaMinimize(lua_State *L);
static int luaMaximize(lua_State *L);
static int luaRestore(lua_State *L);
static int lua_defineouterspace(lua_State *L);
static int lua_attachouterspace(lua_State *L);
static int lua_detachouterspace(lua_State *L);
static int lua_attachdefault(lua_State *L);
static int lua_detachdefault(lua_State *L);
static int lua_createradius(lua_State *L);
static int lua_gettitle(lua_State *L);
static int lua_setgroup(lua_State *L);
static int lua_getmaterial(lua_State *L);
static int lua_getboundingbox(lua_State *L);
static int lua_getprobleminfo(lua_State *L);
static int lua_selectcircle(lua_State *L);
static int lua_selectrectangle(lua_State *L);
virtual ~CcdrawDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CcdrawDoc)
afx_msg void OnDefineProblem();
afx_msg void OnEditMatprops();
afx_msg void OnEditPtprops();
afx_msg void OnEditSegprops();
afx_msg void OnEditCircprops();
afx_msg void OnEditExterior();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
};
/////////////////////////////////////////////////////////////////////////////
char* StripKey(char *c);
char *ParseDbl(char *t, double *f);
char *ParseInt(char *t, int *f);

2827
femm/CDRAWLUA.CPP Normal file

File diff suppressed because it is too large Load Diff

424
femm/CD_PREF.CPP Normal file
View File

@ -0,0 +1,424 @@
// Pref.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include <afxdlgs.h>
#include "cd_Pref.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define SelColor clist[0]
#define MeshColor clist[1]
#define BlockColor clist[2]
#define LineColor clist[3]
#define GridColor clist[4]
#define NodeColor clist[5]
#define BackColor clist[6]
#define NameColor clist[7]
/////////////////////////////////////////////////////////////////////////////
// cdCPref dialog
cdCPref::cdCPref(CWnd* pParent /*=NULL*/)
: CDialog(cdCPref::IDD, pParent)
{
//{{AFX_DATA_INIT(cdCPref)
m_d_gridsize = 0.25;
m_d_pixels = 100.0;
m_d_prec = 1.e-8;
m_d_minangle = DEFAULT_MINIMUM_ANGLE;
m_d_depth = 1.0;
m_d_frequency = 60;
m_d_showgrid = TRUE;
m_d_snapgrid = FALSE;
m_d_showorigin = FALSE;
m_d_shownames = TRUE;
//}}AFX_DATA_INIT
s_action=0;
s_coord=0;
s_length=0;
s_type=0;
clist=(COLORREF *)calloc(16,sizeof(COLORREF));
clist[0]= dSelColor;
clist[1]= dMeshColor;
clist[2]= dBlockColor;
clist[3]= dLineColor;
clist[4]= dGridColor;
clist[5]= dNodeColor;
clist[6]= dBackColor;
clist[7]= dNameColor;
}
cdCPref::~cdCPref()
{
free(clist);
}
void cdCPref::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(cdCPref)
DDX_Control(pDX, IDC_CD_DCOLOR, m_d_color);
DDX_Control(pDX, IDC_CD_DTYPE, m_d_type);
DDX_Control(pDX, IDC_CD_DLENGTH, m_d_length);
DDX_Control(pDX, IDC_CD_DCOORD, m_d_coord);
DDX_Control(pDX, IDC_CD_DACTION, m_d_action);
DDX_Text(pDX, IDC_CD_DGRIDSIZE, m_d_gridsize);
DDX_Text(pDX, IDC_CD_DDEPTH2, m_d_depth);
DDX_Text(pDX, IDC_CD_DFREQUENCY, m_d_frequency);
DDX_Text(pDX, IDC_CD_DPIXELS, m_d_pixels);
DDX_Text(pDX, IDC_CD_DPREC, m_d_prec);
DDV_MinMaxDouble(pDX, m_d_prec, 1.e-016, 1.e-008);
DDX_Text(pDX, IDC_CD_DMINANGLE, m_d_minangle);
DDV_MinMaxDouble(pDX, m_d_minangle, 1., MINANGLE_MAX);
DDX_Check(pDX, IDC_CD_DSHOWGRID, m_d_showgrid);
DDX_Check(pDX, IDC_CD_DSNAPGRID, m_d_snapgrid);
DDX_Check(pDX, IDC_CD_SHOW_ORIGIN, m_d_showorigin);
DDX_Check(pDX, IDC_CD_SHOW_NAMES, m_d_shownames);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_CD_DGRIDSIZE, m_IDC_d_gridsize);
DDX_Control(pDX, IDC_CD_DPIXELS, m_IDC_d_pixels);
DDX_Control(pDX, IDC_CD_DPREC, m_IDC_d_prec);
DDX_Control(pDX, IDC_CD_DFREQUENCY, m_IDC_d_frequency);
DDX_Control(pDX, IDC_CD_DDEPTH2, m_IDC_d_depth);
}
BEGIN_MESSAGE_MAP(cdCPref, CDialog)
//{{AFX_MSG_MAP(cdCPref)
ON_BN_CLICKED(IDC_CD_MODBTN, OnModifyButton)
ON_BN_CLICKED(IDC_CD_RESTORE, OnRestoreColors)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// cdCPref message handlers
void cdCPref::OnModifyButton()
{
CColorDialog dlg;
int i;
UpdateData();
i=m_d_color.GetCurSel();
dlg.m_cc.lpCustColors=clist;
dlg.m_cc.rgbResult=clist[i];
dlg.m_cc.Flags=dlg.m_cc.Flags | CC_FULLOPEN | CC_RGBINIT;
if(dlg.DoModal()==IDOK){
clist[i]=dlg.GetColor();
}
else{
}
}
BOOL cdCPref::OnInitDialog()
{
CDialog::OnInitDialog();
ScanPrefs();
m_d_action.SetCurSel(s_action);
m_d_coord.SetCurSel(s_coord);
m_d_length.SetCurSel(s_length);
m_d_type.SetCurSel(s_type);
m_d_color.SetCurSel(0);
UpdateData(FALSE);
return TRUE;
}
void cdCPref::OnOK()
{
UpdateData();
s_action=m_d_action.GetCurSel();
s_coord=m_d_coord.GetCurSel();
s_length=m_d_length.GetCurSel();
s_type=m_d_type.GetCurSel();
CDialog::OnOK();
}
void cdCPref::OnRestoreColors()
{
if(AfxMessageBox("Reset all color preferences?",MB_OKCANCEL)==IDOK)
{
clist[0]= dSelColor;
clist[1]= dMeshColor;
clist[2]= dBlockColor;
clist[3]= dLineColor;
clist[4]= dGridColor;
clist[5]= dNodeColor;
clist[6]= dBackColor;
clist[7]= dNameColor;
}
}
BOOL cdCPref::PreTranslateMessage(MSG* pMsg)
{
// Pressing ENTER should reroute message to parent
if( (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_RETURN) )
{
GetParent()->PostMessage(WM_KEYDOWN, VK_RETURN, 0);
// Message needs no further processing
return TRUE;
}
// Pressing ESC should reroute message to parent
if( (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_ESCAPE) )
{
GetParent()->PostMessage(WM_KEYDOWN, VK_ESCAPE, 0);
// Message needs no further processing
return TRUE;
}
// Allow default handler otherwise
return CDialog::PreTranslateMessage(pMsg);
}
char* StripKey(char *c);
void cdCPref::ScanPrefs()
{
FILE *fp;
CString fname = ((CFemmApp *)AfxGetApp())->GetExecutablePath() + "cdraw.cfg";
fp=fopen(fname,"rt");
if (fp!=NULL)
{
BOOL flag=FALSE;
char s[1024];
char q[1024];
char *v;
int cr,cg,cb;
// parse the file
while (fgets(s,1024,fp)!=NULL)
{
sscanf(s,"%s",q);
if( _strnicmp(q,"<Precision>",11)==0)
{
v=StripKey(s);
sscanf(v,"%lf",&m_d_prec);
q[0]=NULL;
}
if( _strnicmp(q,"<MinAngle>",10)==0)
{
v=StripKey(s);
sscanf(v,"%lf",&m_d_minangle);
q[0]=NULL;
}
if( _strnicmp(q,"<Depth>",7)==0)
{
v=StripKey(s);
sscanf(v,"%lf",&m_d_depth);
q[0]=NULL;
}
if( _strnicmp(q,"<Frequency>",11)==0)
{
v=StripKey(s);
sscanf(v,"%lf",&m_d_frequency);
q[0]=NULL;
}
if( _strnicmp(q,"<Coordinates>",13)==0)
{
v=StripKey(s);
sscanf(v,"%i",&s_coord);
q[0]=NULL;
}
if( _strnicmp(q,"<LengthUnits>",13)==0)
{
v=StripKey(s);
sscanf(v,"%i",&s_length);
q[0]=NULL;
}
if( _strnicmp(q,"<ProblemType>",13)==0)
{
v=StripKey(s);
sscanf(v,"%i",&s_type);
q[0]=NULL;
}
sscanf(s,"%s",q);
if( _strnicmp(q,"<SelColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
SelColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<BkgndColor>",12)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
BackColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<MeshColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
MeshColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<BlockColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
BlockColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<LineColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
LineColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<GridColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
GridColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<NodeColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
NodeColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<NameColor>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i %i %i",&cr,&cg,&cb);
NameColor=RGB(cr,cg,cb);
q[0]=NULL;
}
if( _strnicmp(q,"<EditAction>",12)==0)
{
v=StripKey(s);
sscanf(v,"%i",&s_action);
q[0]=NULL;
}
if( _strnicmp(q,"<PixelsPerUnit>",15)==0)
{
v=StripKey(s);
sscanf(v,"%lf",&m_d_pixels);
q[0]=NULL;
}
if( _strnicmp(q,"<GridSize>",10)==0)
{
v=StripKey(s);
sscanf(v,"%lf",&m_d_gridsize);
q[0]=NULL;
}
if( _strnicmp(q,"<ShowGrid>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i",&m_d_showgrid);
q[0]=NULL;
}
if( _strnicmp(q,"<ShowOrigin>",12)==0)
{
v=StripKey(s);
sscanf(v,"%i",&m_d_showorigin);
q[0]=NULL;
}
if( _strnicmp(q,"<SnapGrid>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i",&m_d_snapgrid);
q[0]=NULL;
}
if( _strnicmp(q,"<ShowNames>",10)==0)
{
v=StripKey(s);
sscanf(v,"%i",&m_d_shownames);
q[0]=NULL;
}
}
fclose(fp);
}
}
void WriteColor(char *cname, COLORREF c,FILE *fp);
void cdCPref::WritePrefs()
{
FILE *fp;
CString fname;
UpdateData();
s_action=m_d_action.GetCurSel();
s_coord=m_d_coord.GetCurSel();
s_length=m_d_length.GetCurSel();
s_type=m_d_type.GetCurSel();
fname=((CFemmApp *)AfxGetApp())->GetExecutablePath()+"cdraw.cfg";
fp=fopen(fname,"wt");
if (fp!=NULL)
{
WriteColor("SelColor",SelColor,fp);
WriteColor("BkgndColor",BackColor,fp);
WriteColor("MeshColor",MeshColor,fp);
WriteColor("BlockColor",BlockColor,fp);
WriteColor("LineColor",LineColor,fp);
WriteColor("GridColor",GridColor,fp);
WriteColor("NodeColor",NodeColor,fp);
WriteColor("NameColor",NameColor,fp);
fprintf(fp,"<EditAction> = %i\n",s_action);
fprintf(fp,"<PixelsPerUnit> = %g\n",m_d_pixels);
fprintf(fp,"<GridSize> = %g\n",m_d_gridsize);
fprintf(fp,"<ShowGrid> = %i\n",m_d_showgrid);
fprintf(fp,"<SnapGrid> = %i\n",m_d_snapgrid);
fprintf(fp,"<ShowNames> = %i\n",m_d_shownames);
fprintf(fp,"<ShowOrigin> = %i\n",m_d_showorigin);
fprintf(fp,"<ProblemType> = %i\n",s_type);
fprintf(fp,"<LengthUnits> = %i\n",s_length);
fprintf(fp,"<Precision> = %g\n",m_d_prec);
fprintf(fp,"<MinAngle> = %g\n",m_d_minangle);
fprintf(fp,"<Depth> = %g\n",m_d_depth);
fprintf(fp,"<Frequency> = %g\n",m_d_frequency);
fprintf(fp,"<Coordinates> = %i\n",s_coord);
fclose(fp);
}
}

69
femm/CD_PREF.H Normal file
View File

@ -0,0 +1,69 @@
// cd_Pref.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// cdCPref dialog
class cdCPref : public CDialog
{
// Construction
public:
cdCPref(CWnd* pParent = NULL); // standard constructor
~cdCPref();
COLORREF *clist;
int s_action;
int s_coord;
int s_length;
int s_type;
void ScanPrefs();
void WritePrefs();
// Dialog Data
//{{AFX_DATA(cdCPref)
enum { IDD = IDD_CD_PREF };
CComboBox m_d_color;
CComboBox m_d_type;
CComboBox m_d_length;
CComboBox m_d_coord;
CComboBox m_d_action;
double m_d_gridsize;
double m_d_pixels;
double m_d_prec;
double m_d_minangle;
double m_d_depth;
double m_d_frequency;
BOOL m_d_showgrid;
BOOL m_d_snapgrid;
BOOL m_d_showorigin;
BOOL m_d_shownames;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(cdCPref)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(cdCPref)
afx_msg void OnModifyButton();
virtual BOOL OnInitDialog();
virtual void OnOK();
afx_msg void OnRestoreColors();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_d_gridsize, m_IDC_d_depth,m_IDC_d_frequency;
CLuaEdit m_IDC_d_pixels, m_IDC_d_prec, m_IDC_d_minangle;
};

140
femm/COMPLEX.H Normal file
View File

@ -0,0 +1,140 @@
#ifndef CCOMPLEX
#define CCOMPLEX
#define PI 3.141592653589793238462643383
#define SmallNo 1.e-14
#define DEG 0.01745329251994329576923690768
class CComplex
{
public:
// data members
double re,im;
// member functions
CComplex();
CComplex(double x);
CComplex(int x);
CComplex(double x, double y);
CComplex Sqrt();
CComplex Conj();
CComplex Inv();
void Set(double x, double y);
double Abs();
double Arg();
double Re();
double Im();
char* ToString(char *s);
char* ToStringAlt(char *s);
//operator redefinition
//Addition
CComplex operator+( const CComplex& z );
CComplex operator+(double z);
CComplex operator+(int z);
friend CComplex operator+( int x, const CComplex& y );
friend CComplex operator+( double x, const CComplex& y );
friend CComplex operator+( const CComplex& x, const CComplex& y );
void operator+=( const CComplex& z);
void operator+=(double z);
void operator+=(int z);
//Subtraction
CComplex operator-();
CComplex operator-( const CComplex& z );
CComplex operator-(double z);
CComplex operator-(int z);
friend CComplex operator-( int x, const CComplex& y );
friend CComplex operator-( double x, const CComplex& y );
friend CComplex operator-( const CComplex& x, const CComplex& y );
friend CComplex operator-( const CComplex& x );
void operator-=( const CComplex& z);
void operator-=(double z);
void operator-=(int z);
//Multiplication
CComplex operator*( const CComplex& z );
CComplex operator*(double z);
CComplex operator*(int z);
friend CComplex operator*( int x, const CComplex& y );
friend CComplex operator*( double x, const CComplex& y );
friend CComplex operator*( const CComplex& x, const CComplex& y );
void operator*=( const CComplex& z);
void operator*=(double z);
void operator*=(int z);
//Division
CComplex operator/( const CComplex& z );
CComplex operator/(double z);
CComplex operator/(int z);
friend CComplex operator/( int x, const CComplex& y );
friend CComplex operator/( double x, const CComplex& y );
friend CComplex operator/( const CComplex &x, const CComplex& y );
void operator/=( const CComplex& z);
void operator/=(double z);
void operator/=(int z);
//Equals
void operator=(double z);
void operator=(int z);
//Tests
bool operator==( const CComplex& z);
bool operator==(double z);
bool operator==(int z);
bool operator!=( const CComplex& z);
bool operator!=(double z);
bool operator!=(int z);
bool operator<( const CComplex& z);
bool operator<( double z);
bool operator<( int z);
bool operator<=( const CComplex& z);
bool operator<=( double z);
bool operator<=( int z);
bool operator>( const CComplex& z);
bool operator>( double z);
bool operator>( int z);
bool operator>=( const CComplex& z);
bool operator>=( double z);
bool operator>=( int z);
private:
};
// useful functions...
#define I CComplex(0,1)
double Re( const CComplex& a);
double Im( const CComplex& a);
double abs( const CComplex& x );
double absq( const CComplex& x );
double arg( const CComplex& x );
CComplex conj( const CComplex& x);
CComplex exp( const CComplex& x );
CComplex sqrt( const CComplex& x );
CComplex tanh( const CComplex& x );
CComplex sinh( const CComplex& x );
CComplex cosh( const CComplex& x );
CComplex cos( const CComplex& x );
CComplex acos( const CComplex& x );
CComplex sin( const CComplex& x );
CComplex asin( const CComplex& x );
CComplex tan( const CComplex& x );
CComplex atan( const CComplex& x );
CComplex atan2( const CComplex& y, const CComplex& x);
CComplex log( const CComplex& x );
CComplex pow( const CComplex& x, int y);
CComplex pow( const CComplex& x, double y);
CComplex pow( const CComplex& x, const CComplex& y);
CComplex Chop( const CComplex& a, double tol=1.e-12);
#endif // CCOMPLEX check

67
femm/CPlotDlg.cpp Normal file
View File

@ -0,0 +1,67 @@
// CPlotDlg.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "CPlotDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCPlotDlg dialog
CCPlotDlg::CCPlotDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCPlotDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCPlotDlg)
m_numcontours = 0;
m_showai = FALSE;
m_showar = FALSE;
m_ahigh = 0.0;
m_alow = 0.0;
m_showmask = FALSE;
//}}AFX_DATA_INIT
}
void CCPlotDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCPlotDlg)
DDX_Text(pDX, IDC_NUMCONTOURS, m_numcontours);
DDV_MinMaxInt(pDX, m_numcontours, 4, 999);
DDX_Check(pDX, IDC_SHOW_A_IM, m_showai);
DDX_Check(pDX, IDC_SHOW_A_RE, m_showar);
DDX_Text(pDX, IDC_AHIGH, m_ahigh);
DDX_Text(pDX, IDC_ALOW, m_alow);
DDX_Check(pDX, IDC_SHOW_MASK1, m_showmask);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_NUMCONTOURS, m_IDC_numcontours);
DDX_Control(pDX, IDC_AHIGH, m_IDC_ahigh);
DDX_Control(pDX, IDC_ALOW, m_IDC_alow);
}
BEGIN_MESSAGE_MAP(CCPlotDlg, CDialog)
//{{AFX_MSG_MAP(CCPlotDlg)
ON_BN_CLICKED(IDC_DFLT1, OnDflt1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCPlotDlg message handlers
void CCPlotDlg::OnDflt1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_alow=Alb;
m_ahigh=Aub;
m_numcontours=19;
UpdateData(FALSE);
}

43
femm/CPlotDlg.h Normal file
View File

@ -0,0 +1,43 @@
// CPlotDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CCPlotDlg dialog
class CCPlotDlg : public CDialog
{
// Construction
public:
CCPlotDlg(CWnd* pParent = NULL); // standard constructor
double Alb,Aub;
// Dialog Data
//{{AFX_DATA(CCPlotDlg)
enum { IDD = IDD_CPLOTDLG };
int m_numcontours;
BOOL m_showai;
BOOL m_showar;
double m_ahigh;
double m_alow;
BOOL m_showmask;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCPlotDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCPlotDlg)
afx_msg void OnDflt1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_numcontours, m_IDC_ahigh, m_IDC_alow;
};

2478
femm/CVIEWDOC.CPP Normal file

File diff suppressed because it is too large Load Diff

219
femm/CVIEWDOC.H Normal file
View File

@ -0,0 +1,219 @@
// cviewDoc.h : interface of the CcviewDoc class
//
/////////////////////////////////////////////////////////////////////////////
#include "lua.h"
#include "luadebug.h"
#include "luaconsoledlg.h"
extern CFemmApp theApp; //<DP>
extern void lua_baselibopen (lua_State *L);
extern void lua_iolibopen (lua_State *L);
extern void lua_strlibopen (lua_State *L);
extern void lua_mathlibopen (lua_State *L);
extern void lua_dblibopen (lua_State *L);
class CcviewDoc : public CDocument
{
protected: // create from serialization only
CcviewDoc();
DECLARE_DYNCREATE(CcviewDoc)
// Attributes
public:
// General problem attributes
double Depth;
double Frequency;
int LengthUnits;
double *LengthConv;
BOOL ProblemType;
BOOL Coords;
CString ProblemNote;
BOOL FirstDraw;
BOOL Smooth;
BOOL bMultiplyDefinedLabels;
double extRo, extRi, extZo;
double A_High, A_Low;
CComplex A_lb, A_ub;
double d_PlotBounds[9][2];
double PlotBounds[9][2];
// Some default behaviors
CString BinDir;
int d_LineIntegralPoints;
BOOL bHasMask;
// lists of nodes, segments, and block labels
CArray< cviewtype::CNode, cviewtype::CNode&> nodelist;
CArray< cviewtype::CSegment, cviewtype::CSegment&> linelist;
CArray< cviewtype::CBlockLabel, cviewtype::CBlockLabel&> blocklist;
CArray< cviewtype::CArcSegment, cviewtype::CArcSegment&> arclist;
// CArrays containing the mesh information
CArray< cviewtype::CMeshNode, cviewtype::CMeshNode&> meshnode;
CArray< cviewtype::CElement, cviewtype::CElement&> meshelem;
// List of elements connected to each node;
int *NumList;
int **ConList;
// lists of properties
CArray< cviewtype::CMaterialProp, cviewtype::CMaterialProp& > blockproplist;
CArray< cviewtype::CBoundaryProp, cviewtype::CBoundaryProp& > lineproplist;
CArray< cviewtype::CPointProp, cviewtype::CPointProp& > nodeproplist;
CArray< cviewtype::CCircuit, cviewtype::CCircuit& > circproplist;
// list of points in a user-defined contour;
CArray< CComplex, CComplex& > contour;
// member functions
int InTriangle(double x, double y);
BOOL InTriangleTest(double x, double y, int i);
BOOL GetPointValues(double x, double y, cviewtype::CPointVals &u);
BOOL GetPointValues(double x, double y, int k, cviewtype::CPointVals &u);
void GetLineValues(CXYPlot &p, int PlotType, int npoints);
void GetElementJ(int k);
void OnReload();
int ClosestNode(double x, double y);
CComplex Ctr(int i);
double ElmArea(int i);
double ElmArea(cviewtype::CElement *elm);
void GetPointJ(double x, double y, CComplex &xZ, CComplex &yZ, cviewtype::CElement &elm);
void GetNodalJ(CComplex *xz, CComplex *yz, int i);
CComplex BlockIntegral(int inttype);
void LineIntegral(int inttype, CComplex *z);
int ClosestArcSegment(double x, double y);
void GetCircle(cviewtype::CArcSegment &asegm,CComplex &c, double &R);
double ShortestDistanceFromArc(CComplex p, cviewtype::CArcSegment &arc);
double ShortestDistanceFromSegment(double p, double q, int segm);
double ShortestDistance(double p, double q, int segm);
int ClosestSegment(double x, double y);
BOOL IsSameMaterial(int e1, int e2);
double AECF(int k);
double AECF(int k, CComplex p);
BOOL ScanPreferences();
void BendContour(double angle, double anglestep);
BOOL MakeMask();
CComplex HenrotteVector(int k);
BOOL IsKosher(int k);
void FindBoundaryEdges();
// CComplex E(int k);
// CComplex D(int k);
// CComplex e(int k, int i);
// CComplex d(int k, int i);
/* // Tests for whether or not one is inside a user-defined
// contour; this was really mostly used pre- v3.0, when
// the areas over which block integrals were taken were
// defined by a closed, user-generated contour.
BOOL ContourClosed();
BOOL SlowInContour(double x, double y);
BOOL InContour(double x, double y);
BOOL InContour(CElement &elm);
BOOL InContour(CComplex p);
BOOL OnContour(CElement &elm);
void AvgMaxwell(double &fx, double &fy);
void AvgMaxwell(double &fx, double &fy,
CComplex &f2x, CComplex &f2y);
*/
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CcviewDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
//}}AFX_VIRTUAL
// Implementation
public:
// lua extensions
bool luafired;
void initalise_lua();
static int lua_dumpheader(lua_State * L);
static int lua_getpointvals(lua_State * L);
static int lua_exitpost(lua_State * L);
static int lua_addcontour(lua_State * L);
static int lua_clearcontour(lua_State * L);
static int lua_lineintegral(lua_State * L);
static int lua_selectblock(lua_State * L);
static int lua_groupselectblock(lua_State * L);
static int lua_blockintegral(lua_State * L);
static int lua_clearblock(lua_State * L);
static int lua_zoomout(lua_State * L);
static int lua_zoomin(lua_State * L);
static int lua_zoomnatural(lua_State * L);
static int lua_hidemesh(lua_State * L);
static int lua_showmesh(lua_State * L);
static int lua_showgrid(lua_State * L);
static int lua_hidegrid(lua_State * L);
static int lua_showdensity(lua_State * L);
static int lua_hidedensity(lua_State * L);
static int lua_hidecountour(lua_State * L);
static int lua_showcountour(lua_State * L);
static int lua_zoom(lua_State * L);
static int lua_smoothing(lua_State * L);
static int lua_hidepoints(lua_State * L);
static int lua_showpoints(lua_State * L);
static int lua_gridsnap(lua_State * L);
static int lua_setgrid(lua_State * L);
static int lua_getprobleminfo(lua_State * L);
static int lua_savebitmap(lua_State * L);
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,HBITMAP hBMP, HDC hDC) ;
static int lua_getcircuitprops(lua_State *L);
static int lua_saveWMF(lua_State *L);
static int lua_refrescview(lua_State *L);
static int lua_selectline(lua_State *L);
static int lua_seteditmode(lua_State *L);
static int lua_bendcontour(lua_State *L);
static int lua_makeplot(lua_State *L);
static int lua_unselectall(lua_State *L);
static int lua_selectconductor(lua_State *L);
static int lua_shownames(lua_State * L);
static int lua_vectorplot(lua_State * L);
static int lua_reload(lua_State *L);
static int lua_switchfocus(lua_State *L);
static int luaResize(lua_State *L);
static int luaMinimize(lua_State *L);
static int luaMaximize(lua_State *L);
static int luaRestore(lua_State *L);
static int lua_gettitle(lua_State *L);
// commands to access low-level information through Lua
static int lua_numnodes(lua_State *L);
static int lua_numelements(lua_State *L);
static int lua_getnode(lua_State *L);
static int lua_getelement(lua_State *L);
virtual ~CcviewDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CcviewDoc)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
};
/////////////////////////////////////////////////////////////////////////////
char* StripKey(char *c);

1917
femm/CVIEWLUA.CPP Normal file

File diff suppressed because it is too large Load Diff

1016
femm/CV_PREF.CPP Normal file

File diff suppressed because it is too large Load Diff

69
femm/CV_PREF.H Normal file
View File

@ -0,0 +1,69 @@
// Pref.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// cvCPref dialog
class cvCPref : public CDialog
{
// Construction
public:
cvCPref(CWnd* pParent = NULL); // standard constructor
~cvCPref();
COLORREF *clist;
int m_d_EditAction;
int m_d_DensityPlot;
int m_d_VectorPlot;
void ScanPrefs();
void WritePrefs();
// Dialog Data
//{{AFX_DATA(cvCPref)
enum { IDD = IDD_CV_PREF };
CComboBox m_d_vplotlist;
CComboBox m_d_dplotlist;
CComboBox m_d_editlist;
CComboBox m_d_color;
BOOL m_d_GreyContours;
BOOL m_d_LegendFlag;
int m_d_NumContours;
BOOL m_d_ResetOnReload;
BOOL m_d_GridFlag;
BOOL m_d_ShowAr;
BOOL m_d_ShowAi;
BOOL m_d_PtsFlag;
BOOL m_d_MeshFlag;
BOOL m_d_SnapFlag;
BOOL m_d_Smooth;
int m_d_LineIntegralPoints;
int m_d_PlotPoints;
BOOL m_d_ShowMask;
BOOL m_d_shownames;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(cvCPref)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(cvCPref)
afx_msg void OnModBtn();
virtual BOOL OnInitDialog();
afx_msg void OnResetColors();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_d_NumContours, m_IDC_d_LineIntegralPoints;
CLuaEdit m_IDC_d_PlotPoints;
};

113
femm/ChildFrm.cpp Normal file
View File

@ -0,0 +1,113 @@
// ChildFrm.cpp : implementation of the CChildFrame class
//
#include "stdafx.h"
#include "femm.h"
#include "ChildFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CFemmApp theApp;
extern BOOL bLinehook;
/////////////////////////////////////////////////////////////////////////////
// CChildFrame
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
//{{AFX_MSG_MAP(CChildFrame)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChildFrame construction/destruction
CChildFrame::CChildFrame()
{
// TODO: add member initialization code here
}
CChildFrame::~CChildFrame()
{
}
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
if( !CMDIChildWnd::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
void CChildFrame::ActivateFrame(int nCmdShow)
{
// Gets first window to open maximized. Originally cribbed from:
// Visual C++/MFC Frequently Asked Questions
// Scot Wingo
// Stingray Software
// Version 5.0, updated 5/15/97
if (theApp.luaShowWindow != NULL) CMDIChildWnd::ActivateFrame(theApp.luaShowWindow);
else if(GetMDIFrame()->MDIGetActive()) CMDIChildWnd::ActivateFrame(nCmdShow);
else CMDIChildWnd::ActivateFrame(SW_SHOWMAXIMIZED);
theApp.luaShowWindow=NULL;
}
/////////////////////////////////////////////////////////////////////////////
// CChildFrame diagnostics
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
CMDIChildWnd::AssertValid();
}
void CChildFrame::Dump(CDumpContext& dc) const
{
CMDIChildWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CChildFrame message handlers
BOOL CChildFrame::ResizeClient(int nWidth, int nHeight, BOOL bRedraw)
{
RECT rcWnd;
GetClientRect (&rcWnd);
if(nWidth != -1) rcWnd.right = nWidth;
if(nHeight != -1) rcWnd.bottom = nHeight;
if(!::AdjustWindowRectEx(&rcWnd,GetStyle(),(GetMenu()!=NULL), GetExStyle())) return FALSE;
UINT uFlags = SWP_NOZORDER | SWP_NOMOVE;
if(!bRedraw) uFlags |= SWP_NOREDRAW;
return SetWindowPos(NULL, 0, 0, rcWnd.right - rcWnd.left, rcWnd.bottom - rcWnd.top, uFlags);
}
void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIChildWnd::OnSize(nType, cx, cy);
// Idea here is to give the active view a message that says that the window has
// been minimized. If the active view is a postprocessor window, the output
// window may need to be hidden if the window is minimized but still active.
if (nType==SIZE_MINIMIZED)
{
CView* theView=GetActiveView( );
theView->PostMessage(WM_SIZE,SIZE_MINIMIZED);
}
}

54
femm/ChildFrm.h Normal file
View File

@ -0,0 +1,54 @@
// ChildFrm.h : interface of the CChildFrame class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_CHILDFRM_H__5DA42274_DC99_4A3F_A918_C850B3925734__INCLUDED_)
#define AFX_CHILDFRM_H__5DA42274_DC99_4A3F_A918_C850B3925734__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CChildFrame : public CMDIChildWnd
{
DECLARE_DYNCREATE(CChildFrame)
public:
CChildFrame();
BOOL ResizeClient(int nWidth, int nHeight, BOOL bRedraw=FALSE);
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CChildFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void ActivateFrame(int nCmdShow);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CChildFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
//{{AFX_MSG(CChildFrame)
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CHILDFRM_H__5DA42274_DC99_4A3F_A918_C850B3925734__INCLUDED_)

115
femm/CircDlg.cpp Normal file
View File

@ -0,0 +1,115 @@
// CircDlg.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include <afxtempl.h>
#include "problem.h"
#include "xyplot.h"
#include "femmviewdoc.h"
#include "CircDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCircDlg dialog
CCircDlg::CCircDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCircDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCircDlg)
//}}AFX_DATA_INIT
}
void CCircDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCircDlg)
DDX_Control(pDX, IDC_FV_CIRCNAME, m_circname);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCircDlg, CDialog)
//{{AFX_MSG_MAP(CCircDlg)
ON_CBN_SELCHANGE(IDC_FV_CIRCNAME, OnSelchangeCircname)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCircDlg message handlers
void CCircDlg::OnSelchangeCircname()
{
if(NumCircuits==0) return;
int k;
CString crslt;
k=m_circname.GetCurSel();
CString s;
char c[256];
CComplex amps,flux,volts;
amps=TheDoc->circproplist[k].Amps;
crslt.Format("Total current = %s Amps\r\n",amps.ToStringAlt(c));
volts=TheDoc->GetVoltageDrop(k);
s.Format("Voltage Drop = %s Volts\r\n",volts.ToStringAlt(c));
crslt+=s;
flux = TheDoc->GetFluxLinkage(k);
s.Format("Flux Linkage = %s Webers\r\n",flux.ToStringAlt(c));
crslt+=s;
if (amps!=0){
s.Format("Flux/Current = %s Henries\r\n",
(flux/amps).ToStringAlt(c));
crslt+=s;
s.Format("Voltage/Current = %s Ohms\r\n",
(volts/amps).ToStringAlt(c));
crslt+=s;
}
if (TheDoc->Frequency==0)
{
s.Format("Power = %g Watts\r\n",Re(amps*volts));
crslt+=s;
}
else{
s.Format("Real Power = %g Watts\r\n",Re(volts*conj(amps))/2.);
crslt+=s;
s.Format("Reactive Power = %g VAr\r\n",Im(volts*conj(amps))/2.);
crslt+=s;
s.Format("Apparent Power = %g VA\r\n",abs(volts)*abs(amps)/2.);
crslt+=s;
}
SetDlgItemText(IDC_CIRCRESULT,crslt);
}
BOOL CCircDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int i;
NumCircuits=(int) TheDoc->circproplist.GetSize();
for(i=0;i<NumCircuits;i++)
m_circname.AddString(TheDoc->circproplist[i].CircName);
if(NumCircuits!=0){
m_circname.SetCurSel(0);
OnSelchangeCircname();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

39
femm/CircDlg.h Normal file
View File

@ -0,0 +1,39 @@
// CircDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CCircDlg dialog
class CCircDlg : public CDialog
{
// Construction
public:
CCircDlg(CWnd* pParent = NULL); // standard constructor
CFemmviewDoc *TheDoc;
int NumCircuits;
// Dialog Data
//{{AFX_DATA(CCircDlg)
enum { IDD = IDD_CIRCPROPS };
CComboBox m_circname;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCircDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCircDlg)
afx_msg void OnSelchangeCircname();
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};

95
femm/CircProp.cpp Normal file
View File

@ -0,0 +1,95 @@
// CircProp.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "CircProp.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCircProp dialog
CCircProp::CCircProp(CWnd* pParent /*=NULL*/)
: CDialog(CCircProp::IDD, pParent)
{
//{{AFX_DATA_INIT(CCircProp)
m_circname = _T("");
m_totcurrent = 0;
//}}AFX_DATA_INIT
}
void CCircProp::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCircProp)
DDX_Text(pDX, IDC_CIRCNAME, m_circname);
DDX_Text(pDX, IDC_TOTCURRENT_RE, m_totcurrent);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_CIRCNAME, m_idc_circname);
DDX_Control(pDX, IDC_TOTCURRENT_RE, m_idc_totcurrent_re);
}
BEGIN_MESSAGE_MAP(CCircProp, CDialog)
//{{AFX_MSG_MAP(CCircProp)
ON_BN_CLICKED(IDC_RADIOAMP, OnRadioamp)
ON_BN_CLICKED(IDC_RADIOVOLT, OnRadiovolt)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCircProp message handlers
void CCircProp::OnRadioamp()
{
m_circtype=0;
}
void CCircProp::OnRadiovolt()
{
m_circtype=1;
}
BOOL CCircProp::OnInitDialog()
{
CDialog::OnInitDialog();
int SetEm;
SetEm=IDC_RADIOAMP;
if(m_circtype==1){
SetEm=IDC_RADIOVOLT;
OnRadiovolt();
}
else OnRadioamp();
CheckRadioButton(
IDC_RADIOVOLT,// identifier of first radio button in group
IDC_RADIOAMP, // identifier of last radio button in group
SetEm // identifier of radio button to select
);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCircProp::OnOK()
{
UpdateData();
for(int nn=0;nn<namelist.GetSize();nn++)
{
if (m_circname==namelist[nn]){
MsgBox("The name \"%s\" has already been used.\nSelect a different name for this property.",m_circname);
return;
}
}
CDialog::OnOK();
}

46
femm/CircProp.h Normal file
View File

@ -0,0 +1,46 @@
// CircProp.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CCircProp dialog
class CCircProp : public CDialog
{
// Construction
public:
CCircProp(CWnd* pParent = NULL); // standard constructor
int m_circtype;
CArray<CString,CString&> namelist;
// Dialog Data
//{{AFX_DATA(CCircProp)
enum { IDD = IDD_CIRCPROP };
CString m_circname;
CComplex m_totcurrent;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCircProp)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCircProp)
afx_msg void OnRadioamp();
afx_msg void OnRadiovolt();
virtual BOOL OnInitDialog();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_idc_circname, m_idc_totcurrent_re;
};

113
femm/CopyDlg.cpp Normal file
View File

@ -0,0 +1,113 @@
// CopyDlg.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "CopyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCopyDlg dialog
CCopyDlg::CCopyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCopyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCopyDlg)
m_aboutx = 0.0;
m_abouty = 0.0;
m_deltax = 0.0;
m_deltay = 0.0;
m_shiftangle = 0.0;
m_ncopies = 0;
//}}AFX_DATA_INIT
}
void CCopyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCopyDlg)
DDX_Text(pDX, IDC_ABOUTX, m_aboutx);
DDX_Text(pDX, IDC_ABOUTY, m_abouty);
DDX_Text(pDX, IDC_DELTAX, m_deltax);
DDX_Text(pDX, IDC_DELTAY, m_deltay);
DDX_Text(pDX, IDC_SHIFTANGLE, m_shiftangle);
DDX_Text(pDX, IDC_NCOPIES, m_ncopies);
DDV_MinMaxInt(pDX, m_ncopies, 0, 100);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_ABOUTX, m_IDC_aboutx);
DDX_Control(pDX, IDC_ABOUTY, m_IDC_abouty);
DDX_Control(pDX, IDC_DELTAX, m_IDC_deltax);
DDX_Control(pDX, IDC_DELTAY, m_IDC_deltay);
DDX_Control(pDX, IDC_SHIFTANGLE, m_IDC_shiftangle);
DDX_Control(pDX, IDC_NCOPIES, m_IDC_ncopies);
}
BEGIN_MESSAGE_MAP(CCopyDlg, CDialog)
//{{AFX_MSG_MAP(CCopyDlg)
ON_BN_CLICKED(IDC_ROTATE, OnRotate)
ON_BN_CLICKED(IDC_TRANSLATE, OnTranslate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCopyDlg message handlers
BOOL CCopyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if (IsMove==TRUE){
SetWindowText("Move");
SendDlgItemMessage(IDC_NCOPIES,WM_ENABLE,FALSE,0);
}
else SetWindowText("Copy");
CheckRadioButton(
IDC_ROTATE,// identifier of first radio button in group
IDC_TRANSLATE, // identifier of last radio button in group
IDC_TRANSLATE // identifier of radio button to select
);
OnTranslate();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCopyDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CCopyDlg::OnRotate()
{
// TODO: Add your control notification handler code here
BtnState=0;
SendDlgItemMessage(IDC_SHIFTANGLE,WM_ENABLE,TRUE,0);
SendDlgItemMessage(IDC_ABOUTX,WM_ENABLE,TRUE,0);
SendDlgItemMessage(IDC_ABOUTY,WM_ENABLE,TRUE,0);
SendDlgItemMessage(IDC_DELTAX,WM_ENABLE,FALSE,0);
SendDlgItemMessage(IDC_DELTAY,WM_ENABLE,FALSE,0);
}
void CCopyDlg::OnTranslate()
{
// TODO: Add your control notification handler code here
BtnState=1;
SendDlgItemMessage(IDC_SHIFTANGLE,WM_ENABLE,FALSE,0);
SendDlgItemMessage(IDC_ABOUTX,WM_ENABLE,FALSE,0);
SendDlgItemMessage(IDC_ABOUTY,WM_ENABLE,FALSE,0);
SendDlgItemMessage(IDC_DELTAX,WM_ENABLE,TRUE,0);
SendDlgItemMessage(IDC_DELTAY,WM_ENABLE,TRUE,0);
}

48
femm/CopyDlg.h Normal file
View File

@ -0,0 +1,48 @@
// CopyDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CCopyDlg dialog
class CCopyDlg : public CDialog
{
// Construction
public:
CCopyDlg(CWnd* pParent = NULL); // standard constructor
int BtnState;
BOOL IsMove;
// Dialog Data
//{{AFX_DATA(CCopyDlg)
enum { IDD = IDD_COPYDLG };
double m_aboutx;
double m_abouty;
double m_deltax;
double m_deltay;
double m_shiftangle;
int m_ncopies;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCopyDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCopyDlg)
virtual BOOL OnInitDialog();
virtual void OnOK();
afx_msg void OnRotate();
afx_msg void OnTranslate();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_aboutx, m_IDC_abouty, m_IDC_deltax;
CLuaEdit m_IDC_deltay, m_IDC_shiftangle, m_IDC_ncopies;
};

65
femm/CplotDlg2.cpp Normal file
View File

@ -0,0 +1,65 @@
// CplotDlg2.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "CplotDlg2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCplotDlg2 dialog
CCplotDlg2::CCplotDlg2(CWnd* pParent /*=NULL*/)
: CDialog(CCplotDlg2::IDD, pParent)
{
//{{AFX_DATA_INIT(CCplotDlg2)
m_numcontours = 0;
m_showa = FALSE;
m_ahigh = 0.0;
m_alow = 0.0;
m_showmask = FALSE;
//}}AFX_DATA_INIT
}
void CCplotDlg2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCplotDlg2)
DDX_Text(pDX, IDC_NUMCONTOURS, m_numcontours);
DDV_MinMaxInt(pDX, m_numcontours, 4, 999);
DDX_Check(pDX, IDC_SHOW_A, m_showa);
DDX_Text(pDX, IDC_AHIGH, m_ahigh);
DDX_Text(pDX, IDC_ALOW, m_alow);
DDX_Check(pDX, IDC_SHOW_MASK2, m_showmask);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_NUMCONTOURS, m_IDC_numcontours);
DDX_Control(pDX, IDC_AHIGH, m_IDC_ahigh);
DDX_Control(pDX, IDC_ALOW, m_IDC_alow);
}
BEGIN_MESSAGE_MAP(CCplotDlg2, CDialog)
//{{AFX_MSG_MAP(CCplotDlg2)
ON_BN_CLICKED(IDC_DFLT1, OnDflt1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCplotDlg2 message handlers
void CCplotDlg2::OnDflt1()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_alow=Alb;
m_ahigh=Aub;
m_numcontours=19;
UpdateData(FALSE);
}

42
femm/CplotDlg2.h Normal file
View File

@ -0,0 +1,42 @@
// CplotDlg2.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CCplotDlg2 dialog
class CCplotDlg2 : public CDialog
{
// Construction
public:
CCplotDlg2(CWnd* pParent = NULL); // standard constructor
double Alb,Aub;
// Dialog Data
//{{AFX_DATA(CCplotDlg2)
enum { IDD = IDD_CPLOTDLG2 };
int m_numcontours;
BOOL m_showa;
double m_ahigh;
double m_alow;
BOOL m_showmask;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCplotDlg2)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CCplotDlg2)
afx_msg void OnDflt1();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_numcontours, m_IDC_ahigh, m_IDC_alow;
};

44
femm/DXFImport.cpp Normal file
View File

@ -0,0 +1,44 @@
// DXFImport.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "DXFImport.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDXFImport dialog
CDXFImport::CDXFImport(CWnd* pParent /*=NULL*/)
: CDialog(CDXFImport::IDD, pParent)
{
//{{AFX_DATA_INIT(CDXFImport)
m_dxftol = 0.0;
//}}AFX_DATA_INIT
}
void CDXFImport::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDXFImport)
DDX_Text(pDX, IDC_DXFTOL, m_dxftol);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_DXFTOL, m_IDC_dxftol);
}
BEGIN_MESSAGE_MAP(CDXFImport, CDialog)
//{{AFX_MSG_MAP(CDXFImport)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDXFImport message handlers

39
femm/DXFImport.h Normal file
View File

@ -0,0 +1,39 @@
// DXFImport.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CDXFImport dialog
class CDXFImport : public CDialog
{
// Construction
public:
CDXFImport(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDXFImport)
enum { IDD = IDD_DXFIMPORT };
double m_dxftol;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDXFImport)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDXFImport)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_dxftol;
};

52
femm/EnterPt.cpp Normal file
View File

@ -0,0 +1,52 @@
// EnterPt.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "EnterPt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEnterPt dialog
CEnterPt::CEnterPt(CWnd* pParent /*=NULL*/)
: CDialog(CEnterPt::IDD, pParent)
{
//{{AFX_DATA_INIT(CEnterPt)
m_coord1 = 0.0;
m_coord2 = 0.0;
m_label1 = _T("");
m_label2 = _T("");
//}}AFX_DATA_INIT
}
void CEnterPt::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEnterPt)
DDX_Text(pDX, IDC_COORD1, m_coord1);
DDX_Text(pDX, IDC_COORD2, m_coord2);
DDX_Text(pDX, IDC_LABEL1, m_label1);
DDX_Text(pDX, IDC_LABEL2, m_label2);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_COORD1, m_IDC_coord1);
DDX_Control(pDX, IDC_COORD2, m_IDC_coord2);
}
BEGIN_MESSAGE_MAP(CEnterPt, CDialog)
//{{AFX_MSG_MAP(CEnterPt)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEnterPt message handlers

40
femm/EnterPt.h Normal file
View File

@ -0,0 +1,40 @@
// EnterPt.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CEnterPt dialog
class CEnterPt : public CDialog
{
// Construction
public:
CEnterPt(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CEnterPt)
enum { IDD = IDD_ENTERPT };
double m_coord1;
double m_coord2;
CString m_label1;
CString m_label2;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CEnterPt)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CEnterPt)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_coord1, m_IDC_coord2;
};

50
femm/ExteriorProps.cpp Normal file
View File

@ -0,0 +1,50 @@
// ExteriorProps.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "ExteriorProps.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExteriorProps dialog
CExteriorProps::CExteriorProps(CWnd* pParent /*=NULL*/)
: CDialog(CExteriorProps::IDD, pParent)
{
//{{AFX_DATA_INIT(CExteriorProps)
m_Ri = 0.0;
m_Ro = 0.0;
m_Zo = 0.0;
//}}AFX_DATA_INIT
}
void CExteriorProps::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExteriorProps)
DDX_Text(pDX, IDC_RI, m_Ri);
DDX_Text(pDX, IDC_RO, m_Ro);
DDX_Text(pDX, IDC_ZO, m_Zo);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_RO, m_IDC_RO);
DDX_Control(pDX, IDC_RI, m_IDC_RI);
DDX_Control(pDX, IDC_ZO, m_IDC_ZO);
}
BEGIN_MESSAGE_MAP(CExteriorProps, CDialog)
//{{AFX_MSG_MAP(CExteriorProps)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExteriorProps message handlers

51
femm/ExteriorProps.h Normal file
View File

@ -0,0 +1,51 @@
#if !defined(AFX_EXTERIORPROPS_H__1854BB86_0B6A_4F9B_9407_F5D2B109EF17__INCLUDED_)
#define AFX_EXTERIORPROPS_H__1854BB86_0B6A_4F9B_9407_F5D2B109EF17__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ExteriorProps.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CExteriorProps dialog
class CExteriorProps : public CDialog
{
// Construction
public:
CExteriorProps(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CExteriorProps)
enum { IDD = IDD_EXTERIORPROPS };
double m_Ri;
double m_Ro;
double m_Zo;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CExteriorProps)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CExteriorProps)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_RO, m_IDC_RI, m_IDC_ZO;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_EXTERIORPROPS_H__1854BB86_0B6A_4F9B_9407_F5D2B109EF17__INCLUDED_)

3130
femm/FemmeDoc.cpp Normal file

File diff suppressed because it is too large Load Diff

273
femm/FemmeDoc.h Normal file
View File

@ -0,0 +1,273 @@
#if !defined(AFX_FEMMEDOC_H__C8BAD1A9_C080_4CB6_9B9D_1F22718D3551__INCLUDED_)
#define AFX_FEMMEDOC_H__C8BAD1A9_C080_4CB6_9B9D_1F22718D3551__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FemmeDoc.h : header file
//
#include "nosebl.h"
#include "lua.h"
#include "luaconsoledlg.h"
#include "luadebug.h"
extern CFemmApp theApp; //<DP>
/////////////////////////////////////////////////////////////////////////////
// CFemmeDoc document
class CFemmeDoc : public CDocument
{
protected:
CFemmeDoc(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CFemmeDoc)
// Attributes
public:
// General problem attributes
double Frequency;
double Precision;
double MinAngle;
int SmartMesh;
double Depth;
int LengthUnits;
int ACSolver;
BOOL ProblemType;
BOOL Coords;
CString ProblemNote;
BOOL FirstDraw;
BOOL NoDraw;
CString PrevSoln;
int PrevType;
// default behaviors
double d_prec;
double d_minangle;
double d_freq;
double d_depth;
int d_coord;
int d_length;
int d_type;
int d_solver;
CString BinDir;
// lists of nodes, segments, and block labels
CArray< CNode, CNode&> nodelist;
CArray< CSegment, CSegment&> linelist;
CArray< CArcSegment, CArcSegment&> arclist;
CArray< CBlockLabel, CBlockLabel&> blocklist;
// lists of nodes, segments, and block labels for undo purposes...
CArray< CNode, CNode&> undonodelist;
CArray< CSegment, CSegment&> undolinelist;
CArray< CArcSegment, CArcSegment&> undoarclist;
CArray< CBlockLabel, CBlockLabel&> undoblocklist;
// CArrays containing the mesh information
CArray< CPoint, CPoint&> meshline;
CArray< CPoint, CPoint&> greymeshline;
CArray< CNode, CNode&> meshnode;
// lists of properties
CArray< CMaterialProp, CMaterialProp& > blockproplist;
CArray< CBoundaryProp, CBoundaryProp& > lineproplist;
CArray< CPointProp, CPointProp& > nodeproplist;
CArray< CCircuit, CCircuit& > circproplist;
double extRo,extRi,extZo;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFemmeDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnSaveDocument(LPCTSTR lpszPathName);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFemmeDoc();
void UnselectAll();
double ShortestDistance(double p, double q, int segm);
BOOL AddNode(double x, double y, double d);
BOOL AddSegment(int n0, int n1, double tol=0);
BOOL AddSegment(int n0, int n1, CSegment *parsegm, double tol=0);
BOOL AddArcSegment(CArcSegment &asegm, double tol=0);
BOOL AddBlockLabel(double x, double y, double d);
BOOL AddNode(CNode &node, double d);
BOOL AddSegment(CComplex p0, CComplex p1, CSegment &segm, double tol=0);
BOOL AddArcSegment(CComplex p0, CComplex p1, CArcSegment &asegm, double tol=0);
BOOL AddBlockLabel(CBlockLabel &blabel, double d);
int ClosestNode(double x, double y);
int ClosestBlockLabel(double x, double y);
int ClosestSegment(double x, double y);
BOOL GetIntersection(int n0, int n1, int segm, double *xi, double *yi);
int ClosestArcSegment(double x, double y);
void GetCircle(CArcSegment &asegm,CComplex &c, double &R);
int GetLineArcIntersection(CSegment &seg, CArcSegment &arc, CComplex *p);
int GetArcArcIntersection(CArcSegment &arc1, CArcSegment &arc2, CComplex *p);
double ShortestDistanceFromArc(CComplex p, CArcSegment &arc);
void RotateMove(CComplex c, double t, int EditAction);
void TranslateMove(double dx, double dy, int EditAction);
void ScaleMove(double bx, double by, double sf, int EditAction);
void MirrorSelected(double x0, double y0, double x1, double y1, int ea);
void RotateCopy(CComplex c, double t, int ncopies, int EditAction);
void TranslateCopy(double dx, double dy, int ncopies, int EditAction);
BOOL DeleteSelectedNodes();
BOOL DeleteSelectedSegments();
BOOL DeleteSelectedArcSegments();
BOOL DeleteSelectedBlockLabels();
BOOL OpBlkDlg();
void OpNodeDlg();
void OpSegDlg();
void OpArcSegDlg();
void OpGrpDlg();
BOOL LoadMesh();
BOOL OnWritePoly();
BOOL FunnyOnWritePoly();
BOOL ReadDXF(CString fname, double DefTol=-1.);
BOOL WriteDXF(CString fname);
BOOL OldOnOpenDocument(LPCTSTR lpszPathName);
BOOL HasPeriodicBC();
BOOL CanCreateRadius(int n);
BOOL CreateRadius(int n, double r);
double LineLength(int i);
BOOL ScanPreferences();
void UpdateUndo();
void Undo();
void EnforcePSLG(); // makes sure that everything is kosher...
void EnforcePSLG(double tol);
void FancyEnforcePSLG(double tol);
BOOL SelectOrphans();
BOOL dxf_line_hook();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
// Generated message map functions
protected:
//{{AFX_MSG(CFemmeDoc)
afx_msg void OnDefineProblem();
afx_msg void OnEditMatprops();
afx_msg void OnEditPtprops();
afx_msg void OnEditSegprops();
afx_msg void OnEditCircprops();
afx_msg void OnEditExterior();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnViewLuaConsole();
void initalise_lua();
static int lua_prob_def(lua_State *L);
static int luaSaveDocument(lua_State *L);
static int lua_create_mesh(lua_State *L);
static int lua_smartmesh(lua_State *L);
static int lua_purge_mesh(lua_State *L);
static int lua_show_mesh(lua_State *L);
static int lua_analyze(lua_State *L);
static int lua_runpost(lua_State *L);
static int lua_addnode(lua_State *L);
static int lua_addlabel(lua_State *L);
static int lua_addline(lua_State *L);
static int lua_addarc(lua_State *L);
static int lua_selectnode(lua_State *L);
static int lua_selectlabel(lua_State *L);
static int lua_selectsegment(lua_State *L);
static int lua_selectarcsegment(lua_State *L);
static int lua_clearselected(lua_State *L);
static int lua_setnodeprop(lua_State *L);
static int lua_setblockprop(lua_State *L);
static int lua_setsegmentprop(lua_State *L);
static int lua_setarcsegmentprop(lua_State *L);
static int lua_deleteselected(lua_State *L);
static int lua_deleteselectedsegments(lua_State *L);
static int lua_deleteselectednodes(lua_State *L);
static int lua_deleteselectedlabels(lua_State *L);
static int lua_deleteselectedarcsegments(lua_State *L);
static int lua_zoomout(lua_State *L);
static int lua_zoomnatural(lua_State *L);
static int lua_zoomin(lua_State *L);
static int lua_move_translate(lua_State *L);
static int lua_move_rotate(lua_State *L);
static int lua_copy_translate(lua_State *L);
static int lua_copy_rotate(lua_State *L);
static int lua_mirror(lua_State *L);
static int lua_scale(lua_State *L);
static int lua_addmatprop(lua_State *L);
static int lua_addpointprop(lua_State *L);
static int lua_addboundprop(lua_State *L);
static int lua_addcircuitprop(lua_State *L);
static int lua_delcircuitprop(lua_State *L);
static int lua_delpointprop(lua_State *L);
static int lua_delboundprop(lua_State *L);
static int lua_delmatprop(lua_State *L);
static int lua_seteditmode(lua_State *L);
static int lua_selectgroup(lua_State *L);
static int lua_zoom(lua_State *L);
static int lua_newdocument(lua_State *L);
static int lua_savebitmap(lua_State * L);
static int lua_modmatprop(lua_State *L);
static int lua_modboundprop(lua_State *L);
static int lua_modpointprop(lua_State *L);
static int lua_modcircprop(lua_State *L);
static int lua_exitpre(lua_State *L);
static int lua_addbhpoint(lua_State *L);
static int lua_clearbhpoints(lua_State *L);
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,HBITMAP hBMP, HDC hDC);
static int lua_saveWMF(lua_State *L);
static int lua_updatewindow(lua_State *L);
static int lua_shownames(lua_State * L);
static int lua_showgrid(lua_State *L);
static int lua_hidegrid(lua_State *L);
static int lua_gridsnap(lua_State *L);
static int lua_setgrid(lua_State *L);
static int lua_switchfocus(lua_State *L);
static int lua_readdxf(lua_State *L);
static int lua_savedxf(lua_State *L);
static int luaResize(lua_State *L);
static int luaMinimize(lua_State *L);
static int luaMaximize(lua_State *L);
static int luaRestore(lua_State *L);
static int lua_defineouterspace(lua_State *L);
static int lua_attachouterspace(lua_State *L);
static int lua_detachouterspace(lua_State *L);
static int lua_attachdefault(lua_State *L);
static int lua_detachdefault(lua_State *L);
static int lua_createradius(lua_State *L);
static int lua_gettitle(lua_State *L);
static int lua_setgroup(lua_State *L);
static int lua_getmaterial(lua_State *L);
static int lua_getprobleminfo(lua_State *L);
static int lua_getboundingbox(lua_State *L);
static int lua_selectcircle(lua_State *L);
static int lua_selectrectangle(lua_State *L);
static int lua_previous(lua_State *L);
static int old_lua_addmatprop(lua_State *L);
static int old_lua_modmatprop(lua_State *L);
static int old_lua_addpointprop(lua_State *L);
static int old_lua_modpointprop(lua_State *L);
static int old_lua_addcircuitprop(lua_State *L);
static int old_lua_modcircprop(lua_State *L);
};
char* StripKey(char *c);
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_FEMMEDOC_H__C8BAD1A9_C080_4CB6_9B9D_1F22718D3551__INCLUDED_)

3373
femm/FemmeView.cpp Normal file

File diff suppressed because it is too large Load Diff

181
femm/FemmeView.h Normal file
View File

@ -0,0 +1,181 @@
#if !defined(AFX_FEMMEVIEW_H__9D980E92_AF25_49AD_94B8_5FC96599FC59__INCLUDED_)
#define AFX_FEMMEVIEW_H__9D980E92_AF25_49AD_94B8_5FC96599FC59__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FemmeView.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CFemmeView view
class CFemmeView : public CView
{
protected:
CFemmeView(); // protected constructor used by dynamic creation
DECLARE_DYNCREATE(CFemmeView)
// Attributes
public:
CFemmeDoc* GetDocument();
void ScreenToDwg(int xs, int ys, double *xd, double *yd, RECT *r);
BOOL DwgToScreen(double xd, double yd, int *xs, int *ys, RECT *r);
void DrawPSLG();
void EnterPoint();
BOOL ScanPreferences();
BOOL WritePreferences();
void OnNewDocument();
void CheckIt();
int EditAction; // tells if operating on points, lines, or blox
double mx,my; // location of the mouse in model coordinates
double ox,oy,mag; // location of lower left corner & scaling factor
CStatusBar* StatBar; // pointer to the main window's status bar
double GridSize; // size of each block in the grid
BOOL GridFlag; // Flag telling whether or not to show grid
BOOL SnapFlag;
BOOL MeshFlag;
BOOL ShowNames;
BOOL MeshUpToDate;
int FirstPoint;
int ZoomWndFlag;
int SelectWndFlag;
int SelectCircFlag;
int CreateRadiusFlag;
double wzx,wzy;
double MaxSeg,ArcAngle;
// Colors used to render the view
COLORREF SelColor;
COLORREF MeshColor;
COLORREF BlockColor;
COLORREF LineColor;
COLORREF GridColor;
COLORREF BackColor;
COLORREF NodeColor;
COLORREF NameColor;
// default view properties
int d_action; //=0;
double d_mag; //=100.;
double d_gridsize; //=0.25;
BOOL d_showgrid; //=TRUE;
BOOL d_snapgrid; //=FALSE;
BOOL d_showorigin;
BOOL d_shownames;
CString BinDir; // pathname for other FEMM executables
CArray <CZPix,CZPix&> ZoomPix;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFemmeView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
protected:
virtual void OnInitialUpdate(); // called first time after construct
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
//}}AFX_VIRTUAL
// Implementation
public:
void lua_zoomin();
void lua_zoomout();
void lua_zoomnatural();
void lnu_show_mesh();
void lnu_purge_mesh();
void lnuMakeMesh();
void lnu_analyze(int bShow);
void MyMoveTo(CDC *pDC, int x, int y);
void MyLineTo(CDC *pDC, int x, int y);
BOOL GetBoundingBox(double *x, double *y);
virtual ~CFemmeView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CFemmeView)
afx_msg void OnNodeOp();
afx_msg void OnSegmentOp();
afx_msg void OnBlockOp();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnZoomIn();
afx_msg void OnZoomOut();
afx_msg void OnShowGrid();
afx_msg void OnSetGrid();
afx_msg void OnSnapGrid();
afx_msg void OnShowMesh();
afx_msg void OnEditCopy();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnZoomNatural();
afx_msg void OnZoomWnd();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMakeMesh();
afx_msg void OnMenuAnalyze();
afx_msg void OnMenuViewres();
afx_msg void OnArcsegOp();
afx_msg void OnUndo();
afx_msg void OnKbdZoom();
afx_msg void OnMoveObjects();
afx_msg void OnCopyObjects();
afx_msg void OnDxfin();
afx_msg void OnPurgemesh();
afx_msg void OnDxfwrite();
afx_msg void OnSelectwnd();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnPanDown();
afx_msg void OnPanLeft();
afx_msg void OnPanRight();
afx_msg void OnPanUp();
afx_msg void OnMenuMatlib();
afx_msg void OnGroupOp();
afx_msg void OnOpenSelected();
afx_msg void OnEditScale();
afx_msg void OnEditMirror();
afx_msg void OnEditCut();
afx_msg void OnEditCopyAsMetafile();
afx_msg void OnViewShownames();
afx_msg void OnFDSelectCirc();
afx_msg void OnViewShowOrphans();
afx_msg void OnCreateRadius();
afx_msg void OnUpdateEditExterior(CCmdUI* pCmdUI);
afx_msg void OnMakeABC();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
};
#ifndef _DEBUG // debug version in femmeView.cpp
inline CFemmeDoc* CFemmeView::GetDocument()
{ return (CFemmeDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_FEMMEVIEW_H__9D980E92_AF25_49AD_94B8_5FC96599FC59__INCLUDED_)

4955
femm/FemmviewDoc.cpp Normal file

File diff suppressed because it is too large Load Diff

247
femm/FemmviewDoc.h Normal file
View File

@ -0,0 +1,247 @@
// femmviewDoc.h : interface of the CFemmviewDoc class
//
/////////////////////////////////////////////////////////////////////////////
#include "lua.h"
#include "luadebug.h"
#include "luaconsoledlg.h"
//#define APPROXGAP
extern CFemmApp theApp; //<DP>
class CFemmviewDoc : public CDocument
{
protected: // create from serialization only
CFemmviewDoc();
DECLARE_DYNCREATE(CFemmviewDoc)
// Attributes
public:
// General problem attributes
double Frequency;
double Depth;
int LengthUnits;
double *LengthConv;
BOOL ProblemType;
BOOL Coords;
CString ProblemNote;
CString PrevSoln;
int PrevType;
BOOL bIncremental;
BOOL FirstDraw;
BOOL Smooth;
BOOL bMultiplyDefinedLabels;
int WeightingScheme;
double extRo,extRi,extZo;
double A_High, A_Low;
double A_lb, A_ub;
double PlotBounds[9][2];
double d_PlotBounds[9][2];
// double Br_High,Br_Low;
// double Bi_High,Bi_Low;
double B_High, B_Low;
double H_High;
// double B_lb, B_ub;
// double Jr_High,Jr_Low;
// double Ji_High,Ji_Low;
// double J_High, J_Low;
// Some default behaviors
CString BinDir;
int d_LineIntegralPoints;
int d_WeightingScheme;
BOOL d_ShiftH;
BOOL bHasMask;
// lists of nodes, segments, and block labels
CArray< femmviewdata::CNode, femmviewdata::CNode&> nodelist;
CArray< femmviewdata::CSegment, femmviewdata::CSegment&> linelist;
CArray< femmviewdata::CBlockLabel, femmviewdata::CBlockLabel&> blocklist;
CArray< femmviewdata::CArcSegment, femmviewdata::CArcSegment&> arclist;
// CArrays containing the mesh information
CArray< femmviewdata::CMeshNode, femmviewdata::CMeshNode&> meshnode;
CArray< femmviewdata::CElement, femmviewdata::CElement&> meshelem;
CArray< femmviewdata::CAirGapElement, femmviewdata::CAirGapElement&> agelist;
// List of elements connected to each node;
int *NumList;
int **ConList;
// lists of properties
CArray< femmviewdata::CMaterialProp, femmviewdata::CMaterialProp& > blockproplist;
CArray< femmviewdata::CBoundaryProp, femmviewdata::CBoundaryProp& > lineproplist;
CArray< femmviewdata::CPointProp, femmviewdata::CPointProp& > nodeproplist;
CArray< femmviewdata::CCircuit, femmviewdata::CCircuit& > circproplist;
// list of points in a user-defined contour;
CArray< CComplex, CComplex& > contour;
// stuff that PTLOC needs
CArray< CMeshNode, CMeshNode&> *pmeshnode;
CArray< CElement, CElement&> *pmeshelem;
// TriEdge recenttri;
// int samples;
// unsigned long randomseed;
// TriEdge bdrylinkhead[512];
// int numberofbdrylink;
// member functions
int InTriangle(double x, double y);
BOOL InTriangleTest(double x, double y, int i);
BOOL GetPointValues(double x, double y, CPointVals &u);
BOOL GetPointValues(double x, double y, int k, CPointVals &u);
void GetLineValues(CXYPlot &p, int PlotType, int npoints);
void GetGapValues(CXYPlot &p, int PlotType, int npoints, int myAGE);
void GetElementB(femmviewdata::CElement &elm);
void OnReload();
void FindBoundaryEdges();
int ClosestNode(double x, double y);
int ClosestSegment(double x, double y);
double ShortestDistance(double p, double q, int segm);
CComplex Ctr(int i);
double ElmArea(int i);
double ElmArea(femmviewdata::CElement *elm);
void GetPointB(double x, double y, CComplex &B1, CComplex &B2,
femmviewdata::CElement &elm);
void GetNodalB(CComplex *b1, CComplex *b2,femmviewdata::CElement &elm);
CComplex BlockIntegral(int inttype);
void LineIntegral(int inttype, CComplex *z);
int ClosestArcSegment(double x, double y);
void GetCircle(femmviewdata::CArcSegment &asegm,CComplex &c, double &R);
double ShortestDistanceFromArc(CComplex p, femmviewdata::CArcSegment &arc);
double ShortestDistanceFromSegment(double p, double q, int segm);
CComplex GetJA(int k,CComplex *J,CComplex *A);
CComplex PlnInt(double a, CComplex *u, CComplex *v);
CComplex AxiInt(double a, CComplex *u, CComplex *v,double *r);
BOOL ScanPreferences();
void BendContour(double angle, double anglestep);
BOOL MakeMask();
CComplex HenrotteVector(int k);
BOOL IsKosher(int k);
double AECF(int k);
void GetFillFactor(int lbl);
CComplex GetStrandedVoltageDrop(int lbl);
CComplex GetVoltageDrop(int circnum);
CComplex GetFluxLinkage(int circnum);
CComplex GetStrandedLinkage(int lbl);
CComplex GetSolidAxisymmetricLinkage(int lbl);
CComplex GetParallelLinkage(int numcirc);
CComplex GetParallelLinkageAlt(int numcirc);
void GetMu(CComplex b1, CComplex b2,CComplex &mu1, CComplex &mu2, int i);
void GetMu(double b1, double b2, double &mu1, double &mu2, int i);
void GetMagnetization(int n, CComplex &M1, CComplex &M2);
void GetH(double b1, double b2, double &h1, double &h2, int k);
void GetH(CComplex b1, CComplex b2, CComplex &h1, CComplex &h2, int k);
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFemmviewDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
virtual BOOL OnOpenDocument(LPCTSTR lpszPathName);
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
//}}AFX_VIRTUAL
// Implementation
public:
// lua extensions
bool luafired;
void initalise_lua();
static int lua_dumpheader(lua_State * L);
static int lua_getpointvals(lua_State * L);
static int lua_exitpost(lua_State * L);
static int lua_addcontour(lua_State * L);
static int lua_clearcontour(lua_State * L);
static int lua_lineintegral(lua_State * L);
static int lua_selectblock(lua_State * L);
static int lua_groupselectblock(lua_State * L);
static int lua_blockintegral(lua_State * L);
static int lua_clearblock(lua_State * L);
static int lua_zoomout(lua_State * L);
static int lua_zoomin(lua_State * L);
static int lua_zoomnatural(lua_State * L);
static int lua_hidemesh(lua_State * L);
static int lua_showmesh(lua_State * L);
static int lua_showgrid(lua_State * L);
static int lua_hidegrid(lua_State * L);
static int lua_showdensity(lua_State * L);
static int lua_hidedensity(lua_State * L);
static int lua_hidecountour(lua_State * L);
static int lua_showcountour(lua_State * L);
static int lua_zoom(lua_State * L);
static int lua_smoothing(lua_State * L);
static int lua_hidepoints(lua_State * L);
static int lua_showpoints(lua_State * L);
static int lua_gridsnap(lua_State * L);
static int lua_setgrid(lua_State * L);
static int lua_getprobleminfo(lua_State * L);
static int lua_savebitmap(lua_State * L);
PBITMAPINFO CreateBitmapInfoStruct(HWND hwnd, HBITMAP hBmp);
void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,HBITMAP hBMP, HDC hDC) ;
static int lua_getcircuitprops(lua_State *L);
static int lua_saveWMF(lua_State *L);
static int lua_refreshview(lua_State *L);
static int lua_selectline(lua_State *L);
static int lua_seteditmode(lua_State *L);
static int lua_bendcontour(lua_State *L);
static int lua_makeplot(lua_State *L);
static int lua_shownames(lua_State *L);
static int lua_vectorplot(lua_State *L);
static int lua_gradient(lua_State *L);
static int lua_reload(lua_State *L);
static int lua_switchfocus(lua_State *L);
static int luaResize(lua_State *L);
static int luaMinimize(lua_State *L);
static int luaMaximize(lua_State *L);
static int luaRestore(lua_State *L);
static int lua_gettitle(lua_State *L);
static int lua_weighting(lua_State *L);
// commands to access low-level information through Lua
static int lua_numnodes(lua_State *L);
static int lua_numelements(lua_State *L);
static int lua_getnode(lua_State *L);
static int lua_getelement(lua_State *L);
// functions used for compatibility with older versions
static int old_lua_lineintegral(lua_State * L);
static int old_lua_getpointvals(lua_State * L);
static int old_lua_blockintegral(lua_State * L);
static int old_lua_getcircuitprops(lua_State *L);
// functions used to query air gap elements
static int lua_getAGEflux(lua_State *L);
static int lua_gapintegral(lua_State *L);
static int lua_getgapa(lua_State *L);
static int lua_getgapharmonics(lua_State *L);
virtual ~CFemmviewDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CFemmviewDoc)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
};
/////////////////////////////////////////////////////////////////////////////
char* StripKey(char *c);

4761
femm/FemmviewView.cpp Normal file

File diff suppressed because it is too large Load Diff

230
femm/FemmviewView.h Normal file
View File

@ -0,0 +1,230 @@
// femmviewView.h : interface of the CFemmviewView class
//
/////////////////////////////////////////////////////////////////////////////
class CFemmviewView : public CView
{
protected: // create from serialization only
CFemmviewView();
DECLARE_DYNCREATE(CFemmviewView)
// Attributes
public:
CFemmviewDoc* GetDocument();
void ScreenToDwg(int xs, int ys, double *xd, double *yd, RECT *r);
BOOL DwgToScreen(double xd, double yd, int *xs, int *ys, RECT *r);
void EnterPoint();
int EditAction; // tells if operating on points, lines, or blox
double mx,my; // location of the mouse in model coordinates
double ox,oy,mag; // location of lower left corner & scaling factor
CStatusBar* StatBar; // pointer to the main window's status bar
double GridSize; // size of each block in the grid
BOOL GridFlag; // Flag telling whether or not to show grid
BOOL SnapFlag;
BOOL MeshFlag;
BOOL LegendFlag;
BOOL ShowNames;
BOOL GreyContours;
BOOL PtsFlag;
BOOL Coords; // False=Cartesian; True=Polar
int ZoomWndFlag;
int DrawSelected;
int VectorPlot;
double VectorScaleFactor;
double wzx,wzy;
// default behaviors
int d_EditAction;
BOOL d_GridFlag;
BOOL d_SnapFlag;
BOOL d_MeshFlag;
BOOL d_LegendFlag;
BOOL d_GreyContours;
int d_NumContours;
BOOL d_ShowAr;
BOOL d_ShowAi;
BOOL d_ShowMask;
int d_DensityPlot;
BOOL d_PtsFlag;
BOOL d_ResetOnReload;
BOOL d_Smooth;
BOOL d_ShowNames;
BOOL d_PlotPoints;
int d_VectorPlot;
COutBox *Dspl;
CString BinDir; // pathname for triangle.exe
int NumContours;
BOOL ShowAr,ShowAi,ShowMask;
int DensityPlot;
CString OutputWindowText;
CArray< CPixel, CPixel& > LinePix;
CArray< CZPix, CZPix& > ZoomPix;
// Greyscale Density Plot Colormap
COLORREF Grey00;
COLORREF Grey01;
COLORREF Grey02;
COLORREF Grey03;
COLORREF Grey04;
COLORREF Grey05;
COLORREF Grey06;
COLORREF Grey07;
COLORREF Grey08;
COLORREF Grey09;
COLORREF Grey10;
COLORREF Grey11;
COLORREF Grey12;
COLORREF Grey13;
COLORREF Grey14;
COLORREF Grey15;
COLORREF Grey16;
COLORREF Grey17;
COLORREF Grey18;
COLORREF Grey19;
// Density Plot Colormap
COLORREF Color00;
COLORREF Color01;
COLORREF Color02;
COLORREF Color03;
COLORREF Color04;
COLORREF Color05;
COLORREF Color06;
COLORREF Color07;
COLORREF Color08;
COLORREF Color09;
COLORREF Color10;
COLORREF Color11;
COLORREF Color12;
COLORREF Color13;
COLORREF Color14;
COLORREF Color15;
COLORREF Color16;
COLORREF Color17;
COLORREF Color18;
COLORREF Color19;
// Other colors
COLORREF SelColor;
COLORREF MeshColor;
COLORREF BlockColor;
COLORREF LineColor;
COLORREF RegionColor;
COLORREF GridColor;
COLORREF BackColor;
COLORREF TextColor;
COLORREF NodeColor;
COLORREF RealFluxLineColor;
COLORREF ImagFluxLineColor;
COLORREF MaskLineColor;
COLORREF NameColor;
COLORREF RealVectorColor;
COLORREF ImagVectorColor;
// Operations
public:
void DoContours(CDC *pDC, int *p, int side, int Aflag);
void PlotFluxDensity(CDC *pDC,int elmnum,int flag);
void DisplayPointProperties(double px, double py);
void DrawUserContour(BOOL flag);
void EraseUserContour(BOOL flag);
void SpecialLine(CDC *pDC, int x0, int y0, int x1, int y1, BOOL flag);
void PlotSelectedElm(CDC *pDC,CElement &elm);
void RedrawView();
BOOL IsMinimized();
BOOL ScanPreferences();
BOOL WritePreferences();
void CheckIt();
void LuaViewInfo();
void MyMoveTo(CDC *pDC, int x, int y);
void MyLineTo(CDC *pDC, int x, int y);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFemmviewView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnInitialUpdate();
virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFemmviewView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CFemmviewView)
afx_msg void OnZoomIn();
afx_msg void OnSnapGrid();
afx_msg void OnShowMesh();
afx_msg void OnShowGrid();
afx_msg void OnSetGrid();
afx_msg void OnCplot();
afx_msg void OnDplot();
afx_msg void OnZoomNatural();
afx_msg void OnZoomOut();
afx_msg void OnZoomWindow();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnEditCopy();
afx_msg void OnReload();
afx_msg void OnMenuArea();
afx_msg void OnMenuContour();
afx_msg void OnMenuPoint();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnMenuPlot();
afx_msg void OnMenuIntegrate();
afx_msg void OnMenushowpts();
afx_msg void OnKbdZoom();
afx_msg void OnSmooth();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnPanDown();
afx_msg void OnPanLeft();
afx_msg void OnPanRight();
afx_msg void OnPanUp();
afx_msg void OnViewCircprops();
afx_msg void OnEditCopyAsMetafile();
afx_msg void OnViewBHcurves();
afx_msg void OnViewInfo();
afx_msg void OnViewShownames();
afx_msg void OnVplot();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
};
#ifndef _DEBUG // debug version in femmviewView.cpp
inline CFemmviewDoc* CFemmviewView::GetDocument()
{ return (CFemmviewDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////

62
femm/GRIDDLG.CPP Normal file
View File

@ -0,0 +1,62 @@
// GRIDDLG.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "GRIDDLG.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// GRIDDLG dialog
GRIDDLG::GRIDDLG(CWnd* pParent /*=NULL*/)
: CDialog(GRIDDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(GRIDDLG)
m_gridsize = 0.0;
//}}AFX_DATA_INIT
}
void GRIDDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(GRIDDLG)
DDX_Control(pDX, IDC_COORDS, m_coords);
DDX_Text(pDX, IDC_GRIDSIZE, m_gridsize);
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_GRIDSIZE, m_IDC_gridsize);
}
BEGIN_MESSAGE_MAP(GRIDDLG, CDialog)
//{{AFX_MSG_MAP(GRIDDLG)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// GRIDDLG message handlers
BOOL GRIDDLG::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_coords.SetCurSel(coords);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void GRIDDLG::OnOK()
{
// TODO: Add extra validation here
coords=m_coords.GetCurSel();
CDialog::OnOK();
}

41
femm/GRIDDLG.H Normal file
View File

@ -0,0 +1,41 @@
// GRIDDLG.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// GRIDDLG dialog
class GRIDDLG : public CDialog
{
// Construction
public:
GRIDDLG(CWnd* pParent = NULL); // standard constructor
BOOL coords;
// Dialog Data
//{{AFX_DATA(GRIDDLG)
enum { IDD = IDD_GRIDDLG };
CComboBox m_coords;
double m_gridsize;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(GRIDDLG)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(GRIDDLG)
virtual BOOL OnInitDialog();
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
CLuaEdit m_IDC_gridsize;
};

85
femm/GapIntegral.cpp Normal file
View File

@ -0,0 +1,85 @@
// GapIntegral.cpp : implementation file
//
#include "stdafx.h"
#include "femm.h"
#include "problem.h"
#include "XYPlot.h"
#include "femmviewdoc.h"
#include "GapIntegral.h"
// GapIntegral dialog
IMPLEMENT_DYNAMIC(GapIntegral, CDialog)
GapIntegral::GapIntegral(CWnd* pParent /*=NULL*/)
: CDialog(GapIntegral::IDD, pParent)
{
}
GapIntegral::~GapIntegral()
{
}
void GapIntegral::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_AGENAME, m_AGEname);
DDX_Control(pDX, IDC_GAPINTTYPE, m_IntType);
}
BEGIN_MESSAGE_MAP(GapIntegral, CDialog)
//{{AFX_MSG_MAP(GapIntegral)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// GapIntegral message handlers
BOOL GapIntegral::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CArray<CAirGapElement,CAirGapElement&> &agelist=*pagelist;
int i;
// TODO: Add extra initialization here
for(i=0;i<agelist.GetSize();i++)
m_AGEname.AddString(agelist[i].BdryName);
m_AGEname.SetCurSel(0);
if (bIncremental==FALSE)
{
m_IntType.AddString("Torque");
m_IntType.AddString("Force");
m_IntType.AddString("Energy");
}
else{
m_IntType.AddString("Incremental Torque");
m_IntType.AddString("Incremental Force");
}
m_IntType.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void GapIntegral::OnOK()
{
// TODO: Add extra validation here
CArray<CAirGapElement,CAirGapElement&> &agelist=*pagelist;
BdryName=agelist[m_AGEname.GetCurSel()].BdryName;
if (bIncremental==FALSE)
{
myIntType=m_IntType.GetCurSel();
}
else{
myIntType=m_IntType.GetCurSel() + 3;
}
CDialog::OnOK();
}

Some files were not shown because too many files have changed in this diff Show More