TYCHO  1.3.0
 All Data Structures Files Functions Variables Enumerations Enumerator
Functions
/home/kapf/tycho_docu/read_ic.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "variables_global.h"
#include "prototypes.h"

Go to the source code of this file.

Functions

int read_ic (int x, int y, int z)
int read_dom (int x, int y, int z)
int read_soundemitter (int x, int y, int z)
int read_marker_file (int x, int y, int z)
int read_wind_file (int x, int y, int z)

Function Documentation

int read_dom ( int  x,
int  y,
int  z 
)

Definition at line 129 of file read_ic.c.

References dom, obst_ic, x, y, and z.

Referenced by main().

{
int i, j, k, tmp1;
char filename[200];
FILE *fd;
//The initial obstacles distribution
sprintf(filename, "%s", obst_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("---------------------------------\n");
printf("No initial obstacles file found\n");
printf("---------------------------------\n");
exit(13);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp1, 1, sizeof (int), fd);
dom[i][j][k] = tmp1;
}
}
}
fclose(fd);
return 0;
}
int read_ic ( int  x,
int  y,
int  z 
)

If you want to read in initial conditions from an native TYCHO file.

Definition at line 17 of file read_ic.c.

References counter, counter_restart, dens_ic, dom, gasconstant, intial_velocity_file, obst_ic, pre, rho, temp_ic, time_sim, vel_ic, vx, vy, vz, with_obstacles, x, y, and z.

Referenced by main().

{
int i, j, k, tmp1;
double tmp;
char filename[200];
char buffer[10];
FILE *fd;
//The initial density distribution.
sprintf(filename, "%s", dens_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("-----------------------------\n");
printf("No initial density file found\n");
printf("-----------------------------\n");
exit(12);
}
fgets(buffer, 100, fd);
fgets(buffer, 100, fd);
time_sim = atof(buffer);
fgets(buffer, 100, fd);
x = atoi(buffer);
fgets(buffer, 100, fd);
y = atoi(buffer);
fgets(buffer, 100, fd);
z = atoi(buffer);
fgets(buffer, 100, fd);
counter = atoi(buffer);
fgets(buffer, 100, fd);
counter_restart = atoi(buffer);
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp, 1, sizeof (double), fd);
rho[i][j][k] = tmp;
}
}
}
fclose(fd);
//The initial temperature distribution
sprintf(filename, "%s", temp_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("---------------------------------\n");
printf("No initial temperature file found\n");
printf("---------------------------------\n");
exit(13);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp, 1, sizeof (double), fd);
pre[i][j][k] = (tmp) * gasconstant * rho[i][j][k];
;
}
}
}
fclose(fd);
//The initial velocity distribution
sprintf(filename, "%s", vel_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("------------------------------\n");
printf("No initial velocity file found\n");
printf("------------------------------\n");
exit(14);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp, 1, sizeof (double), fd);
vx[i][j][k] = tmp;
fread(&tmp, 1, sizeof (double), fd);
vy[i][j][k] = tmp;
fread(&tmp, 1, sizeof (double), fd);
vz[i][j][k] = tmp;
}
}
}
fclose(fd);
}
if (with_obstacles == 1) {
//The initial obstacles distribution
sprintf(filename, "%s", obst_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("---------------------------------\n");
printf("No initial obstacles file found\n");
printf("---------------------------------\n");
exit(13);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp1, 1, sizeof (int), fd);
dom[i][j][k] = tmp1;
}
}
}
fclose(fd);
}
return 0;
}
int read_marker_file ( int  x,
int  y,
int  z 
)

Definition at line 186 of file read_ic.c.

References marker, marker_ic, x, y, and z.

Referenced by main().

{
int i, j, k, tmp1;
char filename[200];
FILE *fd;
//The initial marker distribution
sprintf(filename, "%s", marker_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("---------------------------------\n");
printf("No initial marker file found\n");
printf("---------------------------------\n");
exit(13);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp1, 1, sizeof (int), fd);
marker[i][j][k] = tmp1;
}
}
}
fclose(fd);
return 0;
}
int read_soundemitter ( int  x,
int  y,
int  z 
)

Definition at line 158 of file read_ic.c.

References sound_ic, soundemitter, x, y, and z.

Referenced by main().

{
int i, j, k, tmp1;
char filename[200];
FILE *fd;
//The initial obstacles distribution
sprintf(filename, "%s", sound_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("---------------------------------\n");
printf("No initial sound-emitter file found\n");
printf("---------------------------------\n");
exit(13);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp1, 1, sizeof (int), fd);
soundemitter[i][j][k] = tmp1;
}
}
}
fclose(fd);
return 0;
}
int read_wind_file ( int  x,
int  y,
int  z 
)

Definition at line 215 of file read_ic.c.

References wind_ic, wind_marker, x, y, and z.

Referenced by main().

{
int i, j, k, tmp1;
char filename[200];
FILE *fd;
//The initial marker distribution
sprintf(filename, "%s", wind_ic);
fd = fopen(filename, "r");
if (fd == NULL) {
printf("---------------------------------\n");
printf("No wind file found\n");
printf("---------------------------------\n");
exit(13);
}
fseek(fd, 200, SEEK_SET);
for (i = 0; i < x; i++) {
for (j = 0; j < y; j++) {
for (k = 0; k < z; k++) {
fread(&tmp1, 1, sizeof (int), fd);
wind_marker[i][j][k] = tmp1;
}
}
}
fclose(fd);
return 0;
}