/[escript]/trunk/esys2/escript/src/Data/Data.h
ViewVC logotype

Diff of /trunk/esys2/escript/src/Data/Data.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 100 by jgs, Wed Dec 15 03:48:48 2004 UTC revision 119 by jgs, Tue Apr 12 04:45:05 2005 UTC
# Line 23  Line 23 
23  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
24  #include "escript/Data/BinaryOp.h"  #include "escript/Data/BinaryOp.h"
25  #include "escript/Data/UnaryOp.h"  #include "escript/Data/UnaryOp.h"
26    #include "escript/Data/DataException.h"
27    
28  extern "C" {  extern "C" {
29  #include "escript/Data/DataC.h"  #include "escript/Data/DataC.h"
# Line 68  class Data { Line 69  class Data {
69    
70    public:    public:
71    
72      // These typedefs allow function names to be cast to pointers
73      // to functions of the appropriate type when calling unaryOp etc.
74    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
75    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
76    
77    /**    /**
78         Constructors.
79      */
80    
81      /**
82       \brief       \brief
83       Default constructor.       Default constructor.
84       Creates a DataEmpty object.       Creates a DataEmpty object.
# Line 88  class Data { Line 95  class Data {
95    /**    /**
96       \brief       \brief
97       Constructor from another Data object. If "what" is different from the       Constructor from another Data object. If "what" is different from the
98       function space of inData the inData are tried to be interpolated to what       function space of inData the inData are tried to be interpolated to what,
99       otherwise a shallow copy of inData is returned.       otherwise a shallow copy of inData is returned.
100    */    */
101    Data(const Data& inData,    Data(const Data& inData,
# Line 205  class Data { Line 212  class Data {
212    
213    /**    /**
214       \brief       \brief
215       Perform the specified algorithm on the Data and return result.       Perform a deep copy.
   */  
   template <class UnaryFunction>  
   inline double  
   algorithm(UnaryFunction operation) const;  
   
   /**  
      \brief  
      Perform the given unary operation on all of the data's elements.  
   */  
   template <class UnaryFunction>  
   void  
   unaryOp(UnaryFunction operation);  
   
   /**  
      \brief  
      Perform the given binary operation on all of the data's elements.  
      The underlying type of the right hand side (right) determines the final  
      type of *this after the operation. For example if the right hand side  
      is expanded *this will be expanded if necessary.  
   */  
   template <class BinaryFunction>  
   void  
   binaryOp(const Data& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
      Perform the given binary operation on all of the data's elements.  
216    */    */
   template <class BinaryFunction>  
217    void    void
218    binaryOp(const boost::python::object& right,    copy(const Data& other);
            BinaryFunction operation);  
219    
220    /**    /**
221       \brief       Member access methods.
      Overloaded operator +=  
      \param right - Input - The right hand side.  
222    */    */
   Data& operator+=(const Data& right);  
   Data& operator+=(const boost::python::object& right);  
223    
224    /**    /**
225       \brief       \brief
226       Overloaded operator -=       Return the values of all data-points in a single python numarray object.
      \param right - Input - The right hand side.  
   */  
   Data& operator-=(const Data& right);  
   Data& operator-=(const boost::python::object& right);  
   
  /**  
      \brief  
      Overloaded operator *=  
      \param right - Input - The right hand side.  
227    */    */
228    Data& operator*=(const Data& right);    boost::python::numeric::array
229    Data& operator*=(const boost::python::object& right);    convertToNumArray();
   
  /**  
      \brief  
      Overloaded operator /=  
      \param right - Input - The right hand side.  
   */  
   Data& operator/=(const Data& right);  
   Data& operator/=(const boost::python::object& right);  
   
   /**  
      \brief  
      Return the power of Data.  
   */  
   Data powD(const Data& right) const;  
   Data powO(const boost::python::object& right) const;  
230    
231    /**    /**
232       \brief       \brief
233       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
234    */    */
235    escriptDataC getDataC();    escriptDataC
236      getDataC();
237    
238    /**    /**
239       \brief       \brief
240       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
241    */    */
242    escriptDataC getDataC() const;    escriptDataC
243      getDataC() const;
244    
245    /**    /**
246       \brief       \brief
247       Write the data as a string.       Write the data as a string.
248    */    */
249    std::string toString() const;    inline
250      std::string
251      toString() const
252      {
253        return m_data->toString();
254      }
255    
256    /**    /**
257       \brief       \brief
# Line 312  class Data { Line 268  class Data {
268    
269    /**    /**
270       \brief       \brief
271       Perform a deep copy.       Whatever the current Data type make this into a DataExpanded.
   */  
   void  
   copy(const Data& other);  
   
   /**  
     \brief  
     Copy other Data object into this Data object where mask is positive.  
   */  
   void  
   copyWithMask(const Data& other,  
                const Data& mask);  
   
   /**  
      \brief  
      Whatever the current Data type make it expanded.  
272    */    */
273    void    void
274    expand();    expand();
275    
276    /**    /**
277       \brief       \brief
278       If possible convert the Data type to tagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
279       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
280       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
281    */    */
# Line 357  class Data { Line 298  class Data {
298    
299    /**    /**
300       \brief       \brief
301       Return true if this Data is empty.       Return true if this Data is constant.
302    */    */
303    bool    bool
304    isEmpty() const;    isConstant() const;
305    
306    /**    /**
307       \brief       \brief
308       Return true if this Data is constant.       Return true if this Data is empty.
309    */    */
310    bool    bool
311    isConstant() const;    isEmpty() const;
312    
313    /**    /**
314       \brief       \brief
# Line 418  class Data { Line 359  class Data {
359    
360    /**    /**
361       \brief       \brief
362       Return the number of data points per sample.       Return the number of samples.
363    */    */
364    inline    inline
365    int    int
366    getNumDataPointsPerSample() const    getNumSamples() const
367    {    {
368      return m_data->getNumDPPSample();      return m_data->getNumSamples();
369    }    }
370    
371    /**    /**
372       \brief       \brief
373       Return the number of samples.       Return the number of data points per sample.
374    */    */
375      inline
376    int    int
377    getNumSamples() const;    getNumDataPointsPerSample() const
378      {
379    /**      return m_data->getNumDPPSample();
380       \brief    }
      Check *this and the right operand are compatible. Throws  
      an exception if they aren't.  
      \param right - Input - The right hand side.  
   */  
   void  
   operandCheck(const Data& right) const;  
381    
382    /**    /**
383       \brief       \brief
# Line 449  class Data { Line 385  class Data {
385       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
386       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
387    */    */
388      inline
389    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
390    getSampleData(DataAbstract::ShapeType::size_type sampleNo);    getSampleData(DataAbstract::ValueType::size_type sampleNo)
391      {
392        return m_data->getSampleData(sampleNo);
393      }
394    
395    /**    /**
396       \brief       \brief
# Line 458  class Data { Line 398  class Data {
398       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
399       \param tag - Input - the tag key.       \param tag - Input - the tag key.
400    */    */
401      inline
402    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
403    getSampleDataByTag(int tag);    getSampleDataByTag(int tag)
404      {
405        return m_data->getSampleDataByTag(tag);
406      }
407    
408      /**
409         \brief
410         Assign the given value to the data-points referenced by the given
411         reference number.
412    
413         The value supplied is a python numarray object.  The data from this numarray
414         is unpacked into a DataArray, and this is used to set the corresponding
415         data-points in the underlying Data object.
416    
417         If the underlying Data object cannot be accessed via reference numbers, an
418         exception will be thrown.
419    
420         \param ref - Input - reference number.
421         \param value - Input - value to assign to data-points associated with
422                                the given reference number.
423      */
424      void
425      setRefValue(int ref,
426                  const boost::python::numeric::array& value);
427    
428      /**
429         \brief
430         Return the values associated with the data-points referenced by the given
431         reference number.
432    
433         The value supplied is a python numarray object. The data from the corresponding
434         data-points in this Data object are packed into the given numarray object.
435    
436         If the underlying Data object cannot be accessed via reference numbers, an
437         exception will be thrown.
438    
439         \param ref - Input - reference number.
440         \param value - Output - object to receive values from data-points
441                                 associated with the given reference number.
442      */
443      void
444      getRefValue(int ref,
445                  boost::python::numeric::array& value);
446    
447    /**    /**
448       \brief       \brief
# Line 486  class Data { Line 469  class Data {
469    
470    /**    /**
471       \brief       \brief
472       Return data point shape as a tuple of integers:       Return the data point shape as a tuple of integers.
473    */    */
474    boost::python::tuple    boost::python::tuple
475    getShapeTuple() const;    getShapeTuple() const;
# Line 501  class Data { Line 484  class Data {
484    
485    /**    /**
486       \brief       \brief
487       Return the number of doubles stored for Data.       Return the number of doubles stored for this Data.
488    */    */
489    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
490    getLength() const;    getLength() const;
491    
492    /**    /**
493       \brief       \brief
494       Interpolates this onto the given functionspace and returns the result as a Data object.       Assign the given value to the tag. Implicitly converts this
495         object to type DataTagged. Throws an exception if this object
496         cannot be converted to a DataTagged object.
497         \param tagKey - Input - Integer key.
498         \param value - Input - Value to associate with given key.
499      */
500      void
501      setTaggedValue(int tagKey,
502                     const boost::python::object& value);
503    
504      /**
505         \brief
506         Assign the given value to the tag. Implicitly converts this
507         object to type DataTagged. Throws an exception if this object
508         cannot be converted to a DataTagged object.
509         \param tagKey - Input - Integer key.
510         \param value - Input - Value to associate with given key.
511         Note: removed for now - this version not needed, and breaks escript.cpp
512      */
513      /*
514      void
515      setTaggedValue(int tagKey,
516                     const DataArrayView& value);
517      */
518    
519      /**
520        \brief
521        Copy other Data object into this Data object where mask is positive.
522      */
523      void
524      copyWithMask(const Data& other,
525                   const Data& mask);
526    
527      /**
528         Data object operation methods and operators.
529      */
530    
531      /**
532         \brief
533         Interpolates this onto the given functionspace and returns
534         the result as a Data object.
535    */    */
536    Data    Data
537    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 540  class Data { Line 563  class Data {
563    
564    /**    /**
565       \brief       \brief
566       Return a Data with a 1 for +ive values and a 0 for -ive values.       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
567      */
568      Data
569      whereNegative() const;
570    
571      /**
572         \brief
573         Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
574    */    */
575    Data    Data
576    whereNonNegative() const;    whereNonNegative() const;
577    
578    /**    /**
579       \brief       \brief
580       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
581    */    */
582    Data    Data
583    whereNegative() const;    whereNonPositive() const;
584    
585    /**    /**
586       \brief       \brief
587       Return a Data with a 1 for 0 values a 0 for +ive or -ive.       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
588    */    */
589    Data    Data
590    whereZero() const;    whereZero() const;
591    
592    /**    /**
593       \brief       \brief
594       Return the sin of Data.       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
595      */
596      Data
597      whereNonZero() const;
598    
599      /**
600         \brief
601         Return the sin of each data point of this Data object.
602    */    */
603    Data    Data
604    sin() const;    sin() const;
605    
606    /**    /**
607       \brief       \brief
608       Return the cos of Data.       Return the cos of each data point of this Data object.
609    */    */
610    Data    Data
611    cos() const;    cos() const;
612    
613    /**    /**
614       \brief       \brief
615       Return the tan of Data.       Return the tan of each data point of this Data object.
616    */    */
617    Data    Data
618    tan() const;    tan() const;
619    
620    /**    /**
621       \brief       \brief
622       Return the log to base 10 of Data.       Return the log to base 10 of each data point of this Data object.
623    */    */
624    Data    Data
625    log() const;    log() const;
626    
627    /**    /**
628       \brief       \brief
629       Return the natural log of Data.       Return the natural log of each data point of this Data object.
630    */    */
631    Data    Data
632    ln() const;    ln() const;
633    
634    /**    /**
635       \brief       \brief
636       Return a Data containing a slice of this Data.       Return the maximum absolute value of this Data object.
637    */    */
638    Data    double
639    getSlice(const DataArrayView::RegionType& region) const;    Lsup() const;
640    
641    /**    /**
642       \brief       \brief
643       Copy the specified region from the given value.       Return the minimum absolute value of this Data object.
      \param value - Input - Data to copy from.  
      \param region - Input - Region to copy.  
644    */    */
645    void    double
646    setSlice(const Data& value,    Linf() const;
            const DataArrayView::RegionType& region);  
647    
648    /**    /**
649       \brief       \brief
650       Return the maximum absolute value.       Return the maximum value of this Data object.
651    */    */
652    double    double
653    Lsup() const;    sup() const;
654    
655    /**    /**
656       \brief       \brief
657       Return the maximum value.       Return the minimum value of this Data object.
658    */    */
659    double    double
660    sup() const;    inf() const;
661    
662    /**    /**
663       \brief       \brief
664       Return the minimum value.       Return the absolute value of each data point of this Data object.
665    */    */
666    double    Data
667    inf() const;    abs() const;
668    
669    /**    /**
670       \brief       \brief
671       Returns a slice from this.       Return the maximum value of each data point of this Data object.
672    */    */
673    Data    Data
674    getItem(const boost::python::object& key) const;    maxval() const;
675    
676    /**    /**
677       \brief       \brief
678       Copies slice from value into this.       Return the minimum value of each data point of this Data object.
679    */    */
680    void    Data
681    setItem(const boost::python::object& key,    minval() const;
           const Data& value);  
682    
683    /**    /**
684       \brief       \brief
685       Convert the underlying data type to match the RHS.       Return the length of each data point of this Data object.
686       \param right - Input - data type to match.       sqrt(sum(A[i,j,k,l]^2))
687      */
688      Data
689      length() const;
690    
691      /**
692         \brief
693         Return the sign of each data point of this Data object.
694         -1 for negative values, zero for zero values, 1 for positive values.
695      */
696      Data
697      sign() const;
698    
699      /**
700        \transpose
701        Transpose each data point of this Data object around the given axis.
702        --* not implemented yet *--
703      */
704      Data
705      transpose(int axis) const;
706    
707      /**
708        \trace
709        Calculate the trace of each data point of this Data object.
710        sum(A[i,i,i,i])
711      */
712      Data
713      trace() const;
714    
715      /**
716        \exp
717        Return the exponential function of each data point of this Data object.
718      */
719      Data
720      exp() const;
721    
722      /**
723        \sqrt
724        Return the square root of each data point of this Data object.
725      */
726      Data
727      sqrt() const;
728    
729      /**
730         \brief
731         Return the given power of each data point of this Data object.
732      */
733      Data
734      powD(const Data& right) const;
735    
736      Data
737      powO(const boost::python::object& right) const;
738    
739      /**
740        \brief
741        writes the object to a file in the DX file format
742      */
743      void
744      saveDX(std::string fileName) const;
745    
746      /**
747        \brief
748        writes the object to a file in the VTK file format
749    */    */
750    void    void
751    typeMatch(const Data& right);    saveVTK(std::string fileName) const;
752    
753      /**
754        \brief
755        Return the negation of each data point of this Data object.
756      */
757      Data
758      neg() const;
759    
760      /**
761        \brief
762        Return the identity of each data point of this Data object.
763        Simply returns this object unmodified.
764      */
765      Data
766      pos() const;
767    
768      /**
769         \brief
770         Overloaded operator +=
771         \param right - Input - The right hand side.
772      */
773      Data& operator+=(const Data& right);
774      Data& operator+=(const boost::python::object& right);
775    
776      /**
777         \brief
778         Overloaded operator -=
779         \param right - Input - The right hand side.
780      */
781      Data& operator-=(const Data& right);
782      Data& operator-=(const boost::python::object& right);
783    
784     /**
785         \brief
786         Overloaded operator *=
787         \param right - Input - The right hand side.
788      */
789      Data& operator*=(const Data& right);
790      Data& operator*=(const boost::python::object& right);
791    
792     /**
793         \brief
794         Overloaded operator /=
795         \param right - Input - The right hand side.
796      */
797      Data& operator/=(const Data& right);
798      Data& operator/=(const boost::python::object& right);
799    
800    /**    /**
801       \brief       \brief
# Line 663  class Data { Line 805  class Data {
805    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
806    
807    /**    /**
808         Data object slicing methods.
809      */
810    
811      /**
812       \brief       \brief
813       Assign the given value to the tag. Implicitly converts this       Returns a slice from this Data object.
814       object to type DataTagged. Throws an exception if this object  
815       cannot be converted to a DataTagged object.       /description
816       \param tagKey - Input - Integer key.       Implements the [] get operator in python.
817       \param value - Input - Value to associate with given key.       Calls getSlice.
818    
819         \param key - Input - python slice tuple specifying
820         slice to return.
821      */
822      Data
823      getItem(const boost::python::object& key) const;
824    
825      /**
826         \brief
827         Copies slice from value into this Data object.
828    
829         \description
830         Implements the [] set operator in python.
831         Calls setSlice.
832    
833         \param key - Input - python slice tuple specifying
834         slice to copy from value.
835         \param value - Input - Data object to copy from.
836    */    */
837    void    void
838    setTaggedValue(int tagKey,    setItemD(const boost::python::object& key,
839                   const boost::python::object& value);             const Data& value);
840    
841      void
842      setItemO(const boost::python::object& key,
843               const boost::python::object& value);
844    
845      // These following public methods should be treated as private.
846    
847    /**    /**
848       \brief       \brief
849       Assign the given value to the tag. Implicitly converts this       Perform the given unary operation on every element of every data point in
850       object to type DataTagged. Throws an exception if this object       this Data object.
      cannot be converted to a DataTagged object.  
      \param tagKey - Input - Integer key.  
      \param value - Input - Value to associate with given key.  
      Note: removed for now - this version not needed, and breaks escript.cpp  
851    */    */
852    /*    template <class UnaryFunction>
853      inline
854    void    void
855    setTaggedValue(int tagKey,    unaryOp(UnaryFunction operation);
856                   const DataArrayView& value);  
857      /**
858         \brief
859         Return a Data object containing the specified slice of
860         this Data object.
861         \param region - Input - Region to copy.
862    */    */
863      Data
864      getSlice(const DataArrayView::RegionType& region) const;
865    
866      /**
867         \brief
868         Copy the specified slice from the given value into this
869         Data object.
870         \param value - Input - Data to copy from.
871         \param region - Input - Region to copy.
872      */
873      void
874      setSlice(const Data& value,
875               const DataArrayView::RegionType& region);
876    
877      /**
878         \brief
879         Archive the current Data object to the given file.
880         \param fileName - Input - file to archive to.
881      */
882      void
883      archiveData(const std::string fileName);
884    
885      /**
886         \brief
887         Extract the Data object archived in the given file, overwriting
888         the current Data object.
889         Note - the current object must be of type DataEmpty.
890         \param fileName - Input - file to extract from.
891         \param what - Input - a suitable FunctionSpace descibing the data.
892      */
893      void
894      extractData(const std::string fileName,
895                  const FunctionSpace& fspace);
896    
897     protected:
898    
899   private:   private:
900    
901    /**    /**
902       \brief       \brief
903         Check *this and the right operand are compatible. Throws
904         an exception if they aren't.
905         \param right - Input - The right hand side.
906      */
907      inline
908      void
909      operandCheck(const Data& right) const
910      {
911        return m_data->operandCheck(*(right.m_data.get()));
912      }
913    
914      /**
915         \brief
916         Perform the specified reduction algorithm on every element of every data point in
917         this Data object according to the given function and return the single value result.
918      */
919      template <class UnaryFunction>
920      inline
921      double
922      algorithm(UnaryFunction operation) const;
923    
924      /**
925         \brief
926         Reduce each data-point in this Data object using the given operation. Return a Data
927         object with the same number of data-points, but with each data-point containing only
928         one value - the result of the reduction operation on the corresponding data-point in
929         this Data object
930      */
931      template <class UnaryFunction>
932      inline
933      Data
934      dp_algorithm(UnaryFunction operation) const;
935    
936      /**
937         \brief
938         Perform the given binary operation on all of the data's elements.
939         The underlying type of the right hand side (right) determines the final
940         type of *this after the operation. For example if the right hand side
941         is expanded *this will be expanded if necessary.
942         RHS is a Data object.
943      */
944      template <class BinaryFunction>
945      inline
946      void
947      binaryOp(const Data& right,
948               BinaryFunction operation);
949    
950      /**
951         \brief
952         Perform the given binary operation on all of the data's elements.
953         RHS is a boost::python object.
954      */
955      template <class BinaryFunction>
956      inline
957      void
958      binaryOp(const boost::python::object& right,
959               BinaryFunction operation);
960    
961      /**
962         \brief
963         Convert the data type of the RHS to match this.
964         \param right - Input - data type to match.
965      */
966      void
967      typeMatchLeft(Data& right) const;
968    
969      /**
970         \brief
971         Convert the data type of this to match the RHS.
972         \param right - Input - data type to match.
973      */
974      void
975      typeMatchRight(const Data& right);
976    
977      /**
978         \brief
979       Construct a Data object of the appropriate type.       Construct a Data object of the appropriate type.
980    */    */
981    template <class IValueType>    template <class IValueType>
# Line 712  class Data { Line 995  class Data {
995    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
996    
997    //    //
998    // pointer to the actual data    // pointer to the actual data object
999    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1000    
1001  };  };
# Line 730  Data::initialise(const IValueType& value Line 1013  Data::initialise(const IValueType& value
1013    // within the shared_ptr constructor.    // within the shared_ptr constructor.
1014    if (expanded) {    if (expanded) {
1015      DataAbstract* temp=new DataExpanded(value,what);      DataAbstract* temp=new DataExpanded(value,what);
1016      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
1017        m_data=temp_data;
1018    } else {    } else {
1019      DataAbstract* temp=new DataConstant(value,what);      DataAbstract* temp=new DataConstant(value,what);
1020      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
1021        m_data=temp_data;
1022    }    }
1023  }  }
1024    
1025  inline  /**
1026  DataAbstract::ValueType::value_type*     Binary Data object operators.
1027  Data::getSampleData(DataAbstract::ValueType::size_type sampleNo)  */
 {  
   return m_data->getSampleData(sampleNo);  
 }  
   
 inline  
 DataAbstract::ValueType::value_type*  
 Data::getSampleDataByTag(int tag)  
 {  
   return m_data->getSampleDataByTag(tag);  
 }  
   
 inline  
 void  
 Data::operandCheck(const Data& right) const  
 {  
   return m_data->operandCheck(*(right.m_data.get()));  
 }  
   
 inline  
 int  
 Data::getNumSamples() const  
 {  
   return m_data->getNumSamples();  
 }  
   
 inline  
 std::string  
 Data::toString() const  
 {  
   return m_data->toString();  
 }  
1028    
1029  /**  /**
1030    \brief    \brief
# Line 876  std::ostream& operator<<(std::ostream& o Line 1130  std::ostream& operator<<(std::ostream& o
1130    NB: this operator does very little at this point, and isn't to    NB: this operator does very little at this point, and isn't to
1131    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1132  */  */
1133  bool operator==(const Data& left, const Data& right);  //bool operator==(const Data& left, const Data& right);
1134    
1135    /**
1136      \brief
1137      Perform the given binary operation with this and right as operands.
1138      Right is a Data object.
1139    */
1140  template <class BinaryFunction>  template <class BinaryFunction>
1141  inline  inline
1142  void  void
# Line 907  Data::binaryOp(const Data& right, Line 1166  Data::binaryOp(const Data& right,
1166     operandCheck(tempRight);     operandCheck(tempRight);
1167     //     //
1168     // ensure this has the right type for the RHS     // ensure this has the right type for the RHS
1169     typeMatch(tempRight);     typeMatchRight(tempRight);
1170     //     //
1171     // Need to cast to the concrete types so that the correct binaryOp     // Need to cast to the concrete types so that the correct binaryOp
1172     // is called.     // is called.
# Line 933  Data::binaryOp(const Data& right, Line 1192  Data::binaryOp(const Data& right,
1192         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");
1193         escript::binaryOp(*leftC,*rightC,operation);         escript::binaryOp(*leftC,*rightC,operation);
1194       }       }
1195     } else {     } else if (isConstant()) {
      //  
      // can only be DataConstant  
1196       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1197       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
1198       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
# Line 943  Data::binaryOp(const Data& right, Line 1200  Data::binaryOp(const Data& right,
1200     }     }
1201  }  }
1202    
1203    /**
1204      \brief
1205      Perform the given binary operation with this and right as operands.
1206      Right is a boost::python object.
1207    */
1208  template <class BinaryFunction>  template <class BinaryFunction>
1209  inline  inline
1210  void  void
# Line 963  Data::binaryOp(const boost::python::obje Line 1225  Data::binaryOp(const boost::python::obje
1225                    "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));                    "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));
1226       }       }
1227     }     }
   
1228     if (isExpanded()) {     if (isExpanded()) {
      //  
      // Expanded data will be done in parallel  
1229       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1230       EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");       EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");
1231       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
# Line 974  Data::binaryOp(const boost::python::obje Line 1233  Data::binaryOp(const boost::python::obje
1233       DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());       DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1234       EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");       EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1235       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
1236     } else {     } else if (isConstant()) {
      //  
      // can only be DataConstant  
1237       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1238       EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");       EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");
1239       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
1240     }     }
1241  }  }
1242    
1243    /**
1244      \brief
1245      Perform the given unary operation on other and return the result.
1246      Given operation is performed on each element of each data point, thus
1247      argument object is a rank n Data object, and returned object is a rank n
1248      Data object.
1249      Calls Data::unaryOp.
1250    */
1251    template <class UnaryFunction>
1252    inline
1253    Data
1254    unaryOp(const Data& other,
1255            UnaryFunction operation)
1256    {
1257      Data result;
1258      result.copy(other);
1259      result.unaryOp(operation);
1260      return result;
1261    }
1262    
1263    /**
1264      \brief
1265      Perform the given unary operation on this.
1266      Given operation is performed on each element of each data point.
1267      Calls escript::unaryOp.
1268    */
1269  template <class UnaryFunction>  template <class UnaryFunction>
1270  inline  inline
1271  void  void
1272  Data::unaryOp(UnaryFunction operation)  Data::unaryOp(UnaryFunction operation)
1273  {  {
1274    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1275      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1276      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1277      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
# Line 998  Data::unaryOp(UnaryFunction operation) Line 1279  Data::unaryOp(UnaryFunction operation)
1279      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1280      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1281      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1282    } else {    } else if (isConstant()) {
1283      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1284      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1285      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1286    }    }
1287  }  }
1288    
1289    /**
1290      \brief
1291      Perform the given Data object reduction algorithm on this and return the result.
1292      Given operation combines each element of each data point, thus argument
1293      object (*this) is a rank n Data object, and returned object is a scalar.
1294      Calls escript::algorithm.
1295    */
1296  template <class UnaryFunction>  template <class UnaryFunction>
1297  inline  inline
1298  double  double
1299  Data::algorithm(UnaryFunction operation) const  Data::algorithm(UnaryFunction operation) const
1300  {  {
1301    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1302      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1303      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1304      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1305    }    } else if (isTagged()) {
   else if (isTagged()) {  
1306      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1307      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1308      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1309    } else {    } else if (isConstant()) {
1310      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1311      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1312      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1313    }    }
1314      return 0;
1315  }  }
1316    
1317    /**
1318      \brief
1319      Perform the given data point reduction algorithm on data and return the result.
1320      Given operation combines each element within each data point into a scalar,
1321      thus argument object is a rank n Data object, and returned object is a
1322      rank 0 Data object.
1323      Calls escript::dp_algorithm.
1324    */
1325  template <class UnaryFunction>  template <class UnaryFunction>
1326  inline  inline
1327  Data  Data
1328  unaryOp(const Data& other,  Data::dp_algorithm(UnaryFunction operation) const
         UnaryFunction operation)  
1329  {  {
1330    //    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1331    // Perform the given operation on a copy of the input data and return the result    if (isExpanded()) {
1332    Data result;      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1333    //      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1334    // perform a deep copy      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1335    result.copy(other);      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1336    result.unaryOp(operation);      escript::dp_algorithm(*dataE,*resultE,operation);
1337      } else if (isTagged()) {
1338        DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1339        DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1340        EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1341        EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1342        escript::dp_algorithm(*dataT,*resultT,operation);
1343      } else if (isConstant()) {
1344        DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1345        DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1346        EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1347        EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1348        escript::dp_algorithm(*dataC,*resultC,operation);
1349      }
1350    return result;    return result;
1351  }  }
1352    
1353  }  }
   
1354  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26