/[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/escript/src/Data/DataTagged.h revision 155 by jgs, Wed Nov 9 02:02:19 2005 UTC trunk/escript/src/DataTagged.h revision 535 by jgs, Fri Feb 17 02:27:06 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        NB: no unit testing yet
101    */    */
102    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
103               const DataArrayView::ShapeType &shape,               const DataArrayView::ShapeType &shape,
104               const int tags[],               const int tags[],
105               const ValueType &data);               const ValueType& data);
106    
107    /**    /**
108       \brief       \brief
109       Slice constructor for DataTagged.       Copy Constructor for DataTagged.
   
      Description:  
      Slice constructor for DataTagged.  
      Copies a slice from another DataTagged object.  
      \param other - Input - DataTagged object to copy from.  
      \param region - Input - region to copy.  
   */  
   DataTagged(const DataTagged& other,  
          const DataArrayView::RegionType& region);  
   
   /**  
      \brief  
      Copy constructorfor 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 135  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 148  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 155  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.       Return the tag number associated with the given data-point number
154         according to the associated function space.
155        T
156    */    */
157    virtual    virtual
158    int    int
# Line 166  class DataTagged : public DataAbstract { Line 163  class DataTagged : public DataAbstract {
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    ValueType::size_type    ValueType::size_type
175    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
# Line 183  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, by repeatedly       Add the given tags and values to this DataTagged object.
184       using addTaggedValue for each given tag/value pair.       \param tagKeys - Input - A vector of integer tags.
      \param tagKeys - Input - A vector of integer keys.  
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                 number of keys and the number of values an exception
191                 will be generated.
192        T
193    */    */
194    void    void
195    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 203  class DataTagged : public DataAbstract { Line 202  class DataTagged : public DataAbstract {
202       Description:       Description:
203       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
204       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.
205       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer tag.
206       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
207        T
208    */    */
209    void    void
210    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 215  class DataTagged : public DataAbstract { Line 215  class DataTagged : public DataAbstract {
215       setTaggedValues       setTaggedValues
216    
217       Description:       Description:
218       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.
219       using setTaggedValue for each given tag/value pair.       \param tagKeys - Input - A vector of integer tag.
      \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                       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                 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 233  class DataTagged : public DataAbstract { Line 235  class DataTagged : public DataAbstract {
235       setTaggedValue       setTaggedValue
236    
237       Description:       Description:
238       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.
239       associated with it, addTaggedValue will be used to add this tag/value pair.       \param tagKey - Input - Integer tag.
      \param tagKey - Input - Integer key.  
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        T
242    */    */
243    virtual    virtual
244    void    void
# Line 248  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 259  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 277  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 286  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 299  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();
# Line 312  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 323  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 332  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 349  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       \brief
388      Archive the underlying data values to the file referenced       Archive the underlying data values to the file referenced
389      by ofstream. A count of the number of values expected to be written       by ofstream. A count of the number of values expected to be written
390      is provided as a cross-check.       is provided as a cross-check.
391    
392      The return value indicates success (0) or otherwise (1).       The return value indicates success (0) or otherwise (1).
393    */    */
394    int    int
395    archiveData(std::ofstream& archiveFile,    archiveData(std::ofstream& archiveFile,
396                const DataArrayView::ValueType::size_type noValues) const;                const DataArrayView::ValueType::size_type noValues) const;
397    
398    /**    /**
399      \brief       \brief
400      Extract the number of values specified by noValues from the file       Extract the number of values specified by noValues from the file
401      referenced by ifstream to the underlying data structure.       referenced by ifstream to the underlying data structure.
402    
403      The return value indicates success (0) or otherwise (1).       The return value indicates success (0) or otherwise (1).
404    */    */
405    int    int
406    extractData(std::ifstream& archiveFile,    extractData(std::ifstream& archiveFile,
# Line 389  class DataTagged : public DataAbstract { Line 415  class DataTagged : public DataAbstract {
415    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
416    
417    //    //
418    // the default value offset    // the offset to the default value
419    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
420    
421    //    //
# Line 422  DataTagged::getDefaultValue() const Line 448  DataTagged::getDefaultValue() const
448    return getPointDataView();    return getPointDataView();
449  }  }
450    
451    inline
452    const DataTagged::DataMapType&
453    DataTagged::getTagLookup() const
454    {
455      return m_offsetLookup;
456    }
457    
458    inline
459    DataArrayView::ValueType::size_type
460    DataTagged::getLength() const
461    {
462      return m_data.size();
463    }
464    
465  } // end of namespace  } // end of namespace
466    
467  #endif  #endif

Legend:
Removed from v.155  
changed lines
  Added in v.535

  ViewVC Help
Powered by ViewVC 1.1.26