int *
make_mesh_connectivity(int edge_ct_x, /*number of edges in X direction*/
int edge_ct_y /*number of edges in Y direction*/
)
{
SAF_ENTER(make_mesh_connectivity, NULL);
int *node_ids; /* The node to element connectivity. */
int node_ct_y = edge_ct_y + 1; /* Number of nodes in y. */
int tri_ct = 0, /* Number of triangles in mesh. */
conn_idx = 0; /* Index into connectivity array. */
int i, j;
/* Preconditions */
SAF_REQUIRE(edge_ct_x > 0, SAF_LOW_CHK_COST, NULL,
_saf_errmsg("there must be at least 1 edge in the x direction"));
SAF_REQUIRE(edge_ct_y > 0, SAF_LOW_CHK_COST, NULL,
_saf_errmsg("there must be at least 1 edge in the y direction"));
/* Body */
/* allocate node_ids as single index array,
* but treat as node_ids[edge_ct_x][edge_ct_y][3]; */
node_ids = (int*)malloc(edge_ct_x*edge_ct_y*2*3*sizeof(int));
for(i = 0; i < edge_ct_x; i++)
{
for(j = 0; j < edge_ct_y; j++)
{
/* Each (i,j) pair is the lower-left-hand node in
* a quad containing two triangles. */
/* Connectivity for lower triangle in quad,
* follow right-hand rule (ccw) starting
* in llh corner of quad. */
node_ids[conn_idx++] = NODE_ID(i,j);
node_ids[conn_idx++] = NODE_ID(i+1, j);
node_ids[conn_idx++] = NODE_ID(i, j+1);
tri_ct++;
/* Connectivity for upper triangle in quad,
* follow right-hand rule (ccw) starting
* in urh corner of quad. */
node_ids[conn_idx++] = NODE_ID(i+1,j);
node_ids[conn_idx++] = NODE_ID(i+1, j+1);
node_ids[conn_idx++] = NODE_ID(i, j+1);
tri_ct++;
}
}
/* Postconditions */
/* Exit */
SAF_LEAVE(node_ids);
}