/[escript]/trunk/escript/src/DataTagged.h
ViewVC logotype

Diff of /trunk/escript/src/DataTagged.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/src/Data/DataTagged.h revision 102 by jgs, Wed Dec 15 07:08:39 2004 UTC trunk/escript/src/DataTagged.h revision 580 by gross, Wed Mar 8 05:45:51 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*  
3    /*
4   ******************************************************************************   ******************************************************************************
5   *                                                                            *   *                                                                            *
6   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *
# Line 12  Line 13 
13   *                                                                            *   *                                                                            *
14   ******************************************************************************   ******************************************************************************
15  */  */
16                                                                              
17  #if !defined escript_DataTagged_20040615_H  #if !defined escript_DataTagged_20040615_H
18  #define escript_DataTagged_20040615_H  #define escript_DataTagged_20040615_H
19    
20  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataArray.h"  #include "DataArrayView.h"
 #include "escript/Data/DataArrayView.h"  
22    
23  #include <vector>  #include <vector>
24  #include <map>  #include <map>
# Line 29  class DataConstant; Line 29  class DataConstant;
29    
30  /**  /**
31     \brief     \brief
32     Creates the illusion of a full dataset accessible via sampleNo and dataPointNo.     Simulates a full dataset accessible via sampleNo and dataPointNo.
33    
34     Description:     Description:
35     Creates the illusion of a full dataset accessible via sampleNo and     Each data-point has an associated tag number, and a given tag can represent a
36     dataPointNo. In reality a much smaller number of data-points is stored.     range of dataPointNo and sampleNo. Each tag indexes only a single data-point.
    Each data-point has an associated key, thus a given key represents a specific  
    range of dataPointNo and sampleNo. Each key indexes a single data-point.  
37     Thus only a single data-point needs to be stored for a range of sampleNo and     Thus only a single data-point needs to be stored for a range of sampleNo and
38     dataPointNo values.     dataPointNo values.
39  */  */
# Line 44  class DataTagged : public DataAbstract { Line 42  class DataTagged : public DataAbstract {
42    
43   public:   public:
44    
45    typedef std::vector<int> TagListType;    //
46      // Types for the lists of tags and values.
47      typedef std::vector<int>           TagListType;
48    typedef std::vector<DataArrayView> ValueListType;    typedef std::vector<DataArrayView> ValueListType;
49      typedef DataArrayView::ValueType   ValueType;
50    
51    //    //
52    // Map type, maps the key to an array offset.    // Map from a tag to an offset into the data array.
53    typedef std::map<int, int> DataMapType;    typedef std::map<int, int> DataMapType;
54    
55    /**    /**
# Line 57  class DataTagged : public DataAbstract { Line 58  class DataTagged : public DataAbstract {
58    
59       Description:       Description:
60       Default constructor for DataTagged. Creates a DataTagged object for which       Default constructor for DataTagged. Creates a DataTagged object for which
61       the default data-point is a scalar data-point with value 0.0. Any given tag       the default data-point is a scalar data-point with value 0.0, and no other
62       will map to this data-point.       tag values are stored.
63        T
64    */    */
65    DataTagged();    DataTagged();
66    
# Line 68  class DataTagged : public DataAbstract { Line 70  class DataTagged : public DataAbstract {
70    
71       Description:       Description:
72       Constructor for DataTagged.       Constructor for DataTagged.
73       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer tags.
74       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
75                     all tag values will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
76                     it contains one value all tag values will be assigned the                       0. If it contains one value all tag values will be assigned
77             same value. Otherwise if there is a mismatch between               this value. Otherwise consecutive tags will be assigned
78             the number of keys and the number of values an exception                       consecutive values.  If there is a mismatch between  the
79             will be generated.               number of keys and the number of values an exception
80                 will be generated.
81       \param defaultValue - Input - Value returned if a requested tag doesn't exist.       \param defaultValue - Input - Value returned if a requested tag doesn't exist.
82       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
83        T
84    */    */
85    DataTagged(const TagListType& tagKeys,    DataTagged(const TagListType& tagKeys,
86               const ValueListType& values,               const ValueListType& values,
# Line 85  class DataTagged : public DataAbstract { Line 89  class DataTagged : public DataAbstract {
89    
90    /**    /**
91       \brief       \brief
92       Slice constructor for DataTagged.       Alternative Constructor for DataTagged.
93    
94       Description:       Description:
95       Slice constructor for DataTagged.       Alternative Constructor for DataTagged.
96       Copies a slice from another DataTagged object.       \param what - Input - A description of what this data object represents.
97       \param other - Input - DataTagged object to copy from.       \param shape - Input - The shape of each data-point.
98       \param region - Input - region to copy.       \param tags - Input - An array of tags, one for each sample number.
99         \param data - The data values for each tag.
100        NB: no unit testing yet
101    */    */
102    DataTagged(const DataTagged& other,    DataTagged(const FunctionSpace& what,
103           const DataArrayView::RegionType& region);               const DataArrayView::ShapeType &shape,
104                 const int tags[],
105                 const ValueType& data);
106    
107    /**    /**
108       \brief       \brief
109       Copy constructorfor DataTagged.       Copy Constructor for DataTagged.
110       Performs a deep copy from the given DataTagged object.       Performs a deep copy from the given DataTagged object.
111        T
112    */    */
113    DataTagged(const DataTagged& other);    DataTagged(const DataTagged& other);
114    
115    /**    /**
116       \brief       \brief
117       Construct a tagged data from a DataConstant object.       Copy Constructor for DataTagged.
118       The default data-point will be that held by the DataConstant object.       Construct a DataTagged object from a DataConstant object.
119         The default value will be the value of the DataConstant object.
120        T
121    */    */
122    DataTagged(const DataConstant& other);    DataTagged(const DataConstant& other);
123    
# Line 115  class DataTagged : public DataAbstract { Line 126  class DataTagged : public DataAbstract {
126       getSampleDataByTag       getSampleDataByTag
127    
128       Description:       Description:
129       Return the data-point for the given tag. All of the data for the entire       Return the data-point for the given tag. All of the data for the
130       sample should be visable via the returned pointer. This provides an       sample will be visible via the returned pointer.
131       interface into the data suitable for legacy C code.  
132         ** This provides an interface into the data suitable for legacy C code.
133         ** NB: need to do array bounds checking when accessing returned value!
134        T
135    */    */
136    virtual    virtual
137    double*    double*
# Line 128  class DataTagged : public DataAbstract { Line 142  class DataTagged : public DataAbstract {
142       Write the data as a string.       Write the data as a string.
143       Writes out each tag, including the default, and the data-point which is       Writes out each tag, including the default, and the data-point which is
144       associated with each tag.       associated with each tag.
145        T
146    */    */
147    virtual    virtual
148    std::string    std::string
# Line 135  class DataTagged : public DataAbstract { Line 150  class DataTagged : public DataAbstract {
150    
151    /**    /**
152       \brief       \brief
153         Return the tag number associated with the given data-point number
154         according to the associated function space.
155        T
156      */
157      virtual
158      int
159      getTagNumber(int dpno);
160    
161      /**
162         \brief
163       getPointOffset       getPointOffset
164    
165       Description:       Description:
166       Return the offset to the given data-point. This is somewhat artificial,       Return the offset to the given data-point value in the underlying
167       but returns the offset for the given point in the DataTagged object.       data vector.
      Only really necessary to avoid many DataArrayView objects.  
168    
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     */      T
172      */
173    virtual    virtual
174    DataArrayView::ValueType::size_type    ValueType::size_type
175    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
176                   int dataPointNo) const;                   int dataPointNo) const;
177    
# Line 155  class DataTagged : public DataAbstract { Line 180  class DataTagged : public DataAbstract {
180       addTaggedValues       addTaggedValues
181    
182       Description:       Description:
183       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object.
184       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer tags.
185       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
186                     then all given tags will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
187                     it contains one value all tags will be assigned the same value.                       0. If it contains one value all tag values will be assigned
188                     Otherwise if there is a mismatch between the number of tags and               this value. Otherwise consecutive tags will be assigned
189                     the number of values an exception will be generated.                       consecutive values.  If there is a mismatch between  the
190       NB: If a tag given here already exists in this object, this attempt to add the given               number of keys and the number of values an exception
191       value will have no effect. setTaggedValues is more versatile and should be               will be generated.
192       used in most cases in preference to addTaggedValues.      T
193    */    */
194    void    void
195    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 175  class DataTagged : public DataAbstract { Line 200  class DataTagged : public DataAbstract {
200       addTaggedValue       addTaggedValue
201    
202       Description:       Description:
203       Add a single tag and value to this DataTagged object.       Add a single tag and value to this DataTagged object. If this tag already has
204       \param tagKey - Input - Integer key.       a value associated with it, setTaggedValue will be used to update this value.
205       \param value - Input - DataArrayView.       \param tagKey - Input - Integer tag.
206       NB: If this tag already exists in this object, this attempt to add the given       \param value - Input - Single DataArrayView value to be assigned to the tag.
207       value will have no effect. setTaggedValue is more versatile and should be      T
      used in most cases in preference to addTaggedValue.  
208    */    */
209    void    void
210    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 191  class DataTagged : public DataAbstract { Line 215  class DataTagged : public DataAbstract {
215       setTaggedValues       setTaggedValues
216    
217       Description:       Description:
218       Assign the given values to the tags listed.       Set the given tags to the given values in this DataTagged object.
219       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer tag.
220       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
221                        then all given tags will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
222                        it contains one value all tag values will be assigned the same value.                       0. If it contains one value all tag values will be assigned
223                        Otherwise if there is a mismatch between the number of keys and               this value. Otherwise consecutive tags will be assigned
224                        the number of values an exception will be generated.                       consecutive values.  If there is a mismatch between  the
225       NB: If a given tag does not yet exist in this DataTagged object, it will be added.               number of keys and the number of values an exception
226                 will be generated.
227        T
228    */    */
229    void    void
230    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 210  class DataTagged : public DataAbstract { Line 236  class DataTagged : public DataAbstract {
236    
237       Description:       Description:
238       Assign the given value to the given tag.       Assign the given value to the given tag.
239       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer tag.
240       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
241       NB: If the given tag does not yet exist in this DataTagged object, it will be added.      T
242    */    */
243    virtual    virtual
244    void    void
# Line 224  class DataTagged : public DataAbstract { Line 250  class DataTagged : public DataAbstract {
250       getDataPointByTag       getDataPointByTag
251    
252       Description:       Description:
253       Return a view into the data-point associated with the given tag.       Return data-point associated with the given tag as a DataArrayView.
254       \param tag - Input - Integer key.       \param tag - Input - Integer key.
255        T
256    */    */
257    DataArrayView    DataArrayView
258    getDataPointByTag(int tag) const;    getDataPointByTag(int tag) const;
# Line 235  class DataTagged : public DataAbstract { Line 262  class DataTagged : public DataAbstract {
262       getDataPoint       getDataPoint
263    
264       Description:       Description:
265       Return a view into the data-point specified by the given sample       Return the data-point specified by the given sample and data-point
266       and data-point numbers.       numbers as a DataArrayView.
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
267       \param sampleNo - Input.       \param sampleNo - Input.
268       \param dataPointNo - Input.       \param dataPointNo - Input.
269        T
270    */    */
271    virtual    virtual
272    DataArrayView    DataArrayView
# Line 253  class DataTagged : public DataAbstract { Line 279  class DataTagged : public DataAbstract {
279    
280       Description:       Description:
281       Return a reference to the tag offset lookup table.       Return a reference to the tag offset lookup table.
282        T
283    */    */
284    const DataMapType&    const DataMapType&
285    getTagLookup() const;    getTagLookup() const;
# Line 262  class DataTagged : public DataAbstract { Line 289  class DataTagged : public DataAbstract {
289       isCurrentTag       isCurrentTag
290    
291       Description:       Description:
292       Return true if the given tag exists within the DataTagged tag keys.       Return true if the given tag exists within the DataTagged tag map.
293       NOTE: The DataTagged keys do not necessarily coincide with the tag  
294       keys for the function space.       *** NB: The DataTagged tag map does not necessarily coincide with the tag
295     */       keys in the associated function space.
296        T
297      */
298    bool    bool
299    isCurrentTag(int tag) const;    isCurrentTag(int tag) const;
300    
# Line 275  class DataTagged : public DataAbstract { Line 304  class DataTagged : public DataAbstract {
304    
305       Description:       Description:
306       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
307       is not explicitly recorded in this DataTagged object.       is not explicitly recorded in this DataTagged object's tag map.
308        T
309    */    */
310    DataArrayView&    DataArrayView&
311    getDefaultValue();    getDefaultValue();
312    
   /**  
      \brief  
      getDefaultValue  
   
      Description:  
      Return the default value, const version.  
   */  
313    const DataArrayView&    const DataArrayView&
314    getDefaultValue() const;    getDefaultValue() const;
315    
# Line 295  class DataTagged : public DataAbstract { Line 318  class DataTagged : public DataAbstract {
318       getLength       getLength
319    
320       Description:       Description:
321       Return the number of doubles stored for the Data.       Return the total number of doubles stored for this DataTagged object.
322        T
323    */    */
324    virtual    virtual
325    ValueType::size_type    ValueType::size_type
# Line 306  class DataTagged : public DataAbstract { Line 330  class DataTagged : public DataAbstract {
330       getSlice       getSlice
331    
332       Description:       Description:
333       Factory method that returns a newly created DataTagged object.       Factory method that returns a newly created DataTagged object generated
334       The caller is reponsible for managing the object created.       by taking the specified slice from this DataTagged object.
335         The caller is reponsible for managing the returned object.
336        T
337    */    */
338    virtual    virtual
339    DataAbstract*    DataAbstract*
# Line 315  class DataTagged : public DataAbstract { Line 341  class DataTagged : public DataAbstract {
341    
342    /**    /**
343       \brief       \brief
344         Slice Constructor for DataTagged.
345    
346         Description:
347         Creates a DataTagged object which is the specified slice
348         from the given DataTagged object.
349         \param other - Input - DataTagged object to slice from.
350         \param region - Input - Region to slice.
351        T
352      */
353      DataTagged(const DataTagged& other,
354             const DataArrayView::RegionType& region);
355    
356      /**
357         \brief
358       setSlice       setSlice
359    
360       Description:       Description:
361       Copy the specified region from the given value into this object.       Copy the given Data object into the specified region in this object.
362       \param value - Input - Data to copy from.       \param other - Input - Data object to copy from.
363       \param region - Input - Region to copy.       \param region - Input - Region to copy into (NB: must have same shape as other!).
364        T
365    */    */
366    virtual    virtual
367    void    void
368    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* other,
369             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
370    
371    /**    /**
# Line 332  class DataTagged : public DataAbstract { Line 373  class DataTagged : public DataAbstract {
373       reshapeDataPoint       reshapeDataPoint
374    
375       Description:       Description:
376       Reshape the data point only if the data-point is currently rank 0.       Reshape each data-point in this object to the given shape, only
377       An exception is thrown if the data-point has rank other than 0.       if current data-points are scalars. An exception is thrown if
378       The original data point value is used for all values of the new       the current data-points have rank other than 0.
379       data point.       The original values of the data-points are used for all values
380         of the new data-points.
381        T
382    */    */
383    void    void
384    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
385    
386      /**
387         \brief
388         Archive the underlying data values to the file referenced
389         by ofstream. A count of the number of values expected to be written
390         is provided as a cross-check.
391    
392         The return value indicates success (0) or otherwise (1).
393      */
394      int
395      archiveData(std::ofstream& archiveFile,
396                  const DataArrayView::ValueType::size_type noValues) const;
397    
398      /**
399         \brief
400         Extract the number of values specified by noValues from the file
401         referenced by ifstream to the underlying data structure.
402    
403         The return value indicates success (0) or otherwise (1).
404      */
405      int
406      extractData(std::ifstream& archiveFile,
407                  const DataArrayView::ValueType::size_type noValues);
408    
409      /**
410         \brief
411         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
412    
413         \param ev - Output - eigenvalues in increasing order at each data point
414    
415      */
416      virtual void
417      eigenvalues(DataAbstract* ev);
418    
419      /**
420         \brief
421         solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
422    
423         \param ev - Output - eigenvalues in increasing order at each data point
424         \param V - Output - corresponding eigenvectors. They are normalized such that their length is one
425                             and the first nonzero component is positive.
426         \param tol - Input - eigenvalue with relative distance tol are treated as equal.
427    
428      */
429    
430      virtual void
431      eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
432    
433    
434   protected:   protected:
435    
436   private:   private:
# Line 349  class DataTagged : public DataAbstract { Line 440  class DataTagged : public DataAbstract {
440    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
441    
442    //    //
443    // The actual data    // the offset to the default value
444    DataArrayView::ValueType m_data;    static const int m_defaultValueOffset = 0;
445    
446    //    //
447    // the default value offset    // The actual data
448    static const int m_defaultValueOffset = 0;    ValueType m_data;
449    
450  };  };
451    
# Line 370  inline Line 461  inline
461  DataArrayView&  DataArrayView&
462  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
463  {  {
   //  
464    // The default value is always the first value.    // The default value is always the first value.
465    return getPointDataView();    return getPointDataView();
466  }  }
# Line 379  inline Line 469  inline
469  const DataArrayView&  const DataArrayView&
470  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
471  {  {
   //  
472    // The default value is always the first value.    // The default value is always the first value.
473    return getPointDataView();    return getPointDataView();
474  }  }
475    
476    inline
477    const DataTagged::DataMapType&
478    DataTagged::getTagLookup() const
479    {
480      return m_offsetLookup;
481    }
482    
483    inline
484    DataArrayView::ValueType::size_type
485    DataTagged::getLength() const
486    {
487      return m_data.size();
488    }
489    
490  } // end of namespace  } // end of namespace
491    
492  #endif  #endif

Legend:
Removed from v.102  
changed lines
  Added in v.580

  ViewVC Help
Powered by ViewVC 1.1.26