www.cemf.ir
VectorI.hpp
Go to the documentation of this file.
1 #include "Vector.hpp"
2 /*------------------------------- phasicFlow ---------------------------------
3  O C enter of
4  O O E ngineering and
5  O O M ultiscale modeling of
6  OOOOOOO F luid flow
7 ------------------------------------------------------------------------------
8  Copyright (C): www.cemf.ir
9  email: hamid.r.norouzi AT gmail.com
10 ------------------------------------------------------------------------------
11 Licence:
12  This file is part of phasicFlow code. It is a free software for simulating
13  granular and multiphase flows. You can redistribute it and/or modify it under
14  the terms of GNU General Public License v3 or any other later versions.
15 
16  phasicFlow is distributed to help others in their research in the field of
17  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
18  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 
20 -----------------------------------------------------------------------------*/
21 
22 template<typename T, typename Allocator>
23 inline void pFlow::Vector<T, Allocator>::fill( const T& val)
24 {
25  std::fill(this->begin(), this->end(), val);
26 }
27 
28 template <typename T, typename Allocator>
29 inline void pFlow::Vector<T, Allocator>::fill(uint32 start, uint32 end, const T &val)
30 {
31 
32  for(uint32 i=start; i<end; i++)
33  {
34  this->at(i) = val;
35  }
36 }
37 #pragma hd_warning_disable
38 template < typename T, typename Allocator> inline void pFlow::Vector < T, Allocator> ::operator+= (const T &val)
39 {
40  for( auto& v:(*this) )
41  {
42  v+= val;
43  }
44 }
45 
46 #pragma hd_warning_disable
47 template<typename T, typename Allocator>
48 inline void pFlow::Vector<T, Allocator>::operator -=( const T& val)
49 {
50  for( auto& v:(*this) )
51  {
52  v -= val;
53  }
54 }
55 
56 #pragma hd_warning_disable
57 template<typename T, typename Allocator>
58 inline void pFlow::Vector<T, Allocator>::operator *=( const T& val)
59 {
60  for( auto& v:(*this) )
61  {
62  v *= val;
63  }
64 }
65 
66 #pragma hd_warning_disable
67 template<typename T, typename Allocator>
68 inline void pFlow::Vector<T, Allocator>::operator /=( const T& val)
69 {
70  for( auto& v:(*this) )
71  {
72  v /= val;
73  }
74 }
75 
76 #pragma hd_warning_disable
77 template<typename T, typename Allocator>
79 {
80 
81  if(size() != v.size() )
82  {
84  "the += operator is invalid, vector size of right side (" << v.size() <<
85  ") is not equal to the left side (" << size() << ").\n";
86  fatalExit;
87  }
88 
89  for(size_t i=0; i<v.size(); i++)
90  {
91  this->operator[](i) += v[i];
92  }
93 }
94 
95 #pragma hd_warning_disable
96 template<typename T, typename Allocator>
98 {
99 
100  if(size() != v.size() )
101  {
103  "the -= operator is invalid, vector size of right side (" << v.size() <<
104  ") is not equal to the left side (" << size() << ").\n";
105  fatalExit;
106  }
107 
108  for(size_t i=0; i<v.size(); i++)
109  {
110  this->operator[](i) -= v[i];
111  }
112 }
113 
114 #pragma hd_warning_disable
115 template<typename T, typename Allocator>
117 {
118 
119  if(size() != v.size() )
120  {
122  "the * operator is invalid, vector size of right side (" << v.size() <<
123  ") is not equal to the left side (" << size() << ").\n";
124  fatalExit;
125  }
126 
127  for(size_t i=0; i<v.size(); i++)
128  {
129  this->operator[](i) *= v[i];
130  }
131 }
132 
133 #pragma hd_warning_disable
134 template<typename T, typename Allocator>
136 {
137 
138  if(size() != v.size() )
139  {
141  "the /= operator is invalid, vector size of right side (" << v.size() <<
142  ") is not equal to the left side (" << size() << ").\n";
143  fatalExit;
144  }
145 
146  for(size_t i=0; i<v.size(); i++)
147  {
148  this->operator[](i) /= v[i];
149  }
150 }
151 
152 #pragma hd_warning_disable
153 template<typename T, typename Allocator>
155 (
156 )const
157 {
158  Vector<T, Allocator> res(*this);
159  for( auto& vi:res)
160  {
161  vi = -vi;
162  }
163  return res;
164 }
165 
166 #pragma hd_warning_disable
167 template<typename T, typename Allocator>
169 {
170  Vector<T, Allocator> res(op1);
171  res += op2;
172  return res;
173 }
174 
175 #pragma hd_warning_disable
176 template<typename T, typename Allocator>
177 inline pFlow::Vector<T, Allocator> pFlow::operator+ (const T& op1, const Vector<T, Allocator>& op2 )
178 {
179  Vector<T, Allocator> res(op2);
180  res += op1;
181 
182  return res;
183 
184 }
185 
186 #pragma hd_warning_disable
187 template<typename T, typename Allocator>
188 inline pFlow::Vector<T, Allocator> pFlow::operator+ (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
189 {
190  if( op1.size() != op2.size() )
191  {
193  "the + operator is invalid, vector size of operand1 (" << op1.size() <<
194  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
195  fatalExit;
196  }
197 
198  Vector<T, Allocator> res(op1);
199  res += op2;
200  return res;
201 }
202 
203 
204 #pragma hd_warning_disable
205 template<typename T, typename Allocator>
206 inline pFlow::Vector<T, Allocator> pFlow::operator - (const Vector<T, Allocator>& op1, const T& op2 )
207 {
208  Vector<T, Allocator> res(op1);
209  res -= op2;
210  return res;
211 }
212 
213 #pragma hd_warning_disable
214 template<typename T, typename Allocator>
215 inline pFlow::Vector<T, Allocator> pFlow::operator - (const T& op1, const Vector<T, Allocator>& op2 )
216 {
217  Vector<T, Allocator> res(op2.size(), op1);
218  res -= op2;
219  return res;
220 
221 }
222 
223 #pragma hd_warning_disable
224 template<typename T, typename Allocator>
225 inline pFlow::Vector<T, Allocator> pFlow::operator - (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
226 {
227  if( op1.size() != op2.size() )
228  {
230  "the - operator is invalid, vector size of operand1 (" << op1.size() <<
231  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
232  fatalExit;
233  }
234 
235  Vector<T, Allocator> res(op1);
236  res -= op2;
237  return res;
238 }
239 
240 #pragma hd_warning_disable
241 template<typename T, typename Allocator>
242 inline pFlow::Vector<T, Allocator> pFlow::operator* (const Vector<T, Allocator>& op1, const T& op2 )
243 {
244  Vector<T, Allocator> res(op1);
245  res *= op2;
246  return res;
247 }
248 
249 #pragma hd_warning_disable
250 template<typename T, typename Allocator>
251 inline pFlow::Vector<T, Allocator> pFlow::operator* (const T& op1, const Vector<T, Allocator>& op2 )
252 {
253  Vector<T, Allocator> res(op2);
254  res *= op1;
255 
256  return res;
257 
258 }
259 
260 #pragma hd_warning_disable
261 template<typename T, typename Allocator>
262 inline pFlow::Vector<T, Allocator> pFlow::operator* (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
263 {
264  if( op1.size() != op2.size() )
265  {
267  "the * operator is invalid, vector size of operand1 (" << op1.size() <<
268  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
269  fatalExit;
270  }
271 
272  Vector<T, Allocator> res(op1);
273  res *= op2;
274  return res;
275 }
276 
277 #pragma hd_warning_disable
278 template<typename T, typename Allocator>
279 inline pFlow::Vector<T, Allocator> pFlow::operator / (const Vector<T, Allocator>& op1, const T& op2 )
280 {
281  Vector<T, Allocator> res(op1);
282  res /= op2;
283  return res;
284 }
285 
286 #pragma hd_warning_disable
287 template<typename T, typename Allocator>
288 inline pFlow::Vector<T, Allocator> pFlow::operator / (const T& op1, const Vector<T, Allocator>& op2 )
289 {
290  Vector<T, Allocator> res(op2.size(), op1);
291  res /= op2;
292  return res;
293 
294 }
295 
296 #pragma hd_warning_disable
297 template<typename T, typename Allocator>
298 inline pFlow::Vector<T, Allocator> pFlow::operator / (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
299 {
300  if( op1.size() != op2.size() )
301  {
303  "the / operator is invalid, vector size of operand1 (" << op1.size() <<
304  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
305  fatalExit;
306  }
307 
308  Vector<T, Allocator> res(op1);
309  res /= op2;
310  return res;
311 }
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::Vector::operator*=
void operator*=(const T &val)
Definition: VectorI.hpp:58
pFlow::Vector::operator/=
void operator/=(const T &val)
Definition: VectorI.hpp:68
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::operator/
fileSystem operator/(const fileSystem &fs1, const fileSystem &fs2)
Definition: fileSystem.cpp:280
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::operator-
array2D< T, nRow, nCol > operator-(const array2D< T, nRow, nCol > &arr1, const array2D< T, nRow, nCol > &arr2)
Definition: array2D.hpp:60
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::Vector::operator+=
void operator+=(const T &val)
Definition: VectorI.hpp:38
fill
void fill(Vector< T, Allocator > &vec, const T &val)
pFlow::Vector::operator-=
void operator-=(const T &val)
Definition: VectorI.hpp:48
pFlow::operator*
array2D< T, nRow, nCol > operator*(const array2D< T, nRow, nCol > &arr1, const array2D< T, nRow, nCol > &arr2)
Definition: array2D.hpp:73
pFlow::Vector::fill
void fill(const T &val)
Definition: VectorI.hpp:23
pFlow::Vector
Definition: Vector.hpp:48
Vector.hpp
pFlow::operator+
message operator+(message::EVENT evnt1, message::EVENT evnt2)
Definition: message.hpp:216