TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
/home/kapf/tycho_docu/write_ic_amira.c
Go to the documentation of this file.
1 /*
2  * write_ic_amira.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_amira(int x, int y, int z) {
21  FILE *fd;
22  char filename[600];
23  int i, j, k;
24 
25  long long int tmp1, tmp1_vx, tmp1_vy, tmp1_vz;
26  double tmp, tmp_vx, tmp_vy, tmp_vz;
27 
28  sprintf(filename, "%srho_ic.am", output_dir);
29  fd = fopen(filename, "wb");
30  if (fd == NULL) {
31  printf("-----------------------------------\n");
32  printf("The output directory does not exist\n");
33  printf("-----------------------------------\n");
34  exit(13);
35  }
36  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
37  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
38  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
39  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
40  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
41  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
42  fprintf(fd, "}\n\nLattice { double ScalarField } = @1\n\n");
43  fprintf(fd, "@1\n");
44  for (k = 0; k < z; k++) {
45  for (j = 0; j < y; j++) {
46  for (i = 0; i < x; i++) {
47  tmp = rho[i][j][k];
48  tmp1 = ntohll(*((long long int*) & tmp));
49  fwrite(&tmp1, 1, sizeof (double), fd);
50  }
51  }
52  }
53  fclose(fd);
54 
55  sprintf(filename, "%spressure_ic.am", output_dir);
56  fd = fopen(filename, "wb");
57  if (fd == NULL) {
58  printf("-----------------------------------\n");
59  printf("The output directory does not exist\n");
60  printf("-----------------------------------\n");
61  exit(13);
62  }
63  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
64  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
65  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
66  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
67  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
68  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
69  fprintf(fd, "}\n\nLattice { double ScalarField } = @1\n\n");
70  fprintf(fd, "@1\n");
71  for (k = 0; k < z; k++) {
72  for (j = 0; j < y; j++) {
73  for (i = 0; i < x; i++) {
74  if (dom[i][j][k] == 0) tmp = pre[i][j][k];
75  if (dom[i][j][k] == 1) tmp = 0.0;
76  tmp1 = ntohll(*((long long int*) & tmp));
77  fwrite(&tmp1, 1, sizeof (double), fd);
78  }
79  }
80  }
81  fclose(fd);
82 
83  sprintf(filename, "%stemp_ic.am", output_dir);
84  fd = fopen(filename, "wb");
85  if (fd == NULL) {
86  printf("-----------------------------------\n");
87  printf("The output directory does not exist\n");
88  printf("-----------------------------------\n");
89  exit(13);
90  }
91  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
92  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
93  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
94  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
95  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
96  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
97  fprintf(fd, "}\n\nLattice { double ScalarField } = @1\n\n");
98  fprintf(fd, "@1\n");
99  for (k = 0; k < z; k++) {
100  for (j = 0; j < y; j++) {
101  for (i = 0; i < x; i++) {
102  tmp = pre[i][j][k] / (gasconstant * rho[i][j][k]);
103  tmp1 = ntohll(*((long long int*) & tmp));
104  fwrite(&tmp1, 1, sizeof (double), fd);
105  }
106  }
107  }
108  fclose(fd);
109 
110  sprintf(filename, "%svel_ic.am", output_dir);
111  fd = fopen(filename, "wb");
112  if (fd == NULL) {
113  printf("-----------------------------------\n");
114  printf("The output directory does not exist\n");
115  printf("-----------------------------------\n");
116  exit(13);
117  }
118  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
119  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
120  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
121  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
122  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
123  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
124  fprintf(fd, "}\n\nLattice { double[3] ScalarField } = @1\n\n");
125  fprintf(fd, "@1\n");
126  for (k = 0; k < z; k++) {
127  for (j = 0; j < y; j++) {
128  for (i = 0; i < x; i++) {
129  tmp_vx = vx[i][j][k];
130  tmp1_vx = ntohll(*((long long int*) & tmp_vx));
131  tmp_vy = vy[i][j][k];
132  tmp1_vy = ntohll(*((long long int*) & tmp_vy));
133  tmp_vz = vz[i][j][k];
134  tmp1_vz = ntohll(*((long long int*) & tmp_vz));
135 
136  fwrite(&tmp1_vx, 1, sizeof (double), fd);
137  fwrite(&tmp1_vy, 1, sizeof (double), fd);
138  fwrite(&tmp1_vz, 1, sizeof (double), fd);
139  }
140  }
141  }
142  fclose(fd);
143 
144  if (with_obstacles == 1) {
145  sprintf(filename, "%spressure_on_solid_ic.am", output_dir);
146  fd = fopen(filename, "wb");
147  if (fd == NULL) {
148  printf("-----------------------------------\n");
149  printf("The output directory does not exist\n");
150  printf("-----------------------------------\n");
151  exit(13);
152  }
153  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
154  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
155  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
156  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
157  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
158  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
159  fprintf(fd, "}\n\nLattice { double ScalarField } = @1\n\n");
160  fprintf(fd, "@1\n");
161  for (k = 0; k < z; k++) {
162  for (j = 0; j < y; j++) {
163  for (i = 0; i < x; i++) {
164  tmp = pressure_on_solid[i][j][k];
165  tmp1 = ntohll(*((long long int*) & tmp));
166  fwrite(&tmp1, 1, sizeof (double), fd);
167  }
168  }
169  }
170  fclose(fd);
171 
172  if ((with_sound_emitter == 1) && (dB_Map_ready == 1)) {
173  sprintf(filename, "%sdB_map_ic.am", output_dir);
174  fd = fopen(filename, "wb");
175  if (fd == NULL) {
176  printf("-----------------------------------\n");
177  printf("The output directory does not exist\n");
178  printf("-----------------------------------\n");
179  exit(13);
180  }
181  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
182  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
183  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
184  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
185  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
186  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
187  fprintf(fd, "}\n\nLattice { double ScalarField } = @1\n\n");
188  fprintf(fd, "@1\n");
189  for (k = 0; k < z; k++) {
190  for (j = 0; j < y; j++) {
191  for (i = 0; i < x; i++) {
192  tmp = dB_map[i][j][k];
193  tmp1 = ntohll(*((long long int*) & tmp));
194  fwrite(&tmp1, 1, sizeof (double), fd);
195  }
196  }
197  }
198  fclose(fd);
199  }
200  }
201 
202  if (advection == 1) {
203  sprintf(filename, "%smarker_ic.am", output_dir);
204  fd = fopen(filename, "wb");
205  if (fd == NULL) {
206  printf("-----------------------------------\n");
207  printf("The output directory does not exist\n");
208  printf("-----------------------------------\n");
209  exit(13);
210  }
211  fprintf(fd, "# AmiraMesh BINARY 1.0\n");
212  fprintf(fd, "\n# Dimensions in x-, y-, and z-direction\n");
213  fprintf(fd, "define Lattice %i %i %i\n\n", x, y, z);
214  fprintf(fd, "Parameters {\n CoordType \"uniform\"\n");
215  fprintf(fd, " # BoundingBox is xmin xmax ymin ymax zmin zmax\n");
216  fprintf(fd, " BoundingBox %g %g %g %g %g %g\n", xmin, xmax, ymin, ymax, zmin, zmax);
217  fprintf(fd, "}\n\nLattice { double ScalarField } = @1\n\n");
218  fprintf(fd, "@1\n");
219  for (k = 0; k < z; k++) {
220  for (j = 0; j < y; j++) {
221  for (i = 0; i < x; i++) {
222  tmp = marker[i][j][k];
223  tmp1 = ntohll(*((long long int*) & tmp));
224  fwrite(&tmp1, 1, sizeof (double), fd);
225  }
226  }
227  }
228  fclose(fd);
229  }
230 
231  return 0;
232 }