/[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

temp_trunk_copy/escript/src/DataTagged.h revision 1384 by phornby, Fri Jan 11 02:29:38 2008 UTC trunk/escript/src/DataTagged.h revision 2005 by jfenwick, Mon Nov 10 01:21:39 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #if !defined escript_DataTagged_20040615_H  #if !defined escript_DataTagged_20040615_H
16  #define escript_DataTagged_20040615_H  #define escript_DataTagged_20040615_H
17  #include "system_dep.h"  #include "system_dep.h"
18    
19  #include "DataAbstract.h"  #include "DataReady.h"
20  #include "DataArrayView.h"  #include "DataTypes.h"
21    
22  #include <vector>  #include <vector>
23  #include <map>  #include <map>
# Line 38  class DataConstant; Line 37  class DataConstant;
37     dataPointNo values.     dataPointNo values.
38  */  */
39    
40  class DataTagged : public DataAbstract {  class DataTagged : public DataReady {
41    typedef DataReady parent;
42   public:   public:
43    
44    //    //
45    // Types for the lists of tags and values.    // Types for the lists of tags and values.
46    typedef std::vector<int>           TagListType;    typedef std::vector<int>           TagListType;
47    typedef std::vector<DataArrayView> ValueListType;  //  typedef std::vector<DataArrayView> ValueListType;
48    typedef DataArrayView::ValueType   ValueType;    typedef DataTypes::ValueType   ValueType;
49      typedef std::vector<ValueType::ElementType> ValueBatchType;
50    
51    //    //
52    // Map from a tag to an offset into the data array.    // Map from a tag to an offset into the data array.
# Line 67  class DataTagged : public DataAbstract { Line 67  class DataTagged : public DataAbstract {
67    
68    /**    /**
69       \brief       \brief
      Constructor for DataTagged.  
   
      Description:  
      Constructor for DataTagged.  
      \param tagKeys - Input - A vector of integer tags.  
      \param values - Input - A vector of DataArrayViews. If this is empty  
                      all tag values will be assigned a scalar data-point of value  
                      0. If it contains one value all tag values will be assigned  
              this value. Otherwise consecutive tags will be assigned  
                      consecutive values.  If there is a mismatch between  the  
              number of keys and the number of values an exception  
              will be generated.  
      \param defaultValue - Input - Value returned if a requested tag doesn't exist.  
      \param what - Input - A description of what this data represents.  
     T  
   */  
   ESCRIPT_DLL_API  
   DataTagged(const TagListType& tagKeys,  
              const ValueListType& values,  
          const DataArrayView& defaultValue,  
          const FunctionSpace& what);  
   
   /**  
      \brief  
70       Alternative Constructor for DataTagged.       Alternative Constructor for DataTagged.
71    
72       Description:       Description:
73       Alternative Constructor for DataTagged.       Alternative Constructor for DataTagged.
74       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
75       \param shape - Input - The shape of each data-point.       \param shape - Input - The shape of each data-point.
76       \param tags - Input - An array of tags, one for each sample number.       \param tags - Input - An array of tags, one for each sample number (starts at tag[1]).
77       \param data - The data values for each tag.       \param data - The data values for each tag.
78      NB: no unit testing yet      NB: no unit testing yet
79    */    */
80    ESCRIPT_DLL_API    ESCRIPT_DLL_API
81    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
82               const DataArrayView::ShapeType &shape,               const DataTypes::ShapeType &shape,
83               const int tags[],               const int tags[],
84               const ValueType& data);               const ValueType& data);
85    
86    /**   /**
87       \brief       \brief
88       Alternative Constructor for DataTagged.       Alternative Constructor for DataTagged.
89    
# Line 117  class DataTagged : public DataAbstract { Line 93  class DataTagged : public DataAbstract {
93       \param shape - Input - The shape of each data-point.       \param shape - Input - The shape of each data-point.
94       \param tags - Input - An vector of tags, one for each sample number.       \param tags - Input - An vector of tags, one for each sample number.
95       \param data - The data values for each tag.       \param data - The data values for each tag.
96      NB: no unit testing yet  TODO Make sure to document the relationship between tags and data, ie: data also contains the default value
97    */   */
98    ESCRIPT_DLL_API    ESCRIPT_DLL_API
99    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
100               const DataArrayView::ShapeType &shape,               const DataTypes::ShapeType &shape,
101               const TagListType& tags,               const TagListType& tags,
102               const ValueType& data);               const ValueType& data);
103    
# Line 146  class DataTagged : public DataAbstract { Line 122  class DataTagged : public DataAbstract {
122    
123    /**    /**
124       \brief       \brief
125         Copies the tags from a DataTagged into a new Data Tagged and assigns them the default value. ** Not unit tested **
126    
127         This is different from a deep copy because we are not copying shape or other information, just tags.
128         \param what - Input - FunctionSpace for the new DataTagged
129         \param shape - Input - Shape for points in the new DataTagged
130         \param defaultvalue - Input - Default value for new DataTagged
131         \param tagsource - Input - A DataTagged object which supplies the tags.
132      */
133      ESCRIPT_DLL_API
134      DataTagged(const FunctionSpace& what,
135                 const DataTypes::ShapeType& shape,
136             const DataTypes::ValueType& defaultvalue,
137                 const DataTagged* tagsource=0);
138    
139      /**
140         \brief
141         Destructor
142      */
143      ESCRIPT_DLL_API
144      inline virtual
145      ~DataTagged() {};
146    
147      ESCRIPT_DLL_API
148      bool
149      isTagged() const
150      {
151        return true;
152      };
153    
154    
155      /**
156         \brief Return a deep copy of the current object.
157      */
158      ESCRIPT_DLL_API
159      virtual
160      DataAbstract*
161      deepCopy();
162    
163    
164      /**
165         \brief
166       getSampleDataByTag       getSampleDataByTag
167    
168       Description:       Description:
# Line 219  class DataTagged : public DataAbstract { Line 236  class DataTagged : public DataAbstract {
236    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
237                   int dataPointNo) const;                   int dataPointNo) const;
238    
239    /**    ESCRIPT_DLL_API
240      virtual
241      ValueType::size_type
242      getPointOffset(int sampleNo,
243                     int dataPointNo);
244    
245     /**
246       \brief       \brief
247       addTaggedValues       addTaggedValues
248    
249       Description:       Description:
250       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object.
251       \param tagKeys - Input - A vector of integer tags.       \param tagKeys - Input - A vector of integer tags.
252       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of doubles. If this is empty, the default value for
253                       all tag values will be assigned a scalar data-point of value                       this DataTagged will be used for all tags.
254                       0. If it contains one value all tag values will be assigned                       If it contains one value all tag values will be assigned
255               this value. Otherwise consecutive tags will be assigned               this value. Otherwise consecutive tags will be assigned
256                       consecutive values.  If there is a mismatch between  the                       consecutive values.  If there is a mismatch between  the
257               number of keys and the number of values an exception               number of keys and the number of values an exception
258               will be generated.               will be generated.
259         \param vShape - shape of the datapoints in "values"
260      T      T
261     */
262      ESCRIPT_DLL_API
263      void
264      addTaggedValues(const TagListType& tagKeys,
265                                const ValueBatchType& values,
266                                const ShapeType& vShape);
267    
268    
269      /**
270       Description:
271       Add the given tags and values to this DataTagged object.
272       \param tagKeys - Input - A vector of integer tags.
273       \param values - Input - A DataVector containing the datapoints.
274                 If this is empty, the default value for
275                         this DataTagged will be used for all tags.
276                         If it contains one value all tag values will be assigned
277                 this value. Otherwise consecutive tags will be assigned
278                         consecutive values.  If there is a mismatch between  the
279                 number of keys and the number of values an exception
280                 will be generated.
281        \param vShape - shape of the datapoints in "values"
282    
283       TODO Makesure this is properly unit tested
284    */    */
285    ESCRIPT_DLL_API    ESCRIPT_DLL_API
286    void    void
287    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
288                    const ValueListType& values);                                const ValueType& values,
289                                const ShapeType& vShape);
290    
291    
292    
293    
294    /**    /**
295       \brief       \brief
# Line 248  class DataTagged : public DataAbstract { Line 299  class DataTagged : public DataAbstract {
299       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
300       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.
301       \param tagKey - Input - Integer tag.       \param tagKey - Input - Integer tag.
302       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param pointshape - Shape of the value parameter
303      T       \param value - Input - Single DataArrayView value to be assigned to the tag.
304         \param dataOffset - Input - Offset of the beginning of the point in the value parameter
305    */    */
306    ESCRIPT_DLL_API    ESCRIPT_DLL_API
307    void    void
308    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
309                   const DataArrayView& value);           const DataTypes::ShapeType& pointshape,
310                     const ValueType& value,
311             int dataOffset=0);
312    
313    /**    /**
314       \brief       \brief
315       setTaggedValues       addTag - does not modify the default value for this object. ** Not unit tested **
316    
317       Description:       Description:
318       Set the given tags to the given values in this DataTagged object.       Add a single tag. The default value for this DataTagged will be associated with the tag.
319       \param tagKeys - Input - A vector of integer tag.       If this tag already has a value associated with it, then no change will be made.
320       \param values - Input - A vector of DataArrayViews. If this is empty       \param tagKey - Input - Integer tag.
321                       all tag values will be assigned a scalar data-point of value      TODO: Make sure this is unit tested
                      0. If it contains one value all tag values will be assigned  
              this value. Otherwise consecutive tags will be assigned  
                      consecutive values.  If there is a mismatch between  the  
              number of keys and the number of values an exception  
              will be generated.  
     T  
322    */    */
323    ESCRIPT_DLL_API    ESCRIPT_DLL_API
324    void    void
325    setTaggedValues(const TagListType& tagKeys,    addTag(int tagKey);
                   const ValueListType& values);  
326    
327    /**    /**
328       \brief       \brief
# Line 284  class DataTagged : public DataAbstract { Line 331  class DataTagged : public DataAbstract {
331       Description:       Description:
332       Assign the given value to the given tag.       Assign the given value to the given tag.
333       \param tagKey - Input - Integer tag.       \param tagKey - Input - Integer tag.
334       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param pointshape - the shape of the value parameter
335         \param value - Input - Vector storing the datapoint to be assigned to the tag.
336         \param dataOffset - beginning of the datapoint within "value".
337      T      T
338    */    */
339    ESCRIPT_DLL_API    ESCRIPT_DLL_API
   virtual  
340    void    void
341    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
342                   const DataArrayView& value);           const DataTypes::ShapeType& pointshape,
343                     const ValueType& value,
344             int dataOffset=0);
345    
346    /**    /**
347       \brief       \brief
348       getDataPointByTag       getDataByTag
349    
350       Description:       Return a pointer to the beginning of the datapoint with the specified tag.
351       Return data-point associated with the given tag as a DataArrayView.       TODO Eventually these should be inlined.
352       \param tag - Input - Integer key.       \param tag - Input - Integer key.
353         \param i - position in the underlying datastructure
354      T      T
355    */    */
356    ESCRIPT_DLL_API    ESCRIPT_DLL_API
357    DataArrayView    DataTypes::ValueType::const_reference
358    getDataPointByTag(int tag) const;    getDataByTag(int tag, DataTypes::ValueType::size_type i) const;
359    
360      ESCRIPT_DLL_API
361      DataTypes::ValueType::reference
362      getDataByTag(int tag, DataTypes::ValueType::size_type i);
363    
364    
365    /**    /**
366       \brief        \brief
367       getDataPoint        getOffsetForTag
368    
369       Description:        \param tag
370       Return the data-point specified by the given sample and data-point        \return the offset of the beginning of the datapoint corresponding to tag.
371       numbers as a DataArrayView.  
372       \param sampleNo - Input.        Note: If the tag is not valid, the offset of the default value is returned instead.
      \param dataPointNo - Input.  
     T  
373    */    */
374    ESCRIPT_DLL_API    ESCRIPT_DLL_API
375    virtual    DataTypes::ValueType::size_type
376    DataArrayView    getOffsetForTag(int tag) const;
377    getDataPoint(int sampleNo,  
378                 int dataPointNo);  
379      /**
380         \brief
381         Return a reference to the underlying DataVector.
382      */
383    
384      ESCRIPT_DLL_API
385      DataTypes::ValueType&
386      getVector();
387    
388      ESCRIPT_DLL_API
389      const DataTypes::ValueType&
390      getVector() const;
391    
392    
393    
394    /**    /**
395       \brief       \brief
# Line 331  class DataTagged : public DataAbstract { Line 399  class DataTagged : public DataAbstract {
399       Return pointer to the data       Return pointer to the data
400      T      T
401    */    */
402    ESCRIPT_DLL_API  //   ESCRIPT_DLL_API
403    const DataArrayView::ValueType::ElementType*  //   const DataTypes::ValueType::ElementType*
404    getData() const;  //   getData() const;
405    
406    /**    /**
407       \brief       \brief
# Line 369  class DataTagged : public DataAbstract { Line 437  class DataTagged : public DataAbstract {
437       Description:       Description:
438       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
439       is not explicitly recorded in this DataTagged object's tag map.       is not explicitly recorded in this DataTagged object's tag map.
440         \param i - position in the underlying datastructure
441      T      T
442    */    */
443    ESCRIPT_DLL_API    ESCRIPT_DLL_API
444    DataArrayView&    DataTypes::ValueType::reference
445    getDefaultValue();    getDefaultValue(DataTypes::ValueType::size_type i);
446    
447    ESCRIPT_DLL_API    ESCRIPT_DLL_API
448    const DataArrayView&    DataTypes::ValueType::const_reference
449    getDefaultValue() const;    getDefaultValue(DataTypes::ValueType::size_type i) const;
450    
451    
452    
453    
454    /**    /**
455       \brief       \brief
# Line 405  class DataTagged : public DataAbstract { Line 477  class DataTagged : public DataAbstract {
477    ESCRIPT_DLL_API    ESCRIPT_DLL_API
478    virtual    virtual
479    DataAbstract*    DataAbstract*
480    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
481    
482    /**    /**
483       \brief       \brief
# Line 420  class DataTagged : public DataAbstract { Line 492  class DataTagged : public DataAbstract {
492    */    */
493    ESCRIPT_DLL_API    ESCRIPT_DLL_API
494    DataTagged(const DataTagged& other,    DataTagged(const DataTagged& other,
495           const DataArrayView::RegionType& region);           const DataTypes::RegionType& region);
496    
497    /**    /**
498       \brief       \brief
# Line 436  class DataTagged : public DataAbstract { Line 508  class DataTagged : public DataAbstract {
508    virtual    virtual
509    void    void
510    setSlice(const DataAbstract* other,    setSlice(const DataAbstract* other,
511             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
512    
   /**  
      \brief  
      Archive the underlying data values to the file referenced  
      by ofstream. A count of the number of values expected to be written  
      is provided as a cross-check.  
   
      The return value indicates success (0) or otherwise (1).  
   */  
   ESCRIPT_DLL_API  
   int  
   archiveData(std::ofstream& archiveFile,  
               const DataArrayView::ValueType::size_type noValues) const;  
   
   /**  
      \brief  
      Extract the number of values specified by noValues from the file  
      referenced by ifstream to the underlying data structure.  
   
      The return value indicates success (0) or otherwise (1).  
   */  
   ESCRIPT_DLL_API  
   int  
   extractData(std::ifstream& archiveFile,  
               const DataArrayView::ValueType::size_type noValues);  
513    
514    /**    /**
515       \brief       \brief
# Line 545  class DataTagged : public DataAbstract { Line 593  class DataTagged : public DataAbstract {
593    eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);    eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
594    
595    
596      /**
597         \brief  Returns the offset in the structure which stores the default value
598      */
599      ESCRIPT_DLL_API
600      DataTypes::ValueType::size_type
601      getDefaultOffset() const;
602    
603   protected:   protected:
604    
605   private:   private:
# Line 571  DataTagged::isCurrentTag(int tag) const Line 626  DataTagged::isCurrentTag(int tag) const
626    return (pos!=m_offsetLookup.end());    return (pos!=m_offsetLookup.end());
627  }  }
628    
629  inline  // inline
630  DataArrayView&  // DataArrayView&
631  DataTagged::getDefaultValue()  // DataTagged::getDefaultValue()
632    // {
633    //   // The default value is always the first value.
634    //   return getPointDataView();
635    // }
636    
637    // inline
638    // const DataArrayView&
639    // DataTagged::getDefaultValue() const
640    // {
641    //   // The default value is always the first value.
642    //   return getPointDataView();
643    // }
644    
645    
646    inline
647    DataTypes::ValueType::size_type
648    DataTagged::getDefaultOffset() const
649  {  {
650    // The default value is always the first value.    return m_defaultValueOffset;  
   return getPointDataView();  
651  }  }
652    
653  inline  inline
654  const DataArrayView&  DataTypes::ValueType::reference
655  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue(DataTypes::ValueType::size_type i)
656  {  {
657    // The default value is always the first value.      return getVector()[i];
   return getPointDataView();  
658  }  }
659    
660  inline  inline
661  const DataArrayView::ValueType::ElementType*  DataTypes::ValueType::const_reference
662  DataTagged::getData() const  DataTagged::getDefaultValue(DataTypes::ValueType::size_type i) const
663  {  {
664     return &(m_data[0]);      return getVector()[i];
665  }  }
666    
667    
668    
669    
670    // inline
671    // const DataTypes::ValueType::ElementType*
672    // DataTagged::getData() const
673    // {
674    //    return &(m_data[0]);
675    // }
676    
677  inline  inline
678  const DataTagged::DataMapType&  const DataTagged::DataMapType&
679  DataTagged::getTagLookup() const  DataTagged::getTagLookup() const
# Line 602  DataTagged::getTagLookup() const Line 682  DataTagged::getTagLookup() const
682  }  }
683    
684  inline  inline
685  DataArrayView::ValueType::size_type  DataTypes::ValueType::size_type
686  DataTagged::getLength() const  DataTagged::getLength() const
687  {  {
688    return m_data.size();    return m_data.size();

Legend:
Removed from v.1384  
changed lines
  Added in v.2005

  ViewVC Help
Powered by ViewVC 1.1.26