/[escript]/branches/schroedinger/escript/src/Data.h
ViewVC logotype

Diff of /branches/schroedinger/escript/src/Data.h

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

trunk/esys2/escript/src/Data/Data.h revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC trunk/escript/src/Data.h revision 751 by bcumming, Mon Jun 26 01:46:34 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
3     ************************************************************
4   ******************************************************************************   *          Copyright 2006 by ACcESS MNRF                   *
5   *                                                                            *   *                                                          *
6   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *              http://www.access.edu.au                    *
7   *                                                                            *   *       Primary Business: Queensland, Australia            *
8   * This software is the property of ACcESS.  No part of this code             *   *  Licensed under the Open Software License version 3.0    *
9   * may be copied in any form or by any means without the expressed written    *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *                                                          *
11   * by any unauthorised person is illegal unless that                          *   ************************************************************
12   * person has a software license agreement with ACcESS.                       *  */
  *                                                                            *  
  ******************************************************************************  
13    
14  ******************************************************************************/  /** \file Data.h */
15    
16  #ifndef DATA_H  #ifndef DATA_H
17  #define DATA_H  #define DATA_H
18    
19  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
20  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
21  #include "escript/Data/FunctionSpace.h"  #include "FunctionSpace.h"
22  #include "escript/Data/BinaryOp.h"  #include "BinaryOp.h"
23  #include "escript/Data/UnaryOp.h"  #include "UnaryOp.h"
24  #include "escript/Data/DataException.h"  #include "DataException.h"
25    
26  extern "C" {  extern "C" {
27  #include "escript/Data/DataC.h"  #include "DataC.h"
28    #include "./paso/Paso.h"
29  }  }
30    
 #include <iostream>  
31  #include <string>  #include <string>
 #include <memory>  
32  #include <algorithm>  #include <algorithm>
33    
34  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
35  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
36  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
37  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
38    
39    namespace escript {
40    
41    //
42    // Forward declaration for various implementations of Data.
43    class DataConstant;
44    class DataTagged;
45    class DataExpanded;
46    
47  /**  /**
48     \brief     \brief
49     Data is essentially a factory class which creates the appropriate Data     Data creates the appropriate Data object for the given construction
50     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.  
51    
52     Description:     Description:
53     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 56  extern "C" {
56     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
57     the Data object.     the Data object.
58  */  */
   
 namespace escript {  
   
 //  
 // Forward declaration for various implimentations of Data.  
 class DataEmpty;  
 class DataConstant;  
 class DataTagged;  
 class DataExpanded;  
   
59  class Data {  class Data {
60    
61    public:    public:
# Line 153  class Data { Line 144  class Data {
144       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
145       \param expanded - Input - Flag, if true fill the entire container with       \param expanded - Input - Flag, if true fill the entire container with
146                         the appropriate values.                         the appropriate values.
147        ==>*
148    */    */
149    Data(const DataTagged::TagListType& tagKeys,    Data(const DataTagged::TagListType& tagKeys,
150         const DataTagged::ValueListType& values,         const DataTagged::ValueListType& values,
# Line 209  class Data { Line 201  class Data {
201         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
202         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
203         bool expanded=false);         bool expanded=false);
204      /**
205         \brief
206         Destructor
207      */
208      ~Data();
209    
210    /**    /**
211       \brief       \brief
# Line 223  class Data { Line 220  class Data {
220    
221    /**    /**
222       \brief       \brief
223       Return the values of all data-points in a single python numarray object.       Return the values of all data-points as a single python numarray object.
224    */    */
225    boost::python::numeric::array    const boost::python::numeric::array
226    convertToNumArray();    convertToNumArray();
227    
228    /**    /**
229       \brief       \brief
230         Return the values of all data-points for the given sample as a single python numarray object.
231      */
232      const boost::python::numeric::array
233      convertToNumArrayFromSampleNo(int sampleNo);
234    
235      /**
236         \brief
237         Return the value of the specified data-point as a single python numarray object.
238      */
239      const boost::python::numeric::array
240      convertToNumArrayFromDPNo(int sampleNo,
241                                int dataPointNo);
242    
243      /**
244         \brief
245         Fills the expanded Data object from values of a python numarray object.
246      */
247      void
248      fillFromNumArray(const boost::python::numeric::array);
249    
250      /**
251         \brief
252         Return the tag number associated with the given data-point.
253    
254         The data-point number here corresponds to the data-point number in the
255         numarray returned by convertToNumArray.
256      */
257      int
258      getTagNumber(int dpno);
259    
260      /**
261         \brief
262       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
263    */    */
264    escriptDataC    escriptDataC
# Line 278  class Data { Line 307  class Data {
307       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
308       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
309       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
310        ==>*
311    */    */
312    void    void
313    tag();    tag();
# Line 471  class Data { Line 501  class Data {
501       \brief       \brief
502       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
503    */    */
504    boost::python::tuple    const boost::python::tuple
505    getShapeTuple() const;    getShapeTuple() const;
506    
507    /**    /**
# Line 496  class Data { Line 526  class Data {
526       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
527       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
528       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
529        ==>*
530    */    */
531    void    void
532    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
# Line 508  class Data { Line 539  class Data {
539       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
540       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
541       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
542       Note: removed for now - this version not needed, and breaks escript.cpp      ==>*
543    */    */
   /*  
544    void    void
545    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
546                   const DataArrayView& value);                          const DataArrayView& value);
   */  
547    
548    /**    /**
549      \brief      \brief
# Line 532  class Data { Line 561  class Data {
561       \brief       \brief
562       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
563       the result as a Data object.       the result as a Data object.
564         *
565    */    */
566    Data    Data
567    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 540  class Data { Line 570  class Data {
570       \brief       \brief
571       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
572       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.
573         *
574    */    */
575    Data    Data
576    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
# Line 550  class Data { Line 581  class Data {
581    /**    /**
582       \brief       \brief
583       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
584         *
585    */    */
586    boost::python::numeric::array    boost::python::numeric::array
587    integrate() const;    integrate() const;
# Line 557  class Data { Line 589  class Data {
589    /**    /**
590       \brief       \brief
591       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.
592         *
593    */    */
594    Data    Data
595    wherePositive() const;    wherePositive() const;
# Line 564  class Data { Line 597  class Data {
597    /**    /**
598       \brief       \brief
599       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.
600         *
601    */    */
602    Data    Data
603    whereNegative() const;    whereNegative() const;
# Line 571  class Data { Line 605  class Data {
605    /**    /**
606       \brief       \brief
607       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.
608         *
609    */    */
610    Data    Data
611    whereNonNegative() const;    whereNonNegative() const;
# Line 578  class Data { Line 613  class Data {
613    /**    /**
614       \brief       \brief
615       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.
616         *
617    */    */
618    Data    Data
619    whereNonPositive() const;    whereNonPositive() const;
# Line 585  class Data { Line 621  class Data {
621    /**    /**
622       \brief       \brief
623       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.
624         *
625    */    */
626    Data    Data
627    whereZero() const;    whereZero(double tol=0.0) const;
628    
629    /**    /**
630       \brief       \brief
631       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.
632         *
633      */
634      Data
635      whereNonZero(double tol=0.0) const;
636    
637      /**
638         \brief
639         Return the maximum absolute value of this Data object.
640         *
641      */
642      double
643      Lsup() const;
644    
645      /**
646         \brief
647         Return the minimum absolute value of this Data object.
648         *
649      */
650      double
651      Linf() const;
652    
653      /**
654         \brief
655         Return the maximum value of this Data object.
656         *
657      */
658      double
659      sup() const;
660    
661      /**
662         \brief
663         Return the minimum value of this Data object.
664         *
665      */
666      double
667      inf() const;
668    
669      /**
670         \brief
671         Return the absolute value of each data point of this Data object.
672         *
673      */
674      Data
675      abs() const;
676    
677      /**
678         \brief
679         Return the maximum value of each data point of this Data object.
680         *
681      */
682      Data
683      maxval() const;
684    
685      /**
686         \brief
687         Return the minimum value of each data point of this Data object.
688         *
689      */
690      Data
691      minval() const;
692    
693      /**
694         \brief
695         Return the (sample number, data-point number) of the data point with
696         the minimum value in this Data object.
697      */
698      const boost::python::tuple
699      mindp() const;
700    
701      void
702      calc_mindp(int& SampleNo,
703                 int& DataPointNo) const;
704    
705      /**
706         \brief
707         Return the sign of each data point of this Data object.
708         -1 for negative values, zero for zero values, 1 for positive values.
709         *
710      */
711      Data
712      sign() const;
713    
714      /**
715         \brief
716         Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
717         Currently this function is restricted to rank 2, square shape, and dimension 3.
718         *
719      */
720      Data
721      eigenvalues() const;
722    
723      /**
724         \brief
725         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
726         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
727         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
728         first non-zero entry is positive.
729         Currently this function is restricted to rank 2, square shape, and dimension 3
730         *
731      */
732      const boost::python::tuple
733      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
734    
735      /**
736         \brief
737         Transpose each data point of this Data object around the given axis.
738         --* not implemented yet *--
739         *
740      */
741      Data
742      transpose(int axis) const;
743    
744      /**
745         \brief
746         Calculate the trace of each data point of this Data object.
747         *
748    */    */
749    Data    Data
750    whereNonZero() const;    trace() const;
751    
752    /**    /**
753       \brief       \brief
754       Return the sin of each data point of this Data object.       Return the sin of each data point of this Data object.
755         *
756    */    */
757    Data    Data
758    sin() const;    sin() const;
# Line 606  class Data { Line 760  class Data {
760    /**    /**
761       \brief       \brief
762       Return the cos of each data point of this Data object.       Return the cos of each data point of this Data object.
763         *
764    */    */
765    Data    Data
766    cos() const;    cos() const;
# Line 613  class Data { Line 768  class Data {
768    /**    /**
769       \brief       \brief
770       Return the tan of each data point of this Data object.       Return the tan of each data point of this Data object.
771         *
772    */    */
773    Data    Data
774    tan() const;    tan() const;
775    
776    /**    /**
777       \brief       \brief
778       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.
779         *
780    */    */
781    Data    Data
782    log() const;    asin() const;
783    
784    /**    /**
785       \brief       \brief
786       Return the natural log of each data point of this Data object.       Return the acos of each data point of this Data object.
787         *
788    */    */
789    Data    Data
790    ln() const;    acos() const;
791    
792    /**    /**
793       \brief       \brief
794       Return the maximum absolute value of this Data object.       Return the atan of each data point of this Data object.
795         *
796    */    */
797    double    Data
798    Lsup() const;    atan() const;
799    
800    /**    /**
801       \brief       \brief
802       Return the minimum absolute value of this Data object.       Return the sinh of each data point of this Data object.
803         *
804    */    */
805    double    Data
806    Linf() const;    sinh() const;
807    
808    /**    /**
809       \brief       \brief
810       Return the maximum value of this Data object.       Return the cosh of each data point of this Data object.
811         *
812    */    */
813    double    Data
814    sup() const;    cosh() const;
815    
816    /**    /**
817       \brief       \brief
818       Return the minimum value of this Data object.       Return the tanh of each data point of this Data object.
819         *
820    */    */
821    double    Data
822    inf() const;    tanh() const;
823    
824    /**    /**
825       \brief       \brief
826       Return the absolute value of each data point of this Data object.       Return the asinh of each data point of this Data object.
827         *
828    */    */
829    Data    Data
830    abs() const;    asinh() const;
831    
832    /**    /**
833       \brief       \brief
834       Return the maximum value of each data point of this Data object.       Return the acosh of each data point of this Data object.
835         *
836    */    */
837    Data    Data
838    maxval() const;    acosh() const;
839    
840    /**    /**
841       \brief       \brief
842       Return the minimum value of each data point of this Data object.       Return the atanh of each data point of this Data object.
843         *
844    */    */
845    Data    Data
846    minval() const;    atanh() const;
847    
848    /**    /**
849       \brief       \brief
850       Return the length of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
851       sqrt(sum(A[i,j,k,l]^2))       *
852    */    */
853    Data    Data
854    length() const;    log10() const;
855    
856    /**    /**
857       \brief       \brief
858       Return the sign of each data point of this Data object.       Return the natural log of each data point of this Data object.
859       -1 for negative values, zero for zero values, 1 for positive values.       *
860    */    */
861    Data    Data
862    sign() const;    log() const;
863    
864    /**    /**
865      \transpose       \brief
866      Transpose each data point of this Data object around the given axis.       Return the exponential function of each data point of this Data object.
867      --* not implemented yet *--       *
868    */    */
869    Data    Data
870    transpose(int axis) const;    exp() const;
871    
872    /**    /**
873      \trace       \brief
874      Calculate the trace of each data point of this Data object.       Return the square root of each data point of this Data object.
875      sum(A[i,i,i,i])       *
876    */    */
877    Data    Data
878    trace() const;    sqrt() const;
879    
880    /**    /**
881      \exp       \brief
882      Return the exponential function of each data point of this Data object.       Return the negation of each data point of this Data object.
883         *
884    */    */
885    Data    Data
886    exp() const;    neg() const;
887    
888    /**    /**
889      \sqrt       \brief
890      Return the square root of each data point of this Data object.       Return the identity of each data point of this Data object.
891         Simply returns this object unmodified.
892         *
893    */    */
894    Data    Data
895    sqrt() const;    pos() const;
896    
897    /**    /**
898       \brief       \brief
899       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
900    
901         \param right Input - the power to raise the object to.
902         *
903    */    */
904    Data    Data
905    powD(const Data& right) const;    powD(const Data& right) const;
906    
907      /**
908         \brief
909         Return the given power of each data point of this boost python object.
910        
911         \param right Input - the power to raise the object to.
912         *
913       */
914    Data    Data
915    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
916    
917    /**    /**
918      \brief       \brief
919      writes the object to a file in the DX file format       Return the given power of each data point of this boost python object.
920        
921         \param left Input - the bases
922         *
923       */
924    
925      Data
926      rpowO(const boost::python::object& left) const;
927    
928      /**
929         \brief
930         writes the object to a file in the DX file format
931    */    */
932    void    void
933    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
934    
935    /**    /**
936      \brief       \brief
937      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
938    */    */
939    void    void
940    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
941    
942    /**    /**
     \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;  
   
   /**  
943       \brief       \brief
944       Overloaded operator +=       Overloaded operator +=
945       \param right - Input - The right hand side.       \param right - Input - The right hand side.
946         *
947    */    */
948    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
949    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
# Line 777  class Data { Line 952  class Data {
952       \brief       \brief
953       Overloaded operator -=       Overloaded operator -=
954       \param right - Input - The right hand side.       \param right - Input - The right hand side.
955         *
956    */    */
957    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
958    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
# Line 785  class Data { Line 961  class Data {
961       \brief       \brief
962       Overloaded operator *=       Overloaded operator *=
963       \param right - Input - The right hand side.       \param right - Input - The right hand side.
964         *
965    */    */
966    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
967    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
# Line 793  class Data { Line 970  class Data {
970       \brief       \brief
971       Overloaded operator /=       Overloaded operator /=
972       \param right - Input - The right hand side.       \param right - Input - The right hand side.
973         *
974    */    */
975    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
976    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
# Line 826  class Data { Line 1004  class Data {
1004       \brief       \brief
1005       Copies slice from value into this Data object.       Copies slice from value into this Data object.
1006    
      \description  
1007       Implements the [] set operator in python.       Implements the [] set operator in python.
1008       Calls setSlice.       Calls setSlice.
1009    
# Line 859  class Data { Line 1036  class Data {
1036       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1037       this Data object.       this Data object.
1038       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1039         *
1040    */    */
1041    Data    Data
1042    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
# Line 869  class Data { Line 1047  class Data {
1047       Data object.       Data object.
1048       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1049       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1050         *
1051    */    */
1052    void    void
1053    setSlice(const Data& value,    setSlice(const Data& value,
1054             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
1055    
1056      /**
1057         \brief
1058         Archive the current Data object to the given file.
1059         \param fileName - Input - file to archive to.
1060      */
1061      void
1062      archiveData(const std::string fileName);
1063    
1064      /**
1065         \brief
1066         Extract the Data object archived in the given file, overwriting
1067         the current Data object.
1068         Note - the current object must be of type DataEmpty.
1069         \param fileName - Input - file to extract from.
1070         \param fspace - Input - a suitable FunctionSpace descibing the data.
1071      */
1072      void
1073      extractData(const std::string fileName,
1074                  const FunctionSpace& fspace);
1075    
1076    
1077      /**
1078         \brief
1079         print the data values to stdout. Used for debugging
1080      */
1081      void print();
1082    
1083   protected:   protected:
1084    
1085   private:   private:
# Line 896  class Data { Line 1102  class Data {
1102       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
1103       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.
1104    */    */
1105    template <class UnaryFunction>    template <class BinaryFunction>
1106    inline    inline
1107    double    double
1108    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1109                double initial_value) const;
1110    
1111    /**    /**
1112       \brief       \brief
# Line 908  class Data { Line 1115  class Data {
1115       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
1116       this Data object       this Data object
1117    */    */
1118    template <class UnaryFunction>    template <class BinaryFunction>
1119    inline    inline
1120    Data    Data
1121    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1122                   double initial_value) const;
1123    
1124    /**    /**
1125       \brief       \brief
# Line 978  class Data { Line 1186  class Data {
1186    // pointer to the actual data object    // pointer to the actual data object
1187    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1188    
1189      //
1190      // pointer to the internal profiling data
1191      struct profDataEntry *profData;
1192    
1193  };  };
1194    
1195  template <class IValueType>  template <class IValueType>
# Line 1273  Data::unaryOp(UnaryFunction operation) Line 1485  Data::unaryOp(UnaryFunction operation)
1485    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.
1486    Calls escript::algorithm.    Calls escript::algorithm.
1487  */  */
1488  template <class UnaryFunction>  template <class BinaryFunction>
1489  inline  inline
1490  double  double
1491  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1492  {  {
1493    if (isExpanded()) {    if (isExpanded()) {
1494      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1495      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1496      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1497    } else if (isTagged()) {    } else if (isTagged()) {
1498      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1499      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1500      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1501    } else if (isConstant()) {    } else if (isConstant()) {
1502      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1503      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1504      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1505    }    }
1506    return 0;    return 0;
1507  }  }
# Line 1302  Data::algorithm(UnaryFunction operation) Line 1514  Data::algorithm(UnaryFunction operation)
1514    rank 0 Data object.    rank 0 Data object.
1515    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1516  */  */
1517  template <class UnaryFunction>  template <class BinaryFunction>
1518  inline  inline
1519  Data  Data
1520  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1521  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1522    if (isExpanded()) {    if (isExpanded()) {
1523        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1524      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1525      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1526      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1527      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1528      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1529        return result;
1530    } else if (isTagged()) {    } else if (isTagged()) {
1531      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1532        DataArrayView::ShapeType viewShape;
1533        DataArrayView::ValueType viewData(1);
1534        viewData[0]=0;
1535        DataArrayView defaultValue(viewData,viewShape);
1536        DataTagged::TagListType keys;
1537        DataTagged::ValueListType values;
1538        DataTagged::DataMapType::const_iterator i;
1539        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1540          keys.push_back(i->first);
1541          values.push_back(defaultValue);
1542        }
1543        Data result(keys,values,defaultValue,getFunctionSpace());
1544      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1545      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1546      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1547      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1548        return result;
1549    } else if (isConstant()) {    } else if (isConstant()) {
1550        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1551      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1552      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1553      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1554      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1555      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1556        return result;
1557    }    }
1558    return result;    Data falseRetVal; // to keep compiler quiet
1559      return falseRetVal;
1560  }  }
1561    
1562  }  }

Legend:
Removed from v.117  
changed lines
  Added in v.751

  ViewVC Help
Powered by ViewVC 1.1.26