/[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 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/src/DataTagged.h revision 500 by jgs, Tue Feb 7 05:19:07 2006 UTC
# Line 17  Line 17 
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 30  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 46  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;    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 61  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         T
64    */    */
65    DataTagged();    DataTagged();
66    
# Line 74  class DataTagged : public DataAbstract { Line 72  class DataTagged : public DataAbstract {
72       Constructor for DataTagged.       Constructor for DataTagged.
73       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
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 value of zero. If
76                     it contains one value all tag values will be assigned the                       it contains one value all tag values will be assigned the
77             same value. Otherwise if there is a mismatch between               same value. Otherwise if there is a mismatch between
78             the number of keys and the number of values an exception               the number of keys and the number of values an exception
79             will be generated.               will be generated.
80       \param defaultValue - Input - Value returned if a requested tag doesn't exist.       \param defaultValue - Input - Value returned if a requested tag doesn't exist.
81       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
82         T
83    */    */
84    DataTagged(const TagListType& tagKeys,    DataTagged(const TagListType& tagKeys,
85               const ValueListType& values,               const ValueListType& values,
# Line 89  class DataTagged : public DataAbstract { Line 88  class DataTagged : public DataAbstract {
88    
89    /**    /**
90       \brief       \brief
91       Alternative constructor for DataTagged objects.       Alternative Constructor for DataTagged.
92    
93       Description:       Description:
94       Alternative Constructor for DataTagged objects.       Alternative Constructor for DataTagged.
95       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
96       \param shape - Input - the shape of each data-point.       \param shape - Input - The shape of each data-point.
97       \param tags - Input - array of tags, one for each sample number       \param tags - Input - An array of tags, one for each sample number.
98       \param data - the data values for each data-point.       \param data - The data values for each tag.
99    */    */
100    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
101               const DataArrayView::ShapeType &shape,               const DataArrayView::ShapeType &shape,
102               const int tags[],               const int tags[],
103               const ValueType &data);               const ValueType& data);
104    
105    /**    /**
106       \brief       \brief
107       Slice constructor for DataTagged.       Slice Constructor for DataTagged.
108    
109       Description:       Description:
110       Slice constructor for DataTagged.       Slice Constructor for DataTagged.
111       Copies a slice from another DataTagged object.       Copies a slice from another DataTagged object.
112       \param other - Input - DataTagged object to copy from.       \param other - Input - DataTagged object to copy from.
113       \param region - Input - region to copy.       \param region - Input - Region to copy.
114    */    */
115    DataTagged(const DataTagged& other,    DataTagged(const DataTagged& other,
116           const DataArrayView::RegionType& region);           const DataArrayView::RegionType& region);
117    
118    /**    /**
119       \brief       \brief
120       Copy constructorfor DataTagged.       Copy Constructor for DataTagged.
121       Performs a deep copy from the given DataTagged object.       Performs a deep copy from the given DataTagged object.
122    */    */
123    DataTagged(const DataTagged& other);    DataTagged(const DataTagged& other);
124    
125    /**    /**
126       \brief       \brief
127         Copy Constructor for DataTagged.
128       Construct a tagged data from a DataConstant object.       Construct a tagged data from a DataConstant object.
129       The default data-point will be that held by the DataConstant object.       The default value will be that held by the DataConstant object.
130    */    */
131    DataTagged(const DataConstant& other);    DataTagged(const DataConstant& other);
132    
# Line 135  class DataTagged : public DataAbstract { Line 135  class DataTagged : public DataAbstract {
135       getSampleDataByTag       getSampleDataByTag
136    
137       Description:       Description:
138       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
139       sample should be visable via the returned pointer. This provides an       sample will be visible via the returned pointer.
140       interface into the data suitable for legacy C code.  
141         ** This provides an interface into the data suitable for legacy C code.
142    */    */
143    virtual    virtual
144    double*    double*
# Line 148  class DataTagged : public DataAbstract { Line 149  class DataTagged : public DataAbstract {
149       Write the data as a string.       Write the data as a string.
150       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
151       associated with each tag.       associated with each tag.
152         T
153    */    */
154    virtual    virtual
155    std::string    std::string
# Line 155  class DataTagged : public DataAbstract { Line 157  class DataTagged : public DataAbstract {
157    
158    /**    /**
159       \brief       \brief
160         Return the tag number associated with the given data-point number
161         according to the associated function space.
162         T
163      */
164      virtual
165      int
166      getTagNumber(int dpno);
167    
168      /**
169         \brief
170       getPointOffset       getPointOffset
171    
172       Description:       Description:
173       Return the offset to the given data-point. This is somewhat artificial,       Return the offset to the given data-point value in the underlying
174       but returns the offset for the given point in the DataTagged object.       data vector.
      Only really necessary to avoid many DataArrayView objects.  
175    
176       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
177       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
178         T
179     */     */
180    virtual    virtual
181    ValueType::size_type    ValueType::size_type
# Line 242  class DataTagged : public DataAbstract { Line 254  class DataTagged : public DataAbstract {
254       Description:       Description:
255       Return a view into the data-point associated with the given tag.       Return a view into the data-point associated with the given tag.
256       \param tag - Input - Integer key.       \param tag - Input - Integer key.
257         T
258    */    */
259    DataArrayView    DataArrayView
260    getDataPointByTag(int tag) const;    getDataPointByTag(int tag) const;
# Line 253  class DataTagged : public DataAbstract { Line 266  class DataTagged : public DataAbstract {
266       Description:       Description:
267       Return a view into the data-point specified by the given sample       Return a view into the data-point specified by the given sample
268       and data-point numbers.       and data-point numbers.
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
269       \param sampleNo - Input.       \param sampleNo - Input.
270       \param dataPointNo - Input.       \param dataPointNo - Input.
271         T
272    */    */
273    virtual    virtual
274    DataArrayView    DataArrayView
# Line 269  class DataTagged : public DataAbstract { Line 281  class DataTagged : public DataAbstract {
281    
282       Description:       Description:
283       Return a reference to the tag offset lookup table.       Return a reference to the tag offset lookup table.
284         T
285    */    */
286    const DataMapType&    const DataMapType&
287    getTagLookup() const;    getTagLookup() const;
# Line 278  class DataTagged : public DataAbstract { Line 291  class DataTagged : public DataAbstract {
291       isCurrentTag       isCurrentTag
292    
293       Description:       Description:
294       Return true if the given tag exists within the DataTagged tag keys.       Return true if the given tag exists within the DataTagged tag map.
295       NOTE: The DataTagged keys do not necessarily coincide with the tag  
296       keys for the function space.       NOTE: The DataTagged tag map does not necessarily coincide with the tag
297         keys in the associated function space.
298         T
299     */     */
300    bool    bool
301    isCurrentTag(int tag) const;    isCurrentTag(int tag) const;
# Line 291  class DataTagged : public DataAbstract { Line 306  class DataTagged : public DataAbstract {
306    
307       Description:       Description:
308       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
309       is not explicitly recorded in this DataTagged object.       is not explicitly recorded in this DataTagged object's tag map.
310         T
311    */    */
312    DataArrayView&    DataArrayView&
313    getDefaultValue();    getDefaultValue();
# Line 305  class DataTagged : public DataAbstract { Line 321  class DataTagged : public DataAbstract {
321    
322       Description:       Description:
323       Return the number of doubles stored for the Data.       Return the number of doubles stored for the Data.
324         T
325    */    */
326    virtual    virtual
327    ValueType::size_type    ValueType::size_type
# Line 349  class DataTagged : public DataAbstract { Line 366  class DataTagged : public DataAbstract {
366    void    void
367    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
368    
369      /**
370        \brief
371        Archive the underlying data values to the file referenced
372        by ofstream. A count of the number of values expected to be written
373        is provided as a cross-check.
374    
375        The return value indicates success (0) or otherwise (1).
376      */
377      int
378      archiveData(std::ofstream& archiveFile,
379                  const DataArrayView::ValueType::size_type noValues) const;
380    
381      /**
382        \brief
383        Extract the number of values specified by noValues from the file
384        referenced by ifstream to the underlying data structure.
385    
386        The return value indicates success (0) or otherwise (1).
387      */
388      int
389      extractData(std::ifstream& archiveFile,
390                  const DataArrayView::ValueType::size_type noValues);
391    
392   protected:   protected:
393    
394   private:   private:
# Line 358  class DataTagged : public DataAbstract { Line 398  class DataTagged : public DataAbstract {
398    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
399    
400    //    //
401    // the default value offset    // the offset to the default value
402    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
403    
404    //    //
# Line 391  DataTagged::getDefaultValue() const Line 431  DataTagged::getDefaultValue() const
431    return getPointDataView();    return getPointDataView();
432  }  }
433    
434    inline
435    const DataTagged::DataMapType&
436    DataTagged::getTagLookup() const
437    {
438      return m_offsetLookup;
439    }
440    
441    inline
442    DataArrayView::ValueType::size_type
443    DataTagged::getLength() const
444    {
445      return m_data.size();
446    }
447    
448  } // end of namespace  } // end of namespace
449    
450  #endif  #endif

Legend:
Removed from v.121  
changed lines
  Added in v.500

  ViewVC Help
Powered by ViewVC 1.1.26