Grid

Grids

Let a N-dimensional Data object be defined on a given mesh M. Coordinates of points of M are (X1i, X2j, X3k, ...). A Grid object stores, for a given i (the dimension number), Ni points Xij (where j is in {0, 1, ..., Ni-1}). It enables to associate a coordinate to any value stored by the Data object.

Mesh M is a particular case because, for example, coordinates X1i do not depend on other coordinates. If N=2, M could be the set of points (2i, 3j), but not (2i+j, 3j). So, let M' be a more general mesh, which stores points (X1ijk..., X2ijk..., X3ijk.., ...). Then, the grid associated with the first dimension stores points X1ijk...

Two grid structures are therefore available. The first is RegularGrid and stores simple grids (mesh M). The second is GeneralGrid and is able to deal with the "M' case". Both derive from the template class Grid.

Common features

We describe features that are available for both RegularGrid and GeneralGrid.

Dimensions are refered by a number between 0 and 9, the first dimension being associated with 0 and the tenth dimension with 9. One may set to which dimension is associated a grid through method SetVariable, and one may retrieve this information through GetVariable. If the grid G is associated with the second dimension (let's say Y), then G stores ordinates, and GetVariable should return 1 (which is the number associated to the second dimension Y). Most of the time, SetVariable is not useful. Actually, dependencies (if needed - i.e. mostly for GeneralGrid) are provided to the constructor (see GeneralGrid constructor). Finally, one may know whether a grid depends upon a dimension or not through IsDependent. For instance, in a 3D case (with X, Y, Z as dimensions), if vertical coordinates Z (represented by the grid GridZ, for example) depend upon Y and not upon X, then GridZ.IsDependent(0) returns false (no dependency upon X), GridZ.IsDependent(1) returns true (dependency upon Y) and GridZ.IsDependent(2) returns true (of course).

Among useful functions, one may use GetLength or access methods. Value(int, int, ...) is the more general access method. Refer to the documentation for further details.

Since a grid may be shared by several Data structures, a reference counting mechanism is possible. SetDuplicate(false) lets a grid be shared. If two Data objects D1 and D2 are created with a shared grid G, then changing one grid coordinates will change the other grid coordinates. Changing G coordinates will change D1 and D2 grids coordinates as well. For instance:

  RegularGrid<double> G(2);
  G.SetDuplicate(false);

  Data<double, 1> D1(G), D2(G);

  G(0) = 1.0; G(1) = 2.5;
  D1[0].Print();

returns on screen:

Regular grid:
2
 [         1       2.5  ]

D1[0] refers to the first grid of D1. Since duplication is not allowed for G, reference counting is performed so that D1[0] is the same as G. The full example is example2.cpp.:

#define SELDONDATA_DEBUG_CHECK_INDICES
#define SELDONDATA_DEBUG_CHECK_IO
#define SELDONDATA_DEBUG_CHECK_DIMENSIONS
#define SELDONDATA_DEBUG_CHECK_MEMORY

#include "SeldonData.hxx"
using namespace SeldonData;

int main()
{

  TRY;

  RegularGrid<double> G(2);
  G.SetDuplicate(false);

  Data<double, 1> D1(G), D2(G);

  G(0) = 1.0; G(1) = 2.5;
  D1[0].Print();

  G(0) = 4.0; D1[0](1) = 5.0;
  D2[0].Print();

  END;

  return 0;

}

The following makefile may be used (command: make example2):

CC	=	g++
# Put the paths to Blitz++, Talos and SeldonData.
INCPATH	=	-I/home/vivien/codes/MyBlitz++-0.7 \
		-I/home/vivien/codes/Talos-0.3 \
		-I/home/vivien/codes/SeldonData-1.4
LINK	=	g++

TARGETS	=	example1 example2 example3

all: $(TARGETS)

$(TARGETS): % : %.o
	$(LINK) -o $@ $<

%.o : %.cpp
	$(CC) $(INCPATH) -c -o $@ $<

clean:
	rm -f $(TARGETS) $(TARGETS:%=%.o)

RegularGrid

For RegularGrid, the access operator operator(int) is defined. Coordinates values are stored in an one-dimensional array which is reachable through GetArray().

GeneralGrid

GeneralGrid is a template class whose template parameters are the type of stored values and the number of dimensions upon which grid coordinates depend.

Coordinates values are stored in a multi-dimensional array which is reachable through GetArray(). Method GetDependencies returns upon which dimensions current-grid coordinates depend. GetMainVariable identifies to which dimension of the array (returned by GetArray) the current grid is related. Let us consider the previous example with GridZ which depends upon Y but not upon X. Then, GridZ may be defined as: (1) GeneralGrid<double, 2> GridZ(shape(Ny, Nz), 2, shape(1, 2));, or (2) GeneralGrid<double, 2> GridZ(shape(Nz, Ny), 2, shape(2, 1));. The first parameter provides extents in each dimension, the second argument identifies the dimension to which the grid is related (in this case, Z), and the last parameter provides upon which dimensions coordinates are dependent. Notice that dimension numbers match dimension numbers of the Data object which uses GridZ. In case (1), GetDependencies will return (1, 2), GetMainVariable will return 1, and GetVariable will return 2. In case (1), GetDependencies will return (2, 1), GetMainVariable will return 0, and GetVariable will return 2.