cuIBM
A GPU-based Immersed Boundary Method code
parameterDB.cu
Go to the documentation of this file.
1 
7 #include "parameterDB.h"
8 #include "body.h"
9 #include "boundaryCondition.h"
10 
11 
19 template <typename T>
20 std::string toString(T num)
21 {
22  std::stringstream ss;
23  ss << num;
24  return ss.str();
25 } // toString
26 
27 
35 template <>
36 std::string toString(bcType b)
37 {
38  if (b == DIRICHLET)
39  return "Dirichlet";
40  else if (b == NEUMANN)
41  return "Neumann";
42  else if (b == CONVECTIVE)
43  return "Convective";
44  else
45  {
46  printf("Error: Unknown boundary type!\n");
47  exit(-1);
48  }
49 } // toString
50 
51 
57 template <>
58 std::string property::get()
59 {
60  return std::string(value);
61 } // get
62 
63 
69 template <typename T>
71 {
72  T r = *reinterpret_cast<T*>(&value[0]);
73  return r;
74 } // get
75 
76 
77 // explicit instantiations of the method property::get()
78 // to be able to define the template function outside the header file
79 template double property::get<double>();
80 template float property::get<float>();
81 template int property::get<int>();
82 template bool property::get<bool>();
83 template preconditionerType property::get<preconditionerType>();
84 template timeScheme property::get<timeScheme>();
85 template ibmScheme property::get<ibmScheme>();
86 template interpolationType property::get<interpolationType>();
87 template std::vector<body> *property::get<std::vector<body>*>();
88 template boundaryCondition **property::get<boundaryCondition **>();
89 
90 
96 const char *property::print()
97 {
98  if (*type == typeid(int))
99  return toString(this->get<int>()).c_str();
100  else if (*type == typeid(double))
101  return toString(this->get<double>()).c_str();
102  else if (*type == typeid(float))
103  return toString(this->get<float>()).c_str();
104  else if (*type == typeid(std::string))
105  return (const char *)value;
106  else
107  {
108  printf("Error: Unsupported type!\n");
109  exit(-1);
110  }
111 } // print
112 
113 
119 template <>
120 void property::set(std::string s)
121 {
122  strncpy(value, s.c_str(), 256);
123 } // set
124 
125 
131 template <typename T>
132 void property::set(T v)
133 {
134  // assume we have enough space (256 bytes)
135  type = &typeid(T);
136  *reinterpret_cast<T*>(&value[0]) = v;
137 } // set
138 
139 
140 // explicit instantiations of the method property::set()
141 // to be able to define the template function outside the header file
142 template void property::set(int v);
143 template void property::set(float v);
144 template void property::set(double v);
145 template void property::set(bool v);
146 template void property::set(timeScheme v);
147 template void property::set(ibmScheme v);
148 template void property::set(interpolationType v);
149 template void property::set(preconditionerType v);
150 template void property::set(boundaryCondition **v);
151 template void property::set(std::vector<body> *v);
Definition of the class body.
Definition of the class boundaryCondition.
Dirichlet boundary condition.
Definition: types.h:35
Neumann boundary condition.
Definition: types.h:36
ibmScheme
Specifies the immersed boundary method used to solve the flow.
Definition: types.h:74
timeScheme
Specifies the numerical scheme used for time-integration.
Definition: types.h:60
preconditionerType
Specifies the type of preconditioner.
Definition: types.h:104
void set(T v)
Sets the value of the property given a type.
Definition: parameterDB.cu:132
T get()
Gets the value of the property as a given type.
Definition: parameterDB.cu:70
char value[256]
Definition: parameterDB.h:31
const std::type_info * type
Definition: parameterDB.h:28
const char * print()
Returns a string describing the value of property as appropriate.
Definition: parameterDB.cu:96
Declaration of the class property.
convective boundary condition
Definition: types.h:37
interpolationType
Specifies the type of interpolation.
Definition: types.h:92
bcType
Specifies the type of boundary condition.
Definition: types.h:33
std::string toString(T num)
Converts a number to a string.
Definition: parameterDB.cu:20
Stores the type of boundary condition and its value.