tmost file IO works, needs O from c - ns2dfd - 2D finite difference Navier Stokes solver for fluid dynamics
 (HTM) git clone git://src.adamsgaard.dk/ns2dfd
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) LICENSE
       ---
 (DIR) commit ec7d202b3fe33c4e0f9838b110c2f75f448837b7
 (DIR) parent 428ee066696d71e182801d30915c3ee16ea06e9b
 (HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
       Date:   Sun,  2 Mar 2014 19:37:05 +0100
       
       most file IO works, needs O from c
       
       Diffstat:
         M ns2dfd.py                           |      18 +++++++++---------
         M src/file_io.c                       |      26 ++++++++++++++++----------
         M src/file_io.h                       |       2 +-
         M src/main.c                          |       6 ++++--
         M src/utility.c                       |      12 ++++++------
         M src/utility.h                       |       5 +----
       
       6 files changed, 37 insertions(+), 32 deletions(-)
       ---
 (DIR) diff --git a/ns2dfd.py b/ns2dfd.py
       t@@ -41,9 +41,9 @@ class fluid:
                self.ny = numpy.asarray(ny)
                self.dx = numpy.asarray(dx)
                self.dy = numpy.asarray(dy)
       -        self.p = numpy.zeros((nx+1, ny+1))
       -        self.u = numpy.zeros((nx+2, ny+2))
       -        self.v = numpy.zeros((nx+2, ny+2))
       +        self.P = numpy.zeros((nx+1, ny+1))
       +        self.U = numpy.zeros((nx+2, ny+2))
       +        self.V = numpy.zeros((nx+2, ny+2))
        
            def current_time(self, t = 0.0):
                '''
       t@@ -176,17 +176,17 @@ class fluid:
                    init_grid(dx = self.dx, dy = self.dy, nx = self.nx, ny = self.ny)
                    for j in range(self.ny+1):
                        for i in range(self.nx+1):
       -                    self.p[i,j] = \
       +                    self.P[i,j] = \
                                    numpy.fromfile(fh, dtype=numpy.float64, count=1)
        
                    for j in range(self.ny+2):
                        for i in range(self.nx+2):
       -                    self.u[i,j] = \
       +                    self.U[i,j] = \
                                    numpy.fromfile(fh, dtype=numpy.float64, count=1)
        
                    for j in range(self.ny+2):
                        for i in range(self.nx+2):
       -                    self.v[i,j] = \
       +                    self.V[i,j] = \
                                    numpy.fromfile(fh, dtype=numpy.float64, count=1)
        
                finally:
       t@@ -230,15 +230,15 @@ class fluid:
        
                    for j in range(self.ny+1):
                        for i in range(self.nx+1):
       -                    fh.write(self.p[i,j].astype(numpy.float64))
       +                    fh.write(self.P[i,j].astype(numpy.float64))
        
                    for j in range(self.ny+2):
                        for i in range(self.nx+2):
       -                    fh.write(self.u[i,j].astype(numpy.float64))
       +                    fh.write(self.U[i,j].astype(numpy.float64))
        
                    for j in range(self.ny+2):
                        for i in range(self.nx+2):
       -                    fh.write(self.v[i,j].astype(numpy.float64))
       +                    fh.write(self.V[i,j].astype(numpy.float64))
        
                finally:
                    if fh is not None:
 (DIR) diff --git a/src/file_io.c b/src/file_io.c
       t@@ -9,7 +9,7 @@ int read_file(char *path,
                int *w_left, int *w_right, int *w_top, int *w_bottom,
                double *dx, double *dy,
                int *nx, int *ny,
       -        double **P, double **U, double **V)
       +        double ***P, double ***U, double ***V)
        {
            int i, j;
            double tmp;
       t@@ -43,20 +43,26 @@ int read_file(char *path,
        
                allocate_memory(P, U, V, *nx, *ny);
                
       -        for (j=0; j<*ny+1; j++)
       +        for (j=0; j<*ny+1; j++) {
                    for (i=0; i<*nx+1; i++) {
                        fread(&tmp, sizeof(double), 1, fp);
       -                P[i][j] = tmp;
       +                (*P)[i][j] = tmp;
                    }
       -                /*fread(P[i][j], sizeof(double), 1, fp);*/
       +        }
        
       -        for (j=0; j<*ny+2; j++)
       -            for (i=0; i<*nx+2; i++)
       -                fread(&U[i][j], sizeof(double), 1, fp);
       +        for (j=0; j<*ny+2; j++) {
       +            for (i=0; i<*nx+2; i++) {
       +                fread(&tmp, sizeof(double), 1, fp);
       +                (*U)[i][j] = tmp;
       +            }
       +        }
        
       -        for (j=0; j<*ny+2; j++)
       -            for (i=0; i<*nx+2; i++)
       -                fread(&V[i][j], sizeof(double), 1, fp);
       +        for (j=0; j<*ny+2; j++) {
       +            for (i=0; i<*nx+2; i++) {
       +                fread(&tmp, sizeof(double), 1, fp);
       +                (*V)[i][j] = tmp;
       +            }
       +        }
        
                fclose(fp);
            }
 (DIR) diff --git a/src/file_io.h b/src/file_io.h
       t@@ -8,6 +8,6 @@ int read_file(char *path,
                int *w_left, int *w_right, int *w_top, int *w_bottom,
                double *dx, double *dy,
                int *nx, int *ny,
       -        double **p, double **u, double **v);
       +        double ***P, double ***U, double ***V);
        
        #endif
 (DIR) diff --git a/src/main.c b/src/main.c
       t@@ -12,11 +12,13 @@ int main(int argc, char** argv)
            int w_left, w_right, w_top, w_bottom;
            double dx, dy;
            int nx, ny;
       -    double **P, **U, **V;
       +    double **P = NULL;
       +    double **U = NULL;
       +    double **V = NULL;
        
            read_file("unnamed.dat", &t, &t_end, &tau, &itermax, &epsilon, &omega, &gamma, 
                    &gx, &gy, &re, &w_left, &w_right, &w_top, &w_bottom,
       -            &dx, &dy, &nx, &ny, P, U, V);
       +            &dx, &dy, &nx, &ny, &P, &U, &V);
        
            printf("omega = %f\n", omega);
            printf("P[0][0] = %f\n", P[0][0]);
 (DIR) diff --git a/src/utility.c b/src/utility.c
       t@@ -4,12 +4,12 @@
        int allocate_matrix(double ***M, int nx, int ny)
        {
            int i;
       -    *M = (double**)malloc(sizeof(double*)*nx);
       +    (*M) = (double**) malloc(sizeof(double*)*nx);
            if (*M == NULL)
                return 1;
        
            for (i=0; i<nx; i++) {
       -        (*M)[i] = (double*)malloc(sizeof(double)*ny);
       +        (*M)[i] = (double*) malloc(sizeof(double)*ny);
                if ((*M)[i] == NULL)
                    return 1;
            }
       t@@ -24,17 +24,17 @@ void free_matrix(double ***M, int nx)
            free(*M);
        }
        
       -int allocate_memory(double **P, double **U, double **V, int nx, int ny)
       +int allocate_memory(double ***P, double ***U, double ***V, int nx, int ny)
        {
       -    if (allocate_matrix(&P, nx+1, ny+1) != 0) {
       +    if (allocate_matrix(P, nx+1, ny+1) != 0) {
                fprintf(stderr, "allocate_memory: Could not allocate memory for P\n");
                return 1;
            }
       -    if (allocate_matrix(&U, nx+2, ny+2) != 0) {
       +    if (allocate_matrix(U, nx+2, ny+2) != 0) {
                fprintf(stderr, "allocate_memory: Could not allocate memory for U\n");
                return 1;
            }
       -    if (allocate_matrix(&V, nx+2, ny+2) != 0) {
       +    if (allocate_matrix(V, nx+2, ny+2) != 0) {
                fprintf(stderr, "allocate_memory: Could not allocate memory for V\n");
                return 1;
            }
 (DIR) diff --git a/src/utility.h b/src/utility.h
       t@@ -1,10 +1,7 @@
        #ifndef UTILITY_H_
        #define UTILITY_H_
        
       -int allocate_matrix(double ***M, int nx, int ny);
       -void free_matrix(double ***M, int nx);
       -
       -int allocate_memory(double **P, double **U, double **V, int nx, int ny);
       +int allocate_memory(double ***P, double ***U, double ***V, int nx, int ny);
        void free_memory(double **P, double **U, double **V, int nx);
        
        #endif