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

📄 mainfunctiontest.html

📁 Delaunay三角形的网格剖分程序
💻 HTML
字号:
<TITLE>COG 2.1: Functions</TITLE><PRE>#include "<A HREF="coglib.hxx">cog/coglib.hxx</A>"</PRE><H1>Functions</H1> <P>COG has interesting possibilities to work with floating pointfunctions defined on the space.  They may be used for variouspurposes, and computed and interpolated on grids.<H2>How to define functions</H2> <P>Functions may be defined on the nodes of grids, as part of the<B>wzgrid</B> data structure.  They may be also defined in C++ code.Such functions will be named <I>grid functions</I> resp. <I>internalfunctions</I>.<H3>Internal functions</H3> <P>Let's see how to define internal functions.  There are twoways: a simple one and a more complex one.<H4>Simple internal functions</H4> <P>The simple way is to define a function on points of the followingsimple type:<PRE>wzFloat f1(const wzPoint&amp; p){  return p[0]*p[0]+p[1]*p[1];}</PRE><H4>Complex internal functions</H4> <P>The second is to define a derived class of the class<B>wzPointToFloat</B> defined in <A HREF="wzfunction.hxx">wzfunction.hxx</A>.  It is useful if yourfunction depends on other parameters and you don't want to use globalparameters.  It also allows you to have several instances of functionswith the same code but different parameters:<PRE>class MyFunctionType: public wzPointToFloat{   wzFloat some_parameter;public:   MyFunctionType(wzFloat x):some_parameter(x){;}   wzFloat operator()(const wzPoint& p) const	{return p[0]*p[0]+p[1]*p[1]+some_parameter;}};MyFunctionType f2(1);MyFunctionType f3(2);</PRE><H4>Using other functions</H4> <P>In the function, you can use all what is defined on the point.  Ifyou are sure that some function values are already defined on thepoint, you can even use such function values:<PRE>wzFloat f4(const wzPoint&amp; p){  return p.f(1)-p.f(0);}</PRE> <P>Of course, if you want to use such function values, you have to becareful about the order of declarations (see below) - else, thefunction values may be undefined.<H3>Grid functions</H3> <P>Now, a grid function may be defined by computing a given internalfunction on all nodes of the grid.  So, for a simple grid<PRE>int main(){  cogenOctree gen = new CogenOctree();  gen-&gt;setBorder(0.0,1.0, 0.0,1.0);  wzgrid grid = (*gen)();</PRE> <P>we can compute the values of the functions f1 and f2, and storethem as the first and second function value:<PRE>  wzIndex i0 = grid-&gt;createFloatValue(f1);  wzIndex i1 = grid-&gt;createFloatValue(f2);  wzAssert(i0==0);  wzAssert(i1==1);</PRE> <P>The maximal number of function values <B>wzPointDimFloat</B> isdefined in <A HREF="wzpoint.hxx">wzpoint.hxx</A>.  You can alsooverwrite the values in another call:<PRE>  grid-&gt;setFloatValue(f3,i1);</PRE> <P>Grid functions can be written out and read in using the standard <A HREF="simplex.html">simplex grid format</A>.  In this way you canimport grid functions on grids created by other grid generators.<PRE>  grid-&gt;write("test.sg");  grid = new wzGrid("test.sg");</PRE><H2>Cogeometries with functions</H2> <P>Now, grid functions as well as internal functions may be using inthe geometry description. <P>What does this mean?  Whenever the cogeometry interface returns apoint, it does not only what is necessary to describe the geometry ofthis point, but also computes the function value for this point.Thus, in the case of a grid function, the function value for the pointwill be interpolated on the grid. Or, in the case of an internalfunction, it will be called for the given point. <P>The most important effect is that these function values may beused during grid generation, for example in the refinement criterion.<H3>Cogeometry with a grid function</H3> <P>Now, if you have a grid with grid functions on it, you can use agrid to <A HREF="maingridtest.html">define a geometry as usual</A>:<PRE>  gen = new CogenGrid(grid);  cogeometry geom0 = gen-&gt;geometry();</PRE> <P> In this case, the geometry description <I>geom0</I> automaticallycomputes the function values too - as the linear approximation fromthe original grid.  <H3>Cogeometry with an internal function</H3> <P>But there is also another possibility - to compute the functionsdirectly on each new node.  For this purpose, we have to define thefunction on the geometry.<PRE>  cogeometry geom1 = new CogeometryFunctionOnRegions(geom0,f1,i1);  cogeometry geom2 = new CogeometryFunctionOnRegions(geom1,f4,i0);</PRE> <P>The order of definition is also the order of computation.  First,the two values will be interpolated on the grid.  Then, the function<I>f1</I> will be computed on the node and replaces the interpolatedvalue.  Then, <I>f4</I> will be computed.  The order is in our caseimportant because <I>f4</I> uses the previously computed functionvalues. <P>Now, let's use this geometry to create a grid within the bordersof the original grid (which is done by <B>CogenGrid</B>) but slightlymore refinement:<PRE>  gen-&gt;refinementGlobal(0.5,0.5);  grid = (*gen)(geom2);</PRE> <P>Now, <I>f1</I> will be interpolated at <I>i0</I>, directlycomputed at <I>i1</I>, and then the difference will be computed by<I>f4</I> and written at <I>i0</I>.<PRE>  grid-&gt;write("test.sg");}</PRE>

⌨️ 快捷键说明

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