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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC
# Line 11  Line 11 
11   *                                                                            *   *                                                                            *
12   ******************************************************************************   ******************************************************************************
13  */  */
14                                                                              
15  #if !defined  escript_DataBlocks2D_20040405_H  #if !defined escript_DataBlocks2D_20040405_H
16  #define escript_DataBlocks2D_20040405_H  #define escript_DataBlocks2D_20040405_H
17    
18  #include <vector>  #include <vector>
19    #include "escript/Data/DataVector.h"
20    
21    #include "esysUtils/EsysAssert.h"
22    
23  namespace escript {  namespace escript {
24    
25  /**  /**
26     \brief     \brief
27     DataBlocks2D allocates and manages a 2D array of data blocks.     DataBlocks2D manages a 2D array of multi-dimensional data points.
28    
29     Description:     Description:
30     DataBlocks2D allocates and manages a 2D array of data blocks.     This class is used to manage the data held by instances of
31       the DataExpanded class.
32  */  */
33    
34  class DataBlocks2D {  class DataBlocks2D {
35    
36   public:   public:
37    
38    typedef std::vector<double> ValueType;    //
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       \brief
47       Default constructor for DataBlocks2D       Default constructor for DataBlocks2D.
48    
49       Description:       Description:
50       Default constructor for DataBlocks2D       Default constructor for DataBlocks2D.
51         Creates a 0 * 0 array of data points with 0 values.
52    */    */
53    DataBlocks2D();    DataBlocks2D();
54    
55    /**    /**
56       \brief       \brief
57       Copy constructor for DataBlocks2D       Copy constructor for DataBlocks2D.
58    
59       Description:       Description:
60       Copy constructor for DataBlocks2D       Copy constructor for DataBlocks2D.
61    */    */
62    DataBlocks2D(const DataBlocks2D& other);    DataBlocks2D(const DataBlocks2D& other);
63    
64    /**    /**
65       \brief       \brief
66       Constructor for DataBlocks2D       Constructor for DataBlocks2D.
67    
68       Description:       Description:
69       Constructor for DataBlocks2D       Constructor for DataBlocks2D.
70       \param numRows - Input - Number of rows  
71       \param numCols - Input - Number of columns       \param numRows - Input - Number of rows.
72       \param blockSize - Input - Number of elements per block       \param numCols - Input - Number of columns.
73         \param blockSize - Input - Number of elements per block.
74    */    */
75    DataBlocks2D(int numRows, int numCols, int blockSize);    DataBlocks2D(int numRows, int numCols, int blockSize);
76    
77    /**    /**
78       \brief       \brief
79       Default destructor for DataBlocks2D       Default destructor for DataBlocks2D.
80    
81       Description:       Description:
82       Default destructor for DataBlocks2D       Default destructor for DataBlocks2D.
83    */    */
84    ~DataBlocks2D();    ~DataBlocks2D();
85    
86    /**    /**
87       \brief       \brief
88       Resize the container. All current data is lost.       Return the size of the underlying data array.
89         ie: Number of rows * Number of columns * Number of elements per data point.
      Description:  
      Resize the container. All current data is lost. The data elements are  
      initialised to 0.  
   
      \param numRows - Input - Number of rows  
      \param numCols - Input - Number of columns  
      \param blockSize - Input - Number of elements per block  
90    */    */
91    void resize(int numRows, int numCols, int blockSize);    inline
92      ValueType::size_type
93      size() const;
94    
95    /**    /**
96      \brief       \brief
97      Return the 1 dimensional index of the first element for the block i,j.       Return the number of rows in this DataBlocks2D array.
     Allows each element to be referenced as though entire 3D array was laid  
     out as a 1 dimensional list of elements.  
98    */    */
99    ValueType::size_type index(ValueType::size_type i, ValueType::size_type j) const;    inline
100      ValueType::size_type
101      getNumRows() const;
102    
103    /**    /**
104       \brief       \brief
105       Return the data       Return the number of columns in this DataBlocks2D array.
      Data is returned as an array that can be indexed via indexes generated by DataBlocks2D::index  
106    */    */
107    ValueType& getData();    inline
108      ValueType::size_type
109      getNumCols() const;
110    
111    /**    /**
112       \brief       \brief
113       Return the data       Return the data point size for this DataBlocks2D array.
      Data is returned as an array that can be indexed via indexes generated by DataBlocks2D::index  
114    */    */
115    const ValueType& getData() const;    inline
116      ValueType::size_type
117      getBlockSize() const;
118    
119    /**    /**
120       \brief       \brief
121       Return the number of rows       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    ValueType::size_type getNumRows() const;    void
129      resize(int numRows, int numCols, int blockSize);
130    
131    /**    /**
132       \brief       \brief
133       Return the number of columns       DataBlocks2D assignment operator =
134         Assign the given DataBlocks2D object to this one.
135    */    */
136    ValueType::size_type getNumCols() const;    DataBlocks2D&
137      operator=(const DataBlocks2D& other);
138    
139    /**    /**
140       \brief       \brief
141       Swap       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    void Swap(DataBlocks2D& other);    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       \brief
185       operator=       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    */    */
189    DataBlocks2D& operator=(const DataBlocks2D& other);    inline
190      ValueType&
191      getData();
192    
193      inline
194      const
195      ValueType&
196      getData() const;
197    
198   protected:   protected:
199    
200   private:   private:
201    
202    //    //
203    // data container, currently only concerned with doubles    // 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    ValueType m_data;    ValueType m_data;
207    
208    //    //
209    // the number of doubles per data block    // The number of values per data point.
210    int m_blockSize;    ValueType::size_type m_blockSize;
211    
212    //    //
213    //    // The dimensions of the 2D array of data points.
214    int m_numRows;    ValueType::size_type m_numRows;
215    int m_numCols;    ValueType::size_type m_numCols;
216    
217  };  };
218    
219  inline DataBlocks2D::ValueType::size_type DataBlocks2D::getNumRows() const  inline
220    DataBlocks2D::ValueType::size_type
221    DataBlocks2D::size() const
222    {
223      return m_data.size();
224    }
225    
226    inline
227    DataBlocks2D::ValueType::size_type
228    DataBlocks2D::getNumRows() const
229  {  {
230    return m_numRows;    return m_numRows;
231  }  }
232    
233  inline DataBlocks2D::ValueType::size_type DataBlocks2D::getNumCols() const  inline
234    DataBlocks2D::ValueType::size_type
235    DataBlocks2D::getNumCols() const
236  {  {
237    return m_numCols;    return m_numCols;
238  }  }
239    
240    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  } // end of namespace  } // end of namespace
300    
301  #endif  #endif

Legend:
Removed from v.82  
changed lines
  Added in v.117

  ViewVC Help
Powered by ViewVC 1.1.26