/[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 2458 by jfenwick, Wed Jun 3 06:18:21 2009 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  class DataEmpty;  //
27    // Forward declarations of other Data types.
28  class DataConstant;  class DataConstant;
29  class DataTagged;  class DataTagged;
30    
# Line 34  class DataTagged; Line 33  class DataTagged;
33     Give a short description of what DataExpanded does.     Give a short description of what DataExpanded does.
34    
35     Description:     Description:
36     Give a detailed description of DataExpanded     Give a detailed description of DataExpanded.
37    
38     Template Parameters:     Template Parameters:
39     For templates describe any conditions that the parameters used in the     For templates describe any conditions that the parameters used in the
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    
49    /**    /**
50       \brief       \brief
51       Copy constructor for DataExpanded. Performs a deep copy.       Constructor for DataExpanded.
   */  
   DataExpanded(const DataExpanded& other);  
52    
53    /**       Description:
54       \brief       Constructor for DataExpanded.
55       Construct a DataExpanded from a DataConstant.  
56         The given single data value is copied to all the data points in
57         this data object, where the number of data points is defined by
58         the given function space.
59    
60         \param value - Input - The value of a single data point.
61         \param what - Input - A description of what this data represents.
62    */    */
63    DataExpanded(const DataConstant& other);    ESCRIPT_DLL_API
64      DataExpanded(const WrappedArray& value,
65                   const FunctionSpace& what);
66    
67    /**    /**
68       \brief       \brief
69       Construct a DataExpanded from a DataTagged.       Alternative constructor for DataExpanded that copies a slice from
70         another DataExpanded.
71    
72         \param other - Input - DataExpanded object to slice from.
73         \param region - Input - region to copy.
74    */    */
75    DataExpanded(const DataTagged& other);    ESCRIPT_DLL_API
76      DataExpanded(const DataExpanded& other,
77                   const DataTypes::RegionType& region);
78    
79    /**    /**
80       \brief       \brief
81       Constructor for DataExpanded       Alternative constructor for DataExpanded objects.
82    
83       Description:       Description:
84       Constructor for DataExpanded       Alternative Constructor for DataExpanded objects.
85       \param value - Input - Data value for a single point.       \param what - Input - A description of what this data object represents.
86       \param what - Input - A description of what this data represents.       \param shape - Input - the shape of each data-point.
87         \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    DataExpanded(const boost::python::numeric::array& value,    ESCRIPT_DLL_API
92                 const FunctionSpace& what);    DataExpanded(const FunctionSpace& what,
93                   const DataTypes::ShapeType &shape,
94                   const DataTypes::ValueType &data);
95    
96    /**    /**
97       \brief       \brief
98       Alternative constructor for DataExpanded       Copy constructor for DataExpanded.
99         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.  
   
100    */    */
101    DataExpanded(const DataArrayView& value,    ESCRIPT_DLL_API
102                 const FunctionSpace& what);    DataExpanded(const DataExpanded& other);
103    
104    /**    /**
105       \brief       \brief
106       Alternative constructor for DataExpanded that copies a slice from       Copy constructor for DataExpanded.
107       another DataExpanded.       Construct a DataExpanded from a DataConstant.
108      */
109      ESCRIPT_DLL_API
110      DataExpanded(const DataConstant& other);
111    
112       \param other - Input - DataExpanded object to slice from.    /**
113       \param region - Input - region to copy.       \brief
114         Copy constructor for DataExpanded.
115         Construct a DataExpanded from a DataTagged.
116    */    */
117    DataExpanded(const DataExpanded& other,    ESCRIPT_DLL_API
118                 const DataArrayView::RegionType& region);    DataExpanded(const DataTagged& other);
119    
120    /**    /**
121       \brief       \brief
122       Destructor       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    void
167    reshapeDataPoint(const DataArrayView::ShapeType& shape);    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
176      setToZero();
177    
178    /**    /**
179       \brief       \brief
180       Return the offset for the given sample. This is somewhat artificial notion       Return the offset for the given given data point. This returns
181       but returns the offset in bytes for the given point into the container       the offset in bytes for the given point into the container
182       holding the point data.       holding the point data.
183       \param sampleNo - Input - number of samples.  
184       \param dataPointNo - Input - Input.       \param sampleNo - Input - sample number.
185         \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 for the data point specified.       Return a a reference to the underlying DataVector.
202       NOTE: Construction of the DataArrayView is a relatively expensive    */
203       operation.  
204       \param sampleNo - Input    ESCRIPT_DLL_API
205       \param dataPointNo - Input    DataTypes::ValueType&
206       \return DataArrayView of the data point.    getVectorRW();
207    */  
208    DataArrayView    ESCRIPT_DLL_API
209    getDataPoint(int sampleNo,    const DataTypes::ValueType&
210                 int dataPointNo);    getVectorRO() const;
211    
212    
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 161  class DataExpanded : public DataAbstract Line 224  class DataExpanded : public DataAbstract
224       \brief       \brief
225       Factory method that returns a newly created DataExpanded.       Factory method that returns a newly created DataExpanded.
226       The caller is reponsible for managing the object created.       The caller is reponsible for managing the object created.
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
237       Copy the specified region from the given value.       Copy the specified region from the given value.
238       \param value - Input - Data to copy from  
239         \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
250         setTaggedValue
251    
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      */
259      void  
260      setTaggedValue(int tagKey,
261                 const DataTypes::ShapeType& pointshape,
262                     const DataTypes::ValueType& value,
263             int dataOffset=0);
264    
265    
266    
267    /**    /**
268       \brief       \brief
269       Assign the given value to the data-point associated with the given       Computes a symmetric matrix (A + AT) / 2
270       reference number.  
271         \param ev - Output - symmetric matrix
272    
273       A reference number corresponds to a sample, and thus to all data-points    */
274       in that sample. If there is more than one data-point per sample number    ESCRIPT_DLL_API
275       in this Data object, an exception will be thrown. If the given reference    virtual void
276       number does not correspond to any sample in this Data object, an exception    symmetric(DataAbstract* ev);
      will be thrown.  
277    
278       If the given value is a different shape to this Data object, an exception    /**
279       will be thrown.       \brief
280         Computes a nonsymmetric matrix (A - AT) / 2
281    
282         \param ev - Output - nonsymmetric matrix
283    
      \param ref - Input - reference number which determines data-point to assign to.  
      \param value - Input - Value to assign to data-point associated with  
                             the given reference number.  
284    */    */
285    virtual    ESCRIPT_DLL_API
286    void    virtual void
287    setRefValue(int ref,    nonsymmetric(DataAbstract* ev);
               const DataArray& value);  
288    
289    /**    /**
290       \brief       \brief
291       Return the value of the data-point associated with the given       Computes the trace of a matrix
      reference number.  
292    
293       A reference number corresponds to a sample, and thus to all data-points       \param ev - Output - trace of your matrix
      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.  
294    
295       If the given value is a different shape to this Data object, an exception    */
296       will be thrown.    ESCRIPT_DLL_API
297      virtual void
298      trace(DataAbstract* ev, int axis_offset);
299    
300      /**
301         \brief
302         Transpose each data point of this Data object around the given axis.
303    
304         \param ev - Output - transpose of your matrix
305    
      \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.  
306    */    */
307    virtual    ESCRIPT_DLL_API
308    void    virtual void
309    getRefValue(int ref,    transpose(DataAbstract* ev, int axis_offset);
310                DataArray& value);  
311      /**
312         \brief
313         swaps components axis0 and axis1
314    
315         \param ev - Output - swapped components
316    
317      */
318      ESCRIPT_DLL_API
319      virtual void
320      swapaxes(DataAbstract* ev, int axis0, int axis1);
321    
322    
323      /**
324         \brief
325         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
326    
327         \param ev - Output - eigenvalues in increasing order at each data point
328    
329      */
330      ESCRIPT_DLL_API
331      virtual void
332      eigenvalues(DataAbstract* ev);
333    
334      /**
335         \brief
336         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
337    
338         \param ev - Output - eigenvalues in increasing order at each data point
339         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
340                             and the first nonzero component is positive.
341         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
342    
343      */
344    
345      ESCRIPT_DLL_API
346      virtual void
347      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
348    
349    /**
350     *      \brief
351     *           reorders data sample ordered by reference_ids to the ordering of the functions space
352     *
353     *                \param reference_ids - Input - reference_ids used for current ordering
354     *                  */
355      ESCRIPT_DLL_API
356      virtual void
357      reorderByReferenceIDs(int *reference_ids);
358    
359    
360    
361   protected:   protected:
362    
# Line 230  class DataExpanded : public DataAbstract Line 364  class DataExpanded : public DataAbstract
364    
365    /**    /**
366       \brief       \brief
367       Common initialisation called from constructors       Common initialisation called from constructors.
368    
369       Description:       Description:
370       Common initialisation called from constructors       Common initialisation called from constructors.
371       \param shape - Input - The shape of the point data.  
372         Resizes the underlying data array to provide sufficient storage for the
373         given shape and number of data points, and creates the corresponding
374         DataArrayView of this data.
375    
376       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
377       \param noDataPointsPerSample - Input -       \param noDataPointsPerSample - Input - number of data points per sample.
378    */    */
379    void    void
380    initialise(const DataArrayView::ShapeType& shape,    initialise(int noSamples,
              int noSamples,  
381               int noDataPointsPerSample);               int noDataPointsPerSample);
382    
383    /**    /**
384       \brief       \brief
385       Copy the given data point to all data points.       Copy the given data point value to all data points in this object.
386    
387       Description:       Description:
388       Copy the given data point to all data points.       Copy the given data point to all data points in this object.
389       \param value Input - Value for a single data point.  
390         \param value Input - A single data point value.
391    */    */
392    void    void
393    copy(const DataArrayView& value);    copy(const DataConstant& value);
394    
395    
396    
397      /**
398         \brief
399         Copy the given data point value to all data points in this object.
400    
401         \param value Input - A single data point value.
402      */
403    
404    void    void
405    copy(const boost::python::numeric::array& value);    copy(const WrappedArray& value);
406    
407    
408      /**
409         \brief
410         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
411    
412         Description:
413         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
414    
415         \param sampleNo Input - sample number
416         \param dataPointNo Input - data point of the sample
417         \param value Input - new values for the data point
418      */
419      ESCRIPT_DLL_API
420      virtual void
421      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
422    
423    
424      /**
425         \brief
426         Copy the value to the data point dataPointNo of sample sampleNo in this object.
427    
428         \param sampleNo Input - sample number
429         \param dataPointNo Input - data point of the sample
430         \param value Input - new values for the data point
431      */
432      ESCRIPT_DLL_API
433      virtual void
434      copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
435    
436    //    //
437    // The main data storage, a 2D array of data blocks.    // The main data storage array, a 2D array of data blocks.
438      // noSamples * noDataPointsPerSample
439    DataBlocks2D m_data;    DataBlocks2D m_data;
440    
441  };  };

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

  ViewVC Help
Powered by ViewVC 1.1.26