/[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 119 by jgs, Tue Apr 12 04:45:05 2005 UTC trunk/escript/src/DataTagged.h revision 496 by jgs, Tue Feb 7 01:27:14 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 45  class DataTagged : public DataAbstract { Line 43  class DataTagged : public DataAbstract {
43   public:   public:
44    
45    //    //
46    // Types for the lists of tags and values    // Types for the lists of tags and values.
47    typedef std::vector<int> TagListType;    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 from the tag to an offset the the data array.    // 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 59  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 only data-point is a scalar data-point with value 0.0. All tags
62       will map to this data-point.       will map to this single data-point.
63    */    */
64    DataTagged();    DataTagged();
65    
# Line 72  class DataTagged : public DataAbstract { Line 71  class DataTagged : public DataAbstract {
71       Constructor for DataTagged.       Constructor for DataTagged.
72       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
73       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
74                     all tag values will be assigned a value of zero. If                       all tag values will be assigned a value of zero. If
75                     it contains one value all tag values will be assigned the                       it contains one value all tag values will be assigned the
76             same value. Otherwise if there is a mismatch between               same value. Otherwise if there is a mismatch between
77             the number of keys and the number of values an exception               the number of keys and the number of values an exception
78             will be generated.               will be generated.
79       \param defaultValue - Input - Value returned if a requested tag doesn't exist.       \param defaultValue - Input - Value returned if a requested tag doesn't exist.
80       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
81    */    */
# Line 87  class DataTagged : public DataAbstract { Line 86  class DataTagged : public DataAbstract {
86    
87    /**    /**
88       \brief       \brief
89       Alternative constructor for DataTagged objects.       Alternative Constructor for DataTagged.
90    
91       Description:       Description:
92       Alternative Constructor for DataTagged objects.       Alternative Constructor for DataTagged.
93       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
94       \param shape - Input - the shape of each data-point.       \param shape - Input - The shape of each data-point.
95       \param tags - Input - array of tags, one for each sample number       \param tags - Input - An array of tags, one for each sample number.
96       \param data - the data values for each data-point.       \param data - The data values for each tag.
97    */    */
98    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
99               const DataArrayView::ShapeType &shape,               const DataArrayView::ShapeType &shape,
100               const int tags[],               const int tags[],
101               const DataArrayView::ValueType &data);               const ValueType &data);
102    
103    /**    /**
104       \brief       \brief
105       Slice constructor for DataTagged.       Slice Constructor for DataTagged.
106    
107       Description:       Description:
108       Slice constructor for DataTagged.       Slice Constructor for DataTagged.
109       Copies a slice from another DataTagged object.       Copies a slice from another DataTagged object.
110       \param other - Input - DataTagged object to copy from.       \param other - Input - DataTagged object to copy from.
111       \param region - Input - region to copy.       \param region - Input - Region to copy.
112    */    */
113    DataTagged(const DataTagged& other,    DataTagged(const DataTagged& other,
114           const DataArrayView::RegionType& region);           const DataArrayView::RegionType& region);
115    
116    /**    /**
117       \brief       \brief
118       Copy constructorfor DataTagged.       Copy Constructor for DataTagged.
119       Performs a deep copy from the given DataTagged object.       Performs a deep copy from the given DataTagged object.
120    */    */
121    DataTagged(const DataTagged& other);    DataTagged(const DataTagged& other);
122    
123    /**    /**
124       \brief       \brief
125         Copy Constructor for DataTagged.
126       Construct a tagged data from a DataConstant object.       Construct a tagged data from a DataConstant object.
127       The default data-point will be that held by the DataConstant object.       The default value will be that held by the DataConstant object.
128    */    */
129    DataTagged(const DataConstant& other);    DataTagged(const DataConstant& other);
130    
# Line 133  class DataTagged : public DataAbstract { Line 133  class DataTagged : public DataAbstract {
133       getSampleDataByTag       getSampleDataByTag
134    
135       Description:       Description:
136       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
137       sample should be visable via the returned pointer. This provides an       sample will be visible via the returned pointer.
138       interface into the data suitable for legacy C code.  
139         ** This provides an interface into the data suitable for legacy C code.
140    */    */
141    virtual    virtual
142    double*    double*
# Line 153  class DataTagged : public DataAbstract { Line 154  class DataTagged : public DataAbstract {
154    
155    /**    /**
156       \brief       \brief
157         Return the tag number associated with the given data-point number
158         according to the associated function space.
159      */
160      virtual
161      int
162      getTagNumber(int dpno);
163    
164      /**
165         \brief
166       getPointOffset       getPointOffset
167    
168       Description:       Description:
169       Return the offset to the given data-point. This is somewhat artificial,       Return the offset to the given data-point value in the underlying
170       but returns the offset for the given point in the DataTagged object.       data vector.
      Only really necessary to avoid many DataArrayView objects.  
171    
172       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
173       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
174     */     */
175    virtual    virtual
176    DataArrayView::ValueType::size_type    ValueType::size_type
177    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
178                   int dataPointNo) const;                   int dataPointNo) const;
179    
# Line 173  class DataTagged : public DataAbstract { Line 182  class DataTagged : public DataAbstract {
182       addTaggedValues       addTaggedValues
183    
184       Description:       Description:
185       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object, by repeatedly
186         using addTaggedValue for each given tag/value pair.
187       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
188       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
189                     then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
190                     it contains one value all tags will be assigned the same value.                        it contains one value all tags will be assigned the same value.
191                     Otherwise if there is a mismatch between the number of tags and                        Otherwise if there is a mismatch between the number of tags and
192                     the number of values an exception will be generated.                        the number of values an exception will be generated.
      NB: If a tag given here already exists in this object, this attempt to add the given  
      value will have no effect. setTaggedValues is more versatile and should be  
      used in most cases in preference to addTaggedValues.  
193    */    */
194    void    void
195    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 193  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         a value associated with it, setTaggedValue will be used to update this value.
205       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
206       \param value - Input - DataArrayView.       \param value - Input - Single DataArrayView value to be assigned to the tag.
      NB: If this tag already exists in this object, this attempt to add the given  
      value will have no effect. setTaggedValue is more versatile and should be  
      used in most cases in preference to addTaggedValue.  
207    */    */
208    void    void
209    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 209  class DataTagged : public DataAbstract { Line 214  class DataTagged : public DataAbstract {
214       setTaggedValues       setTaggedValues
215    
216       Description:       Description:
217       Assign the given values to the tags listed.       Set the given tags to the given values in this DataTagged object, by repeatedly
218         using setTaggedValue for each given tag/value pair.
219       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
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                        then all given tags will be assigned a value of zero. If
222                        it contains one value all tag values will be assigned the same value.                        it contains one value all tag values will be assigned the same value.
223                        Otherwise if there is a mismatch between the number of keys and                        Otherwise if there is a mismatch between the number of keys and
224                        the number of values an exception will be generated.                        the number of values an exception will be generated.
      NB: If a given tag does not yet exist in this DataTagged object, it will be added.  
225    */    */
226    void    void
227    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 227  class DataTagged : public DataAbstract { Line 232  class DataTagged : public DataAbstract {
232       setTaggedValue       setTaggedValue
233    
234       Description:       Description:
235       Assign the given value to the given tag.       Assign the given value to the given tag. If this tag does not already have a value
236         associated with it, addTaggedValue will be used to add this tag/value pair.
237       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
238       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
      NB: If the given tag does not yet exist in this DataTagged object, it will be added.  
239    */    */
240    virtual    virtual
241    void    void
# Line 255  class DataTagged : public DataAbstract { Line 260  class DataTagged : public DataAbstract {
260       Description:       Description:
261       Return a view into the data-point specified by the given sample       Return a view into the data-point specified by the given sample
262       and data-point numbers.       and data-point numbers.
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
263       \param sampleNo - Input.       \param sampleNo - Input.
264       \param dataPointNo - Input.       \param dataPointNo - Input.
265    */    */
# Line 280  class DataTagged : public DataAbstract { Line 283  class DataTagged : public DataAbstract {
283       isCurrentTag       isCurrentTag
284    
285       Description:       Description:
286       Return true if the given tag exists within the DataTagged tag keys.       Return true if the given tag exists within the DataTagged tag map.
287       NOTE: The DataTagged keys do not necessarily coincide with the tag  
288       keys for the function space.       NOTE: The DataTagged tag map does not necessarily coincide with the tag
289         keys in the associated function space.
290     */     */
291    bool    bool
292    isCurrentTag(int tag) const;    isCurrentTag(int tag) const;
# Line 293  class DataTagged : public DataAbstract { Line 297  class DataTagged : public DataAbstract {
297    
298       Description:       Description:
299       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
300       is not explicitly recorded in this DataTagged object.       is not explicitly recorded in this DataTagged object's tag map.
301    */    */
302    DataArrayView&    DataArrayView&
303    getDefaultValue();    getDefaultValue();
# Line 351  class DataTagged : public DataAbstract { Line 355  class DataTagged : public DataAbstract {
355    void    void
356    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
357    
358      /**
359        \brief
360        Archive the underlying data values to the file referenced
361        by ofstream. A count of the number of values expected to be written
362        is provided as a cross-check.
363    
364        The return value indicates success (0) or otherwise (1).
365      */
366      int
367      archiveData(std::ofstream& archiveFile,
368                  const DataArrayView::ValueType::size_type noValues) const;
369    
370      /**
371        \brief
372        Extract the number of values specified by noValues from the file
373        referenced by ifstream to the underlying data structure.
374    
375        The return value indicates success (0) or otherwise (1).
376      */
377      int
378      extractData(std::ifstream& archiveFile,
379                  const DataArrayView::ValueType::size_type noValues);
380    
381   protected:   protected:
382    
383   private:   private:
# Line 360  class DataTagged : public DataAbstract { Line 387  class DataTagged : public DataAbstract {
387    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
388    
389    //    //
390    // the default value offset    // the offset to the default value
391    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
392    
393    //    //
394    // The actual data    // The actual data
395    DataArrayView::ValueType m_data;    ValueType m_data;
396    
397  };  };
398    
# Line 381  inline Line 408  inline
408  DataArrayView&  DataArrayView&
409  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
410  {  {
   //  
411    // The default value is always the first value.    // The default value is always the first value.
412    return getPointDataView();    return getPointDataView();
413  }  }
# Line 390  inline Line 416  inline
416  const DataArrayView&  const DataArrayView&
417  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
418  {  {
   //  
419    // The default value is always the first value.    // The default value is always the first value.
420    return getPointDataView();    return getPointDataView();
421  }  }
422    
423    inline
424    const DataTagged::DataMapType&
425    DataTagged::getTagLookup() const
426    {
427      return m_offsetLookup;
428    }
429    
430    inline
431    DataArrayView::ValueType::size_type
432    DataTagged::getLength() const
433    {
434      return m_data.size();
435    }
436    
437  } // end of namespace  } // end of namespace
438    
439  #endif  #endif

Legend:
Removed from v.119  
changed lines
  Added in v.496

  ViewVC Help
Powered by ViewVC 1.1.26