accelerInt  v0.1
read_initial_conditions.c
Go to the documentation of this file.
1 
10 #include "header.h"
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14 #include <sys/time.h>
15 
30  void read_initial_conditions(const char* filename, int NUM, double** y_host, double** variable_host) {
31  (*y_host) = (double*)malloc(NUM * NSP * sizeof(double));
32  (*variable_host) = (double*)malloc(NUM * sizeof(double));
33  FILE *fp = fopen (filename, "rb");
34  if (fp == NULL)
35  {
36  fprintf(stderr, "Could not open file: %s\n", filename);
37  exit(-1);
38  }
39  double buffer[NN + 2];
40 
41  // load temperature and mass fractions for all threads (cells)
42  for (int i = 0; i < NUM; ++i)
43  {
44  // read line from data file
45  int count = fread(buffer, sizeof(double), NN + 2, fp);
46  if (count != (NN + 2))
47  {
48  fprintf(stderr, "File (%s) is incorrectly formatted, %d doubles were expected but only %d were read.\n", filename, NN + 1, count);
49  exit(-1);
50  }
51  //apply mask if necessary
52  apply_mask(&buffer[3]);
53  //put into y_host
54  (*y_host)[i] = buffer[1];
55 #ifdef CONP
56  (*variable_host)[i] = buffer[2];
57 #elif CONV
58  double pres = buffer[2];
59 #endif
60  for (int j = 0; j < NSP - 1; j++)
61  (*y_host)[i + (j + 1) * NUM] = buffer[j + 3];
62 
63  // if constant volume, calculate density
64 #ifdef CONV
65  double Yi[NSP - 1];
66  double Xi[NSP - 1];
67 
68  for (int j = 0; j < NSP - 1; ++j)
69  {
70  Yi[j] = (*y_host)[i + (j + 1) * NUM];
71  }
72 
73  mass2mole (Yi, Xi);
74  (*variable_host)[i] = getDensity ((*y_host)[i], pres, Xi);
75 #endif
76  }
77  fclose (fp);
78 }
An example header file that defines system size and other required methods for integration of the van...
#define NSP
The IVP system size.
Definition: header.cuh:20
void apply_mask(double *y_host)
Not needed for van der Pol.
Definition: ics.cu:46
void read_initial_conditions(const char *filename, int NUM, double **y_host, double **variable_host)
Reads initial conditions for IVPs from binary file.
#define NN
Input vector size (in read_initial_conditions)
Definition: header.cuh:22