-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvisual.cpp
More file actions
111 lines (94 loc) · 3.07 KB
/
Copy pathvisual.cpp
File metadata and controls
111 lines (94 loc) · 3.07 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "visual.hpp"
#include <stdio.h>
#include "helper.hpp"
#include "datastructures.hpp"
void write_vtkFile(const char *szProblem,
int timeStepNumber,
Config& config,
MatrixXd& U, MatrixXd& V,
MatrixXd& P, MatrixXd& T,
matrix<int>& GeoArray) {
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, config.imax, config.jmax, config.dx, config.dy);
write_vtkPointCoordinates(fp, config.imax, config.jmax, config.il, config.jb, config.dx, config.dy);
fprintf(fp, "POINT_DATA %i \n", (config.imax + 1) * (config.jmax + 1));
fprintf(fp, "\n");
fprintf(fp, "VECTORS velocity float\n");
for (j = 0; j < config.jmax + 1; j++) {
for (i = 0; i < config.imax + 1; i++) {
fprintf(fp, "%f %f 0\n", (U.coeffRef(i,j) + U.coeffRef(i,j + 1)) * 0.5,
(V.coeffRef(i,j) + V.coeffRef(i + 1,j)) * 0.5);
}
}
fprintf(fp, "\n");
fprintf(fp, "CELL_DATA %i \n", ((config.imax) * (config.jmax)));
fprintf(fp, "SCALARS pressure float 1 \n");
fprintf(fp, "LOOKUP_TABLE default \n");
for (j = 1; j < config.jmax + 1; j++) {
for (i = 1; i < config.imax + 1; i++) {
fprintf(fp, "%f\n", P.coeffRef(i,j));
}
}
if(config.calcTemp > 0) {
fprintf(fp, "\n");
fprintf(fp, "SCALARS temperature float 1 \n");
fprintf(fp, "LOOKUP_TABLE default \n");
for (j = 1; j < config.jmax + 1; j++) {
for (i = 1; i < config.imax + 1; i++) {
fprintf(fp, "%f\n", T.coeffRef(i,j));
}
}
}
fprintf(fp, "\n");
fprintf(fp, "SCALARS domain int 1 \n");
fprintf(fp, "LOOKUP_TABLE default \n");
for (j = 1; j < config.jmax + 1; j++) {
for (i = 1; i < config.imax + 1; i++) {
fprintf(fp, "%i\n", GeoArray[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, int il, int jb, double dx,
double dy) {
double originX = (il-1) * dx;
double originY = (jb-1) * dy;
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));
}
}
}