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

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

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

trunk/esys2/escript/src/Data/Data.h revision 113 by jgs, Mon Feb 28 07:06:33 2005 UTC trunk/escript/src/Data.h revision 562 by jgs, Thu Feb 23 05:03:16 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
   
3   ******************************************************************************   ******************************************************************************
4   *                                                                            *   *                                                                            *
5   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *
# Line 12  Line 11 
11   * person has a software license agreement with ACcESS.                       *   * person has a software license agreement with ACcESS.                       *
12   *                                                                            *   *                                                                            *
13   ******************************************************************************   ******************************************************************************
14    */
15    
16  ******************************************************************************/  /** \file Data.h */
17    
18  #ifndef DATA_H  #ifndef DATA_H
19  #define DATA_H  #define DATA_H
20    
21  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
22  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
23  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
24  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
25  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
26  #include "escript/Data/DataException.h"  #include "DataException.h"
27    
28  extern "C" {  extern "C" {
29  #include "escript/Data/DataC.h"  #include "DataC.h"
30  }  }
31    
 #include <iostream>  
32  #include <string>  #include <string>
 #include <memory>  
33  #include <algorithm>  #include <algorithm>
34    
35  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
36  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
37  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
38  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
39    
40    namespace escript {
41    
42    //
43    // Forward declaration for various implementations of Data.
44    class DataConstant;
45    class DataTagged;
46    class DataExpanded;
47    
48  /**  /**
49     \brief     \brief
50     Data is essentially a factory class which creates the appropriate Data     Data creates the appropriate Data object for the given construction
51     object for the given construction arguments. It retains control over     arguments.
    the object created for the lifetime of the object.  
    The type of Data object referred to may change during the lifetime of  
    the Data object.  
52    
53     Description:     Description:
54     Data is essentially a factory class which creates the appropriate Data     Data is essentially a factory class which creates the appropriate Data
# Line 55  extern "C" { Line 57  extern "C" {
57     The type of Data object referred to may change during the lifetime of     The type of Data object referred to may change during the lifetime of
58     the Data object.     the Data object.
59  */  */
   
 namespace escript {  
   
 //  
 // Forward declaration for various implimentations of Data.  
 class DataEmpty;  
 class DataConstant;  
 class DataTagged;  
 class DataExpanded;  
   
60  class Data {  class Data {
61    
62    public:    public:
# Line 153  class Data { Line 145  class Data {
145       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
146       \param expanded - Input - Flag, if true fill the entire container with       \param expanded - Input - Flag, if true fill the entire container with
147                         the appropriate values.                         the appropriate values.
148        ==>*
149    */    */
150    Data(const DataTagged::TagListType& tagKeys,    Data(const DataTagged::TagListType& tagKeys,
151         const DataTagged::ValueListType& values,         const DataTagged::ValueListType& values,
# Line 209  class Data { Line 202  class Data {
202         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
203         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
204         bool expanded=false);         bool expanded=false);
205      /**
206         \brief
207         Destructor
208      */
209      ~Data();
210    
211    /**    /**
212       \brief       \brief
# Line 223  class Data { Line 221  class Data {
221    
222    /**    /**
223       \brief       \brief
224         Return the values of all data-points as a single python numarray object.
225      */
226      const boost::python::numeric::array
227      convertToNumArray();
228    
229      /**
230         \brief
231         Return the values of all data-points for the given sample as a single python numarray object.
232      */
233      const boost::python::numeric::array
234      convertToNumArrayFromSampleNo(int sampleNo);
235    
236      /**
237         \brief
238         Return the value of the specified data-point as a single python numarray object.
239      */
240      const boost::python::numeric::array
241      convertToNumArrayFromDPNo(int sampleNo,
242                                int dataPointNo);
243    
244      /**
245         \brief
246         Fills the expanded Data object from values of a python numarray object.
247      */
248      void
249      fillFromNumArray(const boost::python::numeric::array);
250    
251      /**
252         \brief
253         Return the tag number associated with the given data-point.
254    
255         The data-point number here corresponds to the data-point number in the
256         numarray returned by convertToNumArray.
257      */
258      int
259      getTagNumber(int dpno);
260    
261      /**
262         \brief
263       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
264    */    */
265    escriptDataC    escriptDataC
# Line 271  class Data { Line 308  class Data {
308       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
309       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
310       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
311        ==>*
312    */    */
313    void    void
314    tag();    tag();
# Line 464  class Data { Line 502  class Data {
502       \brief       \brief
503       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
504    */    */
505    boost::python::tuple    const boost::python::tuple
506    getShapeTuple() const;    getShapeTuple() const;
507    
508    /**    /**
# Line 489  class Data { Line 527  class Data {
527       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
528       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
529       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
530        ==>*
531    */    */
532    void    void
533    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
# Line 501  class Data { Line 540  class Data {
540       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
541       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
542       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
543       Note: removed for now - this version not needed, and breaks escript.cpp      ==>*
544    */    */
   /*  
545    void    void
546    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
547                   const DataArrayView& value);                          const DataArrayView& value);
   */  
548    
549    /**    /**
550      \brief      \brief
# Line 525  class Data { Line 562  class Data {
562       \brief       \brief
563       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
564       the result as a Data object.       the result as a Data object.
565         *
566    */    */
567    Data    Data
568    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 533  class Data { Line 571  class Data {
571       \brief       \brief
572       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
573       If functionspace is not present the function space of Function(getDomain()) is used.       If functionspace is not present the function space of Function(getDomain()) is used.
574         *
575    */    */
576    Data    Data
577    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
# Line 543  class Data { Line 582  class Data {
582    /**    /**
583       \brief       \brief
584       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
585         *
586    */    */
587    boost::python::numeric::array    boost::python::numeric::array
588    integrate() const;    integrate() const;
# Line 550  class Data { Line 590  class Data {
590    /**    /**
591       \brief       \brief
592       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
593         *
594    */    */
595    Data    Data
596    wherePositive() const;    wherePositive() const;
# Line 557  class Data { Line 598  class Data {
598    /**    /**
599       \brief       \brief
600       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 values and a 0 for +ive or 0 values.
601         *
602    */    */
603    Data    Data
604    whereNegative() const;    whereNegative() const;
# Line 564  class Data { Line 606  class Data {
606    /**    /**
607       \brief       \brief
608       Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.       Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
609         *
610    */    */
611    Data    Data
612    whereNonNegative() const;    whereNonNegative() const;
# Line 571  class Data { Line 614  class Data {
614    /**    /**
615       \brief       \brief
616       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
617         *
618    */    */
619    Data    Data
620    whereNonPositive() const;    whereNonPositive() const;
# Line 578  class Data { Line 622  class Data {
622    /**    /**
623       \brief       \brief
624       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
625         *
626    */    */
627    Data    Data
628    whereZero() const;    whereZero() const;
# Line 585  class Data { Line 630  class Data {
630    /**    /**
631       \brief       \brief
632       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
633         *
634    */    */
635    Data    Data
636    whereNonZero() const;    whereNonZero() const;
637    
638    /**    /**
639       \brief       \brief
640         Return the maximum absolute value of this Data object.
641         *
642      */
643      double
644      Lsup() const;
645    
646      /**
647         \brief
648         Return the minimum absolute value of this Data object.
649         *
650      */
651      double
652      Linf() const;
653    
654      /**
655         \brief
656         Return the maximum value of this Data object.
657         *
658      */
659      double
660      sup() const;
661    
662      /**
663         \brief
664         Return the minimum value of this Data object.
665         *
666      */
667      double
668      inf() const;
669    
670      /**
671         \brief
672         Return the absolute value of each data point of this Data object.
673         *
674      */
675      Data
676      abs() const;
677    
678      /**
679         \brief
680         Return the maximum value of each data point of this Data object.
681         *
682      */
683      Data
684      maxval() const;
685    
686      /**
687         \brief
688         Return the minimum value of each data point of this Data object.
689         *
690      */
691      Data
692      minval() const;
693    
694      /**
695         \brief
696         Return the (sample number, data-point number) of the data point with
697         the minimum value in this Data object.
698      */
699      const boost::python::tuple
700      mindp() const;
701    
702      void
703      calc_mindp(int& SampleNo,
704                 int& DataPointNo) const;
705    
706      /**
707         \brief
708         Return the sign of each data point of this Data object.
709         -1 for negative values, zero for zero values, 1 for positive values.
710         *
711      */
712      Data
713      sign() const;
714    
715      /**
716         \brief
717         Transpose each data point of this Data object around the given axis.
718         --* not implemented yet *--
719         *
720      */
721      Data
722      transpose(int axis) const;
723    
724      /**
725         \brief
726         Calculate the trace of each data point of this Data object.
727         sum(A[i,i,i,i])
728         *
729      */
730      Data
731      trace() const;
732    
733      /**
734         \brief
735       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
736         *
737    */    */
738    Data    Data
739    sin() const;    sin() const;
# Line 599  class Data { Line 741  class Data {
741    /**    /**
742       \brief       \brief
743       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
744         *
745    */    */
746    Data    Data
747    cos() const;    cos() const;
# Line 606  class Data { Line 749  class Data {
749    /**    /**
750       \brief       \brief
751       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
752         *
753    */    */
754    Data    Data
755    tan() const;    tan() const;
756    
757    /**    /**
758       \brief       \brief
759       Return the log to base 10 of each data point of this Data object.       Return the asin of each data point of this Data object.
760         *
761    */    */
762    Data    Data
763    log() const;    asin() const;
764    
765    /**    /**
766       \brief       \brief
767       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
768         *
769    */    */
770    Data    Data
771    ln() const;    acos() const;
772    
773    /**    /**
774       \brief       \brief
775       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
776         *
777    */    */
778    double    Data
779    Lsup() const;    atan() const;
780    
781    /**    /**
782       \brief       \brief
783       Return the maximum value of this Data object.       Return the sinh of each data point of this Data object.
784         *
785    */    */
786    double    Data
787    sup() const;    sinh() const;
788    
789    /**    /**
790       \brief       \brief
791       Return the minimum value of this Data object.       Return the cosh of each data point of this Data object.
792         *
793    */    */
794    double    Data
795    inf() const;    cosh() const;
796    
797    /**    /**
798       \brief       \brief
799       Return the absolute value of each data point of this Data object.       Return the tanh of each data point of this Data object.
800         *
801    */    */
802    Data    Data
803    abs() const;    tanh() const;
804    
805    /**    /**
806       \brief       \brief
807       Return the maximum value of each data point of this Data object.       Return the asinh of each data point of this Data object.
808         *
809    */    */
810    Data    Data
811    maxval() const;    asinh() const;
812    
813    /**    /**
814       \brief       \brief
815       Return the minimum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
816         *
817    */    */
818    Data    Data
819    minval() const;    acosh() const;
820    
821    /**    /**
822       \brief       \brief
823       Return the length of each data point of this Data object.       Return the atanh of each data point of this Data object.
824       sqrt(sum(A[i,j,k,l]^2))       *
825    */    */
826    Data    Data
827    length() const;    atanh() const;
828    
829    /**    /**
830       \brief       \brief
831       Return the sign of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
832       -1 for negative values, zero for zero values, 1 for positive values.       *
833    */    */
834    Data    Data
835    sign() const;    log10() const;
836    
837    /**    /**
838      \transpose       \brief
839      Transpose each data point of this Data object around the given axis.       Return the natural log of each data point of this Data object.
840      --* not implemented yet *--       *
841    */    */
842    Data    Data
843    transpose(int axis) const;    log() const;
844    
845    /**    /**
846      \trace       \brief
847      Calculate the trace of each data point of this Data object.       Return the exponential function of each data point of this Data object.
848      sum(A[i,i,i,i])       *
849    */    */
850    Data    Data
851    trace() const;    exp() const;
852    
853    /**    /**
854      \exp       \brief
855      Return the exponential function of each data point of this Data object.       Return the square root of each data point of this Data object.
856         *
857    */    */
858    Data    Data
859    exp() const;    sqrt() const;
860    
861    /**    /**
862      \sqrt       \brief
863      Return the square root of each data point of this Data object.       Return the negation of each data point of this Data object.
864         *
865    */    */
866    Data    Data
867    sqrt() const;    neg() const;
868    
869      /**
870         \brief
871         Return the identity of each data point of this Data object.
872         Simply returns this object unmodified.
873         *
874      */
875      Data
876      pos() const;
877    
878    /**    /**
879       \brief       \brief
880       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
881    
882         \param right Input - the power to raise the object to.
883         *
884    */    */
885    Data    Data
886    powD(const Data& right) const;    powD(const Data& right) const;
887    
888      /**
889         \brief
890         Return the given power of each data point of this boost python object.
891        
892         \param right Input - the power to raise the object to.
893         *
894       */
895    Data    Data
896    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
897    
898    /**    /**
899      \brief       \brief
900      writes the object to a file in the DX file format       writes the object to a file in the DX file format
901    */    */
902    void    void
903    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
904    
905    /**    /**
906      \brief       \brief
907      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
908    */    */
909    void    void
910    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
911    
912    /**    /**
     \brief  
     Return the negation of each data point of this Data object.  
   */  
   Data  
   neg() const;  
   
   /**  
     \brief  
     Return the identity of each data point of this Data object.  
     Simply returns this object unmodified.  
   */  
   Data  
   pos() const;  
   
   /**  
913       \brief       \brief
914       Overloaded operator +=       Overloaded operator +=
915       \param right - Input - The right hand side.       \param right - Input - The right hand side.
916         *
917    */    */
918    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
919    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
# Line 763  class Data { Line 922  class Data {
922       \brief       \brief
923       Overloaded operator -=       Overloaded operator -=
924       \param right - Input - The right hand side.       \param right - Input - The right hand side.
925         *
926    */    */
927    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
928    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
# Line 771  class Data { Line 931  class Data {
931       \brief       \brief
932       Overloaded operator *=       Overloaded operator *=
933       \param right - Input - The right hand side.       \param right - Input - The right hand side.
934         *
935    */    */
936    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
937    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
# Line 779  class Data { Line 940  class Data {
940       \brief       \brief
941       Overloaded operator /=       Overloaded operator /=
942       \param right - Input - The right hand side.       \param right - Input - The right hand side.
943         *
944    */    */
945    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
946    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
# Line 812  class Data { Line 974  class Data {
974       \brief       \brief
975       Copies slice from value into this Data object.       Copies slice from value into this Data object.
976    
      \description  
977       Implements the [] set operator in python.       Implements the [] set operator in python.
978       Calls setSlice.       Calls setSlice.
979    
# Line 845  class Data { Line 1006  class Data {
1006       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1007       this Data object.       this Data object.
1008       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1009         *
1010    */    */
1011    Data    Data
1012    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
# Line 855  class Data { Line 1017  class Data {
1017       Data object.       Data object.
1018       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1019       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1020         *
1021    */    */
1022    void    void
1023    setSlice(const Data& value,    setSlice(const Data& value,
1024             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1025    
1026      /**
1027         \brief
1028         Archive the current Data object to the given file.
1029         \param fileName - Input - file to archive to.
1030      */
1031      void
1032      archiveData(const std::string fileName);
1033    
1034      /**
1035         \brief
1036         Extract the Data object archived in the given file, overwriting
1037         the current Data object.
1038         Note - the current object must be of type DataEmpty.
1039         \param fileName - Input - file to extract from.
1040         \param fspace - Input - a suitable FunctionSpace descibing the data.
1041      */
1042      void
1043      extractData(const std::string fileName,
1044                  const FunctionSpace& fspace);
1045    
1046   protected:   protected:
1047    
1048   private:   private:
# Line 882  class Data { Line 1065  class Data {
1065       Perform the specified reduction algorithm on every element of every data point in       Perform the specified reduction algorithm on every element of every data point in
1066       this Data object according to the given function and return the single value result.       this Data object according to the given function and return the single value result.
1067    */    */
1068    template <class UnaryFunction>    template <class BinaryFunction>
1069    inline    inline
1070    double    double
1071    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1072                double initial_value) const;
1073    
1074    /**    /**
1075       \brief       \brief
# Line 894  class Data { Line 1078  class Data {
1078       one value - the result of the reduction operation on the corresponding data-point in       one value - the result of the reduction operation on the corresponding data-point in
1079       this Data object       this Data object
1080    */    */
1081    template <class UnaryFunction>    template <class BinaryFunction>
1082    inline    inline
1083    Data    Data
1084    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1085                   double initial_value) const;
1086    
1087    /**    /**
1088       \brief       \brief
# Line 964  class Data { Line 1149  class Data {
1149    // pointer to the actual data object    // pointer to the actual data object
1150    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1151    
1152      //
1153      // pointer to the internal profiling data
1154      struct profDataEntry *profData;
1155    
1156  };  };
1157    
1158  template <class IValueType>  template <class IValueType>
# Line 1259  Data::unaryOp(UnaryFunction operation) Line 1448  Data::unaryOp(UnaryFunction operation)
1448    object (*this) is a rank n Data object, and returned object is a scalar.    object (*this) is a rank n Data object, and returned object is a scalar.
1449    Calls escript::algorithm.    Calls escript::algorithm.
1450  */  */
1451  template <class UnaryFunction>  template <class BinaryFunction>
1452  inline  inline
1453  double  double
1454  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1455  {  {
1456    if (isExpanded()) {    if (isExpanded()) {
1457      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1458      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1459      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1460    } else if (isTagged()) {    } else if (isTagged()) {
1461      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1462      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1463      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1464    } else if (isConstant()) {    } else if (isConstant()) {
1465      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1466      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1467      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1468    }    }
1469    return 0;    return 0;
1470  }  }
# Line 1288  Data::algorithm(UnaryFunction operation) Line 1477  Data::algorithm(UnaryFunction operation)
1477    rank 0 Data object.    rank 0 Data object.
1478    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1479  */  */
1480  template <class UnaryFunction>  template <class BinaryFunction>
1481  inline  inline
1482  Data  Data
1483  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1484  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1485    if (isExpanded()) {    if (isExpanded()) {
1486        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1487      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1488      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1489      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1490      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1491      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1492        return result;
1493    } else if (isTagged()) {    } else if (isTagged()) {
1494      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1495        DataArrayView::ShapeType viewShape;
1496        DataArrayView::ValueType viewData(1);
1497        viewData[0]=0;
1498        DataArrayView defaultValue(viewData,viewShape);
1499        DataTagged::TagListType keys;
1500        DataTagged::ValueListType values;
1501        DataTagged::DataMapType::const_iterator i;
1502        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1503          keys.push_back(i->first);
1504          values.push_back(defaultValue);
1505        }
1506        Data result(keys,values,defaultValue,getFunctionSpace());
1507      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1508      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1509      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1510      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1511        return result;
1512    } else if (isConstant()) {    } else if (isConstant()) {
1513        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1514      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1515      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1516      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1517      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1518      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1519        return result;
1520    }    }
1521    return result;    Data falseRetVal; // to keep compiler quiet
1522      return falseRetVal;
1523  }  }
1524    
1525  }  }

Legend:
Removed from v.113  
changed lines
  Added in v.562

  ViewVC Help
Powered by ViewVC 1.1.26