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

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

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

trunk/esys2/escript/src/Data/Data.h revision 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/src/Data/Data.h revision 155 by jgs, Wed Nov 9 02:02:19 2005 UTC
# Line 20  Line 20 
20    
21  #include "escript/Data/DataAbstract.h"  #include "escript/Data/DataAbstract.h"
22  #include "escript/Data/DataTagged.h"  #include "escript/Data/DataTagged.h"
23    #include "escript/Data/DataAlgorithm.h"
24  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
25  #include "escript/Data/BinaryOp.h"  #include "escript/Data/BinaryOp.h"
26  #include "escript/Data/UnaryOp.h"  #include "escript/Data/UnaryOp.h"
# Line 43  extern "C" { Line 44  extern "C" {
44  namespace escript {  namespace escript {
45    
46  //  //
47  // Forward declaration for various implimentations of Data.  // Forward declaration for various implementations of Data.
48  class DataEmpty;  class DataEmpty;
49  class DataConstant;  class DataConstant;
50  class DataTagged;  class DataTagged;
# Line 205  class Data { Line 206  class Data {
206         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
207         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
208         bool expanded=false);         bool expanded=false);
209      /**
210         \brief
211         Destructor
212      */
213      ~Data();
214    
215    /**    /**
216       \brief       \brief
# Line 241  class Data { Line 247  class Data {
247    
248    /**    /**
249       \brief       \brief
250         Fills the expanded Data object from values of a python numarray object.
251      */
252      void
253      fillFromNumArray(const boost::python::numeric::array);
254    
255      /**
256         \brief
257         Return the tag number associated with the given data-point.
258    
259         The data-point number here corresponds to the data-point number in the
260         numarray returned by convertToNumArray.
261      */
262      int
263      getTagNumber(int dpno);
264    
265      /**
266         \brief
267       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
268    */    */
269    escriptDataC    escriptDataC
# Line 540  class Data { Line 563  class Data {
563       \brief       \brief
564       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
565       the result as a Data object.       the result as a Data object.
566         *
567    */    */
568    Data    Data
569    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 548  class Data { Line 572  class Data {
572       \brief       \brief
573       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
574       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.
575         *
576    */    */
577    Data    Data
578    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
# Line 558  class Data { Line 583  class Data {
583    /**    /**
584       \brief       \brief
585       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
586         *
587    */    */
588    boost::python::numeric::array    boost::python::numeric::array
589    integrate() const;    integrate() const;
# Line 565  class Data { Line 591  class Data {
591    /**    /**
592       \brief       \brief
593       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.
594         *
595    */    */
596    Data    Data
597    wherePositive() const;    wherePositive() const;
# Line 572  class Data { Line 599  class Data {
599    /**    /**
600       \brief       \brief
601       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.
602         *
603    */    */
604    Data    Data
605    whereNegative() const;    whereNegative() const;
# Line 579  class Data { Line 607  class Data {
607    /**    /**
608       \brief       \brief
609       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.
610         *
611    */    */
612    Data    Data
613    whereNonNegative() const;    whereNonNegative() const;
# Line 586  class Data { Line 615  class Data {
615    /**    /**
616       \brief       \brief
617       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.
618         *
619    */    */
620    Data    Data
621    whereNonPositive() const;    whereNonPositive() const;
# Line 593  class Data { Line 623  class Data {
623    /**    /**
624       \brief       \brief
625       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.
626         *
627    */    */
628    Data    Data
629    whereZero() const;    whereZero() const;
# Line 600  class Data { Line 631  class Data {
631    /**    /**
632       \brief       \brief
633       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.
634         *
635    */    */
636    Data    Data
637    whereNonZero() const;    whereNonZero() const;
638    
639    /**    /**
640       \brief       \brief
      Return the sin of each data point of this Data object.  
   */  
   Data  
   sin() const;  
   
   /**  
      \brief  
      Return the cos of each data point of this Data object.  
   */  
   Data  
   cos() const;  
   
   /**  
      \brief  
      Return the tan of each data point of this Data object.  
   */  
   Data  
   tan() const;  
   
   /**  
      \brief  
      Return the log to base 10 of each data point of this Data object.  
   */  
   Data  
   log() const;  
   
   /**  
      \brief  
      Return the natural log of each data point of this Data object.  
   */  
   Data  
   ln() const;  
   
   /**  
      \brief  
641       Return the maximum absolute value of this Data object.       Return the maximum absolute value of this Data object.
642         *
643    */    */
644    double    double
645    Lsup() const;    Lsup() const;
# Line 649  class Data { Line 647  class Data {
647    /**    /**
648       \brief       \brief
649       Return the minimum absolute value of this Data object.       Return the minimum absolute value of this Data object.
650         *
651    */    */
652    double    double
653    Linf() const;    Linf() const;
# Line 656  class Data { Line 655  class Data {
655    /**    /**
656       \brief       \brief
657       Return the maximum value of this Data object.       Return the maximum value of this Data object.
658         *
659    */    */
660    double    double
661    sup() const;    sup() const;
# Line 663  class Data { Line 663  class Data {
663    /**    /**
664       \brief       \brief
665       Return the minimum value of this Data object.       Return the minimum value of this Data object.
666         *
667    */    */
668    double    double
669    inf() const;    inf() const;
# Line 670  class Data { Line 671  class Data {
671    /**    /**
672       \brief       \brief
673       Return the absolute value of each data point of this Data object.       Return the absolute value of each data point of this Data object.
674         *
675    */    */
676    Data    Data
677    abs() const;    abs() const;
# Line 677  class Data { Line 679  class Data {
679    /**    /**
680       \brief       \brief
681       Return the maximum value of each data point of this Data object.       Return the maximum value of each data point of this Data object.
682         *
683    */    */
684    Data    Data
685    maxval() const;    maxval() const;
# Line 684  class Data { Line 687  class Data {
687    /**    /**
688       \brief       \brief
689       Return the minimum value of each data point of this Data object.       Return the minimum value of each data point of this Data object.
690         *
691    */    */
692    Data    Data
693    minval() const;    minval() const;
# Line 696  class Data { Line 700  class Data {
700    const boost::python::tuple    const boost::python::tuple
701    mindp() const;    mindp() const;
702    
703      void
704      calc_mindp(int& SampleNo,
705                 int& DataPointNo) const;
706    
707    /**    /**
708       \brief       \brief
709       Return the length of each data point of this Data object.       Return the length of each data point of this Data object.
710       sqrt(sum(A[i,j,k,l]^2))       sqrt(sum(A[i,j,k,l]^2))
711         *
712    */    */
713    Data    Data
714    length() const;    length() const;
# Line 708  class Data { Line 717  class Data {
717       \brief       \brief
718       Return the sign of each data point of this Data object.       Return the sign of each data point of this Data object.
719       -1 for negative values, zero for zero values, 1 for positive values.       -1 for negative values, zero for zero values, 1 for positive values.
720         *
721    */    */
722    Data    Data
723    sign() const;    sign() const;
724    
725    /**    /**
726      \brief       \brief
727      Transpose each data point of this Data object around the given axis.       Transpose each data point of this Data object around the given axis.
728      --* not implemented yet *--       --* not implemented yet *--
729         *
730    */    */
731    Data    Data
732    transpose(int axis) const;    transpose(int axis) const;
733    
734    /**    /**
735      \brief       \brief
736      Calculate the trace of each data point of this Data object.       Calculate the trace of each data point of this Data object.
737      sum(A[i,i,i,i])       sum(A[i,i,i,i])
738         *
739    */    */
740    Data    Data
741    trace() const;    trace() const;
742    
743    /**    /**
744      \brief       \brief
745      Return the exponential function of each data point of this Data object.       Return the sin of each data point of this Data object.
746         *
747      */
748      Data
749      sin() const;
750    
751      /**
752         \brief
753         Return the cos of each data point of this Data object.
754         *
755      */
756      Data
757      cos() const;
758    
759      /**
760         \brief
761         Return the tan of each data point of this Data object.
762         *
763      */
764      Data
765      tan() const;
766    
767      /**
768         \brief
769         Return the asin of each data point of this Data object.
770         *
771      */
772      Data
773      asin() const;
774    
775      /**
776         \brief
777         Return the acos of each data point of this Data object.
778         *
779      */
780      Data
781      acos() const;
782    
783      /**
784         \brief
785         Return the atan of each data point of this Data object.
786         *
787      */
788      Data
789      atan() const;
790    
791      /**
792         \brief
793         Return the sinh of each data point of this Data object.
794         *
795      */
796      Data
797      sinh() const;
798    
799      /**
800         \brief
801         Return the cosh of each data point of this Data object.
802         *
803      */
804      Data
805      cosh() const;
806    
807      /**
808         \brief
809         Return the tanh of each data point of this Data object.
810         *
811      */
812      Data
813      tanh() const;
814    
815      /**
816         \brief
817         Return the asinh of each data point of this Data object.
818         *
819      */
820      Data
821      asinh() const;
822    
823      /**
824         \brief
825         Return the acosh of each data point of this Data object.
826         *
827      */
828      Data
829      acosh() const;
830    
831      /**
832         \brief
833         Return the atanh of each data point of this Data object.
834         *
835      */
836      Data
837      atanh() const;
838    
839      /**
840         \brief
841         Return the log to base 10 of each data point of this Data object.
842         *
843      */
844      Data
845      log() const;
846    
847      /**
848         \brief
849         Return the natural log of each data point of this Data object.
850         *
851      */
852      Data
853      ln() const;
854    
855      /**
856         \brief
857         Return the exponential function of each data point of this Data object.
858         *
859    */    */
860    Data    Data
861    exp() const;    exp() const;
862    
863    /**    /**
864      \brief       \brief
865      Return the square root of each data point of this Data object.       Return the square root of each data point of this Data object.
866         *
867    */    */
868    Data    Data
869    sqrt() const;    sqrt() const;
870    
871    /**    /**
872      \brief       \brief
873      Return the negation of each data point of this Data object.       Return the negation of each data point of this Data object.
874         *
875    */    */
876    Data    Data
877    neg() const;    neg() const;
878    
879    /**    /**
880      \brief       \brief
881      Return the identity of each data point of this Data object.       Return the identity of each data point of this Data object.
882      Simply returns this object unmodified.       Simply returns this object unmodified.
883         *
884    */    */
885    Data    Data
886    pos() const;    pos() const;
# Line 762  class Data { Line 890  class Data {
890       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
891    
892       \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
893         *
894    */    */
895    Data    Data
896    powD(const Data& right) const;    powD(const Data& right) const;
897    
898    /**    /**
899     * \brief       \brief
900     * Return the given power of each data point of this boost python object.       Return the given power of each data point of this boost python object.
901     *      
902     * \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
903         *
904     */     */
905    Data    Data
906    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
907    
908    /**    /**
909      \brief       \brief
910      writes the object to a file in the DX file format       writes the object to a file in the DX file format
911    */    */
912    void    void
913    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
914    
915    /**    /**
916      \brief       \brief
917      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
918    */    */
919    void    void
920    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
# Line 793  class Data { Line 923  class Data {
923       \brief       \brief
924       Overloaded operator +=       Overloaded operator +=
925       \param right - Input - The right hand side.       \param right - Input - The right hand side.
926         *
927    */    */
928    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
929    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
# Line 801  class Data { Line 932  class Data {
932       \brief       \brief
933       Overloaded operator -=       Overloaded operator -=
934       \param right - Input - The right hand side.       \param right - Input - The right hand side.
935         *
936    */    */
937    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
938    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
# Line 809  class Data { Line 941  class Data {
941       \brief       \brief
942       Overloaded operator *=       Overloaded operator *=
943       \param right - Input - The right hand side.       \param right - Input - The right hand side.
944         *
945    */    */
946    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
947    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
# Line 817  class Data { Line 950  class Data {
950       \brief       \brief
951       Overloaded operator /=       Overloaded operator /=
952       \param right - Input - The right hand side.       \param right - Input - The right hand side.
953         *
954    */    */
955    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
956    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
# Line 882  class Data { Line 1016  class Data {
1016       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1017       this Data object.       this Data object.
1018       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1019         *
1020    */    */
1021    Data    Data
1022    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
# Line 892  class Data { Line 1027  class Data {
1027       Data object.       Data object.
1028       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1029       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1030         *
1031    */    */
1032    void    void
1033    setSlice(const Data& value,    setSlice(const Data& value,
# Line 939  class Data { Line 1075  class Data {
1075       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
1076       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.
1077    */    */
1078    template <class UnaryFunction>    template <class BinaryFunction>
1079    inline    inline
1080    double    double
1081    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1082                double initial_value) const;
1083    
1084    /**    /**
1085       \brief       \brief
# Line 951  class Data { Line 1088  class Data {
1088       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
1089       this Data object       this Data object
1090    */    */
1091    template <class UnaryFunction>    template <class BinaryFunction>
1092    inline    inline
1093    Data    Data
1094    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1095                   double initial_value) const;
1096    
1097    /**    /**
1098       \brief       \brief
# Line 1021  class Data { Line 1159  class Data {
1159    // pointer to the actual data object    // pointer to the actual data object
1160    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1161    
1162      //
1163      // pointer to the internal profiling data
1164      struct profDataEntry *profData;
1165    
1166  };  };
1167    
1168  template <class IValueType>  template <class IValueType>
# Line 1316  Data::unaryOp(UnaryFunction operation) Line 1458  Data::unaryOp(UnaryFunction operation)
1458    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.
1459    Calls escript::algorithm.    Calls escript::algorithm.
1460  */  */
1461  template <class UnaryFunction>  template <class BinaryFunction>
1462  inline  inline
1463  double  double
1464  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1465  {  {
1466    if (isExpanded()) {    if (isExpanded()) {
1467      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1468      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1469      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1470    } else if (isTagged()) {    } else if (isTagged()) {
1471      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1472      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1473      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1474    } else if (isConstant()) {    } else if (isConstant()) {
1475      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1476      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1477      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1478    }    }
1479    return 0;    return 0;
1480  }  }
# Line 1345  Data::algorithm(UnaryFunction operation) Line 1487  Data::algorithm(UnaryFunction operation)
1487    rank 0 Data object.    rank 0 Data object.
1488    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1489  */  */
1490  template <class UnaryFunction>  template <class BinaryFunction>
1491  inline  inline
1492  Data  Data
1493  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1494  {  {
1495    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1496    if (isExpanded()) {    if (isExpanded()) {
# Line 1356  Data::dp_algorithm(UnaryFunction operati Line 1498  Data::dp_algorithm(UnaryFunction operati
1498      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1499      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1500      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1501      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1502    } else if (isTagged()) {    } else if (isTagged()) {
1503      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1504      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1505      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1506      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1507      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1508    } else if (isConstant()) {    } else if (isConstant()) {
1509      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1510      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1511      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1512      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1513      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1514    }    }
1515    return result;    return result;
1516  }  }

Legend:
Removed from v.121  
changed lines
  Added in v.155

  ViewVC Help
Powered by ViewVC 1.1.26