cuIBM
A GPU-based Immersed Boundary Method code
parseBodiesFile.cu
Go to the documentation of this file.
1 
7 #include <fstream>
8 #include <vector>
9 
10 #include "io.h"
11 #include "utilities/body.h"
12 #include "yaml-cpp/yaml.h"
13 
14 
19 namespace io
20 {
21 
29 void parseBodiesNode(const YAML::Node &node, body &Body, parameterDB &DB)
30 {
31  for (int i=0; i<2; i++)
32  Body.X0[i] = node["centerRotation"][i].as<real>(0.0);
33  // initial configuration
34  for (int i=0; i<2; i++)
35  {
36  Body.Xc0[i] = node["initialOffset"][i].as<real>(0.0);
37  Body.Xc[i] = Body.Xc0[i];
38  }
39  // initial angle of attack
40  Body.Theta0 = node["angleOfAttack"].as<real>(0.0) * M_PI / 180.0;
41  Body.Theta = Body.Theta0;
42  // moving flags
43  for (int i=0; i<2; i++)
44  Body.moving[i] = node["moving"][i].as<bool>(false);
45  // velocity
46  for (int i=0; i<2; i++)
47  Body.velocity[i] = node["velocity"][i].as<real>(0.0);
48  // omega
49  Body.omega = node["omega"].as<real>(0.0);
50  // oscillation in X
51  for (int i=0; i<3; i++)
52  Body.xOscillation[i] = node["xOscillation"][i].as<real>(0.0);
53  Body.xOscillation[1] *= 2 * M_PI;
54  // oscillation in Y
55  for (int i=0; i<3; i++)
56  Body.yOscillation[i] = node["yOscillation"][i].as<real>(0.0);
57  Body.yOscillation[1] *= 2 * M_PI;
58  // pitch oscillation
59  for (int i=0; i<3; i++)
60  Body.pitchOscillation[i] = node["pitchOscillation"][i].as<real>(0.0);
61  Body.pitchOscillation[0] *= M_PI / 180.0;
62  Body.pitchOscillation[1] *= 2 * M_PI;
63 
64  // get the type of body and read in appropriate details
65  std::string type = node["type"].as<std::string>();
66  if (type == "points")
67  {
68  std::string fileName = node["pointsFile"].as<std::string>();
69  std::string folderPath = DB["inputs"]["caseFolder"].get<std::string>();
70  std::ifstream inFile((folderPath + "/" + fileName).c_str());
71  inFile >> Body.numPoints;
72  Body.X.resize(Body.numPoints);
73  Body.Y.resize(Body.numPoints);
74  for (int i=0; i<Body.numPoints; i++)
75  inFile >> Body.X[i] >> Body.Y[i];
76  inFile.close();
77  }
78  else if (type == "lineSegment")
79  {
80  real startX = node["segmentOptions"][0].as<real>();
81  real endX = node["segmentOptions"][1].as<real>();
82  real startY = node["segmentOptions"][2].as<real>();
83  real endY = node["segmentOptions"][3].as<real>();
84  int numPoints = node["segmentOptions"][4].as<int>();
85  Body.numPoints = numPoints;
86  // initialize line segment
87  }
88  else if (type == "circle")
89  {
90  real cx = node["circleOptions"][0].as<real>();
91  real cy = node["circleOptions"][1].as<real>();
92  real R = node["circleOptions"][2].as<real>();
93  int numPoints = node["circleOptions"][3].as<int>();
94  Body.numPoints = numPoints;
95  // initialize circle
96  Body.X.resize(numPoints);
97  Body.Y.resize(numPoints);
98  for (int i=0; i<Body.numPoints; i++)
99  {
100  Body.X[i] = cx + R*cos(i*2*M_PI/Body.numPoints);
101  Body.Y[i] = cy + R*sin(i*2*M_PI/Body.numPoints);
102  }
103  }
104  else
105  {
106  printf("Error: Unknown body type '%s'!\n", type.c_str());
107  exit(-1);
108  }
109 } // parseBodiesNode
110 
111 
117 void parseBodiesFile(std::string &bodiesFile, parameterDB &DB)
118 {
119  if (!std::ifstream(bodiesFile.c_str()))
120  {
121  if (DB["simulation"]["ibmScheme"].get<ibmScheme>() != NAVIER_STOKES)
122  {
123  printf("Error: Missing YAML file bodies.yaml!\n");
124  exit(-1);
125  }
126  return;
127  }
128  printf("Parsing YAML file with bodies info ...\n");
129  YAML::Node nodes = YAML::LoadFile(bodiesFile);
130  body Body;
131  std::vector<body> *B = DB["flow"]["bodies"].get<std::vector<body> *>();
132  for (int i=0; i<nodes.size(); i++)
133  {
134  Body.reset();
135  parseBodiesNode(nodes[i], Body, DB);
136  B->push_back(Body);
137  }
138 } // parseBodiesFile
139 
140 } // End of namespace io
real xOscillation[3]
amplitude, angular frequency and phase difference of oscillation in the x-direction ...
Definition: body.h:46
Definition of the class body.
double real
Is a float or a double depending on the machine precision.
Definition: types.h:116
real pitchOscillation[3]
amplitude, angular frequency and phase difference of pitch oscillation
Definition: body.h:46
vecH Y
reference y-coordinate of boundary points
Definition: body.h:28
Contains information about an immersed boundary in the flow.
Definition: body.h:23
Declaration of the functions of the namespace io.
std::map< std::string, componentParameter > parameterDB
Map from a string to a componentParameter.
Definition: parameterDB.h:64
Contains functions related to I/O tasks.
vecH X
reference x-coordinate of boundary points
Definition: body.h:28
no immersed bodies - Perot (1993)
Definition: types.h:76
real X0[2]
reference center of rotation
Definition: body.h:31
real Theta0
initial angle of attack
Definition: body.h:33
real Xc[2]
actual center of rotation (x- and y-coordinates)
Definition: body.h:36
real Theta
actual angle of attack (counterclockwise is positive)
Definition: body.h:36
real omega
uniform rotational velocity
Definition: body.h:43
real velocity[2]
uniform translational velocity (x- and y-components)
Definition: body.h:43
void parseBodiesFile(std::string &bodiesFile, parameterDB &DB)
Parses the bodies.yaml file and stores information about the immersed bodies.
bool moving[2]
flag to indicate if the body is moving (translating or rotating)
Definition: body.h:41
int numPoints
number of boundary points
Definition: body.h:26
real Xc0[2]
initial position of center of rotation
Definition: body.h:33
void parseBodiesNode(const YAML::Node &node, body &Body, parameterDB &DB)
Overloads the operator >>. Stores information about an immersed body.
void reset()
Resets the position and motion of the body.
Definition: body.h:84
real yOscillation[3]
amplitude, angular frequency and phase difference of oscillation in the y-direction ...
Definition: body.h:46