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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (hide annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 1 month ago) by ksteube
File MIME type: text/plain
File size: 8830 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1 jgs 117
2 ksteube 1312 /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 jgs 117 #if !defined escript_DataBlocks2D_20040405_H
17 jgs 82 #define escript_DataBlocks2D_20040405_H
18 woo409 757 #include "system_dep.h"
19 jgs 82
20 jgs 474 #include "DataVector.h"
21 jgs 82
22 jgs 474 #include <sstream>
23     #include <iostream>
24    
25 jgs 82 namespace escript {
26    
27     /**
28     \brief
29 jgs 117 DataBlocks2D manages a 2D array of multi-dimensional data points.
30 jgs 82
31     Description:
32 jgs 117 This class is used to manage the data held by instances of
33     the DataExpanded class.
34 jgs 82 */
35    
36     class DataBlocks2D {
37    
38     public:
39    
40 jgs 117 //
41     // The type of the underlying data array under management.
42     // The multi-dimensional data points are flattened and stored
43     // serially as a vector of doubles.
44     typedef DataVector ValueType;
45 jgs 82
46     /**
47     \brief
48 jgs 117 Default constructor for DataBlocks2D.
49 jgs 82
50     Description:
51 jgs 117 Default constructor for DataBlocks2D.
52 jgs 151 Creates an empty DataBlocks2D object.
53 jgs 82 */
54 woo409 757 ESCRIPT_DLL_API
55 jgs 82 DataBlocks2D();
56    
57     /**
58     \brief
59 jgs 117 Copy constructor for DataBlocks2D.
60 jgs 82
61     Description:
62 jgs 117 Copy constructor for DataBlocks2D.
63 jgs 82 */
64 woo409 757 ESCRIPT_DLL_API
65 jgs 82 DataBlocks2D(const DataBlocks2D& other);
66    
67     /**
68     \brief
69 jgs 117 Constructor for DataBlocks2D.
70 jgs 82
71     Description:
72 jgs 117 Constructor for DataBlocks2D.
73    
74 jgs 151 \param numRows - Input - Number of rows(samples).
75     \param numCols - Input - Number of columns(data-points per sample).
76     \param blockSize - Input - Number of elements per block(per data-point).
77    
78     All parameters must be >0, else an exception will be thrown.
79 jgs 82 */
80 woo409 757 ESCRIPT_DLL_API
81 jgs 82 DataBlocks2D(int numRows, int numCols, int blockSize);
82    
83     /**
84     \brief
85 jgs 117 Default destructor for DataBlocks2D.
86 jgs 82
87     Description:
88 jgs 117 Default destructor for DataBlocks2D.
89 jgs 82 */
90 woo409 757 ESCRIPT_DLL_API
91 jgs 82 ~DataBlocks2D();
92    
93     /**
94     \brief
95 jgs 117 Return the size of the underlying data array.
96     ie: Number of rows * Number of columns * Number of elements per data point.
97 jgs 82 */
98 woo409 757 ESCRIPT_DLL_API
99 jgs 117 inline
100     ValueType::size_type
101     size() const;
102 jgs 82
103     /**
104 jgs 117 \brief
105     Return the number of rows in this DataBlocks2D array.
106 jgs 82 */
107 woo409 757 ESCRIPT_DLL_API
108 jgs 117 inline
109     ValueType::size_type
110     getNumRows() const;
111 jgs 82
112     /**
113     \brief
114 jgs 117 Return the number of columns in this DataBlocks2D array.
115 jgs 82 */
116 woo409 757 ESCRIPT_DLL_API
117 jgs 117 inline
118     ValueType::size_type
119     getNumCols() const;
120 jgs 82
121     /**
122     \brief
123 jgs 117 Return the data point size for this DataBlocks2D array.
124 jgs 82 */
125 woo409 757 ESCRIPT_DLL_API
126 jgs 117 inline
127     ValueType::size_type
128     getBlockSize() const;
129 jgs 82
130     /**
131     \brief
132 jgs 117 Resize the underlying data array. All current data is lost.
133     The new data elements are initialised to 0.
134    
135     \param numRows - Input - Number of rows.
136     \param numCols - Input - Number of columns.
137     \param blockSize - Input - Number of elements per block.
138 jgs 151
139     All parameters must be >0, else an exception will be thrown.
140 jgs 82 */
141 woo409 757 ESCRIPT_DLL_API
142 jgs 117 void
143     resize(int numRows, int numCols, int blockSize);
144 jgs 82
145     /**
146     \brief
147 jgs 117 DataBlocks2D assignment operator =
148     Assign the given DataBlocks2D object to this one.
149 jgs 82 */
150 woo409 757 ESCRIPT_DLL_API
151 jgs 117 DataBlocks2D&
152     operator=(const DataBlocks2D& other);
153 jgs 82
154     /**
155     \brief
156 jgs 117 Swap all the values managed by the given DataBlocks2D objects.
157 jgs 82 */
158 woo409 757 ESCRIPT_DLL_API
159 jgs 117 void
160     Swap(DataBlocks2D& other);
161 jgs 82
162     /**
163 jgs 117 \brief
164     Return the 1 dimensional index of the first element for data-point (i,j)
165     within the underlying data array.
166     Provides an index for accessing this data value via the [] operator.
167     Subsequent elements of this data point can be accessed by manually
168     incrementing the returned index value.
169     */
170 woo409 757 ESCRIPT_DLL_API
171 jgs 117 inline
172     ValueType::size_type
173     index(int row, int col) const;
174    
175     /**
176     \brief
177     Return a reference to the first element for the data-point with index i
178     within the underlying data array as determined by the index(i,j) method.
179     */
180 woo409 757 ESCRIPT_DLL_API
181 jgs 117 inline
182     ValueType::reference
183     operator[](ValueType::size_type i);
184    
185 woo409 757 ESCRIPT_DLL_API
186 jgs 117 inline
187     ValueType::const_reference
188     operator[](ValueType::size_type i) const;
189    
190     /**
191     \brief
192     Return a reference to the first element for the data-point (i,j).
193     */
194 woo409 757 ESCRIPT_DLL_API
195 jgs 117 inline
196     ValueType::reference
197     operator()(int row, int col);
198    
199 woo409 757 ESCRIPT_DLL_API
200 jgs 117 inline
201     ValueType::const_reference
202     operator()(int row, int col) const;
203    
204     /**
205 jgs 82 \brief
206 jgs 119 Return a reference to the underlying data array.
207 jgs 117 Data returned is an array type object that can be indexed via indexes generated
208     by DataBlocks2D::index.
209 jgs 82 */
210 woo409 757 ESCRIPT_DLL_API
211 jgs 117 inline
212     ValueType&
213     getData();
214 jgs 82
215 woo409 757 ESCRIPT_DLL_API
216 jgs 117 inline
217 jgs 151 const ValueType&
218 jgs 117 getData() const;
219    
220 jgs 123 /**
221     \brief
222     Archive the data managed by this DataBlocks2D to the file referenced
223     by ofstream. A count of the number of values expected to be written
224     is provided as a cross-check.
225    
226     The return value indicates success (0) or otherwise (1).
227     */
228 woo409 757 ESCRIPT_DLL_API
229 jgs 123 int
230     archiveData(std::ofstream& archiveFile,
231     const ValueType::size_type noValues) const;
232    
233     /**
234     \brief
235     Extract the number of values specified by noValues from the file
236     referenced by ifstream to this DataBlocks2D.
237    
238     The return value indicates success (0) or otherwise (1).
239     */
240 woo409 757 ESCRIPT_DLL_API
241 jgs 123 int
242     extractData(std::ifstream& archiveFile,
243     const ValueType::size_type noValues);
244    
245 jgs 82 protected:
246    
247     private:
248    
249     //
250 jgs 117 // The underlying array of data values.
251     // The two dimensional array of multi-dimensional data points is flattened
252     // and serialised within this one dimensional array of doubles.
253 jgs 82 ValueType m_data;
254    
255     //
256 jgs 117 // The dimensions of the 2D array of data points.
257     ValueType::size_type m_numRows;
258     ValueType::size_type m_numCols;
259 jgs 82
260 jgs 151 //
261     // The number of values per data point.
262     ValueType::size_type m_blockSize;
263    
264 jgs 82 };
265    
266 jgs 117 inline
267     DataBlocks2D::ValueType::size_type
268     DataBlocks2D::size() const
269 jgs 82 {
270 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
271     return m_data.size();
272 jgs 117 }
273    
274     inline
275     DataBlocks2D::ValueType::size_type
276     DataBlocks2D::getNumRows() const
277     {
278 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
279     return m_numRows;
280 jgs 82 }
281    
282 jgs 117 inline
283     DataBlocks2D::ValueType::size_type
284     DataBlocks2D::getNumCols() const
285 jgs 82 {
286 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
287     return m_numCols;
288 jgs 82 }
289    
290 jgs 117 inline
291     DataBlocks2D::ValueType::size_type
292     DataBlocks2D::getBlockSize() const
293     {
294 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
295     return m_blockSize;
296 jgs 117 }
297    
298     inline
299     DataBlocks2D::ValueType::size_type
300     DataBlocks2D::index(int row, int col) const
301     {
302 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
303 jgs 117 EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");
304     ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
305     EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
306     return (temp);
307     }
308    
309     inline
310     DataBlocks2D::ValueType::reference
311     DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
312     {
313 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
314 jgs 117 return m_data[i];
315     }
316    
317     inline
318     DataBlocks2D::ValueType::const_reference
319     DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
320     {
321 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
322 jgs 117 return m_data[i];
323     }
324    
325     inline
326     DataBlocks2D::ValueType::reference
327     DataBlocks2D::operator()(int row, int col)
328     {
329 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
330 jgs 117 return m_data[index(row,col)];
331     }
332    
333     inline
334     DataBlocks2D::ValueType::const_reference
335     DataBlocks2D::operator()(int row, int col) const
336     {
337 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
338 jgs 117 return m_data[index(row,col)];
339     }
340    
341     inline
342     DataBlocks2D::ValueType&
343     DataBlocks2D::getData()
344     {
345 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
346 jgs 117 return m_data;
347     }
348    
349     inline
350     const DataBlocks2D::ValueType&
351     DataBlocks2D::getData() const
352     {
353 jgs 151 EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
354 jgs 117 return m_data;
355     }
356    
357 jgs 82 } // end of namespace
358 jgs 117
359 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26