/[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 82 by jgs, Tue Oct 26 06:53:54 2004 UTC trunk/escript/src/DataAbstract.h revision 615 by elspeth, Wed Mar 22 02:12:00 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    
18  #include "escript/Data/DataException.h"  #include "DataArrayView.h"
19  #include "escript/Data/DataArrayView.h"  #include "DataArray.h"
20  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
21    
 #include <iostream>  
22  #include <boost/scoped_ptr.hpp>  #include <boost/scoped_ptr.hpp>
23  #include <functional>  #include <boost/python/numeric.hpp>
24    
25  #include <string>  #include <string>
26    #include <fstream>
27    
28  namespace escript {  namespace escript {
29    
30  /**  /**
31     \brief     \brief
32     DataAbstract provides an interface for the class of containers     DataAbstract provides an abstract interface for the class of containers
33     which hold ESyS data.     which hold ESyS data.
34    
35     Description:     Description:
36     DataAbstract provides an interface for the class of containers     DataAbstract provides an abstract interface for the class of containers
37     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
38     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
39       and the other to the number of data points per sample as defined by the function
40       space associated with each Data object. The data points themselves are arrays of
41       doubles of rank 0-4.
42  */  */
43    
44  class DataAbstract {  class DataAbstract {
# Line 51  class DataAbstract { Line 54  class DataAbstract {
54    
55       Description:       Description:
56       Constructor for DataAbstract.       Constructor for DataAbstract.
57    
58       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
59    */    */
60    DataAbstract(const FunctionSpace& what);    DataAbstract(const FunctionSpace& what);
# Line 59  class DataAbstract { Line 63  class DataAbstract {
63      \brief      \brief
64      Destructor for DataAbstract.      Destructor for DataAbstract.
65    */    */
66    virtual ~DataAbstract();    virtual
67      ~DataAbstract();
68    
69    /**    /**
70       \brief       \brief
# Line 89  class DataAbstract { Line 94  class DataAbstract {
94       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
95       to manipulate the point data.       to manipulate the point data.
96    */    */
   const DataArrayView&  
   getPointDataView() const;  
   
97    DataArrayView&    DataArrayView&
98    getPointDataView();    getPointDataView();
99    
100      const DataArrayView&
101      getPointDataView() const;
102    
103    /**    /**
104       \brief       \brief
105       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
106       but returns the offset for the given point into the container       point into the container holding the point data. Only really necessary to
107       holding the point data. Only really necessary to avoid many DataArrayView       avoid creating many DataArrayView objects.
108       objects.  
109       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
110       \param dataPointNo - Input - Input.       \param dataPointNo - Input - data point number.
111     */     */
112    virtual    virtual
113    ValueType::size_type    ValueType::size_type
# Line 111  class DataAbstract { Line 116  class DataAbstract {
116    
117    /**    /**
118       \brief       \brief
119       Return the sample data for the given sample no.       Return the sample data for the given sample number.
120    */    */
121    double*    double*
122    getSampleData(ValueType::size_type sampleNo);    getSampleData(ValueType::size_type sampleNo);
123    
124    /**    /**
125       \brief       \brief
126       Return the number of doubles stored for the Data.       Return the number of doubles stored for this Data object.
127    */    */
128    virtual    virtual
129    ValueType::size_type    ValueType::size_type
# Line 135  class DataAbstract { Line 140  class DataAbstract {
140    
141    /**    /**
142       \brief       \brief
143       Check this and the right operands are compatible. Throws       Assign the given value to the data-points(s) referenced by the given
144         reference number.
145    
146         If this Data object cannot be accessed by reference numbers an
147         exception will be thrown.
148    
149         \param ref - Input - reference number.
150         \param value - Input - value to assign to data-points associated with
151                                the given reference number.
152      */
153      virtual
154      void
155      setRefValue(int ref,
156                  const DataArray& value);
157    
158      /**
159         \brief
160         Return the values associated with the data-point(s) referenced by the given
161         reference number.
162    
163         If this Data object cannot be accessed by reference numbers an
164         exception will be thrown.
165    
166         \param ref - Input - reference number.
167         \param value - Output - object to receive data-points associated with
168                                 the given reference number.
169      */
170      virtual
171      void
172      getRefValue(int ref,
173                  DataArray& value);
174    
175      /**
176         \brief
177         Check this and the given RHS operands are compatible. Throws
178       an exception if they aren't.       an exception if they aren't.
179    
180       \param right - Input - The right hand side.       \param right - Input - The right hand side.
181    */    */
182    void    void
# Line 151  class DataAbstract { Line 191  class DataAbstract {
191    
192    /**    /**
193       \brief       \brief
194       Return true if a valid number.       Return true if a valid sample number.
195    */    */
196    bool    bool
197    validSampleNo(int sampleNo) const;    validSampleNo(int sampleNo) const;
# Line 161  class DataAbstract { Line 201  class DataAbstract {
201       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
202       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
203       operation.       operation.
204       \param samplesNo Input  
205       \param dataPointNo Input       \param sampleNo - Input - the sample number.
206         \param dataPointNo - Input - the data point number.
207    */    */
208    virtual    virtual
209    DataArrayView getDataPoint(int samplesNo,    DataArrayView
210                               int dataPointNo) = 0;    getDataPoint(int sampleNo,
211                   int dataPointNo) = 0;
212    
213    /**    /**
214       \brief       \brief
215       Return the function space.       Return the function space associated with this Data object.
216    */    */
217    const FunctionSpace&    const
218      FunctionSpace&
219    getFunctionSpace() const;    getFunctionSpace() const;
220    
221    /**    /**
222       \brief       \brief
223       Return a newly constructed DataAbstract. The caller is responsible for       Return the given slice from this object.
224       managing the object created.  
225         NB: The caller is responsible for managing the object created.
226    */    */
227    virtual    virtual
228    DataAbstract*    DataAbstract*
# Line 186  class DataAbstract { Line 230  class DataAbstract {
230    
231    /**    /**
232       \brief       \brief
233       Copy the specified region from the given value.       Copy the specified region from the given object.
234    
235       \param value - Input - Data to copy from       \param value - Input - Data to copy from
236       \param region - Input - Region to copy.       \param region - Input - Region to copy.
237    */    */
# Line 197  class DataAbstract { Line 242  class DataAbstract {
242    
243    /**    /**
244       \brief       \brief
245       Reshape the data point if the data point is currently rank 0.       Reshape the data points if they are currently rank 0.
246       Will throw an exception if the data points are not rank 0.       Will throw an exception if the data points are not rank 0.
247       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
248       data point.       data point.
249    */    */
250    virtual    virtual
251    void    void
252    reshapeDataPoint(const DataArrayView::ShapeType& shape) = 0;    reshapeDataPoint(const ShapeType& shape) = 0;
253    
254    /**    /**
255       \brief       \brief
# Line 212  class DataAbstract { Line 257  class DataAbstract {
257                                                                                                                                                                                                                                                                        
258       Description:       Description:
259       Assign the given value to the given tag.       Assign the given value to the given tag.
260    
261         NB: If the data isn't tagged an exception will be thrown.
262    
263       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
264       \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.  
265    */    */
266    virtual    virtual
267    void    void
268    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
269                   const DataArrayView& value);                   const DataArrayView& value);
270    
271      /**
272        \brief
273        Archive the underlying data values to the file referenced
274        by ofstream. A count of the number of values expected to be written
275        is provided as a cross-check.
276    
277        The return value indicates success (0) or otherwise (1).
278      */
279      virtual
280      int
281      archiveData(std::ofstream& archiveFile,
282                  const ValueType::size_type noValues) const;
283    
284      /**
285        \brief
286        Extract the number of values specified by noValues from the file
287        referenced by ifstream to the underlying data structure.
288    
289        The return value indicates success (0) or otherwise (1).
290      */
291      virtual
292      int
293      extractData(std::ifstream& archiveFile,
294                  const ValueType::size_type noValues);
295    
296      /**
297         \brief
298         Copy the numarray object to the data points in this object.
299    
300         Description:
301         Copy the numarray object to the data points in this object.
302    
303         \param value Input - new values for the data points
304      */
305      virtual void
306      copyAll(const boost::python::numeric::array& value);
307    
308      /**
309         \brief
310         Return the tag number associated with the given data-point number.
311    
312         If the object cannot be referenced by tag numbers, an exception
313         will be thrown.
314      */
315      virtual
316      int
317      getTagNumber(int dpno);
318    
319      /**
320         \brief
321         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
322    
323         \param ev - Output - eigenvalues in increasing order at each data point
324    
325      */
326      virtual void
327      eigenvalues(DataAbstract* ev);
328    
329      /**
330         \brief
331         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
332    
333         \param ev - Output - eigenvalues in increasing order at each data point
334         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
335                             and the first nonzero component is positive.
336         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
337    
338      */
339    
340      virtual void
341      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
342    
343   protected:   protected:
344    
345    /**    /**
346       \brief       \brief
347       Set the pointDataView       Set the pointDataView DataArrayView associated with this object.
348       \param right - Input - The point data view. DataAbstract takes ownership  
349         \param input - Input - The point data view. DataAbstract takes ownership
350       of the DataArrayView provided. It will delete it when it is destructed.       of the DataArrayView provided. It will delete it when it is destructed.
351    */    */
352    void    void
353    setPointDataView(const DataArrayView& input);    setPointDataView(const DataArrayView& input);
354    
355   private:    void
356      resetPointDataView();
357    
358    int m_noDataPointsPerSample;   private:
359    
360      //
361      // The number of samples in this Data object.
362      // This is derived directly from the FunctionSpace.
363    int m_noSamples;    int m_noSamples;
364    
365    //    //
366    // Provides a view of the data as point data    // The number of data points per sample in this Data object.
367      // This is derived directly from the FunctionSpace.
368      int m_noDataPointsPerSample;
369    
370      //
371      // The DataArrayView of the data array associated with this object.
372      // The data array is defined only in child classes of this class, it
373      // is not defined in this abstract parent class.
374    boost::scoped_ptr<DataArrayView> m_pointDataView;    boost::scoped_ptr<DataArrayView> m_pointDataView;
375    
376    //    //
377    // function space    // A FunctionSpace which provides a description of the data associated
378      // with this Data object.
379    FunctionSpace m_functionSpace;    FunctionSpace m_functionSpace;
380    
381  };  };
382    
383  inline  inline
384  bool  bool
385   DataAbstract::validSamplePointNo(int samplePointNo) const  DataAbstract::validSamplePointNo(int samplePointNo) const
386  {  {
387    return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));    return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
388  }  }
# Line 284  DataAbstract::getNumSamples() const Line 416  DataAbstract::getNumSamples() const
416  }  }
417    
418  inline  inline
419  const FunctionSpace&  const
420    FunctionSpace&
421  DataAbstract::getFunctionSpace() const  DataAbstract::getFunctionSpace() const
422  {  {
423    return m_functionSpace;    return m_functionSpace;
424  }  }
425    
426  inline  inline
427  const DataArrayView&  const
428    DataArrayView&
429  DataAbstract::getPointDataView() const  DataAbstract::getPointDataView() const
430  {  {
431    return *(m_pointDataView.get());    return *(m_pointDataView.get());
# Line 303  DataAbstract::getPointDataView() Line 437  DataAbstract::getPointDataView()
437  {  {
438    return *(m_pointDataView.get());    return *(m_pointDataView.get());
439  }  }
   
440  } // end of namespace  } // end of namespace
441    
442  #endif  #endif

Legend:
Removed from v.82  
changed lines
  Added in v.615

  ViewVC Help
Powered by ViewVC 1.1.26