/[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 123 by jgs, Fri Jul 8 04:08:13 2005 UTC trunk/escript/src/DataBlocks2D.h revision 478 by jgs, Tue Jan 31 02:21:49 2006 UTC
# Line 15  Line 15 
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 "DataVector.h"
 #include "escript/Data/DataVector.h"  
19    
20  #include "esysUtils/EsysAssert.h"  #include <sstream>
21    #include <iostream>
22    
23  namespace escript {  namespace escript {
24    
# Line 39  class DataBlocks2D { Line 39  class DataBlocks2D {
39    // The type of the underlying data array under management.    // The type of the underlying data array under management.
40    // The multi-dimensional data points are flattened and stored    // The multi-dimensional data points are flattened and stored
41    // serially as a vector of doubles.    // serially as a vector of doubles.
   //typedef std::vector<double> ValueType;  
42    typedef DataVector ValueType;    typedef DataVector ValueType;
43    
44    /**    /**
# Line 48  class DataBlocks2D { Line 47  class DataBlocks2D {
47    
48       Description:       Description:
49       Default constructor for DataBlocks2D.       Default constructor for DataBlocks2D.
50       Creates a 0 * 0 array of data points with 0 values.       Creates an empty DataBlocks2D object.
51    */    */
52    DataBlocks2D();    DataBlocks2D();
53    
# Line 68  class DataBlocks2D { Line 67  class DataBlocks2D {
67       Description:       Description:
68       Constructor for DataBlocks2D.       Constructor for DataBlocks2D.
69    
70       \param numRows - Input - Number of rows.       \param numRows - Input - Number of rows(samples).
71       \param numCols - Input - Number of columns.       \param numCols - Input - Number of columns(data-points per sample).
72       \param blockSize - Input - Number of elements per block.       \param blockSize - Input - Number of elements per block(per data-point).
73    
74         All parameters must be >0, else an exception will be thrown.
75    */    */
76    DataBlocks2D(int numRows, int numCols, int blockSize);    DataBlocks2D(int numRows, int numCols, int blockSize);
77    
# Line 124  class DataBlocks2D { Line 125  class DataBlocks2D {
125       \param numRows - Input - Number of rows.       \param numRows - Input - Number of rows.
126       \param numCols - Input - Number of columns.       \param numCols - Input - Number of columns.
127       \param blockSize - Input - Number of elements per block.       \param blockSize - Input - Number of elements per block.
128    
129         All parameters must be >0, else an exception will be thrown.
130    */    */
131    void    void
132    resize(int numRows, int numCols, int blockSize);    resize(int numRows, int numCols, int blockSize);
# Line 191  class DataBlocks2D { Line 194  class DataBlocks2D {
194    getData();    getData();
195    
196    inline    inline
197    const    const ValueType&
   ValueType&  
198    getData() const;    getData() const;
199    
200    /**    /**
# Line 229  class DataBlocks2D { Line 231  class DataBlocks2D {
231    ValueType m_data;    ValueType m_data;
232    
233    //    //
   // The number of values per data point.  
   ValueType::size_type m_blockSize;  
   
   //  
234    // The dimensions of the 2D array of data points.    // The dimensions of the 2D array of data points.
235    ValueType::size_type m_numRows;    ValueType::size_type m_numRows;
236    ValueType::size_type m_numCols;    ValueType::size_type m_numCols;
237    
238      //
239      // The number of values per data point.
240      ValueType::size_type m_blockSize;
241    
242  };  };
243    
244  inline  inline
245  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
246  DataBlocks2D::size() const  DataBlocks2D::size() const
247  {  {
248    return m_data.size();      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
249        return m_data.size();
250  }  }
251    
252  inline  inline
253  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
254  DataBlocks2D::getNumRows() const  DataBlocks2D::getNumRows() const
255  {  {
256    return m_numRows;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
257        return m_numRows;
258  }  }
259    
260  inline  inline
261  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
262  DataBlocks2D::getNumCols() const  DataBlocks2D::getNumCols() const
263  {  {
264    return m_numCols;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
265        return m_numCols;
266  }  }
267    
268  inline  inline
269  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
270  DataBlocks2D::getBlockSize() const  DataBlocks2D::getBlockSize() const
271  {  {
272    return m_blockSize;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
273        return m_blockSize;
274  }  }
275    
276  inline  inline
277  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
278  DataBlocks2D::index(int row, int col) const  DataBlocks2D::index(int row, int col) const
279  {  {
280        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
281      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.");
282      ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;      ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
283      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 281  inline Line 288  inline
288  DataBlocks2D::ValueType::reference  DataBlocks2D::ValueType::reference
289  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
290  {  {
291        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
292      return m_data[i];      return m_data[i];
293  }  }
294    
# Line 288  inline Line 296  inline
296  DataBlocks2D::ValueType::const_reference  DataBlocks2D::ValueType::const_reference
297  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
298  {  {
299        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
300      return m_data[i];      return m_data[i];
301  }  }
302    
# Line 295  inline Line 304  inline
304  DataBlocks2D::ValueType::reference  DataBlocks2D::ValueType::reference
305  DataBlocks2D::operator()(int row, int col)  DataBlocks2D::operator()(int row, int col)
306  {  {
307        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
308      return m_data[index(row,col)];      return m_data[index(row,col)];
309  }  }
310    
# Line 302  inline Line 312  inline
312  DataBlocks2D::ValueType::const_reference  DataBlocks2D::ValueType::const_reference
313  DataBlocks2D::operator()(int row, int col) const  DataBlocks2D::operator()(int row, int col) const
314  {  {
315        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
316      return m_data[index(row,col)];      return m_data[index(row,col)];
317  }  }
318    
# Line 309  inline Line 320  inline
320  DataBlocks2D::ValueType&  DataBlocks2D::ValueType&
321  DataBlocks2D::getData()  DataBlocks2D::getData()
322  {  {
323        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
324      return m_data;      return m_data;
325  }  }
326    
# Line 316  inline Line 328  inline
328  const DataBlocks2D::ValueType&  const DataBlocks2D::ValueType&
329  DataBlocks2D::getData() const  DataBlocks2D::getData() const
330  {  {
331        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
332      return m_data;      return m_data;
333  }  }
334    

Legend:
Removed from v.123  
changed lines
  Added in v.478

  ViewVC Help
Powered by ViewVC 1.1.26