From 406016998bac2190c9cf5a738aaacad17f020c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A5rd=20Skaflestad?= Date: Wed, 20 Jun 2012 13:02:57 +0000 Subject: [PATCH] Continue reorganisation to promote readability. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- preprocess.c | 53 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/preprocess.c b/preprocess.c index 426599d5..e626b37e 100644 --- a/preprocess.c +++ b/preprocess.c @@ -63,6 +63,13 @@ process_horizontal_faces(int **intersections, int *plist, 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 with k index running faster than i running faster than j, and Cartesian dimensions , find pointers to the @@ -95,19 +102,22 @@ static void igetvectors(int dims[3], int i, int j, int *field, int *v[]) */ 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; - if (i<0 || i>=dims[0] || j<0 || j >= dims[1]){ - for(k=0; k= dims[0])) || /* 'i' outside [0, dims[0]) */ + ((j < 0) || (j >= dims[1]))) { /* 'j' outside [0, dims[1]) */ + + for (k = 0; k < len; k += 2) { + neighbors[k] = -1; /* Neighbour is outside domain */ } - }else{ - for(k=0; k */ /* 0 2 2 3 */ @@ -223,15 +233,23 @@ process_vertical_faces(int direction, num_intersections = out->number_of_nodes - out->number_of_nodes_on_pillars; - findconnections(2*nz+2, cornerpts, - *intersections+4*num_intersections, + /* Establish new connections (faces) along pillar pair. */ + findconnections(2*nz + 2, cornerpts, + *intersections + 4*num_intersections, work, out); + /* Start of ->face_neighbors[] for this set of connections. */ 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; - compute_cell_index(out->dimensions, i-1+direction, j-direction, ptr, len); - compute_cell_index(out->dimensions, i, j, ptr+1, len); + /* 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 , j , ptr + 1, len); /* Tag the new faces */ f = startface; @@ -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),