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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 123 - (hide 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 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     Creates a 0 * 0 array of data points with 0 values.
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     \param numRows - Input - Number of rows.
72     \param numCols - Input - Number of columns.
73     \param blockSize - Input - Number of elements per block.
74 jgs 82 */
75     DataBlocks2D(int numRows, int numCols, int blockSize);
76    
77     /**
78     \brief
79 jgs 117 Default destructor for DataBlocks2D.
80 jgs 82
81     Description:
82 jgs 117 Default destructor for DataBlocks2D.
83 jgs 82 */
84     ~DataBlocks2D();
85    
86     /**
87     \brief
88 jgs 117 Return the size of the underlying data array.
89     ie: Number of rows * Number of columns * Number of elements per data point.
90 jgs 82 */
91 jgs 117 inline
92     ValueType::size_type
93     size() const;
94 jgs 82
95     /**
96 jgs 117 \brief
97     Return the number of rows in this DataBlocks2D array.
98 jgs 82 */
99 jgs 117 inline
100     ValueType::size_type
101     getNumRows() const;
102 jgs 82
103     /**
104     \brief
105 jgs 117 Return the number of columns in this DataBlocks2D array.
106 jgs 82 */
107 jgs 117 inline
108     ValueType::size_type
109     getNumCols() const;
110 jgs 82
111     /**
112     \brief
113 jgs 117 Return the data point size for this DataBlocks2D array.
114 jgs 82 */
115 jgs 117 inline
116     ValueType::size_type
117     getBlockSize() const;
118 jgs 82
119     /**
120     \brief
121 jgs 117 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 jgs 82 */
128 jgs 117 void
129     resize(int numRows, int numCols, int blockSize);
130 jgs 82
131     /**
132     \brief
133 jgs 117 DataBlocks2D assignment operator =
134     Assign the given DataBlocks2D object to this one.
135 jgs 82 */
136 jgs 117 DataBlocks2D&
137     operator=(const DataBlocks2D& other);
138 jgs 82
139     /**
140     \brief
141 jgs 117 Swap all the values managed by the given DataBlocks2D objects.
142 jgs 82 */
143 jgs 117 void
144     Swap(DataBlocks2D& other);
145 jgs 82
146     /**
147 jgs 117 \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 jgs 82 \brief
185 jgs 119 Return a reference to the underlying data array.
186 jgs 117 Data returned is an array type object that can be indexed via indexes generated
187     by DataBlocks2D::index.
188 jgs 82 */
189 jgs 117 inline
190     ValueType&
191     getData();
192 jgs 82
193 jgs 117 inline
194     const
195     ValueType&
196     getData() const;
197    
198 jgs 123 /**
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 jgs 82 protected:
222    
223     private:
224    
225     //
226 jgs 117 // 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 jgs 82 ValueType m_data;
230    
231     //
232 jgs 117 // The number of values per data point.
233     ValueType::size_type m_blockSize;
234 jgs 82
235     //
236 jgs 117 // The dimensions of the 2D array of data points.
237     ValueType::size_type m_numRows;
238     ValueType::size_type m_numCols;
239 jgs 82
240     };
241    
242 jgs 117 inline
243     DataBlocks2D::ValueType::size_type
244     DataBlocks2D::size() const
245 jgs 82 {
246 jgs 117 return m_data.size();
247     }
248    
249     inline
250     DataBlocks2D::ValueType::size_type
251     DataBlocks2D::getNumRows() const
252     {
253 jgs 82 return m_numRows;
254     }
255    
256 jgs 117 inline
257     DataBlocks2D::ValueType::size_type
258     DataBlocks2D::getNumCols() const
259 jgs 82 {
260     return m_numCols;
261     }
262    
263 jgs 117 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 jgs 82 } // end of namespace
323 jgs 117
324 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26