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

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

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

trunk/esys2/escript/src/Data/DataAbstract.h revision 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/src/DataAbstract.h revision 1325 by matt, Mon Oct 1 06:28:24 2007 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /* $Id$ */
3   ******************************************************************************  
4   *                                                                            *  /*******************************************************
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *
6   *                                                                            *   *           Copyright 2003-2007 by ACceSS MNRF
7   * This software is the property of ACcESS. No part of this code              *   *       Copyright 2007 by University of Queensland
8   * may be copied in any form or by any means without the expressed written    *   *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *                http://esscc.uq.edu.au
10   * by any unauthorised person is illegal unless that person has a software    *   *        Primary Business: Queensland, Australia
11   * license agreement with ACcESS.                                             *   *  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_DataAbstract_20040315_H  #if !defined escript_DataAbstract_20040315_H
17  #define escript_DataAbstract_20040315_H  #define escript_DataAbstract_20040315_H
18    #include "system_dep.h"
19    
20  #include "escript/Data/DataException.h"  #include "DataArrayView.h"
21  #include "escript/Data/DataArrayView.h"  #include "FunctionSpace.h"
 #include "escript/Data/DataArray.h"  
 #include "escript/Data/FunctionSpace.h"  
22    
 #include <iostream>  
23  #include <boost/scoped_ptr.hpp>  #include <boost/scoped_ptr.hpp>
24  #include <functional>  #include <boost/python/numeric.hpp>
25    
26  #include <string>  #include <string>
27    #include <fstream>
28    
29  namespace escript {  namespace escript {
30    
31  /**  /**
32     \brief     \brief
33     DataAbstract provides an abstract interface for the class of containers     DataAbstract provides an abstract interface for the class of containers
34     which hold ESyS data.     which hold ESyS data.
35    
36     Description:     Description:
37     DataAbstract provides an abstract interface for the class of containers     DataAbstract provides an abstract interface for the class of containers
# Line 58  class DataAbstract { Line 58  class DataAbstract {
58    
59       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
60    */    */
61      ESCRIPT_DLL_API
62    DataAbstract(const FunctionSpace& what);    DataAbstract(const FunctionSpace& what);
63    
64    /**    /**
65      \brief      \brief
66      Destructor for DataAbstract.      Destructor for DataAbstract.
67    */    */
68      ESCRIPT_DLL_API
69    virtual    virtual
70    ~DataAbstract();    ~DataAbstract();
71    
# Line 71  class DataAbstract { Line 73  class DataAbstract {
73       \brief       \brief
74       Write the data as a string.       Write the data as a string.
75    */    */
76      ESCRIPT_DLL_API
77    virtual    virtual
78    std::string    std::string
79    toString() const = 0;    toString() const = 0;
80    
81     /**
82         \brief
83         dumps the object into a netCDF file
84      */
85      ESCRIPT_DLL_API
86      virtual
87      void
88      dump(const std::string fileName) const;
89    
90    /**    /**
91       \brief       \brief
92       Return the number of data points per sample.       Return the number of data points per sample.
93    */    */
94      ESCRIPT_DLL_API
95    int    int
96    getNumDPPSample() const;    getNumDPPSample() const;
97    
# Line 86  class DataAbstract { Line 99  class DataAbstract {
99       \brief       \brief
100       Return the number of samples.       Return the number of samples.
101    */    */
102      ESCRIPT_DLL_API
103    int    int
104    getNumSamples() const;    getNumSamples() const;
105    
106    /**    /**
107       \brief       \brief
108       Return the DataArrayView of the point data. This essentially contains       Return the DataArrayView of the point data. This essentially contains
109       the shape information for each data point although it also may be used       the shape information for each data point although it also may be used
110       to manipulate the point data.       to manipulate the point data.
111    */    */
112      ESCRIPT_DLL_API
113    DataArrayView&    DataArrayView&
114    getPointDataView();    getPointDataView();
115    
116      ESCRIPT_DLL_API
117    const DataArrayView&    const DataArrayView&
118    getPointDataView() const;    getPointDataView() const;
119    
# Line 110  class DataAbstract { Line 126  class DataAbstract {
126       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
127       \param dataPointNo - Input - data point number.       \param dataPointNo - Input - data point number.
128     */     */
129      ESCRIPT_DLL_API
130    virtual    virtual
131    ValueType::size_type    ValueType::size_type
132    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
# Line 119  class DataAbstract { Line 136  class DataAbstract {
136       \brief       \brief
137       Return the sample data for the given sample number.       Return the sample data for the given sample number.
138    */    */
139      ESCRIPT_DLL_API
140    double*    double*
141    getSampleData(ValueType::size_type sampleNo);    getSampleData(ValueType::size_type sampleNo);
142    
# Line 126  class DataAbstract { Line 144  class DataAbstract {
144       \brief       \brief
145       Return the number of doubles stored for this Data object.       Return the number of doubles stored for this Data object.
146    */    */
147      ESCRIPT_DLL_API
148    virtual    virtual
149    ValueType::size_type    ValueType::size_type
150    getLength() const = 0;    getLength() const = 0;
# Line 135  class DataAbstract { Line 154  class DataAbstract {
154       Return the sample data for the given tag key.       Return the sample data for the given tag key.
155       NB: If the data isn't tagged an exception will be thrown.       NB: If the data isn't tagged an exception will be thrown.
156    */    */
157      ESCRIPT_DLL_API
158    virtual    virtual
159    double*    double*
160    getSampleDataByTag(int tag);    getSampleDataByTag(int tag);
161    
   /**  
      \brief  
      Assign the given value to the data-points(s) referenced by the given  
      reference number.  
   
      If this Data object cannot be accessed by reference numbers an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Input - value to assign to data-points associated with  
                             the given reference number.  
   */  
   virtual  
   void  
   setRefValue(int ref,  
               const DataArray& value);  
   
   /**  
      \brief  
      Return the values associated with the data-point(s) referenced by the given  
      reference number.  
   
      If this Data object cannot be accessed by reference numbers an  
      exception will be thrown.  
   
      \param ref - Input - reference number.  
      \param value - Output - object to receive data-points associated with  
                              the given reference number.  
   */  
   virtual  
   void  
   getRefValue(int ref,  
               DataArray& value);  
162    
163    /**    /**
164       \brief       \brief
# Line 180  class DataAbstract { Line 167  class DataAbstract {
167    
168       \param right - Input - The right hand side.       \param right - Input - The right hand side.
169    */    */
170      ESCRIPT_DLL_API
171    void    void
172    operandCheck(const DataAbstract& right) const;    operandCheck(const DataAbstract& right) const;
173    
# Line 187  class DataAbstract { Line 175  class DataAbstract {
175       \brief       \brief
176       Return true if a valid sample point number.       Return true if a valid sample point number.
177    */    */
178      ESCRIPT_DLL_API
179    bool    bool
180    validSamplePointNo(int samplePointNo) const;    validSamplePointNo(int samplePointNo) const;
181    
# Line 194  class DataAbstract { Line 183  class DataAbstract {
183       \brief       \brief
184       Return true if a valid sample number.       Return true if a valid sample number.
185    */    */
186      ESCRIPT_DLL_API
187    bool    bool
188    validSampleNo(int sampleNo) const;    validSampleNo(int sampleNo) const;
189    
190    /**    /**
191       \brief       \brief
192       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
193       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
194       operation.       operation.
195    
196       \param sampleNo - Input - the sample number.       \param sampleNo - Input - the sample number.
197       \param dataPointNo - Input - the data point number.       \param dataPointNo - Input - the data point number.
198    */    */
199      ESCRIPT_DLL_API
200    virtual    virtual
201    DataArrayView    DataArrayView
202    getDataPoint(int sampleNo,    getDataPoint(int sampleNo,
# Line 215  class DataAbstract { Line 206  class DataAbstract {
206       \brief       \brief
207       Return the function space associated with this Data object.       Return the function space associated with this Data object.
208    */    */
209      ESCRIPT_DLL_API
210    const    const
211    FunctionSpace&    FunctionSpace&
212    getFunctionSpace() const;    getFunctionSpace() const;
# Line 225  class DataAbstract { Line 217  class DataAbstract {
217    
218       NB: The caller is responsible for managing the object created.       NB: The caller is responsible for managing the object created.
219    */    */
220      ESCRIPT_DLL_API
221    virtual    virtual
222    DataAbstract*    DataAbstract*
223    getSlice(const DataArrayView::RegionType& region) const = 0;    getSlice(const DataArrayView::RegionType& region) const = 0;
# Line 236  class DataAbstract { Line 229  class DataAbstract {
229       \param value - Input - Data to copy from       \param value - Input - Data to copy from
230       \param region - Input - Region to copy.       \param region - Input - Region to copy.
231    */    */
232      ESCRIPT_DLL_API
233    virtual    virtual
234    void    void
235    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
236             const DataArrayView::RegionType& region) = 0;             const DataArrayView::RegionType& region) = 0;
237    
   /**  
      \brief  
      Reshape the data points if they are currently rank 0.  
      Will throw an exception if the data points are not rank 0.  
      The original data point value is used for all values of the new  
      data point.  
   */  
   virtual  
   void  
   reshapeDataPoint(const ShapeType& shape) = 0;  
238    
239    /**    /**
240       \brief       \brief
241       setTaggedValue       setTaggedValue
242                                                                                                                                      
243       Description:       Description:
244       Assign the given value to the given tag.       Assign the given value to the given tag.
245    
# Line 264  class DataAbstract { Line 248  class DataAbstract {
248       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
249       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
250    */    */
251      ESCRIPT_DLL_API
252    virtual    virtual
253    void    void
254    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
255                   const DataArrayView& value);                   const DataArrayView& value);
256    
257      /**
258        \brief
259        Archive the underlying data values to the file referenced
260        by ofstream. A count of the number of values expected to be written
261        is provided as a cross-check.
262    
263        The return value indicates success (0) or otherwise (1).
264      */
265      ESCRIPT_DLL_API
266      virtual
267      int
268      archiveData(std::ofstream& archiveFile,
269                  const ValueType::size_type noValues) const;
270    
271      /**
272        \brief
273        Extract the number of values specified by noValues from the file
274        referenced by ifstream to the underlying data structure.
275    
276        The return value indicates success (0) or otherwise (1).
277      */
278      ESCRIPT_DLL_API
279      virtual
280      int
281      extractData(std::ifstream& archiveFile,
282                  const ValueType::size_type noValues);
283    
284      /**
285         \brief
286         Copy the numarray object to the data points in this object.
287    
288         Description:
289         Copy the numarray object to the data points in this object.
290    
291         \param value Input - new values for the data points
292      */
293      ESCRIPT_DLL_API
294      virtual void
295      copyAll(const boost::python::numeric::array& value);
296    
297      /**
298         \brief
299         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
300    
301         Description:
302         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
303    
304         \param sampleNo Input - sample number
305         \param dataPointNo Input - data point of the sample
306         \param value Input - new values for the data point
307      */
308      ESCRIPT_DLL_API
309      virtual void
310      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
311    
312      /**
313         \brief
314         Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
315    
316         Description:
317         Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
318    
319         \param sampleNo Input - sample number
320         \param dataPointNo Input - data point of the sample
321         \param value Input - new values for the data point
322      */
323      ESCRIPT_DLL_API
324      virtual void
325      copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
326    
327    
328      /**
329         \brief
330         Return the tag number associated with the given data-point number.
331    
332         If the object cannot be referenced by tag numbers, an exception
333         will be thrown.
334      */
335      ESCRIPT_DLL_API
336      virtual
337      int
338      getTagNumber(int dpno);
339    
340      /**
341         \brief
342         Computes a symmetric matrix (A + AT) / 2
343    
344         \param ev - Output - a symmetric matrix
345    
346      */
347      ESCRIPT_DLL_API
348      virtual void
349      symmetric(DataAbstract* ev);
350    
351      /**
352         \brief
353         Computes a nonsymmetric matrix (A - AT) / 2
354    
355         \param ev - Output - a nonsymmetric matrix
356    
357      */
358      ESCRIPT_DLL_API
359      virtual void
360      nonsymmetric(DataAbstract* ev);
361    
362      /**
363         \brief
364         Computes the trace of a matrix
365    
366         \param ev - Output - the trace of a matrix
367    
368      */
369      ESCRIPT_DLL_API
370      virtual void
371      trace(DataAbstract* ev, int axis_offset);
372    
373      /**
374         \brief
375         Transpose each data point of this Data object around the given axis.
376    
377         \param ev - Output - the transpose of a matrix
378    
379      */
380      ESCRIPT_DLL_API
381      virtual void
382      transpose(DataAbstract* ev, int axis_offset);
383    
384      /**
385         \brief
386         swaps components axis0 and axis1
387    
388         \param ev - Output - swapped components
389    
390      */
391      ESCRIPT_DLL_API
392      virtual void
393      swapaxes(DataAbstract* ev, int axis0, int axis1);
394      /**
395         \brief
396         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
397    
398         \param ev - Output - eigenvalues in increasing order at each data point
399    
400      */
401      ESCRIPT_DLL_API
402      virtual void
403      eigenvalues(DataAbstract* ev);
404    
405      /**
406         \brief
407         sets values to zero
408    
409      */
410      ESCRIPT_DLL_API
411      virtual void
412      setToZero();
413    
414      /**
415         \brief
416         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
417    
418         \param ev - Output - eigenvalues in increasing order at each data point
419         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
420                             and the first nonzero component is positive.
421         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
422    
423      */
424    
425      ESCRIPT_DLL_API
426      virtual void
427      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
428    
429   protected:   protected:
430    
431    /**    /**
# Line 278  class DataAbstract { Line 435  class DataAbstract {
435       \param input - Input - The point data view. DataAbstract takes ownership       \param input - Input - The point data view. DataAbstract takes ownership
436       of the DataArrayView provided. It will delete it when it is destructed.       of the DataArrayView provided. It will delete it when it is destructed.
437    */    */
438      ESCRIPT_DLL_API
439    void    void
440    setPointDataView(const DataArrayView& input);    setPointDataView(const DataArrayView& input);
441    
442      ESCRIPT_DLL_API
443    void    void
444    resetPointDataView();    resetPointDataView();
445    
# Line 311  class DataAbstract { Line 470  class DataAbstract {
470    
471  inline  inline
472  bool  bool
473  DataAbstract::validSamplePointNo(int samplePointNo) const  DataAbstract::validSamplePointNo(int samplePointNo) const
474  {  {
475    return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));    return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
476  }  }
# Line 332  DataAbstract::getSampleData(ValueType::s Line 491  DataAbstract::getSampleData(ValueType::s
491    
492  inline  inline
493  int  int
494  DataAbstract::getNumDPPSample() const  DataAbstract::getNumDPPSample() const
495  {  {
496    return m_noDataPointsPerSample;    return m_noDataPointsPerSample;
497  }  }
# Line 366  DataAbstract::getPointDataView() Line 525  DataAbstract::getPointDataView()
525  {  {
526    return *(m_pointDataView.get());    return *(m_pointDataView.get());
527  }  }
   
528  } // end of namespace  } // end of namespace
529    
530  #endif  #endif

Legend:
Removed from v.121  
changed lines
  Added in v.1325

  ViewVC Help
Powered by ViewVC 1.1.26