/[escript]/trunk/escript/src/DataVector.h
ViewVC logotype

Contents of /trunk/escript/src/DataVector.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2653 - (show annotations)
Tue Sep 8 04:26:30 2009 UTC (9 years, 10 months ago) by jfenwick
File MIME type: text/plain
File size: 6208 byte(s)
Fix bug in maxGlobalDataPoint and minGlobalDataPoint.
They now give the correct answers and the datapoint ids returned are globally
correct.

Removed some #defines from before COW
Removed hasNoSamples() - I don't trust myself to use that properly let alone anybody else.


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #if !defined escript_DataVector_20050324_H
16 #define escript_DataVector_20050324_H
17 #include "system_dep.h"
18
19 #include "esysUtils/EsysAssert.h"
20
21 #include <vector>
22 #include <iostream>
23 #include <fstream>
24
25 namespace escript {
26
27 class WrappedArray;
28
29 /**
30 \brief
31 DataVector implements an arbitrarily long vector of data values.
32 DataVector is the underlying data container for Data objects.
33
34 Description:
35 DataVector provides an implementation of a vector of data values for use
36 by DataBlocks2D and DataArrayView. Hiding the vector in this container
37 allows different implementations to be swapped in without disrupting the
38 client classes.
39 */
40
41 class ESCRIPT_DLL_API DataVector {
42
43 public:
44
45 //
46 // The type of the elements stored in the vector.
47 typedef double ElementType;
48
49 //
50 // The underlying type used to implement the vector.
51 typedef ElementType * ValueType;
52
53 //
54 // Various types exported to clients of this class.
55 typedef ElementType value_type;
56 typedef long size_type;
57 typedef ElementType & reference;
58 typedef const ElementType & const_reference;
59
60 /**
61 \brief
62 Default constructor for DataVector.
63
64 Description:
65 Constructs an empty DataVector object.
66 */
67 DataVector();
68
69 /**
70 \brief
71 Copy constructor for DataVector.
72
73 Description:
74 Constructs a DataVector object which is a copy of the
75 given DataVector object.
76 */
77 DataVector(const DataVector& other);
78
79 /**
80 \brief
81 Constructor for DataVector.
82
83 Description:
84 Constructs a DataVector object of length "size" with all elements
85 initilised to "val".
86
87 \param size - Input - Number of elements in the vector.
88 \param val - Input - Initial value for all elements in the vector. Default is 0.0.
89 \param blockSize - Input - size of blocks within the vector, overall vector
90 size must be a precise multiple of the block size. Default is 1.
91
92 In escript::Data, blocksize corresponds to the number of elements required to hold all
93 the data-points for a sample, ie: the product of the dimensions of a data-point and the
94 number of data-points per sample. Size is the total number of elements required to hold
95 all elements for all data-points in the given object, ie: number of samples * blocksize.
96 */
97 DataVector(const size_type size,
98 const value_type val=0.0,
99 const size_type blockSize=1);
100
101 /**
102 \brief
103 Default destructor for DataVector.
104
105 Description:
106 Destroys the current DataVector object.
107 */
108 ~DataVector();
109
110 /**
111 \brief
112 Resize the DataVector to the given length "newSize".
113 All current data is lost. All elements in the new DataVector are
114 initialised to "newVal".
115
116 \param newSize - Input - New size for the vector.
117 \param newVal - Input - New initial value for all elements in the vector.
118 \param newBlockSize - Input - New block size for the vector.
119 */
120 void
121 resize(const size_type newSize,
122 const value_type newVal=0.0,
123 const size_type newBlockSize=1);
124
125 /**
126 \brief
127 Populates the vector with the data from value.
128 This method currently throws an exception if the specified number of copies won't fit.
129 \warning This function does not attempt to perform shape checking.
130 */
131 void
132 copyFromArray(const escript::WrappedArray& value, size_type copies);
133
134 void
135 copyFromArrayToOffset(const WrappedArray& value, size_type offset, size_type copies);
136
137
138 /**
139 \brief
140 Return the number of elements in this DataVector.
141 */
142 inline
143 size_type
144 size() const;
145
146 /**
147 \brief
148 DataVector assignment operator "=".
149 Assign the given DataVector object to this.
150 */
151 DataVector&
152 operator=(const DataVector& other);
153
154 /**
155 \brief
156 DataVector equality comparison operator "==".
157 Return true if the given DataVector is equal to this.
158 */
159 bool
160 operator==(const DataVector& other) const;
161
162 /**
163 \brief
164 DataVector inequality comparison operator "!=".
165 Return true if the given DataVector is not equal to this.
166 */
167 bool
168 operator!=(const DataVector& other) const;
169
170 /**
171 \brief
172 Return a reference to the element at position i in this DataVector.
173 Will throw an exception if an invalid index "i" is given.
174
175 NB: access to the element one past the end of the vector is permitted
176 in order to provide a facility equivalent to an end() pointer.
177 */
178 inline
179 reference
180 operator[](const size_type i);
181
182 inline
183 const_reference
184 operator[](const size_type i) const;
185
186
187 protected:
188
189 private:
190
191 size_type m_size;
192 size_type m_dim;
193 size_type m_N;
194
195 //
196 // The container for the elements contained in this DataVector.
197 ValueType m_array_data;
198 };
199
200 /**
201 \brief
202 releases unused memory in the memory manager.
203 */
204
205 ESCRIPT_DLL_API void releaseUnusedMemory();
206
207
208
209 inline
210 DataVector::size_type
211 DataVector::size() const
212 {
213 return m_size;
214 }
215
216 inline
217 DataVector::reference
218 DataVector::operator[](const DataVector::size_type i)
219 {
220 EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
221 return m_array_data[i];
222 }
223
224 inline
225 DataVector::const_reference
226 DataVector::operator[](const DataVector::size_type i) const
227 {
228 EsysAssert(i<size(),"DataVector: invalid index specified. " << i << " of " << size());
229 return m_array_data[i];
230 }
231
232 } // end of namespace
233
234 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26