/[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 110 by jgs, Mon Feb 14 04:14:42 2005 UTC trunk/escript/src/DataAbstract.h revision 775 by ksteube, Mon Jul 10 04:00:08 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS. No part of this code              *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that person has a software    *   *                                                          *
11   * license agreement with ACcESS.                                             *   ************************************************************
12   *                                                                            *  
  ******************************************************************************  
13  */  */
14                                                                              
15  #if !defined escript_DataAbstract_20040315_H  #if !defined escript_DataAbstract_20040315_H
16  #define escript_DataAbstract_20040315_H  #define escript_DataAbstract_20040315_H
17    #include "system_dep.h"
18    
19  #include "escript/Data/DataException.h"  #include "DataArrayView.h"
20  #include "escript/Data/DataArrayView.h"  #include "DataArray.h"
21  #include "escript/Data/DataArray.h"  #include "FunctionSpace.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 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 interface for the class of containers     DataAbstract provides an abstract interface for the class of containers
38     which hold ESyS data. The container may be thought of as a 2 dimensional     which hold ESyS data. The container may be thought of as a 2 dimensional
39     array of data points. The data points themselves are arrays of rank 0-4.     array of data points where one dimension corresponds to the number of samples
40       and the other to the number of data points per sample as defined by the function
41       space associated with each Data object. The data points themselves are arrays of
42       doubles of rank 0-4.
43  */  */
44    
45  class DataAbstract {  class DataAbstract {
# Line 52  class DataAbstract { Line 55  class DataAbstract {
55    
56       Description:       Description:
57       Constructor for DataAbstract.       Constructor for 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 67  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;
# Line 75  class DataAbstract { Line 82  class DataAbstract {
82       \brief       \brief
83       Return the number of data points per sample.       Return the number of data points per sample.
84    */    */
85      ESCRIPT_DLL_API
86    int    int
87    getNumDPPSample() const;    getNumDPPSample() const;
88    
# Line 82  class DataAbstract { Line 90  class DataAbstract {
90       \brief       \brief
91       Return the number of samples.       Return the number of samples.
92    */    */
93      ESCRIPT_DLL_API
94    int    int
95    getNumSamples() const;    getNumSamples() const;
96    
# Line 91  class DataAbstract { Line 100  class DataAbstract {
100       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
101       to manipulate the point data.       to manipulate the point data.
102    */    */
103    const DataArrayView&    ESCRIPT_DLL_API
   getPointDataView() const;  
   
104    DataArrayView&    DataArrayView&
105    getPointDataView();    getPointDataView();
106    
107      ESCRIPT_DLL_API
108      const DataArrayView&
109      getPointDataView() const;
110    
111    /**    /**
112       \brief       \brief
113       Return the offset for the given sample. This is somewhat artificial notion       Return the offset for the given sample. This returns the offset for the given
114       but returns the offset for the given point into the container       point into the container holding the point data. Only really necessary to
115       holding the point data. Only really necessary to avoid many DataArrayView       avoid creating many DataArrayView objects.
116       objects.  
117       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
118       \param dataPointNo - Input - Input.       \param dataPointNo - Input - data point number.
119     */     */
120      ESCRIPT_DLL_API
121    virtual    virtual
122    ValueType::size_type    ValueType::size_type
123    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
# Line 113  class DataAbstract { Line 125  class DataAbstract {
125    
126    /**    /**
127       \brief       \brief
128       Return the sample data for the given sample no.       Return the sample data for the given sample number.
129    */    */
130      ESCRIPT_DLL_API
131    double*    double*
132    getSampleData(ValueType::size_type sampleNo);    getSampleData(ValueType::size_type sampleNo);
133    
134    /**    /**
135       \brief       \brief
136       Return the number of doubles stored for the Data.       Return the number of doubles stored for this Data object.
137    */    */
138      ESCRIPT_DLL_API
139    virtual    virtual
140    ValueType::size_type    ValueType::size_type
141    getLength() const = 0;    getLength() const = 0;
# Line 131  class DataAbstract { Line 145  class DataAbstract {
145       Return the sample data for the given tag key.       Return the sample data for the given tag key.
146       NB: If the data isn't tagged an exception will be thrown.       NB: If the data isn't tagged an exception will be thrown.
147    */    */
148      ESCRIPT_DLL_API
149    virtual    virtual
150    double*    double*
151    getSampleDataByTag(int tag);    getSampleDataByTag(int tag);
# Line 147  class DataAbstract { Line 162  class DataAbstract {
162       \param value - Input - value to assign to data-points associated with       \param value - Input - value to assign to data-points associated with
163                              the given reference number.                              the given reference number.
164    */    */
165      ESCRIPT_DLL_API
166    virtual    virtual
167    void    void
168    setRefValue(int ref,    setRefValue(int ref,
# Line 164  class DataAbstract { Line 180  class DataAbstract {
180       \param value - Output - object to receive data-points associated with       \param value - Output - object to receive data-points associated with
181                               the given reference number.                               the given reference number.
182    */    */
183      ESCRIPT_DLL_API
184    virtual    virtual
185    void    void
186    getRefValue(int ref,    getRefValue(int ref,
# Line 171  class DataAbstract { Line 188  class DataAbstract {
188    
189    /**    /**
190       \brief       \brief
191       Check this and the right operands are compatible. Throws       Check this and the given RHS operands are compatible. Throws
192       an exception if they aren't.       an exception if they aren't.
193    
194       \param right - Input - The right hand side.       \param right - Input - The right hand side.
195    */    */
196      ESCRIPT_DLL_API
197    void    void
198    operandCheck(const DataAbstract& right) const;    operandCheck(const DataAbstract& right) const;
199    
# Line 182  class DataAbstract { Line 201  class DataAbstract {
201       \brief       \brief
202       Return true if a valid sample point number.       Return true if a valid sample point number.
203    */    */
204      ESCRIPT_DLL_API
205    bool    bool
206    validSamplePointNo(int samplePointNo) const;    validSamplePointNo(int samplePointNo) const;
207    
208    /**    /**
209       \brief       \brief
210       Return true if a valid number.       Return true if a valid sample number.
211    */    */
212      ESCRIPT_DLL_API
213    bool    bool
214    validSampleNo(int sampleNo) const;    validSampleNo(int sampleNo) const;
215    
# Line 197  class DataAbstract { Line 218  class DataAbstract {
218       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
219       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
220       operation.       operation.
221       \param samplesNo Input  
222       \param dataPointNo Input       \param sampleNo - Input - the sample number.
223         \param dataPointNo - Input - the data point number.
224    */    */
225      ESCRIPT_DLL_API
226    virtual    virtual
227    DataArrayView    DataArrayView
228    getDataPoint(int samplesNo,    getDataPoint(int sampleNo,
229                 int dataPointNo) = 0;                 int dataPointNo) = 0;
230    
231    /**    /**
232       \brief       \brief
233       Return the function space.       Return the function space associated with this Data object.
234    */    */
235    const FunctionSpace&    ESCRIPT_DLL_API
236      const
237      FunctionSpace&
238    getFunctionSpace() const;    getFunctionSpace() const;
239    
240    /**    /**
241       \brief       \brief
242       Return a newly constructed DataAbstract. The caller is responsible for       Return the given slice from this object.
243       managing the object created.  
244         NB: The caller is responsible for managing the object created.
245    */    */
246      ESCRIPT_DLL_API
247    virtual    virtual
248    DataAbstract*    DataAbstract*
249    getSlice(const DataArrayView::RegionType& region) const = 0;    getSlice(const DataArrayView::RegionType& region) const = 0;
250    
251    /**    /**
252       \brief       \brief
253       Copy the specified region from the given value.       Copy the specified region from the given object.
254    
255       \param value - Input - Data to copy from       \param value - Input - Data to copy from
256       \param region - Input - Region to copy.       \param region - Input - Region to copy.
257    */    */
258      ESCRIPT_DLL_API
259    virtual    virtual
260    void    void
261    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
# Line 234  class DataAbstract { Line 263  class DataAbstract {
263    
264    /**    /**
265       \brief       \brief
266       Reshape the data point if the data point is currently rank 0.       Reshape the data points if they are currently rank 0.
267       Will throw an exception if the data points are not rank 0.       Will throw an exception if the data points are not rank 0.
268       The original data point value is used for all values of the new       The original data point value is used for all values of the new
269       data point.       data point.
270    */    */
271      ESCRIPT_DLL_API
272    virtual    virtual
273    void    void
274    reshapeDataPoint(const DataArrayView::ShapeType& shape) = 0;    reshapeDataPoint(const ShapeType& shape) = 0;
275    
276    /**    /**
277       \brief       \brief
# Line 249  class DataAbstract { Line 279  class DataAbstract {
279                                                                                                                                                                                                                                                                        
280       Description:       Description:
281       Assign the given value to the given tag.       Assign the given value to the given tag.
282    
283         NB: If the data isn't tagged an exception will be thrown.
284    
285       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
286       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
      NB: If the data isn't tagged an exception will be thrown.  
287    */    */
288      ESCRIPT_DLL_API
289    virtual    virtual
290    void    void
291    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
292                   const DataArrayView& value);                   const DataArrayView& value);
293    
294      /**
295        \brief
296        Archive the underlying data values to the file referenced
297        by ofstream. A count of the number of values expected to be written
298        is provided as a cross-check.
299    
300        The return value indicates success (0) or otherwise (1).
301      */
302      ESCRIPT_DLL_API
303      virtual
304      int
305      archiveData(std::ofstream& archiveFile,
306                  const ValueType::size_type noValues) const;
307    
308      /**
309        \brief
310        Extract the number of values specified by noValues from the file
311        referenced by ifstream to the underlying data structure.
312    
313        The return value indicates success (0) or otherwise (1).
314      */
315      ESCRIPT_DLL_API
316      virtual
317      int
318      extractData(std::ifstream& archiveFile,
319                  const ValueType::size_type noValues);
320    
321      /**
322         \brief
323         Copy the numarray object to the data points in this object.
324    
325         Description:
326         Copy the numarray object to the data points in this object.
327    
328         \param value Input - new values for the data points
329      */
330      ESCRIPT_DLL_API
331      virtual void
332      copyAll(const boost::python::numeric::array& value);
333    
334      /**
335         \brief
336         Return the tag number associated with the given data-point number.
337    
338         If the object cannot be referenced by tag numbers, an exception
339         will be thrown.
340      */
341      ESCRIPT_DLL_API
342      virtual
343      int
344      getTagNumber(int dpno);
345    
346      /**
347         \brief
348         Computes a symmetric matrix (A + AT) / 2
349    
350         \param ev - Output - a symmetric matrix
351    
352      */
353      virtual void
354      symmetric(DataAbstract* ev);
355    
356      /**
357         \brief
358         Computes a nonsymmetric matrix (A - AT) / 2
359    
360         \param ev - Output - a nonsymmetric matrix
361    
362      */
363      virtual void
364      nonsymmetric(DataAbstract* ev);
365    
366      /**
367         \brief
368         Computes the trace of a matrix
369    
370         \param ev - Output - the trace of a matrix
371    
372      */
373      virtual void
374      matrixtrace(DataAbstract* ev, int axis_offset);
375    
376      /**
377         \brief
378         Transpose each data point of this Data object around the given axis.
379    
380         \param ev - Output - the transpose of a matrix
381    
382      */
383      virtual void
384      transpose(DataAbstract* ev, int axis_offset);
385    
386      /**
387         \brief
388         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
389    
390         \param ev - Output - eigenvalues in increasing order at each data point
391    
392      */
393      ESCRIPT_DLL_API
394      virtual void
395      eigenvalues(DataAbstract* ev);
396    
397      /**
398         \brief
399         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
400    
401         \param ev - Output - eigenvalues in increasing order at each data point
402         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
403                             and the first nonzero component is positive.
404         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
405    
406      */
407    
408      ESCRIPT_DLL_API
409      virtual void
410      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
411    
412   protected:   protected:
413    
414    /**    /**
415       \brief       \brief
416       Set the pointDataView       Set the pointDataView DataArrayView associated with this object.
417       \param right - Input - The point data view. DataAbstract takes ownership  
418         \param input - Input - The point data view. DataAbstract takes ownership
419       of the DataArrayView provided. It will delete it when it is destructed.       of the DataArrayView provided. It will delete it when it is destructed.
420    */    */
421      ESCRIPT_DLL_API
422    void    void
423    setPointDataView(const DataArrayView& input);    setPointDataView(const DataArrayView& input);
424    
425   private:    ESCRIPT_DLL_API
426      void
427      resetPointDataView();
428    
429    int m_noDataPointsPerSample;   private:
430    
431      //
432      // The number of samples in this Data object.
433      // This is derived directly from the FunctionSpace.
434    int m_noSamples;    int m_noSamples;
435    
436    //    //
437    // Provides a view of the data as point data    // The number of data points per sample in this Data object.
438      // This is derived directly from the FunctionSpace.
439      int m_noDataPointsPerSample;
440    
441      //
442      // The DataArrayView of the data array associated with this object.
443      // The data array is defined only in child classes of this class, it
444      // is not defined in this abstract parent class.
445    boost::scoped_ptr<DataArrayView> m_pointDataView;    boost::scoped_ptr<DataArrayView> m_pointDataView;
446    
447    //    //
448    // function space    // A FunctionSpace which provides a description of the data associated
449      // with this Data object.
450    FunctionSpace m_functionSpace;    FunctionSpace m_functionSpace;
451    
452  };  };
# Line 342  DataAbstract::getPointDataView() Line 508  DataAbstract::getPointDataView()
508  {  {
509    return *(m_pointDataView.get());    return *(m_pointDataView.get());
510  }  }
   
511  } // end of namespace  } // end of namespace
512    
513  #endif  #endif

Legend:
Removed from v.110  
changed lines
  Added in v.775

  ViewVC Help
Powered by ViewVC 1.1.26