/[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 509 by jgs, Fri Feb 10 03:24:44 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 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 72  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 89  class DataTagged : public DataAbstract { Line 89  class DataTagged : public DataAbstract {
89    
90    /**    /**
91       \brief       \brief
92       Alternative constructor for DataTagged objects.       Alternative Constructor for DataTagged.
93    
94       Description:       Description:
95       Alternative Constructor for DataTagged objects.       Alternative Constructor for DataTagged.
96       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
97       \param shape - Input - the shape of each data-point.       \param shape - Input - The shape of each data-point.
98       \param tags - Input - array of tags, one for each sample number       \param tags - Input - An array of tags, one for each sample number.
99       \param data - the data values for each data-point.       \param data - The data values for each tag.
100    */    */
101    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
102               const DataArrayView::ShapeType &shape,               const DataArrayView::ShapeType &shape,
103               const int tags[],               const int tags[],
104               const ValueType &data);               const ValueType& data);
105    
106    /**    /**
107       \brief       \brief
108       Slice constructor for DataTagged.       Slice Constructor for DataTagged.
109    
110       Description:       Description:
111       Slice constructor for DataTagged.       Slice Constructor for DataTagged.
112       Copies a slice from another DataTagged object.       Copies a slice from another DataTagged object.
113       \param other - Input - DataTagged object to copy from.       \param other - Input - DataTagged object to copy from.
114       \param region - Input - region to copy.       \param region - Input - Region to copy.
115    */    */
116    DataTagged(const DataTagged& other,    DataTagged(const DataTagged& other,
117           const DataArrayView::RegionType& region);           const DataArrayView::RegionType& region);
118    
119    /**    /**
120       \brief       \brief
121       Copy constructorfor DataTagged.       Copy Constructor for DataTagged.
122       Performs a deep copy from the given DataTagged object.       Performs a deep copy from the given DataTagged object.
123        T
124    */    */
125    DataTagged(const DataTagged& other);    DataTagged(const DataTagged& other);
126    
127    /**    /**
128       \brief       \brief
129       Construct a tagged data from a DataConstant object.       Copy Constructor for DataTagged.
130       The default data-point will be that held by the DataConstant object.       Construct a DataTagged object from a DataConstant object.
131         The default value will be the value of the DataConstant object.
132        T
133    */    */
134    DataTagged(const DataConstant& other);    DataTagged(const DataConstant& other);
135    
# Line 135  class DataTagged : public DataAbstract { Line 138  class DataTagged : public DataAbstract {
138       getSampleDataByTag       getSampleDataByTag
139    
140       Description:       Description:
141       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
142       sample should be visable via the returned pointer. This provides an       sample will be visible via the returned pointer.
143       interface into the data suitable for legacy C code.  
144         ** This provides an interface into the data suitable for legacy C code.
145         ** NB: need to do array bounds checking when accessing returned value!
146        T
147    */    */
148    virtual    virtual
149    double*    double*
# Line 148  class DataTagged : public DataAbstract { Line 154  class DataTagged : public DataAbstract {
154       Write the data as a string.       Write the data as a string.
155       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
156       associated with each tag.       associated with each tag.
157        T
158    */    */
159    virtual    virtual
160    std::string    std::string
# Line 155  class DataTagged : public DataAbstract { Line 162  class DataTagged : public DataAbstract {
162    
163    /**    /**
164       \brief       \brief
165         Return the tag number associated with the given data-point number
166         according to the associated function space.
167        T
168      */
169      virtual
170      int
171      getTagNumber(int dpno);
172    
173      /**
174         \brief
175       getPointOffset       getPointOffset
176    
177       Description:       Description:
178       Return the offset to the given data-point. This is somewhat artificial,       Return the offset to the given data-point value in the underlying
179       but returns the offset for the given point in the DataTagged object.       data vector.
      Only really necessary to avoid many DataArrayView objects.  
180    
181       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
182       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
183     */      T
184      */
185    virtual    virtual
186    ValueType::size_type    ValueType::size_type
187    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
# Line 175  class DataTagged : public DataAbstract { Line 192  class DataTagged : public DataAbstract {
192       addTaggedValues       addTaggedValues
193    
194       Description:       Description:
195       Add the given tags and values to this DataTagged object, by repeatedly       Add the given tags and values to this DataTagged object.
196       using addTaggedValue for each given tag/value pair.       \param tagKeys - Input - A vector of integer tags.
      \param tagKeys - Input - A vector of integer keys.  
197       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
198                        then all given tags will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
199                        it contains one value all tags will be assigned the same value.                       0. If it contains one value all tag values will be assigned
200                        Otherwise if there is a mismatch between the number of tags and               this value. Otherwise consecutive tags will be assigned
201                        the number of values an exception will be generated.                       consecutive values.  If there is a mismatch between  the
202                 number of keys and the number of values an exception
203                 will be generated.
204        T
205    */    */
206    void    void
207    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 195  class DataTagged : public DataAbstract { Line 214  class DataTagged : public DataAbstract {
214       Description:       Description:
215       Add a single tag and value to this DataTagged object. If this tag already has       Add a single tag and value to this DataTagged object. If this tag already has
216       a value associated with it, setTaggedValue will be used to update this value.       a value associated with it, setTaggedValue will be used to update this value.
217       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer tag.
218       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
219        T
220    */    */
221    void    void
222    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 207  class DataTagged : public DataAbstract { Line 227  class DataTagged : public DataAbstract {
227       setTaggedValues       setTaggedValues
228    
229       Description:       Description:
230       Set the given tags to the given values in this DataTagged object, by repeatedly       Set the given tags to the given values in this DataTagged object.
231       using setTaggedValue for each given tag/value pair.       \param tagKeys - Input - A vector of integer tag.
      \param tagKeys - Input - A vector of integer keys.  
232       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
233                        then all given tags will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
234                        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
235                        Otherwise if there is a mismatch between the number of keys and               this value. Otherwise consecutive tags will be assigned
236                        the number of values an exception will be generated.                       consecutive values.  If there is a mismatch between  the
237                 number of keys and the number of values an exception
238                 will be generated.
239        T
240    */    */
241    void    void
242    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 225  class DataTagged : public DataAbstract { Line 247  class DataTagged : public DataAbstract {
247       setTaggedValue       setTaggedValue
248    
249       Description:       Description:
250       Assign the given value to the given tag. If this tag does not already have a value       Assign the given value to the given tag.
251       associated with it, addTaggedValue will be used to add this tag/value pair.       \param tagKey - Input - Integer tag.
      \param tagKey - Input - Integer key.  
252       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
253        T
254    */    */
255    virtual    virtual
256    void    void
# Line 240  class DataTagged : public DataAbstract { Line 262  class DataTagged : public DataAbstract {
262       getDataPointByTag       getDataPointByTag
263    
264       Description:       Description:
265       Return a view into the data-point associated with the given tag.       Return data-point associated with the given tag as a DataArrayView.
266       \param tag - Input - Integer key.       \param tag - Input - Integer key.
267        T
268    */    */
269    DataArrayView    DataArrayView
270    getDataPointByTag(int tag) const;    getDataPointByTag(int tag) const;
# Line 251  class DataTagged : public DataAbstract { Line 274  class DataTagged : public DataAbstract {
274       getDataPoint       getDataPoint
275    
276       Description:       Description:
277       Return a view into the data-point specified by the given sample       Return the data-point specified by the given sample and data-point
278       and data-point numbers.       numbers as a DataArrayView.
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
279       \param sampleNo - Input.       \param sampleNo - Input.
280       \param dataPointNo - Input.       \param dataPointNo - Input.
281        T
282    */    */
283    virtual    virtual
284    DataArrayView    DataArrayView
# Line 269  class DataTagged : public DataAbstract { Line 291  class DataTagged : public DataAbstract {
291    
292       Description:       Description:
293       Return a reference to the tag offset lookup table.       Return a reference to the tag offset lookup table.
294        T
295    */    */
296    const DataMapType&    const DataMapType&
297    getTagLookup() const;    getTagLookup() const;
# Line 278  class DataTagged : public DataAbstract { Line 301  class DataTagged : public DataAbstract {
301       isCurrentTag       isCurrentTag
302    
303       Description:       Description:
304       Return true if the given tag exists within the DataTagged tag keys.       Return true if the given tag exists within the DataTagged tag map.
305       NOTE: The DataTagged keys do not necessarily coincide with the tag  
306       keys for the function space.       *** NB: The DataTagged tag map does not necessarily coincide with the tag
307     */       keys in the associated function space.
308        T
309      */
310    bool    bool
311    isCurrentTag(int tag) const;    isCurrentTag(int tag) const;
312    
# Line 291  class DataTagged : public DataAbstract { Line 316  class DataTagged : public DataAbstract {
316    
317       Description:       Description:
318       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
319       is not explicitly recorded in this DataTagged object.       is not explicitly recorded in this DataTagged object's tag map.
320        T
321    */    */
322    DataArrayView&    DataArrayView&
323    getDefaultValue();    getDefaultValue();
# Line 304  class DataTagged : public DataAbstract { Line 330  class DataTagged : public DataAbstract {
330       getLength       getLength
331    
332       Description:       Description:
333       Return the number of doubles stored for the Data.       Return the total number of doubles stored for this DataTagged object.
334        T
335    */    */
336    virtual    virtual
337    ValueType::size_type    ValueType::size_type
# Line 341  class DataTagged : public DataAbstract { Line 368  class DataTagged : public DataAbstract {
368       reshapeDataPoint       reshapeDataPoint
369    
370       Description:       Description:
371       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
372       An exception is thrown if the data-point has rank other than 0.       if current data-points are scalars. An exception is thrown if
373       The original data point value is used for all values of the new       the current data-points have rank other than 0.
374       data point.       The original values of the data-points are used for all values
375         of the new data-points.
376        T
377    */    */
378    void    void
379    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
380    
381      /**
382         \brief
383         Archive the underlying data values to the file referenced
384         by ofstream. A count of the number of values expected to be written
385         is provided as a cross-check.
386    
387         The return value indicates success (0) or otherwise (1).
388      */
389      int
390      archiveData(std::ofstream& archiveFile,
391                  const DataArrayView::ValueType::size_type noValues) const;
392    
393      /**
394         \brief
395         Extract the number of values specified by noValues from the file
396         referenced by ifstream to the underlying data structure.
397    
398         The return value indicates success (0) or otherwise (1).
399      */
400      int
401      extractData(std::ifstream& archiveFile,
402                  const DataArrayView::ValueType::size_type noValues);
403    
404   protected:   protected:
405    
406   private:   private:
# Line 358  class DataTagged : public DataAbstract { Line 410  class DataTagged : public DataAbstract {
410    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
411    
412    //    //
413    // the default value offset    // the offset to the default value
414    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
415    
416    //    //
# Line 391  DataTagged::getDefaultValue() const Line 443  DataTagged::getDefaultValue() const
443    return getPointDataView();    return getPointDataView();
444  }  }
445    
446    inline
447    const DataTagged::DataMapType&
448    DataTagged::getTagLookup() const
449    {
450      return m_offsetLookup;
451    }
452    
453    inline
454    DataArrayView::ValueType::size_type
455    DataTagged::getLength() const
456    {
457      return m_data.size();
458    }
459    
460  } // end of namespace  } // end of namespace
461    
462  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26