cuIBM
A GPU-based Immersed Boundary Method code
parseDomainFile.cu
Go to the documentation of this file.
1 
8 #include <fstream>
9 
10 #include "io.h"
11 #include "yaml-cpp/yaml.h"
12 
13 
18 namespace io
19 {
20 
27 void parseDomain(const YAML::Node &node, domain &D)
28 {
29  std::string dir;
30  real start, end, stretchRatio, h;
31  int numCells;
32 
33  dir = node["direction"].as<std::string>();
34  start = node["start"].as<real>();
35 
36  if (dir=="x")
37  D.nx = 0;
38  else if(dir=="y")
39  D.ny = 0;
40 
41  const YAML::Node &subDomains = node["subDomains"];
42  // first pass
43  for (unsigned int i=0; i<subDomains.size(); i++)
44  {
45  numCells = subDomains[i]["cells"].as<int>();
46  if (dir=="x")
47  D.nx += numCells;
48  else if(dir=="y")
49  D.ny += numCells;
50  }
51 
52  // allocate memory
53  int beg = 0;
54  if(dir=="x")
55  {
56  D.x.resize(D.nx+1);
57  D.dx.resize(D.nx);
58  D.xD.resize(D.nx+1);
59  D.dxD.resize(D.nx);
60  D.x[beg] = start;
61  }
62  if(dir=="y")
63  {
64  D.y.resize(D.ny+1);
65  D.dy.resize(D.ny);
66  D.yD.resize(D.ny+1);
67  D.dyD.resize(D.ny);
68  D.y[beg] = start;
69  }
70 
71  // second pass
72  for (unsigned int i=0; i<subDomains.size(); i++)
73  {
74  end = subDomains[i]["end"].as<real>();
75  numCells = subDomains[i]["cells"].as<int>();
76  stretchRatio = subDomains[i]["stretchRatio"].as<real>();
77 
78  if(fabs(stretchRatio-1.0) < 1.0e-6)
79  {
80  h = (end - start)/numCells;
81  for(int j=beg; j<beg+numCells; j++)
82  {
83  if(dir=="x")
84  {
85  D.dx[j] = h;
86  D.x[j+1] = D.x[j] + D.dx[j];
87  }
88  else if(dir=="y")
89  {
90  D.dy[j] = h;
91  D.y[j+1] = D.y[j] + D.dy[j];
92  }
93  }
94  }
95  else
96  {
97  h = (end - start)*(stretchRatio-1)/(pow(stretchRatio, numCells)-1);
98  for(int j=beg; j<beg+numCells; j++)
99  {
100  if(dir=="x")
101  {
102  D.dx[j] = h*pow(stretchRatio, j-beg);
103  D.x[j+1] = D.x[j] + D.dx[j];
104  }
105  else if(dir=="y")
106  {
107  D.dy[j] = h*pow(stretchRatio, j-beg);
108  D.y[j+1] = D.y[j] + D.dy[j];
109  }
110  }
111  }
112  beg += numCells;
113  start = end;
114  }
115 
116  if(dir=="x")
117  {
118  D.xD = D.x;
119  D.dxD = D.dx;
120  }
121  else if(dir=="y")
122  {
123  D.yD = D.y;
124  D.dyD = D.dy;
125  }
126 } // parseDomain
127 
128 
135 void parseDomainFile(std::string &domFile, domain &D)
136 {
137  printf("Parsing YAML file with grid info ...\n");
138  YAML::Node nodes = YAML::LoadFile(domFile);
139  for (unsigned int i=0; i<nodes.size(); i++)
140  parseDomain(nodes[i], D);
141 
142  D.xu.resize(D.nx-1);
143  D.yu.resize(D.ny);
144  D.xv.resize(D.nx);
145  D.yv.resize(D.ny-1);
146 
147  int i, j;
148  for(i=0; i<D.nx-1; i++)
149  {
150  D.xu[i] = D.x[i+1];
151  D.xv[i] = (D.x[i]+D.x[i+1])/2.0;
152  }
153  D.xv[i] = (D.x[i]+D.x[i+1])/2.0;
154 
155  for(j=0; j<D.ny-1; j++)
156  {
157  D.yu[j] = (D.y[j]+D.y[j+1])/2.0;
158  D.yv[j] = D.y[j+1];
159  }
160  D.yu[j] = (D.y[j]+D.y[j+1])/2.0;
161 } // parseDomainFile
162 
163 } // End of namespace io
vecH x
x-coordinates of the nodes
Definition: domain.h:22
void parseDomain(const YAML::Node &node, domain &D)
Gets information from the parsed domain file.
vecH dx
cell-widths in the x-direction
Definition: domain.h:22
double real
Is a float or a double depending on the machine precision.
Definition: types.h:116
vecH yv
y-coordinates where the y-components of velocity are evaluated
Definition: domain.h:32
vecH dy
cell-widths in the y-direction
Definition: domain.h:22
vecD xD
x-coordinates of the nodes stored on the device
Definition: domain.h:27
Declaration of the functions of the namespace io.
vecD yD
y-coordinates of the nodes stored on the device
Definition: domain.h:27
vecH yu
y-coordinates where the x-components of velocity are evaluated
Definition: domain.h:32
Contains functions related to I/O tasks.
Stores information about the computational grid.
Definition: domain.h:16
vecH xu
x-coordinates where the x-components of velocity are evaluated
Definition: domain.h:32
vecH xv
x-coordinates where the y-components of velocity are evaluated
Definition: domain.h:32
vecD dxD
x- cell widths stored on the device
Definition: domain.h:27
int ny
number of cells in the y-direction
Definition: domain.h:19
int nx
number of cells in the x-direction
Definition: domain.h:19
void parseDomainFile(std::string &domFile, domain &D)
Parses the domain file and generates the computational grid.
vecD dyD
y- cell widths stored on the device
Definition: domain.h:27
vecH y
y-coordinates of the nodes
Definition: domain.h:22