2
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
3
<!-- Created on November, 4 2004 by texi2html 1.64 -->
5
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
6
Karl Berry <karl@freefriends.org>
7
Olaf Bachmann <obachman@mathematik.uni-kl.de>
9
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
10
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
14
<TITLE>Blitz++: Stencils</TITLE>
16
<META NAME="description" CONTENT="Blitz++: Stencils">
17
<META NAME="keywords" CONTENT="Blitz++: Stencils">
18
<META NAME="resource-type" CONTENT="document">
19
<META NAME="distribution" CONTENT="global">
20
<META NAME="Generator" CONTENT="texi2html 1.64">
24
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
27
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
28
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_3.html#SEC97"> < </A>]</TD>
29
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC99"> > </A>]</TD>
30
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> << </A>]</TD>
31
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top"> Up </A>]</TD>
32
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
33
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
34
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
35
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
36
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
38
<H1> 4. Stencils </H1>
46
Blitz++ provides an implementation of stencil objects which is currently
47
<STRONG>experimental</STRONG>. This means that the exact details of how they are
48
declared and used may change in future releases. Use at your own risk.
53
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
54
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> < </A>]</TD>
55
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC100"> > </A>]</TD>
56
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> << </A>]</TD>
57
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> Up </A>]</TD>
58
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
59
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
60
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
61
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
62
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
64
<H2> 4.1 Motivation: a nicer notation for stencils </H2>
68
Suppose we wanted to implement the 3-D acoustic wave equation using finite
69
differencing. Here is how a single iteration would look using subarray
73
<TABLE><tr><td> </td><td class=example><pre>Range I(1,N-2), J(1,N-2), K(1,N-2);
75
P3(I,J,K) = (2-6*c(I,J,K)) * P2(I,J,K)
76
+ c(I,J,K)*(P2(I-1,J,K) + P2(I+1,J,K) + P2(I,J-1,K) + P2(I,J+1,K)
77
+ P2(I,J,K-1) + P2(I,J,K+1)) - P1(I,J,K);
78
</pre></td></tr></table></P><P>
80
This syntax is a bit klunky. With stencil objects, the implementation
84
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_STENCIL4(acoustic3D_stencil,P1,P2,P3,c)
85
P3 = 2 * P2 + c * Laplacian3D(P2) - P1;
91
applyStencil(acoustic3D_stencil(), P1, P2, P3, c);
92
</pre></td></tr></table></P><P>
96
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
97
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC99"> < </A>]</TD>
98
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC101"> > </A>]</TD>
99
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC101"> << </A>]</TD>
100
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> Up </A>]</TD>
101
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
102
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
103
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
104
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
105
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
107
<H2> 4.2 Declaring stencil objects </H2>
108
<!--docid::SEC100::-->
111
A stencil declaration may not be inside a function. It can appear inside a
112
class declaration (in which case the stencil object is a nested type).
115
Stencil objects are declared using the macros <CODE>BZ_DECLARE_STENCIL1</CODE>,
116
<CODE>BZ_DECLARE_STENCIL2</CODE>, etc. The number suffix is how many arrays are
117
involved in the stencil (in the above example, 4 arrays-- P1, P2, P3, c -- are
118
used, so the macro <CODE>BZ_DECLARE_STENCIL4</CODE> is invoked).
121
The first argument is a name for the stencil object. Subsequent arguments
122
are names for the arrays on which the stencil operates.
125
After the stencil declaration, the macro <CODE>BZ_END_STENCIL</CODE> must appear
126
(or the macro <CODE>BZ_END_STENCIL_WITH_SHAPE</CODE>, described in the next
130
In between the two macros, you can have multiple assignment statements,
131
if/else/elseif constructs, function calls, loops, etc.
134
Here are some simple examples:
137
<A NAME="IDX309"></A>
140
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_STENCIL2(smooth2D,A,B)
141
A = (B(0,0) + B(0,1) + B(0,-1) + B(1,0) + B(-1,0)) / 5.0;
144
BZ_DECLARE_STENCIL4(acoustic2D,P1,P2,P3,c)
145
A = 2 * P2 + c * (-4 * P2(0,0) + P2(0,1) + P2(0,-1) + P2(1,0) + P2(-1,0))
149
BZ_DECLARE_STENCIL8(prop2D,E1,E2,E3,M1,M2,M3,cE,cM)
150
E3 = 2 * E2 + cE * Laplacian2D(E2) - E1;
151
M3 = 2 * M2 + cM * Laplacian2D(M2) - M1;
154
BZ_DECLARE_STENCIL3(smooth2Db,A,B,c)
155
if ((c > 0.0) && (c < 1.0))
156
A = c * (B(0,0) + B(0,1) + B(0,-1) + B(1,0) + B(-1,0)) / 5.0
161
</pre></td></tr></table></P><P>
163
Currently, a stencil can take up to 11 array parameters.
166
You can use the notation <CODE>A(i,j,k)</CODE> to read the element at an offset
167
<CODE>(i,j,k)</CODE> from the current element. If you omit the parentheses
168
(i.e. as in "<CODE>A</CODE>" then the current element is read.
171
You can invoke <EM>stencil operators</EM> which calculate finite differences
176
<A NAME="SEC101"></A>
177
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
178
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC100"> < </A>]</TD>
179
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> > </A>]</TD>
180
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> << </A>]</TD>
181
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> Up </A>]</TD>
182
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
183
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
184
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
185
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
186
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
188
<H2> 4.3 Automatic determination of stencil extent </H2>
189
<!--docid::SEC101::-->
192
In stencil declarations such as
195
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_STENCIL2(smooth2D,A,B)
196
A = (B(0,0) + B(0,1) + B(0,-1) + B(1,0) + B(-1,0)) / 5.0;
198
</pre></td></tr></table></P><P>
200
Blitz++ will try to automatically determine the spatial extent of the
201
stencil. This will usually work for stencils defined on integer or float
202
arrays. However, the mechanism does not work well for complex-valued
203
arrays, or arrays of user-defined types. If you get a peculiar error when
204
you try to use a stencil, you probably need to tell Blitz++ the special
205
extent of the stencil manually.
208
You do this by ending a stencil declaration with
209
<CODE>BZ_END_STENCIL_WITH_SHAPE</CODE>:
212
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_STENCIL2(smooth2D,A,B)
213
A = (B(0,0) + B(0,1) + B(0,-1) + B(1,0) + B(-1,0)) / 5.0;
214
BZ_END_STENCIL_WITH_SHAPE(shape(-1,-1),shape(+1,+1))
215
</pre></td></tr></table></P><P>
217
The parameters of this macro are: a <CODE>TinyVector</CODE> (constructed by the
218
<CODE>shape()</CODE> function) containing the lower bounds of the stencil offsets,
219
and a <CODE>TinyVector</CODE> containing the upper bounds. You can determine this
220
by looking at the the terms in the stencil and finding the minimum and
221
maximum value of each index:
224
<TABLE><tr><td> </td><td class=example><pre> A = (B(0, 0)
232
</pre></td></tr></table></P><P>
235
<A NAME="SEC102"></A>
236
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
237
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC101"> < </A>]</TD>
238
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC103"> > </A>]</TD>
239
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> << </A>]</TD>
240
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> Up </A>]</TD>
241
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
242
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
243
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
244
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
245
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
247
<H2> 4.4 Stencil operators </H2>
248
<!--docid::SEC102::-->
251
This section lists all the stencil operators provided by Blitz++. They
252
assume that an array represents evenly spaced data points separated by a
253
distance of <CODE>h</CODE>. A 2nd-order accurate operator has error term
254
<EM>O(h^2)</EM>; a 4th-order accurate operator has error term <EM>O(h^4)</EM>.
257
All of the stencils have factors associated with them. For example, the
258
<CODE>central12</CODE> operator is a discrete first derivative which is 2nd-order
259
accurate. Its factor is 2h; this means that to get the first derivative of
260
an array A, you need to use <CODE>central12(A,firstDim)</CODE><EM>/(2h)</EM>.
261
Typically when designing stencils, one factors out all of the <EM>h</EM> terms
265
The factor terms always consist of an integer multiplier (often 1) and a
266
power of <EM>h</EM>. For ease of use, all of the operators listed below are
267
provided in a second "normalized" version in which the integer multiplier
268
is 1. The normalized versions have an <CODE>n</CODE> appended to the name, for
269
example <CODE>central12n</CODE> is the normalized version of <CODE>central12</CODE>, and
270
has factor <EM>h</EM> instead of <EM>2h</EM>.
273
These operators are defined in <CODE>blitz/array/stencilops.h</CODE> if you wish
274
to see the implementation.
278
<A NAME="SEC103"></A>
279
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
280
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> < </A>]</TD>
281
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC104"> > </A>]</TD>
282
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> << </A>]</TD>
283
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
284
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
285
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
286
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
287
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
288
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
290
<H3> 4.4.1 Central differences </H3>
291
<!--docid::SEC103::-->
295
<DT><CODE>central12(A,dimension)</CODE>
296
<DD>1st derivative, 2nd order accurate. Factor: <EM>2h</EM>
297
<table cellpadding=2 rules=all>
298
<tr align=right><td></td><td>-1</td><td>0</td><td>1</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
302
<DT><CODE>central22(A,dimension)</CODE>
303
<DD>2nd derivative, 2nd order accurate. Factor: <EM>h^2</EM>
304
<table cellpadding=2 rules=all>
305
<tr align=right><td></td><td>-1</td><td>0</td><td>1</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000060"><font color="#ffffff">-2</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
309
<DT><CODE>central32(A,dimension)</CODE>
310
<DD>3rd derivative, 2nd order accurate. Factor: <EM>2h^3</EM>
311
<table cellpadding=2 rules=all>
312
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">2</font></td><td></td><td bgcolor="#000000"><font color="#ffffff">-2</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
316
<DT><CODE>central42(A,dimension)</CODE>
317
<DD>4th derivative, 2nd order accurate. Factor: <EM>h^4</EM>
318
<table cellpadding=2 rules=all>
319
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000060"><font color="#ffffff">6</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
323
<DT><CODE>central14(A,dimension)</CODE>
324
<DD>1st derivative, 4th order accurate. Factor: <EM>12h</EM>
325
<table cellpadding=2 rules=all>
326
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-8</font></td><td></td><td bgcolor="#000000"><font color="#ffffff">8</font></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td></tr>
330
<DT><CODE>central24(A,dimension)</CODE>
331
<DD>2nd derivative, 4th order accurate. Factor: <EM>12h^2</EM>
332
<table cellpadding=2 rules=all>
333
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">16</font></td><td bgcolor="#000060"><font color="#ffffff">-30</font></td><td bgcolor="#000000"><font color="#ffffff">16</font></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td></tr>
337
<DT><CODE>central34(A,dimension)</CODE>
338
<DD>3rd derivative, 4th order accurate. Factor: <EM>8h^3</EM>
339
<table cellpadding=2 rules=all>
340
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-8</font></td><td bgcolor="#000000"><font color="#ffffff">13</font></td><td></td><td bgcolor="#000000"><font color="#ffffff">-13</font></td><td bgcolor="#000000"><font color="#ffffff">8</font></td></tr>
344
<DT><CODE>central44(A,dimension)</CODE>
345
<DD>4th derivative, 4th order accurate. Factor: <EM>6h^4</EM>
346
<table cellpadding=2 rules=all>
347
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">12</font></td><td bgcolor="#000000"><font color="#ffffff">-39</font></td><td bgcolor="#000060"><font color="#ffffff">56</font></td><td bgcolor="#000000"><font color="#ffffff">-39</font></td><td bgcolor="#000000"><font color="#ffffff">12</font></td></tr>
352
Note that the above are available in normalized versions <CODE>central12n</CODE>,
353
<CODE>central22n</CODE>, ..., <CODE>central44n</CODE> which have factors of <EM>h</EM>,
354
<EM>h^2</EM>, <EM>h^3</EM>, or <EM>h^4</EM> as appropriate.
357
These are available in multicomponent versions: for example,
358
<CODE>central12(A,component,dimension)</CODE> gives the central12 operator for the
359
specified component (Components are numbered 0, 1, ... N-1).
363
<A NAME="SEC104"></A>
364
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
365
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC103"> < </A>]</TD>
366
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC105"> > </A>]</TD>
367
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC105"> << </A>]</TD>
368
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
369
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
370
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
371
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
372
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
373
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
375
<H3> 4.4.2 Forward differences </H3>
376
<!--docid::SEC104::-->
380
<DT><CODE>forward11(A,dimension)</CODE>
381
<DD>1st derivative, 1st order accurate. Factor: <EM>h</EM>
382
<table cellpadding=2 rules=all>
383
<tr align=right><td></td><td>0</td><td>1</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
387
<DT><CODE>forward21(A,dimension)</CODE>
388
<DD>2nd derivative, 1st order accurate. Factor: <EM>h^2</EM>
389
<table cellpadding=2 rules=all>
390
<tr align=right><td></td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-2</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
394
<DT><CODE>forward31(A,dimension)</CODE>
395
<DD>3rd derivative, 1st order accurate. Factor: <EM>h^3</EM>
396
<table cellpadding=2 rules=all>
397
<tr align=right><td></td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">3</font></td><td bgcolor="#000000"><font color="#ffffff">-3</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
401
<DT><CODE>forward41(A,dimension)</CODE>
402
<DD>4th derivative, 1st order accurate. Factor: <EM>h^4</EM>
403
<table cellpadding=2 rules=all>
404
<tr align=right><td></td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000000"><font color="#ffffff">6</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
408
<DT><CODE>forward12(A,dimension)</CODE>
409
<DD>1st derivative, 2nd order accurate. Factor: <EM>2h</EM>
410
<table cellpadding=2 rules=all>
411
<tr align=right><td></td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">-3</font></td><td bgcolor="#000000"><font color="#ffffff">4</font></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td></tr>
415
<DT><CODE>forward22(A,dimension)</CODE>
416
<DD>2nd derivative, 2nd order accurate. Factor: <EM>h^2</EM>
417
<table cellpadding=2 rules=all>
418
<tr align=right><td></td><td>0</td><td>1</td><td>2</td><td>3</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">2</font></td><td bgcolor="#000000"><font color="#ffffff">-5</font></td><td bgcolor="#000000"><font color="#ffffff">4</font></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td></tr>
422
<DT><CODE>forward32(A,dimension)</CODE>
423
<DD>3rd derivative, 2nd order accurate. Factor: <EM>2h^3</EM>
424
<table cellpadding=2 rules=all>
425
<tr align=right><td></td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">-5</font></td><td bgcolor="#000000"><font color="#ffffff">18</font></td><td bgcolor="#000000"><font color="#ffffff">-24</font></td><td bgcolor="#000000"><font color="#ffffff">14</font></td><td bgcolor="#000000"><font color="#ffffff">-3</font></td></tr>
429
<DT><CODE>forward42(A,dimension)</CODE>
430
<DD>4th derivative, 2nd order accurate. Factor: <EM>h^4</EM>
431
<table cellpadding=2 rules=all>
432
<tr align=right><td></td><td>0</td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td></tr><tr align=right><td></td><td bgcolor="#000060"><font color="#ffffff">3</font></td><td bgcolor="#000000"><font color="#ffffff">-14</font></td><td bgcolor="#000000"><font color="#ffffff">26</font></td><td bgcolor="#000000"><font color="#ffffff">-24</font></td><td bgcolor="#000000"><font color="#ffffff">11</font></td><td bgcolor="#000000"><font color="#ffffff">-2</font></td></tr>
437
Note that the above are available in normalized versions <CODE>forward11n</CODE>,
438
<CODE>forward21n</CODE>, ..., <CODE>forward42n</CODE> which have factors of <EM>h</EM>,
439
<EM>h^2</EM>, <EM>h^3</EM>, or <EM>h^4</EM> as appropriate.
442
These are available in multicomponent versions: for example,
443
<CODE>forward11(A,component,dimension)</CODE> gives the forward11 operator for the
444
specified component (Components are numbered 0, 1, ... N-1).
448
<A NAME="SEC105"></A>
449
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
450
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC104"> < </A>]</TD>
451
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC106"> > </A>]</TD>
452
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC106"> << </A>]</TD>
453
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
454
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
455
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
456
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
457
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
458
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
460
<H3> 4.4.3 Backward differences </H3>
461
<!--docid::SEC105::-->
465
<DT><CODE>backward11(A,dimension)</CODE>
466
<DD>1st derivative, 1st order accurate. Factor: <EM>h</EM>
467
<table cellpadding=2 rules=all>
468
<tr align=right><td></td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td bgcolor="#000060"><font color="#ffffff">1</font></td></tr>
472
<DT><CODE>backward21(A,dimension)</CODE>
473
<DD>2nd derivative, 1st order accurate. Factor: <EM>h^2</EM>
474
<table cellpadding=2 rules=all>
475
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-2</font></td><td bgcolor="#000060"><font color="#ffffff">1</font></td></tr>
479
<DT><CODE>backward31(A,dimension)</CODE>
480
<DD>3rd derivative, 1st order accurate. Factor: <EM>h^3</EM>
481
<table cellpadding=2 rules=all>
482
<tr align=right><td></td><td>-3</td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">3</font></td><td bgcolor="#000000"><font color="#ffffff">-3</font></td><td bgcolor="#000060"><font color="#ffffff">1</font></td></tr>
486
<DT><CODE>backward41(A,dimension)</CODE>
487
<DD>4th derivative, 1st order accurate. Factor: <EM>h^4</EM>
488
<table cellpadding=2 rules=all>
489
<tr align=right><td></td><td>-4</td><td>-3</td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000000"><font color="#ffffff">6</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000060"><font color="#ffffff">1</font></td></tr>
493
<DT><CODE>backward12(A,dimension)</CODE>
494
<DD>1st derivative, 2nd order accurate. Factor: <EM>2h</EM>
495
<table cellpadding=2 rules=all>
496
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000000"><font color="#ffffff">-4</font></td><td bgcolor="#000060"><font color="#ffffff">3</font></td></tr>
500
<DT><CODE>backward22(A,dimension)</CODE>
501
<DD>2nd derivative, 2nd order accurate. Factor: <EM>h^2</EM>
502
<table cellpadding=2 rules=all>
503
<tr align=right><td></td><td>-3</td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">4</font></td><td bgcolor="#000000"><font color="#ffffff">-5</font></td><td bgcolor="#000060"><font color="#ffffff">2</font></td></tr>
507
<DT><CODE>backward32(A,dimension)</CODE>
508
<DD>3rd derivative, 2nd order accurate. Factor: <EM>2h^3</EM>
509
<table cellpadding=2 rules=all>
510
<tr align=right><td></td><td>-4</td><td>-3</td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">3</font></td><td bgcolor="#000000"><font color="#ffffff">-14</font></td><td bgcolor="#000000"><font color="#ffffff">24</font></td><td bgcolor="#000000"><font color="#ffffff">-18</font></td><td bgcolor="#000060"><font color="#ffffff">5</font></td></tr>
514
<DT><CODE>backward42(A,dimension)</CODE>
515
<DD>4th derivative, 2nd order accurate. Factor: <EM>h^4</EM>
516
<table cellpadding=2 rules=all>
517
<tr align=right><td></td><td>-5</td><td>-4</td><td>-3</td><td>-2</td><td>-1</td><td>0</td></tr><tr align=right><td></td><td bgcolor="#000000"><font color="#ffffff">-2</font></td><td bgcolor="#000000"><font color="#ffffff">11</font></td><td bgcolor="#000000"><font color="#ffffff">-24</font></td><td bgcolor="#000000"><font color="#ffffff">26</font></td><td bgcolor="#000000"><font color="#ffffff">-14</font></td><td bgcolor="#000060"><font color="#ffffff">3</font></td></tr>
522
Note that the above are available in normalized versions <CODE>backward11n</CODE>,
523
<CODE>backward21n</CODE>, ..., <CODE>backward42n</CODE> which have factors of <EM>h</EM>,
524
<EM>h^2</EM>, <EM>h^3</EM>, or <EM>h^4</EM> as appropriate.
527
These are available in multicomponent versions: for example,
528
<CODE>backward42(A,component,dimension)</CODE> gives the backward42 operator for
529
the specified component (Components are numbered 0, 1, ... N-1).
533
<A NAME="SEC106"></A>
534
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
535
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC105"> < </A>]</TD>
536
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC107"> > </A>]</TD>
537
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC107"> << </A>]</TD>
538
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
539
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
540
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
541
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
542
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
543
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
545
<H3> 4.4.4 Laplacian (<EM>nabla ^2</EM>) operators </H3>
546
<!--docid::SEC106::-->
550
<DT><CODE>Laplacian2D(A)</CODE>
551
<DD>2nd order accurate, 2-dimensional laplacian. Factor: <EM>h^2</EM>
552
<table cellpadding=2 rules=all>
553
<tr align=right><td></td><td>-1</td><td>0</td><td>1</td></tr><tr align=right><td>-1</td><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td></td></tr>
554
<tr align=right><td>0</td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td bgcolor="#000060"><font color="#ffffff">-4</font></td><td bgcolor="#000000"><font color="#ffffff">1</font></td></tr>
555
<tr align=right><td>1</td><td></td><td bgcolor="#000000"><font color="#ffffff">1</font></td><td></td></tr>
559
<DT><CODE>Laplacian3D(A)</CODE>
560
<DD>2nd order accurate, 3-dimensional laplacian. Factor: <EM>h^2</EM>
563
<DT><CODE>Laplacian2D4(A)</CODE>
564
<DD>4th order accurate, 2-dimensional laplacian. Factor: <EM>12h^2</EM>
565
<table cellpadding=2 rules=all>
566
<tr align=right><td></td><td>-2</td><td>-1</td><td>0</td><td>1</td><td>2</td></tr><tr align=right><td>-2</td><td></td><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td></td><td></td></tr>
567
<tr align=right><td>-1</td><td></td><td></td><td bgcolor="#000000"><font color="#ffffff">16</font></td><td></td><td></td></tr>
568
<tr align=right><td>0</td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td bgcolor="#000000"><font color="#ffffff">16</font></td><td bgcolor="#000060"><font color="#ffffff">-60</font></td><td bgcolor="#000000"><font color="#ffffff">16</font></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td></tr>
569
<tr align=right><td>1</td><td></td><td></td><td bgcolor="#000000"><font color="#ffffff">16</font></td><td></td><td></td></tr>
570
<tr align=right><td>2</td><td></td><td></td><td bgcolor="#000000"><font color="#ffffff">-1</font></td><td></td><td></td></tr>
574
<DT><CODE>Laplacian3D4(A)</CODE>
575
<DD>4th order accurate, 3-dimensional laplacian. Factor: <EM>12h^2</EM>
579
Note that the above are available in normalized versions
580
<CODE>Laplacian2D4n</CODE>, <CODE>Laplacian3D4n</CODE> which have factors <EM>h^2</EM>.
584
<A NAME="SEC107"></A>
585
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
586
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC106"> < </A>]</TD>
587
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC108"> > </A>]</TD>
588
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC108"> << </A>]</TD>
589
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
590
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
591
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
592
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
593
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
594
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
596
<H3> 4.4.5 Gradient (<EM>nabla</EM>) operators </H3>
597
<!--docid::SEC107::-->
600
These return <CODE>TinyVector</CODE>s of the appropriate numeric type and length:
605
<DT><CODE>grad2D(A)</CODE>
606
<DD>2nd order, 2-dimensional gradient (vector of first derivatives), generated
607
using the central12 operator. Factor: <EM>2h</EM>
610
<DT><CODE>grad2D4(A)</CODE>
611
<DD>4th order, 2-dimensional gradient, using central14 operator. Factor: <EM>12h</EM>
614
<DT><CODE>grad3D(A)</CODE>
615
<DD>2nd order, 3-dimensional gradient, using central12 operator. Factor: <EM>2h</EM>
618
<DT><CODE>grad3D4(A)</CODE>
619
<DD>4th order, 3-dimensional gradient, using central14 operator. Factor: <EM>12h</EM>
623
These are available in normalized versions <CODE>grad2Dn</CODE>, <CODE>grad2D4n</CODE>,
624
<CODE>grad3Dn</CODE> and <CODE>grad3D4n</CODE> which have factors <EM>h</EM>.
628
<A NAME="SEC108"></A>
629
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
630
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC107"> < </A>]</TD>
631
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC109"> > </A>]</TD>
632
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC109"> << </A>]</TD>
633
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
634
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
635
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
636
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
637
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
638
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
640
<H3> 4.4.6 Jacobian operators </H3>
641
<!--docid::SEC108::-->
644
The Jacobian operators are defined over 3D vector fields only (e.g.
645
<CODE>Array<TinyVector<double,3>,3></CODE>). They return a
646
<CODE>TinyMatrix<T,3,3></CODE> where T is the numeric type of the vector field.
650
<DT><CODE>Jacobian3D(A)</CODE>
651
<DD>2nd order, 3-dimensional Jacobian using the central12 operator. Factor:
655
<DT><CODE>Jacobian3D4(A)</CODE>
656
<DD>4th order, 3-dimensional Jacobian using the central14 operator. Factor:
661
These are also available in normalized versions <CODE>Jacobian3Dn</CODE> and
662
<CODE>Jacobain3D4n</CODE> which have factors <EM>h</EM>.
666
<A NAME="SEC109"></A>
667
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
668
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC108"> < </A>]</TD>
669
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC110"> > </A>]</TD>
670
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC110"> << </A>]</TD>
671
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
672
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
673
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
674
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
675
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
676
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
678
<H3> 4.4.7 Grad-squared operators </H3>
679
<!--docid::SEC109::-->
682
There are also grad-squared operators, which return <CODE>TinyVector</CODE>s of
687
<DT><CODE>gradSqr2D(A)</CODE>
688
<DD>2nd order, 2-dimensional grad-squared (vector of second derivatives),
689
generated using the central22 operator. Factor: <EM>h^2</EM>
692
<DT><CODE>gradSqr2D4(A)</CODE>
693
<DD>4th order, 2-dimensional grad-squared, using central24 operator. Factor:
697
<DT><CODE>gradSqr3D(A)</CODE>
698
<DD>2nd order, 3-dimensional grad-squared, using the central22 operator.
702
<DT><CODE>gradSqr3D4(A)</CODE>
703
<DD>4th order, 3-dimensional grad-squared, using central24 operator. Factor:
708
Note that the above are available in normalized versions <CODE>gradSqr2Dn</CODE>,
709
<CODE>gradSqr2D4n</CODE>, <CODE>gradSqr3Dn</CODE>, <CODE>gradSqr3D4n</CODE> which have factors
714
<A NAME="SEC110"></A>
715
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
716
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC109"> < </A>]</TD>
717
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC111"> > </A>]</TD>
718
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC111"> << </A>]</TD>
719
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
720
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
721
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
722
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
723
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
724
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
726
<H3> 4.4.8 Curl (<EM>nabla times</EM>) operators </H3>
727
<!--docid::SEC110::-->
730
These curl operators return scalar values:
734
<DT><CODE>curl(Vx,Vy)</CODE>
735
<DD>2nd order curl operator using the central12 operator. Factor: <EM>2h</EM>
738
<DT><CODE>curl4(Vx,Vy)</CODE>
739
<DD>4th order curl operator using the central14 operator. Factor: <EM>12h</EM>
742
<DT><CODE>curl2D(V)</CODE>
743
<DD>2nd order curl operator on a 2D vector field (e.g.
744
<CODE>Array<TinyVector<float,2>,2></CODE>), using the central12 operator. Factor:
748
<DT><CODE>curl2D4(V)</CODE>
749
<DD>4th order curl operator on a 2D vector field, using the central12 operator.
754
Available in normalized forms <CODE>curln</CODE>, <CODE>curl4n</CODE>, <CODE>curl2Dn</CODE>,
755
<CODE>curl2D4n</CODE>.
758
These curl operators return three-dimensional <CODE>TinyVector</CODE>s of the
759
appropriate numeric type:
763
<DT><CODE>curl(Vx,Vy,Vz)</CODE>
764
<DD>2nd order curl operator using the central12 operator. Factor: <EM>2h</EM>
767
<DT><CODE>curl4(Vx,Vy,Vz)</CODE>
768
<DD>4th order curl operator using the central14 operator. Factor: <EM>12h</EM>
771
<DT><CODE>curl(V)</CODE>
772
<DD>2nd order curl operator on a 3D vector field (e.g.
773
<CODE>Array<TinyVector<double,3>,3></CODE>, using the central12 operator. Factor:
777
<DT><CODE>curl4(V)</CODE>
778
<DD>4th order curl operator on a 3D vector field, using the central14 operator.
783
Note that the above are available in normalized versions <CODE>curln</CODE> and
784
<CODE>curl4n</CODE>, which have factors of <CODE>h</CODE>.
788
<A NAME="SEC111"></A>
789
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
790
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC110"> < </A>]</TD>
791
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC112"> > </A>]</TD>
792
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> << </A>]</TD>
793
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
794
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
795
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
796
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
797
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
798
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
800
<H3> 4.4.9 Divergence (<EM>nabla cdot</EM>) operators </H3>
801
<!--docid::SEC111::-->
804
The divergence operators return a scalar value.
808
<DT><CODE>div(Vx,Vy)</CODE>
809
<DD>2nd order div operator using the central12 operator. Factor: <EM>2h</EM>
812
<DT><CODE>div4(Vx,Vy)</CODE>
813
<DD>4th order div operator using the central14 operator. Factor: <EM>12h</EM>
816
<DT><CODE>div(Vx,Vy,Vz)</CODE>
817
<DD>2nd order div operator using the central12 operator. Factor: <EM>2h</EM>
820
<DT><CODE>div4(Vx,Vy,Vz)</CODE>
821
<DD>4th order div operator using the central14 operator. Factor: <EM>12h</EM>
824
<DT><CODE>div2D(V)</CODE>
825
<DD>2nd order div operator on a 2D vector field, using the central12 operator.
829
<DT><CODE>div2D4(V)</CODE>
830
<DD>2nd order div operator on a 2D vector field, using the central14 operator.
834
<DT><CODE>div3D(V)</CODE>
835
<DD>2nd order div operator on a 3D vector field, using the central12 operator.
839
<DT><CODE>div3D4(V)</CODE>
840
<DD>2nd order div operator on a 3D vector field using the central14 operator.
845
These are available in normalized versions
846
<CODE>divn</CODE>, <CODE>div4n</CODE>, <CODE>div2Dn</CODE>, <CODE>div2D4n</CODE>, <CODE>div3Dn</CODE>, and
847
<CODE>div3D4n</CODE> which have factors of <EM>h</EM>.
851
<A NAME="SEC112"></A>
852
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
853
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC111"> < </A>]</TD>
854
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> > </A>]</TD>
855
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC104"> << </A>]</TD>
856
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC102"> Up </A>]</TD>
857
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> >> </A>]</TD>
858
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
859
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
860
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
861
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
863
<H3> 4.4.10 Mixed partial derivatives </H3>
864
<!--docid::SEC112::-->
868
<DT><CODE>mixed22(A,dim1,dim2)</CODE>
869
<DD>2nd order accurate, 2nd mixed partial derivative. Factor: <EM>4h^2</EM>
872
<DT><CODE>mixed24(A,dim1,dim2)</CODE>
873
<DD>4th order accurate, 2nd mixed partial derivative. Factor: <EM>144h^2</EM>
877
There are also normalized versions of the above, <CODE>mixed22n</CODE> and
878
<CODE>mixed24n</CODE> which have factors <EM>h^2</EM>.
882
<A NAME="SEC113"></A>
883
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
884
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC112"> < </A>]</TD>
885
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC114"> > </A>]</TD>
886
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC114"> << </A>]</TD>
887
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> Up </A>]</TD>
888
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
889
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
890
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
891
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
892
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
894
<H2> 4.5 Declaring your own stencil operators </H2>
895
<!--docid::SEC113::-->
898
You can declare your own stencil operators using the macro
899
<CODE>BZ_DECLARE_STENCIL_OPERATOR1</CODE>. For example, here is the declaration
900
of <CODE>Laplacian2D</CODE>:
903
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_STENCIL_OPERATOR1(Laplacian2D, A)
904
return -4*A(0,0) + A(-1,0) + A(1,0) + A(0,-1) + A(0,1);
905
BZ_END_STENCIL_OPERATOR
906
</pre></td></tr></table></P><P>
908
To declare a stencil operator on 3 operands, use the macro
909
<CODE>BZ_DECLARE_STENCIL_OPERATOR3</CODE>. Here is the declaration of <CODE>div</CODE>:
912
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_STENCIL_OPERATOR3(div,vx,vy,vz)
913
return central12(vx,firstDim) + central12(vy,secondDim)
914
+ central12(vz,thirdDim);
915
BZ_END_STENCIL_OPERATOR
916
</pre></td></tr></table></P><P>
918
The macros aren't magical; they just declare an inline template function
919
with the names and arguments you specify. For example, the declaration of
920
<CODE>div</CODE> could also be written
923
<TABLE><tr><td> </td><td class=example><pre>template<class T>
924
inline typename T::T_numtype div(T& vx, T& vy, T& vz)
926
return central12(vx,firstDim) + central12(vy,secondDim)
927
+ central12(vz,thirdDim);
929
</pre></td></tr></table></P><P>
931
The template parameter <CODE>T</CODE> is an iterator type for arrays.
934
You are encouraged to use the macros when possible, because it is possible
935
the implementation could be changed in the future.
938
To declare a difference operator, use this syntax:
941
<TABLE><tr><td> </td><td class=example><pre>BZ_DECLARE_DIFF(central12,A) {
942
return A.shift(1,dim) - A.shift(-1,dim);
944
</pre></td></tr></table></P><P>
946
The method <CODE>shift(offset,dim)</CODE> retrieves the element at
947
<CODE>offset</CODE> in dimension <CODE>dim</CODE>.
950
Stencil operator declarations cannot occur inside a function. If
951
declared inside a class, they are scoped by the class.
955
<A NAME="SEC114"></A>
956
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
957
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC113"> < </A>]</TD>
958
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> > </A>]</TD>
959
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> << </A>]</TD>
960
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> Up </A>]</TD>
961
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
962
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
963
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
964
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
965
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
967
<H2> 4.6 Applying a stencil </H2>
968
<!--docid::SEC114::-->
971
The syntax for applying a stencil is:
974
<TABLE><tr><td> </td><td class=example><pre>applyStencil(stencilname(),A,B,C...,F);
975
</pre></td></tr></table></P><P>
977
Where <CODE>stencilname</CODE> is the name of the stencil, and <CODE>A,B,C,...,F</CODE>
978
are the arrays on which the stencil operates.
981
For examples, see <TT>`examples/stencil.cpp'</TT> and <TT>`examples/stencil2.cpp'</TT>.
984
Blitz++ interrogates the stencil object to find out how large its footprint
985
is. It only applies the stencil over the region of the arrays where it
986
won't overrun the boundaries.
989
<A NAME="Customised Arrays"></A>
991
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
992
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_4.html#SEC98"> << </A>]</TD>
993
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_5.html#SEC115"> >> </A>]</TD>
994
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz.html#SEC_Top">Top</A>]</TD>
995
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_toc.html#SEC_Contents">Contents</A>]</TD>
996
<TD VALIGN="MIDDLE" ALIGN="LEFT">[Index]</TD>
997
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="blitz_abt.html#SEC_About"> ? </A>]</TD>
1001
This document was generated
1002
by <I>Julian Cummings</I> on <I>November, 4 2004</I>
1003
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
1004
"><I>texi2html</I></A>