/[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 trunk/escript/src/DataBlocks2D.h revision 477 by jgs, Mon Jan 30 07:20:20 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"
19  #include "escript/Data/DataVector.h"  #include "DataException.h"
20    
21  #include "esysUtils/EsysAssert.h"  #include "EsysAssert.h"
22    
23    #include <sstream>
24    #include <iostream>
25    
26  namespace escript {  namespace escript {
27    
# Line 39  class DataBlocks2D { Line 42  class DataBlocks2D {
42    // The type of the underlying data array under management.    // The type of the underlying data array under management.
43    // The multi-dimensional data points are flattened and stored    // The multi-dimensional data points are flattened and stored
44    // serially as a vector of doubles.    // serially as a vector of doubles.
   //typedef std::vector<double> ValueType;  
45    typedef DataVector ValueType;    typedef DataVector ValueType;
46    
47    /**    /**
# Line 48  class DataBlocks2D { Line 50  class DataBlocks2D {
50    
51       Description:       Description:
52       Default constructor for DataBlocks2D.       Default constructor for DataBlocks2D.
53       Creates a 0 * 0 array of data points with 0 values.       Creates an empty DataBlocks2D object.
54    */    */
55    DataBlocks2D();    DataBlocks2D();
56    
# Line 68  class DataBlocks2D { Line 70  class DataBlocks2D {
70       Description:       Description:
71       Constructor for DataBlocks2D.       Constructor for DataBlocks2D.
72    
73       \param numRows - Input - Number of rows.       \param numRows - Input - Number of rows(samples).
74       \param numCols - Input - Number of columns.       \param numCols - Input - Number of columns(data-points per sample).
75       \param blockSize - Input - Number of elements per block.       \param blockSize - Input - Number of elements per block(per data-point).
76    
77         All parameters must be >0, else an exception will be thrown.
78    */    */
79    DataBlocks2D(int numRows, int numCols, int blockSize);    DataBlocks2D(int numRows, int numCols, int blockSize);
80    
# Line 124  class DataBlocks2D { Line 128  class DataBlocks2D {
128       \param numRows - Input - Number of rows.       \param numRows - Input - Number of rows.
129       \param numCols - Input - Number of columns.       \param numCols - Input - Number of columns.
130       \param blockSize - Input - Number of elements per block.       \param blockSize - Input - Number of elements per block.
131    
132         All parameters must be >0, else an exception will be thrown.
133    */    */
134    void    void
135    resize(int numRows, int numCols, int blockSize);    resize(int numRows, int numCols, int blockSize);
# Line 182  class DataBlocks2D { Line 188  class DataBlocks2D {
188    
189    /**    /**
190       \brief       \brief
191       Return the underlying data array.       Return a reference to the underlying data array.
192       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
193       by DataBlocks2D::index.       by DataBlocks2D::index.
194    */    */
# Line 191  class DataBlocks2D { Line 197  class DataBlocks2D {
197    getData();    getData();
198    
199    inline    inline
200    const    const ValueType&
   ValueType&  
201    getData() const;    getData() const;
202    
203      /**
204        \brief
205        Archive the data managed by this DataBlocks2D to the file referenced
206        by ofstream. A count of the number of values expected to be written
207        is provided as a cross-check.
208    
209        The return value indicates success (0) or otherwise (1).
210      */
211      int
212      archiveData(std::ofstream& archiveFile,
213                  const ValueType::size_type noValues) const;
214    
215      /**
216        \brief
217        Extract the number of values specified by noValues from the file
218        referenced by ifstream to this DataBlocks2D.
219    
220        The return value indicates success (0) or otherwise (1).
221      */
222      int
223      extractData(std::ifstream& archiveFile,
224                  const ValueType::size_type noValues);
225    
226   protected:   protected:
227    
228   private:   private:
# Line 206  class DataBlocks2D { Line 234  class DataBlocks2D {
234    ValueType m_data;    ValueType m_data;
235    
236    //    //
   // The number of values per data point.  
   ValueType::size_type m_blockSize;  
   
   //  
237    // The dimensions of the 2D array of data points.    // The dimensions of the 2D array of data points.
238    ValueType::size_type m_numRows;    ValueType::size_type m_numRows;
239    ValueType::size_type m_numCols;    ValueType::size_type m_numCols;
240    
241      //
242      // The number of values per data point.
243      ValueType::size_type m_blockSize;
244    
245  };  };
246    
247  inline  inline
248  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
249  DataBlocks2D::size() const  DataBlocks2D::size() const
250  {  {
251    return m_data.size();      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
252        return m_data.size();
253  }  }
254    
255  inline  inline
256  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
257  DataBlocks2D::getNumRows() const  DataBlocks2D::getNumRows() const
258  {  {
259    return m_numRows;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
260        return m_numRows;
261  }  }
262    
263  inline  inline
264  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
265  DataBlocks2D::getNumCols() const  DataBlocks2D::getNumCols() const
266  {  {
267    return m_numCols;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
268        return m_numCols;
269  }  }
270    
271  inline  inline
272  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
273  DataBlocks2D::getBlockSize() const  DataBlocks2D::getBlockSize() const
274  {  {
275    return m_blockSize;      EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
276        return m_blockSize;
277  }  }
278    
279  inline  inline
280  DataBlocks2D::ValueType::size_type  DataBlocks2D::ValueType::size_type
281  DataBlocks2D::index(int row, int col) const  DataBlocks2D::index(int row, int col) const
282  {  {
283        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
284      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.");
285      ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;      ValueType::size_type temp=(row*m_numCols+col)*m_blockSize;
286      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 291  inline
291  DataBlocks2D::ValueType::reference  DataBlocks2D::ValueType::reference
292  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i)
293  {  {
294        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
295      return m_data[i];      return m_data[i];
296  }  }
297    
# Line 265  inline Line 299  inline
299  DataBlocks2D::ValueType::const_reference  DataBlocks2D::ValueType::const_reference
300  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const  DataBlocks2D::operator[](DataBlocks2D::ValueType::size_type i) const
301  {  {
302        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
303      return m_data[i];      return m_data[i];
304  }  }
305    
# Line 272  inline Line 307  inline
307  DataBlocks2D::ValueType::reference  DataBlocks2D::ValueType::reference
308  DataBlocks2D::operator()(int row, int col)  DataBlocks2D::operator()(int row, int col)
309  {  {
310        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
311      return m_data[index(row,col)];      return m_data[index(row,col)];
312  }  }
313    
# Line 279  inline Line 315  inline
315  DataBlocks2D::ValueType::const_reference  DataBlocks2D::ValueType::const_reference
316  DataBlocks2D::operator()(int row, int col) const  DataBlocks2D::operator()(int row, int col) const
317  {  {
318        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
319      return m_data[index(row,col)];      return m_data[index(row,col)];
320  }  }
321    
# Line 286  inline Line 323  inline
323  DataBlocks2D::ValueType&  DataBlocks2D::ValueType&
324  DataBlocks2D::getData()  DataBlocks2D::getData()
325  {  {
326        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
327      return m_data;      return m_data;
328  }  }
329    
# Line 293  inline Line 331  inline
331  const DataBlocks2D::ValueType&  const DataBlocks2D::ValueType&
332  DataBlocks2D::getData() const  DataBlocks2D::getData() const
333  {  {
334        EsysAssert(((m_numRows >= 0) && (m_numCols >= 0) && (m_blockSize >= 0)), "(DataBlocks2D) Invalid object.");
335      return m_data;      return m_data;
336  }  }
337    

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

  ViewVC Help
Powered by ViewVC 1.1.26