-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisual.c
99 lines (82 loc) · 2.32 KB
/
visual.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "helper.h"
#include "visual.h"
#include <stdio.h>
void write_vtkFile(const char *szProblem,
int timeStepNumber,
double xlength,
double ylength,
int imax,
int jmax,
double dx,
double dy,
double **U,
double **V,
double **P) {
int i,j;
char szFileName[80];
FILE *fp=NULL;
sprintf( szFileName, "%s.%i.vtk", szProblem, timeStepNumber );
fp = fopen( szFileName, "w");
if( fp == NULL )
{
char szBuff[80];
sprintf( szBuff, "Failed to open %s", szFileName );
ERROR( szBuff );
return;
}
write_vtkHeader( fp, imax, jmax, dx, dy);
write_vtkPointCoordinates(fp, imax, jmax, dx, dy);
fprintf(fp,"POINT_DATA %i \n", (imax+1)*(jmax+1) );
fprintf(fp,"\n");
fprintf(fp, "VECTORS velocity float\n");
for(j = 0; j < jmax+1; j++) {
for(i = 0; i < imax+1; i++) {
fprintf(fp, "%f %f 0\n", (U[i][j] + U[i][j+1]) * 0.5, (V[i][j] + V[i+1][j]) * 0.5 );
}
}
fprintf(fp,"\n");
fprintf(fp,"CELL_DATA %i \n", ((imax)*(jmax)) );
fprintf(fp, "SCALARS pressure float 1 \n");
fprintf(fp, "LOOKUP_TABLE default \n");
for(j = 1; j < jmax+1; j++) {
for(i = 1; i < imax+1; i++) {
fprintf(fp, "%f\n", P[i][j] );
}
}
if( fclose(fp) )
{
char szBuff[80];
sprintf( szBuff, "Failed to close %s", szFileName );
ERROR( szBuff );
}
}
void write_vtkHeader( FILE *fp, int imax, int jmax,
double dx, double dy) {
if( fp == NULL )
{
char szBuff[80];
sprintf( szBuff, "Null pointer in write_vtkHeader" );
ERROR( szBuff );
return;
}
fprintf(fp,"# vtk DataFile Version 2.0\n");
fprintf(fp,"generated by CFD-lab course output (written by Tobias Neckel) \n");
fprintf(fp,"ASCII\n");
fprintf(fp,"\n");
fprintf(fp,"DATASET STRUCTURED_GRID\n");
fprintf(fp,"DIMENSIONS %i %i 1 \n", imax+1, jmax+1);
fprintf(fp,"POINTS %i float\n", (imax+1)*(jmax+1) );
fprintf(fp,"\n");
}
void write_vtkPointCoordinates( FILE *fp, int imax, int jmax,
double dx, double dy) {
double originX = 0.0;
double originY = 0.0;
int i = 0;
int j = 0;
for(j = 0; j < jmax+1; j++) {
for(i = 0; i < imax+1; i++) {
fprintf(fp, "%f %f 0\n", originX+(i*dx), originY+(j*dy) );
}
}
}