Grid

From Open Ideas
Jump to: navigation, search

Definition

A grid is a finite sampling of a larger (sometimes uncountable) set with rectangular topology but not necessarily rectangular geometry. For examples have a look at Wikipedia:structured Grid. You could build all there presented types of grids with QFF.

Description in QFF

In the framework of qff we have several types of grids. The base abstract class is NumberGrid . Every grid defined on JScience Number sets or the standart primitives like int , long , ... is an extension of it. The most general class is GridND , where you are free to choose the dimension d (if you want d=1 or d=2 there exists Grid1D and Grid2D ), all grid-points and the form of the grid-points. LinearGridND is an extension of GridND, where the distance between two grid-points along an axis is constant. In this case, one gets congruent cuboids.

Mainly this framework works with double values, so there are special classes for grids consisting of double values. These are DoubleGrid as the abstract base class, DoubleGridND as general class and finally RegularGridND as the class for constant increments along any axis.

Codebook

Construction

Grids in 1 dimension

IDoubleGrid1D grid10 = new DoubleGrid1D(1.0, 2.0, 4.0, 2.5, 3.5, 8.0);
double[] vertices1 = grid10.toArray();  // contains [1.0, 2.0, 2.5, 3.5, 4.0, 8.0];

Note that the elements of the grid are ordered during creation.

There are two alternatives to create a regular grid, i.e. a grid with equidistant vertices. The first constructor takes a start value, an end value and the total number of vertices (length).

IRegularDoubleGrid1D grid11 = new RegularDoubleGrid1D(10.0, 12.5, 6);
double[] vertices2 = grid11.toArray();  // contains [10.0, 10.5, 11.0, 11.5, 12.0, 12.5]

The second constructor takes a start value, the total number of vertices (length) and the constant increment.

IRegularDoubleGrid1D grid12 = new RegularDoubleGrid1D(-3.0, 5, 1.5);
double[] vertices3 = grid12.toArray();  // contains [-3.0, -1.5, 0.0, 1.5, 3.0]

It is possible to reverse the order.

IRegularDoubleGrid1D grid13 = new RegularDoubleGrid1D(12.5, 10.0, 6);
IRegularDoubleGrid1D grid14 = new RegularDoubleGrid1D(3.0, 5, -1.5);

Grids in 2 dimensions

IRegularDoubleGrid2D grid20 = new RegularDoubleGrid2D(grid11, grid12);

Methods

Here we will present the important methods of the classes DoubleGrid(1D,2D,ND). Beside the natural question methods which returns for example the upper bound (getUpperBound()), ect. there are two very important methods:

  • valueToGrid(double[][]) and
  • gridToValue(double[][]).

The first one transfers values of the real grid into indexes of the intern grid. Intern, the first number (=smallest) of one axis is indicated with 0, the next one with 1, and so on. gridToValue(double[][]) does exactly the opposite, it transfers intern indexes into grid values. Remark: These method uses the according method of the Visualization for Algorithm Development (VisAD)-package. But the method for dimensions higher than 2 doesn't exists there. Therefore these method is useless in case of DoubleGridND. We give an example how it works in 2 dimensions later. With help of these methods, one can approximately calculate values of Function, which are only defined on the knots of the grid.

Another useful method is

  • containsPoint(double...)

which is self-descriptive. Mentionable is also

  • lebesgueRectangular().

It gives an upper bound for the Lebesgue-measure of the smallest cuboid the grid fits in.

Except the two valueToGrid and gridToValue all methods are availabe for the classes Grid(1D,2D,ND), too.

Example

We define a simple grid with 9 knots, if you draw a small picture, it will be easier to understand.

private double[][] feld = {{3.0, 2.0, 1.0, 3.0, 2.0, 1.0, 3.0, 2.0, 1.0},
                           {3.0, 2.0, 1.0, 5.0, 4.0, 3.0, 7.0, 6.0, 5.0}};
DoubleGrid2D grid1 = new DoubleGrid2D(3, 3, feld);

We have to handle two coordinate systems. The "real" one, where our points are defined and the intern one, which is created by the points. In this coordinate system, the first point gets the coordinates (0,0), the second (0,1), and the 4th (because it is a 3x3 grid) gets (1,0). If we now pass double[][] x = {{1.5},{1.5}} to the method valueToGrid we get

double[][] y = valueToGrid(x);
y[0][0] = 1.5  
y[1][0] = 0.0 

This are the coordinates of the "real" point (1.5,1.5) in the grid-coordinates. If we pass the point x to the other method, we get

double z[][] = gridToValue(x);
z[0][0] = 1.5
z[1][0] = 4.5

We see that the point (1.5,1.5) in grid coordinates belongs to the point (1.5,4.5) in "real". Naturally, if we pass y to gridToValue(), we get back x.

linear grid

Here we have a look at a linear (i.e. regular) grid.

DoublePoint2D start = DoublePoint2D.create(1.0,1.0);
DoublePoint2D end = DoublePoint2D.create(11.0,11.0);
RegularDoubleGrid2D grid2 = new RegularDoubleGrid2D(start, end, 6, 11);

Now we will pass the point double[][] x = {2.2,4.7} to the method valueToGrid:

double[][] y = valueToGrid(x);
y[0][0] = 0.6 = (2.2-1.0)/2.0
y[1][0] = 3.7 = (4.7-1.0)/1.0

Here we can present the way its calculated, but in the general case above the visad-package is used.

See also

Set