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 -----------------------------------------------------------------------------*/
20 
21 #ifndef __bTypesFunctions_hpp__
22 #define __bTypesFunctions_hpp__
23 
24 #include "pFlowMacros.hpp"
25 #include "numericConstants.hpp"
26 #include "builtinTypes.hpp"
27 #include "math.hpp"
28 
29 
30 // helper functions and constants for basic types
31 namespace pFlow
32 {
33 
34 
35 inline const real zero = 0.0;
36 inline const real one = 1.0;
37 
38 inline const int32 zero32 = 0;
39 inline const int32 one32 = 1;
40 
41 inline const word nullWord;
42 
43 inline const word whiteSpace(" \t\n\v\f\r");
44 
45 
46 int32 countChar (const word& s, const char c);
47 
48 int32 countChar(const char* s, const char c);
49 
50 word toUpper(const word & inStr);
51 
52 bool isYes(const word & str);
53 
54 bool isNo(const word & str);
55 
56 word real2Fixed(const real & v, int32 numPrecision = 6);
57 
58 word real2Word(const real & v, int32 numPrecision = 6);
59 
60 word removeDecimalZeros(const word& str);
61 
62 word real2FixedStripZeros(const real & v, int32 numPrecision = 6);
63 
64 word int322Word(const int32 & v);
65 
66 
67 word angleBracketsNames(const word& w1, const word& w2);
68 
69 
70 word angleBracketsNames2(const word& base, const word& w1, const word& w2);
71 
72 word angleBracketsNames3(const word& base, const word& w1, const word& w2, const word& w3);
73 
74 word groupNames(const word& bw, const word& tw, char sep = '.');
75 
76 word baseName(const word& w, char sep = '.');
77 
78 word tailName(const word& w, char sep = '.');
79 
80 
81 // is the character valid for a word name
82 bool validWord(char c);
83 
84 bool validWordWithQuote(char c);
85 
86 
87 bool validWord(const word& w);
88 
89 bool validWordWithQuote(const word& c);
90 
91 
92 bool readLabel( const word& w, label & val);
93 
94 
95 bool readLabel( const char* buf, label & val);
96 
97 
98 bool readUint32( const word& w, uint32 & val);
99 
100 
101 bool readUint32( const char* buf, uint32 & val);
102 
103 
104 bool readInt64( const word& w, int64 & val);
105 
106 
107 bool readInt64( const char* buf, int64 & val);
108 
109 
110 bool readInt32( const word& w, int32 & val);
111 
112 
113 bool readInt32( const char* buf, int32 & val);
114 
115 
116 bool readInt16( const word& w, int16 & val);
117 
118 
119 bool readInt16( const char* buf, int16 & val);
120 
121 
122 bool readInt8( const word& w, int8 & val);
123 
124 
125 bool readInt8( const char* buf, int8 & val);
126 
127 
128 bool readReal( const word& w, real & val);
129 
130 
131 bool readReal( const char* buf, real & val );
132 
133 
134 bool readBoolian_Str( const word& w, bool & val);
135 
136 
137 bool readBoolian_Str( const char* buf, bool & val);
138 
139 inline
140 bool readValue(const word& w, real& val)
141 {
142  return readReal(w,val);
143 }
144 
145 inline
146 bool readValue(const word& w, label& val)
147 {
148  return readLabel(w,val);
149 }
150 
151 inline
152 bool readValue(const word& w, uint32& val)
153 {
154  return readUint32(w,val);
155 }
156 
157 inline
158 bool readValue(const word& w, int64& val)
159 {
160  return readInt64(w,val);
161 }
162 
163 inline
164 bool readValue(const word& w, int32& val)
165 {
166  return readInt32(w,val);
167 }
168 
169 inline
170 bool readValue(const word& w, int16& val)
171 {
172  return readInt16(w,val);
173 }
174 
175 inline
176 bool readValue(const word& w, int8& val)
177 {
178  return readInt8(w,val);
179 }
180 
181 inline
182 bool readValue(const word& w, bool& val)
183 {
184  return readBoolian_Str(w,val);
185 }
186 
187 
188 INLINE_FUNCTION_HD bool equal(const real& s1, const real& s2)
189 {
190  return abs(s1 - s2) <= smallValue;
191 }
192 
193 INLINE_FUNCTION_HD bool equal(const int64& s1, const int64& s2)
194 {
195  return s1 == s2;
196 }
197 
198 INLINE_FUNCTION_HD bool equal(const int32& s1, const int32& s2)
199 {
200  return s1 == s2;
201 }
202 
203 INLINE_FUNCTION_HD bool equal(const int16& s1, const int16& s2)
204 {
205  return s1 == s2;
206 }
207 
208 INLINE_FUNCTION_HD bool equal(const int8& s1, const int8& s2)
209 {
210  return s1 == s2;
211 }
212 
213 INLINE_FUNCTION_HD bool equal(const uint32& s1, const uint32& s2)
214 {
215  return s1 == s2;
216 }
217 
218 INLINE_FUNCTION_HD bool equal(const label& s1, const label& s2)
219 {
220  return s1 == s2;
221 }
222 
223 // host only
224 INLINE_FUNCTION bool equal(const word& s1, const word& s2)
225 {
226  return s1==s2;
227 }
228 
230 {
231  return theta / 180.0 * Pi;
232 }
233 
235 {
236  return phi / Pi * 180.0;
237 }
238 
239 
240 } // end of pFlow
241 
242 
243 #endif //__bTypesFunctions_hpp__
pFlow::tailName
word tailName(const word &w, char sep='.')
Definition: bTypesFunctions.cpp:168
pFlow::angleBracketsNames3
word angleBracketsNames3(const word &base, const word &w1, const word &w2, const word &w3)
Definition: bTypesFunctions.cpp:146
INLINE_FUNCTION
#define INLINE_FUNCTION
Definition: pFlowMacros.hpp:62
pFlow::readValue
bool readValue(const word &w, real &val)
Definition: bTypesFunctions.hpp:140
pFlow::real2Fixed
word real2Fixed(const real &v, int32 numPrecision=6)
Definition: bTypesFunctions.cpp:44
pFlow::readInt32
bool readInt32(const word &w, int32 &val)
Definition: bTypesFunctions.cpp:280
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::real2FixedStripZeros
word real2FixedStripZeros(const real &v, int32 numPrecision=6)
Definition: bTypesFunctions.cpp:101
pFlow::smallValue
const real smallValue
Definition: numericConstants.hpp:33
pFlow::validWordWithQuote
bool validWordWithQuote(char c)
Definition: bTypesFunctions.cpp:194
pFlow::readUint32
bool readUint32(const word &w, uint32 &val)
Definition: bTypesFunctions.cpp:244
pFlow::readBoolian_Str
bool readBoolian_Str(const word &w, bool &val)
Definition: bTypesFunctions.cpp:372
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::readReal
bool readReal(const word &w, real &val)
Definition: bTypesFunctions.cpp:335
pFlow::toUpper
word toUpper(const word &inStr)
Definition: bTypesFunctions.cpp:107
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::validWord
bool validWord(char c)
Definition: bTypesFunctions.cpp:180
pFlow::readLabel
bool readLabel(const word &w, label &val)
Definition: bTypesFunctions.cpp:226
pFlow::nullWord
const word nullWord
Definition: bTypesFunctions.hpp:41
pFlow
Definition: demComponent.hpp:28
pFlow::readInt64
bool readInt64(const word &w, int64 &val)
Definition: bTypesFunctions.cpp:262
pFlow::readInt16
bool readInt16(const word &w, int16 &val)
Definition: bTypesFunctions.cpp:299
pFlow::baseName
word baseName(const word &w, char sep='.')
Definition: bTypesFunctions.cpp:156
pFlow::angleBracketsNames2
word angleBracketsNames2(const word &base, const word &w1, const word &w2)
Definition: bTypesFunctions.cpp:137
pFlow::int16
short int int16
Definition: builtinTypes.hpp:51
pFlowMacros.hpp
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::zero32
const int32 zero32
Definition: bTypesFunctions.hpp:38
pFlow::one32
const int32 one32
Definition: bTypesFunctions.hpp:39
pFlow::angleBracketsNames
word angleBracketsNames(const word &w1, const word &w2)
Definition: bTypesFunctions.cpp:131
pFlow::abs
INLINE_FUNCTION_HD real abs(real x)
Definition: math.hpp:43
pFlow::isNo
bool isNo(const word &str)
Definition: bTypesFunctions.cpp:122
pFlow::whiteSpace
const word whiteSpace(" \t\n\v\f\r")
pFlow::removeDecimalZeros
word removeDecimalZeros(const word &str)
Definition: bTypesFunctions.cpp:75
pFlow::readInt8
bool readInt8(const word &w, int8 &val)
Definition: bTypesFunctions.cpp:317
pFlow::real2Word
word real2Word(const real &v, int32 numPrecision=6)
Definition: bTypesFunctions.cpp:52
pFlow::zero
const real zero
Definition: bTypesFunctions.hpp:35
pFlow::radian2Degree
INLINE_FUNCTION_HD real radian2Degree(const real &phi)
Definition: bTypesFunctions.hpp:234
pFlow::groupNames
word groupNames(const word &bw, const word &tw, char sep='.')
Definition: bTypesFunctions.cpp:151
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
numericConstants.hpp
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:32
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::int322Word
word int322Word(const int32 &v)
Definition: bTypesFunctions.cpp:67
builtinTypes.hpp
pFlow::isYes
bool isYes(const word &str)
Definition: bTypesFunctions.cpp:114
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
math.hpp
pFlow::degree2Radian
INLINE_FUNCTION_HD real degree2Radian(const real &theta)
Definition: bTypesFunctions.hpp:229
pFlow::countChar
int32 countChar(const word &s, const char c)
Definition: bTypesFunctions.cpp:28
pFlow::equal
INLINE_FUNCTION_HD bool equal(const real &s1, const real &s2)
Definition: bTypesFunctions.hpp:188
pFlow::one
const real one
Definition: bTypesFunctions.hpp:36