/[escript]/branches/complex/escriptcore/src/DataVector.h
ViewVC logotype

Contents of /branches/complex/escriptcore/src/DataVector.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5868 - (show annotations)
Wed Jan 13 07:23:44 2016 UTC (3 years, 4 months ago) by jfenwick
File MIME type: text/plain
File size: 11553 byte(s)
Adding an alternate DataVector which does not use Taipan
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17
18 #if !defined escript_DataVectorTaipan_20050324_H
19 #define escript_DataVectorTaipan_20050324_H
20 #include "system_dep.h"
21
22 #include "esysUtils/EsysAssert.h"
23
24 #include <vector>
25 #include <iostream>
26 #include <fstream>
27
28 namespace escript {
29
30 class WrappedArray;
31
32 /**
33 \brief
34 DataVectorTaipan implements an arbitrarily long vector of data values.
35 DataVectorTaipan is the underlying data container for Data objects.
36
37 Description:
38 DataVectorTaipan provides an implementation of a vector of data values for use
39 by DataBlocks2D and DataArrayView. Hiding the vector in this container
40 allows different implementations to be swapped in without disrupting the
41 client classes.
42 */
43
44 class ESCRIPT_DLL_API DataVectorTaipan {
45
46 public:
47
48 //
49 // The type of the elements stored in the vector.
50 typedef double ElementType;
51
52 //
53 // The underlying type used to implement the vector.
54 typedef ElementType * VectorStorageType;
55 typedef const ElementType * ConstValueType;
56
57 //
58 // Various types exported to clients of this class.
59 typedef ElementType value_type;
60 typedef long size_type;
61 typedef ElementType & reference;
62 typedef const ElementType & const_reference;
63
64 /**
65 \brief
66 Default constructor for DataVectorTaipan.
67
68 Description:
69 Constructs an empty DataVectorTaipan object.
70 */
71 DataVectorTaipan();
72
73 /**
74 \brief
75 Copy constructor for DataVectorTaipan.
76
77 Description:
78 Constructs a DataVectorTaipan object which is a copy of the
79 given DataVectorTaipan object.
80 */
81 DataVectorTaipan(const DataVectorTaipan& other);
82
83 /**
84 \brief
85 Constructor for DataVectorTaipan.
86
87 Description:
88 Constructs a DataVectorTaipan object of length "size" with all elements
89 initilised to "val".
90
91 \param size - Input - Number of elements in the vector.
92 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
93 \param blockSize - Input - size of blocks within the vector, overall vector
94 size must be a precise multiple of the block size. Default is 1.
95
96 In escript::Data, blocksize corresponds to the number of elements required to hold all
97 the data-points for a sample, ie: the product of the dimensions of a data-point and the
98 number of data-points per sample. Size is the total number of elements required to hold
99 all elements for all data-points in the given object, ie: number of samples * blocksize.
100 */
101 DataVectorTaipan(const size_type size,
102 const value_type val=0.0,
103 const size_type blockSize=1);
104
105 /**
106 \brief
107 Default destructor for DataVectorTaipan.
108
109 Description:
110 Destroys the current DataVectorTaipan object.
111 */
112 ~DataVectorTaipan();
113
114 /**
115 \brief
116 Resize the DataVectorTaipan to the given length "newSize".
117 All current data is lost. All elements in the new DataVectorTaipan are
118 initialised to "newVal".
119
120 \param newSize - Input - New size for the vector.
121 \param newVal - Input - New initial value for all elements in the vector.
122 \param newBlockSize - Input - New block size for the vector.
123 */
124 void
125 resize(const size_type newSize,
126 const value_type newVal=0.0,
127 const size_type newBlockSize=1);
128
129 /**
130 \brief
131 Populates the vector with the data from value.
132 This method currently throws an exception if the specified number of copies won't fit.
133 \warning This function does not attempt to perform shape checking.
134 */
135 void
136 copyFromArray(const escript::WrappedArray& value, size_type copies);
137
138 void
139 copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
140
141
142 /**
143 \brief
144 Return the number of elements in this DataVectorTaipan.
145 */
146 inline
147 size_type
148 size() const;
149
150 /**
151 \brief
152 DataVectorTaipan assignment operator "=".
153 Assign the given DataVectorTaipan object to this.
154 */
155 DataVectorTaipan&
156 operator=(const DataVectorTaipan& other);
157
158 /**
159 \brief
160 DataVectorTaipan equality comparison operator "==".
161 Return true if the given DataVectorTaipan is equal to this.
162 */
163 bool
164 operator==(const DataVectorTaipan& other) const;
165
166 /**
167 \brief
168 DataVectorTaipan inequality comparison operator "!=".
169 Return true if the given DataVectorTaipan is not equal to this.
170 */
171 bool
172 operator!=(const DataVectorTaipan& other) const;
173
174 /**
175 \brief
176 Return a reference to the element at position i in this DataVectorTaipan.
177 Will throw an exception if an invalid index "i" is given.
178
179 NB: access to the element one past the end of the vector is permitted
180 in order to provide a facility equivalent to an end() pointer.
181 */
182 inline
183 reference
184 operator[](const size_type i);
185
186 inline
187 const_reference
188 operator[](const size_type i) const;
189
190
191 protected:
192
193 private:
194
195 size_type m_size;
196 size_type m_dim;
197 size_type m_N;
198
199 //
200 // The container for the elements contained in this DataVectorTaipan.
201 VectorStorageType m_array_data;
202 };
203
204
205
206 class ESCRIPT_DLL_API DataVectorAlt {
207
208 public:
209
210 //
211 // The type of the elements stored in the vector.
212 typedef double ElementType;
213
214 //
215 // Various types exported to clients of this class.
216
217 typedef const ElementType * ConstValueType;
218 typedef ElementType value_type;
219 typedef long size_type;
220 typedef ElementType & reference;
221 typedef const ElementType & const_reference;
222
223 /**
224 \brief
225 Default constructor for DataVectorAlt.
226
227 Description:
228 Constructs an empty DataVectorAlt object.
229 */
230 DataVectorAlt();
231
232 /**
233 \brief
234 Copy constructor for DataVectorAlt.
235
236 Description:
237 Constructs a DataVectorAlt object which is a copy of the
238 given DataVectorAlt object.
239 */
240 DataVectorAlt(const DataVectorAlt& other);
241
242 /**
243 \brief
244 Constructor for DataVectorAlt.
245
246 Description:
247 Constructs a DataVectorAlt object of length "size" with all elements
248 initilised to "val".
249
250 \param size - Input - Number of elements in the vector.
251 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
252 \param blockSize - Input - size of blocks within the vector, overall vector
253 size must be a precise multiple of the block size. Default is 1.
254
255 In escript::Data, blocksize corresponds to the number of elements required to hold all
256 the data-points for a sample, ie: the product of the dimensions of a data-point and the
257 number of data-points per sample. Size is the total number of elements required to hold
258 all elements for all data-points in the given object, ie: number of samples * blocksize.
259 */
260 DataVectorAlt(const size_type size,
261 const value_type val=0.0,
262 const size_type blockSize=1);
263
264 /**
265 \brief
266 Default destructor for DataVectorAlt.
267
268 Description:
269 Destroys the current DataVectorAlt object.
270 */
271 ~DataVectorAlt();
272
273 /**
274 \brief
275 Resize the DataVectorAlt to the given length "newSize".
276 All current data is lost. All elements in the new DataVectorAlt are
277 initialised to "newVal".
278
279 \param newSize - Input - New size for the vector.
280 \param newVal - Input - New initial value for all elements in the vector.
281 \param newBlockSize - Input - New block size for the vector.
282 */
283 void
284 resize(const size_type newSize,
285 const value_type newVal=0.0,
286 const size_type newBlockSize=1);
287
288 /**
289 \brief
290 Populates the vector with the data from value.
291 This method currently throws an exception if the specified number of copies won't fit.
292 \warning This function does not attempt to perform shape checking.
293 */
294 void
295 copyFromArray(const escript::WrappedArray& value, size_type copies);
296
297 void
298 copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
299
300
301 /**
302 \brief
303 Return the number of elements in this DataVectorAlt.
304 */
305 inline
306 size_type
307 size() const;
308
309 /**
310 \brief
311 DataVectorAlt assignment operator "=".
312 Assign the given DataVectorAlt object to this.
313 */
314 DataVectorAlt&
315 operator=(const DataVectorAlt& other);
316
317 /**
318 \brief
319 DataVectorAlt equality comparison operator "==".
320 Return true if the given DataVectorAlt is equal to this.
321 */
322 bool
323 operator==(const DataVectorAlt& other) const;
324
325 /**
326 \brief
327 DataVectorAlt inequality comparison operator "!=".
328 Return true if the given DataVectorAlt is not equal to this.
329 */
330 bool
331 operator!=(const DataVectorAlt& other) const;
332
333 /**
334 \brief
335 Return a reference to the element at position i in this DataVectorAlt.
336 Will throw an exception if an invalid index "i" is given.
337
338 NB: access to the element one past the end of the vector is permitted
339 in order to provide a facility equivalent to an end() pointer.
340 */
341 inline
342 reference
343 operator[](const size_type i);
344
345 inline
346 const_reference
347 operator[](const size_type i) const;
348
349
350 protected:
351
352 private:
353
354 size_type m_size;
355 size_type m_dim;
356 size_type m_N;
357
358 //
359 // The container for the elements contained in this DataVectorTaipan.
360 std::vector<ElementType> m_array_data;
361 };
362
363
364
365 // This is the main version we had
366 //typedef DataVectorTaipan DataVector;
367
368 typedef DataVectorAlt DataVector;
369
370
371 /**
372 \brief
373 releases unused memory in the memory manager.
374 */
375
376 ESCRIPT_DLL_API void releaseUnusedMemory();
377
378
379
380 inline
381 DataVectorTaipan::size_type
382 DataVectorTaipan::size() const
383 {
384 return m_size;
385 }
386
387 inline
388 DataVectorTaipan::reference
389 DataVectorTaipan::operator[](const DataVectorTaipan::size_type i)
390 {
391 EsysAssert(i<size(),"DataVectorTaipan: invalid index specified. " << i << " of " << size());
392 return m_array_data[i];
393 }
394
395 inline
396 DataVectorTaipan::const_reference
397 DataVectorTaipan::operator[](const DataVectorTaipan::size_type i) const
398 {
399 EsysAssert(i<size(),"DataVectorTaipan: invalid index specified. " << i << " of " << size());
400 return m_array_data[i];
401 }
402
403
404
405
406 inline
407 DataVectorAlt::size_type
408 DataVectorAlt::size() const
409 {
410 return m_size;
411 }
412
413 inline
414 DataVectorAlt::reference
415 DataVectorAlt::operator[](const DataVectorAlt::size_type i)
416 {
417 EsysAssert(i<size(),"DataVectorAlt: invalid index specified. " << i << " of " << size());
418 return m_array_data[i];
419 }
420
421 inline
422 DataVectorAlt::const_reference
423 DataVectorAlt::operator[](const DataVectorAlt::size_type i) const
424 {
425 EsysAssert(i<size(),"DataVectorAlt: invalid index specified. " << i << " of " << size());
426 return m_array_data[i];
427 }
428
429
430 } // end of namespace
431
432 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26