/[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 1808 by jfenwick, Thu Sep 25 03:14:56 2008 UTC
# Line 1  Line 1 
1  // $Id$  
2  /*  /* $Id$ */
3   ******************************************************************************  
4   *                                                                            *  /*******************************************************
5   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *
6   *                                                                            *   *           Copyright 2003-2007 by ACceSS MNRF
7   * This software is the property of ACcESS. No part of this code              *   *       Copyright 2007 by University of Queensland
8   * may be copied in any form or by any means without the expressed written    *   *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *                http://esscc.uq.edu.au
10   * by any unauthorised person is illegal unless that person has a software    *   *        Primary Business: Queensland, Australia
11   * license agreement with ACcESS.                                             *   *  Licensed under the Open Software License version 3.0
12   *                                                                            *   *     http://www.opensource.org/licenses/osl-3.0.php
13   ******************************************************************************   *
14  */   *******************************************************/
15                                                                              
16  #if !defined escript_DataExpanded_20040323_H  #if !defined escript_DataExpanded_20040323_H
17  #define escript_DataExpanded_20040323_H  #define escript_DataExpanded_20040323_H
18    #include "system_dep.h"
19    
20  #include "DataAbstract.h"  #include "DataAbstract.h"
21  #include "DataBlocks2D.h"  #include "DataBlocks2D.h"
 #include "DataArrayView.h"  
22    
 #include <boost/scoped_ptr.hpp>  
23  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
24    
25  namespace escript {  namespace escript {
26    
27  //  //
28  // Forward declarations of other Data types.  // Forward declarations of other Data types.
 class DataEmpty;  
29  class DataConstant;  class DataConstant;
30  class DataTagged;  class DataTagged;
31    
# Line 61  class DataExpanded : public DataAbstract Line 59  class DataExpanded : public DataAbstract
59       \param value - Input - A single data value.       \param value - Input - A single data value.
60       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
61    */    */
62      ESCRIPT_DLL_API
63    DataExpanded(const boost::python::numeric::array& value,    DataExpanded(const boost::python::numeric::array& value,
64                 const FunctionSpace& what);                 const FunctionSpace& what);
65    
66    /**    /**
67       \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  
68       Alternative constructor for DataExpanded that copies a slice from       Alternative constructor for DataExpanded that copies a slice from
69       another DataExpanded.       another DataExpanded.
70    
71       \param other - Input - DataExpanded object to slice from.       \param other - Input - DataExpanded object to slice from.
72       \param region - Input - region to copy.       \param region - Input - region to copy.
73    */    */
74      ESCRIPT_DLL_API
75    DataExpanded(const DataExpanded& other,    DataExpanded(const DataExpanded& other,
76                 const DataArrayView::RegionType& region);                 const DataTypes::RegionType& region);
77    
78    /**    /**
79       \brief       \brief
# Line 101  class DataExpanded : public DataAbstract Line 84  class DataExpanded : public DataAbstract
84       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
85       \param shape - Input - the shape of each data-point.       \param shape - Input - the shape of each data-point.
86       \param data - the array of data values for the data-points.       \param data - the array of data values for the data-points.
87    
88    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.
89    */    */
90      ESCRIPT_DLL_API
91    DataExpanded(const FunctionSpace& what,    DataExpanded(const FunctionSpace& what,
92                 const DataArrayView::ShapeType &shape,                 const DataTypes::ShapeType &shape,
93                 const DataArrayView::ValueType &data);                 const DataTypes::ValueType &data);
94    
95    /**    /**
96       \brief       \brief
97       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
98       Performs a deep copy from another DataExpanded.       Performs a deep copy from another DataExpanded.
99    */    */
100      ESCRIPT_DLL_API
101    DataExpanded(const DataExpanded& other);    DataExpanded(const DataExpanded& other);
102    
103    /**    /**
# Line 118  class DataExpanded : public DataAbstract Line 105  class DataExpanded : public DataAbstract
105       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
106       Construct a DataExpanded from a DataConstant.       Construct a DataExpanded from a DataConstant.
107    */    */
108      ESCRIPT_DLL_API
109    DataExpanded(const DataConstant& other);    DataExpanded(const DataConstant& other);
110    
111    /**    /**
# Line 125  class DataExpanded : public DataAbstract Line 113  class DataExpanded : public DataAbstract
113       Copy constructor for DataExpanded.       Copy constructor for DataExpanded.
114       Construct a DataExpanded from a DataTagged.       Construct a DataExpanded from a DataTagged.
115    */    */
116      ESCRIPT_DLL_API
117    DataExpanded(const DataTagged& other);    DataExpanded(const DataTagged& other);
118    
119    /**    /**
120       \brief       \brief
121       Default destructor for DataExpanded.       Default destructor for DataExpanded.
122    */    */
123      ESCRIPT_DLL_API
124    virtual    virtual
125    ~DataExpanded();    ~DataExpanded();
126    
# Line 138  class DataExpanded : public DataAbstract Line 128  class DataExpanded : public DataAbstract
128       \brief       \brief
129       Return a textual representation of the data.       Return a textual representation of the data.
130    */    */
131      ESCRIPT_DLL_API
132    virtual    virtual
133    std::string    std::string
134    toString() const;    toString() const;
135    
136    /**    /**
137         \brief Return a deep copy of the current object.
138      */
139      ESCRIPT_DLL_API
140      virtual
141      DataAbstract*
142      deepCopy();
143    
144    
145     /**
146       \brief       \brief
147       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.  
148    */    */
149      ESCRIPT_DLL_API
150      virtual
151    void    void
152    reshapeDataPoint(const DataArrayView::ShapeType& shape);    dump(const std::string fileName) const;
153    
154     /**
155         \brief
156        sets all values to zero
157      */
158      ESCRIPT_DLL_API
159      virtual
160      void
161      setToZero();
162    
163    /**    /**
164       \brief       \brief
# Line 160  class DataExpanded : public DataAbstract Line 169  class DataExpanded : public DataAbstract
169       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
170       \param dataPointNo - Input - data point number.       \param dataPointNo - Input - data point number.
171    */    */
172      ESCRIPT_DLL_API
173    virtual    virtual
174    DataArrayView::ValueType::size_type    DataTypes::ValueType::size_type
175    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
176                   int dataPointNo) const;                   int dataPointNo) const;
177    
178    /**    /**
179       \brief       \brief
180       Return a view into the data array for the data point specified.       Return a a reference to the underlying DataVector.
181      */
182    
183       NOTE: Construction of the DataArrayView is a relatively expensive    ESCRIPT_DLL_API
184       operation.    DataTypes::ValueType&
185      getVector();
186    
187      ESCRIPT_DLL_API
188      const DataTypes::ValueType&
189      getVector() const;
190    
      \param sampleNo - Input - sample number.  
      \param dataPointNo - Input - data point number.  
      \return DataArrayView for the data point.  
   */  
   DataArrayView  
   getDataPoint(int sampleNo,  
                int dataPointNo);  
191    
192    /**    /**
193       \brief       \brief
194       Return the number of doubles stored for the Data.       Return the number of doubles stored for the Data.
195    */    */
196      ESCRIPT_DLL_API
197    virtual    virtual
198    ValueType::size_type    ValueType::size_type
199    getLength() const;    getLength() const;
# Line 195  class DataExpanded : public DataAbstract Line 205  class DataExpanded : public DataAbstract
205    
206       \param region - Input - Region to copy.       \param region - Input - Region to copy.
207    */    */
208      ESCRIPT_DLL_API
209    virtual    virtual
210    DataAbstract*    DataAbstract*
211    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
212    
213    /**    /**
214       \brief       \brief
# Line 206  class DataExpanded : public DataAbstract Line 217  class DataExpanded : public DataAbstract
217       \param value - Input - Data object to copy from.       \param value - Input - Data object to copy from.
218       \param region - Input - Region to copy.       \param region - Input - Region to copy.
219    */    */
220      ESCRIPT_DLL_API
221    virtual    virtual
222    void    void
223    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* value,
224             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
225    
226    /**    /**
227       \brief       \brief
228       Assign the given value to all data-points associated with the given       setTaggedValue
229       reference number.  
230         Description:
231         uses tag to set a new value
232    
233         \param tagKey - Input - Integer key.
234         \param pointshape - Input - The shape of the value parameter
235         \param value - Input - .
236      */
237      void  
238      setTaggedValue(int tagKey,
239                 const DataTypes::ShapeType& pointshape,
240                     const DataTypes::ValueType& value,
241             int dataOffset=0);
242    
243    
      A reference number corresponds to a sample, and thus to all data-points  
      in that sample.  
244    
245       If the given reference number does not correspond to any sample in this    /**
246       Data object, an exception will be thrown.       \brief
247         Computes a symmetric matrix (A + AT) / 2
248    
249       If the given value is a different shape to this Data object, an exception       \param ev - Output - symmetric matrix
      will be thrown.  
250    
      \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.  
251    */    */
252    virtual    ESCRIPT_DLL_API
253    void    virtual void
254    setRefValue(int ref,    symmetric(DataAbstract* ev);
               const DataArray& value);  
255    
256    /**    /**
257       \brief       \brief
258       Return the value of the first data-point in the sample associated with       Computes a nonsymmetric matrix (A - AT) / 2
      the given reference number.  
259    
260       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.  
261    
262       If the given reference number does not correspond to any sample in this    */
263       Data object, an exception will be thrown.    ESCRIPT_DLL_API
264      virtual void
265      nonsymmetric(DataAbstract* ev);
266    
267       If the given value is a different shape to this Data object, an exception    /**
268       will be thrown.       \brief
269         Computes the trace of a matrix
270    
271         \param ev - Output - trace of your matrix
272    
      \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.  
273    */    */
274    virtual    ESCRIPT_DLL_API
275    void    virtual void
276    getRefValue(int ref,    trace(DataAbstract* ev, int axis_offset);
277                DataArray& value);  
278      /**
279         \brief
280         Transpose each data point of this Data object around the given axis.
281    
282         \param ev - Output - transpose of your matrix
283    
284      */
285      ESCRIPT_DLL_API
286      virtual void
287      transpose(DataAbstract* ev, int axis_offset);
288    
289      /**
290         \brief
291         swaps components axis0 and axis1
292    
293         \param ev - Output - swapped components
294    
295      */
296      ESCRIPT_DLL_API
297      virtual void
298      swapaxes(DataAbstract* ev, int axis0, int axis1);
299    
300    
301    /**    /**
302      \brief       \brief
303      Archive the underlying data values to the file referenced       solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
304      by ofstream. A count of the number of values expected to be written  
305      is provided as a cross-check.       \param ev - Output - eigenvalues in increasing order at each data point
306    
     The return value indicates success (0) or otherwise (1).  
307    */    */
308    int    ESCRIPT_DLL_API
309    archiveData(std::ofstream& archiveFile,    virtual void
310                const DataArrayView::ValueType::size_type noValues) const;    eigenvalues(DataAbstract* ev);
311    
312    /**    /**
313      \brief       \brief
314      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
315      referenced by ifstream to the underlying data structure.  
316         \param ev - Output - eigenvalues in increasing order at each data point
317         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
318                             and the first nonzero component is positive.
319         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
320    
     The return value indicates success (0) or otherwise (1).  
321    */    */
322    int  
323    extractData(std::ifstream& archiveFile,    ESCRIPT_DLL_API
324                const DataArrayView::ValueType::size_type noValues);    virtual void
325      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
326    
327    /**
328     *      \brief
329     *           reorders data sample ordered by reference_ids to the ordering of the functions space
330     *
331     *                \param reference_ids - Input - reference_ids used for current ordering
332     *                  */
333      ESCRIPT_DLL_API
334      virtual void
335      reorderByReferenceIDs(int *reference_ids);
336    
337    
338    
339   protected:   protected:
340    
# Line 298  class DataExpanded : public DataAbstract Line 351  class DataExpanded : public DataAbstract
351       given shape and number of data points, and creates the corresponding       given shape and number of data points, and creates the corresponding
352       DataArrayView of this data.       DataArrayView of this data.
353    
      \param shape - Input - The shape of the point data.  
354       \param noSamples - Input - number of samples.       \param noSamples - Input - number of samples.
355       \param noDataPointsPerSample - Input - number of data points per sample.       \param noDataPointsPerSample - Input - number of data points per sample.
356    */    */
357    void    void
358    initialise(const DataArrayView::ShapeType& shape,    initialise(int noSamples,
              int noSamples,  
359               int noDataPointsPerSample);               int noDataPointsPerSample);
360    
361    /**    /**
362       \brief       \brief
363       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.
364    
365       Description:       Description:
366       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 368  class DataExpanded : public DataAbstract
368       \param value Input - A single data point value.       \param value Input - A single data point value.
369    */    */
370    void    void
371    copy(const DataArrayView& value);    copy(const DataConstant& value);
372    
373    
374    
375      /**
376         \brief
377         Copy the given data point value given a numarray object to all data points in this object.
378    
379         Description:
380         Copy the given data point value given a numarray object to all data points in this object.
381    
382         \param value Input - A single data point value.
383      */
384    void    void
385    copy(const boost::python::numeric::array& value);    copy(const boost::python::numeric::array& value);
386    
387      /**
388         \brief
389         Copy the numarray object to the data points in this object.
390    
391         Description:
392         Copy the numarray object to the data points in this object.
393    
394         \param value Input - new values for the data points
395      */
396      void
397      copyAll(const boost::python::numeric::array& value);
398    
399      /**
400         \brief
401         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
402    
403         Description:
404         Copy a double value to the data point dataPointNo of sample sampleNo in this object.
405    
406         \param sampleNo Input - sample number
407         \param dataPointNo Input - data point of the sample
408         \param value Input - new values for the data point
409      */
410      ESCRIPT_DLL_API
411      virtual void
412      copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
413    
414    
415      /**
416         \brief
417         Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
418    
419         Description:
420         Copy the numarray object to the data point dataPointNo of sample sampleNo in this object.
421    
422         \param sampleNo Input - sample number
423         \param dataPointNo Input - data point of the sample
424         \param value Input - new values for the data point
425      */
426      void
427      copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value);
428    
429    //    //
430    // The main data storage array, a 2D array of data blocks.    // The main data storage array, a 2D array of data blocks.
431    // noSamples * noDataPointsPerSample    // noSamples * noDataPointsPerSample

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

  ViewVC Help
Powered by ViewVC 1.1.26