Continue reorganisation to promote readability.

Specifically:
    * Move linearindex() ahead of all existing functions and use it in
      compute_cell_index().
    * compute_cell_index(): Insert white-space and comments.
    * process_vertical_faces(): Add comments to describe stages in the
      process of computing new connections (faces).

Signed-off-by: Bård Skaflestad <Bard.Skaflestad@sintef.no>
This commit is contained in:
Bård Skaflestad
2012-06-20 13:02:57 +00:00
committed by Bård Skaflestad
parent 0d84dad30c
commit 406016998b

View File

@@ -63,6 +63,13 @@ process_horizontal_faces(int **intersections,
int *plist, int *plist,
struct processed_grid *out); struct processed_grid *out);
static int
linearindex(const int dims[3], int i, int j, int k)
{
return i + dims[0]*(j + dims[1]*k);
}
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
Given a vector <field> with k index running faster than i running Given a vector <field> with k index running faster than i running
faster than j, and Cartesian dimensions <dims>, find pointers to the faster than j, and Cartesian dimensions <dims>, find pointers to the
@@ -95,19 +102,22 @@ static void igetvectors(int dims[3], int i, int j, int *field, int *v[])
*/ */
static void static void
compute_cell_index(const int dims[3], int i, int j, int *neighbors, int len) compute_cell_index(const int dims[3], int i, int j,
int *neighbors, int len)
{ {
int k; int k;
if (i<0 || i>=dims[0] || j<0 || j >= dims[1]){
if (((i < 0) || (i >= dims[0])) || /* 'i' outside [0, dims[0]) */
((j < 0) || (j >= dims[1]))) { /* 'j' outside [0, dims[1]) */
for (k = 0; k < len; k += 2) { for (k = 0; k < len; k += 2) {
neighbors[k] = -1; neighbors[k] = -1; /* Neighbour is outside domain */
} }
}else{ }
else {
for (k = 0; k < len; k += 2) { for (k = 0; k < len; k += 2) {
if (neighbors[k] != -1) { if (neighbors[k] != -1) {
int tmp = i + dims[0]*(j + dims[1]*neighbors[k]); neighbors[k] = linearindex(dims, i, j, neighbors[k]);
neighbors[k] = tmp;
} }
} }
} }
@@ -223,13 +233,21 @@ process_vertical_faces(int direction,
num_intersections = out->number_of_nodes - num_intersections = out->number_of_nodes -
out->number_of_nodes_on_pillars; out->number_of_nodes_on_pillars;
/* Establish new connections (faces) along pillar pair. */
findconnections(2*nz + 2, cornerpts, findconnections(2*nz + 2, cornerpts,
*intersections + 4*num_intersections, *intersections + 4*num_intersections,
work, out); work, out);
/* Start of ->face_neighbors[] for this set of connections. */
ptr = out->face_neighbors + 2*startface; ptr = out->face_neighbors + 2*startface;
/* Total number of cells (both sides) connected by this
* set of connections (faces). */
len = 2*out->number_of_faces - 2*startface; len = 2*out->number_of_faces - 2*startface;
/* Derive inter-cell connectivity (i.e. ->face_neighbors)
* of global (uncompressed) cells for this set of
* connections (faces). */
compute_cell_index(out->dimensions, i-1+direction, j-direction, ptr , len); compute_cell_index(out->dimensions, i-1+direction, j-direction, ptr , len);
compute_cell_index(out->dimensions, i , j , ptr + 1, len); compute_cell_index(out->dimensions, i , j , ptr + 1, len);
@@ -242,11 +260,6 @@ process_vertical_faces(int direction,
} }
} }
static int linearindex(const int dims[3], int i, int j, int k)
{
return i + dims[0]*(j + dims[1]*k);
}
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
For each horizontal face (i.e. k constant), For each horizontal face (i.e. k constant),