Regular Grids
![]() |
We introduce a new type of data structure, grids, in this tutorial just as we did in our tutorials dealing with complex data structures. Grids are an essential data structure in the field of scientific computing. Most of the algorithms used are evaluated on some kind of grid. The dimension of the grid can be derived from the number of coordinates necessary to identify a single point, e.g., a two-dimensional grid uses two coordinates
. A point can be depicted as the intersection of two coordinate lines. A regular grid can then be specified easily by the number of points in each of the available dimensions, e.g., 10x10 points.
Simulations often use these grid data structures to store and evaluate physical quantities. Different kinds of algorithms can also conveniently operate on the coordinates of the grid. In some cases it is advantageous to identify points by unique numbers, these can be derived from point indices by:
.
The coordinates can be calculated by:
struct grid_2d { long axis1; long axis2; double ticks1; double ticks2; double offset1; double offset2; }; struct coordinate { double cx; double cy; };
Write functions for the following tasks:
- L1: Create a file with all information necessary to specify a grid in two dimensions. Write functions to read and write these files.
- L1: Write a function to edit the grid properties.
- L1: Write a function which calculates the number of a grid node. This number has to be unique and should be adressed by the corresponding indices.
- L1: Write a function which returns the coordinates of a point. The function should take the indices as arguments.
- L2: Write a data structure which stores a quantity on the points. Use the unique index of a point to store the value.
- L2: Write a function, which compares two different grids. The return value should be true if the grids are based on the same properties.
- L2: Write a function which transfers the quantity of a grid onto another grid. The grids must have the same properties.
- L3: Write a function which transfers the quantity of a grid onto another grid. The grids need not have the same properties.
