/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC trunk/escript/src/Data.h revision 576 by gross, Fri Mar 3 08:28:42 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 "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 54  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:
63    
64      // These typedefs allow function names to be cast to pointers
65      // to functions of the appropriate type when calling unaryOp etc.
66    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
67    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
68    
# Line 150  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 206  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 220  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 268  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 397  class Data { Line 438  class Data {
438    
439    /**    /**
440       \brief       \brief
441         Assign the given value to the data-points referenced by the given
442         reference number.
443    
444         The value supplied is a python numarray object.  The data from this numarray
445         is unpacked into a DataArray, and this is used to set the corresponding
446         data-points in the underlying Data object.
447    
448         If the underlying Data object cannot be accessed via reference numbers, an
449         exception will be thrown.
450    
451         \param ref - Input - reference number.
452         \param value - Input - value to assign to data-points associated with
453                                the given reference number.
454      */
455      void
456      setRefValue(int ref,
457                  const boost::python::numeric::array& value);
458    
459      /**
460         \brief
461         Return the values associated with the data-points referenced by the given
462         reference number.
463    
464         The value supplied is a python numarray object. The data from the corresponding
465         data-points in this Data object are packed into the given numarray object.
466    
467         If the underlying Data object cannot be accessed via reference numbers, an
468         exception will be thrown.
469    
470         \param ref - Input - reference number.
471         \param value - Output - object to receive values from data-points
472                                 associated with the given reference number.
473      */
474      void
475      getRefValue(int ref,
476                  boost::python::numeric::array& value);
477    
478      /**
479         \brief
480       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
481       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
482       operation.       operation.
# Line 422  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 447  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 459  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 483  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 491  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 501  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 508  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(double tol=0.0) const;
597    
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(double tol=0.0) const;
605    
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(double tol=0.0) const;
613    
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(double tol=0.0) const;
621    
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(double tol=0.0) const;
629    
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
636      whereNonZero(double tol=0.0) const;
637    
638      /**
639         \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         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
718         Currently this function is restricted to rank 2, square shape, and dimension 3.
719         *
720      */
721      Data
722      eigenvalues() const;
723    
724      /**
725         \brief
726         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
727         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
728         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
729         first non-zero entry is positive.
730         Currently this function is restricted to rank 2, square shape, and dimension 3
731         *
732      */
733      const boost::python::tuple
734      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
735    
736      /**
737         \brief
738         Transpose each data point of this Data object around the given axis.
739         --* not implemented yet *--
740         *
741      */
742      Data
743      transpose(int axis) const;
744    
745      /**
746         \brief
747         Calculate the trace of each data point of this Data object.
748         *
749    */    */
750    Data    Data
751    whereNonZero() const;    trace() const;
752    
753    /**    /**
754       \brief       \brief
755       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
756         *
757    */    */
758    Data    Data
759    sin() const;    sin() const;
# Line 557  class Data { Line 761  class Data {
761    /**    /**
762       \brief       \brief
763       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
764         *
765    */    */
766    Data    Data
767    cos() const;    cos() const;
# Line 564  class Data { Line 769  class Data {
769    /**    /**
770       \brief       \brief
771       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
772         *
773    */    */
774    Data    Data
775    tan() const;    tan() const;
776    
777    /**    /**
778       \brief       \brief
779       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.
780         *
781    */    */
782    Data    Data
783    log() const;    asin() const;
784    
785    /**    /**
786       \brief       \brief
787       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
788         *
789    */    */
790    Data    Data
791    ln() const;    acos() const;
792    
793    /**    /**
794       \brief       \brief
795       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
796         *
797    */    */
798    double    Data
799    Lsup() const;    atan() const;
800    
801    /**    /**
802       \brief       \brief
803       Return the maximum value of this Data object.       Return the sinh of each data point of this Data object.
804         *
805    */    */
806    double    Data
807    sup() const;    sinh() const;
808    
809    /**    /**
810       \brief       \brief
811       Return the minimum value of this Data object.       Return the cosh of each data point of this Data object.
812         *
813    */    */
814    double    Data
815    inf() const;    cosh() const;
816    
817    /**    /**
818       \brief       \brief
819       Return the absolute value of each data point of this Data object.       Return the tanh of each data point of this Data object.
820         *
821    */    */
822    Data    Data
823    abs() const;    tanh() const;
824    
825    /**    /**
826       \brief       \brief
827       Return the maximum value of each data point of this Data object.       Return the asinh of each data point of this Data object.
828         *
829    */    */
830    Data    Data
831    maxval() const;    asinh() const;
832    
833    /**    /**
834       \brief       \brief
835       Return the minimum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
836         *
837    */    */
838    Data    Data
839    minval() const;    acosh() const;
840    
841    /**    /**
842       \brief       \brief
843       Return the length of each data point of this Data object.       Return the atanh of each data point of this Data object.
844       sqrt(sum(A[i,j,k,l]^2))       *
845    */    */
846    Data    Data
847    length() const;    atanh() const;
848    
849    /**    /**
850       \brief       \brief
851       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.
852       -1 for negative values, zero for zero values, 1 for positive values.       *
853    */    */
854    Data    Data
855    sign() const;    log10() const;
856    
857    /**    /**
858      \transpose       \brief
859      Transpose each data point of this Data object around the given axis.       Return the natural log of each data point of this Data object.
860         *
861    */    */
862    Data    Data
863    transpose(int axis) const;    log() const;
864    
865    /**    /**
866      \trace       \brief
867      Calculate the trace of each data point of this Data object.       Return the exponential function of each data point of this Data object.
868      sum(A[i,i,i,i])       *
869    */    */
870    Data    Data
871    trace() const;    exp() const;
872    
873    /**    /**
874      \exp       \brief
875      Return the exponential function of each data point of this Data object.       Return the square root of each data point of this Data object.
876         *
877    */    */
878    Data    Data
879    exp() const;    sqrt() const;
880    
881    /**    /**
882      \sqrt       \brief
883      Return the square root of each data point of this Data object.       Return the negation of each data point of this Data object.
884         *
885    */    */
886    Data    Data
887    sqrt() const;    neg() const;
888    
889      /**
890         \brief
891         Return the identity of each data point of this Data object.
892         Simply returns this object unmodified.
893         *
894      */
895      Data
896      pos() const;
897    
898    /**    /**
899       \brief       \brief
900       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
901    
902         \param right Input - the power to raise the object to.
903         *
904    */    */
905    Data    Data
906    powD(const Data& right) const;    powD(const Data& right) const;
907    
908      /**
909         \brief
910         Return the given power of each data point of this boost python object.
911        
912         \param right Input - the power to raise the object to.
913         *
914       */
915    Data    Data
916    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
917    
918    /**    /**
919      \brief       \brief
920      Return the negation of each data point of this Data object.       writes the object to a file in the DX file format
921    */    */
922    Data    void
923    neg() const;    saveDX(std::string fileName) const;
924    
925    /**    /**
926      \brief       \brief
927      Return the identity of each data point of this Data object.       writes the object to a file in the VTK file format
     Simply returns this object unmodified.  
928    */    */
929    Data    void
930    pos() const;    saveVTK(std::string fileName) const;
931    
932    /**    /**
933       \brief       \brief
934       Overloaded operator +=       Overloaded operator +=
935       \param right - Input - The right hand side.       \param right - Input - The right hand side.
936         *
937    */    */
938    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
939    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
# Line 706  class Data { Line 942  class Data {
942       \brief       \brief
943       Overloaded operator -=       Overloaded operator -=
944       \param right - Input - The right hand side.       \param right - Input - The right hand side.
945         *
946    */    */
947    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
948    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
# Line 714  class Data { Line 951  class Data {
951       \brief       \brief
952       Overloaded operator *=       Overloaded operator *=
953       \param right - Input - The right hand side.       \param right - Input - The right hand side.
954         *
955    */    */
956    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
957    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
# Line 722  class Data { Line 960  class Data {
960       \brief       \brief
961       Overloaded operator /=       Overloaded operator /=
962       \param right - Input - The right hand side.       \param right - Input - The right hand side.
963         *
964    */    */
965    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
966    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
# Line 755  class Data { Line 994  class Data {
994       \brief       \brief
995       Copies slice from value into this Data object.       Copies slice from value into this Data object.
996    
      \description  
997       Implements the [] set operator in python.       Implements the [] set operator in python.
998       Calls setSlice.       Calls setSlice.
999    
# Line 788  class Data { Line 1026  class Data {
1026       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1027       this Data object.       this Data object.
1028       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1029         *
1030    */    */
1031    Data    Data
1032    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
# Line 798  class Data { Line 1037  class Data {
1037       Data object.       Data object.
1038       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1039       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1040         *
1041    */    */
1042    void    void
1043    setSlice(const Data& value,    setSlice(const Data& value,
1044             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1045    
1046      /**
1047         \brief
1048         Archive the current Data object to the given file.
1049         \param fileName - Input - file to archive to.
1050      */
1051      void
1052      archiveData(const std::string fileName);
1053    
1054      /**
1055         \brief
1056         Extract the Data object archived in the given file, overwriting
1057         the current Data object.
1058         Note - the current object must be of type DataEmpty.
1059         \param fileName - Input - file to extract from.
1060         \param fspace - Input - a suitable FunctionSpace descibing the data.
1061      */
1062      void
1063      extractData(const std::string fileName,
1064                  const FunctionSpace& fspace);
1065    
1066   protected:   protected:
1067    
1068   private:   private:
# Line 823  class Data { Line 1083  class Data {
1083    /**    /**
1084       \brief       \brief
1085       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
1086       this Data object and return the single double value result.       this Data object according to the given function and return the single value result.
1087    */    */
1088    template <class UnaryFunction>    template <class BinaryFunction>
1089    inline    inline
1090    double    double
1091    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1092                double initial_value) const;
1093    
1094      /**
1095         \brief
1096         Reduce each data-point in this Data object using the given operation. Return a Data
1097         object with the same number of data-points, but with each data-point containing only
1098         one value - the result of the reduction operation on the corresponding data-point in
1099         this Data object
1100      */
1101      template <class BinaryFunction>
1102      inline
1103      Data
1104      dp_algorithm(BinaryFunction operation,
1105                   double initial_value) const;
1106    
1107    /**    /**
1108       \brief       \brief
# Line 895  class Data { Line 1169  class Data {
1169    // pointer to the actual data object    // pointer to the actual data object
1170    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1171    
1172      //
1173      // pointer to the internal profiling data
1174      struct profDataEntry *profData;
1175    
1176  };  };
1177    
1178  template <class IValueType>  template <class IValueType>
# Line 1190  Data::unaryOp(UnaryFunction operation) Line 1468  Data::unaryOp(UnaryFunction operation)
1468    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.
1469    Calls escript::algorithm.    Calls escript::algorithm.
1470  */  */
1471  template <class UnaryFunction>  template <class BinaryFunction>
1472  inline  inline
1473  double  double
1474  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1475  {  {
1476    if (isExpanded()) {    if (isExpanded()) {
1477      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1478      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1479      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1480    } else if (isTagged()) {    } else if (isTagged()) {
1481      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1482      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1483      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1484    } else if (isConstant()) {    } else if (isConstant()) {
1485      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1486      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1487      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1488    }    }
1489    return 0;    return 0;
1490  }  }
# Line 1219  Data::algorithm(UnaryFunction operation) Line 1497  Data::algorithm(UnaryFunction operation)
1497    rank 0 Data object.    rank 0 Data object.
1498    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1499  */  */
1500  template <class UnaryFunction>  template <class BinaryFunction>
1501  inline  inline
1502  Data  Data
1503  dp_algorithm(const Data& data,  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
              UnaryFunction operation)  
1504  {  {
1505    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());    if (isExpanded()) {
1506    if (data.isExpanded()) {      Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1507      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1508      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1509      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1510      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1511      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1512    } else if (data.isTagged()) {      return result;
1513      DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());    } else if (isTagged()) {
1514        DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1515        DataArrayView::ShapeType viewShape;
1516        DataArrayView::ValueType viewData(1);
1517        viewData[0]=0;
1518        DataArrayView defaultValue(viewData,viewShape);
1519        DataTagged::TagListType keys;
1520        DataTagged::ValueListType values;
1521        DataTagged::DataMapType::const_iterator i;
1522        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1523          keys.push_back(i->first);
1524          values.push_back(defaultValue);
1525        }
1526        Data result(keys,values,defaultValue,getFunctionSpace());
1527      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1528      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1529      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1530      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1531    } else if (data.isConstant()) {      return result;
1532      DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());    } else if (isConstant()) {
1533        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1534        DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1535      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1536      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1537      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1538      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1539        return result;
1540    }    }
1541    return result;    Data falseRetVal; // to keep compiler quiet
1542      return falseRetVal;
1543  }  }
1544    
1545  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26