/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataTagged.h
ViewVC logotype

Diff of /branches/arrayview_from_1695_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 500 by jgs, Tue Feb 7 05:19:07 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 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 70  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 85  class DataTagged : public DataAbstract { Line 88  class DataTagged : public DataAbstract {
88    
89    /**    /**
90       \brief       \brief
91       Slice constructor for DataTagged.       Alternative Constructor for DataTagged.
92    
93       Description:       Description:
94       Slice constructor for DataTagged.       Alternative Constructor for DataTagged.
95         \param what - Input - A description of what this data object represents.
96         \param shape - Input - The shape of each data-point.
97         \param tags - Input - An array of tags, one for each sample number.
98         \param data - The data values for each tag.
99      */
100      DataTagged(const FunctionSpace& what,
101                 const DataArrayView::ShapeType &shape,
102                 const int tags[],
103                 const ValueType& data);
104    
105      /**
106         \brief
107         Slice Constructor for DataTagged.
108    
109         Description:
110         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 115  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 128  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 135  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    DataArrayView::ValueType::size_type    ValueType::size_type
182    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
183                   int dataPointNo) const;                   int dataPointNo) const;
184    
# Line 155  class DataTagged : public DataAbstract { Line 187  class DataTagged : public DataAbstract {
187       addTaggedValues       addTaggedValues
188    
189       Description:       Description:
190       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object, by repeatedly
191         using addTaggedValue for each given tag/value pair.
192       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
193       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
194                     then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
195                     it contains one value all tags will be assigned the same value.                        it contains one value all tags will be assigned the same value.
196                     Otherwise if there is a mismatch between the number of tags and                        Otherwise if there is a mismatch between the number of tags and
197                     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.  
198    */    */
199    void    void
200    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 175  class DataTagged : public DataAbstract { Line 205  class DataTagged : public DataAbstract {
205       addTaggedValue       addTaggedValue
206    
207       Description:       Description:
208       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
209         a value associated with it, setTaggedValue will be used to update this value.
210       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
211       \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.  
212    */    */
213    void    void
214    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 191  class DataTagged : public DataAbstract { Line 219  class DataTagged : public DataAbstract {
219       setTaggedValues       setTaggedValues
220    
221       Description:       Description:
222       Assign the given values to the tags listed.       Set the given tags to the given values in this DataTagged object, by repeatedly
223         using setTaggedValue for each given tag/value pair.
224       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
225       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
226                        then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
227                        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.
228                        Otherwise if there is a mismatch between the number of keys and                        Otherwise if there is a mismatch between the number of keys and
229                        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.  
230    */    */
231    void    void
232    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 209  class DataTagged : public DataAbstract { Line 237  class DataTagged : public DataAbstract {
237       setTaggedValue       setTaggedValue
238    
239       Description:       Description:
240       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
241         associated with it, addTaggedValue will be used to add this tag/value pair.
242       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
243       \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.  
244    */    */
245    virtual    virtual
246    void    void
# Line 226  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 237  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 253  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 262  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 275  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();
314    
   /**  
      \brief  
      getDefaultValue  
   
      Description:  
      Return the default value, const version.  
   */  
315    const DataArrayView&    const DataArrayView&
316    getDefaultValue() const;    getDefaultValue() const;
317    
# Line 296  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 340  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 349  class DataTagged : public DataAbstract { Line 398  class DataTagged : public DataAbstract {
398    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
399    
400    //    //
401    // The actual data    // the offset to the default value
402    DataArrayView::ValueType m_data;    static const int m_defaultValueOffset = 0;
403    
404    //    //
405    // the default value offset    // The actual data
406    static const int m_defaultValueOffset = 0;    ValueType m_data;
407    
408  };  };
409    
# Line 370  inline Line 419  inline
419  DataArrayView&  DataArrayView&
420  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
421  {  {
   //  
422    // The default value is always the first value.    // The default value is always the first value.
423    return getPointDataView();    return getPointDataView();
424  }  }
# Line 379  inline Line 427  inline
427  const DataArrayView&  const DataArrayView&
428  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
429  {  {
   //  
430    // The default value is always the first value.    // The default value is always the first value.
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.102  
changed lines
  Added in v.500

  ViewVC Help
Powered by ViewVC 1.1.26