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

revision 1795 by phornby, Fri Jul 11 13:12:46 2008 UTC revision 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC
# Line 18  Line 18 
18  #include "system_dep.h"  #include "system_dep.h"
19    
20  #include "DataAbstract.h"  #include "DataAbstract.h"
21  #include "DataArrayView.h"  #include "DataTypes.h"
22    
23  #include <vector>  #include <vector>
24  #include <map>  #include <map>
# Line 45  class DataTagged : public DataAbstract { Line 45  class DataTagged : public DataAbstract {
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 DataTypes::ValueType   ValueType;
50      typedef std::vector<ValueType::ElementType> ValueBatchType;
51    
52    //    //
53    // Map from a tag to an offset into the data array.    // Map from a tag to an offset into the data array.
# Line 65  class DataTagged : public DataAbstract { Line 66  class DataTagged : public DataAbstract {
66    ESCRIPT_DLL_API    ESCRIPT_DLL_API
67    DataTagged();    DataTagged();
68    
69    /**  //  /**
70       \brief  //      \brief
71       Constructor for DataTagged.  //      Constructor for DataTagged.
72    //
73       Description:  //      Description:
74       Constructor for DataTagged.  //      Constructor for DataTagged.
75       \param tagKeys - Input - A vector of integer tags.  //      \param tagKeys - Input - A vector of integer tags.
76       \param values - Input - A vector of DataArrayViews. If this is empty  //      \param values - Input - A vector of DataArrayViews. If this is empty
77                       all tag values will be assigned a scalar data-point of value  //                      all tag values will be assigned a scalar data-point of value
78                       0. If it contains one value all tag values will be assigned  //                      0. If it contains one value all tag values will be assigned
79               this value. Otherwise consecutive tags will be assigned  //           this value. Otherwise consecutive tags will be assigned
80                       consecutive values.  If there is a mismatch between  the  //                      consecutive values.  If there is a mismatch between  the
81               number of keys and the number of values an exception  //           number of keys and the number of values an exception
82               will be generated.  //           will be generated.
83       \param defaultValue - Input - Value returned if a requested tag doesn't exist.  //      \param defaultValue - Input - Value returned if a requested tag doesn't exist.
84       \param what - Input - A description of what this data represents.  //      \param what - Input - A description of what this data represents.
85      T  //     T
86    */  //  */
87    ESCRIPT_DLL_API  //   ESCRIPT_DLL_API
88    DataTagged(const TagListType& tagKeys,  //   DataTagged(const TagListType& tagKeys,
89               const ValueListType& values,  //              const ValueListType& values,
90           const DataArrayView& defaultValue,  //       const DataArrayView& defaultValue,
91           const FunctionSpace& what);  //       const FunctionSpace& what);
92    
93    /**    /**
94       \brief       \brief
# Line 97  class DataTagged : public DataAbstract { Line 98  class DataTagged : public DataAbstract {
98       Alternative Constructor for DataTagged.       Alternative Constructor for DataTagged.
99       \param what - Input - A description of what this data object represents.       \param what - Input - A description of what this data object represents.
100       \param shape - Input - The shape of each data-point.       \param shape - Input - The shape of each data-point.
101       \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]).
102       \param data - The data values for each tag.       \param data - The data values for each tag.
103      NB: no unit testing yet      NB: no unit testing yet
104    */    */
105    ESCRIPT_DLL_API    ESCRIPT_DLL_API
106    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
107               const DataArrayView::ShapeType &shape,               const DataTypes::ShapeType &shape,
108               const int tags[],               const int tags[],
109               const ValueType& data);               const ValueType& data);
110    
111    /**   /**
112       \brief       \brief
113       Alternative Constructor for DataTagged.       Alternative Constructor for DataTagged.
114    
# Line 117  class DataTagged : public DataAbstract { Line 118  class DataTagged : public DataAbstract {
118       \param shape - Input - The shape of each data-point.       \param shape - Input - The shape of each data-point.
119       \param tags - Input - An vector of tags, one for each sample number.       \param tags - Input - An vector of tags, one for each sample number.
120       \param data - The data values for each tag.       \param data - The data values for each tag.
121      NB: no unit testing yet  TODO Make sure to document the relationship between tags and data, ie: data also contains the default value
122    */   */
123    ESCRIPT_DLL_API    ESCRIPT_DLL_API
124    DataTagged(const FunctionSpace& what,    DataTagged(const FunctionSpace& what,
125               const DataArrayView::ShapeType &shape,               const DataTypes::ShapeType &shape,
126               const TagListType& tags,               const TagListType& tags,
127               const ValueType& data);               const ValueType& data);
128    
# Line 146  class DataTagged : public DataAbstract { Line 147  class DataTagged : public DataAbstract {
147    
148    /**    /**
149       \brief       \brief
150         Copies the tags from a DataTagged into a new Data Tagged and assigns them the default value. ** Not unit tested **
151    
152         This is different from a deep copy because we are not copying shape or other information, just tags.
153         \param what - Input - FunctionSpace for the new DataTagged
154         \param shape - Input - Shape for points in the new DataTagged
155         \param defaultvalue - Input - Default value for new DataTagged
156         \param tagsource - Input - A DataTagged object which supplies the tags.
157      */
158      ESCRIPT_DLL_API
159      DataTagged(const FunctionSpace& what,
160                 const DataTypes::ShapeType& shape,
161             const DataTypes::ValueType& defaultvalue,
162                 const DataTagged* tagsource=0);
163    
164      /**
165         \brief
166       Destructor       Destructor
167    */    */
168    ESCRIPT_DLL_API    ESCRIPT_DLL_API
# Line 227  class DataTagged : public DataAbstract { Line 244  class DataTagged : public DataAbstract {
244    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
245                   int dataPointNo) const;                   int dataPointNo) const;
246    
247    /**  
248    
249    //  /**
250    //      \brief
251    //      addTaggedValues
252    //
253    //      Description:
254    //      Add the given tags and values to this DataTagged object.
255    //      \param tagKeys - Input - A vector of integer tags.
256    //      \param values - Input - A vector of DataArrayViews. If this is empty
257    //                      all tag values will be assigned a scalar data-point of value
258    //                      0. If it contains one value all tag values will be assigned
259    //           this value. Otherwise consecutive tags will be assigned
260    //                      consecutive values.  If there is a mismatch between  the
261    //           number of keys and the number of values an exception
262    //           will be generated.
263    //     T
264    //  */
265    //   ESCRIPT_DLL_API
266    //   void
267    //   addTaggedValues(const TagListType& tagKeys,
268    //                   const ValueListType& values);  
269    
270    //  /**
271    //      \brief
272    //      addTaggedValue
273    //
274    //      Description:
275    //      Add a single tag and value to this DataTagged object. If this tag already has
276    //      a value associated with it, setTaggedValue will be used to update this value.
277    //      \param tagKey - Input - Integer tag.
278    //      \param value - Input - Single DataArrayView value to be assigned to the tag.
279    //     T
280     // */
281    //   ESCRIPT_DLL_API
282    //   void
283    //   addTaggedValue(int tagKey,
284    //                  const DataArrayView& value);
285    
286    
287    
288     /**
289       \brief       \brief
290       addTaggedValues       addTaggedValues
291    
292       Description:       Description:
293       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object.
294       \param tagKeys - Input - A vector of integer tags.       \param tagKeys - Input - A vector of integer tags.
295       \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
296                       all tag values will be assigned a scalar data-point of value                       this DataTagged will be used for all tags.
297                       0. If it contains one value all tag values will be assigned                       If it contains one value all tag values will be assigned
298               this value. Otherwise consecutive tags will be assigned               this value. Otherwise consecutive tags will be assigned
299                       consecutive values.  If there is a mismatch between  the                       consecutive values.  If there is a mismatch between  the
300               number of keys and the number of values an exception               number of keys and the number of values an exception
301               will be generated.               will be generated.
302         \param vShape - shape of the datapoints in "values"
303      T      T
304     */
305      ESCRIPT_DLL_API
306      void
307      addTaggedValues(const TagListType& tagKeys,
308                                const ValueBatchType& values,
309                                const ShapeType& vShape);
310    
311    
312      /**
313       Description:
314       Add the given tags and values to this DataTagged object.
315       \param tagKeys - Input - A vector of integer tags.
316       \param values - Input - A DataVector containing the datapoints.
317                 If this is empty, the default value for
318                         this DataTagged will be used for all tags.
319                         If it contains one value all tag values will be assigned
320                 this value. Otherwise consecutive tags will be assigned
321                         consecutive values.  If there is a mismatch between  the
322                 number of keys and the number of values an exception
323                 will be generated.
324        \param vShape - shape of the datapoints in "values"
325    
326       TODO Makesure this is properly unit tested
327    */    */
328    ESCRIPT_DLL_API    ESCRIPT_DLL_API
329    void    void
330    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
331                    const ValueListType& values);                                const ValueType& values,
332                                const ShapeType& vShape);
333    
334    
335    
336    
337    /**    /**
338       \brief       \brief
# Line 256  class DataTagged : public DataAbstract { Line 342  class DataTagged : public DataAbstract {
342       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
343       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.
344       \param tagKey - Input - Integer tag.       \param tagKey - Input - Integer tag.
345       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param pointshape - Shape of the value parameter
346      T       \param value - Input - Single DataArrayView value to be assigned to the tag.
347         \param dataOffset - Input - Offset of the beginning of the point in the value parameter
348    */    */
349    ESCRIPT_DLL_API    ESCRIPT_DLL_API
350    void    void
351    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
352                   const DataArrayView& value);           const DataTypes::ShapeType& pointshape,
353                     const ValueType& value,
354             int dataOffset=0);
355    
356    /**    /**
357       \brief       \brief
358       setTaggedValues       addTag - does not modify the default value for this object. ** Not unit tested **
359    
360       Description:       Description:
361       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.
362       \param tagKeys - Input - A vector of integer tag.       If this tag already has a value associated with it, then no change will be made.
363       \param values - Input - A vector of DataArrayViews. If this is empty       \param tagKey - Input - Integer tag.
364                       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  
365    */    */
366    ESCRIPT_DLL_API    ESCRIPT_DLL_API
367    void    void
368    setTaggedValues(const TagListType& tagKeys,    addTag(int tagKey);
369                    const ValueListType& values);  
370    
371    //  /**
372    //      \brief
373    //      setTaggedValues
374    //
375    //      Description:
376    //      Set the given tags to the given values in this DataTagged object.
377    //      \param tagKeys - Input - A vector of integer tag.
378    //      \param values - Input - A vector of DataArrayViews. If this is empty
379    //                      all tag values will be assigned a scalar data-point of value
380    //                      0. If it contains one value all tag values will be assigned
381    //           this value. Otherwise consecutive tags will be assigned
382    //                      consecutive values.  If there is a mismatch between  the
383    //           number of keys and the number of values an exception
384    //           will be generated.
385    //     T
386    //  */
387    //   ESCRIPT_DLL_API
388    //   void
389    //   setTaggedValues(const TagListType& tagKeys,
390    //                   const ValueListType& values);
391    
392    //  /**
393    //      \brief
394    //      setTaggedValue
395    //
396    //      Description:
397    //      Assign the given value to the given tag.
398    //      \param tagKey - Input - Integer tag.
399    //      \param value - Input - Single DataArrayView value to be assigned to the tag.
400    //     T
401    //  */
402    //   ESCRIPT_DLL_API
403    //   virtual
404    //   void
405    //   setTaggedValue(int tagKey,
406    //                  const DataArrayView& value);
407    
408    /**    /**
409       \brief       \brief
# Line 292  class DataTagged : public DataAbstract { Line 412  class DataTagged : public DataAbstract {
412       Description:       Description:
413       Assign the given value to the given tag.       Assign the given value to the given tag.
414       \param tagKey - Input - Integer tag.       \param tagKey - Input - Integer tag.
415       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param pointshape - the shape of the value parameter
416         \param value - Input - Vector storing the datapoint to be assigned to the tag.
417         \param dataOffset - beginning of the datapoint within "value".
418      T      T
419    */    */
420    ESCRIPT_DLL_API    ESCRIPT_DLL_API
   virtual  
421    void    void
422    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
423                   const DataArrayView& value);           const DataTypes::ShapeType& pointshape,
424                     const ValueType& value,
425             int dataOffset=0);
426    
427    
428    //  /**
429    //      \brief
430    //      getDataPointByTag
431    //
432    //      Description:
433    //      Return data-point associated with the given tag as a DataArrayView.
434    //      \param tag - Input - Integer key.
435    //     T
436    //  */
437    //   ESCRIPT_DLL_API
438    //   DataArrayView
439    //   getDataPointByTag(int tag) const;
440    
441    /**    /**
442       \brief       \brief
443       getDataPointByTag       getDataByTag
444    
445       Description:       Return a pointer to the beginning of the datapoint with the specified tag.
446       Return data-point associated with the given tag as a DataArrayView.       TODO Eventually these should be inlined.
447       \param tag - Input - Integer key.       \param tag - Input - Integer key.
448         \param i - position in the underlying datastructure
449      T      T
450    */    */
451    ESCRIPT_DLL_API    ESCRIPT_DLL_API
452    DataArrayView    DataTypes::ValueType::const_reference
453    getDataPointByTag(int tag) const;    getDataByTag(int tag, DataTypes::ValueType::size_type i) const;
454    
455      ESCRIPT_DLL_API
456      DataTypes::ValueType::reference
457      getDataByTag(int tag, DataTypes::ValueType::size_type i);
458    
459    
460    /**    /**
461       \brief        \brief
462       getDataPoint        getOffsetForTag
463    
464       Description:        \param tag
465       Return the data-point specified by the given sample and data-point        \return the offset of the beginning of the datapoint corresponding to tag.
466       numbers as a DataArrayView.  
467       \param sampleNo - Input.        Note: If the tag is not valid, the offset of the default value is returned instead.
      \param dataPointNo - Input.  
     T  
468    */    */
469    ESCRIPT_DLL_API    ESCRIPT_DLL_API
470    virtual    DataTypes::ValueType::size_type
471    DataArrayView    getOffsetForTag(int tag) const;
472    getDataPoint(int sampleNo,  
473                 int dataPointNo);  //  /**
474    //      \brief
475    //      getDataPoint
476    //
477    //      Description:
478    //      Return the data-point specified by the given sample and data-point
479    //      numbers as a DataArrayView.
480    //      \param sampleNo - Input.
481    //      \param dataPointNo - Input.
482    //     T
483    //  */
484    //   ESCRIPT_DLL_API
485    //   virtual
486    //   DataArrayView
487    //   getDataPoint(int sampleNo,
488    //                int dataPointNo);
489    
490    
491      /**
492         \brief
493         Return a reference to the underlying DataVector.
494      */
495    
496      ESCRIPT_DLL_API
497      DataTypes::ValueType&
498      getVector();
499    
500      ESCRIPT_DLL_API
501      const DataTypes::ValueType&
502      getVector() const;
503    
504    
505    
506    /**    /**
507       \brief       \brief
# Line 339  class DataTagged : public DataAbstract { Line 511  class DataTagged : public DataAbstract {
511       Return pointer to the data       Return pointer to the data
512      T      T
513    */    */
514    ESCRIPT_DLL_API  //   ESCRIPT_DLL_API
515    const DataArrayView::ValueType::ElementType*  //   const DataTypes::ValueType::ElementType*
516    getData() const;  //   getData() const;
517    
518    /**    /**
519       \brief       \brief
# Line 370  class DataTagged : public DataAbstract { Line 542  class DataTagged : public DataAbstract {
542    bool    bool
543    isCurrentTag(int tag) const;    isCurrentTag(int tag) const;
544    
545    // /**
546    //      \brief
547    //      getDefaultValue
548    //
549    //      Description:
550    //      Return the default value. This value is associated with any tag which
551    //      is not explicitly recorded in this DataTagged object's tag map.
552    //     T
553    //  */
554    //   ESCRIPT_DLL_API
555    //   DataArrayView&
556    //   getDefaultValue();
557    //
558    //   ESCRIPT_DLL_API
559    //   const DataArrayView&
560    //   getDefaultValue() const;
561    
562    /**    /**
563       \brief       \brief
564       getDefaultValue       getDefaultValue
# Line 377  class DataTagged : public DataAbstract { Line 566  class DataTagged : public DataAbstract {
566       Description:       Description:
567       Return the default value. This value is associated with any tag which       Return the default value. This value is associated with any tag which
568       is not explicitly recorded in this DataTagged object's tag map.       is not explicitly recorded in this DataTagged object's tag map.
569         \param i - position in the underlying datastructure
570      T      T
571    */    */
572    ESCRIPT_DLL_API    ESCRIPT_DLL_API
573    DataArrayView&    DataTypes::ValueType::reference
574    getDefaultValue();    getDefaultValue(DataTypes::ValueType::size_type i);
575    
576    ESCRIPT_DLL_API    ESCRIPT_DLL_API
577    const DataArrayView&    DataTypes::ValueType::const_reference
578    getDefaultValue() const;    getDefaultValue(DataTypes::ValueType::size_type i) const;
579    
580    
581    
582    
583    /**    /**
584       \brief       \brief
# Line 413  class DataTagged : public DataAbstract { Line 606  class DataTagged : public DataAbstract {
606    ESCRIPT_DLL_API    ESCRIPT_DLL_API
607    virtual    virtual
608    DataAbstract*    DataAbstract*
609    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataTypes::RegionType& region) const;
610    
611    /**    /**
612       \brief       \brief
# Line 428  class DataTagged : public DataAbstract { Line 621  class DataTagged : public DataAbstract {
621    */    */
622    ESCRIPT_DLL_API    ESCRIPT_DLL_API
623    DataTagged(const DataTagged& other,    DataTagged(const DataTagged& other,
624           const DataArrayView::RegionType& region);           const DataTypes::RegionType& region);
625    
626    /**    /**
627       \brief       \brief
# Line 444  class DataTagged : public DataAbstract { Line 637  class DataTagged : public DataAbstract {
637    virtual    virtual
638    void    void
639    setSlice(const DataAbstract* other,    setSlice(const DataAbstract* other,
640             const DataArrayView::RegionType& region);             const DataTypes::RegionType& region);
641    
   /**  
      \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);  
642    
643    /**    /**
644       \brief       \brief
# Line 553  class DataTagged : public DataAbstract { Line 722  class DataTagged : public DataAbstract {
722    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);
723    
724    
725      /**
726         \brief  Returns the offset in the structure which stores the default value
727      */
728      ESCRIPT_DLL_API
729      DataTypes::ValueType::size_type
730      getDefaultOffset() const;
731    
732   protected:   protected:
733    
734   private:   private:
# Line 579  DataTagged::isCurrentTag(int tag) const Line 755  DataTagged::isCurrentTag(int tag) const
755    return (pos!=m_offsetLookup.end());    return (pos!=m_offsetLookup.end());
756  }  }
757    
758  inline  // inline
759  DataArrayView&  // DataArrayView&
760  DataTagged::getDefaultValue()  // DataTagged::getDefaultValue()
761    // {
762    //   // The default value is always the first value.
763    //   return getPointDataView();
764    // }
765    
766    // inline
767    // const DataArrayView&
768    // DataTagged::getDefaultValue() const
769    // {
770    //   // The default value is always the first value.
771    //   return getPointDataView();
772    // }
773    
774    
775    inline
776    DataTypes::ValueType::size_type
777    DataTagged::getDefaultOffset() const
778  {  {
779    // The default value is always the first value.    return m_defaultValueOffset;  
   return getPointDataView();  
780  }  }
781    
782  inline  inline
783  const DataArrayView&  DataTypes::ValueType::reference
784  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue(DataTypes::ValueType::size_type i)
785  {  {
786    // The default value is always the first value.      return getVector()[i];
   return getPointDataView();  
787  }  }
788    
789  inline  inline
790  const DataArrayView::ValueType::ElementType*  DataTypes::ValueType::const_reference
791  DataTagged::getData() const  DataTagged::getDefaultValue(DataTypes::ValueType::size_type i) const
792  {  {
793     return &(m_data[0]);      return getVector()[i];
794  }  }
795    
796    
797    
798    
799    // inline
800    // const DataTypes::ValueType::ElementType*
801    // DataTagged::getData() const
802    // {
803    //    return &(m_data[0]);
804    // }
805    
806  inline  inline
807  const DataTagged::DataMapType&  const DataTagged::DataMapType&
808  DataTagged::getTagLookup() const  DataTagged::getTagLookup() const
# Line 610  DataTagged::getTagLookup() const Line 811  DataTagged::getTagLookup() const
811  }  }
812    
813  inline  inline
814  DataArrayView::ValueType::size_type  DataTypes::ValueType::size_type
815  DataTagged::getLength() const  DataTagged::getLength() const
816  {  {
817    return m_data.size();    return m_data.size();

Legend:
Removed from v.1795  
changed lines
  Added in v.1796

  ViewVC Help
Powered by ViewVC 1.1.26