mainfunc.c
来自「有限元学习研究用源代码(老外的),供科研人员参考」· C语言 代码 · 共 114 行
C
114 行
/* last edit: Ilja Schmelzer -------------- 10-JUN-1994 17:57:36.12 */
/************************************************************************/
/* */
/* <<< I B G >>> - Intersection - Based Grid generation package */
/* */
/* Version 1.1 by Ilja Schmelzer schmelzer@iaas-berlin.d400.de */
/* */
/* to be distributed under IBG license conditions (see "readme.ibg") */
/* */
/************************************************************************/
/*
Intersection-Based Grid Generator Version 1.1
author: Ilja Schmelzer, IAAS,
Mohrenst. 39, D-10117 Berlin Germany
e-mail: schmelzer@iaas-berlin.d400.de
Tel: +49 30 20377 567
Fax: +49 30 200 4975
This is an example for a main program. It shows the possibility to define
a function value for each point by an "analytical" function and the usage
of this function value for a refinement criterion.
It shows also some properties of the anisotropical refinement - for refinement
in skew directions we obtain an isotropical grid.
*/
#include <stdio.h>
#include <math.h>
#include "ibg.h"
#include "ibgd.h"
#include "ibgg.h"
#include "ibgapplication.h"
/* An example of a C-function which will be computed for each point. It creates
function with a sharp front of high 1.
*/
ibgFloat ff(ibgPtObject This, ibgPoint *n)
{ibgFloat *rx = ibgpX(*n), xx = rx[0], yy = rx[1], zz = rx[2], rr=0.537, r0;
rr *= rr; xx *= xx; yy *= yy;
rr *= rr; xx *= xx; yy *= yy;
r0 = rr; rr = rr - xx - yy;
rr *= rr; rr -= r0;
if(rr>0) rr=0; return -rr/r0;
}
/* an example of a nontrivial refinement criterion. The problem is to
get a criterion which is sharp enough to catch the front.
*/
static void refineRegion(ibgPtObject This, ibgPoint *n, ibgFloat *length)
{
ibgFloat ff = ibgpF(*n)[0];
if(ff<=0) {*length = 2.0; return;}
*length = 1 - 0.8*sqrt(ff);
}
/* an example of an anisotropical refinement criterion. This function has to
return ibgTrue if the edge from x1 to x2 must be refined. It is possible to
use the coordinates, the segment number and function values of the points
*/
static int refineEdge(ibgPtObject This, ibgPoint *x1, ibgPoint *x2)
{ibgFloat dx,dy,dz,dd,df;
dx = ibgpX(*x1)[0]-ibgpX(*x2)[0];
dy = ibgpX(*x1)[1]-ibgpX(*x2)[1];
dz = ibgpX(*x1)[2]-ibgpX(*x2)[2];
df = ibgpF(*x1)[0]-ibgpF(*x2)[0];
dd = sqrt(dx*dx+dy*dy+dz*dz);
if(df<0) df = -df;
if ((df/dd) > 2) return ibgTrue;
return ibgFalse;
}
int main()
{
/* the data of the coarse grid - cuboid */
ibgFloat x[2] = {-1.0,1.0},
y[2] = {-1.0,1.0},
z[2] = { 0.0,1.0};
ibGeometry g0;
ibGrid *grid;
ibgApplicationInit(); /* calls also ibgdInit and ibGridInit */
g0 = ibgdNew(2); /* start: only one region 2 */
g0 = ibgdFunction(g0,0,ff,ibgNULL);
/* use explicite minimal refinement if the criterion gives too fine grids */
ibggDmin[0] = ibggDmin[1] = ibggDmin[2] = 0.02;
/* grid generator call. */
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. */
1,z,0, /* for the 2D variant only 1 value in z direction */
/* 2,z,3, alternative: for the 3D variant 2 values in z direction */
/* refinement criteria: */
refineRegion,ibgNULL, /* isotropical refinement */
ibggDefaultRefineFace,ibgNULL,
ibggDefaultRefineLine,ibgNULL,
ibggDefaultRefineNode,ibgNULL,
refineEdge,ibgNULL); /* anisotropical refinement */
/* end of program: */
ibgNameFile = "testfunc";
ibgOutput(grid);
return ibgdQuit();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?