/[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 100 by jgs, Wed Dec 15 03:48:48 2004 UTC trunk/escript/src/DataTagged.h revision 519 by jgs, Tue Feb 14 05:30:50 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 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 68  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 85  class DataTagged : public DataAbstract { Line 89  class DataTagged : public DataAbstract {
89    
90    /**    /**
91       \brief       \brief
92       Slice constructor for DataTagged.       Alternative Constructor for DataTagged.
93    
94       Description:       Description:
95       Slice constructor for DataTagged.       Alternative Constructor for DataTagged.
96       Copies a slice from another DataTagged object.       \param what - Input - A description of what this data object represents.
97       \param other - Input - DataTagged object to copy from.       \param shape - Input - The shape of each data-point.
98       \param region - Input - region to copy.       \param tags - Input - An array of tags, one for each sample number.
99         \param data - The data values for each tag.
100    */    */
101    DataTagged(const DataTagged& other,    DataTagged(const FunctionSpace& what,
102           const DataArrayView::RegionType& region);               const DataArrayView::ShapeType &shape,
103                 const int tags[],
104                 const ValueType& data);
105    
106    /**    /**
107       \brief       \brief
108       Copy constructorfor DataTagged.       Copy Constructor for DataTagged.
109       Performs a deep copy from the given DataTagged object.       Performs a deep copy from the given DataTagged object.
110        T
111    */    */
112    DataTagged(const DataTagged& other);    DataTagged(const DataTagged& other);
113    
114    /**    /**
115       \brief       \brief
116       Construct a tagged data from a DataConstant object.       Copy Constructor for DataTagged.
117       The default data-point will be that held by the DataConstant object.       Construct a DataTagged object from a DataConstant object.
118         The default value will be the value of the DataConstant object.
119        T
120    */    */
121    DataTagged(const DataConstant& other);    DataTagged(const DataConstant& other);
122    
# Line 115  class DataTagged : public DataAbstract { Line 125  class DataTagged : public DataAbstract {
125       getSampleDataByTag       getSampleDataByTag
126    
127       Description:       Description:
128       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
129       sample should be visable via the returned pointer. This provides an       sample will be visible via the returned pointer.
130       interface into the data suitable for legacy C code.  
131         ** This provides an interface into the data suitable for legacy C code.
132         ** NB: need to do array bounds checking when accessing returned value!
133        T
134    */    */
135    virtual    virtual
136    double*    double*
# Line 128  class DataTagged : public DataAbstract { Line 141  class DataTagged : public DataAbstract {
141       Write the data as a string.       Write the data as a string.
142       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
143       associated with each tag.       associated with each tag.
144        T
145    */    */
146    virtual    virtual
147    std::string    std::string
# Line 135  class DataTagged : public DataAbstract { Line 149  class DataTagged : public DataAbstract {
149    
150    /**    /**
151       \brief       \brief
152         Return the tag number associated with the given data-point number
153         according to the associated function space.
154        T
155      */
156      virtual
157      int
158      getTagNumber(int dpno);
159    
160      /**
161         \brief
162       getPointOffset       getPointOffset
163    
164       Description:       Description:
165       Return the offset to the given data-point. This is somewhat artificial,       Return the offset to the given data-point value in the underlying
166       but returns the offset for the given point in the DataTagged object.       data vector.
      Only really necessary to avoid many DataArrayView objects.  
167    
168       \param sampleNo - Input - sample number.       \param sampleNo - Input - sample number.
169       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
170     */      T
171      */
172    virtual    virtual
173    DataArrayView::ValueType::size_type    ValueType::size_type
174    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
175                   int dataPointNo) const;                   int dataPointNo) const;
176    
# Line 155  class DataTagged : public DataAbstract { Line 179  class DataTagged : public DataAbstract {
179       addTaggedValues       addTaggedValues
180    
181       Description:       Description:
182       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object.
183       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer tags.
184       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
185                     then all given tags will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
186                     it contains one value all tags will be assigned the same value.                       0. If it contains one value all tag values will be assigned
187                     Otherwise if there is a mismatch between the number of tags and               this value. Otherwise consecutive tags will be assigned
188                     the number of values an exception will be generated.                       consecutive values.  If there is a mismatch between  the
189       NB: If a tag given here already exists in this object, this attempt to add the given               number of keys and the number of values an exception
190       value will have no effect. setTaggedValues is more versatile and should be               will be generated.
191       used in most cases in preference to addTaggedValues.      T
192    */    */
193    void    void
194    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 175  class DataTagged : public DataAbstract { Line 199  class DataTagged : public DataAbstract {
199       addTaggedValue       addTaggedValue
200    
201       Description:       Description:
202       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
203       \param tagKey - Input - Integer key.       a value associated with it, setTaggedValue will be used to update this value.
204       \param value - Input - DataArrayView.       \param tagKey - Input - Integer tag.
205       NB: If this tag already exists in this object, this attempt to add the given       \param value - Input - Single DataArrayView value to be assigned to the tag.
206       value will have no effect. setTaggedValue is more versatile and should be      T
      used in most cases in preference to addTaggedValue.  
207    */    */
208    void    void
209    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 191  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.
218       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer tag.
219       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
220                        then all given tags will be assigned a value of zero. If                       all tag values will be assigned a scalar data-point of value
221                        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
222                        Otherwise if there is a mismatch between the number of keys and               this value. Otherwise consecutive tags will be assigned
223                        the number of values an exception will be generated.                       consecutive values.  If there is a mismatch between  the
224       NB: If a given tag does not yet exist in this DataTagged object, it will be added.               number of keys and the number of values an exception
225                 will be generated.
226        T
227    */    */
228    void    void
229    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 210  class DataTagged : public DataAbstract { Line 235  class DataTagged : public DataAbstract {
235    
236       Description:       Description:
237       Assign the given value to the given tag.       Assign the given value to the given tag.
238       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer tag.
239       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
240       NB: If the given tag does not yet exist in this DataTagged object, it will be added.      T
241    */    */
242    virtual    virtual
243    void    void
# Line 224  class DataTagged : public DataAbstract { Line 249  class DataTagged : public DataAbstract {
249       getDataPointByTag       getDataPointByTag
250    
251       Description:       Description:
252       Return a view into the data-point associated with the given tag.       Return data-point associated with the given tag as a DataArrayView.
253       \param tag - Input - Integer key.       \param tag - Input - Integer key.
254        T
255    */    */
256    DataArrayView    DataArrayView
257    getDataPointByTag(int tag) const;    getDataPointByTag(int tag) const;
# Line 235  class DataTagged : public DataAbstract { Line 261  class DataTagged : public DataAbstract {
261       getDataPoint       getDataPoint
262    
263       Description:       Description:
264       Return a view into the data-point specified by the given sample       Return the data-point specified by the given sample and data-point
265       and data-point numbers.       numbers as a DataArrayView.
      NOTE: Construction of the DataArrayView is a relatively expensive  
      operation.  
266       \param sampleNo - Input.       \param sampleNo - Input.
267       \param dataPointNo - Input.       \param dataPointNo - Input.
268        T
269    */    */
270    virtual    virtual
271    DataArrayView    DataArrayView
# Line 253  class DataTagged : public DataAbstract { Line 278  class DataTagged : public DataAbstract {
278    
279       Description:       Description:
280       Return a reference to the tag offset lookup table.       Return a reference to the tag offset lookup table.
281        T
282    */    */
283    const DataMapType&    const DataMapType&
284    getTagLookup() const;    getTagLookup() const;
# Line 262  class DataTagged : public DataAbstract { Line 288  class DataTagged : public DataAbstract {
288       isCurrentTag       isCurrentTag
289    
290       Description:       Description:
291       Return true if the given tag exists within the DataTagged tag keys.       Return true if the given tag exists within the DataTagged tag map.
292       NOTE: The DataTagged keys do not necessarily coincide with the tag  
293       keys for the function space.       *** NB: The DataTagged tag map does not necessarily coincide with the tag
294     */       keys in the associated function space.
295        T
296      */
297    bool    bool
298    isCurrentTag(int tag) const;    isCurrentTag(int tag) const;
299    
# Line 275  class DataTagged : public DataAbstract { Line 303  class DataTagged : public DataAbstract {
303    
304       Description:       Description:
305       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
306       is not explicitly recorded in this DataTagged object.       is not explicitly recorded in this DataTagged object's tag map.
307        T
308    */    */
309    DataArrayView&    DataArrayView&
310    getDefaultValue();    getDefaultValue();
311    
   /**  
      \brief  
      getDefaultValue  
   
      Description:  
      Return the default value, const version.  
   */  
312    const DataArrayView&    const DataArrayView&
313    getDefaultValue() const;    getDefaultValue() const;
314    
# Line 295  class DataTagged : public DataAbstract { Line 317  class DataTagged : public DataAbstract {
317       getLength       getLength
318    
319       Description:       Description:
320       Return the number of doubles stored for the Data.       Return the total number of doubles stored for this DataTagged object.
321        T
322    */    */
323    virtual    virtual
324    ValueType::size_type    ValueType::size_type
# Line 306  class DataTagged : public DataAbstract { Line 329  class DataTagged : public DataAbstract {
329       getSlice       getSlice
330    
331       Description:       Description:
332       Factory method that returns a newly created DataTagged.       Factory method that returns a newly created DataTagged object generated
333       The caller is reponsible for managing the object created.       by taking the specified slice from this DataTagged object.
334         The caller is reponsible for managing the returned object.
335    */    */
336    virtual    virtual
337    DataAbstract*    DataAbstract*
# Line 315  class DataTagged : public DataAbstract { Line 339  class DataTagged : public DataAbstract {
339    
340    /**    /**
341       \brief       \brief
342         Slice Constructor for DataTagged.
343    
344         Description:
345         Creates a DataTagged object which is the specified slice
346         from the given DataTagged object.
347         \param other - Input - DataTagged object to slice from.
348         \param region - Input - Region to slice.
349      */
350      DataTagged(const DataTagged& other,
351             const DataArrayView::RegionType& region);
352    
353      /**
354         \brief
355       setSlice       setSlice
356    
357       Description:       Description:
358       Copy the specified region from the given value.       Copy the given Data object into the specified region in this object.
359       \param value - Input - Data to copy from.       \param other - Input - Data object to copy from.
360       \param region - Input - Region to copy.       \param region - Input - Region to copy into (NB: must have same shape as other!).
361    */    */
362    virtual    virtual
363    void    void
364    setSlice(const DataAbstract* value,    setSlice(const DataAbstract* other,
365             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
366    
367    /**    /**
# Line 332  class DataTagged : public DataAbstract { Line 369  class DataTagged : public DataAbstract {
369       reshapeDataPoint       reshapeDataPoint
370    
371       Description:       Description:
372       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
373       An exception is thrown if the data-point has rank other than 0.       if current data-points are scalars. An exception is thrown if
374       The original data point value is used for all values of the new       the current data-points have rank other than 0.
375       data point.       The original values of the data-points are used for all values
376         of the new data-points.
377        T
378    */    */
379    void    void
380    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
381    
382      /**
383         \brief
384         Archive the underlying data values to the file referenced
385         by ofstream. A count of the number of values expected to be written
386         is provided as a cross-check.
387    
388         The return value indicates success (0) or otherwise (1).
389      */
390      int
391      archiveData(std::ofstream& archiveFile,
392                  const DataArrayView::ValueType::size_type noValues) const;
393    
394      /**
395         \brief
396         Extract the number of values specified by noValues from the file
397         referenced by ifstream to the underlying data structure.
398    
399         The return value indicates success (0) or otherwise (1).
400      */
401      int
402      extractData(std::ifstream& archiveFile,
403                  const DataArrayView::ValueType::size_type noValues);
404    
405   protected:   protected:
406    
407   private:   private:
# Line 349  class DataTagged : public DataAbstract { Line 411  class DataTagged : public DataAbstract {
411    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
412    
413    //    //
414    // The actual data    // the offset to the default value
415    DataArrayView::ValueType m_data;    static const int m_defaultValueOffset = 0;
416    
417    //    //
418    // the default value offset    // The actual data
419    static const int m_defaultValueOffset = 0;    ValueType m_data;
420    
421  };  };
422    
# Line 370  inline Line 432  inline
432  DataArrayView&  DataArrayView&
433  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
434  {  {
   //  
435    // The default value is always the first value.    // The default value is always the first value.
436    return getPointDataView();    return getPointDataView();
437  }  }
# Line 379  inline Line 440  inline
440  const DataArrayView&  const DataArrayView&
441  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
442  {  {
   //  
443    // The default value is always the first value.    // The default value is always the first value.
444    return getPointDataView();    return getPointDataView();
445  }  }
446    
447    inline
448    const DataTagged::DataMapType&
449    DataTagged::getTagLookup() const
450    {
451      return m_offsetLookup;
452    }
453    
454    inline
455    DataArrayView::ValueType::size_type
456    DataTagged::getLength() const
457    {
458      return m_data.size();
459    }
460    
461  } // end of namespace  } // end of namespace
462    
463  #endif  #endif

Legend:
Removed from v.100  
changed lines
  Added in v.519

  ViewVC Help
Powered by ViewVC 1.1.26