cogrotortest.cxx
来自「有限元学习研究用源代码(老外的),供科研人员参考」· CXX 代码 · 共 244 行
CXX
244 行
#line 7 "cogRotorTest.html"
#include <iostream.hxx>
#include <math.h>
#include "cogeometries.hxx"
#include "cogfunction.hxx"
#include "wzsegment.hxx"
typedef enum{Dirichlet,Neumann,Cauchy} BoundaryCondition;
const Deviceregions = 20;
class DeviceClass: public wzSegmentDescription{
public:
DeviceClass();
// this order is relevant for the assignment of numbers:
wzRegion Gehaeuse; // default: 1
wzRegion Magnet; // 2
wzRegion Rotor; // 3
wzRegion Achse; // 4
wzRegion Luft; // 5
wzRegion Spalt; // 6
wzRegion Oeffnung; // 7
wzRegion Hohlraum; // 8
wzFace face; // default
wzEdge edge; // default
wzVertex vertex; // default
};
extern DeviceClass Device;
DeviceClass::DeviceClass()
:wzSegmentDescription()
,Gehaeuse("Gehaeuse", wzColor(0x00,0x00,0x00))
,Magnet("Magnet", wzColor(0x10,0x20,0x04))
,Rotor("Rotor", wzColor(0x30,0x30,0x00))
,Achse("Achse", wzColor(0x20,0x30,0x04))
,Luft("Luft", wzColor(0x00,0x00,0x70))
,Spalt("Spalt", wzColor(0x00,0x00,0x70))
,Oeffnung("Oeffnung", wzColor(0x00,0x00,0x70))
,Hohlraum("Hohlraum", wzColor(0x00,0x00,0x70))
,face("face", wzColor(0x00,0x00,0xff))
,edge("edge", wzColor(0x00,0x00,0xff))
,vertex("vertex", wzColor(0x20,0x10,0x00))
{;}
void cogmain();
DeviceClass Device;
int main()
{try{
Device;
cogmain();
// cogView.show();
cerr<<"\ntest was successful;\n";
}catch(wzFailure f){
cerr << "\ntest has failed: "<< f.description << "\n";
return 1;
}catch(...){
cerr << "\ntest has failed: "<< "unexpected error" << "\n";
return 2;
} return 0;
}
// Berechnung der Konstanten, die gebraucht werden, aus der
// vorhandenen technischen Zeichnung
cogFloat rGehaeuse = 29.0;
cogFloat rMagnet = 22.0;
cogFloat rRotor = 21.5;
cogFloat rAchse = 3.0;
cogFloat rKleinerKreis = 0.79;
cogFloat rGrosserKreis = 2.93;
cogFloat dMagnet = 10.0;
cogFloat dRotor = 2.5;
cogFloat dOeffnung = 0.75;
cogFloat Winkel = atan(1.0)/2.5; // 18 grad
cogFloat yKleinerKreis = dRotor + rKleinerKreis;
cogFloat yGrosserKreis = dRotor + rGrosserKreis;
cogFloat xKleinerKreis = yKleinerKreis/tan(Winkel);
cogFloat xGrosserKreis = yGrosserKreis/tan(Winkel);
//cogFloat rmKleinerKreis = 9.85 + rKleinerKreis;
//cogFloat rmGrosserKreis = rRotor - 1.0 - rGrosserKreis;
cogFloat rKleinerKreis2 = rKleinerKreis*rKleinerKreis;
cogFloat rGrosserKreis2 = rGrosserKreis*rGrosserKreis;
static cogSegment DeviceRegions(const cogPoint& x)
{
cogFloat al,dd,xx=x[0],yy=x[1],x1,y1;
xx *= 30; yy *= 30;
dd=sqrt(xx*xx+yy*yy);
if(yy<0) yy = -yy;
if(xx<0) xx = -xx;
if(dd>rGehaeuse){return Device.Gehaeuse;}
if(dd>rMagnet){
if(yy>dMagnet) return Device.Magnet;
return Device.Luft;
}
if(dd>rRotor) {return Device.Spalt;}
if(dd<rAchse) {return Device.Achse;}
// angular transformation to the range (0...18 degree)
if(xx>yy) al = atan(yy/xx); else al = 2*atan(1) - atan(xx/yy);
al = al - ((int)(al/(2*Winkel)))*2*Winkel; if(al>Winkel) al=2*Winkel-al;
// wzAssert(al>=-0.01 && al<=Winkel+0.01);
yy = sin(al)*dd; xx = cos(al)*dd;
// wzAssert(xx>-0.01 && yy>-0.01);
// Herausschneiden des Hohlraums:
if(yy>dRotor){
if(xx<xKleinerKreis){
x1=xx-xKleinerKreis; y1=yy-yKleinerKreis;
if(x1*x1+y1*y1<rKleinerKreis2) return Device.Hohlraum;
}else if(xx>xGrosserKreis){
x1=xx-xGrosserKreis; y1=yy-yGrosserKreis;
if(x1*x1+y1*y1<rGrosserKreis2) return Device.Hohlraum;
}else
return Device.Hohlraum;
}
// Herausschneiden der Oeffnung:
al = Winkel-al;
yy = sin(al)*dd; xx = cos(al)*dd;
if(xx>xGrosserKreis){
if(yy<dOeffnung) return Device.Oeffnung;
}
return Device.Rotor;
}
/*
<H1>Connection with IBG 1.3</H1>
*/
#include "cog2ibgd.hxx"
/*
<P><B>IBGD</B> is the old version of the <B>cogeometry concept</B>
used by the C-version of the grid generator <B>IBG</B>. To allow to
use the new C++ package COG 1.0 with the C-version of IBG it is useful
to have a conversion of a <B>cogeometry</B> into the related data
structure of IBGD <B>ibGeometry</B>.
<P>There is also some interest in the other direction. It allows to
look at geometries of type <B>ibGeometry</B> using applications based
on <B>COG</B> like the geometry viewer. One application is to look at
the geometry of a grid created by IBG. Indeed, an IBG grid can be
used to define an <B>ibGeometry</B> via the function <B>ibgdGrid</B>.
<P>In this example, we consider the whole way: Starting from a
<B>cogeometry</B>, we create a <B>ibGeometry</B>, create the related
<B>ibGrid</B>, define the <B>ibGeometry</B> of this grid, and the
related cogeometry using the class <B>CogeometryIBGD</B>.
<P>We have to include here a lot of code copied from standard IBG
examples:
*/
extern "C"{
#include <stdio.h>
#include <math.h>
#include "ibg.h"
#include "ibgd.h"
#include "ibgdefault.h"
#include "ibgg.h"
#include "ibgapplication.h"
static void refineRegion(ibgPtObject This, ibgPoint *n, ibgFloat *length)
{
*length = 2.0;
}
static int refineEdge(ibgPtObject This, ibgPoint *x1, ibgPoint *x2)
{ibgFloat dx,dy,dz,dd;
if(ibgpSegment(*x1)==ibgpSegment(*x2)) return ibgFalse;
dx = ibgpX(*x1)[0]-ibgpX(*x2)[0];
dy = ibgpX(*x1)[1]-ibgpX(*x2)[1];
dz = ibgpX(*x1)[2]-ibgpX(*x2)[2];
/* here we refine an edge near the boundary */
// if(dx*dx+dy*dy+dz*dz < 0.0004) return ibgFalse; else return ibgTrue;
if(dx*dx+dy*dy+dz*dz < 0.00005) return ibgFalse; else return ibgTrue;
}
}
#include "cogmap.hxx"
void cogmain()
{ibgFloat x[2] = {0.0,1.0},
y[2] = {0.0,1.0},
z[2] = {0.0,1.0};
ibGeometry g0,g1;
ibGrid *grid;
ibgApplicationInit();
/*
Now comes the first interesting part - construction of a simple
example <B>cogeometry</B> and definition of the related
<B>ibGeometry</B>:
*/
CogeometrySimpleRegions gDevice(DeviceRegions);
// cogOutput(&gDevice);
g0 = ibgdCogeometry(&gDevice);
/*
now we have to call the grid generator IBG and to convert the
resulting grid with <B>ibgdGrid</B> into another <B>ibGeometry</B> -
this is again standard IBG example code:
*/
ibggDefaultLineNormal = 1000.0;
grid=ibGridGenerate(g0, /* geometry description */
10000, /* approx. point number (for malloc to minimize realloc) */
2,x,3, /* coarse grid data */
2,y,3, /* 2 values in x and y data field, + 3 points by reg. ref. */
2,z,3, /* for the 2D variant only 1 value in z direction */
refineRegion,ibgNULL, /* isotropical refinement */
ibggDefaultRefinlFace,ibgNULL,
ibggDefaultRefineLine,ibgNULL,
ibggDefaultRefinlNode,ibgNULL,
refineEdge,ibgNULL); /* anisotropical refinement */
ibgNameFile = "cogrotor";
ibgOutput(grid);
/* if we like, we may later read it again with
ff = fopen("cogrotor.smp","r");
grid = ibgOtSimplex(ff);
*/
g1 = ibgdGrid(grid,0,0);
/*
<H2>class CogeometryIBGD</H2>
<P>Now comes the second interesting part - the constructor call for
<B>CogeometryIBGD</B>:
*/
CogeometryIBGD cogResult(g1);
CogeometryBox cBox(&cogResult);
cBox.setMinimum(0,0,0);
cBox.setMaximum(1,1,1);
cogOutput(&cBox,&cogResult,&gDevice);
/*
*/
ibgdQuit();
}
/*
*/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?