cuIBM
A GPU-based Immersed Boundary Method code
parseFlowFile.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 
29 {
30  if (s == "xMinus")
31  return XMINUS;
32  else if (s == "xPlus")
33  return XPLUS;
34  else if (s == "yMinus")
35  return YMINUS;
36  else if (s == "yPlus")
37  return YPLUS;
38  else
39  {
40  printf("Error: Unknown location '%s'!\n", s.c_str());
41  exit(-1);
42  }
43 } // boundaryFromString
44 
45 
53 bcType bcTypeFromString(std::string s)
54 {
55  if (s == "DIRICHLET")
56  return DIRICHLET;
57  else if (s == "NEUMANN")
58  return NEUMANN;
59  else if (s == "CONVECTIVE")
60  return CONVECTIVE;
61  else if (s == "PERIODIC")
62  return PERIODIC;
63  else if (s == "SPECIAL")
64  return SPECIAL;
65  else
66  {
67  printf("Error: Unknown boundary type '%s'!\n", s.c_str());
68  exit(-1);
69  }
70 } // bcTypeFromString
71 
72 
79 void parseFlow(const YAML::Node &node, parameterDB &DB)
80 {
81  std::string dbKey = "flow";
82  DB[dbKey]["nu"].set<real>(node["nu"].as<real>(0.01));
83  DB[dbKey]["uInitial"].set<real>(node["initialVelocity"][0].as<real>(1.0));
84  DB[dbKey]["vInitial"].set<real>(node["initialVelocity"][1].as<real>(0.0));
85  DB[dbKey]["uPerturb"].set<real>(node["initialPerturbation"][0].as<real>(0.0));
86  DB[dbKey]["vPerturb"].set<real>(node["initialPerturbation"][1].as<real>(0.0));
87 
88  boundaryCondition **bc = 0;
89  bc = DB[dbKey]["boundaryConditions"].get<boundaryCondition **>();
90  if (!bc)
91  {
92  printf("Error: BoundaryConditions pointer not initialized.\n");
93  exit(-1);
94  }
95  const YAML::Node &BCs = node["boundaryConditions"];
96  for (unsigned int i=0; i<BCs.size(); i++)
97  {
98  boundary loc = boundaryFromString(BCs[i]["location"].as<std::string>());
99  bc[loc][0] = boundaryCondition(
100  bcTypeFromString(BCs[i]["u"][0].as<std::string>()), BCs[i]["u"][1].as<real>());
101  bc[loc][1] = boundaryCondition(
102  bcTypeFromString(BCs[i]["v"][0].as<std::string>()), BCs[i]["v"][1].as<real>());
103  }
104 } // parseFlow
105 
106 
113 void parseFlowFile(std::string &flowFile, parameterDB &DB)
114 {
115  printf("Parsing YAML file with flow conditions ...\n");
116  YAML::Node nodes = YAML::LoadFile(flowFile);
117  for (unsigned int i=0; i<nodes.size(); i++)
118  parseFlow(nodes[i], DB);
119 } // parseFlowFile
120 
121 } // End of namespace io
void parseFlowFile(std::string &flowFile, parameterDB &DB)
Parses the flow file and stores the parameters in the database.
double real
Is a float or a double depending on the machine precision.
Definition: types.h:116
Dirichlet boundary condition.
Definition: types.h:35
right boundary
Definition: types.h:50
boundary boundaryFromString(std::string s)
Converts a string to a boundary location type.
Neumann boundary condition.
Definition: types.h:36
bottom boundary
Definition: types.h:51
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.
left boundary
Definition: types.h:49
convective boundary condition
Definition: types.h:37
bcType bcTypeFromString(std::string s)
Converts string to a boundary condition type.
periodic boundary condition
Definition: types.h:38
top boundary
Definition: types.h:52
bcType
Specifies the type of boundary condition.
Definition: types.h:33
boundary
Specifies the location of the boundary.
Definition: types.h:47
Definition: types.h:39
void parseFlow(const YAML::Node &node, parameterDB &DB)
Fills the database with the flow parameters.
Stores the type of boundary condition and its value.