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