/[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 110 by jgs, Mon Feb 14 04:14:42 2005 UTC trunk/escript/src/DataExpanded.h revision 2881 by jfenwick, Thu Jan 28 02:03:15 2010 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /*******************************************************
3   ******************************************************************************  *
4   *                                                                            *  * Copyright (c) 2003-2010 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/scoped_ptr.hpp>  
 #include <boost/python/numeric.hpp>  
21    
22  namespace escript {  namespace escript {
23    
24  class DataEmpty;  //
25    // Forward declarations of other Data types.
26  class DataConstant;  class DataConstant;
27  class DataTagged;  class DataTagged;
28    
# Line 34  class DataTagged; Line 31  class DataTagged;
31     Give a short description of what DataExpanded does.     Give a short description of what DataExpanded does.
32    
33     Description:     Description:
34     Give a detailed description of DataExpanded     Give a detailed description of DataExpanded.
35    
36     Template Parameters:     Template Parameters:
37     For templates describe any conditions that the parameters used in the     For templates describe any conditions that the parameters used in the
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    
47    /**    /**
48       \brief       \brief
49       Copy constructor for DataExpanded. Performs a deep copy.       Constructor for DataExpanded.
   */  
   DataExpanded(const DataExpanded& other);  
50    
51    /**       Description:
52       \brief       Constructor for DataExpanded.
53       Construct a DataExpanded from a DataConstant.  
54         The given single data value is copied to all the data points in
55         this data object, where the number of data points is defined by
56         the given function space.
57    
58         \param value - Input - The value of a single data point.
59         \param what - Input - A description of what this data represents.
60    */    */
61    DataExpanded(const DataConstant& other);    ESCRIPT_DLL_API
62      DataExpanded(const WrappedArray& value,
63                   const FunctionSpace& what);
64    
65    /**    /**
66       \brief       \brief
67       Construct a DataExpanded from a DataTagged.       Alternative constructor for DataExpanded that copies a slice from
68         another DataExpanded.
69    
70         \param other - Input - DataExpanded object to slice from.
71         \param region - Input - region to copy.
72    */    */
73    DataExpanded(const DataTagged& other);    ESCRIPT_DLL_API
74      DataExpanded(const DataExpanded& other,
75                   const DataTypes::RegionType& region);
76    
77    /**    /**
78       \brief       \brief
79       Constructor for DataExpanded       Alternative constructor for DataExpanded objects.
80    
81       Description:       Description:
82       Constructor for DataExpanded       Alternative Constructor for DataExpanded objects.
83       \param value - Input - Data value for a single point.       \param what - Input - A description of what this data object represents.
84       \param what - Input - A description of what this data represents.       \param shape - Input - the shape of each data-point.
85         \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    DataExpanded(const boost::python::numeric::array& value,    ESCRIPT_DLL_API
90                 const FunctionSpace& what);    DataExpanded(const FunctionSpace& what,
91                   const DataTypes::ShapeType &shape,
92                   const DataTypes::ValueType &data);
93    
94    /**    /**
95       \brief       \brief
96       Alternative constructor for DataExpanded       Copy constructor for DataExpanded.
97         Performs a deep copy from another DataExpanded.
      Description:  
      Alternative Constructor for DataExpanded.  
      \param value - Input - Data value for a single point.  
      \param what - Input - A description of what this data represents.  
   
98    */    */
99    DataExpanded(const DataArrayView& value,    ESCRIPT_DLL_API
100                 const FunctionSpace& what);    DataExpanded(const DataExpanded& other);
101    
102    /**    /**
103       \brief       \brief
104       Alternative constructor for DataExpanded that copies a slice from       Copy constructor for DataExpanded.
105       another DataExpanded.       Construct a DataExpanded from a DataConstant.
106      */
107      ESCRIPT_DLL_API
108      DataExpanded(const DataConstant& other);
109    
110       \param other - Input - DataExpanded object to slice from.    /**
111       \param region - Input - region to copy.       \brief
112         Copy constructor for DataExpanded.
113         Construct a DataExpanded from a DataTagged.
114    */    */
115    DataExpanded(const DataExpanded& other,    ESCRIPT_DLL_API
116                 const DataArrayView::RegionType& region);    DataExpanded(const DataTagged& other);
117    
118    /**    /**
119       \brief       \brief
120       Destructor       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        \return errorcode (0 indicates success)
179      */
180      ESCRIPT_DLL_API
181      virtual int
182      matrixInverse(DataAbstract* out) const;
183    
184     /**
185       \brief       \brief
186       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.  
187    */    */
188      ESCRIPT_DLL_API
189      virtual
190    void    void
191    reshapeDataPoint(const DataArrayView::ShapeType& shape);    setToZero();
192    
193    /**    /**
194       \brief       \brief
195       Return the offset for the given sample. This is somewhat artificial notion       Return the offset for the given given data point. This returns
196       but returns the offset in bytes for the given point into the container       the offset in bytes for the given point into the container
197       holding the point data.       holding the point data.
198       \param sampleNo - Input - number of samples.  
199       \param dataPointNo - Input - Input.       \param sampleNo - Input - sample number.
200         \param dataPointNo - Input - data point number.
201    */    */
202      ESCRIPT_DLL_API
203    virtual    virtual
204    DataArrayView::ValueType::size_type    DataTypes::ValueType::size_type
205    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
206                   int dataPointNo) const;                   int dataPointNo) const;
207    
208      ESCRIPT_DLL_API
209      virtual
210      DataTypes::ValueType::size_type
211      getPointOffset(int sampleNo,
212                     int dataPointNo);
213    
214    /**    /**
215       \brief       \brief
216       Return a view into the data for the data point specified.       Return a a reference to the underlying DataVector.
217       NOTE: Construction of the DataArrayView is a relatively expensive    */
218       operation.  
219       \param sampleNo - Input    ESCRIPT_DLL_API
220       \param dataPointNo - Input    DataTypes::ValueType&
221       \return DataArrayView of the data point.    getVectorRW();
222    */  
223    DataArrayView    ESCRIPT_DLL_API
224    getDataPoint(int sampleNo,    const DataTypes::ValueType&
225                 int dataPointNo);    getVectorRO() const;
226    
227    
228    
229    /**    /**
230       \brief       \brief
231       Return the number of doubles stored for the Data.       Return the number of doubles stored for the Data.
232    */    */
233      ESCRIPT_DLL_API
234    virtual    virtual
235    ValueType::size_type    ValueType::size_type
236    getLength() const;    getLength() const;
# Line 161  class DataExpanded : public DataAbstract Line 239  class DataExpanded : public DataAbstract
239       \brief       \brief
240       Factory method that returns a newly created DataExpanded.       Factory method that returns a newly created DataExpanded.
241       The caller is reponsible for managing the object created.       The caller is reponsible for managing the object created.
242    
243       \param region - Input - Region to copy.       \param region - Input - Region to copy.
244    */    */
245      ESCRIPT_DLL_API
246    virtual    virtual
247    DataAbstract*    DataAbstract*
248    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
249    
250    /**    /**
251       \brief       \brief
252       Copy the specified region from the given value.       Copy the specified region from the given value.
253       \param value - Input - Data to copy from  
254         \param value - Input - Data object to copy from.
255       \param region - Input - Region to copy.       \param region - Input - Region to copy.
256    */    */
257      ESCRIPT_DLL_API
258    virtual    virtual
259    void    void
260    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
261             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
262    
263    /**    /**
264       \brief       \brief
265       Assign the given value to the data-point associated with the given       setTaggedValue
266       reference number.  
267         Description:
268         uses tag to set a new value
269    
270         \param tagKey - Input - Integer key.
271         \param pointshape - Input - The shape of the value parameter
272         \param value - Input -
273         \param dataOffset - Input - where in the value parameter to start reading the data point value.
274      */
275      void  
276      setTaggedValue(int tagKey,
277                 const DataTypes::ShapeType& pointshape,
278                     const DataTypes::ValueType& value,
279             int dataOffset=0);
280    
      A reference number corresponds to a sample, and thus to all data-points  
      in that sample. If there is more than one data-point per sample number  
      in this Data object, an exception will be thrown. If the given reference  
      number does not correspond to any sample in this Data object, an exception  
      will be thrown.  
281    
      If the given value is a different shape to this Data object, an exception  
      will be thrown.  
282    
283       \param ref - Input - reference number which determines data-point to assign to.    /**
284       \param value - Input - Value to assign to data-point associated with       \brief
285                              the given reference number.       Computes a symmetric matrix (A + AT) / 2
286    
287         \param ev - Output - symmetric matrix
288    
289    */    */
290    virtual    ESCRIPT_DLL_API
291    void    virtual void
292    setRefValue(int ref,    symmetric(DataAbstract* ev);
               const DataArray& value);  
293    
294    /**    /**
295       \brief       \brief
296       Return the value of the data-point associated with the given       Computes a nonsymmetric matrix (A - AT) / 2
297       reference number.  
298         \param ev - Output - nonsymmetric matrix
299    
300       A reference number corresponds to a sample, and thus to all data-points    */
301       in that sample. If there is more than one data-point per sample number    ESCRIPT_DLL_API
302       in this Data object, an exception will be thrown. If the given reference    virtual void
303       number does not correspond to any sample in this Data object, an exception    nonsymmetric(DataAbstract* ev);
304       will be thrown.  
305      /**
306         \brief
307         Computes the trace of a matrix
308    
309       If the given value is a different shape to this Data object, an exception       \param ev - Output - trace of your matrix
310       will be thrown.       \param axis_offset -
311    
      \param ref - Input - reference number which determines data-point to read from.  
      \param value - Output - Object to receive data-points associated with  
                             the given reference number.  
312    */    */
313    virtual    ESCRIPT_DLL_API
314    void    virtual void
315    getRefValue(int ref,    trace(DataAbstract* ev, int axis_offset);
316                DataArray& value);  
317      /**
318         \brief
319         Transpose each data point of this Data object around the given axis.
320    
321         \param ev - Output - transpose of your matrix
322         \param axis_offset -
323      */
324      ESCRIPT_DLL_API
325      virtual void
326      transpose(DataAbstract* ev, int axis_offset);
327    
328      /**
329         \brief
330         swaps components axis0 and axis1
331    
332         \param ev - Output - swapped components
333         \param axis0
334         \param axis1
335      */
336      ESCRIPT_DLL_API
337      virtual void
338      swapaxes(DataAbstract* ev, int axis0, int axis1);
339    
340    
341      /**
342         \brief
343         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
344    
345         \param ev - Output - eigenvalues in increasing order at each data point
346    
347      */
348      ESCRIPT_DLL_API
349      virtual void
350      eigenvalues(DataAbstract* ev);
351    
352      /**
353         \brief
354         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
355    
356         \param ev - Output - eigenvalues in increasing order at each data point
357         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
358                             and the first nonzero component is positive.
359         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
360    
361      */
362    
363      ESCRIPT_DLL_API
364      virtual void
365      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
366    
367    /**
368     *      \brief
369     *           reorders data sample ordered by reference_ids to the ordering of the functions space
370     *
371     *                \param reference_ids - Input - reference_ids used for current ordering
372     *                  */
373      ESCRIPT_DLL_API
374      virtual void
375      reorderByReferenceIDs(int *reference_ids);
376    
377    
378    
379   protected:   protected:
380    
# Line 230  class DataExpanded : public DataAbstract Line 382  class DataExpanded : public DataAbstract
382    
383    /**    /**
384       \brief       \brief
385       Common initialisation called from constructors       Common initialisation called from constructors.
386    
387       Description:       Description:
388       Common initialisation called from constructors       Common initialisation called from constructors.
389       \param shape - Input - The shape of the point data.  
390         Resizes the underlying data array to provide sufficient storage for the
391         given shape and number of data points, and creates the corresponding
392         DataArrayView of this data.
393    
394       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
395       \param noDataPointsPerSample - Input -       \param noDataPointsPerSample - Input - number of data points per sample.
396    */    */
397    void    void
398    initialise(const DataArrayView::ShapeType& shape,    initialise(int noSamples,
              int noSamples,  
399               int noDataPointsPerSample);               int noDataPointsPerSample);
400    
401    /**    /**
402       \brief       \brief
403       Copy the given data point to all data points.       Copy the given data point value to all data points in this object.
404    
405       Description:       Description:
406       Copy the given data point to all data points.       Copy the given data point to all data points in this object.
407       \param value Input - Value for a single data point.  
408         \param value Input - A single data point value.
409    */    */
410    void    void
411    copy(const DataArrayView& value);    copy(const DataConstant& value);
412    
413    
414    
415      /**
416         \brief
417         Copy the given data point value to all data points in this object.
418    
419         \param value Input - A single data point value.
420      */
421    
422    void    void
423    copy(const boost::python::numeric::array& value);    copy(const WrappedArray& value);
424    
425    
426      /**
427         \brief
428         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
429    
430         Description:
431         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
432    
433         \param sampleNo Input - sample number
434         \param dataPointNo Input - data point of the sample
435         \param value Input - new values for the data point
436      */
437      ESCRIPT_DLL_API
438      virtual void
439      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
440    
441    
442      /**
443         \brief
444         Copy the value to the data point dataPointNo of sample sampleNo in this object.
445    
446         \param sampleNo Input - sample number
447         \param dataPointNo Input - data point of the sample
448         \param value Input - new values for the data point
449      */
450      ESCRIPT_DLL_API
451      virtual void
452      copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
453    
454    //    //
455    // The main data storage, a 2D array of data blocks.    // The main data storage array, a 2D array of data blocks.
456      // noSamples * noDataPointsPerSample
457    DataBlocks2D m_data;    DataBlocks2D m_data;
458    
459  };  };

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

  ViewVC Help
Powered by ViewVC 1.1.26