next up previous contents index
Next: Input and Output Up: Statements Previous: Masks vs. Shattered Control

Wrap and Reflect

         

   figure828
Figure 2: The Reflect and Wrap Operators.

ZPL's wrap and reflect statements are used to initialize periodic and mirrored boundary conditions, respectively. These statements can be used in conjunction with regions that are derived using the of or in operators. The example below initializes the parallel array A in the region [east of R] by reflecting the values in [R] across the boundary between [east of R] and [R].

    direction  east = [0, 1];
    region     R    = [1..n, 1..n];
    var        A    : [R] float;

    [east of R] reflect A;
    [east of R] wrap A, B;
When used with In Regions, the reflect statements reflects data across the boundary that is shared by the base and derived regions, which in the following example would again be the boundary between [east of R] and [R].

    [east in R] reflect A;    -- copy values from [east of R] to [east in R]

The wrap statement is similar to reflect except it copies data from the western columns of R as if the region were connected as a torus. (See Figure 2.)

The wrap and reflect statements can only operate on parallel variables. Furthermore, the boundary between the source and destination regions must be well defined, so these statements must have an Of Region applied to them. Note that a named region that is defined using Of is itself considered an Of Region. If an Of Region is a defined in terms of some other Of Region, as shown below, the boundary used by wrap and reflect is defined by the outermost Of, in this case the boundary between [E] and [EE]. (See Figure 3.)

   figure862
Figure 3: Reflect for Nested Of Regions.

    region    E  = [east of R];
              EE = [east of E];
    
    [EE]      reflect A;

Since wrap and reflect are forms of assignment statements, they implicitly define storage for their operands when used in Of Regions, as explained in Section 4.2.4.

   figure876
Figure 4: Illustration of Reflect Applied to Operands with @'s.

Note that wrap and reflect may be applied to operands involving @'s, so the following is legal:

    [east of R]  reflect X@west;
In this case [east of R] X@west is the target of the reflect, and the source is the data reflect across the boundary between [east of R] and [R] shifted west. This is illustrated in Figure 4.


next up previous contents index
Next: Input and Output Up: Statements Previous: Masks vs. Shattered Control

Kay Nettle
Fri Feb 21 21:14:29 CST 1997