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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (hide annotations)
Fri Apr 1 05:48:57 2005 UTC (14 years, 8 months ago) by jgs
File MIME type: text/plain
File size: 6868 byte(s)
*** empty log message ***

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 117 Return the underlying data array.
186     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 82 protected:
199    
200     private:
201    
202     //
203 jgs 117 // 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 jgs 82 ValueType m_data;
207    
208     //
209 jgs 117 // The number of values per data point.
210     ValueType::size_type m_blockSize;
211 jgs 82
212     //
213 jgs 117 // The dimensions of the 2D array of data points.
214     ValueType::size_type m_numRows;
215     ValueType::size_type m_numCols;
216 jgs 82
217     };
218    
219 jgs 117 inline
220     DataBlocks2D::ValueType::size_type
221     DataBlocks2D::size() const
222 jgs 82 {
223 jgs 117 return m_data.size();
224     }
225    
226     inline
227     DataBlocks2D::ValueType::size_type
228     DataBlocks2D::getNumRows() const
229     {
230 jgs 82 return m_numRows;
231     }
232    
233 jgs 117 inline
234     DataBlocks2D::ValueType::size_type
235     DataBlocks2D::getNumCols() const
236 jgs 82 {
237     return m_numCols;
238     }
239    
240 jgs 117 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 jgs 82 } // end of namespace
300 jgs 117
301 jgs 82 #endif

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26