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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (show annotations)
Tue Apr 12 04:45:05 2005 UTC (14 years, 7 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataBlocks2D.h
File MIME type: text/plain
File size: 6883 byte(s)
*** empty log message ***

1 /*
2 ******************************************************************************
3 * *
4 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
5 * *
6 * This software is the property of ACcESS. No part of this code *
7 * may be copied in any form or by any means without the expressed written *
8 * consent of ACcESS. Copying, use or modification of this software *
9 * by any unauthorised person is illegal unless that person has a software *
10 * license agreement with ACcESS. *
11 * *
12 ******************************************************************************
13 */
14
15 #if !defined escript_DataBlocks2D_20040405_H
16 #define escript_DataBlocks2D_20040405_H
17
18 #include <vector>
19 #include "escript/Data/DataVector.h"
20
21 #include "esysUtils/EsysAssert.h"
22
23 namespace escript {
24
25 /**
26 \brief
27 DataBlocks2D manages a 2D array of multi-dimensional data points.
28
29 Description:
30 This class is used to manage the data held by instances of
31 the DataExpanded class.
32 */
33
34 class DataBlocks2D {
35
36 public:
37
38 //
39 // The type of the underlying data array under management.
40 // The multi-dimensional data points are flattened and stored
41 // serially as a vector of doubles.
42 //typedef std::vector<double> ValueType;
43 typedef DataVector ValueType;
44
45 /**
46 \brief
47 Default constructor for DataBlocks2D.
48
49 Description:
50 Default constructor for DataBlocks2D.
51 Creates a 0 * 0 array of data points with 0 values.
52 */
53 DataBlocks2D();
54
55 /**
56 \brief
57 Copy constructor for DataBlocks2D.
58
59 Description:
60 Copy constructor for DataBlocks2D.
61 */
62 DataBlocks2D(const DataBlocks2D& other);
63
64 /**
65 \brief
66 Constructor for DataBlocks2D.
67
68 Description:
69 Constructor for DataBlocks2D.
70
71 \param numRows - Input - Number of rows.
72 \param numCols - Input - Number of columns.
73 \param blockSize - Input - Number of elements per block.
74 */
75 DataBlocks2D(int numRows, int numCols, int blockSize);
76
77 /**
78 \brief
79 Default destructor for DataBlocks2D.
80
81 Description:
82 Default destructor for DataBlocks2D.
83 */
84 ~DataBlocks2D();
85
86 /**
87 \brief
88 Return the size of the underlying data array.
89 ie: Number of rows * Number of columns * Number of elements per data point.
90 */
91 inline
92 ValueType::size_type
93 size() const;
94
95 /**
96 \brief
97 Return the number of rows in this DataBlocks2D array.
98 */
99 inline
100 ValueType::size_type
101 getNumRows() const;
102
103 /**
104 \brief
105 Return the number of columns in this DataBlocks2D array.
106 */
107 inline
108 ValueType::size_type
109 getNumCols() const;
110
111 /**
112 \brief
113 Return the data point size for this DataBlocks2D array.
114 */
115 inline
116 ValueType::size_type
117 getBlockSize() const;
118
119 /**
120 \brief
121 Resize the underlying data array. All current data is lost.
122 The new data elements are initialised to 0.
123
124 \param numRows - Input - Number of rows.
125 \param numCols - Input - Number of columns.
126 \param blockSize - Input - Number of elements per block.
127 */
128 void
129 resize(int numRows, int numCols, int blockSize);
130
131 /**
132 \brief
133 DataBlocks2D assignment operator =
134 Assign the given DataBlocks2D object to this one.
135 */
136 DataBlocks2D&
137 operator=(const DataBlocks2D& other);
138
139 /**
140 \brief
141 Swap all the values managed by the given DataBlocks2D objects.
142 */
143 void
144 Swap(DataBlocks2D& other);
145
146 /**
147 \brief
148 Return the 1 dimensional index of the first element for data-point (i,j)
149 within the underlying data array.
150 Provides an index for accessing this data value via the [] operator.
151 Subsequent elements of this data point can be accessed by manually
152 incrementing the returned index value.
153 */
154 inline
155 ValueType::size_type
156 index(int row, int col) const;
157
158 /**
159 \brief
160 Return a reference to the first element for the data-point with index i
161 within the underlying data array as determined by the index(i,j) method.
162 */
163 inline
164 ValueType::reference
165 operator[](ValueType::size_type i);
166
167 inline
168 ValueType::const_reference
169 operator[](ValueType::size_type i) const;
170
171 /**
172 \brief
173 Return a reference to the first element for the data-point (i,j).
174 */
175 inline
176 ValueType::reference
177 operator()(int row, int col);
178
179 inline
180 ValueType::const_reference
181 operator()(int row, int col) const;
182
183 /**
184 \brief
185 Return a reference to the underlying data array.
186 Data returned is an array type object that can be indexed via indexes generated
187 by DataBlocks2D::index.
188 */
189 inline
190 ValueType&
191 getData();
192
193 inline
194 const
195 ValueType&
196 getData() const;
197
198 protected:
199
200 private:
201
202 //
203 // The underlying array of data values.
204 // The two dimensional array of multi-dimensional data points is flattened
205 // and serialised within this one dimensional array of doubles.
206 ValueType m_data;
207
208 //
209 // The number of values per data point.
210 ValueType::size_type m_blockSize;
211
212 //
213 // The dimensions of the 2D array of data points.
214 ValueType::size_type m_numRows;
215 ValueType::size_type m_numCols;
216
217 };
218
219 inline
220 DataBlocks2D::ValueType::size_type
221 DataBlocks2D::size() const
222 {
223 return m_data.size();
224 }
225
226 inline
227 DataBlocks2D::ValueType::size_type
228 DataBlocks2D::getNumRows() const
229 {
230 return m_numRows;
231 }
232
233 inline
234 DataBlocks2D::ValueType::size_type
235 DataBlocks2D::getNumCols() const
236 {
237 return m_numCols;
238 }
239
240 inline
241 DataBlocks2D::ValueType::size_type
242 DataBlocks2D::getBlockSize() const
243 {
244 return m_blockSize;
245 }
246
247 inline
248 DataBlocks2D::ValueType::size_type
249 DataBlocks2D::index(int row, int col) const
250 {
251 EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");
252 ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
253 EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
254 return (temp);
255 }
256
257 inline
258 DataBlocks2D::ValueType::reference
259 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
260 {
261 return m_data[i];
262 }
263
264 inline
265 DataBlocks2D::ValueType::const_reference
266 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
267 {
268 return m_data[i];
269 }
270
271 inline
272 DataBlocks2D::ValueType::reference
273 DataBlocks2D::operator()(int row, int col)
274 {
275 return m_data[index(row,col)];
276 }
277
278 inline
279 DataBlocks2D::ValueType::const_reference
280 DataBlocks2D::operator()(int row, int col) const
281 {
282 return m_data[index(row,col)];
283 }
284
285 inline
286 DataBlocks2D::ValueType&
287 DataBlocks2D::getData()
288 {
289 return m_data;
290 }
291
292 inline
293 const DataBlocks2D::ValueType&
294 DataBlocks2D::getData() const
295 {
296 return m_data;
297 }
298
299 } // end of namespace
300
301 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26