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

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

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

revision 480 by jgs, Wed Feb 1 05:15:12 2006 UTC revision 2766 by jfenwick, Mon Nov 23 05:10:53 2009 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /*******************************************************
3   ******************************************************************************  *
4   *                                                                            *  * Copyright (c) 2003-2009 by University of Queensland
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *  * Earth Systems Science Computational Center (ESSCC)
6   *                                                                            *  * http://www.uq.edu.au/esscc
7   * This software is the property of ACcESS. No part of this code              *  *
8   * may be copied in any form or by any means without the expressed written    *  * Primary Business: Queensland, Australia
9   * consent of ACcESS.  Copying, use or modification of this software          *  * Licensed under the Open Software License version 3.0
10   * by any unauthorised person is illegal unless that person has a software    *  * http://www.opensource.org/licenses/osl-3.0.php
11   * license agreement with ACcESS.                                             *  *
12   *                                                                            *  *******************************************************/
13   ******************************************************************************  
 */  
14    
15  #if !defined escript_DataExpanded_20040323_H  #if !defined escript_DataExpanded_20040323_H
16  #define escript_DataExpanded_20040323_H  #define escript_DataExpanded_20040323_H
17    #include "system_dep.h"
18    
19  #include "DataAbstract.h"  #include "DataReady.h"
20  #include "DataBlocks2D.h"  #include "DataBlocks2D.h"
 #include "DataArrayView.h"  
   
 #include <boost/python/numeric.hpp>  
21    
22  namespace escript {  namespace escript {
23    
# Line 41  class DataTagged; Line 38  class DataTagged;
38     template must satisfy.     template must satisfy.
39  */  */
40    
41  class DataExpanded : public DataAbstract {  class DataExpanded : public DataReady {
42    
43    typedef DataReady parent;
44    
45   public:   public:
46    
# Line 56  class DataExpanded : public DataAbstract Line 55  class DataExpanded : public DataAbstract
55       this data object, where the number of data points is defined by       this data object, where the number of data points is defined by
56       the given function space.       the given function space.
57    
58       \param value - Input - A single data value.       \param value - Input - The value of a single data point.
      \param what - Input - A description of what this data represents.  
   */  
   DataExpanded(const boost::python::numeric::array& value,  
                const FunctionSpace& what);  
   
   /**  
      \brief  
      Alternative constructor for DataExpanded.  
   
      Description:  
      Alternative Constructor for DataExpanded.  
   
      The given single data value is copied to all the data points in  
      this data object, where the number of data points is defined by  
      the given function space.  
   
      \param value - Input - A single data value.  
59       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
60    */    */
61    DataExpanded(const DataArrayView& value,    ESCRIPT_DLL_API
62      DataExpanded(const WrappedArray& value,
63                 const FunctionSpace& what);                 const FunctionSpace& what);
64    
65    /**    /**
# Line 87  class DataExpanded : public DataAbstract Line 70  class DataExpanded : public DataAbstract
70       \param other - Input - DataExpanded object to slice from.       \param other - Input - DataExpanded object to slice from.
71       \param region - Input - region to copy.       \param region - Input - region to copy.
72    */    */
73      ESCRIPT_DLL_API
74    DataExpanded(const DataExpanded& other,    DataExpanded(const DataExpanded& other,
75                 const DataArrayView::RegionType& region);                 const DataTypes::RegionType& region);
76    
77    /**    /**
78       \brief       \brief
# Line 99  class DataExpanded : public DataAbstract Line 83  class DataExpanded : public DataAbstract
83       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
84       \param shape - Input - the shape of each data-point.       \param shape - Input - the shape of each data-point.
85       \param data - the array of data values for the data-points.       \param data - the array of data values for the data-points.
86    
87    TODO Note that this constructor will also copy data to all points if it only contains enough elements to hold a single point.  ie this is the merge of two separate constructors.
88    */    */
89      ESCRIPT_DLL_API
90    DataExpanded(const FunctionSpace& what,    DataExpanded(const FunctionSpace& what,
91                 const DataArrayView::ShapeType &shape,                 const DataTypes::ShapeType &shape,
92                 const DataArrayView::ValueType &data);                 const DataTypes::ValueType &data);
93    
94    /**    /**
95       \brief       \brief
96       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
97       Performs a deep copy from another DataExpanded.       Performs a deep copy from another DataExpanded.
98    */    */
99      ESCRIPT_DLL_API
100    DataExpanded(const DataExpanded& other);    DataExpanded(const DataExpanded& other);
101    
102    /**    /**
# Line 116  class DataExpanded : public DataAbstract Line 104  class DataExpanded : public DataAbstract
104       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
105       Construct a DataExpanded from a DataConstant.       Construct a DataExpanded from a DataConstant.
106    */    */
107      ESCRIPT_DLL_API
108    DataExpanded(const DataConstant& other);    DataExpanded(const DataConstant& other);
109    
110    /**    /**
# Line 123  class DataExpanded : public DataAbstract Line 112  class DataExpanded : public DataAbstract
112       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
113       Construct a DataExpanded from a DataTagged.       Construct a DataExpanded from a DataTagged.
114    */    */
115      ESCRIPT_DLL_API
116    DataExpanded(const DataTagged& other);    DataExpanded(const DataTagged& other);
117    
118    /**    /**
119       \brief       \brief
120       Default destructor for DataExpanded.       Default destructor for DataExpanded.
121    */    */
122      ESCRIPT_DLL_API
123    virtual    virtual
124    ~DataExpanded();    ~DataExpanded();
125    
126      ESCRIPT_DLL_API
127      bool
128      isExpanded() const
129      {
130        return true;
131      };
132    
133      ESCRIPT_DLL_API
134      bool
135      actsExpanded() const
136      {
137        return true;
138      }
139    
140      /**
141      \brief Return true if any value in the data contains a NaN.
142      */
143      ESCRIPT_DLL_API
144      bool
145      hasNaN() const;
146    
147    /**    /**
148       \brief       \brief
149       Return a textual representation of the data.       Return a textual representation of the data.
150    */    */
151      ESCRIPT_DLL_API
152    virtual    virtual
153    std::string    std::string
154    toString() const;    toString() const;
155    
156    /**    /**
157         \brief Return a deep copy of the current object.
158      */
159      ESCRIPT_DLL_API
160      virtual
161      DataAbstract*
162      deepCopy();
163    
164    
165     /**
166         \brief
167         dumps the object into a netCDF file
168      */
169      ESCRIPT_DLL_API
170      virtual
171      void
172      dump(const std::string fileName) const;
173    
174    
175      /**
176        \brief invert square matricies
177        \param out - Where to store the results
178      */
179      ESCRIPT_DLL_API
180      virtual void
181      matrixInverse(DataAbstract* out) const;
182    
183     /**
184       \brief       \brief
185       Reshape the data point if the data point is currently rank 0.      sets all values to zero
      The original data point value is used for all values of the new  
      data point.  
186    */    */
187      ESCRIPT_DLL_API
188      virtual
189    void    void
190    reshapeDataPoint(const DataArrayView::ShapeType& shape);    setToZero();
191    
192    /**    /**
193       \brief       \brief
# Line 158  class DataExpanded : public DataAbstract Line 198  class DataExpanded : public DataAbstract
198       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
199       \param dataPointNo - Input - data point number.       \param dataPointNo - Input - data point number.
200    */    */
201      ESCRIPT_DLL_API
202    virtual    virtual
203    DataArrayView::ValueType::size_type    DataTypes::ValueType::size_type
204    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
205                   int dataPointNo) const;                   int dataPointNo) const;
206    
207      ESCRIPT_DLL_API
208      virtual
209      DataTypes::ValueType::size_type
210      getPointOffset(int sampleNo,
211                     int dataPointNo);
212    
213    /**    /**
214       \brief       \brief
215       Return a view into the data array for the data point specified.       Return a a reference to the underlying DataVector.
216      */
217    
218      ESCRIPT_DLL_API
219      DataTypes::ValueType&
220      getVectorRW();
221    
222      ESCRIPT_DLL_API
223      const DataTypes::ValueType&
224      getVectorRO() const;
225    
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
226    
      \param sampleNo - Input - sample number.  
      \param dataPointNo - Input - data point number.  
      \return DataArrayView for the data point.  
   */  
   DataArrayView  
   getDataPoint(int sampleNo,  
                int dataPointNo);  
227    
228    /**    /**
229       \brief       \brief
230       Return the number of doubles stored for the Data.       Return the number of doubles stored for the Data.
231    */    */
232      ESCRIPT_DLL_API
233    virtual    virtual
234    ValueType::size_type    ValueType::size_type
235    getLength() const;    getLength() const;
# Line 193  class DataExpanded : public DataAbstract Line 241  class DataExpanded : public DataAbstract
241    
242       \param region - Input - Region to copy.       \param region - Input - Region to copy.
243    */    */
244      ESCRIPT_DLL_API
245    virtual    virtual
246    DataAbstract*    DataAbstract*
247    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
248    
249    /**    /**
250       \brief       \brief
# Line 204  class DataExpanded : public DataAbstract Line 253  class DataExpanded : public DataAbstract
253       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
254       \param region - Input - Region to copy.       \param region - Input - Region to copy.
255    */    */
256      ESCRIPT_DLL_API
257    virtual    virtual
258    void    void
259    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
260             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
261    
262    /**    /**
263       \brief       \brief
264       Assign the given value to all data-points associated with the given       setTaggedValue
      reference number.  
265    
266       A reference number corresponds to a sample, and thus to all data-points       Description:
267       in that sample.       uses tag to set a new value
268    
269         \param tagKey - Input - Integer key.
270         \param pointshape - Input - The shape of the value parameter
271         \param value - Input -
272         \param dataOffset - Input - where in the value parameter to start reading the data point value.
273      */
274      void  
275      setTaggedValue(int tagKey,
276                 const DataTypes::ShapeType& pointshape,
277                     const DataTypes::ValueType& value,
278             int dataOffset=0);
279    
      If the given reference number does not correspond to any sample in this  
      Data object, an exception will be thrown.  
280    
      If the given value is a different shape to this Data object, an exception  
      will be thrown.  
281    
282       \param ref - Input - reference number which determines sample numebr to    /**
283                            assign given values to.       \brief
284       \param value - Input - Value to assign to data-point associated with       Computes a symmetric matrix (A + AT) / 2
285                              the given reference number.  
286         \param ev - Output - symmetric matrix
287    
288    */    */
289    virtual    ESCRIPT_DLL_API
290    void    virtual void
291    setRefValue(int ref,    symmetric(DataAbstract* ev);
               const DataArray& value);  
292    
293    /**    /**
294       \brief       \brief
295       Return the value of the first data-point in the sample associated with       Computes a nonsymmetric matrix (A - AT) / 2
      the given reference number.  
296    
297       A reference number corresponds to a sample, and thus to all data-points       \param ev - Output - nonsymmetric matrix
      in that sample. If there is more than one data-point per sample number  
      in this Data object, the value of the first data-point will be returned.  
298    
299       If the given reference number does not correspond to any sample in this    */
300       Data object, an exception will be thrown.    ESCRIPT_DLL_API
301      virtual void
302      nonsymmetric(DataAbstract* ev);
303    
304      /**
305         \brief
306         Computes the trace of a matrix
307    
308       If the given value is a different shape to this Data object, an exception       \param ev - Output - trace of your matrix
309       will be thrown.       \param axis_offset -
310    
      \param ref - Input - reference number which determines sample number to  
                           read from.  
      \param value - Output - Object to receive data-points associated with  
                             the given reference number.  
311    */    */
312    virtual    ESCRIPT_DLL_API
313    void    virtual void
314    getRefValue(int ref,    trace(DataAbstract* ev, int axis_offset);
315                DataArray& value);  
316      /**
317         \brief
318         Transpose each data point of this Data object around the given axis.
319    
320         \param ev - Output - transpose of your matrix
321         \param axis_offset -
322      */
323      ESCRIPT_DLL_API
324      virtual void
325      transpose(DataAbstract* ev, int axis_offset);
326    
327      /**
328         \brief
329         swaps components axis0 and axis1
330    
331         \param ev - Output - swapped components
332         \param axis0
333         \param axis1
334      */
335      ESCRIPT_DLL_API
336      virtual void
337      swapaxes(DataAbstract* ev, int axis0, int axis1);
338    
339    
340    /**    /**
341      \brief       \brief
342      Archive the underlying data values to the file referenced       solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
343      by ofstream. A count of the number of values expected to be written  
344      is provided as a cross-check.       \param ev - Output - eigenvalues in increasing order at each data point
345    
     The return value indicates success (0) or otherwise (1).  
346    */    */
347    int    ESCRIPT_DLL_API
348    archiveData(std::ofstream& archiveFile,    virtual void
349                const DataArrayView::ValueType::size_type noValues) const;    eigenvalues(DataAbstract* ev);
350    
351    /**    /**
352      \brief       \brief
353      Extract the number of values specified by noValues from the file       solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
354      referenced by ifstream to the underlying data structure.  
355         \param ev - Output - eigenvalues in increasing order at each data point
356         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
357                             and the first nonzero component is positive.
358         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
359    
     The return value indicates success (0) or otherwise (1).  
360    */    */
361    int  
362    extractData(std::ifstream& archiveFile,    ESCRIPT_DLL_API
363                const DataArrayView::ValueType::size_type noValues);    virtual void
364      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
365    
366    /**
367     *      \brief
368     *           reorders data sample ordered by reference_ids to the ordering of the functions space
369     *
370     *                \param reference_ids - Input - reference_ids used for current ordering
371     *                  */
372      ESCRIPT_DLL_API
373      virtual void
374      reorderByReferenceIDs(int *reference_ids);
375    
376    
377    
378   protected:   protected:
379    
# Line 296  class DataExpanded : public DataAbstract Line 390  class DataExpanded : public DataAbstract
390       given shape and number of data points, and creates the corresponding       given shape and number of data points, and creates the corresponding
391       DataArrayView of this data.       DataArrayView of this data.
392    
      \param shape - Input - The shape of the point data.  
393       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
394       \param noDataPointsPerSample - Input - number of data points per sample.       \param noDataPointsPerSample - Input - number of data points per sample.
395    */    */
396    void    void
397    initialise(const DataArrayView::ShapeType& shape,    initialise(int noSamples,
              int noSamples,  
398               int noDataPointsPerSample);               int noDataPointsPerSample);
399    
400    /**    /**
# Line 315  class DataExpanded : public DataAbstract Line 407  class DataExpanded : public DataAbstract
407       \param value Input - A single data point value.       \param value Input - A single data point value.
408    */    */
409    void    void
410    copy(const DataArrayView& value);    copy(const DataConstant& value);
411    
412    
413    
414    /**    /**
415       \brief       \brief
416       Copy the given data point value given a numarray object to all data points in this object.       Copy the given data point value to all data points in this object.
   
      Description:  
      Copy the given data point value given a numarray object to all data points in this object.  
417    
418       \param value Input - A single data point value.       \param value Input - A single data point value.
419    */    */
420    
421    void    void
422    copy(const boost::python::numeric::array& value);    copy(const WrappedArray& value);
423    
424    
425    /**    /**
426       \brief       \brief
427       Copy the numarray object to the data points in this object.       Copy a double value to the data point dataPointNo of sample sampleNo in this object.
428    
429       Description:       Description:
430       Copy the numarray object to the data points in this object.       Copy a double value to the data point dataPointNo of sample sampleNo in this object.
431    
432       \param value Input - new values for the data points       \param sampleNo Input - sample number
433         \param dataPointNo Input - data point of the sample
434         \param value Input - new values for the data point
435    */    */
436    void    ESCRIPT_DLL_API
437    copyAll(const boost::python::numeric::array& value);    virtual void
438      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
439    
440    
441      /**
442         \brief
443         Copy the value to the data point dataPointNo of sample sampleNo in this object.
444    
445         \param sampleNo Input - sample number
446         \param dataPointNo Input - data point of the sample
447         \param value Input - new values for the data point
448      */
449      ESCRIPT_DLL_API
450      virtual void
451      copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
452    
453    //    //
454    // The main data storage array, a 2D array of data blocks.    // The main data storage array, a 2D array of data blocks.

Legend:
Removed from v.480  
changed lines
  Added in v.2766

  ViewVC Help
Powered by ViewVC 1.1.26