/[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 2548 by jfenwick, Mon Jul 20 06:20:06 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"  
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 58  class DataExpanded : public DataAbstract Line 57  class DataExpanded : public DataAbstract
57       this data object, where the number of data points is defined by       this data object, where the number of data points is defined by
58       the given function space.       the given function space.
59    
60       \param value - Input - A single data value.       \param value - Input - The value of a single data point.
61       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
62    */    */
63    DataExpanded(const boost::python::numeric::array& value,    ESCRIPT_DLL_API
64                 const FunctionSpace& what);    DataExpanded(const WrappedArray& value,
   
   /**  
      \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,  
65                 const FunctionSpace& what);                 const FunctionSpace& what);
66    
67    /**    /**
# Line 89  class DataExpanded : public DataAbstract Line 72  class DataExpanded : public DataAbstract
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      ESCRIPT_DLL_API
136      bool
137      actsExpanded() const
138      {
139        return true;
140      }
141    
142    /**    /**
143       \brief       \brief
144       Return a textual representation of the data.       Return a textual representation of the data.
145    */    */
146      ESCRIPT_DLL_API
147    virtual    virtual
148    std::string    std::string
149    toString() const;    toString() const;
150    
151    /**    /**
152         \brief Return a deep copy of the current object.
153      */
154      ESCRIPT_DLL_API
155      virtual
156      DataAbstract*
157      deepCopy();
158    
159    
160     /**
161       \brief       \brief
162       Reshape the data point if the data point is currently rank 0.       dumps the object into a netCDF file
      The original data point value is used for all values of the new  
      data point.  
163    */    */
164      ESCRIPT_DLL_API
165      virtual
166      void
167      dump(const std::string fileName) const;
168    
169     /**
170         \brief
171        sets all values to zero
172      */
173      ESCRIPT_DLL_API
174      virtual
175    void    void
176    reshapeDataPoint(const DataArrayView::ShapeType& shape);    setToZero();
177    
178    /**    /**
179       \brief       \brief
# Line 160  class DataExpanded : public DataAbstract Line 184  class DataExpanded : public DataAbstract
184       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
185       \param dataPointNo - Input - data point number.       \param dataPointNo - Input - data point number.
186    */    */
187      ESCRIPT_DLL_API
188    virtual    virtual
189    DataArrayView::ValueType::size_type    DataTypes::ValueType::size_type
190    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
191                   int dataPointNo) const;                   int dataPointNo) const;
192    
193      ESCRIPT_DLL_API
194      virtual
195      DataTypes::ValueType::size_type
196      getPointOffset(int sampleNo,
197                     int dataPointNo);
198    
199    /**    /**
200       \brief       \brief
201       Return a view into the data array for the data point specified.       Return a a reference to the underlying DataVector.
202      */
203    
204      ESCRIPT_DLL_API
205      DataTypes::ValueType&
206      getVectorRW();
207    
208      ESCRIPT_DLL_API
209      const DataTypes::ValueType&
210      getVectorRO() const;
211    
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
212    
      \param sampleNo - Input - sample number.  
      \param dataPointNo - Input - data point number.  
      \return DataArrayView for the data point.  
   */  
   DataArrayView  
   getDataPoint(int sampleNo,  
                int dataPointNo);  
213    
214    /**    /**
215       \brief       \brief
216       Return the number of doubles stored for the Data.       Return the number of doubles stored for the Data.
217    */    */
218      ESCRIPT_DLL_API
219    virtual    virtual
220    ValueType::size_type    ValueType::size_type
221    getLength() const;    getLength() const;
# Line 195  class DataExpanded : public DataAbstract Line 227  class DataExpanded : public DataAbstract
227    
228       \param region - Input - Region to copy.       \param region - Input - Region to copy.
229    */    */
230      ESCRIPT_DLL_API
231    virtual    virtual
232    DataAbstract*    DataAbstract*
233    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
234    
235    /**    /**
236       \brief       \brief
# Line 206  class DataExpanded : public DataAbstract Line 239  class DataExpanded : public DataAbstract
239       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
240       \param region - Input - Region to copy.       \param region - Input - Region to copy.
241    */    */
242      ESCRIPT_DLL_API
243    virtual    virtual
244    void    void
245    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
246             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
247    
248    /**    /**
249       \brief       \brief
250       Assign the given value to all data-points associated with the given       setTaggedValue
251       reference number.  
252         Description:
253         uses tag to set a new value
254    
255         \param tagKey - Input - Integer key.
256         \param pointshape - Input - The shape of the value parameter
257         \param value - Input -
258         \param dataOffset - Input - where in the value parameter to start reading the data point value.
259      */
260      void  
261      setTaggedValue(int tagKey,
262                 const DataTypes::ShapeType& pointshape,
263                     const DataTypes::ValueType& value,
264             int dataOffset=0);
265    
266    
      A reference number corresponds to a sample, and thus to all data-points  
      in that sample.  
267    
268       If the given reference number does not correspond to any sample in this    /**
269       Data object, an exception will be thrown.       \brief
270         Computes a symmetric matrix (A + AT) / 2
271    
272       If the given value is a different shape to this Data object, an exception       \param ev - Output - symmetric matrix
      will be thrown.  
273    
      \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.  
274    */    */
275    virtual    ESCRIPT_DLL_API
276    void    virtual void
277    setRefValue(int ref,    symmetric(DataAbstract* ev);
               const DataArray& value);  
278    
279    /**    /**
280       \brief       \brief
281       Return the value of the first data-point in the sample associated with       Computes a nonsymmetric matrix (A - AT) / 2
      the given reference number.  
282    
283       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.  
284    
285       If the given reference number does not correspond to any sample in this    */
286       Data object, an exception will be thrown.    ESCRIPT_DLL_API
287      virtual void
288      nonsymmetric(DataAbstract* ev);
289    
290      /**
291         \brief
292         Computes the trace of a matrix
293    
294       If the given value is a different shape to this Data object, an exception       \param ev - Output - trace of your matrix
295       will be thrown.       \param axis_offset -
296    
      \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.  
297    */    */
298    virtual    ESCRIPT_DLL_API
299    void    virtual void
300    getRefValue(int ref,    trace(DataAbstract* ev, int axis_offset);
               DataArray& value);  
301    
302    /**    /**
303      \brief       \brief
304      Archive the underlying data values to the file referenced       Transpose each data point of this Data object around the given axis.
     by ofstream. A count of the number of values expected to be written  
     is provided as a cross-check.  
305    
306      The return value indicates success (0) or otherwise (1).       \param ev - Output - transpose of your matrix
307         \param axis_offset -
308    */    */
309    int    ESCRIPT_DLL_API
310    archiveData(std::ofstream& archiveFile,    virtual void
311                const DataArrayView::ValueType::size_type noValues) const;    transpose(DataAbstract* ev, int axis_offset);
312    
313    /**    /**
314      \brief       \brief
315      Extract the number of values specified by noValues from the file       swaps components axis0 and axis1
     referenced by ifstream to the underlying data structure.  
316    
317      The return value indicates success (0) or otherwise (1).       \param ev - Output - swapped components
318         \param axis0
319         \param axis1
320    */    */
321    int    ESCRIPT_DLL_API
322    extractData(std::ifstream& archiveFile,    virtual void
323                const DataArrayView::ValueType::size_type noValues);    swapaxes(DataAbstract* ev, int axis0, int axis1);
324    
325    
326      /**
327         \brief
328         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
329    
330         \param ev - Output - eigenvalues in increasing order at each data point
331    
332      */
333      ESCRIPT_DLL_API
334      virtual void
335      eigenvalues(DataAbstract* ev);
336    
337      /**
338         \brief
339         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
340    
341         \param ev - Output - eigenvalues in increasing order at each data point
342         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
343                             and the first nonzero component is positive.
344         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
345    
346      */
347    
348      ESCRIPT_DLL_API
349      virtual void
350      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
351    
352    /**
353     *      \brief
354     *           reorders data sample ordered by reference_ids to the ordering of the functions space
355     *
356     *                \param reference_ids - Input - reference_ids used for current ordering
357     *                  */
358      ESCRIPT_DLL_API
359      virtual void
360      reorderByReferenceIDs(int *reference_ids);
361    
362    
363    
364   protected:   protected:
365    
# Line 298  class DataExpanded : public DataAbstract Line 376  class DataExpanded : public DataAbstract
376       given shape and number of data points, and creates the corresponding       given shape and number of data points, and creates the corresponding
377       DataArrayView of this data.       DataArrayView of this data.
378    
      \param shape - Input - The shape of the point data.  
379       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
380       \param noDataPointsPerSample - Input - number of data points per sample.       \param noDataPointsPerSample - Input - number of data points per sample.
381    */    */
382    void    void
383    initialise(const DataArrayView::ShapeType& shape,    initialise(int noSamples,
              int noSamples,  
384               int noDataPointsPerSample);               int noDataPointsPerSample);
385    
386    /**    /**
387       \brief       \brief
388       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.
389    
390       Description:       Description:
391       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 393  class DataExpanded : public DataAbstract
393       \param value Input - A single data point value.       \param value Input - A single data point value.
394    */    */
395    void    void
396    copy(const DataArrayView& value);    copy(const DataConstant& value);
397    
398    
399    
400      /**
401         \brief
402         Copy the given data point value to all data points in this object.
403    
404         \param value Input - A single data point value.
405      */
406    
407    void    void
408    copy(const boost::python::numeric::array& value);    copy(const WrappedArray& value);
409    
410    
411      /**
412         \brief
413         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
414    
415         Description:
416         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
417    
418         \param sampleNo Input - sample number
419         \param dataPointNo Input - data point of the sample
420         \param value Input - new values for the data point
421      */
422      ESCRIPT_DLL_API
423      virtual void
424      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
425    
426    
427      /**
428         \brief
429         Copy the value to the data point dataPointNo of sample sampleNo in this object.
430    
431         \param sampleNo Input - sample number
432         \param dataPointNo Input - data point of the sample
433         \param value Input - new values for the data point
434      */
435      ESCRIPT_DLL_API
436      virtual void
437      copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
438    
439    //    //
440    // 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.123  
changed lines
  Added in v.2548

  ViewVC Help
Powered by ViewVC 1.1.26