VectorI.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 template<typename T, typename Allocator>
22 inline void pFlow::Vector<T, Allocator>::fill( const T& val)
23 {
24  std::fill(this->begin(), this->end(), val);
25 }
26 
27 #pragma hd_warning_disable
28 template<typename T, typename Allocator>
29 inline void pFlow::Vector<T, Allocator>::operator +=( const T& val)
30 {
31  for( auto& v:(*this) )
32  {
33  v+= val;
34  }
35 }
36 
37 #pragma hd_warning_disable
38 template<typename T, typename Allocator>
39 inline void pFlow::Vector<T, Allocator>::operator -=( const T& val)
40 {
41  for( auto& v:(*this) )
42  {
43  v -= val;
44  }
45 }
46 
47 #pragma hd_warning_disable
48 template<typename T, typename Allocator>
49 inline void pFlow::Vector<T, Allocator>::operator *=( const T& val)
50 {
51  for( auto& v:(*this) )
52  {
53  v *= val;
54  }
55 }
56 
57 #pragma hd_warning_disable
58 template<typename T, typename Allocator>
59 inline void pFlow::Vector<T, Allocator>::operator /=( const T& val)
60 {
61  for( auto& v:(*this) )
62  {
63  v /= val;
64  }
65 }
66 
67 #pragma hd_warning_disable
68 template<typename T, typename Allocator>
70 {
71 
72  if(size() != v.size() )
73  {
75  "the += operator is invalid, vector size of right side (" << v.size() <<
76  ") is not equal to the left side (" << size() << ").\n";
77  fatalExit;
78  }
79 
80  for(label i=0; i<v.size(); i++)
81  {
82  this->operator[](i) += v[i];
83  }
84 }
85 
86 #pragma hd_warning_disable
87 template<typename T, typename Allocator>
89 {
90 
91  if(size() != v.size() )
92  {
94  "the -= operator is invalid, vector size of right side (" << v.size() <<
95  ") is not equal to the left side (" << size() << ").\n";
96  fatalExit;
97  }
98 
99  for(label i=0; i<v.size(); i++)
100  {
101  this->operator[](i) -= v[i];
102  }
103 }
104 
105 #pragma hd_warning_disable
106 template<typename T, typename Allocator>
108 {
109 
110  if(size() != v.size() )
111  {
113  "the * operator is invalid, vector size of right side (" << v.size() <<
114  ") is not equal to the left side (" << size() << ").\n";
115  fatalExit;
116  }
117 
118  for(label i=0; i<v.size(); i++)
119  {
120  this->operator[](i) *= v[i];
121  }
122 }
123 
124 #pragma hd_warning_disable
125 template<typename T, typename Allocator>
127 {
128 
129  if(size() != v.size() )
130  {
132  "the /= operator is invalid, vector size of right side (" << v.size() <<
133  ") is not equal to the left side (" << size() << ").\n";
134  fatalExit;
135  }
136 
137  for(label i=0; i<v.size(); i++)
138  {
139  this->operator[](i) /= v[i];
140  }
141 }
142 
143 #pragma hd_warning_disable
144 template<typename T, typename Allocator>
146 (
147 )const
148 {
149  Vector<T, Allocator> res(*this);
150  for( auto& vi:res)
151  {
152  vi = -vi;
153  }
154  return res;
155 }
156 
157 #pragma hd_warning_disable
158 template<typename T, typename Allocator>
160 {
161  Vector<T, Allocator> res(op1);
162  res += op2;
163  return res;
164 }
165 
166 #pragma hd_warning_disable
167 template<typename T, typename Allocator>
168 inline pFlow::Vector<T, Allocator> pFlow::operator+ (const T& op1, const Vector<T, Allocator>& op2 )
169 {
170  Vector<T, Allocator> res(op2);
171  res += op1;
172 
173  return res;
174 
175 }
176 
177 #pragma hd_warning_disable
178 template<typename T, typename Allocator>
179 inline pFlow::Vector<T, Allocator> pFlow::operator+ (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
180 {
181  if( op1.size() != op2.size() )
182  {
184  "the + operator is invalid, vector size of operand1 (" << op1.size() <<
185  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
186  fatalExit;
187  }
188 
189  Vector<T, Allocator> res(op1);
190  res += op2;
191  return res;
192 }
193 
194 
195 #pragma hd_warning_disable
196 template<typename T, typename Allocator>
197 inline pFlow::Vector<T, Allocator> pFlow::operator - (const Vector<T, Allocator>& op1, const T& op2 )
198 {
199  Vector<T, Allocator> res(op1);
200  res -= op2;
201  return res;
202 }
203 
204 #pragma hd_warning_disable
205 template<typename T, typename Allocator>
206 inline pFlow::Vector<T, Allocator> pFlow::operator - (const T& op1, const Vector<T, Allocator>& op2 )
207 {
208  Vector<T, Allocator> res(op2.size(), op1);
209  res -= op2;
210  return res;
211 
212 }
213 
214 #pragma hd_warning_disable
215 template<typename T, typename Allocator>
216 inline pFlow::Vector<T, Allocator> pFlow::operator - (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
217 {
218  if( op1.size() != op2.size() )
219  {
221  "the - operator is invalid, vector size of operand1 (" << op1.size() <<
222  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
223  fatalExit;
224  }
225 
226  Vector<T, Allocator> res(op1);
227  res -= op2;
228  return res;
229 }
230 
231 #pragma hd_warning_disable
232 template<typename T, typename Allocator>
233 inline pFlow::Vector<T, Allocator> pFlow::operator* (const Vector<T, Allocator>& op1, const T& op2 )
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 T& op1, const Vector<T, Allocator>& op2 )
243 {
244  Vector<T, Allocator> res(op2);
245  res *= op1;
246 
247  return res;
248 
249 }
250 
251 #pragma hd_warning_disable
252 template<typename T, typename Allocator>
253 inline pFlow::Vector<T, Allocator> pFlow::operator* (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
254 {
255  if( op1.size() != op2.size() )
256  {
258  "the * operator is invalid, vector size of operand1 (" << op1.size() <<
259  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
260  fatalExit;
261  }
262 
263  Vector<T, Allocator> res(op1);
264  res *= op2;
265  return res;
266 }
267 
268 #pragma hd_warning_disable
269 template<typename T, typename Allocator>
270 inline pFlow::Vector<T, Allocator> pFlow::operator / (const Vector<T, Allocator>& op1, const T& op2 )
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 T& op1, const Vector<T, Allocator>& op2 )
280 {
281  Vector<T, Allocator> res(op2.size(), op1);
282  res /= op2;
283  return res;
284 
285 }
286 
287 #pragma hd_warning_disable
288 template<typename T, typename Allocator>
289 inline pFlow::Vector<T, Allocator> pFlow::operator / (const Vector<T, Allocator>& op1, const Vector<T, Allocator>& op2 )
290 {
291  if( op1.size() != op2.size() )
292  {
294  "the / operator is invalid, vector size of operand1 (" << op1.size() <<
295  ") is not equal to vector size of operand2 (" << op1.size() << ").\n";
296  fatalExit;
297  }
298 
299  Vector<T, Allocator> res(op1);
300  res /= op2;
301  return res;
302 }
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::Vector::operator*=
void operator*=(const T &val)
Definition: VectorI.hpp:49
pFlow::Vector::operator/=
void operator/=(const T &val)
Definition: VectorI.hpp:59
pFlow::operator/
fileSystem operator/(const fileSystem &fs1, const fileSystem &fs2)
Definition: fileSystem.cpp:265
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
operator*
Vector< T, Allocator > operator*(const Vector< T, Allocator > &op1, const T &op2)
pFlow::Vector::operator+=
void operator+=(const T &val)
Definition: VectorI.hpp:29
fill
void fill(Vector< T, Allocator > &vec, const T &val)
pFlow::Vector::operator-=
void operator-=(const T &val)
Definition: VectorI.hpp:39
pFlow::operator+
fileSystem operator+(const fileSystem &fs1, const word fName)
Definition: fileSystem.cpp:277
pFlow::Vector::fill
void fill(const T &val)
Definition: VectorI.hpp:22
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::Vector
Definition: Vector.hpp:46
operator-
Vector< T, Allocator > operator-(const Vector< T, Allocator > &op1, const T &op2)