TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/write_ic_vtk.c
Go to the documentation of this file.
1 /*
2  * write_ic_vtk.c
3  *
4  * Author: Wolfgang Kapferer
5  */
6 
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <math.h>
11 
12 #include "variables_global.h"
13 #include "prototypes.h"
14 
20 int write_ic_vtk(int x, int y, int z) {
21  FILE *fd;
22  char filename[600];
23  int i, j, k;
24  long long int tmp1, tmp1_vx, tmp1_vy, tmp1_vz;
25  double tmp, tmp_vx, tmp_vy, tmp_vz;
26 
27  sprintf(filename, "%srho_ic.vtk", output_dir);
28  fd = fopen(filename, "wb");
29  if (fd == NULL) {
30  printf("-----------------------------------\n");
31  printf("The output directory does not exist\n");
32  printf("-----------------------------------\n");
33  exit(13);
34  }
35  fprintf(fd, "# vtk DataFile Version 3.0\n");
36  fprintf(fd, "TYCHO Density File - Time:%g\n", time_sim / minute_in_sec);
37  fprintf(fd, "BINARY\n");
38  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
39  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
40  fprintf(fd, "X_COORDINATES %i double\n", x);
41  for (i = 0; i < x; i++) {
42  tmp = ((double) xmax / (double) x) * (double) i;
43  tmp1 = ntohll(*((long long int*) & tmp));
44  fwrite(&tmp1, 1, sizeof (double), fd);
45  }
46  fprintf(fd, "\nY_COORDINATES %i double\n", y);
47  for (i = 0; i < y; i++) {
48  tmp = ((double) ymax / (double) y) * (double) i;
49  tmp1 = ntohll(*((long long int*) & tmp));
50  fwrite(&tmp1, 1, sizeof (double), fd);
51  }
52  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
53  for (i = 0; i < z; i++) {
54  tmp = ((double) zmax / (double) z) * (double) i;
55  tmp1 = ntohll(*((long long int*) & tmp));
56  fwrite(&tmp1, 1, sizeof (double), fd);
57  }
58  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
59  fprintf(fd, "SCALARS density double 1\n");
60  fprintf(fd, "LOOKUP_TABLE default\n");
61  for (k = 0; k < z; k++) {
62  for (j = 0; j < y; j++) {
63  for (i = 0; i < x; i++) {
64  tmp = rho[i][j][k];
65  tmp1 = ntohll(*((long long int*) & tmp));
66  fwrite(&tmp1, 1, sizeof (double), fd);
67  }
68  }
69  }
70  fclose(fd);
71 
72  sprintf(filename, "%spressure_ic.vtk", output_dir);
73  fd = fopen(filename, "wb");
74  if (fd == NULL) {
75  printf("-----------------------------------\n");
76  printf("The output directory does not exist\n");
77  printf("-----------------------------------\n");
78  exit(13);
79  }
80  fprintf(fd, "# vtk DataFile Version 3.0\n");
81  fprintf(fd, "TYCHO Pressure File - Time:%g\n", time_sim / minute_in_sec);
82  fprintf(fd, "BINARY\n");
83  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
84  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
85  fprintf(fd, "X_COORDINATES %i double\n", x);
86  for (i = 0; i < x; i++) {
87  tmp = ((double) xmax / (double) x) * (double) i;
88  tmp1 = ntohll(*((long long int*) & tmp));
89  fwrite(&tmp1, 1, sizeof (double), fd);
90  }
91  fprintf(fd, "\nY_COORDINATES %i double\n", y);
92  for (i = 0; i < y; i++) {
93  tmp = ((double) ymax / (double) y) * (double) i;
94  tmp1 = ntohll(*((long long int*) & tmp));
95  fwrite(&tmp1, 1, sizeof (double), fd);
96  }
97  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
98  for (i = 0; i < z; i++) {
99  tmp = ((double) zmax / (double) z) * (double) i;
100  tmp1 = ntohll(*((long long int*) & tmp));
101  fwrite(&tmp1, 1, sizeof (double), fd);
102  }
103  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
104  fprintf(fd, "SCALARS pressure double 1\n");
105  fprintf(fd, "LOOKUP_TABLE default\n");
106  for (k = 0; k < z; k++) {
107  for (j = 0; j < y; j++) {
108  for (i = 0; i < x; i++) {
109  if (dom[i][j][k] == 0) tmp = pre[i][j][k];
110  if (dom[i][j][k] == 1) tmp = 0.0;
111  tmp1 = ntohll(*((long long int*) & tmp));
112  fwrite(&tmp1, 1, sizeof (double), fd);
113  }
114  }
115  }
116  fclose(fd);
117 
118  sprintf(filename, "%stemp_ic.vtk", output_dir);
119  fd = fopen(filename, "wb");
120  if (fd == NULL) {
121  printf("-----------------------------------\n");
122  printf("The output directory does not exist\n");
123  printf("-----------------------------------\n");
124  exit(13);
125  }
126  fprintf(fd, "# vtk DataFile Version 3.0\n");
127  fprintf(fd, "TYCHO Temperature File - Time:%g\n", time_sim / minute_in_sec);
128  fprintf(fd, "BINARY\n");
129  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
130  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
131  fprintf(fd, "X_COORDINATES %i double\n", x);
132  for (i = 0; i < x; i++) {
133  tmp = ((double) xmax / (double) x) * (double) i;
134  tmp1 = ntohll(*((long long int*) & tmp));
135  fwrite(&tmp1, 1, sizeof (double), fd);
136  }
137  fprintf(fd, "\nY_COORDINATES %i double\n", y);
138  for (i = 0; i < y; i++) {
139  tmp = ((double) ymax / (double) y) * (double) i;
140  tmp1 = ntohll(*((long long int*) & tmp));
141  fwrite(&tmp1, 1, sizeof (double), fd);
142  }
143  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
144  for (i = 0; i < z; i++) {
145  tmp = ((double) zmax / (double) z) * (double) i;
146  tmp1 = ntohll(*((long long int*) & tmp));
147  fwrite(&tmp1, 1, sizeof (double), fd);
148  }
149  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
150  fprintf(fd, "SCALARS temperature double 1\n");
151  fprintf(fd, "LOOKUP_TABLE default\n");
152  for (k = 0; k < z; k++) {
153  for (j = 0; j < y; j++) {
154  for (i = 0; i < x; i++) {
155  tmp = pre[i][j][k] / (gasconstant * rho[i][j][k]);
156  tmp1 = ntohll(*((long long int*) & tmp));
157  fwrite(&tmp1, 1, sizeof (double), fd);
158  }
159  }
160  }
161  fclose(fd);
162 
163  sprintf(filename, "%svel_ic.vtk", output_dir);
164  fd = fopen(filename, "wb");
165  if (fd == NULL) {
166  printf("-----------------------------------\n");
167  printf("The output directory does not exist\n");
168  printf("-----------------------------------\n");
169  exit(13);
170  }
171  fprintf(fd, "# vtk DataFile Version 3.0\n");
172  fprintf(fd, "TYCHO Velocity File - Time:%g\n", time_sim / minute_in_sec);
173  fprintf(fd, "BINARY\n");
174  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
175  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
176  fprintf(fd, "X_COORDINATES %i double\n", x);
177  for (i = 0; i < x; i++) {
178  tmp = ((double) xmax / (double) x) * (double) i;
179  tmp1 = ntohll(*((long long int*) & tmp));
180  fwrite(&tmp1, 1, sizeof (double), fd);
181  }
182  fprintf(fd, "\nY_COORDINATES %i double\n", y);
183  for (i = 0; i < y; i++) {
184  tmp = ((double) ymax / (double) y) * (double) i;
185  tmp1 = ntohll(*((long long int*) & tmp));
186  fwrite(&tmp1, 1, sizeof (double), fd);
187  }
188  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
189  for (i = 0; i < z; i++) {
190  tmp = ((double) zmax / (double) z) * (double) i;
191  tmp1 = ntohll(*((long long int*) & tmp));
192  fwrite(&tmp1, 1, sizeof (double), fd);
193  }
194  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
195  fprintf(fd, "VECTORS velocity double 1\n");
196  for (k = 0; k < z; k++) {
197  for (j = 0; j < y; j++) {
198  for (i = 0; i < x; i++) {
199  tmp_vx = vx[i][j][k];
200  tmp1_vx = ntohll(*((long long int*) & tmp_vx));
201  tmp_vy = vy[i][j][k];
202  tmp1_vy = ntohll(*((long long int*) & tmp_vy));
203  tmp_vz = vz[i][j][k];
204  tmp1_vz = ntohll(*((long long int*) & tmp_vz));
205 
206  fwrite(&tmp1_vx, 1, sizeof (double), fd);
207  fwrite(&tmp1_vy, 1, sizeof (double), fd);
208  fwrite(&tmp1_vz, 1, sizeof (double), fd);
209  }
210  }
211  }
212  fclose(fd);
213 
214  if (with_obstacles == 1) {
215  sprintf(filename, "%spressure_on_solid_ic.vtk", output_dir);
216  fd = fopen(filename, "wb");
217  if (fd == NULL) {
218  printf("-----------------------------------\n");
219  printf("The output directory does not exist\n");
220  printf("-----------------------------------\n");
221  exit(13);
222  }
223  fprintf(fd, "# vtk DataFile Version 3.0\n");
224  fprintf(fd, "TYCHO pressure on solid File - Time:%g\n", time_sim / minute_in_sec);
225  fprintf(fd, "BINARY\n");
226  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
227  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
228  fprintf(fd, "X_COORDINATES %i double\n", x);
229  for (i = 0; i < x; i++) {
230  tmp = ((double) xmax / (double) x) * (double) i;
231  tmp1 = ntohll(*((long long int*) & tmp));
232  fwrite(&tmp1, 1, sizeof (double), fd);
233  }
234  fprintf(fd, "\nY_COORDINATES %i double\n", y);
235  for (i = 0; i < y; i++) {
236  tmp = ((double) ymax / (double) y) * (double) i;
237  tmp1 = ntohll(*((long long int*) & tmp));
238  fwrite(&tmp1, 1, sizeof (double), fd);
239  }
240  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
241  for (i = 0; i < z; i++) {
242  tmp = ((double) zmax / (double) z) * (double) i;
243  tmp1 = ntohll(*((long long int*) & tmp));
244  fwrite(&tmp1, 1, sizeof (double), fd);
245  }
246  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
247  fprintf(fd, "SCALARS pressure_on_solid double 1\n");
248  fprintf(fd, "LOOKUP_TABLE default\n");
249  for (k = 0; k < z; k++) {
250  for (j = 0; j < y; j++) {
251  for (i = 0; i < x; i++) {
252  tmp = pressure_on_solid[i][j][k];
253  tmp1 = ntohll(*((long long int*) & tmp));
254  fwrite(&tmp1, 1, sizeof (double), fd);
255  }
256  }
257  }
258  fclose(fd);
259  if ((with_sound_emitter == 1) && (dB_Map_ready == 1)) {
260  sprintf(filename, "%TYCHO dB_map_ic.vtk", output_dir);
261  fd = fopen(filename, "wb");
262  if (fd == NULL) {
263  printf("-----------------------------------\n");
264  printf("The output directory does not exist\n");
265  printf("-----------------------------------\n");
266  exit(13);
267  }
268  fprintf(fd, "# vtk DataFile Version 3.0\n");
269  fprintf(fd, "TYCHO dBA map file - Time:%g\n", time_sim / minute_in_sec);
270  fprintf(fd, "BINARY\n");
271  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
272  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
273  fprintf(fd, "X_COORDINATES %i double\n", x);
274  for (i = 0; i < x; i++) {
275  tmp = ((double) xmax / (double) x) * (double) i;
276  tmp1 = ntohll(*((long long int*) & tmp));
277  fwrite(&tmp1, 1, sizeof (double), fd);
278  }
279  fprintf(fd, "\nY_COORDINATES %i double\n", y);
280  for (i = 0; i < y; i++) {
281  tmp = ((double) ymax / (double) y) * (double) i;
282  tmp1 = ntohll(*((long long int*) & tmp));
283  fwrite(&tmp1, 1, sizeof (double), fd);
284  }
285  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
286  for (i = 0; i < z; i++) {
287  tmp = ((double) zmax / (double) z) * (double) i;
288  tmp1 = ntohll(*((long long int*) & tmp));
289  fwrite(&tmp1, 1, sizeof (double), fd);
290  }
291  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
292  fprintf(fd, "SCALARS pressure_on_solid double 1\n");
293  fprintf(fd, "LOOKUP_TABLE default\n");
294  for (k = 0; k < z; k++) {
295  for (j = 0; j < y; j++) {
296  for (i = 0; i < x; i++) {
297  tmp = dB_map[i][j][k];
298  tmp1 = ntohll(*((long long int*) & tmp));
299  fwrite(&tmp1, 1, sizeof (double), fd);
300  }
301  }
302  }
303  fclose(fd);
304  }
305  }
306 
307  if (advection == 1) {
308 
309  sprintf(filename, "%smarker_ic.vtk", output_dir);
310  fd = fopen(filename, "wb");
311  if (fd == NULL) {
312  printf("-----------------------------------\n");
313  printf("The output directory does not exist\n");
314  printf("-----------------------------------\n");
315  exit(13);
316  }
317  fprintf(fd, "# vtk DataFile Version 3.0\n");
318  fprintf(fd, "TYCHO Marker File - Time:%g\n", time_sim / minute_in_sec);
319  fprintf(fd, "BINARY\n");
320  fprintf(fd, "DATASET RECTILINEAR_GRID\n");
321  fprintf(fd, "DIMENSIONS %i %i %i\n", x, y, z);
322  fprintf(fd, "X_COORDINATES %i double\n", x);
323  for (i = 0; i < x; i++) {
324  tmp = ((double) xmax / (double) x) * (double) i;
325  tmp1 = ntohll(*((long long int*) & tmp));
326  fwrite(&tmp1, 1, sizeof (double), fd);
327  }
328  fprintf(fd, "\nY_COORDINATES %i double\n", y);
329  for (i = 0; i < y; i++) {
330  tmp = ((double) ymax / (double) y) * (double) i;
331  tmp1 = ntohll(*((long long int*) & tmp));
332  fwrite(&tmp1, 1, sizeof (double), fd);
333  }
334  fprintf(fd, "\nZ_COORDINATES %i double\n", z);
335  for (i = 0; i < z; i++) {
336  tmp = ((double) zmax / (double) z) * (double) i;
337  tmp1 = ntohll(*((long long int*) & tmp));
338  fwrite(&tmp1, 1, sizeof (double), fd);
339  }
340  fprintf(fd, "\nPOINT_DATA %i\n", x * y * z);
341  fprintf(fd, "SCALARS marker_density double 1\n");
342  fprintf(fd, "LOOKUP_TABLE default\n");
343  for (k = 0; k < z; k++) {
344  for (j = 0; j < y; j++) {
345  for (i = 0; i < x; i++) {
346  tmp = marker[i][j][k];
347  tmp1 = ntohll(*((long long int*) & tmp));
348  fwrite(&tmp1, 1, sizeof (double), fd);
349  }
350  }
351  }
352  fclose(fd);
353 
354  }
355 
356  return 0;
357 }