/[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

trunk/esys2/escript/src/Data/DataBlocks2D.h revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC temp_trunk_copy/escript/src/DataBlocks2D.h revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC
# Line 1  Line 1 
1  /*  
2   ******************************************************************************  /* $Id$ */
3   *                                                                            *  
4   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *  /*******************************************************
5   *                                                                            *   *
6   * This software is the property of ACcESS. No part of this code              *   *           Copyright 2003-2007 by ACceSS MNRF
7   * may be copied in any form or by any means without the expressed written    *   *       Copyright 2007 by University of Queensland
8   * consent of ACcESS.  Copying, use or modification of this software          *   *
9   * by any unauthorised person is illegal unless that person has a software    *   *                http://esscc.uq.edu.au
10   * license agreement with ACcESS.                                             *   *        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  #if !defined escript_DataBlocks2D_20040405_H  #if !defined escript_DataBlocks2D_20040405_H
17  #define escript_DataBlocks2D_20040405_H  #define escript_DataBlocks2D_20040405_H
18    #include "system_dep.h"
19    
20  #include <vector>  #include "DataVector.h"
 #include "escript/Data/DataVector.h"  
21    
22  #include "esysUtils/EsysAssert.h"  #include <sstream>
23    #include <iostream>
24    
25  namespace escript {  namespace escript {
26    
# Line 39  class DataBlocks2D { Line 41  class DataBlocks2D {
41    // The type of the underlying data array under management.    // The type of the underlying data array under management.
42    // The multi-dimensional data points are flattened and stored    // The multi-dimensional data points are flattened and stored
43    // serially as a vector of doubles.    // serially as a vector of doubles.
   //typedef std::vector<double> ValueType;  
44    typedef DataVector ValueType;    typedef DataVector ValueType;
45    
46    /**    /**
# Line 48  class DataBlocks2D { Line 49  class DataBlocks2D {
49    
50       Description:       Description:
51       Default constructor for DataBlocks2D.       Default constructor for DataBlocks2D.
52       Creates a 0 * 0 array of data points with 0 values.       Creates an empty DataBlocks2D object.
53    */    */
54      ESCRIPT_DLL_API
55    DataBlocks2D();    DataBlocks2D();
56    
57    /**    /**
# Line 59  class DataBlocks2D { Line 61  class DataBlocks2D {
61       Description:       Description:
62       Copy constructor for DataBlocks2D.       Copy constructor for DataBlocks2D.
63    */    */
64      ESCRIPT_DLL_API
65    DataBlocks2D(const DataBlocks2D& other);    DataBlocks2D(const DataBlocks2D& other);
66    
67    /**    /**
# Line 68  class DataBlocks2D { Line 71  class DataBlocks2D {
71       Description:       Description:
72       Constructor for DataBlocks2D.       Constructor for DataBlocks2D.
73    
74       \param numRows - Input - Number of rows.       \param numRows - Input - Number of rows(samples).
75       \param numCols - Input - Number of columns.       \param numCols - Input - Number of columns(data-points per sample).
76       \param blockSize - Input - Number of elements per block.       \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    */    */
80      ESCRIPT_DLL_API
81    DataBlocks2D(int numRows, int numCols, int blockSize);    DataBlocks2D(int numRows, int numCols, int blockSize);
82    
83    /**    /**
# Line 81  class DataBlocks2D { Line 87  class DataBlocks2D {
87       Description:       Description:
88       Default destructor for DataBlocks2D.       Default destructor for DataBlocks2D.
89    */    */
90      ESCRIPT_DLL_API
91    ~DataBlocks2D();    ~DataBlocks2D();
92    
93    /**    /**
# Line 88  class DataBlocks2D { Line 95  class DataBlocks2D {
95       Return the size of the underlying data array.       Return the size of the underlying data array.
96       ie: Number of rows * Number of columns * Number of elements per data point.       ie: Number of rows * Number of columns * Number of elements per data point.
97    */    */
98      ESCRIPT_DLL_API
99    inline    inline
100    ValueType::size_type    ValueType::size_type
101    size() const;    size() const;
# Line 96  class DataBlocks2D { Line 104  class DataBlocks2D {
104       \brief       \brief
105       Return the number of rows in this DataBlocks2D array.       Return the number of rows in this DataBlocks2D array.
106    */    */
107      ESCRIPT_DLL_API
108    inline    inline
109    ValueType::size_type    ValueType::size_type
110    getNumRows() const;    getNumRows() const;
# Line 104  class DataBlocks2D { Line 113  class DataBlocks2D {
113       \brief       \brief
114       Return the number of columns in this DataBlocks2D array.       Return the number of columns in this DataBlocks2D array.
115    */    */
116      ESCRIPT_DLL_API
117    inline    inline
118    ValueType::size_type    ValueType::size_type
119    getNumCols() const;    getNumCols() const;
# Line 112  class DataBlocks2D { Line 122  class DataBlocks2D {
122       \brief       \brief
123       Return the data point size for this DataBlocks2D array.       Return the data point size for this DataBlocks2D array.
124    */    */
125      ESCRIPT_DLL_API
126    inline    inline
127    ValueType::size_type    ValueType::size_type
128    getBlockSize() const;    getBlockSize() const;
# Line 124  class DataBlocks2D { Line 135  class DataBlocks2D {
135       \param numRows - Input - Number of rows.       \param numRows - Input - Number of rows.
136       \param numCols - Input - Number of columns.       \param numCols - Input - Number of columns.
137       \param blockSize - Input - Number of elements per block.       \param blockSize - Input - Number of elements per block.
138    
139         All parameters must be >0, else an exception will be thrown.
140    */    */
141      ESCRIPT_DLL_API
142    void    void
143    resize(int numRows, int numCols, int blockSize);    resize(int numRows, int numCols, int blockSize);
144    
# Line 133  class DataBlocks2D { Line 147  class DataBlocks2D {
147       DataBlocks2D assignment operator =       DataBlocks2D assignment operator =
148       Assign the given DataBlocks2D object to this one.       Assign the given DataBlocks2D object to this one.
149    */    */
150      ESCRIPT_DLL_API
151    DataBlocks2D&    DataBlocks2D&
152    operator=(const DataBlocks2D& other);    operator=(const DataBlocks2D& other);
153    
# Line 140  class DataBlocks2D { Line 155  class DataBlocks2D {
155       \brief       \brief
156       Swap all the values managed by the given DataBlocks2D objects.       Swap all the values managed by the given DataBlocks2D objects.
157    */    */
158      ESCRIPT_DLL_API
159    void    void
160    Swap(DataBlocks2D& other);    Swap(DataBlocks2D& other);
161    
# Line 151  class DataBlocks2D { Line 167  class DataBlocks2D {
167      Subsequent elements of this data point can be accessed by manually      Subsequent elements of this data point can be accessed by manually
168      incrementing the returned index value.      incrementing the returned index value.
169    */    */
170      ESCRIPT_DLL_API
171    inline    inline
172    ValueType::size_type    ValueType::size_type
173    index(int row, int col) const;    index(int row, int col) const;
# Line 160  class DataBlocks2D { Line 177  class DataBlocks2D {
177      Return a reference to the first element for the data-point with index i      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.      within the underlying data array as determined by the index(i,j) method.
179    */    */
180      ESCRIPT_DLL_API
181    inline    inline
182    ValueType::reference    ValueType::reference
183    operator[](ValueType::size_type i);    operator[](ValueType::size_type i);
184    
185      ESCRIPT_DLL_API
186    inline    inline
187    ValueType::const_reference    ValueType::const_reference
188    operator[](ValueType::size_type i) const;    operator[](ValueType::size_type i) const;
# Line 172  class DataBlocks2D { Line 191  class DataBlocks2D {
191      \brief      \brief
192      Return a reference to the first element for the data-point (i,j).      Return a reference to the first element for the data-point (i,j).
193    */    */
194      ESCRIPT_DLL_API
195    inline    inline
196    ValueType::reference    ValueType::reference
197    operator()(int row, int col);    operator()(int row, int col);
198    
199      ESCRIPT_DLL_API
200    inline    inline
201    ValueType::const_reference    ValueType::const_reference
202    operator()(int row, int col) const;    operator()(int row, int col) const;
203    
204    /**    /**
205       \brief       \brief
206       Return the underlying data array.       Return a reference to the underlying data array.
207       Data returned is an array type object that can be indexed via indexes generated       Data returned is an array type object that can be indexed via indexes generated
208       by DataBlocks2D::index.       by DataBlocks2D::index.
209    */    */
210      ESCRIPT_DLL_API
211    inline    inline
212    ValueType&    ValueType&
213    getData();    getData();
214    
215      ESCRIPT_DLL_API
216    inline    inline
217    const    const ValueType&
   ValueType&  
218    getData() const;    getData() const;
219    
220      /**
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      ESCRIPT_DLL_API
229      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      ESCRIPT_DLL_API
241      int
242      extractData(std::ifstream& archiveFile,
243                  const ValueType::size_type noValues);
244    
245   protected:   protected:
246    
247   private:   private:
# Line 206  class DataBlocks2D { Line 253  class DataBlocks2D {
253    ValueType m_data;    ValueType m_data;
254    
255    //    //
   // The number of values per data point.  
   ValueType::size_type m_blockSize;  
   
   //  
256    // The dimensions of the 2D array of data points.    // The dimensions of the 2D array of data points.
257    ValueType::size_type m_numRows;    ValueType::size_type m_numRows;
258    ValueType::size_type m_numCols;    ValueType::size_type m_numCols;
259    
260      //
261      // The number of values per data point.
262      ValueType::size_type m_blockSize;
263    
264  };  };
265    
266  inline  inline
267  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
268  DataBlocks2D::size() const  DataBlocks2D::size() const
269  {  {
270    return m_data.size();      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
271        return m_data.size();
272  }  }
273    
274  inline  inline
275  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
276  DataBlocks2D::getNumRows() const  DataBlocks2D::getNumRows() const
277  {  {
278    return m_numRows;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
279        return m_numRows;
280  }  }
281    
282  inline  inline
283  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
284  DataBlocks2D::getNumCols() const  DataBlocks2D::getNumCols() const
285  {  {
286    return m_numCols;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
287        return m_numCols;
288  }  }
289    
290  inline  inline
291  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
292  DataBlocks2D::getBlockSize() const  DataBlocks2D::getBlockSize() const
293  {  {
294    return m_blockSize;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
295        return m_blockSize;
296  }  }
297    
298  inline  inline
299  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
300  DataBlocks2D::index(int row, int col) const  DataBlocks2D::index(int row, int col) const
301  {  {
302        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
303      EsysAssert(((row >= 0) && (col >= 0) && (m_data.size() > 0)), "(DataBlocks2D) Index value out of range.");      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;      ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
305      EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");      EsysAssert((temp <= (m_data.size()-m_blockSize)), "(DataBlocks2D) Index value out of range.");
# Line 258  inline Line 310  inline
310  DataBlocks2D::ValueType::reference  DataBlocks2D::ValueType::reference
311  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
312  {  {
313        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
314      return m_data[i];      return m_data[i];
315  }  }
316    
# Line 265  inline Line 318  inline
318  DataBlocks2D::ValueType::const_reference  DataBlocks2D::ValueType::const_reference
319  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
320  {  {
321        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
322      return m_data[i];      return m_data[i];
323  }  }
324    
# Line 272  inline Line 326  inline
326  DataBlocks2D::ValueType::reference  DataBlocks2D::ValueType::reference
327  DataBlocks2D::operator()(int row, int col)  DataBlocks2D::operator()(int row, int col)
328  {  {
329        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
330      return m_data[index(row,col)];      return m_data[index(row,col)];
331  }  }
332    
# Line 279  inline Line 334  inline
334  DataBlocks2D::ValueType::const_reference  DataBlocks2D::ValueType::const_reference
335  DataBlocks2D::operator()(int row, int col) const  DataBlocks2D::operator()(int row, int col) const
336  {  {
337        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
338      return m_data[index(row,col)];      return m_data[index(row,col)];
339  }  }
340    
# Line 286  inline Line 342  inline
342  DataBlocks2D::ValueType&  DataBlocks2D::ValueType&
343  DataBlocks2D::getData()  DataBlocks2D::getData()
344  {  {
345        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
346      return m_data;      return m_data;
347  }  }
348    
# Line 293  inline Line 350  inline
350  const DataBlocks2D::ValueType&  const DataBlocks2D::ValueType&
351  DataBlocks2D::getData() const  DataBlocks2D::getData() const
352  {  {
353        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
354      return m_data;      return m_data;
355  }  }
356    

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

  ViewVC Help
Powered by ViewVC 1.1.26