www.cemf.ir
bTypesFunctions.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
25 #ifndef __bTypesFunctions_hpp__
26 #define __bTypesFunctions_hpp__
27 
28 #include "builtinTypes.hpp"
29 //#include "math.hpp"
30 #include "numericConstants.hpp"
31 #include "pFlowMacros.hpp"
32 
33 namespace pFlow
34 {
35 
37 inline const real zero = 0.0;
38 
40 inline const real one = 1.0;
41 
43 inline const int32 zero32 = 0;
44 
46 inline const int32 one32 = 1;
47 
49 inline const word nullWord;
50 
52 inline const word whiteSpace(" \t\n\v\f\r");
53 
55 int32
56 countChar(const word& s, const char c);
57 
59 int32
60 countChar(const char* s, const char c);
61 
63 word
64 toUpper(const word& inStr);
65 
66 word
67 firstCapital(const word& inStr);
68 
70 bool
71 isYes(const word& str);
72 
74 bool
75 isNo(const word& str);
76 
78 word
79 real2Fixed(const real& v, int32 numPrecision = 6);
80 
82 word
83 real2Word(const real& v, int32 numPrecision = 6);
84 
86 word
87 int322Word(const int32& v);
88 
90 word
91 removeDecimalZeros(const word& str);
92 
94 word
95 real2FixedStripZeros(const real& v, int32 numPrecision = 6);
96 
98 word
99 angleBracketsNames(const word& w1, const word& w2);
100 
102 word
103 angleBracketsNames2(const word& base, const word& w1, const word& w2);
104 
106 word
108  const word& base,
109  const word& w1,
110  const word& w2,
111  const word& w3
112 );
113 
115 word
116 groupNames(const word& bw, const word& tw, char sep = '.');
117 
119 word
120 baseName(const word& w, char sep = '.');
121 
123 word
124 tailName(const word& w, char sep = '.');
125 
127 bool
128 validWord(char c);
129 
131 bool
132 validWordWithQuote(char c);
133 
135 bool
136 validWord(const word& w);
137 
139 bool
140 validWordWithQuote(const word& c);
141 
143 bool
144 readUint32(const word& w, uint32& val);
145 
147 bool
148 readUint32(const char* buf, uint32& val);
149 
151 bool
152 readInt64(const word& w, int64& val);
153 
155 bool
156 readInt64(const char* buf, int64& val);
157 
159 bool
160 readInt32(const word& w, int32& val);
161 
163 bool
164 readInt32(const char* buf, int32& val);
165 
167 bool
168 readInt8(const word& w, int8& val);
169 
171 bool
172 readInt8(const char* buf, int8& val);
173 
175 bool
176 readReal(const word& w, real& val);
177 
179 bool
180 readReal(const char* buf, real& val);
181 
183 bool
184 readBoolian_Str(const word& w, bool& val);
185 
187 bool
188 readBoolian_Str(const char* buf, bool& val);
189 
190 inline bool
191 readValue(const word& w, real& val)
192 {
193  return readReal(w, val);
194 }
195 
196 inline bool
197 readValue(const word& w, uint32& val)
198 {
199  return readUint32(w, val);
200 }
201 
202 inline bool
203 readValue(const word& w, int64& val)
204 {
205  return readInt64(w, val);
206 }
207 
208 inline bool
209 readValue(const word& w, int32& val)
210 {
211  return readInt32(w, val);
212 }
213 
214 inline bool
215 readValue(const word& w, int8& val)
216 {
217  return readInt8(w, val);
218 }
219 
220 inline bool
221 readValue(const word& w, bool& val)
222 {
223  return readBoolian_Str(w, val);
224 }
225 
227 bool
228 equal(const real& s1, const real& s2, real tol = smallValue)
229 {
230  return abs(s1 - s2) <= tol;
231 }
232 
234 bool
235 equal(const int64& s1, const int64& s2)
236 {
237  return s1 == s2;
238 }
239 
241 bool
242 equal(const int32& s1, const int32& s2)
243 {
244  return s1 == s2;
245 }
246 
248 bool
249 equal(const int8& s1, const int8& s2)
250 {
251  return s1 == s2;
252 }
253 
255 bool
256 equal(const uint32& s1, const uint32& s2)
257 {
258  return s1 == s2;
259 }
260 
263 bool
264 equal(const word& s1, const word& s2)
265 {
266  return s1 == s2;
267 }
268 
271 real
272 degree2Radian(const real& theta)
273 {
274  return theta / 180.0 * Pi;
275 }
276 
279 real
280 radian2Degree(const real& phi)
281 {
282  return phi / Pi * 180.0;
283 }
284 
285 } // end of pFlow
286 
287 #endif //__bTypesFunctions_hpp__
pFlow::tailName
word tailName(const word &w, char sep='.')
Find tail name in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:198
pFlow::angleBracketsNames3
word angleBracketsNames3(const word &base, const word &w1, const word &w2, const word &w3)
Output base<w1,sw2,w3>
Definition: bTypesFunctions.cpp:168
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:66
pFlow::readValue
bool readValue(const word &w, real &val)
Definition: bTypesFunctions.hpp:191
pFlow::real2Fixed
word real2Fixed(const real &v, int32 numPrecision=6)
Convert floating point variable to string with fixed number of precisions.
Definition: bTypesFunctions.cpp:85
pFlow::readInt32
bool readInt32(const word &w, int32 &val)
Convert word to int32.
Definition: bTypesFunctions.cpp:300
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::real2FixedStripZeros
word real2FixedStripZeros(const real &v, int32 numPrecision=6)
Convert to fixed point variable and remove zeros.
Definition: bTypesFunctions.cpp:149
pFlow::smallValue
const real smallValue
Definition: numericConstants.hpp:31
pFlow::validWordWithQuote
bool validWordWithQuote(char c)
Is c a valid character including quote?
Definition: bTypesFunctions.cpp:224
pFlow::readUint32
bool readUint32(const word &w, uint32 &val)
Convert word to uint32.
Definition: bTypesFunctions.cpp:258
pFlow::readBoolian_Str
bool readBoolian_Str(const word &w, bool &val)
Convert word to bool.
Definition: bTypesFunctions.cpp:381
pFlow::equal
INLINE_FUNCTION_HD bool equal(const box &b1, const box &b2, real tol=smallValue)
Definition: box.hpp:135
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::readReal
bool readReal(const word &w, real &val)
Convert word to real.
Definition: bTypesFunctions.cpp:343
pFlow::toUpper
word toUpper(const word &inStr)
convert a word to all caps
Definition: bTypesFunctions.cpp:43
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
pFlow::validWord
bool validWord(char c)
Is the character valid for a word name?
Definition: bTypesFunctions.cpp:211
pFlow::nullWord
const word nullWord
null/empty word
Definition: bTypesFunctions.hpp:49
pFlow
Definition: demGeometry.hpp:27
pFlow::readInt64
bool readInt64(const word &w, int64 &val)
Convert word to int64.
Definition: bTypesFunctions.cpp:279
pFlow::baseName
word baseName(const word &w, char sep='.')
Find the base in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:185
pFlow::angleBracketsNames2
word angleBracketsNames2(const word &base, const word &w1, const word &w2)
Output base<w1,w2>
Definition: bTypesFunctions.cpp:162
pFlowMacros.hpp
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::zero32
const int32 zero32
zero int32 variable
Definition: bTypesFunctions.hpp:43
pFlow::one32
const int32 one32
one int32 variable
Definition: bTypesFunctions.hpp:46
pFlow::angleBracketsNames
word angleBracketsNames(const word &w1, const word &w2)
Output <w1,w2>
Definition: bTypesFunctions.cpp:156
pFlow::isNo
bool isNo(const word &str)
Check if str equals "No", "N", "False", or "Off".
Definition: bTypesFunctions.cpp:74
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
pFlow::whiteSpace
const word whiteSpace(" \t\n\v\f\r")
white space
pFlow::removeDecimalZeros
word removeDecimalZeros(const word &str)
Remove zeros from decimal part of a string number.
Definition: bTypesFunctions.cpp:119
pFlow::readInt8
bool readInt8(const word &w, int8 &val)
Convert word to int8.
Definition: bTypesFunctions.cpp:321
pFlow::real2Word
word real2Word(const real &v, int32 numPrecision=6)
Convert floating point variable to string with general format.
Definition: bTypesFunctions.cpp:94
pFlow::zero
const real zero
Zero real variable.
Definition: bTypesFunctions.hpp:37
pFlow::radian2Degree
INLINE_FUNCTION_HD real radian2Degree(const real &phi)
Convert radians to degree.
Definition: bTypesFunctions.hpp:280
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Group words and output bw.tw.
Definition: bTypesFunctions.cpp:179
pFlow::firstCapital
word firstCapital(const word &inStr)
Definition: bTypesFunctions.cpp:51
numericConstants.hpp
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:30
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:48
pFlow::int322Word
word int322Word(const int32 &v)
Convert int32 to word.
Definition: bTypesFunctions.cpp:110
builtinTypes.hpp
pFlow::isYes
bool isYes(const word &str)
Check if str equals "Yes", "Y", "True", "Ok", "ON", or "T".
Definition: bTypesFunctions.cpp:59
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::degree2Radian
INLINE_FUNCTION_HD real degree2Radian(const real &theta)
Convert degree to radians.
Definition: bTypesFunctions.hpp:272
pFlow::countChar
int32 countChar(const word &s, const char c)
Count numer of chars c in a word.
Definition: bTypesFunctions.cpp:28
pFlow::one
const real one
one real variable
Definition: bTypesFunctions.hpp:40