📄 userfunc.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>User-specified functions in QMG</title>
</head>
<body BGCOLOR="#E0FFE0" TEXT="#000000" LINK = "#0080C0" VLINK = "#004060" ALINK = "#FF0000" >
<center>
<table>
<tr>
<td>
<a href="qmg2_0_home.html"><img src=logo1.jpg alt="QMG logo"></a></td>
<td>
<h1>
User-specified functions in QMG
</h1>
</td>
</table>
</center>
One of the arguments to the mesh generator is a user-specified
size control function. Similarly, the <code>gmfem</code> routine takes as
inputs user-specified source functions, conductivity functions
and boundary conditions. QMG tries to provide a
method that is consistent, convenient and flexible for specifying all
these functions. In this page we describe the method
used for specifying
these functions. For the sake of explanation this page focuses
on the size-control function. At the end of the page we also explain
the curvature, conductivity, boundary condition and source term
functions in the <code>gmfem</code> routine.
<p>
The size-control function is a string. A simple example of a
legal size-control string is <strong>(const 0.1)</strong>;
this denotes the
function that returns the constant value 0.1 (i.e., the desired
mesh size is 0.1).
There are three places
where this size-control string can be specified.
<p>
First, it can
be attached as a property-value pair to a face of a brep.
In this case, the property name is <strong>sizecontrol</strong>,
and the value
would be the string <strong>(const 0.1)</strong>.
A size-control function
attached to a face acts only on the part of the mesh near
that face.
The routine to add property-value pairs, including
<strong>sizecontrol</strong>,
is <code><a href="ref.html#gm_addpropval">gm_addpropval</a></code>.
<p>
The second place this string is specified is as a keyword argument
to <code>gmmeshgen</code>.
The keyword name is <strong>sizecontrol</strong>
Thus, the user can say (in Matlab)
<blockquote>
<code>
m = gmmeshgen(b, 'size', '(const 0.1)');
</code>
</blockquote>
<p>
The third place a size-control string is specified is in
<code>gmmeshgen.m</code>
or <code>gmmeshgen.tcl</code>;
in these files the default size control is
defined to be <strong>(const 1e307)</strong>.
<p>
If multiple size control parameters are specified, then all of them
act as upper bounds.
<p>
Here is an example of using <strong>const</strong> size control functions.
Suppose the user types in Matlab:
<blockquote>
<code>
t = gm_cpoly([1,1; 0,2; -1,1; 0,-3], [0;3;1;1]);<br>
t{6}{1,2}={'sizecontrol'; '(const 0.05)'};<br>
m = gmmeshgen(t, 'sizecontrol', '(const 0.3)');<br>
</code>
</blockquote>
or in Tcl:
<blockquote>
<code>
gmset t [gm_cpoly {{1 1} {0 2} {-1 1} {0 -3}} {0 3 1 1}]<br>
gmset t [gm_addpropval $t e4 {sizecontrol} {"(const 0.05)"}]<br>
gmset m [gmmeshgen $t size "(const 0.3)"]<br>
</code>
</blockquote>
(Note that the quotation marks are necessary in Tcl for an
argument containing a space. See the <a href="tclsyntax.html">Tcl
syntax synopsis</a>
for more details.)
<p>
The first line creates a brep shaped like the outline of an ice-cream
cone. The second line attaches
a size control property to one edge of the cone (the edge whose
facespec is 1:2) that requests triangles of size 0.05 or smaller.
The default size passed into the mesh generator is size 0.3.
Therefore, the mesh generator will generate triangles with side
lengths approximately 0.3, except in the neighborhood of the specified
edge, where they will be size approximately 0.05. In between the
two regions the mesh size will decrease smoothly. Here is how the
mesh appears:
<p>
<img src=icecream-mesh1.jpg alt="Ice-cream cone mesh #1">
<p>
Note that the size control
parameter acts as an upper bound, but the actual
mesh size could be smaller. This is because the mesh generator must
take into account geometric constraints imposed by the domain itself.
For instance, in the above ice-cream cone example, if we had specified
"(const 20)" as the size control argument, clearly we should not
expect triangles of side-length 20 as output.
<p>
Another valid size control function is an string containing a
formula. In this case, the function has the form
<strong>(formula <em> expression</em>)</strong>.
The expression is a usual arithmetic expression
containing numbers, +, -, *, / , (), and so on.
Special functions like
sqrt, log, and so on are also OK.
In addition, the expression
can contain the special symbols %0, %1, and %2 which represent
the coordinates of the point at which the size control function
is being evaluated (the first coordinate is %0, the second is %1, and
so on).
<p>
Here is an example of this. Suppose you type in Matlab:
<blockquote>
<code>
t = gm_cpoly([1,1; 0,2; -1,1; 0,-3], [0;3;1;1]);<br>
m = gmmeshgen(t, 'sizecontrol', '(formula abs(-3.02-%1))');<br>
</code>
</blockquote>
In other words, the desired size of triangles is -3.02 minus the
y coordinate.
In this case, you would get the following mesh:
<p>
<img src=icecream-mesh2.jpg alt = "ice-cream cone mesh #2">
<p>
The expression is evaluated either by the Tcl expr function or
the Matlab eval function. These two functions have fairly similar
expression syntax; the above example works the same in both
expression evaluators.
One important difference is exponentiation. In
Tcl you say <code>pow(a,b)</code> whereas in Matlab you say
<code>a^b</code>.
A second important difference is that Tcl switches to integer
arithmetic if it detects all integers in an expression, in contrast
to Matlab, which always uses floating-point arithmetic. Thus,
you should avoid something like "%0/10" in a Tcl expression because
if %0 happens to be 1, then this expression would evaluate to 0.
Instead you should say "%0/10.0".
<p>
Security note: the Matlab
eval function has the ability to
execute arbitrary shell commands. Therefore, if you receive
a brep from an untrusted source, check the property/value pairs
carefully for undesirable shell commands. In Tcl, the
expression interpreter is made safe using a call to
<code>Tcl_MakeSafe</code>, which gives an added measure
of security against arbitrary shell commands.
<p>
In both Matlab and Tcl, the size control string is processed by
functions called
<code>gm_sizecontrol</code> and
<code>gm_sizecontrol_interior</code>. The former is used
for points on the boundary, and the latter for points on the interior.
In
Tcl, these functions are located in file <code>qmg_sizecontrol.tcl</code>.
These functions make sure that the size control string is
a parenthesized
list and that the first item in the list is
either <strong>const</strong> or
<strong>formula</strong>. Then they substitute
actual point coordinates for %0, etc., if the size control is a formula and
compute the value. These functions <code>gm_sizecontrol</code>
and <code>gm_sizecontrol_interior</code>
are invoked by
a C++ routine in source file <code>sizectl_fe.cpp</code>
of the mesh generator.
There are
two versions of this source file, one for Matlab and one for Tcl.
<p>
The size control scheme is reasonably general, but the user might
want to customize it further to suit his/her own needs, for instance,
by tying the size control to a posteriori error indicators.
In this case the user should rewrite <code>gm_sizecontrol</code>.
There is an
additional hook to help with customization of the size control.
The keyword option <strong>userdata</strong> can be passed to the
mesh generator
(e.g., m = gmmeshgen(t, 'userdata', 'somestring',...)); the value
of this string is passed verbatim to
<code>gm_sizecontrol</code> and
<code>gm_sizecontrol_interior</code>
on every invocation as one of their arguments.
Neither routine uses this argument.
<p>
Another user-specified function for the mesh generator is the
curvature control. This is specified by a value attached to
property <strong>curvecontrol</strong>
associated with faces. It is also specified by a
<strong>curvecontrol</strong> keyword option to <code>gmmeshgen</code>.
This function is interpreted by function <code>gm_curvecontrol</code>
in both Matlab and Tcl.
In
Tcl, this function is located in file <code>qmg_sizecontrol.tcl</code>.
<p>
The other functions specified by the user—conductivity, source term, and
boundary conditions—are all associated with
<code>gmfem</code> (Matlab only).
The specification of these is very similar, except there is an alternate
form of specifying a formula: <strong>vecformula</strong>.
If the user specifies
a vecformula, then when the formula is eval'd, %0 will have substituted
a column vector of x-coordinates instead of a single x-coordinate, and
similarly for %1 and so on. (The column vector for %0 will have the same
number of entries as the vector for %1). The formula is expected to
return a column vector of function values of the same size. The purpose
of the vecformula option is
to speed up processing in Matlab, since vector formulas are much faster
than evaluation by loops. An example of a vector formula would be
<code>(vecformula (sqrt(%0.^2 + %1.^2)))</code>.
<p>
Conductivity is
handled by <code>gm_conductivity</code>, which can be customized
by the user as mentioned above. The default conductivity is
<strong>(const 1.0)</strong>.
As above, the user can specify conductivities as property-value
pairs to top level faces only or as an argument to <code>gmfem</code>.
The property name for conductivity is <strong>conductivity</strong>.
If the user
specifies both, then the property-value pair takes precedence.
<p>
Source terms are handled by
<code>gm_source</code>. The default is
<strong>(const 0.0)</strong>. Source terms can also be
property-value pairs of top level faces.
As with conductivity, property
value pairs take precedence over specification as an argument to
<code>gmfem</code>.
The property name for a source term is <strong>source</strong>.
<p>
Boundary conditions are handled by
<code>gm_bdrycond</code>. Unlike conductivity and source,
there is no argument to <code>gmfem</code> for boundary conditions;
they must be property-value pairs on the faces of the brep
of dimension <em>d</em>−1, where <em>d</em>
is the dimension of the brep. The
property name is <strong>bc</strong>. The value is the boundary condition,
which has a somewhat different syntax. It is specified
as an ordered pair (<em>type</em> <em>string</em>); where
<em>type</em> is either <strong>d</strong> or <strong>n</strong> (for
Dirichlet or Neumann) and <em>string</em> is a string of the kind
described
above, for example, <strong>(const 0.1)</strong> or
<strong>(formula %0+%1)</strong>. The parentheses are part
of the syntax.
The default boundary condition is <strong>(n (const 0))</strong>,
i.e.,
<em>du</em>/<em>dn</em>=0,
which corresponds to an insulated boundary. Thus, for
a 2-dimensional problem, to add a Dirichlet condition of constant
10.0 to face 1:2, you would type
<blockquote>
<code>
[scrap,p] = size(t{6}{1,2});<br>
t{6}{1,2}{0,p}='bc';<br>
t{6}{1,2}{1,p}='(d (const 10.0))';<br>
</code>
</blockquote>
<hr>
<p>
This documentation is written by
<a href="http://www.cs.cornell.edu/home/vavasis/vavasis.html">Stephen A.
Vavasis</a> and is
copyright ©1999 by
<a href="http://www.info.cornell.edu/CUHomePage.html">Cornell
University</a>.
Permission to reproduce this documentation is granted provided this
notice remains attached. There is no warranty of any kind on
this software or its documentation. See the accompanying file
<a href="copyright.html">'copyright'</a>
for a full statement of the copyright.
<p>
<address>
Stephen A. Vavasis, Computer Science Department, Cornell University,
Ithaca, NY 14853, vavasis@cs.cornell.edu
</address>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -