TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/write_restart_tyc.c
Go to the documentation of this file.
1 /*
2  * write_restart_tyc.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_restart_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_restart.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  if (isnan(tmp)) {
38  printf("NaN in density array %i %i %i\n", i, j, k);
39  exit(0);
40  }
41  fwrite(&tmp, 1, sizeof (double), fd);
42  }
43  }
44  }
45 
46  fclose(fd);
47 
48  sprintf(filename, "%stemp_restart.tyc", output_dir);
49  fd = fopen(filename, "wb");
50  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);
51  fseek(fd, 200, SEEK_SET);
52  for (i = 0; i < x; i++) {
53  for (j = 0; j < y; j++) {
54  for (k = 0; k < z; k++) {
55  tmp = pre[i][j][k] / (gasconstant * rho[i][j][k]);
56  if (isnan(tmp)) {
57  printf("NaN in temperature array %i %i %i\n", i, j, k);
58  exit(0);
59  }
60  fwrite(&tmp, 1, sizeof (double), fd);
61  }
62  }
63  }
64  fclose(fd);
65 
66  sprintf(filename, "%svel_restart.tyc", output_dir);
67  fd = fopen(filename, "wb");
68  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);
69  fseek(fd, 200, SEEK_SET);
70  for (i = 0; i < x; i++) {
71  for (j = 0; j < y; j++) {
72  for (k = 0; k < z; k++) {
73  tmp = vx[i][j][k];
74  fwrite(&tmp, 1, sizeof (double), fd);
75  tmp = vy[i][j][k];
76  fwrite(&tmp, 1, sizeof (double), fd);
77  tmp = vz[i][j][k];
78  fwrite(&tmp, 1, sizeof (double), fd);
79  }
80  }
81  }
82  fclose(fd);
83 
84  if (with_obstacles == 1) {
85  sprintf(filename, "%sdom_restart.tyc", output_dir);
86  fd = fopen(filename, "wb");
87  fprintf(fd, "TYCHO Dom File%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
88  fseek(fd, 200, SEEK_SET);
89  for (i = 0; i < x; i++) {
90  for (j = 0; j < y; j++) {
91  for (k = 0; k < z; k++) {
92  tmp1 = dom[i][j][k];
93  if (isnan(tmp1)) {
94  printf("NaN in dom array %i %i %i\n", i, j, k);
95  exit(1);
96  }
97  fwrite(&tmp1, 1, sizeof (int), fd);
98  }
99  }
100  }
101  fclose(fd);
102  }
103 
104  if (with_sound_emitter == 1) {
105  sprintf(filename, "%ssound_emitter_restart.tyc", output_dir);
106  fd = fopen(filename, "wb");
107  fprintf(fd, "TYCHO Dom File%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
108  fseek(fd, 200, SEEK_SET);
109  for (i = 0; i < x; i++) {
110  for (j = 0; j < y; j++) {
111  for (k = 0; k < z; k++) {
112  tmp1 = soundemitter[i][j][k];
113  if (isnan(tmp1)) {
114  printf("NaN in sound_emitter array %i %i %i\n", i, j, k);
115  exit(1);
116  }
117  fwrite(&tmp1, 1, sizeof (int), fd);
118  }
119  }
120  }
121  fclose(fd);
122 
123  sprintf(filename, "%spressure_integrated_restart.tyc", output_dir);
124  fd = fopen(filename, "wb");
125  fprintf(fd, "TYCHO Pressure Integrated File%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
126  fseek(fd, 200, SEEK_SET);
127  for (i = 0; i < x; i++) {
128  for (j = 0; j < y; j++) {
129  for (k = 0; k < z; k++) {
130  tmp = pressure_integrated[i][j][k];
131  if (isnan(tmp)) {
132  printf("NaN in spressure_integrated_restart array %i %i %i\n", i, j, k);
133  exit(1);
134  }
135  fwrite(&tmp, 1, sizeof (double), fd);
136  }
137  }
138  }
139  fclose(fd);
140  }
141 
142  if (advection == 1) {
143 
144  sprintf(filename, "%smarker_restart.tyc", output_dir);
145  fd = fopen(filename, "wb");
146  fprintf(fd, "TYCHO Marker File%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
147  fseek(fd, 200, SEEK_SET);
148  for (i = 0; i < x; i++) {
149  for (j = 0; j < y; j++) {
150  for (k = 0; k < z; k++) {
151  tmp = marker[i][j][k];
152  if (isnan(tmp)) {
153  printf("NaN in marker array %i %i %i\n", i, j, k);
154  exit(1);
155  }
156  fwrite(&tmp, 1, sizeof (double), fd);
157  }
158  }
159  }
160  fclose(fd);
161 
162  }
163 
164  if (wind_on_off == 1) {
165 
166  sprintf(filename, "%swind_restart.tyc", output_dir);
167  fd = fopen(filename, "wb");
168  fprintf(fd, "TYCHO Wind File%g\n%i\n%i\n%i\n%i\n%i\n", time_sim, x, y, z, counter, counter_restart);
169  fseek(fd, 200, SEEK_SET);
170  for (i = 0; i < x; i++) {
171  for (j = 0; j < y; j++) {
172  for (k = 0; k < z; k++) {
173  tmp = wind_marker[i][j][k];
174  if (isnan(tmp)) {
175  printf("NaN in wind marker array %i %i %i\n", i, j, k);
176  exit(1);
177  }
178  fwrite(&tmp, 1, sizeof (double), fd);
179  }
180  }
181  }
182  fclose(fd);
183 
184  }
185 
186  return 0;
187 
188 }