/[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 94 by jgs, Wed Oct 27 00:45:54 2004 UTC revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC
# Line 72  class Data { Line 72  class Data {
72    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
73    
74    /**    /**
75         Constructors.
76      */
77    
78      /**
79       \brief       \brief
80       Default constructor.       Default constructor.
81       Creates a DataEmpty object.       Creates a DataEmpty object.
# Line 88  class Data { Line 92  class Data {
92    /**    /**
93       \brief       \brief
94       Constructor from another Data object. If "what" is different from the       Constructor from another Data object. If "what" is different from the
95       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,
96       otherwise a shallow copy of inData is returned.       otherwise a shallow copy of inData is returned.
97    */    */
98    Data(const Data& inData,    Data(const Data& inData,
# Line 205  class Data { Line 209  class Data {
209    
210    /**    /**
211       \brief       \brief
212       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.  
213    */    */
   template <class BinaryFunction>  
214    void    void
215    binaryOp(const boost::python::object& right,    copy(const Data& other);
            BinaryFunction operation);  
   
   /**  
      \brief  
      Overloaded operator +=  
      \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.  
   */  
   Data& operator-=(const Data& right);  
   Data& operator-=(const boost::python::object& right);  
   
  /**  
      \brief  
      Overloaded operator *=  
      \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.  
   */  
   Data& operator/=(const Data& right);  
   Data& operator/=(const boost::python::object& right);  
216    
217    /**    /**
218       \brief       Member access methods.
      Return the power of Data.  
219    */    */
   Data powD(const Data& right) const;  
   Data powO(const boost::python::object& right) const;  
220    
221    /**    /**
222       \brief       \brief
223       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
224    */    */
225    escriptDataC getDataC();    escriptDataC
226      getDataC();
227    
228    /**    /**
229       \brief       \brief
230       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
231    */    */
232    escriptDataC getDataC() const;    escriptDataC
233      getDataC() const;
234    
235    /**    /**
236       \brief       \brief
237       Write the data as a string.       Write the data as a string.
238    */    */
239    std::string toString() const;    inline
240      std::string
241      toString() const
242      {
243        return m_data->toString();
244      }
245    
246    /**    /**
247       \brief       \brief
# Line 312  class Data { Line 258  class Data {
258    
259    /**    /**
260       \brief       \brief
261       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.  
262    */    */
263    void    void
264    expand();    expand();
265    
266    /**    /**
267       \brief       \brief
268       If possible convert the Data type to tagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
269       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
270       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
271    */    */
# Line 357  class Data { Line 288  class Data {
288    
289    /**    /**
290       \brief       \brief
291       Return true if this Data is empty.       Return true if this Data is constant.
292    */    */
293    bool    bool
294    isEmpty() const;    isConstant() const;
295    
296    /**    /**
297       \brief       \brief
298       Return true if this Data is constant.       Return true if this Data is empty.
299    */    */
300    bool    bool
301    isConstant() const;    isEmpty() const;
302    
303    /**    /**
304       \brief       \brief
# Line 418  class Data { Line 349  class Data {
349    
350    /**    /**
351       \brief       \brief
352       Return the number of data points per sample.       Return the number of samples.
353    */    */
354    inline    inline
355    int    int
356    getNumDataPointsPerSample() const    getNumSamples() const
357    {    {
358      return m_data->getNumDPPSample();      return m_data->getNumSamples();
359    }    }
360    
361    /**    /**
362       \brief       \brief
363       Return the number of samples.       Return the number of data points per sample.
364    */    */
365      inline
366    int    int
367    getNumSamples() const;    getNumDataPointsPerSample() const
368      {
369    /**      return m_data->getNumDPPSample();
370       \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;  
371    
372    /**    /**
373       \brief       \brief
# Line 449  class Data { Line 375  class Data {
375       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
376       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
377    */    */
378      inline
379    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
380    getSampleData(DataAbstract::ShapeType::size_type sampleNo);    getSampleData(DataAbstract::ValueType::size_type sampleNo)
381      {
382        return m_data->getSampleData(sampleNo);
383      }
384    
385    /**    /**
386       \brief       \brief
# Line 458  class Data { Line 388  class Data {
388       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
389       \param tag - Input - the tag key.       \param tag - Input - the tag key.
390    */    */
391      inline
392    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
393    getSampleDataByTag(int tag);    getSampleDataByTag(int tag)
394      {
395        return m_data->getSampleDataByTag(tag);
396      }
397    
398    /**    /**
399       \brief       \brief
# Line 486  class Data { Line 420  class Data {
420    
421    /**    /**
422       \brief       \brief
423       Return data point shape as a tuple of integers:       Return the data point shape as a tuple of integers.
424    */    */
425    boost::python::tuple    boost::python::tuple
426    getShapeTuple() const;    getShapeTuple() const;
# Line 501  class Data { Line 435  class Data {
435    
436    /**    /**
437       \brief       \brief
438       Return the number of doubles stored for Data.       Return the number of doubles stored for this Data.
439    */    */
440    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
441    getLength() const;    getLength() const;
442    
443    /**    /**
444       \brief       \brief
445       Interpolates this onto the given functionspace and returns the result as a Data object.       Assign the given value to the tag. Implicitly converts this
446         object to type DataTagged. Throws an exception if this object
447         cannot be converted to a DataTagged object.
448         \param tagKey - Input - Integer key.
449         \param value - Input - Value to associate with given key.
450      */
451      void
452      setTaggedValue(int tagKey,
453                     const boost::python::object& value);
454    
455      /**
456         \brief
457         Assign the given value to the tag. Implicitly converts this
458         object to type DataTagged. Throws an exception if this object
459         cannot be converted to a DataTagged object.
460         \param tagKey - Input - Integer key.
461         \param value - Input - Value to associate with given key.
462         Note: removed for now - this version not needed, and breaks escript.cpp
463      */
464      /*
465      void
466      setTaggedValue(int tagKey,
467                     const DataArrayView& value);
468      */
469    
470      /**
471        \brief
472        Copy other Data object into this Data object where mask is positive.
473      */
474      void
475      copyWithMask(const Data& other,
476                   const Data& mask);
477    
478      /**
479         Data object operation methods and operators.
480      */
481    
482      /**
483         \brief
484         Interpolates this onto the given functionspace and returns
485         the result as a Data object.
486    */    */
487    Data    Data
488    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 540  class Data { Line 514  class Data {
514    
515    /**    /**
516       \brief       \brief
517       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.
518      */
519      Data
520      whereNegative() const;
521    
522      /**
523         \brief
524         Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
525    */    */
526    Data    Data
527    whereNonNegative() const;    whereNonNegative() const;
528    
529    /**    /**
530       \brief       \brief
531       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.
532    */    */
533    Data    Data
534    whereNegative() const;    whereNonPositive() const;
535    
536    /**    /**
537       \brief       \brief
538       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.
539    */    */
540    Data    Data
541    whereZero() const;    whereZero() const;
542    
543    /**    /**
544       \brief       \brief
545       Return the sin of Data.       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
546      */
547      Data
548      whereNonZero() const;
549    
550      /**
551         \brief
552         Return the sin of each data point of this Data object.
553    */    */
554    Data    Data
555    sin() const;    sin() const;
556    
557    /**    /**
558       \brief       \brief
559       Return the cos of Data.       Return the cos of each data point of this Data object.
560    */    */
561    Data    Data
562    cos() const;    cos() const;
563    
564    /**    /**
565       \brief       \brief
566       Return the tan of Data.       Return the tan of each data point of this Data object.
567    */    */
568    Data    Data
569    tan() const;    tan() const;
570    
571    /**    /**
572       \brief       \brief
573       Return the log to base 10 of Data.       Return the log to base 10 of each data point of this Data object.
574    */    */
575    Data    Data
576    log() const;    log() const;
577    
578    /**    /**
579       \brief       \brief
580       Return the natural log of Data.       Return the natural log of each data point of this Data object.
581    */    */
582    Data    Data
583    ln() const;    ln() const;
584    
585    /**    /**
586       \brief       \brief
587       Return a Data containing a slice of this Data.       Return the maximum absolute value of this Data object.
588    */    */
589    Data    double
590    getSlice(const DataArrayView::RegionType& region) const;    Lsup() const;
591    
592    /**    /**
593       \brief       \brief
594       Copy the specified region from the given value.       Return the maximum value of this Data object.
      \param value - Input - Data to copy from.  
      \param region - Input - Region to copy.  
595    */    */
596    void    double
597    setSlice(const Data& value,    sup() const;
            const DataArrayView::RegionType& region);  
598    
599    /**    /**
600       \brief       \brief
601       Return the maximum absolute value.       Return the minimum value of this Data object.
602    */    */
603    double    double
604    Lsup() const;    inf() const;
605    
606    /**    /**
607       \brief       \brief
608       Return the maximum value.       Return the absolute value of each data point of this Data object.
609    */    */
610    double    Data
611    sup() const;    abs() const;
612    
613    /**    /**
614       \brief       \brief
615       Return the minimum value.       Return the maximum value of each data point of this Data object.
616    */    */
617    double    Data
618    inf() const;    maxval() const;
619    
620    /**    /**
621       \brief       \brief
622       Returns a slice from this.       Return the minimum value of each data point of this Data object.
623    */    */
624    Data    Data
625    getItem(const boost::python::object& key) const;    minval() const;
626    
627    /**    /**
628       \brief       \brief
629       Copies slice from value into this.       Return the length of each data point of this Data object.
630         sqrt(sum(A[i,j,k,l]^2))
631    */    */
632    void    Data
633    setItem(const boost::python::object& key,    length() const;
           const Data& value);  
634    
635    /**    /**
636       \brief       \brief
637       Convert the underlying data type to match the RHS.       Return the sign of each data point of this Data object.
638       \param right - Input - data type to match.       -1 for negative values, zero for zero values, 1 for positive values.
639    */    */
640    void    Data
641    typeMatch(const Data& right);    sign() const;
642    
643      /**
644        \transpose
645        Transpose each data point of this Data object around the given axis.
646      */
647      Data
648      transpose(int axis) const;
649    
650      /**
651        \trace
652        Calculate the trace of each data point of this Data object.
653        sum(A[i,i,i,i])
654      */
655      Data
656      trace() const;
657    
658      /**
659        \exp
660        Return the exponential function of each data point of this Data object.
661      */
662      Data
663      exp() const;
664    
665      /**
666        \sqrt
667        Return the square root of each data point of this Data object.
668      */
669      Data
670      sqrt() const;
671    
672      /**
673         \brief
674         Return the given power of each data point of this Data object.
675      */
676      Data
677      powD(const Data& right) const;
678    
679      Data
680      powO(const boost::python::object& right) const;
681    
682      /**
683        \brief
684        Return the negation of each data point of this Data object.
685      */
686      Data
687      neg() const;
688    
689      /**
690        \brief
691        Return the identity of each data point of this Data object.
692        Simply returns this object unmodified.
693      */
694      Data
695      pos() const;
696    
697      /**
698         \brief
699         Overloaded operator +=
700         \param right - Input - The right hand side.
701      */
702      Data& operator+=(const Data& right);
703      Data& operator+=(const boost::python::object& right);
704    
705      /**
706         \brief
707         Overloaded operator -=
708         \param right - Input - The right hand side.
709      */
710      Data& operator-=(const Data& right);
711      Data& operator-=(const boost::python::object& right);
712    
713     /**
714         \brief
715         Overloaded operator *=
716         \param right - Input - The right hand side.
717      */
718      Data& operator*=(const Data& right);
719      Data& operator*=(const boost::python::object& right);
720    
721     /**
722         \brief
723         Overloaded operator /=
724         \param right - Input - The right hand side.
725      */
726      Data& operator/=(const Data& right);
727      Data& operator/=(const boost::python::object& right);
728    
729    /**    /**
730       \brief       \brief
# Line 663  class Data { Line 734  class Data {
734    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
735    
736    /**    /**
737         Data object slicing methods.
738      */
739    
740      /**
741       \brief       \brief
742       Assign the given value to the tag. Implicitly converts this       Returns a slice from this Data object.
743       object to type DataTagged. Throws an exception if this object  
744       cannot be converted to a DataTagged object.       /description
745       \param tagKey - Input - Integer key.       Implements the [] get operator in python.
746       \param value - Input - Value to associate with given key.       Calls getSlice.
747    
748         \param key - Input - python slice tuple specifying
749         slice to return.
750      */
751      Data
752      getItem(const boost::python::object& key) const;
753    
754      /**
755         \brief
756         Copies slice from value into this Data object.
757    
758         \description
759         Implements the [] set operator in python.
760         Calls setSlice.
761    
762         \param key - Input - python slice tuple specifying
763         slice to copy from value.
764         \param value - Input - Data object to copy from.
765    */    */
766    void    void
767    setTaggedValue(int tagKey,    setItemD(const boost::python::object& key,
768                   const boost::python::object& value);             const Data& value);
769    
770      void
771      setItemO(const boost::python::object& key,
772               const boost::python::object& value);
773    
774      // These following public methods should be treated as private.
775    
776    /**    /**
777       \brief       \brief
778       Assign the given value to the tag. Implicitly converts this       Perform the given unary operation on every element of every data point in
779       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  
780    */    */
781    /*    template <class UnaryFunction>
782      inline
783    void    void
784    setTaggedValue(int tagKey,    unaryOp(UnaryFunction operation);
785                   const DataArrayView& value);  
786      /**
787         \brief
788         Return a Data object containing the specified slice of
789         this Data object.
790         \param region - Input - Region to copy.
791    */    */
792      Data
793      getSlice(const DataArrayView::RegionType& region) const;
794    
795      /**
796         \brief
797         Copy the specified slice from the given value into this
798         Data object.
799         \param value - Input - Data to copy from.
800         \param region - Input - Region to copy.
801      */
802      void
803      setSlice(const Data& value,
804               const DataArrayView::RegionType& region);
805    
806     protected:
807    
808   private:   private:
809    
810    /**    /**
811       \brief       \brief
812         Check *this and the right operand are compatible. Throws
813         an exception if they aren't.
814         \param right - Input - The right hand side.
815      */
816      inline
817      void
818      operandCheck(const Data& right) const
819      {
820        return m_data->operandCheck(*(right.m_data.get()));
821      }
822    
823      /**
824         \brief
825         Perform the specified reduction algorithm on every element of every data point in
826         this Data object and return the single double value result.
827      */
828      template <class UnaryFunction>
829      inline
830      double
831      algorithm(UnaryFunction operation) const;
832    
833      /**
834         \brief
835         Perform the given binary operation on all of the data's elements.
836         The underlying type of the right hand side (right) determines the final
837         type of *this after the operation. For example if the right hand side
838         is expanded *this will be expanded if necessary.
839         RHS is a Data object.
840      */
841      template <class BinaryFunction>
842      inline
843      void
844      binaryOp(const Data& right,
845               BinaryFunction operation);
846    
847      /**
848         \brief
849         Perform the given binary operation on all of the data's elements.
850         RHS is a boost::python object.
851      */
852      template <class BinaryFunction>
853      inline
854      void
855      binaryOp(const boost::python::object& right,
856               BinaryFunction operation);
857    
858      /**
859         \brief
860         Convert the data type of the RHS to match this.
861         \param right - Input - data type to match.
862      */
863      void
864      typeMatchLeft(Data& right) const;
865    
866      /**
867         \brief
868         Convert the data type of this to match the RHS.
869         \param right - Input - data type to match.
870      */
871      void
872      typeMatchRight(const Data& right);
873    
874      /**
875         \brief
876       Construct a Data object of the appropriate type.       Construct a Data object of the appropriate type.
877    */    */
878    template <class IValueType>    template <class IValueType>
# Line 712  class Data { Line 892  class Data {
892    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
893    
894    //    //
895    // pointer to the actual data    // pointer to the actual data object
896    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
897    
898  };  };
# Line 730  Data::initialise(const IValueType& value Line 910  Data::initialise(const IValueType& value
910    // within the shared_ptr constructor.    // within the shared_ptr constructor.
911    if (expanded) {    if (expanded) {
912      DataAbstract* temp=new DataExpanded(value,what);      DataAbstract* temp=new DataExpanded(value,what);
913      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
914        m_data=temp_data;
915    } else {    } else {
916      DataAbstract* temp=new DataConstant(value,what);      DataAbstract* temp=new DataConstant(value,what);
917      m_data=boost::shared_ptr<DataAbstract>(temp);      boost::shared_ptr<DataAbstract> temp_data(temp);
918        m_data=temp_data;
919    }    }
920  }  }
921    
922  inline  /**
923  DataAbstract::ValueType::value_type*     Binary Data object operators.
924  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();  
 }  
925    
926  /**  /**
927    \brief    \brief
# Line 876  std::ostream& operator<<(std::ostream& o Line 1027  std::ostream& operator<<(std::ostream& o
1027    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
1028    be relied on. Requires further implementation.    be relied on. Requires further implementation.
1029  */  */
1030  bool operator==(const Data& left, const Data& right);  //bool operator==(const Data& left, const Data& right);
1031    
1032    /**
1033      \brief
1034      Perform the given binary operation with this and right as operands.
1035      Right is a Data object.
1036    */
1037  template <class BinaryFunction>  template <class BinaryFunction>
1038  inline  inline
1039  void  void
# Line 907  Data::binaryOp(const Data& right, Line 1063  Data::binaryOp(const Data& right,
1063     operandCheck(tempRight);     operandCheck(tempRight);
1064     //     //
1065     // ensure this has the right type for the RHS     // ensure this has the right type for the RHS
1066     typeMatch(tempRight);     typeMatchRight(tempRight);
1067     //     //
1068     // Need to cast to the concrete types so that the correct binaryOp     // Need to cast to the concrete types so that the correct binaryOp
1069     // is called.     // is called.
# Line 933  Data::binaryOp(const Data& right, Line 1089  Data::binaryOp(const Data& right,
1089         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");
1090         escript::binaryOp(*leftC,*rightC,operation);         escript::binaryOp(*leftC,*rightC,operation);
1091       }       }
1092     } else {     } else if (isConstant()) {
      //  
      // can only be DataConstant  
1093       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1094       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
1095       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 1097  Data::binaryOp(const Data& right,
1097     }     }
1098  }  }
1099    
1100    /**
1101      \brief
1102      Perform the given binary operation with this and right as operands.
1103      Right is a boost::python object.
1104    */
1105  template <class BinaryFunction>  template <class BinaryFunction>
1106  inline  inline
1107  void  void
# Line 963  Data::binaryOp(const boost::python::obje Line 1122  Data::binaryOp(const boost::python::obje
1122                    "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));                    "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));
1123       }       }
1124     }     }
   
1125     if (isExpanded()) {     if (isExpanded()) {
      //  
      // Expanded data will be done in parallel  
1126       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1127       EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");       EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");
1128       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
# Line 974  Data::binaryOp(const boost::python::obje Line 1130  Data::binaryOp(const boost::python::obje
1130       DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());       DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1131       EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");       EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1132       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
1133     } else {     } else if (isConstant()) {
      //  
      // can only be DataConstant  
1134       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1135       EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");       EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");
1136       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
1137     }     }
1138  }  }
1139    
1140    /**
1141      \brief
1142      Perform the given unary operation on other and return the result.
1143      Given operation is performed on each element of each data point, thus
1144      argument object is a rank n Data object, and returned object is a rank n
1145      Data object.
1146      Calls Data::unaryOp.
1147    */
1148    template <class UnaryFunction>
1149    inline
1150    Data
1151    unaryOp(const Data& other,
1152            UnaryFunction operation)
1153    {
1154      Data result;
1155      result.copy(other);
1156      result.unaryOp(operation);
1157      return result;
1158    }
1159    
1160    /**
1161      \brief
1162      Perform the given unary operation on this.
1163      Given operation is performed on each element of each data point.
1164      Calls escript::unaryOp.
1165    */
1166  template <class UnaryFunction>  template <class UnaryFunction>
1167  inline  inline
1168  void  void
1169  Data::unaryOp(UnaryFunction operation)  Data::unaryOp(UnaryFunction operation)
1170  {  {
1171    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1172      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1173      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1174      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
# Line 998  Data::unaryOp(UnaryFunction operation) Line 1176  Data::unaryOp(UnaryFunction operation)
1176      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1177      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1178      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1179    } else {    } else if (isConstant()) {
1180      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1181      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1182      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1183    }    }
1184  }  }
1185    
1186    /**
1187      \brief
1188      Perform the given Data object reduction algorithm on this and return the result.
1189      Given operation combines each element of each data point, thus argument
1190      object (*this) is a rank n Data object, and returned object is a scalar.
1191      Calls escript::algorithm.
1192    */
1193  template <class UnaryFunction>  template <class UnaryFunction>
1194  inline  inline
1195  double  double
1196  Data::algorithm(UnaryFunction operation) const  Data::algorithm(UnaryFunction operation) const
1197  {  {
1198    if (isExpanded()) {    if (isExpanded()) {
     //  
     // Expanded data will be done in parallel  
1199      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1200      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1201      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1202    }    } else if (isTagged()) {
   else if (isTagged()) {  
1203      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1204      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1205      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1206    } else {    } else if (isConstant()) {
1207      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1208      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1209      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1210    }    }
1211      return 0;
1212  }  }
1213    
1214    /**
1215      \brief
1216      Perform the given data point reduction algorithm on data and return the result.
1217      Given operation combines each element within each data point into a scalar,
1218      thus argument object is a rank n Data object, and returned object is a
1219      rank 0 Data object.
1220      Calls escript::dp_algorithm.
1221    */
1222  template <class UnaryFunction>  template <class UnaryFunction>
1223  inline  inline
1224  Data  Data
1225  unaryOp(const Data& other,  dp_algorithm(const Data& data,
1226          UnaryFunction operation)               UnaryFunction operation)
1227  {  {
1228    //    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());
1229    // Perform the given operation on a copy of the input data and return the result    if (data.isExpanded()) {
1230    Data result;      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get());
1231    //      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1232    // perform a deep copy      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1233    result.copy(other);      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1234    result.unaryOp(operation);      escript::dp_algorithm(*dataE,*resultE,operation);
1235      } else if (data.isTagged()) {
1236        DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());
1237        DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1238        EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1239        EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1240        escript::dp_algorithm(*dataT,*resultT,operation);
1241      } else if (data.isConstant()) {
1242        DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());
1243        DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1244        EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1245        EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1246        escript::dp_algorithm(*dataC,*resultC,operation);
1247      }
1248    return result;    return result;
1249  }  }
1250    
1251  }  }
   
1252  #endif  #endif

Legend:
Removed from v.94  
changed lines
  Added in v.97

  ViewVC Help
Powered by ViewVC 1.1.26