www.cemf.ir
Vector.cpp
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
22
/*template<typename T, typename Allocator>
23
bool pFlow::Vector<T, Allocator>::readVector
24
(
25
iIstream& is,
26
const IOPattern& iop
27
)
28
{
29
return readStdVector(is, vectorField(), iop);
30
}
31
32
33
template<typename T, typename Allocator>
34
bool pFlow::Vector<T, Allocator>::writeVector
35
(
36
iOstream& os,
37
const IOPattern& iop
38
) const
39
{
40
return writeStdVector(os, vectorField(), iop);
41
}*/
42
43
/*template<typename T, typename Allocator>
44
bool pFlow::Vector<T, Allocator>::deleteElement_sorted
45
(
46
const Vector<label>& indices
47
)
48
{
49
if( indices.size() == 0 )return true;
50
51
if( indices.size() == 1 )
52
{
53
return deleteElement(indices[0]);
54
}
55
56
if( *(indices.end()-1) >= size() ) return false;
57
58
59
VectorType tmp(capacity(), RESERVE());
60
tmp.clear();
61
62
label lindex = 0;
63
for(auto& delem: indices)
64
{
65
for(label i=lindex; i<delem; i++)
66
{
67
tmp.push_back( vectorType::operator[](i) );
68
}
69
lindex = delem+1;
70
}
71
72
// copy after the last delete element
73
for(label i=lindex; i<size(); i++)
74
{
75
tmp.push_back( vectorType::operator[](i) );
76
}
77
78
79
vectorType::swap(tmp);
80
81
return true;
82
}
83
84
85
template<typename T, typename Allocator>
86
bool pFlow::Vector<T, Allocator>::deleteElement
87
(
88
const Vector<label>& indices
89
)
90
{
91
if( indices.size() == 0 )return true;
92
93
if( indices.size() == 1)
94
{
95
return deleteElement(indices[0]);
96
}
97
98
// sorts
99
auto sorted = indices;
100
sort(sorted);
101
return deleteElement_sorted(sorted);
102
}
103
104
template<typename T, typename Allocator>
105
bool pFlow::Vector<T, Allocator>::deleteElement
106
(
107
label index
108
)
109
{
110
if(index < size())
111
{
112
auto iter = vectorType::begin();
113
advance(iter, index);
114
vectorType::erase(iter);
115
return true;
116
}
117
else
118
return false;
119
}
120
121
template<typename T, typename Allocator>
122
void pFlow::Vector<T, Allocator>::sortItems(
123
const int32IndexContainer& indices)
124
{
125
if(indices.size() == 0)
126
{
127
this->resize(0);
128
return;
129
}
130
size_t newSize = indices.size();
131
auto hIndices = indices.hostView();
132
VectorType sortedVec(name(), capacity(), newSize, RESERVE());
133
134
ForAll(i, hIndices)
135
{
136
sortedVec[i] = vectorType::operator[](i);
137
}
138
*this = std::move(sortedVec);
139
}
140
141
template<typename T, typename Allocator>
142
bool pFlow::Vector<T, Allocator>::insertSetElement(
143
const int32IndexContainer& indices,
144
const T& val)
145
{
146
147
if(indices.size() == 0)return true;
148
149
auto hIndices = indices.hostView();
150
151
ForAll(i, indices)
152
{
153
auto s = size();
154
auto idx = hIndices[i];
155
156
if( idx < s )
157
{
158
this->operator[](idx) = val;
159
}
160
else if(idx == s )
161
{
162
this->push_back(val);
163
}
164
else
165
{
166
this->resize(idx+1);
167
this->operator[](idx) = val;
168
}
169
}
170
return true;
171
}
172
173
template<typename T, typename Allocator>
174
bool pFlow::Vector<T, Allocator>::insertSetElement(
175
const int32IndexContainer& indices,
176
const Vector<T>& vals)
177
{
178
if(indices.size() == 0)return true;
179
if(indices.size() != vals.size())return false;
180
181
auto hIndices = indices.hostView();
182
183
ForAll(i, indices)
184
{
185
auto s = size();
186
auto idx = hIndices[i];
187
if( idx < s )
188
{
189
this->operator[](idx) = vals[i];
190
}
191
else if(idx == s )
192
{
193
this->push_back(vals[i]);
194
}
195
else
196
{
197
this->resize(idx+1);
198
this->operator[](idx) = vals[i];
199
}
200
}
201
return true;
202
203
}
204
205
template<typename T, typename Allocator>
206
bool pFlow::Vector<T, Allocator>::insertSetElement
207
(
208
const Vector<int32>& indices,
209
const T& val
210
)
211
{
212
if(indices.size() == 0)return true;
213
214
ForAll(i, indices)
215
{
216
auto s = size();
217
auto idx = indices[i];
218
if( idx < s )
219
{
220
this->operator[](idx) = val;
221
}
222
else if(idx == s )
223
{
224
this->push_back(val);
225
}
226
else
227
{
228
this->resize(idx+1);
229
this->operator[](idx) = val;
230
}
231
}
232
return true;
233
}
234
235
236
template<typename T, typename Allocator>
237
bool pFlow::Vector<T, Allocator>::insertSetElement
238
(
239
const Vector<int32>& indices,
240
const Vector<T>& vals
241
)
242
{
243
if(indices.size() == 0)return true;
244
if(indices.size() != vals.size())return false;
245
246
ForAll(i, indices)
247
{
248
auto s = size();
249
auto idx = indices[i];
250
if( idx < s )
251
{
252
this->operator[](idx) = vals[i];
253
}
254
else if(idx == s )
255
{
256
this->push_back(vals[i]);
257
}
258
else
259
{
260
this->resize(idx+1);
261
this->operator[](idx) = vals[i];
262
}
263
}
264
return true;
265
}
266
267
template<typename T, typename Allocator>
268
inline bool pFlow::Vector<T, Allocator>::insertSetElement
269
(
270
int32 idx,
271
const T & val
272
)
273
{
274
275
auto s = size();
276
277
if( idx < s )
278
{
279
this->operator[](idx) = val;
280
}
281
else if(idx == s)
282
{
283
this->push_back(val);
284
}
285
else
286
{
287
this->resize(idx+1);
288
this->operator[](idx) = val;
289
}
290
291
return true;
292
}*/
src
phasicFlow
containers
Vector
Vector.cpp
Generated by
1.8.17