TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/write_ic_tyc.c
Go to the documentation of this file.
1 /*
2  * write_ic.c
3  *
4  * Author: Wolfgang Kapferer
5  */
6 
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 
11 #include "variables_global.h"
12 #include "prototypes.h"
13 
17 int write_ic_tyc(int x, int y, int z) {
18  FILE *fd;
19  char filename[600];
20  int i, j, k, tmp1;
21  double tmp;
22 
23  sprintf(filename, "%srho_ic.tyc", output_dir);
24  fd = fopen(filename, "wb");
25  if (fd == NULL) {
26  printf("-----------------------------------\n");
27  printf("The output directory does not exist\n");
28  printf("-----------------------------------\n");
29  exit(13);
30  }
31  fprintf(fd, "TYCHO Density File\n%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
32  fseek(fd, 200, SEEK_SET);
33  for (i = 0; i < x; i++) {
34  for (j = 0; j < y; j++) {
35  for (k = 0; k < z; k++) {
36  tmp = rho[i][j][k];
37  fwrite(&tmp, 1, sizeof (double), fd);
38  //printf("write: %f %i %i\n", tmp, i, j);
39  }
40  }
41  }
42 
43  fclose(fd);
44 
45  sprintf(filename, "%stemp_ic.tyc", output_dir);
46  fd = fopen(filename, "wb");
47  fprintf(fd, "TYCHO Temperature File\n%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
48  fseek(fd, 200, SEEK_SET);
49  for (i = 0; i < x; i++) {
50  for (j = 0; j < y; j++) {
51  for (k = 0; k < z; k++) {
52  tmp = pre[i][j][k] / (gasconstant * rho[i][j][k]);
53  fwrite(&tmp, 1, sizeof (double), fd);
54  }
55  }
56  }
57  fclose(fd);
58 
59  sprintf(filename, "%spressure_ic.tyc", output_dir);
60  fd = fopen(filename, "wb");
61  fprintf(fd, "TYCHO Pressure File\n%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
62  fseek(fd, 200, SEEK_SET);
63  for (i = 0; i < x; i++) {
64  for (j = 0; j < y; j++) {
65  for (k = 0; k < z; k++) {
66  if (dom[i][j][k] == 0) tmp = pre[i][j][k];
67  if (dom[i][j][k] == 1) tmp = 0.0;
68  fwrite(&tmp, 1, sizeof (double), fd);
69  }
70  }
71  }
72  fclose(fd);
73 
74  sprintf(filename, "%svel_ic.tyc", output_dir);
75  fd = fopen(filename, "wb");
76  fprintf(fd, "TYCHO Velocity File%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
77  fseek(fd, 200, SEEK_SET);
78  for (i = 0; i < x; i++) {
79  for (j = 0; j < y; j++) {
80  for (k = 0; k < z; k++) {
81  tmp = vx[i][j][k];
82  fwrite(&tmp, 1, sizeof (double), fd);
83  tmp = vy[i][j][k];
84  fwrite(&tmp, 1, sizeof (double), fd);
85  tmp = vz[i][j][k];
86  fwrite(&tmp, 1, sizeof (double), fd);
87  }
88  }
89  }
90  fclose(fd);
91 
92  if (with_obstacles == 1) {
93  sprintf(filename, "%spressure_on_solid_ic.tyc", output_dir);
94  fd = fopen(filename, "wb");
95  fprintf(fd, "TYCHO pressure on solid File\n%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
96  fseek(fd, 200, SEEK_SET);
97  for (i = 0; i < x; i++) {
98  for (j = 0; j < y; j++) {
99  for (k = 0; k < z; k++) {
100  tmp = pressure_on_solid[i][j][k];
101  fwrite(&tmp, 1, sizeof (double), fd);
102  }
103  }
104  }
105  fclose(fd);
106 
107  if ((with_sound_emitter == 1) && (dB_Map_ready == 1)) {
108  sprintf(filename, "%sdB_map_ic.tyc", output_dir, counter);
109  fd = fopen(filename, "wb");
110  fprintf(fd, "TYCHO dba_map\n%g\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter);
111  fseek(fd, 200, SEEK_SET);
112  for (i = 0; i < x; i++) {
113  for (j = 0; j < y; j++) {
114  for (k = 0; k < z; k++) {
115  tmp = dB_map[i][j][k];
116  if (isnan(tmp)) {
117  printf("NaN in dB_map array %i %i %i\n", i, j, k);
118  exit(1);
119  }
120 
121  fwrite(&tmp, 1, sizeof (double), fd);
122  }
123  }
124  }
125  fclose(fd);
126  }
127 
128  }
129 
130  if (advection == 1) {
131  sprintf(filename, "%smarker_ic.tyc", output_dir);
132  fd = fopen(filename, "wb");
133  fprintf(fd, "TYCHO Marker File\n%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
134  fseek(fd, 200, SEEK_SET);
135  for (i = 0; i < x; i++) {
136  for (j = 0; j < y; j++) {
137  for (k = 0; k < z; k++) {
138  tmp = marker[i][j][k];
139  if (isnan(tmp)) {
140  printf("NaN in marker array %i %i %i\n", i, j, k);
141  exit(1);
142  }
143  fwrite(&tmp, 1, sizeof (double), fd);
144  }
145  }
146  }
147  fclose(fd);
148  }
149 
150  return 0;
151 }