tfile io in progress - 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 d7c14c02d398035d751b2d5e7dee8896b9c53437
(DIR) parent ff4818b93a5d588736b06699059914c255ee1596
(HTM) Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date: Sun, 2 Mar 2014 09:44:54 +0100
file io in progress
Diffstat:
A src/file_io.h | 13 +++++++++++++
A src/utility.c | 36 +++++++++++++++++++++++++++++++
A src/utility.h | 8 ++++++++
3 files changed, 57 insertions(+), 0 deletions(-)
---
(DIR) diff --git a/src/file_io.h b/src/file_io.h
t@@ -0,0 +1,13 @@
+#ifndef FILE_IO_H_
+#define FILE_IO_H_
+
+int read_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
(DIR) diff --git a/src/utility.c b/src/utility.c
t@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+/* Linear index from two-dimensional index */
+unsigned int idx(int x, int y, int nx)
+{
+ return x + y*nx;
+}
+
+/* Allocate memory for 2d arrays */
+int allocate_memory(double *p, double *u, double *v, int nx, int ny)
+{
+ p = malloc(sizeof(double)*(nx+1)*(ny+1));
+ if (p == NULL) {
+ fprintf(stderr, "allocate_memory: Could not allocate memory for p\n");
+ return 1;
+ }
+ u = malloc(sizeof(double)*(nx+2)*(ny+2));
+ if (u == NULL) {
+ fprintf(stderr, "allocate_memory: Could not allocate memory for u\n");
+ return 1;
+ }
+ v = malloc(sizeof(double)*(nx+2)*(ny+2));
+ if (v == NULL) {
+ fprintf(stderr, "allocate_memory: Could not allocate memory for v\n");
+ return 1;
+ }
+ return 0;
+}
+
+void free_memory(double *p, double *u, double *v)
+{
+ free(p);
+ free(u);
+ free(v);
+}
(DIR) diff --git a/src/utility.h b/src/utility.h
t@@ -0,0 +1,8 @@
+#ifndef UTILITY_H_
+#define UTILITY_H_
+
+unsigned int idx(int x, int y, int nx);
+int allocate_memory(double *p, double *u, double *v, int nx, int ny);
+void free_memory(double *p, double *u, double *v);
+
+#endif