/[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

trunk/esys2/escript/src/Data/DataExpanded.h revision 123 by jgs, Fri Jul 8 04:08:13 2005 UTC trunk/escript/src/DataExpanded.h revision 2005 by jfenwick, Mon Nov 10 01:21:39 2008 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /*******************************************************
3   ******************************************************************************  *
4   *                                                                            *  * Copyright (c) 2003-2008 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"  
21    
 #include <boost/scoped_ptr.hpp>  
22  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
23    
24  namespace escript {  namespace escript {
25    
26  //  //
27  // Forward declarations of other Data types.  // Forward declarations of other Data types.
 class DataEmpty;  
28  class DataConstant;  class DataConstant;
29  class DataTagged;  class DataTagged;
30    
# Line 43  class DataTagged; Line 40  class DataTagged;
40     template must satisfy.     template must satisfy.
41  */  */
42    
43  class DataExpanded : public DataAbstract {  class DataExpanded : public DataReady {
44    
45    typedef DataReady parent;
46    
47   public:   public:
48    
# Line 61  class DataExpanded : public DataAbstract Line 60  class DataExpanded : public DataAbstract
60       \param value - Input - A single data value.       \param value - Input - A single data value.
61       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
62    */    */
63      ESCRIPT_DLL_API
64    DataExpanded(const boost::python::numeric::array& value,    DataExpanded(const boost::python::numeric::array& value,
65                 const FunctionSpace& what);                 const FunctionSpace& what);
66    
67    /**    /**
68       \brief       \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.  
      \param what - Input - A description of what this data represents.  
   */  
   DataExpanded(const DataArrayView& value,  
                const FunctionSpace& what);  
   
   /**  
      \brief  
69       Alternative constructor for DataExpanded that copies a slice from       Alternative constructor for DataExpanded that copies a slice from
70       another DataExpanded.       another DataExpanded.
71    
72       \param other - Input - DataExpanded object to slice from.       \param other - Input - DataExpanded object to slice from.
73       \param region - Input - region to copy.       \param region - Input - region to copy.
74    */    */
75      ESCRIPT_DLL_API
76    DataExpanded(const DataExpanded& other,    DataExpanded(const DataExpanded& other,
77                 const DataArrayView::RegionType& region);                 const DataTypes::RegionType& region);
78    
79    /**    /**
80       \brief       \brief
# Line 101  class DataExpanded : public DataAbstract Line 85  class DataExpanded : public DataAbstract
85       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
86       \param shape - Input - the shape of each data-point.       \param shape - Input - the shape of each data-point.
87       \param data - the array of data values for the data-points.       \param data - the array of data values for the data-points.
88    
89    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.
90    */    */
91      ESCRIPT_DLL_API
92    DataExpanded(const FunctionSpace& what,    DataExpanded(const FunctionSpace& what,
93                 const DataArrayView::ShapeType &shape,                 const DataTypes::ShapeType &shape,
94                 const DataArrayView::ValueType &data);                 const DataTypes::ValueType &data);
95    
96    /**    /**
97       \brief       \brief
98       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
99       Performs a deep copy from another DataExpanded.       Performs a deep copy from another DataExpanded.
100    */    */
101      ESCRIPT_DLL_API
102    DataExpanded(const DataExpanded& other);    DataExpanded(const DataExpanded& other);
103    
104    /**    /**
# Line 118  class DataExpanded : public DataAbstract Line 106  class DataExpanded : public DataAbstract
106       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
107       Construct a DataExpanded from a DataConstant.       Construct a DataExpanded from a DataConstant.
108    */    */
109      ESCRIPT_DLL_API
110    DataExpanded(const DataConstant& other);    DataExpanded(const DataConstant& other);
111    
112    /**    /**
# Line 125  class DataExpanded : public DataAbstract Line 114  class DataExpanded : public DataAbstract
114       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
115       Construct a DataExpanded from a DataTagged.       Construct a DataExpanded from a DataTagged.
116    */    */
117      ESCRIPT_DLL_API
118    DataExpanded(const DataTagged& other);    DataExpanded(const DataTagged& other);
119    
120    /**    /**
121       \brief       \brief
122       Default destructor for DataExpanded.       Default destructor for DataExpanded.
123    */    */
124      ESCRIPT_DLL_API
125    virtual    virtual
126    ~DataExpanded();    ~DataExpanded();
127    
128      ESCRIPT_DLL_API
129      bool
130      isExpanded() const
131      {
132        return true;
133      };
134    
135    /**    /**
136       \brief       \brief
137       Return a textual representation of the data.       Return a textual representation of the data.
138    */    */
139      ESCRIPT_DLL_API
140    virtual    virtual
141    std::string    std::string
142    toString() const;    toString() const;
143    
144    /**    /**
145         \brief Return a deep copy of the current object.
146      */
147      ESCRIPT_DLL_API
148      virtual
149      DataAbstract*
150      deepCopy();
151    
152    
153     /**
154         \brief
155         dumps the object into a netCDF file
156      */
157      ESCRIPT_DLL_API
158      virtual
159      void
160      dump(const std::string fileName) const;
161    
162     /**
163       \brief       \brief
164       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.  
165    */    */
166      ESCRIPT_DLL_API
167      virtual
168    void    void
169    reshapeDataPoint(const DataArrayView::ShapeType& shape);    setToZero();
170    
171    /**    /**
172       \brief       \brief
# Line 160  class DataExpanded : public DataAbstract Line 177  class DataExpanded : public DataAbstract
177       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
178       \param dataPointNo - Input - data point number.       \param dataPointNo - Input - data point number.
179    */    */
180      ESCRIPT_DLL_API
181    virtual    virtual
182    DataArrayView::ValueType::size_type    DataTypes::ValueType::size_type
183    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
184                   int dataPointNo) const;                   int dataPointNo) const;
185    
186      ESCRIPT_DLL_API
187      virtual
188      DataTypes::ValueType::size_type
189      getPointOffset(int sampleNo,
190                     int dataPointNo);
191    
192    /**    /**
193       \brief       \brief
194       Return a view into the data array for the data point specified.       Return a a reference to the underlying DataVector.
195      */
196    
197       NOTE: Construction of the DataArrayView is a relatively expensive    ESCRIPT_DLL_API
198       operation.    DataTypes::ValueType&
199      getVector();
200    
201      ESCRIPT_DLL_API
202      const DataTypes::ValueType&
203      getVector() const;
204    
      \param sampleNo - Input - sample number.  
      \param dataPointNo - Input - data point number.  
      \return DataArrayView for the data point.  
   */  
   DataArrayView  
   getDataPoint(int sampleNo,  
                int dataPointNo);  
205    
206    /**    /**
207       \brief       \brief
208       Return the number of doubles stored for the Data.       Return the number of doubles stored for the Data.
209    */    */
210      ESCRIPT_DLL_API
211    virtual    virtual
212    ValueType::size_type    ValueType::size_type
213    getLength() const;    getLength() const;
# Line 195  class DataExpanded : public DataAbstract Line 219  class DataExpanded : public DataAbstract
219    
220       \param region - Input - Region to copy.       \param region - Input - Region to copy.
221    */    */
222      ESCRIPT_DLL_API
223    virtual    virtual
224    DataAbstract*    DataAbstract*
225    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
226    
227    /**    /**
228       \brief       \brief
# Line 206  class DataExpanded : public DataAbstract Line 231  class DataExpanded : public DataAbstract
231       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
232       \param region - Input - Region to copy.       \param region - Input - Region to copy.
233    */    */
234      ESCRIPT_DLL_API
235    virtual    virtual
236    void    void
237    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
238             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
239    
240    /**    /**
241       \brief       \brief
242       Assign the given value to all data-points associated with the given       setTaggedValue
243       reference number.  
244         Description:
245         uses tag to set a new value
246    
247         \param tagKey - Input - Integer key.
248         \param pointshape - Input - The shape of the value parameter
249         \param value - Input - .
250      */
251      void  
252      setTaggedValue(int tagKey,
253                 const DataTypes::ShapeType& pointshape,
254                     const DataTypes::ValueType& value,
255             int dataOffset=0);
256    
      A reference number corresponds to a sample, and thus to all data-points  
      in that sample.  
257    
      If the given reference number does not correspond to any sample in this  
      Data object, an exception will be thrown.  
258    
259       If the given value is a different shape to this Data object, an exception    /**
260       will be thrown.       \brief
261         Computes a symmetric matrix (A + AT) / 2
262    
263         \param ev - Output - symmetric matrix
264    
      \param ref - Input - reference number which determines sample numebr to  
                           assign given values to.  
      \param value - Input - Value to assign to data-point associated with  
                             the given reference number.  
265    */    */
266    virtual    ESCRIPT_DLL_API
267    void    virtual void
268    setRefValue(int ref,    symmetric(DataAbstract* ev);
               const DataArray& value);  
269    
270    /**    /**
271       \brief       \brief
272       Return the value of the first data-point in the sample associated with       Computes a nonsymmetric matrix (A - AT) / 2
      the given reference number.  
273    
274       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.  
275    
276       If the given reference number does not correspond to any sample in this    */
277       Data object, an exception will be thrown.    ESCRIPT_DLL_API
278      virtual void
279      nonsymmetric(DataAbstract* ev);
280    
281      /**
282         \brief
283         Computes the trace of a matrix
284    
285       If the given value is a different shape to this Data object, an exception       \param ev - Output - trace of your matrix
      will be thrown.  
286    
      \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.  
287    */    */
288    virtual    ESCRIPT_DLL_API
289    void    virtual void
290    getRefValue(int ref,    trace(DataAbstract* ev, int axis_offset);
               DataArray& value);  
291    
292    /**    /**
293      \brief       \brief
294      Archive the underlying data values to the file referenced       Transpose each data point of this Data object around the given axis.
295      by ofstream. A count of the number of values expected to be written  
296      is provided as a cross-check.       \param ev - Output - transpose of your matrix
297    
298      */
299      ESCRIPT_DLL_API
300      virtual void
301      transpose(DataAbstract* ev, int axis_offset);
302    
303      /**
304         \brief
305         swaps components axis0 and axis1
306    
307         \param ev - Output - swapped components
308    
309      */
310      ESCRIPT_DLL_API
311      virtual void
312      swapaxes(DataAbstract* ev, int axis0, int axis1);
313    
314    
315      /**
316         \brief
317         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
318    
319         \param ev - Output - eigenvalues in increasing order at each data point
320    
     The return value indicates success (0) or otherwise (1).  
321    */    */
322    int    ESCRIPT_DLL_API
323    archiveData(std::ofstream& archiveFile,    virtual void
324                const DataArrayView::ValueType::size_type noValues) const;    eigenvalues(DataAbstract* ev);
325    
326    /**    /**
327      \brief       \brief
328      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
329      referenced by ifstream to the underlying data structure.  
330         \param ev - Output - eigenvalues in increasing order at each data point
331         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
332                             and the first nonzero component is positive.
333         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
334    
     The return value indicates success (0) or otherwise (1).  
335    */    */
336    int  
337    extractData(std::ifstream& archiveFile,    ESCRIPT_DLL_API
338                const DataArrayView::ValueType::size_type noValues);    virtual void
339      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
340    
341    /**
342     *      \brief
343     *           reorders data sample ordered by reference_ids to the ordering of the functions space
344     *
345     *                \param reference_ids - Input - reference_ids used for current ordering
346     *                  */
347      ESCRIPT_DLL_API
348      virtual void
349      reorderByReferenceIDs(int *reference_ids);
350    
351    
352    
353   protected:   protected:
354    
# Line 298  class DataExpanded : public DataAbstract Line 365  class DataExpanded : public DataAbstract
365       given shape and number of data points, and creates the corresponding       given shape and number of data points, and creates the corresponding
366       DataArrayView of this data.       DataArrayView of this data.
367    
      \param shape - Input - The shape of the point data.  
368       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
369       \param noDataPointsPerSample - Input - number of data points per sample.       \param noDataPointsPerSample - Input - number of data points per sample.
370    */    */
371    void    void
372    initialise(const DataArrayView::ShapeType& shape,    initialise(int noSamples,
              int noSamples,  
373               int noDataPointsPerSample);               int noDataPointsPerSample);
374    
375    /**    /**
376       \brief       \brief
377       Copy the given data point to all data points in this object.       Copy the given data point value to all data points in this object.
378    
379       Description:       Description:
380       Copy the given data point to all data points in this object.       Copy the given data point to all data points in this object.
# Line 317  class DataExpanded : public DataAbstract Line 382  class DataExpanded : public DataAbstract
382       \param value Input - A single data point value.       \param value Input - A single data point value.
383    */    */
384    void    void
385    copy(const DataArrayView& value);    copy(const DataConstant& value);
386    
387    
388    
389      /**
390         \brief
391         Copy the given data point value given a numarray object to all data points in this object.
392    
393         Description:
394         Copy the given data point value given a numarray object to all data points in this object.
395    
396         \param value Input - A single data point value.
397      */
398    void    void
399    copy(const boost::python::numeric::array& value);    copy(const boost::python::numeric::array& value);
400    
401      /**
402         \brief
403         Copy the numarray object to the data points in this object.
404    
405         Description:
406         Copy the numarray object to the data points in this object.
407    
408         \param value Input - new values for the data points
409      */
410      void
411      copyAll(const boost::python::numeric::array& value);
412    
413      /**
414         \brief
415         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
416    
417         Description:
418         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
419    
420         \param sampleNo Input - sample number
421         \param dataPointNo Input - data point of the sample
422         \param value Input - new values for the data point
423      */
424      ESCRIPT_DLL_API
425      virtual void
426      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
427    
428    
429      /**
430         \brief
431         Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
432    
433         Description:
434         Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
435    
436         \param sampleNo Input - sample number
437         \param dataPointNo Input - data point of the sample
438         \param value Input - new values for the data point
439      */
440      void
441      copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
442    
443    //    //
444    // The main data storage array, a 2D array of data blocks.    // The main data storage array, a 2D array of data blocks.
445    // noSamples * noDataPointsPerSample    // noSamples * noDataPointsPerSample

Legend:
Removed from v.123  
changed lines
  Added in v.2005

  ViewVC Help
Powered by ViewVC 1.1.26