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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (show annotations)
Fri Jul 8 04:08:13 2005 UTC (14 years, 3 months ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataBlocks2D.h
File MIME type: text/plain
File size: 7556 byte(s)
Merge of development branch back to main trunk on 2005-07-08

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 /**
199 \brief
200 Archive the data managed by this DataBlocks2D to the file referenced
201 by ofstream. A count of the number of values expected to be written
202 is provided as a cross-check.
203
204 The return value indicates success (0) or otherwise (1).
205 */
206 int
207 archiveData(std::ofstream& archiveFile,
208 const ValueType::size_type noValues) const;
209
210 /**
211 \brief
212 Extract the number of values specified by noValues from the file
213 referenced by ifstream to this DataBlocks2D.
214
215 The return value indicates success (0) or otherwise (1).
216 */
217 int
218 extractData(std::ifstream& archiveFile,
219 const ValueType::size_type noValues);
220
221 protected:
222
223 private:
224
225 //
226 // The underlying array of data values.
227 // The two dimensional array of multi-dimensional data points is flattened
228 // and serialised within this one dimensional array of doubles.
229 ValueType m_data;
230
231 //
232 // The number of values per data point.
233 ValueType::size_type m_blockSize;
234
235 //
236 // The dimensions of the 2D array of data points.
237 ValueType::size_type m_numRows;
238 ValueType::size_type m_numCols;
239
240 };
241
242 inline
243 DataBlocks2D::ValueType::size_type
244 DataBlocks2D::size() const
245 {
246 return m_data.size();
247 }
248
249 inline
250 DataBlocks2D::ValueType::size_type
251 DataBlocks2D::getNumRows() const
252 {
253 return m_numRows;
254 }
255
256 inline
257 DataBlocks2D::ValueType::size_type
258 DataBlocks2D::getNumCols() const
259 {
260 return m_numCols;
261 }
262
263 inline
264 DataBlocks2D::ValueType::size_type
265 DataBlocks2D::getBlockSize() const
266 {
267 return m_blockSize;
268 }
269
270 inline
271 DataBlocks2D::ValueType::size_type
272 DataBlocks2D::index(int row, int col) const
273 {
274 EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");
275 ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
276 EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
277 return (temp);
278 }
279
280 inline
281 DataBlocks2D::ValueType::reference
282 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
283 {
284 return m_data[i];
285 }
286
287 inline
288 DataBlocks2D::ValueType::const_reference
289 DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
290 {
291 return m_data[i];
292 }
293
294 inline
295 DataBlocks2D::ValueType::reference
296 DataBlocks2D::operator()(int row, int col)
297 {
298 return m_data[index(row,col)];
299 }
300
301 inline
302 DataBlocks2D::ValueType::const_reference
303 DataBlocks2D::operator()(int row, int col) const
304 {
305 return m_data[index(row,col)];
306 }
307
308 inline
309 DataBlocks2D::ValueType&
310 DataBlocks2D::getData()
311 {
312 return m_data;
313 }
314
315 inline
316 const DataBlocks2D::ValueType&
317 DataBlocks2D::getData() const
318 {
319 return m_data;
320 }
321
322 } // end of namespace
323
324 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26