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

📄 geometry.h

📁 有限元学习研究用源代码(老外的),供科研人员参考
💻 H
字号:
#include <windows.h>
#include "usertype.h"

#define QUADCODE       2
#define TRICODE        3
#define RECTCODE       4
#define INTERIOR       0x00
#define EXTERIOR       0x01
#define CONDUCTING     0x02
#define MAGNETIC       0x04
#define ABSORBING      0x08

#define INTERIORMASK   0xfe
#define PROPERTYMASK   0x0f
#define CONNECTMASK    0x40

const double PI = 3.1415927;

#define MAXID         60000

class surnode{
public:
	ID             cellid;
	SURSN          node;
	PRPTY          property;  // BIT 6 IS A CONNECT-MASK
	real           x, y;
	unsigned short index;
	surnode& operator=(const surnode&);
	surnode(){cellid = 0; node = 0; property = 0;};
	void draw(HDC);
};

class surside{
public:
	ID             cellid;
	SURSN          side;
	PRPTY          property;   // BIT 6 IS A CONNECT-MASK
	unsigned short index;
	surside& operator=(const surside&);
	surside(){cellid = 0; side = 0; property = 0;};
	void draw(HDC, double, double, double, double);
};


class block{
protected:
	 ID           id;
	 double       epsilon, sigma, mu, sigma_mu;
	 double       xloc, yloc;

public:
	 surnode      *exteriornode;
	 surside      *exteriorside;
public:
	 ID           getid(void){return id;};
	 void         setid(int i){id = i;};
	 void         assignid(void);
	 ID           getnextavailableid(ID);
	 int          proximity(block *, int, block *, int);
	 int          connectednodes(int, block *);
	 int          connectedsides(int, block *);
	 void         disconnect(void);
	 void         disconnect(class blocklist*, class blocklist&);
	 COUNT        connect(class blocklist&);
	 void         clearconnectmask(void);
	 int          connectednodes(int, class block *, int);
	 int          connectexteriornode(int, class listcell *);
	 int          connectexteriorside(void);
	 void         connectsides(int, class block *, int);
	 int          disconnectnodes(int, class listcell *);
	 int          disconnectsides(int, class listcell *);
	 int          modifyproperty(HDC, dRECT);
	 int          modifyproperty(HDC, dPOINT);
	 void         move(double, double);
	 void         relmove(dPOINT);
	 int          inbox(dRECT);
	 int          outsidewindow(void);
    block *      enclosepoint(dPOINT);
    block *      hook(dPOINT, int *);
    void         drawsidesandnodes(HDC);
    void         clearnumber(void);
    COUNT        numberexteriorelmts(COUNT);
    COUNT genexteriornodeinfo(FILE *, COUNT);
    COUNT genexteriorsideinfo(FILE *, COUNT);
    int          withinboundary(dPOINT);
    int          withinboundary(double, double);
    int          withinboundary(dPOINT, double, double);
    int          withinboundary(dPOINT, double);
    void         getsize(dRECT *);
    void         replace(ID, ID);
    virtual void draw(HDC) = 0;
    virtual void highlight(HDC) = 0;
    virtual void move(dPOINT, double, double) = 0;
    virtual void outline(HDC, short, HPEN, dPOINT) = 0; //move
    virtual void outline(HDC, short, HPEN, dPOINT, double, double) = 0; //rotate
    virtual void outline(HDC, short, HPEN, dPOINT, int) = 0; //reshape
    virtual void outline(HDC, short, HPEN, double, dPOINT) = 0; //rescale
    virtual void resize(double) = 0;      // resize to new factor
    virtual void resize(dPOINT, int) = 0; // reshape to rew corner
    virtual void refine() = 0;
    virtual void getreference(dPOINT *) = 0;
    virtual block * copy(void) = 0;
    virtual int  nvertex(void) = 0;
    virtual void vertex(dPOINT *, int)= 0;
    virtual int    cellcount(void) = 0;
    virtual unsigned int exteriorelmtcount(void) = 0;
    virtual unsigned int interiornodecount(void) = 0;
    virtual unsigned int interiorsidecount(void) = 0;
    virtual double allowablesnap(void) = 0;
    virtual void   dialog(void) = 0;
    virtual void  generatenodes(void) = 0;
    virtual void  initnodes(void) = 0;
    virtual void  initsides(void) = 0;
    virtual void  snaptogrid(void) = 0;
    virtual COUNT gencellinfo(FILE *, COUNT) = 0;
    virtual COUNT geninteriorsideinfo(FILE *, COUNT) = 0;
    virtual COUNT geninteriornodeinfo(FILE *, COUNT) = 0;
    virtual int   savegdfinfo(FILE *) = 0;
    virtual int   readgdfinfo(FILE *) = 0;
    virtual dPOINT snaptonode(dPOINT) = 0;
    virtual int   snaptoCSN(dPOINT, unsigned int *, unsigned int *) = 0;
    virtual CELLINFO cellenquiry(unsigned int i, unsigned int j) = 0;
    virtual SIDEINFO sideenquiry(unsigned int, unsigned int) = 0;
    virtual NODEINFO nodeenquiry(unsigned int, unsigned int) = 0;
};


class listcell{
public:
    block    *cellblk;
    listcell *next;

};


class rectblk:public block{
private:
    double  length1, length2, angle;
    int div1, div2;

public:
    rectblk(void){exteriornode = NULL; exteriorside = NULL;};
    rectblk(double, double, double, double,
	    double, double, double, double, int, int, double);
    ~rectblk();
    rectblk& operator=(rectblk&);
    void draw(HDC);
    void highlight(HDC);
    void drawinteriorcell(HDC, HPEN);
    void move(dPOINT, double, double);
    void outline(HDC, short, HPEN, dPOINT);  //move
    void outline(HDC, short, HPEN, dPOINT, double, double); //rotate
    void outline(HDC, short, HPEN, dPOINT, int); //reshape
    void outline(HDC, short, HPEN, double, dPOINT); //rescale
    void outline(HDC, short, HPEN, double, double, dPOINT, double, double); //kernel
    void resize(double);
    void resize(double, double);
    void resize(dPOINT, int);

    void refine();
    void reconfig(double, double, double, double,
                   double, double, double, double, int, int, double);
    void getreference(dPOINT *ref){ref->x = xloc; ref->y=yloc;};
    block * copy(void);
    int    nvertex(void){return 4;};
    void   vertex(dPOINT *, int);
    void   eval(dPOINT, dPOINT *, double *, double *, int);
    double getl1(void){return length1;};
    double getl2(void){return length2;};
    void   generatenodes(void);
    void   initnodes(void);
    void   initsides(void);
    int    cellcount(void){return div1*div2;};
    unsigned int exteriorelmtcount(void){ return 2*(div1+div2);};
    unsigned int interiornodecount(void){ return (div1-1)*(div2-1);};
    unsigned int interiorsidecount(void){ return div1*(div2-1) + div2*(div1-1);};
    double allowablesnap(void);
    void   dialog(void);
    void   snaptogrid(void);
    friend BOOL FAR PASCAL _export RectDlgProc(HWND, UINT, UINT, LONG);
    COUNT gencellinfo(FILE *, COUNT);
    COUNT geninteriorsideinfo(FILE *, COUNT);
    COUNT geninteriornodeinfo(FILE *, COUNT);
    int   savegdfinfo(FILE *);
    int   readgdfinfo(FILE *);
    dPOINT snaptonode(dPOINT);
    int   snaptoCSN(dPOINT, unsigned int *, unsigned int *);
    CELLINFO cellenquiry(unsigned int i, unsigned int j);
    SIDEINFO sideenquiry(unsigned int, unsigned int);
    NODEINFO nodeenquiry(unsigned int, unsigned int);

};


class quadblk:public block{
private:
    double  cornerx1, cornery1, cornerx2, cornery2, cornerx3, cornery3;
    int     div1, div2;
    void    ordervertex(void);
public:
    quadblk(void){exteriornode = NULL; exteriorside = NULL;};
    quadblk(double, double, double, double, double, double, double,
	    double, double, double, double, double, int, int);
    ~quadblk();
    quadblk& operator=(const quadblk&);

    void draw(HDC);
    void highlight(HDC);
    void drawinteriorcell(HDC, HPEN);
    void move(dPOINT, double, double);
    void outline(HDC, short, HPEN, dPOINT);  //move
    void outline(HDC, short, HPEN, dPOINT, double, double); //rotate
    void outline(HDC, short, HPEN, dPOINT, int); //reshape
    void outline(HDC, short, HPEN, double, dPOINT); //rescale
    void outline(HDC, short, HPEN, double, dPOINT, dPOINT, int, double, double); //kernel
    void resize(double);
    void resize(dPOINT, int);

    void refine();
    void reconfig(double, double, double, double, double, double, double,
		   double, double, double, double, double, int, int);
    void getreference(dPOINT *ref){ref->x = xloc; ref->y=yloc;};
    block * copy(void);
    int    nvertex(void){return 4;};
    void   vertex(dPOINT *, int);
    void   generatenodes(void);
    void   initnodes(void);
    void   initsides(void);
    int    cellcount(void){return div1*div2;};
    unsigned int exteriorelmtcount(void){ return 2*(div1+div2);};
    unsigned int interiornodecount(void){ return (div1-1)*(div2-1);};
    unsigned int interiorsidecount(void){ return div1*(div2-1) + div2*(div1-1);};
    double allowablesnap(void);
    void   dialog(void);
    void   snaptogrid(void);
    friend BOOL FAR PASCAL _export QuadDlgProc(HWND, UINT, UINT, LONG);
    COUNT gencellinfo(FILE *, COUNT);
    COUNT geninteriorsideinfo(FILE *, COUNT);
    COUNT geninteriornodeinfo(FILE *, COUNT);
    int   savegdfinfo(FILE *);
    int   readgdfinfo(FILE *);
    dPOINT snaptonode(dPOINT);
    int   snaptoCSN(dPOINT, unsigned int *, unsigned int *);
    CELLINFO cellenquiry(unsigned int, unsigned int);
    SIDEINFO sideenquiry(unsigned int, unsigned int);
    NODEINFO nodeenquiry(unsigned int, unsigned int);


};


class triblk:public block{
private:
    double  cornerx1, cornery1, cornerx2, cornery2;
    int     div1;
    void    ordervertex(void);
public:
    triblk(void){exteriornode = NULL; exteriorside = NULL;};
    triblk(double, double, double, double, double, double, double,
	    double, double, double, int);
    ~triblk();
    triblk& operator=(const triblk&);

    void draw(HDC);
    void highlight(HDC);
    void drawinteriorcell(HDC, HPEN);
    void move(dPOINT, double, double);
    void outline(HDC, short, HPEN, dPOINT);  //move
    void outline(HDC, short, HPEN, dPOINT, double, double); //rotate
    void outline(HDC, short, HPEN, dPOINT, int); //reshape
    void outline(HDC, short, HPEN, double, dPOINT); //rescale
    void outline(HDC, short, HPEN, double, dPOINT, dPOINT, int, double, double); //kernel
    void resize(double);
    void resize(dPOINT, int);

    void refine();
    void reconfig(double, double, double, double, double, double, double,
		   double, double, double, int);
    void getreference(dPOINT *ref){ref->x = xloc; ref->y=yloc;};
    block * copy(void);
    int    nvertex(void){return 3;};
    void   vertex(dPOINT *, int);
    void   generatenodes(void);
    void   initnodes(void);
    void   initsides(void);
    int    cellcount(void){return (div1 * (div1+1) + div1 * (div1 - 1)) / 2;};
    unsigned int exteriorelmtcount(void){ return (3 * div1);};
    unsigned int interiornodecount(void){ return (div1-1)*(div1-2)/2;};
    unsigned int interiorsidecount(void){ return 3 * (div1-1) * div1 / 2;};
    double allowablesnap(void);
    void   dialog(void);
    void   snaptogrid(void);
    friend BOOL FAR PASCAL _export TriDlgProc(HWND, UINT, UINT, LONG);
    COUNT gencellinfo(FILE *, COUNT);
    COUNT geninteriorsideinfo(FILE *, COUNT);
    COUNT geninteriornodeinfo(FILE *, COUNT);
    int   savegdfinfo(FILE *);
    int   readgdfinfo(FILE *);
    dPOINT snaptonode(dPOINT);
    int   snaptoCSN(dPOINT, unsigned int *, unsigned int *);
    CELLINFO cellenquiry(unsigned int, unsigned int);
    SIDEINFO sideenquiry(unsigned int, unsigned int);
    NODEINFO nodeenquiry(unsigned int, unsigned int);

};


class blocklist{
private:
    listcell *head;
public:

    blocklist(void);

    int  empty(void);
    int  blockcount(void);
    int  cellcount(void);
    int  interiornodecount(void);
    int  interiorsidecount(void);
    void insert(block *);
    void reverse(void);
    void transfer(blocklist&);
    void copy(blocklist&);
    void draw(HDC);
    void highlight(HDC);
    void clear(void);
    void center(dPOINT *);
    void outline(HDC);
    void outline(HDC, short, HPEN, dPOINT, dPOINT); // for moved objects
    void outline(HDC, short, HPEN, dPOINT, double, double); // for rotated objects
    void outline(HDC, short, HPEN, dPOINT, double); // for scaled objects
    void move(double, double, double, double);  // move to new loc
    void move(dPOINT, double, double); // move and rotate
    void move(dPOINT, double);  // move to new scale
    void relmove(dPOINT);
    int  selectblks(dRECT, blocklist&);
    block * enclosepoint(dPOINT);
    block * hook(dPOINT, int *);
    block * firstblock(void);
    listcell * gethead(void);
    int  nonexist(block *);
    int  idused(ID);
    block * by_id(ID);
    void  disconnect(blocklist&);
    COUNT connect(blocklist&);
    void  clearconnectmask(void);
    double  allowablesnap(void);
    int   remove(block *);
    int   modifyproperty(HDC, dRECT);
    int   modifyproperty(HDC, dPOINT);
    void  clearnumber(void);
    int   readgdfinfo(FILE *);
    int  withinboundary(dPOINT);
    int  withinboundary(dPOINT, double, double);
    int  withinboundary(dPOINT, double);
    void assignid(void);
    dRECT getsize(void);
};


⌨️ 快捷键说明

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