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 \vec{v} = v_x \cdot \vec{e}_x + v_y \cdot \vec{e}_y. 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:

\mathrm{n_i} = \mathrm{i}_1 + \mathrm{a}_1 * \mathrm{i}_2.

The coordinates can be calculated by:

\mathrm{c_x} = \mathrm{off}_1 + \mathrm{i}_1 * \mathrm{ti}_1

\mathrm{c_y} = \mathrm{off}_2 + \mathrm{i}_2 * \mathrm{ti}_2

 

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: