Introduction
Introduction Statistics Contact Development Disclaimer Help
tadded C output, fixed Python input - ns2dfd - 2D finite difference Navier Stok…
git clone git://src.adamsgaard.dk/ns2dfd
Log
Files
Refs
LICENSE
---
commit 1c27cca37f5dad626780cc0a7475f76285534073
parent ec7d202b3fe33c4e0f9838b110c2f75f448837b7
Author: Anders Damsgaard <[email protected]>
Date: Sun, 2 Mar 2014 19:47:08 +0100
added C output, fixed Python input
Diffstat:
M ns2dfd.py | 2 +-
M src/file_io.c | 68 +++++++++++++++++++++++++++++…
M src/file_io.h | 8 ++++++++
M src/main.c | 12 ++++++++----
4 files changed, 85 insertions(+), 5 deletions(-)
---
diff --git a/ns2dfd.py b/ns2dfd.py
t@@ -145,7 +145,7 @@ class fluid:
'''
fh = None
try:
- targetfile = folder + '/' + self.sim_id
+ targetfile = path
if verbose == True:
print('Input file: ' + targetfile)
fh = open(targetfile, 'rb')
diff --git a/src/file_io.c b/src/file_io.c
t@@ -18,6 +18,7 @@ int read_file(char *path,
fprintf(stderr, "read_file: Could not open file %s\n", path);
return 1;
} else {
+
fread(t, sizeof(double), 1, fp);
fread(t_end, sizeof(double), 1, fp);
fread(tau, sizeof(double), 1, fp);
t@@ -68,3 +69,70 @@ int read_file(char *path,
}
return 0;
}
+
+/* Write the variable values to a file on disk */
+int write_file(char *path,
+ double *t, double *t_end, double *tau, int *itermax,
+ double *epsilon, double *omega, double *gamma,
+ double *gx, double *gy, double *re,
+ 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)
+{
+ int i, j;
+ double tmp;
+ FILE *fp;
+ if ((fp = fopen(path, "wb")) == NULL) {
+ fprintf(stderr, "write_file: Could not open file %s\n", path);
+ return 1;
+ } else {
+
+ fwrite(t, sizeof(double), 1, fp);
+ fwrite(t_end, sizeof(double), 1, fp);
+ fwrite(tau, sizeof(double), 1, fp);
+
+ fwrite(itermax, sizeof(int), 1, fp);
+ fwrite(epsilon, sizeof(double), 1, fp);
+ fwrite(omega, sizeof(double), 1, fp);
+ fwrite(gamma, sizeof(double), 1, fp);
+
+ fwrite(gx, sizeof(double), 1, fp);
+ fwrite(gy, sizeof(double), 1, fp);
+ fwrite(re, sizeof(double), 1, fp);
+
+ fwrite(w_left, sizeof(int), 1, fp);
+ fwrite(w_right, sizeof(int), 1, fp);
+ fwrite(w_top, sizeof(int), 1, fp);
+ fwrite(w_bottom, sizeof(int), 1, fp);
+
+ fwrite(dx, sizeof(double), 1, fp);
+ fwrite(dy, sizeof(double), 1, fp);
+ fwrite(nx, sizeof(int), 1, fp);
+ fwrite(ny, sizeof(int), 1, fp);
+
+ for (j=0; j<*ny+1; j++) {
+ for (i=0; i<*nx+1; i++) {
+ tmp = (*P)[i][j];
+ fwrite(&tmp, sizeof(double), 1, fp);
+ }
+ }
+
+ for (j=0; j<*ny+2; j++) {
+ for (i=0; i<*nx+2; i++) {
+ tmp = (*U)[i][j];
+ fwrite(&tmp, sizeof(double), 1, fp);
+ }
+ }
+
+ for (j=0; j<*ny+2; j++) {
+ for (i=0; i<*nx+2; i++) {
+ tmp = (*V)[i][j];
+ fwrite(&tmp, sizeof(double), 1, fp);
+ }
+ }
+
+ fclose(fp);
+ }
+ return 0;
+}
diff --git a/src/file_io.h b/src/file_io.h
t@@ -10,4 +10,12 @@ int read_file(char *path,
int *nx, int *ny,
double ***P, double ***U, double ***V);
+int write_file(char *path,
+ double *t, double *t_end, double *tau, int *itermax,
+ double *epsilon, double *omega, double *gamma,
+ double *gx, double *gy, double *re,
+ 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);
#endif
diff --git a/src/main.c b/src/main.c
t@@ -12,11 +12,10 @@ int main(int argc, char** argv)
int w_left, w_right, w_top, w_bottom;
double dx, dy;
int nx, ny;
- double **P = NULL;
- double **U = NULL;
- double **V = NULL;
+ double **P, **U, **V;
- read_file("unnamed.dat", &t, &t_end, &tau, &itermax, &epsilon, &omega, &ga…
+ 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);
t@@ -24,6 +23,11 @@ int main(int argc, char** argv)
printf("P[0][0] = %f\n", P[0][0]);
printf("V[%d][%d] = %f\n", nx, ny, V[nx][ny]);
+ write_file("unnamed2.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);
+
free_memory(P, U, V, nx);
return 0;
}
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.