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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 151 - (hide annotations)
Thu Sep 22 01:55:00 2005 UTC (14 years ago) by jgs
Original Path: trunk/esys2/escript/src/Data/DataBlocks2D.h
File MIME type: text/plain
File size: 8963 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-22

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26